comparison mac/dw.m @ 2392:9fcc9ee25c4b

Mac: Prefix any global internal functions or variables with _dw or make them static to prevent global namespace polution. Done on Mac, iOS and GTK4... Will do GTK2/3 in the future, not necessary on OS/2 and Windows due to explicit exports... but may do it there too in the future.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 25 Mar 2021 07:34:13 +0000
parents 6feefce31675
children e0c63f2cbdbf
comparison
equal deleted inserted replaced
2391:a7bfb97fd80e 2392:9fcc9ee25c4b
357 HMTX DWThreadMutex; 357 HMTX DWThreadMutex;
358 HMTX DWThreadMutex2; 358 HMTX DWThreadMutex2;
359 DWTID _dw_mutex_locked = (DWTID)-1; 359 DWTID _dw_mutex_locked = (DWTID)-1;
360 #endif 360 #endif
361 361
362 unsigned long _colors[] = 362 unsigned long _dw_colors[] =
363 { 363 {
364 0x00000000, /* 0 black */ 364 0x00000000, /* 0 black */
365 0x000000bb, /* 1 red */ 365 0x000000bb, /* 1 red */
366 0x0000bb00, /* 2 green */ 366 0x0000bb00, /* 2 green */
367 0x0000aaaa, /* 3 yellow */ 367 0x0000aaaa, /* 3 yellow */
382 382
383 /* 383 /*
384 * List those icons that have transparency first 384 * List those icons that have transparency first
385 */ 385 */
386 #define NUM_EXTS 8 386 #define NUM_EXTS 8
387 char *image_exts[NUM_EXTS] = 387 char *_dw_image_exts[NUM_EXTS+1] =
388 { 388 {
389 ".png", 389 ".png",
390 ".ico", 390 ".ico",
391 ".icns", 391 ".icns",
392 ".gif", 392 ".gif",
393 ".jpg", 393 ".jpg",
394 ".jpeg", 394 ".jpeg",
395 ".tiff", 395 ".tiff",
396 ".bmp" 396 ".bmp",
397 NULL
397 }; 398 };
398 399
399 char *_dw_get_image_extension(const char *filename) 400 char *_dw_get_image_extension(const char *filename)
400 { 401 {
401 char *file = alloca(strlen(filename) + 6); 402 char *file = alloca(strlen(filename) + 6);
403 404
404 /* Try various extentions */ 405 /* Try various extentions */
405 for ( i = 0; i < NUM_EXTS; i++ ) 406 for ( i = 0; i < NUM_EXTS; i++ )
406 { 407 {
407 strcpy( file, filename ); 408 strcpy( file, filename );
408 strcat( file, image_exts[i] ); 409 strcat( file, _dw_image_exts[i] );
409 if ( access( file, R_OK ) == 0 ) 410 if ( access( file, R_OK ) == 0 )
410 { 411 {
411 found_ext = 1; 412 found_ext = 1;
412 break; 413 break;
413 } 414 }
414 } 415 }
415 if ( found_ext == 1 ) 416 if ( found_ext == 1 )
416 { 417 {
417 return image_exts[i]; 418 return _dw_image_exts[i];
418 } 419 }
419 return NULL; 420 return NULL;
420 } 421 }
421 422
422 /* Return the RGB color regardless if a predefined color was passed */ 423 /* Return the RGB color regardless if a predefined color was passed */
423 unsigned long _get_color(unsigned long thiscolor) 424 unsigned long _dw_get_color(unsigned long thiscolor)
424 { 425 {
425 if(thiscolor & DW_RGB_COLOR) 426 if(thiscolor & DW_RGB_COLOR)
426 { 427 {
427 return thiscolor & ~DW_RGB_COLOR; 428 return thiscolor & ~DW_RGB_COLOR;
428 } 429 }
429 else if(thiscolor < 17) 430 else if(thiscolor < 17)
430 { 431 {
431 return _colors[thiscolor]; 432 return _dw_colors[thiscolor];
432 } 433 }
433 return 0; 434 return 0;
434 } 435 }
435 436
436 /* Returns TRUE of Mojave or later is in Dark Mode */ 437 /* Returns TRUE of Mojave or later is in Dark Mode */
437 BOOL _is_dark(id object) 438 BOOL _dw_is_dark(id object)
438 { 439 {
439 #ifdef BUILDING_FOR_MOJAVE 440 #ifdef BUILDING_FOR_MOJAVE
440 NSAppearance *appearance = [object effectiveAppearance]; 441 NSAppearance *appearance = [object effectiveAppearance];
441 442
442 if(@available(macOS 10.14, *)) 443 if(@available(macOS 10.14, *))
454 #if !defined(GARBAGE_COLLECT) 455 #if !defined(GARBAGE_COLLECT)
455 pthread_key_t _dw_pool_key; 456 pthread_key_t _dw_pool_key;
456 #endif 457 #endif
457 pthread_key_t _dw_fg_color_key; 458 pthread_key_t _dw_fg_color_key;
458 pthread_key_t _dw_bg_color_key; 459 pthread_key_t _dw_bg_color_key;
459 int DWOSMajor, DWOSMinor, DWOSBuild; 460 static int DWOSMajor, DWOSMinor, DWOSBuild;
460 static char _dw_bundle_path[PATH_MAX+1] = { 0 }; 461 static char _dw_bundle_path[PATH_MAX+1] = { 0 };
461 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; 462 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0};
462 463
463 /* Create a default colors for a thread */ 464 /* Create a default colors for a thread */
464 void _init_colors(void) 465 void _dw_init_colors(void)
465 { 466 {
466 NSColor *fgcolor = [[NSColor grayColor] retain]; 467 NSColor *fgcolor = [[NSColor grayColor] retain];
467 pthread_setspecific(_dw_fg_color_key, fgcolor); 468 pthread_setspecific(_dw_fg_color_key, fgcolor);
468 pthread_setspecific(_dw_bg_color_key, NULL); 469 pthread_setspecific(_dw_bg_color_key, NULL);
469 } 470 }
478 void *discfunction; 479 void *discfunction;
479 void *data; 480 void *data;
480 481
481 } SignalHandler; 482 } SignalHandler;
482 483
483 SignalHandler *Root = NULL; 484 static SignalHandler *DWRoot = NULL;
484 485
485 /* Some internal prototypes */ 486 /* Some internal prototypes */
486 static void _do_resize(Box *thisbox, int x, int y); 487 static void _dw_do_resize(Box *thisbox, int x, int y);
487 void _handle_resize_events(Box *thisbox); 488 void _dw_handle_resize_events(Box *thisbox);
488 int _remove_userdata(UserData **root, const char *varname, int all); 489 int _dw_remove_userdata(UserData **root, const char *varname, int all);
489 int _dw_main_iteration(NSDate *date); 490 int _dw_main_iteration(NSDate *date);
490 NSGraphicsContext *_dw_draw_context(NSBitmapImageRep *image); 491 NSGraphicsContext *_dw_draw_context(NSBitmapImageRep *image);
491 typedef id (*DWIMP)(id, SEL, ...); 492 typedef id (*DWIMP)(id, SEL, ...);
492 493
493 /* Internal function to queue a window redraw */ 494 /* Internal function to queue a window redraw */
504 { 505 {
505 dw_window_redraw(redraw); 506 dw_window_redraw(redraw);
506 } 507 }
507 } 508 }
508 509
509 SignalHandler *_get_handler(HWND window, int messageid) 510 SignalHandler *_dw_get_handler(HWND window, int messageid)
510 { 511 {
511 SignalHandler *tmp = Root; 512 SignalHandler *tmp = DWRoot;
512 513
513 /* Find any callbacks for this function */ 514 /* Find any callbacks for this function */
514 while(tmp) 515 while(tmp)
515 { 516 {
516 if(tmp->message == messageid && window == tmp->window) 517 if(tmp->message == messageid && window == tmp->window)
530 } SignalList; 531 } SignalList;
531 532
532 /* List of signals */ 533 /* List of signals */
533 #define SIGNALMAX 19 534 #define SIGNALMAX 19
534 535
535 SignalList SignalTranslate[SIGNALMAX] = { 536 static SignalList DWSignalTranslate[SIGNALMAX] = {
536 { 1, DW_SIGNAL_CONFIGURE }, 537 { 1, DW_SIGNAL_CONFIGURE },
537 { 2, DW_SIGNAL_KEY_PRESS }, 538 { 2, DW_SIGNAL_KEY_PRESS },
538 { 3, DW_SIGNAL_BUTTON_PRESS }, 539 { 3, DW_SIGNAL_BUTTON_PRESS },
539 { 4, DW_SIGNAL_BUTTON_RELEASE }, 540 { 4, DW_SIGNAL_BUTTON_RELEASE },
540 { 5, DW_SIGNAL_MOTION_NOTIFY }, 541 { 5, DW_SIGNAL_MOTION_NOTIFY },
552 { 17, DW_SIGNAL_COLUMN_CLICK }, 553 { 17, DW_SIGNAL_COLUMN_CLICK },
553 { 18, DW_SIGNAL_HTML_RESULT }, 554 { 18, DW_SIGNAL_HTML_RESULT },
554 { 19, DW_SIGNAL_HTML_CHANGED } 555 { 19, DW_SIGNAL_HTML_CHANGED }
555 }; 556 };
556 557
557 int _event_handler1(id object, NSEvent *event, int message) 558 int _dw_event_handler1(id object, NSEvent *event, int message)
558 { 559 {
559 SignalHandler *handler = _get_handler(object, message); 560 SignalHandler *handler = _dw_get_handler(object, message);
560 /* NSLog(@"Event handler - type %d\n", message); */ 561 /* NSLog(@"Event handler - type %d\n", message); */
561 562
562 if(handler) 563 if(handler)
563 { 564 {
564 switch(message) 565 switch(message)
823 } 824 }
824 return -1; 825 return -1;
825 } 826 }
826 827
827 /* Sub function to handle redraws */ 828 /* Sub function to handle redraws */
828 int _event_handler(id object, NSEvent *event, int message) 829 int _dw_event_handler(id object, NSEvent *event, int message)
829 { 830 {
830 int ret = _event_handler1(object, event, message); 831 int ret = _dw_event_handler1(object, event, message);
831 if(ret != -1) 832 if(ret != -1)
832 _dw_redraw(nil, FALSE); 833 _dw_redraw(nil, FALSE);
833 return ret; 834 return ret;
834 } 835 }
835 836
837 @interface DWTimerHandler : NSObject { } 838 @interface DWTimerHandler : NSObject { }
838 -(void)runTimer:(id)sender; 839 -(void)runTimer:(id)sender;
839 @end 840 @end
840 841
841 @implementation DWTimerHandler 842 @implementation DWTimerHandler
842 -(void)runTimer:(id)sender { _event_handler(sender, nil, 0); } 843 -(void)runTimer:(id)sender { _dw_event_handler(sender, nil, 0); }
843 @end 844 @end
844 845
845 NSApplication *DWApp = nil; 846 static NSApplication *DWApp = nil;
846 NSFontManager *DWFontManager = nil; 847 static NSFontManager *DWFontManager = nil;
847 NSMenu *DWMainMenu; 848 static NSMenu *DWMainMenu;
848 NSFont *DWDefaultFont; 849 static NSFont *DWDefaultFont;
849 DWTimerHandler *DWHandler; 850 static DWTimerHandler *DWHandler;
850 #if !defined(GARBAGE_COLLECT) 851 #ifdef BUILDING_FOR_MOJAVE
851 NSAutoreleasePool *pool; 852 static NSMutableArray *_DWDirtyDrawables;
853 #else
854 static HWND _DWLastDrawable;
852 #endif 855 #endif
853 #ifdef BUILDING_FOR_MOJAVE 856 static DWTID DWThread = (DWTID)-1;
854 NSMutableArray *_DWDirtyDrawables;
855 #else
856 HWND _DWLastDrawable;
857 #endif
858 DWTID DWThread = (DWTID)-1;
859 857
860 /* Send fake event to make sure the loop isn't stuck */ 858 /* Send fake event to make sure the loop isn't stuck */
861 void _dw_wakeup_app() 859 void _dw_wakeup_app()
862 { 860 {
863 [DWApp postEvent:[NSEvent otherEventWithType:DWEventTypeApplicationDefined 861 [DWApp postEvent:[NSEvent otherEventWithType:DWEventTypeApplicationDefined
958 { 956 {
959 UserData *root = userdata; 957 UserData *root = userdata;
960 if(box->items) 958 if(box->items)
961 free(box->items); 959 free(box->items);
962 free(box); 960 free(box);
963 _remove_userdata(&root, NULL, TRUE); 961 _dw_remove_userdata(&root, NULL, TRUE);
964 dw_signal_disconnect_by_window(self); 962 dw_signal_disconnect_by_window(self);
965 [super dealloc]; 963 [super dealloc];
966 } 964 }
967 -(Box *)box { return box; } 965 -(Box *)box { return box; }
968 -(id)contentView { return self; } 966 -(id)contentView { return self; }
975 [bgcolor set]; 973 [bgcolor set];
976 NSRectFill([self bounds]); 974 NSRectFill([self bounds]);
977 } 975 }
978 } 976 }
979 -(BOOL)isFlipped { return YES; } 977 -(BOOL)isFlipped { return YES; }
980 -(void)mouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)1, 3); } 978 -(void)mouseDown:(NSEvent *)theEvent { _dw_event_handler(self, (void *)1, 3); }
981 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)1, 4); } 979 -(void)mouseUp:(NSEvent *)theEvent { _dw_event_handler(self, (void *)1, 4); }
982 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } 980 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _dw_event_handler(self, (void *)2, 3); return nil; }
983 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)2, 4); } 981 -(void)rightMouseUp:(NSEvent *)theEvent { _dw_event_handler(self, (void *)2, 4); }
984 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); } 982 -(void)otherMouseDown:(NSEvent *)theEvent { _dw_event_handler(self, (void *)3, 3); }
985 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); } 983 -(void)otherMouseUp:(NSEvent *)theEvent { _dw_event_handler(self, (void *)3, 4); }
986 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); } 984 -(void)keyDown:(NSEvent *)theEvent { _dw_event_handler(self, theEvent, 2); }
987 -(void)setColor:(unsigned long)input 985 -(void)setColor:(unsigned long)input
988 { 986 {
989 id orig = bgcolor; 987 id orig = bgcolor;
990 988
991 if(input == _colors[DW_CLR_DEFAULT]) 989 if(input == _dw_colors[DW_CLR_DEFAULT])
992 { 990 {
993 bgcolor = nil; 991 bgcolor = nil;
994 } 992 }
995 else 993 else
996 { 994 {
1063 -(void)sendEvent:(NSEvent *)theEvent 1061 -(void)sendEvent:(NSEvent *)theEvent
1064 { 1062 {
1065 int rcode = -1; 1063 int rcode = -1;
1066 if([theEvent type] == DWEventTypeKeyDown) 1064 if([theEvent type] == DWEventTypeKeyDown)
1067 { 1065 {
1068 rcode = _event_handler(self, theEvent, 2); 1066 rcode = _dw_event_handler(self, theEvent, 2);
1069 } 1067 }
1070 if ( rcode != TRUE ) 1068 if ( rcode != TRUE )
1071 [super sendEvent:theEvent]; 1069 [super sendEvent:theEvent];
1072 } 1070 }
1073 -(void)keyDown:(NSEvent *)theEvent { } 1071 -(void)keyDown:(NSEvent *)theEvent { }
1074 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } 1072 -(void)mouseDragged:(NSEvent *)theEvent { _dw_event_handler(self, theEvent, 5); }
1075 -(int)redraw { return redraw; } 1073 -(int)redraw { return redraw; }
1076 -(void)setRedraw:(int)val { redraw = val; } 1074 -(void)setRedraw:(int)val { redraw = val; }
1077 -(int)shown { return shown; } 1075 -(int)shown { return shown; }
1078 -(void)setShown:(int)val { shown = val; } 1076 -(void)setShown:(int)val { shown = val; }
1079 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; } 1077 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; }
1141 } 1139 }
1142 #endif 1140 #endif
1143 -(void)mouseDown:(NSEvent *)theEvent 1141 -(void)mouseDown:(NSEvent *)theEvent
1144 { 1142 {
1145 if(![theEvent isMemberOfClass:[NSEvent class]] || !([theEvent modifierFlags] & DWEventModifierFlagControl)) 1143 if(![theEvent isMemberOfClass:[NSEvent class]] || !([theEvent modifierFlags] & DWEventModifierFlagControl))
1146 _event_handler(self, theEvent, 3); 1144 _dw_event_handler(self, theEvent, 3);
1147 } 1145 }
1148 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } 1146 -(void)mouseUp:(NSEvent *)theEvent { _dw_event_handler(self, theEvent, 4); }
1149 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } 1147 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _dw_event_handler(self, theEvent, 3); return nil; }
1150 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } 1148 -(void)rightMouseUp:(NSEvent *)theEvent { _dw_event_handler(self, theEvent, 4); }
1151 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); } 1149 -(void)otherMouseDown:(NSEvent *)theEvent { _dw_event_handler(self, theEvent, 3); }
1152 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } 1150 -(void)otherMouseUp:(NSEvent *)theEvent { _dw_event_handler(self, theEvent, 4); }
1153 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } 1151 -(void)mouseDragged:(NSEvent *)theEvent { _dw_event_handler(self, theEvent, 5); }
1154 -(void)delayedNeedsDisplay { [self setNeedsDisplay:YES]; } 1152 -(void)delayedNeedsDisplay { [self setNeedsDisplay:YES]; }
1155 -(void)drawRect:(NSRect)rect { 1153 -(void)drawRect:(NSRect)rect {
1156 _event_handler(self, nil, 7); 1154 _dw_event_handler(self, nil, 7);
1157 #ifdef BUILDING_FOR_MOJAVE 1155 #ifdef BUILDING_FOR_MOJAVE
1158 if (cachedDrawingRep) 1156 if (cachedDrawingRep)
1159 { 1157 {
1160 [cachedDrawingRep drawInRect:self.bounds]; 1158 [cachedDrawingRep drawInRect:self.bounds];
1161 [_DWDirtyDrawables removeObject:self]; 1159 [_DWDirtyDrawables removeObject:self];
1165 else 1163 else
1166 [self performSelector:@selector(delayedNeedsDisplay) withObject:nil afterDelay:0]; 1164 [self performSelector:@selector(delayedNeedsDisplay) withObject:nil afterDelay:0];
1167 } 1165 }
1168 #endif 1166 #endif
1169 } 1167 }
1170 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); } 1168 -(void)keyDown:(NSEvent *)theEvent { _dw_event_handler(self, theEvent, 2); }
1171 -(BOOL)isFlipped { return YES; } 1169 -(BOOL)isFlipped { return YES; }
1172 -(void)dealloc { 1170 -(void)dealloc {
1173 UserData *root = userdata; 1171 UserData *root = userdata;
1174 _remove_userdata(&root, NULL, TRUE); 1172 _dw_remove_userdata(&root, NULL, TRUE);
1175 [font release]; 1173 [font release];
1176 dw_signal_disconnect_by_window(self); 1174 dw_signal_disconnect_by_window(self);
1177 #ifdef BUILDING_FOR_MOJAVE 1175 #ifdef BUILDING_FOR_MOJAVE
1178 [cachedDrawingRep release]; 1176 [cachedDrawingRep release];
1179 [_DWDirtyDrawables removeObject:self]; 1177 [_DWDirtyDrawables removeObject:self];
1202 if([item state] == DWControlStateValueOn) 1200 if([item state] == DWControlStateValueOn)
1203 [item setState:DWControlStateValueOff]; 1201 [item setState:DWControlStateValueOff];
1204 else 1202 else
1205 [item setState:DWControlStateValueOn]; 1203 [item setState:DWControlStateValueOn];
1206 } 1204 }
1207 _event_handler(param, nil, 8); 1205 _dw_event_handler(param, nil, 8);
1208 } 1206 }
1209 #ifdef BUILDING_FOR_MOJAVE 1207 #ifdef BUILDING_FOR_MOJAVE
1210 -(void)callBack:(NSPointerArray *)params 1208 -(void)callBack:(NSPointerArray *)params
1211 { 1209 {
1212 void (*mycallback)(NSPointerArray *) = [params pointerAtIndex:0]; 1210 void (*mycallback)(NSPointerArray *) = [params pointerAtIndex:0];
1394 -(void *)userdata { return userdata; } 1392 -(void *)userdata { return userdata; }
1395 -(void)setUserdata:(void *)input { userdata = input; } 1393 -(void)setUserdata:(void *)input { userdata = input; }
1396 -(void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation 1394 -(void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation
1397 { 1395 {
1398 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), [[self URL] absoluteString] }; 1396 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), [[self URL] absoluteString] };
1399 _event_handler(self, (NSEvent *)params, 19); 1397 _dw_event_handler(self, (NSEvent *)params, 19);
1400 } 1398 }
1401 -(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation 1399 -(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
1402 { 1400 {
1403 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), [[self URL] absoluteString] }; 1401 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), [[self URL] absoluteString] };
1404 _event_handler(self, (NSEvent *)params, 19); 1402 _dw_event_handler(self, (NSEvent *)params, 19);
1405 } 1403 }
1406 -(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation 1404 -(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
1407 { 1405 {
1408 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), [[self URL] absoluteString] }; 1406 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), [[self URL] absoluteString] };
1409 _event_handler(self, (NSEvent *)params, 19); 1407 _dw_event_handler(self, (NSEvent *)params, 19);
1410 } 1408 }
1411 -(void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation 1409 -(void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation
1412 { 1410 {
1413 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_REDIRECT), [[self URL] absoluteString] }; 1411 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_REDIRECT), [[self URL] absoluteString] };
1414 _event_handler(self, (NSEvent *)params, 19); 1412 _dw_event_handler(self, (NSEvent *)params, 19);
1415 } 1413 }
1416 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1414 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1417 @end 1415 @end
1418 #else 1416 #else
1419 @interface DWWebView : WebView 1417 @interface DWWebView : WebView
1420 { 1418 {
1421 void *userdata; 1419 void *userdata;
1431 -(void *)userdata { return userdata; } 1429 -(void *)userdata { return userdata; }
1432 -(void)setUserdata:(void *)input { userdata = input; } 1430 -(void)setUserdata:(void *)input { userdata = input; }
1433 -(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame 1431 -(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
1434 { 1432 {
1435 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), [self mainFrameURL] }; 1433 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), [self mainFrameURL] };
1436 _event_handler(self, (NSEvent *)params, 19); 1434 _dw_event_handler(self, (NSEvent *)params, 19);
1437 } 1435 }
1438 -(void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame 1436 -(void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame
1439 { 1437 {
1440 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), [self mainFrameURL] }; 1438 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), [self mainFrameURL] };
1441 _event_handler(self, (NSEvent *)params, 19); 1439 _dw_event_handler(self, (NSEvent *)params, 19);
1442 } 1440 }
1443 -(void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame 1441 -(void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
1444 { 1442 {
1445 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), [self mainFrameURL] }; 1443 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), [self mainFrameURL] };
1446 _event_handler(self, (NSEvent *)params, 19); 1444 _dw_event_handler(self, (NSEvent *)params, 19);
1447 } 1445 }
1448 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1446 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1449 @end 1447 @end
1450 #endif 1448 #endif
1451 1449
1452 1450
1453 @implementation DWAppDel 1451 @implementation DWAppDel
1454 -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender 1452 -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
1455 { 1453 {
1456 if(_event_handler(sender, nil, 6) > 0) 1454 if(_dw_event_handler(sender, nil, 6) > 0)
1457 return NSTerminateCancel; 1455 return NSTerminateCancel;
1458 return NSTerminateNow; 1456 return NSTerminateNow;
1459 } 1457 }
1460 #if defined(BUILDING_FOR_MOUNTAIN_LION) && !defined(BUILDING_FOR_BIG_SUR) 1458 #if defined(BUILDING_FOR_MOUNTAIN_LION) && !defined(BUILDING_FOR_BIG_SUR)
1461 -(void)applicationDidFinishLaunching:(NSNotification *)aNotification 1459 -(void)applicationDidFinishLaunching:(NSNotification *)aNotification
1485 notification = DW_UINT_TO_POINTER(handle); 1483 notification = DW_UINT_TO_POINTER(handle);
1486 1484
1487 switch(usernotification.activationType) 1485 switch(usernotification.activationType)
1488 { 1486 {
1489 case NSUserNotificationActivationTypeContentsClicked: 1487 case NSUserNotificationActivationTypeContentsClicked:
1490 _event_handler(notification, nil, 8); 1488 _dw_event_handler(notification, nil, 8);
1491 break; 1489 break;
1492 default: 1490 default:
1493 break; 1491 break;
1494 } 1492 }
1495 dw_signal_disconnect_by_window(notification); 1493 dw_signal_disconnect_by_window(notification);
1514 @end 1512 @end
1515 1513
1516 @implementation DWView 1514 @implementation DWView
1517 -(BOOL)windowShouldClose:(id)sender 1515 -(BOOL)windowShouldClose:(id)sender
1518 { 1516 {
1519 if(_event_handler(sender, nil, 6) > 0) 1517 if(_dw_event_handler(sender, nil, 6) > 0)
1520 return NO; 1518 return NO;
1521 return YES; 1519 return YES;
1522 } 1520 }
1523 -(void)viewDidMoveToWindow 1521 -(void)viewDidMoveToWindow
1524 { 1522 {
1539 { 1537 {
1540 NSSize size = [self frame].size; 1538 NSSize size = [self frame].size;
1541 1539
1542 if(oldsize.width != size.width || oldsize.height != size.height) 1540 if(oldsize.width != size.width || oldsize.height != size.height)
1543 { 1541 {
1544 _do_resize(box, size.width, size.height); 1542 _dw_do_resize(box, size.width, size.height);
1545 _event_handler([self window], nil, 1); 1543 _dw_event_handler([self window], nil, 1);
1546 oldsize.width = size.width; 1544 oldsize.width = size.width;
1547 oldsize.height = size.height; 1545 oldsize.height = size.height;
1548 _handle_resize_events(box); 1546 _dw_handle_resize_events(box);
1549 } 1547 }
1550 } 1548 }
1551 -(void)showWindow 1549 -(void)showWindow
1552 { 1550 {
1553 NSSize size = [self frame].size; 1551 NSSize size = [self frame].size;
1554 1552
1555 if(oldsize.width == size.width && oldsize.height == size.height) 1553 if(oldsize.width == size.width && oldsize.height == size.height)
1556 { 1554 {
1557 _do_resize(box, size.width, size.height); 1555 _dw_do_resize(box, size.width, size.height);
1558 _handle_resize_events(box); 1556 _dw_handle_resize_events(box);
1559 } 1557 }
1560 1558
1561 } 1559 }
1562 -(void)windowDidBecomeMain:(id)sender 1560 -(void)windowDidBecomeMain:(id)sender
1563 { 1561 {
1567 } 1565 }
1568 else 1566 else
1569 { 1567 {
1570 [DWApp setMainMenu:DWMainMenu]; 1568 [DWApp setMainMenu:DWMainMenu];
1571 } 1569 }
1572 _event_handler([self window], nil, 13); 1570 _dw_event_handler([self window], nil, 13);
1573 } 1571 }
1574 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; } 1572 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; }
1575 -(void)menuHandler:(id)sender 1573 -(void)menuHandler:(id)sender
1576 { 1574 {
1577 id menu = [sender menu]; 1575 id menu = [sender menu];
1587 [DWObj performSelector:@selector(menuHandler:) withObject:sender afterDelay:0]; 1585 [DWObj performSelector:@selector(menuHandler:) withObject:sender afterDelay:0];
1588 else 1586 else
1589 [DWObj menuHandler:sender]; 1587 [DWObj menuHandler:sender];
1590 _dw_wakeup_app(); 1588 _dw_wakeup_app();
1591 } 1589 }
1592 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } 1590 -(void)mouseDragged:(NSEvent *)theEvent { _dw_event_handler(self, theEvent, 5); }
1593 -(void)mouseMoved:(NSEvent *)theEvent 1591 -(void)mouseMoved:(NSEvent *)theEvent
1594 { 1592 {
1595 id hit = [self hitTest:[theEvent locationInWindow]]; 1593 id hit = [self hitTest:[theEvent locationInWindow]];
1596 1594
1597 if([hit isMemberOfClass:[DWRender class]]) 1595 if([hit isMemberOfClass:[DWRender class]])
1598 { 1596 {
1599 _event_handler(hit, theEvent, 5); 1597 _dw_event_handler(hit, theEvent, 5);
1600 } 1598 }
1601 } 1599 }
1602 @end 1600 @end
1603 1601
1604 /* Subclass for a button type */ 1602 /* Subclass for a button type */
1622 @implementation DWButton 1620 @implementation DWButton
1623 -(void *)userdata { return userdata; } 1621 -(void *)userdata { return userdata; }
1624 -(void)setUserdata:(void *)input { userdata = input; } 1622 -(void)setUserdata:(void *)input { userdata = input; }
1625 -(void)buttonClicked:(id)sender 1623 -(void)buttonClicked:(id)sender
1626 { 1624 {
1627 _event_handler(self, nil, 8); 1625 _dw_event_handler(self, nil, 8);
1628 if([self buttonType] == DWButtonTypeRadio) 1626 if([self buttonType] == DWButtonTypeRadio)
1629 { 1627 {
1630 DWBox *viewbox = [self parent]; 1628 DWBox *viewbox = [self parent];
1631 Box *thisbox = [viewbox box]; 1629 Box *thisbox = [viewbox box];
1632 int z; 1630 int z;
1696 [super keyDown:theEvent]; 1694 [super keyDown:theEvent];
1697 } 1695 }
1698 } 1696 }
1699 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; } 1697 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; }
1700 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; } 1698 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; }
1701 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1699 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1702 @end 1700 @end
1703 1701
1704 /* Subclass for a progress type */ 1702 /* Subclass for a progress type */
1705 @interface DWPercent : NSProgressIndicator 1703 @interface DWPercent : NSProgressIndicator
1706 { 1704 {
1711 @end 1709 @end
1712 1710
1713 @implementation DWPercent 1711 @implementation DWPercent
1714 -(void *)userdata { return userdata; } 1712 -(void *)userdata { return userdata; }
1715 -(void)setUserdata:(void *)input { userdata = input; } 1713 -(void)setUserdata:(void *)input { userdata = input; }
1716 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1714 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1717 @end 1715 @end
1718 1716
1719 /* Subclass for a menu item type */ 1717 /* Subclass for a menu item type */
1720 @implementation DWMenuItem 1718 @implementation DWMenuItem
1721 -(void)setCheck:(int)input { check = input; } 1719 -(void)setCheck:(int)input { check = input; }
1738 @implementation DWScrollBox 1736 @implementation DWScrollBox
1739 -(void *)userdata { return userdata; } 1737 -(void *)userdata { return userdata; }
1740 -(void)setUserdata:(void *)input { userdata = input; } 1738 -(void)setUserdata:(void *)input { userdata = input; }
1741 -(void)setBox:(void *)input { box = input; } 1739 -(void)setBox:(void *)input { box = input; }
1742 -(id)box { return box; } 1740 -(id)box { return box; }
1743 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1741 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1744 @end 1742 @end
1745 1743
1746 /* Subclass for a textfield that supports vertical centering */ 1744 /* Subclass for a textfield that supports vertical centering */
1747 @interface DWTextFieldCell : NSTextFieldCell 1745 @interface DWTextFieldCell : NSTextFieldCell
1748 { 1746 {
1857 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"a"]) 1855 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"a"])
1858 return [NSApp sendAction:@selector(selectAll:) to:[[self window] firstResponder] from:self]; 1856 return [NSApp sendAction:@selector(selectAll:) to:[[self window] firstResponder] from:self];
1859 } 1857 }
1860 return [super performKeyEquivalent:theEvent]; 1858 return [super performKeyEquivalent:theEvent];
1861 } 1859 }
1862 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1860 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1863 @end 1861 @end
1864 1862
1865 /* Subclass for a text and status text type */ 1863 /* Subclass for a text and status text type */
1866 @interface DWText : NSTextField 1864 @interface DWText : NSTextField
1867 { 1865 {
1873 @end 1871 @end
1874 1872
1875 @implementation DWText 1873 @implementation DWText
1876 -(void *)userdata { return userdata; } 1874 -(void *)userdata { return userdata; }
1877 -(void)setUserdata:(void *)input { userdata = input; } 1875 -(void)setUserdata:(void *)input { userdata = input; }
1878 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1876 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); [super dealloc]; }
1879 @end 1877 @end
1880 1878
1881 1879
1882 /* Subclass for a entryfield password type */ 1880 /* Subclass for a entryfield password type */
1883 @interface DWEntryFieldPassword : NSSecureTextField 1881 @interface DWEntryFieldPassword : NSSecureTextField
1921 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"a"]) 1919 else if ([[theEvent charactersIgnoringModifiers] isEqualToString:@"a"])
1922 return [NSApp sendAction:@selector(selectAll:) to:[[self window] firstResponder] from:self]; 1920 return [NSApp sendAction:@selector(selectAll:) to:[[self window] firstResponder] from:self];
1923 } 1921 }
1924 return [super performKeyEquivalent:theEvent]; 1922 return [super performKeyEquivalent:theEvent];
1925 } 1923 }
1926 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1924 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1927 @end 1925 @end
1928 1926
1929 /* Subclass for a Notebook control type */ 1927 /* Subclass for a Notebook control type */
1930 @interface DWNotebook : NSTabView 1928 @interface DWNotebook : NSTabView
1931 #ifdef BUILDING_FOR_SNOW_LEOPARD 1929 #ifdef BUILDING_FOR_SNOW_LEOPARD
1967 if([object isMemberOfClass:[DWBox class]]) 1965 if([object isMemberOfClass:[DWBox class]])
1968 { 1966 {
1969 DWBox *view = object; 1967 DWBox *view = object;
1970 Box *box = [view box]; 1968 Box *box = [view box];
1971 NSSize size = [view frame].size; 1969 NSSize size = [view frame].size;
1972 _do_resize(box, size.width, size.height); 1970 _dw_do_resize(box, size.width, size.height);
1973 _handle_resize_events(box); 1971 _dw_handle_resize_events(box);
1974 } 1972 }
1975 _event_handler(self, DW_INT_TO_POINTER([page pageid]), 15); 1973 _dw_event_handler(self, DW_INT_TO_POINTER([page pageid]), 15);
1976 } 1974 }
1977 -(void)keyDown:(NSEvent *)theEvent 1975 -(void)keyDown:(NSEvent *)theEvent
1978 { 1976 {
1979 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; 1977 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
1980 1978
2013 } 2011 }
2014 [super keyDown:theEvent]; 2012 [super keyDown:theEvent];
2015 } 2013 }
2016 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; } 2014 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; }
2017 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; } 2015 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; }
2018 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 2016 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2019 @end 2017 @end
2020 2018
2021 @implementation DWNotebookPage 2019 @implementation DWNotebookPage
2022 -(void *)userdata { return userdata; } 2020 -(void *)userdata { return userdata; }
2023 -(void)setUserdata:(void *)input { userdata = input; } 2021 -(void)setUserdata:(void *)input { userdata = input; }
2024 -(int)pageid { return pageid; } 2022 -(int)pageid { return pageid; }
2025 -(void)setPageid:(int)input { pageid = input; } 2023 -(void)setPageid:(int)input { pageid = input; }
2026 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 2024 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2027 @end 2025 @end
2028 2026
2029 /* Subclass for a color chooser type */ 2027 /* Subclass for a color chooser type */
2030 @interface DWColorChoose : NSColorPanel 2028 @interface DWColorChoose : NSColorPanel
2031 { 2029 {
2111 if([object isMemberOfClass:[DWBox class]]) 2109 if([object isMemberOfClass:[DWBox class]])
2112 { 2110 {
2113 DWBox *view = object; 2111 DWBox *view = object;
2114 Box *box = [view box]; 2112 Box *box = [view box];
2115 NSSize size = [view frame].size; 2113 NSSize size = [view frame].size;
2116 _do_resize(box, size.width, size.height); 2114 _dw_do_resize(box, size.width, size.height);
2117 _handle_resize_events(box); 2115 _dw_handle_resize_events(box);
2118 } 2116 }
2119 } 2117 }
2120 } 2118 }
2121 -(void)setTag:(NSInteger)tag { Tag = tag; } 2119 -(void)setTag:(NSInteger)tag { Tag = tag; }
2122 -(void *)userdata { return userdata; } 2120 -(void *)userdata { return userdata; }
2123 -(void)setUserdata:(void *)input { userdata = input; } 2121 -(void)setUserdata:(void *)input { userdata = input; }
2124 -(float)percent { return percent; } 2122 -(float)percent { return percent; }
2125 -(void)setPercent:(float)input { percent = input; } 2123 -(void)setPercent:(float)input { percent = input; }
2126 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 2124 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2127 @end 2125 @end
2128 2126
2129 /* Subclass for a slider type */ 2127 /* Subclass for a slider type */
2130 @interface DWSlider : NSSlider 2128 @interface DWSlider : NSSlider
2131 { 2129 {
2137 @end 2135 @end
2138 2136
2139 @implementation DWSlider 2137 @implementation DWSlider
2140 -(void *)userdata { return userdata; } 2138 -(void *)userdata { return userdata; }
2141 -(void)setUserdata:(void *)input { userdata = input; } 2139 -(void)setUserdata:(void *)input { userdata = input; }
2142 -(void)sliderChanged:(id)sender { _event_handler(self, (void *)[self integerValue], 14); } 2140 -(void)sliderChanged:(id)sender { _dw_event_handler(self, (void *)[self integerValue], 14); }
2143 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 2141 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2144 @end 2142 @end
2145 2143
2146 /* Subclass for a slider type */ 2144 /* Subclass for a slider type */
2147 @interface DWScrollbar : NSScroller 2145 @interface DWScrollbar : NSScroller
2148 { 2146 {
2215 newpos = (newpos - (double)newposi) > 0.5 ? (double)(newposi + 1) : (double)newposi; 2213 newpos = (newpos - (double)newposi) > 0.5 ? (double)(newposi + 1) : (double)newposi;
2216 if(newpos != result) 2214 if(newpos != result)
2217 { 2215 {
2218 [self setDoubleValue:(newpos/max)]; 2216 [self setDoubleValue:(newpos/max)];
2219 } 2217 }
2220 _event_handler(self, DW_INT_TO_POINTER((int)newpos), 14); 2218 _dw_event_handler(self, DW_INT_TO_POINTER((int)newpos), 14);
2221 } 2219 }
2222 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 2220 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2223 @end 2221 @end
2224 2222
2225 /* Subclass for a MLE type */ 2223 /* Subclass for a MLE type */
2226 @interface DWMLE : NSTextView 2224 @interface DWMLE : NSTextView
2227 { 2225 {
2237 @implementation DWMLE 2235 @implementation DWMLE
2238 -(void *)userdata { return userdata; } 2236 -(void *)userdata { return userdata; }
2239 -(void)setUserdata:(void *)input { userdata = input; } 2237 -(void)setUserdata:(void *)input { userdata = input; }
2240 -(id)scrollview { return scrollview; } 2238 -(id)scrollview { return scrollview; }
2241 -(void)setScrollview:(id)input { scrollview = input; } 2239 -(void)setScrollview:(id)input { scrollview = input; }
2242 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 2240 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2243 @end 2241 @end
2244 2242
2245 #ifndef DW_USE_NSVIEW 2243 #ifndef DW_USE_NSVIEW
2246 /* Subclass NSTextFieldCell for displaying image and text */ 2244 /* Subclass NSTextFieldCell for displaying image and text */
2247 @interface DWImageAndTextCell : NSTextFieldCell 2245 @interface DWImageAndTextCell : NSTextFieldCell
2564 -(void)refreshColors 2562 -(void)refreshColors
2565 { 2563 {
2566 NSColor *oldodd = oddcolor; 2564 NSColor *oldodd = oddcolor;
2567 NSColor *oldeven = evencolor; 2565 NSColor *oldeven = evencolor;
2568 unsigned long thisodd = dw_oddcolor == DW_CLR_DEFAULT ? _DW_COLOR_ROW_ODD : dw_oddcolor; 2566 unsigned long thisodd = dw_oddcolor == DW_CLR_DEFAULT ? _DW_COLOR_ROW_ODD : dw_oddcolor;
2569 unsigned long _odd = _get_color(thisodd); 2567 unsigned long _odd = _dw_get_color(thisodd);
2570 unsigned long thiseven = dw_evencolor == DW_CLR_DEFAULT ? _DW_COLOR_ROW_EVEN : dw_evencolor; 2568 unsigned long thiseven = dw_evencolor == DW_CLR_DEFAULT ? _DW_COLOR_ROW_EVEN : dw_evencolor;
2571 unsigned long _even = _get_color(thiseven); 2569 unsigned long _even = _dw_get_color(thiseven);
2572 2570
2573 /* Get the NSColor for non-default colors */ 2571 /* Get the NSColor for non-default colors */
2574 if(thisodd != DW_RGB_TRANSPARENT) 2572 if(thisodd != DW_RGB_TRANSPARENT)
2575 oddcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_odd)/255.0 green: DW_GREEN_VALUE(_odd)/255.0 blue: DW_BLUE_VALUE(_odd)/255.0 alpha: 1] retain]; 2573 oddcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_odd)/255.0 green: DW_GREEN_VALUE(_odd)/255.0 blue: DW_BLUE_VALUE(_odd)/255.0 alpha: 1] retain];
2576 else 2574 else
2591 } 2589 }
2592 -(void)checkDark 2590 -(void)checkDark
2593 { 2591 {
2594 /* Update any system colors based on the Dark Mode */ 2592 /* Update any system colors based on the Dark Mode */
2595 _DW_COLOR_ROW_EVEN = DW_RGB_TRANSPARENT; 2593 _DW_COLOR_ROW_EVEN = DW_RGB_TRANSPARENT;
2596 if(_is_dark(self)) 2594 if(_dw_is_dark(self))
2597 _DW_COLOR_ROW_ODD = DW_RGB(100, 100, 100); 2595 _DW_COLOR_ROW_ODD = DW_RGB(100, 100, 100);
2598 else 2596 else
2599 _DW_COLOR_ROW_ODD = DW_RGB(230, 230, 230); 2597 _DW_COLOR_ROW_ODD = DW_RGB(230, 230, 230);
2600 /* Only refresh if we've been setup already */ 2598 /* Only refresh if we've been setup already */
2601 if(titles) 2599 if(titles)
3007 3005
3008 params[0] = (void *)[self getRowTitle:(int)[self selectedRow]]; 3006 params[0] = (void *)[self getRowTitle:(int)[self selectedRow]];
3009 params[1] = (void *)[self getRowData:(int)[self selectedRow]]; 3007 params[1] = (void *)[self getRowData:(int)[self selectedRow]];
3010 3008
3011 /* Handler for container class */ 3009 /* Handler for container class */
3012 _event_handler(self, (NSEvent *)params, 9); 3010 _dw_event_handler(self, (NSEvent *)params, 9);
3013 } 3011 }
3014 -(void)keyUp:(NSEvent *)theEvent 3012 -(void)keyUp:(NSEvent *)theEvent
3015 { 3013 {
3016 if([[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN) 3014 if([[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
3017 { 3015 {
3018 void *params[2]; 3016 void *params[2];
3019 3017
3020 params[0] = (void *)[self getRowTitle:(int)[self selectedRow]]; 3018 params[0] = (void *)[self getRowTitle:(int)[self selectedRow]];
3021 params[1] = (void *)[self getRowData:(int)[self selectedRow]]; 3019 params[1] = (void *)[self getRowData:(int)[self selectedRow]];
3022 3020
3023 _event_handler(self, (NSEvent *)params, 9); 3021 _dw_event_handler(self, (NSEvent *)params, 9);
3024 } 3022 }
3025 [super keyUp:theEvent]; 3023 [super keyUp:theEvent];
3026 } 3024 }
3027 3025
3028 -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn 3026 -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn
3029 { 3027 {
3030 NSUInteger index = [tvcols indexOfObject:tableColumn]; 3028 NSUInteger index = [tvcols indexOfObject:tableColumn];
3031 3029
3032 /* Handler for column click class */ 3030 /* Handler for column click class */
3033 _event_handler(self, (NSEvent *)index, 17); 3031 _dw_event_handler(self, (NSEvent *)index, 17);
3034 } 3032 }
3035 -(void)selectionChanged:(id)sender 3033 -(void)selectionChanged:(id)sender
3036 { 3034 {
3037 void *params[2]; 3035 void *params[2];
3038 3036
3039 params[0] = (void *)[self getRowTitle:(int)[self selectedRow]]; 3037 params[0] = (void *)[self getRowTitle:(int)[self selectedRow]];
3040 params[1] = (void *)[self getRowData:(int)[self selectedRow]]; 3038 params[1] = (void *)[self getRowData:(int)[self selectedRow]];
3041 3039
3042 /* Handler for container class */ 3040 /* Handler for container class */
3043 _event_handler(self, (NSEvent *)params, 12); 3041 _dw_event_handler(self, (NSEvent *)params, 12);
3044 /* Handler for listbox class */ 3042 /* Handler for listbox class */
3045 _event_handler(self, DW_INT_TO_POINTER((int)[self selectedRow]), 11); 3043 _dw_event_handler(self, DW_INT_TO_POINTER((int)[self selectedRow]), 11);
3046 } 3044 }
3047 -(NSMenu *)menuForEvent:(NSEvent *)event 3045 -(NSMenu *)menuForEvent:(NSEvent *)event
3048 { 3046 {
3049 int row; 3047 int row;
3050 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; 3048 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil];
3051 row = (int)[self rowAtPoint:where]; 3049 row = (int)[self rowAtPoint:where];
3052 _event_handler(self, (NSEvent *)[self getRowTitle:row], 10); 3050 _dw_event_handler(self, (NSEvent *)[self getRowTitle:row], 10);
3053 return nil; 3051 return nil;
3054 } 3052 }
3055 -(void)keyDown:(NSEvent *)theEvent 3053 -(void)keyDown:(NSEvent *)theEvent
3056 { 3054 {
3057 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; 3055 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
3060 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; 3058 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
3061 [super keyDown:theEvent]; 3059 [super keyDown:theEvent];
3062 } 3060 }
3063 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; } 3061 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; }
3064 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; } 3062 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; }
3065 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 3063 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
3066 @end 3064 @end
3067 3065
3068 /* Dive into the tree freeing all desired child nodes */ 3066 /* Dive into the tree freeing all desired child nodes */
3069 void _free_tree_recurse(NSMutableArray *node, NSMutableArray *item) 3067 void _dw_free_tree_recurse(NSMutableArray *node, NSMutableArray *item)
3070 { 3068 {
3071 if(node && ([node isKindOfClass:[NSArray class]])) 3069 if(node && ([node isKindOfClass:[NSArray class]]))
3072 { 3070 {
3073 int count = (int)[node count]; 3071 int count = (int)[node count];
3074 NSInteger index = -1; 3072 NSInteger index = -1;
3087 children = (NSMutableArray *)[pnt objectAtIndex:3]; 3085 children = (NSMutableArray *)[pnt objectAtIndex:3];
3088 } 3086 }
3089 3087
3090 if(z == index) 3088 if(z == index)
3091 { 3089 {
3092 _free_tree_recurse(children, NULL); 3090 _dw_free_tree_recurse(children, NULL);
3093 [node removeObjectAtIndex:z]; 3091 [node removeObjectAtIndex:z];
3094 count = (int)[node count]; 3092 count = (int)[node count];
3095 index = -1; 3093 index = -1;
3096 z--; 3094 z--;
3097 } 3095 }
3098 else if(item == NULL) 3096 else if(item == NULL)
3099 { 3097 {
3100 NSString *oldstr = [pnt objectAtIndex:1]; 3098 NSString *oldstr = [pnt objectAtIndex:1];
3101 [oldstr release]; 3099 [oldstr release];
3102 _free_tree_recurse(children, item); 3100 _dw_free_tree_recurse(children, item);
3103 } 3101 }
3104 else 3102 else
3105 _free_tree_recurse(children, item); 3103 _dw_free_tree_recurse(children, item);
3106 } 3104 }
3107 } 3105 }
3108 if(!item) 3106 if(!item)
3109 { 3107 {
3110 [node release]; 3108 [node release];
3303 /* Handler for tree class */ 3301 /* Handler for tree class */
3304 id item = [self itemAtRow:[self selectedRow]]; 3302 id item = [self itemAtRow:[self selectedRow]];
3305 3303
3306 if(item) 3304 if(item)
3307 { 3305 {
3308 _event_handler(self, (void *)item, 12); 3306 _dw_event_handler(self, (void *)item, 12);
3309 } 3307 }
3310 } 3308 }
3311 -(void)treeItemExpanded:(NSNotification *)notification 3309 -(void)treeItemExpanded:(NSNotification *)notification
3312 { 3310 {
3313 id item = [[notification userInfo ] objectForKey: @"NSObject"]; 3311 id item = [[notification userInfo ] objectForKey: @"NSObject"];
3314 3312
3315 if(item) 3313 if(item)
3316 { 3314 {
3317 _event_handler(self, (void *)item, 16); 3315 _dw_event_handler(self, (void *)item, 16);
3318 } 3316 }
3319 } 3317 }
3320 -(NSMenu *)menuForEvent:(NSEvent *)event 3318 -(NSMenu *)menuForEvent:(NSEvent *)event
3321 { 3319 {
3322 int row; 3320 int row;
3323 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; 3321 NSPoint where = [self convertPoint:[event locationInWindow] fromView:nil];
3324 row = (int)[self rowAtPoint:where]; 3322 row = (int)[self rowAtPoint:where];
3325 id item = [self itemAtRow:row]; 3323 id item = [self itemAtRow:row];
3326 _event_handler(self, (NSEvent *)item, 10); 3324 _dw_event_handler(self, (NSEvent *)item, 10);
3327 return nil; 3325 return nil;
3328 } 3326 }
3329 -(NSScrollView *)scrollview { return scrollview; } 3327 -(NSScrollView *)scrollview { return scrollview; }
3330 -(void)setScrollview:(NSScrollView *)input { scrollview = input; } 3328 -(void)setScrollview:(NSScrollView *)input { scrollview = input; }
3331 -(void)deleteNode:(NSMutableArray *)item { _free_tree_recurse(data, item); } 3329 -(void)deleteNode:(NSMutableArray *)item { _dw_free_tree_recurse(data, item); }
3332 -(void)setForegroundColor:(NSColor *)input 3330 -(void)setForegroundColor:(NSColor *)input
3333 { 3331 {
3334 NSTextFieldCell *cell = [treecol dataCell]; 3332 NSTextFieldCell *cell = [treecol dataCell];
3335 fgcolor = input; 3333 fgcolor = input;
3336 [fgcolor retain]; 3334 [fgcolor retain];
3337 [cell setTextColor:fgcolor]; 3335 [cell setTextColor:fgcolor];
3338 } 3336 }
3339 -(void)clear { NSMutableArray *toclear = data; data = nil; _free_tree_recurse(toclear, NULL); [self reloadData]; } 3337 -(void)clear { NSMutableArray *toclear = data; data = nil; _dw_free_tree_recurse(toclear, NULL); [self reloadData]; }
3340 -(void)keyDown:(NSEvent *)theEvent 3338 -(void)keyDown:(NSEvent *)theEvent
3341 { 3339 {
3342 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; 3340 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
3343 3341
3344 if(vk == NSTabCharacter || vk == NSBackTabCharacter) 3342 if(vk == NSTabCharacter || vk == NSBackTabCharacter)
3348 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; } 3346 -(void)insertTab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectNextKeyView:self]; }
3349 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; } 3347 -(void)insertBacktab:(id)sender { if([[self window] firstResponder] == self) [[self window] selectPreviousKeyView:self]; }
3350 -(void)dealloc 3348 -(void)dealloc
3351 { 3349 {
3352 UserData *root = userdata; 3350 UserData *root = userdata;
3353 _remove_userdata(&root, NULL, TRUE); 3351 _dw_remove_userdata(&root, NULL, TRUE);
3354 _free_tree_recurse(data, NULL); 3352 _dw_free_tree_recurse(data, NULL);
3355 [treecol release]; 3353 [treecol release];
3356 dw_signal_disconnect_by_window(self); 3354 dw_signal_disconnect_by_window(self);
3357 [super dealloc]; 3355 [super dealloc];
3358 } 3356 }
3359 @end 3357 @end
3368 @end 3366 @end
3369 3367
3370 @implementation DWCalendar 3368 @implementation DWCalendar
3371 -(void *)userdata { return userdata; } 3369 -(void *)userdata { return userdata; }
3372 -(void)setUserdata:(void *)input { userdata = input; } 3370 -(void)setUserdata:(void *)input { userdata = input; }
3373 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 3371 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
3374 @end 3372 @end
3375 3373
3376 /* Subclass for a Combobox type */ 3374 /* Subclass for a Combobox type */
3377 @interface DWComboBox : NSComboBox 3375 @interface DWComboBox : NSComboBox
3378 #ifdef BUILDING_FOR_SNOW_LEOPARD 3376 #ifdef BUILDING_FOR_SNOW_LEOPARD
3389 @end 3387 @end
3390 3388
3391 @implementation DWComboBox 3389 @implementation DWComboBox
3392 -(void *)userdata { return userdata; } 3390 -(void *)userdata { return userdata; }
3393 -(void)setUserdata:(void *)input { userdata = input; } 3391 -(void)setUserdata:(void *)input { userdata = input; }
3394 -(void)comboBoxSelectionDidChange:(NSNotification *)not { _event_handler(self, (void *)[self indexOfSelectedItem], 11); } 3392 -(void)comboBoxSelectionDidChange:(NSNotification *)not { _dw_event_handler(self, (void *)[self indexOfSelectedItem], 11); }
3395 -(void)setClickDefault:(id)input { clickDefault = input; } 3393 -(void)setClickDefault:(id)input { clickDefault = input; }
3396 -(void)keyUp:(NSEvent *)theEvent 3394 -(void)keyUp:(NSEvent *)theEvent
3397 { 3395 {
3398 if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN) 3396 if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
3399 { 3397 {
3401 } else 3399 } else
3402 { 3400 {
3403 [super keyUp:theEvent]; 3401 [super keyUp:theEvent];
3404 } 3402 }
3405 } 3403 }
3406 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 3404 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
3407 @end 3405 @end
3408 3406
3409 /* Subclass for a stepper component of the spinbutton type */ 3407 /* Subclass for a stepper component of the spinbutton type */
3410 /* This is a bad way of doing this... but I can't get the other methods to work */ 3408 /* This is a bad way of doing this... but I can't get the other methods to work */
3411 @interface DWStepper : NSStepper 3409 @interface DWStepper : NSStepper
3433 [self mouseUp:event]; 3431 [self mouseUp:event];
3434 } 3432 }
3435 -(void)mouseUp:(NSEvent *)event 3433 -(void)mouseUp:(NSEvent *)event
3436 { 3434 {
3437 [textfield takeIntValueFrom:self]; 3435 [textfield takeIntValueFrom:self];
3438 _event_handler(parent, (void *)[self integerValue], 14); 3436 _dw_event_handler(parent, (void *)[self integerValue], 14);
3439 } 3437 }
3440 -(void)keyDown:(NSEvent *)theEvent 3438 -(void)keyDown:(NSEvent *)theEvent
3441 { 3439 {
3442 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; 3440 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
3443 if(vk == VK_UP || vk == VK_DOWN) 3441 if(vk == VK_UP || vk == VK_DOWN)
3505 -(NSStepper *)stepper { return stepper; } 3503 -(NSStepper *)stepper { return stepper; }
3506 -(void)controlTextDidChange:(NSNotification *)aNotification 3504 -(void)controlTextDidChange:(NSNotification *)aNotification
3507 { 3505 {
3508 [stepper takeIntValueFrom:textfield]; 3506 [stepper takeIntValueFrom:textfield];
3509 [textfield takeIntValueFrom:stepper]; 3507 [textfield takeIntValueFrom:stepper];
3510 _event_handler(self, (void *)[stepper integerValue], 14); 3508 _dw_event_handler(self, (void *)[stepper integerValue], 14);
3511 } 3509 }
3512 -(void)setClickDefault:(id)input { clickDefault = input; } 3510 -(void)setClickDefault:(id)input { clickDefault = input; }
3513 -(void)keyUp:(NSEvent *)theEvent 3511 -(void)keyUp:(NSEvent *)theEvent
3514 { 3512 {
3515 if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN) 3513 if(clickDefault && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
3520 { 3518 {
3521 [super keyUp:theEvent]; 3519 [super keyUp:theEvent];
3522 } 3520 }
3523 } 3521 }
3524 -(void)performClick:(id)sender { [textfield performClick:sender]; } 3522 -(void)performClick:(id)sender { [textfield performClick:sender]; }
3525 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 3523 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
3526 @end 3524 @end
3527 3525
3528 #ifdef BUILDING_FOR_MOJAVE 3526 #ifdef BUILDING_FOR_MOJAVE
3529 API_AVAILABLE(macos(10.14)) 3527 API_AVAILABLE(macos(10.14))
3530 @interface DWUserNotificationCenterDelegate : NSObject <UNUserNotificationCenterDelegate> 3528 @interface DWUserNotificationCenterDelegate : NSObject <UNUserNotificationCenterDelegate>
3554 dw_signal_disconnect_by_window(notification); 3552 dw_signal_disconnect_by_window(notification);
3555 } 3553 }
3556 else if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) 3554 else if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier])
3557 { 3555 {
3558 /* The user launched the app. */ 3556 /* The user launched the app. */
3559 _event_handler(notification, nil, 8); 3557 _dw_event_handler(notification, nil, 8);
3560 dw_signal_disconnect_by_window(notification); 3558 dw_signal_disconnect_by_window(notification);
3561 } 3559 }
3562 completionHandler(); 3560 completionHandler();
3563 } 3561 }
3564 @end 3562 @end
3574 @implementation DWMDI 3572 @implementation DWMDI
3575 @end 3573 @end
3576 3574
3577 /* This function adds a signal handler callback into the linked list. 3575 /* This function adds a signal handler callback into the linked list.
3578 */ 3576 */
3579 void _new_signal(ULONG message, HWND window, int msgid, void *signalfunction, void *discfunc, void *data) 3577 void _dw_new_signal(ULONG message, HWND window, int msgid, void *signalfunction, void *discfunc, void *data)
3580 { 3578 {
3581 SignalHandler *new = malloc(sizeof(SignalHandler)); 3579 SignalHandler *new = malloc(sizeof(SignalHandler));
3582 3580
3583 new->message = message; 3581 new->message = message;
3584 new->window = window; 3582 new->window = window;
3586 new->signalfunction = signalfunction; 3584 new->signalfunction = signalfunction;
3587 new->discfunction = discfunc; 3585 new->discfunction = discfunc;
3588 new->data = data; 3586 new->data = data;
3589 new->next = NULL; 3587 new->next = NULL;
3590 3588
3591 if (!Root) 3589 if (!DWRoot)
3592 Root = new; 3590 DWRoot = new;
3593 else 3591 else
3594 { 3592 {
3595 SignalHandler *prev = NULL, *tmp = Root; 3593 SignalHandler *prev = NULL, *tmp = DWRoot;
3596 while(tmp) 3594 while(tmp)
3597 { 3595 {
3598 if(tmp->message == message && 3596 if(tmp->message == message &&
3599 tmp->window == window && 3597 tmp->window == window &&
3600 tmp->id == msgid && 3598 tmp->id == msgid &&
3608 tmp = tmp->next; 3606 tmp = tmp->next;
3609 } 3607 }
3610 if(prev) 3608 if(prev)
3611 prev->next = new; 3609 prev->next = new;
3612 else 3610 else
3613 Root = new; 3611 DWRoot = new;
3614 } 3612 }
3615 } 3613 }
3616 3614
3617 /* Finds the message number for a given signal name */ 3615 /* Finds the message number for a given signal name */
3618 ULONG _findsigmessage(const char *signame) 3616 ULONG _dw_findsigmessage(const char *signame)
3619 { 3617 {
3620 int z; 3618 int z;
3621 3619
3622 for(z=0;z<SIGNALMAX;z++) 3620 for(z=0;z<SIGNALMAX;z++)
3623 { 3621 {
3624 if(strcasecmp(signame, SignalTranslate[z].name) == 0) 3622 if(strcasecmp(signame, DWSignalTranslate[z].name) == 0)
3625 return SignalTranslate[z].message; 3623 return DWSignalTranslate[z].message;
3626 } 3624 }
3627 return 0L; 3625 return 0L;
3628 } 3626 }
3629 3627
3630 unsigned long _foreground = 0xAAAAAA, _background = 0; 3628 unsigned long _dw_foreground = 0xAAAAAA, _dw_background = 0;
3631 3629
3632 void _handle_resize_events(Box *thisbox) 3630 void _dw_handle_resize_events(Box *thisbox)
3633 { 3631 {
3634 int z; 3632 int z;
3635 3633
3636 for(z=0;z<thisbox->count;z++) 3634 for(z=0;z<thisbox->count;z++)
3637 { 3635 {
3641 { 3639 {
3642 Box *tmp = (Box *)[handle box]; 3640 Box *tmp = (Box *)[handle box];
3643 3641
3644 if(tmp) 3642 if(tmp)
3645 { 3643 {
3646 _handle_resize_events(tmp); 3644 _dw_handle_resize_events(tmp);
3647 } 3645 }
3648 } 3646 }
3649 else 3647 else
3650 { 3648 {
3651 if([handle isMemberOfClass:[DWRender class]]) 3649 if([handle isMemberOfClass:[DWRender class]])
3670 if(oldsize.width != newsize.width || oldsize.height != newsize.height) 3668 if(oldsize.width != newsize.width || oldsize.height != newsize.height)
3671 { 3669 {
3672 if(newsize.width > 0 && newsize.height > 0) 3670 if(newsize.width > 0 && newsize.height > 0)
3673 { 3671 {
3674 [render setSize:newsize]; 3672 [render setSize:newsize];
3675 _event_handler(handle, nil, 1); 3673 _dw_event_handler(handle, nil, 1);
3676 } 3674 }
3677 } 3675 }
3678 } 3676 }
3679 /* Special handling for notebook controls */ 3677 /* Special handling for notebook controls */
3680 else if([handle isMemberOfClass:[DWNotebook class]]) 3678 else if([handle isMemberOfClass:[DWNotebook class]])
3684 id view = [notepage view]; 3682 id view = [notepage view];
3685 3683
3686 if([view isMemberOfClass:[DWBox class]]) 3684 if([view isMemberOfClass:[DWBox class]])
3687 { 3685 {
3688 Box *box = (Box *)[view box]; 3686 Box *box = (Box *)[view box];
3689 _handle_resize_events(box); 3687 _dw_handle_resize_events(box);
3690 } 3688 }
3691 } 3689 }
3692 /* Handle laying out scrollviews... if required space is less 3690 /* Handle laying out scrollviews... if required space is less
3693 * than available space, then expand. Otherwise use required space. 3691 * than available space, then expand. Otherwise use required space.
3694 */ 3692 */
3697 DWScrollBox *scrollbox = (DWScrollBox *)handle; 3695 DWScrollBox *scrollbox = (DWScrollBox *)handle;
3698 DWBox *contentbox = [scrollbox documentView]; 3696 DWBox *contentbox = [scrollbox documentView];
3699 Box *thisbox = [contentbox box]; 3697 Box *thisbox = [contentbox box];
3700 3698
3701 /* Get the required space for the box */ 3699 /* Get the required space for the box */
3702 _handle_resize_events(thisbox); 3700 _dw_handle_resize_events(thisbox);
3703 } 3701 }
3704 } 3702 }
3705 } 3703 }
3706 } 3704 }
3707 3705
3708 /* This function calculates how much space the widgets and boxes require 3706 /* This function calculates how much space the widgets and boxes require
3709 * and does expansion as necessary. 3707 * and does expansion as necessary.
3710 */ 3708 */
3711 static void _resize_box(Box *thisbox, int *depth, int x, int y, int pass) 3709 static void _dw_resize_box(Box *thisbox, int *depth, int x, int y, int pass)
3712 { 3710 {
3713 /* Current item position */ 3711 /* Current item position */
3714 int z, currentx = thisbox->pad, currenty = thisbox->pad; 3712 int z, currentx = thisbox->pad, currenty = thisbox->pad;
3715 /* Used x, y and padding maximum values... 3713 /* Used x, y and padding maximum values...
3716 * These will be used to find the widest or 3714 * These will be used to find the widest or
3767 if(pass == 1) 3765 if(pass == 1)
3768 { 3766 {
3769 (*depth)++; 3767 (*depth)++;
3770 3768
3771 /* Save the newly calculated values on the box */ 3769 /* Save the newly calculated values on the box */
3772 _resize_box(tmp, depth, x, y, pass); 3770 _dw_resize_box(tmp, depth, x, y, pass);
3773 3771
3774 /* Duplicate the values in the item list for use below */ 3772 /* Duplicate the values in the item list for use below */
3775 thisbox->items[z].width = tmp->minwidth; 3773 thisbox->items[z].width = tmp->minwidth;
3776 thisbox->items[z].height = tmp->minheight; 3774 thisbox->items[z].height = tmp->minheight;
3777 3775
3901 Box *tmp = (Box *)[box box]; 3899 Box *tmp = (Box *)[box box];
3902 3900
3903 if(tmp) 3901 if(tmp)
3904 { 3902 {
3905 (*depth)++; 3903 (*depth)++;
3906 _resize_box(tmp, depth, width, height, pass); 3904 _dw_resize_box(tmp, depth, width, height, pass);
3907 (*depth)--; 3905 (*depth)--;
3908 } 3906 }
3909 } 3907 }
3910 3908
3911 /* Special handling for notebook controls */ 3909 /* Special handling for notebook controls */
3917 3915
3918 if([view isMemberOfClass:[DWBox class]]) 3916 if([view isMemberOfClass:[DWBox class]])
3919 { 3917 {
3920 Box *box = (Box *)[view box]; 3918 Box *box = (Box *)[view box];
3921 NSSize size = [view frame].size; 3919 NSSize size = [view frame].size;
3922 _do_resize(box, size.width, size.height); 3920 _dw_do_resize(box, size.width, size.height);
3923 _handle_resize_events(box); 3921 _dw_handle_resize_events(box);
3924 } 3922 }
3925 } 3923 }
3926 /* Handle laying out scrollviews... if required space is less 3924 /* Handle laying out scrollviews... if required space is less
3927 * than available space, then expand. Otherwise use required space. 3925 * than available space, then expand. Otherwise use required space.
3928 */ 3926 */
3933 DWBox *contentbox = [scrollbox documentView]; 3931 DWBox *contentbox = [scrollbox documentView];
3934 Box *thisbox = [contentbox box]; 3932 Box *thisbox = [contentbox box];
3935 NSSize contentsize = [scrollbox contentSize]; 3933 NSSize contentsize = [scrollbox contentSize];
3936 3934
3937 /* Get the required space for the box */ 3935 /* Get the required space for the box */
3938 _resize_box(thisbox, &depth, x, y, 1); 3936 _dw_resize_box(thisbox, &depth, x, y, 1);
3939 3937
3940 if(contentsize.width < thisbox->minwidth) 3938 if(contentsize.width < thisbox->minwidth)
3941 { 3939 {
3942 contentsize.width = thisbox->minwidth; 3940 contentsize.width = thisbox->minwidth;
3943 } 3941 }
3946 contentsize.height = thisbox->minheight; 3944 contentsize.height = thisbox->minheight;
3947 } 3945 }
3948 [contentbox setFrameSize:contentsize]; 3946 [contentbox setFrameSize:contentsize];
3949 3947
3950 /* Layout the content of the scrollbox */ 3948 /* Layout the content of the scrollbox */
3951 _do_resize(thisbox, contentsize.width, contentsize.height); 3949 _dw_do_resize(thisbox, contentsize.width, contentsize.height);
3952 _handle_resize_events(thisbox); 3950 _dw_handle_resize_events(thisbox);
3953 } 3951 }
3954 /* Special handling for spinbutton controls */ 3952 /* Special handling for spinbutton controls */
3955 else if([handle isMemberOfClass:[DWSpinButton class]]) 3953 else if([handle isMemberOfClass:[DWSpinButton class]])
3956 { 3954 {
3957 DWSpinButton *spinbutton = (DWSpinButton *)handle; 3955 DWSpinButton *spinbutton = (DWSpinButton *)handle;
3987 } 3985 }
3988 } 3986 }
3989 } 3987 }
3990 } 3988 }
3991 3989
3992 static void _do_resize(Box *thisbox, int x, int y) 3990 static void _dw_do_resize(Box *thisbox, int x, int y)
3993 { 3991 {
3994 if(x > 0 && y > 0) 3992 if(x > 0 && y > 0)
3995 { 3993 {
3996 if(thisbox) 3994 if(thisbox)
3997 { 3995 {
3998 int depth = 0; 3996 int depth = 0;
3999 3997
4000 /* Calculate space requirements */ 3998 /* Calculate space requirements */
4001 _resize_box(thisbox, &depth, x, y, 1); 3999 _dw_resize_box(thisbox, &depth, x, y, 1);
4002 4000
4003 /* Finally place all the boxes and controls */ 4001 /* Finally place all the boxes and controls */
4004 _resize_box(thisbox, &depth, x, y, 2); 4002 _dw_resize_box(thisbox, &depth, x, y, 2);
4005 } 4003 }
4006 } 4004 }
4007 } 4005 }
4008 4006
4009 NSMenu *_generate_main_menu() 4007 NSMenu *_dw_generate_main_menu()
4010 { 4008 {
4011 NSString *applicationName = nil; 4009 NSString *applicationName = nil;
4012 4010
4013 /* This only works on 10.6 so we have a backup method */ 4011 /* This only works on 10.6 so we have a backup method */
4014 #ifdef BUILDING_FOR_SNOW_LEOPARD 4012 #ifdef BUILDING_FOR_SNOW_LEOPARD
4184 * Cleanly terminates a DW session, should be signal handler safe. 4182 * Cleanly terminates a DW session, should be signal handler safe.
4185 */ 4183 */
4186 void API dw_shutdown(void) 4184 void API dw_shutdown(void)
4187 { 4185 {
4188 #if !defined(GARBAGE_COLLECT) 4186 #if !defined(GARBAGE_COLLECT)
4189 pool = pthread_getspecific(_dw_pool_key); 4187 NSAutoreleasePool *pool = pthread_getspecific(_dw_pool_key);
4190 [pool drain]; 4188 [pool drain];
4191 #endif 4189 #endif
4192 } 4190 }
4193 4191
4194 /* 4192 /*
4744 } 4742 }
4745 return range; 4743 return range;
4746 } 4744 }
4747 4745
4748 /* Return the handle to the text object */ 4746 /* Return the handle to the text object */
4749 id _text_handle(id object) 4747 id _dw_text_handle(id object)
4750 { 4748 {
4751 if([object isMemberOfClass:[ DWSpinButton class]]) 4749 if([object isMemberOfClass:[ DWSpinButton class]])
4752 { 4750 {
4753 DWSpinButton *spinbutton = object; 4751 DWSpinButton *spinbutton = object;
4754 object = [spinbutton textfield]; 4752 object = [spinbutton textfield];
4779 */ 4777 */
4780 void _dw_control_size(id handle, int *width, int *height) 4778 void _dw_control_size(id handle, int *width, int *height)
4781 { 4779 {
4782 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; 4780 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0;
4783 NSString *nsstr = nil; 4781 NSString *nsstr = nil;
4784 id object = _text_handle(handle); 4782 id object = _dw_text_handle(handle);
4785 4783
4786 /* Handle all the different button types */ 4784 /* Handle all the different button types */
4787 if([ object isKindOfClass:[ NSButton class ] ]) 4785 if([ object isKindOfClass:[ NSButton class ] ])
4788 { 4786 {
4789 switch([object buttonType]) 4787 switch([object buttonType])
6712 { 6710 {
6713 NSColor *oldcolor = pthread_getspecific(_dw_fg_color_key); 6711 NSColor *oldcolor = pthread_getspecific(_dw_fg_color_key);
6714 NSColor *newcolor; 6712 NSColor *newcolor;
6715 DW_LOCAL_POOL_IN; 6713 DW_LOCAL_POOL_IN;
6716 6714
6717 _foreground = _get_color(value); 6715 _dw_foreground = _dw_get_color(value);
6718 6716
6719 newcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_foreground)/255.0 green: 6717 newcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_dw_foreground)/255.0 green:
6720 DW_GREEN_VALUE(_foreground)/255.0 blue: 6718 DW_GREEN_VALUE(_dw_foreground)/255.0 blue:
6721 DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] retain]; 6719 DW_BLUE_VALUE(_dw_foreground)/255.0 alpha: 1] retain];
6722 pthread_setspecific(_dw_fg_color_key, newcolor); 6720 pthread_setspecific(_dw_fg_color_key, newcolor);
6723 [oldcolor release]; 6721 [oldcolor release];
6724 DW_LOCAL_POOL_OUT; 6722 DW_LOCAL_POOL_OUT;
6725 } 6723 }
6726 6724
6740 { 6738 {
6741 pthread_setspecific(_dw_bg_color_key, NULL); 6739 pthread_setspecific(_dw_bg_color_key, NULL);
6742 } 6740 }
6743 else 6741 else
6744 { 6742 {
6745 _background = _get_color(value); 6743 _dw_background = _dw_get_color(value);
6746 6744
6747 newcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_background)/255.0 green: 6745 newcolor = [[NSColor colorWithDeviceRed: DW_RED_VALUE(_dw_background)/255.0 green:
6748 DW_GREEN_VALUE(_background)/255.0 blue: 6746 DW_GREEN_VALUE(_dw_background)/255.0 blue:
6749 DW_BLUE_VALUE(_background)/255.0 alpha: 1] retain]; 6747 DW_BLUE_VALUE(_dw_background)/255.0 alpha: 1] retain];
6750 pthread_setspecific(_dw_bg_color_key, newcolor); 6748 pthread_setspecific(_dw_bg_color_key, newcolor);
6751 } 6749 }
6752 [oldcolor release]; 6750 [oldcolor release];
6753 DW_LOCAL_POOL_OUT; 6751 DW_LOCAL_POOL_OUT;
6754 } 6752 }
6782 { 6780 {
6783 DW_LOCAL_POOL_OUT; 6781 DW_LOCAL_POOL_OUT;
6784 return value; 6782 return value;
6785 } 6783 }
6786 6784
6787 unsigned long tempcol = _get_color(value); 6785 unsigned long tempcol = _dw_get_color(value);
6788 NSColor *color = [[NSColor colorWithDeviceRed: DW_RED_VALUE(tempcol)/255.0 green: DW_GREEN_VALUE(tempcol)/255.0 blue: DW_BLUE_VALUE(tempcol)/255.0 alpha: 1] retain]; 6786 NSColor *color = [[NSColor colorWithDeviceRed: DW_RED_VALUE(tempcol)/255.0 green: DW_GREEN_VALUE(tempcol)/255.0 blue: DW_BLUE_VALUE(tempcol)/255.0 alpha: 1] retain];
6789 [colorDlg setColor:color]; 6787 [colorDlg setColor:color];
6790 6788
6791 dialog = dw_dialog_new(colorDlg); 6789 dialog = dw_dialog_new(colorDlg);
6792 [colorDlg setDialog:dialog]; 6790 [colorDlg setDialog:dialog];
7059 } 7057 }
7060 7058
7061 /* Internal function to create an image graphics context... 7059 /* Internal function to create an image graphics context...
7062 * with or without antialiasing enabled. 7060 * with or without antialiasing enabled.
7063 */ 7061 */
7064 id _create_gc(id image, bool antialiased) 7062 id _dw_create_gc(id image, bool antialiased)
7065 { 7063 {
7066 #ifdef BUILDING_FOR_YOSEMITE 7064 #ifdef BUILDING_FOR_YOSEMITE
7067 CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext]; 7065 CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext];
7068 NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:context flipped:YES]; 7066 NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:context flipped:YES];
7069 #else 7067 #else
7116 } 7114 }
7117 #endif 7115 #endif
7118 } 7116 }
7119 if(bi) 7117 if(bi)
7120 { 7118 {
7121 id gc = _create_gc(bi, flags & DW_DRAW_NOAA ? NO : YES); 7119 id gc = _dw_create_gc(bi, flags & DW_DRAW_NOAA ? NO : YES);
7122 [NSGraphicsContext saveGraphicsState]; 7120 [NSGraphicsContext saveGraphicsState];
7123 [NSGraphicsContext setCurrentContext:gc]; 7121 [NSGraphicsContext setCurrentContext:gc];
7124 } 7122 }
7125 7123
7126 if(bCanDraw == YES) 7124 if(bCanDraw == YES)
7192 } 7190 }
7193 #endif 7191 #endif
7194 } 7192 }
7195 if(bi) 7193 if(bi)
7196 { 7194 {
7197 id gc = _create_gc(bi, flags & DW_DRAW_NOAA ? NO : YES); 7195 id gc = _dw_create_gc(bi, flags & DW_DRAW_NOAA ? NO : YES);
7198 [NSGraphicsContext saveGraphicsState]; 7196 [NSGraphicsContext saveGraphicsState];
7199 [NSGraphicsContext setCurrentContext:gc]; 7197 [NSGraphicsContext setCurrentContext:gc];
7200 } 7198 }
7201 7199
7202 if(bCanDraw == YES) 7200 if(bCanDraw == YES)
7263 } 7261 }
7264 #endif 7262 #endif
7265 } 7263 }
7266 if(bi) 7264 if(bi)
7267 { 7265 {
7268 id gc = _create_gc(bi, flags & DW_DRAW_NOAA ? NO : YES); 7266 id gc = _dw_create_gc(bi, flags & DW_DRAW_NOAA ? NO : YES);
7269 [NSGraphicsContext saveGraphicsState]; 7267 [NSGraphicsContext saveGraphicsState];
7270 [NSGraphicsContext setCurrentContext:gc]; 7268 [NSGraphicsContext setCurrentContext:gc];
7271 } 7269 }
7272 7270
7273 if(bCanDraw) 7271 if(bCanDraw)
8792 bitsPerPixel:0]; 8790 bitsPerPixel:0];
8793 return pixmap; 8791 return pixmap;
8794 } 8792 }
8795 8793
8796 /* Function takes an NSImage and copies it into a flipped NSBitmapImageRep */ 8794 /* Function takes an NSImage and copies it into a flipped NSBitmapImageRep */
8797 void _flip_image(NSImage *tmpimage, NSBitmapImageRep *image, NSSize size) 8795 void _dw_flip_image(NSImage *tmpimage, NSBitmapImageRep *image, NSSize size)
8798 { 8796 {
8799 NSCompositingOperation op = DWCompositingOperationSourceOver; 8797 NSCompositingOperation op = DWCompositingOperationSourceOver;
8800 [NSGraphicsContext saveGraphicsState]; 8798 [NSGraphicsContext saveGraphicsState];
8801 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; 8799 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)];
8802 [[[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil] autorelease]; 8800 [[[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil] autorelease];
8859 hasAlpha:YES 8857 hasAlpha:YES
8860 isPlanar:NO 8858 isPlanar:NO
8861 colorSpaceName:NSDeviceRGBColorSpace 8859 colorSpaceName:NSDeviceRGBColorSpace
8862 bytesPerRow:0 8860 bytesPerRow:0
8863 bitsPerPixel:0]; 8861 bitsPerPixel:0];
8864 _flip_image(tmpimage, image, size); 8862 _dw_flip_image(tmpimage, image, size);
8865 pixmap->width = size.width; 8863 pixmap->width = size.width;
8866 pixmap->height = size.height; 8864 pixmap->height = size.height;
8867 pixmap->image = image; 8865 pixmap->image = image;
8868 pixmap->handle = handle; 8866 pixmap->handle = handle;
8869 DW_LOCAL_POOL_OUT; 8867 DW_LOCAL_POOL_OUT;
8907 hasAlpha:YES 8905 hasAlpha:YES
8908 isPlanar:NO 8906 isPlanar:NO
8909 colorSpaceName:NSDeviceRGBColorSpace 8907 colorSpaceName:NSDeviceRGBColorSpace
8910 bytesPerRow:0 8908 bytesPerRow:0
8911 bitsPerPixel:0]; 8909 bitsPerPixel:0];
8912 _flip_image(tmpimage, image, size); 8910 _dw_flip_image(tmpimage, image, size);
8913 pixmap->width = size.width; 8911 pixmap->width = size.width;
8914 pixmap->height = size.height; 8912 pixmap->height = size.height;
8915 pixmap->image = image; 8913 pixmap->image = image;
8916 pixmap->handle = handle; 8914 pixmap->handle = handle;
8917 DW_LOCAL_POOL_OUT; 8915 DW_LOCAL_POOL_OUT;
8968 hasAlpha:YES 8966 hasAlpha:YES
8969 isPlanar:NO 8967 isPlanar:NO
8970 colorSpaceName:NSDeviceRGBColorSpace 8968 colorSpaceName:NSDeviceRGBColorSpace
8971 bytesPerRow:0 8969 bytesPerRow:0
8972 bitsPerPixel:0]; 8970 bitsPerPixel:0];
8973 _flip_image(temp, image, size); 8971 _dw_flip_image(temp, image, size);
8974 pixmap->width = size.width; 8972 pixmap->width = size.width;
8975 pixmap->height = size.height; 8973 pixmap->height = size.height;
8976 pixmap->image = image; 8974 pixmap->image = image;
8977 pixmap->handle = handle; 8975 pixmap->handle = handle;
8978 [temp release]; 8976 [temp release];
9266 9264
9267 #if WK_API_ENABLED 9265 #if WK_API_ENABLED
9268 [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:^(NSString *result, NSError *error) 9266 [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:^(NSString *result, NSError *error)
9269 { 9267 {
9270 void *params[2] = { result, scriptdata }; 9268 void *params[2] = { result, scriptdata };
9271 _event_handler(html, (NSEvent *)params, 18); 9269 _dw_event_handler(html, (NSEvent *)params, 18);
9272 }]; 9270 }];
9273 #else 9271 #else
9274 NSString *result = [html stringByEvaluatingJavaScriptFromString:[NSString stringWithUTF8String:script]]; 9272 NSString *result = [html stringByEvaluatingJavaScriptFromString:[NSString stringWithUTF8String:script]];
9275 void *params[2] = { result, scriptdata }; 9273 void *params[2] = { result, scriptdata };
9276 _event_handler(html, (NSEvent *)params, 18); 9274 _dw_event_handler(html, (NSEvent *)params, 18);
9277 #endif 9275 #endif
9278 DW_LOCAL_POOL_OUT; 9276 DW_LOCAL_POOL_OUT;
9279 return DW_ERROR_NONE; 9277 return DW_ERROR_NONE;
9280 } 9278 }
9281 9279
9353 * location: Handle of a window frame to be attached to. 9351 * location: Handle of a window frame to be attached to.
9354 */ 9352 */
9355 HMENUI API dw_menubar_new(HWND location) 9353 HMENUI API dw_menubar_new(HWND location)
9356 { 9354 {
9357 NSWindow *window = location; 9355 NSWindow *window = location;
9358 NSMenu *windowmenu = _generate_main_menu(); 9356 NSMenu *windowmenu = _dw_generate_main_menu();
9359 [[window contentView] setMenu:windowmenu]; 9357 [[window contentView] setMenu:windowmenu];
9360 return (HMENUI)windowmenu; 9358 return (HMENUI)windowmenu;
9361 } 9359 }
9362 9360
9363 /* 9361 /*
9374 } 9372 }
9375 9373
9376 /* Handle deprecation of convertScreenToBase in 10.10 yet still supporting 9374 /* Handle deprecation of convertScreenToBase in 10.10 yet still supporting
9377 * 10.6 and earlier since convertRectFromScreen was introduced in 10.7. 9375 * 10.6 and earlier since convertRectFromScreen was introduced in 10.7.
9378 */ 9376 */
9379 NSPoint _windowPointFromScreen(id window, NSPoint p) 9377 NSPoint _dw_windowPointFromScreen(id window, NSPoint p)
9380 { 9378 {
9381 SEL crfs = NSSelectorFromString(@"convertRectFromScreen:"); 9379 SEL crfs = NSSelectorFromString(@"convertRectFromScreen:");
9382 9380
9383 if([window respondsToSelector:crfs]) 9381 if([window respondsToSelector:crfs])
9384 { 9382 {
9417 if(!window) 9415 if(!window)
9418 window = [event window]; 9416 window = [event window];
9419 [thismenu autorelease]; 9417 [thismenu autorelease];
9420 NSPoint p = NSMakePoint(x, [[NSScreen mainScreen] frame].size.height - y); 9418 NSPoint p = NSMakePoint(x, [[NSScreen mainScreen] frame].size.height - y);
9421 NSEvent* fake = [NSEvent mouseEventWithType:DWEventTypeRightMouseDown 9419 NSEvent* fake = [NSEvent mouseEventWithType:DWEventTypeRightMouseDown
9422 location:_windowPointFromScreen(window, p) 9420 location:_dw_windowPointFromScreen(window, p)
9423 modifierFlags:0 9421 modifierFlags:0
9424 timestamp:[event timestamp] 9422 timestamp:[event timestamp]
9425 windowNumber:[window windowNumber] 9423 windowNumber:[window windowNumber]
9426 context:[NSGraphicsContext currentContext] 9424 context:[NSGraphicsContext currentContext]
9427 eventNumber:1 9425 eventNumber:1
9428 clickCount:1 9426 clickCount:1
9429 pressure:0.0]; 9427 pressure:0.0];
9430 [NSMenu popUpContextMenu:thismenu withEvent:fake forView:view]; 9428 [NSMenu popUpContextMenu:thismenu withEvent:fake forView:view];
9431 } 9429 }
9432 9430
9433 char _removetilde(char *dest, const char *src) 9431 char _dw_removetilde(char *dest, const char *src)
9434 { 9432 {
9435 int z, cur=0; 9433 int z, cur=0;
9436 char accel = '\0'; 9434 char accel = '\0';
9437 9435
9438 for(z=0;z<strlen(src);z++) 9436 for(z=0;z<strlen(src);z++)
9476 { 9474 {
9477 char accel[2]; 9475 char accel[2];
9478 char *newtitle = malloc(strlen(title)+1); 9476 char *newtitle = malloc(strlen(title)+1);
9479 NSString *nstr; 9477 NSString *nstr;
9480 9478
9481 accel[0] = _removetilde(newtitle, title); 9479 accel[0] = _dw_removetilde(newtitle, title);
9482 accel[1] = 0; 9480 accel[1] = 0;
9483 9481
9484 nstr = [ NSString stringWithUTF8String:newtitle ]; 9482 nstr = [ NSString stringWithUTF8String:newtitle ];
9485 free(newtitle); 9483 free(newtitle);
9486 9484
9593 } 9591 }
9594 } 9592 }
9595 } 9593 }
9596 9594
9597 /* Gets the notebook page from associated ID */ 9595 /* Gets the notebook page from associated ID */
9598 DWNotebookPage *_notepage_from_id(DWNotebook *notebook, unsigned long pageid) 9596 DWNotebookPage *_dw_notepage_from_id(DWNotebook *notebook, unsigned long pageid)
9599 { 9597 {
9600 NSArray *pages = [notebook tabViewItems]; 9598 NSArray *pages = [notebook tabViewItems];
9601 for(DWNotebookPage *notepage in pages) 9599 for(DWNotebookPage *notepage in pages)
9602 { 9600 {
9603 if([notepage pageid] == pageid) 9601 if([notepage pageid] == pageid)
9655 * pageid: ID of the page to be destroyed. 9653 * pageid: ID of the page to be destroyed.
9656 */ 9654 */
9657 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid) 9655 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid)
9658 { 9656 {
9659 DWNotebook *notebook = handle; 9657 DWNotebook *notebook = handle;
9660 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); 9658 DWNotebookPage *notepage = _dw_notepage_from_id(notebook, pageid);
9661 DW_LOCAL_POOL_IN; 9659 DW_LOCAL_POOL_IN;
9662 9660
9663 if(notepage != nil) 9661 if(notepage != nil)
9664 { 9662 {
9665 [notebook removeTabViewItem:notepage]; 9663 [notebook removeTabViewItem:notepage];
9686 * pageid: ID of the page to be made visible. 9684 * pageid: ID of the page to be made visible.
9687 */ 9685 */
9688 void API dw_notebook_page_set(HWND handle, unsigned int pageid) 9686 void API dw_notebook_page_set(HWND handle, unsigned int pageid)
9689 { 9687 {
9690 DWNotebook *notebook = handle; 9688 DWNotebook *notebook = handle;
9691 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); 9689 DWNotebookPage *notepage = _dw_notepage_from_id(notebook, pageid);
9692 9690
9693 if(notepage != nil) 9691 if(notepage != nil)
9694 { 9692 {
9695 [notebook selectTabViewItem:notepage]; 9693 [notebook selectTabViewItem:notepage];
9696 } 9694 }
9704 * text: Pointer to the text to set. 9702 * text: Pointer to the text to set.
9705 */ 9703 */
9706 void API dw_notebook_page_set_text(HWND handle, ULONG pageid, const char *text) 9704 void API dw_notebook_page_set_text(HWND handle, ULONG pageid, const char *text)
9707 { 9705 {
9708 DWNotebook *notebook = handle; 9706 DWNotebook *notebook = handle;
9709 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); 9707 DWNotebookPage *notepage = _dw_notepage_from_id(notebook, pageid);
9710 9708
9711 if(notepage != nil) 9709 if(notepage != nil)
9712 { 9710 {
9713 [notepage setLabel:[ NSString stringWithUTF8String:text ]]; 9711 [notepage setLabel:[ NSString stringWithUTF8String:text ]];
9714 } 9712 }
9734 * page: Box handle to be packed. 9732 * page: Box handle to be packed.
9735 */ 9733 */
9736 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page) 9734 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page)
9737 { 9735 {
9738 DWNotebook *notebook = handle; 9736 DWNotebook *notebook = handle;
9739 DWNotebookPage *notepage = _notepage_from_id(notebook, pageid); 9737 DWNotebookPage *notepage = _dw_notepage_from_id(notebook, pageid);
9740 9738
9741 if(notepage != nil) 9739 if(notepage != nil)
9742 { 9740 {
9743 HWND tmpbox = dw_box_new(DW_VERT, 0); 9741 HWND tmpbox = dw_box_new(DW_VERT, 0);
9744 DWBox *box = tmpbox; 9742 DWBox *box = tmpbox;
9951 * back: Background color in DW_RGB format or a default color index. 9949 * back: Background color in DW_RGB format or a default color index.
9952 */ 9950 */
9953 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back) 9951 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back)
9954 { 9952 {
9955 id object = handle; 9953 id object = handle;
9956 unsigned long _fore = _get_color(fore); 9954 unsigned long _fore = _dw_get_color(fore);
9957 unsigned long _back = _get_color(back); 9955 unsigned long _back = _dw_get_color(back);
9958 NSColor *fg = NULL; 9956 NSColor *fg = NULL;
9959 NSColor *bg = NULL; 9957 NSColor *bg = NULL;
9960 9958
9961 /* Get the NSColor for non-default colors */ 9959 /* Get the NSColor for non-default colors */
9962 if(fore != DW_CLR_DEFAULT) 9960 if(fore != DW_CLR_DEFAULT)
10032 * width: New width in pixels. 10030 * width: New width in pixels.
10033 * height: New height in pixels. 10031 * height: New height in pixels.
10034 */ 10032 */
10035 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) 10033 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask)
10036 { 10034 {
10037 id object = _text_handle(handle); 10035 id object = _dw_text_handle(handle);
10038 10036
10039 if([object isMemberOfClass:[DWWindow class]]) 10037 if([object isMemberOfClass:[DWWindow class]])
10040 { 10038 {
10041 DWWindow *window = object; 10039 DWWindow *window = object;
10042 SEL sssm = NSSelectorFromString(@"setStyleMask"); 10040 SEL sssm = NSSelectorFromString(@"setStyleMask");
10283 } 10281 }
10284 10282
10285 /* Internal function to return a pointer to an item struct 10283 /* Internal function to return a pointer to an item struct
10286 * with information about the packing information regarding object. 10284 * with information about the packing information regarding object.
10287 */ 10285 */
10288 Item *_box_item(id object) 10286 Item *_dw_box_item(id object)
10289 { 10287 {
10290 /* Find the item within the box it is packed into */ 10288 /* Find the item within the box it is packed into */
10291 if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[DWGroupBox class]] || [object isKindOfClass:[NSControl class]]) 10289 if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[DWGroupBox class]] || [object isKindOfClass:[NSControl class]])
10292 { 10290 {
10293 DWBox *parent = (DWBox *)[object superview]; 10291 DWBox *parent = (DWBox *)[object superview];
10328 NSFont *font = fontname ? _dw_font_by_name(fontname) : 10326 NSFont *font = fontname ? _dw_font_by_name(fontname) :
10329 (DWDefaultFont ? DWDefaultFont : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]); 10327 (DWDefaultFont ? DWDefaultFont : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]);
10330 10328
10331 if(font) 10329 if(font)
10332 { 10330 {
10333 id object = _text_handle(handle); 10331 id object = _dw_text_handle(handle);
10334 if([object window]) 10332 if([object window])
10335 { 10333 {
10336 [object lockFocus]; 10334 [object lockFocus];
10337 [font set]; 10335 [font set];
10338 [object unlockFocus]; 10336 [object unlockFocus];
10359 [render setFont:font]; 10357 [render setFont:font];
10360 } 10358 }
10361 else 10359 else
10362 return DW_ERROR_UNKNOWN; 10360 return DW_ERROR_UNKNOWN;
10363 /* If we changed the text... */ 10361 /* If we changed the text... */
10364 Item *item = _box_item(handle); 10362 Item *item = _dw_box_item(handle);
10365 10363
10366 /* Check to see if any of the sizes need to be recalculated */ 10364 /* Check to see if any of the sizes need to be recalculated */
10367 if(item && (item->origwidth == -1 || item->origheight == -1)) 10365 if(item && (item->origwidth == -1 || item->origheight == -1))
10368 { 10366 {
10369 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); 10367 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
10380 * Parameters: 10378 * Parameters:
10381 * handle: The window handle from which to obtain the font. 10379 * handle: The window handle from which to obtain the font.
10382 */ 10380 */
10383 char * API dw_window_get_font(HWND handle) 10381 char * API dw_window_get_font(HWND handle)
10384 { 10382 {
10385 id object = _text_handle(handle); 10383 id object = _dw_text_handle(handle);
10386 NSFont *font = nil; 10384 NSFont *font = nil;
10387 10385
10388 if([object isMemberOfClass:[DWGroupBox class]]) 10386 if([object isMemberOfClass:[DWGroupBox class]])
10389 { 10387 {
10390 font = [object titleFont]; 10388 font = [object titleFont];
10508 DW_FUNCTION_ADD_PARAM1(handle) 10506 DW_FUNCTION_ADD_PARAM1(handle)
10509 DW_FUNCTION_RETURN(dw_window_get_text, char *) 10507 DW_FUNCTION_RETURN(dw_window_get_text, char *)
10510 DW_FUNCTION_RESTORE_PARAM1(handle, HWND) 10508 DW_FUNCTION_RESTORE_PARAM1(handle, HWND)
10511 { 10509 {
10512 DW_FUNCTION_INIT; 10510 DW_FUNCTION_INIT;
10513 id object = _text_handle(handle); 10511 id object = _dw_text_handle(handle);
10514 char *retval = NULL; 10512 char *retval = NULL;
10515 10513
10516 if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ]) 10514 if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ])
10517 { 10515 {
10518 id window = object; 10516 id window = object;
10540 DW_FUNCTION_ADD_PARAM2(handle, text) 10538 DW_FUNCTION_ADD_PARAM2(handle, text)
10541 DW_FUNCTION_NO_RETURN(dw_window_set_text) 10539 DW_FUNCTION_NO_RETURN(dw_window_set_text)
10542 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, text, char *) 10540 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, text, char *)
10543 { 10541 {
10544 DW_FUNCTION_INIT; 10542 DW_FUNCTION_INIT;
10545 id object = _text_handle(handle); 10543 id object = _dw_text_handle(handle);
10546 10544
10547 if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ]) 10545 if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ])
10548 [object setTitle:[ NSString stringWithUTF8String:text ]]; 10546 [object setTitle:[ NSString stringWithUTF8String:text ]];
10549 else if([ object isKindOfClass:[ NSControl class ] ]) 10547 else if([ object isKindOfClass:[ NSControl class ] ])
10550 { 10548 {
10557 [groupbox setTitle:[NSString stringWithUTF8String:text]]; 10555 [groupbox setTitle:[NSString stringWithUTF8String:text]];
10558 } 10556 }
10559 else 10557 else
10560 return; 10558 return;
10561 /* If we changed the text... */ 10559 /* If we changed the text... */
10562 Item *item = _box_item(handle); 10560 Item *item = _dw_box_item(handle);
10563 10561
10564 /* Check to see if any of the sizes need to be recalculated */ 10562 /* Check to see if any of the sizes need to be recalculated */
10565 if(item && (item->origwidth == -1 || item->origheight == -1)) 10563 if(item && (item->origwidth == -1 || item->origheight == -1))
10566 { 10564 {
10567 int newwidth, newheight; 10565 int newwidth, newheight;
10690 if(pixmap) 10688 if(pixmap)
10691 { 10689 {
10692 [object setImage:pixmap]; 10690 [object setImage:pixmap];
10693 } 10691 }
10694 /* If we changed the bitmap... */ 10692 /* If we changed the bitmap... */
10695 Item *item = _box_item(handle); 10693 Item *item = _dw_box_item(handle);
10696 10694
10697 /* Check to see if any of the sizes need to be recalculated */ 10695 /* Check to see if any of the sizes need to be recalculated */
10698 if(item && (item->origwidth == -1 || item->origheight == -1)) 10696 if(item && (item->origwidth == -1 || item->origheight == -1))
10699 { 10697 {
10700 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); 10698 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
10748 if(bitmap) 10746 if(bitmap)
10749 { 10747 {
10750 [object setImage:bitmap]; 10748 [object setImage:bitmap];
10751 10749
10752 /* If we changed the bitmap... */ 10750 /* If we changed the bitmap... */
10753 Item *item = _box_item(handle); 10751 Item *item = _dw_box_item(handle);
10754 10752
10755 /* Check to see if any of the sizes need to be recalculated */ 10753 /* Check to see if any of the sizes need to be recalculated */
10756 if(item && (item->origwidth == -1 || item->origheight == -1)) 10754 if(item && (item->origwidth == -1 || item->origheight == -1))
10757 { 10755 {
10758 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); 10756 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
10827 */ 10825 */
10828 int API dw_window_raise(HWND handle) 10826 int API dw_window_raise(HWND handle)
10829 { 10827 {
10830 NSWindow *window = handle; 10828 NSWindow *window = handle;
10831 [window orderFront:nil]; 10829 [window orderFront:nil];
10832 return 0; 10830 return DW_ERROR_NONE;
10833 } 10831 }
10834 10832
10835 /* 10833 /*
10836 * Makes the window bottommost. 10834 * Makes the window bottommost.
10837 * Parameters: 10835 * Parameters:
10839 */ 10837 */
10840 int API dw_window_lower(HWND handle) 10838 int API dw_window_lower(HWND handle)
10841 { 10839 {
10842 NSWindow *window = handle; 10840 NSWindow *window = handle;
10843 [window orderBack:nil]; 10841 [window orderBack:nil];
10844 return 0; 10842 return DW_ERROR_NONE;
10845 } 10843 }
10846 10844
10847 /* 10845 /*
10848 * Sets the size of a given window (widget). 10846 * Sets the size of a given window (widget).
10849 * Parameters: 10847 * Parameters:
10875 if((width < 1 || height < 1) && (thisbox = (Box *)[[window contentView] box])) 10873 if((width < 1 || height < 1) && (thisbox = (Box *)[[window contentView] box]))
10876 { 10874 {
10877 int depth = 0; 10875 int depth = 0;
10878 10876
10879 /* Calculate space requirements */ 10877 /* Calculate space requirements */
10880 _resize_box(thisbox, &depth, (int)width, (int)height, 1); 10878 _dw_resize_box(thisbox, &depth, (int)width, (int)height, 1);
10881 10879
10882 /* Update components that need auto-sizing */ 10880 /* Update components that need auto-sizing */
10883 if(width < 1) content.size.width = thisbox->minwidth; 10881 if(width < 1) content.size.width = thisbox->minwidth;
10884 if(height < 1) content.size.height = thisbox->minheight; 10882 if(height < 1) content.size.height = thisbox->minheight;
10885 } 10883 }
10909 { 10907 {
10910 int depth = 0; 10908 int depth = 0;
10911 NSRect frame; 10909 NSRect frame;
10912 10910
10913 /* Calculate space requirements */ 10911 /* Calculate space requirements */
10914 _resize_box(thisbox, &depth, 0, 0, 1); 10912 _dw_resize_box(thisbox, &depth, 0, 0, 1);
10915 10913
10916 /* Figure out the border size */ 10914 /* Figure out the border size */
10917 frame = [NSWindow frameRectForContentRect:NSMakeRect(0, 0, thisbox->minwidth, thisbox->minheight) styleMask:[object styleMask]]; 10915 frame = [NSWindow frameRectForContentRect:NSMakeRect(0, 0, thisbox->minwidth, thisbox->minheight) styleMask:[object styleMask]];
10918 10916
10919 /* Return what was requested */ 10917 /* Return what was requested */
10928 if((thisbox = (Box *)[object box])) 10926 if((thisbox = (Box *)[object box]))
10929 { 10927 {
10930 int depth = 0; 10928 int depth = 0;
10931 10929
10932 /* Calculate space requirements */ 10930 /* Calculate space requirements */
10933 _resize_box(thisbox, &depth, 0, 0, 1); 10931 _dw_resize_box(thisbox, &depth, 0, 0, 1);
10934 10932
10935 /* Return what was requested */ 10933 /* Return what was requested */
10936 if(width) *width = thisbox->minwidth; 10934 if(width) *width = thisbox->minwidth;
10937 if(height) *height = thisbox->minheight; 10935 if(height) *height = thisbox->minheight;
10938 } 10936 }
11306 11304
11307 /* Functions for managing the user data lists that are associated with 11305 /* Functions for managing the user data lists that are associated with
11308 * a given window handle. Used in dw_window_set_data() and 11306 * a given window handle. Used in dw_window_set_data() and
11309 * dw_window_get_data(). 11307 * dw_window_get_data().
11310 */ 11308 */
11311 UserData *_find_userdata(UserData **root, const char *varname) 11309 UserData *_dw_find_userdata(UserData **root, const char *varname)
11312 { 11310 {
11313 UserData *tmp = *root; 11311 UserData *tmp = *root;
11314 11312
11315 while(tmp) 11313 while(tmp)
11316 { 11314 {
11319 tmp = tmp->next; 11317 tmp = tmp->next;
11320 } 11318 }
11321 return NULL; 11319 return NULL;
11322 } 11320 }
11323 11321
11324 int _new_userdata(UserData **root, const char *varname, void *data) 11322 int _dw_new_userdata(UserData **root, const char *varname, void *data)
11325 { 11323 {
11326 UserData *new = _find_userdata(root, varname); 11324 UserData *new = _dw_find_userdata(root, varname);
11327 11325
11328 if(new) 11326 if(new)
11329 { 11327 {
11330 new->data = data; 11328 new->data = data;
11331 return TRUE; 11329 return TRUE;
11357 } 11355 }
11358 } 11356 }
11359 return FALSE; 11357 return FALSE;
11360 } 11358 }
11361 11359
11362 int _remove_userdata(UserData **root, const char *varname, int all) 11360 int _dw_remove_userdata(UserData **root, const char *varname, int all)
11363 { 11361 {
11364 UserData *prev = NULL, *tmp = *root; 11362 UserData *prev = NULL, *tmp = *root;
11365 11363
11366 while(tmp) 11364 while(tmp)
11367 { 11365 {
11426 blah = calloc(1, sizeof(WindowData)); 11424 blah = calloc(1, sizeof(WindowData));
11427 [object setUserdata:blah]; 11425 [object setUserdata:blah];
11428 } 11426 }
11429 11427
11430 if(data) 11428 if(data)
11431 _new_userdata(&(blah->root), dataname, data); 11429 _dw_new_userdata(&(blah->root), dataname, data);
11432 else 11430 else
11433 { 11431 {
11434 if(dataname) 11432 if(dataname)
11435 _remove_userdata(&(blah->root), dataname, FALSE); 11433 _dw_remove_userdata(&(blah->root), dataname, FALSE);
11436 else 11434 else
11437 _remove_userdata(&(blah->root), NULL, TRUE); 11435 _dw_remove_userdata(&(blah->root), NULL, TRUE);
11438 } 11436 }
11439 } 11437 }
11440 11438
11441 /* 11439 /*
11442 * Gets a named user data item to a window handle. 11440 * Gets a named user data item to a window handle.
11460 } 11458 }
11461 WindowData *blah = (WindowData *)[object userdata]; 11459 WindowData *blah = (WindowData *)[object userdata];
11462 11460
11463 if(blah && blah->root && dataname) 11461 if(blah && blah->root && dataname)
11464 { 11462 {
11465 UserData *ud = _find_userdata(&(blah->root), dataname); 11463 UserData *ud = _dw_find_userdata(&(blah->root), dataname);
11466 if(ud) 11464 if(ud)
11467 return ud->data; 11465 return ud->data;
11468 } 11466 }
11469 return NULL; 11467 return NULL;
11470 } 11468 }
11471 11469
11472 #define DW_TIMER_MAX 64 11470 #define DW_TIMER_MAX 64
11473 NSTimer *DWTimers[DW_TIMER_MAX]; 11471 static NSTimer *DWTimers[DW_TIMER_MAX];
11474 11472
11475 /* 11473 /*
11476 * Add a callback to a timer event. 11474 * Add a callback to a timer event.
11477 * Parameters: 11475 * Parameters:
11478 * interval: Milliseconds to delay between calls. 11476 * interval: Milliseconds to delay between calls.
11495 11493
11496 if(sigfunc && !DWTimers[z]) 11494 if(sigfunc && !DWTimers[z])
11497 { 11495 {
11498 NSTimeInterval seconds = (double)interval / 1000.0; 11496 NSTimeInterval seconds = (double)interval / 1000.0;
11499 NSTimer *thistimer = DWTimers[z] = [NSTimer scheduledTimerWithTimeInterval:seconds target:DWHandler selector:@selector(runTimer:) userInfo:nil repeats:YES]; 11497 NSTimer *thistimer = DWTimers[z] = [NSTimer scheduledTimerWithTimeInterval:seconds target:DWHandler selector:@selector(runTimer:) userInfo:nil repeats:YES];
11500 _new_signal(0, thistimer, z+1, sigfunc, NULL, data); 11498 _dw_new_signal(0, thistimer, z+1, sigfunc, NULL, data);
11501 return z+1; 11499 return z+1;
11502 } 11500 }
11503 return 0; 11501 return 0;
11504 } 11502 }
11505 11503
11508 * Parameters: 11506 * Parameters:
11509 * id: Timer ID returned by dw_timer_connect(). 11507 * id: Timer ID returned by dw_timer_connect().
11510 */ 11508 */
11511 void API dw_timer_disconnect(int timerid) 11509 void API dw_timer_disconnect(int timerid)
11512 { 11510 {
11513 SignalHandler *prev = NULL, *tmp = Root; 11511 SignalHandler *prev = NULL, *tmp = DWRoot;
11514 NSTimer *thistimer; 11512 NSTimer *thistimer;
11515 11513
11516 /* 0 is an invalid timer ID */ 11514 /* 0 is an invalid timer ID */
11517 if(timerid < 1 || !DWTimers[timerid-1]) 11515 if(timerid < 1 || !DWTimers[timerid-1])
11518 return; 11516 return;
11532 free(tmp); 11530 free(tmp);
11533 tmp = prev->next; 11531 tmp = prev->next;
11534 } 11532 }
11535 else 11533 else
11536 { 11534 {
11537 Root = tmp->next; 11535 DWRoot = tmp->next;
11538 free(tmp); 11536 free(tmp);
11539 tmp = Root; 11537 tmp = DWRoot;
11540 } 11538 }
11541 } 11539 }
11542 else 11540 else
11543 { 11541 {
11544 prev = tmp; 11542 prev = tmp;
11579 window = DWApp; 11577 window = DWApp;
11580 } 11578 }
11581 11579
11582 if(window && signame && sigfunc) 11580 if(window && signame && sigfunc)
11583 { 11581 {
11584 if((message = _findsigmessage(signame)) != 0) 11582 if((message = _dw_findsigmessage(signame)) != 0)
11585 { 11583 {
11586 _new_signal(message, window, (int)msgid, sigfunc, discfunc, data); 11584 _dw_new_signal(message, window, (int)msgid, sigfunc, discfunc, data);
11587 } 11585 }
11588 } 11586 }
11589 } 11587 }
11590 11588
11591 /* 11589 /*
11593 * Parameters: 11591 * Parameters:
11594 * window: Window handle of callback to be removed. 11592 * window: Window handle of callback to be removed.
11595 */ 11593 */
11596 void API dw_signal_disconnect_by_name(HWND window, const char *signame) 11594 void API dw_signal_disconnect_by_name(HWND window, const char *signame)
11597 { 11595 {
11598 SignalHandler *prev = NULL, *tmp = Root; 11596 SignalHandler *prev = NULL, *tmp = DWRoot;
11599 ULONG message; 11597 ULONG message;
11600 11598
11601 if(!window || !signame || (message = _findsigmessage(signame)) == 0) 11599 if(!window || !signame || (message = _dw_findsigmessage(signame)) == 0)
11602 return; 11600 return;
11603 11601
11604 while(tmp) 11602 while(tmp)
11605 { 11603 {
11606 if(tmp->window == window && tmp->message == message) 11604 if(tmp->window == window && tmp->message == message)
11618 free(tmp); 11616 free(tmp);
11619 tmp = prev->next; 11617 tmp = prev->next;
11620 } 11618 }
11621 else 11619 else
11622 { 11620 {
11623 Root = tmp->next; 11621 DWRoot = tmp->next;
11624 free(tmp); 11622 free(tmp);
11625 tmp = Root; 11623 tmp = DWRoot;
11626 } 11624 }
11627 } 11625 }
11628 else 11626 else
11629 { 11627 {
11630 prev = tmp; 11628 prev = tmp;
11638 * Parameters: 11636 * Parameters:
11639 * window: Window handle of callback to be removed. 11637 * window: Window handle of callback to be removed.
11640 */ 11638 */
11641 void API dw_signal_disconnect_by_window(HWND window) 11639 void API dw_signal_disconnect_by_window(HWND window)
11642 { 11640 {
11643 SignalHandler *prev = NULL, *tmp = Root; 11641 SignalHandler *prev = NULL, *tmp = DWRoot;
11644 11642
11645 while(tmp) 11643 while(tmp)
11646 { 11644 {
11647 if(tmp->window == window) 11645 if(tmp->window == window)
11648 { 11646 {
11659 free(tmp); 11657 free(tmp);
11660 tmp = prev->next; 11658 tmp = prev->next;
11661 } 11659 }
11662 else 11660 else
11663 { 11661 {
11664 Root = tmp->next; 11662 DWRoot = tmp->next;
11665 free(tmp); 11663 free(tmp);
11666 tmp = Root; 11664 tmp = DWRoot;
11667 } 11665 }
11668 } 11666 }
11669 else 11667 else
11670 { 11668 {
11671 prev = tmp; 11669 prev = tmp;
11680 * window: Window handle of callback to be removed. 11678 * window: Window handle of callback to be removed.
11681 * data: Pointer to the data to be compared against. 11679 * data: Pointer to the data to be compared against.
11682 */ 11680 */
11683 void API dw_signal_disconnect_by_data(HWND window, void *data) 11681 void API dw_signal_disconnect_by_data(HWND window, void *data)
11684 { 11682 {
11685 SignalHandler *prev = NULL, *tmp = Root; 11683 SignalHandler *prev = NULL, *tmp = DWRoot;
11686 11684
11687 while(tmp) 11685 while(tmp)
11688 { 11686 {
11689 if(tmp->window == window && tmp->data == data) 11687 if(tmp->window == window && tmp->data == data)
11690 { 11688 {
11701 free(tmp); 11699 free(tmp);
11702 tmp = prev->next; 11700 tmp = prev->next;
11703 } 11701 }
11704 else 11702 else
11705 { 11703 {
11706 Root = tmp->next; 11704 DWRoot = tmp->next;
11707 free(tmp); 11705 free(tmp);
11708 tmp = Root; 11706 tmp = DWRoot;
11709 } 11707 }
11710 } 11708 }
11711 else 11709 else
11712 { 11710 {
11713 prev = tmp; 11711 prev = tmp;
11714 tmp = tmp->next; 11712 tmp = tmp->next;
11715 } 11713 }
11716 } 11714 }
11717 } 11715 }
11718 11716
11719 void _my_strlwr(char *buf) 11717 void _dw_my_strlwr(char *buf)
11720 { 11718 {
11721 int z, len = (int)strlen(buf); 11719 int z, len = (int)strlen(buf);
11722 11720
11723 for(z=0;z<len;z++) 11721 for(z=0;z<len;z++)
11724 { 11722 {
11751 11749
11752 if(!newname) 11750 if(!newname)
11753 return -1; 11751 return -1;
11754 11752
11755 sprintf(newname, "lib%s.dylib", name); 11753 sprintf(newname, "lib%s.dylib", name);
11756 _my_strlwr(newname); 11754 _dw_my_strlwr(newname);
11757 11755
11758 *handle = dlopen(newname, RTLD_NOW); 11756 *handle = dlopen(newname, RTLD_NOW);
11759 if(*handle == NULL) 11757 if(*handle == NULL)
11760 { 11758 {
11761 strncpy(errorbuf, dlerror(), 1024); 11759 strncpy(errorbuf, dlerror(), 1024);
12002 struct _seminfo { 12000 struct _seminfo {
12003 int fd; 12001 int fd;
12004 int waiting; 12002 int waiting;
12005 }; 12003 };
12006 12004
12007 static void _handle_sem(int *tmpsock) 12005 static void _dw_handle_sem(int *tmpsock)
12008 { 12006 {
12009 fd_set rd; 12007 fd_set rd;
12010 struct _seminfo *array = (struct _seminfo *)malloc(sizeof(struct _seminfo)); 12008 struct _seminfo *array = (struct _seminfo *)malloc(sizeof(struct _seminfo));
12011 int listenfd = tmpsock[0]; 12009 int listenfd = tmpsock[0];
12012 int bytesread, connectcount = 1, maxfd, z, posted = 0; 12010 int bytesread, connectcount = 1, maxfd, z, posted = 0;
12211 free(eve); 12209 free(eve);
12212 return NULL; 12210 return NULL;
12213 } 12211 }
12214 12212
12215 /* Create a thread to handle this event semaphore */ 12213 /* Create a thread to handle this event semaphore */
12216 pthread_create(&dwthread, NULL, (void *)_handle_sem, (void *)tmpsock); 12214 pthread_create(&dwthread, NULL, (void *)_dw_handle_sem, (void *)tmpsock);
12217 eve->alive = ev; 12215 eve->alive = ev;
12218 return eve; 12216 return eve;
12219 } 12217 }
12220 12218
12221 /* Open an already existing named event semaphore. 12219 /* Open an already existing named event semaphore.
12347 * an open or create call. 12345 * an open or create call.
12348 */ 12346 */
12349 int dw_named_event_close(HEV eve) 12347 int dw_named_event_close(HEV eve)
12350 { 12348 {
12351 /* Finally close the domain socket, 12349 /* Finally close the domain socket,
12352 * cleanup will continue in _handle_sem. 12350 * cleanup will continue in _dw_handle_sem.
12353 */ 12351 */
12354 if(eve) 12352 if(eve)
12355 { 12353 {
12356 close(eve->alive); 12354 close(eve->alive);
12357 free(eve); 12355 free(eve);
12381 /* If we aren't using garbage collection we need autorelease pools */ 12379 /* If we aren't using garbage collection we need autorelease pools */
12382 #if !defined(GARBAGE_COLLECT) 12380 #if !defined(GARBAGE_COLLECT)
12383 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 12381 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
12384 pthread_setspecific(_dw_pool_key, pool); 12382 pthread_setspecific(_dw_pool_key, pool);
12385 #endif 12383 #endif
12386 _init_colors(); 12384 _dw_init_colors();
12387 } 12385 }
12388 12386
12389 /* 12387 /*
12390 * Generally an internal function called from a terminating 12388 * Generally an internal function called from a terminating
12391 * thread to cleanup the Dynamic Windows environment for the thread. 12389 * thread to cleanup the Dynamic Windows environment for the thread.
12400 color = pthread_getspecific(_dw_fg_color_key); 12398 color = pthread_getspecific(_dw_fg_color_key);
12401 [color release]; 12399 [color release];
12402 color = pthread_getspecific(_dw_bg_color_key); 12400 color = pthread_getspecific(_dw_bg_color_key);
12403 [color release]; 12401 [color release];
12404 #if !defined(GARBAGE_COLLECT) 12402 #if !defined(GARBAGE_COLLECT)
12405 pool = pthread_getspecific(_dw_pool_key); 12403 NSAutoreleasePool *pool = pthread_getspecific(_dw_pool_key);
12406 [pool drain]; 12404 [pool drain];
12407 #endif 12405 #endif
12408 } 12406 }
12409 12407
12410 /* 12408 /*
12524 /* Create object for handling timers */ 12522 /* Create object for handling timers */
12525 DWHandler = [[DWTimerHandler alloc] init]; 12523 DWHandler = [[DWTimerHandler alloc] init];
12526 /* If we aren't using garbage collection we need autorelease pools */ 12524 /* If we aren't using garbage collection we need autorelease pools */
12527 #if !defined(GARBAGE_COLLECT) 12525 #if !defined(GARBAGE_COLLECT)
12528 pthread_key_create(&_dw_pool_key, NULL); 12526 pthread_key_create(&_dw_pool_key, NULL);
12529 pool = [[NSAutoreleasePool alloc] init]; 12527 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
12530 pthread_setspecific(_dw_pool_key, pool); 12528 pthread_setspecific(_dw_pool_key, pool);
12531 #endif 12529 #endif
12532 pthread_key_create(&_dw_fg_color_key, NULL); 12530 pthread_key_create(&_dw_fg_color_key, NULL);
12533 pthread_key_create(&_dw_bg_color_key, NULL); 12531 pthread_key_create(&_dw_bg_color_key, NULL);
12534 _init_colors(); 12532 _dw_init_colors();
12535 /* Create a default main menu, with just the application menu */ 12533 /* Create a default main menu, with just the application menu */
12536 DWMainMenu = _generate_main_menu(); 12534 DWMainMenu = _dw_generate_main_menu();
12537 [DWMainMenu retain]; 12535 [DWMainMenu retain];
12538 [DWApp setMainMenu:DWMainMenu]; 12536 [DWApp setMainMenu:DWMainMenu];
12539 DWObj = [[DWObject alloc] init]; 12537 DWObj = [[DWObject alloc] init];
12540 DWDefaultFont = nil; 12538 DWDefaultFont = nil;
12541 DWFontManager = [NSFontManager sharedFontManager]; 12539 DWFontManager = [NSFontManager sharedFontManager];
13055 /* Call the application's draw function */ 13053 /* Call the application's draw function */
13056 p->drawfunc(print, pixmap, x, p->drawdata); 13054 p->drawfunc(print, pixmap, x, p->drawdata);
13057 if(p->drawfunc) 13055 if(p->drawfunc)
13058 { 13056 {
13059 /* Internal representation is flipped... so flip again so we can print */ 13057 /* Internal representation is flipped... so flip again so we can print */
13060 _flip_image(image, rep2, size); 13058 _dw_flip_image(image, rep2, size);
13061 #ifdef DEBUG_PRINT 13059 #ifdef DEBUG_PRINT
13062 /* Save it to file to see what we have */ 13060 /* Save it to file to see what we have */
13063 NSData *data = [rep2 representationUsingType: NSPNGFileType properties: nil]; 13061 NSData *data = [rep2 representationUsingType: NSPNGFileType properties: nil];
13064 [data writeToFile: @"print.png" atomically: NO]; 13062 [data writeToFile: @"print.png" atomically: NO];
13065 #endif 13063 #endif