Mercurial > dwindows
comparison ios/dw.m @ 2638:b7cc83cf70fa
iOS: Attempt to add "Back" button to secondaries windows to allow them to
close. Also remove windowShouldClose() since it is Mac specific... instead
handle the close event in our Back button handler.
Code builds, but Back button is not showing up, but I wanted to commit.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 12 Aug 2021 21:54:11 +0000 |
parents | 3ec675648cf5 |
children | 0be4b2e21885 |
comparison
equal
deleted
inserted
replaced
2637:22105f99dd6a | 2638:b7cc83cf70fa |
---|---|
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 static int _dw_dark_mode_state = DW_FEATURE_UNSUPPORTED; |
241 static CGPoint _dw_event_point = {0}; | 241 static CGPoint _dw_event_point = {0}; |
242 static NSMutableArray *_dw_toplevel_windows; | |
242 | 243 |
243 /* Create a default colors for a thread */ | 244 /* Create a default colors for a thread */ |
244 void _dw_init_colors(void) | 245 void _dw_init_colors(void) |
245 { | 246 { |
246 UIColor *fgcolor = [[UIColor grayColor] retain]; | 247 UIColor *fgcolor = [[UIColor grayColor] retain]; |
788 -(void)layoutSubviews { } | 789 -(void)layoutSubviews { } |
789 -(void)setMenu:(DWMenu *)input { [windowmenu release]; windowmenu = input; [windowmenu retain]; } | 790 -(void)setMenu:(DWMenu *)input { [windowmenu release]; windowmenu = input; [windowmenu retain]; } |
790 -(void)setPopupMenu:(DWMenu *)input { [popupmenu release]; popupmenu = input; [popupmenu retain]; } | 791 -(void)setPopupMenu:(DWMenu *)input { [popupmenu release]; popupmenu = input; [popupmenu retain]; } |
791 -(DWMenu *)menu { return windowmenu; } | 792 -(DWMenu *)menu { return windowmenu; } |
792 -(DWMenu *)popupMenu { return popupmenu; } | 793 -(DWMenu *)popupMenu { return popupmenu; } |
794 -(void)closeWindow:(id)sender | |
795 { | |
796 if(_dw_event_handler(self, nil, _DW_EVENT_DELETE) < 1) | |
797 dw_window_destroy(self); | |
798 } | |
793 -(void)dealloc | 799 -(void)dealloc |
794 { | 800 { |
795 if(windowmenu) | 801 if(windowmenu) |
796 [windowmenu release]; | 802 [windowmenu release]; |
797 if(popupmenu) | 803 if(popupmenu) |
1341 /* Subclass for a top-level window */ | 1347 /* Subclass for a top-level window */ |
1342 @interface DWView : DWBox /* <UIWindowDelegate> */ | 1348 @interface DWView : DWBox /* <UIWindowDelegate> */ |
1343 { | 1349 { |
1344 CGSize oldsize; | 1350 CGSize oldsize; |
1345 } | 1351 } |
1346 -(BOOL)windowShouldClose:(id)sender; | |
1347 -(void)windowDidBecomeMain:(id)sender; | 1352 -(void)windowDidBecomeMain:(id)sender; |
1348 -(void)menuHandler:(id)sender; | 1353 -(void)menuHandler:(id)sender; |
1349 -(UIResponder *)nextResponder; | 1354 -(UIResponder *)nextResponder; |
1350 @end | 1355 @end |
1351 | 1356 |
1352 @implementation DWView | 1357 @implementation DWView |
1353 -(BOOL)windowShouldClose:(id)sender | |
1354 { | |
1355 if(_dw_event_handler(sender, nil, _DW_EVENT_DELETE) > 0) | |
1356 return NO; | |
1357 return YES; | |
1358 } | |
1359 -(void)willMoveToSuperview:(UIView *)newSuperview | 1358 -(void)willMoveToSuperview:(UIView *)newSuperview |
1360 { | 1359 { |
1361 if(newSuperview) | 1360 if(newSuperview) |
1362 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:UIWindowDidBecomeKeyNotification object:[newSuperview window]]; | 1361 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:UIWindowDidBecomeKeyNotification object:[newSuperview window]]; |
1363 } | 1362 } |
8062 [window setOverrideUserInterfaceStyle:style]; | 8061 [window setOverrideUserInterfaceStyle:style]; |
8063 [window setWindowLevel:UIWindowLevelNormal]; | 8062 [window setWindowLevel:UIWindowLevelNormal]; |
8064 [window setRootViewController:[[DWViewController alloc] init]]; | 8063 [window setRootViewController:[[DWViewController alloc] init]]; |
8065 [window setBackgroundColor:[UIColor systemBackgroundColor]]; | 8064 [window setBackgroundColor:[UIColor systemBackgroundColor]]; |
8066 [[[window rootViewController] view] addSubview:view]; | 8065 [[[window rootViewController] view] addSubview:view]; |
8066 [_dw_toplevel_windows addObject:window]; | |
8067 | 8067 |
8068 /* Handle style flags... There is no visible frame... | 8068 /* Handle style flags... There is no visible frame... |
8069 * On iOS 13 and higher if a titlebar is requested create a navigation bar. | 8069 * On iOS 13 and higher if a titlebar is requested create a navigation bar. |
8070 */ | 8070 */ |
8071 if(@available(iOS 13.0, *)) { | 8071 if(@available(iOS 13.0, *)) { |
8075 { | 8075 { |
8076 NSInteger sbheight = [[[window windowScene] statusBarManager] statusBarFrame].size.height; | 8076 NSInteger sbheight = [[[window windowScene] statusBarManager] statusBarFrame].size.height; |
8077 UINavigationBar* navbar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, sbheight, screenrect.size.width, 40)]; | 8077 UINavigationBar* navbar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, sbheight, screenrect.size.width, 40)]; |
8078 UINavigationItem* navItem = [[UINavigationItem alloc] initWithTitle:nstitle]; | 8078 UINavigationItem* navItem = [[UINavigationItem alloc] initWithTitle:nstitle]; |
8079 | 8079 |
8080 /* We maintain a list of top-level windows... | |
8081 * If there is more than one window, add a Back button that will close it. | |
8082 */ | |
8083 if([_dw_toplevel_windows count] > 1) | |
8084 { | |
8085 UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:@"Back" | |
8086 style:UIBarButtonItemStylePlain | |
8087 target:window | |
8088 action:@selector(closeWindow:)]; | |
8089 | |
8090 navItem.backBarButtonItem = back; | |
8091 } | |
8080 [navbar setItems:@[navItem]]; | 8092 [navbar setItems:@[navItem]]; |
8081 [[[window rootViewController] view] addSubview:navbar]; | 8093 [[[window rootViewController] view] addSubview:navbar]; |
8082 } | 8094 } |
8083 } | 8095 } |
8084 DW_FUNCTION_RETURN_THIS(window); | 8096 DW_FUNCTION_RETURN_THIS(window); |
8523 DW_LOCAL_POOL_IN; | 8535 DW_LOCAL_POOL_IN; |
8524 id object = handle; | 8536 id object = handle; |
8525 int retval = 0; | 8537 int retval = 0; |
8526 | 8538 |
8527 /* Handle destroying a top-level window */ | 8539 /* Handle destroying a top-level window */ |
8528 if([ object isKindOfClass:[ UIWindow class ] ]) | 8540 if([object isKindOfClass:[UIWindow class]]) |
8529 { | 8541 { |
8530 DWWindow *window = handle; | 8542 DWWindow *window = handle; |
8543 [_dw_toplevel_windows removeObject:window]; | |
8544 [window removeFromSuperview]; | |
8531 [window release]; | 8545 [window release]; |
8532 } | 8546 } |
8533 /* Handle removing menu items from menus */ | 8547 /* Handle removing menu items from menus */ |
8534 else if([object isMemberOfClass:[DWMenuItem class]]) | 8548 else if([object isMemberOfClass:[DWMenuItem class]]) |
8535 { | 8549 { |
10539 setlocale(LC_ALL, lang && strstr(lang, ".UTF-8") ? lang : "UTF-8"); | 10553 setlocale(LC_ALL, lang && strstr(lang, ".UTF-8") ? lang : "UTF-8"); |
10540 /* Create the application object */ | 10554 /* Create the application object */ |
10541 _dw_app_init(); | 10555 _dw_app_init(); |
10542 pthread_key_create(&_dw_pool_key, NULL); | 10556 pthread_key_create(&_dw_pool_key, NULL); |
10543 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | 10557 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
10558 _dw_toplevel_windows = [[NSMutableArray new] retain]; | |
10544 pthread_setspecific(_dw_pool_key, pool); | 10559 pthread_setspecific(_dw_pool_key, pool); |
10545 pthread_key_create(&_dw_fg_color_key, NULL); | 10560 pthread_key_create(&_dw_fg_color_key, NULL); |
10546 pthread_key_create(&_dw_bg_color_key, NULL); | 10561 pthread_key_create(&_dw_bg_color_key, NULL); |
10547 _dw_init_colors(); | 10562 _dw_init_colors(); |
10548 DWDefaultFont = nil; | 10563 DWDefaultFont = nil; |