Huw Davies : comctl32: All items should be marked as unchecked when LVS_EX_CHECKBOXES is initially set .

Alexandre Julliard julliard at wine.codeweavers.com
Tue Jul 18 05:13:20 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: f01ae8ace9450866b628ab4b7a485a9d38c8f371
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=f01ae8ace9450866b628ab4b7a485a9d38c8f371

Author: Huw Davies <huw at codeweavers.com>
Date:   Mon Jul 17 12:52:48 2006 +0100

comctl32: All items should be marked as unchecked when LVS_EX_CHECKBOXES is initially set.

When a new item is added with LBS_EX_CHECKBOXES already set then that item is marked as unchecked.

---

 dlls/comctl32/listview.c       |   16 ++++
 dlls/comctl32/tests/listview.c |  147 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 156 insertions(+), 7 deletions(-)

diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index 4d3819d..239a4cd 100644
--- a/dlls/comctl32/listview.c
+++ b/dlls/comctl32/listview.c
@@ -6277,7 +6277,13 @@ static INT LISTVIEW_InsertItemT(LISTVIEW
         memcpy(&item, lpLVItem, offsetof( LVITEMW, iIndent ));
     }
     item.iItem = nItem;
-    if (infoPtr->dwLvExStyle & LVS_EX_CHECKBOXES) item.state &= ~LVIS_STATEIMAGEMASK;
+    if (infoPtr->dwLvExStyle & LVS_EX_CHECKBOXES)
+    {
+        item.mask |= LVIF_STATE;
+        item.stateMask |= LVIS_STATEIMAGEMASK;
+        item.state &= ~LVIS_STATEIMAGEMASK;
+        item.state |= INDEXTOSTATEIMAGEMASK(1);
+    }
     if (!set_main_item(infoPtr, &item, TRUE, isW, &has_changed)) goto undo;
 
     /* if we're sorted, sort the list, and update the index */
@@ -6875,7 +6881,15 @@ static DWORD LISTVIEW_SetExtendedListVie
     {
         HIMAGELIST himl = 0;
         if(infoPtr->dwLvExStyle & LVS_EX_CHECKBOXES)
+        {
+            LVITEMW item;
+            item.mask = LVIF_STATE;
+            item.stateMask = LVIS_STATEIMAGEMASK;
+            item.state = INDEXTOSTATEIMAGEMASK(1);
+            LISTVIEW_SetItemState(infoPtr, -1, &item);
+
             himl = LISTVIEW_CreateCheckBoxIL(infoPtr);
+        }
         LISTVIEW_SetImageList(infoPtr, LVSIL_STATE, himl);
     }
     
diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c
index b6c00e9..df747b6 100644
--- a/dlls/comctl32/tests/listview.c
+++ b/dlls/comctl32/tests/listview.c
@@ -24,10 +24,9 @@ #include <commctrl.h>
 
 #include "wine/test.h"
 
-START_TEST(listview)
+static void test_images(void)
 {
     HWND hwnd, hwndparent = 0;
-    INITCOMMONCONTROLSEX icc;
     DWORD r;
     LVITEM item;
     HIMAGELIST himl;
@@ -35,10 +34,6 @@ START_TEST(listview)
     RECT r1, r2;
     static CHAR hello[] = "hello";
 
-    icc.dwICC = 0;
-    icc.dwSize = sizeof icc;
-    InitCommonControlsEx(&icc);
-
     himl = ImageList_Create(40, 40, 0, 4, 4);
     ok(himl != NULL, "failed to create imagelist\n");
 
@@ -96,3 +91,143 @@ START_TEST(listview)
 
     DestroyWindow(hwnd);
 }
