Mercurial > dwindows
comparison ios/dw.m @ 2408:795056df9efd
iOS: Initial functional implmentation of the notebook/tabbed control.
Some layout issues remain but it generally works.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 29 Mar 2021 22:46:01 +0000 |
parents | 6336244aa895 |
children | 2ab3e88e5d68 |
comparison
equal
deleted
inserted
replaced
2407:6336244aa895 | 2408:795056df9efd |
---|---|
1328 -(void)setUserdata:(void *)input { userdata = input; } | 1328 -(void)setUserdata:(void *)input { userdata = input; } |
1329 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 1329 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
1330 @end | 1330 @end |
1331 | 1331 |
1332 /* Subclass for a Notebook page type */ | 1332 /* Subclass for a Notebook page type */ |
1333 @interface DWNotebookPage : UIView | 1333 @interface DWNotebookPage : DWBox |
1334 { | 1334 { |
1335 int pageid; | |
1336 } | |
1337 -(int)pageid; | |
1338 -(void)setPageid:(int)input; | |
1339 @end | |
1340 | |
1341 /* Subclass for a Notebook control type */ | |
1342 @interface DWNotebook : UIView | |
1343 { | |
1344 UISegmentedControl *tabs; | |
1335 void *userdata; | 1345 void *userdata; |
1336 int pageid; | 1346 int pageid; |
1347 NSMutableArray<DWNotebookPage *> *views; | |
1348 DWNotebookPage *visible; | |
1337 } | 1349 } |
1338 -(void *)userdata; | 1350 -(void *)userdata; |
1339 -(void)setUserdata:(void *)input; | 1351 -(void)setUserdata:(void *)input; |
1340 -(int)pageid; | 1352 -(int)pageid; |
1341 -(void)setPageid:(int)input; | 1353 -(void)setPageid:(int)input; |
1342 @end | 1354 -(UISegmentedControl *)tabs; |
1343 | |
1344 /* Subclass for a Notebook control type */ | |
1345 @interface DWNotebook : UISegmentedControl | |
1346 { | |
1347 void *userdata; | |
1348 int pageid; | |
1349 NSMutableArray<DWNotebookPage *> *views; | |
1350 } | |
1351 -(void *)userdata; | |
1352 -(void)setUserdata:(void *)input; | |
1353 -(int)pageid; | |
1354 -(void)setPageid:(int)input; | |
1355 -(NSMutableArray<DWNotebookPage *> *)views; | 1355 -(NSMutableArray<DWNotebookPage *> *)views; |
1356 -(void)pageChanged:(id)sender; | 1356 -(void)pageChanged:(id)sender; |
1357 @end | 1357 @end |
1358 | 1358 |
1359 @implementation DWNotebook | 1359 @implementation DWNotebook |
1360 -(id)init { | |
1361 self = [super init]; | |
1362 tabs = [[[UISegmentedControl alloc] init] retain]; | |
1363 views = [[[NSMutableArray alloc] init] retain]; | |
1364 [self addSubview:tabs]; | |
1365 return self; | |
1366 } | |
1367 -(void)setFrame:(CGRect)frame { | |
1368 [super setFrame:frame]; | |
1369 frame.size.height = 40; | |
1370 [tabs setFrame:frame]; | |
1371 } | |
1360 -(void *)userdata { return userdata; } | 1372 -(void *)userdata { return userdata; } |
1361 -(void)setUserdata:(void *)input { userdata = input; } | 1373 -(void)setUserdata:(void *)input { userdata = input; } |
1362 -(int)pageid { return pageid; } | 1374 -(int)pageid { return pageid; } |
1363 -(void)setPageid:(int)input { pageid = input; } | 1375 -(void)setPageid:(int)input { pageid = input; } |
1376 -(UISegmentedControl *)tabs { return tabs; } | |
1364 -(NSMutableArray<DWNotebookPage *> *)views { return views; }; | 1377 -(NSMutableArray<DWNotebookPage *> *)views { return views; }; |
1365 -(void)pageChanged:(id)sender | 1378 -(void)pageChanged:(id)sender |
1366 { | 1379 { |
1367 #if 0 /* TODO: Implement page/segment changed handler */ | 1380 NSInteger intpageid = [tabs selectedSegmentIndex]; |
1368 id object = [notepage view]; | 1381 DWNotebookPage *page = [[self views] objectAtIndex:intpageid]; |
1369 DWNotebookPage *page = (DWNotebookPage *)notepage; | 1382 |
1370 | 1383 /* Hide the previously visible page contents */ |
1371 if([object isMemberOfClass:[DWBox class]]) | 1384 if(page != visible) |
1372 { | 1385 [visible setHidden:YES]; |
1373 DWBox *view = object; | 1386 |
1374 Box *box = [view box]; | 1387 /* If the new page is a valid box, lay it out */ |
1375 CGSize size = [view frame].size; | 1388 if([page isKindOfClass:[DWBox class]]) |
1376 _dw_do_resize(box, size.width, size.height); | 1389 { |
1390 Box *box = [page box]; | |
1391 /* Start with the entire notebook size and then adjust | |
1392 * it to account for the segement control's height. | |
1393 */ | |
1394 NSInteger height = [tabs frame].size.height; | |
1395 CGRect frame = [self frame]; | |
1396 frame.origin.y += height; | |
1397 frame.size.height -= height; | |
1398 [page setFrame:frame]; | |
1399 [page setHidden:NO]; | |
1400 visible = page; | |
1401 _dw_do_resize(box, frame.size.width, frame.size.height); | |
1377 _dw_handle_resize_events(box); | 1402 _dw_handle_resize_events(box); |
1378 } | 1403 } |
1379 #endif | 1404 _dw_event_handler(self, DW_INT_TO_POINTER(intpageid), 15); |
1380 _dw_event_handler(self, DW_INT_TO_POINTER([self selectedSegmentIndex]), 15); | 1405 } |
1381 } | 1406 -(void)dealloc { |
1382 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } | 1407 UserData *root = userdata; |
1408 _dw_remove_userdata(&root, NULL, TRUE); | |
1409 dw_signal_disconnect_by_window(self); | |
1410 [tabs release]; | |
1411 [views release]; | |
1412 [super dealloc]; | |
1413 } | |
1383 @end | 1414 @end |
1384 | 1415 |
1385 @implementation DWNotebookPage | 1416 @implementation DWNotebookPage |
1386 -(void *)userdata { return userdata; } | |
1387 -(void)setUserdata:(void *)input { userdata = input; } | |
1388 -(int)pageid { return pageid; } | 1417 -(int)pageid { return pageid; } |
1389 -(void)setPageid:(int)input { pageid = input; } | 1418 -(void)setPageid:(int)input { pageid = input; } |
1390 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } | 1419 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } |
1391 @end | 1420 @end |
1392 | 1421 |
7198 DW_FUNCTION_ADD_PARAM2(cid, top) | 7227 DW_FUNCTION_ADD_PARAM2(cid, top) |
7199 DW_FUNCTION_RETURN(dw_notebook_new, HWND) | 7228 DW_FUNCTION_RETURN(dw_notebook_new, HWND) |
7200 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, DW_UNUSED(top), int) | 7229 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, DW_UNUSED(top), int) |
7201 { | 7230 { |
7202 DWNotebook *notebook = [[[DWNotebook alloc] init] retain]; | 7231 DWNotebook *notebook = [[[DWNotebook alloc] init] retain]; |
7203 [notebook addTarget:notebook | 7232 [[notebook tabs] addTarget:notebook |
7204 action:@selector(pageChanged:) | 7233 action:@selector(pageChanged:) |
7205 forControlEvents:UIControlEventValueChanged]; | 7234 forControlEvents:UIControlEventValueChanged]; |
7206 [notebook setTag:cid]; | 7235 [notebook setTag:cid]; |
7207 DW_FUNCTION_RETURN_THIS(notebook); | 7236 DW_FUNCTION_RETURN_THIS(notebook); |
7208 } | 7237 } |
7209 | 7238 |
7210 /* | 7239 /* |
7219 DW_FUNCTION_RETURN(dw_notebook_page_new, ULONG) | 7248 DW_FUNCTION_RETURN(dw_notebook_page_new, ULONG) |
7220 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, DW_UNUSED(flags), ULONG, front, int) | 7249 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, DW_UNUSED(flags), ULONG, front, int) |
7221 { | 7250 { |
7222 DWNotebook *notebook = handle; | 7251 DWNotebook *notebook = handle; |
7223 NSInteger page = [notebook pageid]; | 7252 NSInteger page = [notebook pageid]; |
7224 DWNotebookPage *notepage = [[DWNotebookPage alloc] init]; | 7253 DWNotebookPage *notepage = [[[DWNotebookPage alloc] init] retain]; |
7225 NSMutableArray<DWNotebookPage *> *views = [notebook views]; | 7254 NSMutableArray<DWNotebookPage *> *views = [notebook views]; |
7226 unsigned long retval; | 7255 unsigned long retval; |
7227 | 7256 |
7228 [notepage setPageid:(int)page]; | 7257 [notepage setPageid:(int)page]; |
7229 if(front) | 7258 if(front) |
7230 { | 7259 { |
7231 [notebook insertSegmentWithTitle:@"" atIndex:(NSInteger)0 animated:NO]; | 7260 [[notebook tabs] insertSegmentWithTitle:@"" atIndex:(NSInteger)0 animated:NO]; |
7232 [views addObject:notepage]; | 7261 [views addObject:notepage]; |
7233 } | 7262 } |
7234 else | 7263 else |
7235 { | 7264 { |
7236 [notebook insertSegmentWithTitle:@"" atIndex:[notebook numberOfSegments] animated:NO]; | 7265 [[notebook tabs] insertSegmentWithTitle:@"" atIndex:[[notebook tabs] numberOfSegments] animated:NO]; |
7237 [views addObject:notepage]; | 7266 [views addObject:notepage]; |
7238 } | 7267 } |
7268 [notebook addSubview:notepage]; | |
7239 [notepage autorelease]; | 7269 [notepage autorelease]; |
7240 [notebook setPageid:(int)(page+1)]; | 7270 [notebook setPageid:(int)(page+1)]; |
7271 | |
7272 #if 0 | |
7273 if([views objectAtIndex:[[notebook tabs] selectedSegmentIndex]] == notepage) | |
7274 { | |
7275 /* If the page we added is the visible page.. lay it out */ | |
7276 [notebook pageChanged:notebook]; | |
7277 } | |
7278 else | |
7279 #endif | |
7280 if([views count] != 1) | |
7281 { | |
7282 /* Otherwise hide the page */ | |
7283 [notepage setHidden:YES]; | |
7284 } | |
7285 | |
7241 retval = (unsigned long)page; | 7286 retval = (unsigned long)page; |
7242 DW_FUNCTION_RETURN_THIS(retval); | 7287 DW_FUNCTION_RETURN_THIS(retval); |
7243 } | 7288 } |
7244 | 7289 |
7245 /* | 7290 /* |
7246 * Remove a page from a notebook. | 7291 * Remove a page from a notebook. |
7247 * Parameters: | 7292 * Parameters: |
7248 * handle: Handle to the notebook widget. | 7293 * handle: Handle to the notebook widget. |
7249 * pageid: ID of the page to be destroyed. | 7294 * pageid: ID of the page to be destroyed. |
7250 */ | 7295 */ |
7251 void API dw_notebook_page_destroy(HWND handle, unsigned int pageid) | 7296 DW_FUNCTION_DEFINITION(dw_notebook_page_destroy, void, HWND handle, unsigned int pageid) |
7297 DW_FUNCTION_ADD_PARAM2(handle, pageid) | |
7298 DW_FUNCTION_NO_RETURN(dw_notebook_page_destroy) | |
7299 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, pageid, unsigned int) | |
7252 { | 7300 { |
7253 DWNotebook *notebook = handle; | 7301 DWNotebook *notebook = handle; |
7254 DWNotebookPage *notepage = _dw_notepage_from_id(notebook, pageid); | 7302 DWNotebookPage *notepage = _dw_notepage_from_id(notebook, pageid); |
7255 DW_LOCAL_POOL_IN; | 7303 DW_LOCAL_POOL_IN; |
7256 | 7304 |
7259 NSMutableArray<DWNotebookPage *> *views = [notebook views]; | 7307 NSMutableArray<DWNotebookPage *> *views = [notebook views]; |
7260 NSUInteger index = [views indexOfObject:notepage]; | 7308 NSUInteger index = [views indexOfObject:notepage]; |
7261 | 7309 |
7262 if(index != NSNotFound) | 7310 if(index != NSNotFound) |
7263 { | 7311 { |
7264 [notebook removeSegmentAtIndex:index animated:NO]; | 7312 [[notebook tabs] removeSegmentAtIndex:index animated:NO]; |
7313 [notepage removeFromSuperview]; | |
7265 [views removeObject:notepage]; | 7314 [views removeObject:notepage]; |
7266 [notepage release]; | 7315 [notepage release]; |
7267 } | 7316 } |
7268 } | 7317 } |
7269 DW_LOCAL_POOL_OUT; | 7318 DW_LOCAL_POOL_OUT; |
7319 DW_FUNCTION_RETURN_NOTHING; | |
7270 } | 7320 } |
7271 | 7321 |
7272 /* | 7322 /* |
7273 * Queries the currently visible page ID. | 7323 * Queries the currently visible page ID. |
7274 * Parameters: | 7324 * Parameters: |
7275 * handle: Handle to the notebook widget. | 7325 * handle: Handle to the notebook widget. |
7276 */ | 7326 */ |
7277 unsigned long API dw_notebook_page_get(HWND handle) | 7327 DW_FUNCTION_DEFINITION(dw_notebook_page_get, unsigned long, HWND handle) |
7328 DW_FUNCTION_ADD_PARAM1(handle) | |
7329 DW_FUNCTION_RETURN(dw_notebook_page_get, unsigned long) | |
7330 DW_FUNCTION_RESTORE_PARAM1(handle, HWND) | |
7278 { | 7331 { |
7279 DWNotebook *notebook = handle; | 7332 DWNotebook *notebook = handle; |
7280 NSInteger index = [notebook selectedSegmentIndex]; | 7333 NSInteger index = [[notebook tabs] selectedSegmentIndex]; |
7281 NSMutableArray<DWNotebookPage *> *views = [notebook views]; | 7334 NSMutableArray<DWNotebookPage *> *views = [notebook views]; |
7282 DWNotebookPage *notepage = [views objectAtIndex:index]; | 7335 DWNotebookPage *notepage = [views objectAtIndex:index]; |
7283 return [notepage pageid]; | 7336 unsigned long retval = [notepage pageid]; |
7337 DW_FUNCTION_RETURN_THIS(retval); | |
7284 } | 7338 } |
7285 | 7339 |
7286 /* | 7340 /* |
7287 * Sets the currently visibale page ID. | 7341 * Sets the currently visibale page ID. |
7288 * Parameters: | 7342 * Parameters: |
7320 DW_FUNCTION_NO_RETURN(dw_notebook_page_set_text) | 7374 DW_FUNCTION_NO_RETURN(dw_notebook_page_set_text) |
7321 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, pageid, ULONG, text, const char *) | 7375 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, pageid, ULONG, text, const char *) |
7322 { | 7376 { |
7323 DWNotebook *notebook = handle; | 7377 DWNotebook *notebook = handle; |
7324 | 7378 |
7325 [notebook setTitle:[NSString stringWithUTF8String:text] forSegmentAtIndex:pageid]; | 7379 [[notebook tabs] setTitle:[NSString stringWithUTF8String:text] forSegmentAtIndex:pageid]; |
7326 DW_FUNCTION_RETURN_NOTHING; | 7380 DW_FUNCTION_RETURN_NOTHING; |
7327 } | 7381 } |
7328 | 7382 |
7329 /* | 7383 /* |
7330 * Sets the text on the specified notebook tab status area. | 7384 * Sets the text on the specified notebook tab status area. |
7343 * Parameters: | 7397 * Parameters: |
7344 * handle: Handle to the notebook to be packed. | 7398 * handle: Handle to the notebook to be packed. |
7345 * pageid: Page ID in the notebook which is being packed. | 7399 * pageid: Page ID in the notebook which is being packed. |
7346 * page: Box handle to be packed. | 7400 * page: Box handle to be packed. |
7347 */ | 7401 */ |
7348 void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page) | 7402 DW_FUNCTION_DEFINITION(dw_notebook_pack, void, HWND handle, ULONG pageid, HWND page) |
7349 { | 7403 DW_FUNCTION_ADD_PARAM3(handle, pageid, page) |
7350 #if 0 /* TODO: Haven't implemented the content yet since UISegmentedControl is just the buttons */ | 7404 DW_FUNCTION_NO_RETURN(dw_notebook_pack) |
7405 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, pageid, ULONG, page, HWND) | |
7406 { | |
7351 DWNotebook *notebook = handle; | 7407 DWNotebook *notebook = handle; |
7352 DWNotebookPage *notepage = _dw_notepage_from_id(notebook, pageid); | 7408 DWNotebookPage *notepage = _dw_notepage_from_id(notebook, pageid); |
7353 | 7409 |
7354 if(notepage != nil) | 7410 if(notepage != nil) |
7355 { | 7411 { |
7356 HWND tmpbox = dw_box_new(DW_VERT, 0); | 7412 dw_box_pack_start(notepage, page, 0, 0, TRUE, TRUE, 0); |
7357 DWBox *box = tmpbox; | 7413 } |
7358 | 7414 DW_FUNCTION_RETURN_NOTHING; |
7359 dw_box_pack_start(tmpbox, page, 0, 0, TRUE, TRUE, 0); | |
7360 [notepage setView:box]; | |
7361 [box autorelease]; | |
7362 } | |
7363 #endif | |
7364 } | 7415 } |
7365 | 7416 |
7366 /* | 7417 /* |
7367 * Create a new Window Frame. | 7418 * Create a new Window Frame. |
7368 * Parameters: | 7419 * Parameters: |