Mercurial > dwindows
comparison ios/dw.m @ 2393:6669e152e30b
iOS: More namespace cleanup.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 25 Mar 2021 07:48:38 +0000 |
parents | a7bfb97fd80e |
children | 2618277de356 |
comparison
equal
deleted
inserted
replaced
2392:9fcc9ee25c4b | 2393:6669e152e30b |
---|---|
152 #define DW_FUNCTION_RETURN_THIS(_retvar) { void *_myreturn = malloc(sizeof(_retvar)); \ | 152 #define DW_FUNCTION_RETURN_THIS(_retvar) { void *_myreturn = malloc(sizeof(_retvar)); \ |
153 memcpy(_myreturn, (void *)&_retvar, sizeof(_retvar)); \ | 153 memcpy(_myreturn, (void *)&_retvar, sizeof(_retvar)); \ |
154 [_args addPointer:_myreturn]; }} | 154 [_args addPointer:_myreturn]; }} |
155 #define DW_FUNCTION_RETURN_NOTHING } | 155 #define DW_FUNCTION_RETURN_NOTHING } |
156 | 156 |
157 unsigned long _colors[] = | 157 unsigned long _dw_colors[] = |
158 { | 158 { |
159 0x00000000, /* 0 black */ | 159 0x00000000, /* 0 black */ |
160 0x000000bb, /* 1 red */ | 160 0x000000bb, /* 1 red */ |
161 0x0000bb00, /* 2 green */ | 161 0x0000bb00, /* 2 green */ |
162 0x0000aaaa, /* 3 yellow */ | 162 0x0000aaaa, /* 3 yellow */ |
222 { | 222 { |
223 return thiscolor & ~DW_RGB_COLOR; | 223 return thiscolor & ~DW_RGB_COLOR; |
224 } | 224 } |
225 else if(thiscolor < 17) | 225 else if(thiscolor < 17) |
226 { | 226 { |
227 return _colors[thiscolor]; | 227 return _dw_colors[thiscolor]; |
228 } | 228 } |
229 return 0; | 229 return 0; |
230 } | 230 } |
231 | 231 |
232 /* Thread specific storage */ | 232 /* Thread specific storage */ |
233 pthread_key_t _dw_pool_key; | 233 pthread_key_t _dw_pool_key; |
234 pthread_key_t _dw_fg_color_key; | 234 pthread_key_t _dw_fg_color_key; |
235 pthread_key_t _dw_bg_color_key; | 235 pthread_key_t _dw_bg_color_key; |
236 int DWOSMajor, DWOSMinor, DWOSBuild; | 236 static int DWOSMajor, DWOSMinor, DWOSBuild; |
237 static char _dw_bundle_path[PATH_MAX+1] = { 0 }; | 237 static char _dw_bundle_path[PATH_MAX+1] = { 0 }; |
238 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; | 238 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; |
239 | 239 |
240 /* Create a default colors for a thread */ | 240 /* Create a default colors for a thread */ |
241 void _dw_init_colors(void) | 241 void _dw_init_colors(void) |
255 void *discfunction; | 255 void *discfunction; |
256 void *data; | 256 void *data; |
257 | 257 |
258 } SignalHandler; | 258 } SignalHandler; |
259 | 259 |
260 SignalHandler *Root = NULL; | 260 static SignalHandler *DWRoot = NULL; |
261 | |
262 | 261 |
263 /* Some internal prototypes */ | 262 /* Some internal prototypes */ |
264 static void _dw_do_resize(Box *thisbox, int x, int y); | 263 static void _dw_do_resize(Box *thisbox, int x, int y); |
265 void _dw_handle_resize_events(Box *thisbox); | 264 void _dw_handle_resize_events(Box *thisbox); |
266 int _dw_remove_userdata(UserData **root, const char *varname, int all); | 265 int _dw_remove_userdata(UserData **root, const char *varname, int all); |
284 } | 283 } |
285 } | 284 } |
286 | 285 |
287 SignalHandler *_dw_get_handler(HWND window, int messageid) | 286 SignalHandler *_dw_get_handler(HWND window, int messageid) |
288 { | 287 { |
289 SignalHandler *tmp = Root; | 288 SignalHandler *tmp = DWRoot; |
290 | 289 |
291 /* Find any callbacks for this function */ | 290 /* Find any callbacks for this function */ |
292 while(tmp) | 291 while(tmp) |
293 { | 292 { |
294 if(tmp->message == messageid && window == tmp->window) | 293 if(tmp->message == messageid && window == tmp->window) |
308 } SignalList; | 307 } SignalList; |
309 | 308 |
310 /* List of signals */ | 309 /* List of signals */ |
311 #define SIGNALMAX 19 | 310 #define SIGNALMAX 19 |
312 | 311 |
313 SignalList SignalTranslate[SIGNALMAX] = { | 312 static SignalList DWSignalTranslate[SIGNALMAX] = { |
314 { 1, DW_SIGNAL_CONFIGURE }, | 313 { 1, DW_SIGNAL_CONFIGURE }, |
315 { 2, DW_SIGNAL_KEY_PRESS }, | 314 { 2, DW_SIGNAL_KEY_PRESS }, |
316 { 3, DW_SIGNAL_BUTTON_PRESS }, | 315 { 3, DW_SIGNAL_BUTTON_PRESS }, |
317 { 4, DW_SIGNAL_BUTTON_RELEASE }, | 316 { 4, DW_SIGNAL_BUTTON_RELEASE }, |
318 { 5, DW_SIGNAL_MOTION_NOTIFY }, | 317 { 5, DW_SIGNAL_MOTION_NOTIFY }, |
573 { | 572 { |
574 return true; | 573 return true; |
575 } | 574 } |
576 @end | 575 @end |
577 | 576 |
578 UIApplication *DWApp = nil; | 577 static UIApplication *DWApp = nil; |
579 UIFont *DWDefaultFont; | 578 static UIFont *DWDefaultFont; |
580 DWTimerHandler *DWHandler; | 579 static DWTimerHandler *DWHandler; |
581 NSAutoreleasePool *pool; | 580 static NSMutableArray *_DWDirtyDrawables; |
582 NSMutableArray *_DWDirtyDrawables; | 581 static DWTID DWThread = (DWTID)-1; |
583 DWTID DWThread = (DWTID)-1; | |
584 | 582 |
585 /* Used for doing bitblts from the main thread */ | 583 /* Used for doing bitblts from the main thread */ |
586 typedef struct _bitbltinfo | 584 typedef struct _bitbltinfo |
587 { | 585 { |
588 id src; | 586 id src; |
718 -(void)keyDown:(UIEvent *)theEvent { _dw_event_handler(self, theEvent, 2); } | 716 -(void)keyDown:(UIEvent *)theEvent { _dw_event_handler(self, theEvent, 2); } |
719 -(void)setColor:(unsigned long)input | 717 -(void)setColor:(unsigned long)input |
720 { | 718 { |
721 id orig = bgcolor; | 719 id orig = bgcolor; |
722 | 720 |
723 if(input == _colors[DW_CLR_DEFAULT]) | 721 if(input == _dw_colors[DW_CLR_DEFAULT]) |
724 { | 722 { |
725 bgcolor = nil; | 723 bgcolor = nil; |
726 } | 724 } |
727 else | 725 else |
728 { | 726 { |
1112 -(void)viewWillLayoutSubviews | 1110 -(void)viewWillLayoutSubviews |
1113 { | 1111 { |
1114 DWWindow *window = (DWWindow *)[[self view] window]; | 1112 DWWindow *window = (DWWindow *)[[self view] window]; |
1115 NSArray *array = [window subviews]; | 1113 NSArray *array = [window subviews]; |
1116 DWView *view = [array firstObject]; | 1114 DWView *view = [array firstObject]; |
1117 #if 0 | |
1118 id object = [array lastObject]; | 1115 id object = [array lastObject]; |
1119 /* Remove the UITransitionView... for testing purposes */ | 1116 /* Remove the UITransitionView... for testing purposes */ |
1120 if(![object isMemberOfClass:[DWView class]]) | 1117 if(![object isMemberOfClass:[DWView class]]) |
1121 [object removeFromSuperview]; | 1118 [object removeFromSuperview]; |
1122 #endif | |
1123 [view setFrame:[window frame]]; | 1119 [view setFrame:[window frame]]; |
1124 [view windowResized:[window frame].size]; | 1120 [view windowResized:[window frame].size]; |
1125 } | 1121 } |
1126 @end | 1122 @end |
1127 | |
1128 | 1123 |
1129 /* Subclass for a button type */ | 1124 /* Subclass for a button type */ |
1130 @interface DWButton : UIButton | 1125 @interface DWButton : UIButton |
1131 { | 1126 { |
1132 void *userdata; | 1127 void *userdata; |
2031 new->signalfunction = signalfunction; | 2026 new->signalfunction = signalfunction; |
2032 new->discfunction = discfunc; | 2027 new->discfunction = discfunc; |
2033 new->data = data; | 2028 new->data = data; |
2034 new->next = NULL; | 2029 new->next = NULL; |
2035 | 2030 |
2036 if (!Root) | 2031 if (!DWRoot) |
2037 Root = new; | 2032 DWRoot = new; |
2038 else | 2033 else |
2039 { | 2034 { |
2040 SignalHandler *prev = NULL, *tmp = Root; | 2035 SignalHandler *prev = NULL, *tmp = DWRoot; |
2041 while(tmp) | 2036 while(tmp) |
2042 { | 2037 { |
2043 if(tmp->message == message && | 2038 if(tmp->message == message && |
2044 tmp->window == window && | 2039 tmp->window == window && |
2045 tmp->id == msgid && | 2040 tmp->id == msgid && |
2053 tmp = tmp->next; | 2048 tmp = tmp->next; |
2054 } | 2049 } |
2055 if(prev) | 2050 if(prev) |
2056 prev->next = new; | 2051 prev->next = new; |
2057 else | 2052 else |
2058 Root = new; | 2053 DWRoot = new; |
2059 } | 2054 } |
2060 } | 2055 } |
2061 | 2056 |
2062 /* Finds the message number for a given signal name */ | 2057 /* Finds the message number for a given signal name */ |
2063 ULONG _dw_findsigmessage(const char *signame) | 2058 ULONG _dw_findsigmessage(const char *signame) |
2064 { | 2059 { |
2065 int z; | 2060 int z; |
2066 | 2061 |
2067 for(z=0;z<SIGNALMAX;z++) | 2062 for(z=0;z<SIGNALMAX;z++) |
2068 { | 2063 { |
2069 if(strcasecmp(signame, SignalTranslate[z].name) == 0) | 2064 if(strcasecmp(signame, DWSignalTranslate[z].name) == 0) |
2070 return SignalTranslate[z].message; | 2065 return DWSignalTranslate[z].message; |
2071 } | 2066 } |
2072 return 0L; | 2067 return 0L; |
2073 } | 2068 } |
2074 | 2069 |
2075 unsigned long _foreground = 0xAAAAAA, _background = 0; | 2070 unsigned long _dw_foreground = 0xAAAAAA, _dw_background = 0; |
2076 | 2071 |
2077 void _dw_handle_resize_events(Box *thisbox) | 2072 void _dw_handle_resize_events(Box *thisbox) |
2078 { | 2073 { |
2079 int z; | 2074 int z; |
2080 | 2075 |
2408 _dw_resize_box(thisbox, &depth, x, y, 2); | 2403 _dw_resize_box(thisbox, &depth, x, y, 2); |
2409 } | 2404 } |
2410 } | 2405 } |
2411 } | 2406 } |
2412 | 2407 |
2413 static int _dw_argc; | 2408 static int _dw_argc = 0; |
2414 static char **_dw_argv; | 2409 static char **_dw_argv = NULL; |
2415 | 2410 |
2416 /* | 2411 /* |
2417 * Runs a message loop for Dynamic Windows. | 2412 * Runs a message loop for Dynamic Windows. |
2418 */ | 2413 */ |
2419 void API dw_main(void) | 2414 void API dw_main(void) |
2496 /* | 2491 /* |
2497 * Cleanly terminates a DW session, should be signal handler safe. | 2492 * Cleanly terminates a DW session, should be signal handler safe. |
2498 */ | 2493 */ |
2499 void API dw_shutdown(void) | 2494 void API dw_shutdown(void) |
2500 { | 2495 { |
2501 pool = pthread_getspecific(_dw_pool_key); | 2496 NSAutoreleasePool *pool = pthread_getspecific(_dw_pool_key); |
2502 [pool drain]; | 2497 [pool drain]; |
2503 } | 2498 } |
2504 | 2499 |
2505 /* | 2500 /* |
2506 * Cleanly terminates a DW session, should be signal handler safe. | 2501 * Cleanly terminates a DW session, should be signal handler safe. |
4525 { | 4520 { |
4526 UIColor *oldcolor = pthread_getspecific(_dw_fg_color_key); | 4521 UIColor *oldcolor = pthread_getspecific(_dw_fg_color_key); |
4527 UIColor *newcolor; | 4522 UIColor *newcolor; |
4528 DW_LOCAL_POOL_IN; | 4523 DW_LOCAL_POOL_IN; |
4529 | 4524 |
4530 _foreground = _dw_get_color(value); | 4525 _dw_foreground = _dw_get_color(value); |
4531 | 4526 |
4532 newcolor = [[UIColor colorWithRed: DW_RED_VALUE(_foreground)/255.0 green: | 4527 newcolor = [[UIColor colorWithRed: DW_RED_VALUE(_dw_foreground)/255.0 green: |
4533 DW_GREEN_VALUE(_foreground)/255.0 blue: | 4528 DW_GREEN_VALUE(_dw_foreground)/255.0 blue: |
4534 DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] retain]; | 4529 DW_BLUE_VALUE(_dw_foreground)/255.0 alpha: 1] retain]; |
4535 pthread_setspecific(_dw_fg_color_key, newcolor); | 4530 pthread_setspecific(_dw_fg_color_key, newcolor); |
4536 [oldcolor release]; | 4531 [oldcolor release]; |
4537 DW_LOCAL_POOL_OUT; | 4532 DW_LOCAL_POOL_OUT; |
4538 } | 4533 } |
4539 | 4534 |
4553 { | 4548 { |
4554 pthread_setspecific(_dw_bg_color_key, NULL); | 4549 pthread_setspecific(_dw_bg_color_key, NULL); |
4555 } | 4550 } |
4556 else | 4551 else |
4557 { | 4552 { |
4558 _background = _dw_get_color(value); | 4553 _dw_background = _dw_get_color(value); |
4559 | 4554 |
4560 newcolor = [[UIColor colorWithRed: DW_RED_VALUE(_background)/255.0 green: | 4555 newcolor = [[UIColor colorWithRed: DW_RED_VALUE(_dw_background)/255.0 green: |
4561 DW_GREEN_VALUE(_background)/255.0 blue: | 4556 DW_GREEN_VALUE(_dw_background)/255.0 blue: |
4562 DW_BLUE_VALUE(_background)/255.0 alpha: 1] retain]; | 4557 DW_BLUE_VALUE(_dw_background)/255.0 alpha: 1] retain]; |
4563 pthread_setspecific(_dw_bg_color_key, newcolor); | 4558 pthread_setspecific(_dw_bg_color_key, newcolor); |
4564 } | 4559 } |
4565 [oldcolor release]; | 4560 [oldcolor release]; |
4566 DW_LOCAL_POOL_OUT; | 4561 DW_LOCAL_POOL_OUT; |
4567 } | 4562 } |
6055 void API dw_taskbar_delete(HWND handle, HICN icon) | 6050 void API dw_taskbar_delete(HWND handle, HICN icon) |
6056 { | 6051 { |
6057 } | 6052 } |
6058 | 6053 |
6059 /* Internal function to keep HICNs from getting too big */ | 6054 /* Internal function to keep HICNs from getting too big */ |
6060 void _icon_resize(UIImage *image) | 6055 void _dw_icon_resize(UIImage *image) |
6061 { | 6056 { |
6062 if(image) | 6057 if(image) |
6063 { | 6058 { |
6064 CGSize size = [image size]; | 6059 CGSize size = [image size]; |
6065 if(size.width > 24 || size.height > 24) | 6060 if(size.width > 24 || size.height > 24) |
6094 * to an embedded XPM. | 6089 * to an embedded XPM. |
6095 */ | 6090 */ |
6096 HICN API dw_icon_load(unsigned long module, unsigned long resid) | 6091 HICN API dw_icon_load(unsigned long module, unsigned long resid) |
6097 { | 6092 { |
6098 UIImage *image = _dw_icon_load(resid); | 6093 UIImage *image = _dw_icon_load(resid); |
6099 _icon_resize(image); | 6094 _dw_icon_resize(image); |
6100 return image; | 6095 return image; |
6101 } | 6096 } |
6102 | 6097 |
6103 /* | 6098 /* |
6104 * Obtains an icon from a file. | 6099 * Obtains an icon from a file. |
6116 if(!image && ext) | 6111 if(!image && ext) |
6117 { | 6112 { |
6118 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; | 6113 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; |
6119 image = [[UIImage alloc] initWithContentsOfFile:nstr]; | 6114 image = [[UIImage alloc] initWithContentsOfFile:nstr]; |
6120 } | 6115 } |
6121 _icon_resize(image); | 6116 _dw_icon_resize(image); |
6122 return image; | 6117 return image; |
6123 } | 6118 } |
6124 | 6119 |
6125 /* | 6120 /* |
6126 * Obtains an icon from data | 6121 * Obtains an icon from data |
6131 */ | 6126 */ |
6132 HICN API dw_icon_load_from_data(const char *data, int len) | 6127 HICN API dw_icon_load_from_data(const char *data, int len) |
6133 { | 6128 { |
6134 NSData *thisdata = [NSData dataWithBytes:data length:len]; | 6129 NSData *thisdata = [NSData dataWithBytes:data length:len]; |
6135 UIImage *image = [[UIImage alloc] initWithData:thisdata]; | 6130 UIImage *image = [[UIImage alloc] initWithData:thisdata]; |
6136 _icon_resize(image); | 6131 _dw_icon_resize(image); |
6137 return image; | 6132 return image; |
6138 } | 6133 } |
6139 | 6134 |
6140 /* | 6135 /* |
6141 * Frees a loaded resource in OS/2 and Windows. | 6136 * Frees a loaded resource in OS/2 and Windows. |
6869 CGPoint p = CGPointMake(x, y); | 6864 CGPoint p = CGPointMake(x, y); |
6870 [UIContextMenuInteraction a | 6865 [UIContextMenuInteraction a |
6871 #endif | 6866 #endif |
6872 } | 6867 } |
6873 | 6868 |
6874 char _removetilde(char *dest, const char *src) | 6869 char _dw_removetilde(char *dest, const char *src) |
6875 { | 6870 { |
6876 int z, cur=0; | 6871 int z, cur=0; |
6877 char accel = '\0'; | 6872 char accel = '\0'; |
6878 | 6873 |
6879 for(z=0;z<strlen(src);z++) | 6874 for(z=0;z<strlen(src);z++) |
6920 char *newtitle = malloc(strlen(title)+1); | 6915 char *newtitle = malloc(strlen(title)+1); |
6921 NSString *nstr; | 6916 NSString *nstr; |
6922 UIMenu *newmenu, *oldmenu = [menu menu]; | 6917 UIMenu *newmenu, *oldmenu = [menu menu]; |
6923 NSArray *newchildren, *oldchildren = [oldmenu children]; | 6918 NSArray *newchildren, *oldchildren = [oldmenu children]; |
6924 | 6919 |
6925 accel[0] = _removetilde(newtitle, title); | 6920 accel[0] = _dw_removetilde(newtitle, title); |
6926 accel[1] = 0; | 6921 accel[1] = 0; |
6927 | 6922 |
6928 nstr = [ NSString stringWithUTF8String:newtitle ]; | 6923 nstr = [ NSString stringWithUTF8String:newtitle ]; |
6929 free(newtitle); | 6924 free(newtitle); |
6930 | 6925 |
7057 #endif | 7052 #endif |
7058 } | 7053 } |
7059 } | 7054 } |
7060 | 7055 |
7061 /* Gets the notebook page from associated ID */ | 7056 /* Gets the notebook page from associated ID */ |
7062 DWNotebookPage *_notepage_from_id(DWNotebook *notebook, unsigned long pageid) | 7057 DWNotebookPage *_dw_notepage_from_id(DWNotebook *notebook, unsigned long pageid) |
7063 { | 7058 { |
7064 NSArray *pages = [notebook views]; | 7059 NSArray *pages = [notebook views]; |
7065 for(DWNotebookPage *notepage in pages) | 7060 for(DWNotebookPage *notepage in pages) |
7066 { | 7061 { |
7067 if([notepage pageid] == pageid) | 7062 if([notepage pageid] == pageid) |
7124 * pageid: ID of the page to be destroyed. | 7119 * pageid: ID of the page to be destroyed. |
7125 */ | 7120 */ |
7126 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid) | 7121 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid) |
7127 { | 7122 { |
7128 DWNotebook *notebook = handle; | 7123 DWNotebook *notebook = handle; |
7129 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 7124 DWNotebookPage *notepage = _dw_notepage_from_id(notebook, pageid); |
7130 DW_LOCAL_POOL_IN; | 7125 DW_LOCAL_POOL_IN; |
7131 | 7126 |
7132 if(notepage != nil) | 7127 if(notepage != nil) |
7133 { | 7128 { |
7134 NSMutableArray<DWNotebookPage *> *views = [notebook views]; | 7129 NSMutableArray<DWNotebookPage *> *views = [notebook views]; |
7166 */ | 7161 */ |
7167 void API dw_notebook_page_set(HWND handle, unsigned int pageid) | 7162 void API dw_notebook_page_set(HWND handle, unsigned int pageid) |
7168 { | 7163 { |
7169 #if 0 /* TODO: Don't see a method to select a tab */ | 7164 #if 0 /* TODO: Don't see a method to select a tab */ |
7170 DWNotebook *notebook = handle; | 7165 DWNotebook *notebook = handle; |
7171 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 7166 DWNotebookPage *notepage = _dw_notepage_from_id(notebook, pageid); |
7172 | 7167 |
7173 if(notepage != nil) | 7168 if(notepage != nil) |
7174 { | 7169 { |
7175 NSMutableArray<DWNotebookPage *> *views = [notebook views]; | 7170 NSMutableArray<DWNotebookPage *> *views = [notebook views]; |
7176 NSUInteger index = [views indexOfObject:notepage]; | 7171 NSUInteger index = [views indexOfObject:notepage]; |
7218 */ | 7213 */ |
7219 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page) | 7214 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page) |
7220 { | 7215 { |
7221 #if 0 /* TODO: Haven't implemented the content yet since UISegmentedControl is just the buttons */ | 7216 #if 0 /* TODO: Haven't implemented the content yet since UISegmentedControl is just the buttons */ |
7222 DWNotebook *notebook = handle; | 7217 DWNotebook *notebook = handle; |
7223 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); | 7218 DWNotebookPage *notepage = _dw_notepage_from_id(notebook, pageid); |
7224 | 7219 |
7225 if(notepage != nil) | 7220 if(notepage != nil) |
7226 { | 7221 { |
7227 HWND tmpbox = dw_box_new(DW_VERT, 0); | 7222 HWND tmpbox = dw_box_new(DW_VERT, 0); |
7228 DWBox *box = tmpbox; | 7223 DWBox *box = tmpbox; |
8385 | 8380 |
8386 /* Functions for managing the user data lists that are associated with | 8381 /* Functions for managing the user data lists that are associated with |
8387 * a given window handle. Used in dw_window_set_data() and | 8382 * a given window handle. Used in dw_window_set_data() and |
8388 * dw_window_get_data(). | 8383 * dw_window_get_data(). |
8389 */ | 8384 */ |
8390 UserData *_find_userdata(UserData **root, const char *varname) | 8385 UserData *_dw_find_userdata(UserData **root, const char *varname) |
8391 { | 8386 { |
8392 UserData *tmp = *root; | 8387 UserData *tmp = *root; |
8393 | 8388 |
8394 while(tmp) | 8389 while(tmp) |
8395 { | 8390 { |
8398 tmp = tmp->next; | 8393 tmp = tmp->next; |
8399 } | 8394 } |
8400 return NULL; | 8395 return NULL; |
8401 } | 8396 } |
8402 | 8397 |
8403 int _new_userdata(UserData **root, const char *varname, void *data) | 8398 int _dw_new_userdata(UserData **root, const char *varname, void *data) |
8404 { | 8399 { |
8405 UserData *new = _find_userdata(root, varname); | 8400 UserData *new = _dw_find_userdata(root, varname); |
8406 | 8401 |
8407 if(new) | 8402 if(new) |
8408 { | 8403 { |
8409 new->data = data; | 8404 new->data = data; |
8410 return TRUE; | 8405 return TRUE; |
8507 blah = calloc(1, sizeof(WindowData)); | 8502 blah = calloc(1, sizeof(WindowData)); |
8508 [object setUserdata:blah]; | 8503 [object setUserdata:blah]; |
8509 } | 8504 } |
8510 | 8505 |
8511 if(data) | 8506 if(data) |
8512 _new_userdata(&(blah->root), dataname, data); | 8507 _dw_new_userdata(&(blah->root), dataname, data); |
8513 else | 8508 else |
8514 { | 8509 { |
8515 if(dataname) | 8510 if(dataname) |
8516 _dw_remove_userdata(&(blah->root), dataname, FALSE); | 8511 _dw_remove_userdata(&(blah->root), dataname, FALSE); |
8517 else | 8512 else |
8543 } | 8538 } |
8544 WindowData *blah = (WindowData *)[object userdata]; | 8539 WindowData *blah = (WindowData *)[object userdata]; |
8545 | 8540 |
8546 if(blah && blah->root && dataname) | 8541 if(blah && blah->root && dataname) |
8547 { | 8542 { |
8548 UserData *ud = _find_userdata(&(blah->root), dataname); | 8543 UserData *ud = _dw_find_userdata(&(blah->root), dataname); |
8549 if(ud) | 8544 if(ud) |
8550 return ud->data; | 8545 return ud->data; |
8551 } | 8546 } |
8552 return NULL; | 8547 return NULL; |
8553 } | 8548 } |
8554 | 8549 |
8555 #define DW_TIMER_MAX 64 | 8550 #define DW_TIMER_MAX 64 |
8556 NSTimer *DWTimers[DW_TIMER_MAX]; | 8551 static NSTimer *DWTimers[DW_TIMER_MAX]; |
8557 | 8552 |
8558 /* | 8553 /* |
8559 * Add a callback to a timer event. | 8554 * Add a callback to a timer event. |
8560 * Parameters: | 8555 * Parameters: |
8561 * interval: Milliseconds to delay between calls. | 8556 * interval: Milliseconds to delay between calls. |
8591 * Parameters: | 8586 * Parameters: |
8592 * id: Timer ID returned by dw_timer_connect(). | 8587 * id: Timer ID returned by dw_timer_connect(). |
8593 */ | 8588 */ |
8594 void API dw_timer_disconnect(int timerid) | 8589 void API dw_timer_disconnect(int timerid) |
8595 { | 8590 { |
8596 SignalHandler *prev = NULL, *tmp = Root; | 8591 SignalHandler *prev = NULL, *tmp = DWRoot; |
8597 NSTimer *thistimer; | 8592 NSTimer *thistimer; |
8598 | 8593 |
8599 /* 0 is an invalid timer ID */ | 8594 /* 0 is an invalid timer ID */ |
8600 if(timerid < 1 || !DWTimers[timerid-1]) | 8595 if(timerid < 1 || !DWTimers[timerid-1]) |
8601 return; | 8596 return; |
8615 free(tmp); | 8610 free(tmp); |
8616 tmp = prev->next; | 8611 tmp = prev->next; |
8617 } | 8612 } |
8618 else | 8613 else |
8619 { | 8614 { |
8620 Root = tmp->next; | 8615 DWRoot = tmp->next; |
8621 free(tmp); | 8616 free(tmp); |
8622 tmp = Root; | 8617 tmp = DWRoot; |
8623 } | 8618 } |
8624 } | 8619 } |
8625 else | 8620 else |
8626 { | 8621 { |
8627 prev = tmp; | 8622 prev = tmp; |
8676 * Parameters: | 8671 * Parameters: |
8677 * window: Window handle of callback to be removed. | 8672 * window: Window handle of callback to be removed. |
8678 */ | 8673 */ |
8679 void API dw_signal_disconnect_by_name(HWND window, const char *signame) | 8674 void API dw_signal_disconnect_by_name(HWND window, const char *signame) |
8680 { | 8675 { |
8681 SignalHandler *prev = NULL, *tmp = Root; | 8676 SignalHandler *prev = NULL, *tmp = DWRoot; |
8682 ULONG message; | 8677 ULONG message; |
8683 | 8678 |
8684 if(!window || !signame || (message = _dw_findsigmessage(signame)) == 0) | 8679 if(!window || !signame || (message = _dw_findsigmessage(signame)) == 0) |
8685 return; | 8680 return; |
8686 | 8681 |
8701 free(tmp); | 8696 free(tmp); |
8702 tmp = prev->next; | 8697 tmp = prev->next; |
8703 } | 8698 } |
8704 else | 8699 else |
8705 { | 8700 { |
8706 Root = tmp->next; | 8701 DWRoot = tmp->next; |
8707 free(tmp); | 8702 free(tmp); |
8708 tmp = Root; | 8703 tmp = DWRoot; |
8709 } | 8704 } |
8710 } | 8705 } |
8711 else | 8706 else |
8712 { | 8707 { |
8713 prev = tmp; | 8708 prev = tmp; |
8721 * Parameters: | 8716 * Parameters: |
8722 * window: Window handle of callback to be removed. | 8717 * window: Window handle of callback to be removed. |
8723 */ | 8718 */ |
8724 void API dw_signal_disconnect_by_window(HWND window) | 8719 void API dw_signal_disconnect_by_window(HWND window) |
8725 { | 8720 { |
8726 SignalHandler *prev = NULL, *tmp = Root; | 8721 SignalHandler *prev = NULL, *tmp = DWRoot; |
8727 | 8722 |
8728 while(tmp) | 8723 while(tmp) |
8729 { | 8724 { |
8730 if(tmp->window == window) | 8725 if(tmp->window == window) |
8731 { | 8726 { |
8742 free(tmp); | 8737 free(tmp); |
8743 tmp = prev->next; | 8738 tmp = prev->next; |
8744 } | 8739 } |
8745 else | 8740 else |
8746 { | 8741 { |
8747 Root = tmp->next; | 8742 DWRoot = tmp->next; |
8748 free(tmp); | 8743 free(tmp); |
8749 tmp = Root; | 8744 tmp = DWRoot; |
8750 } | 8745 } |
8751 } | 8746 } |
8752 else | 8747 else |
8753 { | 8748 { |
8754 prev = tmp; | 8749 prev = tmp; |
8763 * window: Window handle of callback to be removed. | 8758 * window: Window handle of callback to be removed. |
8764 * data: Pointer to the data to be compared against. | 8759 * data: Pointer to the data to be compared against. |
8765 */ | 8760 */ |
8766 void API dw_signal_disconnect_by_data(HWND window, void *data) | 8761 void API dw_signal_disconnect_by_data(HWND window, void *data) |
8767 { | 8762 { |
8768 SignalHandler *prev = NULL, *tmp = Root; | 8763 SignalHandler *prev = NULL, *tmp = DWRoot; |
8769 | 8764 |
8770 while(tmp) | 8765 while(tmp) |
8771 { | 8766 { |
8772 if(tmp->window == window && tmp->data == data) | 8767 if(tmp->window == window && tmp->data == data) |
8773 { | 8768 { |
8784 free(tmp); | 8779 free(tmp); |
8785 tmp = prev->next; | 8780 tmp = prev->next; |
8786 } | 8781 } |
8787 else | 8782 else |
8788 { | 8783 { |
8789 Root = tmp->next; | 8784 DWRoot = tmp->next; |
8790 free(tmp); | 8785 free(tmp); |
8791 tmp = Root; | 8786 tmp = DWRoot; |
8792 } | 8787 } |
8793 } | 8788 } |
8794 else | 8789 else |
8795 { | 8790 { |
8796 prev = tmp; | 8791 prev = tmp; |
8797 tmp = tmp->next; | 8792 tmp = tmp->next; |
8798 } | 8793 } |
8799 } | 8794 } |
8800 } | 8795 } |
8801 | 8796 |
8802 void _my_strlwr(char *buf) | 8797 void _dw_my_strlwr(char *buf) |
8803 { | 8798 { |
8804 int z, len = (int)strlen(buf); | 8799 int z, len = (int)strlen(buf); |
8805 | 8800 |
8806 for(z=0;z<len;z++) | 8801 for(z=0;z<len;z++) |
8807 { | 8802 { |
8834 | 8829 |
8835 if(!newname) | 8830 if(!newname) |
8836 return -1; | 8831 return -1; |
8837 | 8832 |
8838 sprintf(newname, "lib%s.dylib", name); | 8833 sprintf(newname, "lib%s.dylib", name); |
8839 _my_strlwr(newname); | 8834 _dw_my_strlwr(newname); |
8840 | 8835 |
8841 *handle = dlopen(newname, RTLD_NOW); | 8836 *handle = dlopen(newname, RTLD_NOW); |
8842 if(*handle == NULL) | 8837 if(*handle == NULL) |
8843 { | 8838 { |
8844 strncpy(errorbuf, dlerror(), 1024); | 8839 strncpy(errorbuf, dlerror(), 1024); |
9085 struct _seminfo { | 9080 struct _seminfo { |
9086 int fd; | 9081 int fd; |
9087 int waiting; | 9082 int waiting; |
9088 }; | 9083 }; |
9089 | 9084 |
9090 static void _handle_sem(int *tmpsock) | 9085 static void _dw_handle_sem(int *tmpsock) |
9091 { | 9086 { |
9092 fd_set rd; | 9087 fd_set rd; |
9093 struct _seminfo *array = (struct _seminfo *)malloc(sizeof(struct _seminfo)); | 9088 struct _seminfo *array = (struct _seminfo *)malloc(sizeof(struct _seminfo)); |
9094 int listenfd = tmpsock[0]; | 9089 int listenfd = tmpsock[0]; |
9095 int bytesread, connectcount = 1, maxfd, z, posted = 0; | 9090 int bytesread, connectcount = 1, maxfd, z, posted = 0; |
9294 free(eve); | 9289 free(eve); |
9295 return NULL; | 9290 return NULL; |
9296 } | 9291 } |
9297 | 9292 |
9298 /* Create a thread to handle this event semaphore */ | 9293 /* Create a thread to handle this event semaphore */ |
9299 pthread_create(&dwthread, NULL, (void *)_handle_sem, (void *)tmpsock); | 9294 pthread_create(&dwthread, NULL, (void *)_dw_handle_sem, (void *)tmpsock); |
9300 eve->alive = ev; | 9295 eve->alive = ev; |
9301 return eve; | 9296 return eve; |
9302 } | 9297 } |
9303 | 9298 |
9304 /* Open an already existing named event semaphore. | 9299 /* Open an already existing named event semaphore. |
9430 * an open or create call. | 9425 * an open or create call. |
9431 */ | 9426 */ |
9432 int dw_named_event_close(HEV eve) | 9427 int dw_named_event_close(HEV eve) |
9433 { | 9428 { |
9434 /* Finally close the domain socket, | 9429 /* Finally close the domain socket, |
9435 * cleanup will continue in _handle_sem. | 9430 * cleanup will continue in _dw_handle_sem. |
9436 */ | 9431 */ |
9437 if(eve) | 9432 if(eve) |
9438 { | 9433 { |
9439 close(eve->alive); | 9434 close(eve->alive); |
9440 free(eve); | 9435 free(eve); |
9478 /* Release the pool when we are done so we don't leak */ | 9473 /* Release the pool when we are done so we don't leak */ |
9479 color = pthread_getspecific(_dw_fg_color_key); | 9474 color = pthread_getspecific(_dw_fg_color_key); |
9480 [color release]; | 9475 [color release]; |
9481 color = pthread_getspecific(_dw_bg_color_key); | 9476 color = pthread_getspecific(_dw_bg_color_key); |
9482 [color release]; | 9477 [color release]; |
9483 pool = pthread_getspecific(_dw_pool_key); | 9478 NSAutoreleasePool *pool = pthread_getspecific(_dw_pool_key); |
9484 [pool drain]; | 9479 [pool drain]; |
9485 } | 9480 } |
9486 | 9481 |
9487 /* | 9482 /* |
9488 * Setup thread independent pools. | 9483 * Setup thread independent pools. |
9598 /* Create the application object */ | 9593 /* Create the application object */ |
9599 _dw_app_init(); | 9594 _dw_app_init(); |
9600 /* Create object for handling timers */ | 9595 /* Create object for handling timers */ |
9601 DWHandler = [[DWTimerHandler alloc] init]; | 9596 DWHandler = [[DWTimerHandler alloc] init]; |
9602 pthread_key_create(&_dw_pool_key, NULL); | 9597 pthread_key_create(&_dw_pool_key, NULL); |
9603 pool = [[NSAutoreleasePool alloc] init]; | 9598 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
9604 pthread_setspecific(_dw_pool_key, pool); | 9599 pthread_setspecific(_dw_pool_key, pool); |
9605 pthread_key_create(&_dw_fg_color_key, NULL); | 9600 pthread_key_create(&_dw_fg_color_key, NULL); |
9606 pthread_key_create(&_dw_bg_color_key, NULL); | 9601 pthread_key_create(&_dw_bg_color_key, NULL); |
9607 _dw_init_colors(); | 9602 _dw_init_colors(); |
9608 DWObj = [[DWObject alloc] init]; | 9603 DWObj = [[DWObject alloc] init]; |