comparison ios/dw.m @ 2456:54f760a257f3

iOS: initial support for iOS Dark Mode... untested. Part 2. Ugh in my haste to commit this, I was in the wrong Terminal window and instead committed a typo fix in the Mac code in that last commit.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 13 Apr 2021 20:01:36 +0000
parents 2c03987c95bd
children 181e48c5dc0c
comparison
equal deleted inserted replaced
2455:0315ae3a8820 2456:54f760a257f3
235 pthread_key_t _dw_fg_color_key; 235 pthread_key_t _dw_fg_color_key;
236 pthread_key_t _dw_bg_color_key; 236 pthread_key_t _dw_bg_color_key;
237 static int DWOSMajor, DWOSMinor, DWOSBuild; 237 static int DWOSMajor, DWOSMinor, DWOSBuild;
238 static char _dw_bundle_path[PATH_MAX+1] = { 0 }; 238 static char _dw_bundle_path[PATH_MAX+1] = { 0 };
239 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; 239 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0};
240 static int _dw_dark_mode_state = DW_FEATURE_UNSUPPORTED;
240 241
241 /* Create a default colors for a thread */ 242 /* Create a default colors for a thread */
242 void _dw_init_colors(void) 243 void _dw_init_colors(void)
243 { 244 {
244 UIColor *fgcolor = [[UIColor grayColor] retain]; 245 UIColor *fgcolor = [[UIColor grayColor] retain];
627 } 628 }
628 -(void)uselessThread:(id)sender; 629 -(void)uselessThread:(id)sender;
629 -(void)menuHandler:(id)param; 630 -(void)menuHandler:(id)param;
630 -(void)doBitBlt:(id)param; 631 -(void)doBitBlt:(id)param;
631 -(void)doFlush:(id)param; 632 -(void)doFlush:(id)param;
633 -(UIWindow *)hiddenWindow;
632 @end 634 @end
633 635
634 API_AVAILABLE(ios(13.0)) 636 API_AVAILABLE(ios(13.0))
635 @interface DWMenuItem : UICommand 637 @interface DWMenuItem : UICommand
636 { 638 {
1013 */ 1015 */
1014 hiddenWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 1016 hiddenWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
1015 [hiddenWindow setWindowLevel:UIWindowLevelAlert+1]; 1017 [hiddenWindow setWindowLevel:UIWindowLevelAlert+1];
1016 [hiddenWindow setHidden:YES]; 1018 [hiddenWindow setHidden:YES];
1017 [hiddenWindow setRootViewController:[UIViewController new]]; 1019 [hiddenWindow setRootViewController:[UIViewController new]];
1018 } 1020 /* Handle setting the dark mode state now that DWObj is valid */
1021 if(_dw_dark_mode_state != DW_FEATURE_UNSUPPORTED)
1022 dw_feature_set(DW_FEATURE_DARK_MODE, _dw_dark_mode_state);
1023 }
1024 -(UIWindow *)hiddenWindow { return hiddenWindow; };
1019 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ } 1025 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ }
1020 -(void)menuHandler:(id)param 1026 -(void)menuHandler:(id)param
1021 { 1027 {
1022 _dw_event_handler(param, nil, 8); 1028 _dw_event_handler(param, nil, 8);
1023 } 1029 }
1229 } 1235 }
1230 @end 1236 @end
1231 1237
1232 DWObject *DWObj; 1238 DWObject *DWObj;
1233 1239
1240 /* Returns TRUE if iOS 12+ is in Dark Mode */
1241 BOOL _dw_is_dark(void)
1242 {
1243 if([[[[DWObj hiddenWindow] rootViewController] traitCollection] userInterfaceStyle] == UIUserInterfaceStyleDark)
1244 return YES;
1245 return NO;
1246 }
1247
1234 @interface DWWebView : WKWebView <WKNavigationDelegate> 1248 @interface DWWebView : WKWebView <WKNavigationDelegate>
1235 { 1249 {
1236 void *userdata; 1250 void *userdata;
1237 } 1251 }
1238 -(void *)userdata; 1252 -(void *)userdata;
1998 } 2012 }
1999 -(void)checkDark 2013 -(void)checkDark
2000 { 2014 {
2001 /* Update any system colors based on the Dark Mode */ 2015 /* Update any system colors based on the Dark Mode */
2002 _DW_COLOR_ROW_EVEN = DW_RGB_TRANSPARENT; 2016 _DW_COLOR_ROW_EVEN = DW_RGB_TRANSPARENT;
2003 _DW_COLOR_ROW_ODD = DW_RGB(230, 230, 230); 2017 if(_dw_is_dark())
2018 _DW_COLOR_ROW_ODD = DW_RGB(100, 100, 100);
2019 else
2020 _DW_COLOR_ROW_ODD = DW_RGB(230, 230, 230);
2004 /* Only refresh if we've been setup already */ 2021 /* Only refresh if we've been setup already */
2005 if(titles) 2022 if(titles)
2006 [self refreshColors]; 2023 [self refreshColors];
2007 } 2024 }
2008 -(void)viewDidChangeEffectiveAppearance { [self checkDark]; } 2025 -(void)viewDidChangeEffectiveAppearance { [self checkDark]; }
7802 DW_FUNCTION_RESTORE_PARAM3(DW_UNUSED(hwndOwner), HWND, title, char *, DW_UNUSED(flStyle), ULONG) 7819 DW_FUNCTION_RESTORE_PARAM3(DW_UNUSED(hwndOwner), HWND, title, char *, DW_UNUSED(flStyle), ULONG)
7803 { 7820 {
7804 DW_FUNCTION_INIT; 7821 DW_FUNCTION_INIT;
7805 DWWindow *window = [[DWWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 7822 DWWindow *window = [[DWWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
7806 DWView *view = [[DWView alloc] init]; 7823 DWView *view = [[DWView alloc] init];
7824 UIUserInterfaceStyle style = [[DWObj hiddenWindow] overrideUserInterfaceStyle];
7807 7825
7808 [window setWindowLevel:UIWindowLevelNormal]; 7826 [window setWindowLevel:UIWindowLevelNormal];
7809 [window setRootViewController:[[DWViewController alloc] init]]; 7827 [window setRootViewController:[[DWViewController alloc] init]];
7810 [window addSubview:view]; 7828 [window addSubview:view];
7811 [window setBackgroundColor:[UIColor systemBackgroundColor]]; 7829 [window setBackgroundColor:[UIColor systemBackgroundColor]];
7812 7830
7813 /* TODO: Handle style flags... if we can? There is no visible frame */ 7831 /* TODO: Handle style flags... if we can? There is no visible frame */
7814 if(@available(iOS 13.0, *)) { 7832 if(@available(iOS 13.0, *)) {
7815 [window setLargeContentTitle:[NSString stringWithUTF8String:title]]; 7833 [window setLargeContentTitle:[NSString stringWithUTF8String:title]];
7816 } 7834 }
7835 /* Copy the overrideUserInterfaceStyle property from the hiddenWindow */
7836 if(style != UIUserInterfaceStyleUnspecified)
7837 [window setOverrideUserInterfaceStyle:style];
7817 DW_FUNCTION_RETURN_THIS(window); 7838 DW_FUNCTION_RETURN_THIS(window);
7818 } 7839 }
7819 7840
7820 /* 7841 /*
7821 * Call a function from the window (widget)'s context. 7842 * Call a function from the window (widget)'s context.
10600 case DW_FEATURE_HTML_RESULT: 10621 case DW_FEATURE_HTML_RESULT:
10601 case DW_FEATURE_CONTAINER_STRIPE: 10622 case DW_FEATURE_CONTAINER_STRIPE:
10602 case DW_FEATURE_MLE_WORD_WRAP: 10623 case DW_FEATURE_MLE_WORD_WRAP:
10603 case DW_FEATURE_UTF8_UNICODE: 10624 case DW_FEATURE_UTF8_UNICODE:
10604 return DW_FEATURE_ENABLED; 10625 return DW_FEATURE_ENABLED;
10626 case DW_FEATURE_DARK_MODE:
10627 {
10628 if(DWObj)
10629 {
10630 UIUserInterfaceStyle style = [[DWObj hiddenWindow] overrideUserInterfaceStyle];
10631
10632 switch(style)
10633 {
10634 case UIUserInterfaceStyleLight:
10635 return DW_FEATURE_DISABLED;
10636 case UIUserInterfaceStyleDark:
10637 return DW_DARK_MODE_FORCED;
10638 default: /* UIUserInterfaceStyleUnspecified */
10639 return DW_FEATURE_ENABLED;
10640 }
10641 }
10642 return _dw_dark_mode_state;
10643 }
10605 default: 10644 default:
10606 return DW_FEATURE_UNSUPPORTED; 10645 return DW_FEATURE_UNSUPPORTED;
10607 } 10646 }
10608 } 10647 }
10609 10648
10631 case DW_FEATURE_HTML_RESULT: 10670 case DW_FEATURE_HTML_RESULT:
10632 case DW_FEATURE_CONTAINER_STRIPE: 10671 case DW_FEATURE_CONTAINER_STRIPE:
10633 case DW_FEATURE_MLE_WORD_WRAP: 10672 case DW_FEATURE_MLE_WORD_WRAP:
10634 case DW_FEATURE_UTF8_UNICODE: 10673 case DW_FEATURE_UTF8_UNICODE:
10635 return DW_ERROR_GENERAL; 10674 return DW_ERROR_GENERAL;
10675 case DW_FEATURE_DARK_MODE:
10676 {
10677 /* Make sure DWObj is initialized */
10678 if(DWObj)
10679 {
10680 /* Disabled forces the non-dark aqua theme */
10681 if(state == DW_FEATURE_DISABLED)
10682 [[DWObj hiddenWindow] setOverrideUserInterfaceStyle:UIUserInterfaceStyleLight];
10683 /* Enabled lets the OS decide the mode */
10684 else if(state == DW_FEATURE_ENABLED || state == DW_DARK_MODE_FULL)
10685 [[DWObj hiddenWindow] setOverrideUserInterfaceStyle:UIUserInterfaceStyleUnspecified];
10686 /* 2 forces dark mode aqua appearance */
10687 else if(state == DW_DARK_MODE_FORCED)
10688 [[DWObj hiddenWindow] setOverrideUserInterfaceStyle:UIUserInterfaceStyleDark];
10689 }
10690 else /* Save the requested state for dw_init() */
10691 _dw_dark_mode_state = state;
10692 }
10636 default: 10693 default:
10637 return DW_FEATURE_UNSUPPORTED; 10694 return DW_FEATURE_UNSUPPORTED;
10638 } 10695 }
10639 } 10696 }