Mercurial > dwindows
comparison ios/dw.m @ 2402:b28852b35452
iOS: Fix message boxes... the hiddenWindow they are attached to was being
created in DWObject initialization which was happening before
UIApplicationMain() thus did not function. Delay creation in delayedInit:
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 28 Mar 2021 02:23:20 +0000 |
parents | 010ae32a5067 |
children | d4a044d24529 |
comparison
equal
deleted
inserted
replaced
2401:010ae32a5067 | 2402:b28852b35452 |
---|---|
869 | 869 |
870 @implementation DWObject | 870 @implementation DWObject |
871 -(id)init | 871 -(id)init |
872 { | 872 { |
873 self = [super init]; | 873 self = [super init]; |
874 /* This previously had the code in delayedIinit: */ | |
875 return self; | |
876 } | |
877 -(void)delayedInit:(id)param | |
878 { | |
879 /* When DWObject is initialized, UIApplicationMain() has not yet been called... | |
880 * So the created objects can't interact with the user interface... therefore | |
881 * we wait until UIApplicationMain() has been called and run this then. | |
882 */ | |
874 hiddenWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | 883 hiddenWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
875 [hiddenWindow setBackgroundColor:[UIColor clearColor]]; | 884 [hiddenWindow setWindowLevel:UIWindowLevelAlert+1]; |
876 [hiddenWindow setWindowLevel:UIWindowLevelAlert]; | |
877 [hiddenWindow setHidden:YES]; | 885 [hiddenWindow setHidden:YES]; |
878 return self; | 886 [hiddenWindow setRootViewController:[UIViewController new]]; |
879 } | 887 } |
880 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ } | 888 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ } |
881 -(void)menuHandler:(id)param | 889 -(void)menuHandler:(id)param |
882 { | 890 { |
883 _dw_event_handler(param, nil, 8); | 891 _dw_event_handler(param, nil, 8); |
888 if(mycallback) | 896 if(mycallback) |
889 mycallback(params); | 897 mycallback(params); |
890 } | 898 } |
891 -(void)messageBox:(NSMutableArray *)params | 899 -(void)messageBox:(NSMutableArray *)params |
892 { | 900 { |
893 __block NSInteger iResponse = 0; | 901 __block DWDialog *dialog = dw_dialog_new(NULL); |
902 NSInteger iResponse; | |
894 UIAlertController* alert = [UIAlertController alertControllerWithTitle:[params objectAtIndex:0] | 903 UIAlertController* alert = [UIAlertController alertControllerWithTitle:[params objectAtIndex:0] |
895 message:[params objectAtIndex:1] | 904 message:[params objectAtIndex:1] |
896 preferredStyle:[[params objectAtIndex:2] integerValue]]; | 905 preferredStyle:[[params objectAtIndex:2] integerValue]]; |
897 | |
898 UIAlertAction* action = [UIAlertAction actionWithTitle:[params objectAtIndex:3] style:UIAlertActionStyleDefault | 906 UIAlertAction* action = [UIAlertAction actionWithTitle:[params objectAtIndex:3] style:UIAlertActionStyleDefault |
899 handler:^(UIAlertAction * action) { iResponse = 1; }]; | 907 handler:^(UIAlertAction * action) { dw_dialog_dismiss(dialog, DW_INT_TO_POINTER(1)); }]; |
900 [alert addAction:action]; | 908 [alert addAction:action]; |
901 if([params count] > 4) | 909 if([params count] > 4) |
910 { | |
902 action = [UIAlertAction actionWithTitle:[params objectAtIndex:4] style:UIAlertActionStyleDefault | 911 action = [UIAlertAction actionWithTitle:[params objectAtIndex:4] style:UIAlertActionStyleDefault |
903 handler:^(UIAlertAction * action) { iResponse = 2; }]; | 912 handler:^(UIAlertAction * action) { dw_dialog_dismiss(dialog, DW_INT_TO_POINTER(2)); }]; |
904 [alert addAction:action]; | 913 [alert addAction:action]; |
914 } | |
905 if([params count] > 5) | 915 if([params count] > 5) |
916 { | |
906 action = [UIAlertAction actionWithTitle:[params objectAtIndex:5] style:UIAlertActionStyleDefault | 917 action = [UIAlertAction actionWithTitle:[params objectAtIndex:5] style:UIAlertActionStyleDefault |
907 handler:^(UIAlertAction * action) { iResponse = 3; }]; | 918 handler:^(UIAlertAction * action) { dw_dialog_dismiss(dialog, DW_INT_TO_POINTER(3)); }]; |
908 [alert addAction:action]; | 919 [alert addAction:action]; |
920 } | |
909 | 921 |
910 /* Unhide our hidden window and make it key */ | 922 /* Unhide our hidden window and make it key */ |
911 [hiddenWindow setHidden:NO]; | 923 [hiddenWindow setHidden:NO]; |
912 [hiddenWindow makeKeyAndVisible]; | 924 [hiddenWindow makeKeyAndVisible]; |
913 [[hiddenWindow rootViewController] presentViewController:alert animated:YES completion:nil]; | 925 [[hiddenWindow rootViewController] presentViewController:alert animated:YES completion:nil]; |
926 iResponse = DW_POINTER_TO_INT(dw_dialog_wait(dialog)); | |
914 /* Once the dialog is gone we can rehide our window */ | 927 /* Once the dialog is gone we can rehide our window */ |
928 [hiddenWindow resignKeyWindow]; | |
915 [hiddenWindow setHidden:YES]; | 929 [hiddenWindow setHidden:YES]; |
916 [params addObject:[NSNumber numberWithInteger:iResponse]]; | 930 [params addObject:[NSNumber numberWithInteger:iResponse]]; |
917 } | 931 } |
918 -(void)safeCall:(SEL)sel withObject:(id)param | 932 -(void)safeCall:(SEL)sel withObject:(id)param |
919 { | 933 { |
2493 /* | 2507 /* |
2494 * Cleanly terminates a DW session, should be signal handler safe. | 2508 * Cleanly terminates a DW session, should be signal handler safe. |
2495 */ | 2509 */ |
2496 void API dw_shutdown(void) | 2510 void API dw_shutdown(void) |
2497 { | 2511 { |
2498 NSAutoreleasePool *pool = pthread_getspecific(_dw_pool_key); | |
2499 [pool drain]; | |
2500 } | 2512 } |
2501 | 2513 |
2502 /* | 2514 /* |
2503 * Cleanly terminates a DW session, should be signal handler safe. | 2515 * Cleanly terminates a DW session, should be signal handler safe. |
2504 * Parameters: | 2516 * Parameters: |
2629 | 2641 |
2630 va_start(args, format); | 2642 va_start(args, format); |
2631 mtext = [[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:args] autorelease]; | 2643 mtext = [[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:args] autorelease]; |
2632 va_end(args); | 2644 va_end(args); |
2633 | 2645 |
2646 #if 0 /* TODO: If we want to use this style it requires a rectangle... | |
2647 * However the alert style looks pretty good to me... | |
2648 */ | |
2634 if(flags & DW_MB_INFORMATION) | 2649 if(flags & DW_MB_INFORMATION) |
2635 mstyle = UIAlertControllerStyleActionSheet; | 2650 mstyle = UIAlertControllerStyleActionSheet; |
2651 #endif | |
2636 | 2652 |
2637 params = [NSMutableArray arrayWithObjects:mtitle, mtext, [NSNumber numberWithInteger:mstyle], button1, button2, button3, nil]; | 2653 params = [NSMutableArray arrayWithObjects:mtitle, mtext, [NSNumber numberWithInteger:mstyle], button1, button2, button3, nil]; |
2638 [DWObj safeCall:@selector(messageBox:) withObject:params]; | 2654 [DWObj safeCall:@selector(messageBox:) withObject:params]; |
2639 iResponse = [[params lastObject] integerValue]; | 2655 iResponse = [[params lastObject] integerValue]; |
2640 | 2656 |
7334 { | 7350 { |
7335 DW_FUNCTION_INIT; | 7351 DW_FUNCTION_INIT; |
7336 DWWindow *window = [[DWWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | 7352 DWWindow *window = [[DWWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
7337 DWView *view = [[DWView alloc] init]; | 7353 DWView *view = [[DWView alloc] init]; |
7338 | 7354 |
7355 [window setWindowLevel:UIWindowLevelNormal]; | |
7339 [window setRootViewController:[[DWViewController alloc] init]]; | 7356 [window setRootViewController:[[DWViewController alloc] init]]; |
7340 [window addSubview:view]; | 7357 [window addSubview:view]; |
7341 | 7358 |
7342 /* TODO: Handle style flags... if we can? There is no visible frame */ | 7359 /* TODO: Handle style flags... if we can? There is no visible frame */ |
7343 if(@available(iOS 13.0, *)) { | 7360 if(@available(iOS 13.0, *)) { |
9679 } | 9696 } |
9680 pthread_yield_np(); | 9697 pthread_yield_np(); |
9681 DWApp = [UIApplication sharedApplication]; | 9698 DWApp = [UIApplication sharedApplication]; |
9682 } | 9699 } |
9683 dw_event_reset(DWMainEvent); | 9700 dw_event_reset(DWMainEvent); |
9701 [DWObj performSelectorOnMainThread:@selector(delayedInit:) withObject:nil waitUntilDone:YES]; | |
9684 } | 9702 } |
9685 | 9703 |
9686 /* | 9704 /* |
9687 * Initializes the Dynamic Windows engine. | 9705 * Initializes the Dynamic Windows engine. |
9688 * Parameters: | 9706 * Parameters: |