ui/cocoa/toolkit.m

changeset 48
0b8ac9d6d473
parent 31
34df61c6ec3c
child 49
a80ba8741be6
equal deleted inserted replaced
47:97792f44d919 48:0b8ac9d6d473
30 #import <stdlib.h> 30 #import <stdlib.h>
31 #import <sys/stat.h> 31 #import <sys/stat.h>
32 #import <sys/types.h> 32 #import <sys/types.h>
33 #import <errno.h> 33 #import <errno.h>
34 34
35 #import "../common/context.h"
35 #import "../common/document.h" 36 #import "../common/document.h"
36 #import "../common/properties.h" 37 #import "../common/properties.h"
37 38
38 #import "toolkit.h" 39 #import "toolkit.h"
39 #import "window.h" 40 #import "window.h"
90 } else { 91 } else {
91 printf("Error: ui_show: Object is not a Window!\n"); 92 printf("Error: ui_show: Object is not a Window!\n");
92 } 93 }
93 } 94 }
94 95
96 void ui_set_show_all(UIWIDGET widget, int value) {
97 // TODO
98 }
99
100 void ui_set_visible(UIWIDGET widget, int visible) {
101 // TODO
102 }
103
95 void ui_set_enabled(UIWIDGET widget, int enabled) { 104 void ui_set_enabled(UIWIDGET widget, int enabled) {
96 [(id)widget setEnabled: enabled]; 105 [(id)widget setEnabled: enabled];
106 }
107
108
109
110 void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd) {
111 UiThread *thread = [[UiThread alloc]initWithObject:obj];
112 [thread setJobFunction:tf];
113 [thread setJobData:td];
114 [thread setFinishCallback:f];
115 [thread setFinishData:fd];
116 [thread start];
97 } 117 }
98 118
99 void ui_main() { 119 void ui_main() {
100 [NSApp run]; 120 [NSApp run];
101 [pool release]; 121 [pool release];
204 UiEvent event; 224 UiEvent event;
205 event.eventdata = NULL; 225 event.eventdata = NULL;
206 if([activeWindow class] == [UiCocoaWindow class]) { 226 if([activeWindow class] == [UiCocoaWindow class]) {
207 event.obj = [(UiCocoaWindow*)activeWindow object]; 227 event.obj = [(UiCocoaWindow*)activeWindow object];
208 event.window = event.obj->window; 228 event.window = event.obj->window;
209 event.document = event.obj->document; 229 event.document = event.obj->ctx->document;
210 event.intval = value; 230 event.intval = value;
211 } 231 }
212 if(callback) { 232 if(callback) {
213 callback(&event, data); 233 callback(&event, data);
214 } 234 }
225 event.intval = state; 245 event.intval = state;
226 event.eventdata = NULL; 246 event.eventdata = NULL;
227 if([activeWindow class] == [UiCocoaWindow class]) { 247 if([activeWindow class] == [UiCocoaWindow class]) {
228 event.obj = [(UiCocoaWindow*)activeWindow object]; 248 event.obj = [(UiCocoaWindow*)activeWindow object];
229 event.window = event.obj->window; 249 event.window = event.obj->window;
230 event.document = event.obj->document; 250 event.document = event.obj->ctx->document;
231 // update state in window data 251 // update state in window data
232 UiMenuItem *wmi = [(UiCocoaWindow*)activeWindow getMenuItem: sender]; 252 UiMenuItem *wmi = [(UiCocoaWindow*)activeWindow getMenuItem: sender];
233 wmi->state = state; 253 wmi->state = state;
234 } else { 254 } else {
235 event.window = NULL; 255 event.window = NULL;
243 return true; 263 return true;
244 } 264 }
245 265
246 @end 266 @end
247 267
248 268 @implementation UiThread
269
270 - (id) initWithObject:(UiObject*)object {
271 obj = object;
272 job_func = NULL;
273 job_data = NULL;
274 finish_callback = NULL;
275 finish_data = NULL;
276 return self;
277 }
278
279 - (void) setJobFunction:(ui_threadfunc)func {
280 job_func = func;
281 }
282
283 - (void) setJobData:(void*)data {
284 job_data = data;
285 }
286
287 - (void) setFinishCallback:(ui_callback)callback {
288 finish_callback = callback;
289 }
290
291 - (void) setFinishData:(void*)data {
292 finish_data = data;
293 }
294
295 - (void) start {
296 [NSThread detachNewThreadSelector:@selector(runJob:)
297 toTarget:self
298 withObject:nil];
299 }
300
301 - (void) runJob:(id)n {
302 int result = job_func(job_data);
303 if(!result) {
304 [self performSelectorOnMainThread:@selector(finish:)
305 withObject:nil
306 waitUntilDone:NO];
307 }
308 }
309
310 - (void) finish:(id)n {
311 UiEvent event;
312 event.obj = obj;
313 event.window = obj->window;
314 event.document = obj->ctx->document;
315 event.eventdata = NULL;
316 event.intval = 0;
317 finish_callback(&event, finish_data);
318 }
319
320 @end
321
322

mercurial