Dmitry Timoshkov : comctl32/listview: Send change notifications when inserting (LVIS_SELECTED|LVIS_FOCUSED) items.

Alexandre Julliard julliard at winehq.org
Tue Feb 22 16:06:49 CST 2022


Module: wine
Branch: master
Commit: 3cd366eee620aca79d1008644525b01165aa84c3
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=3cd366eee620aca79d1008644525b01165aa84c3

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Tue Feb 22 11:06:27 2022 +0300

comctl32/listview: Send change notifications when inserting (LVIS_SELECTED|LVIS_FOCUSED) items.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/comctl32/listview.c       | 22 +++++++++++++---------
 dlls/comctl32/tests/listview.c |  6 +++---
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index cd7fec28e27..d8abd8236eb 100644
--- a/dlls/comctl32/listview.c
+++ b/dlls/comctl32/listview.c
@@ -4200,6 +4200,7 @@ static BOOL set_main_item(LISTVIEW_INFO *infoPtr, const LVITEMW *lpLVItem, BOOL
     LVITEMW item;
     /* stateMask is ignored for LVM_INSERTITEM */
     UINT stateMask = isNew ? ~0 : lpLVItem->stateMask;
+    BOOL send_change_notification;
 
     TRACE("()\n");
 
@@ -4260,11 +4261,16 @@ static BOOL set_main_item(LISTVIEW_INFO *infoPtr, const LVITEMW *lpLVItem, BOOL
     nmlv.uChanged = uChanged ? uChanged : lpLVItem->mask;
     nmlv.lParam = item.lParam;
 
-    /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
+    /* Send change notification if the item is not being inserted, or inserted (selected|focused),
        and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
-       are enabled. Even nothing really changed we still need to send this,
+       are enabled. Even if nothing really changed we still need to send this,
        in this case uChanged mask is just set to passed item mask. */
-    if (lpItem && !isNew && (infoPtr->notify_mask & NOTIFY_MASK_ITEM_CHANGE))
+
+    send_change_notification = !isNew;
+    send_change_notification |= (uChanged & LVIF_STATE) && (lpLVItem->state & (LVIS_FOCUSED | LVIS_SELECTED));
+    send_change_notification &= !!(infoPtr->notify_mask & NOTIFY_MASK_ITEM_CHANGE);
+
+    if (lpItem && send_change_notification)
     {
       HWND hwndSelf = infoPtr->hwndSelf;
 
@@ -4352,13 +4358,11 @@ static BOOL set_main_item(LISTVIEW_INFO *infoPtr, const LVITEMW *lpLVItem, BOOL
 	}
     }
 
-    /* if we're inserting the item, we're done */
-    if (isNew) return TRUE;
-
-    /* send LVN_ITEMCHANGED notification */
-    if (lpLVItem->mask & LVIF_PARAM) nmlv.lParam = lpLVItem->lParam;
-    if (infoPtr->notify_mask & NOTIFY_MASK_ITEM_CHANGE)
+    if (send_change_notification)
+    {
+        if (lpLVItem->mask & LVIF_PARAM) nmlv.lParam = lpLVItem->lParam;
         notify_listview(infoPtr, LVN_ITEMCHANGED, &nmlv);
+    }
 
     return TRUE;
 }
diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c
index 4c2dd534dbd..92e11685331 100644
--- a/dlls/comctl32/tests/listview.c
+++ b/dlls/comctl32/tests/listview.c
@@ -6023,7 +6023,7 @@ static void test_LVM_INSERTITEM(void)
         if ((insert_item[i].mask & LVIF_STATE) && (insert_item[i].state & (LVIS_FOCUSED | LVIS_SELECTED)))
         {
             sprintf(buf, "%d: insert focused", i);
-            ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused0_seq, buf, TRUE);
+            ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused0_seq, buf, insert_item[i].mask != LVIF_STATE);
         }
         else
         {
@@ -6060,7 +6060,7 @@ static void test_insertitem(void)
     item.iSubItem = 0;
     ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
     ok(ret == 0, "got %d\n", ret);
-    ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused0_seq, "insert focused 0", TRUE);
+    ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused0_seq, "insert focused 0", FALSE);
 
     state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
     ok(state == LVIS_FOCUSED, "got %x\n", state);
@@ -6073,7 +6073,7 @@ static void test_insertitem(void)
     item.iSubItem = 0;
     ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
     ok(ret == 1, "got %d\n", ret);
-    ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused1_seq, "insert focused 1", TRUE);
+    ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused1_seq, "insert focused 1", FALSE);
 
     state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
     ok(state == LVIS_FOCUSED, "got %x\n", state);




More information about the wine-cvs mailing list