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_QUERYNEWPALETTE, sent|optional },
52 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
53 { WM_WINDOWPOSCHANGED, sent|optional },
54 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
55 { WM_ACTIVATEAPP, sent|wparam, 1 },
56 { WM_NCACTIVATE, sent|wparam, 1 },
57 { WM_ACTIVATE, sent|wparam, 1 },
58 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
59 { WM_IME_NOTIFY, sent|defwinproc|optional },
60 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
61 /* Win9x adds SWP_NOZORDER below */
62 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
63 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
69 static const struct message redraw_listview_seq[] = {
70 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
71 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
72 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
73 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, HEADER_ID },
74 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
75 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
76 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
80 static const struct message listview_icon_spacing_seq[] = {
81 { LVM_SETICONSPACING, sent|lparam, 0, (LPARAM) MAKELONG(20, 30) },
82 { LVM_SETICONSPACING, sent|lparam, 0, (LPARAM) MAKELONG(25, 35) },
83 { LVM_SETICONSPACING, sent|lparam, 0, (LPARAM) MAKELONG(-1, -1) },
87 static const struct message listview_color_seq[] = {
88 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
89 { LVM_GETBKCOLOR, sent },
90 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
91 { LVM_GETTEXTCOLOR, sent },
92 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
93 { LVM_GETTEXTBKCOLOR, sent },
95 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
96 { LVM_GETBKCOLOR, sent },
97 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
98 { LVM_GETTEXTCOLOR, sent },
99 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
100 { LVM_GETTEXTBKCOLOR, sent },
102 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
103 { LVM_GETBKCOLOR, sent },
104 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
105 { LVM_GETTEXTCOLOR, sent },
106 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
107 { LVM_GETTEXTBKCOLOR, sent },
109 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
110 { LVM_GETBKCOLOR, sent },
111 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
112 { LVM_GETTEXTCOLOR, sent },
113 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
114 { LVM_GETTEXTBKCOLOR, sent },
118 static const struct message listview_item_count_seq[] = {
119 { LVM_GETITEMCOUNT, sent },
120 { LVM_INSERTITEM, sent },
121 { LVM_INSERTITEM, sent },
122 { LVM_INSERTITEM, sent },
123 { LVM_GETITEMCOUNT, sent },
124 { LVM_DELETEITEM, sent|wparam, 2 },
125 { LVM_GETITEMCOUNT, sent },
126 { LVM_DELETEALLITEMS, sent },
127 { LVM_GETITEMCOUNT, sent },
128 { LVM_INSERTITEM, sent },
129 { LVM_INSERTITEM, sent },
130 { LVM_GETITEMCOUNT, sent },
131 { LVM_INSERTITEM, sent },
132 { LVM_GETITEMCOUNT, sent },
136 static const struct message listview_itempos_seq[] = {
137 { LVM_INSERTITEM, sent },
138 { LVM_INSERTITEM, sent },
139 { LVM_INSERTITEM, sent },
140 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
141 { LVM_GETITEMPOSITION, sent|wparam, 1 },
142 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
143 { LVM_GETITEMPOSITION, sent|wparam, 2 },
144 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
145 { LVM_GETITEMPOSITION, sent|wparam, 0 },
154 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
156 static long defwndproc_counter = 0;
160 /* do not log painting messages */
161 if (message != WM_PAINT &&
162 message != WM_ERASEBKGND &&
163 message != WM_NCPAINT &&
164 message != WM_NCHITTEST &&
165 message != WM_GETTEXT &&
166 message != WM_GETICON &&
167 message != WM_DEVICECHANGE)
169 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
171 msg.message = message;
172 msg.flags = sent|wparam|lparam;
173 if (defwndproc_counter) msg.flags |= defwinproc;
176 add_message(sequences, PARENT_SEQ_INDEX, &msg);
179 defwndproc_counter++;
180 ret = DefWindowProcA(hwnd, message, wParam, lParam);
181 defwndproc_counter--;
186 static BOOL register_parent_wnd_class(void)
191 cls.lpfnWndProc = parent_wnd_proc;
194 cls.hInstance = GetModuleHandleA(NULL);
196 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
197 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
198 cls.lpszMenuName = NULL;
199 cls.lpszClassName = "Listview test parent class";
200 return RegisterClassA(&cls);
203 static HWND create_parent_window(void)
205 if (!register_parent_wnd_class())
208 return CreateWindowEx(0, "Listview test parent class",
209 "Listview test parent window",
210 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
211 WS_MAXIMIZEBOX | WS_VISIBLE,
213 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
216 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
218 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
219 static long defwndproc_counter = 0;
223 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
225 msg.message = message;
226 msg.flags = sent|wparam|lparam;
227 if (defwndproc_counter) msg.flags |= defwinproc;
230 msg.id = LISTVIEW_ID;
231 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
233 defwndproc_counter++;
234 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
235 defwndproc_counter--;
239 static HWND create_listview_control(void)
241 struct subclass_info *info;
245 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
249 GetClientRect(hwndparent, &rect);
250 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
251 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
252 0, 0, rect.right, rect.bottom,
253 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
254 ok(hwnd != NULL, "gle=%d\n", GetLastError());
258 HeapFree(GetProcessHeap(), 0, info);
262 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
263 (LONG_PTR)listview_subclass_proc);
264 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
269 static HWND create_custom_listview_control(DWORD style)
271 struct subclass_info *info;
275 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
279 GetClientRect(hwndparent, &rect);
280 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
281 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
282 0, 0, rect.right, rect.bottom,
283 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
284 ok(hwnd != NULL, "gle=%d\n", GetLastError());
288 HeapFree(GetProcessHeap(), 0, info);
292 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
293 (LONG_PTR)listview_subclass_proc);
294 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
299 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
301 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
302 static long defwndproc_counter = 0;
306 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
308 msg.message = message;
309 msg.flags = sent|wparam|lparam;
310 if (defwndproc_counter) msg.flags |= defwinproc;
314 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
316 defwndproc_counter++;
317 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
318 defwndproc_counter--;
322 static HWND subclass_header(HWND hwndListview)
324 struct subclass_info *info;
327 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
331 hwnd = ListView_GetHeader(hwndListview);
332 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
333 (LONG_PTR)header_subclass_proc);
334 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
339 static void test_images(void)
347 static CHAR hello[] = "hello";
349 himl = ImageList_Create(40, 40, 0, 4, 4);
350 ok(himl != NULL, "failed to create imagelist\n");
352 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
353 ok(hbmp != NULL, "failed to create bitmap\n");
355 r = ImageList_Add(himl, hbmp, 0);
356 ok(r == 0, "should be zero\n");
358 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
359 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
360 ok(hwnd != NULL, "failed to create listview window\n");
362 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, 0x940);
363 ok(r == 0, "should return zero\n");
365 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
366 ok(r == 0, "should return zero\n");
368 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
369 /* returns dimensions */
371 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
372 ok(r == 0, "should be zero items\n");
374 item.mask = LVIF_IMAGE | LVIF_TEXT;
379 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
380 ok(r == -1, "should fail\n");
383 item.pszText = hello;
384 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
385 ok(r == 0, "should not fail\n");
387 memset(&r1, 0, sizeof r1);
389 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
391 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
392 ok(r == TRUE, "should not fail\n");
395 item.pszText = hello;
396 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
397 ok(r == 0, "should not fail\n");
399 memset(&r2, 0, sizeof r2);
401 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
403 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
408 static void test_checkboxes(void)
413 static CHAR text[] = "Text",
417 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
418 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
419 ok(hwnd != NULL, "failed to create listview window\n");
421 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
422 item.mask = LVIF_TEXT | LVIF_STATE;
423 item.stateMask = 0xffff;
428 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
429 ok(r == 0, "ret %d\n", r);
432 item.mask = LVIF_STATE;
433 item.stateMask = 0xffff;
434 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
435 ok(item.state == 0xfccc, "state %x\n", item.state);
437 /* Don't set LVIF_STATE */
438 item.mask = LVIF_TEXT;
439 item.stateMask = 0xffff;
444 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
445 ok(r == 1, "ret %d\n", r);
448 item.mask = LVIF_STATE;
449 item.stateMask = 0xffff;
450 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
451 ok(item.state == 0, "state %x\n", item.state);
453 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
454 ok(r == 0, "should return zero\n");
456 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
458 item.mask = LVIF_STATE;
459 item.stateMask = 0xffff;
460 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
461 ok(item.state == 0x1ccc, "state %x\n", item.state);
463 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
465 item.mask = LVIF_TEXT;
467 item.pszText = text2;
468 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
469 ok(r == 2, "ret %d\n", r);
472 item.mask = LVIF_STATE;
473 item.stateMask = 0xffff;
474 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
475 ok(item.state == 0x1000, "state %x\n", item.state);
477 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
479 item.mask = LVIF_TEXT | LVIF_STATE;
480 item.stateMask = 0xffff;
482 item.pszText = text3;
483 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
484 ok(r == 3, "ret %d\n", r);
487 item.mask = LVIF_STATE;
488 item.stateMask = 0xffff;
489 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
490 ok(item.state == 0x1aaa, "state %x\n", item.state);
492 /* Set an item's state to checked */
494 item.mask = LVIF_STATE;
495 item.stateMask = 0xf000;
497 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
500 item.mask = LVIF_STATE;
501 item.stateMask = 0xffff;
502 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
503 ok(item.state == 0x2aaa, "state %x\n", item.state);
505 /* Check that only the bits we asked for are returned,
506 * and that all the others are set to zero
509 item.mask = LVIF_STATE;
510 item.stateMask = 0xf000;
512 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
513 ok(item.state == 0x2000, "state %x\n", item.state);
515 /* Set the style again and check that doesn't change an item's state */
516 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
517 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
520 item.mask = LVIF_STATE;
521 item.stateMask = 0xffff;
522 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
523 ok(item.state == 0x2aaa, "state %x\n", item.state);
525 /* Unsetting the checkbox extended style doesn't change an item's state */
526 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
527 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
530 item.mask = LVIF_STATE;
531 item.stateMask = 0xffff;
532 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
533 ok(item.state == 0x2aaa, "state %x\n", item.state);
535 /* Now setting the style again will change an item's state */
536 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
537 ok(r == 0, "ret %x\n", r);
540 item.mask = LVIF_STATE;
541 item.stateMask = 0xffff;
542 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
543 ok(item.state == 0x1aaa, "state %x\n", item.state);
545 /* Toggle checkbox tests (bug 9934) */
546 memset (&item, 0xcc, sizeof(item));
547 item.mask = LVIF_STATE;
550 item.state = LVIS_FOCUSED;
551 item.stateMask = LVIS_FOCUSED;
552 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
556 item.mask = LVIF_STATE;
557 item.stateMask = 0xffff;
558 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
559 ok(item.state == 0x1aab, "state %x\n", item.state);
561 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
563 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
567 item.mask = LVIF_STATE;
568 item.stateMask = 0xffff;
569 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
570 ok(item.state == 0x2aab, "state %x\n", item.state);
572 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
574 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
578 item.mask = LVIF_STATE;
579 item.stateMask = 0xffff;
580 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
581 ok(item.state == 0x1aab, "state %x\n", item.state);
586 static void insert_column(HWND hwnd, int idx)
591 memset(&column, 0xcc, sizeof(column));
592 column.mask = LVCF_SUBITEM;
593 column.iSubItem = idx;
595 rc = ListView_InsertColumn(hwnd, idx, &column);
599 static void insert_item(HWND hwnd, int idx)
601 static CHAR text[] = "foo";
606 memset(&item, 0xcc, sizeof (item));
607 item.mask = LVIF_TEXT;
612 rc = ListView_InsertItem(hwnd, &item);
616 static void test_items(void)
618 const LPARAM lparamTest = 0x42;
622 static CHAR text[] = "Text";
624 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
625 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
626 ok(hwnd != NULL, "failed to create listview window\n");
629 * Test setting/getting item params
632 /* Set up two columns */
633 insert_column(hwnd, 0);
634 insert_column(hwnd, 1);
636 /* Insert an item with just a param */
637 memset (&item, 0xcc, sizeof (item));
638 item.mask = LVIF_PARAM;
641 item.lParam = lparamTest;
642 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
643 ok(r == 0, "ret %d\n", r);
645 /* Test getting of the param */
646 memset (&item, 0xcc, sizeof (item));
647 item.mask = LVIF_PARAM;
650 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
651 ok(r != 0, "ret %d\n", r);
652 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
654 /* Set up a subitem */
655 memset (&item, 0xcc, sizeof (item));
656 item.mask = LVIF_TEXT;
660 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
661 ok(r != 0, "ret %d\n", r);
663 /* Query param from subitem: returns main item param */
664 memset (&item, 0xcc, sizeof (item));
665 item.mask = LVIF_PARAM;
668 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
669 ok(r != 0, "ret %d\n", r);
670 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
672 /* Set up param on first subitem: no effect */
673 memset (&item, 0xcc, sizeof (item));
674 item.mask = LVIF_PARAM;
677 item.lParam = lparamTest+1;
678 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
679 ok(r == 0, "ret %d\n", r);
681 /* Query param from subitem again: should still return main item param */
682 memset (&item, 0xcc, sizeof (item));
683 item.mask = LVIF_PARAM;
686 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
687 ok(r != 0, "ret %d\n", r);
688 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
690 /**** Some tests of state highlighting ****/
691 memset (&item, 0xcc, sizeof (item));
692 item.mask = LVIF_STATE;
695 item.state = LVIS_SELECTED;
696 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
697 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
698 ok(r != 0, "ret %d\n", r);
700 item.state = LVIS_DROPHILITED;
701 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
702 ok(r != 0, "ret %d\n", r);
704 memset (&item, 0xcc, sizeof (item));
705 item.mask = LVIF_STATE;
709 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
710 ok(r != 0, "ret %d\n", r);
711 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
713 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
714 ok(r != 0, "ret %d\n", r);
715 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
720 static void test_columns(void)
726 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
727 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
728 ok(hwnd != NULL, "failed to create listview window\n");
730 /* Add a column with no mask */
731 memset(&column, 0xcc, sizeof(column));
733 rc = ListView_InsertColumn(hwnd, 0, &column);
734 ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
736 /* Check its width */
737 rc = ListView_GetColumnWidth(hwnd, 0);
739 broken(rc==0), /* win9x */
740 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
744 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
745 static WNDPROC listviewWndProc;
746 static HIMAGELIST test_create_imagelist;
748 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
750 if (uMsg == WM_CREATE)
752 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
753 lpcs->style |= LVS_REPORT;
754 SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
756 return CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
759 static void test_create(void)
764 cls.cbSize = sizeof(WNDCLASSEX);
765 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
766 listviewWndProc = cls.lpfnWndProc;
767 cls.lpfnWndProc = create_test_wndproc;
768 cls.lpszClassName = "MyListView32";
769 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
771 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
772 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
773 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
774 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
775 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
776 DestroyWindow(hList);
779 static void test_redraw(void)
781 HWND hwnd, hwndheader;
783 hwnd = create_listview_control();
784 hwndheader = subclass_header(hwnd);
786 flush_sequences(sequences, NUM_MSG_SEQUENCES);
788 trace("invalidate & update\n");
789 InvalidateRect(hwnd, NULL, TRUE);
791 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
793 flush_sequences(sequences, NUM_MSG_SEQUENCES);
798 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
800 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
802 if(msg == WM_NOTIFY) {
803 NMHDR *nmhdr = (PVOID)lp;
804 if(nmhdr->code == NM_CUSTOMDRAW) {
805 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
806 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
807 switch(nmlvcd->nmcd.dwDrawStage) {
809 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
810 return CDRF_NOTIFYITEMDRAW;
811 case CDDS_ITEMPREPAINT:
812 nmlvcd->clrTextBk = CLR_DEFAULT;
813 return CDRF_NOTIFYSUBITEMDRAW;
814 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
815 clr = GetBkColor(nmlvcd->nmcd.hdc);
816 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
817 return CDRF_NOTIFYPOSTPAINT;
818 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
819 clr = GetBkColor(nmlvcd->nmcd.hdc);
820 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
821 return CDRF_DODEFAULT;
823 return CDRF_DODEFAULT;
827 return DefWindowProcA(hwnd, msg, wp, lp);
830 static void test_customdraw(void)
835 hwnd = create_listview_control();
837 insert_column(hwnd, 0);
838 insert_column(hwnd, 1);
839 insert_item(hwnd, 0);
841 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
842 (LONG_PTR)cd_wndproc);
844 InvalidateRect(hwnd, NULL, TRUE);
847 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
852 static void test_icon_spacing(void)
854 /* LVM_SETICONSPACING */
855 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
861 hwnd = create_custom_listview_control(LVS_ICON);
862 ok(hwnd != NULL, "failed to create a listview window\n");
864 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
867 /* reset the icon spacing to defaults */
868 SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(-1, -1));
870 /* now we can request what the defaults are */
871 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(-1, -1));
875 flush_sequences(sequences, NUM_MSG_SEQUENCES);
877 trace("test icon spacing\n");
879 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(20, 30));
880 ok(r == MAKELONG(w, h) ||
881 broken(r == MAKELONG(w, w)), /* win98 */
882 "Expected %d, got %d\n", MAKELONG(w, h), r);
884 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(25, 35));
885 expect(MAKELONG(20,30), r);
887 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(-1,-1));
888 expect(MAKELONG(25,35), r);
890 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
892 flush_sequences(sequences, NUM_MSG_SEQUENCES);
896 static void test_color(void)
898 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
905 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
907 hwnd = create_listview_control();
908 ok(hwnd != NULL, "failed to create a listview window\n");
910 flush_sequences(sequences, NUM_MSG_SEQUENCES);
912 trace("test color seq\n");
913 for (i = 0; i < 4; i++)
917 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
919 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
922 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
924 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
927 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
929 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
933 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
935 flush_sequences(sequences, NUM_MSG_SEQUENCES);
939 static void test_item_count(void)
941 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
949 static CHAR item0text[] = "item0";
950 static CHAR item1text[] = "item1";
951 static CHAR item2text[] = "item2";
953 hwnd = create_listview_control();
954 ok(hwnd != NULL, "failed to create a listview window\n");
956 flush_sequences(sequences, NUM_MSG_SEQUENCES);
958 trace("test item count\n");
960 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
964 item0.mask = LVIF_TEXT;
967 item0.pszText = item0text;
968 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
972 item1.mask = LVIF_TEXT;
975 item1.pszText = item1text;
976 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
979 /* [item0, item1, item2] */
980 item2.mask = LVIF_TEXT;
983 item2.pszText = item2text;
984 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
987 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
991 r = SendMessage(hwnd, LVM_DELETEITEM, (WPARAM) 2, 0);
994 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
998 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1001 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1005 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1008 /* [item0, item1] */
1009 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1012 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1015 /* [item0, item1, item2] */
1016 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1019 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1022 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1024 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1025 DestroyWindow(hwnd);
1028 static void test_item_position(void)
1030 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1039 static CHAR item0text[] = "item0";
1040 static CHAR item1text[] = "item1";
1041 static CHAR item2text[] = "item2";
1043 hwnd = create_custom_listview_control(LVS_ICON);
1044 ok(hwnd != NULL, "failed to create a listview window\n");
1046 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1048 trace("test item position\n");
1051 item0.mask = LVIF_TEXT;
1054 item0.pszText = item0text;
1055 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1058 /* [item0, item1] */
1059 item1.mask = LVIF_TEXT;
1062 item1.pszText = item1text;
1063 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1066 /* [item0, item1, item2] */
1067 item2.mask = LVIF_TEXT;
1070 item2.pszText = item2text;
1071 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1074 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1076 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1078 expect2(10, 5, position.x, position.y);
1080 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1082 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1084 expect2(0, 0, position.x, position.y);
1086 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1088 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1090 expect2(20, 20, position.x, position.y);
1092 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1094 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1095 DestroyWindow(hwnd);
1098 static void test_getorigin(void)
1106 position.x = position.y = 0;
1108 hwnd = create_custom_listview_control(LVS_ICON);
1109 ok(hwnd != NULL, "failed to create a listview window\n");
1110 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1111 trace("test get origin results\n");
1112 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1114 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1115 DestroyWindow(hwnd);
1117 hwnd = create_custom_listview_control(LVS_SMALLICON);
1118 ok(hwnd != NULL, "failed to create a listview window\n");
1119 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1120 trace("test get origin results\n");
1121 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1123 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1124 DestroyWindow(hwnd);
1126 hwnd = create_custom_listview_control(LVS_LIST);
1127 ok(hwnd != NULL, "failed to create a listview window\n");
1128 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1129 trace("test get origin results\n");
1130 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1132 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1133 DestroyWindow(hwnd);
1135 hwnd = create_custom_listview_control(LVS_REPORT);
1136 ok(hwnd != NULL, "failed to create a listview window\n");
1137 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1138 trace("test get origin results\n");
1139 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1141 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1142 DestroyWindow(hwnd);
1146 static void test_multiselect(void)
1148 typedef struct t_select_task
1159 int i,j,item_count,selected_count;
1160 static const int items=5;
1164 static struct t_select_task task_list[] = {
1165 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1166 { "using VK_UP", -1, VK_UP, -1, -1 },
1167 { "using VK_END", 0, VK_END, 1, -1 },
1168 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1172 hwnd = create_listview_control();
1174 for (i=0;i<items;i++) {
1175 insert_item(hwnd, 0);
1178 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1180 expect(items,item_count);
1183 task = task_list[i];
1185 /* deselect all items */
1186 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1187 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1189 /* set initial position */
1190 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1191 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1193 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1195 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1197 /* Set SHIFT key pressed */
1198 GetKeyboardState(kstate);
1199 kstate[VK_SHIFT]=0x80;
1200 SetKeyboardState(kstate);
1202 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1203 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1205 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1209 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1211 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);
1213 /* Set SHIFT key released */
1214 GetKeyboardState(kstate);
1215 kstate[VK_SHIFT]=0x00;
1216 SetKeyboardState(kstate);
1218 DestroyWindow(hwnd);
1221 START_TEST(listview)
1224 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1226 hComctl32 = GetModuleHandleA("comctl32.dll");
1227 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1228 if (pInitCommonControlsEx)
1230 INITCOMMONCONTROLSEX iccex;
1231 iccex.dwSize = sizeof(iccex);
1232 iccex.dwICC = ICC_LISTVIEW_CLASSES;
1233 pInitCommonControlsEx(&iccex);
1236 InitCommonControls();
1238 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1240 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1241 hwndparent = create_parent_window();
1242 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent window", TRUE);
1243 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1251 test_icon_spacing();
1254 test_item_position();