+
+static void test_checkboxes(void)
+{
+    HWND hwnd, hwndparent = 0;
+    LVITEMA item;
+    DWORD r;
+
+    hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT, 
+                10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
+    ok(hwnd != NULL, "failed to create listview window\n");
+
+    /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
+    item.mask = LVIF_TEXT | LVIF_STATE;
+    item.stateMask = 0xffff;
+    item.state = 0xfccc;
+    item.iItem = 0;
+    item.iSubItem = 0;
+    item.pszText = "Text";
+    r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
+    ok(r == 0, "ret %ld\n", r);
+
+    item.iItem = 0;
+    item.mask = LVIF_STATE;
+    item.stateMask = 0xffff;
+    r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
+    ok(item.state == 0xfccc, "state %x\n", item.state);
+
+    /* Don't set LVIF_STATE */
+    item.mask = LVIF_TEXT;
+    item.stateMask = 0xffff;
+    item.state = 0xfccc;
+    item.iItem = 1;
+    item.iSubItem = 0;
+    item.pszText = "Text";
+    r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
+    ok(r == 1, "ret %ld\n", r);
+
+    item.iItem = 1;
+    item.mask = LVIF_STATE;
+    item.stateMask = 0xffff;
+    r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
+    ok(item.state == 0, "state %x\n", item.state);
+
+    r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
+    ok(r == 0, "should return zero\n");
+    
+    /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
+    item.iItem = 0;
+    item.mask = LVIF_STATE;
+    item.stateMask = 0xffff;
+    r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
+    ok(item.state == 0x1ccc, "state %x\n", item.state);
+
+    /* Now add an item without specifying a state and check that it's state goes to 0x1000 */
+    item.iItem = 2;
+    item.mask = LVIF_TEXT;
+    item.state = 0;
+    item.pszText = "Text2";
+    r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
+    ok(r == 2, "ret %ld\n", r);
+
+    item.iItem = 2;
+    item.mask = LVIF_STATE;
+    item.stateMask = 0xffff;
+    r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
+    ok(item.state == 0x1000, "state %x\n", item.state);
+
+    /* Add a further item this time specifying a state and still it's state goes to 0x1000 */
+    item.iItem = 3;
+    item.mask = LVIF_TEXT | LVIF_STATE;
+    item.stateMask = 0xffff;
+    item.state = 0x2aaa;
+    item.pszText = "Text3";
+    r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
+    ok(r == 3, "ret %ld\n", r);
+
+    item.iItem = 3;
+    item.mask = LVIF_STATE;
+    item.stateMask = 0xffff;
+    r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
+    ok(item.state == 0x1aaa, "state %x\n", item.state);
+
+    /* Set an item's state to checked */
+    item.iItem = 3;
+    item.mask = LVIF_STATE;
+    item.stateMask = 0xf000;
+    item.state = 0x2000;
+    r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
+
+    item.iItem = 3;
+    item.mask = LVIF_STATE;
+    item.stateMask = 0xffff;
+    r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
+    ok(item.state == 0x2aaa, "state %x\n", item.state);
+
+    /* Set the style again and check that doesn't change an item's state */
+    r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
+    ok(r == LVS_EX_CHECKBOXES, "ret %lx\n", r);
+   
+    item.iItem = 3;
+    item.mask = LVIF_STATE;
+    item.stateMask = 0xffff;
+    r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
+    ok(item.state == 0x2aaa, "state %x\n", item.state);
+
+    /* Unsetting the checkbox extended style doesn't change an item's state */
+    r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
+    ok(r == LVS_EX_CHECKBOXES, "ret %lx\n", r);
+
+    item.iItem = 3;
+    item.mask = LVIF_STATE;
+    item.stateMask = 0xffff;
+    r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
+    ok(item.state == 0x2aaa, "state %x\n", item.state);
+
+    /* Now setting the style again will change an item's state */
+    r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
+    ok(r == 0, "ret %lx\n", r);
+   
+    item.iItem = 3;
+    item.mask = LVIF_STATE;
+    item.stateMask = 0xffff;
+    r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
+    ok(item.state == 0x1aaa, "state %x\n", item.state);
+
+
+    DestroyWindow(hwnd);
+}
+
+START_TEST(listview)
+{
+    INITCOMMONCONTROLSEX icc;
+
+    icc.dwICC = 0;
+    icc.dwSize = sizeof icc;
+    InitCommonControlsEx(&icc);
+
+    test_images();
+    test_checkboxes();
+}




More information about the wine-cvs mailing list