4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
29 #define PARENT_SEQ_INDEX 0
30 #define LISTVIEW_SEQ_INDEX 1
31 #define NUM_MSG_SEQUENCES 2
36 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
37 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
38 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
42 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
44 static const struct message create_parent_wnd_seq[] = {
45 { WM_GETMINMAXINFO, sent },
46 { WM_NCCREATE, sent },
47 { WM_NCCALCSIZE, sent|wparam, 0 },
49 { WM_SHOWWINDOW, sent|wparam, 1 },
50 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
51 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
52 { WM_ACTIVATEAPP, sent|wparam, 1 },
53 { WM_NCACTIVATE, sent|wparam, 1 },
54 { WM_ACTIVATE, sent|wparam, 1 },
55 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
56 { WM_IME_NOTIFY, sent|defwinproc|optional },
57 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
58 /* Win9x adds SWP_NOZORDER below */
59 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
60 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
66 static const struct message redraw_listview_seq[] = {
67 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
68 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
69 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
70 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, HEADER_ID },
71 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
72 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
73 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
77 static const struct message listview_icon_spacing_seq[] = {
78 { LVM_SETICONSPACING, sent|lparam, 0, (LPARAM) MAKELONG(20, 30) },
79 { LVM_SETICONSPACING, sent|lparam, 0, (LPARAM) MAKELONG(25, 35) },
80 { LVM_SETICONSPACING, sent|lparam, 0, (LPARAM) MAKELONG(-1, -1) },
84 static const struct message listview_color_seq[] = {
85 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
86 { LVM_GETBKCOLOR, sent },
87 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
88 { LVM_GETTEXTCOLOR, sent },
89 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
90 { LVM_GETTEXTBKCOLOR, sent },
92 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
93 { LVM_GETBKCOLOR, sent },
94 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
95 { LVM_GETTEXTCOLOR, sent },
96 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
97 { LVM_GETTEXTBKCOLOR, sent },
99 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
100 { LVM_GETBKCOLOR, sent },
101 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
102 { LVM_GETTEXTCOLOR, sent },
103 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
104 { LVM_GETTEXTBKCOLOR, sent },
106 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
107 { LVM_GETBKCOLOR, sent },
108 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
109 { LVM_GETTEXTCOLOR, sent },
110 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
111 { LVM_GETTEXTBKCOLOR, sent },
115 static const struct message listview_item_count_seq[] = {
116 { LVM_GETITEMCOUNT, sent },
117 { LVM_INSERTITEM, sent },
118 { LVM_INSERTITEM, sent },
119 { LVM_INSERTITEM, sent },
120 { LVM_GETITEMCOUNT, sent },
121 { LVM_DELETEITEM, sent|wparam, 2 },
122 { LVM_GETITEMCOUNT, sent },
123 { LVM_DELETEALLITEMS, sent },
124 { LVM_GETITEMCOUNT, sent },
125 { LVM_INSERTITEM, sent },
126 { LVM_INSERTITEM, sent },
127 { LVM_GETITEMCOUNT, sent },
128 { LVM_INSERTITEM, sent },
129 { LVM_GETITEMCOUNT, sent },
133 static const struct message listview_itempos_seq[] = {
134 { LVM_INSERTITEM, sent },
135 { LVM_INSERTITEM, sent },
136 { LVM_INSERTITEM, sent },
137 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
138 { LVM_GETITEMPOSITION, sent|wparam, 1 },
139 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
140 { LVM_GETITEMPOSITION, sent|wparam, 2 },
141 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
142 { LVM_GETITEMPOSITION, sent|wparam, 0 },
151 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
153 static long defwndproc_counter = 0;
157 /* do not log painting messages */
158 if (message != WM_PAINT &&
159 message != WM_ERASEBKGND &&
160 message != WM_NCPAINT &&
161 message != WM_NCHITTEST &&
162 message != WM_GETTEXT &&
163 message != WM_GETICON &&
164 message != WM_DEVICECHANGE)
166 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
168 msg.message = message;
169 msg.flags = sent|wparam|lparam;
170 if (defwndproc_counter) msg.flags |= defwinproc;
173 add_message(sequences, PARENT_SEQ_INDEX, &msg);
176 defwndproc_counter++;
177 ret = DefWindowProcA(hwnd, message, wParam, lParam);
178 defwndproc_counter--;
183 static BOOL register_parent_wnd_class(void)
188 cls.lpfnWndProc = parent_wnd_proc;
191 cls.hInstance = GetModuleHandleA(NULL);
193 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
194 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
195 cls.lpszMenuName = NULL;
196 cls.lpszClassName = "Listview test parent class";
197 return RegisterClassA(&cls);
200 static HWND create_parent_window(void)
202 if (!register_parent_wnd_class())
205 return CreateWindowEx(0, "Listview test parent class",
206 "Listview test parent window",
207 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
208 WS_MAXIMIZEBOX | WS_VISIBLE,
210 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
213 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
215 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
216 static long defwndproc_counter = 0;
220 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
222 msg.message = message;
223 msg.flags = sent|wparam|lparam;
224 if (defwndproc_counter) msg.flags |= defwinproc;
227 msg.id = LISTVIEW_ID;
228 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
230 defwndproc_counter++;
231 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
232 defwndproc_counter--;
236 static HWND create_listview_control(void)
238 struct subclass_info *info;
242 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
246 GetClientRect(hwndparent, &rect);
247 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
248 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
249 0, 0, rect.right, rect.bottom,
250 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
251 ok(hwnd != NULL, "gle=%d\n", GetLastError());
255 HeapFree(GetProcessHeap(), 0, info);
259 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
260 (LONG_PTR)listview_subclass_proc);
261 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
266 static HWND create_custom_listview_control(DWORD style)
268 struct subclass_info *info;
272 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
276 GetClientRect(hwndparent, &rect);
277 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
278 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
279 0, 0, rect.right, rect.bottom,
280 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
281 ok(hwnd != NULL, "gle=%d\n", GetLastError());
285 HeapFree(GetProcessHeap(), 0, info);
289 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
290 (LONG_PTR)listview_subclass_proc);
291 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
296 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
298 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
299 static long defwndproc_counter = 0;
303 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
305 msg.message = message;
306 msg.flags = sent|wparam|lparam;
307 if (defwndproc_counter) msg.flags |= defwinproc;
311 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
313 defwndproc_counter++;
314 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
315 defwndproc_counter--;
319 static HWND subclass_header(HWND hwndListview)
321 struct subclass_info *info;
324 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
328 hwnd = ListView_GetHeader(hwndListview);
329 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
330 (LONG_PTR)header_subclass_proc);
331 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
336 static void test_images(void)
344 static CHAR hello[] = "hello";
346 himl = ImageList_Create(40, 40, 0, 4, 4);
347 ok(himl != NULL, "failed to create imagelist\n");
349 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
350 ok(hbmp != NULL, "failed to create bitmap\n");
352 r = ImageList_Add(himl, hbmp, 0);
353 ok(r == 0, "should be zero\n");
355 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
356 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
357 ok(hwnd != NULL, "failed to create listview window\n");
359 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, 0x940);
360 ok(r == 0, "should return zero\n");
362 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
363 ok(r == 0, "should return zero\n");
365 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
366 /* returns dimensions */
368 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
369 ok(r == 0, "should be zero items\n");
371 item.mask = LVIF_IMAGE | LVIF_TEXT;
376 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
377 ok(r == -1, "should fail\n");
380 item.pszText = hello;
381 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
382 ok(r == 0, "should not fail\n");
384 memset(&r1, 0, sizeof r1);
386 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
388 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
389 ok(r == TRUE, "should not fail\n");
392 item.pszText = hello;
393 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
394 ok(r == 0, "should not fail\n");
396 memset(&r2, 0, sizeof r2);
398 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
400 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
405 static void test_checkboxes(void)
410 static CHAR text[] = "Text",
414 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
415 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
416 ok(hwnd != NULL, "failed to create listview window\n");
418 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
419 item.mask = LVIF_TEXT | LVIF_STATE;
420 item.stateMask = 0xffff;
425 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
426 ok(r == 0, "ret %d\n", r);
429 item.mask = LVIF_STATE;
430 item.stateMask = 0xffff;
431 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
432 ok(item.state == 0xfccc, "state %x\n", item.state);
434 /* Don't set LVIF_STATE */
435 item.mask = LVIF_TEXT;
436 item.stateMask = 0xffff;
441 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
442 ok(r == 1, "ret %d\n", r);
445 item.mask = LVIF_STATE;
446 item.stateMask = 0xffff;
447 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
448 ok(item.state == 0, "state %x\n", item.state);
450 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
451 ok(r == 0, "should return zero\n");
453 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
455 item.mask = LVIF_STATE;
456 item.stateMask = 0xffff;
457 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
458 ok(item.state == 0x1ccc, "state %x\n", item.state);
460 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
462 item.mask = LVIF_TEXT;
464 item.pszText = text2;
465 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
466 ok(r == 2, "ret %d\n", r);
469 item.mask = LVIF_STATE;
470 item.stateMask = 0xffff;
471 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
472 ok(item.state == 0x1000, "state %x\n", item.state);
474 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
476 item.mask = LVIF_TEXT | LVIF_STATE;
477 item.stateMask = 0xffff;
479 item.pszText = text3;
480 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
481 ok(r == 3, "ret %d\n", r);
484 item.mask = LVIF_STATE;
485 item.stateMask = 0xffff;
486 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
487 ok(item.state == 0x1aaa, "state %x\n", item.state);
489 /* Set an item's state to checked */
491 item.mask = LVIF_STATE;
492 item.stateMask = 0xf000;
494 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
497 item.mask = LVIF_STATE;
498 item.stateMask = 0xffff;
499 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
500 ok(item.state == 0x2aaa, "state %x\n", item.state);
502 /* Check that only the bits we asked for are returned,
503 * and that all the others are set to zero
506 item.mask = LVIF_STATE;
507 item.stateMask = 0xf000;
509 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
510 ok(item.state == 0x2000, "state %x\n", item.state);
512 /* Set the style again and check that doesn't change an item's state */
513 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
514 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
517 item.mask = LVIF_STATE;
518 item.stateMask = 0xffff;
519 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
520 ok(item.state == 0x2aaa, "state %x\n", item.state);
522 /* Unsetting the checkbox extended style doesn't change an item's state */
523 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
524 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
527 item.mask = LVIF_STATE;
528 item.stateMask = 0xffff;
529 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
530 ok(item.state == 0x2aaa, "state %x\n", item.state);
532 /* Now setting the style again will change an item's state */
533 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
534 ok(r == 0, "ret %x\n", r);
537 item.mask = LVIF_STATE;
538 item.stateMask = 0xffff;
539 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
540 ok(item.state == 0x1aaa, "state %x\n", item.state);
542 /* Toggle checkbox tests (bug 9934) */
543 memset (&item, 0xcc, sizeof(item));
544 item.mask = LVIF_STATE;
547 item.state = LVIS_FOCUSED;
548 item.stateMask = LVIS_FOCUSED;
549 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
553 item.mask = LVIF_STATE;
554 item.stateMask = 0xffff;
555 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
556 ok(item.state == 0x1aab, "state %x\n", item.state);
558 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
560 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
564 item.mask = LVIF_STATE;
565 item.stateMask = 0xffff;
566 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
567 ok(item.state == 0x2aab, "state %x\n", item.state);
569 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
571 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
575 item.mask = LVIF_STATE;
576 item.stateMask = 0xffff;
577 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
578 ok(item.state == 0x1aab, "state %x\n", item.state);
583 static void insert_column(HWND hwnd, int idx)
588 memset(&column, 0xcc, sizeof(column));
589 column.mask = LVCF_SUBITEM;
590 column.iSubItem = idx;
592 rc = ListView_InsertColumn(hwnd, idx, &column);
596 static void insert_item(HWND hwnd, int idx)
598 static CHAR text[] = "foo";
603 memset(&item, 0xcc, sizeof (item));
604 item.mask = LVIF_TEXT;
609 rc = ListView_InsertItem(hwnd, &item);
613 static void test_items(void)
615 const LPARAM lparamTest = 0x42;
619 static CHAR text[] = "Text";
621 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
622 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
623 ok(hwnd != NULL, "failed to create listview window\n");
626 * Test setting/getting item params
629 /* Set up two columns */
630 insert_column(hwnd, 0);
631 insert_column(hwnd, 1);
633 /* Insert an item with just a param */
634 memset (&item, 0xcc, sizeof (item));
635 item.mask = LVIF_PARAM;
638 item.lParam = lparamTest;
639 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
640 ok(r == 0, "ret %d\n", r);
642 /* Test getting of the param */
643 memset (&item, 0xcc, sizeof (item));
644 item.mask = LVIF_PARAM;
647 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
648 ok(r != 0, "ret %d\n", r);
649 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
651 /* Set up a subitem */
652 memset (&item, 0xcc, sizeof (item));
653 item.mask = LVIF_TEXT;
657 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
658 ok(r != 0, "ret %d\n", r);
660 /* Query param from subitem: returns main item param */
661 memset (&item, 0xcc, sizeof (item));
662 item.mask = LVIF_PARAM;
665 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
666 ok(r != 0, "ret %d\n", r);
667 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
669 /* Set up param on first subitem: no effect */
670 memset (&item, 0xcc, sizeof (item));
671 item.mask = LVIF_PARAM;
674 item.lParam = lparamTest+1;
675 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
676 ok(r == 0, "ret %d\n", r);
678 /* Query param from subitem again: should still return main item param */
679 memset (&item, 0xcc, sizeof (item));
680 item.mask = LVIF_PARAM;
683 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
684 ok(r != 0, "ret %d\n", r);
685 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
687 /**** Some tests of state highlighting ****/
688 memset (&item, 0xcc, sizeof (item));
689 item.mask = LVIF_STATE;
692 item.state = LVIS_SELECTED;
693 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
694 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
695 ok(r != 0, "ret %d\n", r);
697 item.state = LVIS_DROPHILITED;
698 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
699 ok(r != 0, "ret %d\n", r);
701 memset (&item, 0xcc, sizeof (item));
702 item.mask = LVIF_STATE;
706 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
707 ok(r != 0, "ret %d\n", r);
708 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
710 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
711 ok(r != 0, "ret %d\n", r);
712 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
717 static void test_columns(void)
723 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
724 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
725 ok(hwnd != NULL, "failed to create listview window\n");
727 /* Add a column with no mask */
728 memset(&column, 0xcc, sizeof(column));
730 rc = ListView_InsertColumn(hwnd, 0, &column);
731 ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
733 /* Check its width */
734 rc = ListView_GetColumnWidth(hwnd, 0);
735 ok(rc==10, "Inserting column with no mask failed to set width to 10 with %d\n", rc);
739 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
740 static WNDPROC listviewWndProc;
741 static HIMAGELIST test_create_imagelist;
743 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
745 if (uMsg == WM_CREATE)
747 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
748 lpcs->style |= LVS_REPORT;
749 SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
751 return CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
754 static void test_create(void)
759 cls.cbSize = sizeof(WNDCLASSEX);
760 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
761 listviewWndProc = cls.lpfnWndProc;
762 cls.lpfnWndProc = create_test_wndproc;
763 cls.lpszClassName = "MyListView32";
764 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
766 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
767 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
768 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
769 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
770 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
771 DestroyWindow(hList);
774 static void test_redraw(void)
776 HWND hwnd, hwndheader;
778 hwnd = create_listview_control();
779 hwndheader = subclass_header(hwnd);
781 flush_sequences(sequences, NUM_MSG_SEQUENCES);
783 trace("invalidate & update\n");
784 InvalidateRect(hwnd, NULL, TRUE);
786 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
788 flush_sequences(sequences, NUM_MSG_SEQUENCES);
793 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
795 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
797 if(msg == WM_NOTIFY) {
798 NMHDR *nmhdr = (PVOID)lp;
799 if(nmhdr->code == NM_CUSTOMDRAW) {
800 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
801 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
802 switch(nmlvcd->nmcd.dwDrawStage) {
804 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
805 return CDRF_NOTIFYITEMDRAW;
806 case CDDS_ITEMPREPAINT:
807 nmlvcd->clrTextBk = CLR_DEFAULT;
808 return CDRF_NOTIFYSUBITEMDRAW;
809 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
810 clr = GetBkColor(nmlvcd->nmcd.hdc);
811 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
812 return CDRF_NOTIFYPOSTPAINT;
813 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
814 clr = GetBkColor(nmlvcd->nmcd.hdc);
815 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
816 return CDRF_DODEFAULT;
818 return CDRF_DODEFAULT;
822 return DefWindowProcA(hwnd, msg, wp, lp);
825 static void test_customdraw(void)
830 hwnd = create_listview_control();
832 insert_column(hwnd, 0);
833 insert_column(hwnd, 1);
834 insert_item(hwnd, 0);
836 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
837 (LONG_PTR)cd_wndproc);
839 InvalidateRect(hwnd, NULL, TRUE);
842 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
847 static void test_icon_spacing(void)
849 /* LVM_SETICONSPACING */
850 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
856 hwnd = create_custom_listview_control(LVS_ICON);
857 ok(hwnd != NULL, "failed to create a listview window\n");
859 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
862 /* reset the icon spacing to defaults */
863 SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(-1, -1));
865 /* now we can request what the defaults are */
866 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(-1, -1));
870 flush_sequences(sequences, NUM_MSG_SEQUENCES);
872 trace("test icon spacing\n");
874 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(20, 30));
875 expect(MAKELONG(w,h), r);
877 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(25, 35));
878 expect(MAKELONG(20,30), r);
880 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(-1,-1));
881 expect(MAKELONG(25,35), r);
883 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
885 flush_sequences(sequences, NUM_MSG_SEQUENCES);
889 static void test_color(void)
891 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
898 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
900 hwnd = create_listview_control();
901 ok(hwnd != NULL, "failed to create a listview window\n");
903 flush_sequences(sequences, NUM_MSG_SEQUENCES);
905 trace("test color seq\n");
906 for (i = 0; i < 4; i++)
910 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
912 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
915 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
917 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
920 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
922 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
926 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
928 flush_sequences(sequences, NUM_MSG_SEQUENCES);
932 static void test_item_count(void)
934 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
942 static CHAR item0text[] = "item0";
943 static CHAR item1text[] = "item1";
944 static CHAR item2text[] = "item2";
946 hwnd = create_listview_control();
947 ok(hwnd != NULL, "failed to create a listview window\n");
949 flush_sequences(sequences, NUM_MSG_SEQUENCES);
951 trace("test item count\n");
953 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
957 item0.mask = LVIF_TEXT;
960 item0.pszText = item0text;
961 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
965 item1.mask = LVIF_TEXT;
968 item1.pszText = item1text;
969 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
972 /* [item0, item1, item2] */
973 item2.mask = LVIF_TEXT;
976 item2.pszText = item2text;
977 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
980 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
984 r = SendMessage(hwnd, LVM_DELETEITEM, (WPARAM) 2, 0);
987 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
991 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
994 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
998 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1001 /* [item0, item1] */
1002 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1005 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1008 /* [item0, item1, item2] */
1009 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1012 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1015 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1017 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1018 DestroyWindow(hwnd);
1021 static void test_item_position(void)
1023 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1032 static CHAR item0text[] = "item0";
1033 static CHAR item1text[] = "item1";
1034 static CHAR item2text[] = "item2";
1036 hwnd = create_custom_listview_control(LVS_ICON);
1037 ok(hwnd != NULL, "failed to create a listview window\n");
1039 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1041 trace("test item position\n");
1044 item0.mask = LVIF_TEXT;
1047 item0.pszText = item0text;
1048 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1051 /* [item0, item1] */
1052 item1.mask = LVIF_TEXT;
1055 item1.pszText = item1text;
1056 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1059 /* [item0, item1, item2] */
1060 item2.mask = LVIF_TEXT;
1063 item2.pszText = item2text;
1064 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1067 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1069 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1071 expect2(10, 5, position.x, position.y);
1073 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1075 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1077 expect2(0, 0, position.x, position.y);
1079 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1081 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1083 expect2(20, 20, position.x, position.y);
1085 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1087 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1088 DestroyWindow(hwnd);
1091 static void test_getorigin(void)
1099 position.x = position.y = 0;
1101 hwnd = create_custom_listview_control(LVS_ICON);
1102 ok(hwnd != NULL, "failed to create a listview window\n");
1103 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1104 trace("test get origin results\n");
1105 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1107 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1108 DestroyWindow(hwnd);
1110 hwnd = create_custom_listview_control(LVS_SMALLICON);
1111 ok(hwnd != NULL, "failed to create a listview window\n");
1112 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1113 trace("test get origin results\n");
1114 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1116 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1117 DestroyWindow(hwnd);
1119 hwnd = create_custom_listview_control(LVS_LIST);
1120 ok(hwnd != NULL, "failed to create a listview window\n");
1121 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1122 trace("test get origin results\n");
1123 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1125 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1126 DestroyWindow(hwnd);
1128 hwnd = create_custom_listview_control(LVS_REPORT);
1129 ok(hwnd != NULL, "failed to create a listview window\n");
1130 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1131 trace("test get origin results\n");
1132 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1134 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1135 DestroyWindow(hwnd);
1139 static void test_multiselect(void)
1141 typedef struct t_select_task
1152 int i,j,item_count,selected_count;
1153 static const int items=5;
1157 static struct t_select_task task_list[] = {
1158 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1159 { "using VK_UP", -1, VK_UP, -1, -1 },
1160 { "using VK_END", 0, VK_END, 1, -1 },
1161 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1165 hwnd = create_listview_control();
1167 for (i=0;i<items;i++) {
1168 insert_item(hwnd, 0);
1171 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1173 expect(items,item_count);
1176 task = task_list[i];
1178 /* deselect all items */
1179 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1180 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1182 /* set initial position */
1183 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1184 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1186 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1188 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1190 /* Set SHIFT key pressed */
1191 GetKeyboardState(kstate);
1192 kstate[VK_SHIFT]=0x80;
1193 SetKeyboardState(kstate);
1195 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1196 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1198 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1202 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1204 ok((task.result == -1 ? item_count : task.result) == selected_count, "Failed multiple selection %s. There should be %d selected items (is %d)\n", task.descr, item_count, selected_count);
1206 /* Set SHIFT key released */
1207 GetKeyboardState(kstate);
1208 kstate[VK_SHIFT]=0x00;
1209 SetKeyboardState(kstate);
1211 DestroyWindow(hwnd);
1214 START_TEST(listview)
1217 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1219 hComctl32 = GetModuleHandleA("comctl32.dll");
1220 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1221 if (pInitCommonControlsEx)
1223 INITCOMMONCONTROLSEX iccex;
1224 iccex.dwSize = sizeof(iccex);
1225 iccex.dwICC = ICC_LISTVIEW_CLASSES;
1226 pInitCommonControlsEx(&iccex);
1229 InitCommonControls();
1231 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1233 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1234 hwndparent = create_parent_window();
1235 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent window", TRUE);
1236 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1244 test_icon_spacing();
1247 test_item_position();