changeset 2413:8727ad1a19c3

iOS: Fix notebook relayout on rotation. Also fix autosizing of controls.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 01 Apr 2021 21:15:55 +0000
parents 3b59cbd26fab
children 5e5fab842901
files ios/dw.m
diffstat 1 files changed, 75 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/ios/dw.m	Wed Mar 31 16:31:27 2021 +0000
+++ b/ios/dw.m	Thu Apr 01 21:15:55 2021 +0000
@@ -1380,30 +1380,34 @@
 -(void)pageChanged:(id)sender
 {
     NSInteger intpageid = [tabs selectedSegmentIndex];
-    DWNotebookPage *page = [[self views] objectAtIndex:intpageid];
-
-    /* Hide the previously visible page contents */
-    if(page != visible)
-        [visible setHidden:YES];
-
-    /* If the new page is a valid box, lay it out */
-    if([page isKindOfClass:[DWBox class]])
-    {
-        Box *box = [page box];
-        /* Start with the entire notebook size and then adjust
-         * it to account for the segement control's height.
-         */
-        NSInteger height = [tabs frame].size.height;
-        CGRect frame = [self frame];
-        frame.origin.y += height;
-        frame.size.height -= height;
-        [page setFrame:frame];
-        [page setHidden:NO];
-        visible = page;
-        _dw_do_resize(box, frame.size.width, frame.size.height);
-        _dw_handle_resize_events(box);
-    }
-    _dw_event_handler(self, DW_INT_TO_POINTER(intpageid), 15);
+    
+    if(intpageid != NSNotFound && intpageid < [views count])
+    {
+        DWNotebookPage *page = [views objectAtIndex:intpageid];
+
+        /* Hide the previously visible page contents */
+        if(page != visible)
+            [visible setHidden:YES];
+
+        /* If the new page is a valid box, lay it out */
+        if([page isKindOfClass:[DWBox class]])
+        {
+            Box *box = [page box];
+            /* Start with the entire notebook size and then adjust
+             * it to account for the segement control's height.
+             */
+            NSInteger height = [tabs frame].size.height;
+            CGRect frame = [self frame];
+            frame.origin.y += height;
+            frame.size.height -= height;
+            [page setFrame:frame];
+            [page setHidden:NO];
+            visible = page;
+            _dw_do_resize(box, frame.size.width, frame.size.height);
+            _dw_handle_resize_events(box);
+        }
+        _dw_event_handler(self, DW_INT_TO_POINTER(intpageid), 15);
+    }
 }
 -(void)dealloc {
     UserData *root = userdata;
@@ -2160,20 +2164,22 @@
                 }
             }
             /* Special handling for notebook controls */
-#if 0 /* TODO: Segmented control might not have subviews */
             else if([handle isMemberOfClass:[DWNotebook class]])
             {
-                DWNotebook *notebook = (DWNotebook *)handle;
-                NSInteger index = [notebook selectedSegmentIndex];
-                id view = [notepage view];
-
-                if([view isMemberOfClass:[DWBox class]])
+                DWNotebook *notebook = handle;
+                NSInteger intpageid = [[notebook tabs] selectedSegmentIndex];
+                
+                if(intpageid != NSNotFound && intpageid < [[notebook views] count])
                 {
-                    Box *box = (Box *)[view box];
-                    _dw_handle_resize_events(box);
+                    DWNotebookPage *page = [[notebook views] objectAtIndex:intpageid];
+
+                    if([page isKindOfClass:[DWBox class]])
+                    {
+                        Box *box = [page box];
+                        _dw_handle_resize_events(box);
+                    }
                 }
             }
-#endif
             /* Handle laying out scrollviews... if required space is less
              * than available space, then expand.  Otherwise use required space.
              */
@@ -2340,7 +2346,7 @@
             if(height > 0 && width > 0)
             {
                 int pad = thisbox->items[z].pad;
-                UIView *handle = thisbox->items[z].hwnd;
+                id handle = thisbox->items[z].hwnd;
                 CGRect rect;
 
                 rect.origin.x = currentx + pad;
@@ -2363,23 +2369,33 @@
                     }
                 }
 
-#if 0 /* TODO: Segemented control may not have subviews */
                 /* Special handling for notebook controls */
                 if([handle isMemberOfClass:[DWNotebook class]])
                 {
-                    DWNotebook *notebook = (DWNotebook *)handle;
-                    NSInteger index = [notebook selectedSegmentIndex];
-                    id view = [notepage view];
-
-                    if([view isMemberOfClass:[DWBox class]])
+                    DWNotebook *notebook = handle;
+                    NSInteger intpageid = [[notebook tabs] selectedSegmentIndex];
+                    
+                    if(intpageid != NSNotFound && intpageid < [[notebook views] count])
                     {
-                        Box *box = (Box *)[view box];
-                        CGSize size = [view frame].size;
-                        _dw_do_resize(box, size.width, size.height);
-                        _dw_handle_resize_events(box);
+                        DWNotebookPage *page = [[notebook views] objectAtIndex:intpageid];
+
+                        /* If the new page is a valid box, lay it out */
+                        if([page isKindOfClass:[DWBox class]])
+                        {
+                            Box *box = [page box];
+                            /* Start with the entire notebook size and then adjust
+                             * it to account for the segement control's height.
+                             */
+                            NSInteger height = [[notebook tabs] frame].size.height;
+                            CGRect frame = [notebook frame];
+                            frame.origin.y += height;
+                            frame.size.height -= height;
+                            [page setFrame:frame];
+                            _dw_do_resize(box, frame.size.width, frame.size.height);
+                            _dw_handle_resize_events(box);
+                        }
                     }
                 }
-#endif
                 /* Handle laying out scrollviews... if required space is less
                  * than available space, then expand.  Otherwise use required space.
                  */
@@ -2982,7 +2998,7 @@
                 else
                 {
                     /* Text button */
-                    nsstr = [object title];
+                    nsstr = [[object titleLabel] text];
 
                     extrawidth = 8;
                     extraheight = 4;
@@ -3005,7 +3021,7 @@
                 thiswidth = 150;
         }
         else
-            nsstr = [object stringValue];
+            nsstr = [object text];
 
         if(font)
             thisheight = (int)[font lineHeight];
@@ -3071,9 +3087,11 @@
         if(thisheight > _DW_SCROLLED_MAX_HEIGHT)
             thisheight = _DW_SCROLLED_MAX_HEIGHT;
     }
+    else if([ object isMemberOfClass:[UILabel class] ])
+        nsstr = [object text];
     /* Any other control type */
     else if([ object isKindOfClass:[ UIControl class ] ])
-        nsstr = [object stringValue];
+        nsstr = [object text];
 
     /* If we have a string...
      * calculate the size with the current font.
@@ -7334,9 +7352,15 @@
 {
     DWNotebook *notebook = handle;
     NSInteger index = [[notebook tabs] selectedSegmentIndex];
-    NSMutableArray<DWNotebookPage *> *views = [notebook views];
-    DWNotebookPage *notepage = [views objectAtIndex:index];
-    unsigned long retval = [notepage pageid];
+    unsigned long retval = 0;
+    
+    if(index != NSNotFound)
+    {
+        NSMutableArray<DWNotebookPage *> *views = [notebook views];
+        DWNotebookPage *notepage = [views objectAtIndex:index];
+
+        retval = [notepage pageid];
+    }
     DW_FUNCTION_RETURN_THIS(retval);
 }