Sat, 13 Dec 2025 15:58:58 +0100
fix build with newest toolkit version
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
| 100 | 4 | * Copyright 2024 Olaf Wintermann. All rights reserved. |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
| 100 | 29 | #import "toolkit.h" |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
| 100 | 31 | #include "../common/document.h" |
| 32 | #include "../common/properties.h" | |
| 33 | #include "../common/menu.h" | |
| 34 | #include "../common/toolbar.h" | |
| 35 | #include "../common/threadpool.h" | |
|
115
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
36 | #include "../common/app.h" |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
38 | #import "image.h" |
|
103
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
39 | #import "menu.h" |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
40 | #import "Toolbar.h" |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
41 | #import "UiThread.h" |
|
103
6606616eca9f
update uwproj, toolkit, libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
100
diff
changeset
|
42 | |
| 100 | 43 | #import "AppDelegate.h" |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
| 100 | 45 | static const char *application_name; |
| 46 | ||
| 47 | static int app_argc; | |
| 48 | static const char **app_argv; | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | |
|
108
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
50 | static UiBool exit_on_shutdown; |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
| 100 | 52 | /* ------------------- App Init / Event Loop functions ------------------- */ |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | |
| 113 | 54 | |
| 100 | 55 | void ui_init(const char *appname, int argc, char **argv) { |
| 56 | application_name = appname; | |
| 57 | app_argc = argc; | |
| 58 | app_argv = (const char**)argv; | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | |
| 100 | 60 | uic_init_global_context(); |
| 61 | ||
| 62 | uic_menu_init(); | |
| 63 | uic_toolbar_init(); | |
| 64 | ||
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | uic_load_app_properties(); |
| 100 | 66 | |
| 113 | 67 | NSApplication *app = [NSApplication sharedApplication]; |
| 68 | //[app setActivationPolicy:NSApplicationActivationPolicyRegular]; | |
| 69 | ||
| 100 | 70 | //[NSBundle loadNibNamed:@"MainMenu" owner:NSApp ]; |
| 71 | //[[NSBundle mainBundle] loadNibNamed:@"MainMenu" owner:NSApp topLevelObjects:&topLevelObjects]; | |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
72 | |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
73 | ui_icon_init(); |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
74 | ui_toolbar_init(); |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
75 | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | } |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | |
| 100 | 78 | const char* ui_appname() { |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | return application_name; |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | } |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | |
|
108
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
82 | void ui_app_exit_on_shutdown(UiBool exitapp) { |
|
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
83 | exit_on_shutdown = exitapp; |
|
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
84 | } |
|
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
85 | |
| 100 | 86 | void ui_cocoa_onstartup(void) { |
| 87 | UiEvent e; | |
| 88 | e.obj = NULL; | |
| 89 | e.window = NULL; | |
| 90 | e.document = NULL; | |
| 91 | e.eventdata = NULL; | |
| 92 | e.intval = 0; | |
|
115
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
93 | uic_application_startup(&e); |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | } |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | |
| 100 | 96 | void ui_cocoa_onopen(const char *file) { |
| 97 | UiEvent e; | |
| 98 | e.obj = NULL; | |
| 99 | e.window = NULL; | |
| 100 | e.document = NULL; | |
| 101 | e.eventdata = NULL; | |
| 102 | e.intval = 0; | |
|
115
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
103 | uic_application_open(&e); |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | } |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | |
| 100 | 106 | void ui_cocoa_onexit(void) { |
| 107 | UiEvent e; | |
| 108 | e.obj = NULL; | |
| 109 | e.window = NULL; | |
| 110 | e.document = NULL; | |
| 111 | e.eventdata = NULL; | |
| 112 | e.intval = 0; | |
|
115
e57ca2747782
fix build with newest toolkit version
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
113 | uic_application_exit(&e); |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | } |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | |
| 100 | 116 | void ui_main(void) { |
| 117 | NSApplicationMain(app_argc, app_argv); | |
|
108
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
118 | if(exit_on_shutdown) { |
|
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
119 | exit(0); |
|
77254bd6dccb
update toolkit, adjust UI code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
120 | } |
| 100 | 121 | } |
| 122 | ||
| 123 | /* ------------------- Window Visibility functions ------------------- */ | |
| 124 | ||
| 125 | void ui_show(UiObject *obj) { | |
| 126 | if(obj->wobj) { | |
| 112 | 127 | id<UiToplevelObject> window = (__bridge id<UiToplevelObject>)obj->wobj; |
| 128 | ||
| 129 | if(![window getIsVisible]) { | |
| 130 | obj->ref++; | |
| 131 | } | |
| 132 | ||
| 133 | [window setVisible:YES]; | |
| 100 | 134 | } |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | } |
|
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | |
| 100 | 137 | void ui_close(UiObject *obj) { |
| 112 | 138 | // TODO: unref, window close, ... |
| 139 | if(obj->wobj) { | |
| 140 | id<UiToplevelObject> window = (__bridge id<UiToplevelObject>)obj->wobj; | |
| 141 | [window setVisible:NO]; | |
| 142 | } | |
| 100 | 143 | } |
| 144 | ||
| 145 | /* ------------------- Job Control / Threadpool functions ------------------- */ | |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | |
| 100 | 147 | void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd) { |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
148 | UiThread *thread = [[UiThread alloc]init:obj jobfunc:tf jobdata:td]; |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
149 | thread.finish_callback = f; |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
150 | thread.finish_userdata = fd; |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
151 | [thread start]; |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
152 | } |
|
0
2483f517c562
add existing toolkit code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
154 | @implementation UiAppCallback |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
155 | |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
156 | - (id) initWithCallback:(ui_threadfunc)func userdata:(void*)userdata { |
| 113 | 157 | _callback = func; |
| 158 | _userdata = userdata; | |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
159 | return self; |
| 100 | 160 | } |
| 161 | ||
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
162 | - (void) callMainThread { |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
163 | [self performSelectorOnMainThread:@selector(mainThread:) |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
164 | withObject:nil |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
165 | waitUntilDone:NO]; |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
166 | } |
| 100 | 167 | |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
168 | - (void) mainThread:(id)n { |
| 113 | 169 | if(_callback) { |
| 170 | _callback(_userdata); | |
| 171 | } | |
| 100 | 172 | } |
|
109
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
173 | |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
174 | @end |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
175 | |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
176 | void ui_call_mainthread(ui_threadfunc tf, void* td) { |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
177 | UiAppCallback *cb = [[UiAppCallback alloc]initWithCallback:tf userdata:td]; |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
178 | [cb callMainThread]; |
|
c3dfcb8f0be7
update toolkit, remove getvalue func from model to table/listview args
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
108
diff
changeset
|
179 | } |