Mercurial > dwindows
comparison mac/dw.m @ 752:cf447811d322
Converted tabs to spaces.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 17 Mar 2011 04:48:06 +0000 |
parents | eba6ab48c952 |
children | 590eebc9b61f |
comparison
equal
deleted
inserted
replaced
751:eba6ab48c952 | 752:cf447811d322 |
---|---|
40 dw_mutex_unlock(DWThreadMutex); \ | 40 dw_mutex_unlock(DWThreadMutex); \ |
41 _locked_by_me = FALSE; } } | 41 _locked_by_me = FALSE; } } |
42 | 42 |
43 unsigned long _colors[] = | 43 unsigned long _colors[] = |
44 { | 44 { |
45 0x00000000, /* 0 black */ | 45 0x00000000, /* 0 black */ |
46 0x000000bb, /* 1 red */ | 46 0x000000bb, /* 1 red */ |
47 0x0000bb00, /* 2 green */ | 47 0x0000bb00, /* 2 green */ |
48 0x0000aaaa, /* 3 yellow */ | 48 0x0000aaaa, /* 3 yellow */ |
49 0x00cc0000, /* 4 blue */ | 49 0x00cc0000, /* 4 blue */ |
50 0x00bb00bb, /* 5 magenta */ | 50 0x00bb00bb, /* 5 magenta */ |
51 0x00bbbb00, /* 6 cyan */ | 51 0x00bbbb00, /* 6 cyan */ |
52 0x00bbbbbb, /* 7 white */ | 52 0x00bbbbbb, /* 7 white */ |
53 0x00777777, /* 8 grey */ | 53 0x00777777, /* 8 grey */ |
54 0x000000ff, /* 9 bright red */ | 54 0x000000ff, /* 9 bright red */ |
55 0x0000ff00, /* 10 bright green */ | 55 0x0000ff00, /* 10 bright green */ |
56 0x0000eeee, /* 11 bright yellow */ | 56 0x0000eeee, /* 11 bright yellow */ |
57 0x00ff0000, /* 12 bright blue */ | 57 0x00ff0000, /* 12 bright blue */ |
58 0x00ff00ff, /* 13 bright magenta */ | 58 0x00ff00ff, /* 13 bright magenta */ |
59 0x00eeee00, /* 14 bright cyan */ | 59 0x00eeee00, /* 14 bright cyan */ |
60 0x00ffffff, /* 15 bright white */ | 60 0x00ffffff, /* 15 bright white */ |
61 0xff000000 /* 16 default color */ | 61 0xff000000 /* 16 default color */ |
62 }; | 62 }; |
63 | 63 |
64 unsigned long _get_color(unsigned long thiscolor) | 64 unsigned long _get_color(unsigned long thiscolor) |
65 { | 65 { |
66 if(thiscolor & DW_RGB_COLOR) | 66 if(thiscolor & DW_RGB_COLOR) |
67 { | 67 { |
68 return thiscolor & ~DW_RGB_COLOR; | 68 return thiscolor & ~DW_RGB_COLOR; |
69 } | 69 } |
70 else if(thiscolor < 17) | 70 else if(thiscolor < 17) |
71 { | 71 { |
72 return _colors[thiscolor]; | 72 return _colors[thiscolor]; |
73 } | 73 } |
74 return 0; | 74 return 0; |
75 } | 75 } |
76 | 76 |
77 typedef struct _sighandler | 77 typedef struct _sighandler |
78 { | 78 { |
79 struct _sighandler *next; | 79 struct _sighandler *next; |
80 ULONG message; | 80 ULONG message; |
81 HWND window; | 81 HWND window; |
82 int id; | 82 int id; |
83 void *signalfunction; | 83 void *signalfunction; |
84 void *data; | 84 void *data; |
85 | 85 |
86 } SignalHandler; | 86 } SignalHandler; |
87 | 87 |
88 SignalHandler *Root = NULL; | 88 SignalHandler *Root = NULL; |
89 | 89 |
90 /* Some internal prototypes */ | 90 /* Some internal prototypes */ |
92 int _remove_userdata(UserData **root, char *varname, int all); | 92 int _remove_userdata(UserData **root, char *varname, int all); |
93 int _dw_main_iteration(NSDate *date); | 93 int _dw_main_iteration(NSDate *date); |
94 | 94 |
95 SignalHandler *_get_handler(HWND window, int messageid) | 95 SignalHandler *_get_handler(HWND window, int messageid) |
96 { | 96 { |
97 SignalHandler *tmp = Root; | 97 SignalHandler *tmp = Root; |
98 | 98 |
99 /* Find any callbacks for this function */ | 99 /* Find any callbacks for this function */ |
100 while(tmp) | 100 while(tmp) |
101 { | 101 { |
102 if(tmp->message == messageid && window == tmp->window) | 102 if(tmp->message == messageid && window == tmp->window) |
103 { | 103 { |
104 return tmp; | 104 return tmp; |
105 } | 105 } |
106 tmp = tmp->next; | 106 tmp = tmp->next; |
107 } | 107 } |
108 return NULL; | 108 return NULL; |
109 } | 109 } |
110 | 110 |
111 typedef struct | 111 typedef struct |
112 { | 112 { |
113 ULONG message; | 113 ULONG message; |
114 char name[30]; | 114 char name[30]; |
115 | 115 |
116 } SignalList; | 116 } SignalList; |
117 | 117 |
118 /* List of signals */ | 118 /* List of signals */ |
119 #define SIGNALMAX 16 | 119 #define SIGNALMAX 16 |
120 | 120 |
121 SignalList SignalTranslate[SIGNALMAX] = { | 121 SignalList SignalTranslate[SIGNALMAX] = { |
122 { 1, DW_SIGNAL_CONFIGURE }, | 122 { 1, DW_SIGNAL_CONFIGURE }, |
123 { 2, DW_SIGNAL_KEY_PRESS }, | 123 { 2, DW_SIGNAL_KEY_PRESS }, |
124 { 3, DW_SIGNAL_BUTTON_PRESS }, | 124 { 3, DW_SIGNAL_BUTTON_PRESS }, |
125 { 4, DW_SIGNAL_BUTTON_RELEASE }, | 125 { 4, DW_SIGNAL_BUTTON_RELEASE }, |
126 { 5, DW_SIGNAL_MOTION_NOTIFY }, | 126 { 5, DW_SIGNAL_MOTION_NOTIFY }, |
127 { 6, DW_SIGNAL_DELETE }, | 127 { 6, DW_SIGNAL_DELETE }, |
128 { 7, DW_SIGNAL_EXPOSE }, | 128 { 7, DW_SIGNAL_EXPOSE }, |
129 { 8, DW_SIGNAL_CLICKED }, | 129 { 8, DW_SIGNAL_CLICKED }, |
130 { 9, DW_SIGNAL_ITEM_ENTER }, | 130 { 9, DW_SIGNAL_ITEM_ENTER }, |
131 { 10, DW_SIGNAL_ITEM_CONTEXT }, | 131 { 10, DW_SIGNAL_ITEM_CONTEXT }, |
132 { 11, DW_SIGNAL_LIST_SELECT }, | 132 { 11, DW_SIGNAL_LIST_SELECT }, |
133 { 12, DW_SIGNAL_ITEM_SELECT }, | 133 { 12, DW_SIGNAL_ITEM_SELECT }, |
134 { 13, DW_SIGNAL_SET_FOCUS }, | 134 { 13, DW_SIGNAL_SET_FOCUS }, |
135 { 14, DW_SIGNAL_VALUE_CHANGED }, | 135 { 14, DW_SIGNAL_VALUE_CHANGED }, |
136 { 15, DW_SIGNAL_SWITCH_PAGE }, | 136 { 15, DW_SIGNAL_SWITCH_PAGE }, |
137 { 16, DW_SIGNAL_TREE_EXPAND } | 137 { 16, DW_SIGNAL_TREE_EXPAND } |
138 }; | 138 }; |
139 | 139 |
140 int _event_handler(id object, NSEvent *event, int message) | 140 int _event_handler(id object, NSEvent *event, int message) |
141 { | 141 { |
142 SignalHandler *handler = _get_handler(object, message); | 142 SignalHandler *handler = _get_handler(object, message); |
143 /* NSLog(@"Event handler - type %d\n", message); */ | 143 /* NSLog(@"Event handler - type %d\n", message); */ |
144 | 144 |
145 if(handler) | 145 if(handler) |
146 { | 146 { |
147 switch(message) | 147 switch(message) |
148 { | 148 { |
149 /* Timer event */ | 149 /* Timer event */ |
150 case 0: | 150 case 0: |
151 { | 151 { |
152 int (* API timerfunc)(void *) = (int (* API)(void *))handler->signalfunction; | 152 int (* API timerfunc)(void *) = (int (* API)(void *))handler->signalfunction; |
153 | 153 |
154 if(!timerfunc(handler->data)) | 154 if(!timerfunc(handler->data)) |
155 dw_timer_disconnect(handler->id); | 155 dw_timer_disconnect(handler->id); |
156 return 0; | 156 return 0; |
157 } | 157 } |
158 /* Configure/Resize event */ | 158 /* Configure/Resize event */ |
159 case 1: | 159 case 1: |
160 { | 160 { |
161 int (*sizefunc)(HWND, int, int, void *) = handler->signalfunction; | 161 int (*sizefunc)(HWND, int, int, void *) = handler->signalfunction; |
162 NSSize size; | 162 NSSize size; |
163 | 163 |
164 if([object isMemberOfClass:[NSWindow class]]) | 164 if([object isMemberOfClass:[NSWindow class]]) |
165 { | 165 { |
166 NSWindow *window = object; | 166 NSWindow *window = object; |
167 size = [[window contentView] frame].size; | 167 size = [[window contentView] frame].size; |
168 } | 168 } |
169 else | 169 else |
170 { | 170 { |
171 NSView *view = object; | 171 NSView *view = object; |
172 size = [view frame].size; | 172 size = [view frame].size; |
173 } | 173 } |
174 | 174 |
175 if(size.width > 0 && size.height > 0) | 175 if(size.width > 0 && size.height > 0) |
176 { | 176 { |
177 return sizefunc(object, size.width, size.height, handler->data); | 177 return sizefunc(object, size.width, size.height, handler->data); |
178 } | 178 } |
179 return 0; | 179 return 0; |
180 } | 180 } |
181 case 2: | 181 case 2: |
182 { | 182 { |
183 int (*keypressfunc)(HWND, char, int, int, void *) = handler->signalfunction; | 183 int (*keypressfunc)(HWND, char, int, int, void *) = handler->signalfunction; |
184 NSString *nchar = [event charactersIgnoringModifiers]; | 184 NSString *nchar = [event charactersIgnoringModifiers]; |
185 int special = (int)[event modifierFlags]; | 185 int special = (int)[event modifierFlags]; |
197 } | 197 } |
198 | 198 |
199 return keypressfunc(handler->window, ch, (int)vk, special, handler->data); | 199 return keypressfunc(handler->window, ch, (int)vk, special, handler->data); |
200 } | 200 } |
201 /* Button press and release event */ | 201 /* Button press and release event */ |
202 case 3: | 202 case 3: |
203 case 4: | 203 case 4: |
204 { | 204 { |
205 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; | 205 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; |
206 int button = (int)event; | 206 int button = (int)event; |
207 LONG x,y; | 207 LONG x,y; |
208 | 208 |
209 dw_pointer_query_pos(&x, &y); | 209 dw_pointer_query_pos(&x, &y); |
210 | 210 |
211 return buttonfunc(object, (int)x, (int)y, button, handler->data); | 211 return buttonfunc(object, (int)x, (int)y, button, handler->data); |
212 } | 212 } |
213 /* Window close event */ | 213 /* Window close event */ |
214 case 6: | 214 case 6: |
215 { | 215 { |
216 int (* API closefunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; | 216 int (* API closefunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; |
217 return closefunc(object, handler->data); | 217 return closefunc(object, handler->data); |
218 } | 218 } |
219 /* Window expose/draw event */ | 219 /* Window expose/draw event */ |
220 case 7: | 220 case 7: |
221 { | 221 { |
222 DWExpose exp; | 222 DWExpose exp; |
223 int (* API exposefunc)(HWND, DWExpose *, void *) = (int (* API)(HWND, DWExpose *, void *))handler->signalfunction; | 223 int (* API exposefunc)(HWND, DWExpose *, void *) = (int (* API)(HWND, DWExpose *, void *))handler->signalfunction; |
224 NSRect rect = [object frame]; | 224 NSRect rect = [object frame]; |
225 | 225 |
226 exp.x = rect.origin.x; | 226 exp.x = rect.origin.x; |
227 exp.y = rect.origin.y; | 227 exp.y = rect.origin.y; |
228 exp.width = rect.size.width; | 228 exp.width = rect.size.width; |
229 exp.height = rect.size.height; | 229 exp.height = rect.size.height; |
230 int result = exposefunc(object, &exp, handler->data); | 230 int result = exposefunc(object, &exp, handler->data); |
231 [[object window] flushWindow]; | 231 [[object window] flushWindow]; |
232 return result; | 232 return result; |
233 } | 233 } |
234 /* Clicked event for buttons and menu items */ | 234 /* Clicked event for buttons and menu items */ |
235 case 8: | 235 case 8: |
236 { | 236 { |
237 int (* API clickfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; | 237 int (* API clickfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; |
238 | 238 |
239 return clickfunc(object, handler->data); | 239 return clickfunc(object, handler->data); |
240 } | 240 } |
241 /* Container class selection event */ | 241 /* Container class selection event */ |
242 case 9: | 242 case 9: |
243 { | 243 { |
244 int (*containerselectfunc)(HWND, char *, void *) = handler->signalfunction; | 244 int (*containerselectfunc)(HWND, char *, void *) = handler->signalfunction; |
245 | 245 |
246 return containerselectfunc(handler->window, (char *)event, handler->data); | 246 return containerselectfunc(handler->window, (char *)event, handler->data); |
247 } | 247 } |
248 /* Container context menu event */ | 248 /* Container context menu event */ |
249 case 10: | 249 case 10: |
250 { | 250 { |
251 int (* API containercontextfunc)(HWND, char *, int, int, void *, void *) = (int (* API)(HWND, char *, int, int, void *, void *))handler->signalfunction; | 251 int (* API containercontextfunc)(HWND, char *, int, int, void *, void *) = (int (* API)(HWND, char *, int, int, void *, void *))handler->signalfunction; |
252 char *text = (char *)event; | 252 char *text = (char *)event; |
253 void *user = NULL; | 253 void *user = NULL; |
254 LONG x,y; | 254 LONG x,y; |
255 | 255 |
256 dw_pointer_query_pos(&x, &y); | 256 dw_pointer_query_pos(&x, &y); |
257 | 257 |
258 return containercontextfunc(handler->window, text, (int)x, (int)y, handler->data, user); | 258 return containercontextfunc(handler->window, text, (int)x, (int)y, handler->data, user); |
259 } | 259 } |
260 /* Generic selection changed event for several classes */ | 260 /* Generic selection changed event for several classes */ |
261 case 11: | 261 case 11: |
262 case 14: | 262 case 14: |
263 { | 263 { |
264 int (* API valuechangedfunc)(HWND, int, void *) = (int (* API)(HWND, int, void *))handler->signalfunction; | 264 int (* API valuechangedfunc)(HWND, int, void *) = (int (* API)(HWND, int, void *))handler->signalfunction; |
265 int selected = (int)event; | 265 int selected = (int)event; |
266 | 266 |
267 return valuechangedfunc(handler->window, selected, handler->data);; | 267 return valuechangedfunc(handler->window, selected, handler->data);; |
268 } | 268 } |
269 /* Tree class selection event */ | 269 /* Tree class selection event */ |
270 case 12: | 270 case 12: |
271 { | 271 { |
272 int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction; | 272 int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction; |
273 char *text = (char *)event; | 273 char *text = (char *)event; |
274 void *user = NULL; | 274 void *user = NULL; |
275 id item = nil; | 275 id item = nil; |
276 | 276 |
293 { | 293 { |
294 free(text); | 294 free(text); |
295 } | 295 } |
296 return result; | 296 return result; |
297 } | 297 } |
298 | 298 |
299 return treeselectfunc(handler->window, item, text, handler->data, user); | 299 return treeselectfunc(handler->window, item, text, handler->data, user); |
300 } | 300 } |
301 /* Set Focus event */ | 301 /* Set Focus event */ |
302 case 13: | 302 case 13: |
303 { | 303 { |
304 int (* API setfocusfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; | 304 int (* API setfocusfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; |
305 | 305 |
317 { | 317 { |
318 int (* API treeexpandfunc)(HWND, HTREEITEM, void *) = (int (* API)(HWND, HTREEITEM, void *))handler->signalfunction; | 318 int (* API treeexpandfunc)(HWND, HTREEITEM, void *) = (int (* API)(HWND, HTREEITEM, void *))handler->signalfunction; |
319 | 319 |
320 return treeexpandfunc(handler->window, (HTREEITEM)event, handler->data); | 320 return treeexpandfunc(handler->window, (HTREEITEM)event, handler->data); |
321 } | 321 } |
322 } | 322 } |
323 } | 323 } |
324 return -1; | 324 return -1; |
325 } | 325 } |
326 | 326 |
327 /* Subclass for the Timer type */ | 327 /* Subclass for the Timer type */ |
328 @interface DWTimerHandler : NSObject { } | 328 @interface DWTimerHandler : NSObject { } |
329 -(void)runTimer:(id)sender; | 329 -(void)runTimer:(id)sender; |
407 [bltdest unlockFocus]; | 407 [bltdest unlockFocus]; |
408 free(bltinfo); | 408 free(bltinfo); |
409 } | 409 } |
410 -(void)doFlush:(id)param | 410 -(void)doFlush:(id)param |
411 { | 411 { |
412 if(_DWLastDrawable) | 412 if(_DWLastDrawable) |
413 { | 413 { |
414 id object = _DWLastDrawable; | 414 id object = _DWLastDrawable; |
415 NSWindow *window = [object window]; | 415 NSWindow *window = [object window]; |
416 [window flushWindow]; | 416 [window flushWindow]; |
417 } | 417 } |
418 } | 418 } |
419 -(void)doWindowFunc:(id)param | 419 -(void)doWindowFunc:(id)param |
420 { | 420 { |
421 NSValue *v = (NSValue *)param; | 421 NSValue *v = (NSValue *)param; |
422 void **params = (void **)[v pointerValue]; | 422 void **params = (void **)[v pointerValue]; |
423 void (* windowfunc)(void *); | 423 void (* windowfunc)(void *); |
424 | 424 |
425 if(params) | 425 if(params) |
426 { | 426 { |
427 windowfunc = params[0]; | 427 windowfunc = params[0]; |
428 if(windowfunc) | 428 if(windowfunc) |
429 { | 429 { |
430 windowfunc(params[1]); | 430 windowfunc(params[1]); |
431 } | 431 } |
432 } | 432 } |
433 } | 433 } |
434 @end | 434 @end |
435 | 435 |
436 DWObject *DWObj; | 436 DWObject *DWObj; |
437 | 437 |
447 @interface DWBox : NSView | 447 @interface DWBox : NSView |
448 #ifdef BUILDING_FOR_SNOW_LEOPARD | 448 #ifdef BUILDING_FOR_SNOW_LEOPARD |
449 <NSWindowDelegate> | 449 <NSWindowDelegate> |
450 #endif | 450 #endif |
451 { | 451 { |
452 Box *box; | 452 Box *box; |
453 void *userdata; | 453 void *userdata; |
454 NSColor *bgcolor; | 454 NSColor *bgcolor; |
455 } | 455 } |
456 -(id)init; | 456 -(id)init; |
457 -(void)dealloc; | 457 -(void)dealloc; |
458 -(Box *)box; | 458 -(Box *)box; |
459 -(void *)userdata; | 459 -(void *)userdata; |
491 -(Box *)box { return box; } | 491 -(Box *)box { return box; } |
492 -(void *)userdata { return userdata; } | 492 -(void *)userdata { return userdata; } |
493 -(void)setUserdata:(void *)input { userdata = input; } | 493 -(void)setUserdata:(void *)input { userdata = input; } |
494 -(void)drawRect:(NSRect)rect | 494 -(void)drawRect:(NSRect)rect |
495 { | 495 { |
496 if(bgcolor) | 496 if(bgcolor) |
497 { | 497 { |
498 [bgcolor set]; | 498 [bgcolor set]; |
499 NSRectFill( [self bounds] ); | 499 NSRectFill( [self bounds] ); |
500 } | 500 } |
501 } | 501 } |
502 -(BOOL)isFlipped { return YES; } | 502 -(BOOL)isFlipped { return YES; } |
503 -(void)mouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)1, 3); } | 503 -(void)mouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)1, 3); } |
504 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)1, 4); } | 504 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)1, 4); } |
505 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } | 505 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } |
507 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); } | 507 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); } |
508 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); } | 508 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); } |
509 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); } | 509 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); } |
510 -(void)setColor:(unsigned long)input | 510 -(void)setColor:(unsigned long)input |
511 { | 511 { |
512 if(input == _colors[DW_CLR_DEFAULT]) | 512 if(input == _colors[DW_CLR_DEFAULT]) |
513 { | 513 { |
514 bgcolor = nil; | 514 bgcolor = nil; |
515 } | 515 } |
516 else | 516 else |
517 { | 517 { |
518 bgcolor = [NSColor colorWithDeviceRed: DW_RED_VALUE(input)/255.0 green: DW_GREEN_VALUE(input)/255.0 blue: DW_BLUE_VALUE(input)/255.0 alpha: 1]; | 518 bgcolor = [NSColor colorWithDeviceRed: DW_RED_VALUE(input)/255.0 green: DW_GREEN_VALUE(input)/255.0 blue: DW_BLUE_VALUE(input)/255.0 alpha: 1]; |
519 } | 519 } |
520 } | 520 } |
521 @end | 521 @end |
522 | 522 |
523 /* Subclass for a top-level window */ | 523 /* Subclass for a top-level window */ |
524 @interface DWView : DWBox | 524 @interface DWView : DWBox |
525 { | 525 { |
526 NSMenu *windowmenu; | 526 NSMenu *windowmenu; |
527 } | 527 } |
528 -(BOOL)windowShouldClose:(id)sender; | 528 -(BOOL)windowShouldClose:(id)sender; |
529 -(void)setMenu:(NSMenu *)input; | 529 -(void)setMenu:(NSMenu *)input; |
530 -(void)windowDidBecomeMain:(id)sender; | 530 -(void)windowDidBecomeMain:(id)sender; |
531 -(void)menuHandler:(id)sender; | 531 -(void)menuHandler:(id)sender; |
534 | 534 |
535 @implementation DWView | 535 @implementation DWView |
536 -(BOOL)windowShouldClose:(id)sender | 536 -(BOOL)windowShouldClose:(id)sender |
537 { | 537 { |
538 if(_event_handler(self, nil, 6) == FALSE) | 538 if(_event_handler(self, nil, 6) == FALSE) |
539 return NO; | 539 return NO; |
540 return YES; | 540 return YES; |
541 } | 541 } |
542 - (void)viewDidMoveToWindow | 542 - (void)viewDidMoveToWindow |
543 { | 543 { |
544 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]]; | 544 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]]; |
545 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:NSWindowDidBecomeMainNotification object:[self window]]; | 545 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:NSWindowDidBecomeMainNotification object:[self window]]; |
546 } | 546 } |
547 - (void)dealloc | 547 - (void)dealloc |
548 { | 548 { |
549 if(windowmenu) | 549 if(windowmenu) |
550 { | 550 { |
553 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 553 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
554 [super dealloc]; | 554 [super dealloc]; |
555 } | 555 } |
556 - (void)windowResized:(NSNotification *)notification; | 556 - (void)windowResized:(NSNotification *)notification; |
557 { | 557 { |
558 NSSize size = [self frame].size; | 558 NSSize size = [self frame].size; |
559 _do_resize(box, size.width, size.height); | 559 _do_resize(box, size.width, size.height); |
560 _event_handler([self window], nil, 1); | 560 _event_handler([self window], nil, 1); |
561 } | 561 } |
562 -(void)windowDidBecomeMain:(id)sender | 562 -(void)windowDidBecomeMain:(id)sender |
563 { | 563 { |
564 if(windowmenu) | 564 if(windowmenu) |
565 { | 565 { |
566 [DWApp setMainMenu:windowmenu]; | 566 [DWApp setMainMenu:windowmenu]; |
567 } | 567 } |
568 else | 568 else |
569 { | 569 { |
570 [DWApp setMainMenu:DWMainMenu]; | 570 [DWApp setMainMenu:DWMainMenu]; |
571 } | 571 } |
572 _event_handler(self, nil, 13); | 572 _event_handler(self, nil, 13); |
573 } | 573 } |
574 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; } | 574 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; } |
575 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); } | 575 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); } |
576 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); } | 576 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); } |
577 @end | 577 @end |
578 | 578 |
579 /* Subclass for a button type */ | 579 /* Subclass for a button type */ |
580 @interface DWButton : NSButton | 580 @interface DWButton : NSButton |
581 { | 581 { |
582 void *userdata; | 582 void *userdata; |
583 } | 583 } |
584 -(void *)userdata; | 584 -(void *)userdata; |
585 -(void)setUserdata:(void *)input; | 585 -(void)setUserdata:(void *)input; |
586 -(void)buttonClicked:(id)sender; | 586 -(void)buttonClicked:(id)sender; |
587 @end | 587 @end |
594 @end | 594 @end |
595 | 595 |
596 /* Subclass for a progress type */ | 596 /* Subclass for a progress type */ |
597 @interface DWPercent : NSProgressIndicator | 597 @interface DWPercent : NSProgressIndicator |
598 { | 598 { |
599 void *userdata; | 599 void *userdata; |
600 } | 600 } |
601 -(void *)userdata; | 601 -(void *)userdata; |
602 -(void)setUserdata:(void *)input; | 602 -(void)setUserdata:(void *)input; |
603 @end | 603 @end |
604 | 604 |
609 @end | 609 @end |
610 | 610 |
611 /* Subclass for a entryfield type */ | 611 /* Subclass for a entryfield type */ |
612 @interface DWEntryField : NSTextField | 612 @interface DWEntryField : NSTextField |
613 { | 613 { |
614 void *userdata; | 614 void *userdata; |
615 } | 615 } |
616 -(void *)userdata; | 616 -(void *)userdata; |
617 -(void)setUserdata:(void *)input; | 617 -(void)setUserdata:(void *)input; |
618 @end | 618 @end |
619 | 619 |
624 @end | 624 @end |
625 | 625 |
626 /* Subclass for a entryfield password type */ | 626 /* Subclass for a entryfield password type */ |
627 @interface DWEntryFieldPassword : NSSecureTextField | 627 @interface DWEntryFieldPassword : NSSecureTextField |
628 { | 628 { |
629 void *userdata; | 629 void *userdata; |
630 } | 630 } |
631 -(void *)userdata; | 631 -(void *)userdata; |
632 -(void)setUserdata:(void *)input; | 632 -(void)setUserdata:(void *)input; |
633 @end | 633 @end |
634 | 634 |
642 @interface DWNotebook : NSTabView | 642 @interface DWNotebook : NSTabView |
643 #ifdef BUILDING_FOR_SNOW_LEOPARD | 643 #ifdef BUILDING_FOR_SNOW_LEOPARD |
644 <NSTabViewDelegate> | 644 <NSTabViewDelegate> |
645 #endif | 645 #endif |
646 { | 646 { |
647 void *userdata; | 647 void *userdata; |
648 int pageid; | 648 int pageid; |
649 } | 649 } |
650 -(void *)userdata; | 650 -(void *)userdata; |
651 -(void)setUserdata:(void *)input; | 651 -(void)setUserdata:(void *)input; |
652 -(int)pageid; | 652 -(int)pageid; |
653 -(void)setPageid:(int)input; | 653 -(void)setPageid:(int)input; |
655 @end | 655 @end |
656 | 656 |
657 /* Subclass for a Notebook page type */ | 657 /* Subclass for a Notebook page type */ |
658 @interface DWNotebookPage : NSTabViewItem | 658 @interface DWNotebookPage : NSTabViewItem |
659 { | 659 { |
660 void *userdata; | 660 void *userdata; |
661 int pageid; | 661 int pageid; |
662 } | 662 } |
663 -(void *)userdata; | 663 -(void *)userdata; |
664 -(void)setUserdata:(void *)input; | 664 -(void)setUserdata:(void *)input; |
665 -(int)pageid; | 665 -(int)pageid; |
666 -(void)setPageid:(int)input; | 666 -(void)setPageid:(int)input; |
671 -(void)setUserdata:(void *)input { userdata = input; } | 671 -(void)setUserdata:(void *)input { userdata = input; } |
672 -(int)pageid { return pageid; } | 672 -(int)pageid { return pageid; } |
673 -(void)setPageid:(int)input { pageid = input; } | 673 -(void)setPageid:(int)input { pageid = input; } |
674 -(void)tabView:(NSTabView *)notebook didSelectTabViewItem:(NSTabViewItem *)notepage | 674 -(void)tabView:(NSTabView *)notebook didSelectTabViewItem:(NSTabViewItem *)notepage |
675 { | 675 { |
676 id object = [notepage view]; | 676 id object = [notepage view]; |
677 DWNotebookPage *page = (DWNotebookPage *)notepage; | 677 DWNotebookPage *page = (DWNotebookPage *)notepage; |
678 | 678 |
679 if([object isMemberOfClass:[DWBox class]]) | 679 if([object isMemberOfClass:[DWBox class]]) |
680 { | 680 { |
681 DWBox *view = object; | 681 DWBox *view = object; |
682 Box *box = [view box]; | 682 Box *box = [view box]; |
683 NSSize size = [view frame].size; | 683 NSSize size = [view frame].size; |
684 _do_resize(box, size.width, size.height); | 684 _do_resize(box, size.width, size.height); |
685 } | 685 } |
686 _event_handler(self, (void *)[page pageid], 15); | 686 _event_handler(self, (void *)[page pageid], 15); |
687 } | 687 } |
688 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 688 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
689 @end | 689 @end |
690 | 690 |
691 @implementation DWNotebookPage | 691 @implementation DWNotebookPage |
692 -(void *)userdata { return userdata; } | 692 -(void *)userdata { return userdata; } |
697 @end | 697 @end |
698 | 698 |
699 /* Subclass for a color chooser type */ | 699 /* Subclass for a color chooser type */ |
700 @interface DWColorChoose : NSColorPanel | 700 @interface DWColorChoose : NSColorPanel |
701 { | 701 { |
702 DWDialog *dialog; | 702 DWDialog *dialog; |
703 NSColor *pickedcolor; | 703 NSColor *pickedcolor; |
704 } | 704 } |
705 -(void)changeColor:(id)sender; | 705 -(void)changeColor:(id)sender; |
706 -(void)setDialog:(DWDialog *)input; | 706 -(void)setDialog:(DWDialog *)input; |
707 -(DWDialog *)dialog; | 707 -(DWDialog *)dialog; |
718 @interface DWSplitBar : NSSplitView | 718 @interface DWSplitBar : NSSplitView |
719 #ifdef BUILDING_FOR_SNOW_LEOPARD | 719 #ifdef BUILDING_FOR_SNOW_LEOPARD |
720 <NSSplitViewDelegate> | 720 <NSSplitViewDelegate> |
721 #endif | 721 #endif |
722 { | 722 { |
723 void *userdata; | 723 void *userdata; |
724 float percent; | 724 float percent; |
725 } | 725 } |
726 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification; | 726 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification; |
727 -(void *)userdata; | 727 -(void *)userdata; |
728 -(void)setUserdata:(void *)input; | 728 -(void)setUserdata:(void *)input; |
731 @end | 731 @end |
732 | 732 |
733 @implementation DWSplitBar | 733 @implementation DWSplitBar |
734 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification | 734 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification |
735 { | 735 { |
736 NSArray *views = [self subviews]; | 736 NSArray *views = [self subviews]; |
737 id object; | 737 id object; |
738 | 738 |
739 for(object in views) | 739 for(object in views) |
740 { | 740 { |
741 if([object isMemberOfClass:[DWBox class]]) | 741 if([object isMemberOfClass:[DWBox class]]) |
742 { | 742 { |
743 DWBox *view = object; | 743 DWBox *view = object; |
744 Box *box = [view box]; | 744 Box *box = [view box]; |
745 NSSize size = [view frame].size; | 745 NSSize size = [view frame].size; |
746 _do_resize(box, size.width, size.height); | 746 _do_resize(box, size.width, size.height); |
747 } | 747 } |
748 } | 748 } |
749 } | 749 } |
750 -(void *)userdata { return userdata; } | 750 -(void *)userdata { return userdata; } |
751 -(void)setUserdata:(void *)input { userdata = input; } | 751 -(void)setUserdata:(void *)input { userdata = input; } |
752 -(float)percent { return percent; } | 752 -(float)percent { return percent; } |
753 -(void)setPercent:(float)input { percent = input; } | 753 -(void)setPercent:(float)input { percent = input; } |
755 @end | 755 @end |
756 | 756 |
757 /* Subclass for a slider type */ | 757 /* Subclass for a slider type */ |
758 @interface DWSlider : NSSlider | 758 @interface DWSlider : NSSlider |
759 { | 759 { |
760 void *userdata; | 760 void *userdata; |
761 } | 761 } |
762 -(void *)userdata; | 762 -(void *)userdata; |
763 -(void)setUserdata:(void *)input; | 763 -(void)setUserdata:(void *)input; |
764 -(void)sliderChanged:(id)sender; | 764 -(void)sliderChanged:(id)sender; |
765 @end | 765 @end |
772 @end | 772 @end |
773 | 773 |
774 /* Subclass for a slider type */ | 774 /* Subclass for a slider type */ |
775 @interface DWScrollbar : NSScroller | 775 @interface DWScrollbar : NSScroller |
776 { | 776 { |
777 void *userdata; | 777 void *userdata; |
778 float range; | 778 float range; |
779 float visible; | 779 float visible; |
780 } | 780 } |
781 -(void *)userdata; | 781 -(void *)userdata; |
782 -(void)setUserdata:(void *)input; | 782 -(void)setUserdata:(void *)input; |
783 -(float)range; | 783 -(float)range; |
784 -(float)visible; | 784 -(float)visible; |
847 @end | 847 @end |
848 | 848 |
849 /* Subclass for a render area type */ | 849 /* Subclass for a render area type */ |
850 @interface DWRender : NSView | 850 @interface DWRender : NSView |
851 { | 851 { |
852 void *userdata; | 852 void *userdata; |
853 NSFont *font; | 853 NSFont *font; |
854 } | 854 } |
855 -(void *)userdata; | 855 -(void *)userdata; |
856 -(void)setUserdata:(void *)input; | 856 -(void)setUserdata:(void *)input; |
857 -(void)setFont:(NSFont *)input; | 857 -(void)setFont:(NSFont *)input; |
885 @end | 885 @end |
886 | 886 |
887 /* Subclass for a MLE type */ | 887 /* Subclass for a MLE type */ |
888 @interface DWMLE : NSTextView | 888 @interface DWMLE : NSTextView |
889 { | 889 { |
890 void *userdata; | 890 void *userdata; |
891 } | 891 } |
892 -(void *)userdata; | 892 -(void *)userdata; |
893 -(void)setUserdata:(void *)input; | 893 -(void)setUserdata:(void *)input; |
894 @end | 894 @end |
895 | 895 |
903 @interface DWContainer : NSTableView | 903 @interface DWContainer : NSTableView |
904 #ifdef BUILDING_FOR_SNOW_LEOPARD | 904 #ifdef BUILDING_FOR_SNOW_LEOPARD |
905 <NSTableViewDataSource> | 905 <NSTableViewDataSource> |
906 #endif | 906 #endif |
907 { | 907 { |
908 void *userdata; | 908 void *userdata; |
909 NSMutableArray *tvcols; | 909 NSMutableArray *tvcols; |
910 NSMutableArray *data; | 910 NSMutableArray *data; |
911 NSMutableArray *types; | 911 NSMutableArray *types; |
912 NSPointerArray *titles; | 912 NSPointerArray *titles; |
913 int lastAddPoint, lastQueryPoint; | 913 int lastAddPoint, lastQueryPoint; |
914 id scrollview; | 914 id scrollview; |
915 } | 915 } |
916 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable; | 916 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable; |
917 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow; | 917 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow; |
918 -(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex; | 918 -(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex; |
941 @end | 941 @end |
942 | 942 |
943 @implementation DWContainer | 943 @implementation DWContainer |
944 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable | 944 -(NSInteger)numberOfRowsInTableView:(NSTableView *)aTable |
945 { | 945 { |
946 if(tvcols && data) | 946 if(tvcols && data) |
947 { | 947 { |
948 int cols = (int)[tvcols count]; | 948 int cols = (int)[tvcols count]; |
949 if(cols) | 949 if(cols) |
950 { | 950 { |
951 return [data count] / cols; | 951 return [data count] / cols; |
952 } | 952 } |
953 } | 953 } |
954 return 0; | 954 return 0; |
955 } | 955 } |
956 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow | 956 -(id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(NSInteger)aRow |
957 { | 957 { |
958 if(tvcols) | 958 if(tvcols) |
959 { | 959 { |
960 int z, col = -1; | 960 int z, col = -1; |
961 int count = (int)[tvcols count]; | 961 int count = (int)[tvcols count]; |
962 | 962 |
963 for(z=0;z<count;z++) | 963 for(z=0;z<count;z++) |
964 { | 964 { |
965 if([tvcols objectAtIndex:z] == aCol) | 965 if([tvcols objectAtIndex:z] == aCol) |
966 { | 966 { |
967 col = z; | 967 col = z; |
968 break; | 968 break; |
969 } | 969 } |
970 } | 970 } |
971 if(col != -1) | 971 if(col != -1) |
972 { | 972 { |
973 int index = (int)(aRow * count) + col; | 973 int index = (int)(aRow * count) + col; |
974 id this = [data objectAtIndex:index]; | 974 id this = [data objectAtIndex:index]; |
975 return ([this isKindOfClass:[NSNull class]]) ? nil : this; | 975 return ([this isKindOfClass:[NSNull class]]) ? nil : this; |
976 } | 976 } |
977 } | 977 } |
978 return nil; | 978 return nil; |
979 } | 979 } |
980 -(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return NO; } | 980 -(BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return NO; } |
981 -(void *)userdata { return userdata; } | 981 -(void *)userdata { return userdata; } |
982 -(void)setUserdata:(void *)input { userdata = input; } | 982 -(void)setUserdata:(void *)input { userdata = input; } |
983 -(id)scrollview { return scrollview; } | 983 -(id)scrollview { return scrollview; } |
1012 } | 1012 } |
1013 return 0; | 1013 return 0; |
1014 } | 1014 } |
1015 -(int)addRows:(int)number | 1015 -(int)addRows:(int)number |
1016 { | 1016 { |
1017 if(tvcols) | 1017 if(tvcols) |
1018 { | 1018 { |
1019 int count = (int)(number * [tvcols count]); | 1019 int count = (int)(number * [tvcols count]); |
1020 int z; | 1020 int z; |
1021 | 1021 |
1022 lastAddPoint = (int)[titles count]; | 1022 lastAddPoint = (int)[titles count]; |
1023 | 1023 |
1024 for(z=0;z<count;z++) | 1024 for(z=0;z<count;z++) |
1025 { | 1025 { |
1026 [data addObject:[NSNull null]]; | 1026 [data addObject:[NSNull null]]; |
1027 } | 1027 } |
1028 for(z=0;z<number;z++) | 1028 for(z=0;z<number;z++) |
1029 { | 1029 { |
1030 [titles addPointer:NULL]; | 1030 [titles addPointer:NULL]; |
1031 } | 1031 } |
1032 return (int)[titles count]; | 1032 return (int)[titles count]; |
1033 } | 1033 } |
1034 return 0; | 1034 return 0; |
1035 } | 1035 } |
1036 -(void)editCell:(id)input at:(int)row and:(int)col | 1036 -(void)editCell:(id)input at:(int)row and:(int)col |
1037 { | 1037 { |
1038 if(tvcols && input) | 1038 if(tvcols && input) |
1039 { | 1039 { |
1040 int index = (int)(row * [tvcols count]) + col; | 1040 int index = (int)(row * [tvcols count]) + col; |
1041 [data replaceObjectAtIndex:index withObject:input]; | 1041 [data replaceObjectAtIndex:index withObject:input]; |
1042 } | 1042 } |
1043 } | 1043 } |
1044 -(void)removeRow:(int)row | 1044 -(void)removeRow:(int)row |
1045 { | 1045 { |
1046 if(tvcols) | 1046 if(tvcols) |
1047 { | 1047 { |
1048 int z, start, end; | 1048 int z, start, end; |
1049 int count = (int)[tvcols count]; | 1049 int count = (int)[tvcols count]; |
1050 | 1050 |
1051 start = count * row; | 1051 start = count * row; |
1052 end = start + count; | 1052 end = start + count; |
1053 | 1053 |
1054 for(z=start;z<end;z++) | 1054 for(z=start;z<end;z++) |
1055 { | 1055 { |
1056 [data removeObjectAtIndex:z]; | 1056 [data removeObjectAtIndex:z]; |
1057 } | 1057 } |
1058 [titles removePointerAtIndex:row]; | 1058 [titles removePointerAtIndex:row]; |
1059 if(lastAddPoint > 0 && lastAddPoint < row) | 1059 if(lastAddPoint > 0 && lastAddPoint < row) |
1060 { | 1060 { |
1061 lastAddPoint--; | 1061 lastAddPoint--; |
1062 } | 1062 } |
1063 } | 1063 } |
1064 } | 1064 } |
1065 -(void)setRow:(int)row title:(void *)input { if(titles && input) { [titles replacePointerAtIndex:row withPointer:input]; } } | 1065 -(void)setRow:(int)row title:(void *)input { if(titles && input) { [titles replacePointerAtIndex:row withPointer:input]; } } |
1066 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; } | 1066 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; } |
1067 -(id)getRow:(int)row and:(int)col { if(data) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; } | 1067 -(id)getRow:(int)row and:(int)col { if(data) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; } |
1068 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } | 1068 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } |
1070 -(int)lastQueryPoint { return lastQueryPoint; } | 1070 -(int)lastQueryPoint { return lastQueryPoint; } |
1071 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } | 1071 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } |
1072 -(void)clear { if(data) { [data removeAllObjects]; while([titles count]) { [titles removePointerAtIndex:0]; } } lastAddPoint = 0; } | 1072 -(void)clear { if(data) { [data removeAllObjects]; while([titles count]) { [titles removePointerAtIndex:0]; } } lastAddPoint = 0; } |
1073 -(void)setup | 1073 -(void)setup |
1074 { | 1074 { |
1075 tvcols = [[[NSMutableArray alloc] init] retain]; | 1075 tvcols = [[[NSMutableArray alloc] init] retain]; |
1076 data = [[[NSMutableArray alloc] init] retain]; | 1076 data = [[[NSMutableArray alloc] init] retain]; |
1077 types = [[[NSMutableArray alloc] init] retain]; | 1077 types = [[[NSMutableArray alloc] init] retain]; |
1078 titles = [[NSPointerArray pointerArrayWithWeakObjects] retain]; | 1078 titles = [[NSPointerArray pointerArrayWithWeakObjects] retain]; |
1079 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:self]; | 1079 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:self]; |
1080 } | 1080 } |
1081 -(void)doubleClicked:(id)sender | 1081 -(void)doubleClicked:(id)sender |
1082 { | 1082 { |
1083 /* Handler for container class */ | 1083 /* Handler for container class */ |
1084 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 9); | 1084 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 9); |
1085 } | 1085 } |
1086 -(void)selectionChanged:(id)sender | 1086 -(void)selectionChanged:(id)sender |
1087 { | 1087 { |
1088 /* Handler for container class */ | 1088 /* Handler for container class */ |
1089 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 12); | 1089 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 12); |
1090 /* Handler for listbox class */ | 1090 /* Handler for listbox class */ |
1091 _event_handler(self, (NSEvent *)(int)[self selectedRow], 11); | 1091 _event_handler(self, (NSEvent *)(int)[self selectedRow], 11); |
1092 } | 1092 } |
1093 -(NSMenu *)menuForEvent:(NSEvent *)event | 1093 -(NSMenu *)menuForEvent:(NSEvent *)event |
1094 { | 1094 { |
1095 int row; | 1095 int row; |
1096 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; | 1096 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; |
1137 @interface DWTree : NSOutlineView | 1137 @interface DWTree : NSOutlineView |
1138 #ifdef BUILDING_FOR_SNOW_LEOPARD | 1138 #ifdef BUILDING_FOR_SNOW_LEOPARD |
1139 <NSOutlineViewDataSource> | 1139 <NSOutlineViewDataSource> |
1140 #endif | 1140 #endif |
1141 { | 1141 { |
1142 void *userdata; | 1142 void *userdata; |
1143 NSTableColumn *imagecol; | 1143 NSTableColumn *imagecol; |
1144 NSTableColumn *textcol; | 1144 NSTableColumn *textcol; |
1145 NSMutableArray *data; | 1145 NSMutableArray *data; |
1146 /* Each data item consists of a linked lists of tree item data. | 1146 /* Each data item consists of a linked lists of tree item data. |
1147 * NSImage *, NSString *, Item Data *, NSMutableArray * of Children | 1147 * NSImage *, NSString *, Item Data *, NSMutableArray * of Children |
1148 */ | 1148 */ |
1149 id scrollview; | 1149 id scrollview; |
1150 } | 1150 } |
1185 } | 1185 } |
1186 return self; | 1186 return self; |
1187 } | 1187 } |
1188 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item | 1188 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item |
1189 { | 1189 { |
1190 if(item) | 1190 if(item) |
1191 { | 1191 { |
1192 NSMutableArray *array = [item pointerAtIndex:3]; | 1192 NSMutableArray *array = [item pointerAtIndex:3]; |
1193 return array ? [array objectAtIndex:index] : nil; | 1193 return array ? [array objectAtIndex:index] : nil; |
1194 } | 1194 } |
1195 else | 1195 else |
1196 { | 1196 { |
1197 return [data objectAtIndex:index]; | 1197 return [data objectAtIndex:index]; |
1198 } | 1198 } |
1199 } | 1199 } |
1200 -(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item | 1200 -(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item |
1201 { | 1201 { |
1202 return [self outlineView:outlineView numberOfChildrenOfItem:item] != 0; | 1202 return [self outlineView:outlineView numberOfChildrenOfItem:item] != 0; |
1203 } | 1203 } |
1204 -(int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item | 1204 -(int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item |
1205 { | 1205 { |
1206 if(item) | 1206 if(item) |
1207 { | 1207 { |
1208 if([item isKindOfClass:[NSPointerArray class]]) | 1208 if([item isKindOfClass:[NSPointerArray class]]) |
1209 { | 1209 { |
1210 NSMutableArray *array = [item pointerAtIndex:3]; | 1210 NSMutableArray *array = [item pointerAtIndex:3]; |
1211 return array ? (int)[array count] : 0; | 1211 return array ? (int)[array count] : 0; |
1212 } | 1212 } |
1213 else | 1213 else |
1214 { | 1214 { |
1215 return 0; | 1215 return 0; |
1216 } | 1216 } |
1217 } | 1217 } |
1218 else | 1218 else |
1219 { | 1219 { |
1220 return data ? (int)[data count] : 0; | 1220 return data ? (int)[data count] : 0; |
1221 } | 1221 } |
1222 } | 1222 } |
1223 -(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item | 1223 -(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item |
1224 { | 1224 { |
1225 if(item) | 1225 if(item) |
1226 { | 1226 { |
1227 if([item isKindOfClass:[NSPointerArray class]]) | 1227 if([item isKindOfClass:[NSPointerArray class]]) |
1228 { | 1228 { |
1229 NSPointerArray *this = (NSPointerArray *)item; | 1229 NSPointerArray *this = (NSPointerArray *)item; |
1230 if(tableColumn == imagecol) | 1230 if(tableColumn == imagecol) |
1231 { | 1231 { |
1232 return [this pointerAtIndex:0]; | 1232 return [this pointerAtIndex:0]; |
1233 } | 1233 } |
1234 return [this pointerAtIndex:1]; | 1234 return [this pointerAtIndex:1]; |
1235 } | 1235 } |
1236 else | 1236 else |
1237 { | 1237 { |
1238 return nil; | 1238 return nil; |
1239 } | 1239 } |
1240 } | 1240 } |
1241 return @"List Root"; | 1241 return @"List Root"; |
1242 } | 1242 } |
1243 -(BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item { return NO; } | 1243 -(BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item { return NO; } |
1244 -(void)addTree:(NSPointerArray *)item and:(NSPointerArray *)parent; | 1244 -(void)addTree:(NSPointerArray *)item and:(NSPointerArray *)parent; |
1245 { | 1245 { |
1309 @end | 1309 @end |
1310 | 1310 |
1311 /* Subclass for a Calendar type */ | 1311 /* Subclass for a Calendar type */ |
1312 @interface DWCalendar : NSDatePicker | 1312 @interface DWCalendar : NSDatePicker |
1313 { | 1313 { |
1314 void *userdata; | 1314 void *userdata; |
1315 } | 1315 } |
1316 -(void *)userdata; | 1316 -(void *)userdata; |
1317 -(void)setUserdata:(void *)input; | 1317 -(void)setUserdata:(void *)input; |
1318 @end | 1318 @end |
1319 | 1319 |
1327 @interface DWComboBox : NSComboBox | 1327 @interface DWComboBox : NSComboBox |
1328 #ifdef BUILDING_FOR_SNOW_LEOPARD | 1328 #ifdef BUILDING_FOR_SNOW_LEOPARD |
1329 <NSComboBoxDelegate> | 1329 <NSComboBoxDelegate> |
1330 #endif | 1330 #endif |
1331 { | 1331 { |
1332 void *userdata; | 1332 void *userdata; |
1333 } | 1333 } |
1334 -(void *)userdata; | 1334 -(void *)userdata; |
1335 -(void)setUserdata:(void *)input; | 1335 -(void)setUserdata:(void *)input; |
1336 -(void)comboBoxSelectionDidChange:(NSNotification *)not; | 1336 -(void)comboBoxSelectionDidChange:(NSNotification *)not; |
1337 @end | 1337 @end |
1383 @interface DWSpinButton : NSView | 1383 @interface DWSpinButton : NSView |
1384 #ifdef BUILDING_FOR_SNOW_LEOPARD | 1384 #ifdef BUILDING_FOR_SNOW_LEOPARD |
1385 <NSTextFieldDelegate> | 1385 <NSTextFieldDelegate> |
1386 #endif | 1386 #endif |
1387 { | 1387 { |
1388 void *userdata; | 1388 void *userdata; |
1389 NSTextField *textfield; | 1389 NSTextField *textfield; |
1390 DWStepper *stepper; | 1390 DWStepper *stepper; |
1391 } | 1391 } |
1392 -(id)init; | 1392 -(id)init; |
1393 -(void *)userdata; | 1393 -(void *)userdata; |
1440 | 1440 |
1441 /* This function adds a signal handler callback into the linked list. | 1441 /* This function adds a signal handler callback into the linked list. |
1442 */ | 1442 */ |
1443 void _new_signal(ULONG message, HWND window, int msgid, void *signalfunction, void *data) | 1443 void _new_signal(ULONG message, HWND window, int msgid, void *signalfunction, void *data) |
1444 { | 1444 { |
1445 SignalHandler *new = malloc(sizeof(SignalHandler)); | 1445 SignalHandler *new = malloc(sizeof(SignalHandler)); |
1446 | 1446 |
1447 new->message = message; | 1447 new->message = message; |
1448 new->window = window; | 1448 new->window = window; |
1449 new->id = msgid; | 1449 new->id = msgid; |
1450 new->signalfunction = signalfunction; | 1450 new->signalfunction = signalfunction; |
1451 new->data = data; | 1451 new->data = data; |
1452 new->next = NULL; | 1452 new->next = NULL; |
1453 | 1453 |
1454 if (!Root) | 1454 if (!Root) |
1455 Root = new; | 1455 Root = new; |
1456 else | 1456 else |
1457 { | 1457 { |
1458 SignalHandler *prev = NULL, *tmp = Root; | 1458 SignalHandler *prev = NULL, *tmp = Root; |
1459 while(tmp) | 1459 while(tmp) |
1460 { | 1460 { |
1461 if(tmp->message == message && | 1461 if(tmp->message == message && |
1462 tmp->window == window && | 1462 tmp->window == window && |
1463 tmp->id == msgid && | 1463 tmp->id == msgid && |
1464 tmp->signalfunction == signalfunction) | 1464 tmp->signalfunction == signalfunction) |
1465 { | 1465 { |
1466 tmp->data = data; | 1466 tmp->data = data; |
1467 free(new); | 1467 free(new); |
1468 return; | 1468 return; |
1469 } | 1469 } |
1470 prev = tmp; | 1470 prev = tmp; |
1471 tmp = tmp->next; | 1471 tmp = tmp->next; |
1472 } | 1472 } |
1473 if(prev) | 1473 if(prev) |
1474 prev->next = new; | 1474 prev->next = new; |
1475 else | 1475 else |
1476 Root = new; | 1476 Root = new; |
1477 } | 1477 } |
1478 } | 1478 } |
1479 | 1479 |
1480 /* Finds the message number for a given signal name */ | 1480 /* Finds the message number for a given signal name */ |
1481 ULONG _findsigmessage(char *signame) | 1481 ULONG _findsigmessage(char *signame) |
1482 { | 1482 { |
1483 int z; | 1483 int z; |
1484 | 1484 |
1485 for(z=0;z<SIGNALMAX;z++) | 1485 for(z=0;z<SIGNALMAX;z++) |
1486 { | 1486 { |
1487 if(strcasecmp(signame, SignalTranslate[z].name) == 0) | 1487 if(strcasecmp(signame, SignalTranslate[z].name) == 0) |
1488 return SignalTranslate[z].message; | 1488 return SignalTranslate[z].message; |
1489 } | 1489 } |
1490 return 0L; | 1490 return 0L; |
1491 } | 1491 } |
1492 | 1492 |
1493 unsigned long _foreground = 0xAAAAAA, _background = 0; | 1493 unsigned long _foreground = 0xAAAAAA, _background = 0; |
1494 | 1494 |
1495 /* This function calculates how much space the widgets and boxes require | 1495 /* This function calculates how much space the widgets and boxes require |
1502 int uymax = 0, uxmax = 0; | 1502 int uymax = 0, uxmax = 0; |
1503 int upymax = 0, upxmax = 0; | 1503 int upymax = 0, upxmax = 0; |
1504 /* Used for the SIZEEXPAND */ | 1504 /* Used for the SIZEEXPAND */ |
1505 int nux = *usedx, nuy = *usedy; | 1505 int nux = *usedx, nuy = *usedy; |
1506 int nupx = *usedpadx, nupy = *usedpady; | 1506 int nupx = *usedpadx, nupy = *usedpady; |
1507 | 1507 |
1508 (*usedx) += (thisbox->pad * 2); | 1508 (*usedx) += (thisbox->pad * 2); |
1509 (*usedy) += (thisbox->pad * 2); | 1509 (*usedy) += (thisbox->pad * 2); |
1510 | 1510 |
1511 for(z=0;z<thisbox->count;z++) | 1511 for(z=0;z<thisbox->count;z++) |
1512 { | 1512 { |
1513 if(thisbox->items[z].type == TYPEBOX) | 1513 if(thisbox->items[z].type == TYPEBOX) |
1514 { | 1514 { |
1515 int initialx, initialy; | 1515 int initialx, initialy; |
1516 DWBox *box = thisbox->items[z].hwnd; | 1516 DWBox *box = thisbox->items[z].hwnd; |
1517 Box *tmp = [box box]; | 1517 Box *tmp = [box box]; |
1518 | 1518 |
1519 initialx = x - (*usedx); | 1519 initialx = x - (*usedx); |
1520 initialy = y - (*usedy); | 1520 initialy = y - (*usedy); |
1521 | 1521 |
1522 if(tmp) | 1522 if(tmp) |
1623 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy)); | 1623 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy)); |
1624 } | 1624 } |
1625 | 1625 |
1626 if(thisbox->items[z].type == TYPEBOX) | 1626 if(thisbox->items[z].type == TYPEBOX) |
1627 { | 1627 { |
1628 DWBox *box = thisbox->items[z].hwnd; | 1628 DWBox *box = thisbox->items[z].hwnd; |
1629 Box *tmp = [box box]; | 1629 Box *tmp = [box box]; |
1630 | 1630 |
1631 if(tmp) | 1631 if(tmp) |
1632 { | 1632 { |
1633 tmp->parentxratio = thisbox->items[z].xratio; | 1633 tmp->parentxratio = thisbox->items[z].xratio; |
1634 tmp->parentyratio = thisbox->items[z].yratio; | 1634 tmp->parentyratio = thisbox->items[z].yratio; |
1724 if(thisbox->items[z].vsize == SIZEEXPAND && thisbox->type == DW_HORZ) | 1724 if(thisbox->items[z].vsize == SIZEEXPAND && thisbox->type == DW_HORZ) |
1725 thisbox->items[z].height = uymax-(thisbox->items[z].pad*2); | 1725 thisbox->items[z].height = uymax-(thisbox->items[z].pad*2); |
1726 /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */ | 1726 /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */ |
1727 if(thisbox->items[z].type == TYPEBOX) | 1727 if(thisbox->items[z].type == TYPEBOX) |
1728 { | 1728 { |
1729 DWBox *box = thisbox->items[z].hwnd; | 1729 DWBox *box = thisbox->items[z].hwnd; |
1730 Box *tmp = [box box]; | 1730 Box *tmp = [box box]; |
1731 | 1731 |
1732 if(tmp) | 1732 if(tmp) |
1733 { | 1733 { |
1734 if(*depth > 0) | 1734 if(*depth > 0) |
1735 { | 1735 { |
1769 { | 1769 { |
1770 int height = thisbox->items[z].height; | 1770 int height = thisbox->items[z].height; |
1771 int width = thisbox->items[z].width; | 1771 int width = thisbox->items[z].width; |
1772 int pad = thisbox->items[z].pad; | 1772 int pad = thisbox->items[z].pad; |
1773 NSView *handle = thisbox->items[z].hwnd; | 1773 NSView *handle = thisbox->items[z].hwnd; |
1774 NSPoint point; | 1774 NSPoint point; |
1775 NSSize size; | 1775 NSSize size; |
1776 int vectorx, vectory; | 1776 int vectorx, vectory; |
1777 | 1777 |
1778 /* When upxmax != pad*2 then ratios are incorrect. */ | 1778 /* When upxmax != pad*2 then ratios are incorrect. */ |
1779 vectorx = (int)((width*thisbox->items[z].xratio)-width); | 1779 vectorx = (int)((width*thisbox->items[z].xratio)-width); |
1780 vectory = (int)((height*thisbox->items[z].yratio)-height); | 1780 vectory = (int)((height*thisbox->items[z].yratio)-height); |
1792 if(thisbox->items[z].vsize != SIZEEXPAND) | 1792 if(thisbox->items[z].vsize != SIZEEXPAND) |
1793 vectory = 0; | 1793 vectory = 0; |
1794 if(thisbox->items[z].hsize != SIZEEXPAND) | 1794 if(thisbox->items[z].hsize != SIZEEXPAND) |
1795 vectorx = 0; | 1795 vectorx = 0; |
1796 | 1796 |
1797 point.x = currentx + pad; | 1797 point.x = currentx + pad; |
1798 point.y = currenty + pad; | 1798 point.y = currenty + pad; |
1799 size.width = width + vectorx; | 1799 size.width = width + vectorx; |
1800 size.height = height + vectory; | 1800 size.height = height + vectory; |
1801 [handle setFrameOrigin:point]; | 1801 [handle setFrameOrigin:point]; |
1802 [handle setFrameSize:size]; | 1802 [handle setFrameSize:size]; |
1803 | 1803 |
1804 /* Special handling for notebook controls */ | 1804 /* Special handling for notebook controls */ |
1805 if([handle isMemberOfClass:[DWNotebook class]]) | 1805 if([handle isMemberOfClass:[DWNotebook class]]) |
1806 { | 1806 { |
1807 DWNotebook *notebook = (DWNotebook *)handle; | 1807 DWNotebook *notebook = (DWNotebook *)handle; |
1808 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; | 1808 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; |
1809 DWBox *view = [notepage view]; | 1809 DWBox *view = [notepage view]; |
1810 | 1810 |
1811 if(view != nil) | 1811 if(view != nil) |
1812 { | 1812 { |
1813 Box *box = [view box]; | 1813 Box *box = [view box]; |
1814 NSSize size = [view frame].size; | 1814 NSSize size = [view frame].size; |
1815 _do_resize(box, size.width, size.height); | 1815 _do_resize(box, size.width, size.height); |
1816 } | 1816 } |
1817 } | 1817 } |
1818 /* Special handling for spinbutton controls */ | 1818 /* Special handling for spinbutton controls */ |
1819 else if([handle isMemberOfClass:[DWSpinButton class]]) | 1819 else if([handle isMemberOfClass:[DWSpinButton class]]) |
1820 { | 1820 { |
1821 DWSpinButton *spinbutton = (DWSpinButton *)handle; | 1821 DWSpinButton *spinbutton = (DWSpinButton *)handle; |
1822 NSTextField *textfield = [spinbutton textfield]; | 1822 NSTextField *textfield = [spinbutton textfield]; |
1824 [textfield setFrameOrigin:NSMakePoint(0,0)]; | 1824 [textfield setFrameOrigin:NSMakePoint(0,0)]; |
1825 [textfield setFrameSize:NSMakeSize(size.width-20,size.height)]; | 1825 [textfield setFrameSize:NSMakeSize(size.width-20,size.height)]; |
1826 [stepper setFrameOrigin:NSMakePoint(size.width-20,0)]; | 1826 [stepper setFrameOrigin:NSMakePoint(size.width-20,0)]; |
1827 [stepper setFrameSize:NSMakeSize(20,size.height)]; | 1827 [stepper setFrameSize:NSMakeSize(20,size.height)]; |
1828 } | 1828 } |
1829 else if([handle isMemberOfClass:[DWRender class]]) | 1829 else if([handle isMemberOfClass:[DWRender class]]) |
1830 { | 1830 { |
1831 _event_handler(handle, nil, 1); | 1831 _event_handler(handle, nil, 1); |
1832 } | 1832 } |
1833 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20) | 1833 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20) |
1834 { | 1834 { |
1835 DWSplitBar *split = (DWSplitBar *)handle; | 1835 DWSplitBar *split = (DWSplitBar *)handle; |
1836 float percent = [split percent]; | 1836 float percent = [split percent]; |
1837 | 1837 |
1838 if(percent > 0) | 1838 if(percent > 0) |
1839 { | 1839 { |
1840 dw_splitbar_set(handle, percent); | 1840 dw_splitbar_set(handle, percent); |
1841 [split setPercent:0]; | 1841 [split setPercent:0]; |
1842 } | 1842 } |
1843 } | 1843 } |
1844 | 1844 |
1845 if(thisbox->type == DW_HORZ) | 1845 if(thisbox->type == DW_HORZ) |
1846 currentx += width + vectorx + (pad * 2); | 1846 currentx += width + vectorx + (pad * 2); |
1847 if(thisbox->type == DW_VERT) | 1847 if(thisbox->type == DW_VERT) |
1848 currenty += height + vectory + (pad * 2); | 1848 currenty += height + vectory + (pad * 2); |
1849 } | 1849 } |
1850 } | 1850 } |
1876 } | 1876 } |
1877 | 1877 |
1878 NSMenu *_generate_main_menu() | 1878 NSMenu *_generate_main_menu() |
1879 { | 1879 { |
1880 NSString *applicationName = nil; | 1880 NSString *applicationName = nil; |
1881 | 1881 |
1882 /* This only works on 10.6 so we have a backup method */ | 1882 /* This only works on 10.6 so we have a backup method */ |
1883 #ifdef BUILDING_FOR_SNOW_LEOPARD | 1883 #ifdef BUILDING_FOR_SNOW_LEOPARD |
1884 applicationName = [[NSRunningApplication currentApplication] localizedName]; | 1884 applicationName = [[NSRunningApplication currentApplication] localizedName]; |
1885 #endif | 1885 #endif |
1886 if(applicationName == nil) | 1886 if(applicationName == nil) |
1887 { | 1887 { |
1888 applicationName = [[NSProcessInfo processInfo] processName]; | 1888 applicationName = [[NSProcessInfo processInfo] processName]; |
1889 } | 1889 } |
1890 | 1890 |
1891 /* Create the main menu */ | 1891 /* Create the main menu */ |
1892 NSMenu * mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease]; | 1892 NSMenu * mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease]; |
1893 | 1893 |
1894 NSMenuItem * mitem = [mainMenu addItemWithTitle:@"Apple" action:NULL keyEquivalent:@""]; | 1894 NSMenuItem * mitem = [mainMenu addItemWithTitle:@"Apple" action:NULL keyEquivalent:@""]; |
1895 NSMenu * menu = [[[NSMenu alloc] initWithTitle:@"Apple"] autorelease]; | 1895 NSMenu * menu = [[[NSMenu alloc] initWithTitle:@"Apple"] autorelease]; |
1896 | 1896 |
1897 [DWApp performSelector:@selector(setAppleMenu:) withObject:menu]; | 1897 [DWApp performSelector:@selector(setAppleMenu:) withObject:menu]; |
1898 | 1898 |
1899 /* Setup the Application menu */ | 1899 /* Setup the Application menu */ |
1900 NSMenuItem * item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"About", nil), applicationName] | 1900 NSMenuItem * item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"About", nil), applicationName] |
1901 action:@selector(orderFrontStandardAboutPanel:) | 1901 action:@selector(orderFrontStandardAboutPanel:) |
1902 keyEquivalent:@""]; | 1902 keyEquivalent:@""]; |
1903 [item setTarget:DWApp]; | 1903 [item setTarget:DWApp]; |
1904 | 1904 |
1905 [menu addItem:[NSMenuItem separatorItem]]; | 1905 [menu addItem:[NSMenuItem separatorItem]]; |
1906 | 1906 |
1907 item = [menu addItemWithTitle:NSLocalizedString(@"Services", nil) | 1907 item = [menu addItemWithTitle:NSLocalizedString(@"Services", nil) |
1908 action:NULL | 1908 action:NULL |
1909 keyEquivalent:@""]; | 1909 keyEquivalent:@""]; |
1910 NSMenu * servicesMenu = [[[NSMenu alloc] initWithTitle:@"Services"] autorelease]; | 1910 NSMenu * servicesMenu = [[[NSMenu alloc] initWithTitle:@"Services"] autorelease]; |
1911 [menu setSubmenu:servicesMenu forItem:item]; | 1911 [menu setSubmenu:servicesMenu forItem:item]; |
1912 [DWApp setServicesMenu:servicesMenu]; | 1912 [DWApp setServicesMenu:servicesMenu]; |
1913 | 1913 |
1914 [menu addItem:[NSMenuItem separatorItem]]; | 1914 [menu addItem:[NSMenuItem separatorItem]]; |
1915 | 1915 |
1916 item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Hide", nil), applicationName] | 1916 item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Hide", nil), applicationName] |
1917 action:@selector(hide:) | 1917 action:@selector(hide:) |
1918 keyEquivalent:@"h"]; | 1918 keyEquivalent:@"h"]; |
1919 [item setTarget:DWApp]; | 1919 [item setTarget:DWApp]; |
1920 | 1920 |
1921 item = [menu addItemWithTitle:NSLocalizedString(@"Hide Others", nil) | 1921 item = [menu addItemWithTitle:NSLocalizedString(@"Hide Others", nil) |
1922 action:@selector(hideOtherApplications:) | 1922 action:@selector(hideOtherApplications:) |
1923 keyEquivalent:@"h"]; | 1923 keyEquivalent:@"h"]; |
1924 [item setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask]; | 1924 [item setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask]; |
1925 [item setTarget:DWApp]; | 1925 [item setTarget:DWApp]; |
1926 | 1926 |
1927 item = [menu addItemWithTitle:NSLocalizedString(@"Show All", nil) | 1927 item = [menu addItemWithTitle:NSLocalizedString(@"Show All", nil) |
1928 action:@selector(unhideAllApplications:) | 1928 action:@selector(unhideAllApplications:) |
1929 keyEquivalent:@""]; | 1929 keyEquivalent:@""]; |
1930 [item setTarget:DWApp]; | 1930 [item setTarget:DWApp]; |
1931 | 1931 |
1932 [menu addItem:[NSMenuItem separatorItem]]; | 1932 [menu addItem:[NSMenuItem separatorItem]]; |
1933 | 1933 |
1934 item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Quit", nil), applicationName] | 1934 item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Quit", nil), applicationName] |
1935 action:@selector(terminate:) | 1935 action:@selector(terminate:) |
1936 keyEquivalent:@"q"]; | 1936 keyEquivalent:@"q"]; |
1937 [item setTarget:DWApp]; | 1937 [item setTarget:DWApp]; |
1938 | 1938 |
1939 [mainMenu setSubmenu:menu forItem:mitem]; | 1939 [mainMenu setSubmenu:menu forItem:mitem]; |
1940 | 1940 |
1941 return mainMenu; | 1941 return mainMenu; |
1942 } | 1942 } |
1943 | 1943 |
1944 /* | 1944 /* |
1945 * Runs a message loop for Dynamic Windows. | 1945 * Runs a message loop for Dynamic Windows. |
1946 */ | 1946 */ |
2031 * Parameters: | 2031 * Parameters: |
2032 * exitcode: Exit code reported to the operating system. | 2032 * exitcode: Exit code reported to the operating system. |
2033 */ | 2033 */ |
2034 void API dw_exit(int exitcode) | 2034 void API dw_exit(int exitcode) |
2035 { | 2035 { |
2036 exit(exitcode); | 2036 exit(exitcode); |
2037 } | 2037 } |
2038 | 2038 |
2039 /* | 2039 /* |
2040 * Free's memory allocated by dynamic windows. | 2040 * Free's memory allocated by dynamic windows. |
2041 * Parameters: | 2041 * Parameters: |
2052 * current user directory. Or the root directory (C:\ on | 2052 * current user directory. Or the root directory (C:\ on |
2053 * OS/2 and Windows). | 2053 * OS/2 and Windows). |
2054 */ | 2054 */ |
2055 char *dw_user_dir(void) | 2055 char *dw_user_dir(void) |
2056 { | 2056 { |
2057 static char _user_dir[1024] = ""; | 2057 static char _user_dir[1024] = ""; |
2058 | 2058 |
2059 if(!_user_dir[0]) | 2059 if(!_user_dir[0]) |
2060 { | 2060 { |
2061 char *home = getenv("HOME"); | 2061 char *home = getenv("HOME"); |
2062 | 2062 |
2063 if(home) | 2063 if(home) |
2064 strcpy(_user_dir, home); | 2064 strcpy(_user_dir, home); |
2065 else | 2065 else |
2066 strcpy(_user_dir, "/"); | 2066 strcpy(_user_dir, "/"); |
2067 } | 2067 } |
2068 return _user_dir; | 2068 return _user_dir; |
2069 } | 2069 } |
2070 | 2070 |
2071 /* | 2071 /* |
2072 * Displays a Message Box with given text and title.. | 2072 * Displays a Message Box with given text and title.. |
2073 * Parameters: | 2073 * Parameters: |
2076 * format: printf style format string. | 2076 * format: printf style format string. |
2077 * ...: Additional variables for use in the format. | 2077 * ...: Additional variables for use in the format. |
2078 */ | 2078 */ |
2079 int API dw_messagebox(char *title, int flags, char *format, ...) | 2079 int API dw_messagebox(char *title, int flags, char *format, ...) |
2080 { | 2080 { |
2081 int iResponse; | 2081 int iResponse; |
2082 NSString *button1 = @"OK"; | 2082 NSString *button1 = @"OK"; |
2083 NSString *button2 = nil; | 2083 NSString *button2 = nil; |
2084 NSString *button3 = nil; | 2084 NSString *button3 = nil; |
2085 va_list args; | 2085 va_list args; |
2086 char outbuf[1000]; | 2086 char outbuf[1000]; |
2087 | 2087 |
2088 va_start(args, format); | 2088 va_start(args, format); |
2089 vsprintf(outbuf, format, args); | 2089 vsprintf(outbuf, format, args); |
2090 va_end(args); | 2090 va_end(args); |
2091 | 2091 |
2092 if(flags & DW_MB_OKCANCEL) | 2092 if(flags & DW_MB_OKCANCEL) |
2093 { | 2093 { |
2094 button2 = @"Cancel"; | 2094 button2 = @"Cancel"; |
2095 } | 2095 } |
2096 else if(flags & DW_MB_YESNO) | 2096 else if(flags & DW_MB_YESNO) |
2097 { | 2097 { |
2098 button1 = @"Yes"; | 2098 button1 = @"Yes"; |
2099 button2 = @"No"; | 2099 button2 = @"No"; |
2100 } | 2100 } |
2101 else if(flags & DW_MB_YESNOCANCEL) | 2101 else if(flags & DW_MB_YESNOCANCEL) |
2102 { | 2102 { |
2103 button1 = @"Yes"; | 2103 button1 = @"Yes"; |
2104 button2 = @"No"; | 2104 button2 = @"No"; |
2105 button3 = @"Cancel"; | 2105 button3 = @"Cancel"; |
2106 } | 2106 } |
2107 | 2107 |
2108 if(flags & DW_MB_ERROR) | 2108 if(flags & DW_MB_ERROR) |
2109 { | 2109 { |
2110 iResponse = (int) | 2110 iResponse = (int) |
2111 NSRunCriticalAlertPanel([ NSString stringWithUTF8String:title ], | 2111 NSRunCriticalAlertPanel([ NSString stringWithUTF8String:title ], |
2112 [ NSString stringWithUTF8String:outbuf ], | 2112 [ NSString stringWithUTF8String:outbuf ], |
2113 button1, button2, button3); } | 2113 button1, button2, button3); } |
2114 else | 2114 else |
2115 { | 2115 { |
2116 iResponse = (int) | 2116 iResponse = (int) |
2117 NSRunAlertPanel([ NSString stringWithUTF8String:title ], | 2117 NSRunAlertPanel([ NSString stringWithUTF8String:title ], |
2118 [ NSString stringWithUTF8String:outbuf ], | 2118 [ NSString stringWithUTF8String:outbuf ], |
2119 button1, button2, button3); | 2119 button1, button2, button3); |
2120 } | 2120 } |
2121 | 2121 |
2122 switch(iResponse) | 2122 switch(iResponse) |
2123 { | 2123 { |
2124 case NSAlertDefaultReturn: /* user pressed OK */ | 2124 case NSAlertDefaultReturn: /* user pressed OK */ |
2125 if(flags & DW_MB_YESNO || flags & DW_MB_YESNOCANCEL) | 2125 if(flags & DW_MB_YESNO || flags & DW_MB_YESNOCANCEL) |
2126 { | 2126 { |
2127 return DW_MB_RETURN_YES; | 2127 return DW_MB_RETURN_YES; |
2128 } | 2128 } |
2129 return DW_MB_RETURN_OK; | 2129 return DW_MB_RETURN_OK; |
2130 case NSAlertAlternateReturn: /* user pressed Cancel */ | 2130 case NSAlertAlternateReturn: /* user pressed Cancel */ |
2131 if(flags & DW_MB_OKCANCEL) | 2131 if(flags & DW_MB_OKCANCEL) |
2132 { | 2132 { |
2133 return DW_MB_RETURN_CANCEL; | 2133 return DW_MB_RETURN_CANCEL; |
2134 } | 2134 } |
2135 return DW_MB_RETURN_NO; | 2135 return DW_MB_RETURN_NO; |
2136 case NSAlertOtherReturn: /* user pressed the third button */ | 2136 case NSAlertOtherReturn: /* user pressed the third button */ |
2137 return DW_MB_RETURN_CANCEL; | 2137 return DW_MB_RETURN_CANCEL; |
2138 case NSAlertErrorReturn: /* an error occurred */ | 2138 case NSAlertErrorReturn: /* an error occurred */ |
2139 break; | 2139 break; |
2140 } | 2140 } |
2141 return 0; | 2141 return 0; |
2142 } | 2142 } |
2143 | 2143 |
2144 /* | 2144 /* |
2145 * Opens a file dialog and queries user selection. | 2145 * Opens a file dialog and queries user selection. |
2146 * Parameters: | 2146 * Parameters: |
2153 * the file path on success. | 2153 * the file path on success. |
2154 * | 2154 * |
2155 */ | 2155 */ |
2156 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) | 2156 char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) |
2157 { | 2157 { |
2158 if(flags == DW_FILE_OPEN) | 2158 if(flags == DW_FILE_OPEN) |
2159 { | 2159 { |
2160 /* Create the File Open Dialog class. */ | 2160 /* Create the File Open Dialog class. */ |
2161 NSOpenPanel* openDlg = [NSOpenPanel openPanel]; | 2161 NSOpenPanel* openDlg = [NSOpenPanel openPanel]; |
2162 | 2162 |
2163 /* Enable the selection of files in the dialog. */ | 2163 /* Enable the selection of files in the dialog. */ |
2164 [openDlg setCanChooseFiles:YES]; | 2164 [openDlg setCanChooseFiles:YES]; |
2165 [openDlg setCanChooseDirectories:NO]; | 2165 [openDlg setCanChooseDirectories:NO]; |
2166 | 2166 |
2167 /* Disable multiple selection */ | 2167 /* Disable multiple selection */ |
2168 [openDlg setAllowsMultipleSelection:NO]; | 2168 [openDlg setAllowsMultipleSelection:NO]; |
2169 | 2169 |
2170 /* Display the dialog. If the OK button was pressed, | 2170 /* Display the dialog. If the OK button was pressed, |
2171 * process the files. | 2171 * process the files. |
2172 */ | 2172 */ |
2173 if([openDlg runModal] == NSOKButton) | 2173 if([openDlg runModal] == NSOKButton) |
2174 { | 2174 { |
2175 /* Get an array containing the full filenames of all | 2175 /* Get an array containing the full filenames of all |
2176 * files and directories selected. | 2176 * files and directories selected. |
2177 */ | 2177 */ |
2178 NSArray* files = [openDlg filenames]; | 2178 NSArray* files = [openDlg filenames]; |
2179 NSString* fileName = [files objectAtIndex:0]; | 2179 NSString* fileName = [files objectAtIndex:0]; |
2180 return strdup([ fileName UTF8String ]); | 2180 return strdup([ fileName UTF8String ]); |
2181 } | 2181 } |
2182 } | 2182 } |
2183 else | 2183 else |
2184 { | 2184 { |
2185 /* Create the File Save Dialog class. */ | 2185 /* Create the File Save Dialog class. */ |
2186 NSSavePanel* saveDlg = [NSSavePanel savePanel]; | 2186 NSSavePanel* saveDlg = [NSSavePanel savePanel]; |
2187 | 2187 |
2188 /* Enable the creation of directories in the dialog. */ | 2188 /* Enable the creation of directories in the dialog. */ |
2189 [saveDlg setCanCreateDirectories:YES]; | 2189 [saveDlg setCanCreateDirectories:YES]; |
2190 | 2190 |
2191 /* Display the dialog. If the OK button was pressed, | 2191 /* Display the dialog. If the OK button was pressed, |
2192 * process the files. | 2192 * process the files. |
2193 */ | 2193 */ |
2194 if([saveDlg runModal] == NSFileHandlingPanelOKButton) | 2194 if([saveDlg runModal] == NSFileHandlingPanelOKButton) |
2195 { | 2195 { |
2196 /* Get an array containing the full filenames of all | 2196 /* Get an array containing the full filenames of all |
2197 * files and directories selected. | 2197 * files and directories selected. |
2198 */ | 2198 */ |
2199 NSString* fileName = [saveDlg filename]; | 2199 NSString* fileName = [saveDlg filename]; |
2200 return strdup([ fileName UTF8String ]); | 2200 return strdup([ fileName UTF8String ]); |
2201 } | 2201 } |
2202 } | 2202 } |
2203 | 2203 |
2204 return NULL; | 2204 return NULL; |
2205 } | 2205 } |
2206 | 2206 |
2207 /* | 2207 /* |
2208 * Gets the contents of the default clipboard as text. | 2208 * Gets the contents of the default clipboard as text. |
2209 * Parameters: | 2209 * Parameters: |
2212 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not | 2212 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not |
2213 * be converted to text. | 2213 * be converted to text. |
2214 */ | 2214 */ |
2215 char *dw_clipboard_get_text() | 2215 char *dw_clipboard_get_text() |
2216 { | 2216 { |
2217 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; | 2217 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; |
2218 NSString *str = [pasteboard stringForType:NSStringPboardType]; | 2218 NSString *str = [pasteboard stringForType:NSStringPboardType]; |
2219 if(str != nil) | 2219 if(str != nil) |
2220 { | 2220 { |
2221 return strdup([ str UTF8String ]); | 2221 return strdup([ str UTF8String ]); |
2222 } | 2222 } |
2223 return NULL; | 2223 return NULL; |
2224 } | 2224 } |
2225 | 2225 |
2226 /* | 2226 /* |
2227 * Sets the contents of the default clipboard to the supplied text. | 2227 * Sets the contents of the default clipboard to the supplied text. |
2228 * Parameters: | 2228 * Parameters: |
2229 * Text. | 2229 * Text. |
2230 */ | 2230 */ |
2231 void dw_clipboard_set_text( char *str, int len) | 2231 void dw_clipboard_set_text( char *str, int len) |
2232 { | 2232 { |
2233 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; | 2233 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; |
2234 | 2234 |
2235 /* Only in Snow Leopard */ | 2235 /* Only in Snow Leopard */ |
2236 if(DWOSMinor > 5) | 2236 if(DWOSMinor > 5) |
2237 { | 2237 { |
2238 [pasteboard clearContents]; | 2238 [pasteboard clearContents]; |
2239 } | 2239 } |
2240 | 2240 |
2241 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType]; | 2241 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType]; |
2242 } | 2242 } |
2243 | 2243 |
2244 | 2244 |
2245 /* | 2245 /* |
2246 * Allocates and initializes a dialog struct. | 2246 * Allocates and initializes a dialog struct. |
2247 * Parameters: | 2247 * Parameters: |
2248 * data: User defined data to be passed to functions. | 2248 * data: User defined data to be passed to functions. |
2249 */ | 2249 */ |
2250 DWDialog * API dw_dialog_new(void *data) | 2250 DWDialog * API dw_dialog_new(void *data) |
2251 { | 2251 { |
2252 DWDialog *tmp = malloc(sizeof(DWDialog)); | 2252 DWDialog *tmp = malloc(sizeof(DWDialog)); |
2253 | 2253 |
2254 if(tmp) | 2254 if(tmp) |
2255 { | 2255 { |
2256 tmp->eve = dw_event_new(); | 2256 tmp->eve = dw_event_new(); |
2257 dw_event_reset(tmp->eve); | 2257 dw_event_reset(tmp->eve); |
2258 tmp->data = data; | 2258 tmp->data = data; |
2259 tmp->done = FALSE; | 2259 tmp->done = FALSE; |
2260 tmp->result = NULL; | 2260 tmp->result = NULL; |
2261 } | 2261 } |
2262 return tmp; | 2262 return tmp; |
2263 } | 2263 } |
2264 | 2264 |
2265 /* | 2265 /* |
2266 * Accepts a dialog struct and returns the given data to the | 2266 * Accepts a dialog struct and returns the given data to the |
2267 * initial called of dw_dialog_wait(). | 2267 * initial called of dw_dialog_wait(). |
2269 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). | 2269 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). |
2270 * result: Data to be returned by dw_dialog_wait(). | 2270 * result: Data to be returned by dw_dialog_wait(). |
2271 */ | 2271 */ |
2272 int API dw_dialog_dismiss(DWDialog *dialog, void *result) | 2272 int API dw_dialog_dismiss(DWDialog *dialog, void *result) |
2273 { | 2273 { |
2274 dialog->result = result; | 2274 dialog->result = result; |
2275 dw_event_post(dialog->eve); | 2275 dw_event_post(dialog->eve); |
2276 dialog->done = TRUE; | 2276 dialog->done = TRUE; |
2277 return 0; | 2277 return 0; |
2278 } | 2278 } |
2279 | 2279 |
2280 /* | 2280 /* |
2281 * Accepts a dialog struct waits for dw_dialog_dismiss() to be | 2281 * Accepts a dialog struct waits for dw_dialog_dismiss() to be |
2282 * called by a signal handler with the given dialog struct. | 2282 * called by a signal handler with the given dialog struct. |
2283 * Parameters: | 2283 * Parameters: |
2284 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). | 2284 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). |
2285 */ | 2285 */ |
2286 void * API dw_dialog_wait(DWDialog *dialog) | 2286 void * API dw_dialog_wait(DWDialog *dialog) |
2287 { | 2287 { |
2288 void *tmp; | 2288 void *tmp; |
2289 | 2289 |
2290 while(!dialog->done) | 2290 while(!dialog->done) |
2291 { | 2291 { |
2292 _dw_main_iteration([NSDate dateWithTimeIntervalSinceNow:0.01]); | 2292 _dw_main_iteration([NSDate dateWithTimeIntervalSinceNow:0.01]); |
2293 } | 2293 } |
2294 dw_event_close(&dialog->eve); | 2294 dw_event_close(&dialog->eve); |
2295 tmp = dialog->result; | 2295 tmp = dialog->result; |
2296 free(dialog); | 2296 free(dialog); |
2297 return tmp; | 2297 return tmp; |
2298 } | 2298 } |
2299 | 2299 |
2300 /* | 2300 /* |
2301 * Create a new Box to be packed. | 2301 * Create a new Box to be packed. |
2302 * Parameters: | 2302 * Parameters: |
2306 HWND API dw_box_new(int type, int pad) | 2306 HWND API dw_box_new(int type, int pad) |
2307 { | 2307 { |
2308 int _locked_by_me = FALSE; | 2308 int _locked_by_me = FALSE; |
2309 DW_MUTEX_LOCK; | 2309 DW_MUTEX_LOCK; |
2310 DWBox *view = [[DWBox alloc] init]; | 2310 DWBox *view = [[DWBox alloc] init]; |
2311 Box *newbox = [view box]; | 2311 Box *newbox = [view box]; |
2312 memset(newbox, 0, sizeof(Box)); | 2312 memset(newbox, 0, sizeof(Box)); |
2313 newbox->pad = pad; | 2313 newbox->pad = pad; |
2314 newbox->type = type; | 2314 newbox->type = type; |
2315 DW_MUTEX_UNLOCK; | 2315 DW_MUTEX_UNLOCK; |
2316 return view; | 2316 return view; |
2317 } | 2317 } |
2318 | 2318 |
2319 /* | 2319 /* |
2320 * Create a new Group Box to be packed. | 2320 * Create a new Group Box to be packed. |
2321 * Parameters: | 2321 * Parameters: |
2323 * pad: Number of pixels to pad around the box. | 2323 * pad: Number of pixels to pad around the box. |
2324 * title: Text to be displayined in the group outline. | 2324 * title: Text to be displayined in the group outline. |
2325 */ | 2325 */ |
2326 HWND API dw_groupbox_new(int type, int pad, char *title) | 2326 HWND API dw_groupbox_new(int type, int pad, char *title) |
2327 { | 2327 { |
2328 DWBox *box = dw_box_new(type, pad); | 2328 DWBox *box = dw_box_new(type, pad); |
2329 [box setFocusRingType:NSFocusRingTypeExterior]; | 2329 [box setFocusRingType:NSFocusRingTypeExterior]; |
2330 return box; | 2330 return box; |
2331 } | 2331 } |
2332 | 2332 |
2333 #ifndef INCOMPLETE | 2333 #ifndef INCOMPLETE |
2334 /* | 2334 /* |
2335 * Create a new scrollable Box to be packed. | 2335 * Create a new scrollable Box to be packed. |
2386 */ | 2386 */ |
2387 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 2387 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
2388 { | 2388 { |
2389 int _locked_by_me = FALSE; | 2389 int _locked_by_me = FALSE; |
2390 DW_MUTEX_LOCK; | 2390 DW_MUTEX_LOCK; |
2391 NSObject *object = box; | 2391 NSObject *object = box; |
2392 DWBox *view = box; | 2392 DWBox *view = box; |
2393 DWBox *this = item; | 2393 DWBox *this = item; |
2394 Box *thisbox; | 2394 Box *thisbox; |
2395 int z; | 2395 int z; |
2396 Item *tmpitem, *thisitem; | 2396 Item *tmpitem, *thisitem; |
2397 | 2397 |
2398 /* Query the objects */ | 2398 /* Query the objects */ |
2399 if([ object isKindOfClass:[ NSWindow class ] ]) | 2399 if([ object isKindOfClass:[ NSWindow class ] ]) |
2400 { | 2400 { |
2401 NSWindow *window = box; | 2401 NSWindow *window = box; |
2402 view = [window contentView]; | 2402 view = [window contentView]; |
2403 } | 2403 } |
2404 | 2404 |
2405 thisbox = [view box]; | 2405 thisbox = [view box]; |
2406 thisitem = thisbox->items; | 2406 thisitem = thisbox->items; |
2407 object = item; | 2407 object = item; |
2408 | 2408 |
2409 /* Query the objects */ | 2409 /* Query the objects */ |
2410 if([ object isKindOfClass:[ DWContainer class ] ]) | 2410 if([ object isKindOfClass:[ DWContainer class ] ]) |
2411 { | 2411 { |
2412 DWContainer *cont = item; | 2412 DWContainer *cont = item; |
2413 this = item = [cont scrollview]; | 2413 this = item = [cont scrollview]; |
2414 } | 2414 } |
2415 else if([ object isKindOfClass:[ DWTree class ] ]) | 2415 else if([ object isKindOfClass:[ DWTree class ] ]) |
2416 { | 2416 { |
2417 DWTree *tree = item; | 2417 DWTree *tree = item; |
2418 this = item = [tree scrollview]; | 2418 this = item = [tree scrollview]; |
2419 } | 2419 } |
2420 | 2420 |
2421 /* Duplicate the existing data */ | 2421 /* Duplicate the existing data */ |
2422 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | 2422 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); |
2423 | 2423 |
2424 for(z=0;z<thisbox->count;z++) | 2424 for(z=0;z<thisbox->count;z++) |
2425 { | 2425 { |
2426 tmpitem[z+1] = thisitem[z]; | 2426 tmpitem[z+1] = thisitem[z]; |
2427 } | 2427 } |
2428 | 2428 |
2429 /* Sanity checks */ | 2429 /* Sanity checks */ |
2430 if(vsize && !height) | 2430 if(vsize && !height) |
2431 height = 1; | 2431 height = 1; |
2432 if(hsize && !width) | 2432 if(hsize && !width) |
2433 width = 1; | 2433 width = 1; |
2434 | 2434 |
2435 /* Fill in the item data appropriately */ | 2435 /* Fill in the item data appropriately */ |
2436 if([ object isKindOfClass:[ DWBox class ] ]) | 2436 if([ object isKindOfClass:[ DWBox class ] ]) |
2437 tmpitem[0].type = TYPEBOX; | 2437 tmpitem[0].type = TYPEBOX; |
2438 else | 2438 else |
2439 tmpitem[0].type = TYPEITEM; | 2439 tmpitem[0].type = TYPEITEM; |
2440 | 2440 |
2441 tmpitem[0].hwnd = item; | 2441 tmpitem[0].hwnd = item; |
2452 else | 2452 else |
2453 tmpitem[0].vsize = SIZESTATIC; | 2453 tmpitem[0].vsize = SIZESTATIC; |
2454 | 2454 |
2455 thisbox->items = tmpitem; | 2455 thisbox->items = tmpitem; |
2456 | 2456 |
2457 /* Update the item count */ | 2457 /* Update the item count */ |
2458 thisbox->count++; | 2458 thisbox->count++; |
2459 | 2459 |
2460 /* Add the item to the box */ | 2460 /* Add the item to the box */ |
2461 [view addSubview:this]; | 2461 [view addSubview:this]; |
2462 | 2462 |
2463 /* Free the old data */ | 2463 /* Free the old data */ |
2464 if(thisbox->count) | 2464 if(thisbox->count) |
2465 free(thisitem); | 2465 free(thisitem); |
2466 DW_MUTEX_UNLOCK; | 2466 DW_MUTEX_UNLOCK; |
2467 } | 2467 } |
2468 | 2468 |
2479 */ | 2479 */ |
2480 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 2480 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
2481 { | 2481 { |
2482 int _locked_by_me = FALSE; | 2482 int _locked_by_me = FALSE; |
2483 DW_MUTEX_LOCK; | 2483 DW_MUTEX_LOCK; |
2484 NSObject *object = box; | 2484 NSObject *object = box; |
2485 DWBox *view = box; | 2485 DWBox *view = box; |
2486 DWBox *this = item; | 2486 DWBox *this = item; |
2487 Box *thisbox; | 2487 Box *thisbox; |
2488 int z; | 2488 int z; |
2489 Item *tmpitem, *thisitem; | 2489 Item *tmpitem, *thisitem; |
2490 | 2490 |
2491 /* Query the objects */ | 2491 /* Query the objects */ |
2492 if([ object isKindOfClass:[ NSWindow class ] ]) | 2492 if([ object isKindOfClass:[ NSWindow class ] ]) |
2493 { | 2493 { |
2494 NSWindow *window = box; | 2494 NSWindow *window = box; |
2495 view = [window contentView]; | 2495 view = [window contentView]; |
2496 } | 2496 } |
2497 | 2497 |
2498 thisbox = [view box]; | 2498 thisbox = [view box]; |
2499 thisitem = thisbox->items; | 2499 thisitem = thisbox->items; |
2500 object = item; | 2500 object = item; |
2501 | 2501 |
2502 /* Query the objects */ | 2502 /* Query the objects */ |
2503 if([ object isKindOfClass:[ DWContainer class ] ]) | 2503 if([ object isKindOfClass:[ DWContainer class ] ]) |
2504 { | 2504 { |
2505 DWContainer *cont = item; | 2505 DWContainer *cont = item; |
2506 this = item = [cont scrollview]; | 2506 this = item = [cont scrollview]; |
2507 } | 2507 } |
2508 else if([ object isKindOfClass:[ DWTree class ] ]) | 2508 else if([ object isKindOfClass:[ DWTree class ] ]) |
2509 { | 2509 { |
2510 DWTree *tree = item; | 2510 DWTree *tree = item; |
2511 this = item = [tree scrollview]; | 2511 this = item = [tree scrollview]; |
2512 } | 2512 } |
2513 | 2513 |
2514 /* Duplicate the existing data */ | 2514 /* Duplicate the existing data */ |
2515 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | 2515 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); |
2516 | 2516 |
2517 for(z=0;z<thisbox->count;z++) | 2517 for(z=0;z<thisbox->count;z++) |
2518 { | 2518 { |
2519 tmpitem[z] = thisitem[z]; | 2519 tmpitem[z] = thisitem[z]; |
2520 } | 2520 } |
2521 | 2521 |
2522 /* Sanity checks */ | 2522 /* Sanity checks */ |
2523 if(vsize && !height) | 2523 if(vsize && !height) |
2524 height = 1; | 2524 height = 1; |
2525 if(hsize && !width) | 2525 if(hsize && !width) |
2526 width = 1; | 2526 width = 1; |
2527 | 2527 |
2528 /* Fill in the item data appropriately */ | 2528 /* Fill in the item data appropriately */ |
2529 if([ object isKindOfClass:[ DWBox class ] ]) | 2529 if([ object isKindOfClass:[ DWBox class ] ]) |
2530 tmpitem[thisbox->count].type = TYPEBOX; | 2530 tmpitem[thisbox->count].type = TYPEBOX; |
2531 else | 2531 else |
2532 tmpitem[thisbox->count].type = TYPEITEM; | 2532 tmpitem[thisbox->count].type = TYPEITEM; |
2533 | 2533 |
2534 tmpitem[thisbox->count].hwnd = item; | 2534 tmpitem[thisbox->count].hwnd = item; |
2543 if(vsize) | 2543 if(vsize) |
2544 tmpitem[thisbox->count].vsize = SIZEEXPAND; | 2544 tmpitem[thisbox->count].vsize = SIZEEXPAND; |
2545 else | 2545 else |
2546 tmpitem[thisbox->count].vsize = SIZESTATIC; | 2546 tmpitem[thisbox->count].vsize = SIZESTATIC; |
2547 | 2547 |
2548 thisbox->items = tmpitem; | 2548 thisbox->items = tmpitem; |
2549 | 2549 |
2550 /* Update the item count */ | 2550 /* Update the item count */ |
2551 thisbox->count++; | 2551 thisbox->count++; |
2552 | 2552 |
2553 /* Add the item to the box */ | 2553 /* Add the item to the box */ |
2554 [view addSubview:this]; | 2554 [view addSubview:this]; |
2555 | 2555 |
2556 /* Free the old data */ | 2556 /* Free the old data */ |
2557 if(thisbox->count) | 2557 if(thisbox->count) |
2558 free(thisitem); | 2558 free(thisitem); |
2559 DW_MUTEX_UNLOCK; | 2559 DW_MUTEX_UNLOCK; |
2560 } | 2560 } |
2561 | 2561 |
2590 [button setButtonType:NSMomentaryPushInButton]; | 2590 [button setButtonType:NSMomentaryPushInButton]; |
2591 [button setBezelStyle:NSRoundedBezelStyle]; | 2591 [button setBezelStyle:NSRoundedBezelStyle]; |
2592 [button setImagePosition:NSNoImage]; | 2592 [button setImagePosition:NSNoImage]; |
2593 [button setAlignment:NSCenterTextAlignment]; | 2593 [button setAlignment:NSCenterTextAlignment]; |
2594 [[button cell] setControlTint:NSBlueControlTint]; | 2594 [[button cell] setControlTint:NSBlueControlTint]; |
2595 return button; | 2595 return button; |
2596 } | 2596 } |
2597 | 2597 |
2598 /* | 2598 /* |
2599 * Create a new Entryfield window (widget) to be packed. | 2599 * Create a new Entryfield window (widget) to be packed. |
2600 * Parameters: | 2600 * Parameters: |
2601 * text: The default text to be in the entryfield widget. | 2601 * text: The default text to be in the entryfield widget. |
2602 * id: An ID to be used with dw_window_from_id() or 0L. | 2602 * id: An ID to be used with dw_window_from_id() or 0L. |
2603 */ | 2603 */ |
2604 HWND API dw_entryfield_new(char *text, ULONG cid) | 2604 HWND API dw_entryfield_new(char *text, ULONG cid) |
2605 { | 2605 { |
2606 DWEntryField *entry = [[DWEntryField alloc] init]; | 2606 DWEntryField *entry = [[DWEntryField alloc] init]; |
2607 [entry setStringValue:[ NSString stringWithUTF8String:text ]]; | 2607 [entry setStringValue:[ NSString stringWithUTF8String:text ]]; |
2608 [entry setTag:cid]; | 2608 [entry setTag:cid]; |
2609 return entry; | 2609 return entry; |
2610 } | 2610 } |
2611 | 2611 |
2612 /* | 2612 /* |
2613 * Create a new Entryfield (password) window (widget) to be packed. | 2613 * Create a new Entryfield (password) window (widget) to be packed. |
2614 * Parameters: | 2614 * Parameters: |
2615 * text: The default text to be in the entryfield widget. | 2615 * text: The default text to be in the entryfield widget. |
2616 * id: An ID to be used with dw_window_from_id() or 0L. | 2616 * id: An ID to be used with dw_window_from_id() or 0L. |
2617 */ | 2617 */ |
2618 HWND API dw_entryfield_password_new(char *text, ULONG cid) | 2618 HWND API dw_entryfield_password_new(char *text, ULONG cid) |
2619 { | 2619 { |
2620 DWEntryFieldPassword *entry = [[DWEntryFieldPassword alloc] init]; | 2620 DWEntryFieldPassword *entry = [[DWEntryFieldPassword alloc] init]; |
2621 [entry setStringValue:[ NSString stringWithUTF8String:text ]]; | 2621 [entry setStringValue:[ NSString stringWithUTF8String:text ]]; |
2622 [entry setTag:cid]; | 2622 [entry setTag:cid]; |
2623 return entry; | 2623 return entry; |
2624 } | 2624 } |
2625 | 2625 |
2626 /* | 2626 /* |
2627 * Sets the entryfield character limit. | 2627 * Sets the entryfield character limit. |
2628 * Parameters: | 2628 * Parameters: |
2629 * handle: Handle to the spinbutton to be set. | 2629 * handle: Handle to the spinbutton to be set. |
2630 * limit: Number of characters the entryfield will take. | 2630 * limit: Number of characters the entryfield will take. |
2631 */ | 2631 */ |
2632 void API dw_entryfield_set_limit(HWND handle, ULONG limit) | 2632 void API dw_entryfield_set_limit(HWND handle, ULONG limit) |
2633 { | 2633 { |
2634 NSLog(@"dw_entryfield_set_limit() unimplemented\n"); | 2634 NSLog(@"dw_entryfield_set_limit() unimplemented\n"); |
2635 } | 2635 } |
2636 | 2636 |
2637 /* | 2637 /* |
2638 * Create a new bitmap button window (widget) to be packed. | 2638 * Create a new bitmap button window (widget) to be packed. |
2639 * Parameters: | 2639 * Parameters: |
2720 * id: An ID to be used with dw_window_from_id() or 0L. | 2720 * id: An ID to be used with dw_window_from_id() or 0L. |
2721 */ | 2721 */ |
2722 HWND API dw_spinbutton_new(char *text, ULONG cid) | 2722 HWND API dw_spinbutton_new(char *text, ULONG cid) |
2723 { | 2723 { |
2724 DWSpinButton *spinbutton = [[DWSpinButton alloc] init]; | 2724 DWSpinButton *spinbutton = [[DWSpinButton alloc] init]; |
2725 NSStepper *stepper = [spinbutton stepper]; | 2725 NSStepper *stepper = [spinbutton stepper]; |
2726 [stepper setIncrement:1]; | 2726 [stepper setIncrement:1]; |
2727 [stepper setTag:cid]; | 2727 [stepper setTag:cid]; |
2728 return spinbutton; | 2728 return spinbutton; |
2729 } | 2729 } |
2730 | 2730 |
2735 * position: Current value of the spinbutton. | 2735 * position: Current value of the spinbutton. |
2736 */ | 2736 */ |
2737 void API dw_spinbutton_set_pos(HWND handle, long position) | 2737 void API dw_spinbutton_set_pos(HWND handle, long position) |
2738 { | 2738 { |
2739 DWSpinButton *spinbutton = handle; | 2739 DWSpinButton *spinbutton = handle; |
2740 NSStepper *stepper = [spinbutton stepper]; | 2740 NSStepper *stepper = [spinbutton stepper]; |
2741 NSTextField *textfield = [spinbutton textfield]; | 2741 NSTextField *textfield = [spinbutton textfield]; |
2742 [stepper setIntValue:(int)position]; | 2742 [stepper setIntValue:(int)position]; |
2743 [textfield takeIntValueFrom:stepper]; | 2743 [textfield takeIntValueFrom:stepper]; |
2744 } | 2744 } |
2745 | 2745 |
2751 * lower: Lower limit. | 2751 * lower: Lower limit. |
2752 */ | 2752 */ |
2753 void API dw_spinbutton_set_limits(HWND handle, long upper, long lower) | 2753 void API dw_spinbutton_set_limits(HWND handle, long upper, long lower) |
2754 { | 2754 { |
2755 DWSpinButton *spinbutton = handle; | 2755 DWSpinButton *spinbutton = handle; |
2756 NSStepper *stepper = [spinbutton stepper]; | 2756 NSStepper *stepper = [spinbutton stepper]; |
2757 [stepper setMinValue:(double)lower]; | 2757 [stepper setMinValue:(double)lower]; |
2758 [stepper setMaxValue:(double)upper]; | 2758 [stepper setMaxValue:(double)upper]; |
2759 } | 2759 } |
2760 | 2760 |
2761 /* | 2761 /* |
2764 * handle: Handle to the spinbutton to be queried. | 2764 * handle: Handle to the spinbutton to be queried. |
2765 */ | 2765 */ |
2766 long API dw_spinbutton_get_pos(HWND handle) | 2766 long API dw_spinbutton_get_pos(HWND handle) |
2767 { | 2767 { |
2768 DWSpinButton *spinbutton = handle; | 2768 DWSpinButton *spinbutton = handle; |
2769 NSStepper *stepper = [spinbutton stepper]; | 2769 NSStepper *stepper = [spinbutton stepper]; |
2770 return (long)[stepper integerValue]; | 2770 return (long)[stepper integerValue]; |
2771 } | 2771 } |
2772 | 2772 |
2773 /* | 2773 /* |
2774 * Create a new radiobutton window (widget) to be packed. | 2774 * Create a new radiobutton window (widget) to be packed. |
2776 * text: The text to be display by the static text widget. | 2776 * text: The text to be display by the static text widget. |
2777 * id: An ID to be used with dw_window_from_id() or 0L. | 2777 * id: An ID to be used with dw_window_from_id() or 0L. |
2778 */ | 2778 */ |
2779 HWND API dw_radiobutton_new(char *text, ULONG cid) | 2779 HWND API dw_radiobutton_new(char *text, ULONG cid) |
2780 { | 2780 { |
2781 DWButton *button = _button_new(text, cid); | 2781 DWButton *button = _button_new(text, cid); |
2782 [button setButtonType:NSRadioButton]; | 2782 [button setButtonType:NSRadioButton]; |
2783 return button; | 2783 return button; |
2784 } | 2784 } |
2785 | 2785 |
2786 /* | 2786 /* |
2787 * Create a new slider window (widget) to be packed. | 2787 * Create a new slider window (widget) to be packed. |
2788 * Parameters: | 2788 * Parameters: |
2807 * Parameters: | 2807 * Parameters: |
2808 * handle: Handle to the slider to be queried. | 2808 * handle: Handle to the slider to be queried. |
2809 */ | 2809 */ |
2810 unsigned int API dw_slider_get_pos(HWND handle) | 2810 unsigned int API dw_slider_get_pos(HWND handle) |
2811 { | 2811 { |
2812 DWSlider *slider = handle; | 2812 DWSlider *slider = handle; |
2813 double val = [slider doubleValue]; | 2813 double val = [slider doubleValue]; |
2814 return (int)val; | 2814 return (int)val; |
2815 } | 2815 } |
2816 | 2816 |
2817 /* | 2817 /* |
2818 * Sets the slider position. | 2818 * Sets the slider position. |
2819 * Parameters: | 2819 * Parameters: |
2820 * handle: Handle to the slider to be set. | 2820 * handle: Handle to the slider to be set. |
2821 * position: Position of the slider withing the range. | 2821 * position: Position of the slider withing the range. |
2822 */ | 2822 */ |
2823 void API dw_slider_set_pos(HWND handle, unsigned int position) | 2823 void API dw_slider_set_pos(HWND handle, unsigned int position) |
2824 { | 2824 { |
2825 DWSlider *slider = handle; | 2825 DWSlider *slider = handle; |
2826 [slider setDoubleValue:(double)position]; | 2826 [slider setDoubleValue:(double)position]; |
2827 } | 2827 } |
2828 | 2828 |
2829 /* | 2829 /* |
2830 * Create a new scrollbar window (widget) to be packed. | 2830 * Create a new scrollbar window (widget) to be packed. |
2831 * Parameters: | 2831 * Parameters: |
2861 * Parameters: | 2861 * Parameters: |
2862 * handle: Handle to the scrollbar to be queried. | 2862 * handle: Handle to the scrollbar to be queried. |
2863 */ | 2863 */ |
2864 unsigned int API dw_scrollbar_get_pos(HWND handle) | 2864 unsigned int API dw_scrollbar_get_pos(HWND handle) |
2865 { | 2865 { |
2866 DWScrollbar *scrollbar = handle; | 2866 DWScrollbar *scrollbar = handle; |
2867 float range = [scrollbar range]; | 2867 float range = [scrollbar range]; |
2868 float fresult = [scrollbar doubleValue] * range; | 2868 float fresult = [scrollbar doubleValue] * range; |
2869 return (int)fresult; | 2869 return (int)fresult; |
2870 } | 2870 } |
2871 | 2871 |
2872 /* | 2872 /* |
2873 * Sets the scrollbar position. | 2873 * Sets the scrollbar position. |
2874 * Parameters: | 2874 * Parameters: |
2875 * handle: Handle to the scrollbar to be set. | 2875 * handle: Handle to the scrollbar to be set. |
2876 * position: Position of the scrollbar withing the range. | 2876 * position: Position of the scrollbar withing the range. |
2877 */ | 2877 */ |
2878 void API dw_scrollbar_set_pos(HWND handle, unsigned int position) | 2878 void API dw_scrollbar_set_pos(HWND handle, unsigned int position) |
2879 { | 2879 { |
2880 DWScrollbar *scrollbar = handle; | 2880 DWScrollbar *scrollbar = handle; |
2881 double range = (double)[scrollbar range]; | 2881 double range = (double)[scrollbar range]; |
2882 double newpos = (double)position/range; | 2882 double newpos = (double)position/range; |
2883 [scrollbar setDoubleValue:newpos]; | 2883 [scrollbar setDoubleValue:newpos]; |
2884 } | 2884 } |
2885 | 2885 |
2886 /* | 2886 /* |
2887 * Sets the scrollbar range. | 2887 * Sets the scrollbar range. |
2888 * Parameters: | 2888 * Parameters: |
2890 * range: Maximum range value. | 2890 * range: Maximum range value. |
2891 * visible: Visible area relative to the range. | 2891 * visible: Visible area relative to the range. |
2892 */ | 2892 */ |
2893 void API dw_scrollbar_set_range(HWND handle, unsigned int range, unsigned int visible) | 2893 void API dw_scrollbar_set_range(HWND handle, unsigned int range, unsigned int visible) |
2894 { | 2894 { |
2895 DWScrollbar *scrollbar = handle; | 2895 DWScrollbar *scrollbar = handle; |
2896 float knob = (float)visible/(float)range; | 2896 float knob = (float)visible/(float)range; |
2897 [scrollbar setRange:(float)range andVisible:(float)visible]; | 2897 [scrollbar setRange:(float)range andVisible:(float)visible]; |
2898 [scrollbar setKnobProportion:knob]; | 2898 [scrollbar setKnobProportion:knob]; |
2899 } | 2899 } |
2900 | 2900 |
2901 /* | 2901 /* |
2902 * Create a new percent bar window (widget) to be packed. | 2902 * Create a new percent bar window (widget) to be packed. |
2903 * Parameters: | 2903 * Parameters: |
2904 * id: An ID to be used with dw_window_from_id() or 0L. | 2904 * id: An ID to be used with dw_window_from_id() or 0L. |
2905 */ | 2905 */ |
2906 HWND API dw_percent_new(ULONG cid) | 2906 HWND API dw_percent_new(ULONG cid) |
2907 { | 2907 { |
2908 DWPercent *percent = [[DWPercent alloc] init]; | 2908 DWPercent *percent = [[DWPercent alloc] init]; |
2909 [percent setStyle:NSProgressIndicatorBarStyle]; | 2909 [percent setStyle:NSProgressIndicatorBarStyle]; |
2910 [percent setBezeled:YES]; | 2910 [percent setBezeled:YES]; |
2911 [percent setMaxValue:100]; | 2911 [percent setMaxValue:100]; |
2912 [percent setMinValue:0]; | 2912 [percent setMinValue:0]; |
2913 [percent incrementBy:1]; | 2913 [percent incrementBy:1]; |
2914 [percent setIndeterminate:NO]; | 2914 [percent setIndeterminate:NO]; |
2915 /*[percent setTag:cid]; Why doesn't this work? */ | 2915 /*[percent setTag:cid]; Why doesn't this work? */ |
2916 return percent; | 2916 return percent; |
2917 } | 2917 } |
2918 | 2918 |
2919 /* | 2919 /* |
2920 * Sets the percent bar position. | 2920 * Sets the percent bar position. |
2921 * Parameters: | 2921 * Parameters: |
2922 * handle: Handle to the percent bar to be set. | 2922 * handle: Handle to the percent bar to be set. |
2923 * position: Position of the percent bar withing the range. | 2923 * position: Position of the percent bar withing the range. |
2924 */ | 2924 */ |
2925 void API dw_percent_set_pos(HWND handle, unsigned int position) | 2925 void API dw_percent_set_pos(HWND handle, unsigned int position) |
2926 { | 2926 { |
2927 DWPercent *percent = handle; | 2927 DWPercent *percent = handle; |
2928 [percent setDoubleValue:(double)position]; | 2928 [percent setDoubleValue:(double)position]; |
2929 } | 2929 } |
2930 | 2930 |
2931 /* | 2931 /* |
2932 * Create a new checkbox window (widget) to be packed. | 2932 * Create a new checkbox window (widget) to be packed. |
2933 * Parameters: | 2933 * Parameters: |
2934 * text: The text to be display by the static text widget. | 2934 * text: The text to be display by the static text widget. |
2935 * id: An ID to be used with dw_window_from_id() or 0L. | 2935 * id: An ID to be used with dw_window_from_id() or 0L. |
2936 */ | 2936 */ |
2937 HWND API dw_checkbox_new(char *text, ULONG cid) | 2937 HWND API dw_checkbox_new(char *text, ULONG cid) |
2938 { | 2938 { |
2939 DWButton *button = _button_new(text, cid); | 2939 DWButton *button = _button_new(text, cid); |
2940 [button setButtonType:NSSwitchButton]; | 2940 [button setButtonType:NSSwitchButton]; |
2941 [button setBezelStyle:NSRegularSquareBezelStyle]; | 2941 [button setBezelStyle:NSRegularSquareBezelStyle]; |
2942 return button; | 2942 return button; |
2943 } | 2943 } |
2944 | 2944 |
2945 /* | 2945 /* |
2946 * Returns the state of the checkbox. | 2946 * Returns the state of the checkbox. |
2947 * Parameters: | 2947 * Parameters: |
2948 * handle: Handle to the checkbox to be queried. | 2948 * handle: Handle to the checkbox to be queried. |
2949 */ | 2949 */ |
2950 int API dw_checkbox_get(HWND handle) | 2950 int API dw_checkbox_get(HWND handle) |
2951 { | 2951 { |
2952 DWButton *button = handle; | 2952 DWButton *button = handle; |
2953 if([button state]) | 2953 if([button state]) |
2954 { | 2954 { |
2955 return TRUE; | 2955 return TRUE; |
2956 } | 2956 } |
2957 return FALSE; | 2957 return FALSE; |
2958 } | 2958 } |
2959 | 2959 |
2960 /* | 2960 /* |
2961 * Sets the state of the checkbox. | 2961 * Sets the state of the checkbox. |
2962 * Parameters: | 2962 * Parameters: |
2963 * handle: Handle to the checkbox to be queried. | 2963 * handle: Handle to the checkbox to be queried. |
2964 * value: TRUE for checked, FALSE for unchecked. | 2964 * value: TRUE for checked, FALSE for unchecked. |
2965 */ | 2965 */ |
2966 void API dw_checkbox_set(HWND handle, int value) | 2966 void API dw_checkbox_set(HWND handle, int value) |
2967 { | 2967 { |
2968 DWButton *button = handle; | 2968 DWButton *button = handle; |
2969 if(value) | 2969 if(value) |
2970 { | 2970 { |
2971 [button setState:NSOnState]; | 2971 [button setState:NSOnState]; |
2972 } | 2972 } |
2973 else | 2973 else |
2974 { | 2974 { |
2975 [button setState:NSOffState]; | 2975 [button setState:NSOffState]; |
2976 } | 2976 } |
2977 | 2977 |
2978 } | 2978 } |
2979 | 2979 |
2980 /* Common code for containers and listboxes */ | 2980 /* Common code for containers and listboxes */ |
2981 HWND _cont_new(ULONG cid, int multi) | 2981 HWND _cont_new(ULONG cid, int multi) |
2982 { | 2982 { |
2983 NSScrollView *scrollview = [[NSScrollView alloc] init]; | 2983 NSScrollView *scrollview = [[NSScrollView alloc] init]; |
2984 DWContainer *cont = [[DWContainer alloc] init]; | 2984 DWContainer *cont = [[DWContainer alloc] init]; |
2985 | 2985 |
2986 [cont setScrollview:scrollview]; | 2986 [cont setScrollview:scrollview]; |
2987 [scrollview setBorderType:NSBezelBorder]; | 2987 [scrollview setBorderType:NSBezelBorder]; |
2988 [scrollview setHasVerticalScroller:YES]; | 2988 [scrollview setHasVerticalScroller:YES]; |
2989 [scrollview setAutohidesScrollers:YES]; | 2989 [scrollview setAutohidesScrollers:YES]; |
2990 | 2990 |
2991 if(multi) | 2991 if(multi) |
2992 { | 2992 { |
2993 [cont setAllowsMultipleSelection:YES]; | 2993 [cont setAllowsMultipleSelection:YES]; |
2994 } | 2994 } |
2995 else | 2995 else |
2996 { | 2996 { |
2997 [cont setAllowsMultipleSelection:NO]; | 2997 [cont setAllowsMultipleSelection:NO]; |
2998 } | 2998 } |
2999 [cont setDataSource:cont]; | 2999 [cont setDataSource:cont]; |
3000 [scrollview setDocumentView:cont]; | 3000 [scrollview setDocumentView:cont]; |
3001 [cont setTag:cid]; | 3001 [cont setTag:cid]; |
3002 [scrollview release]; | 3002 [scrollview release]; |
3003 return cont; | 3003 return cont; |
3004 } | 3004 } |
3005 | 3005 |
3006 /* | 3006 /* |
3007 * Create a new listbox window (widget) to be packed. | 3007 * Create a new listbox window (widget) to be packed. |
3008 * Parameters: | 3008 * Parameters: |
3011 */ | 3011 */ |
3012 HWND API dw_listbox_new(ULONG cid, int multi) | 3012 HWND API dw_listbox_new(ULONG cid, int multi) |
3013 { | 3013 { |
3014 int _locked_by_me = FALSE; | 3014 int _locked_by_me = FALSE; |
3015 DW_MUTEX_LOCK; | 3015 DW_MUTEX_LOCK; |
3016 DWContainer *cont = _cont_new(cid, multi); | 3016 DWContainer *cont = _cont_new(cid, multi); |
3017 [cont setHeaderView:nil]; | 3017 [cont setHeaderView:nil]; |
3018 int type = DW_CFA_STRING; | 3018 int type = DW_CFA_STRING; |
3019 [cont setup]; | 3019 [cont setup]; |
3020 NSTableColumn *column = [[NSTableColumn alloc] init]; | 3020 NSTableColumn *column = [[NSTableColumn alloc] init]; |
3021 [cont addTableColumn:column]; | 3021 [cont addTableColumn:column]; |
3022 [cont addColumn:column andType:type]; | 3022 [cont addColumn:column andType:type]; |
3023 [column release]; | 3023 [column release]; |
3024 DW_MUTEX_UNLOCK; | 3024 DW_MUTEX_UNLOCK; |
3025 return cont; | 3025 return cont; |
3026 } | 3026 } |
3027 | 3027 |
3028 /* | 3028 /* |
3029 * Appends the specified text to the listbox's (or combobox) entry list. | 3029 * Appends the specified text to the listbox's (or combobox) entry list. |
3030 * Parameters: | 3030 * Parameters: |
3033 */ | 3033 */ |
3034 void API dw_listbox_append(HWND handle, char *text) | 3034 void API dw_listbox_append(HWND handle, char *text) |
3035 { | 3035 { |
3036 int _locked_by_me = FALSE; | 3036 int _locked_by_me = FALSE; |
3037 DW_MUTEX_LOCK; | 3037 DW_MUTEX_LOCK; |
3038 id object = handle; | 3038 id object = handle; |
3039 | 3039 |
3040 if([object isMemberOfClass:[DWComboBox class]]) | 3040 if([object isMemberOfClass:[DWComboBox class]]) |
3041 { | 3041 { |
3042 DWComboBox *combo = handle; | 3042 DWComboBox *combo = handle; |
3043 | 3043 |
3044 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text ]]; | 3044 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text ]]; |
3045 } | 3045 } |
3046 else if([object isMemberOfClass:[DWContainer class]]) | 3046 else if([object isMemberOfClass:[DWContainer class]]) |
3047 { | 3047 { |
3048 DWContainer *cont = handle; | 3048 DWContainer *cont = handle; |
3049 NSString *nstr = [ NSString stringWithUTF8String:text ]; | 3049 NSString *nstr = [ NSString stringWithUTF8String:text ]; |
3050 NSArray *newrow = [NSArray arrayWithObject:nstr]; | 3050 NSArray *newrow = [NSArray arrayWithObject:nstr]; |
3067 */ | 3067 */ |
3068 void API dw_listbox_insert(HWND handle, char *text, int pos) | 3068 void API dw_listbox_insert(HWND handle, char *text, int pos) |
3069 { | 3069 { |
3070 int _locked_by_me = FALSE; | 3070 int _locked_by_me = FALSE; |
3071 DW_MUTEX_LOCK; | 3071 DW_MUTEX_LOCK; |
3072 id object = handle; | 3072 id object = handle; |
3073 | 3073 |
3074 if([object isMemberOfClass:[DWComboBox class]]) | 3074 if([object isMemberOfClass:[DWComboBox class]]) |
3075 { | 3075 { |
3076 DWComboBox *combo = handle; | 3076 DWComboBox *combo = handle; |
3077 | 3077 |
3078 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:text ] atIndex:pos]; | 3078 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:text ] atIndex:pos]; |
3079 } | 3079 } |
3080 else if([object isMemberOfClass:[DWContainer class]]) | 3080 else if([object isMemberOfClass:[DWContainer class]]) |
3081 { | 3081 { |
3082 DWContainer *cont = handle; | 3082 DWContainer *cont = handle; |
3083 NSString *nstr = [ NSString stringWithUTF8String:text ]; | 3083 NSString *nstr = [ NSString stringWithUTF8String:text ]; |
3084 NSArray *newrow = [NSArray arrayWithObject:nstr]; | 3084 NSArray *newrow = [NSArray arrayWithObject:nstr]; |
3098 */ | 3098 */ |
3099 void API dw_listbox_list_append(HWND handle, char **text, int count) | 3099 void API dw_listbox_list_append(HWND handle, char **text, int count) |
3100 { | 3100 { |
3101 int _locked_by_me = FALSE; | 3101 int _locked_by_me = FALSE; |
3102 DW_MUTEX_LOCK; | 3102 DW_MUTEX_LOCK; |
3103 id object = handle; | 3103 id object = handle; |
3104 | 3104 |
3105 if([object isMemberOfClass:[DWComboBox class]]) | 3105 if([object isMemberOfClass:[DWComboBox class]]) |
3106 { | 3106 { |
3107 DWComboBox *combo = handle; | 3107 DWComboBox *combo = handle; |
3108 int z; | 3108 int z; |
3109 | 3109 |
3110 for(z=0;z<count;z++) | 3110 for(z=0;z<count;z++) |
3111 { | 3111 { |
3112 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text[z] ]]; | 3112 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text[z] ]]; |
3113 } | 3113 } |
3114 } | 3114 } |
3115 else if([object isMemberOfClass:[DWContainer class]]) | 3115 else if([object isMemberOfClass:[DWContainer class]]) |
3116 { | 3116 { |
3117 DWContainer *cont = handle; | 3117 DWContainer *cont = handle; |
3118 int z; | 3118 int z; |
3119 | 3119 |
3120 for(z=0;z<count;z++) | 3120 for(z=0;z<count;z++) |
3121 { | 3121 { |
3122 NSString *nstr = [ NSString stringWithUTF8String:text[z] ]; | 3122 NSString *nstr = [ NSString stringWithUTF8String:text[z] ]; |
3123 NSArray *newrow = [[NSArray alloc] arrayWithObject:nstr]; | 3123 NSArray *newrow = [[NSArray alloc] arrayWithObject:nstr]; |
3124 | 3124 |
3125 [cont addRow:newrow]; | 3125 [cont addRow:newrow]; |
3126 } | 3126 } |
3136 */ | 3136 */ |
3137 void API dw_listbox_clear(HWND handle) | 3137 void API dw_listbox_clear(HWND handle) |
3138 { | 3138 { |
3139 int _locked_by_me = FALSE; | 3139 int _locked_by_me = FALSE; |
3140 DW_MUTEX_LOCK; | 3140 DW_MUTEX_LOCK; |
3141 id object = handle; | 3141 id object = handle; |
3142 | 3142 |
3143 if([object isMemberOfClass:[DWComboBox class]]) | 3143 if([object isMemberOfClass:[DWComboBox class]]) |
3144 { | 3144 { |
3145 DWComboBox *combo = handle; | 3145 DWComboBox *combo = handle; |
3146 | 3146 |
3147 [combo removeAllItems]; | 3147 [combo removeAllItems]; |
3148 } | 3148 } |
3149 else if([object isMemberOfClass:[DWContainer class]]) | 3149 else if([object isMemberOfClass:[DWContainer class]]) |
3150 { | 3150 { |
3151 DWContainer *cont = handle; | 3151 DWContainer *cont = handle; |
3152 | 3152 |
3153 [cont clear]; | 3153 [cont clear]; |
3161 * Parameters: | 3161 * Parameters: |
3162 * handle: Handle to the listbox to be cleared. | 3162 * handle: Handle to the listbox to be cleared. |
3163 */ | 3163 */ |
3164 int API dw_listbox_count(HWND handle) | 3164 int API dw_listbox_count(HWND handle) |
3165 { | 3165 { |
3166 id object = handle; | 3166 id object = handle; |
3167 | 3167 |
3168 if([object isMemberOfClass:[DWComboBox class]]) | 3168 if([object isMemberOfClass:[DWComboBox class]]) |
3169 { | 3169 { |
3170 DWComboBox *combo = handle; | 3170 DWComboBox *combo = handle; |
3171 | 3171 |
3172 return (int)[combo numberOfItems]; | 3172 return (int)[combo numberOfItems]; |
3173 } | 3173 } |
3174 else if([object isMemberOfClass:[DWContainer class]]) | 3174 else if([object isMemberOfClass:[DWContainer class]]) |
3175 { | 3175 { |
3176 int _locked_by_me = FALSE; | 3176 int _locked_by_me = FALSE; |
3177 DW_MUTEX_LOCK; | 3177 DW_MUTEX_LOCK; |
3178 DWContainer *cont = handle; | 3178 DWContainer *cont = handle; |
3179 int result = (int)[cont numberOfRowsInTableView:cont]; | 3179 int result = (int)[cont numberOfRowsInTableView:cont]; |
3180 DW_MUTEX_UNLOCK; | 3180 DW_MUTEX_UNLOCK; |
3181 return result; | 3181 return result; |
3182 } | 3182 } |
3183 return 0; | 3183 return 0; |
3184 } | 3184 } |
3185 | 3185 |
3186 /* | 3186 /* |
3187 * Sets the topmost item in the viewport. | 3187 * Sets the topmost item in the viewport. |
3188 * Parameters: | 3188 * Parameters: |
3191 */ | 3191 */ |
3192 void API dw_listbox_set_top(HWND handle, int top) | 3192 void API dw_listbox_set_top(HWND handle, int top) |
3193 { | 3193 { |
3194 int _locked_by_me = FALSE; | 3194 int _locked_by_me = FALSE; |
3195 DW_MUTEX_LOCK; | 3195 DW_MUTEX_LOCK; |
3196 id object = handle; | 3196 id object = handle; |
3197 | 3197 |
3198 if([object isMemberOfClass:[DWComboBox class]]) | 3198 if([object isMemberOfClass:[DWComboBox class]]) |
3199 { | 3199 { |
3200 DWComboBox *combo = handle; | 3200 DWComboBox *combo = handle; |
3201 | 3201 |
3202 [combo scrollItemAtIndexToTop:top]; | 3202 [combo scrollItemAtIndexToTop:top]; |
3203 } | 3203 } |
3204 else if([object isMemberOfClass:[DWContainer class]]) | 3204 else if([object isMemberOfClass:[DWContainer class]]) |
3205 { | 3205 { |
3206 DWContainer *cont = handle; | 3206 DWContainer *cont = handle; |
3207 | 3207 |
3208 [cont scrollRowToVisible:top]; | 3208 [cont scrollRowToVisible:top]; |
3220 */ | 3220 */ |
3221 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) | 3221 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) |
3222 { | 3222 { |
3223 int _locked_by_me = FALSE; | 3223 int _locked_by_me = FALSE; |
3224 DW_MUTEX_LOCK; | 3224 DW_MUTEX_LOCK; |
3225 id object = handle; | 3225 id object = handle; |
3226 | 3226 |
3227 if([object isMemberOfClass:[DWComboBox class]]) | 3227 if([object isMemberOfClass:[DWComboBox class]]) |
3228 { | 3228 { |
3229 DWComboBox *combo = handle; | 3229 DWComboBox *combo = handle; |
3230 int count = (int)[combo numberOfItems]; | 3230 int count = (int)[combo numberOfItems]; |
3231 | 3231 |
3232 if(index > count) | 3232 if(index > count) |
3233 { | 3233 { |
3234 *buffer = '\0'; | 3234 *buffer = '\0'; |
3236 else | 3236 else |
3237 { | 3237 { |
3238 NSString *nstr = [combo itemObjectValueAtIndex:index]; | 3238 NSString *nstr = [combo itemObjectValueAtIndex:index]; |
3239 strncpy(buffer, [ nstr UTF8String ], length - 1); | 3239 strncpy(buffer, [ nstr UTF8String ], length - 1); |
3240 } | 3240 } |
3241 } | 3241 } |
3242 else if([object isMemberOfClass:[DWContainer class]]) | 3242 else if([object isMemberOfClass:[DWContainer class]]) |
3243 { | 3243 { |
3244 DWContainer *cont = handle; | 3244 DWContainer *cont = handle; |
3245 int count = (int)[cont numberOfRowsInTableView:cont]; | 3245 int count = (int)[cont numberOfRowsInTableView:cont]; |
3246 | 3246 |
3267 */ | 3267 */ |
3268 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer) | 3268 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer) |
3269 { | 3269 { |
3270 int _locked_by_me = FALSE; | 3270 int _locked_by_me = FALSE; |
3271 DW_MUTEX_LOCK; | 3271 DW_MUTEX_LOCK; |
3272 id object = handle; | 3272 id object = handle; |
3273 | 3273 |
3274 if([object isMemberOfClass:[DWComboBox class]]) | 3274 if([object isMemberOfClass:[DWComboBox class]]) |
3275 { | 3275 { |
3276 DWComboBox *combo = handle; | 3276 DWComboBox *combo = handle; |
3277 int count = (int)[combo numberOfItems]; | 3277 int count = (int)[combo numberOfItems]; |
3278 | 3278 |
3279 if(index <= count) | 3279 if(index <= count) |
3280 { | 3280 { |
3281 [combo removeItemAtIndex:index]; | 3281 [combo removeItemAtIndex:index]; |
3282 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:buffer ] atIndex:index]; | 3282 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:buffer ] atIndex:index]; |
3283 } | 3283 } |
3284 } | 3284 } |
3285 else if([object isMemberOfClass:[DWContainer class]]) | 3285 else if([object isMemberOfClass:[DWContainer class]]) |
3286 { | 3286 { |
3287 DWContainer *cont = handle; | 3287 DWContainer *cont = handle; |
3288 int count = (int)[cont numberOfRowsInTableView:cont]; | 3288 int count = (int)[cont numberOfRowsInTableView:cont]; |
3289 | 3289 |
3303 * Parameters: | 3303 * Parameters: |
3304 * handle: Handle to the listbox to be queried. | 3304 * handle: Handle to the listbox to be queried. |
3305 */ | 3305 */ |
3306 unsigned int API dw_listbox_selected(HWND handle) | 3306 unsigned int API dw_listbox_selected(HWND handle) |
3307 { | 3307 { |
3308 id object = handle; | 3308 id object = handle; |
3309 | 3309 |
3310 if([object isMemberOfClass:[DWComboBox class]]) | 3310 if([object isMemberOfClass:[DWComboBox class]]) |
3311 { | 3311 { |
3312 DWComboBox *combo = handle; | 3312 DWComboBox *combo = handle; |
3313 return (int)[combo indexOfSelectedItem]; | 3313 return (int)[combo indexOfSelectedItem]; |
3314 } | 3314 } |
3315 else if([object isMemberOfClass:[DWContainer class]]) | 3315 else if([object isMemberOfClass:[DWContainer class]]) |
3316 { | 3316 { |
3317 int _locked_by_me = FALSE; | 3317 int _locked_by_me = FALSE; |
3318 DW_MUTEX_LOCK; | 3318 DW_MUTEX_LOCK; |
3319 DWContainer *cont = handle; | 3319 DWContainer *cont = handle; |
3320 int result = (int)[cont selectedRow]; | 3320 int result = (int)[cont selectedRow]; |
3321 DW_MUTEX_UNLOCK; | 3321 DW_MUTEX_UNLOCK; |
3322 return result; | 3322 return result; |
3323 } | 3323 } |
3324 return -1; | 3324 return -1; |
3325 } | 3325 } |
3326 | 3326 |
3327 /* | 3327 /* |
3328 * Returns the index to the current selected item or -1 when done. | 3328 * Returns the index to the current selected item or -1 when done. |
3329 * Parameters: | 3329 * Parameters: |
3332 */ | 3332 */ |
3333 int API dw_listbox_selected_multi(HWND handle, int where) | 3333 int API dw_listbox_selected_multi(HWND handle, int where) |
3334 { | 3334 { |
3335 int _locked_by_me = FALSE; | 3335 int _locked_by_me = FALSE; |
3336 DW_MUTEX_LOCK; | 3336 DW_MUTEX_LOCK; |
3337 id object = handle; | 3337 id object = handle; |
3338 int retval = -1; | 3338 int retval = -1; |
3339 | 3339 |
3340 if([object isMemberOfClass:[DWContainer class]]) | 3340 if([object isMemberOfClass:[DWContainer class]]) |
3341 { | 3341 { |
3342 DWContainer *cont = handle; | 3342 DWContainer *cont = handle; |
3347 { | 3347 { |
3348 retval = (int)result; | 3348 retval = (int)result; |
3349 } | 3349 } |
3350 } | 3350 } |
3351 DW_MUTEX_UNLOCK; | 3351 DW_MUTEX_UNLOCK; |
3352 return retval; | 3352 return retval; |
3353 } | 3353 } |
3354 | 3354 |
3355 /* | 3355 /* |
3356 * Sets the selection state of a given index. | 3356 * Sets the selection state of a given index. |
3357 * Parameters: | 3357 * Parameters: |
3361 */ | 3361 */ |
3362 void API dw_listbox_select(HWND handle, int index, int state) | 3362 void API dw_listbox_select(HWND handle, int index, int state) |
3363 { | 3363 { |
3364 int _locked_by_me = FALSE; | 3364 int _locked_by_me = FALSE; |
3365 DW_MUTEX_LOCK; | 3365 DW_MUTEX_LOCK; |
3366 id object = handle; | 3366 id object = handle; |
3367 | 3367 |
3368 if([object isMemberOfClass:[DWComboBox class]]) | 3368 if([object isMemberOfClass:[DWComboBox class]]) |
3369 { | 3369 { |
3370 DWComboBox *combo = handle; | 3370 DWComboBox *combo = handle; |
3371 if(state) | 3371 if(state) |
3372 [combo selectItemAtIndex:index]; | 3372 [combo selectItemAtIndex:index]; |
3373 else | 3373 else |
3374 [combo deselectItemAtIndex:index]; | 3374 [combo deselectItemAtIndex:index]; |
3375 } | 3375 } |
3376 else if([object isMemberOfClass:[DWContainer class]]) | 3376 else if([object isMemberOfClass:[DWContainer class]]) |
3377 { | 3377 { |
3378 DWContainer *cont = handle; | 3378 DWContainer *cont = handle; |
3379 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)index]; | 3379 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)index]; |
3380 | 3380 |
3392 */ | 3392 */ |
3393 void API dw_listbox_delete(HWND handle, int index) | 3393 void API dw_listbox_delete(HWND handle, int index) |
3394 { | 3394 { |
3395 int _locked_by_me = FALSE; | 3395 int _locked_by_me = FALSE; |
3396 DW_MUTEX_LOCK; | 3396 DW_MUTEX_LOCK; |
3397 id object = handle; | 3397 id object = handle; |
3398 | 3398 |
3399 if([object isMemberOfClass:[DWComboBox class]]) | 3399 if([object isMemberOfClass:[DWComboBox class]]) |
3400 { | 3400 { |
3401 DWComboBox *combo = handle; | 3401 DWComboBox *combo = handle; |
3402 | 3402 |
3403 [combo removeItemAtIndex:index]; | 3403 [combo removeItemAtIndex:index]; |
3404 } | 3404 } |
3405 else if([object isMemberOfClass:[DWContainer class]]) | 3405 else if([object isMemberOfClass:[DWContainer class]]) |
3406 { | 3406 { |
3407 DWContainer *cont = handle; | 3407 DWContainer *cont = handle; |
3408 | 3408 |
3409 [cont removeRow:index]; | 3409 [cont removeRow:index]; |
3418 * text: The default text to be in the combpbox widget. | 3418 * text: The default text to be in the combpbox widget. |
3419 * id: An ID to be used with dw_window_from_id() or 0L. | 3419 * id: An ID to be used with dw_window_from_id() or 0L. |
3420 */ | 3420 */ |
3421 HWND API dw_combobox_new(char *text, ULONG cid) | 3421 HWND API dw_combobox_new(char *text, ULONG cid) |
3422 { | 3422 { |
3423 DWComboBox *combo = [[DWComboBox alloc] init]; | 3423 DWComboBox *combo = [[DWComboBox alloc] init]; |
3424 [combo setDelegate:combo]; | 3424 [combo setDelegate:combo]; |
3425 [combo setTag:cid]; | 3425 [combo setTag:cid]; |
3426 return combo; | 3426 return combo; |
3427 } | 3427 } |
3428 | 3428 |
3429 /* | 3429 /* |
3430 * Create a new Multiline Editbox window (widget) to be packed. | 3430 * Create a new Multiline Editbox window (widget) to be packed. |
3431 * Parameters: | 3431 * Parameters: |
3432 * id: An ID to be used with dw_window_from_id() or 0L. | 3432 * id: An ID to be used with dw_window_from_id() or 0L. |
3433 */ | 3433 */ |
3434 HWND API dw_mle_new(ULONG cid) | 3434 HWND API dw_mle_new(ULONG cid) |
3435 { | 3435 { |
3436 DWMLE *mle = [[DWMLE alloc] init]; | 3436 DWMLE *mle = [[DWMLE alloc] init]; |
3437 NSScrollView *scrollview = [[NSScrollView alloc] init]; | 3437 NSScrollView *scrollview = [[NSScrollView alloc] init]; |
3438 | 3438 |
3439 [scrollview setBorderType:NSBezelBorder]; | 3439 [scrollview setBorderType:NSBezelBorder]; |
3440 [scrollview setHasVerticalScroller:YES]; | 3440 [scrollview setHasVerticalScroller:YES]; |
3441 [scrollview setAutohidesScrollers:YES]; | 3441 [scrollview setAutohidesScrollers:YES]; |
3442 [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; | 3442 [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; |
3443 [scrollview setDocumentView:mle]; | 3443 [scrollview setDocumentView:mle]; |
3444 [mle setAutoresizingMask:NSViewWidthSizable]; | 3444 [mle setAutoresizingMask:NSViewWidthSizable]; |
3445 /* [mle setTag:cid]; Why doesn't this work? */ | 3445 /* [mle setTag:cid]; Why doesn't this work? */ |
3446 [mle release]; | 3446 [mle release]; |
3447 return scrollview; | 3447 return scrollview; |
3448 } | 3448 } |
3449 | 3449 |
3450 /* | 3450 /* |
3451 * Adds text to an MLE box and returns the current point. | 3451 * Adds text to an MLE box and returns the current point. |
3452 * Parameters: | 3452 * Parameters: |
3453 * handle: Handle to the MLE to be queried. | 3453 * handle: Handle to the MLE to be queried. |
3455 * startpoint: Point to start entering text. | 3455 * startpoint: Point to start entering text. |
3456 */ | 3456 */ |
3457 unsigned int API dw_mle_import(HWND handle, char *buffer, int startpoint) | 3457 unsigned int API dw_mle_import(HWND handle, char *buffer, int startpoint) |
3458 { | 3458 { |
3459 NSScrollView *sv = handle; | 3459 NSScrollView *sv = handle; |
3460 DWMLE *mle = [sv documentView]; | 3460 DWMLE *mle = [sv documentView]; |
3461 NSTextStorage *ts = [mle textStorage]; | 3461 NSTextStorage *ts = [mle textStorage]; |
3462 NSString *nstr = [NSString stringWithUTF8String:buffer]; | 3462 NSString *nstr = [NSString stringWithUTF8String:buffer]; |
3463 NSMutableString *ms = [ts mutableString]; | 3463 NSMutableString *ms = [ts mutableString]; |
3464 [ms insertString:nstr atIndex:(startpoint+1)]; | 3464 [ms insertString:nstr atIndex:(startpoint+1)]; |
3465 return (unsigned int)strlen(buffer) + startpoint; | 3465 return (unsigned int)strlen(buffer) + startpoint; |
3466 } | 3466 } |
3467 | 3467 |
3468 /* | 3468 /* |
3469 * Grabs text from an MLE box. | 3469 * Grabs text from an MLE box. |
3470 * Parameters: | 3470 * Parameters: |
3474 * length: Amount of text to be grabbed. | 3474 * length: Amount of text to be grabbed. |
3475 */ | 3475 */ |
3476 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length) | 3476 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length) |
3477 { | 3477 { |
3478 NSScrollView *sv = handle; | 3478 NSScrollView *sv = handle; |
3479 DWMLE *mle = [sv documentView]; | 3479 DWMLE *mle = [sv documentView]; |
3480 NSTextStorage *ts = [mle textStorage]; | 3480 NSTextStorage *ts = [mle textStorage]; |
3481 NSMutableString *ms = [ts mutableString]; | 3481 NSMutableString *ms = [ts mutableString]; |
3482 strncpy(buffer, [ms UTF8String], length); | 3482 strncpy(buffer, [ms UTF8String], length); |
3483 } | 3483 } |
3484 | 3484 |
3490 * lines: A pointer to a variable to return the number of lines. | 3490 * lines: A pointer to a variable to return the number of lines. |
3491 */ | 3491 */ |
3492 void API dw_mle_get_size(HWND handle, unsigned long *bytes, unsigned long *lines) | 3492 void API dw_mle_get_size(HWND handle, unsigned long *bytes, unsigned long *lines) |
3493 { | 3493 { |
3494 NSScrollView *sv = handle; | 3494 NSScrollView *sv = handle; |
3495 DWMLE *mle = [sv documentView]; | 3495 DWMLE *mle = [sv documentView]; |
3496 NSTextStorage *ts = [mle textStorage]; | 3496 NSTextStorage *ts = [mle textStorage]; |
3497 NSMutableString *ms = [ts mutableString]; | 3497 NSMutableString *ms = [ts mutableString]; |
3498 | 3498 |
3499 *bytes = [ms length]; | 3499 *bytes = [ms length]; |
3500 *lines = 0; /* TODO: Line count */ | 3500 *lines = 0; /* TODO: Line count */ |
3508 * length: Amount of text to be deleted. | 3508 * length: Amount of text to be deleted. |
3509 */ | 3509 */ |
3510 void API dw_mle_delete(HWND handle, int startpoint, int length) | 3510 void API dw_mle_delete(HWND handle, int startpoint, int length) |
3511 { | 3511 { |
3512 NSScrollView *sv = handle; | 3512 NSScrollView *sv = handle; |
3513 DWMLE *mle = [sv documentView]; | 3513 DWMLE *mle = [sv documentView]; |
3514 NSTextStorage *ts = [mle textStorage]; | 3514 NSTextStorage *ts = [mle textStorage]; |
3515 NSMutableString *ms = [ts mutableString]; | 3515 NSMutableString *ms = [ts mutableString]; |
3516 [ms deleteCharactersInRange:NSMakeRange(startpoint+1, length)]; | 3516 [ms deleteCharactersInRange:NSMakeRange(startpoint+1, length)]; |
3517 } | 3517 } |
3518 | 3518 |
3522 * handle: Handle to the MLE to be cleared. | 3522 * handle: Handle to the MLE to be cleared. |
3523 */ | 3523 */ |
3524 void API dw_mle_clear(HWND handle) | 3524 void API dw_mle_clear(HWND handle) |
3525 { | 3525 { |
3526 NSScrollView *sv = handle; | 3526 NSScrollView *sv = handle; |
3527 DWMLE *mle = [sv documentView]; | 3527 DWMLE *mle = [sv documentView]; |
3528 NSTextStorage *ts = [mle textStorage]; | 3528 NSTextStorage *ts = [mle textStorage]; |
3529 NSMutableString *ms = [ts mutableString]; | 3529 NSMutableString *ms = [ts mutableString]; |
3530 NSUInteger length = [ms length]; | 3530 NSUInteger length = [ms length]; |
3531 [ms deleteCharactersInRange:NSMakeRange(0, length)]; | 3531 [ms deleteCharactersInRange:NSMakeRange(0, length)]; |
3532 } | 3532 } |
3538 * line: Line to be visible. | 3538 * line: Line to be visible. |
3539 */ | 3539 */ |
3540 void API dw_mle_set_visible(HWND handle, int line) | 3540 void API dw_mle_set_visible(HWND handle, int line) |
3541 { | 3541 { |
3542 /*NSScrollView *sv = handle; | 3542 /*NSScrollView *sv = handle; |
3543 DWMLE *mle = [sv documentView]; | 3543 DWMLE *mle = [sv documentView]; |
3544 [mle scrollrangeToVisible:NSMakeRange(0,13)];*/ | 3544 [mle scrollrangeToVisible:NSMakeRange(0,13)];*/ |
3545 NSLog(@"dw_mle_set_visible() unimplemented\n"); | 3545 NSLog(@"dw_mle_set_visible() unimplemented\n"); |
3546 } | 3546 } |
3547 | 3547 |
3548 /* | 3548 /* |
3549 * Sets the editablity of an MLE box. | 3549 * Sets the editablity of an MLE box. |
3550 * Parameters: | 3550 * Parameters: |
3552 * state: TRUE if it can be edited, FALSE for readonly. | 3552 * state: TRUE if it can be edited, FALSE for readonly. |
3553 */ | 3553 */ |
3554 void API dw_mle_set_editable(HWND handle, int state) | 3554 void API dw_mle_set_editable(HWND handle, int state) |
3555 { | 3555 { |
3556 NSScrollView *sv = handle; | 3556 NSScrollView *sv = handle; |
3557 DWMLE *mle = [sv documentView]; | 3557 DWMLE *mle = [sv documentView]; |
3558 if(state) | 3558 if(state) |
3559 { | 3559 { |
3560 [mle setEditable:YES]; | 3560 [mle setEditable:YES]; |
3561 } | 3561 } |
3562 else | 3562 else |
3563 { | 3563 { |
3564 [mle setEditable:NO]; | 3564 [mle setEditable:NO]; |
3565 } | 3565 } |
3566 } | 3566 } |
3567 | 3567 |
3568 /* | 3568 /* |
3569 * Sets the word wrap state of an MLE box. | 3569 * Sets the word wrap state of an MLE box. |
3570 * Parameters: | 3570 * Parameters: |
3572 * state: TRUE if it wraps, FALSE if it doesn't. | 3572 * state: TRUE if it wraps, FALSE if it doesn't. |
3573 */ | 3573 */ |
3574 void API dw_mle_set_word_wrap(HWND handle, int state) | 3574 void API dw_mle_set_word_wrap(HWND handle, int state) |
3575 { | 3575 { |
3576 NSScrollView *sv = handle; | 3576 NSScrollView *sv = handle; |
3577 DWMLE *mle = [sv documentView]; | 3577 DWMLE *mle = [sv documentView]; |
3578 if(state) | 3578 if(state) |
3579 { | 3579 { |
3580 [mle setHorizontallyResizable:NO]; | 3580 [mle setHorizontallyResizable:NO]; |
3581 } | 3581 } |
3582 else | 3582 else |
3592 * point: Point to position cursor. | 3592 * point: Point to position cursor. |
3593 */ | 3593 */ |
3594 void API dw_mle_set_cursor(HWND handle, int point) | 3594 void API dw_mle_set_cursor(HWND handle, int point) |
3595 { | 3595 { |
3596 NSScrollView *sv = handle; | 3596 NSScrollView *sv = handle; |
3597 DWMLE *mle = [sv documentView]; | 3597 DWMLE *mle = [sv documentView]; |
3598 [mle setSelectedRange: NSMakeRange(point,point)]; | 3598 [mle setSelectedRange: NSMakeRange(point,point)]; |
3599 } | 3599 } |
3600 | 3600 |
3601 /* | 3601 /* |
3602 * Finds text in an MLE box. | 3602 * Finds text in an MLE box. |
3606 * point: Start point of search. | 3606 * point: Start point of search. |
3607 * flags: Search specific flags. | 3607 * flags: Search specific flags. |
3608 */ | 3608 */ |
3609 int API dw_mle_search(HWND handle, char *text, int point, unsigned long flags) | 3609 int API dw_mle_search(HWND handle, char *text, int point, unsigned long flags) |
3610 { | 3610 { |
3611 NSLog(@"dw_mle_search() unimplemented\n"); | 3611 NSLog(@"dw_mle_search() unimplemented\n"); |
3612 return 0; | 3612 return 0; |
3613 } | 3613 } |
3614 | 3614 |
3615 /* | 3615 /* |
3616 * Stops redrawing of an MLE box. | 3616 * Stops redrawing of an MLE box. |
3617 * Parameters: | 3617 * Parameters: |
3618 * handle: Handle to the MLE to freeze. | 3618 * handle: Handle to the MLE to freeze. |
3619 */ | 3619 */ |
3620 void API dw_mle_freeze(HWND handle) | 3620 void API dw_mle_freeze(HWND handle) |
3621 { | 3621 { |
3622 /* Don't think this is necessary */ | 3622 /* Don't think this is necessary */ |
3623 } | 3623 } |
3624 | 3624 |
3625 /* | 3625 /* |
3626 * Resumes redrawing of an MLE box. | 3626 * Resumes redrawing of an MLE box. |
3627 * Parameters: | 3627 * Parameters: |
3628 * handle: Handle to the MLE to thaw. | 3628 * handle: Handle to the MLE to thaw. |
3629 */ | 3629 */ |
3630 void API dw_mle_thaw(HWND handle) | 3630 void API dw_mle_thaw(HWND handle) |
3631 { | 3631 { |
3632 /* Don't think this is necessary */ | 3632 /* Don't think this is necessary */ |
3633 } | 3633 } |
3634 | 3634 |
3635 /* | 3635 /* |
3636 * Create a new status text window (widget) to be packed. | 3636 * Create a new status text window (widget) to be packed. |
3637 * Parameters: | 3637 * Parameters: |
3641 HWND API dw_status_text_new(char *text, ULONG cid) | 3641 HWND API dw_status_text_new(char *text, ULONG cid) |
3642 { | 3642 { |
3643 NSTextField *textfield = dw_text_new(text, cid); | 3643 NSTextField *textfield = dw_text_new(text, cid); |
3644 [textfield setBordered:YES]; | 3644 [textfield setBordered:YES]; |
3645 if(DWOSMinor > 5) | 3645 if(DWOSMinor > 5) |
3646 { | 3646 { |
3647 [textfield setBezeled:YES]; | 3647 [textfield setBezeled:YES]; |
3648 [textfield setBezelStyle:NSTextFieldSquareBezel]; | 3648 [textfield setBezelStyle:NSTextFieldSquareBezel]; |
3649 } | 3649 } |
3650 [textfield setBackgroundColor:[NSColor clearColor]]; | 3650 [textfield setBackgroundColor:[NSColor clearColor]]; |
3651 [textfield setDrawsBackground:NO]; | 3651 [textfield setDrawsBackground:NO]; |
3681 * Returns: | 3681 * Returns: |
3682 * A handle to the widget or NULL on failure. | 3682 * A handle to the widget or NULL on failure. |
3683 */ | 3683 */ |
3684 HWND API dw_render_new(unsigned long cid) | 3684 HWND API dw_render_new(unsigned long cid) |
3685 { | 3685 { |
3686 DWRender *render = [[DWRender alloc] init]; | 3686 DWRender *render = [[DWRender alloc] init]; |
3687 /* [render setTag:cid]; Why doesn't this work? */ | 3687 /* [render setTag:cid]; Why doesn't this work? */ |
3688 return render; | 3688 return render; |
3689 } | 3689 } |
3690 | 3690 |
3691 /* Sets the current foreground drawing color. | 3691 /* Sets the current foreground drawing color. |
3692 * Parameters: | 3692 * Parameters: |
3693 * red: red value. | 3693 * red: red value. |
3695 * blue: blue value. | 3695 * blue: blue value. |
3696 */ | 3696 */ |
3697 void API dw_color_foreground_set(unsigned long value) | 3697 void API dw_color_foreground_set(unsigned long value) |
3698 { | 3698 { |
3699 /* This may need to be thread specific */ | 3699 /* This may need to be thread specific */ |
3700 _foreground = _get_color(value); | 3700 _foreground = _get_color(value); |
3701 } | 3701 } |
3702 | 3702 |
3703 /* Sets the current background drawing color. | 3703 /* Sets the current background drawing color. |
3704 * Parameters: | 3704 * Parameters: |
3705 * red: red value. | 3705 * red: red value. |
3707 * blue: blue value. | 3707 * blue: blue value. |
3708 */ | 3708 */ |
3709 void API dw_color_background_set(unsigned long value) | 3709 void API dw_color_background_set(unsigned long value) |
3710 { | 3710 { |
3711 /* This may need to be thread specific */ | 3711 /* This may need to be thread specific */ |
3712 _background = _get_color(value); | 3712 _background = _get_color(value); |
3713 } | 3713 } |
3714 | 3714 |
3715 /* Allows the user to choose a color using the system's color chooser dialog. | 3715 /* Allows the user to choose a color using the system's color chooser dialog. |
3716 * Parameters: | 3716 * Parameters: |
3717 * value: current color | 3717 * value: current color |
3740 /* Set defaults for the dialog. */ | 3740 /* Set defaults for the dialog. */ |
3741 [colorDlg setContinuous:NO]; | 3741 [colorDlg setContinuous:NO]; |
3742 [colorDlg setTarget:colorDlg]; | 3742 [colorDlg setTarget:colorDlg]; |
3743 [colorDlg setAction:@selector(changeColor:)]; | 3743 [colorDlg setAction:@selector(changeColor:)]; |
3744 } | 3744 } |
3745 | 3745 |
3746 dialog = dw_dialog_new(colorDlg); | 3746 dialog = dw_dialog_new(colorDlg); |
3747 [colorDlg setColor:color]; | 3747 [colorDlg setColor:color]; |
3748 [colorDlg setDialog:dialog]; | 3748 [colorDlg setDialog:dialog]; |
3749 [colorDlg makeKeyAndOrderFront:nil]; | 3749 [colorDlg makeKeyAndOrderFront:nil]; |
3750 | 3750 |
3767 */ | 3767 */ |
3768 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) | 3768 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) |
3769 { | 3769 { |
3770 int _locked_by_me = FALSE; | 3770 int _locked_by_me = FALSE; |
3771 DW_MUTEX_LOCK; | 3771 DW_MUTEX_LOCK; |
3772 id image = handle; | 3772 id image = handle; |
3773 if(pixmap) | 3773 if(pixmap) |
3774 { | 3774 { |
3775 image = (id)pixmap->image; | 3775 image = (id)pixmap->image; |
3776 [image lockFocus]; | 3776 [image lockFocus]; |
3777 } | 3777 } |
3778 else | 3778 else |
3779 { | 3779 { |
3780 if([image lockFocusIfCanDraw] == NO) | 3780 if([image lockFocusIfCanDraw] == NO) |
3781 { | 3781 { |
3782 DW_MUTEX_UNLOCK; | 3782 DW_MUTEX_UNLOCK; |
3783 return; | 3783 return; |
3784 } | 3784 } |
3785 _DWLastDrawable = handle; | 3785 _DWLastDrawable = handle; |
3786 } | 3786 } |
3787 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 3787 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
3788 [aPath setLineWidth: 0.5]; | 3788 [aPath setLineWidth: 0.5]; |
3789 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; | 3789 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; |
3790 [color set]; | 3790 [color set]; |
3791 | 3791 |
3792 [aPath moveToPoint:NSMakePoint(x, y)]; | 3792 [aPath moveToPoint:NSMakePoint(x, y)]; |
3793 [aPath stroke]; | 3793 [aPath stroke]; |
3794 [image unlockFocus]; | 3794 [image unlockFocus]; |
3795 DW_MUTEX_UNLOCK; | 3795 DW_MUTEX_UNLOCK; |
3796 } | 3796 } |
3797 | 3797 |
3798 /* Draw a line on a window (preferably a render window). | 3798 /* Draw a line on a window (preferably a render window). |
3799 * Parameters: | 3799 * Parameters: |
3806 */ | 3806 */ |
3807 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) | 3807 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) |
3808 { | 3808 { |
3809 int _locked_by_me = FALSE; | 3809 int _locked_by_me = FALSE; |
3810 DW_MUTEX_LOCK; | 3810 DW_MUTEX_LOCK; |
3811 id image = handle; | 3811 id image = handle; |
3812 if(pixmap) | 3812 if(pixmap) |
3813 { | 3813 { |
3814 image = (id)pixmap->image; | 3814 image = (id)pixmap->image; |
3815 [image lockFocus]; | 3815 [image lockFocus]; |
3816 } | 3816 } |
3817 else | 3817 else |
3818 { | 3818 { |
3819 if([image lockFocusIfCanDraw] == NO) | 3819 if([image lockFocusIfCanDraw] == NO) |
3820 { | 3820 { |
3821 DW_MUTEX_UNLOCK; | 3821 DW_MUTEX_UNLOCK; |
3822 return; | 3822 return; |
3823 } | 3823 } |
3824 _DWLastDrawable = handle; | 3824 _DWLastDrawable = handle; |
3825 } | 3825 } |
3826 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 3826 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
3827 [aPath setLineWidth: 0.5]; | 3827 [aPath setLineWidth: 0.5]; |
3828 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; | 3828 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; |
3829 [color set]; | 3829 [color set]; |
3830 | 3830 |
3831 [aPath moveToPoint:NSMakePoint(x1, y1)]; | 3831 [aPath moveToPoint:NSMakePoint(x1, y1)]; |
3832 [aPath lineToPoint:NSMakePoint(x2, y2)]; | 3832 [aPath lineToPoint:NSMakePoint(x2, y2)]; |
3833 [aPath stroke]; | 3833 [aPath stroke]; |
3834 | 3834 |
3835 [image unlockFocus]; | 3835 [image unlockFocus]; |
3836 DW_MUTEX_UNLOCK; | 3836 DW_MUTEX_UNLOCK; |
3837 } | 3837 } |
3838 | 3838 |
3839 /* Draw text on a window (preferably a render window). | 3839 /* Draw text on a window (preferably a render window). |
3840 * Parameters: | 3840 * Parameters: |
3946 */ | 3946 */ |
3947 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int fill, int npoints, int *x, int *y ) | 3947 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int fill, int npoints, int *x, int *y ) |
3948 { | 3948 { |
3949 int _locked_by_me = FALSE; | 3949 int _locked_by_me = FALSE; |
3950 DW_MUTEX_LOCK; | 3950 DW_MUTEX_LOCK; |
3951 id image = handle; | 3951 id image = handle; |
3952 int z; | 3952 int z; |
3953 if(pixmap) | 3953 if(pixmap) |
3954 { | 3954 { |
3955 image = (id)pixmap->image; | 3955 image = (id)pixmap->image; |
3956 [image lockFocus]; | 3956 [image lockFocus]; |
3957 } | 3957 } |
3958 else | 3958 else |
3959 { | 3959 { |
3960 if([image lockFocusIfCanDraw] == NO) | 3960 if([image lockFocusIfCanDraw] == NO) |
3961 { | 3961 { |
3962 DW_MUTEX_UNLOCK; | 3962 DW_MUTEX_UNLOCK; |
3963 return; | 3963 return; |
3964 } | 3964 } |
3965 _DWLastDrawable = handle; | 3965 _DWLastDrawable = handle; |
3966 } | 3966 } |
3967 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 3967 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
3968 [aPath setLineWidth: 0.5]; | 3968 [aPath setLineWidth: 0.5]; |
3969 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; | 3969 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; |
3970 [color set]; | 3970 [color set]; |
3971 | 3971 |
3972 [aPath moveToPoint:NSMakePoint(*x, *y)]; | 3972 [aPath moveToPoint:NSMakePoint(*x, *y)]; |
3973 for(z=1;z<npoints;z++) | 3973 for(z=1;z<npoints;z++) |
3974 { | 3974 { |
3975 [aPath lineToPoint:NSMakePoint(x[z], y[z])]; | 3975 [aPath lineToPoint:NSMakePoint(x[z], y[z])]; |
3976 } | 3976 } |
3977 [aPath closePath]; | 3977 [aPath closePath]; |
3978 if(fill) | 3978 if(fill) |
3979 { | 3979 { |
3980 [aPath fill]; | 3980 [aPath fill]; |
3981 } | 3981 } |
3982 [aPath stroke]; | 3982 [aPath stroke]; |
3983 [image unlockFocus]; | 3983 [image unlockFocus]; |
3984 DW_MUTEX_UNLOCK; | 3984 DW_MUTEX_UNLOCK; |
3985 } | 3985 } |
3986 | 3986 |
3987 /* Draw a rectangle on a window (preferably a render window). | 3987 /* Draw a rectangle on a window (preferably a render window). |
3988 * Parameters: | 3988 * Parameters: |
3996 */ | 3996 */ |
3997 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) | 3997 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) |
3998 { | 3998 { |
3999 int _locked_by_me = FALSE; | 3999 int _locked_by_me = FALSE; |
4000 DW_MUTEX_LOCK; | 4000 DW_MUTEX_LOCK; |
4001 id image = handle; | 4001 id image = handle; |
4002 if(pixmap) | 4002 if(pixmap) |
4003 { | 4003 { |
4004 image = (id)pixmap->image; | 4004 image = (id)pixmap->image; |
4005 [image lockFocus]; | 4005 [image lockFocus]; |
4006 } | 4006 } |
4007 else | 4007 else |
4008 { | 4008 { |
4009 if([image lockFocusIfCanDraw] == NO) | 4009 if([image lockFocusIfCanDraw] == NO) |
4010 { | 4010 { |
4011 DW_MUTEX_UNLOCK; | 4011 DW_MUTEX_UNLOCK; |
4012 return; | 4012 return; |
4013 } | 4013 } |
4014 _DWLastDrawable = handle; | 4014 _DWLastDrawable = handle; |
4015 } | 4015 } |
4016 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 4016 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
4017 [aPath setLineWidth: 0.5]; | 4017 [aPath setLineWidth: 0.5]; |
4018 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; | 4018 NSColor *color = [NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: DW_GREEN_VALUE(_foreground)/255.0 blue: DW_BLUE_VALUE(_foreground)/255.0 alpha: 1]; |
4019 [color set]; | 4019 [color set]; |
4020 | 4020 |
4021 [aPath moveToPoint:NSMakePoint(x, y)]; | 4021 [aPath moveToPoint:NSMakePoint(x, y)]; |
4022 [aPath lineToPoint:NSMakePoint(x, y + height)]; | 4022 [aPath lineToPoint:NSMakePoint(x, y + height)]; |
4023 [aPath lineToPoint:NSMakePoint(x + width, y + height)]; | 4023 [aPath lineToPoint:NSMakePoint(x + width, y + height)]; |
4024 [aPath lineToPoint:NSMakePoint(x + width, y)]; | 4024 [aPath lineToPoint:NSMakePoint(x + width, y)]; |
4025 [aPath closePath]; | 4025 [aPath closePath]; |
4026 [aPath fill]; | 4026 [aPath fill]; |
4027 [aPath stroke]; | 4027 [aPath stroke]; |
4028 [image unlockFocus]; | 4028 [image unlockFocus]; |
4029 DW_MUTEX_UNLOCK; | 4029 DW_MUTEX_UNLOCK; |
4030 } | 4030 } |
4031 | 4031 |
4032 /* | 4032 /* |
4033 * Create a tree object to be packed. | 4033 * Create a tree object to be packed. |
4038 HWND API dw_tree_new(ULONG cid) | 4038 HWND API dw_tree_new(ULONG cid) |
4039 { | 4039 { |
4040 int _locked_by_me = FALSE; | 4040 int _locked_by_me = FALSE; |
4041 DW_MUTEX_LOCK; | 4041 DW_MUTEX_LOCK; |
4042 NSScrollView *scrollview = [[NSScrollView alloc] init]; | 4042 NSScrollView *scrollview = [[NSScrollView alloc] init]; |
4043 DWTree *tree = [[DWTree alloc] init]; | 4043 DWTree *tree = [[DWTree alloc] init]; |
4044 | 4044 |
4045 [tree setScrollview:scrollview]; | 4045 [tree setScrollview:scrollview]; |
4046 [scrollview setBorderType:NSBezelBorder]; | 4046 [scrollview setBorderType:NSBezelBorder]; |
4047 [scrollview setHasVerticalScroller:YES]; | 4047 [scrollview setHasVerticalScroller:YES]; |
4048 [scrollview setAutohidesScrollers:YES]; | 4048 [scrollview setAutohidesScrollers:YES]; |
4049 | 4049 |
4050 [tree setAllowsMultipleSelection:NO]; | 4050 [tree setAllowsMultipleSelection:NO]; |
4051 [tree setDataSource:tree]; | 4051 [tree setDataSource:tree]; |
4052 [scrollview setDocumentView:tree]; | 4052 [scrollview setDocumentView:tree]; |
4053 [tree setHeaderView:nil]; | 4053 [tree setHeaderView:nil]; |
4054 [tree setTag:cid]; | 4054 [tree setTag:cid]; |
4055 [scrollview release]; | 4055 [scrollview release]; |
4056 DW_MUTEX_UNLOCK; | 4056 DW_MUTEX_UNLOCK; |
4079 [treenode addPointer:itemdata]; | 4079 [treenode addPointer:itemdata]; |
4080 [treenode addPointer:NULL]; | 4080 [treenode addPointer:NULL]; |
4081 [tree addTree:treenode and:parent]; | 4081 [tree addTree:treenode and:parent]; |
4082 [tree reloadData]; | 4082 [tree reloadData]; |
4083 DW_MUTEX_UNLOCK; | 4083 DW_MUTEX_UNLOCK; |
4084 return treenode; | 4084 return treenode; |
4085 } | 4085 } |
4086 | 4086 |
4087 /* | 4087 /* |
4088 * Inserts an item into a tree window (widget). | 4088 * Inserts an item into a tree window (widget). |
4089 * Parameters: | 4089 * Parameters: |
4120 * handle: Handle to the tree containing the item. | 4120 * handle: Handle to the tree containing the item. |
4121 * item: Handle of the item to be modified. | 4121 * item: Handle of the item to be modified. |
4122 */ | 4122 */ |
4123 HTREEITEM API dw_tree_get_parent(HWND handle, HTREEITEM item) | 4123 HTREEITEM API dw_tree_get_parent(HWND handle, HTREEITEM item) |
4124 { | 4124 { |
4125 NSLog(@"dw_tree_get_parent() unimplemented\n"); | 4125 NSLog(@"dw_tree_get_parent() unimplemented\n"); |
4126 return HWND_DESKTOP; | 4126 return HWND_DESKTOP; |
4127 } | 4127 } |
4128 | 4128 |
4129 /* | 4129 /* |
4130 * Sets the text and icon of an item in a tree window (widget). | 4130 * Sets the text and icon of an item in a tree window (widget). |
4131 * Parameters: | 4131 * Parameters: |
4298 */ | 4298 */ |
4299 int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator) | 4299 int API dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator) |
4300 { | 4300 { |
4301 int _locked_by_me = FALSE; | 4301 int _locked_by_me = FALSE; |
4302 DW_MUTEX_LOCK; | 4302 DW_MUTEX_LOCK; |
4303 int z; | 4303 int z; |
4304 DWContainer *cont = handle; | 4304 DWContainer *cont = handle; |
4305 | 4305 |
4306 [cont setup]; | 4306 [cont setup]; |
4307 | 4307 |
4308 for(z=0;z<count;z++) | 4308 for(z=0;z<count;z++) |
4309 { | 4309 { |
4310 NSTableColumn *column = [[NSTableColumn alloc] init]; | 4310 NSTableColumn *column = [[NSTableColumn alloc] init]; |
4311 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]]; | 4311 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]]; |
4312 if(flags[z] & DW_CFA_BITMAPORICON) | 4312 if(flags[z] & DW_CFA_BITMAPORICON) |
4313 { | 4313 { |
4314 NSImageCell *imagecell = [[NSImageCell alloc] init]; | 4314 NSImageCell *imagecell = [[NSImageCell alloc] init]; |
4315 [column setDataCell:imagecell]; | 4315 [column setDataCell:imagecell]; |
4316 if(z == 0 && titles[z] && strcmp(titles[z], "Icon") == 0) | 4316 if(z == 0 && titles[z] && strcmp(titles[z], "Icon") == 0) |
4318 [column setResizingMask:NSTableColumnNoResizing]; | 4318 [column setResizingMask:NSTableColumnNoResizing]; |
4319 [column setWidth:20]; | 4319 [column setWidth:20]; |
4320 } | 4320 } |
4321 [imagecell release]; | 4321 [imagecell release]; |
4322 } | 4322 } |
4323 [cont addTableColumn:column]; | 4323 [cont addTableColumn:column]; |
4324 [cont addColumn:column andType:(int)flags[z]]; | 4324 [cont addColumn:column andType:(int)flags[z]]; |
4325 [column release]; | 4325 [column release]; |
4326 } | 4326 } |
4327 DW_MUTEX_UNLOCK; | 4327 DW_MUTEX_UNLOCK; |
4328 return TRUE; | 4328 return TRUE; |
4329 } | 4329 } |
4330 | 4330 |
4331 /* | 4331 /* |
4332 * Sets up the filesystem columns, note: filesystem always has an icon/filename field. | 4332 * Sets up the filesystem columns, note: filesystem always has an icon/filename field. |
4333 * Parameters: | 4333 * Parameters: |
4336 * titles: An array of strings with column text titles. | 4336 * titles: An array of strings with column text titles. |
4337 * count: The number of columns (this should match the arrays). | 4337 * count: The number of columns (this should match the arrays). |
4338 */ | 4338 */ |
4339 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) | 4339 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) |
4340 { | 4340 { |
4341 char **newtitles = malloc(sizeof(char *) * (count + 2)); | 4341 char **newtitles = malloc(sizeof(char *) * (count + 2)); |
4342 unsigned long *newflags = malloc(sizeof(unsigned long) * (count + 2)); | 4342 unsigned long *newflags = malloc(sizeof(unsigned long) * (count + 2)); |
4343 | 4343 |
4344 newtitles[0] = "Icon"; | 4344 newtitles[0] = "Icon"; |
4345 newtitles[1] = "Filename"; | 4345 newtitles[1] = "Filename"; |
4346 | 4346 |
4347 newflags[0] = DW_CFA_BITMAPORICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; | 4347 newflags[0] = DW_CFA_BITMAPORICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; |
4348 newflags[1] = DW_CFA_STRING | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; | 4348 newflags[1] = DW_CFA_STRING | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; |
4349 | 4349 |
4350 memcpy(&newtitles[2], titles, sizeof(char *) * count); | 4350 memcpy(&newtitles[2], titles, sizeof(char *) * count); |
4351 memcpy(&newflags[2], flags, sizeof(unsigned long) * count); | 4351 memcpy(&newflags[2], flags, sizeof(unsigned long) * count); |
4352 | 4352 |
4353 dw_container_setup(handle, newflags, newtitles, count + 2, 0); | 4353 dw_container_setup(handle, newflags, newtitles, count + 2, 0); |
4354 | 4354 |
4355 free(newtitles); | 4355 free(newtitles); |
4356 free(newflags); | 4356 free(newflags); |
4357 return TRUE; | 4357 return TRUE; |
4358 } | 4358 } |
4359 | 4359 |
4360 /* | 4360 /* |
4361 * Allocates memory used to populate a container. | 4361 * Allocates memory used to populate a container. |
4362 * Parameters: | 4362 * Parameters: |
4365 */ | 4365 */ |
4366 void * API dw_container_alloc(HWND handle, int rowcount) | 4366 void * API dw_container_alloc(HWND handle, int rowcount) |
4367 { | 4367 { |
4368 int _locked_by_me = FALSE; | 4368 int _locked_by_me = FALSE; |
4369 DW_MUTEX_LOCK; | 4369 DW_MUTEX_LOCK; |
4370 DWContainer *cont = handle; | 4370 DWContainer *cont = handle; |
4371 [cont addRows:rowcount]; | 4371 [cont addRows:rowcount]; |
4372 DW_MUTEX_UNLOCK; | 4372 DW_MUTEX_UNLOCK; |
4373 return cont; | 4373 return cont; |
4374 } | 4374 } |
4375 | 4375 |
4376 /* | 4376 /* |
4377 * Sets an item in specified row and column to the given data. | 4377 * Sets an item in specified row and column to the given data. |
4378 * Parameters: | 4378 * Parameters: |
4384 */ | 4384 */ |
4385 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) | 4385 void API dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) |
4386 { | 4386 { |
4387 int _locked_by_me = FALSE; | 4387 int _locked_by_me = FALSE; |
4388 DW_MUTEX_LOCK; | 4388 DW_MUTEX_LOCK; |
4389 DWContainer *cont = handle; | 4389 DWContainer *cont = handle; |
4390 id object = nil; | 4390 id object = nil; |
4391 int type = [cont cellType:column]; | 4391 int type = [cont cellType:column]; |
4392 int lastadd = [cont lastAddPoint]; | 4392 int lastadd = [cont lastAddPoint]; |
4393 | 4393 |
4394 if(!data) | 4394 if(!data) |
4395 { | 4395 { |
4396 DW_MUTEX_UNLOCK; | 4396 DW_MUTEX_UNLOCK; |
4397 return; | 4397 return; |
4398 } | 4398 } |
4399 if(type & DW_CFA_BITMAPORICON) | 4399 if(type & DW_CFA_BITMAPORICON) |
4400 { | 4400 { |
4401 object = *((NSImage **)data); | 4401 object = *((NSImage **)data); |
4402 } | 4402 } |
4403 else if(type & DW_CFA_STRING) | 4403 else if(type & DW_CFA_STRING) |
4404 { | 4404 { |
4405 char *str = *((char **)data); | 4405 char *str = *((char **)data); |
4406 object = [ NSString stringWithUTF8String:str ]; | 4406 object = [ NSString stringWithUTF8String:str ]; |
4407 } | 4407 } |
4408 else | 4408 else |
4409 { | 4409 { |
4410 char textbuffer[100]; | 4410 char textbuffer[100]; |
4411 | 4411 |
4412 if(type & DW_CFA_ULONG) | 4412 if(type & DW_CFA_ULONG) |
4413 { | 4413 { |
4414 ULONG tmp = *((ULONG *)data); | 4414 ULONG tmp = *((ULONG *)data); |
4415 | 4415 |
4416 sprintf(textbuffer, "%lu", tmp); | 4416 sprintf(textbuffer, "%lu", tmp); |
4417 } | 4417 } |
4418 else if(type & DW_CFA_DATE) | 4418 else if(type & DW_CFA_DATE) |
4419 { | 4419 { |
4420 struct tm curtm; | 4420 struct tm curtm; |
4421 CDATE cdate = *((CDATE *)data); | 4421 CDATE cdate = *((CDATE *)data); |
4422 | 4422 |
4423 memset( &curtm, 0, sizeof(curtm) ); | 4423 memset( &curtm, 0, sizeof(curtm) ); |
4424 curtm.tm_mday = cdate.day; | 4424 curtm.tm_mday = cdate.day; |
4425 curtm.tm_mon = cdate.month - 1; | 4425 curtm.tm_mon = cdate.month - 1; |
4426 curtm.tm_year = cdate.year - 1900; | 4426 curtm.tm_year = cdate.year - 1900; |
4427 | 4427 |
4428 strftime(textbuffer, 100, "%x", &curtm); | 4428 strftime(textbuffer, 100, "%x", &curtm); |
4429 } | 4429 } |
4430 else if(type & DW_CFA_TIME) | 4430 else if(type & DW_CFA_TIME) |
4431 { | 4431 { |
4432 struct tm curtm; | 4432 struct tm curtm; |
4433 CTIME ctime = *((CTIME *)data); | 4433 CTIME ctime = *((CTIME *)data); |
4434 | 4434 |
4435 memset( &curtm, 0, sizeof(curtm) ); | 4435 memset( &curtm, 0, sizeof(curtm) ); |
4436 curtm.tm_hour = ctime.hours; | 4436 curtm.tm_hour = ctime.hours; |
4437 curtm.tm_min = ctime.minutes; | 4437 curtm.tm_min = ctime.minutes; |
4438 curtm.tm_sec = ctime.seconds; | 4438 curtm.tm_sec = ctime.seconds; |
4439 | 4439 |
4440 strftime(textbuffer, 100, "%X", &curtm); | 4440 strftime(textbuffer, 100, "%X", &curtm); |
4441 } | 4441 } |
4442 else | 4442 else |
4443 { | 4443 { |
4444 DW_MUTEX_UNLOCK; | 4444 DW_MUTEX_UNLOCK; |
4445 return; | 4445 return; |
4446 } | 4446 } |
4447 object = [ NSString stringWithUTF8String:textbuffer ]; | 4447 object = [ NSString stringWithUTF8String:textbuffer ]; |
4448 } | 4448 } |
4449 | 4449 |
4450 [cont editCell:object at:(row+lastadd) and:column]; | 4450 [cont editCell:object at:(row+lastadd) and:column]; |
4451 DW_MUTEX_UNLOCK; | 4451 DW_MUTEX_UNLOCK; |
4452 } | 4452 } |
4453 | 4453 |
4454 /* | 4454 /* |
4455 * Changes an existing item in specified row and column to the given data. | 4455 * Changes an existing item in specified row and column to the given data. |
4459 * row: Zero based row of data being set. | 4459 * row: Zero based row of data being set. |
4460 * data: Pointer to the data to be added. | 4460 * data: Pointer to the data to be added. |
4461 */ | 4461 */ |
4462 void API dw_container_change_item(HWND handle, int column, int row, void *data) | 4462 void API dw_container_change_item(HWND handle, int column, int row, void *data) |
4463 { | 4463 { |
4464 dw_container_set_item(handle, NULL, column, row, data); | 4464 dw_container_set_item(handle, NULL, column, row, data); |
4465 } | 4465 } |
4466 | 4466 |
4467 /* | 4467 /* |
4468 * Changes an existing item in specified row and column to the given data. | 4468 * Changes an existing item in specified row and column to the given data. |
4469 * Parameters: | 4469 * Parameters: |
4472 * row: Zero based row of data being set. | 4472 * row: Zero based row of data being set. |
4473 * data: Pointer to the data to be added. | 4473 * data: Pointer to the data to be added. |
4474 */ | 4474 */ |
4475 void API dw_filesystem_change_item(HWND handle, int column, int row, void *data) | 4475 void API dw_filesystem_change_item(HWND handle, int column, int row, void *data) |
4476 { | 4476 { |
4477 dw_container_change_item(handle, column+2, row, data); | 4477 dw_container_change_item(handle, column+2, row, data); |
4478 } | 4478 } |
4479 | 4479 |
4480 /* | 4480 /* |
4481 * Changes an item in specified row and column to the given data. | 4481 * Changes an item in specified row and column to the given data. |
4482 * Parameters: | 4482 * Parameters: |
4487 * data: Pointer to the data to be added. | 4487 * data: Pointer to the data to be added. |
4488 */ | 4488 */ |
4489 void API dw_filesystem_change_file(HWND handle, int row, char *filename, HICN icon) | 4489 void API dw_filesystem_change_file(HWND handle, int row, char *filename, HICN icon) |
4490 { | 4490 { |
4491 dw_container_change_item(handle, 0, row, &icon); | 4491 dw_container_change_item(handle, 0, row, &icon); |
4492 dw_container_change_item(handle, 1, row, &filename); | 4492 dw_container_change_item(handle, 1, row, &filename); |
4493 } | 4493 } |
4494 | 4494 |
4495 /* | 4495 /* |
4496 * Sets an item in specified row and column to the given data. | 4496 * Sets an item in specified row and column to the given data. |
4497 * Parameters: | 4497 * Parameters: |
4502 * data: Pointer to the data to be added. | 4502 * data: Pointer to the data to be added. |
4503 */ | 4503 */ |
4504 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, HICN icon) | 4504 void API dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, HICN icon) |
4505 { | 4505 { |
4506 dw_container_set_item(handle, pointer, 0, row, &icon); | 4506 dw_container_set_item(handle, pointer, 0, row, &icon); |
4507 dw_container_set_item(handle, pointer, 1, row, &filename); | 4507 dw_container_set_item(handle, pointer, 1, row, &filename); |
4508 } | 4508 } |
4509 | 4509 |
4510 /* | 4510 /* |
4511 * Sets an item in specified row and column to the given data. | 4511 * Sets an item in specified row and column to the given data. |
4512 * Parameters: | 4512 * Parameters: |
4516 * row: Zero based row of data being set. | 4516 * row: Zero based row of data being set. |
4517 * data: Pointer to the data to be added. | 4517 * data: Pointer to the data to be added. |
4518 */ | 4518 */ |
4519 void API dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data) | 4519 void API dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data) |
4520 { | 4520 { |
4521 dw_container_set_item(handle, pointer, column+2, row, data); | 4521 dw_container_set_item(handle, pointer, column+2, row, data); |
4522 } | 4522 } |
4523 | 4523 |
4524 /* | 4524 /* |
4525 * Gets column type for a container column | 4525 * Gets column type for a container column |
4526 * Parameters: | 4526 * Parameters: |
4588 */ | 4588 */ |
4589 void API dw_container_set_row_title(void *pointer, int row, char *title) | 4589 void API dw_container_set_row_title(void *pointer, int row, char *title) |
4590 { | 4590 { |
4591 int _locked_by_me = FALSE; | 4591 int _locked_by_me = FALSE; |
4592 DW_MUTEX_LOCK; | 4592 DW_MUTEX_LOCK; |
4593 DWContainer *cont = pointer; | 4593 DWContainer *cont = pointer; |
4594 [cont setRow:row title:title]; | 4594 [cont setRow:row title:title]; |
4595 DW_MUTEX_UNLOCK; | 4595 DW_MUTEX_UNLOCK; |
4596 } | 4596 } |
4597 | 4597 |
4598 /* | 4598 /* |
4599 * Sets the title of a row in the container. | 4599 * Sets the title of a row in the container. |
4604 */ | 4604 */ |
4605 void API dw_container_insert(HWND handle, void *pointer, int rowcount) | 4605 void API dw_container_insert(HWND handle, void *pointer, int rowcount) |
4606 { | 4606 { |
4607 int _locked_by_me = FALSE; | 4607 int _locked_by_me = FALSE; |
4608 DW_MUTEX_LOCK; | 4608 DW_MUTEX_LOCK; |
4609 DWContainer *cont = handle; | 4609 DWContainer *cont = handle; |
4610 [cont reloadData]; | 4610 [cont reloadData]; |
4611 DW_MUTEX_UNLOCK; | 4611 DW_MUTEX_UNLOCK; |
4612 } | 4612 } |
4613 | 4613 |
4614 /* | 4614 /* |
4619 */ | 4619 */ |
4620 void API dw_container_clear(HWND handle, int redraw) | 4620 void API dw_container_clear(HWND handle, int redraw) |
4621 { | 4621 { |
4622 int _locked_by_me = FALSE; | 4622 int _locked_by_me = FALSE; |
4623 DW_MUTEX_LOCK; | 4623 DW_MUTEX_LOCK; |
4624 DWContainer *cont = handle; | 4624 DWContainer *cont = handle; |
4625 [cont clear]; | 4625 [cont clear]; |
4626 if(redraw) | 4626 if(redraw) |
4627 { | 4627 { |
4628 [cont reloadData]; | 4628 [cont reloadData]; |
4629 } | 4629 } |
4630 DW_MUTEX_UNLOCK; | 4630 DW_MUTEX_UNLOCK; |
4658 * DW_SCROLL_BOTTOM. (rows is ignored for last two) | 4658 * DW_SCROLL_BOTTOM. (rows is ignored for last two) |
4659 * rows: The number of rows to be scrolled. | 4659 * rows: The number of rows to be scrolled. |
4660 */ | 4660 */ |
4661 void API dw_container_scroll(HWND handle, int direction, long rows) | 4661 void API dw_container_scroll(HWND handle, int direction, long rows) |
4662 { | 4662 { |
4663 NSLog(@"dw_container_scroll() unimplemented\n"); | 4663 NSLog(@"dw_container_scroll() unimplemented\n"); |
4664 } | 4664 } |
4665 | 4665 |
4666 /* | 4666 /* |
4667 * Starts a new query of a container. | 4667 * Starts a new query of a container. |
4668 * Parameters: | 4668 * Parameters: |
4684 { | 4684 { |
4685 retval = [cont getRowTitle:(int)result]; | 4685 retval = [cont getRowTitle:(int)result]; |
4686 [cont setLastQueryPoint:(int)result]; | 4686 [cont setLastQueryPoint:(int)result]; |
4687 } | 4687 } |
4688 DW_MUTEX_UNLOCK; | 4688 DW_MUTEX_UNLOCK; |
4689 return retval; | 4689 return retval; |
4690 } | 4690 } |
4691 | 4691 |
4692 /* | 4692 /* |
4693 * Continues an existing query of a container. | 4693 * Continues an existing query of a container. |
4694 * Parameters: | 4694 * Parameters: |
4711 { | 4711 { |
4712 retval = [cont getRowTitle:(int)result]; | 4712 retval = [cont getRowTitle:(int)result]; |
4713 [cont setLastQueryPoint:(int)result]; | 4713 [cont setLastQueryPoint:(int)result]; |
4714 } | 4714 } |
4715 DW_MUTEX_UNLOCK; | 4715 DW_MUTEX_UNLOCK; |
4716 return retval; | 4716 return retval; |
4717 } | 4717 } |
4718 | 4718 |
4719 /* | 4719 /* |
4720 * Cursors the item with the text speficied, and scrolls to that item. | 4720 * Cursors the item with the text speficied, and scrolls to that item. |
4721 * Parameters: | 4721 * Parameters: |
4779 */ | 4779 */ |
4780 void API dw_container_optimize(HWND handle) | 4780 void API dw_container_optimize(HWND handle) |
4781 { | 4781 { |
4782 int _locked_by_me = FALSE; | 4782 int _locked_by_me = FALSE; |
4783 DW_MUTEX_LOCK; | 4783 DW_MUTEX_LOCK; |
4784 DWContainer *cont = handle; | 4784 DWContainer *cont = handle; |
4785 /*[cont sizeToFit];*/ | 4785 /*[cont sizeToFit];*/ |
4786 [cont setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle]; | 4786 [cont setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle]; |
4787 DW_MUTEX_UNLOCK; | 4787 DW_MUTEX_UNLOCK; |
4788 } | 4788 } |
4789 | 4789 |
4790 /* | 4790 /* |
4791 * Inserts an icon into the taskbar. | 4791 * Inserts an icon into the taskbar. |
4794 * icon: Icon handle to display in the taskbar. | 4794 * icon: Icon handle to display in the taskbar. |
4795 * bubbletext: Text to show when the mouse is above the icon. | 4795 * bubbletext: Text to show when the mouse is above the icon. |
4796 */ | 4796 */ |
4797 void API dw_taskbar_insert(HWND handle, HICN icon, char *bubbletext) | 4797 void API dw_taskbar_insert(HWND handle, HICN icon, char *bubbletext) |
4798 { | 4798 { |
4799 NSLog(@"dw_taskbar_insert() unimplemented\n"); | 4799 NSLog(@"dw_taskbar_insert() unimplemented\n"); |
4800 } | 4800 } |
4801 | 4801 |
4802 /* | 4802 /* |
4803 * Deletes an icon from the taskbar. | 4803 * Deletes an icon from the taskbar. |
4804 * Parameters: | 4804 * Parameters: |
4805 * handle: Window handle that was used with dw_taskbar_insert(). | 4805 * handle: Window handle that was used with dw_taskbar_insert(). |
4806 * icon: Icon handle that was used with dw_taskbar_insert(). | 4806 * icon: Icon handle that was used with dw_taskbar_insert(). |
4807 */ | 4807 */ |
4808 void API dw_taskbar_delete(HWND handle, HICN icon) | 4808 void API dw_taskbar_delete(HWND handle, HICN icon) |
4809 { | 4809 { |
4810 NSLog(@"dw_taskbar_delete() unimplemented\n"); | 4810 NSLog(@"dw_taskbar_delete() unimplemented\n"); |
4811 } | 4811 } |
4812 | 4812 |
4813 /* | 4813 /* |
4814 * Obtains an icon from a module (or header in GTK). | 4814 * Obtains an icon from a module (or header in GTK). |
4815 * Parameters: | 4815 * Parameters: |
4821 HICN API dw_icon_load(unsigned long module, unsigned long resid) | 4821 HICN API dw_icon_load(unsigned long module, unsigned long resid) |
4822 { | 4822 { |
4823 NSBundle *bundle = [NSBundle mainBundle]; | 4823 NSBundle *bundle = [NSBundle mainBundle]; |
4824 NSString *respath = [bundle resourcePath]; | 4824 NSString *respath = [bundle resourcePath]; |
4825 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; | 4825 NSString *filepath = [respath stringByAppendingFormat:@"/%u.png", resid]; |
4826 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; | 4826 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; |
4827 return image; | 4827 return image; |
4828 } | 4828 } |
4829 | 4829 |
4830 /* | 4830 /* |
4831 * Obtains an icon from a file. | 4831 * Obtains an icon from a file. |
4832 * Parameters: | 4832 * Parameters: |
4841 if(!image) | 4841 if(!image) |
4842 { | 4842 { |
4843 nstr = [nstr stringByAppendingString:@".png"]; | 4843 nstr = [nstr stringByAppendingString:@".png"]; |
4844 image = [[NSImage alloc] initWithContentsOfFile:nstr]; | 4844 image = [[NSImage alloc] initWithContentsOfFile:nstr]; |
4845 } | 4845 } |
4846 return image; | 4846 return image; |
4847 } | 4847 } |
4848 | 4848 |
4849 /* | 4849 /* |
4850 * Obtains an icon from data | 4850 * Obtains an icon from data |
4851 * Parameters: | 4851 * Parameters: |
4853 * DW pick the appropriate file extension. | 4853 * DW pick the appropriate file extension. |
4854 * (ICO on OS/2 or Windows, XPM on Unix) | 4854 * (ICO on OS/2 or Windows, XPM on Unix) |
4855 */ | 4855 */ |
4856 HICN API dw_icon_load_from_data(char *data, int len) | 4856 HICN API dw_icon_load_from_data(char *data, int len) |
4857 { | 4857 { |
4858 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; | 4858 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; |
4859 NSImage *image = [[NSImage alloc] initWithData:thisdata]; | 4859 NSImage *image = [[NSImage alloc] initWithData:thisdata]; |
4860 return image; | 4860 return image; |
4861 } | 4861 } |
4862 | 4862 |
4863 /* | 4863 /* |
4864 * Frees a loaded resource in OS/2 and Windows. | 4864 * Frees a loaded resource in OS/2 and Windows. |
4865 * Parameters: | 4865 * Parameters: |
4900 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long cid) | 4900 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long cid) |
4901 { | 4901 { |
4902 HWND tmpbox = dw_box_new(DW_VERT, 0); | 4902 HWND tmpbox = dw_box_new(DW_VERT, 0); |
4903 int _locked_by_me = FALSE; | 4903 int _locked_by_me = FALSE; |
4904 DW_MUTEX_LOCK; | 4904 DW_MUTEX_LOCK; |
4905 DWSplitBar *split = [[DWSplitBar alloc] init]; | 4905 DWSplitBar *split = [[DWSplitBar alloc] init]; |
4906 [split setDelegate:split]; | 4906 [split setDelegate:split]; |
4907 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0); | 4907 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0); |
4908 [split addSubview:tmpbox]; | 4908 [split addSubview:tmpbox]; |
4909 tmpbox = dw_box_new(DW_VERT, 0); | 4909 tmpbox = dw_box_new(DW_VERT, 0); |
4910 dw_box_pack_start(tmpbox, bottomright, 0, 0, TRUE, TRUE, 0); | 4910 dw_box_pack_start(tmpbox, bottomright, 0, 0, TRUE, TRUE, 0); |
4911 [split addSubview:tmpbox]; | 4911 [split addSubview:tmpbox]; |
4912 if(type == DW_VERT) | 4912 if(type == DW_VERT) |
4913 { | 4913 { |
4914 [split setVertical:NO]; | 4914 [split setVertical:NO]; |
4915 } | 4915 } |
4916 else | 4916 else |
4917 { | 4917 { |
4918 [split setVertical:YES]; | 4918 [split setVertical:YES]; |
4919 } | 4919 } |
4920 /* [split setTag:cid]; Why doesn't this work? */ | 4920 /* [split setTag:cid]; Why doesn't this work? */ |
4921 DW_MUTEX_UNLOCK; | 4921 DW_MUTEX_UNLOCK; |
4922 return split; | 4922 return split; |
4923 } | 4923 } |
4924 | 4924 |
4925 /* | 4925 /* |
4926 * Sets the position of a splitbar (pecentage). | 4926 * Sets the position of a splitbar (pecentage). |
4927 * Parameters: | 4927 * Parameters: |
4928 * handle: The handle to the splitbar returned by dw_splitbar_new(). | 4928 * handle: The handle to the splitbar returned by dw_splitbar_new(). |
4929 */ | 4929 */ |
4930 void API dw_splitbar_set(HWND handle, float percent) | 4930 void API dw_splitbar_set(HWND handle, float percent) |
4931 { | 4931 { |
4932 DWSplitBar *split = handle; | 4932 DWSplitBar *split = handle; |
4933 int _locked_by_me = FALSE; | 4933 int _locked_by_me = FALSE; |
4934 DW_MUTEX_LOCK; | 4934 DW_MUTEX_LOCK; |
4935 NSRect rect = [split frame]; | 4935 NSRect rect = [split frame]; |
4936 float pos; | 4936 float pos; |
4937 /* Calculate the position based on the size */ | 4937 /* Calculate the position based on the size */ |
4963 * Parameters: | 4963 * Parameters: |
4964 * handle: The handle to the splitbar returned by dw_splitbar_new(). | 4964 * handle: The handle to the splitbar returned by dw_splitbar_new(). |
4965 */ | 4965 */ |
4966 float API dw_splitbar_get(HWND handle) | 4966 float API dw_splitbar_get(HWND handle) |
4967 { | 4967 { |
4968 DWSplitBar *split = handle; | 4968 DWSplitBar *split = handle; |
4969 NSRect rect1 = [split frame]; | 4969 NSRect rect1 = [split frame]; |
4970 NSArray *subviews = [split subviews]; | 4970 NSArray *subviews = [split subviews]; |
4971 NSView *view = [subviews objectAtIndex:0]; | 4971 NSView *view = [subviews objectAtIndex:0]; |
4972 NSRect rect2 = [view frame]; | 4972 NSRect rect2 = [view frame]; |
4973 float pos, total, retval = 0.0; | 4973 float pos, total, retval = 0.0; |
4983 } | 4983 } |
4984 if(total > 0) | 4984 if(total > 0) |
4985 { | 4985 { |
4986 retval = pos / total; | 4986 retval = pos / total; |
4987 } | 4987 } |
4988 return retval; | 4988 return retval; |
4989 } | 4989 } |
4990 | 4990 |
4991 /* | 4991 /* |
4992 * Create a bitmap object to be packed. | 4992 * Create a bitmap object to be packed. |
4993 * Parameters: | 4993 * Parameters: |
4995 */ | 4995 */ |
4996 HWND API dw_bitmap_new(ULONG cid) | 4996 HWND API dw_bitmap_new(ULONG cid) |
4997 { | 4997 { |
4998 int _locked_by_me = FALSE; | 4998 int _locked_by_me = FALSE; |
4999 DW_MUTEX_LOCK; | 4999 DW_MUTEX_LOCK; |
5000 NSImageView *bitmap = [[NSImageView alloc] init]; | 5000 NSImageView *bitmap = [[NSImageView alloc] init]; |
5001 [bitmap setImageFrameStyle:NSImageFrameNone]; | 5001 [bitmap setImageFrameStyle:NSImageFrameNone]; |
5002 [bitmap setEditable:NO]; | 5002 [bitmap setEditable:NO]; |
5003 [bitmap setTag:cid]; | 5003 [bitmap setTag:cid]; |
5004 DW_MUTEX_UNLOCK; | 5004 DW_MUTEX_UNLOCK; |
5005 return bitmap; | 5005 return bitmap; |
5006 } | 5006 } |
5007 | 5007 |
5008 /* | 5008 /* |
5009 * Creates a pixmap with given parameters. | 5009 * Creates a pixmap with given parameters. |
5010 * Parameters: | 5010 * Parameters: |
5017 */ | 5017 */ |
5018 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) | 5018 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) |
5019 { | 5019 { |
5020 NSSize size = { (float)width, (float)height }; | 5020 NSSize size = { (float)width, (float)height }; |
5021 HPIXMAP pixmap; | 5021 HPIXMAP pixmap; |
5022 | 5022 |
5023 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 5023 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
5024 return NULL; | 5024 return NULL; |
5025 pixmap->width = width; | 5025 pixmap->width = width; |
5026 pixmap->height = height; | 5026 pixmap->height = height; |
5027 pixmap->handle = handle; | 5027 pixmap->handle = handle; |
5041 * A handle to a pixmap or NULL on failure. | 5041 * A handle to a pixmap or NULL on failure. |
5042 */ | 5042 */ |
5043 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) | 5043 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) |
5044 { | 5044 { |
5045 HPIXMAP pixmap; | 5045 HPIXMAP pixmap; |
5046 | 5046 |
5047 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 5047 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
5048 return NULL; | 5048 return NULL; |
5049 NSString *nstr = [ NSString stringWithUTF8String:filename ]; | 5049 NSString *nstr = [ NSString stringWithUTF8String:filename ]; |
5050 NSImage *image = [[NSImage alloc] initWithContentsOfFile:nstr]; | 5050 NSImage *image = [[NSImage alloc] initWithContentsOfFile:nstr]; |
5051 if(!image) | 5051 if(!image) |
5073 * A handle to a pixmap or NULL on failure. | 5073 * A handle to a pixmap or NULL on failure. |
5074 */ | 5074 */ |
5075 HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len) | 5075 HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len) |
5076 { | 5076 { |
5077 HPIXMAP pixmap; | 5077 HPIXMAP pixmap; |
5078 | 5078 |
5079 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 5079 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
5080 return NULL; | 5080 return NULL; |
5081 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; | 5081 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; |
5082 NSImage *image = [[NSImage alloc] initWithData:thisdata]; | 5082 NSImage *image = [[NSImage alloc] initWithData:thisdata]; |
5083 NSSize size = [image size]; | 5083 NSSize size = [image size]; |
5092 /* | 5092 /* |
5093 * Creates a bitmap mask for rendering bitmaps with transparent backgrounds | 5093 * Creates a bitmap mask for rendering bitmaps with transparent backgrounds |
5094 */ | 5094 */ |
5095 void API dw_pixmap_set_transparent_color( HPIXMAP pixmap, ULONG color ) | 5095 void API dw_pixmap_set_transparent_color( HPIXMAP pixmap, ULONG color ) |
5096 { | 5096 { |
5097 NSLog(@"dw_pixmap_set_transparent_color() unimplemented\n"); | 5097 NSLog(@"dw_pixmap_set_transparent_color() unimplemented\n"); |
5098 } | 5098 } |
5099 | 5099 |
5100 /* | 5100 /* |
5101 * Creates a pixmap from internal resource graphic specified by id. | 5101 * Creates a pixmap from internal resource graphic specified by id. |
5102 * Parameters: | 5102 * Parameters: |
5106 * A handle to a pixmap or NULL on failure. | 5106 * A handle to a pixmap or NULL on failure. |
5107 */ | 5107 */ |
5108 HPIXMAP API dw_pixmap_grab(HWND handle, ULONG resid) | 5108 HPIXMAP API dw_pixmap_grab(HWND handle, ULONG resid) |
5109 { | 5109 { |
5110 HPIXMAP pixmap; | 5110 HPIXMAP pixmap; |
5111 | 5111 |
5112 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 5112 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
5113 return NULL; | 5113 return NULL; |
5114 | 5114 |
5115 NSBundle *bundle = [NSBundle mainBundle]; | 5115 NSBundle *bundle = [NSBundle mainBundle]; |
5116 NSString *respath = [bundle resourcePath]; | 5116 NSString *respath = [bundle resourcePath]; |
5131 * pixmap: Handle to a pixmap returned by | 5131 * pixmap: Handle to a pixmap returned by |
5132 * dw_pixmap_new.. | 5132 * dw_pixmap_new.. |
5133 */ | 5133 */ |
5134 void API dw_pixmap_destroy(HPIXMAP pixmap) | 5134 void API dw_pixmap_destroy(HPIXMAP pixmap) |
5135 { | 5135 { |
5136 NSImage *image = (NSImage *)pixmap->image; | 5136 NSImage *image = (NSImage *)pixmap->image; |
5137 [image dealloc]; | 5137 [image dealloc]; |
5138 free(pixmap); | 5138 free(pixmap); |
5139 } | 5139 } |
5140 | 5140 |
5141 /* | 5141 /* |
5142 * Copies from one item to another. | 5142 * Copies from one item to another. |
5143 * Parameters: | 5143 * Parameters: |
5205 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) | 5205 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) |
5206 { | 5206 { |
5207 DWCalendar *calendar = handle; | 5207 DWCalendar *calendar = handle; |
5208 NSDate *date; | 5208 NSDate *date; |
5209 char buffer[100]; | 5209 char buffer[100]; |
5210 | 5210 |
5211 sprintf(buffer, "%04d-%02d-%02d 00:00:00 +0600", year, month, day); | 5211 sprintf(buffer, "%04d-%02d-%02d 00:00:00 +0600", year, month, day); |
5212 | 5212 |
5213 date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]]; | 5213 date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]]; |
5214 [calendar setDateValue:date]; | 5214 [calendar setDateValue:date]; |
5215 [date release]; | 5215 [date release]; |
5216 } | 5216 } |
5217 | 5217 |
5245 * handle: Handle to the window. | 5245 * handle: Handle to the window. |
5246 * action: One of the DW_HTML_* constants. | 5246 * action: One of the DW_HTML_* constants. |
5247 */ | 5247 */ |
5248 void API dw_html_action(HWND handle, int action) | 5248 void API dw_html_action(HWND handle, int action) |
5249 { | 5249 { |
5250 WebView *html = handle; | 5250 WebView *html = handle; |
5251 switch(action) | 5251 switch(action) |
5252 { | 5252 { |
5253 case DW_HTML_GOBACK: | 5253 case DW_HTML_GOBACK: |
5254 [html goBack]; | 5254 [html goBack]; |
5255 break; | 5255 break; |
5256 case DW_HTML_GOFORWARD: | 5256 case DW_HTML_GOFORWARD: |
5257 [html goForward]; | 5257 [html goForward]; |
5258 break; | 5258 break; |
5259 case DW_HTML_GOHOME: | 5259 case DW_HTML_GOHOME: |
5260 break; | 5260 break; |
5261 case DW_HTML_SEARCH: | 5261 case DW_HTML_SEARCH: |
5262 break; | 5262 break; |
5263 case DW_HTML_RELOAD: | 5263 case DW_HTML_RELOAD: |
5264 [html reload:html]; | 5264 [html reload:html]; |
5265 break; | 5265 break; |
5266 case DW_HTML_STOP: | 5266 case DW_HTML_STOP: |
5267 [html stopLoading:html]; | 5267 [html stopLoading:html]; |
5268 break; | 5268 break; |
5269 case DW_HTML_PRINT: | 5269 case DW_HTML_PRINT: |
5270 break; | 5270 break; |
5271 } | 5271 } |
5272 } | 5272 } |
5273 | 5273 |
5274 /* | 5274 /* |
5275 * Render raw HTML code in the embedded HTML widget.. | 5275 * Render raw HTML code in the embedded HTML widget.. |
5276 * Parameters: | 5276 * Parameters: |
5280 * Returns: | 5280 * Returns: |
5281 * 0 on success. | 5281 * 0 on success. |
5282 */ | 5282 */ |
5283 int API dw_html_raw(HWND handle, char *string) | 5283 int API dw_html_raw(HWND handle, char *string) |
5284 { | 5284 { |
5285 WebView *html = handle; | 5285 WebView *html = handle; |
5286 [[html mainFrame] loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil]; | 5286 [[html mainFrame] loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil]; |
5287 return 0; | 5287 return 0; |
5288 } | 5288 } |
5289 | 5289 |
5290 /* | 5290 /* |
5291 * Render file or web page in the embedded HTML widget.. | 5291 * Render file or web page in the embedded HTML widget.. |
5292 * Parameters: | 5292 * Parameters: |
5296 * Returns: | 5296 * Returns: |
5297 * 0 on success. | 5297 * 0 on success. |
5298 */ | 5298 */ |
5299 int API dw_html_url(HWND handle, char *url) | 5299 int API dw_html_url(HWND handle, char *url) |
5300 { | 5300 { |
5301 WebView *html = handle; | 5301 WebView *html = handle; |
5302 [[html mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]]; | 5302 [[html mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]]; |
5303 return 0; | 5303 return 0; |
5304 } | 5304 } |
5305 | 5305 |
5306 /* | 5306 /* |
5307 * Create a new HTML window (widget) to be packed. | 5307 * Create a new HTML window (widget) to be packed. |
5308 * Not available under OS/2, eCS | 5308 * Not available under OS/2, eCS |
5312 */ | 5312 */ |
5313 HWND API dw_html_new(unsigned long cid) | 5313 HWND API dw_html_new(unsigned long cid) |
5314 { | 5314 { |
5315 int _locked_by_me = FALSE; | 5315 int _locked_by_me = FALSE; |
5316 DW_MUTEX_LOCK; | 5316 DW_MUTEX_LOCK; |
5317 WebView *web = [[WebView alloc] init]; | 5317 WebView *web = [[WebView alloc] init]; |
5318 /* [web setTag:cid]; Why doesn't this work? */ | 5318 /* [web setTag:cid]; Why doesn't this work? */ |
5319 DW_MUTEX_UNLOCK; | 5319 DW_MUTEX_UNLOCK; |
5320 return web; | 5320 return web; |
5321 } | 5321 } |
5322 | 5322 |
5323 /* | 5323 /* |
5324 * Returns the current X and Y coordinates of the mouse pointer. | 5324 * Returns the current X and Y coordinates of the mouse pointer. |
5325 * Parameters: | 5325 * Parameters: |
5328 */ | 5328 */ |
5329 void API dw_pointer_query_pos(long *x, long *y) | 5329 void API dw_pointer_query_pos(long *x, long *y) |
5330 { | 5330 { |
5331 NSPoint mouseLoc; | 5331 NSPoint mouseLoc; |
5332 mouseLoc = [NSEvent mouseLocation]; | 5332 mouseLoc = [NSEvent mouseLocation]; |
5333 if(x) | 5333 if(x) |
5334 { | 5334 { |
5335 *x = mouseLoc.x; | 5335 *x = mouseLoc.x; |
5336 } | 5336 } |
5337 if(y) | 5337 if(y) |
5338 { | 5338 { |
5339 *y = mouseLoc.y; | 5339 *y = mouseLoc.y; |
5340 } | 5340 } |
5341 } | 5341 } |
5342 | 5342 |
5343 /* | 5343 /* |
5344 * Sets the X and Y coordinates of the mouse pointer. | 5344 * Sets the X and Y coordinates of the mouse pointer. |
5345 * Parameters: | 5345 * Parameters: |
5346 * x: X coordinate. | 5346 * x: X coordinate. |
5347 * y: Y coordinate. | 5347 * y: Y coordinate. |
5348 */ | 5348 */ |
5349 void API dw_pointer_set_pos(long x, long y) | 5349 void API dw_pointer_set_pos(long x, long y) |
5350 { | 5350 { |
5351 /* From what I have read this isn't possible, agaist human interface rules */ | 5351 /* From what I have read this isn't possible, agaist human interface rules */ |
5352 } | 5352 } |
5353 | 5353 |
5354 /* | 5354 /* |
5355 * Create a menu object to be popped up. | 5355 * Create a menu object to be popped up. |
5356 * Parameters: | 5356 * Parameters: |
5357 * id: An ID to be used for getting the resource from the | 5357 * id: An ID to be used for getting the resource from the |
5358 * resource file. | 5358 * resource file. |
5359 */ | 5359 */ |
5360 HMENUI API dw_menu_new(ULONG cid) | 5360 HMENUI API dw_menu_new(ULONG cid) |
5361 { | 5361 { |
5362 NSMenu *menu = [[[NSMenu alloc] init] autorelease]; | 5362 NSMenu *menu = [[[NSMenu alloc] init] autorelease]; |
5363 [menu setAutoenablesItems:NO]; | 5363 [menu setAutoenablesItems:NO]; |
5364 /* [menu setTag:cid]; Why doesn't this work? */ | 5364 /* [menu setTag:cid]; Why doesn't this work? */ |
5365 return menu; | 5365 return menu; |
5366 } | 5366 } |
5367 | 5367 |
5368 /* | 5368 /* |
5369 * Create a menubar on a window. | 5369 * Create a menubar on a window. |
5370 * Parameters: | 5370 * Parameters: |
5371 * location: Handle of a window frame to be attached to. | 5371 * location: Handle of a window frame to be attached to. |
5372 */ | 5372 */ |
5373 HMENUI API dw_menubar_new(HWND location) | 5373 HMENUI API dw_menubar_new(HWND location) |
5374 { | 5374 { |
5375 NSWindow *window = location; | 5375 NSWindow *window = location; |
5376 NSMenu *windowmenu = _generate_main_menu(); | 5376 NSMenu *windowmenu = _generate_main_menu(); |
5377 [[window contentView] setMenu:windowmenu]; | 5377 [[window contentView] setMenu:windowmenu]; |
5378 return (HMENUI)windowmenu; | 5378 return (HMENUI)windowmenu; |
5379 } | 5379 } |
5380 | 5380 |
5381 /* | 5381 /* |
5382 * Destroys a menu created with dw_menubar_new or dw_menu_new. | 5382 * Destroys a menu created with dw_menubar_new or dw_menu_new. |
5383 * Parameters: | 5383 * Parameters: |
5384 * menu: Handle of a menu. | 5384 * menu: Handle of a menu. |
5385 */ | 5385 */ |
5386 void API dw_menu_destroy(HMENUI *menu) | 5386 void API dw_menu_destroy(HMENUI *menu) |
5387 { | 5387 { |
5388 NSMenu *thismenu = *menu; | 5388 NSMenu *thismenu = *menu; |
5389 [thismenu release]; | 5389 [thismenu release]; |
5390 } | 5390 } |
5391 | 5391 |
5392 /* | 5392 /* |
5393 * Pops up a context menu at given x and y coordinates. | 5393 * Pops up a context menu at given x and y coordinates. |
5394 * Parameters: | 5394 * Parameters: |
5416 [NSMenu popUpContextMenu:thismenu withEvent:fake forView:view]; | 5416 [NSMenu popUpContextMenu:thismenu withEvent:fake forView:view]; |
5417 } | 5417 } |
5418 | 5418 |
5419 char _removetilde(char *dest, char *src) | 5419 char _removetilde(char *dest, char *src) |
5420 { | 5420 { |
5421 int z, cur=0; | 5421 int z, cur=0; |
5422 char accel = '\0'; | 5422 char accel = '\0'; |
5423 | 5423 |
5424 for(z=0;z<strlen(src);z++) | 5424 for(z=0;z<strlen(src);z++) |
5425 { | 5425 { |
5426 if(src[z] != '~') | 5426 if(src[z] != '~') |
5427 { | 5427 { |
5428 dest[cur] = src[z]; | 5428 dest[cur] = src[z]; |
5429 cur++; | 5429 cur++; |
5430 } | 5430 } |
5431 else | 5431 else |
5432 { | 5432 { |
5433 accel = src[z+1]; | 5433 accel = src[z+1]; |
5434 } | 5434 } |
5435 } | 5435 } |
5436 dest[cur] = 0; | 5436 dest[cur] = 0; |
5437 return accel; | 5437 return accel; |
5438 } | 5438 } |
5439 | 5439 |
5440 /* | 5440 /* |
5441 * Adds a menuitem or submenu to an existing menu. | 5441 * Adds a menuitem or submenu to an existing menu. |
5442 * Parameters: | 5442 * Parameters: |
5449 * flags: Extended attributes to set on the menu. | 5449 * flags: Extended attributes to set on the menu. |
5450 * submenu: Handle to an existing menu to be a submenu or NULL. | 5450 * submenu: Handle to an existing menu to be a submenu or NULL. |
5451 */ | 5451 */ |
5452 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux) | 5452 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux) |
5453 { | 5453 { |
5454 NSMenu *menu = menux; | 5454 NSMenu *menu = menux; |
5455 NSMenu *submenu = submenux; | 5455 NSMenu *submenu = submenux; |
5456 NSMenuItem *item = NULL; | 5456 NSMenuItem *item = NULL; |
5457 if(strlen(title) == 0) | 5457 if(strlen(title) == 0) |
5458 { | 5458 { |
5459 [menu addItem:[NSMenuItem separatorItem]]; | 5459 [menu addItem:[NSMenuItem separatorItem]]; |
5460 } | 5460 } |
5461 else | 5461 else |
5462 { | 5462 { |
5463 char accel[2]; | 5463 char accel[2]; |
5464 char *newtitle = malloc(strlen(title)+1); | 5464 char *newtitle = malloc(strlen(title)+1); |
5465 NSString *nstr; | 5465 NSString *nstr; |
5466 | 5466 |
5467 accel[0] = _removetilde(newtitle, title); | 5467 accel[0] = _removetilde(newtitle, title); |
5468 accel[1] = 0; | 5468 accel[1] = 0; |
5469 | 5469 |
5470 nstr = [ NSString stringWithUTF8String:newtitle ]; | 5470 nstr = [ NSString stringWithUTF8String:newtitle ]; |
5471 free(newtitle); | 5471 free(newtitle); |
5472 | 5472 |
5473 item = [menu addItemWithTitle: nstr | 5473 item = [menu addItemWithTitle: nstr |
5474 action:@selector(menuHandler:) | 5474 action:@selector(menuHandler:) |
5475 keyEquivalent:[ NSString stringWithUTF8String:accel ]]; | 5475 keyEquivalent:[ NSString stringWithUTF8String:accel ]]; |
5476 [item setTag:itemid]; | 5476 [item setTag:itemid]; |
5477 if(flags & DW_MIS_CHECKED) | 5477 if(flags & DW_MIS_CHECKED) |
5478 { | 5478 { |
5479 [item setState:NSOnState]; | 5479 [item setState:NSOnState]; |
5480 } | 5480 } |
5481 if(flags & DW_MIS_DISABLED) | 5481 if(flags & DW_MIS_DISABLED) |
5482 { | 5482 { |
5483 [item setEnabled:NO]; | 5483 [item setEnabled:NO]; |
5484 } | 5484 } |
5485 | 5485 |
5486 if(submenux) | 5486 if(submenux) |
5487 { | 5487 { |
5488 [submenu setTitle:nstr]; | 5488 [submenu setTitle:nstr]; |
5489 [menu setSubmenu:submenu forItem:item]; | 5489 [menu setSubmenu:submenu forItem:item]; |
5490 } | 5490 } |
5491 return item; | 5491 return item; |
5492 } | 5492 } |
5493 return item; | 5493 return item; |
5494 } | 5494 } |
5495 | 5495 |
5496 /* | 5496 /* |
5497 * Sets the state of a menu item check. | 5497 * Sets the state of a menu item check. |
5498 * Deprecated; use dw_menu_item_set_state() | 5498 * Deprecated; use dw_menu_item_set_state() |
5501 * id: Menuitem id. | 5501 * id: Menuitem id. |
5502 * check: TRUE for checked FALSE for not checked. | 5502 * check: TRUE for checked FALSE for not checked. |
5503 */ | 5503 */ |
5504 void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check) | 5504 void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check) |
5505 { | 5505 { |
5506 id menu = menux; | 5506 id menu = menux; |
5507 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid]; | 5507 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid]; |
5508 | 5508 |
5509 if(menuitem != nil) | 5509 if(menuitem != nil) |
5510 { | 5510 { |
5511 if(check) | 5511 if(check) |
5512 { | 5512 { |
5513 [menuitem setState:NSOnState]; | 5513 [menuitem setState:NSOnState]; |
5514 } | 5514 } |
5515 else | 5515 else |
5516 { | 5516 { |
5517 [menuitem setState:NSOffState]; | 5517 [menuitem setState:NSOffState]; |
5518 } | 5518 } |
5519 } | 5519 } |
5520 } | 5520 } |
5521 | 5521 |
5522 /* | 5522 /* |
5523 * Sets the state of a menu item. | 5523 * Sets the state of a menu item. |
5524 * Parameters: | 5524 * Parameters: |
5527 * flags: DW_MIS_ENABLED/DW_MIS_DISABLED | 5527 * flags: DW_MIS_ENABLED/DW_MIS_DISABLED |
5528 * DW_MIS_CHECKED/DW_MIS_UNCHECKED | 5528 * DW_MIS_CHECKED/DW_MIS_UNCHECKED |
5529 */ | 5529 */ |
5530 void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state) | 5530 void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state) |
5531 { | 5531 { |
5532 id menu = menux; | 5532 id menu = menux; |
5533 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid]; | 5533 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid]; |
5534 | 5534 |
5535 if(menuitem != nil) | 5535 if(menuitem != nil) |
5536 { | 5536 { |
5537 if(state & DW_MIS_CHECKED) | 5537 if(state & DW_MIS_CHECKED) |
5538 { | 5538 { |
5539 [menuitem setState:NSOnState]; | 5539 [menuitem setState:NSOnState]; |
5540 } | 5540 } |
5541 else if(state & DW_MIS_UNCHECKED) | 5541 else if(state & DW_MIS_UNCHECKED) |
5542 { | 5542 { |
5543 [menuitem setState:NSOffState]; | 5543 [menuitem setState:NSOffState]; |
5544 } | 5544 } |
5545 if(state & DW_MIS_ENABLED) | 5545 if(state & DW_MIS_ENABLED) |
5546 { | 5546 { |
5547 [menuitem setEnabled:YES]; | 5547 [menuitem setEnabled:YES]; |
5548 } | 5548 } |
5549 else if(state & DW_MIS_DISABLED) | 5549 else if(state & DW_MIS_DISABLED) |
5550 { | 5550 { |
5551 [menuitem setEnabled:NO]; | 5551 [menuitem setEnabled:NO]; |
5552 } | 5552 } |
5553 } | 5553 } |
5554 } | 5554 } |
5555 | 5555 |
5556 /* Gets the notebook page from associated ID */ | 5556 /* Gets the notebook page from associated ID */ |
5557 DWNotebookPage *_notepage_from_id(DWNotebook *notebook, unsigned long pageid) | 5557 DWNotebookPage *_notepage_from_id(DWNotebook *notebook, unsigned long pageid) |
5558 { | 5558 { |
5559 NSArray *pages = [notebook tabViewItems]; | 5559 NSArray *pages = [notebook tabViewItems]; |
5560 for(DWNotebookPage *notepage in pages) | 5560 for(DWNotebookPage *notepage in pages) |
5561 { | 5561 { |
5562 if([notepage pageid] == pageid) | 5562 if([notepage pageid] == pageid) |
5563 { | 5563 { |
5564 return notepage; | 5564 return notepage; |
5565 } | 5565 } |
5566 } | 5566 } |
5567 return nil; | 5567 return nil; |
5568 } | 5568 } |
5569 | 5569 |
5570 /* | 5570 /* |
5571 * Create a notebook object to be packed. | 5571 * Create a notebook object to be packed. |
5572 * Parameters: | 5572 * Parameters: |
5573 * id: An ID to be used for getting the resource from the | 5573 * id: An ID to be used for getting the resource from the |
5574 * resource file. | 5574 * resource file. |
5575 */ | 5575 */ |
5576 HWND API dw_notebook_new(ULONG cid, int top) | 5576 HWND API dw_notebook_new(ULONG cid, int top) |
5577 { | 5577 { |
5578 DWNotebook *notebook = [[DWNotebook alloc] init]; | 5578 DWNotebook *notebook = [[DWNotebook alloc] init]; |
5579 [notebook setDelegate:notebook]; | 5579 [notebook setDelegate:notebook]; |
5580 /* [notebook setTag:cid]; Why doesn't this work? */ | 5580 /* [notebook setTag:cid]; Why doesn't this work? */ |
5581 return notebook; | 5581 return notebook; |
5582 } | 5582 } |
5583 | 5583 |
5584 /* | 5584 /* |
5585 * Adds a new page to specified notebook. | 5585 * Adds a new page to specified notebook. |
5586 * Parameters: | 5586 * Parameters: |
5588 * flags: Any additional page creation flags. | 5588 * flags: Any additional page creation flags. |
5589 * front: If TRUE page is added at the beginning. | 5589 * front: If TRUE page is added at the beginning. |
5590 */ | 5590 */ |
5591 unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front) | 5591 unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front) |
5592 { | 5592 { |
5593 DWNotebook *notebook = handle; | 5593 DWNotebook *notebook = handle; |
5594 NSInteger page = [notebook pageid]; | 5594 NSInteger page = [notebook pageid]; |
5595 DWNotebookPage *notepage = [[DWNotebookPage alloc] initWithIdentifier:nil]; | 5595 DWNotebookPage *notepage = [[DWNotebookPage alloc] initWithIdentifier:nil]; |
5596 [notepage setPageid:(NSInteger)page]; | 5596 [notepage setPageid:(NSInteger)page]; |
5597 if(front) | 5597 if(front) |
5598 { | 5598 { |
5599 [notebook insertTabViewItem:notepage atIndex:(NSInteger)0]; | 5599 [notebook insertTabViewItem:notepage atIndex:(NSInteger)0]; |
5600 } | 5600 } |
5601 else | 5601 else |
5602 { | 5602 { |
5603 [notebook addTabViewItem:notepage]; | 5603 [notebook addTabViewItem:notepage]; |
5604 } | 5604 } |
5605 [notebook setPageid:(page+1)]; | 5605 [notebook setPageid:(page+1)]; |
5606 [notepage release]; | 5606 [notepage release]; |
5607 return (unsigned long)page; | 5607 return (unsigned long)page; |
5608 } | 5608 } |
5609 | 5609 |
5610 /* | 5610 /* |
5611 * Remove a page from a notebook. | 5611 * Remove a page from a notebook. |
5612 * Parameters: | 5612 * Parameters: |
5613 * handle: Handle to the notebook widget. | 5613 * handle: Handle to the notebook widget. |
5614 * pageid: ID of the page to be destroyed. | 5614 * pageid: ID of the page to be destroyed. |
5615 */ | 5615 */ |
5616 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid) | 5616 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid) |
5617 { | 5617 { |
5618 DWNotebook *notebook = handle; | 5618 DWNotebook *notebook = handle; |
5619 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 5619 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
5620 | 5620 |
5621 if(notepage != nil) | 5621 if(notepage != nil) |
5622 { | 5622 { |
5623 [notebook removeTabViewItem:notepage]; | 5623 [notebook removeTabViewItem:notepage]; |
5624 [notepage release]; | 5624 [notepage release]; |
5625 } | 5625 } |
5626 } | 5626 } |
5627 | 5627 |
5628 /* | 5628 /* |
5629 * Queries the currently visible page ID. | 5629 * Queries the currently visible page ID. |
5630 * Parameters: | 5630 * Parameters: |
5631 * handle: Handle to the notebook widget. | 5631 * handle: Handle to the notebook widget. |
5632 */ | 5632 */ |
5633 unsigned long API dw_notebook_page_get(HWND handle) | 5633 unsigned long API dw_notebook_page_get(HWND handle) |
5634 { | 5634 { |
5635 DWNotebook *notebook = handle; | 5635 DWNotebook *notebook = handle; |
5636 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; | 5636 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; |
5637 return [notepage pageid]; | 5637 return [notepage pageid]; |
5638 } | 5638 } |
5639 | 5639 |
5640 /* | 5640 /* |
5641 * Sets the currently visibale page ID. | 5641 * Sets the currently visibale page ID. |
5642 * Parameters: | 5642 * Parameters: |
5643 * handle: Handle to the notebook widget. | 5643 * handle: Handle to the notebook widget. |
5644 * pageid: ID of the page to be made visible. | 5644 * pageid: ID of the page to be made visible. |
5645 */ | 5645 */ |
5646 void API dw_notebook_page_set(HWND handle, unsigned int pageid) | 5646 void API dw_notebook_page_set(HWND handle, unsigned int pageid) |
5647 { | 5647 { |
5648 DWNotebook *notebook = handle; | 5648 DWNotebook *notebook = handle; |
5649 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 5649 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
5650 | 5650 |
5651 if(notepage != nil) | 5651 if(notepage != nil) |
5652 { | 5652 { |
5653 [notebook selectTabViewItem:notepage]; | 5653 [notebook selectTabViewItem:notepage]; |
5654 } | 5654 } |
5655 } | 5655 } |
5656 | 5656 |
5657 /* | 5657 /* |
5658 * Sets the text on the specified notebook tab. | 5658 * Sets the text on the specified notebook tab. |
5659 * Parameters: | 5659 * Parameters: |
5661 * pageid: Page ID of the tab to set. | 5661 * pageid: Page ID of the tab to set. |
5662 * text: Pointer to the text to set. | 5662 * text: Pointer to the text to set. |
5663 */ | 5663 */ |
5664 void API dw_notebook_page_set_text(HWND handle, ULONG pageid, char *text) | 5664 void API dw_notebook_page_set_text(HWND handle, ULONG pageid, char *text) |
5665 { | 5665 { |
5666 DWNotebook *notebook = handle; | 5666 DWNotebook *notebook = handle; |
5667 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 5667 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
5668 | 5668 |
5669 if(notepage != nil) | 5669 if(notepage != nil) |
5670 { | 5670 { |
5671 [notepage setLabel:[ NSString stringWithUTF8String:text ]]; | 5671 [notepage setLabel:[ NSString stringWithUTF8String:text ]]; |
5672 } | 5672 } |
5673 } | 5673 } |
5674 | 5674 |
5675 /* | 5675 /* |
5676 * Sets the text on the specified notebook tab status area. | 5676 * Sets the text on the specified notebook tab status area. |
5677 * Parameters: | 5677 * Parameters: |
5679 * pageid: Page ID of the tab to set. | 5679 * pageid: Page ID of the tab to set. |
5680 * text: Pointer to the text to set. | 5680 * text: Pointer to the text to set. |
5681 */ | 5681 */ |
5682 void API dw_notebook_page_set_status_text(HWND handle, ULONG pageid, char *text) | 5682 void API dw_notebook_page_set_status_text(HWND handle, ULONG pageid, char *text) |
5683 { | 5683 { |
5684 /* Note supported here... do nothing */ | 5684 /* Note supported here... do nothing */ |
5685 } | 5685 } |
5686 | 5686 |
5687 /* | 5687 /* |
5688 * Packs the specified box into the notebook page. | 5688 * Packs the specified box into the notebook page. |
5689 * Parameters: | 5689 * Parameters: |
5691 * pageid: Page ID in the notebook which is being packed. | 5691 * pageid: Page ID in the notebook which is being packed. |
5692 * page: Box handle to be packed. | 5692 * page: Box handle to be packed. |
5693 */ | 5693 */ |
5694 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page) | 5694 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page) |
5695 { | 5695 { |
5696 DWNotebook *notebook = handle; | 5696 DWNotebook *notebook = handle; |
5697 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 5697 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
5698 | 5698 |
5699 if(notepage != nil) | 5699 if(notepage != nil) |
5700 { | 5700 { |
5701 HWND tmpbox = dw_box_new(DW_VERT, 0); | 5701 HWND tmpbox = dw_box_new(DW_VERT, 0); |
5702 DWBox *box = tmpbox; | 5702 DWBox *box = tmpbox; |
5703 | 5703 |
5704 dw_box_pack_start(tmpbox, page, 0, 0, TRUE, TRUE, 0); | 5704 dw_box_pack_start(tmpbox, page, 0, 0, TRUE, TRUE, 0); |
5705 [notepage setView:box]; | 5705 [notepage setView:box]; |
5706 } | 5706 } |
5707 } | 5707 } |
5708 | 5708 |
5709 /* | 5709 /* |
5710 * Create a new Window Frame. | 5710 * Create a new Window Frame. |
5711 * Parameters: | 5711 * Parameters: |
5723 styleMask:(flStyle | NSTexturedBackgroundWindowMask) | 5723 styleMask:(flStyle | NSTexturedBackgroundWindowMask) |
5724 backing:NSBackingStoreBuffered | 5724 backing:NSBackingStoreBuffered |
5725 defer:false]; | 5725 defer:false]; |
5726 | 5726 |
5727 [window setTitle:[ NSString stringWithUTF8String:title ]]; | 5727 [window setTitle:[ NSString stringWithUTF8String:title ]]; |
5728 | 5728 |
5729 DWView *view = [[DWView alloc] init]; | 5729 DWView *view = [[DWView alloc] init]; |
5730 | 5730 |
5731 [window setContentView:view]; | 5731 [window setContentView:view]; |
5732 [window setDelegate:view]; | 5732 [window setDelegate:view]; |
5733 [view release]; | 5733 [view release]; |
5734 | 5734 |
5735 /* If it isn't a toplevel window... */ | 5735 /* If it isn't a toplevel window... */ |
5775 */ | 5775 */ |
5776 void API dw_window_set_pointer(HWND handle, int pointertype) | 5776 void API dw_window_set_pointer(HWND handle, int pointertype) |
5777 { | 5777 { |
5778 id object = handle; | 5778 id object = handle; |
5779 | 5779 |
5780 if([ object isKindOfClass:[ NSView class ] ]) | 5780 if([ object isKindOfClass:[ NSView class ] ]) |
5781 { | 5781 { |
5782 NSView *view = handle; | 5782 NSView *view = handle; |
5783 | 5783 |
5784 if(pointertype == DW_POINTER_DEFAULT) | 5784 if(pointertype == DW_POINTER_DEFAULT) |
5785 { | 5785 { |
5786 [view discardCursorRects]; | 5786 [view discardCursorRects]; |
5787 } | 5787 } |
5802 * handle: The window handle to make visible. | 5802 * handle: The window handle to make visible. |
5803 */ | 5803 */ |
5804 int API dw_window_show(HWND handle) | 5804 int API dw_window_show(HWND handle) |
5805 { | 5805 { |
5806 NSObject *object = handle; | 5806 NSObject *object = handle; |
5807 | 5807 |
5808 if([ object isKindOfClass:[ NSWindow class ] ]) | 5808 if([ object isKindOfClass:[ NSWindow class ] ]) |
5809 { | 5809 { |
5810 NSWindow *window = handle; | 5810 NSWindow *window = handle; |
5811 NSRect rect = [window frame]; | 5811 NSRect rect = [window frame]; |
5812 if([window isMiniaturized]) | 5812 if([window isMiniaturized]) |
5831 * Parameters: | 5831 * Parameters: |
5832 * handle: The window handle to make visible. | 5832 * handle: The window handle to make visible. |
5833 */ | 5833 */ |
5834 int API dw_window_hide(HWND handle) | 5834 int API dw_window_hide(HWND handle) |
5835 { | 5835 { |
5836 NSObject *object = handle; | 5836 NSObject *object = handle; |
5837 | 5837 |
5838 if([ object isKindOfClass:[ NSWindow class ] ]) | 5838 if([ object isKindOfClass:[ NSWindow class ] ]) |
5839 { | 5839 { |
5840 NSWindow *window = handle; | 5840 NSWindow *window = handle; |
5841 | 5841 |
5842 [window orderOut:nil]; | 5842 [window orderOut:nil]; |
5843 } | 5843 } |
5844 return 0; | 5844 return 0; |
5845 } | 5845 } |
5846 | 5846 |
5847 /* | 5847 /* |
5848 * Sets the colors used by a specified window (widget) handle. | 5848 * Sets the colors used by a specified window (widget) handle. |
5849 * Parameters: | 5849 * Parameters: |
5856 id object = handle; | 5856 id object = handle; |
5857 unsigned long _fore = _get_color(fore); | 5857 unsigned long _fore = _get_color(fore); |
5858 unsigned long _back = _get_color(back); | 5858 unsigned long _back = _get_color(back); |
5859 NSColor *fg = [NSColor colorWithDeviceRed: DW_RED_VALUE(_fore)/255.0 green: DW_GREEN_VALUE(_fore)/255.0 blue: DW_BLUE_VALUE(_fore)/255.0 alpha: 1]; | 5859 NSColor *fg = [NSColor colorWithDeviceRed: DW_RED_VALUE(_fore)/255.0 green: DW_GREEN_VALUE(_fore)/255.0 blue: DW_BLUE_VALUE(_fore)/255.0 alpha: 1]; |
5860 NSColor *bg = [NSColor colorWithDeviceRed: DW_RED_VALUE(_back)/255.0 green: DW_GREEN_VALUE(_back)/255.0 blue: DW_BLUE_VALUE(_back)/255.0 alpha: 1]; | 5860 NSColor *bg = [NSColor colorWithDeviceRed: DW_RED_VALUE(_back)/255.0 green: DW_GREEN_VALUE(_back)/255.0 blue: DW_BLUE_VALUE(_back)/255.0 alpha: 1]; |
5861 | 5861 |
5862 if([object isMemberOfClass:[NSTextFieldCell class]]) | 5862 if([object isMemberOfClass:[NSTextFieldCell class]]) |
5863 { | 5863 { |
5864 NSTextFieldCell *text = object; | 5864 NSTextFieldCell *text = object; |
5865 [text setTextColor:fg]; | 5865 [text setTextColor:fg]; |
5866 } | 5866 } |
5867 else if([object isMemberOfClass:[DWBox class]]) | 5867 else if([object isMemberOfClass:[DWBox class]]) |
5868 { | 5868 { |
5869 DWBox *box = object; | 5869 DWBox *box = object; |
5870 | 5870 |
5871 [box setColor:_back]; | 5871 [box setColor:_back]; |
5872 } | 5872 } |
5873 else if([object isMemberOfClass:[DWButton class]]) | 5873 else if([object isMemberOfClass:[DWButton class]]) |
5874 { | 5874 { |
5875 DWButton *button = object; | 5875 DWButton *button = object; |
5876 | 5876 |
5885 * handle: The window (widget) handle. | 5885 * handle: The window (widget) handle. |
5886 * border: Size of the window border in pixels. | 5886 * border: Size of the window border in pixels. |
5887 */ | 5887 */ |
5888 int API dw_window_set_border(HWND handle, int border) | 5888 int API dw_window_set_border(HWND handle, int border) |
5889 { | 5889 { |
5890 return 0; | 5890 return 0; |
5891 } | 5891 } |
5892 | 5892 |
5893 /* | 5893 /* |
5894 * Sets the style of a given window (widget). | 5894 * Sets the style of a given window (widget). |
5895 * Parameters: | 5895 * Parameters: |
5897 * width: New width in pixels. | 5897 * width: New width in pixels. |
5898 * height: New height in pixels. | 5898 * height: New height in pixels. |
5899 */ | 5899 */ |
5900 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) | 5900 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) |
5901 { | 5901 { |
5902 id object = handle; | 5902 id object = handle; |
5903 | 5903 |
5904 if(DWOSMinor > 5 && [object isMemberOfClass:[NSWindow class]]) | 5904 if(DWOSMinor > 5 && [object isMemberOfClass:[NSWindow class]]) |
5905 { | 5905 { |
5906 NSWindow *window = object; | 5906 NSWindow *window = object; |
5907 int currentstyle = (int)[window styleMask]; | 5907 int currentstyle = (int)[window styleMask]; |
5908 int tmp; | 5908 int tmp; |
5909 | 5909 |
5910 tmp = currentstyle | (int)mask; | 5910 tmp = currentstyle | (int)mask; |
5911 tmp ^= mask; | 5911 tmp ^= mask; |
5912 tmp |= style; | 5912 tmp |= style; |
5913 | 5913 |
5914 [window setStyleMask:tmp]; | 5914 [window setStyleMask:tmp]; |
5915 } | 5915 } |
5916 else if([object isKindOfClass:[NSTextField class]]) | 5916 else if([object isKindOfClass:[NSTextField class]]) |
5917 { | 5917 { |
5918 NSTextField *tf = object; | 5918 NSTextField *tf = object; |
5933 * window: Toplevel window or dialog. | 5933 * window: Toplevel window or dialog. |
5934 * defaultitem: Handle to the dialog item to be default. | 5934 * defaultitem: Handle to the dialog item to be default. |
5935 */ | 5935 */ |
5936 void API dw_window_default(HWND window, HWND defaultitem) | 5936 void API dw_window_default(HWND window, HWND defaultitem) |
5937 { | 5937 { |
5938 NSLog(@"dw_window_default() unimplemented\n"); | 5938 NSLog(@"dw_window_default() unimplemented\n"); |
5939 } | 5939 } |
5940 | 5940 |
5941 /* | 5941 /* |
5942 * Sets window to click the default dialog item when an ENTER is pressed. | 5942 * Sets window to click the default dialog item when an ENTER is pressed. |
5943 * Parameters: | 5943 * Parameters: |
5944 * window: Window (widget) to look for the ENTER press. | 5944 * window: Window (widget) to look for the ENTER press. |
5945 * next: Window (widget) to move to next (or click) | 5945 * next: Window (widget) to move to next (or click) |
5946 */ | 5946 */ |
5947 void API dw_window_click_default(HWND window, HWND next) | 5947 void API dw_window_click_default(HWND window, HWND next) |
5948 { | 5948 { |
5949 NSLog(@"dw_window_click_default() unimplemented\n"); | 5949 NSLog(@"dw_window_click_default() unimplemented\n"); |
5950 } | 5950 } |
5951 | 5951 |
5952 static id _DWCapture; | 5952 static id _DWCapture; |
5953 | 5953 |
5954 /* | 5954 /* |
5988 * Parameters: | 5988 * Parameters: |
5989 * handle: Handle to frame to be tracked. | 5989 * handle: Handle to frame to be tracked. |
5990 */ | 5990 */ |
5991 void API dw_window_track(HWND handle) | 5991 void API dw_window_track(HWND handle) |
5992 { | 5992 { |
5993 NSLog(@"dw_window_track() unimplemented\n"); | 5993 NSLog(@"dw_window_track() unimplemented\n"); |
5994 } | 5994 } |
5995 | 5995 |
5996 /* | 5996 /* |
5997 * Changes a window's parent to newparent. | 5997 * Changes a window's parent to newparent. |
5998 * Parameters: | 5998 * Parameters: |
6108 */ | 6108 */ |
6109 int API dw_window_destroy(HWND handle) | 6109 int API dw_window_destroy(HWND handle) |
6110 { | 6110 { |
6111 int _locked_by_me = FALSE; | 6111 int _locked_by_me = FALSE; |
6112 DW_MUTEX_LOCK; | 6112 DW_MUTEX_LOCK; |
6113 NSObject *object = handle; | 6113 NSObject *object = handle; |
6114 | 6114 |
6115 if([ object isKindOfClass:[ NSWindow class ] ]) | 6115 if([ object isKindOfClass:[ NSWindow class ] ]) |
6116 { | 6116 { |
6117 NSWindow *window = handle; | 6117 NSWindow *window = handle; |
6118 [window close]; | 6118 [window close]; |
6119 } | 6119 } |
6120 DW_MUTEX_UNLOCK; | 6120 DW_MUTEX_UNLOCK; |
6121 return 0; | 6121 return 0; |
6122 } | 6122 } |
6123 | 6123 |
6124 /* | 6124 /* |
6125 * Gets the text used for a given window. | 6125 * Gets the text used for a given window. |
6126 * Parameters: | 6126 * Parameters: |
6128 * Returns: | 6128 * Returns: |
6129 * text: The text associsated with a given window. | 6129 * text: The text associsated with a given window. |
6130 */ | 6130 */ |
6131 char * API dw_window_get_text(HWND handle) | 6131 char * API dw_window_get_text(HWND handle) |
6132 { | 6132 { |
6133 NSObject *object = handle; | 6133 NSObject *object = handle; |
6134 | 6134 |
6135 if([ object isKindOfClass:[ NSControl class ] ]) | 6135 if([ object isKindOfClass:[ NSControl class ] ]) |
6136 { | 6136 { |
6137 NSControl *control = handle; | 6137 NSControl *control = handle; |
6138 NSString *nsstr = [ control stringValue]; | 6138 NSString *nsstr = [ control stringValue]; |
6139 | 6139 |
6140 return strdup([ nsstr UTF8String ]); | 6140 return strdup([ nsstr UTF8String ]); |
6141 } | 6141 } |
6142 else if([ object isKindOfClass:[ NSWindow class ] ]) | 6142 else if([ object isKindOfClass:[ NSWindow class ] ]) |
6143 { | 6143 { |
6144 NSWindow *window = handle; | 6144 NSWindow *window = handle; |
6145 NSString *nsstr = [ window title]; | 6145 NSString *nsstr = [ window title]; |
6146 | 6146 |
6147 return strdup([ nsstr UTF8String ]); | 6147 return strdup([ nsstr UTF8String ]); |
6148 } | 6148 } |
6149 return NULL; | 6149 return NULL; |
6150 } | 6150 } |
6151 | 6151 |
6152 /* | 6152 /* |
6153 * Sets the text used for a given window. | 6153 * Sets the text used for a given window. |
6154 * Parameters: | 6154 * Parameters: |
6157 */ | 6157 */ |
6158 void API dw_window_set_text(HWND handle, char *text) | 6158 void API dw_window_set_text(HWND handle, char *text) |
6159 { | 6159 { |
6160 int _locked_by_me = FALSE; | 6160 int _locked_by_me = FALSE; |
6161 DW_MUTEX_LOCK; | 6161 DW_MUTEX_LOCK; |
6162 NSObject *object = handle; | 6162 NSObject *object = handle; |
6163 | 6163 |
6164 if([ object isKindOfClass:[ NSControl class ] ]) | 6164 if([ object isKindOfClass:[ NSControl class ] ]) |
6165 { | 6165 { |
6166 NSControl *control = handle; | 6166 NSControl *control = handle; |
6167 [control setStringValue:[ NSString stringWithUTF8String:text ]]; | 6167 [control setStringValue:[ NSString stringWithUTF8String:text ]]; |
6168 } | 6168 } |
6169 else if([ object isKindOfClass:[ NSWindow class ] ]) | 6169 else if([ object isKindOfClass:[ NSWindow class ] ]) |
6170 { | 6170 { |
6171 NSWindow *window = handle; | 6171 NSWindow *window = handle; |
6172 [window setTitle:[ NSString stringWithUTF8String:text ]]; | 6172 [window setTitle:[ NSString stringWithUTF8String:text ]]; |
6173 } | 6173 } |
6174 DW_MUTEX_UNLOCK; | 6174 DW_MUTEX_UNLOCK; |
6175 } | 6175 } |
6176 | 6176 |
6177 /* | 6177 /* |
6178 * Disables given window (widget). | 6178 * Disables given window (widget). |
6179 * Parameters: | 6179 * Parameters: |
6180 * handle: Handle to the window. | 6180 * handle: Handle to the window. |
6181 */ | 6181 */ |
6182 void API dw_window_disable(HWND handle) | 6182 void API dw_window_disable(HWND handle) |
6183 { | 6183 { |
6184 NSObject *object = handle; | 6184 NSObject *object = handle; |
6185 if([ object isKindOfClass:[ NSControl class ] ]) | 6185 if([ object isKindOfClass:[ NSControl class ] ]) |
6186 { | 6186 { |
6187 NSControl *control = handle; | 6187 NSControl *control = handle; |
6188 [control setEnabled:NO]; | 6188 [control setEnabled:NO]; |
6189 } | 6189 } |
6190 } | 6190 } |
6191 | 6191 |
6192 /* | 6192 /* |
6193 * Enables given window (widget). | 6193 * Enables given window (widget). |
6194 * Parameters: | 6194 * Parameters: |
6195 * handle: Handle to the window. | 6195 * handle: Handle to the window. |
6196 */ | 6196 */ |
6197 void API dw_window_enable(HWND handle) | 6197 void API dw_window_enable(HWND handle) |
6198 { | 6198 { |
6199 NSObject *object = handle; | 6199 NSObject *object = handle; |
6200 if([ object isKindOfClass:[ NSControl class ] ]) | 6200 if([ object isKindOfClass:[ NSControl class ] ]) |
6201 { | 6201 { |
6202 NSControl *control = handle; | 6202 NSControl *control = handle; |
6203 [control setEnabled:YES]; | 6203 [control setEnabled:YES]; |
6204 } | 6204 } |
6205 } | 6205 } |
6206 | 6206 |
6207 /* | 6207 /* |
6208 * Sets the bitmap used for a given static window. | 6208 * Sets the bitmap used for a given static window. |
6209 * Parameters: | 6209 * Parameters: |
6214 * Windows and a pixmap on Unix, pass | 6214 * Windows and a pixmap on Unix, pass |
6215 * NULL if you use the id param) | 6215 * NULL if you use the id param) |
6216 */ | 6216 */ |
6217 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, char *data, int len) | 6217 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, char *data, int len) |
6218 { | 6218 { |
6219 NSObject *object = handle; | 6219 NSObject *object = handle; |
6220 if([ object isKindOfClass:[ NSImageView class ] ]) | 6220 if([ object isKindOfClass:[ NSImageView class ] ]) |
6221 { | 6221 { |
6222 NSImageView *iv = handle; | 6222 NSImageView *iv = handle; |
6223 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; | 6223 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; |
6224 NSImage *pixmap = [[NSImage alloc] initWithData:thisdata]; | 6224 NSImage *pixmap = [[NSImage alloc] initWithData:thisdata]; |
6225 | 6225 |
6226 if(pixmap) | 6226 if(pixmap) |
6227 { | 6227 { |
6228 [iv setImage:pixmap]; | 6228 [iv setImage:pixmap]; |
6229 } | 6229 } |
6230 [pixmap release]; | 6230 [pixmap release]; |
6231 } | 6231 } |
6232 } | 6232 } |
6233 | 6233 |
6234 /* | 6234 /* |
6235 * Sets the bitmap used for a given static window. | 6235 * Sets the bitmap used for a given static window. |
6236 * Parameters: | 6236 * Parameters: |
6241 * Windows and a pixmap on Unix, pass | 6241 * Windows and a pixmap on Unix, pass |
6242 * NULL if you use the id param) | 6242 * NULL if you use the id param) |
6243 */ | 6243 */ |
6244 void API dw_window_set_bitmap(HWND handle, unsigned long resid, char *filename) | 6244 void API dw_window_set_bitmap(HWND handle, unsigned long resid, char *filename) |
6245 { | 6245 { |
6246 NSObject *object = handle; | 6246 NSObject *object = handle; |
6247 if([ object isKindOfClass:[ NSImageView class ] ]) | 6247 if([ object isKindOfClass:[ NSImageView class ] ]) |
6248 { | 6248 { |
6249 NSImageView *iv = handle; | 6249 NSImageView *iv = handle; |
6250 NSImage *bitmap = nil; | 6250 NSImage *bitmap = nil; |
6251 | 6251 |
6252 if(filename) | 6252 if(filename) |
6253 { | 6253 { |
6254 bitmap = [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; | 6254 bitmap = [[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]]; |
6255 } | 6255 } |
6256 else if(resid > 0 && resid < 65536) | 6256 else if(resid > 0 && resid < 65536) |
6257 { | 6257 { |
6258 bitmap = dw_icon_load(0, resid); | 6258 bitmap = dw_icon_load(0, resid); |
6259 } | 6259 } |
6260 | 6260 |
6261 if(bitmap) | 6261 if(bitmap) |
6262 { | 6262 { |
6263 [iv setImage:bitmap]; | 6263 [iv setImage:bitmap]; |
6264 } | 6264 } |
6265 } | 6265 } |
6266 } | 6266 } |
6267 | 6267 |
6268 /* | 6268 /* |
6269 * Sets the icon used for a given window. | 6269 * Sets the icon used for a given window. |
6270 * Parameters: | 6270 * Parameters: |
6271 * handle: Handle to the window. | 6271 * handle: Handle to the window. |
6272 * id: An ID to be used to specify the icon. | 6272 * id: An ID to be used to specify the icon. |
6273 */ | 6273 */ |
6274 void API dw_window_set_icon(HWND handle, HICN icon) | 6274 void API dw_window_set_icon(HWND handle, HICN icon) |
6275 { | 6275 { |
6276 /* This isn't needed, it is loaded from the bundle */ | 6276 /* This isn't needed, it is loaded from the bundle */ |
6277 } | 6277 } |
6278 | 6278 |
6279 /* | 6279 /* |
6280 * Gets the child window handle with specified ID. | 6280 * Gets the child window handle with specified ID. |
6281 * Parameters: | 6281 * Parameters: |
6282 * handle: Handle to the parent window. | 6282 * handle: Handle to the parent window. |
6283 * id: Integer ID of the child. | 6283 * id: Integer ID of the child. |
6284 */ | 6284 */ |
6285 HWND API dw_window_from_id(HWND handle, int cid) | 6285 HWND API dw_window_from_id(HWND handle, int cid) |
6286 { | 6286 { |
6287 NSObject *object = handle; | 6287 NSObject *object = handle; |
6288 NSView *view = handle; | 6288 NSView *view = handle; |
6289 if([ object isKindOfClass:[ NSWindow class ] ]) | 6289 if([ object isKindOfClass:[ NSWindow class ] ]) |
6290 { | 6290 { |
6291 NSWindow *window = handle; | 6291 NSWindow *window = handle; |
6292 view = [window contentView]; | 6292 view = [window contentView]; |
6293 } | 6293 } |
6294 return [view viewWithTag:cid]; | 6294 return [view viewWithTag:cid]; |
6295 } | 6295 } |
6296 | 6296 |
6297 /* | 6297 /* |
6298 * Minimizes or Iconifies a top-level window. | 6298 * Minimizes or Iconifies a top-level window. |
6299 * Parameters: | 6299 * Parameters: |
6300 * handle: The window handle to minimize. | 6300 * handle: The window handle to minimize. |
6301 */ | 6301 */ |
6302 int API dw_window_minimize(HWND handle) | 6302 int API dw_window_minimize(HWND handle) |
6303 { | 6303 { |
6304 NSWindow *window = handle; | 6304 NSWindow *window = handle; |
6305 [window miniaturize:nil]; | 6305 [window miniaturize:nil]; |
6306 return 0; | 6306 return 0; |
6307 } | 6307 } |
6308 | 6308 |
6309 /* Causes entire window to be invalidated and redrawn. | 6309 /* Causes entire window to be invalidated and redrawn. |
6310 * Parameters: | 6310 * Parameters: |
6311 * handle: Toplevel window handle to be redrawn. | 6311 * handle: Toplevel window handle to be redrawn. |
6312 */ | 6312 */ |
6313 void API dw_window_redraw(HWND handle) | 6313 void API dw_window_redraw(HWND handle) |
6314 { | 6314 { |
6315 NSWindow *window = handle; | 6315 NSWindow *window = handle; |
6316 [window flushWindow]; | 6316 [window flushWindow]; |
6317 } | 6317 } |
6318 | 6318 |
6319 /* | 6319 /* |
6320 * Makes the window topmost. | 6320 * Makes the window topmost. |
6321 * Parameters: | 6321 * Parameters: |
6322 * handle: The window handle to make topmost. | 6322 * handle: The window handle to make topmost. |
6323 */ | 6323 */ |
6324 int API dw_window_raise(HWND handle) | 6324 int API dw_window_raise(HWND handle) |
6325 { | 6325 { |
6326 NSWindow *window = handle; | 6326 NSWindow *window = handle; |
6327 [window orderFront:nil]; | 6327 [window orderFront:nil]; |
6328 return 0; | 6328 return 0; |
6329 } | 6329 } |
6330 | 6330 |
6331 /* | 6331 /* |
6332 * Makes the window bottommost. | 6332 * Makes the window bottommost. |
6333 * Parameters: | 6333 * Parameters: |
6334 * handle: The window handle to make bottommost. | 6334 * handle: The window handle to make bottommost. |
6335 */ | 6335 */ |
6336 int API dw_window_lower(HWND handle) | 6336 int API dw_window_lower(HWND handle) |
6337 { | 6337 { |
6338 NSWindow *window = handle; | 6338 NSWindow *window = handle; |
6339 [window orderBack:nil]; | 6339 [window orderBack:nil]; |
6340 return 0; | 6340 return 0; |
6341 } | 6341 } |
6342 | 6342 |
6343 /* | 6343 /* |
6344 * Sets the size of a given window (widget). | 6344 * Sets the size of a given window (widget). |
6345 * Parameters: | 6345 * Parameters: |
6349 */ | 6349 */ |
6350 void API dw_window_set_size(HWND handle, ULONG width, ULONG height) | 6350 void API dw_window_set_size(HWND handle, ULONG width, ULONG height) |
6351 { | 6351 { |
6352 int _locked_by_me = FALSE; | 6352 int _locked_by_me = FALSE; |
6353 DW_MUTEX_LOCK; | 6353 DW_MUTEX_LOCK; |
6354 NSObject *object = handle; | 6354 NSObject *object = handle; |
6355 NSSize size; | 6355 NSSize size; |
6356 size.width = width; | 6356 size.width = width; |
6357 size.height = height; | 6357 size.height = height; |
6358 | 6358 |
6359 if([ object isKindOfClass:[ NSWindow class ] ]) | 6359 if([ object isKindOfClass:[ NSWindow class ] ]) |
6360 { | 6360 { |
6361 NSWindow *window = handle; | 6361 NSWindow *window = handle; |
6362 [window setContentSize:size]; | 6362 [window setContentSize:size]; |
6363 } | 6363 } |
6364 DW_MUTEX_UNLOCK; | 6364 DW_MUTEX_UNLOCK; |
6365 } | 6365 } |
6366 | 6366 |
6367 /* | 6367 /* |
6368 * Sets the position of a given window (widget). | 6368 * Sets the position of a given window (widget). |
6373 */ | 6373 */ |
6374 void API dw_window_set_pos(HWND handle, LONG x, LONG y) | 6374 void API dw_window_set_pos(HWND handle, LONG x, LONG y) |
6375 { | 6375 { |
6376 int _locked_by_me = FALSE; | 6376 int _locked_by_me = FALSE; |
6377 DW_MUTEX_LOCK; | 6377 DW_MUTEX_LOCK; |
6378 NSObject *object = handle; | 6378 NSObject *object = handle; |
6379 NSPoint point; | 6379 NSPoint point; |
6380 point.x = x; | 6380 point.x = x; |
6381 point.y = y; | 6381 point.y = y; |
6382 | 6382 |
6383 if([ object isKindOfClass:[ NSWindow class ] ]) | 6383 if([ object isKindOfClass:[ NSWindow class ] ]) |
6384 { | 6384 { |
6385 NSWindow *window = handle; | 6385 NSWindow *window = handle; |
6386 [window setFrameOrigin:point]; | 6386 [window setFrameOrigin:point]; |
6387 } | 6387 } |
6388 DW_MUTEX_UNLOCK; | 6388 DW_MUTEX_UNLOCK; |
6389 } | 6389 } |
6390 | 6390 |
6391 /* | 6391 /* |
6392 * Sets the position and size of a given window (widget). | 6392 * Sets the position and size of a given window (widget). |
6397 * width: Width of the widget. | 6397 * width: Width of the widget. |
6398 * height: Height of the widget. | 6398 * height: Height of the widget. |
6399 */ | 6399 */ |
6400 void API dw_window_set_pos_size(HWND handle, LONG x, LONG y, ULONG width, ULONG height) | 6400 void API dw_window_set_pos_size(HWND handle, LONG x, LONG y, ULONG width, ULONG height) |
6401 { | 6401 { |
6402 dw_window_set_pos(handle, x, y); | 6402 dw_window_set_pos(handle, x, y); |
6403 dw_window_set_size(handle, width, height); | 6403 dw_window_set_size(handle, width, height); |
6404 } | 6404 } |
6405 | 6405 |
6406 /* | 6406 /* |
6407 * Gets the position and size of a given window (widget). | 6407 * Gets the position and size of a given window (widget). |
6408 * Parameters: | 6408 * Parameters: |
6412 * width: Width of the widget. | 6412 * width: Width of the widget. |
6413 * height: Height of the widget. | 6413 * height: Height of the widget. |
6414 */ | 6414 */ |
6415 void API dw_window_get_pos_size(HWND handle, LONG *x, LONG *y, ULONG *width, ULONG *height) | 6415 void API dw_window_get_pos_size(HWND handle, LONG *x, LONG *y, ULONG *width, ULONG *height) |
6416 { | 6416 { |
6417 NSObject *object = handle; | 6417 NSObject *object = handle; |
6418 | 6418 |
6419 if([ object isKindOfClass:[ NSWindow class ] ]) | 6419 if([ object isKindOfClass:[ NSWindow class ] ]) |
6420 { | 6420 { |
6421 NSWindow *window = handle; | 6421 NSWindow *window = handle; |
6422 NSRect rect = [window frame]; | 6422 NSRect rect = [window frame]; |
6423 if(x) | 6423 if(x) |
6424 *x = rect.origin.x; | 6424 *x = rect.origin.x; |
6425 if(y) | 6425 if(y) |
6426 *y = rect.origin.y; | 6426 *y = rect.origin.y; |
6427 if(width) | 6427 if(width) |
6428 *width = rect.size.width; | 6428 *width = rect.size.width; |
6429 if(height) | 6429 if(height) |
6430 *height = rect.size.height; | 6430 *height = rect.size.height; |
6431 return; | 6431 return; |
6432 } | 6432 } |
6433 } | 6433 } |
6434 | 6434 |
6435 /* | 6435 /* |
6436 * Returns the width of the screen. | 6436 * Returns the width of the screen. |
6437 */ | 6437 */ |
6438 int API dw_screen_width(void) | 6438 int API dw_screen_width(void) |
6439 { | 6439 { |
6440 NSRect screenRect = [[NSScreen mainScreen] frame]; | 6440 NSRect screenRect = [[NSScreen mainScreen] frame]; |
6441 return screenRect.size.width; | 6441 return screenRect.size.width; |
6442 } | 6442 } |
6443 | 6443 |
6444 /* | 6444 /* |
6445 * Returns the height of the screen. | 6445 * Returns the height of the screen. |
6446 */ | 6446 */ |
6447 int API dw_screen_height(void) | 6447 int API dw_screen_height(void) |
6448 { | 6448 { |
6449 NSRect screenRect = [[NSScreen mainScreen] frame]; | 6449 NSRect screenRect = [[NSScreen mainScreen] frame]; |
6450 return screenRect.size.height; | 6450 return screenRect.size.height; |
6451 } | 6451 } |
6452 | 6452 |
6453 /* This should return the current color depth */ | 6453 /* This should return the current color depth */ |
6454 unsigned long API dw_color_depth_get(void) | 6454 unsigned long API dw_color_depth_get(void) |
6455 { | 6455 { |
6456 NSWindowDepth screenDepth = [[NSScreen mainScreen] depth]; | 6456 NSWindowDepth screenDepth = [[NSScreen mainScreen] depth]; |
6457 return NSBitsPerPixelFromDepth(screenDepth); | 6457 return NSBitsPerPixelFromDepth(screenDepth); |
6458 } | 6458 } |
6459 | 6459 |
6460 /* | 6460 /* |
6461 * Returns some information about the current operating environment. | 6461 * Returns some information about the current operating environment. |
6462 * Parameters: | 6462 * Parameters: |
6463 * env: Pointer to a DWEnv struct. | 6463 * env: Pointer to a DWEnv struct. |
6464 */ | 6464 */ |
6465 void dw_environment_query(DWEnv *env) | 6465 void dw_environment_query(DWEnv *env) |
6466 { | 6466 { |
6467 struct utsname name; | 6467 struct utsname name; |
6468 | 6468 |
6469 uname(&name); | 6469 uname(&name); |
6470 strcpy(env->osName, "MacOS"); | 6470 strcpy(env->osName, "MacOS"); |
6471 | 6471 |
6472 strcpy(env->buildDate, __DATE__); | 6472 strcpy(env->buildDate, __DATE__); |
6473 strcpy(env->buildTime, __TIME__); | 6473 strcpy(env->buildTime, __TIME__); |
6474 env->DWMajorVersion = DW_MAJOR_VERSION; | 6474 env->DWMajorVersion = DW_MAJOR_VERSION; |
6475 env->DWMinorVersion = DW_MINOR_VERSION; | 6475 env->DWMinorVersion = DW_MINOR_VERSION; |
6476 env->DWSubVersion = DW_SUB_VERSION; | 6476 env->DWSubVersion = DW_SUB_VERSION; |
6477 | 6477 |
6478 env->MajorVersion = DWOSMajor; | 6478 env->MajorVersion = DWOSMajor; |
6479 env->MinorVersion = DWOSMinor; | 6479 env->MinorVersion = DWOSMinor; |
6480 env->MajorBuild = DWOSBuild; | 6480 env->MajorBuild = DWOSBuild; |
6481 } | 6481 } |
6482 | 6482 |
6486 * freq: Frequency. | 6486 * freq: Frequency. |
6487 * dur: Duration. | 6487 * dur: Duration. |
6488 */ | 6488 */ |
6489 void API dw_beep(int freq, int dur) | 6489 void API dw_beep(int freq, int dur) |
6490 { | 6490 { |
6491 NSBeep(); | 6491 NSBeep(); |
6492 } | 6492 } |
6493 | 6493 |
6494 /* Call this after drawing to the screen to make sure | 6494 /* Call this after drawing to the screen to make sure |
6495 * anything you have drawn is visible. | 6495 * anything you have drawn is visible. |
6496 */ | 6496 */ |
6504 * a given window handle. Used in dw_window_set_data() and | 6504 * a given window handle. Used in dw_window_set_data() and |
6505 * dw_window_get_data(). | 6505 * dw_window_get_data(). |
6506 */ | 6506 */ |
6507 UserData *_find_userdata(UserData **root, char *varname) | 6507 UserData *_find_userdata(UserData **root, char *varname) |
6508 { | 6508 { |
6509 UserData *tmp = *root; | 6509 UserData *tmp = *root; |
6510 | 6510 |
6511 while(tmp) | 6511 while(tmp) |
6512 { | 6512 { |
6513 if(strcasecmp(tmp->varname, varname) == 0) | 6513 if(strcasecmp(tmp->varname, varname) == 0) |
6514 return tmp; | 6514 return tmp; |
6515 tmp = tmp->next; | 6515 tmp = tmp->next; |
6516 } | 6516 } |
6517 return NULL; | 6517 return NULL; |
6518 } | 6518 } |
6519 | 6519 |
6520 int _new_userdata(UserData **root, char *varname, void *data) | 6520 int _new_userdata(UserData **root, char *varname, void *data) |
6521 { | 6521 { |
6522 UserData *new = _find_userdata(root, varname); | 6522 UserData *new = _find_userdata(root, varname); |
6523 | 6523 |
6524 if(new) | 6524 if(new) |
6525 { | 6525 { |
6526 new->data = data; | 6526 new->data = data; |
6527 return TRUE; | 6527 return TRUE; |
6528 } | 6528 } |
6529 else | 6529 else |
6530 { | 6530 { |
6531 new = malloc(sizeof(UserData)); | 6531 new = malloc(sizeof(UserData)); |
6532 if(new) | 6532 if(new) |
6533 { | 6533 { |
6534 new->varname = strdup(varname); | 6534 new->varname = strdup(varname); |
6535 new->data = data; | 6535 new->data = data; |
6536 | 6536 |
6537 new->next = NULL; | 6537 new->next = NULL; |
6538 | 6538 |
6539 if (!*root) | 6539 if (!*root) |
6540 *root = new; | 6540 *root = new; |
6541 else | 6541 else |
6542 { | 6542 { |
6543 UserData *prev = NULL, *tmp = *root; | 6543 UserData *prev = NULL, *tmp = *root; |
6544 while(tmp) | 6544 while(tmp) |
6545 { | 6545 { |
6546 prev = tmp; | 6546 prev = tmp; |
6547 tmp = tmp->next; | 6547 tmp = tmp->next; |
6548 } | 6548 } |
6549 if(prev) | 6549 if(prev) |
6550 prev->next = new; | 6550 prev->next = new; |
6551 else | 6551 else |
6552 *root = new; | 6552 *root = new; |
6553 } | 6553 } |
6554 return TRUE; | 6554 return TRUE; |
6555 } | 6555 } |
6556 } | 6556 } |
6557 return FALSE; | 6557 return FALSE; |
6558 } | 6558 } |
6559 | 6559 |
6560 int _remove_userdata(UserData **root, char *varname, int all) | 6560 int _remove_userdata(UserData **root, char *varname, int all) |
6561 { | 6561 { |
6562 UserData *prev = NULL, *tmp = *root; | 6562 UserData *prev = NULL, *tmp = *root; |
6563 | 6563 |
6564 while(tmp) | 6564 while(tmp) |
6565 { | 6565 { |
6566 if(all || strcasecmp(tmp->varname, varname) == 0) | 6566 if(all || strcasecmp(tmp->varname, varname) == 0) |
6567 { | 6567 { |
6568 if(!prev) | 6568 if(!prev) |
6569 { | 6569 { |
6570 *root = tmp->next; | 6570 *root = tmp->next; |
6571 free(tmp->varname); | 6571 free(tmp->varname); |
6572 free(tmp); | 6572 free(tmp); |
6573 if(!all) | 6573 if(!all) |
6574 return 0; | 6574 return 0; |
6575 tmp = *root; | 6575 tmp = *root; |
6576 } | 6576 } |
6577 else | 6577 else |
6578 { | 6578 { |
6579 /* If all is true we should | 6579 /* If all is true we should |
6580 * never get here. | 6580 * never get here. |
6581 */ | 6581 */ |
6582 prev->next = tmp->next; | 6582 prev->next = tmp->next; |
6583 free(tmp->varname); | 6583 free(tmp->varname); |
6584 free(tmp); | 6584 free(tmp); |
6585 return 0; | 6585 return 0; |
6586 } | 6586 } |
6587 } | 6587 } |
6588 else | 6588 else |
6589 { | 6589 { |
6590 prev = tmp; | 6590 prev = tmp; |
6591 tmp = tmp->next; | 6591 tmp = tmp->next; |
6592 } | 6592 } |
6593 } | 6593 } |
6594 return 0; | 6594 return 0; |
6595 } | 6595 } |
6596 | 6596 |
6597 /* | 6597 /* |
6598 * Add a named user data item to a window handle. | 6598 * Add a named user data item to a window handle. |
6599 * Parameters: | 6599 * Parameters: |
6601 * dataname: A string pointer identifying which signal to be hooked. | 6601 * dataname: A string pointer identifying which signal to be hooked. |
6602 * data: User data to be passed to the handler function. | 6602 * data: User data to be passed to the handler function. |
6603 */ | 6603 */ |
6604 void dw_window_set_data(HWND window, char *dataname, void *data) | 6604 void dw_window_set_data(HWND window, char *dataname, void *data) |
6605 { | 6605 { |
6606 id object = window; | 6606 id object = window; |
6607 if([object isMemberOfClass:[NSWindow class]]) | 6607 if([object isMemberOfClass:[NSWindow class]]) |
6608 { | 6608 { |
6609 NSWindow *win = window; | 6609 NSWindow *win = window; |
6610 object = [win contentView]; | 6610 object = [win contentView]; |
6611 } | 6611 } |
6612 else if([object isMemberOfClass:[NSScrollView class]]) | 6612 else if([object isMemberOfClass:[NSScrollView class]]) |
6613 { | 6613 { |
6614 NSScrollView *sv = window; | 6614 NSScrollView *sv = window; |
6615 object = [sv documentView]; | 6615 object = [sv documentView]; |
6616 } | 6616 } |
6617 WindowData *blah = (WindowData *)[object userdata]; | 6617 WindowData *blah = (WindowData *)[object userdata]; |
6618 | 6618 |
6619 if(!blah) | 6619 if(!blah) |
6620 { | 6620 { |
6621 if(!dataname) | 6621 if(!dataname) |
6622 return; | 6622 return; |
6623 | 6623 |
6624 blah = calloc(1, sizeof(WindowData)); | 6624 blah = calloc(1, sizeof(WindowData)); |
6625 [object setUserdata:blah]; | 6625 [object setUserdata:blah]; |
6626 } | 6626 } |
6627 | 6627 |
6628 if(data) | 6628 if(data) |
6629 _new_userdata(&(blah->root), dataname, data); | 6629 _new_userdata(&(blah->root), dataname, data); |
6630 else | 6630 else |
6631 { | 6631 { |
6632 if(dataname) | 6632 if(dataname) |
6633 _remove_userdata(&(blah->root), dataname, FALSE); | 6633 _remove_userdata(&(blah->root), dataname, FALSE); |
6634 else | 6634 else |
6635 _remove_userdata(&(blah->root), NULL, TRUE); | 6635 _remove_userdata(&(blah->root), NULL, TRUE); |
6636 } | 6636 } |
6637 } | 6637 } |
6638 | 6638 |
6639 /* | 6639 /* |
6640 * Gets a named user data item to a window handle. | 6640 * Gets a named user data item to a window handle. |
6641 * Parameters: | 6641 * Parameters: |
6643 * dataname: A string pointer identifying which signal to be hooked. | 6643 * dataname: A string pointer identifying which signal to be hooked. |
6644 * data: User data to be passed to the handler function. | 6644 * data: User data to be passed to the handler function. |
6645 */ | 6645 */ |
6646 void *dw_window_get_data(HWND window, char *dataname) | 6646 void *dw_window_get_data(HWND window, char *dataname) |
6647 { | 6647 { |
6648 id object = window; | 6648 id object = window; |
6649 if([object isMemberOfClass:[NSWindow class]]) | 6649 if([object isMemberOfClass:[NSWindow class]]) |
6650 { | 6650 { |
6651 NSWindow *win = window; | 6651 NSWindow *win = window; |
6652 object = [win contentView]; | 6652 object = [win contentView]; |
6653 } | 6653 } |
6654 else if([object isMemberOfClass:[NSScrollView class]]) | 6654 else if([object isMemberOfClass:[NSScrollView class]]) |
6655 { | 6655 { |
6656 NSScrollView *sv = window; | 6656 NSScrollView *sv = window; |
6657 object = [sv documentView]; | 6657 object = [sv documentView]; |
6658 } | 6658 } |
6659 WindowData *blah = (WindowData *)[object userdata]; | 6659 WindowData *blah = (WindowData *)[object userdata]; |
6660 | 6660 |
6661 if(blah && blah->root && dataname) | 6661 if(blah && blah->root && dataname) |
6662 { | 6662 { |
6663 UserData *ud = _find_userdata(&(blah->root), dataname); | 6663 UserData *ud = _find_userdata(&(blah->root), dataname); |
6664 if(ud) | 6664 if(ud) |
6665 return ud->data; | 6665 return ud->data; |
6666 } | 6666 } |
6667 return NULL; | 6667 return NULL; |
6668 } | 6668 } |
6669 | 6669 |
6670 #define DW_TIMER_MAX 64 | 6670 #define DW_TIMER_MAX 64 |
6671 NSTimer *DWTimers[DW_TIMER_MAX]; | 6671 NSTimer *DWTimers[DW_TIMER_MAX]; |
6672 | 6672 |
6679 * Returns: | 6679 * Returns: |
6680 * Timer ID for use with dw_timer_disconnect(), 0 on error. | 6680 * Timer ID for use with dw_timer_disconnect(), 0 on error. |
6681 */ | 6681 */ |
6682 int API dw_timer_connect(int interval, void *sigfunc, void *data) | 6682 int API dw_timer_connect(int interval, void *sigfunc, void *data) |
6683 { | 6683 { |
6684 int z; | 6684 int z; |
6685 | 6685 |
6686 for(z=0;z<DW_TIMER_MAX;z++) | 6686 for(z=0;z<DW_TIMER_MAX;z++) |
6687 { | 6687 { |
6688 if(!DWTimers[z]) | 6688 if(!DWTimers[z]) |
6689 { | 6689 { |
6690 break; | 6690 break; |
6691 } | 6691 } |
6692 } | 6692 } |
6693 | 6693 |
6694 if(sigfunc && !DWTimers[z]) | 6694 if(sigfunc && !DWTimers[z]) |
6695 { | 6695 { |
6696 NSTimeInterval seconds = (double)interval / 1000.0; | 6696 NSTimeInterval seconds = (double)interval / 1000.0; |
6697 NSTimer *thistimer = DWTimers[z] = [NSTimer scheduledTimerWithTimeInterval:seconds target:DWHandler selector:@selector(runTimer:) userInfo:nil repeats:YES]; | 6697 NSTimer *thistimer = DWTimers[z] = [NSTimer scheduledTimerWithTimeInterval:seconds target:DWHandler selector:@selector(runTimer:) userInfo:nil repeats:YES]; |
6698 _new_signal(0, thistimer, z+1, sigfunc, data); | 6698 _new_signal(0, thistimer, z+1, sigfunc, data); |
6699 return z+1; | 6699 return z+1; |
6700 } | 6700 } |
6701 return 0; | 6701 return 0; |
6702 } | 6702 } |
6703 | 6703 |
6704 /* | 6704 /* |
6705 * Removes timer callback. | 6705 * Removes timer callback. |
6706 * Parameters: | 6706 * Parameters: |
6707 * id: Timer ID returned by dw_timer_connect(). | 6707 * id: Timer ID returned by dw_timer_connect(). |
6708 */ | 6708 */ |
6709 void API dw_timer_disconnect(int timerid) | 6709 void API dw_timer_disconnect(int timerid) |
6710 { | 6710 { |
6711 SignalHandler *prev = NULL, *tmp = Root; | 6711 SignalHandler *prev = NULL, *tmp = Root; |
6712 NSTimer *thistimer; | 6712 NSTimer *thistimer; |
6713 | 6713 |
6714 /* 0 is an invalid timer ID */ | 6714 /* 0 is an invalid timer ID */ |
6715 if(timerid < 1 || !DWTimers[timerid-1]) | 6715 if(timerid < 1 || !DWTimers[timerid-1]) |
6716 return; | 6716 return; |
6717 | 6717 |
6718 thistimer = DWTimers[timerid-1]; | 6718 thistimer = DWTimers[timerid-1]; |
6719 DWTimers[timerid-1] = nil; | 6719 DWTimers[timerid-1] = nil; |
6720 | 6720 |
6721 [thistimer invalidate]; | 6721 [thistimer invalidate]; |
6722 | 6722 |
6723 while(tmp) | 6723 while(tmp) |
6724 { | 6724 { |
6725 if(tmp->id == timerid && tmp->window == thistimer) | 6725 if(tmp->id == timerid && tmp->window == thistimer) |
6726 { | 6726 { |
6727 if(prev) | 6727 if(prev) |
6728 { | 6728 { |
6729 prev->next = tmp->next; | 6729 prev->next = tmp->next; |
6730 free(tmp); | 6730 free(tmp); |
6731 tmp = prev->next; | 6731 tmp = prev->next; |
6732 } | 6732 } |
6733 else | 6733 else |
6734 { | 6734 { |
6735 Root = tmp->next; | 6735 Root = tmp->next; |
6736 free(tmp); | 6736 free(tmp); |
6737 tmp = Root; | 6737 tmp = Root; |
6738 } | 6738 } |
6739 } | 6739 } |
6740 else | 6740 else |
6741 { | 6741 { |
6742 prev = tmp; | 6742 prev = tmp; |
6743 tmp = tmp->next; | 6743 tmp = tmp->next; |
6744 } | 6744 } |
6745 } | 6745 } |
6746 } | 6746 } |
6747 | 6747 |
6748 /* | 6748 /* |
6749 * Add a callback to a window event. | 6749 * Add a callback to a window event. |
6750 * Parameters: | 6750 * Parameters: |
6753 * sigfunc: The pointer to the function to be used as the callback. | 6753 * sigfunc: The pointer to the function to be used as the callback. |
6754 * data: User data to be passed to the handler function. | 6754 * data: User data to be passed to the handler function. |
6755 */ | 6755 */ |
6756 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) | 6756 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) |
6757 { | 6757 { |
6758 ULONG message = 0, msgid = 0; | 6758 ULONG message = 0, msgid = 0; |
6759 | 6759 |
6760 if(window && signame && sigfunc) | 6760 if(window && signame && sigfunc) |
6761 { | 6761 { |
6762 if((message = _findsigmessage(signame)) != 0) | 6762 if((message = _findsigmessage(signame)) != 0) |
6763 { | 6763 { |
6764 _new_signal(message, window, (int)msgid, sigfunc, data); | 6764 _new_signal(message, window, (int)msgid, sigfunc, data); |
6765 } | 6765 } |
6766 } | 6766 } |
6767 } | 6767 } |
6768 | 6768 |
6769 /* | 6769 /* |
6770 * Removes callbacks for a given window with given name. | 6770 * Removes callbacks for a given window with given name. |
6771 * Parameters: | 6771 * Parameters: |
6772 * window: Window handle of callback to be removed. | 6772 * window: Window handle of callback to be removed. |
6773 */ | 6773 */ |
6774 void API dw_signal_disconnect_by_name(HWND window, char *signame) | 6774 void API dw_signal_disconnect_by_name(HWND window, char *signame) |
6775 { | 6775 { |
6776 SignalHandler *prev = NULL, *tmp = Root; | 6776 SignalHandler *prev = NULL, *tmp = Root; |
6777 ULONG message; | 6777 ULONG message; |
6778 | 6778 |
6779 if(!window || !signame || (message = _findsigmessage(signame)) == 0) | 6779 if(!window || !signame || (message = _findsigmessage(signame)) == 0) |
6780 return; | 6780 return; |
6781 | 6781 |
6782 while(tmp) | 6782 while(tmp) |
6783 { | 6783 { |
6784 if(tmp->window == window && tmp->message == message) | 6784 if(tmp->window == window && tmp->message == message) |
6785 { | 6785 { |
6786 if(prev) | 6786 if(prev) |
6787 { | 6787 { |
6788 prev->next = tmp->next; | 6788 prev->next = tmp->next; |
6789 free(tmp); | 6789 free(tmp); |
6790 tmp = prev->next; | 6790 tmp = prev->next; |
6791 } | 6791 } |
6792 else | 6792 else |
6793 { | 6793 { |
6794 Root = tmp->next; | 6794 Root = tmp->next; |
6795 free(tmp); | 6795 free(tmp); |
6796 tmp = Root; | 6796 tmp = Root; |
6797 } | 6797 } |
6798 } | 6798 } |
6799 else | 6799 else |
6800 { | 6800 { |
6801 prev = tmp; | 6801 prev = tmp; |
6802 tmp = tmp->next; | 6802 tmp = tmp->next; |
6803 } | 6803 } |
6804 } | 6804 } |
6805 } | 6805 } |
6806 | 6806 |
6807 /* | 6807 /* |
6808 * Removes all callbacks for a given window. | 6808 * Removes all callbacks for a given window. |
6809 * Parameters: | 6809 * Parameters: |
6810 * window: Window handle of callback to be removed. | 6810 * window: Window handle of callback to be removed. |
6811 */ | 6811 */ |
6812 void API dw_signal_disconnect_by_window(HWND window) | 6812 void API dw_signal_disconnect_by_window(HWND window) |
6813 { | 6813 { |
6814 SignalHandler *prev = NULL, *tmp = Root; | 6814 SignalHandler *prev = NULL, *tmp = Root; |
6815 | 6815 |
6816 while(tmp) | 6816 while(tmp) |
6817 { | 6817 { |
6818 if(tmp->window == window) | 6818 if(tmp->window == window) |
6819 { | 6819 { |
6820 if(prev) | 6820 if(prev) |
6821 { | 6821 { |
6822 prev->next = tmp->next; | 6822 prev->next = tmp->next; |
6823 free(tmp); | 6823 free(tmp); |
6824 tmp = prev->next; | 6824 tmp = prev->next; |
6825 } | 6825 } |
6826 else | 6826 else |
6827 { | 6827 { |
6828 Root = tmp->next; | 6828 Root = tmp->next; |
6829 free(tmp); | 6829 free(tmp); |
6830 tmp = Root; | 6830 tmp = Root; |
6831 } | 6831 } |
6832 } | 6832 } |
6833 else | 6833 else |
6834 { | 6834 { |
6835 prev = tmp; | 6835 prev = tmp; |
6836 tmp = tmp->next; | 6836 tmp = tmp->next; |
6837 } | 6837 } |
6838 } | 6838 } |
6839 } | 6839 } |
6840 | 6840 |
6841 /* | 6841 /* |
6842 * Removes all callbacks for a given window with specified data. | 6842 * Removes all callbacks for a given window with specified data. |
6843 * Parameters: | 6843 * Parameters: |
6844 * window: Window handle of callback to be removed. | 6844 * window: Window handle of callback to be removed. |
6845 * data: Pointer to the data to be compared against. | 6845 * data: Pointer to the data to be compared against. |
6846 */ | 6846 */ |
6847 void API dw_signal_disconnect_by_data(HWND window, void *data) | 6847 void API dw_signal_disconnect_by_data(HWND window, void *data) |
6848 { | 6848 { |
6849 SignalHandler *prev = NULL, *tmp = Root; | 6849 SignalHandler *prev = NULL, *tmp = Root; |
6850 | 6850 |
6851 while(tmp) | 6851 while(tmp) |
6852 { | 6852 { |
6853 if(tmp->window == window && tmp->data == data) | 6853 if(tmp->window == window && tmp->data == data) |
6854 { | 6854 { |
6855 if(prev) | 6855 if(prev) |
6856 { | 6856 { |
6857 prev->next = tmp->next; | 6857 prev->next = tmp->next; |
6858 free(tmp); | 6858 free(tmp); |
6859 tmp = prev->next; | 6859 tmp = prev->next; |
6860 } | 6860 } |
6861 else | 6861 else |
6862 { | 6862 { |
6863 Root = tmp->next; | 6863 Root = tmp->next; |
6864 free(tmp); | 6864 free(tmp); |
6865 tmp = Root; | 6865 tmp = Root; |
6866 } | 6866 } |
6867 } | 6867 } |
6868 else | 6868 else |
6869 { | 6869 { |
6870 prev = tmp; | 6870 prev = tmp; |
6871 tmp = tmp->next; | 6871 tmp = tmp->next; |
6872 } | 6872 } |
6873 } | 6873 } |
6874 } | 6874 } |
6875 | 6875 |
6876 void _my_strlwr(char *buf) | 6876 void _my_strlwr(char *buf) |
6877 { | 6877 { |
6878 int z, len = strlen(buf); | 6878 int z, len = strlen(buf); |
7292 * name: Name given to semaphore which can be opened | 7292 * name: Name given to semaphore which can be opened |
7293 * by other processes. | 7293 * by other processes. |
7294 */ | 7294 */ |
7295 HEV dw_named_event_new(char *name) | 7295 HEV dw_named_event_new(char *name) |
7296 { | 7296 { |
7297 struct sockaddr_un un; | 7297 struct sockaddr_un un; |
7298 int ev, *tmpsock = (int *)malloc(sizeof(int)*2); | 7298 int ev, *tmpsock = (int *)malloc(sizeof(int)*2); |
7299 HEV eve; | 7299 HEV eve; |
7300 DWTID dwthread; | 7300 DWTID dwthread; |
7301 | 7301 |
7302 if(!tmpsock) | 7302 if(!tmpsock) |
7303 return NULL; | 7303 return NULL; |
7304 | 7304 |
7305 eve = (HEV)malloc(sizeof(struct _dw_unix_event)); | 7305 eve = (HEV)malloc(sizeof(struct _dw_unix_event)); |
7306 | 7306 |
7307 if(!eve) | 7307 if(!eve) |
7308 { | 7308 { |
7309 free(tmpsock); | 7309 free(tmpsock); |
7310 return NULL; | 7310 return NULL; |
7311 } | 7311 } |
7312 | 7312 |
7313 tmpsock[0] = socket(AF_UNIX, SOCK_STREAM, 0); | 7313 tmpsock[0] = socket(AF_UNIX, SOCK_STREAM, 0); |
7314 ev = socket(AF_UNIX, SOCK_STREAM, 0); | 7314 ev = socket(AF_UNIX, SOCK_STREAM, 0); |
7315 memset(&un, 0, sizeof(un)); | 7315 memset(&un, 0, sizeof(un)); |
7316 un.sun_family=AF_UNIX; | 7316 un.sun_family=AF_UNIX; |
7317 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); | 7317 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); |
7318 strcpy(un.sun_path, "/tmp/.dw/"); | 7318 strcpy(un.sun_path, "/tmp/.dw/"); |
7319 strcat(un.sun_path, name); | 7319 strcat(un.sun_path, name); |
7320 | 7320 |
7321 /* just to be safe, this should be changed | 7321 /* just to be safe, this should be changed |
7322 * to support multiple instances. | 7322 * to support multiple instances. |
7323 */ | 7323 */ |
7324 remove(un.sun_path); | 7324 remove(un.sun_path); |
7325 | 7325 |
7326 bind(tmpsock[0], (struct sockaddr *)&un, sizeof(un)); | 7326 bind(tmpsock[0], (struct sockaddr *)&un, sizeof(un)); |
7327 listen(tmpsock[0], 0); | 7327 listen(tmpsock[0], 0); |
7328 connect(ev, (struct sockaddr *)&un, sizeof(un)); | 7328 connect(ev, (struct sockaddr *)&un, sizeof(un)); |
7329 tmpsock[1] = accept(tmpsock[0], 0, 0); | 7329 tmpsock[1] = accept(tmpsock[0], 0, 0); |
7330 | 7330 |
7331 if(tmpsock[0] < 0 || tmpsock[1] < 0 || ev < 0) | 7331 if(tmpsock[0] < 0 || tmpsock[1] < 0 || ev < 0) |
7332 { | 7332 { |
7333 if(tmpsock[0] > -1) | 7333 if(tmpsock[0] > -1) |
7334 close(tmpsock[0]); | 7334 close(tmpsock[0]); |
7335 if(tmpsock[1] > -1) | 7335 if(tmpsock[1] > -1) |
7336 close(tmpsock[1]); | 7336 close(tmpsock[1]); |
7337 if(ev > -1) | 7337 if(ev > -1) |
7338 close(ev); | 7338 close(ev); |
7339 free(tmpsock); | 7339 free(tmpsock); |
7340 free(eve); | 7340 free(eve); |
7341 return NULL; | 7341 return NULL; |
7342 } | 7342 } |
7343 | 7343 |
7344 /* Create a thread to handle this event semaphore */ | 7344 /* Create a thread to handle this event semaphore */ |
7345 pthread_create(&dwthread, NULL, (void *)_handle_sem, (void *)tmpsock); | 7345 pthread_create(&dwthread, NULL, (void *)_handle_sem, (void *)tmpsock); |
7346 eve->alive = ev; | 7346 eve->alive = ev; |
7347 return eve; | 7347 return eve; |
7348 } | 7348 } |
7349 | 7349 |
7350 /* Open an already existing named event semaphore. | 7350 /* Open an already existing named event semaphore. |
7351 * Parameters: | 7351 * Parameters: |
7352 * eve: Pointer to an event handle to receive handle. | 7352 * eve: Pointer to an event handle to receive handle. |
7353 * name: Name given to semaphore which can be opened | 7353 * name: Name given to semaphore which can be opened |
7354 * by other processes. | 7354 * by other processes. |
7355 */ | 7355 */ |
7356 HEV dw_named_event_get(char *name) | 7356 HEV dw_named_event_get(char *name) |
7357 { | 7357 { |
7358 struct sockaddr_un un; | 7358 struct sockaddr_un un; |
7359 HEV eve; | 7359 HEV eve; |
7360 int ev = socket(AF_UNIX, SOCK_STREAM, 0); | 7360 int ev = socket(AF_UNIX, SOCK_STREAM, 0); |
7361 if(ev < 0) | 7361 if(ev < 0) |
7362 return NULL; | 7362 return NULL; |
7363 | 7363 |
7364 eve = (HEV)malloc(sizeof(struct _dw_unix_event)); | 7364 eve = (HEV)malloc(sizeof(struct _dw_unix_event)); |
7365 | 7365 |
7366 if(!eve) | 7366 if(!eve) |
7367 { | 7367 { |
7368 close(ev); | 7368 close(ev); |
7369 return NULL; | 7369 return NULL; |
7370 } | 7370 } |
7371 | 7371 |
7372 un.sun_family=AF_UNIX; | 7372 un.sun_family=AF_UNIX; |
7373 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); | 7373 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); |
7374 strcpy(un.sun_path, "/tmp/.dw/"); | 7374 strcpy(un.sun_path, "/tmp/.dw/"); |
7375 strcat(un.sun_path, name); | 7375 strcat(un.sun_path, name); |
7376 connect(ev, (struct sockaddr *)&un, sizeof(un)); | 7376 connect(ev, (struct sockaddr *)&un, sizeof(un)); |
7377 eve->alive = ev; | 7377 eve->alive = ev; |
7378 return eve; | 7378 return eve; |
7379 } | 7379 } |
7380 | 7380 |
7381 /* Resets the event semaphore so threads who call wait | 7381 /* Resets the event semaphore so threads who call wait |
7382 * on this semaphore will block. | 7382 * on this semaphore will block. |
7383 * Parameters: | 7383 * Parameters: |
7480 int dw_named_event_close(HEV eve) | 7480 int dw_named_event_close(HEV eve) |
7481 { | 7481 { |
7482 /* Finally close the domain socket, | 7482 /* Finally close the domain socket, |
7483 * cleanup will continue in _handle_sem. | 7483 * cleanup will continue in _handle_sem. |
7484 */ | 7484 */ |
7485 if(eve) | 7485 if(eve) |
7486 { | 7486 { |
7487 close(eve->alive); | 7487 close(eve->alive); |
7488 free(eve); | 7488 free(eve); |
7489 } | 7489 } |
7490 return 0; | 7490 return 0; |
7491 } | 7491 } |
7492 | 7492 |
7493 #if !defined(GARBAGE_COLLECT) | 7493 #if !defined(GARBAGE_COLLECT) |
7494 pthread_key_t _dw_pool_key; | 7494 pthread_key_t _dw_pool_key; |
7495 #endif | 7495 #endif |
7512 { | 7512 { |
7513 void (*threadfunc)(void *) = NULL; | 7513 void (*threadfunc)(void *) = NULL; |
7514 void **tmp = (void **)data; | 7514 void **tmp = (void **)data; |
7515 /* If we aren't using garbage collection we need autorelease pools */ | 7515 /* If we aren't using garbage collection we need autorelease pools */ |
7516 #if !defined(GARBAGE_COLLECT) | 7516 #if !defined(GARBAGE_COLLECT) |
7517 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | 7517 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
7518 pthread_setspecific(_dw_pool_key, pool); | 7518 pthread_setspecific(_dw_pool_key, pool); |
7519 #endif | 7519 #endif |
7520 | 7520 |
7521 threadfunc = (void (*)(void *))tmp[0]; | 7521 threadfunc = (void (*)(void *))tmp[0]; |
7522 | 7522 |
7523 threadfunc(tmp[1]); | 7523 threadfunc(tmp[1]); |
7524 /* Release the pool when we are done so we don't leak */ | 7524 /* Release the pool when we are done so we don't leak */ |
7525 #if !defined(GARBAGE_COLLECT) | 7525 #if !defined(GARBAGE_COLLECT) |
7526 pool = pthread_getspecific(_dw_pool_key); | 7526 pool = pthread_getspecific(_dw_pool_key); |
7527 [pool drain]; | 7527 [pool drain]; |
7528 #endif | 7528 #endif |
7529 free(tmp); | 7529 free(tmp); |
7530 } | 7530 } |
7531 | 7531 |
7532 void _dw_default_font(char *fontname) | 7532 void _dw_default_font(char *fontname) |
7690 * data: Parameter(s) passed to the function. | 7690 * data: Parameter(s) passed to the function. |
7691 * stack: Stack size of new thread (OS/2 and Windows only). | 7691 * stack: Stack size of new thread (OS/2 and Windows only). |
7692 */ | 7692 */ |
7693 DWTID dw_thread_new(void *func, void *data, int stack) | 7693 DWTID dw_thread_new(void *func, void *data, int stack) |
7694 { | 7694 { |
7695 DWTID thread; | 7695 DWTID thread; |
7696 void **tmp = malloc(sizeof(void *) * 2); | 7696 void **tmp = malloc(sizeof(void *) * 2); |
7697 int rc; | 7697 int rc; |
7698 | 7698 |
7699 tmp[0] = func; | 7699 tmp[0] = func; |
7700 tmp[1] = data; | 7700 tmp[1] = data; |
7701 | 7701 |
7702 rc = pthread_create(&thread, NULL, (void *)_dwthreadstart, (void *)tmp); | 7702 rc = pthread_create(&thread, NULL, (void *)_dwthreadstart, (void *)tmp); |
7730 * Returns: | 7730 * Returns: |
7731 * -1 on error. | 7731 * -1 on error. |
7732 */ | 7732 */ |
7733 int dw_exec(char *program, int type, char **params) | 7733 int dw_exec(char *program, int type, char **params) |
7734 { | 7734 { |
7735 int ret = -1; | 7735 int ret = -1; |
7736 | 7736 |
7737 if(type == DW_EXEC_GUI) | 7737 if(type == DW_EXEC_GUI) |
7738 { | 7738 { |
7739 if(params && params[0] && params[1]) | 7739 if(params && params[0] && params[1]) |
7740 { | 7740 { |
7741 [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithUTF8String:params[1]] | 7741 [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithUTF8String:params[1]] |
7746 [[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:program]]; | 7746 [[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:program]]; |
7747 } | 7747 } |
7748 return 0; | 7748 return 0; |
7749 } | 7749 } |
7750 | 7750 |
7751 if((ret = fork()) == 0) | 7751 if((ret = fork()) == 0) |
7752 { | 7752 { |
7753 int i; | 7753 int i; |
7754 | |
7755 for (i = 3; i < 256; i++) | |
7756 close(i); | |
7757 setsid(); | |
7758 | 7754 |
7759 if(type == DW_EXEC_CON) | 7755 for (i = 3; i < 256; i++) |
7760 { | 7756 close(i); |
7761 char **tmpargs; | 7757 setsid(); |
7762 | 7758 |
7763 if(!params) | 7759 if(type == DW_EXEC_CON) |
7764 { | 7760 { |
7765 tmpargs = malloc(sizeof(char *)); | 7761 char **tmpargs; |
7766 tmpargs[0] = NULL; | 7762 |
7767 } | 7763 if(!params) |
7768 else | 7764 { |
7769 { | 7765 tmpargs = malloc(sizeof(char *)); |
7770 int z = 0; | 7766 tmpargs[0] = NULL; |
7771 | 7767 } |
7772 while(params[z]) | 7768 else |
7773 { | 7769 { |
7774 z++; | 7770 int z = 0; |
7775 } | 7771 |
7776 tmpargs = malloc(sizeof(char *)*(z+3)); | 7772 while(params[z]) |
7777 z=0; | 7773 { |
7778 tmpargs[0] = "xterm"; | 7774 z++; |
7779 tmpargs[1] = "-e"; | 7775 } |
7780 while(params[z]) | 7776 tmpargs = malloc(sizeof(char *)*(z+3)); |
7781 { | 7777 z=0; |
7782 tmpargs[z+2] = params[z]; | 7778 tmpargs[0] = "xterm"; |
7783 z++; | 7779 tmpargs[1] = "-e"; |
7784 } | 7780 while(params[z]) |
7785 tmpargs[z+2] = NULL; | 7781 { |
7786 } | 7782 tmpargs[z+2] = params[z]; |
7787 execvp("xterm", tmpargs); | 7783 z++; |
7788 free(tmpargs); | 7784 } |
7789 } | 7785 tmpargs[z+2] = NULL; |
7790 /* If we got here exec failed */ | 7786 } |
7791 _exit(-1); | 7787 execvp("xterm", tmpargs); |
7792 } | 7788 free(tmpargs); |
7793 return ret; | 7789 } |
7790 /* If we got here exec failed */ | |
7791 _exit(-1); | |
7792 } | |
7793 return ret; | |
7794 } | 7794 } |
7795 | 7795 |
7796 /* | 7796 /* |
7797 * Loads a web browser pointed at the given URL. | 7797 * Loads a web browser pointed at the given URL. |
7798 * Parameters: | 7798 * Parameters: |