[PATCH] Fixed listview bug, when client sends bogus SETITEMSTATE request, requesting all items to be focused.
Peter Dons Tychsen (none)
donpedro at dhcppc4.
Mon Feb 11 20:24:53 CST 2008
Added test-case to proove correctness & tested on Linux and WinXP.
---
dlls/comctl32/listview.c | 3 ++
dlls/comctl32/tests/listview.c | 70 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 0 deletions(-)
diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index 0c27885..599a1a9 100644
--- a/dlls/comctl32/listview.c
+++ b/dlls/comctl32/listview.c
@@ -7381,6 +7381,9 @@ static BOOL LISTVIEW_SetItemState(LISTVIEW_INFO *infoPtr, INT nItem, const LVITE
if (nItem == -1)
{
+ /* cannot apply "focused" to all items */
+ if((lpLVItem->stateMask & LVIS_FOCUSED) && (lpLVItem->state & LVIS_FOCUSED)) return FALSE;
+
/* apply to all items */
for (lvItem.iItem = 0; lvItem.iItem < infoPtr->nItemCount; lvItem.iItem++)
if (!LISTVIEW_SetItemT(infoPtr, &lvItem, TRUE)) bResult = FALSE;
diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c
index 30a81a8..349bacb 100644
--- a/dlls/comctl32/tests/listview.c
+++ b/dlls/comctl32/tests/listview.c
@@ -1038,6 +1038,75 @@ static void test_item_position(void)
DestroyWindow(hwnd);
}
+static void test_item_states(void)
+{
+ HWND hwnd;
+ DWORD r;
+ LVITEM item0;
+ LVITEM item1;
+ LVITEM item2;
+ LVITEM item;
+ static CHAR item0text[] = "item0";
+ static CHAR item1text[] = "item1";
+ static CHAR item2text[] = "item2";
+
+ hwnd = create_custom_listview_control(LVS_ICON);
+ ok(hwnd != NULL, "failed to create a listview window\n");
+
+ flush_sequences(sequences, NUM_MSG_SEQUENCES);
+
+ trace("test item states\n");
+
+ /* [item0] */
+ item0.mask = LVIF_TEXT;
+ item0.iItem = 0;
+ item0.iSubItem = 0;
+ item0.pszText = item0text;
+ r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
+ expect(0, r);
+
+ /* [item0, item1] */
+ item1.mask = LVIF_TEXT;
+ item1.iItem = 1;
+ item1.iSubItem = 0;
+ item1.pszText = item1text;
+ r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
+ expect(1, r);
+
+ /* [item0, item1, item2] */
+ item2.mask = LVIF_TEXT;
+ item2.iItem = 2;
+ item2.iSubItem = 0;
+ item2.pszText = item2text;
+ r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
+ expect(2, r);
+
+ /* Set focus on a valid item (1) */
+ ListView_SetItemState(hwnd, 1, LVIS_FOCUSED, LVIS_FOCUSED);
+
+ /* Try setting all items to state "focused" - should fail */
+ item.state = LVIS_FOCUSED | LVIS_SELECTED;
+ item.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
+ r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM) &item);
+ expect(0, r);
+
+ /* Check that nothing has been touched */
+ item.mask = LVIF_STATE;
+ item.iSubItem = 0;
+ item.iItem = 0;
+ r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
+ expect(0, item.state);
+ item.iItem = 1;
+ r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
+ expect(1, item.state);
+ item.iItem = 2;
+ r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
+ expect(0, item.state);
+
+ flush_sequences(sequences, NUM_MSG_SEQUENCES);
+ DestroyWindow(hwnd);
+}
+
START_TEST(listview)
{
InitCommonControls();
@@ -1059,5 +1128,6 @@ START_TEST(listview)
test_color();
test_item_count();
test_item_position();
+ test_item_states();
test_columns();
}
--
1.5.3.8
--=-in0eF9EH+hzu25xA0TqH--
More information about the wine-patches
mailing list