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.
This commit is contained in:
Huw Davies 2006-07-17 12:52:48 +01:00 committed by Alexandre Julliard
parent 3d08f5d914
commit f01ae8ace9
2 changed files with 156 additions and 7 deletions

View File

@ -6277,7 +6277,13 @@ static INT LISTVIEW_InsertItemT(LISTVIEW_INFO *infoPtr, const LVITEMW *lpLVItem,
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_SetExtendedListViewStyle(LISTVIEW_INFO *infoPtr, DWORD dwM
{
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);
}

View File

@ -24,10 +24,9 @@
#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();
}