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, MAKELPARAM(20, 30) },
82 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
83 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-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 /* log system messages, except for painting */
161 if (message < WM_USER &&
162 message != WM_PAINT &&
163 message != WM_ERASEBKGND &&
164 message != WM_NCPAINT &&
165 message != WM_NCHITTEST &&
166 message != WM_GETTEXT &&
167 message != WM_GETICON &&
168 message != WM_DEVICECHANGE)
170 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
172 msg.message = message;
173 msg.flags = sent|wparam|lparam;
174 if (defwndproc_counter) msg.flags |= defwinproc;
177 add_message(sequences, PARENT_SEQ_INDEX, &msg);
180 defwndproc_counter++;
181 ret = DefWindowProcA(hwnd, message, wParam, lParam);
182 defwndproc_counter--;
187 static BOOL register_parent_wnd_class(void)
192 cls.lpfnWndProc = parent_wnd_proc;
195 cls.hInstance = GetModuleHandleA(NULL);
197 cls.hCursor = LoadCursorA(0, IDC_ARROW);
198 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
199 cls.lpszMenuName = NULL;
200 cls.lpszClassName = "Listview test parent class";
201 return RegisterClassA(&cls);
204 static HWND create_parent_window(void)
206 if (!register_parent_wnd_class())
209 return CreateWindowEx(0, "Listview test parent class",
210 "Listview test parent window",
211 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
212 WS_MAXIMIZEBOX | WS_VISIBLE,
214 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
217 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
219 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
220 static LONG defwndproc_counter = 0;
224 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
226 msg.message = message;
227 msg.flags = sent|wparam|lparam;
228 if (defwndproc_counter) msg.flags |= defwinproc;
231 msg.id = LISTVIEW_ID;
232 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
234 defwndproc_counter++;
235 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
236 defwndproc_counter--;
240 static HWND create_listview_control(void)
242 struct subclass_info *info;
246 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
250 GetClientRect(hwndparent, &rect);
251 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
252 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
253 0, 0, rect.right, rect.bottom,
254 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
255 ok(hwnd != NULL, "gle=%d\n", GetLastError());
259 HeapFree(GetProcessHeap(), 0, info);
263 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
264 (LONG_PTR)listview_subclass_proc);
265 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
270 static HWND create_custom_listview_control(DWORD style)
272 struct subclass_info *info;
276 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
280 GetClientRect(hwndparent, &rect);
281 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
282 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
283 0, 0, rect.right, rect.bottom,
284 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
285 ok(hwnd != NULL, "gle=%d\n", GetLastError());
289 HeapFree(GetProcessHeap(), 0, info);
293 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
294 (LONG_PTR)listview_subclass_proc);
295 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
300 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
302 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
303 static LONG defwndproc_counter = 0;
307 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
309 msg.message = message;
310 msg.flags = sent|wparam|lparam;
311 if (defwndproc_counter) msg.flags |= defwinproc;
315 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
317 defwndproc_counter++;
318 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
319 defwndproc_counter--;
323 static HWND subclass_header(HWND hwndListview)
325 struct subclass_info *info;
328 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
332 hwnd = ListView_GetHeader(hwndListview);
333 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
334 (LONG_PTR)header_subclass_proc);
335 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
340 static void test_images(void)
348 static CHAR hello[] = "hello";
350 himl = ImageList_Create(40, 40, 0, 4, 4);
351 ok(himl != NULL, "failed to create imagelist\n");
353 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
354 ok(hbmp != NULL, "failed to create bitmap\n");
356 r = ImageList_Add(himl, hbmp, 0);
357 ok(r == 0, "should be zero\n");
359 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
360 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
361 ok(hwnd != NULL, "failed to create listview window\n");
363 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, 0x940);
364 ok(r == 0, "should return zero\n");
366 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
367 ok(r == 0, "should return zero\n");
369 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
370 /* returns dimensions */
372 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
373 ok(r == 0, "should be zero items\n");
375 item.mask = LVIF_IMAGE | LVIF_TEXT;
380 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
381 ok(r == -1, "should fail\n");
384 item.pszText = hello;
385 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
386 ok(r == 0, "should not fail\n");
388 memset(&r1, 0, sizeof r1);
390 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
392 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
393 ok(r == TRUE, "should not fail\n");
396 item.pszText = hello;
397 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
398 ok(r == 0, "should not fail\n");
400 memset(&r2, 0, sizeof r2);
402 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
404 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
409 static void test_checkboxes(void)
414 static CHAR text[] = "Text",
418 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
419 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
420 ok(hwnd != NULL, "failed to create listview window\n");
422 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
423 item.mask = LVIF_TEXT | LVIF_STATE;
424 item.stateMask = 0xffff;
429 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
430 ok(r == 0, "ret %d\n", r);
433 item.mask = LVIF_STATE;
434 item.stateMask = 0xffff;
435 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
436 ok(item.state == 0xfccc, "state %x\n", item.state);
438 /* Don't set LVIF_STATE */
439 item.mask = LVIF_TEXT;
440 item.stateMask = 0xffff;
445 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
446 ok(r == 1, "ret %d\n", r);
449 item.mask = LVIF_STATE;
450 item.stateMask = 0xffff;
451 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
452 ok(item.state == 0, "state %x\n", item.state);
454 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
455 ok(r == 0, "should return zero\n");
457 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
459 item.mask = LVIF_STATE;
460 item.stateMask = 0xffff;
461 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
462 ok(item.state == 0x1ccc, "state %x\n", item.state);
464 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
466 item.mask = LVIF_TEXT;
468 item.pszText = text2;
469 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
470 ok(r == 2, "ret %d\n", r);
473 item.mask = LVIF_STATE;
474 item.stateMask = 0xffff;
475 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
476 ok(item.state == 0x1000, "state %x\n", item.state);
478 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
480 item.mask = LVIF_TEXT | LVIF_STATE;
481 item.stateMask = 0xffff;
483 item.pszText = text3;
484 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
485 ok(r == 3, "ret %d\n", r);
488 item.mask = LVIF_STATE;
489 item.stateMask = 0xffff;
490 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
491 ok(item.state == 0x1aaa, "state %x\n", item.state);
493 /* Set an item's state to checked */
495 item.mask = LVIF_STATE;
496 item.stateMask = 0xf000;
498 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
501 item.mask = LVIF_STATE;
502 item.stateMask = 0xffff;
503 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
504 ok(item.state == 0x2aaa, "state %x\n", item.state);
506 /* Check that only the bits we asked for are returned,
507 * and that all the others are set to zero
510 item.mask = LVIF_STATE;
511 item.stateMask = 0xf000;
513 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
514 ok(item.state == 0x2000, "state %x\n", item.state);
516 /* Set the style again and check that doesn't change an item's state */
517 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
518 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
521 item.mask = LVIF_STATE;
522 item.stateMask = 0xffff;
523 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
524 ok(item.state == 0x2aaa, "state %x\n", item.state);
526 /* Unsetting the checkbox extended style doesn't change an item's state */
527 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
528 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
531 item.mask = LVIF_STATE;
532 item.stateMask = 0xffff;
533 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
534 ok(item.state == 0x2aaa, "state %x\n", item.state);
536 /* Now setting the style again will change an item's state */
537 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
538 ok(r == 0, "ret %x\n", r);
541 item.mask = LVIF_STATE;
542 item.stateMask = 0xffff;
543 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
544 ok(item.state == 0x1aaa, "state %x\n", item.state);
546 /* Toggle checkbox tests (bug 9934) */
547 memset (&item, 0xcc, sizeof(item));
548 item.mask = LVIF_STATE;
551 item.state = LVIS_FOCUSED;
552 item.stateMask = LVIS_FOCUSED;
553 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
557 item.mask = LVIF_STATE;
558 item.stateMask = 0xffff;
559 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
560 ok(item.state == 0x1aab, "state %x\n", item.state);
562 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
564 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
568 item.mask = LVIF_STATE;
569 item.stateMask = 0xffff;
570 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
571 ok(item.state == 0x2aab, "state %x\n", item.state);
573 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
575 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
579 item.mask = LVIF_STATE;
580 item.stateMask = 0xffff;
581 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
582 ok(item.state == 0x1aab, "state %x\n", item.state);
587 static void insert_column(HWND hwnd, int idx)
592 memset(&column, 0xcc, sizeof(column));
593 column.mask = LVCF_SUBITEM;
594 column.iSubItem = idx;
596 rc = ListView_InsertColumn(hwnd, idx, &column);
600 static void insert_item(HWND hwnd, int idx)
602 static CHAR text[] = "foo";
607 memset(&item, 0xcc, sizeof (item));
608 item.mask = LVIF_TEXT;
613 rc = ListView_InsertItem(hwnd, &item);
617 static void test_items(void)
619 const LPARAM lparamTest = 0x42;
623 static CHAR text[] = "Text";
625 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
626 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
627 ok(hwnd != NULL, "failed to create listview window\n");
630 * Test setting/getting item params
633 /* Set up two columns */
634 insert_column(hwnd, 0);
635 insert_column(hwnd, 1);
637 /* Insert an item with just a param */
638 memset (&item, 0xcc, sizeof (item));
639 item.mask = LVIF_PARAM;
642 item.lParam = lparamTest;
643 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
644 ok(r == 0, "ret %d\n", r);
646 /* Test getting of the param */
647 memset (&item, 0xcc, sizeof (item));
648 item.mask = LVIF_PARAM;
651 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
652 ok(r != 0, "ret %d\n", r);
653 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
655 /* Set up a subitem */
656 memset (&item, 0xcc, sizeof (item));
657 item.mask = LVIF_TEXT;
661 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
662 ok(r != 0, "ret %d\n", r);
664 /* Query param from subitem: returns main item param */
665 memset (&item, 0xcc, sizeof (item));
666 item.mask = LVIF_PARAM;
669 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
670 ok(r != 0, "ret %d\n", r);
671 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
673 /* Set up param on first subitem: no effect */
674 memset (&item, 0xcc, sizeof (item));
675 item.mask = LVIF_PARAM;
678 item.lParam = lparamTest+1;
679 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
680 ok(r == 0, "ret %d\n", r);
682 /* Query param from subitem again: should still return main item param */
683 memset (&item, 0xcc, sizeof (item));
684 item.mask = LVIF_PARAM;
687 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
688 ok(r != 0, "ret %d\n", r);
689 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
691 /**** Some tests of state highlighting ****/
692 memset (&item, 0xcc, sizeof (item));
693 item.mask = LVIF_STATE;
696 item.state = LVIS_SELECTED;
697 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
698 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
699 ok(r != 0, "ret %d\n", r);
701 item.state = LVIS_DROPHILITED;
702 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
703 ok(r != 0, "ret %d\n", r);
705 memset (&item, 0xcc, sizeof (item));
706 item.mask = LVIF_STATE;
710 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
711 ok(r != 0, "ret %d\n", r);
712 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
714 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
715 ok(r != 0, "ret %d\n", r);
716 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
721 static void test_columns(void)
727 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
728 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
729 ok(hwnd != NULL, "failed to create listview window\n");
731 /* Add a column with no mask */
732 memset(&column, 0xcc, sizeof(column));
734 rc = ListView_InsertColumn(hwnd, 0, &column);
735 ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
737 /* Check its width */
738 rc = ListView_GetColumnWidth(hwnd, 0);
740 broken(rc==0), /* win9x */
741 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
745 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
746 static WNDPROC listviewWndProc;
747 static HIMAGELIST test_create_imagelist;
749 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
753 if (uMsg == WM_CREATE)
755 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
756 lpcs->style |= LVS_REPORT;
758 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
759 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
763 static void test_create(void)
771 cls.cbSize = sizeof(WNDCLASSEX);
772 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
773 listviewWndProc = cls.lpfnWndProc;
774 cls.lpfnWndProc = create_test_wndproc;
775 cls.lpszClassName = "MyListView32";
776 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
778 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
779 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
780 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
781 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
782 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
783 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
784 DestroyWindow(hList);
786 /* header isn't created on LVS_ICON and LVS_LIST styles */
787 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
788 GetModuleHandle(NULL), 0);
789 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
790 todo_wine ok(!IsWindow(hHeader), "Header shouldn't be created\n");
791 todo_wine ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
793 memset(&col, 0, sizeof(LVCOLUMNA));
794 col.mask = LVCF_WIDTH;
796 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
797 ok(r == 0, "Expected 0 column's inserted\n");
798 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
799 ok(IsWindow(hHeader), "Header should be created\n");
800 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
801 DestroyWindow(hList);
803 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
804 GetModuleHandle(NULL), 0);
805 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
806 todo_wine ok(!IsWindow(hHeader), "Header shouldn't be created\n");
807 todo_wine ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
809 memset(&col, 0, sizeof(LVCOLUMNA));
810 col.mask = LVCF_WIDTH;
812 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
813 ok(r == 0, "Expected 0 column's inserted\n");
814 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
815 ok(IsWindow(hHeader), "Header should be created\n");
816 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
817 DestroyWindow(hList);
819 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
820 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
821 GetModuleHandle(NULL), 0);
822 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
823 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
824 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
825 ok(IsWindow(hHeader), "Header should be created\n");
826 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
827 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
828 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
829 ok(IsWindow(hHeader), "Header should be created\n");
830 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
831 DestroyWindow(hList);
833 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
834 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
835 GetModuleHandle(NULL), 0);
836 ret = SetWindowLongPtr(hList, GWL_STYLE,
837 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
838 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
839 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
840 ok(IsWindow(hHeader), "Header shouldn't be created\n");
841 ok(hHeader == GetDlgItem(hList, 0), "NULL dialog item expected\n");
842 ret = SetWindowLongPtr(hList, GWL_STYLE,
843 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
844 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
845 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
846 ok(IsWindow(hHeader), "Header shouldn't be created\n");
847 ok(hHeader == GetDlgItem(hList, 0), "NULL dialog item expected\n");
848 DestroyWindow(hList);
850 /* LVS_REPORT without WS_VISIBLE */
851 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
852 GetModuleHandle(NULL), 0);
853 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
854 todo_wine ok(!IsWindow(hHeader), "Header shouldn't be created\n");
855 todo_wine ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
857 memset(&col, 0, sizeof(LVCOLUMNA));
858 col.mask = LVCF_WIDTH;
860 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
861 ok(r == 0, "Expected 0 column's inserted\n");
862 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
863 ok(IsWindow(hHeader), "Header should be created\n");
864 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
865 DestroyWindow(hList);
867 /* LVS_REPORT without WS_VISIBLE, try to show it */
868 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
869 GetModuleHandle(NULL), 0);
870 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
871 todo_wine ok(!IsWindow(hHeader), "Header shouldn't be created\n");
872 todo_wine ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
873 ShowWindow(hList, SW_SHOW);
874 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
875 ok(IsWindow(hHeader), "Header shouldn't be created\n");
876 ok(hHeader == GetDlgItem(hList, 0), "NULL dialog item expected\n");
877 DestroyWindow(hList);
880 static void test_redraw(void)
882 HWND hwnd, hwndheader;
884 hwnd = create_listview_control();
885 hwndheader = subclass_header(hwnd);
887 flush_sequences(sequences, NUM_MSG_SEQUENCES);
889 trace("invalidate & update\n");
890 InvalidateRect(hwnd, NULL, TRUE);
892 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
894 flush_sequences(sequences, NUM_MSG_SEQUENCES);
899 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
901 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
903 if(msg == WM_NOTIFY) {
904 NMHDR *nmhdr = (PVOID)lp;
905 if(nmhdr->code == NM_CUSTOMDRAW) {
906 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
907 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
908 switch(nmlvcd->nmcd.dwDrawStage) {
910 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
911 return CDRF_NOTIFYITEMDRAW;
912 case CDDS_ITEMPREPAINT:
913 nmlvcd->clrTextBk = CLR_DEFAULT;
914 return CDRF_NOTIFYSUBITEMDRAW;
915 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
916 clr = GetBkColor(nmlvcd->nmcd.hdc);
917 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
918 return CDRF_NOTIFYPOSTPAINT;
919 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
920 clr = GetBkColor(nmlvcd->nmcd.hdc);
921 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
922 return CDRF_DODEFAULT;
924 return CDRF_DODEFAULT;
928 return DefWindowProcA(hwnd, msg, wp, lp);
931 static void test_customdraw(void)
936 hwnd = create_listview_control();
938 insert_column(hwnd, 0);
939 insert_column(hwnd, 1);
940 insert_item(hwnd, 0);
942 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
943 (LONG_PTR)cd_wndproc);
945 InvalidateRect(hwnd, NULL, TRUE);
948 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
953 static void test_icon_spacing(void)
955 /* LVM_SETICONSPACING */
956 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
962 hwnd = create_custom_listview_control(LVS_ICON);
963 ok(hwnd != NULL, "failed to create a listview window\n");
965 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
968 /* reset the icon spacing to defaults */
969 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
971 /* now we can request what the defaults are */
972 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
976 flush_sequences(sequences, NUM_MSG_SEQUENCES);
978 trace("test icon spacing\n");
980 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
981 ok(r == MAKELONG(w, h) ||
982 broken(r == MAKELONG(w, w)), /* win98 */
983 "Expected %d, got %d\n", MAKELONG(w, h), r);
985 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
986 expect(MAKELONG(20,30), r);
988 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
989 expect(MAKELONG(25,35), r);
991 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
993 flush_sequences(sequences, NUM_MSG_SEQUENCES);
997 static void test_color(void)
999 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1006 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1008 hwnd = create_listview_control();
1009 ok(hwnd != NULL, "failed to create a listview window\n");
1011 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1013 trace("test color seq\n");
1014 for (i = 0; i < 4; i++)
1018 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1020 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1023 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1025 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1028 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1030 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1034 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1036 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1037 DestroyWindow(hwnd);
1040 static void test_item_count(void)
1042 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1050 static CHAR item0text[] = "item0";
1051 static CHAR item1text[] = "item1";
1052 static CHAR item2text[] = "item2";
1054 hwnd = create_listview_control();
1055 ok(hwnd != NULL, "failed to create a listview window\n");
1057 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1059 trace("test item count\n");
1061 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1065 item0.mask = LVIF_TEXT;
1068 item0.pszText = item0text;
1069 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1072 /* [item0, item1] */
1073 item1.mask = LVIF_TEXT;
1076 item1.pszText = item1text;
1077 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1080 /* [item0, item1, item2] */
1081 item2.mask = LVIF_TEXT;
1084 item2.pszText = item2text;
1085 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1088 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1091 /* [item0, item1] */
1092 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1095 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1099 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1102 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1106 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1109 /* [item0, item1] */
1110 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1113 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1116 /* [item0, item1, item2] */
1117 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1120 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1123 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1125 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1126 DestroyWindow(hwnd);
1129 static void test_item_position(void)
1131 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1140 static CHAR item0text[] = "item0";
1141 static CHAR item1text[] = "item1";
1142 static CHAR item2text[] = "item2";
1144 hwnd = create_custom_listview_control(LVS_ICON);
1145 ok(hwnd != NULL, "failed to create a listview window\n");
1147 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1149 trace("test item position\n");
1152 item0.mask = LVIF_TEXT;
1155 item0.pszText = item0text;
1156 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1159 /* [item0, item1] */
1160 item1.mask = LVIF_TEXT;
1163 item1.pszText = item1text;
1164 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1167 /* [item0, item1, item2] */
1168 item2.mask = LVIF_TEXT;
1171 item2.pszText = item2text;
1172 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1175 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1177 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1179 expect2(10, 5, position.x, position.y);
1181 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1183 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1185 expect2(0, 0, position.x, position.y);
1187 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1189 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1191 expect2(20, 20, position.x, position.y);
1193 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1195 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1196 DestroyWindow(hwnd);
1199 static void test_getorigin(void)
1207 position.x = position.y = 0;
1209 hwnd = create_custom_listview_control(LVS_ICON);
1210 ok(hwnd != NULL, "failed to create a listview window\n");
1211 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1212 trace("test get origin results\n");
1213 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1215 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1216 DestroyWindow(hwnd);
1218 hwnd = create_custom_listview_control(LVS_SMALLICON);
1219 ok(hwnd != NULL, "failed to create a listview window\n");
1220 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1221 trace("test get origin results\n");
1222 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1224 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1225 DestroyWindow(hwnd);
1227 hwnd = create_custom_listview_control(LVS_LIST);
1228 ok(hwnd != NULL, "failed to create a listview window\n");
1229 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1230 trace("test get origin results\n");
1231 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1233 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1234 DestroyWindow(hwnd);
1236 hwnd = create_custom_listview_control(LVS_REPORT);
1237 ok(hwnd != NULL, "failed to create a listview window\n");
1238 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1239 trace("test get origin results\n");
1240 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1242 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1243 DestroyWindow(hwnd);
1247 static void test_multiselect(void)
1249 typedef struct t_select_task
1260 int i,j,item_count,selected_count;
1261 static const int items=5;
1265 static struct t_select_task task_list[] = {
1266 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1267 { "using VK_UP", -1, VK_UP, -1, -1 },
1268 { "using VK_END", 0, VK_END, 1, -1 },
1269 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1273 hwnd = create_listview_control();
1275 for (i=0;i<items;i++) {
1276 insert_item(hwnd, 0);
1279 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1281 expect(items,item_count);
1284 task = task_list[i];
1286 /* deselect all items */
1287 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1288 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1290 /* set initial position */
1291 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1292 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1294 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1296 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1298 /* Set SHIFT key pressed */
1299 GetKeyboardState(kstate);
1300 kstate[VK_SHIFT]=0x80;
1301 SetKeyboardState(kstate);
1303 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1304 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1306 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1310 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1312 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);
1314 /* Set SHIFT key released */
1315 GetKeyboardState(kstate);
1316 kstate[VK_SHIFT]=0x00;
1317 SetKeyboardState(kstate);
1319 DestroyWindow(hwnd);
1322 static void test_subitem_rect(void)
1329 /* test LVM_GETSUBITEMRECT for header */
1330 hwnd = create_listview_control();
1331 ok(hwnd != NULL, "failed to create a listview window\n");
1332 /* add some columns */
1333 memset(&col, 0, sizeof(LVCOLUMN));
1334 col.mask = LVCF_WIDTH;
1337 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1341 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
1345 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
1347 /* item = -1 means header, subitem index is 1 based */
1348 rect.left = LVIR_BOUNDS;
1350 rect.right = rect.bottom = 0;
1351 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1354 rect.left = LVIR_BOUNDS;
1356 rect.right = rect.bottom = 0;
1357 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1359 ok(r != 0, "Expected not-null LRESULT\n");
1360 expect(100, rect.left);
1361 expect(250, rect.right);
1362 expect(3, rect.top);
1364 rect.left = LVIR_BOUNDS;
1366 rect.right = rect.bottom = 0;
1367 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1369 ok(r != 0, "Expected not-null LRESULT\n");
1370 expect(250, rect.left);
1371 expect(450, rect.right);
1372 expect(3, rect.top);
1375 DestroyWindow(hwnd);
1378 START_TEST(listview)
1381 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1383 hComctl32 = GetModuleHandleA("comctl32.dll");
1384 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1385 if (pInitCommonControlsEx)
1387 INITCOMMONCONTROLSEX iccex;
1388 iccex.dwSize = sizeof(iccex);
1389 iccex.dwICC = ICC_LISTVIEW_CLASSES;
1390 pInitCommonControlsEx(&iccex);
1393 InitCommonControls();
1395 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1397 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1398 hwndparent = create_parent_window();
1399 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent window", TRUE);
1400 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1408 test_icon_spacing();
1411 test_item_position();
1415 test_subitem_rect();