comparison ios/dw.m @ 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
comparison
equal deleted inserted replaced
2412:3b59cbd26fab 2413:8727ad1a19c3
1378 -(UISegmentedControl *)tabs { return tabs; } 1378 -(UISegmentedControl *)tabs { return tabs; }
1379 -(NSMutableArray<DWNotebookPage *> *)views { return views; }; 1379 -(NSMutableArray<DWNotebookPage *> *)views { return views; };
1380 -(void)pageChanged:(id)sender 1380 -(void)pageChanged:(id)sender
1381 { 1381 {
1382 NSInteger intpageid = [tabs selectedSegmentIndex]; 1382 NSInteger intpageid = [tabs selectedSegmentIndex];
1383 DWNotebookPage *page = [[self views] objectAtIndex:intpageid]; 1383
1384 1384 if(intpageid != NSNotFound && intpageid < [views count])
1385 /* Hide the previously visible page contents */ 1385 {
1386 if(page != visible) 1386 DWNotebookPage *page = [views objectAtIndex:intpageid];
1387 [visible setHidden:YES]; 1387
1388 1388 /* Hide the previously visible page contents */
1389 /* If the new page is a valid box, lay it out */ 1389 if(page != visible)
1390 if([page isKindOfClass:[DWBox class]]) 1390 [visible setHidden:YES];
1391 { 1391
1392 Box *box = [page box]; 1392 /* If the new page is a valid box, lay it out */
1393 /* Start with the entire notebook size and then adjust 1393 if([page isKindOfClass:[DWBox class]])
1394 * it to account for the segement control's height. 1394 {
1395 */ 1395 Box *box = [page box];
1396 NSInteger height = [tabs frame].size.height; 1396 /* Start with the entire notebook size and then adjust
1397 CGRect frame = [self frame]; 1397 * it to account for the segement control's height.
1398 frame.origin.y += height; 1398 */
1399 frame.size.height -= height; 1399 NSInteger height = [tabs frame].size.height;
1400 [page setFrame:frame]; 1400 CGRect frame = [self frame];
1401 [page setHidden:NO]; 1401 frame.origin.y += height;
1402 visible = page; 1402 frame.size.height -= height;
1403 _dw_do_resize(box, frame.size.width, frame.size.height); 1403 [page setFrame:frame];
1404 _dw_handle_resize_events(box); 1404 [page setHidden:NO];
1405 } 1405 visible = page;
1406 _dw_event_handler(self, DW_INT_TO_POINTER(intpageid), 15); 1406 _dw_do_resize(box, frame.size.width, frame.size.height);
1407 _dw_handle_resize_events(box);
1408 }
1409 _dw_event_handler(self, DW_INT_TO_POINTER(intpageid), 15);
1410 }
1407 } 1411 }
1408 -(void)dealloc { 1412 -(void)dealloc {
1409 UserData *root = userdata; 1413 UserData *root = userdata;
1410 _dw_remove_userdata(&root, NULL, TRUE); 1414 _dw_remove_userdata(&root, NULL, TRUE);
1411 dw_signal_disconnect_by_window(self); 1415 dw_signal_disconnect_by_window(self);
2158 _dw_event_handler(handle, nil, 1); 2162 _dw_event_handler(handle, nil, 1);
2159 } 2163 }
2160 } 2164 }
2161 } 2165 }
2162 /* Special handling for notebook controls */ 2166 /* Special handling for notebook controls */
2163 #if 0 /* TODO: Segmented control might not have subviews */
2164 else if([handle isMemberOfClass:[DWNotebook class]]) 2167 else if([handle isMemberOfClass:[DWNotebook class]])
2165 { 2168 {
2166 DWNotebook *notebook = (DWNotebook *)handle; 2169 DWNotebook *notebook = handle;
2167 NSInteger index = [notebook selectedSegmentIndex]; 2170 NSInteger intpageid = [[notebook tabs] selectedSegmentIndex];
2168 id view = [notepage view]; 2171
2169 2172 if(intpageid != NSNotFound && intpageid < [[notebook views] count])
2170 if([view isMemberOfClass:[DWBox class]])
2171 { 2173 {
2172 Box *box = (Box *)[view box]; 2174 DWNotebookPage *page = [[notebook views] objectAtIndex:intpageid];
2173 _dw_handle_resize_events(box); 2175
2176 if([page isKindOfClass:[DWBox class]])
2177 {
2178 Box *box = [page box];
2179 _dw_handle_resize_events(box);
2180 }
2174 } 2181 }
2175 } 2182 }
2176 #endif
2177 /* Handle laying out scrollviews... if required space is less 2183 /* Handle laying out scrollviews... if required space is less
2178 * than available space, then expand. Otherwise use required space. 2184 * than available space, then expand. Otherwise use required space.
2179 */ 2185 */
2180 else if([handle isMemberOfClass:[DWScrollBox class]]) 2186 else if([handle isMemberOfClass:[DWScrollBox class]])
2181 { 2187 {
2338 2344
2339 /* If the calculated size is valid... */ 2345 /* If the calculated size is valid... */
2340 if(height > 0 && width > 0) 2346 if(height > 0 && width > 0)
2341 { 2347 {
2342 int pad = thisbox->items[z].pad; 2348 int pad = thisbox->items[z].pad;
2343 UIView *handle = thisbox->items[z].hwnd; 2349 id handle = thisbox->items[z].hwnd;
2344 CGRect rect; 2350 CGRect rect;
2345 2351
2346 rect.origin.x = currentx + pad; 2352 rect.origin.x = currentx + pad;
2347 rect.origin.y = currenty + pad; 2353 rect.origin.y = currenty + pad;
2348 rect.size.width = width; 2354 rect.size.width = width;
2361 _dw_resize_box(tmp, depth, width, height, pass); 2367 _dw_resize_box(tmp, depth, width, height, pass);
2362 (*depth)--; 2368 (*depth)--;
2363 } 2369 }
2364 } 2370 }
2365 2371
2366 #if 0 /* TODO: Segemented control may not have subviews */
2367 /* Special handling for notebook controls */ 2372 /* Special handling for notebook controls */
2368 if([handle isMemberOfClass:[DWNotebook class]]) 2373 if([handle isMemberOfClass:[DWNotebook class]])
2369 { 2374 {
2370 DWNotebook *notebook = (DWNotebook *)handle; 2375 DWNotebook *notebook = handle;
2371 NSInteger index = [notebook selectedSegmentIndex]; 2376 NSInteger intpageid = [[notebook tabs] selectedSegmentIndex];
2372 id view = [notepage view]; 2377
2373 2378 if(intpageid != NSNotFound && intpageid < [[notebook views] count])
2374 if([view isMemberOfClass:[DWBox class]])
2375 { 2379 {
2376 Box *box = (Box *)[view box]; 2380 DWNotebookPage *page = [[notebook views] objectAtIndex:intpageid];
2377 CGSize size = [view frame].size; 2381
2378 _dw_do_resize(box, size.width, size.height); 2382 /* If the new page is a valid box, lay it out */
2379 _dw_handle_resize_events(box); 2383 if([page isKindOfClass:[DWBox class]])
2384 {
2385 Box *box = [page box];
2386 /* Start with the entire notebook size and then adjust
2387 * it to account for the segement control's height.
2388 */
2389 NSInteger height = [[notebook tabs] frame].size.height;
2390 CGRect frame = [notebook frame];
2391 frame.origin.y += height;
2392 frame.size.height -= height;
2393 [page setFrame:frame];
2394 _dw_do_resize(box, frame.size.width, frame.size.height);
2395 _dw_handle_resize_events(box);
2396 }
2380 } 2397 }
2381 } 2398 }
2382 #endif
2383 /* Handle laying out scrollviews... if required space is less 2399 /* Handle laying out scrollviews... if required space is less
2384 * than available space, then expand. Otherwise use required space. 2400 * than available space, then expand. Otherwise use required space.
2385 */ 2401 */
2386 else if([handle isMemberOfClass:[DWScrollBox class]]) 2402 else if([handle isMemberOfClass:[DWScrollBox class]])
2387 { 2403 {
2980 thisheight = (int)size.height; 2996 thisheight = (int)size.height;
2981 } 2997 }
2982 else 2998 else
2983 { 2999 {
2984 /* Text button */ 3000 /* Text button */
2985 nsstr = [object title]; 3001 nsstr = [[object titleLabel] text];
2986 3002
2987 extrawidth = 8; 3003 extrawidth = 8;
2988 extraheight = 4; 3004 extraheight = 4;
2989 } 3005 }
2990 break; 3006 break;
3003 thiswidth = 50; 3019 thiswidth = 50;
3004 else 3020 else
3005 thiswidth = 150; 3021 thiswidth = 150;
3006 } 3022 }
3007 else 3023 else
3008 nsstr = [object stringValue]; 3024 nsstr = [object text];
3009 3025
3010 if(font) 3026 if(font)
3011 thisheight = (int)[font lineHeight]; 3027 thisheight = (int)[font lineHeight];
3012 } 3028 }
3013 /* Handle the ranged widgets */ 3029 /* Handle the ranged widgets */
3069 if(thisheight < _DW_SCROLLED_MIN_HEIGHT) 3085 if(thisheight < _DW_SCROLLED_MIN_HEIGHT)
3070 thisheight = _DW_SCROLLED_MIN_HEIGHT; 3086 thisheight = _DW_SCROLLED_MIN_HEIGHT;
3071 if(thisheight > _DW_SCROLLED_MAX_HEIGHT) 3087 if(thisheight > _DW_SCROLLED_MAX_HEIGHT)
3072 thisheight = _DW_SCROLLED_MAX_HEIGHT; 3088 thisheight = _DW_SCROLLED_MAX_HEIGHT;
3073 } 3089 }
3090 else if([ object isMemberOfClass:[UILabel class] ])
3091 nsstr = [object text];
3074 /* Any other control type */ 3092 /* Any other control type */
3075 else if([ object isKindOfClass:[ UIControl class ] ]) 3093 else if([ object isKindOfClass:[ UIControl class ] ])
3076 nsstr = [object stringValue]; 3094 nsstr = [object text];
3077 3095
3078 /* If we have a string... 3096 /* If we have a string...
3079 * calculate the size with the current font. 3097 * calculate the size with the current font.
3080 */ 3098 */
3081 if(nsstr && [nsstr length]) 3099 if(nsstr && [nsstr length])
7332 DW_FUNCTION_RETURN(dw_notebook_page_get, unsigned long) 7350 DW_FUNCTION_RETURN(dw_notebook_page_get, unsigned long)
7333 DW_FUNCTION_RESTORE_PARAM1(handle, HWND) 7351 DW_FUNCTION_RESTORE_PARAM1(handle, HWND)
7334 { 7352 {
7335 DWNotebook *notebook = handle; 7353 DWNotebook *notebook = handle;
7336 NSInteger index = [[notebook tabs] selectedSegmentIndex]; 7354 NSInteger index = [[notebook tabs] selectedSegmentIndex];
7337 NSMutableArray<DWNotebookPage *> *views = [notebook views]; 7355 unsigned long retval = 0;
7338 DWNotebookPage *notepage = [views objectAtIndex:index]; 7356
7339 unsigned long retval = [notepage pageid]; 7357 if(index != NSNotFound)
7358 {
7359 NSMutableArray<DWNotebookPage *> *views = [notebook views];
7360 DWNotebookPage *notepage = [views objectAtIndex:index];
7361
7362 retval = [notepage pageid];
7363 }
7340 DW_FUNCTION_RETURN_THIS(retval); 7364 DW_FUNCTION_RETURN_THIS(retval);
7341 } 7365 }
7342 7366
7343 /* 7367 /*
7344 * Sets the currently visibale page ID. 7368 * Sets the currently visibale page ID.