Mercurial > dwindows
comparison mac/dw.m @ 762:2aaa3f67cfb1
Fix for crashes with generating images from data
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 17 Mar 2011 23:58:33 +0000 |
parents | 2fb17622a455 |
children | 2cace4e6e69a |
comparison
equal
deleted
inserted
replaced
761:39d848c20c05 | 762:2aaa3f67cfb1 |
---|---|
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 */ |
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 { |
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 |
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]; |
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 */ |
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); |
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: |
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 { |
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 |
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 id orig = bgcolor; | 512 id orig = bgcolor; |
513 | 513 |
514 if(input == _colors[DW_CLR_DEFAULT]) | 514 if(input == _colors[DW_CLR_DEFAULT]) |
515 { | 515 { |
516 bgcolor = nil; | 516 bgcolor = nil; |
517 } | 517 } |
518 else | 518 else |
676 -(void)setPageid:(int)input { pageid = input; } | 676 -(void)setPageid:(int)input { pageid = input; } |
677 -(void)tabView:(NSTabView *)notebook didSelectTabViewItem:(NSTabViewItem *)notepage | 677 -(void)tabView:(NSTabView *)notebook didSelectTabViewItem:(NSTabViewItem *)notepage |
678 { | 678 { |
679 id object = [notepage view]; | 679 id object = [notepage view]; |
680 DWNotebookPage *page = (DWNotebookPage *)notepage; | 680 DWNotebookPage *page = (DWNotebookPage *)notepage; |
681 | 681 |
682 if([object isMemberOfClass:[DWBox class]]) | 682 if([object isMemberOfClass:[DWBox class]]) |
683 { | 683 { |
684 DWBox *view = object; | 684 DWBox *view = object; |
685 Box *box = [view box]; | 685 Box *box = [view box]; |
686 NSSize size = [view frame].size; | 686 NSSize size = [view frame].size; |
687 _do_resize(box, size.width, size.height); | 687 _do_resize(box, size.width, size.height); |
688 } | 688 } |
689 _event_handler(self, (void *)[page pageid], 15); | 689 _event_handler(self, (void *)[page pageid], 15); |
690 } | 690 } |
691 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 691 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
692 @end | 692 @end |
693 | 693 |
694 @implementation DWNotebookPage | 694 @implementation DWNotebookPage |
695 -(void *)userdata { return userdata; } | 695 -(void *)userdata { return userdata; } |
736 @implementation DWSplitBar | 736 @implementation DWSplitBar |
737 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification | 737 -(void)splitViewDidResizeSubviews:(NSNotification *)aNotification |
738 { | 738 { |
739 NSArray *views = [self subviews]; | 739 NSArray *views = [self subviews]; |
740 id object; | 740 id object; |
741 | 741 |
742 for(object in views) | 742 for(object in views) |
743 { | 743 { |
744 if([object isMemberOfClass:[DWBox class]]) | 744 if([object isMemberOfClass:[DWBox class]]) |
745 { | 745 { |
746 DWBox *view = object; | 746 DWBox *view = object; |
747 Box *box = [view box]; | 747 Box *box = [view box]; |
748 NSSize size = [view frame].size; | 748 NSSize size = [view frame].size; |
749 _do_resize(box, size.width, size.height); | 749 _do_resize(box, size.width, size.height); |
750 } | 750 } |
751 } | 751 } |
752 } | 752 } |
753 -(void *)userdata { return userdata; } | 753 -(void *)userdata { return userdata; } |
754 -(void)setUserdata:(void *)input { userdata = input; } | 754 -(void)setUserdata:(void *)input { userdata = input; } |
755 -(float)percent { return percent; } | 755 -(float)percent { return percent; } |
756 -(void)setPercent:(float)input { percent = input; } | 756 -(void)setPercent:(float)input { percent = input; } |
960 { | 960 { |
961 if(tvcols) | 961 if(tvcols) |
962 { | 962 { |
963 int z, col = -1; | 963 int z, col = -1; |
964 int count = (int)[tvcols count]; | 964 int count = (int)[tvcols count]; |
965 | 965 |
966 for(z=0;z<count;z++) | 966 for(z=0;z<count;z++) |
967 { | 967 { |
968 if([tvcols objectAtIndex:z] == aCol) | 968 if([tvcols objectAtIndex:z] == aCol) |
969 { | 969 { |
970 col = z; | 970 col = z; |
1019 { | 1019 { |
1020 if(tvcols) | 1020 if(tvcols) |
1021 { | 1021 { |
1022 int count = (int)(number * [tvcols count]); | 1022 int count = (int)(number * [tvcols count]); |
1023 int z; | 1023 int z; |
1024 | 1024 |
1025 lastAddPoint = (int)[titles count]; | 1025 lastAddPoint = (int)[titles count]; |
1026 | 1026 |
1027 for(z=0;z<count;z++) | 1027 for(z=0;z<count;z++) |
1028 { | 1028 { |
1029 [data addObject:[NSNull null]]; | 1029 [data addObject:[NSNull null]]; |
1030 } | 1030 } |
1031 for(z=0;z<number;z++) | 1031 for(z=0;z<number;z++) |
1033 [titles addPointer:NULL]; | 1033 [titles addPointer:NULL]; |
1034 } | 1034 } |
1035 return (int)[titles count]; | 1035 return (int)[titles count]; |
1036 } | 1036 } |
1037 return 0; | 1037 return 0; |
1038 } | 1038 } |
1039 -(void)editCell:(id)input at:(int)row and:(int)col | 1039 -(void)editCell:(id)input at:(int)row and:(int)col |
1040 { | 1040 { |
1041 if(tvcols && input) | 1041 if(tvcols && input) |
1042 { | 1042 { |
1043 int index = (int)(row * [tvcols count]) + col; | 1043 int index = (int)(row * [tvcols count]) + col; |
1048 { | 1048 { |
1049 if(tvcols) | 1049 if(tvcols) |
1050 { | 1050 { |
1051 int z, start, end; | 1051 int z, start, end; |
1052 int count = (int)[tvcols count]; | 1052 int count = (int)[tvcols count]; |
1053 | 1053 |
1054 start = count * row; | 1054 start = count * row; |
1055 end = start + count; | 1055 end = start + count; |
1056 | 1056 |
1057 for(z=start;z<end;z++) | 1057 for(z=start;z<end;z++) |
1058 { | 1058 { |
1059 [data removeObjectAtIndex:z]; | 1059 [data removeObjectAtIndex:z]; |
1060 } | 1060 } |
1061 [titles removePointerAtIndex:row]; | 1061 [titles removePointerAtIndex:row]; |
1444 /* This function adds a signal handler callback into the linked list. | 1444 /* This function adds a signal handler callback into the linked list. |
1445 */ | 1445 */ |
1446 void _new_signal(ULONG message, HWND window, int msgid, void *signalfunction, void *data) | 1446 void _new_signal(ULONG message, HWND window, int msgid, void *signalfunction, void *data) |
1447 { | 1447 { |
1448 SignalHandler *new = malloc(sizeof(SignalHandler)); | 1448 SignalHandler *new = malloc(sizeof(SignalHandler)); |
1449 | 1449 |
1450 new->message = message; | 1450 new->message = message; |
1451 new->window = window; | 1451 new->window = window; |
1452 new->id = msgid; | 1452 new->id = msgid; |
1453 new->signalfunction = signalfunction; | 1453 new->signalfunction = signalfunction; |
1454 new->data = data; | 1454 new->data = data; |
1455 new->next = NULL; | 1455 new->next = NULL; |
1456 | 1456 |
1457 if (!Root) | 1457 if (!Root) |
1458 Root = new; | 1458 Root = new; |
1459 else | 1459 else |
1460 { | 1460 { |
1461 SignalHandler *prev = NULL, *tmp = Root; | 1461 SignalHandler *prev = NULL, *tmp = Root; |
1482 | 1482 |
1483 /* Finds the message number for a given signal name */ | 1483 /* Finds the message number for a given signal name */ |
1484 ULONG _findsigmessage(char *signame) | 1484 ULONG _findsigmessage(char *signame) |
1485 { | 1485 { |
1486 int z; | 1486 int z; |
1487 | 1487 |
1488 for(z=0;z<SIGNALMAX;z++) | 1488 for(z=0;z<SIGNALMAX;z++) |
1489 { | 1489 { |
1490 if(strcasecmp(signame, SignalTranslate[z].name) == 0) | 1490 if(strcasecmp(signame, SignalTranslate[z].name) == 0) |
1491 return SignalTranslate[z].message; | 1491 return SignalTranslate[z].message; |
1492 } | 1492 } |
1505 int uymax = 0, uxmax = 0; | 1505 int uymax = 0, uxmax = 0; |
1506 int upymax = 0, upxmax = 0; | 1506 int upymax = 0, upxmax = 0; |
1507 /* Used for the SIZEEXPAND */ | 1507 /* Used for the SIZEEXPAND */ |
1508 int nux = *usedx, nuy = *usedy; | 1508 int nux = *usedx, nuy = *usedy; |
1509 int nupx = *usedpadx, nupy = *usedpady; | 1509 int nupx = *usedpadx, nupy = *usedpady; |
1510 | 1510 |
1511 (*usedx) += (thisbox->pad * 2); | 1511 (*usedx) += (thisbox->pad * 2); |
1512 (*usedy) += (thisbox->pad * 2); | 1512 (*usedy) += (thisbox->pad * 2); |
1513 | 1513 |
1514 for(z=0;z<thisbox->count;z++) | 1514 for(z=0;z<thisbox->count;z++) |
1515 { | 1515 { |
1808 if([handle isMemberOfClass:[DWNotebook class]]) | 1808 if([handle isMemberOfClass:[DWNotebook class]]) |
1809 { | 1809 { |
1810 DWNotebook *notebook = (DWNotebook *)handle; | 1810 DWNotebook *notebook = (DWNotebook *)handle; |
1811 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; | 1811 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem]; |
1812 DWBox *view = [notepage view]; | 1812 DWBox *view = [notepage view]; |
1813 | 1813 |
1814 if(view != nil) | 1814 if(view != nil) |
1815 { | 1815 { |
1816 Box *box = [view box]; | 1816 Box *box = [view box]; |
1817 NSSize size = [view frame].size; | 1817 NSSize size = [view frame].size; |
1818 _do_resize(box, size.width, size.height); | 1818 _do_resize(box, size.width, size.height); |
1835 } | 1835 } |
1836 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20) | 1836 else if([handle isMemberOfClass:[DWSplitBar class]] && size.width > 20 && size.height > 20) |
1837 { | 1837 { |
1838 DWSplitBar *split = (DWSplitBar *)handle; | 1838 DWSplitBar *split = (DWSplitBar *)handle; |
1839 float percent = [split percent]; | 1839 float percent = [split percent]; |
1840 | 1840 |
1841 if(percent > 0) | 1841 if(percent > 0) |
1842 { | 1842 { |
1843 dw_splitbar_set(handle, percent); | 1843 dw_splitbar_set(handle, percent); |
1844 [split setPercent:0]; | 1844 [split setPercent:0]; |
1845 } | 1845 } |
1846 } | 1846 } |
1847 | 1847 |
1848 if(thisbox->type == DW_HORZ) | 1848 if(thisbox->type == DW_HORZ) |
1849 currentx += width + vectorx + (pad * 2); | 1849 currentx += width + vectorx + (pad * 2); |
1850 if(thisbox->type == DW_VERT) | 1850 if(thisbox->type == DW_VERT) |
1851 currenty += height + vectory + (pad * 2); | 1851 currenty += height + vectory + (pad * 2); |
1852 } | 1852 } |
1879 } | 1879 } |
1880 | 1880 |
1881 NSMenu *_generate_main_menu() | 1881 NSMenu *_generate_main_menu() |
1882 { | 1882 { |
1883 NSString *applicationName = nil; | 1883 NSString *applicationName = nil; |
1884 | 1884 |
1885 /* This only works on 10.6 so we have a backup method */ | 1885 /* This only works on 10.6 so we have a backup method */ |
1886 #ifdef BUILDING_FOR_SNOW_LEOPARD | 1886 #ifdef BUILDING_FOR_SNOW_LEOPARD |
1887 applicationName = [[NSRunningApplication currentApplication] localizedName]; | 1887 applicationName = [[NSRunningApplication currentApplication] localizedName]; |
1888 #endif | 1888 #endif |
1889 if(applicationName == nil) | 1889 if(applicationName == nil) |
1890 { | 1890 { |
1891 applicationName = [[NSProcessInfo processInfo] processName]; | 1891 applicationName = [[NSProcessInfo processInfo] processName]; |
1892 } | 1892 } |
1893 | 1893 |
1894 /* Create the main menu */ | 1894 /* Create the main menu */ |
1895 NSMenu * mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease]; | 1895 NSMenu * mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease]; |
1896 | 1896 |
1897 NSMenuItem * mitem = [mainMenu addItemWithTitle:@"Apple" action:NULL keyEquivalent:@""]; | 1897 NSMenuItem * mitem = [mainMenu addItemWithTitle:@"Apple" action:NULL keyEquivalent:@""]; |
1898 NSMenu * menu = [[[NSMenu alloc] initWithTitle:@"Apple"] autorelease]; | 1898 NSMenu * menu = [[[NSMenu alloc] initWithTitle:@"Apple"] autorelease]; |
1899 | 1899 |
1900 [DWApp performSelector:@selector(setAppleMenu:) withObject:menu]; | 1900 [DWApp performSelector:@selector(setAppleMenu:) withObject:menu]; |
1901 | 1901 |
1902 /* Setup the Application menu */ | 1902 /* Setup the Application menu */ |
1903 NSMenuItem * item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"About", nil), applicationName] | 1903 NSMenuItem * item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"About", nil), applicationName] |
1904 action:@selector(orderFrontStandardAboutPanel:) | 1904 action:@selector(orderFrontStandardAboutPanel:) |
1905 keyEquivalent:@""]; | 1905 keyEquivalent:@""]; |
1906 [item setTarget:DWApp]; | 1906 [item setTarget:DWApp]; |
1907 | 1907 |
1908 [menu addItem:[NSMenuItem separatorItem]]; | 1908 [menu addItem:[NSMenuItem separatorItem]]; |
1909 | 1909 |
1910 item = [menu addItemWithTitle:NSLocalizedString(@"Services", nil) | 1910 item = [menu addItemWithTitle:NSLocalizedString(@"Services", nil) |
1911 action:NULL | 1911 action:NULL |
1912 keyEquivalent:@""]; | 1912 keyEquivalent:@""]; |
1913 NSMenu * servicesMenu = [[[NSMenu alloc] initWithTitle:@"Services"] autorelease]; | 1913 NSMenu * servicesMenu = [[[NSMenu alloc] initWithTitle:@"Services"] autorelease]; |
1914 [menu setSubmenu:servicesMenu forItem:item]; | 1914 [menu setSubmenu:servicesMenu forItem:item]; |
1915 [DWApp setServicesMenu:servicesMenu]; | 1915 [DWApp setServicesMenu:servicesMenu]; |
1916 | 1916 |
1917 [menu addItem:[NSMenuItem separatorItem]]; | 1917 [menu addItem:[NSMenuItem separatorItem]]; |
1918 | 1918 |
1919 item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Hide", nil), applicationName] | 1919 item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Hide", nil), applicationName] |
1920 action:@selector(hide:) | 1920 action:@selector(hide:) |
1921 keyEquivalent:@"h"]; | 1921 keyEquivalent:@"h"]; |
1922 [item setTarget:DWApp]; | 1922 [item setTarget:DWApp]; |
1923 | 1923 |
1924 item = [menu addItemWithTitle:NSLocalizedString(@"Hide Others", nil) | 1924 item = [menu addItemWithTitle:NSLocalizedString(@"Hide Others", nil) |
1925 action:@selector(hideOtherApplications:) | 1925 action:@selector(hideOtherApplications:) |
1926 keyEquivalent:@"h"]; | 1926 keyEquivalent:@"h"]; |
1927 [item setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask]; | 1927 [item setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask]; |
1928 [item setTarget:DWApp]; | 1928 [item setTarget:DWApp]; |
1929 | 1929 |
1930 item = [menu addItemWithTitle:NSLocalizedString(@"Show All", nil) | 1930 item = [menu addItemWithTitle:NSLocalizedString(@"Show All", nil) |
1931 action:@selector(unhideAllApplications:) | 1931 action:@selector(unhideAllApplications:) |
1932 keyEquivalent:@""]; | 1932 keyEquivalent:@""]; |
1933 [item setTarget:DWApp]; | 1933 [item setTarget:DWApp]; |
1934 | 1934 |
1935 [menu addItem:[NSMenuItem separatorItem]]; | 1935 [menu addItem:[NSMenuItem separatorItem]]; |
1936 | 1936 |
1937 item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Quit", nil), applicationName] | 1937 item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Quit", nil), applicationName] |
1938 action:@selector(terminate:) | 1938 action:@selector(terminate:) |
1939 keyEquivalent:@"q"]; | 1939 keyEquivalent:@"q"]; |
1940 [item setTarget:DWApp]; | 1940 [item setTarget:DWApp]; |
1941 | 1941 |
1942 [mainMenu setSubmenu:menu forItem:mitem]; | 1942 [mainMenu setSubmenu:menu forItem:mitem]; |
1943 | 1943 |
1944 return mainMenu; | 1944 return mainMenu; |
1945 } | 1945 } |
1946 | 1946 |
1947 /* | 1947 /* |
1948 * Runs a message loop for Dynamic Windows. | 1948 * Runs a message loop for Dynamic Windows. |
2056 * OS/2 and Windows). | 2056 * OS/2 and Windows). |
2057 */ | 2057 */ |
2058 char *dw_user_dir(void) | 2058 char *dw_user_dir(void) |
2059 { | 2059 { |
2060 static char _user_dir[1024] = ""; | 2060 static char _user_dir[1024] = ""; |
2061 | 2061 |
2062 if(!_user_dir[0]) | 2062 if(!_user_dir[0]) |
2063 { | 2063 { |
2064 char *home = getenv("HOME"); | 2064 char *home = getenv("HOME"); |
2065 | 2065 |
2066 if(home) | 2066 if(home) |
2067 strcpy(_user_dir, home); | 2067 strcpy(_user_dir, home); |
2068 else | 2068 else |
2069 strcpy(_user_dir, "/"); | 2069 strcpy(_user_dir, "/"); |
2070 } | 2070 } |
2089 char outbuf[1000]; | 2089 char outbuf[1000]; |
2090 | 2090 |
2091 va_start(args, format); | 2091 va_start(args, format); |
2092 vsprintf(outbuf, format, args); | 2092 vsprintf(outbuf, format, args); |
2093 va_end(args); | 2093 va_end(args); |
2094 | 2094 |
2095 if(flags & DW_MB_OKCANCEL) | 2095 if(flags & DW_MB_OKCANCEL) |
2096 { | 2096 { |
2097 button2 = @"Cancel"; | 2097 button2 = @"Cancel"; |
2098 } | 2098 } |
2099 else if(flags & DW_MB_YESNO) | 2099 else if(flags & DW_MB_YESNO) |
2105 { | 2105 { |
2106 button1 = @"Yes"; | 2106 button1 = @"Yes"; |
2107 button2 = @"No"; | 2107 button2 = @"No"; |
2108 button3 = @"Cancel"; | 2108 button3 = @"Cancel"; |
2109 } | 2109 } |
2110 | 2110 |
2111 if(flags & DW_MB_ERROR) | 2111 if(flags & DW_MB_ERROR) |
2112 { | 2112 { |
2113 iResponse = (int) | 2113 iResponse = (int) |
2114 NSRunCriticalAlertPanel([ NSString stringWithUTF8String:title ], | 2114 NSRunCriticalAlertPanel([ NSString stringWithUTF8String:title ], |
2115 [ NSString stringWithUTF8String:outbuf ], | 2115 [ NSString stringWithUTF8String:outbuf ], |
2119 iResponse = (int) | 2119 iResponse = (int) |
2120 NSRunAlertPanel([ NSString stringWithUTF8String:title ], | 2120 NSRunAlertPanel([ NSString stringWithUTF8String:title ], |
2121 [ NSString stringWithUTF8String:outbuf ], | 2121 [ NSString stringWithUTF8String:outbuf ], |
2122 button1, button2, button3); | 2122 button1, button2, button3); |
2123 } | 2123 } |
2124 | 2124 |
2125 switch(iResponse) | 2125 switch(iResponse) |
2126 { | 2126 { |
2127 case NSAlertDefaultReturn: /* user pressed OK */ | 2127 case NSAlertDefaultReturn: /* user pressed OK */ |
2128 if(flags & DW_MB_YESNO || flags & DW_MB_YESNOCANCEL) | 2128 if(flags & DW_MB_YESNO || flags & DW_MB_YESNOCANCEL) |
2129 { | 2129 { |
2160 { | 2160 { |
2161 if(flags == DW_FILE_OPEN) | 2161 if(flags == DW_FILE_OPEN) |
2162 { | 2162 { |
2163 /* Create the File Open Dialog class. */ | 2163 /* Create the File Open Dialog class. */ |
2164 NSOpenPanel* openDlg = [NSOpenPanel openPanel]; | 2164 NSOpenPanel* openDlg = [NSOpenPanel openPanel]; |
2165 | 2165 |
2166 /* Enable the selection of files in the dialog. */ | 2166 /* Enable the selection of files in the dialog. */ |
2167 [openDlg setCanChooseFiles:YES]; | 2167 [openDlg setCanChooseFiles:YES]; |
2168 [openDlg setCanChooseDirectories:NO]; | 2168 [openDlg setCanChooseDirectories:NO]; |
2169 | 2169 |
2170 /* Disable multiple selection */ | 2170 /* Disable multiple selection */ |
2171 [openDlg setAllowsMultipleSelection:NO]; | 2171 [openDlg setAllowsMultipleSelection:NO]; |
2172 | 2172 |
2173 /* Display the dialog. If the OK button was pressed, | 2173 /* Display the dialog. If the OK button was pressed, |
2174 * process the files. | 2174 * process the files. |
2175 */ | 2175 */ |
2176 if([openDlg runModal] == NSOKButton) | 2176 if([openDlg runModal] == NSOKButton) |
2177 { | 2177 { |
2178 /* Get an array containing the full filenames of all | 2178 /* Get an array containing the full filenames of all |
2179 * files and directories selected. | 2179 * files and directories selected. |
2180 */ | 2180 */ |
2181 NSArray* files = [openDlg filenames]; | 2181 NSArray* files = [openDlg filenames]; |
2182 NSString* fileName = [files objectAtIndex:0]; | 2182 NSString* fileName = [files objectAtIndex:0]; |
2183 return strdup([ fileName UTF8String ]); | 2183 return strdup([ fileName UTF8String ]); |
2184 } | 2184 } |
2185 } | 2185 } |
2186 else | 2186 else |
2187 { | 2187 { |
2188 /* Create the File Save Dialog class. */ | 2188 /* Create the File Save Dialog class. */ |
2189 NSSavePanel* saveDlg = [NSSavePanel savePanel]; | 2189 NSSavePanel* saveDlg = [NSSavePanel savePanel]; |
2190 | 2190 |
2191 /* Enable the creation of directories in the dialog. */ | 2191 /* Enable the creation of directories in the dialog. */ |
2192 [saveDlg setCanCreateDirectories:YES]; | 2192 [saveDlg setCanCreateDirectories:YES]; |
2193 | 2193 |
2194 /* Display the dialog. If the OK button was pressed, | 2194 /* Display the dialog. If the OK button was pressed, |
2195 * process the files. | 2195 * process the files. |
2196 */ | 2196 */ |
2197 if([saveDlg runModal] == NSFileHandlingPanelOKButton) | 2197 if([saveDlg runModal] == NSFileHandlingPanelOKButton) |
2198 { | 2198 { |
2199 /* Get an array containing the full filenames of all | 2199 /* Get an array containing the full filenames of all |
2200 * files and directories selected. | 2200 * files and directories selected. |
2201 */ | 2201 */ |
2202 NSString* fileName = [saveDlg filename]; | 2202 NSString* fileName = [saveDlg filename]; |
2203 return strdup([ fileName UTF8String ]); | 2203 return strdup([ fileName UTF8String ]); |
2204 } | 2204 } |
2205 } | 2205 } |
2206 | 2206 |
2207 return NULL; | 2207 return NULL; |
2208 } | 2208 } |
2209 | 2209 |
2232 * Text. | 2232 * Text. |
2233 */ | 2233 */ |
2234 void dw_clipboard_set_text( char *str, int len) | 2234 void dw_clipboard_set_text( char *str, int len) |
2235 { | 2235 { |
2236 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; | 2236 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; |
2237 | 2237 |
2238 /* Only in Snow Leopard */ | 2238 /* Only in Snow Leopard */ |
2239 if(DWOSMinor > 5) | 2239 if(DWOSMinor > 5) |
2240 { | 2240 { |
2241 [pasteboard clearContents]; | 2241 [pasteboard clearContents]; |
2242 } | 2242 } |
2243 | 2243 |
2244 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType]; | 2244 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType]; |
2245 } | 2245 } |
2246 | 2246 |
2247 | 2247 |
2248 /* | 2248 /* |
2251 * data: User defined data to be passed to functions. | 2251 * data: User defined data to be passed to functions. |
2252 */ | 2252 */ |
2253 DWDialog * API dw_dialog_new(void *data) | 2253 DWDialog * API dw_dialog_new(void *data) |
2254 { | 2254 { |
2255 DWDialog *tmp = malloc(sizeof(DWDialog)); | 2255 DWDialog *tmp = malloc(sizeof(DWDialog)); |
2256 | 2256 |
2257 if(tmp) | 2257 if(tmp) |
2258 { | 2258 { |
2259 tmp->eve = dw_event_new(); | 2259 tmp->eve = dw_event_new(); |
2260 dw_event_reset(tmp->eve); | 2260 dw_event_reset(tmp->eve); |
2261 tmp->data = data; | 2261 tmp->data = data; |
2262 tmp->done = FALSE; | 2262 tmp->done = FALSE; |
2263 tmp->result = NULL; | 2263 tmp->result = NULL; |
2264 } | 2264 } |
2265 return tmp; | 2265 return tmp; |
2266 } | 2266 } |
2267 | 2267 |
2268 /* | 2268 /* |
2269 * Accepts a dialog struct and returns the given data to the | 2269 * Accepts a dialog struct and returns the given data to the |
2270 * initial called of dw_dialog_wait(). | 2270 * initial called of dw_dialog_wait(). |
2287 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). | 2287 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). |
2288 */ | 2288 */ |
2289 void * API dw_dialog_wait(DWDialog *dialog) | 2289 void * API dw_dialog_wait(DWDialog *dialog) |
2290 { | 2290 { |
2291 void *tmp; | 2291 void *tmp; |
2292 | 2292 |
2293 while(!dialog->done) | 2293 while(!dialog->done) |
2294 { | 2294 { |
2295 _dw_main_iteration([NSDate dateWithTimeIntervalSinceNow:0.01]); | 2295 _dw_main_iteration([NSDate dateWithTimeIntervalSinceNow:0.01]); |
2296 } | 2296 } |
2297 dw_event_close(&dialog->eve); | 2297 dw_event_close(&dialog->eve); |
2402 if([ object isKindOfClass:[ NSWindow class ] ]) | 2402 if([ object isKindOfClass:[ NSWindow class ] ]) |
2403 { | 2403 { |
2404 NSWindow *window = box; | 2404 NSWindow *window = box; |
2405 view = [window contentView]; | 2405 view = [window contentView]; |
2406 } | 2406 } |
2407 | 2407 |
2408 thisbox = [view box]; | 2408 thisbox = [view box]; |
2409 thisitem = thisbox->items; | 2409 thisitem = thisbox->items; |
2410 object = item; | 2410 object = item; |
2411 | 2411 |
2412 /* Query the objects */ | 2412 /* Query the objects */ |
2460 /* Update the item count */ | 2460 /* Update the item count */ |
2461 thisbox->count++; | 2461 thisbox->count++; |
2462 | 2462 |
2463 /* Add the item to the box */ | 2463 /* Add the item to the box */ |
2464 [view addSubview:this]; | 2464 [view addSubview:this]; |
2465 | 2465 |
2466 /* Free the old data */ | 2466 /* Free the old data */ |
2467 if(thisbox->count) | 2467 if(thisbox->count) |
2468 free(thisitem); | 2468 free(thisitem); |
2469 DW_MUTEX_UNLOCK; | 2469 DW_MUTEX_UNLOCK; |
2470 } | 2470 } |
2495 if([ object isKindOfClass:[ NSWindow class ] ]) | 2495 if([ object isKindOfClass:[ NSWindow class ] ]) |
2496 { | 2496 { |
2497 NSWindow *window = box; | 2497 NSWindow *window = box; |
2498 view = [window contentView]; | 2498 view = [window contentView]; |
2499 } | 2499 } |
2500 | 2500 |
2501 thisbox = [view box]; | 2501 thisbox = [view box]; |
2502 thisitem = thisbox->items; | 2502 thisitem = thisbox->items; |
2503 object = item; | 2503 object = item; |
2504 | 2504 |
2505 /* Query the objects */ | 2505 /* Query the objects */ |
2553 /* Update the item count */ | 2553 /* Update the item count */ |
2554 thisbox->count++; | 2554 thisbox->count++; |
2555 | 2555 |
2556 /* Add the item to the box */ | 2556 /* Add the item to the box */ |
2557 [view addSubview:this]; | 2557 [view addSubview:this]; |
2558 | 2558 |
2559 /* Free the old data */ | 2559 /* Free the old data */ |
2560 if(thisbox->count) | 2560 if(thisbox->count) |
2561 free(thisitem); | 2561 free(thisitem); |
2562 DW_MUTEX_UNLOCK; | 2562 DW_MUTEX_UNLOCK; |
2563 } | 2563 } |
3037 void API dw_listbox_append(HWND handle, char *text) | 3037 void API dw_listbox_append(HWND handle, char *text) |
3038 { | 3038 { |
3039 int _locked_by_me = FALSE; | 3039 int _locked_by_me = FALSE; |
3040 DW_MUTEX_LOCK; | 3040 DW_MUTEX_LOCK; |
3041 id object = handle; | 3041 id object = handle; |
3042 | 3042 |
3043 if([object isMemberOfClass:[DWComboBox class]]) | 3043 if([object isMemberOfClass:[DWComboBox class]]) |
3044 { | 3044 { |
3045 DWComboBox *combo = handle; | 3045 DWComboBox *combo = handle; |
3046 | 3046 |
3047 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text ]]; | 3047 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text ]]; |
3048 } | 3048 } |
3049 else if([object isMemberOfClass:[DWContainer class]]) | 3049 else if([object isMemberOfClass:[DWContainer class]]) |
3050 { | 3050 { |
3051 DWContainer *cont = handle; | 3051 DWContainer *cont = handle; |
3071 void API dw_listbox_insert(HWND handle, char *text, int pos) | 3071 void API dw_listbox_insert(HWND handle, char *text, int pos) |
3072 { | 3072 { |
3073 int _locked_by_me = FALSE; | 3073 int _locked_by_me = FALSE; |
3074 DW_MUTEX_LOCK; | 3074 DW_MUTEX_LOCK; |
3075 id object = handle; | 3075 id object = handle; |
3076 | 3076 |
3077 if([object isMemberOfClass:[DWComboBox class]]) | 3077 if([object isMemberOfClass:[DWComboBox class]]) |
3078 { | 3078 { |
3079 DWComboBox *combo = handle; | 3079 DWComboBox *combo = handle; |
3080 | 3080 |
3081 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:text ] atIndex:pos]; | 3081 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:text ] atIndex:pos]; |
3082 } | 3082 } |
3083 else if([object isMemberOfClass:[DWContainer class]]) | 3083 else if([object isMemberOfClass:[DWContainer class]]) |
3084 { | 3084 { |
3085 DWContainer *cont = handle; | 3085 DWContainer *cont = handle; |
3102 void API dw_listbox_list_append(HWND handle, char **text, int count) | 3102 void API dw_listbox_list_append(HWND handle, char **text, int count) |
3103 { | 3103 { |
3104 int _locked_by_me = FALSE; | 3104 int _locked_by_me = FALSE; |
3105 DW_MUTEX_LOCK; | 3105 DW_MUTEX_LOCK; |
3106 id object = handle; | 3106 id object = handle; |
3107 | 3107 |
3108 if([object isMemberOfClass:[DWComboBox class]]) | 3108 if([object isMemberOfClass:[DWComboBox class]]) |
3109 { | 3109 { |
3110 DWComboBox *combo = handle; | 3110 DWComboBox *combo = handle; |
3111 int z; | 3111 int z; |
3112 | 3112 |
3113 for(z=0;z<count;z++) | 3113 for(z=0;z<count;z++) |
3114 { | 3114 { |
3115 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text[z] ]]; | 3115 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text[z] ]]; |
3116 } | 3116 } |
3117 } | 3117 } |
3118 else if([object isMemberOfClass:[DWContainer class]]) | 3118 else if([object isMemberOfClass:[DWContainer class]]) |
3119 { | 3119 { |
3120 DWContainer *cont = handle; | 3120 DWContainer *cont = handle; |
3121 int z; | 3121 int z; |
3122 | 3122 |
3123 for(z=0;z<count;z++) | 3123 for(z=0;z<count;z++) |
3124 { | 3124 { |
3125 NSString *nstr = [ NSString stringWithUTF8String:text[z] ]; | 3125 NSString *nstr = [ NSString stringWithUTF8String:text[z] ]; |
3126 NSArray *newrow = [[NSArray alloc] arrayWithObject:nstr]; | 3126 NSArray *newrow = [[NSArray alloc] arrayWithObject:nstr]; |
3127 | 3127 |
3128 [cont addRow:newrow]; | 3128 [cont addRow:newrow]; |
3129 } | 3129 } |
3140 void API dw_listbox_clear(HWND handle) | 3140 void API dw_listbox_clear(HWND handle) |
3141 { | 3141 { |
3142 int _locked_by_me = FALSE; | 3142 int _locked_by_me = FALSE; |
3143 DW_MUTEX_LOCK; | 3143 DW_MUTEX_LOCK; |
3144 id object = handle; | 3144 id object = handle; |
3145 | 3145 |
3146 if([object isMemberOfClass:[DWComboBox class]]) | 3146 if([object isMemberOfClass:[DWComboBox class]]) |
3147 { | 3147 { |
3148 DWComboBox *combo = handle; | 3148 DWComboBox *combo = handle; |
3149 | 3149 |
3150 [combo removeAllItems]; | 3150 [combo removeAllItems]; |
3151 } | 3151 } |
3152 else if([object isMemberOfClass:[DWContainer class]]) | 3152 else if([object isMemberOfClass:[DWContainer class]]) |
3153 { | 3153 { |
3154 DWContainer *cont = handle; | 3154 DWContainer *cont = handle; |
3165 * handle: Handle to the listbox to be cleared. | 3165 * handle: Handle to the listbox to be cleared. |
3166 */ | 3166 */ |
3167 int API dw_listbox_count(HWND handle) | 3167 int API dw_listbox_count(HWND handle) |
3168 { | 3168 { |
3169 id object = handle; | 3169 id object = handle; |
3170 | 3170 |
3171 if([object isMemberOfClass:[DWComboBox class]]) | 3171 if([object isMemberOfClass:[DWComboBox class]]) |
3172 { | 3172 { |
3173 DWComboBox *combo = handle; | 3173 DWComboBox *combo = handle; |
3174 | 3174 |
3175 return (int)[combo numberOfItems]; | 3175 return (int)[combo numberOfItems]; |
3176 } | 3176 } |
3177 else if([object isMemberOfClass:[DWContainer class]]) | 3177 else if([object isMemberOfClass:[DWContainer class]]) |
3178 { | 3178 { |
3179 int _locked_by_me = FALSE; | 3179 int _locked_by_me = FALSE; |
3195 void API dw_listbox_set_top(HWND handle, int top) | 3195 void API dw_listbox_set_top(HWND handle, int top) |
3196 { | 3196 { |
3197 int _locked_by_me = FALSE; | 3197 int _locked_by_me = FALSE; |
3198 DW_MUTEX_LOCK; | 3198 DW_MUTEX_LOCK; |
3199 id object = handle; | 3199 id object = handle; |
3200 | 3200 |
3201 if([object isMemberOfClass:[DWComboBox class]]) | 3201 if([object isMemberOfClass:[DWComboBox class]]) |
3202 { | 3202 { |
3203 DWComboBox *combo = handle; | 3203 DWComboBox *combo = handle; |
3204 | 3204 |
3205 [combo scrollItemAtIndexToTop:top]; | 3205 [combo scrollItemAtIndexToTop:top]; |
3206 } | 3206 } |
3207 else if([object isMemberOfClass:[DWContainer class]]) | 3207 else if([object isMemberOfClass:[DWContainer class]]) |
3208 { | 3208 { |
3209 DWContainer *cont = handle; | 3209 DWContainer *cont = handle; |
3224 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) | 3224 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) |
3225 { | 3225 { |
3226 int _locked_by_me = FALSE; | 3226 int _locked_by_me = FALSE; |
3227 DW_MUTEX_LOCK; | 3227 DW_MUTEX_LOCK; |
3228 id object = handle; | 3228 id object = handle; |
3229 | 3229 |
3230 if([object isMemberOfClass:[DWComboBox class]]) | 3230 if([object isMemberOfClass:[DWComboBox class]]) |
3231 { | 3231 { |
3232 DWComboBox *combo = handle; | 3232 DWComboBox *combo = handle; |
3233 int count = (int)[combo numberOfItems]; | 3233 int count = (int)[combo numberOfItems]; |
3234 | 3234 |
3271 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer) | 3271 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer) |
3272 { | 3272 { |
3273 int _locked_by_me = FALSE; | 3273 int _locked_by_me = FALSE; |
3274 DW_MUTEX_LOCK; | 3274 DW_MUTEX_LOCK; |
3275 id object = handle; | 3275 id object = handle; |
3276 | 3276 |
3277 if([object isMemberOfClass:[DWComboBox class]]) | 3277 if([object isMemberOfClass:[DWComboBox class]]) |
3278 { | 3278 { |
3279 DWComboBox *combo = handle; | 3279 DWComboBox *combo = handle; |
3280 int count = (int)[combo numberOfItems]; | 3280 int count = (int)[combo numberOfItems]; |
3281 | 3281 |
3282 if(index <= count) | 3282 if(index <= count) |
3283 { | 3283 { |
3284 [combo removeItemAtIndex:index]; | 3284 [combo removeItemAtIndex:index]; |
3285 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:buffer ] atIndex:index]; | 3285 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:buffer ] atIndex:index]; |
3286 } | 3286 } |
3307 * handle: Handle to the listbox to be queried. | 3307 * handle: Handle to the listbox to be queried. |
3308 */ | 3308 */ |
3309 unsigned int API dw_listbox_selected(HWND handle) | 3309 unsigned int API dw_listbox_selected(HWND handle) |
3310 { | 3310 { |
3311 id object = handle; | 3311 id object = handle; |
3312 | 3312 |
3313 if([object isMemberOfClass:[DWComboBox class]]) | 3313 if([object isMemberOfClass:[DWComboBox class]]) |
3314 { | 3314 { |
3315 DWComboBox *combo = handle; | 3315 DWComboBox *combo = handle; |
3316 return (int)[combo indexOfSelectedItem]; | 3316 return (int)[combo indexOfSelectedItem]; |
3317 } | 3317 } |
3365 void API dw_listbox_select(HWND handle, int index, int state) | 3365 void API dw_listbox_select(HWND handle, int index, int state) |
3366 { | 3366 { |
3367 int _locked_by_me = FALSE; | 3367 int _locked_by_me = FALSE; |
3368 DW_MUTEX_LOCK; | 3368 DW_MUTEX_LOCK; |
3369 id object = handle; | 3369 id object = handle; |
3370 | 3370 |
3371 if([object isMemberOfClass:[DWComboBox class]]) | 3371 if([object isMemberOfClass:[DWComboBox class]]) |
3372 { | 3372 { |
3373 DWComboBox *combo = handle; | 3373 DWComboBox *combo = handle; |
3374 if(state) | 3374 if(state) |
3375 [combo selectItemAtIndex:index]; | 3375 [combo selectItemAtIndex:index]; |
3396 void API dw_listbox_delete(HWND handle, int index) | 3396 void API dw_listbox_delete(HWND handle, int index) |
3397 { | 3397 { |
3398 int _locked_by_me = FALSE; | 3398 int _locked_by_me = FALSE; |
3399 DW_MUTEX_LOCK; | 3399 DW_MUTEX_LOCK; |
3400 id object = handle; | 3400 id object = handle; |
3401 | 3401 |
3402 if([object isMemberOfClass:[DWComboBox class]]) | 3402 if([object isMemberOfClass:[DWComboBox class]]) |
3403 { | 3403 { |
3404 DWComboBox *combo = handle; | 3404 DWComboBox *combo = handle; |
3405 | 3405 |
3406 [combo removeItemAtIndex:index]; | 3406 [combo removeItemAtIndex:index]; |
3407 } | 3407 } |
3408 else if([object isMemberOfClass:[DWContainer class]]) | 3408 else if([object isMemberOfClass:[DWContainer class]]) |
3409 { | 3409 { |
3410 DWContainer *cont = handle; | 3410 DWContainer *cont = handle; |
3446 [scrollview setDocumentView:mle]; | 3446 [scrollview setDocumentView:mle]; |
3447 [mle setAutoresizingMask:NSViewWidthSizable]; | 3447 [mle setAutoresizingMask:NSViewWidthSizable]; |
3448 /* [mle setTag:cid]; Why doesn't this work? */ | 3448 /* [mle setTag:cid]; Why doesn't this work? */ |
3449 [mle release]; | 3449 [mle release]; |
3450 return scrollview; | 3450 return scrollview; |
3451 } | 3451 } |
3452 | 3452 |
3453 /* | 3453 /* |
3454 * Adds text to an MLE box and returns the current point. | 3454 * Adds text to an MLE box and returns the current point. |
3455 * Parameters: | 3455 * Parameters: |
3456 * handle: Handle to the MLE to be queried. | 3456 * handle: Handle to the MLE to be queried. |
3721 * Returns: | 3721 * Returns: |
3722 * The selected color or the current color if cancelled. | 3722 * The selected color or the current color if cancelled. |
3723 */ | 3723 */ |
3724 unsigned long API dw_color_choose(unsigned long value) | 3724 unsigned long API dw_color_choose(unsigned long value) |
3725 { | 3725 { |
3726 NSColor *color = [[NSColor colorWithDeviceRed: DW_RED_VALUE(value)/255.0 green: DW_GREEN_VALUE(value)/255.0 blue: DW_BLUE_VALUE(value)/255.0 alpha: 1] retain]; | 3726 NSColor *color = [[NSColor colorWithDeviceRed: DW_RED_VALUE(value)/255.0 green: DW_GREEN_VALUE(value)/255.0 blue: DW_BLUE_VALUE(value)/255.0 alpha: 1] retain]; |
3727 /* Create the Color Chooser Dialog class. */ | 3727 /* Create the Color Chooser Dialog class. */ |
3728 static DWColorChoose *colorDlg = nil; | 3728 static DWColorChoose *colorDlg = nil; |
3729 DWDialog *dialog; | 3729 DWDialog *dialog; |
3730 | 3730 |
3731 if(colorDlg) | 3731 if(colorDlg) |
3732 { | 3732 { |
3733 dialog = [colorDlg dialog]; | 3733 dialog = [colorDlg dialog]; |
3734 /* If someone is already waiting just return */ | 3734 /* If someone is already waiting just return */ |
3735 if(dialog) | 3735 if(dialog) |
3739 } | 3739 } |
3740 else | 3740 else |
3741 { | 3741 { |
3742 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel]; | 3742 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel]; |
3743 /* Set defaults for the dialog. */ | 3743 /* Set defaults for the dialog. */ |
3744 [colorDlg setContinuous:NO]; | 3744 [colorDlg setContinuous:NO]; |
3745 [colorDlg setTarget:colorDlg]; | 3745 [colorDlg setTarget:colorDlg]; |
3746 [colorDlg setAction:@selector(changeColor:)]; | 3746 [colorDlg setAction:@selector(changeColor:)]; |
3747 } | 3747 } |
3748 | 3748 |
3749 dialog = dw_dialog_new(colorDlg); | 3749 dialog = dw_dialog_new(colorDlg); |
3750 [colorDlg setColor:color]; | 3750 [colorDlg setColor:color]; |
3751 [colorDlg setDialog:dialog]; | 3751 [colorDlg setDialog:dialog]; |
3752 [colorDlg makeKeyAndOrderFront:nil]; | 3752 [colorDlg makeKeyAndOrderFront:nil]; |
3753 | 3753 |
3754 /* Wait for them to pick a color */ | 3754 /* Wait for them to pick a color */ |
3755 color = (NSColor *)dw_dialog_wait(dialog); | 3755 color = (NSColor *)dw_dialog_wait(dialog); |
3756 | 3756 |
3757 /* Figure out the value of what they returned */ | 3757 /* Figure out the value of what they returned */ |
3758 CGFloat red, green, blue; | 3758 CGFloat red, green, blue; |
3759 [color getRed:&red green:&green blue:&blue alpha:NULL]; | 3759 [color getRed:&red green:&green blue:&blue alpha:NULL]; |
3760 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); | 3760 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); |
3761 return value; | 3761 return value; |
3789 } | 3789 } |
3790 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 3790 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
3791 [aPath setLineWidth: 0.5]; | 3791 [aPath setLineWidth: 0.5]; |
3792 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]; | 3792 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]; |
3793 [color set]; | 3793 [color set]; |
3794 | 3794 |
3795 [aPath moveToPoint:NSMakePoint(x, y)]; | 3795 [aPath moveToPoint:NSMakePoint(x, y)]; |
3796 [aPath stroke]; | 3796 [aPath stroke]; |
3797 [image unlockFocus]; | 3797 [image unlockFocus]; |
3798 DW_MUTEX_UNLOCK; | 3798 DW_MUTEX_UNLOCK; |
3799 } | 3799 } |
3800 | 3800 |
3828 } | 3828 } |
3829 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 3829 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
3830 [aPath setLineWidth: 0.5]; | 3830 [aPath setLineWidth: 0.5]; |
3831 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]; | 3831 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]; |
3832 [color set]; | 3832 [color set]; |
3833 | 3833 |
3834 [aPath moveToPoint:NSMakePoint(x1, y1)]; | 3834 [aPath moveToPoint:NSMakePoint(x1, y1)]; |
3835 [aPath lineToPoint:NSMakePoint(x2, y2)]; | 3835 [aPath lineToPoint:NSMakePoint(x2, y2)]; |
3836 [aPath stroke]; | 3836 [aPath stroke]; |
3837 | 3837 |
3838 [image unlockFocus]; | 3838 [image unlockFocus]; |
3839 DW_MUTEX_UNLOCK; | 3839 DW_MUTEX_UNLOCK; |
3840 } | 3840 } |
3841 | 3841 |
3842 /* Draw text on a window (preferably a render window). | 3842 /* Draw text on a window (preferably a render window). |
3917 } | 3917 } |
3918 NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; | 3918 NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; |
3919 if([object isMemberOfClass:[DWRender class]]) | 3919 if([object isMemberOfClass:[DWRender class]]) |
3920 { | 3920 { |
3921 NSFont *font = [object font]; | 3921 NSFont *font = [object font]; |
3922 | 3922 |
3923 if(font) | 3923 if(font) |
3924 { | 3924 { |
3925 [dict setValue:font forKey:NSFontAttributeName]; | 3925 [dict setValue:font forKey:NSFontAttributeName]; |
3926 } | 3926 } |
3927 } | 3927 } |
3969 } | 3969 } |
3970 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 3970 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
3971 [aPath setLineWidth: 0.5]; | 3971 [aPath setLineWidth: 0.5]; |
3972 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]; | 3972 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]; |
3973 [color set]; | 3973 [color set]; |
3974 | 3974 |
3975 [aPath moveToPoint:NSMakePoint(*x, *y)]; | 3975 [aPath moveToPoint:NSMakePoint(*x, *y)]; |
3976 for(z=1;z<npoints;z++) | 3976 for(z=1;z<npoints;z++) |
3977 { | 3977 { |
3978 [aPath lineToPoint:NSMakePoint(x[z], y[z])]; | 3978 [aPath lineToPoint:NSMakePoint(x[z], y[z])]; |
3979 } | 3979 } |
4018 } | 4018 } |
4019 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 4019 NSBezierPath* aPath = [NSBezierPath bezierPath]; |
4020 [aPath setLineWidth: 0.5]; | 4020 [aPath setLineWidth: 0.5]; |
4021 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]; | 4021 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]; |
4022 [color set]; | 4022 [color set]; |
4023 | 4023 |
4024 [aPath moveToPoint:NSMakePoint(x, y)]; | 4024 [aPath moveToPoint:NSMakePoint(x, y)]; |
4025 [aPath lineToPoint:NSMakePoint(x, y + height)]; | 4025 [aPath lineToPoint:NSMakePoint(x, y + height)]; |
4026 [aPath lineToPoint:NSMakePoint(x + width, y + height)]; | 4026 [aPath lineToPoint:NSMakePoint(x + width, y + height)]; |
4027 [aPath lineToPoint:NSMakePoint(x + width, y)]; | 4027 [aPath lineToPoint:NSMakePoint(x + width, y)]; |
4028 [aPath closePath]; | 4028 [aPath closePath]; |
4029 [aPath fill]; | 4029 [aPath fill]; |
4303 { | 4303 { |
4304 int _locked_by_me = FALSE; | 4304 int _locked_by_me = FALSE; |
4305 DW_MUTEX_LOCK; | 4305 DW_MUTEX_LOCK; |
4306 int z; | 4306 int z; |
4307 DWContainer *cont = handle; | 4307 DWContainer *cont = handle; |
4308 | 4308 |
4309 [cont setup]; | 4309 [cont setup]; |
4310 | 4310 |
4311 for(z=0;z<count;z++) | 4311 for(z=0;z<count;z++) |
4312 { | 4312 { |
4313 NSTableColumn *column = [[NSTableColumn alloc] init]; | 4313 NSTableColumn *column = [[NSTableColumn alloc] init]; |
4314 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]]; | 4314 [[column headerCell] setStringValue:[ NSString stringWithUTF8String:titles[z] ]]; |
4315 if(flags[z] & DW_CFA_BITMAPORICON) | 4315 if(flags[z] & DW_CFA_BITMAPORICON) |
4324 [imagecell release]; | 4324 [imagecell release]; |
4325 } | 4325 } |
4326 [cont addTableColumn:column]; | 4326 [cont addTableColumn:column]; |
4327 [cont addColumn:column andType:(int)flags[z]]; | 4327 [cont addColumn:column andType:(int)flags[z]]; |
4328 [column release]; | 4328 [column release]; |
4329 } | 4329 } |
4330 DW_MUTEX_UNLOCK; | 4330 DW_MUTEX_UNLOCK; |
4331 return TRUE; | 4331 return TRUE; |
4332 } | 4332 } |
4333 | 4333 |
4334 /* | 4334 /* |
4341 */ | 4341 */ |
4342 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) | 4342 int API dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) |
4343 { | 4343 { |
4344 char **newtitles = malloc(sizeof(char *) * (count + 2)); | 4344 char **newtitles = malloc(sizeof(char *) * (count + 2)); |
4345 unsigned long *newflags = malloc(sizeof(unsigned long) * (count + 2)); | 4345 unsigned long *newflags = malloc(sizeof(unsigned long) * (count + 2)); |
4346 | 4346 |
4347 newtitles[0] = "Icon"; | 4347 newtitles[0] = "Icon"; |
4348 newtitles[1] = "Filename"; | 4348 newtitles[1] = "Filename"; |
4349 | 4349 |
4350 newflags[0] = DW_CFA_BITMAPORICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; | 4350 newflags[0] = DW_CFA_BITMAPORICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; |
4351 newflags[1] = DW_CFA_STRING | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; | 4351 newflags[1] = DW_CFA_STRING | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; |
4352 | 4352 |
4353 memcpy(&newtitles[2], titles, sizeof(char *) * count); | 4353 memcpy(&newtitles[2], titles, sizeof(char *) * count); |
4354 memcpy(&newflags[2], flags, sizeof(unsigned long) * count); | 4354 memcpy(&newflags[2], flags, sizeof(unsigned long) * count); |
4355 | 4355 |
4356 dw_container_setup(handle, newflags, newtitles, count + 2, 0); | 4356 dw_container_setup(handle, newflags, newtitles, count + 2, 0); |
4357 | 4357 |
4358 free(newtitles); | 4358 free(newtitles); |
4359 free(newflags); | 4359 free(newflags); |
4360 return TRUE; | 4360 return TRUE; |
4361 } | 4361 } |
4362 | 4362 |
4409 object = [ NSString stringWithUTF8String:str ]; | 4409 object = [ NSString stringWithUTF8String:str ]; |
4410 } | 4410 } |
4411 else | 4411 else |
4412 { | 4412 { |
4413 char textbuffer[100]; | 4413 char textbuffer[100]; |
4414 | 4414 |
4415 if(type & DW_CFA_ULONG) | 4415 if(type & DW_CFA_ULONG) |
4416 { | 4416 { |
4417 ULONG tmp = *((ULONG *)data); | 4417 ULONG tmp = *((ULONG *)data); |
4418 | 4418 |
4419 sprintf(textbuffer, "%lu", tmp); | 4419 sprintf(textbuffer, "%lu", tmp); |
4420 } | 4420 } |
4421 else if(type & DW_CFA_DATE) | 4421 else if(type & DW_CFA_DATE) |
4422 { | 4422 { |
4423 struct tm curtm; | 4423 struct tm curtm; |
4424 CDATE cdate = *((CDATE *)data); | 4424 CDATE cdate = *((CDATE *)data); |
4425 | 4425 |
4426 memset( &curtm, 0, sizeof(curtm) ); | 4426 memset( &curtm, 0, sizeof(curtm) ); |
4427 curtm.tm_mday = cdate.day; | 4427 curtm.tm_mday = cdate.day; |
4428 curtm.tm_mon = cdate.month - 1; | 4428 curtm.tm_mon = cdate.month - 1; |
4429 curtm.tm_year = cdate.year - 1900; | 4429 curtm.tm_year = cdate.year - 1900; |
4430 | 4430 |
4431 strftime(textbuffer, 100, "%x", &curtm); | 4431 strftime(textbuffer, 100, "%x", &curtm); |
4432 } | 4432 } |
4433 else if(type & DW_CFA_TIME) | 4433 else if(type & DW_CFA_TIME) |
4434 { | 4434 { |
4435 struct tm curtm; | 4435 struct tm curtm; |
4436 CTIME ctime = *((CTIME *)data); | 4436 CTIME ctime = *((CTIME *)data); |
4437 | 4437 |
4438 memset( &curtm, 0, sizeof(curtm) ); | 4438 memset( &curtm, 0, sizeof(curtm) ); |
4439 curtm.tm_hour = ctime.hours; | 4439 curtm.tm_hour = ctime.hours; |
4440 curtm.tm_min = ctime.minutes; | 4440 curtm.tm_min = ctime.minutes; |
4441 curtm.tm_sec = ctime.seconds; | 4441 curtm.tm_sec = ctime.seconds; |
4442 | 4442 |
4443 strftime(textbuffer, 100, "%X", &curtm); | 4443 strftime(textbuffer, 100, "%X", &curtm); |
4444 } | 4444 } |
4445 else | 4445 else |
4446 { | 4446 { |
4447 DW_MUTEX_UNLOCK; | 4447 DW_MUTEX_UNLOCK; |
4448 return; | 4448 return; |
4449 } | 4449 } |
4450 object = [ NSString stringWithUTF8String:textbuffer ]; | 4450 object = [ NSString stringWithUTF8String:textbuffer ]; |
4451 } | 4451 } |
4452 | 4452 |
4453 [cont editCell:object at:(row+lastadd) and:column]; | 4453 [cont editCell:object at:(row+lastadd) and:column]; |
4454 DW_MUTEX_UNLOCK; | 4454 DW_MUTEX_UNLOCK; |
4455 } | 4455 } |
4456 | 4456 |
4457 /* | 4457 /* |
4856 * DW pick the appropriate file extension. | 4856 * DW pick the appropriate file extension. |
4857 * (ICO on OS/2 or Windows, XPM on Unix) | 4857 * (ICO on OS/2 or Windows, XPM on Unix) |
4858 */ | 4858 */ |
4859 HICN API dw_icon_load_from_data(char *data, int len) | 4859 HICN API dw_icon_load_from_data(char *data, int len) |
4860 { | 4860 { |
4861 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; | 4861 NSData *thisdata = [NSData dataWithBytes:data length:len]; |
4862 NSImage *image = [[NSImage alloc] initWithData:thisdata]; | 4862 NSImage *image = [[NSImage alloc] initWithData:thisdata]; |
4863 return image; | 4863 return image; |
4864 } | 4864 } |
4865 | 4865 |
4866 /* | 4866 /* |
5022 */ | 5022 */ |
5023 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) | 5023 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) |
5024 { | 5024 { |
5025 NSSize size = { (float)width, (float)height }; | 5025 NSSize size = { (float)width, (float)height }; |
5026 HPIXMAP pixmap; | 5026 HPIXMAP pixmap; |
5027 | 5027 |
5028 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 5028 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
5029 return NULL; | 5029 return NULL; |
5030 pixmap->width = width; | 5030 pixmap->width = width; |
5031 pixmap->height = height; | 5031 pixmap->height = height; |
5032 pixmap->handle = handle; | 5032 pixmap->handle = handle; |
5046 * A handle to a pixmap or NULL on failure. | 5046 * A handle to a pixmap or NULL on failure. |
5047 */ | 5047 */ |
5048 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) | 5048 HPIXMAP API dw_pixmap_new_from_file(HWND handle, char *filename) |
5049 { | 5049 { |
5050 HPIXMAP pixmap; | 5050 HPIXMAP pixmap; |
5051 | 5051 |
5052 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 5052 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
5053 return NULL; | 5053 return NULL; |
5054 NSString *nstr = [ NSString stringWithUTF8String:filename ]; | 5054 NSString *nstr = [ NSString stringWithUTF8String:filename ]; |
5055 NSImage *image = [[NSImage alloc] initWithContentsOfFile:nstr]; | 5055 NSImage *image = [[NSImage alloc] initWithContentsOfFile:nstr]; |
5056 if(!image) | 5056 if(!image) |
5078 * A handle to a pixmap or NULL on failure. | 5078 * A handle to a pixmap or NULL on failure. |
5079 */ | 5079 */ |
5080 HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len) | 5080 HPIXMAP API dw_pixmap_new_from_data(HWND handle, char *data, int len) |
5081 { | 5081 { |
5082 HPIXMAP pixmap; | 5082 HPIXMAP pixmap; |
5083 | 5083 |
5084 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 5084 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
5085 return NULL; | 5085 return NULL; |
5086 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; | 5086 NSData *thisdata = [NSData dataWithBytes:data length:len]; |
5087 NSImage *image = [[NSImage alloc] initWithData:thisdata]; | 5087 NSImage *image = [[NSImage alloc] initWithData:thisdata]; |
5088 NSSize size = [image size]; | 5088 NSSize size = [image size]; |
5089 pixmap->width = size.width; | 5089 pixmap->width = size.width; |
5090 pixmap->height = size.height; | 5090 pixmap->height = size.height; |
5091 pixmap->image = image; | 5091 pixmap->image = image; |
5111 * A handle to a pixmap or NULL on failure. | 5111 * A handle to a pixmap or NULL on failure. |
5112 */ | 5112 */ |
5113 HPIXMAP API dw_pixmap_grab(HWND handle, ULONG resid) | 5113 HPIXMAP API dw_pixmap_grab(HWND handle, ULONG resid) |
5114 { | 5114 { |
5115 HPIXMAP pixmap; | 5115 HPIXMAP pixmap; |
5116 | 5116 |
5117 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 5117 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
5118 return NULL; | 5118 return NULL; |
5119 | 5119 |
5120 NSBundle *bundle = [NSBundle mainBundle]; | 5120 NSBundle *bundle = [NSBundle mainBundle]; |
5121 NSString *respath = [bundle resourcePath]; | 5121 NSString *respath = [bundle resourcePath]; |
5210 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) | 5210 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) |
5211 { | 5211 { |
5212 DWCalendar *calendar = handle; | 5212 DWCalendar *calendar = handle; |
5213 NSDate *date; | 5213 NSDate *date; |
5214 char buffer[100]; | 5214 char buffer[100]; |
5215 | 5215 |
5216 sprintf(buffer, "%04d-%02d-%02d 00:00:00 +0600", year, month, day); | 5216 sprintf(buffer, "%04d-%02d-%02d 00:00:00 +0600", year, month, day); |
5217 | 5217 |
5218 date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]]; | 5218 date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]]; |
5219 [calendar setDateValue:date]; | 5219 [calendar setDateValue:date]; |
5220 [date release]; | 5220 [date release]; |
5221 } | 5221 } |
5222 | 5222 |
5233 [df setDateStyle:NSDateFormatterShortStyle]; | 5233 [df setDateStyle:NSDateFormatterShortStyle]; |
5234 NSString *nstr = [df stringFromDate:date]; | 5234 NSString *nstr = [df stringFromDate:date]; |
5235 sscanf([ nstr UTF8String ], "%d/%d/%d", month, day, year); | 5235 sscanf([ nstr UTF8String ], "%d/%d/%d", month, day, year); |
5236 if(*year < 70) | 5236 if(*year < 70) |
5237 { | 5237 { |
5238 *year += 2000; | 5238 *year += 2000; |
5239 } | 5239 } |
5240 else if(*year < 100) | 5240 else if(*year < 100) |
5241 { | 5241 { |
5242 *year += 1900; | 5242 *year += 1900; |
5243 } | 5243 } |
5244 [df release]; | 5244 [df release]; |
5245 } | 5245 } |
5246 | 5246 |
5423 | 5423 |
5424 char _removetilde(char *dest, char *src) | 5424 char _removetilde(char *dest, char *src) |
5425 { | 5425 { |
5426 int z, cur=0; | 5426 int z, cur=0; |
5427 char accel = '\0'; | 5427 char accel = '\0'; |
5428 | 5428 |
5429 for(z=0;z<strlen(src);z++) | 5429 for(z=0;z<strlen(src);z++) |
5430 { | 5430 { |
5431 if(src[z] != '~') | 5431 if(src[z] != '~') |
5432 { | 5432 { |
5433 dest[cur] = src[z]; | 5433 dest[cur] = src[z]; |
5466 else | 5466 else |
5467 { | 5467 { |
5468 char accel[2]; | 5468 char accel[2]; |
5469 char *newtitle = malloc(strlen(title)+1); | 5469 char *newtitle = malloc(strlen(title)+1); |
5470 NSString *nstr; | 5470 NSString *nstr; |
5471 | 5471 |
5472 accel[0] = _removetilde(newtitle, title); | 5472 accel[0] = _removetilde(newtitle, title); |
5473 accel[1] = 0; | 5473 accel[1] = 0; |
5474 | 5474 |
5475 nstr = [ NSString stringWithUTF8String:newtitle ]; | 5475 nstr = [ NSString stringWithUTF8String:newtitle ]; |
5476 free(newtitle); | 5476 free(newtitle); |
5477 | 5477 |
5478 item = [menu addItemWithTitle: nstr | 5478 item = [menu addItemWithTitle: nstr |
5479 action:@selector(menuHandler:) | 5479 action:@selector(menuHandler:) |
5484 [item setState:NSOnState]; | 5484 [item setState:NSOnState]; |
5485 } | 5485 } |
5486 if(flags & DW_MIS_DISABLED) | 5486 if(flags & DW_MIS_DISABLED) |
5487 { | 5487 { |
5488 [item setEnabled:NO]; | 5488 [item setEnabled:NO]; |
5489 } | 5489 } |
5490 | 5490 |
5491 if(submenux) | 5491 if(submenux) |
5492 { | 5492 { |
5493 [submenu setTitle:nstr]; | 5493 [submenu setTitle:nstr]; |
5494 [menu setSubmenu:submenu forItem:item]; | 5494 [menu setSubmenu:submenu forItem:item]; |
5495 } | 5495 } |
5508 */ | 5508 */ |
5509 void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check) | 5509 void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check) |
5510 { | 5510 { |
5511 id menu = menux; | 5511 id menu = menux; |
5512 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid]; | 5512 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid]; |
5513 | 5513 |
5514 if(menuitem != nil) | 5514 if(menuitem != nil) |
5515 { | 5515 { |
5516 if(check) | 5516 if(check) |
5517 { | 5517 { |
5518 [menuitem setState:NSOnState]; | 5518 [menuitem setState:NSOnState]; |
5519 } | 5519 } |
5520 else | 5520 else |
5521 { | 5521 { |
5522 [menuitem setState:NSOffState]; | 5522 [menuitem setState:NSOffState]; |
5523 } | 5523 } |
5524 } | 5524 } |
5525 } | 5525 } |
5526 | 5526 |
5534 */ | 5534 */ |
5535 void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state) | 5535 void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state) |
5536 { | 5536 { |
5537 id menu = menux; | 5537 id menu = menux; |
5538 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid]; | 5538 NSMenuItem *menuitem = (NSMenuItem *)[menu itemWithTag:itemid]; |
5539 | 5539 |
5540 if(menuitem != nil) | 5540 if(menuitem != nil) |
5541 { | 5541 { |
5542 if(state & DW_MIS_CHECKED) | 5542 if(state & DW_MIS_CHECKED) |
5543 { | 5543 { |
5544 [menuitem setState:NSOnState]; | 5544 [menuitem setState:NSOnState]; |
5545 } | 5545 } |
5546 else if(state & DW_MIS_UNCHECKED) | 5546 else if(state & DW_MIS_UNCHECKED) |
5547 { | 5547 { |
5548 [menuitem setState:NSOffState]; | 5548 [menuitem setState:NSOffState]; |
5549 } | 5549 } |
5550 if(state & DW_MIS_ENABLED) | 5550 if(state & DW_MIS_ENABLED) |
5551 { | 5551 { |
5552 [menuitem setEnabled:YES]; | 5552 [menuitem setEnabled:YES]; |
5620 */ | 5620 */ |
5621 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid) | 5621 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid) |
5622 { | 5622 { |
5623 DWNotebook *notebook = handle; | 5623 DWNotebook *notebook = handle; |
5624 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 5624 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
5625 | 5625 |
5626 if(notepage != nil) | 5626 if(notepage != nil) |
5627 { | 5627 { |
5628 [notebook removeTabViewItem:notepage]; | 5628 [notebook removeTabViewItem:notepage]; |
5629 [notepage release]; | 5629 [notepage release]; |
5630 } | 5630 } |
5650 */ | 5650 */ |
5651 void API dw_notebook_page_set(HWND handle, unsigned int pageid) | 5651 void API dw_notebook_page_set(HWND handle, unsigned int pageid) |
5652 { | 5652 { |
5653 DWNotebook *notebook = handle; | 5653 DWNotebook *notebook = handle; |
5654 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 5654 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
5655 | 5655 |
5656 if(notepage != nil) | 5656 if(notepage != nil) |
5657 { | 5657 { |
5658 [notebook selectTabViewItem:notepage]; | 5658 [notebook selectTabViewItem:notepage]; |
5659 } | 5659 } |
5660 } | 5660 } |
5668 */ | 5668 */ |
5669 void API dw_notebook_page_set_text(HWND handle, ULONG pageid, char *text) | 5669 void API dw_notebook_page_set_text(HWND handle, ULONG pageid, char *text) |
5670 { | 5670 { |
5671 DWNotebook *notebook = handle; | 5671 DWNotebook *notebook = handle; |
5672 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 5672 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
5673 | 5673 |
5674 if(notepage != nil) | 5674 if(notepage != nil) |
5675 { | 5675 { |
5676 [notepage setLabel:[ NSString stringWithUTF8String:text ]]; | 5676 [notepage setLabel:[ NSString stringWithUTF8String:text ]]; |
5677 } | 5677 } |
5678 } | 5678 } |
5698 */ | 5698 */ |
5699 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page) | 5699 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page) |
5700 { | 5700 { |
5701 DWNotebook *notebook = handle; | 5701 DWNotebook *notebook = handle; |
5702 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 5702 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); |
5703 | 5703 |
5704 if(notepage != nil) | 5704 if(notepage != nil) |
5705 { | 5705 { |
5706 HWND tmpbox = dw_box_new(DW_VERT, 0); | 5706 HWND tmpbox = dw_box_new(DW_VERT, 0); |
5707 DWBox *box = tmpbox; | 5707 DWBox *box = tmpbox; |
5708 | 5708 |
5728 styleMask:(flStyle | NSTexturedBackgroundWindowMask) | 5728 styleMask:(flStyle | NSTexturedBackgroundWindowMask) |
5729 backing:NSBackingStoreBuffered | 5729 backing:NSBackingStoreBuffered |
5730 defer:false]; | 5730 defer:false]; |
5731 | 5731 |
5732 [window setTitle:[ NSString stringWithUTF8String:title ]]; | 5732 [window setTitle:[ NSString stringWithUTF8String:title ]]; |
5733 | 5733 |
5734 DWView *view = [[DWView alloc] init]; | 5734 DWView *view = [[DWView alloc] init]; |
5735 | 5735 |
5736 [window setContentView:view]; | 5736 [window setContentView:view]; |
5737 [window setDelegate:view]; | 5737 [window setDelegate:view]; |
5738 [view release]; | 5738 [view release]; |
5739 | 5739 |
5740 /* If it isn't a toplevel window... */ | 5740 /* If it isn't a toplevel window... */ |
5807 * handle: The window handle to make visible. | 5807 * handle: The window handle to make visible. |
5808 */ | 5808 */ |
5809 int API dw_window_show(HWND handle) | 5809 int API dw_window_show(HWND handle) |
5810 { | 5810 { |
5811 NSObject *object = handle; | 5811 NSObject *object = handle; |
5812 | 5812 |
5813 if([ object isKindOfClass:[ NSWindow class ] ]) | 5813 if([ object isKindOfClass:[ NSWindow class ] ]) |
5814 { | 5814 { |
5815 NSWindow *window = handle; | 5815 NSWindow *window = handle; |
5816 NSRect rect = [window frame]; | 5816 NSRect rect = [window frame]; |
5817 if([window isMiniaturized]) | 5817 if([window isMiniaturized]) |
5837 * handle: The window handle to make visible. | 5837 * handle: The window handle to make visible. |
5838 */ | 5838 */ |
5839 int API dw_window_hide(HWND handle) | 5839 int API dw_window_hide(HWND handle) |
5840 { | 5840 { |
5841 NSObject *object = handle; | 5841 NSObject *object = handle; |
5842 | 5842 |
5843 if([ object isKindOfClass:[ NSWindow class ] ]) | 5843 if([ object isKindOfClass:[ NSWindow class ] ]) |
5844 { | 5844 { |
5845 NSWindow *window = handle; | 5845 NSWindow *window = handle; |
5846 | 5846 |
5847 [window orderOut:nil]; | 5847 [window orderOut:nil]; |
5848 } | 5848 } |
5849 return 0; | 5849 return 0; |
5850 } | 5850 } |
5851 | 5851 |
5861 id object = handle; | 5861 id object = handle; |
5862 unsigned long _fore = _get_color(fore); | 5862 unsigned long _fore = _get_color(fore); |
5863 unsigned long _back = _get_color(back); | 5863 unsigned long _back = _get_color(back); |
5864 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]; | 5864 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]; |
5865 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]; | 5865 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]; |
5866 | 5866 |
5867 if([object isMemberOfClass:[NSTextFieldCell class]]) | 5867 if([object isMemberOfClass:[NSTextFieldCell class]]) |
5868 { | 5868 { |
5869 NSTextFieldCell *text = object; | 5869 NSTextFieldCell *text = object; |
5870 [text setTextColor:fg]; | 5870 [text setTextColor:fg]; |
5871 } | 5871 } |
5872 else if([object isMemberOfClass:[DWBox class]]) | 5872 else if([object isMemberOfClass:[DWBox class]]) |
5873 { | 5873 { |
5874 DWBox *box = object; | 5874 DWBox *box = object; |
5875 | 5875 |
5876 [box setColor:_back]; | 5876 [box setColor:_back]; |
5877 } | 5877 } |
5878 else if([object isMemberOfClass:[DWButton class]]) | 5878 else if([object isMemberOfClass:[DWButton class]]) |
5879 { | 5879 { |
5880 DWButton *button = object; | 5880 DWButton *button = object; |
5881 | 5881 |
5882 [[button cell] setBackgroundColor:bg]; | 5882 [[button cell] setBackgroundColor:bg]; |
5883 } | 5883 } |
5884 return 0; | 5884 return 0; |
5885 } | 5885 } |
5886 | 5886 |
5903 * height: New height in pixels. | 5903 * height: New height in pixels. |
5904 */ | 5904 */ |
5905 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) | 5905 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) |
5906 { | 5906 { |
5907 id object = handle; | 5907 id object = handle; |
5908 | 5908 |
5909 if(DWOSMinor > 5 && [object isMemberOfClass:[NSWindow class]]) | 5909 if(DWOSMinor > 5 && [object isMemberOfClass:[NSWindow class]]) |
5910 { | 5910 { |
5911 NSWindow *window = object; | 5911 NSWindow *window = object; |
5912 int currentstyle = (int)[window styleMask]; | 5912 int currentstyle = (int)[window styleMask]; |
5913 int tmp; | 5913 int tmp; |
5914 | 5914 |
5915 tmp = currentstyle | (int)mask; | 5915 tmp = currentstyle | (int)mask; |
5916 tmp ^= mask; | 5916 tmp ^= mask; |
5917 tmp |= style; | 5917 tmp |= style; |
5918 | 5918 |
5919 [window setStyleMask:tmp]; | 5919 [window setStyleMask:tmp]; |
5920 } | 5920 } |
5921 else if([object isKindOfClass:[NSTextField class]]) | 5921 else if([object isKindOfClass:[NSTextField class]]) |
5922 { | 5922 { |
5923 NSTextField *tf = object; | 5923 NSTextField *tf = object; |
5924 | 5924 |
5925 /* TODO: See if we need to switch to a bitmask */ | 5925 /* TODO: See if we need to switch to a bitmask */ |
5926 [[tf cell] setAlignment:style]; | 5926 [[tf cell] setAlignment:style]; |
5927 } | 5927 } |
5928 else if([object isMemberOfClass:[NSTextView class]]) | 5928 else if([object isMemberOfClass:[NSTextView class]]) |
5929 { | 5929 { |
6039 NSFont *_dw_font_by_name(char *fontname) | 6039 NSFont *_dw_font_by_name(char *fontname) |
6040 { | 6040 { |
6041 char *fontcopy = strdup(fontname); | 6041 char *fontcopy = strdup(fontname); |
6042 char *name = strchr(fontcopy, '.'); | 6042 char *name = strchr(fontcopy, '.'); |
6043 NSFont *font = nil; | 6043 NSFont *font = nil; |
6044 | 6044 |
6045 if(name) | 6045 if(name) |
6046 { | 6046 { |
6047 int size = atoi(fontcopy); | 6047 int size = atoi(fontcopy); |
6048 *name = 0; | 6048 *name = 0; |
6049 name++; | 6049 name++; |
6060 * fontname: Name and size of the font in the form "size.fontname" | 6060 * fontname: Name and size of the font in the form "size.fontname" |
6061 */ | 6061 */ |
6062 int API dw_window_set_font(HWND handle, char *fontname) | 6062 int API dw_window_set_font(HWND handle, char *fontname) |
6063 { | 6063 { |
6064 NSFont *font = _dw_font_by_name(fontname); | 6064 NSFont *font = _dw_font_by_name(fontname); |
6065 | 6065 |
6066 if(font) | 6066 if(font) |
6067 { | 6067 { |
6068 id object = handle; | 6068 id object = handle; |
6069 if([object window]) | 6069 if([object window]) |
6070 { | 6070 { |
6078 [[object cell] setFont:font]; | 6078 [[object cell] setFont:font]; |
6079 } | 6079 } |
6080 else if([object isMemberOfClass:[DWRender class]]) | 6080 else if([object isMemberOfClass:[DWRender class]]) |
6081 { | 6081 { |
6082 DWRender *render = object; | 6082 DWRender *render = object; |
6083 | 6083 |
6084 [render setFont:font]; | 6084 [render setFont:font]; |
6085 } | 6085 } |
6086 } | 6086 } |
6087 return 0; | 6087 return 0; |
6088 } | 6088 } |
6093 * handle: The window handle from which to obtain the font. | 6093 * handle: The window handle from which to obtain the font. |
6094 */ | 6094 */ |
6095 char * API dw_window_get_font(HWND handle) | 6095 char * API dw_window_get_font(HWND handle) |
6096 { | 6096 { |
6097 id object = handle; | 6097 id object = handle; |
6098 | 6098 |
6099 if([object isKindOfClass:[NSControl class]] || [object isMemberOfClass:[DWRender class]]) | 6099 if([object isKindOfClass:[NSControl class]] || [object isMemberOfClass:[DWRender class]]) |
6100 { | 6100 { |
6101 NSFont *font = [object font]; | 6101 NSFont *font = [object font]; |
6102 NSString *fontname = [font fontName]; | 6102 NSString *fontname = [font fontName]; |
6103 NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]]; | 6103 NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]]; |
6114 int API dw_window_destroy(HWND handle) | 6114 int API dw_window_destroy(HWND handle) |
6115 { | 6115 { |
6116 int _locked_by_me = FALSE; | 6116 int _locked_by_me = FALSE; |
6117 DW_MUTEX_LOCK; | 6117 DW_MUTEX_LOCK; |
6118 NSObject *object = handle; | 6118 NSObject *object = handle; |
6119 | 6119 |
6120 if([ object isKindOfClass:[ NSWindow class ] ]) | 6120 if([ object isKindOfClass:[ NSWindow class ] ]) |
6121 { | 6121 { |
6122 NSWindow *window = handle; | 6122 NSWindow *window = handle; |
6123 [window close]; | 6123 [window close]; |
6124 } | 6124 } |
6134 * text: The text associsated with a given window. | 6134 * text: The text associsated with a given window. |
6135 */ | 6135 */ |
6136 char * API dw_window_get_text(HWND handle) | 6136 char * API dw_window_get_text(HWND handle) |
6137 { | 6137 { |
6138 NSObject *object = handle; | 6138 NSObject *object = handle; |
6139 | 6139 |
6140 if([ object isKindOfClass:[ NSControl class ] ]) | 6140 if([ object isKindOfClass:[ NSControl class ] ]) |
6141 { | 6141 { |
6142 NSControl *control = handle; | 6142 NSControl *control = handle; |
6143 NSString *nsstr = [ control stringValue]; | 6143 NSString *nsstr = [ control stringValue]; |
6144 | 6144 |
6145 return strdup([ nsstr UTF8String ]); | 6145 return strdup([ nsstr UTF8String ]); |
6146 } | 6146 } |
6147 else if([ object isKindOfClass:[ NSWindow class ] ]) | 6147 else if([ object isKindOfClass:[ NSWindow class ] ]) |
6148 { | 6148 { |
6149 NSWindow *window = handle; | 6149 NSWindow *window = handle; |
6150 NSString *nsstr = [ window title]; | 6150 NSString *nsstr = [ window title]; |
6151 | 6151 |
6152 return strdup([ nsstr UTF8String ]); | 6152 return strdup([ nsstr UTF8String ]); |
6153 } | 6153 } |
6154 return NULL; | 6154 return NULL; |
6155 } | 6155 } |
6156 | 6156 |
6163 void API dw_window_set_text(HWND handle, char *text) | 6163 void API dw_window_set_text(HWND handle, char *text) |
6164 { | 6164 { |
6165 int _locked_by_me = FALSE; | 6165 int _locked_by_me = FALSE; |
6166 DW_MUTEX_LOCK; | 6166 DW_MUTEX_LOCK; |
6167 NSObject *object = handle; | 6167 NSObject *object = handle; |
6168 | 6168 |
6169 if([ object isKindOfClass:[ NSControl class ] ]) | 6169 if([ object isKindOfClass:[ NSControl class ] ]) |
6170 { | 6170 { |
6171 NSControl *control = handle; | 6171 NSControl *control = handle; |
6172 [control setStringValue:[ NSString stringWithUTF8String:text ]]; | 6172 [control setStringValue:[ NSString stringWithUTF8String:text ]]; |
6173 } | 6173 } |
6223 { | 6223 { |
6224 NSObject *object = handle; | 6224 NSObject *object = handle; |
6225 if([ object isKindOfClass:[ NSImageView class ] ]) | 6225 if([ object isKindOfClass:[ NSImageView class ] ]) |
6226 { | 6226 { |
6227 NSImageView *iv = handle; | 6227 NSImageView *iv = handle; |
6228 NSData *thisdata = [[NSData alloc] dataWithBytes:data length:len]; | 6228 NSData *thisdata = [NSData dataWithBytes:data length:len]; |
6229 NSImage *pixmap = [[NSImage alloc] initWithData:thisdata]; | 6229 NSImage *pixmap = [[NSImage alloc] initWithData:thisdata]; |
6230 | 6230 |
6231 if(pixmap) | 6231 if(pixmap) |
6232 { | 6232 { |
6233 [iv setImage:pixmap]; | 6233 [iv setImage:pixmap]; |
6234 } | 6234 } |
6235 [pixmap release]; | 6235 [pixmap release]; |
6260 } | 6260 } |
6261 else if(resid > 0 && resid < 65536) | 6261 else if(resid > 0 && resid < 65536) |
6262 { | 6262 { |
6263 bitmap = dw_icon_load(0, resid); | 6263 bitmap = dw_icon_load(0, resid); |
6264 } | 6264 } |
6265 | 6265 |
6266 if(bitmap) | 6266 if(bitmap) |
6267 { | 6267 { |
6268 [iv setImage:bitmap]; | 6268 [iv setImage:bitmap]; |
6269 } | 6269 } |
6270 } | 6270 } |
6358 DW_MUTEX_LOCK; | 6358 DW_MUTEX_LOCK; |
6359 NSObject *object = handle; | 6359 NSObject *object = handle; |
6360 NSSize size; | 6360 NSSize size; |
6361 size.width = width; | 6361 size.width = width; |
6362 size.height = height; | 6362 size.height = height; |
6363 | 6363 |
6364 if([ object isKindOfClass:[ NSWindow class ] ]) | 6364 if([ object isKindOfClass:[ NSWindow class ] ]) |
6365 { | 6365 { |
6366 NSWindow *window = handle; | 6366 NSWindow *window = handle; |
6367 [window setContentSize:size]; | 6367 [window setContentSize:size]; |
6368 } | 6368 } |
6382 DW_MUTEX_LOCK; | 6382 DW_MUTEX_LOCK; |
6383 NSObject *object = handle; | 6383 NSObject *object = handle; |
6384 NSPoint point; | 6384 NSPoint point; |
6385 point.x = x; | 6385 point.x = x; |
6386 point.y = y; | 6386 point.y = y; |
6387 | 6387 |
6388 if([ object isKindOfClass:[ NSWindow class ] ]) | 6388 if([ object isKindOfClass:[ NSWindow class ] ]) |
6389 { | 6389 { |
6390 NSWindow *window = handle; | 6390 NSWindow *window = handle; |
6391 [window setFrameOrigin:point]; | 6391 [window setFrameOrigin:point]; |
6392 } | 6392 } |
6418 * height: Height of the widget. | 6418 * height: Height of the widget. |
6419 */ | 6419 */ |
6420 void API dw_window_get_pos_size(HWND handle, LONG *x, LONG *y, ULONG *width, ULONG *height) | 6420 void API dw_window_get_pos_size(HWND handle, LONG *x, LONG *y, ULONG *width, ULONG *height) |
6421 { | 6421 { |
6422 NSObject *object = handle; | 6422 NSObject *object = handle; |
6423 | 6423 |
6424 if([ object isKindOfClass:[ NSWindow class ] ]) | 6424 if([ object isKindOfClass:[ NSWindow class ] ]) |
6425 { | 6425 { |
6426 NSWindow *window = handle; | 6426 NSWindow *window = handle; |
6427 NSRect rect = [window frame]; | 6427 NSRect rect = [window frame]; |
6428 if(x) | 6428 if(x) |
6468 * env: Pointer to a DWEnv struct. | 6468 * env: Pointer to a DWEnv struct. |
6469 */ | 6469 */ |
6470 void dw_environment_query(DWEnv *env) | 6470 void dw_environment_query(DWEnv *env) |
6471 { | 6471 { |
6472 struct utsname name; | 6472 struct utsname name; |
6473 | 6473 |
6474 uname(&name); | 6474 uname(&name); |
6475 strcpy(env->osName, "MacOS"); | 6475 strcpy(env->osName, "MacOS"); |
6476 | 6476 |
6477 strcpy(env->buildDate, __DATE__); | 6477 strcpy(env->buildDate, __DATE__); |
6478 strcpy(env->buildTime, __TIME__); | 6478 strcpy(env->buildTime, __TIME__); |
6479 env->DWMajorVersion = DW_MAJOR_VERSION; | 6479 env->DWMajorVersion = DW_MAJOR_VERSION; |
6480 env->DWMinorVersion = DW_MINOR_VERSION; | 6480 env->DWMinorVersion = DW_MINOR_VERSION; |
6481 env->DWSubVersion = DW_SUB_VERSION; | 6481 env->DWSubVersion = DW_SUB_VERSION; |
6482 | 6482 |
6483 env->MajorVersion = DWOSMajor; | 6483 env->MajorVersion = DWOSMajor; |
6484 env->MinorVersion = DWOSMinor; | 6484 env->MinorVersion = DWOSMinor; |
6485 env->MajorBuild = DWOSBuild; | 6485 env->MajorBuild = DWOSBuild; |
6486 } | 6486 } |
6487 | 6487 |
6510 * dw_window_get_data(). | 6510 * dw_window_get_data(). |
6511 */ | 6511 */ |
6512 UserData *_find_userdata(UserData **root, char *varname) | 6512 UserData *_find_userdata(UserData **root, char *varname) |
6513 { | 6513 { |
6514 UserData *tmp = *root; | 6514 UserData *tmp = *root; |
6515 | 6515 |
6516 while(tmp) | 6516 while(tmp) |
6517 { | 6517 { |
6518 if(strcasecmp(tmp->varname, varname) == 0) | 6518 if(strcasecmp(tmp->varname, varname) == 0) |
6519 return tmp; | 6519 return tmp; |
6520 tmp = tmp->next; | 6520 tmp = tmp->next; |
6523 } | 6523 } |
6524 | 6524 |
6525 int _new_userdata(UserData **root, char *varname, void *data) | 6525 int _new_userdata(UserData **root, char *varname, void *data) |
6526 { | 6526 { |
6527 UserData *new = _find_userdata(root, varname); | 6527 UserData *new = _find_userdata(root, varname); |
6528 | 6528 |
6529 if(new) | 6529 if(new) |
6530 { | 6530 { |
6531 new->data = data; | 6531 new->data = data; |
6532 return TRUE; | 6532 return TRUE; |
6533 } | 6533 } |
6536 new = malloc(sizeof(UserData)); | 6536 new = malloc(sizeof(UserData)); |
6537 if(new) | 6537 if(new) |
6538 { | 6538 { |
6539 new->varname = strdup(varname); | 6539 new->varname = strdup(varname); |
6540 new->data = data; | 6540 new->data = data; |
6541 | 6541 |
6542 new->next = NULL; | 6542 new->next = NULL; |
6543 | 6543 |
6544 if (!*root) | 6544 if (!*root) |
6545 *root = new; | 6545 *root = new; |
6546 else | 6546 else |
6547 { | 6547 { |
6548 UserData *prev = NULL, *tmp = *root; | 6548 UserData *prev = NULL, *tmp = *root; |
6563 } | 6563 } |
6564 | 6564 |
6565 int _remove_userdata(UserData **root, char *varname, int all) | 6565 int _remove_userdata(UserData **root, char *varname, int all) |
6566 { | 6566 { |
6567 UserData *prev = NULL, *tmp = *root; | 6567 UserData *prev = NULL, *tmp = *root; |
6568 | 6568 |
6569 while(tmp) | 6569 while(tmp) |
6570 { | 6570 { |
6571 if(all || strcasecmp(tmp->varname, varname) == 0) | 6571 if(all || strcasecmp(tmp->varname, varname) == 0) |
6572 { | 6572 { |
6573 if(!prev) | 6573 if(!prev) |
6618 { | 6618 { |
6619 NSScrollView *sv = window; | 6619 NSScrollView *sv = window; |
6620 object = [sv documentView]; | 6620 object = [sv documentView]; |
6621 } | 6621 } |
6622 WindowData *blah = (WindowData *)[object userdata]; | 6622 WindowData *blah = (WindowData *)[object userdata]; |
6623 | 6623 |
6624 if(!blah) | 6624 if(!blah) |
6625 { | 6625 { |
6626 if(!dataname) | 6626 if(!dataname) |
6627 return; | 6627 return; |
6628 | 6628 |
6629 blah = calloc(1, sizeof(WindowData)); | 6629 blah = calloc(1, sizeof(WindowData)); |
6630 [object setUserdata:blah]; | 6630 [object setUserdata:blah]; |
6631 } | 6631 } |
6632 | 6632 |
6633 if(data) | 6633 if(data) |
6634 _new_userdata(&(blah->root), dataname, data); | 6634 _new_userdata(&(blah->root), dataname, data); |
6635 else | 6635 else |
6636 { | 6636 { |
6637 if(dataname) | 6637 if(dataname) |
6660 { | 6660 { |
6661 NSScrollView *sv = window; | 6661 NSScrollView *sv = window; |
6662 object = [sv documentView]; | 6662 object = [sv documentView]; |
6663 } | 6663 } |
6664 WindowData *blah = (WindowData *)[object userdata]; | 6664 WindowData *blah = (WindowData *)[object userdata]; |
6665 | 6665 |
6666 if(blah && blah->root && dataname) | 6666 if(blah && blah->root && dataname) |
6667 { | 6667 { |
6668 UserData *ud = _find_userdata(&(blah->root), dataname); | 6668 UserData *ud = _find_userdata(&(blah->root), dataname); |
6669 if(ud) | 6669 if(ud) |
6670 return ud->data; | 6670 return ud->data; |
6685 * Timer ID for use with dw_timer_disconnect(), 0 on error. | 6685 * Timer ID for use with dw_timer_disconnect(), 0 on error. |
6686 */ | 6686 */ |
6687 int API dw_timer_connect(int interval, void *sigfunc, void *data) | 6687 int API dw_timer_connect(int interval, void *sigfunc, void *data) |
6688 { | 6688 { |
6689 int z; | 6689 int z; |
6690 | 6690 |
6691 for(z=0;z<DW_TIMER_MAX;z++) | 6691 for(z=0;z<DW_TIMER_MAX;z++) |
6692 { | 6692 { |
6693 if(!DWTimers[z]) | 6693 if(!DWTimers[z]) |
6694 { | 6694 { |
6695 break; | 6695 break; |
6696 } | 6696 } |
6697 } | 6697 } |
6698 | 6698 |
6699 if(sigfunc && !DWTimers[z]) | 6699 if(sigfunc && !DWTimers[z]) |
6700 { | 6700 { |
6701 NSTimeInterval seconds = (double)interval / 1000.0; | 6701 NSTimeInterval seconds = (double)interval / 1000.0; |
6702 NSTimer *thistimer = DWTimers[z] = [NSTimer scheduledTimerWithTimeInterval:seconds target:DWHandler selector:@selector(runTimer:) userInfo:nil repeats:YES]; | 6702 NSTimer *thistimer = DWTimers[z] = [NSTimer scheduledTimerWithTimeInterval:seconds target:DWHandler selector:@selector(runTimer:) userInfo:nil repeats:YES]; |
6703 _new_signal(0, thistimer, z+1, sigfunc, data); | 6703 _new_signal(0, thistimer, z+1, sigfunc, data); |
6713 */ | 6713 */ |
6714 void API dw_timer_disconnect(int timerid) | 6714 void API dw_timer_disconnect(int timerid) |
6715 { | 6715 { |
6716 SignalHandler *prev = NULL, *tmp = Root; | 6716 SignalHandler *prev = NULL, *tmp = Root; |
6717 NSTimer *thistimer; | 6717 NSTimer *thistimer; |
6718 | 6718 |
6719 /* 0 is an invalid timer ID */ | 6719 /* 0 is an invalid timer ID */ |
6720 if(timerid < 1 || !DWTimers[timerid-1]) | 6720 if(timerid < 1 || !DWTimers[timerid-1]) |
6721 return; | 6721 return; |
6722 | 6722 |
6723 thistimer = DWTimers[timerid-1]; | 6723 thistimer = DWTimers[timerid-1]; |
6724 DWTimers[timerid-1] = nil; | 6724 DWTimers[timerid-1] = nil; |
6725 | 6725 |
6726 [thistimer invalidate]; | 6726 [thistimer invalidate]; |
6727 | 6727 |
6728 while(tmp) | 6728 while(tmp) |
6729 { | 6729 { |
6730 if(tmp->id == timerid && tmp->window == thistimer) | 6730 if(tmp->id == timerid && tmp->window == thistimer) |
6731 { | 6731 { |
6732 if(prev) | 6732 if(prev) |
6778 */ | 6778 */ |
6779 void API dw_signal_disconnect_by_name(HWND window, char *signame) | 6779 void API dw_signal_disconnect_by_name(HWND window, char *signame) |
6780 { | 6780 { |
6781 SignalHandler *prev = NULL, *tmp = Root; | 6781 SignalHandler *prev = NULL, *tmp = Root; |
6782 ULONG message; | 6782 ULONG message; |
6783 | 6783 |
6784 if(!window || !signame || (message = _findsigmessage(signame)) == 0) | 6784 if(!window || !signame || (message = _findsigmessage(signame)) == 0) |
6785 return; | 6785 return; |
6786 | 6786 |
6787 while(tmp) | 6787 while(tmp) |
6788 { | 6788 { |
6789 if(tmp->window == window && tmp->message == message) | 6789 if(tmp->window == window && tmp->message == message) |
6790 { | 6790 { |
6791 if(prev) | 6791 if(prev) |
6815 * window: Window handle of callback to be removed. | 6815 * window: Window handle of callback to be removed. |
6816 */ | 6816 */ |
6817 void API dw_signal_disconnect_by_window(HWND window) | 6817 void API dw_signal_disconnect_by_window(HWND window) |
6818 { | 6818 { |
6819 SignalHandler *prev = NULL, *tmp = Root; | 6819 SignalHandler *prev = NULL, *tmp = Root; |
6820 | 6820 |
6821 while(tmp) | 6821 while(tmp) |
6822 { | 6822 { |
6823 if(tmp->window == window) | 6823 if(tmp->window == window) |
6824 { | 6824 { |
6825 if(prev) | 6825 if(prev) |
6850 * data: Pointer to the data to be compared against. | 6850 * data: Pointer to the data to be compared against. |
6851 */ | 6851 */ |
6852 void API dw_signal_disconnect_by_data(HWND window, void *data) | 6852 void API dw_signal_disconnect_by_data(HWND window, void *data) |
6853 { | 6853 { |
6854 SignalHandler *prev = NULL, *tmp = Root; | 6854 SignalHandler *prev = NULL, *tmp = Root; |
6855 | 6855 |
6856 while(tmp) | 6856 while(tmp) |
6857 { | 6857 { |
6858 if(tmp->window == window && tmp->data == data) | 6858 if(tmp->window == window && tmp->data == data) |
6859 { | 6859 { |
6860 if(prev) | 6860 if(prev) |
7312 if(!eve) | 7312 if(!eve) |
7313 { | 7313 { |
7314 free(tmpsock); | 7314 free(tmpsock); |
7315 return NULL; | 7315 return NULL; |
7316 } | 7316 } |
7317 | 7317 |
7318 tmpsock[0] = socket(AF_UNIX, SOCK_STREAM, 0); | 7318 tmpsock[0] = socket(AF_UNIX, SOCK_STREAM, 0); |
7319 ev = socket(AF_UNIX, SOCK_STREAM, 0); | 7319 ev = socket(AF_UNIX, SOCK_STREAM, 0); |
7320 memset(&un, 0, sizeof(un)); | 7320 memset(&un, 0, sizeof(un)); |
7321 un.sun_family=AF_UNIX; | 7321 un.sun_family=AF_UNIX; |
7322 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); | 7322 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); |
7520 /* If we aren't using garbage collection we need autorelease pools */ | 7520 /* If we aren't using garbage collection we need autorelease pools */ |
7521 #if !defined(GARBAGE_COLLECT) | 7521 #if !defined(GARBAGE_COLLECT) |
7522 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | 7522 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
7523 pthread_setspecific(_dw_pool_key, pool); | 7523 pthread_setspecific(_dw_pool_key, pool); |
7524 #endif | 7524 #endif |
7525 | 7525 |
7526 threadfunc = (void (*)(void *))tmp[0]; | 7526 threadfunc = (void (*)(void *))tmp[0]; |
7527 | 7527 |
7528 threadfunc(tmp[1]); | 7528 threadfunc(tmp[1]); |
7529 /* Release the pool when we are done so we don't leak */ | 7529 /* Release the pool when we are done so we don't leak */ |
7530 #if !defined(GARBAGE_COLLECT) | 7530 #if !defined(GARBAGE_COLLECT) |
7736 * -1 on error. | 7736 * -1 on error. |
7737 */ | 7737 */ |
7738 int dw_exec(char *program, int type, char **params) | 7738 int dw_exec(char *program, int type, char **params) |
7739 { | 7739 { |
7740 int ret = -1; | 7740 int ret = -1; |
7741 | 7741 |
7742 if(type == DW_EXEC_GUI) | 7742 if(type == DW_EXEC_GUI) |
7743 { | 7743 { |
7744 if(params && params[0] && params[1]) | 7744 if(params && params[0] && params[1]) |
7745 { | 7745 { |
7746 [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithUTF8String:params[1]] | 7746 [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithUTF8String:params[1]] |
7750 { | 7750 { |
7751 [[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:program]]; | 7751 [[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:program]]; |
7752 } | 7752 } |
7753 return 0; | 7753 return 0; |
7754 } | 7754 } |
7755 | 7755 |
7756 if((ret = fork()) == 0) | 7756 if((ret = fork()) == 0) |
7757 { | 7757 { |
7758 int i; | 7758 int i; |
7759 | 7759 |
7760 for (i = 3; i < 256; i++) | 7760 for (i = 3; i < 256; i++) |
7761 close(i); | 7761 close(i); |
7762 setsid(); | 7762 setsid(); |
7763 | 7763 |
7764 if(type == DW_EXEC_CON) | 7764 if(type == DW_EXEC_CON) |
7765 { | 7765 { |
7766 char **tmpargs; | 7766 char **tmpargs; |
7767 | 7767 |
7768 if(!params) | 7768 if(!params) |
7769 { | 7769 { |
7770 tmpargs = malloc(sizeof(char *)); | 7770 tmpargs = malloc(sizeof(char *)); |
7771 tmpargs[0] = NULL; | 7771 tmpargs[0] = NULL; |
7772 } | 7772 } |
7773 else | 7773 else |
7774 { | 7774 { |
7775 int z = 0; | 7775 int z = 0; |
7776 | 7776 |
7777 while(params[z]) | 7777 while(params[z]) |
7778 { | 7778 { |
7779 z++; | 7779 z++; |
7780 } | 7780 } |
7781 tmpargs = malloc(sizeof(char *)*(z+3)); | 7781 tmpargs = malloc(sizeof(char *)*(z+3)); |