comparison ios/dw.m @ 2405:38c17a19e00d

iOS: Add adjustment for the statusbar so it isn't covered up by our windows. Also retain all UI objects we create so they don't get disposed off... during our jumps between threads. This may require a release in box packing.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 28 Mar 2021 18:23:57 +0000
parents d4a044d24529
children 6336244aa895
comparison
equal deleted inserted replaced
2404:d4a044d24529 2405:38c17a19e00d
1127 -(void)viewWillLayoutSubviews 1127 -(void)viewWillLayoutSubviews
1128 { 1128 {
1129 DWWindow *window = (DWWindow *)[[self view] window]; 1129 DWWindow *window = (DWWindow *)[[self view] window];
1130 NSArray *array = [window subviews]; 1130 NSArray *array = [window subviews];
1131 DWView *view = [array firstObject]; 1131 DWView *view = [array firstObject];
1132 CGRect frame = [window frame];
1132 /* Hide the UITransitionView which is blocking the screen... 1133 /* Hide the UITransitionView which is blocking the screen...
1133 * This is probably not the correct solution, but it solves the 1134 * This is probably not the correct solution, but it solves the
1134 * problem for the moment. Figure out what to do with this view. 1135 * problem for the moment. Figure out what to do with this view.
1135 */ 1136 */
1136 id object = [array lastObject]; 1137 id object = [array lastObject];
1137 if(![object isMemberOfClass:[DWView class]]) 1138 if(![object isMemberOfClass:[DWView class]])
1138 [object setHidden:YES]; 1139 [object setHidden:YES];
1139 [view setFrame:[window frame]]; 1140 /* Adjust the frame to account for the status bar */
1140 [view windowResized:[window frame].size]; 1141 frame.size.height -= [UIApplication sharedApplication].statusBarFrame.size.height;;
1142 [view setFrame:frame];
1143 [view windowResized:frame.size];
1141 } 1144 }
1142 @end 1145 @end
1143 1146
1144 /* Subclass for a button type */ 1147 /* Subclass for a button type */
1145 @interface DWButton : UIButton 1148 @interface DWButton : UIButton
2789 DW_FUNCTION_ADD_PARAM2(type, pad) 2792 DW_FUNCTION_ADD_PARAM2(type, pad)
2790 DW_FUNCTION_RETURN(dw_box_new, HWND) 2793 DW_FUNCTION_RETURN(dw_box_new, HWND)
2791 DW_FUNCTION_RESTORE_PARAM2(type, int, pad, int) 2794 DW_FUNCTION_RESTORE_PARAM2(type, int, pad, int)
2792 { 2795 {
2793 DW_FUNCTION_INIT; 2796 DW_FUNCTION_INIT;
2794 DWBox *view = [[DWBox alloc] init]; 2797 DWBox *view = [[[DWBox alloc] init] retain];
2795 Box *newbox = [view box]; 2798 Box *newbox = [view box];
2796 [view setTranslatesAutoresizingMaskIntoConstraints:NO]; 2799 [view setTranslatesAutoresizingMaskIntoConstraints:NO];
2797 memset(newbox, 0, sizeof(Box)); 2800 memset(newbox, 0, sizeof(Box));
2798 newbox->pad = pad; 2801 newbox->pad = pad;
2799 newbox->type = type; 2802 newbox->type = type;
2821 DW_FUNCTION_DEFINITION(dw_scrollbox_new, HWND, int type, int pad) 2824 DW_FUNCTION_DEFINITION(dw_scrollbox_new, HWND, int type, int pad)
2822 DW_FUNCTION_ADD_PARAM2(type, pad) 2825 DW_FUNCTION_ADD_PARAM2(type, pad)
2823 DW_FUNCTION_RETURN(dw_scrollbox_new, HWND) 2826 DW_FUNCTION_RETURN(dw_scrollbox_new, HWND)
2824 DW_FUNCTION_RESTORE_PARAM2(type, int, pad, int) 2827 DW_FUNCTION_RESTORE_PARAM2(type, int, pad, int)
2825 { 2828 {
2826 DWScrollBox *scrollbox = [[DWScrollBox alloc] init]; 2829 DWScrollBox *scrollbox = [[[DWScrollBox alloc] init] retain];
2827 DWBox *box = dw_box_new(type, pad); 2830 DWBox *box = dw_box_new(type, pad);
2828 DWBox *tmpbox = dw_box_new(DW_VERT, 0); 2831 DWBox *tmpbox = dw_box_new(DW_VERT, 0);
2829 dw_box_pack_start(tmpbox, box, 1, 1, TRUE, TRUE, 0); 2832 dw_box_pack_start(tmpbox, box, 1, 1, TRUE, TRUE, 0);
2830 [scrollbox setBox:box]; 2833 [scrollbox setBox:box];
2831 [scrollbox addSubview:tmpbox]; 2834 [scrollbox addSubview:tmpbox];
3440 DW_FUNCTION_DEFINITION(dw_entryfield_new, HWND, const char *text, ULONG cid) 3443 DW_FUNCTION_DEFINITION(dw_entryfield_new, HWND, const char *text, ULONG cid)
3441 DW_FUNCTION_ADD_PARAM2(text, cid) 3444 DW_FUNCTION_ADD_PARAM2(text, cid)
3442 DW_FUNCTION_RETURN(dw_entryfield_new, HWND) 3445 DW_FUNCTION_RETURN(dw_entryfield_new, HWND)
3443 DW_FUNCTION_RESTORE_PARAM2(text, const char *, cid, ULONG) 3446 DW_FUNCTION_RESTORE_PARAM2(text, const char *, cid, ULONG)
3444 { 3447 {
3445 DWEntryField *entry = [[DWEntryField alloc] init]; 3448 DWEntryField *entry = [[[DWEntryField alloc] init] retain];
3446 [entry setText:[ NSString stringWithUTF8String:text ]]; 3449 [entry setText:[ NSString stringWithUTF8String:text ]];
3447 [entry setTag:cid]; 3450 [entry setTag:cid];
3448 DW_FUNCTION_RETURN_THIS(entry); 3451 DW_FUNCTION_RETURN_THIS(entry);
3449 } 3452 }
3450 3453
3572 DW_FUNCTION_DEFINITION(dw_spinbutton_new, HWND, const char *text, ULONG cid) 3575 DW_FUNCTION_DEFINITION(dw_spinbutton_new, HWND, const char *text, ULONG cid)
3573 DW_FUNCTION_ADD_PARAM2(text, cid) 3576 DW_FUNCTION_ADD_PARAM2(text, cid)
3574 DW_FUNCTION_RETURN(dw_spinbutton_new, HWND) 3577 DW_FUNCTION_RETURN(dw_spinbutton_new, HWND)
3575 DW_FUNCTION_RESTORE_PARAM2(text, const char *, cid, ULONG) 3578 DW_FUNCTION_RESTORE_PARAM2(text, const char *, cid, ULONG)
3576 { 3579 {
3577 DWSpinButton *spinbutton = [[DWSpinButton alloc] init]; 3580 DWSpinButton *spinbutton = [[[DWSpinButton alloc] init] retain];
3578 UIStepper *stepper = [spinbutton stepper]; 3581 UIStepper *stepper = [spinbutton stepper];
3579 UITextField *textfield = [spinbutton textfield]; 3582 UITextField *textfield = [spinbutton textfield];
3580 long val = atol(text); 3583 long val = atol(text);
3581 3584
3582 [stepper setStepValue:1]; 3585 [stepper setStepValue:1];
3669 DW_FUNCTION_DEFINITION(dw_slider_new, HWND, int vertical, int increments, ULONG cid) 3672 DW_FUNCTION_DEFINITION(dw_slider_new, HWND, int vertical, int increments, ULONG cid)
3670 DW_FUNCTION_ADD_PARAM3(vertical, increments, cid) 3673 DW_FUNCTION_ADD_PARAM3(vertical, increments, cid)
3671 DW_FUNCTION_RETURN(dw_slider_new, HWND) 3674 DW_FUNCTION_RETURN(dw_slider_new, HWND)
3672 DW_FUNCTION_RESTORE_PARAM3(vertical, int, increments, int, cid, ULONG) 3675 DW_FUNCTION_RESTORE_PARAM3(vertical, int, increments, int, cid, ULONG)
3673 { 3676 {
3674 DWSlider *slider = [[DWSlider alloc] init]; 3677 DWSlider *slider = [[[DWSlider alloc] init] retain];
3675 [slider setMaximumValue:(double)increments]; 3678 [slider setMaximumValue:(double)increments];
3676 [slider setMinimumValue:0]; 3679 [slider setMinimumValue:0];
3677 [slider setContinuous:YES]; 3680 [slider setContinuous:YES];
3678 [slider addTarget:slider 3681 [slider addTarget:slider
3679 action:@selector(sliderChanged:) 3682 action:@selector(sliderChanged:)
3761 DW_FUNCTION_DEFINITION(dw_percent_new, HWND, ULONG cid) 3764 DW_FUNCTION_DEFINITION(dw_percent_new, HWND, ULONG cid)
3762 DW_FUNCTION_ADD_PARAM1(cid) 3765 DW_FUNCTION_ADD_PARAM1(cid)
3763 DW_FUNCTION_RETURN(dw_percent_new, HWND) 3766 DW_FUNCTION_RETURN(dw_percent_new, HWND)
3764 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) 3767 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG)
3765 { 3768 {
3766 DWPercent *percent = [[DWPercent alloc] init]; 3769 DWPercent *percent = [[[DWPercent alloc] init] retain];
3767 [percent setTag:cid]; 3770 [percent setTag:cid];
3768 DW_FUNCTION_RETURN_THIS(percent); 3771 DW_FUNCTION_RETURN_THIS(percent);
3769 } 3772 }
3770 3773
3771 /* 3774 /*
4252 DW_FUNCTION_RETURN(dw_mle_new, HWND) 4255 DW_FUNCTION_RETURN(dw_mle_new, HWND)
4253 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) 4256 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG)
4254 { 4257 {
4255 CGRect frame = CGRectMake(0, 0, 100, 50); 4258 CGRect frame = CGRectMake(0, 0, 100, 50);
4256 NSTextContainer *tc = [[NSTextContainer alloc] initWithSize:frame.size]; 4259 NSTextContainer *tc = [[NSTextContainer alloc] initWithSize:frame.size];
4257 DWMLE *mle = [[DWMLE alloc] initWithFrame:frame textContainer:tc]; 4260 DWMLE *mle = [[[DWMLE alloc] initWithFrame:frame textContainer:tc] retain];
4258 UIScrollView *scrollview = [[UIScrollView alloc] init]; 4261 UIScrollView *scrollview = [[UIScrollView alloc] init];
4259 CGSize size = [mle intrinsicContentSize]; 4262 CGSize size = [mle intrinsicContentSize];
4260 4263
4261 size.width = size.height; 4264 size.width = size.height;
4262 [mle setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; 4265 [mle setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
4556 DW_FUNCTION_DEFINITION(dw_text_new, HWND, const char *text, ULONG cid) 4559 DW_FUNCTION_DEFINITION(dw_text_new, HWND, const char *text, ULONG cid)
4557 DW_FUNCTION_ADD_PARAM2(text, cid) 4560 DW_FUNCTION_ADD_PARAM2(text, cid)
4558 DW_FUNCTION_RETURN(dw_text_new, HWND) 4561 DW_FUNCTION_RETURN(dw_text_new, HWND)
4559 DW_FUNCTION_RESTORE_PARAM2(text, const char *, cid, ULONG) 4562 DW_FUNCTION_RESTORE_PARAM2(text, const char *, cid, ULONG)
4560 { 4563 {
4561 DWText *textfield = [[DWText alloc] init]; 4564 DWText *textfield = [[[DWText alloc] init] retain];
4562 [textfield setText:[NSString stringWithUTF8String:text]]; 4565 [textfield setText:[NSString stringWithUTF8String:text]];
4563 [textfield setTag:cid]; 4566 [textfield setTag:cid];
4564 if(DWDefaultFont) 4567 if(DWDefaultFont)
4565 { 4568 {
4566 [textfield setFont:DWDefaultFont]; 4569 [textfield setFont:DWDefaultFont];
4578 DW_FUNCTION_DEFINITION(dw_render_new, HWND, ULONG cid) 4581 DW_FUNCTION_DEFINITION(dw_render_new, HWND, ULONG cid)
4579 DW_FUNCTION_ADD_PARAM1(cid) 4582 DW_FUNCTION_ADD_PARAM1(cid)
4580 DW_FUNCTION_RETURN(dw_render_new, HWND) 4583 DW_FUNCTION_RETURN(dw_render_new, HWND)
4581 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) 4584 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG)
4582 { 4585 {
4583 DWRender *render = [[DWRender alloc] init]; 4586 DWRender *render = [[[DWRender alloc] init] retain];
4584 [render setTag:cid]; 4587 [render setTag:cid];
4585 DW_FUNCTION_RETURN_THIS(render); 4588 DW_FUNCTION_RETURN_THIS(render);
4586 } 4589 }
4587 4590
4588 /* 4591 /*
6243 /* There isn't anything like quite like MDI on MacOS... 6246 /* There isn't anything like quite like MDI on MacOS...
6244 * However we will make floating windows that hide 6247 * However we will make floating windows that hide
6245 * when the application is deactivated to simulate 6248 * when the application is deactivated to simulate
6246 * similar behavior. 6249 * similar behavior.
6247 */ 6250 */
6248 DWMDI *mdi = [[DWMDI alloc] init]; 6251 DWMDI *mdi = [[[DWMDI alloc] init] retain];
6249 /* [mdi setTag:cid]; Why doesn't this work? */ 6252 /* [mdi setTag:cid]; Why doesn't this work? */
6250 return mdi; 6253 return mdi;
6251 } 6254 }
6252 6255
6253 /* 6256 /*
6265 DW_FUNCTION_RESTORE_PARAM4(DW_UNUSED(type), int, topleft, HWND, bottomright, HWND, cid, unsigned long) 6268 DW_FUNCTION_RESTORE_PARAM4(DW_UNUSED(type), int, topleft, HWND, bottomright, HWND, cid, unsigned long)
6266 { 6269 {
6267 DW_FUNCTION_INIT; 6270 DW_FUNCTION_INIT;
6268 id tmpbox = dw_box_new(DW_VERT, 0); 6271 id tmpbox = dw_box_new(DW_VERT, 0);
6269 DWSplitBar *split = [[DWSplitBar alloc] init]; 6272 DWSplitBar *split = [[DWSplitBar alloc] init];
6270 UIViewController *vc = [[UIViewController alloc] init]; 6273 UIViewController *vc = [[[UIViewController alloc] init] retain];
6271 [split setDelegate:split]; 6274 [split setDelegate:split];
6272 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0); 6275 dw_box_pack_start(tmpbox, topleft, 0, 0, TRUE, TRUE, 0);
6273 [vc setView:tmpbox]; 6276 [vc setView:tmpbox];
6274 if (@available(iOS 14.0, *)) { 6277 if (@available(iOS 14.0, *)) {
6275 [split setViewController:vc forColumn:UISplitViewControllerColumnPrimary]; 6278 [split setViewController:vc forColumn:UISplitViewControllerColumnPrimary];
6406 DW_FUNCTION_ADD_PARAM1(cid) 6409 DW_FUNCTION_ADD_PARAM1(cid)
6407 DW_FUNCTION_RETURN(dw_bitmap_new, HWND) 6410 DW_FUNCTION_RETURN(dw_bitmap_new, HWND)
6408 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) 6411 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG)
6409 { 6412 {
6410 DW_FUNCTION_INIT; 6413 DW_FUNCTION_INIT;
6411 UIImageView *bitmap = [[UIImageView alloc] init]; 6414 UIImageView *bitmap = [[[UIImageView alloc] init] retain];
6412 [bitmap setTag:cid]; 6415 [bitmap setTag:cid];
6413 DW_FUNCTION_RETURN_THIS(bitmap); 6416 DW_FUNCTION_RETURN_THIS(bitmap);
6414 } 6417 }
6415 6418
6416 /* 6419 /*
6711 DW_FUNCTION_DEFINITION(dw_calendar_new, HWND, ULONG cid) 6714 DW_FUNCTION_DEFINITION(dw_calendar_new, HWND, ULONG cid)
6712 DW_FUNCTION_ADD_PARAM1(cid) 6715 DW_FUNCTION_ADD_PARAM1(cid)
6713 DW_FUNCTION_RETURN(dw_calendar_new, HWND) 6716 DW_FUNCTION_RETURN(dw_calendar_new, HWND)
6714 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) 6717 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG)
6715 { 6718 {
6716 DWCalendar *calendar = [[DWCalendar alloc] init]; 6719 DWCalendar *calendar = [[[DWCalendar alloc] init] retain];
6717 [calendar setDatePickerMode:UIDatePickerModeDate]; 6720 [calendar setDatePickerMode:UIDatePickerModeDate];
6718 [calendar setTag:cid]; 6721 [calendar setTag:cid];
6719 [calendar setDate:[NSDate date]]; 6722 [calendar setDate:[NSDate date]];
6720 DW_FUNCTION_RETURN_THIS(calendar); 6723 DW_FUNCTION_RETURN_THIS(calendar);
6721 } 6724 }
6887 DW_FUNCTION_ADD_PARAM1(cid) 6890 DW_FUNCTION_ADD_PARAM1(cid)
6888 DW_FUNCTION_RETURN(dw_html_new, HWND) 6891 DW_FUNCTION_RETURN(dw_html_new, HWND)
6889 DW_FUNCTION_RESTORE_PARAM1(DW_UNUSED(cid), ULONG) 6892 DW_FUNCTION_RESTORE_PARAM1(DW_UNUSED(cid), ULONG)
6890 { 6893 {
6891 DW_FUNCTION_INIT; 6894 DW_FUNCTION_INIT;
6892 DWWebView *web = [[DWWebView alloc] init]; 6895 DWWebView *web = [[[DWWebView alloc] init] retain];
6893 web.navigationDelegate = web; 6896 web.navigationDelegate = web;
6894 /* [web setTag:cid]; Why doesn't this work? */ 6897 /* [web setTag:cid]; Why doesn't this work? */
6895 DW_FUNCTION_RETURN_THIS(web); 6898 DW_FUNCTION_RETURN_THIS(web);
6896 } 6899 }
6897 6900
6930 * id: An ID to be used for getting the resource from the 6933 * id: An ID to be used for getting the resource from the
6931 * resource file. 6934 * resource file.
6932 */ 6935 */
6933 HMENUI API dw_menu_new(ULONG cid) 6936 HMENUI API dw_menu_new(ULONG cid)
6934 { 6937 {
6935 DWMenu *menu = [[DWMenu alloc] init]; 6938 DWMenu *menu = [[[DWMenu alloc] init] retain];
6936 /* [menu setTag:cid]; Why doesn't this work? */ 6939 /* [menu setTag:cid]; Why doesn't this work? */
6937 return menu; 6940 return menu;
6938 } 6941 }
6939 6942
6940 /* 6943 /*
7192 DW_FUNCTION_DEFINITION(dw_notebook_new, HWND, ULONG cid, int top) 7195 DW_FUNCTION_DEFINITION(dw_notebook_new, HWND, ULONG cid, int top)
7193 DW_FUNCTION_ADD_PARAM2(cid, top) 7196 DW_FUNCTION_ADD_PARAM2(cid, top)
7194 DW_FUNCTION_RETURN(dw_notebook_new, HWND) 7197 DW_FUNCTION_RETURN(dw_notebook_new, HWND)
7195 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, top, int) 7198 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, top, int)
7196 { 7199 {
7197 DWNotebook *notebook = [[DWNotebook alloc] init]; 7200 DWNotebook *notebook = [[[DWNotebook alloc] init] retain];
7198 [notebook addTarget:notebook 7201 [notebook addTarget:notebook
7199 action:@selector(pageChanged:) 7202 action:@selector(pageChanged:)
7200 forControlEvents:UIControlEventValueChanged]; 7203 forControlEvents:UIControlEventValueChanged];
7201 [notebook setTag:cid]; 7204 [notebook setTag:cid];
7202 DW_FUNCTION_RETURN_THIS(notebook); 7205 DW_FUNCTION_RETURN_THIS(notebook);