comparison ios/dw.m @ 2463:79c7bf492bc1

iOS: Attempt to get context menus working for iOS 13+. Handle long tap on DWContainer to generate container context event. UIMenu creation seems to be working, but not getting the menu.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 14 Apr 2021 20:53:46 +0000
parents ddc6d49d1110
children 4fba0b9453ee
comparison
equal deleted inserted replaced
2462:596bbc06e134 2463:79c7bf492bc1
632 -(void)doFlush:(id)param; 632 -(void)doFlush:(id)param;
633 -(UIWindow *)hiddenWindow; 633 -(UIWindow *)hiddenWindow;
634 @end 634 @end
635 635
636 API_AVAILABLE(ios(13.0)) 636 API_AVAILABLE(ios(13.0))
637 @interface DWMenu : NSObject
638 {
639 UIMenu *menu;
640 NSMutableArray *children;
641 NSString *title;
642 unsigned long tag;
643 }
644 -(id)initWithTag:(unsigned long)newtag;
645 -(void)setTitle:(NSString *)input;
646 -(UIMenu *)menu;
647 -(unsigned long)tag;
648 -(id)childWithTag:(unsigned long)tag;
649 -(void)addItem:(id)item;
650 -(void)removeItem:(id)item;
651 -(void)dealloc;
652 @end
653
654 API_AVAILABLE(ios(13.0))
637 @interface DWMenuItem : UICommand 655 @interface DWMenuItem : UICommand
638 { 656 {
639 int check; 657 BOOL check, enabled;
640 unsigned long tag; 658 unsigned long tag;
641 } 659 DWMenu *submenu, *menu;
642 -(void)setCheck:(int)input; 660 }
661 -(void)setCheck:(BOOL)input;
662 -(void)setEnabled:(BOOL)input;
643 -(void)setTag:(unsigned long)input; 663 -(void)setTag:(unsigned long)input;
644 -(int)check; 664 -(void)setSubmenu:(DWMenu *)input;
665 -(void)setMenu:(DWMenu *)input;
666 -(DWMenu *)submenu;
667 -(DWMenu *)menu;
668 -(BOOL)check;
669 -(BOOL)enabled;
645 -(unsigned long)tag; 670 -(unsigned long)tag;
646 -(void)dealloc; 671 -(void)dealloc;
647 @end 672 @end
648
649 API_AVAILABLE(ios(13.0))
650 @interface DWMenu : NSObject
651 {
652 UIMenu *menu;
653 }
654 -(void)setMenu:(UIMenu *)input;
655 -(UIMenu *)menu;
656 -(DWMenuItem *)itemWithTag:(unsigned long)tag;
657 -(void)dealloc;
658 @end
659
660 673
661 /* So basically to implement our event handlers... 674 /* So basically to implement our event handlers...
662 * it looks like we are going to have to subclass 675 * it looks like we are going to have to subclass
663 * basically everything. Was hoping to add methods 676 * basically everything. Was hoping to add methods
664 * to the superclasses but it looks like you can 677 * to the superclasses but it looks like you can
759 -(void)layoutSubviews { }; 772 -(void)layoutSubviews { };
760 @end 773 @end
761 774
762 @interface DWWindow : UIWindow 775 @interface DWWindow : UIWindow
763 { 776 {
777 UIMenu *popupmenu;
764 int redraw; 778 int redraw;
765 int shown; 779 int shown;
766 } 780 }
767 -(void)sendEvent:(UIEvent *)theEvent; 781 -(void)sendEvent:(UIEvent *)theEvent;
768 -(void)keyDown:(UIEvent *)theEvent; 782 -(void)keyDown:(UIEvent *)theEvent;
770 -(int)redraw; 784 -(int)redraw;
771 -(void)setRedraw:(int)val; 785 -(void)setRedraw:(int)val;
772 -(int)shown; 786 -(int)shown;
773 -(void)setShown:(int)val; 787 -(void)setShown:(int)val;
774 -(void)layoutSubviews; 788 -(void)layoutSubviews;
789 -(UIMenu *)popupMenu;
790 -(void)setPopupMenu:(UIMenu *)input;
775 @end 791 @end
776 792
777 @implementation DWWindow 793 @implementation DWWindow
778 -(void)sendEvent:(UIEvent *)theEvent 794 -(void)sendEvent:(UIEvent *)theEvent
779 { 795 {
791 -(void)setRedraw:(int)val { redraw = val; } 807 -(void)setRedraw:(int)val { redraw = val; }
792 -(int)shown { return shown; } 808 -(int)shown { return shown; }
793 -(void)setShown:(int)val { shown = val; } 809 -(void)setShown:(int)val { shown = val; }
794 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; } 810 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; }
795 -(void)layoutSubviews { } 811 -(void)layoutSubviews { }
812 -(UIMenu *)popupMenu { return popupmenu; }
813 -(void)setPopupMenu:(UIMenu *)input { [popupmenu release]; popupmenu = input; [popupmenu retain]; }
796 @end 814 @end
797 815
798 @interface DWImage : NSObject 816 @interface DWImage : NSObject
799 { 817 {
800 UIImage *image; 818 UIImage *image;
1325 @end 1343 @end
1326 1344
1327 /* Subclass for a top-level window */ 1345 /* Subclass for a top-level window */
1328 @interface DWView : DWBox /* <UIWindowDelegate> */ 1346 @interface DWView : DWBox /* <UIWindowDelegate> */
1329 { 1347 {
1330 DWMenu *windowmenu; 1348 DWMenu *windowmenu, *popupmenu;
1331 CGSize oldsize; 1349 CGSize oldsize;
1332 } 1350 }
1333 -(BOOL)windowShouldClose:(id)sender; 1351 -(BOOL)windowShouldClose:(id)sender;
1334 -(void)setMenu:(DWMenu *)input; 1352 -(void)setMenu:(DWMenu *)input;
1353 -(void)setPopupMenu:(DWMenu *)input;
1354 -(DWMenu *)menu;
1355 -(DWMenu *)popupMenu;
1335 -(void)windowDidBecomeMain:(id)sender; 1356 -(void)windowDidBecomeMain:(id)sender;
1336 -(void)menuHandler:(id)sender; 1357 -(void)menuHandler:(id)sender;
1337 @end 1358 @end
1338 1359
1339 @implementation DWView 1360 @implementation DWView
1383 -(void)windowDidBecomeMain:(id)sender 1404 -(void)windowDidBecomeMain:(id)sender
1384 { 1405 {
1385 _dw_event_handler([self window], nil, 13); 1406 _dw_event_handler([self window], nil, 13);
1386 } 1407 }
1387 -(void)setMenu:(DWMenu *)input { windowmenu = input; [windowmenu retain]; } 1408 -(void)setMenu:(DWMenu *)input { windowmenu = input; [windowmenu retain]; }
1409 -(void)setPopupMenu:(DWMenu *)input { popupmenu = input; [popupmenu retain]; }
1410 -(DWMenu *)menu { return windowmenu; }
1411 -(DWMenu *)popupMenu { return popupmenu; }
1388 -(void)menuHandler:(id)sender 1412 -(void)menuHandler:(id)sender
1389 { 1413 {
1390 [DWObj menuHandler:sender]; 1414 [DWObj menuHandler:sender];
1391 } 1415 }
1392 @end 1416 @end
1540 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1564 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1541 @end 1565 @end
1542 1566
1543 /* Subclass for a menu item type */ 1567 /* Subclass for a menu item type */
1544 @implementation DWMenuItem 1568 @implementation DWMenuItem
1545 -(void)setCheck:(int)input { check = input; } 1569 -(void)setCheck:(BOOL)input { check = input; }
1570 -(void)setEnabled:(BOOL)input { enabled = input; }
1571 -(void)setSubmenu:(DWMenu *)input { submenu = input; }
1572 -(void)setMenu:(DWMenu *)input { menu = input; }
1546 -(void)setTag:(unsigned long)input { tag = input; } 1573 -(void)setTag:(unsigned long)input { tag = input; }
1547 -(int)check { return check; } 1574 -(BOOL)check { return check; }
1575 -(BOOL)enabled { return enabled; }
1576 -(DWMenu *)submenu { return submenu; }
1577 -(DWMenu *)menu { return menu; }
1548 -(unsigned long)tag { return tag; } 1578 -(unsigned long)tag { return tag; }
1549 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; } 1579 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; }
1550 @end 1580 @end
1551 /* 1581 /*
1552 * Encapsulate immutable objects in our own containers, 1582 * Encapsulate immutable objects in our own containers,
1553 * so we can recreate the immutable subobjects as needed. 1583 * so we can recreate the immutable subobjects as needed.
1554 * Currently in this category: DWMenu and DWImage 1584 * Currently in this category: DWMenu and DWImage
1555 */ 1585 */
1556 @implementation DWMenu 1586 @implementation DWMenu
1557 -(void)setMenu:(UIMenu *)input { menu = input; } 1587 -(id)initWithTag:(unsigned long)newtag
1558 -(UIMenu *)menu { return menu; } 1588 {
1559 -(DWMenuItem *)itemWithTag:(unsigned long)tag 1589 self = [super init];
1560 { 1590 if(self)
1561 NSArray *children = [menu children]; 1591 {
1562 1592 children = [[NSMutableArray alloc] init];
1563 for(DWMenuItem *menuitem in children) 1593 tag = newtag;
1564 { 1594 }
1565 if([menuitem tag] == tag) 1595 return self;
1566 return menuitem; 1596 }
1597 -(void)setTitle:(NSString *)input { title = input; [title retain]; }
1598 -(UIMenu *)menu
1599 {
1600 /* Create or recreate the UIMenu recursively */
1601 UIMenu *oldmenu = menu;
1602 NSMutableArray *menuchildren = [[NSMutableArray alloc] init];
1603
1604 for(id child in children)
1605 {
1606 if([child isMemberOfClass:[DWMenuItem class]])
1607 {
1608 DWMenuItem *menuitem = child;
1609 DWMenu *submenu = [menuitem submenu];
1610
1611 if(submenu)
1612 [menuchildren addObject:[submenu menu]];
1613 else
1614 [menuchildren addObject:child];
1615 }
1616 }
1617 if(title)
1618 menu = [UIMenu menuWithTitle:title children:menuchildren];
1619 else
1620 {
1621 if(@available(iOS 14.0, *))
1622 menu = [UIMenu menuWithChildren:menuchildren];
1623 else
1624 menu = [UIMenu menuWithTitle:@"" children:menuchildren];
1625 }
1626 if(oldmenu)
1627 [oldmenu release];
1628 return menu;
1629 }
1630 -(void)addItem:(id)item
1631 {
1632 [children addObject:item];
1633 }
1634 -(void)removeItem:(id)item
1635 {
1636 [children removeObject:item];
1637 }
1638 -(unsigned long)tag { return tag; }
1639 -(id)childWithTag:(unsigned long)tag
1640 {
1641 if(tag > 0)
1642 {
1643 for(id child in children)
1644 {
1645 if([child isMemberOfClass:[DWMenuItem class]] && [child tag] == tag)
1646 return child;
1647 }
1567 } 1648 }
1568 return nil; 1649 return nil;
1569 } 1650 }
1570 -(void)dealloc { [super dealloc]; } 1651 -(void)dealloc { [super dealloc]; }
1571 @end 1652 @end
1943 int filesystem; 2024 int filesystem;
1944 } 2025 }
1945 -(NSInteger)tableView:(UITableView *)aTable numberOfRowsInSection:(NSInteger)section; 2026 -(NSInteger)tableView:(UITableView *)aTable numberOfRowsInSection:(NSInteger)section;
1946 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 2027 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
1947 -(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath; 2028 -(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath;
2029 -(UIContextMenuConfiguration *)tableView:(UITableView *)tableView contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point;
1948 -(void)addColumn:(NSString *)input andType:(int)type; 2030 -(void)addColumn:(NSString *)input andType:(int)type;
1949 -(NSString *)getColumn:(int)col; 2031 -(NSString *)getColumn:(int)col;
1950 -(void *)userdata; 2032 -(void *)userdata;
1951 -(void)setUserdata:(void *)input; 2033 -(void)setUserdata:(void *)input;
1952 -(void)setFilesystem:(int)input; 2034 -(void)setFilesystem:(int)input;
1964 -(void)setLastQueryPoint:(int)input; 2046 -(void)setLastQueryPoint:(int)input;
1965 -(void)clear; 2047 -(void)clear;
1966 -(void)setup; 2048 -(void)setup;
1967 -(CGSize)getsize; 2049 -(CGSize)getsize;
1968 -(void)setForegroundColor:(UIColor *)input; 2050 -(void)setForegroundColor:(UIColor *)input;
1969 -(DWMenu *)menuForEvent:(UIEvent *)event;
1970 @end 2051 @end
1971 2052
1972 @implementation DWContainer 2053 @implementation DWContainer
1973 -(NSInteger)tableView:(UITableView *)aTable numberOfRowsInSection:(NSInteger)section 2054 -(NSInteger)tableView:(UITableView *)aTable numberOfRowsInSection:(NSInteger)section
1974 { 2055 {
2014 else 2095 else
2015 { 2096 {
2016 if(oddcolor) 2097 if(oddcolor)
2017 [cell setBackgroundColor:oddcolor]; 2098 [cell setBackgroundColor:oddcolor];
2018 } 2099 }
2100 }
2101 -(UIContextMenuConfiguration *)tableView:(UITableView *)tableView contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point
2102 {
2103 DWWindow *window = (DWWindow *)[self window];
2104 UIContextMenuConfiguration *config = nil;
2105
2106 _dw_event_handler(self, (UIEvent *)[self getRowTitle:(int)indexPath.row], 10);
2107
2108 if(window)
2109 {
2110 __block UIMenu *popupmenu = [window popupMenu];
2111 config = [UIContextMenuConfiguration configurationWithIdentifier:@"DWContextMenu"
2112 previewProvider:nil
2113 actionProvider:^(NSArray* suggestedAction){return popupmenu;}];
2114 }
2115 return config;
2019 } 2116 }
2020 -(void)addColumn:(NSString *)input andType:(int)type { if(tvcols) { [tvcols addObject:input]; [types addObject:[NSNumber numberWithInt:type]]; } } 2117 -(void)addColumn:(NSString *)input andType:(int)type { if(tvcols) { [tvcols addObject:input]; [types addObject:[NSNumber numberWithInt:type]]; } }
2021 -(NSString *)getColumn:(int)col { if(tvcols) { return [tvcols objectAtIndex:col]; } return nil; } 2118 -(NSString *)getColumn:(int)col { if(tvcols) { return [tvcols objectAtIndex:col]; } return nil; }
2022 -(void *)userdata { return userdata; } 2119 -(void *)userdata { return userdata; }
2023 -(void)setUserdata:(void *)input { userdata = input; } 2120 -(void)setUserdata:(void *)input { userdata = input; }
2284 } 2381 }
2285 -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath 2382 -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
2286 { 2383 {
2287 if([self allowsMultipleSelection]) 2384 if([self allowsMultipleSelection])
2288 [self tableView:tableView didSelectRowAtIndexPath:indexPath]; 2385 [self tableView:tableView didSelectRowAtIndexPath:indexPath];
2289 }
2290 -(DWMenu *)menuForEvent:(UIEvent *)event
2291 {
2292 #if 0 /* TODO: Fix this */
2293 int row;
2294 CGPoint where = [self convertPoint:[event locationInWindow] fromView:nil];
2295 row = (int)[self rowAtPoint:where];
2296 _dw_event_handler(self, (UIEvent *)[self getRowTitle:row], 10);
2297 #endif
2298 return nil;
2299 } 2386 }
2300 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 2387 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2301 @end 2388 @end
2302 2389
2303 /* Subclass for a Calendar type */ 2390 /* Subclass for a Calendar type */
7402 * id: An ID to be used for getting the resource from the 7489 * id: An ID to be used for getting the resource from the
7403 * resource file. 7490 * resource file.
7404 */ 7491 */
7405 HMENUI API dw_menu_new(ULONG cid) 7492 HMENUI API dw_menu_new(ULONG cid)
7406 { 7493 {
7407 DWMenu *menu = [[[DWMenu alloc] init] retain]; 7494 DWMenu *menu = [[[DWMenu alloc] initWithTag:cid] retain];
7408 /* [menu setTag:cid]; Why doesn't this work? */
7409 return menu; 7495 return menu;
7410 } 7496 }
7411 7497
7412 /* 7498 /*
7413 * Create a menubar on a window. 7499 * Create a menubar on a window.
7441 * x: X coordinate. 7527 * x: X coordinate.
7442 * y: Y coordinate. 7528 * y: Y coordinate.
7443 */ 7529 */
7444 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) 7530 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y)
7445 { 7531 {
7446 #if 0 /* TODO: Figure out how to do this */
7447 DWMenu *thismenu = (DWMenu *)*menu; 7532 DWMenu *thismenu = (DWMenu *)*menu;
7448 id object = parent; 7533 id object = parent;
7449 UIView *view = [object isKindOfClass:[UIWindow class]] ? [object contentView] : parent; 7534 DWWindow *window = [object isMemberOfClass:[DWWindow class]] ? object : (DWWindow *)[object window];
7450 UIWindow *window = [view window];
7451 [thismenu autorelease]; 7535 [thismenu autorelease];
7452 CGPoint p = CGPointMake(x, y); 7536 [window setPopupMenu:[thismenu menu]];
7453 [UIContextMenuInteraction a 7537 *menu = nil;
7454 #endif
7455 } 7538 }
7456 7539
7457 char _dw_removetilde(char *dest, const char *src) 7540 char _dw_removetilde(char *dest, const char *src)
7458 { 7541 {
7459 int z, cur=0; 7542 int z, cur=0;
7488 * submenu: Handle to an existing menu to be a submenu or NULL. 7571 * submenu: Handle to an existing menu to be a submenu or NULL.
7489 */ 7572 */
7490 HWND API dw_menu_append_item(HMENUI menux, const char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux) 7573 HWND API dw_menu_append_item(HMENUI menux, const char *title, ULONG itemid, ULONG flags, int end, int check, HMENUI submenux)
7491 { 7574 {
7492 DWMenu *menu = menux; 7575 DWMenu *menu = menux;
7493 DWMenuItem *item = NULL; 7576 DWMenuItem *item = nil;
7494 if(strlen(title) == 0) 7577 if(!title || strlen(title) == 0)
7495 { 7578 [menu addItem:[[NSNull alloc] init]];
7496 #if 0 /* TODO: Not sure if separators exist in iOS */
7497 [menu addItem:[DWMenuItem separatorItem]];
7498 #endif
7499 }
7500 else 7579 else
7501 { 7580 {
7502 char accel[2]; 7581 char accel[2];
7503 char *newtitle = malloc(strlen(title)+1); 7582 char *newtitle = malloc(strlen(title)+1);
7504 NSString *nstr; 7583 NSString *nstr;
7505 UIMenu *newmenu, *oldmenu = [menu menu];
7506 NSArray *newchildren, *oldchildren = [oldmenu children];
7507 7584
7508 accel[0] = _dw_removetilde(newtitle, title); 7585 accel[0] = _dw_removetilde(newtitle, title);
7509 accel[1] = 0; 7586 accel[1] = 0;
7510 7587
7511 nstr = [ NSString stringWithUTF8String:newtitle ]; 7588 nstr = [NSString stringWithUTF8String:newtitle];
7512 free(newtitle); 7589 free(newtitle);
7513 7590
7514 item = [[DWMenuItem commandWithTitle:nstr image:nil 7591 item = [[DWMenuItem commandWithTitle:nstr image:nil
7515 action:@selector(menuHandler:) 7592 action:@selector(menuHandler:)
7516 propertyList:nil] autorelease]; 7593 propertyList:nil] autorelease];
7517 newchildren = [oldchildren arrayByAddingObjectsFromArray:@[item]]; 7594 [item setTag:itemid];
7518 if(oldmenu) 7595 [menu addItem:item];
7519 {
7520 newmenu = [oldmenu menuByReplacingChildren:newchildren];
7521 [oldmenu release];
7522 }
7523 else if(@available(iOS 14.0, *))
7524 newmenu = [UIMenu menuWithChildren:newchildren];
7525 else
7526 newmenu = [UIMenu menuWithTitle:@"" children:newchildren];
7527 [menu setMenu:newmenu];
7528 7596
7529 [item setTag:itemid];
7530 if(check) 7597 if(check)
7531 { 7598 {
7532 [item setCheck:YES]; 7599 [item setCheck:YES];
7533 if(flags & DW_MIS_CHECKED) 7600 if(flags & DW_MIS_CHECKED)
7534 {
7535 [item setState:UIMenuElementStateOn]; 7601 [item setState:UIMenuElementStateOn];
7536 } 7602 }
7537 }
7538 #if 0 /* TODO: Disabled items not supported on iOS */
7539 if(flags & DW_MIS_DISABLED) 7603 if(flags & DW_MIS_DISABLED)
7540 {
7541 [item setEnabled:NO]; 7604 [item setEnabled:NO];
7542 } 7605
7543 #endif
7544
7545 #if 0 /* TODO: iOS may not support submenus... but may be able to cascade... with defered menus */
7546 if(submenux) 7606 if(submenux)
7547 { 7607 {
7548 DWMenu *submenu = submenux; 7608 DWMenu *submenu = submenux;
7549 7609
7550 [submenu setTitle:nstr]; 7610 [submenu setTitle:nstr];
7551 [menu setSubmenu:submenu forItem:item]; 7611 [item setSubmenu:submenu];
7552 } 7612 }
7553 #endif
7554 return item; 7613 return item;
7555 } 7614 }
7556 return item; 7615 return item;
7557 } 7616 }
7558 7617
7565 * check: TRUE for checked FALSE for not checked. 7624 * check: TRUE for checked FALSE for not checked.
7566 */ 7625 */
7567 void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check) 7626 void API dw_menu_item_set_check(HMENUI menux, unsigned long itemid, int check)
7568 { 7627 {
7569 id menu = menux; 7628 id menu = menux;
7570 DWMenuItem *menuitem = [menu itemWithTag:itemid]; 7629 DWMenuItem *menuitem = [menu childWithTag:itemid];
7571 7630
7572 if(menuitem != nil) 7631 if(menuitem != nil)
7573 { 7632 {
7574 if(check) 7633 if(check)
7575 {
7576 [menuitem setState:UIMenuElementStateOn]; 7634 [menuitem setState:UIMenuElementStateOn];
7577 }
7578 else 7635 else
7579 {
7580 [menuitem setState:UIMenuElementStateOff]; 7636 [menuitem setState:UIMenuElementStateOff];
7581 }
7582 } 7637 }
7583 } 7638 }
7584 7639
7585 /* 7640 /*
7586 * Deletes the menu item specified. 7641 * Deletes the menu item specified.
7590 * Returns: 7645 * Returns:
7591 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure. 7646 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure.
7592 */ 7647 */
7593 int API dw_menu_delete_item(HMENUI menux, unsigned long itemid) 7648 int API dw_menu_delete_item(HMENUI menux, unsigned long itemid)
7594 { 7649 {
7595 #if 0 /* TODO: Remove item from the children array */
7596 id menu = menux; 7650 id menu = menux;
7597 DWMenuItem *menuitem = [menu itemWithTag:itemid]; 7651 DWMenuItem *menuitem = [menu childWithTag:itemid];
7598 7652
7599 if(menuitem != nil) 7653 if(menuitem != nil)
7600 { 7654 {
7601 [menu removeItem:menuitem]; 7655 [menu removeItem:menuitem];
7602 return DW_ERROR_NONE; 7656 return DW_ERROR_NONE;
7603 } 7657 }
7604 #endif
7605 return DW_ERROR_UNKNOWN; 7658 return DW_ERROR_UNKNOWN;
7606 } 7659 }
7607 7660
7608 /* 7661 /*
7609 * Sets the state of a menu item. 7662 * Sets the state of a menu item.
7614 * DW_MIS_CHECKED/DW_MIS_UNCHECKED 7667 * DW_MIS_CHECKED/DW_MIS_UNCHECKED
7615 */ 7668 */
7616 void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state) 7669 void API dw_menu_item_set_state(HMENUI menux, unsigned long itemid, unsigned long state)
7617 { 7670 {
7618 id menu = menux; 7671 id menu = menux;
7619 DWMenuItem *menuitem = [menu itemWithTag:itemid]; 7672 DWMenuItem *menuitem = [menu childWithTag:itemid];
7620 7673
7621 if(menuitem != nil) 7674 if(menuitem != nil)
7622 { 7675 {
7623 if(state & DW_MIS_CHECKED) 7676 if(state & DW_MIS_CHECKED)
7624 { 7677 {
8332 { 8385 {
8333 DWWindow *window = handle; 8386 DWWindow *window = handle;
8334 [window release]; 8387 [window release];
8335 } 8388 }
8336 /* Handle removing menu items from menus */ 8389 /* Handle removing menu items from menus */
8337 #if 0 /* TODO: The menus are technically immutable, so we'd need to recreate it...*/ 8390 else if([object isMemberOfClass:[DWMenuItem class]])
8338 else if([ object isKindOfClass:[UIMenuItem class]]) 8391 {
8339 { 8392 DWMenuItem *item = object;
8340 DWMenu *menu = [object menu]; 8393 DWMenu *menu = [item menu];
8341 8394
8342 [menu removeItem:object]; 8395 [menu removeItem:object];
8343 } 8396 }
8344 #endif
8345 /* Handle destroying a control or box */ 8397 /* Handle destroying a control or box */
8346 else if([object isKindOfClass:[UIView class]] || [object isKindOfClass:[UIControl class]]) 8398 else if([object isKindOfClass:[UIView class]] || [object isKindOfClass:[UIControl class]])
8347 { 8399 {
8348 DWBox *parent = (DWBox *)[object superview]; 8400 DWBox *parent = (DWBox *)[object superview];
8349 8401