changeset 2769:06f45ee90e0f

iOS: dw_tree_get_parent() should return NULL for the root node. I missed implementing dw_tree_item_select() so, implmented now. Always return NO to the canEditTreeItem unless we have a delegate that returns YES. This prevents the swipe left to delete happening.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 10 Apr 2022 15:42:18 +0000
parents b17197a2fb28
children f42d78f136b6
files ios/dw.m
diffstat 1 files changed, 27 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ios/dw.m	Sat Apr 09 18:20:56 2022 +0000
+++ b/ios/dw.m	Sun Apr 10 15:42:18 2022 +0000
@@ -3025,8 +3025,7 @@
     DWTreeItem *treeItem = [self treeItemForIndexPath:indexPath];
     if([_treeViewDelegate respondsToSelector:@selector(treeView:canEditTreeItem:)])
         return [_treeViewDelegate treeView:self canEditTreeItem:treeItem];
-    else
-        return (treeItem.isRoot == NO);
+    return NO;
 }
 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
 {
@@ -6663,6 +6662,8 @@
     DWTreeItem *treeitem = item;
     if(treeitem)
         treeparent = treeitem.parent;
+    if(treeparent && [treeparent isRoot])
+        treeparent = NULL;
     DW_FUNCTION_RETURN_THIS(treeparent);
 }
 
@@ -6735,10 +6736,30 @@
  *       handle: Handle to the tree window (widget) to be selected.
  *       item: Handle to the item to be selected.
  */
-void API dw_tree_item_select(HWND handle, HTREEITEM item)
-{
-    /* TODO: Implement tree for iOS if possible */
-}
+DW_FUNCTION_DEFINITION(dw_tree_item_select, void, HWND handle, HTREEITEM item)
+DW_FUNCTION_ADD_PARAM2(handle, item)
+DW_FUNCTION_NO_RETURN(dw_tree_item_select)
+DW_FUNCTION_RESTORE_PARAM2(handle, HWND, item, HTREEITEM)
+{
+    DW_FUNCTION_INIT;
+    DWTree *tree = handle;
+    DWTreeItem *treeitem = item;
+
+    if(tree && treeitem)
+    {
+        NSInteger itemIndex = [tree treeView:tree rowForTreeItem:treeitem];
+        if(itemIndex > -1)
+        {
+            NSIndexPath *ip = [NSIndexPath indexPathForRow:(NSUInteger)itemIndex inSection:0];
+
+            [tree selectRowAtIndexPath:ip
+                              animated:NO
+                        scrollPosition:UITableViewScrollPositionNone];
+        }
+    }
+    DW_FUNCTION_RETURN_NOTHING;
+}
+
 
 /*
  * Removes all nodes from a tree.