Mercurial > dwindows
comparison ios/dw.m @ 2391:a7bfb97fd80e
iOS: Switch to using UIApplicationMain() in dw_main().
This is not a long term solution since it never exits and has some other
limitations, but apparently it does some setup we were not doing.
We are now getting auto constraint errors due to conflicts with the DW
layout engine. Some changes to avoid these but still getting them... so more
work needed.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 25 Mar 2021 05:30:52 +0000 |
parents | 2613d1533f1a |
children | 6669e152e30b |
comparison
equal
deleted
inserted
replaced
2390:2613d1533f1a | 2391:a7bfb97fd80e |
---|---|
556 | 556 |
557 @implementation DWTimerHandler | 557 @implementation DWTimerHandler |
558 -(void)runTimer:(id)sender { _dw_event_handler(sender, nil, 0); } | 558 -(void)runTimer:(id)sender { _dw_event_handler(sender, nil, 0); } |
559 @end | 559 @end |
560 | 560 |
561 @interface DWAppDel : UIResponder <UIApplicationDelegate> { } | |
562 -(void)applicationWillTerminate:(UIApplication *)application; | |
563 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions; | |
564 @end | |
565 | |
566 @implementation DWAppDel | |
567 -(void)applicationWillTerminate:(UIApplication *)application | |
568 { | |
569 /* On iOS we can't prevent temrination, but send the notificatoin anyway */ | |
570 _dw_event_handler(application, nil, 6); | |
571 } | |
572 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions | |
573 { | |
574 return true; | |
575 } | |
576 @end | |
577 | |
561 UIApplication *DWApp = nil; | 578 UIApplication *DWApp = nil; |
562 UIFont *DWDefaultFont; | 579 UIFont *DWDefaultFont; |
563 DWTimerHandler *DWHandler; | 580 DWTimerHandler *DWHandler; |
564 NSAutoreleasePool *pool; | 581 NSAutoreleasePool *pool; |
565 NSMutableArray *_DWDirtyDrawables; | 582 NSMutableArray *_DWDirtyDrawables; |
650 -(void)rightMouseUp:(UIEvent *)theEvent; | 667 -(void)rightMouseUp:(UIEvent *)theEvent; |
651 -(void)otherMouseDown:(UIEvent *)theEvent; | 668 -(void)otherMouseDown:(UIEvent *)theEvent; |
652 -(void)otherMouseUp:(UIEvent *)theEvent; | 669 -(void)otherMouseUp:(UIEvent *)theEvent; |
653 -(void)keyDown:(UIEvent *)theEvent; | 670 -(void)keyDown:(UIEvent *)theEvent; |
654 -(void)setColor:(unsigned long)input; | 671 -(void)setColor:(unsigned long)input; |
672 -(void)layoutSubviews; | |
655 @end | 673 @end |
656 | 674 |
657 @implementation DWBox | 675 @implementation DWBox |
658 -(id)init | 676 -(id)init |
659 { | 677 { |
716 } | 734 } |
717 } | 735 } |
718 [self setNeedsDisplay]; | 736 [self setNeedsDisplay]; |
719 [orig release]; | 737 [orig release]; |
720 } | 738 } |
739 -(void)layoutSubviews { }; | |
721 @end | 740 @end |
722 | 741 |
723 @interface DWWindow : UIWindow | 742 @interface DWWindow : UIWindow |
724 { | 743 { |
725 int redraw; | 744 int redraw; |
730 -(void)mouseDragged:(UIEvent *)theEvent; | 749 -(void)mouseDragged:(UIEvent *)theEvent; |
731 -(int)redraw; | 750 -(int)redraw; |
732 -(void)setRedraw:(int)val; | 751 -(void)setRedraw:(int)val; |
733 -(int)shown; | 752 -(int)shown; |
734 -(void)setShown:(int)val; | 753 -(void)setShown:(int)val; |
754 -(void)layoutSubviews; | |
735 @end | 755 @end |
736 | 756 |
737 @implementation DWWindow | 757 @implementation DWWindow |
738 -(void)sendEvent:(UIEvent *)theEvent | 758 -(void)sendEvent:(UIEvent *)theEvent |
739 { | 759 { |
750 -(int)redraw { return redraw; } | 770 -(int)redraw { return redraw; } |
751 -(void)setRedraw:(int)val { redraw = val; } | 771 -(void)setRedraw:(int)val { redraw = val; } |
752 -(int)shown { return shown; } | 772 -(int)shown { return shown; } |
753 -(void)setShown:(int)val { shown = val; } | 773 -(void)setShown:(int)val { shown = val; } |
754 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; } | 774 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; } |
775 -(void)layoutSubviews { } | |
755 @end | 776 @end |
756 | 777 |
757 /* Subclass for a render area type */ | 778 /* Subclass for a render area type */ |
758 @interface DWRender : UIControl | 779 @interface DWRender : UIControl |
759 { | 780 { |
1032 { | 1053 { |
1033 if(_dw_event_handler(sender, nil, 6) > 0) | 1054 if(_dw_event_handler(sender, nil, 6) > 0) |
1034 return NO; | 1055 return NO; |
1035 return YES; | 1056 return YES; |
1036 } | 1057 } |
1037 -(void)viewDidMoveToWindow | 1058 -(void)willMoveToSuperview:(UIView *)newSuperview |
1038 { | 1059 { |
1039 #if 0 /* TODO: Find the correct way to do this on iOS */ | 1060 if(newSuperview) |
1040 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]]; | 1061 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:UIWindowDidBecomeKeyNotification object:[newSuperview window]]; |
1041 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:NSWindowDidBecomeMainNotification object:[self window]]; | |
1042 #endif | |
1043 } | 1062 } |
1044 -(void)dealloc | 1063 -(void)dealloc |
1045 { | 1064 { |
1046 if(windowmenu) | 1065 if(windowmenu) |
1047 { | 1066 { |
1093 -(void)viewWillLayoutSubviews | 1112 -(void)viewWillLayoutSubviews |
1094 { | 1113 { |
1095 DWWindow *window = (DWWindow *)[[self view] window]; | 1114 DWWindow *window = (DWWindow *)[[self view] window]; |
1096 NSArray *array = [window subviews]; | 1115 NSArray *array = [window subviews]; |
1097 DWView *view = [array firstObject]; | 1116 DWView *view = [array firstObject]; |
1117 #if 0 | |
1118 id object = [array lastObject]; | |
1119 /* Remove the UITransitionView... for testing purposes */ | |
1120 if(![object isMemberOfClass:[DWView class]]) | |
1121 [object removeFromSuperview]; | |
1122 #endif | |
1098 [view setFrame:[window frame]]; | 1123 [view setFrame:[window frame]]; |
1099 [view windowResized:[window frame].size]; | 1124 [view windowResized:[window frame].size]; |
1100 } | 1125 } |
1101 @end | 1126 @end |
1102 | 1127 |
2383 _dw_resize_box(thisbox, &depth, x, y, 2); | 2408 _dw_resize_box(thisbox, &depth, x, y, 2); |
2384 } | 2409 } |
2385 } | 2410 } |
2386 } | 2411 } |
2387 | 2412 |
2413 static int _dw_argc; | |
2414 static char **_dw_argv; | |
2415 | |
2388 /* | 2416 /* |
2389 * Runs a message loop for Dynamic Windows. | 2417 * Runs a message loop for Dynamic Windows. |
2390 */ | 2418 */ |
2391 void API dw_main(void) | 2419 void API dw_main(void) |
2392 { | 2420 { |
2393 DWThread = dw_thread_id(); | 2421 DWThread = dw_thread_id(); |
2394 /* Make sure any queued redraws are handled */ | 2422 /* Make sure any queued redraws are handled */ |
2395 _dw_redraw(0, FALSE); | 2423 _dw_redraw(0, FALSE); |
2396 [[NSRunLoop mainRunLoop] run]; | 2424 UIApplicationMain(_dw_argc, _dw_argv, nil, NSStringFromClass([DWAppDel class])); |
2397 DWThread = (DWTID)-1; | 2425 DWThread = (DWTID)-1; |
2398 } | 2426 } |
2399 | 2427 |
2400 /* | 2428 /* |
2401 * Causes running dw_main() to return. | 2429 * Causes running dw_main() to return. |
2750 DW_FUNCTION_RESTORE_PARAM2(type, int, pad, int) | 2778 DW_FUNCTION_RESTORE_PARAM2(type, int, pad, int) |
2751 { | 2779 { |
2752 DW_FUNCTION_INIT; | 2780 DW_FUNCTION_INIT; |
2753 DWBox *view = [[DWBox alloc] init]; | 2781 DWBox *view = [[DWBox alloc] init]; |
2754 Box *newbox = [view box]; | 2782 Box *newbox = [view box]; |
2783 [view setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
2755 memset(newbox, 0, sizeof(Box)); | 2784 memset(newbox, 0, sizeof(Box)); |
2756 newbox->pad = pad; | 2785 newbox->pad = pad; |
2757 newbox->type = type; | 2786 newbox->type = type; |
2758 DW_FUNCTION_RETURN_THIS(view); | 2787 DW_FUNCTION_RETURN_THIS(view); |
2759 } | 2788 } |
7210 * Parameters: | 7239 * Parameters: |
7211 * owner: The Owner's window handle or HWND_DESKTOP. | 7240 * owner: The Owner's window handle or HWND_DESKTOP. |
7212 * title: The Window title. | 7241 * title: The Window title. |
7213 * flStyle: Style flags, see the PM reference. | 7242 * flStyle: Style flags, see the PM reference. |
7214 */ | 7243 */ |
7215 DW_FUNCTION_DEFINITION(dw_window_new, HWND, HWND hwndOwner, const char *title, ULONG flStyle) | 7244 DW_FUNCTION_DEFINITION(dw_window_new, HWND, DW_UNUSED(HWND hwndOwner), const char *title, DW_UNUSED(ULONG flStyle)) |
7216 DW_FUNCTION_ADD_PARAM3(hwndOwner, title, flStyle) | 7245 DW_FUNCTION_ADD_PARAM3(hwndOwner, title, flStyle) |
7217 DW_FUNCTION_RETURN(dw_window_new, HWND) | 7246 DW_FUNCTION_RETURN(dw_window_new, HWND) |
7218 DW_FUNCTION_RESTORE_PARAM3(hwndOwner, HWND, title, char *, flStyle, ULONG) | 7247 DW_FUNCTION_RESTORE_PARAM3(DW_UNUSED(hwndOwner), HWND, title, char *, DW_UNUSED(flStyle), ULONG) |
7219 { | 7248 { |
7220 DW_FUNCTION_INIT; | 7249 DW_FUNCTION_INIT; |
7221 DWWindow *window = [[DWWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | 7250 DWWindow *window = [[DWWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
7222 DWView *view = [[DWView alloc] init]; | 7251 DWView *view = [[DWView alloc] init]; |
7223 window.rootViewController = [[DWViewController alloc] init]; | 7252 |
7224 | 7253 [window setRootViewController:[[DWViewController alloc] init]]; |
7225 [window addSubview:view]; | 7254 [window addSubview:view]; |
7226 | 7255 |
7227 /* TODO: Handle style flags */ | 7256 /* TODO: Handle style flags... if we can? There is no visible frame */ |
7228 if(@available(iOS 13.0, *)) { | 7257 if(@available(iOS 13.0, *)) { |
7229 [window setLargeContentTitle:[NSString stringWithUTF8String:title]]; | 7258 [window setLargeContentTitle:[NSString stringWithUTF8String:title]]; |
7230 } | 7259 } |
7231 DW_FUNCTION_RETURN_THIS(window); | 7260 DW_FUNCTION_RETURN_THIS(window); |
7232 } | 7261 } |
7286 if(![window shown]) | 7315 if(![window shown]) |
7287 { | 7316 { |
7288 [window makeKeyAndVisible]; | 7317 [window makeKeyAndVisible]; |
7289 [window setShown:YES]; | 7318 [window setShown:YES]; |
7290 } | 7319 } |
7320 else | |
7321 [window setHidden:NO]; | |
7291 } | 7322 } |
7292 return 0; | 7323 return 0; |
7293 } | 7324 } |
7294 | 7325 |
7295 /* | 7326 /* |
7540 } | 7571 } |
7541 | 7572 |
7542 /* Internal function to return a pointer to an item struct | 7573 /* Internal function to return a pointer to an item struct |
7543 * with information about the packing information regarding object. | 7574 * with information about the packing information regarding object. |
7544 */ | 7575 */ |
7545 Item *_box_item(id object) | 7576 Item *_dw_box_item(id object) |
7546 { | 7577 { |
7547 /* Find the item within the box it is packed into */ | 7578 /* Find the item within the box it is packed into */ |
7548 if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[UIControl class]]) | 7579 if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[UIControl class]]) |
7549 { | 7580 { |
7550 DWBox *parent = (DWBox *)[object superview]; | 7581 DWBox *parent = (DWBox *)[object superview]; |
7605 [render setFont:font]; | 7636 [render setFont:font]; |
7606 } | 7637 } |
7607 else | 7638 else |
7608 return DW_ERROR_UNKNOWN; | 7639 return DW_ERROR_UNKNOWN; |
7609 /* If we changed the text... */ | 7640 /* If we changed the text... */ |
7610 Item *item = _box_item(handle); | 7641 Item *item = _dw_box_item(handle); |
7611 | 7642 |
7612 /* Check to see if any of the sizes need to be recalculated */ | 7643 /* Check to see if any of the sizes need to be recalculated */ |
7613 if(item && (item->origwidth == -1 || item->origheight == -1)) | 7644 if(item && (item->origwidth == -1 || item->origheight == -1)) |
7614 { | 7645 { |
7615 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 7646 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); |
7795 [control setText:[NSString stringWithUTF8String:text]]; | 7826 [control setText:[NSString stringWithUTF8String:text]]; |
7796 } | 7827 } |
7797 else | 7828 else |
7798 return; | 7829 return; |
7799 /* If we changed the text... */ | 7830 /* If we changed the text... */ |
7800 Item *item = _box_item(handle); | 7831 Item *item = _dw_box_item(handle); |
7801 | 7832 |
7802 /* Check to see if any of the sizes need to be recalculated */ | 7833 /* Check to see if any of the sizes need to be recalculated */ |
7803 if(item && (item->origwidth == -1 || item->origheight == -1)) | 7834 if(item && (item->origwidth == -1 || item->origheight == -1)) |
7804 { | 7835 { |
7805 int newwidth, newheight; | 7836 int newwidth, newheight; |
7921 if(pixmap) | 7952 if(pixmap) |
7922 { | 7953 { |
7923 [object setImage:pixmap]; | 7954 [object setImage:pixmap]; |
7924 } | 7955 } |
7925 /* If we changed the bitmap... */ | 7956 /* If we changed the bitmap... */ |
7926 Item *item = _box_item(handle); | 7957 Item *item = _dw_box_item(handle); |
7927 | 7958 |
7928 /* Check to see if any of the sizes need to be recalculated */ | 7959 /* Check to see if any of the sizes need to be recalculated */ |
7929 if(item && (item->origwidth == -1 || item->origheight == -1)) | 7960 if(item && (item->origwidth == -1 || item->origheight == -1)) |
7930 { | 7961 { |
7931 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 7962 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); |
7979 if(bitmap) | 8010 if(bitmap) |
7980 { | 8011 { |
7981 [object setImage:bitmap]; | 8012 [object setImage:bitmap]; |
7982 | 8013 |
7983 /* If we changed the bitmap... */ | 8014 /* If we changed the bitmap... */ |
7984 Item *item = _box_item(handle); | 8015 Item *item = _dw_box_item(handle); |
7985 | 8016 |
7986 /* Check to see if any of the sizes need to be recalculated */ | 8017 /* Check to see if any of the sizes need to be recalculated */ |
7987 if(item && (item->origwidth == -1 || item->origheight == -1)) | 8018 if(item && (item->origwidth == -1 || item->origheight == -1)) |
7988 { | 8019 { |
7989 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 8020 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); |
9504 * False if there is already a message loop running. | 9535 * False if there is already a message loop running. |
9505 */ | 9536 */ |
9506 int API dw_init(int newthread, int argc, char *argv[]) | 9537 int API dw_init(int newthread, int argc, char *argv[]) |
9507 { | 9538 { |
9508 char *lang = getenv("LANG"); | 9539 char *lang = getenv("LANG"); |
9540 | |
9541 _dw_argc = argc; | |
9542 _dw_argv = argv; | |
9509 | 9543 |
9510 /* Correct the startup path if run from a bundle */ | 9544 /* Correct the startup path if run from a bundle */ |
9511 if(argc > 0 && argv[0]) | 9545 if(argc > 0 && argv[0]) |
9512 { | 9546 { |
9513 char *pathcopy = strdup(argv[0]); | 9547 char *pathcopy = strdup(argv[0]); |