[PATCH 2/4] comctl32: Close previously selected treeview item at common ancestor.

Alex Henrie alexhenrie24 at gmail.com
Mon May 18 00:36:25 CDT 2015


Also, send WM_NOTIFY mesages when collapsing the previous selection and
expanding the new one.

Fixes https://bugs.winehq.org/show_bug.cgi?id=37761 and related
problems.
---
 dlls/comctl32/tests/treeview.c | 14 +++++---------
 dlls/comctl32/treeview.c       | 38 +++++++++++---------------------------
 2 files changed, 16 insertions(+), 36 deletions(-)

diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c
index 72d4c2a..d03b126 100644
--- a/dlls/comctl32/tests/treeview.c
+++ b/dlls/comctl32/tests/treeview.c
@@ -1767,9 +1767,9 @@ static void test_TVS_SINGLEEXPAND(void)
     {
         { &alpha,    parent_singleexpand_seq0,  FALSE },
         { &bravo,    parent_singleexpand_seq1,  FALSE },
-        { &delta,    parent_singleexpand_seq2,  TRUE },
-        { &foxtrot,  parent_singleexpand_seq3,  TRUE },
-        { &alpha,    parent_singleexpand_seq4,  TRUE },
+        { &delta,    parent_singleexpand_seq2,  FALSE },
+        { &foxtrot,  parent_singleexpand_seq3,  FALSE },
+        { &alpha,    parent_singleexpand_seq4,  FALSE },
         { &golf,     parent_singleexpand_seq5,  TRUE },
         { &hotel,    parent_singleexpand_seq6,  FALSE },
         { &india,    parent_singleexpand_seq7,  FALSE },
@@ -1801,12 +1801,8 @@ static void test_TVS_SINGLEEXPAND(void)
     for (i = 0; i < sizeof(items)/sizeof(items[0]); i++)
     {
         ret = SendMessageA(hTree, TVM_GETITEMSTATE, (WPARAM)(*items[i].handle), 0xFFFF);
-        if (i == 0)
-            todo_wine ok(ret == items[i].final_state, "singleexpand items[%d]: expected state 0x%x got 0x%x\n",
-                         i, items[i].final_state, ret);
-        else
-            ok(ret == items[i].final_state, "singleexpand items[%d]: expected state 0x%x got 0x%x\n",
-               i, items[i].final_state, ret);
+        ok(ret == items[i].final_state, "singleexpand items[%d]: expected state 0x%x got 0x%x\n",
+           i, items[i].final_state, ret);
     }
 
     /* a workaround for NT4 that sends expand notifications when nothing is about to expand */
diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c
index f13090f..dcb1bf7 100644
--- a/dlls/comctl32/treeview.c
+++ b/dlls/comctl32/treeview.c
@@ -29,7 +29,7 @@
  *
  * TODO:
  *   missing notifications: TVN_GETINFOTIP, TVN_KEYDOWN,
- *      TVN_SETDISPINFO, TVN_SINGLEEXPAND
+ *      TVN_SETDISPINFO
  *
  *   missing styles: TVS_FULLROWSELECT, TVS_INFOTIP, TVS_RTLREADING,
  *
@@ -3508,47 +3508,31 @@ TREEVIEW_Expand(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item,
 static void TREEVIEW_SingleExpand(TREEVIEW_INFO *infoPtr,
     HTREEITEM selection, HTREEITEM item)
 {
-    TREEVIEW_ITEM *SelItem;
+    TREEVIEW_ITEM *prev, *curr;
 
     if ((infoPtr->dwStyle & TVS_SINGLEEXPAND) == 0 || infoPtr->hwndEdit || !item) return;
 
     TREEVIEW_SendTreeviewNotify(infoPtr, TVN_SINGLEEXPAND, TVC_UNKNOWN, TVIF_HANDLE | TVIF_PARAM, item, 0);
 
     /*
-     * Close the previous selection all the way to the root
-     * as long as the new selection is not a child
+     * Close the previous item and its ancestors as long as they are not
+     * ancestors of the current item
      */
-    if(selection && (selection != item))
+    for (prev = selection; prev && TREEVIEW_ValidItem(infoPtr, prev); prev = prev->parent)
     {
-        BOOL closeit = TRUE;
-        SelItem = item;
-
-        /* determine if the hitItem is a child of the currently selected item */
-        while(closeit && SelItem && TREEVIEW_ValidItem(infoPtr, SelItem) &&
-              (SelItem->parent != infoPtr->root))
-        {
-            closeit = (SelItem != selection);
-            SelItem = SelItem->parent;
-        }
-
-        if(closeit)
+        for (curr = item; curr && TREEVIEW_ValidItem(infoPtr, curr); curr = curr->parent)
         {
-            if(TREEVIEW_ValidItem(infoPtr, selection))
-                SelItem = selection;
-
-            while(SelItem && (SelItem != item) && TREEVIEW_ValidItem(infoPtr, SelItem) &&
-                  SelItem->parent != infoPtr->root)
-            {
-                TREEVIEW_Collapse(infoPtr, SelItem, FALSE, FALSE);
-                SelItem = SelItem->parent;
-            }
+            if (curr == prev)
+                goto finish;
         }
+        TREEVIEW_Collapse(infoPtr, prev, FALSE, TRUE);
     }
 
+finish:
     /*
      * Expand the current item
      */
-    TREEVIEW_Expand(infoPtr, item, FALSE, FALSE);
+    TREEVIEW_Expand(infoPtr, item, FALSE, TRUE);
 }
 
 static BOOL
-- 
2.4.1




More information about the wine-patches mailing list