comparison mac/dw.m @ 2103:2417bc294e30

Mac: Make sure DWApp is initialized before using it.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 15 Jun 2020 22:05:55 +0000
parents 07666f97412f
children 50196f67a129
comparison
equal deleted inserted replaced
2102:9a5dbda8f2ab 2103:2417bc294e30
825 825
826 @implementation DWTimerHandler 826 @implementation DWTimerHandler
827 -(void)runTimer:(id)sender { _event_handler(sender, nil, 0); } 827 -(void)runTimer:(id)sender { _event_handler(sender, nil, 0); }
828 @end 828 @end
829 829
830 NSApplication *DWApp; 830 NSApplication *DWApp = nil;
831 NSMenu *DWMainMenu; 831 NSMenu *DWMainMenu;
832 NSFont *DWDefaultFont; 832 NSFont *DWDefaultFont;
833 DWTimerHandler *DWHandler; 833 DWTimerHandler *DWHandler;
834 #if !defined(GARBAGE_COLLECT) 834 #if !defined(GARBAGE_COLLECT)
835 NSAutoreleasePool *pool; 835 NSAutoreleasePool *pool;
12037 DWDefaultFont = _dw_font_by_name(fontname); 12037 DWDefaultFont = _dw_font_by_name(fontname);
12038 [DWDefaultFont retain]; 12038 [DWDefaultFont retain];
12039 [oldfont release]; 12039 [oldfont release];
12040 } 12040 }
12041 12041
12042 /* If DWApp is uninitialized, initialize it */
12043 void _dw_app_init(void)
12044 {
12045 if(!DWApp)
12046 {
12047 DWApp = [NSApplication sharedApplication];
12048 DWAppDel *del = [[DWAppDel alloc] init];
12049 [DWApp setDelegate:del];
12050 }
12051 }
12052
12042 /* 12053 /*
12043 * Initializes the Dynamic Windows engine. 12054 * Initializes the Dynamic Windows engine.
12044 * Parameters: 12055 * Parameters:
12045 * newthread: True if this is the only thread. 12056 * newthread: True if this is the only thread.
12046 * False if there is already a message loop running. 12057 * False if there is already a message loop running.
12099 /* Set the locale... if it is UTF-8 pass it 12110 /* Set the locale... if it is UTF-8 pass it
12100 * directly, otherwise specify UTF-8 explicitly. 12111 * directly, otherwise specify UTF-8 explicitly.
12101 */ 12112 */
12102 setlocale(LC_ALL, lang && strstr(lang, ".UTF-8") ? lang : "UTF-8"); 12113 setlocale(LC_ALL, lang && strstr(lang, ".UTF-8") ? lang : "UTF-8");
12103 /* Create the application object */ 12114 /* Create the application object */
12104 DWApp = [NSApplication sharedApplication]; 12115 _dw_app_init();
12105 DWAppDel *del = [[DWAppDel alloc] init];
12106 [DWApp setDelegate:del];
12107 /* Create object for handling timers */ 12116 /* Create object for handling timers */
12108 DWHandler = [[DWTimerHandler alloc] init]; 12117 DWHandler = [[DWTimerHandler alloc] init];
12109 /* If we aren't using garbage collection we need autorelease pools */ 12118 /* If we aren't using garbage collection we need autorelease pools */
12110 #if !defined(GARBAGE_COLLECT) 12119 #if !defined(GARBAGE_COLLECT)
12111 pthread_key_create(&_dw_pool_key, NULL); 12120 pthread_key_create(&_dw_pool_key, NULL);
12629 #ifdef BUILDING_FOR_MOJAVE 12638 #ifdef BUILDING_FOR_MOJAVE
12630 case DW_FEATURE_DARK_MODE: 12639 case DW_FEATURE_DARK_MODE:
12631 { 12640 {
12632 if(@available(macOS 10.14, *)) 12641 if(@available(macOS 10.14, *))
12633 { 12642 {
12643 /* Make sure DWApp is initialized */
12644 _dw_app_init();
12645 /* Get the current appearance */
12634 NSAppearance *appearance = [DWApp appearance]; 12646 NSAppearance *appearance = [DWApp appearance];
12635 12647
12636 if(appearance) 12648 if(appearance)
12637 { 12649 {
12638 NSAppearanceName basicAppearance = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; 12650 NSAppearanceName basicAppearance = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
12683 #ifdef BUILDING_FOR_MOJAVE 12695 #ifdef BUILDING_FOR_MOJAVE
12684 case DW_FEATURE_DARK_MODE: 12696 case DW_FEATURE_DARK_MODE:
12685 { 12697 {
12686 if(@available(macOS 10.14, *)) 12698 if(@available(macOS 10.14, *))
12687 { 12699 {
12700 /* Make sure DWApp is initialized */
12701 _dw_app_init();
12688 /* Disabled forces the non-dark aqua theme */ 12702 /* Disabled forces the non-dark aqua theme */
12689 if(state == DW_FEATURE_DISABLED) 12703 if(state == DW_FEATURE_DISABLED)
12690 [DWApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]]; 12704 [DWApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
12691 /* Enabled lets the OS decide the mode */ 12705 /* Enabled lets the OS decide the mode */
12692 else if(state == DW_FEATURE_ENABLED || state == 2) 12706 else if(state == DW_FEATURE_ENABLED || state == 2)