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 PARENT_FULL_SEQ_INDEX 1
31 #define LISTVIEW_SEQ_INDEX 2
32 #define EDITBOX_SEQ_INDEX 3
33 #define NUM_MSG_SEQUENCES 4
38 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
39 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
40 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
44 #elif defined __x86_64__
50 static const CHAR manifest_name[] = "cc6.manifest";
52 static const CHAR manifest[] =
53 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
54 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">\n"
55 " <assemblyIdentity\n"
57 " name=\"Wine.ComCtl32.Tests\"\n"
58 " version=\"1.0.0.0\"\n"
59 " processorArchitecture=\"" ARCH "\"\n"
61 "<description>Wine comctl32 test suite</description>\n"
63 " <dependentAssembly>\n"
64 " <assemblyIdentity\n"
66 " name=\"microsoft.windows.common-controls\"\n"
67 " version=\"6.0.0.0\"\n"
68 " processorArchitecture=\"" ARCH "\"\n"
69 " publicKeyToken=\"6595b64144ccf1df\"\n"
72 "</dependentAssembly>\n"
76 static const WCHAR testparentclassW[] =
77 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
79 HWND hwndparent, hwndparentW;
80 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
82 /* format reported to control:
83 -1 falls to defproc, anything else returned */
85 /* indicates we're running < 5.80 version */
88 static HWND subclass_editbox(HWND hwndListview);
90 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
92 static const struct message create_parent_wnd_seq[] = {
93 { WM_GETMINMAXINFO, sent },
94 { WM_NCCREATE, sent },
95 { WM_NCCALCSIZE, sent|wparam, 0 },
97 { WM_SHOWWINDOW, sent|wparam, 1 },
98 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
99 { WM_QUERYNEWPALETTE, sent|optional },
100 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
101 { WM_WINDOWPOSCHANGED, sent|optional },
102 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
103 { WM_ACTIVATEAPP, sent|wparam, 1 },
104 { WM_NCACTIVATE, sent|wparam, 1 },
105 { WM_ACTIVATE, sent|wparam, 1 },
106 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
107 { WM_IME_NOTIFY, sent|defwinproc|optional },
108 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
109 /* Win9x adds SWP_NOZORDER below */
110 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
111 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
117 static const struct message redraw_listview_seq[] = {
118 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
119 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
120 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
121 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, HEADER_ID },
122 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
123 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
124 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
128 static const struct message listview_icon_spacing_seq[] = {
129 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
130 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
131 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
135 static const struct message listview_color_seq[] = {
136 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
137 { LVM_GETBKCOLOR, sent },
138 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
139 { LVM_GETTEXTCOLOR, sent },
140 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
141 { LVM_GETTEXTBKCOLOR, sent },
143 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
144 { LVM_GETBKCOLOR, sent },
145 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
146 { LVM_GETTEXTCOLOR, sent },
147 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
148 { LVM_GETTEXTBKCOLOR, sent },
150 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
151 { LVM_GETBKCOLOR, sent },
152 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
153 { LVM_GETTEXTCOLOR, sent },
154 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
155 { LVM_GETTEXTBKCOLOR, sent },
157 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
158 { LVM_GETBKCOLOR, sent },
159 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
160 { LVM_GETTEXTCOLOR, sent },
161 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
162 { LVM_GETTEXTBKCOLOR, sent },
166 static const struct message listview_item_count_seq[] = {
167 { LVM_GETITEMCOUNT, sent },
168 { LVM_INSERTITEM, sent },
169 { LVM_INSERTITEM, sent },
170 { LVM_INSERTITEM, sent },
171 { LVM_GETITEMCOUNT, sent },
172 { LVM_DELETEITEM, sent|wparam, 2 },
173 { LVM_GETITEMCOUNT, sent },
174 { LVM_DELETEALLITEMS, sent },
175 { LVM_GETITEMCOUNT, sent },
176 { LVM_INSERTITEM, sent },
177 { LVM_INSERTITEM, sent },
178 { LVM_GETITEMCOUNT, sent },
179 { LVM_INSERTITEM, sent },
180 { LVM_GETITEMCOUNT, sent },
184 static const struct message listview_itempos_seq[] = {
185 { LVM_INSERTITEM, sent },
186 { LVM_INSERTITEM, sent },
187 { LVM_INSERTITEM, sent },
188 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
189 { LVM_GETITEMPOSITION, sent|wparam, 1 },
190 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
191 { LVM_GETITEMPOSITION, sent|wparam, 2 },
192 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
193 { LVM_GETITEMPOSITION, sent|wparam, 0 },
197 static const struct message listview_ownerdata_switchto_seq[] = {
198 { WM_STYLECHANGING, sent },
199 { WM_STYLECHANGED, sent },
203 static const struct message listview_getorderarray_seq[] = {
204 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
205 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
209 static const struct message empty_seq[] = {
213 static const struct message forward_erasebkgnd_parent_seq[] = {
214 { WM_ERASEBKGND, sent },
218 static const struct message ownderdata_select_focus_parent_seq[] = {
219 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
220 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
224 static const struct message textcallback_set_again_parent_seq[] = {
225 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
226 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
230 static const struct message single_getdispinfo_parent_seq[] = {
231 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
235 static const struct message getitemposition_seq1[] = {
236 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
240 static const struct message getitemposition_seq2[] = {
241 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
242 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
246 static const struct message editbox_create_pos[] = {
247 /* sequence sent after LVN_BEGINLABELEDIT */
248 { WM_WINDOWPOSCHANGING, sent },
249 { WM_NCCALCSIZE, sent },
250 { WM_WINDOWPOSCHANGED, sent },
251 { WM_MOVE, sent|defwinproc },
252 { WM_SIZE, sent|defwinproc },
253 /* the rest is todo */
254 { WM_WINDOWPOSCHANGING, sent },
255 { WM_WINDOWPOSCHANGED, sent },
264 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
266 static LONG defwndproc_counter = 0;
270 msg.message = message;
271 msg.flags = sent|wparam|lparam;
272 if (defwndproc_counter) msg.flags |= defwinproc;
275 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
277 /* log system messages, except for painting */
278 if (message < WM_USER &&
279 message != WM_PAINT &&
280 message != WM_ERASEBKGND &&
281 message != WM_NCPAINT &&
282 message != WM_NCHITTEST &&
283 message != WM_GETTEXT &&
284 message != WM_GETICON &&
285 message != WM_DEVICECHANGE)
287 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
289 add_message(sequences, PARENT_SEQ_INDEX, &msg);
291 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
297 switch (((NMHDR*)lParam)->code)
299 case LVN_BEGINLABELEDIT:
300 /* subclass edit box */
302 subclass_editbox(((NMHDR*)lParam)->hwndFrom);
306 case LVN_ENDLABELEDIT:
307 /* always accept new item text */
312 case WM_NOTIFYFORMAT:
314 /* force to return format */
315 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
320 defwndproc_counter++;
321 ret = DefWindowProcA(hwnd, message, wParam, lParam);
322 defwndproc_counter--;
327 static BOOL register_parent_wnd_class(BOOL Unicode)
335 clsW.lpfnWndProc = parent_wnd_proc;
338 clsW.hInstance = GetModuleHandleW(NULL);
340 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
341 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
342 clsW.lpszMenuName = NULL;
343 clsW.lpszClassName = testparentclassW;
348 clsA.lpfnWndProc = parent_wnd_proc;
351 clsA.hInstance = GetModuleHandleA(NULL);
353 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
354 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
355 clsA.lpszMenuName = NULL;
356 clsA.lpszClassName = "Listview test parent class";
359 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
362 static HWND create_parent_window(BOOL Unicode)
364 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W'};
366 if (!register_parent_wnd_class(Unicode))
373 return CreateWindowExW(0, testparentclassW, nameW,
374 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
375 WS_MAXIMIZEBOX | WS_VISIBLE,
377 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
379 return CreateWindowExA(0, "Listview test parent class",
380 "Listview test parent window",
381 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
382 WS_MAXIMIZEBOX | WS_VISIBLE,
384 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
387 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
389 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
390 static LONG defwndproc_counter = 0;
394 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
396 /* some debug output for style changing */
397 if ((message == WM_STYLECHANGING ||
398 message == WM_STYLECHANGED) && lParam)
400 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
401 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
404 msg.message = message;
405 msg.flags = sent|wparam|lparam;
406 if (defwndproc_counter) msg.flags |= defwinproc;
409 msg.id = LISTVIEW_ID;
410 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
412 defwndproc_counter++;
413 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
414 defwndproc_counter--;
418 static HWND create_listview_control(DWORD style)
420 struct subclass_info *info;
424 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
428 GetClientRect(hwndparent, &rect);
429 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
430 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
431 0, 0, rect.right, rect.bottom,
432 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
433 ok(hwnd != NULL, "gle=%d\n", GetLastError());
437 HeapFree(GetProcessHeap(), 0, info);
441 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
442 (LONG_PTR)listview_subclass_proc);
443 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
448 /* unicode listview window with specified parent */
449 static HWND create_listview_controlW(DWORD style, HWND parent)
451 struct subclass_info *info;
454 static const WCHAR nameW[] = {'f','o','o',0};
456 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
460 GetClientRect(parent, &rect);
461 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
462 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
463 0, 0, rect.right, rect.bottom,
464 parent, NULL, GetModuleHandleW(NULL), NULL);
465 ok(hwnd != NULL, "gle=%d\n", GetLastError());
469 HeapFree(GetProcessHeap(), 0, info);
473 info->oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
474 (LONG_PTR)listview_subclass_proc);
475 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)info);
480 static HWND create_custom_listview_control(DWORD style)
482 struct subclass_info *info;
486 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
490 GetClientRect(hwndparent, &rect);
491 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
492 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
493 0, 0, rect.right, rect.bottom,
494 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
495 ok(hwnd != NULL, "gle=%d\n", GetLastError());
499 HeapFree(GetProcessHeap(), 0, info);
503 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
504 (LONG_PTR)listview_subclass_proc);
505 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
510 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
512 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
513 static LONG defwndproc_counter = 0;
517 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
519 msg.message = message;
520 msg.flags = sent|wparam|lparam;
521 if (defwndproc_counter) msg.flags |= defwinproc;
525 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
527 defwndproc_counter++;
528 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
529 defwndproc_counter--;
533 static HWND subclass_header(HWND hwndListview)
535 struct subclass_info *info;
538 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
542 hwnd = ListView_GetHeader(hwndListview);
543 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
544 (LONG_PTR)header_subclass_proc);
545 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
550 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
552 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
553 static LONG defwndproc_counter = 0;
557 msg.message = message;
558 msg.flags = sent|wparam|lparam;
559 if (defwndproc_counter) msg.flags |= defwinproc;
563 /* all we need is sizing */
564 if (message == WM_WINDOWPOSCHANGING ||
565 message == WM_NCCALCSIZE ||
566 message == WM_WINDOWPOSCHANGED ||
567 message == WM_MOVE ||
570 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
573 defwndproc_counter++;
574 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
575 defwndproc_counter--;
579 static HWND subclass_editbox(HWND hwndListview)
581 struct subclass_info *info;
584 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
588 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
589 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
590 (LONG_PTR)editbox_subclass_proc);
591 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
596 /* Performs a single LVM_HITTEST test */
597 static void test_lvm_hittest(HWND hwnd, INT x, INT y, INT item, UINT flags,
598 BOOL todo_item, BOOL todo_flags, int line)
607 trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
608 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
614 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
615 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
616 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
621 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
622 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
623 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
629 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
632 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
635 /* Performs a single LVM_SUBITEMHITTEST test */
636 static void test_lvm_subitemhittest(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
637 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
645 trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
646 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
652 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
653 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
658 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
659 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
665 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
668 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
673 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
676 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
679 static void test_images(void)
687 static CHAR hello[] = "hello";
689 himl = ImageList_Create(40, 40, 0, 4, 4);
690 ok(himl != NULL, "failed to create imagelist\n");
692 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
693 ok(hbmp != NULL, "failed to create bitmap\n");
695 r = ImageList_Add(himl, hbmp, 0);
696 ok(r == 0, "should be zero\n");
698 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
699 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
700 ok(hwnd != NULL, "failed to create listview window\n");
702 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
703 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
705 ok(r == 0, "should return zero\n");
707 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
708 ok(r == 0, "should return zero\n");
710 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
711 /* returns dimensions */
713 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
714 ok(r == 0, "should be zero items\n");
716 item.mask = LVIF_IMAGE | LVIF_TEXT;
721 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
722 ok(r == -1, "should fail\n");
725 item.pszText = hello;
726 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
727 ok(r == 0, "should not fail\n");
729 memset(&r1, 0, sizeof r1);
731 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
733 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
734 ok(r == TRUE, "should not fail\n");
737 item.pszText = hello;
738 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
739 ok(r == 0, "should not fail\n");
741 memset(&r2, 0, sizeof r2);
743 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
745 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
750 static void test_checkboxes(void)
755 static CHAR text[] = "Text",
759 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
760 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
761 ok(hwnd != NULL, "failed to create listview window\n");
763 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
764 item.mask = LVIF_TEXT | LVIF_STATE;
765 item.stateMask = 0xffff;
770 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
771 ok(r == 0, "ret %d\n", r);
774 item.mask = LVIF_STATE;
775 item.stateMask = 0xffff;
776 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
777 ok(item.state == 0xfccc, "state %x\n", item.state);
779 /* Don't set LVIF_STATE */
780 item.mask = LVIF_TEXT;
781 item.stateMask = 0xffff;
786 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
787 ok(r == 1, "ret %d\n", r);
790 item.mask = LVIF_STATE;
791 item.stateMask = 0xffff;
792 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
793 ok(item.state == 0, "state %x\n", item.state);
795 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
796 ok(r == 0, "should return zero\n");
798 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
800 item.mask = LVIF_STATE;
801 item.stateMask = 0xffff;
802 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
803 ok(item.state == 0x1ccc, "state %x\n", item.state);
805 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
807 item.mask = LVIF_TEXT;
809 item.pszText = text2;
810 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
811 ok(r == 2, "ret %d\n", r);
814 item.mask = LVIF_STATE;
815 item.stateMask = 0xffff;
816 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
817 ok(item.state == 0x1000, "state %x\n", item.state);
819 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
821 item.mask = LVIF_TEXT | LVIF_STATE;
822 item.stateMask = 0xffff;
824 item.pszText = text3;
825 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
826 ok(r == 3, "ret %d\n", r);
829 item.mask = LVIF_STATE;
830 item.stateMask = 0xffff;
831 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
832 ok(item.state == 0x1aaa, "state %x\n", item.state);
834 /* Set an item's state to checked */
836 item.mask = LVIF_STATE;
837 item.stateMask = 0xf000;
839 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
842 item.mask = LVIF_STATE;
843 item.stateMask = 0xffff;
844 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
845 ok(item.state == 0x2aaa, "state %x\n", item.state);
847 /* Check that only the bits we asked for are returned,
848 * and that all the others are set to zero
851 item.mask = LVIF_STATE;
852 item.stateMask = 0xf000;
854 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
855 ok(item.state == 0x2000, "state %x\n", item.state);
857 /* Set the style again and check that doesn't change an item's state */
858 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
859 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
862 item.mask = LVIF_STATE;
863 item.stateMask = 0xffff;
864 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
865 ok(item.state == 0x2aaa, "state %x\n", item.state);
867 /* Unsetting the checkbox extended style doesn't change an item's state */
868 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
869 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
872 item.mask = LVIF_STATE;
873 item.stateMask = 0xffff;
874 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
875 ok(item.state == 0x2aaa, "state %x\n", item.state);
877 /* Now setting the style again will change an item's state */
878 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
879 ok(r == 0, "ret %x\n", r);
882 item.mask = LVIF_STATE;
883 item.stateMask = 0xffff;
884 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
885 ok(item.state == 0x1aaa, "state %x\n", item.state);
887 /* Toggle checkbox tests (bug 9934) */
888 memset (&item, 0xcc, sizeof(item));
889 item.mask = LVIF_STATE;
892 item.state = LVIS_FOCUSED;
893 item.stateMask = LVIS_FOCUSED;
894 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
898 item.mask = LVIF_STATE;
899 item.stateMask = 0xffff;
900 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
901 ok(item.state == 0x1aab, "state %x\n", item.state);
903 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
905 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
909 item.mask = LVIF_STATE;
910 item.stateMask = 0xffff;
911 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
912 ok(item.state == 0x2aab, "state %x\n", item.state);
914 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
916 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
920 item.mask = LVIF_STATE;
921 item.stateMask = 0xffff;
922 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
923 ok(item.state == 0x1aab, "state %x\n", item.state);
928 static void insert_column(HWND hwnd, int idx)
933 memset(&column, 0xcc, sizeof(column));
934 column.mask = LVCF_SUBITEM;
935 column.iSubItem = idx;
937 rc = ListView_InsertColumn(hwnd, idx, &column);
941 static void insert_item(HWND hwnd, int idx)
943 static CHAR text[] = "foo";
948 memset(&item, 0xcc, sizeof (item));
949 item.mask = LVIF_TEXT;
954 rc = ListView_InsertItem(hwnd, &item);
958 static void test_items(void)
960 const LPARAM lparamTest = 0x42;
964 static CHAR text[] = "Text";
966 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
967 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
968 ok(hwnd != NULL, "failed to create listview window\n");
971 * Test setting/getting item params
974 /* Set up two columns */
975 insert_column(hwnd, 0);
976 insert_column(hwnd, 1);
978 /* LVIS_SELECTED with zero stateMask */
980 memset (&item, 0, sizeof (item));
981 item.mask = LVIF_STATE;
982 item.state = LVIS_SELECTED;
986 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
987 ok(r == 0, "ret %d\n", r);
989 memset (&item, 0xcc, sizeof (item));
990 item.mask = LVIF_STATE;
991 item.stateMask = LVIS_SELECTED;
995 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
996 ok(r != 0, "ret %d\n", r);
997 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
998 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1000 /* LVIS_SELECTED with zero stateMask */
1002 memset (&item, 0, sizeof (item));
1003 item.mask = LVIF_STATE;
1004 item.state = LVIS_FOCUSED;
1008 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1009 ok(r == 0, "ret %d\n", r);
1011 memset (&item, 0xcc, sizeof (item));
1012 item.mask = LVIF_STATE;
1013 item.stateMask = LVIS_FOCUSED;
1017 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1018 ok(r != 0, "ret %d\n", r);
1019 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1020 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1022 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1024 memset (&item, 0, sizeof (item));
1025 item.mask = LVIF_STATE;
1026 item.state = LVIS_CUT;
1027 item.stateMask = LVIS_FOCUSED;
1030 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1031 ok(r == 0, "ret %d\n", r);
1033 memset (&item, 0xcc, sizeof (item));
1034 item.mask = LVIF_STATE;
1035 item.stateMask = LVIS_CUT;
1039 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1040 ok(r != 0, "ret %d\n", r);
1041 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1042 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1044 /* Insert an item with just a param */
1045 memset (&item, 0xcc, sizeof (item));
1046 item.mask = LVIF_PARAM;
1049 item.lParam = lparamTest;
1050 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1051 ok(r == 0, "ret %d\n", r);
1053 /* Test getting of the param */
1054 memset (&item, 0xcc, sizeof (item));
1055 item.mask = LVIF_PARAM;
1058 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1059 ok(r != 0, "ret %d\n", r);
1060 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1062 /* Set up a subitem */
1063 memset (&item, 0xcc, sizeof (item));
1064 item.mask = LVIF_TEXT;
1067 item.pszText = text;
1068 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1069 ok(r != 0, "ret %d\n", r);
1071 /* Query param from subitem: returns main item param */
1072 memset (&item, 0xcc, sizeof (item));
1073 item.mask = LVIF_PARAM;
1076 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1077 ok(r != 0, "ret %d\n", r);
1078 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1080 /* Set up param on first subitem: no effect */
1081 memset (&item, 0xcc, sizeof (item));
1082 item.mask = LVIF_PARAM;
1085 item.lParam = lparamTest+1;
1086 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1087 ok(r == 0, "ret %d\n", r);
1089 /* Query param from subitem again: should still return main item param */
1090 memset (&item, 0xcc, sizeof (item));
1091 item.mask = LVIF_PARAM;
1094 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1095 ok(r != 0, "ret %d\n", r);
1096 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1098 /**** Some tests of state highlighting ****/
1099 memset (&item, 0xcc, sizeof (item));
1100 item.mask = LVIF_STATE;
1103 item.state = LVIS_SELECTED;
1104 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1105 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1106 ok(r != 0, "ret %d\n", r);
1108 item.state = LVIS_DROPHILITED;
1109 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1110 ok(r != 0, "ret %d\n", r);
1112 memset (&item, 0xcc, sizeof (item));
1113 item.mask = LVIF_STATE;
1116 item.stateMask = -1;
1117 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1118 ok(r != 0, "ret %d\n", r);
1119 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1121 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1122 ok(r != 0, "ret %d\n", r);
1123 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1125 /* some notnull but meaningless masks */
1126 memset (&item, 0, sizeof(item));
1127 item.mask = LVIF_NORECOMPUTE;
1130 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1131 ok(r != 0, "ret %d\n", r);
1132 memset (&item, 0, sizeof(item));
1133 item.mask = LVIF_DI_SETITEM;
1136 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1137 ok(r != 0, "ret %d\n", r);
1139 /* set text to callback value already having it */
1140 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1142 memset (&item, 0, sizeof (item));
1143 item.mask = LVIF_TEXT;
1144 item.pszText = LPSTR_TEXTCALLBACK;
1146 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1147 ok(r == 0, "ret %d\n", r);
1148 memset (&item, 0, sizeof (item));
1150 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1152 item.pszText = LPSTR_TEXTCALLBACK;
1153 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1156 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1157 "check callback text comparison rule", FALSE);
1159 DestroyWindow(hwnd);
1162 static void test_columns(void)
1164 HWND hwnd, hwndheader;
1169 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1170 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1171 ok(hwnd != NULL, "failed to create listview window\n");
1173 /* Add a column with no mask */
1174 memset(&column, 0xcc, sizeof(column));
1176 rc = ListView_InsertColumn(hwnd, 0, &column);
1177 ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
1179 /* Check its width */
1180 rc = ListView_GetColumnWidth(hwnd, 0);
1182 broken(rc==0), /* win9x */
1183 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1185 DestroyWindow(hwnd);
1187 /* LVM_GETCOLUMNORDERARRAY */
1188 hwnd = create_listview_control(0);
1189 hwndheader = subclass_header(hwnd);
1191 memset(&column, 0, sizeof(column));
1192 column.mask = LVCF_WIDTH;
1194 rc = ListView_InsertColumn(hwnd, 0, &column);
1195 ok(rc == 0, "Inserting column failed with %d\n", rc);
1198 rc = ListView_InsertColumn(hwnd, 1, &column);
1199 ok(rc == 1, "Inserting column failed with %d\n", rc);
1201 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1203 rc = SendMessage(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1204 ok(rc != 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1205 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1206 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1208 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1210 DestroyWindow(hwnd);
1212 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1213 static WNDPROC listviewWndProc;
1214 static HIMAGELIST test_create_imagelist;
1216 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1220 if (uMsg == WM_CREATE)
1222 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1223 lpcs->style |= LVS_REPORT;
1225 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1226 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1230 static void test_create(void)
1239 cls.cbSize = sizeof(WNDCLASSEX);
1240 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1241 listviewWndProc = cls.lpfnWndProc;
1242 cls.lpfnWndProc = create_test_wndproc;
1243 cls.lpszClassName = "MyListView32";
1244 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1246 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1247 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1248 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1249 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1250 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1251 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1252 DestroyWindow(hList);
1254 /* header isn't created on LVS_ICON and LVS_LIST styles */
1255 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1256 GetModuleHandle(NULL), 0);
1257 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1258 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1259 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1261 memset(&col, 0, sizeof(LVCOLUMNA));
1262 col.mask = LVCF_WIDTH;
1264 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1265 ok(r == 0, "Expected 0 column's inserted\n");
1266 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1267 ok(IsWindow(hHeader), "Header should be created\n");
1268 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1269 DestroyWindow(hList);
1271 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1272 GetModuleHandle(NULL), 0);
1273 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1274 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1275 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1277 memset(&col, 0, sizeof(LVCOLUMNA));
1278 col.mask = LVCF_WIDTH;
1280 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1281 ok(r == 0, "Expected 0 column's inserted\n");
1282 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1283 ok(IsWindow(hHeader), "Header should be created\n");
1284 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1285 DestroyWindow(hList);
1287 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1288 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1289 GetModuleHandle(NULL), 0);
1290 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1291 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1292 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1293 ok(IsWindow(hHeader), "Header should be created\n");
1294 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1295 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1296 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1297 ok(IsWindow(hHeader), "Header should be created\n");
1298 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1299 DestroyWindow(hList);
1301 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1302 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1303 GetModuleHandle(NULL), 0);
1304 ret = SetWindowLongPtr(hList, GWL_STYLE,
1305 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1306 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1307 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1308 ok(IsWindow(hHeader), "Header should be created\n");
1309 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1310 ret = SetWindowLongPtr(hList, GWL_STYLE,
1311 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1312 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1313 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1314 ok(IsWindow(hHeader), "Header should be created\n");
1315 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1316 DestroyWindow(hList);
1318 /* LVS_REPORT without WS_VISIBLE */
1319 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1320 GetModuleHandle(NULL), 0);
1321 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1322 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1323 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1325 memset(&col, 0, sizeof(LVCOLUMNA));
1326 col.mask = LVCF_WIDTH;
1328 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1329 ok(r == 0, "Expected 0 column's inserted\n");
1330 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1331 ok(IsWindow(hHeader), "Header should be created\n");
1332 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1333 DestroyWindow(hList);
1335 /* LVS_REPORT without WS_VISIBLE, try to show it */
1336 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1337 GetModuleHandle(NULL), 0);
1338 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1339 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1340 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1341 ShowWindow(hList, SW_SHOW);
1342 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1343 ok(IsWindow(hHeader), "Header should be created\n");
1344 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1345 DestroyWindow(hList);
1347 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1348 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1349 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1350 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1351 ok(IsWindow(hHeader), "Header should be created\n");
1352 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1353 /* HDS_DRAGDROP set by default */
1354 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1355 DestroyWindow(hList);
1357 /* setting LVS_EX_HEADERDRAGDROP creates header */
1358 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1359 GetModuleHandle(NULL), 0);
1360 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1361 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1362 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1363 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1364 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1365 ok(IsWindow(hHeader), "Header should be created\n");
1366 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1367 DestroyWindow(hList);
1369 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1370 hList = create_custom_listview_control(0);
1371 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1372 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1373 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1374 DestroyWindow(hList);
1376 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1377 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1378 GetModuleHandle(NULL), 0);
1379 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1380 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1382 rect.left = LVIR_BOUNDS;
1384 rect.right = rect.bottom = -10;
1385 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1386 ok(r != 0, "Expected not-null LRESULT\n");
1388 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1389 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1390 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1392 DestroyWindow(hList);
1395 static void test_redraw(void)
1397 HWND hwnd, hwndheader;
1402 hwnd = create_listview_control(0);
1403 hwndheader = subclass_header(hwnd);
1405 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1407 trace("invalidate & update\n");
1408 InvalidateRect(hwnd, NULL, TRUE);
1410 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1412 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1414 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1415 /* 1. Without backbuffer */
1416 res = ListView_SetBkColor(hwnd, CLR_NONE);
1419 hdc = GetWindowDC(hwndparent);
1421 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1422 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1423 ok(r != 0, "Expected not zero result\n");
1424 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1425 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1427 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1430 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1431 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1432 ok(r != 0, "Expected not zero result\n");
1433 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1434 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1436 /* 2. With backbuffer */
1437 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1438 LVS_EX_DOUBLEBUFFER);
1439 res = ListView_SetBkColor(hwnd, CLR_NONE);
1442 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1443 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1444 ok(r != 0, "Expected not zero result\n");
1445 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1446 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1448 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1451 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1452 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1453 todo_wine ok(r != 0, "Expected not zero result\n");
1454 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1455 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1457 ReleaseDC(hwndparent, hdc);
1459 DestroyWindow(hwnd);
1462 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1464 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1466 if(msg == WM_NOTIFY) {
1467 NMHDR *nmhdr = (PVOID)lp;
1468 if(nmhdr->code == NM_CUSTOMDRAW) {
1469 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1470 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1471 switch(nmlvcd->nmcd.dwDrawStage) {
1473 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1474 return CDRF_NOTIFYITEMDRAW;
1475 case CDDS_ITEMPREPAINT:
1476 nmlvcd->clrTextBk = CLR_DEFAULT;
1477 return CDRF_NOTIFYSUBITEMDRAW;
1478 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1479 clr = GetBkColor(nmlvcd->nmcd.hdc);
1480 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1481 return CDRF_NOTIFYPOSTPAINT;
1482 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1483 clr = GetBkColor(nmlvcd->nmcd.hdc);
1484 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1485 return CDRF_DODEFAULT;
1487 return CDRF_DODEFAULT;
1491 return DefWindowProcA(hwnd, msg, wp, lp);
1494 static void test_customdraw(void)
1499 hwnd = create_listview_control(0);
1501 insert_column(hwnd, 0);
1502 insert_column(hwnd, 1);
1503 insert_item(hwnd, 0);
1505 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1506 (LONG_PTR)cd_wndproc);
1508 InvalidateRect(hwnd, NULL, TRUE);
1511 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1513 DestroyWindow(hwnd);
1516 static void test_icon_spacing(void)
1518 /* LVM_SETICONSPACING */
1519 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1525 hwnd = create_custom_listview_control(LVS_ICON);
1526 ok(hwnd != NULL, "failed to create a listview window\n");
1528 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
1529 expect(NFR_ANSI, r);
1531 /* reset the icon spacing to defaults */
1532 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1534 /* now we can request what the defaults are */
1535 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1539 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1541 trace("test icon spacing\n");
1543 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1544 ok(r == MAKELONG(w, h) ||
1545 broken(r == MAKELONG(w, w)), /* win98 */
1546 "Expected %d, got %d\n", MAKELONG(w, h), r);
1548 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1549 expect(MAKELONG(20,30), r);
1551 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1552 expect(MAKELONG(25,35), r);
1554 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1556 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1557 DestroyWindow(hwnd);
1560 static void test_color(void)
1562 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1569 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1571 hwnd = create_listview_control(0);
1572 ok(hwnd != NULL, "failed to create a listview window\n");
1574 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1576 trace("test color seq\n");
1577 for (i = 0; i < 4; i++)
1581 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1583 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1586 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1588 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1591 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1593 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1597 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1599 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1600 DestroyWindow(hwnd);
1603 static void test_item_count(void)
1605 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1618 static CHAR item0text[] = "item0";
1619 static CHAR item1text[] = "item1";
1620 static CHAR item2text[] = "item2";
1622 hwnd = create_listview_control(0);
1623 ok(hwnd != NULL, "failed to create a listview window\n");
1625 /* resize in dpiaware manner to fit all 3 items added */
1627 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1628 GetTextMetricsA(hdc, &tm);
1629 /* 2 extra pixels for bounds and header border */
1630 height = tm.tmHeight + 2;
1631 SelectObject(hdc, hOldFont);
1634 GetWindowRect(hwnd, &rect);
1635 /* 3 items + 1 header + 1 to be sure */
1636 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1638 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1640 trace("test item count\n");
1642 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1646 item0.mask = LVIF_TEXT;
1649 item0.pszText = item0text;
1650 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1653 /* [item0, item1] */
1654 item1.mask = LVIF_TEXT;
1657 item1.pszText = item1text;
1658 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1661 /* [item0, item1, item2] */
1662 item2.mask = LVIF_TEXT;
1665 item2.pszText = item2text;
1666 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1669 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1672 /* [item0, item1] */
1673 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1676 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1680 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1683 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1687 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1690 /* [item0, item1] */
1691 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1694 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1697 /* [item0, item1, item2] */
1698 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1701 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1704 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1706 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1707 DestroyWindow(hwnd);
1710 static void test_item_position(void)
1712 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1721 static CHAR item0text[] = "item0";
1722 static CHAR item1text[] = "item1";
1723 static CHAR item2text[] = "item2";
1725 hwnd = create_custom_listview_control(LVS_ICON);
1726 ok(hwnd != NULL, "failed to create a listview window\n");
1728 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1730 trace("test item position\n");
1733 item0.mask = LVIF_TEXT;
1736 item0.pszText = item0text;
1737 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1740 /* [item0, item1] */
1741 item1.mask = LVIF_TEXT;
1744 item1.pszText = item1text;
1745 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1748 /* [item0, item1, item2] */
1749 item2.mask = LVIF_TEXT;
1752 item2.pszText = item2text;
1753 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1756 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1758 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1760 expect2(10, 5, position.x, position.y);
1762 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1764 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1766 expect2(0, 0, position.x, position.y);
1768 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1770 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1772 expect2(20, 20, position.x, position.y);
1774 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1776 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1777 DestroyWindow(hwnd);
1780 static void test_getorigin(void)
1788 position.x = position.y = 0;
1790 hwnd = create_custom_listview_control(LVS_ICON);
1791 ok(hwnd != NULL, "failed to create a listview window\n");
1792 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1793 trace("test get origin results\n");
1794 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1796 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1797 DestroyWindow(hwnd);
1799 hwnd = create_custom_listview_control(LVS_SMALLICON);
1800 ok(hwnd != NULL, "failed to create a listview window\n");
1801 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1802 trace("test get origin results\n");
1803 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1805 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1806 DestroyWindow(hwnd);
1808 hwnd = create_custom_listview_control(LVS_LIST);
1809 ok(hwnd != NULL, "failed to create a listview window\n");
1810 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1811 trace("test get origin results\n");
1812 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1814 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1815 DestroyWindow(hwnd);
1817 hwnd = create_custom_listview_control(LVS_REPORT);
1818 ok(hwnd != NULL, "failed to create a listview window\n");
1819 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1820 trace("test get origin results\n");
1821 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1823 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1824 DestroyWindow(hwnd);
1828 static void test_multiselect(void)
1830 typedef struct t_select_task
1841 int i,j,item_count,selected_count;
1842 static const int items=5;
1848 static struct t_select_task task_list[] = {
1849 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1850 { "using VK_UP", -1, VK_UP, -1, -1 },
1851 { "using VK_END", 0, VK_END, 1, -1 },
1852 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1856 hwnd = create_listview_control(0);
1858 for (i=0;i<items;i++) {
1859 insert_item(hwnd, 0);
1862 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1864 expect(items,item_count);
1867 task = task_list[i];
1869 /* deselect all items */
1870 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1871 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1873 /* set initial position */
1874 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1875 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1877 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1879 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1881 /* Set SHIFT key pressed */
1882 GetKeyboardState(kstate);
1883 kstate[VK_SHIFT]=0x80;
1884 SetKeyboardState(kstate);
1886 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1887 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1889 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1893 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1895 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);
1897 /* Set SHIFT key released */
1898 GetKeyboardState(kstate);
1899 kstate[VK_SHIFT]=0x00;
1900 SetKeyboardState(kstate);
1902 DestroyWindow(hwnd);
1904 /* make multiple selection, then switch to LVS_SINGLESEL */
1905 hwnd = create_listview_control(0);
1906 for (i=0;i<items;i++) {
1907 insert_item(hwnd, 0);
1909 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1910 expect(items,item_count);
1911 /* deselect all items */
1912 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1913 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1915 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
1918 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1920 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1924 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1925 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
1926 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
1927 /* check that style is accepted */
1928 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1929 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
1932 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
1933 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
1935 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1937 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1940 /* select one more */
1941 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
1944 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
1945 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
1947 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
1948 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
1950 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1952 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1956 /* try to select all on LVS_SINGLESEL */
1957 memset(&item, 0, sizeof(item));
1958 item.stateMask = LVIS_SELECTED;
1959 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1961 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1963 item.stateMask = LVIS_SELECTED;
1964 item.state = LVIS_SELECTED;
1965 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1968 r = ListView_GetSelectedCount(hwnd);
1970 r = ListView_GetSelectionMark(hwnd);
1973 /* try to deselect all on LVS_SINGLESEL */
1974 item.stateMask = LVIS_SELECTED;
1975 item.state = LVIS_SELECTED;
1976 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
1979 item.stateMask = LVIS_SELECTED;
1981 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1983 r = ListView_GetSelectedCount(hwnd);
1986 DestroyWindow(hwnd);
1989 static void test_subitem_rect(void)
1996 /* test LVM_GETSUBITEMRECT for header */
1997 hwnd = create_listview_control(0);
1998 ok(hwnd != NULL, "failed to create a listview window\n");
1999 /* add some columns */
2000 memset(&col, 0, sizeof(LVCOLUMN));
2001 col.mask = LVCF_WIDTH;
2004 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2008 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2012 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2014 /* item = -1 means header, subitem index is 1 based */
2015 rect.left = LVIR_BOUNDS;
2017 rect.right = rect.bottom = 0;
2018 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2021 rect.left = LVIR_BOUNDS;
2023 rect.right = rect.bottom = 0;
2024 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2026 ok(r != 0, "Expected not-null LRESULT\n");
2027 expect(100, rect.left);
2028 expect(250, rect.right);
2030 expect(3, rect.top);
2032 rect.left = LVIR_BOUNDS;
2034 rect.right = rect.bottom = 0;
2035 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2037 ok(r != 0, "Expected not-null LRESULT\n");
2038 expect(250, rect.left);
2039 expect(450, rect.right);
2041 expect(3, rect.top);
2043 /* item LVS_REPORT padding isn't applied to subitems */
2044 insert_item(hwnd, 0);
2046 rect.left = LVIR_BOUNDS;
2048 rect.right = rect.bottom = 0;
2049 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2050 ok(r != 0, "Expected not-null LRESULT\n");
2051 expect(100, rect.left);
2052 expect(250, rect.right);
2054 rect.left = LVIR_ICON;
2056 rect.right = rect.bottom = 0;
2057 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2058 ok(r != 0, "Expected not-null LRESULT\n");
2059 /* no icon attached - zero width rectangle, with no left padding */
2060 expect(100, rect.left);
2061 expect(100, rect.right);
2063 rect.left = LVIR_LABEL;
2065 rect.right = rect.bottom = 0;
2066 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2067 ok(r != 0, "Expected not-null LRESULT\n");
2068 /* same as full LVIR_BOUNDS */
2069 expect(100, rect.left);
2070 expect(250, rect.right);
2072 DestroyWindow(hwnd);
2074 /* try it for non LVS_REPORT style */
2075 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2076 GetModuleHandle(NULL), 0);
2077 rect.left = LVIR_BOUNDS;
2079 rect.right = rect.bottom = -10;
2080 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2081 ok(r == 0, "Expected not-null LRESULT\n");
2082 /* rect is unchanged */
2083 expect(0, rect.left);
2084 expect(-10, rect.right);
2085 expect(1, rect.top);
2086 expect(-10, rect.bottom);
2087 DestroyWindow(hwnd);
2090 /* comparison callback for test_sorting */
2091 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2093 if (first == second) return 0;
2094 return (first > second ? 1 : -1);
2097 static void test_sorting(void)
2103 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2106 hwnd = create_listview_control(0);
2107 ok(hwnd != NULL, "failed to create a listview window\n");
2109 /* insert some items */
2110 item.mask = LVIF_PARAM | LVIF_STATE;
2111 item.state = LVIS_SELECTED;
2115 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2118 item.mask = LVIF_PARAM;
2122 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2125 item.mask = LVIF_STATE | LVIF_PARAM;
2126 item.state = LVIS_SELECTED;
2130 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2133 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2136 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2139 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2142 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2144 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2146 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2148 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2149 expect(LVIS_SELECTED, r);
2150 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2151 expect(LVIS_SELECTED, r);
2153 DestroyWindow(hwnd);
2155 /* switch to LVS_SORTASCENDING when some items added */
2156 hwnd = create_listview_control(0);
2157 ok(hwnd != NULL, "failed to create a listview window\n");
2159 item.mask = LVIF_TEXT;
2162 item.pszText = names[1];
2163 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2166 item.mask = LVIF_TEXT;
2169 item.pszText = names[2];
2170 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2173 item.mask = LVIF_TEXT;
2176 item.pszText = names[0];
2177 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2180 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2181 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2182 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2183 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2185 /* no sorting performed when switched to LVS_SORTASCENDING */
2186 item.mask = LVIF_TEXT;
2188 item.pszText = buff;
2189 item.cchTextMax = sizeof(buff);
2190 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2192 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2195 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2197 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2200 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2202 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2204 /* adding new item doesn't resort list */
2205 item.mask = LVIF_TEXT;
2208 item.pszText = names[3];
2209 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2212 item.mask = LVIF_TEXT;
2214 item.pszText = buff;
2215 item.cchTextMax = sizeof(buff);
2216 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2218 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2221 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2223 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2226 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2228 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2231 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2233 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2235 /* corner case - item should be placed at first position */
2236 item.mask = LVIF_TEXT;
2239 item.pszText = names[4];
2240 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2244 item.pszText = buff;
2245 item.cchTextMax = sizeof(buff);
2246 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2248 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2251 item.pszText = buff;
2252 item.cchTextMax = sizeof(buff);
2253 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2255 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2258 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2260 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2263 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2265 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2268 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2270 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2272 DestroyWindow(hwnd);
2275 static void test_ownerdata(void)
2278 LONG_PTR style, ret;
2282 /* it isn't possible to set LVS_OWNERDATA after creation */
2285 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2289 hwnd = create_listview_control(0);
2290 ok(hwnd != NULL, "failed to create a listview window\n");
2291 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2292 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2294 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2296 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2297 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2298 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2299 "try to switch to LVS_OWNERDATA seq", FALSE);
2301 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2302 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2303 DestroyWindow(hwnd);
2306 /* try to set LVS_OWNERDATA after creation just having it */
2307 hwnd = create_listview_control(LVS_OWNERDATA);
2308 ok(hwnd != NULL, "failed to create a listview window\n");
2309 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2310 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2312 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2314 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2315 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2316 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2317 "try to switch to LVS_OWNERDATA seq", FALSE);
2318 DestroyWindow(hwnd);
2320 /* try to remove LVS_OWNERDATA after creation just having it */
2323 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2327 hwnd = create_listview_control(LVS_OWNERDATA);
2328 ok(hwnd != NULL, "failed to create a listview window\n");
2329 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2330 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2332 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2334 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2335 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2336 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2337 "try to switch to LVS_OWNERDATA seq", FALSE);
2338 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2339 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2340 DestroyWindow(hwnd);
2343 /* try select an item */
2344 hwnd = create_listview_control(LVS_OWNERDATA);
2345 ok(hwnd != NULL, "failed to create a listview window\n");
2346 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2347 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2348 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2350 memset(&item, 0, sizeof(item));
2351 item.stateMask = LVIS_SELECTED;
2352 item.state = LVIS_SELECTED;
2353 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2355 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2357 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2359 DestroyWindow(hwnd);
2361 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2362 hwnd = create_listview_control(LVS_OWNERDATA);
2363 ok(hwnd != NULL, "failed to create a listview window\n");
2364 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2365 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2366 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2368 memset(&item, 0, sizeof(item));
2369 item.mask = LVIF_STATE;
2371 item.stateMask = LVIS_SELECTED;
2372 item.state = LVIS_SELECTED;
2373 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2375 DestroyWindow(hwnd);
2377 /* check notifications after focused/selected changed */
2378 hwnd = create_listview_control(LVS_OWNERDATA);
2379 ok(hwnd != NULL, "failed to create a listview window\n");
2380 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2381 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2383 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2385 memset(&item, 0, sizeof(item));
2386 item.stateMask = LVIS_SELECTED;
2387 item.state = LVIS_SELECTED;
2388 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2391 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2392 "ownerdata select notification", TRUE);
2394 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2396 memset(&item, 0, sizeof(item));
2397 item.stateMask = LVIS_FOCUSED;
2398 item.state = LVIS_FOCUSED;
2399 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2402 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2403 "ownerdata focus notification", TRUE);
2404 DestroyWindow(hwnd);
2406 /* check notifications on LVM_GETITEM */
2407 /* zero callback mask */
2408 hwnd = create_listview_control(LVS_OWNERDATA);
2409 ok(hwnd != NULL, "failed to create a listview window\n");
2410 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2411 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2413 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2415 memset(&item, 0, sizeof(item));
2416 item.stateMask = LVIS_SELECTED;
2417 item.mask = LVIF_STATE;
2418 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2421 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2422 "ownerdata getitem selected state 1", FALSE);
2424 /* non zero callback mask but not we asking for */
2425 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2428 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2430 memset(&item, 0, sizeof(item));
2431 item.stateMask = LVIS_SELECTED;
2432 item.mask = LVIF_STATE;
2433 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2436 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2437 "ownerdata getitem selected state 2", FALSE);
2439 /* LVIS_OVERLAYMASK callback mask, asking for index */
2440 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2442 memset(&item, 0, sizeof(item));
2443 item.stateMask = LVIS_OVERLAYMASK;
2444 item.mask = LVIF_STATE;
2445 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2448 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2449 "ownerdata getitem selected state 2", FALSE);
2451 DestroyWindow(hwnd);
2453 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2454 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING);
2455 ok(hwnd != NULL, "failed to create a listview window\n");
2456 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2457 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2458 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2459 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2460 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2461 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2462 DestroyWindow(hwnd);
2463 /* apparently it's allowed to switch these style on after creation */
2464 hwnd = create_listview_control(LVS_OWNERDATA);
2465 ok(hwnd != NULL, "failed to create a listview window\n");
2466 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2467 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2468 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2469 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2470 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2471 DestroyWindow(hwnd);
2473 hwnd = create_listview_control(LVS_OWNERDATA);
2474 ok(hwnd != NULL, "failed to create a listview window\n");
2475 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2476 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2477 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2478 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2479 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2480 DestroyWindow(hwnd);
2483 static void test_norecompute(void)
2485 static CHAR testA[] = "test";
2491 /* self containing control */
2492 hwnd = create_listview_control(0);
2493 ok(hwnd != NULL, "failed to create a listview window\n");
2494 memset(&item, 0, sizeof(item));
2495 item.mask = LVIF_TEXT | LVIF_STATE;
2497 item.stateMask = LVIS_SELECTED;
2498 item.state = LVIS_SELECTED;
2499 item.pszText = testA;
2500 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2502 /* retrieve with LVIF_NORECOMPUTE */
2503 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2505 item.pszText = buff;
2506 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2507 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2509 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2511 item.mask = LVIF_TEXT;
2513 item.pszText = LPSTR_TEXTCALLBACK;
2514 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2517 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2519 item.pszText = buff;
2520 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2522 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2523 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2525 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2526 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2527 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2529 DestroyWindow(hwnd);
2532 hwnd = create_listview_control(LVS_OWNERDATA);
2533 ok(hwnd != NULL, "failed to create a listview window\n");
2535 item.mask = LVIF_STATE;
2536 item.stateMask = LVIS_SELECTED;
2537 item.state = LVIS_SELECTED;
2539 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2542 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2544 item.pszText = buff;
2545 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2546 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2547 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2549 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2550 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2551 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2553 DestroyWindow(hwnd);
2556 static void test_nosortheader(void)
2561 hwnd = create_listview_control(0);
2562 ok(hwnd != NULL, "failed to create a listview window\n");
2564 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2565 ok(IsWindow(header), "header expected\n");
2567 style = GetWindowLongPtr(header, GWL_STYLE);
2568 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2570 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2571 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2572 /* HDS_BUTTONS retained */
2573 style = GetWindowLongPtr(header, GWL_STYLE);
2574 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2576 DestroyWindow(hwnd);
2578 /* create with LVS_NOSORTHEADER */
2579 hwnd = create_listview_control(LVS_NOSORTHEADER);
2580 ok(hwnd != NULL, "failed to create a listview window\n");
2582 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2583 ok(IsWindow(header), "header expected\n");
2585 style = GetWindowLongPtr(header, GWL_STYLE);
2586 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2588 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2589 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2590 /* not changed here */
2591 style = GetWindowLongPtr(header, GWL_STYLE);
2592 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2594 DestroyWindow(hwnd);
2597 static void test_setredraw(void)
2603 hwnd = create_listview_control(0);
2604 ok(hwnd != NULL, "failed to create a listview window\n");
2606 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2607 ListView seems to handle it internally without DefWinProc */
2609 /* default value first */
2610 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2613 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2614 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2615 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2617 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2618 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2620 DestroyWindow(hwnd);
2623 static void test_hittest(void)
2629 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2632 HIMAGELIST himl, himl2;
2635 hwnd = create_listview_control(0);
2636 ok(hwnd != NULL, "failed to create a listview window\n");
2638 /* LVS_REPORT with a single subitem (2 columns) */
2639 insert_column(hwnd, 0);
2640 insert_column(hwnd, 1);
2641 insert_item(hwnd, 0);
2644 /* the only purpose of that line is to be as long as a half item rect */
2645 item.pszText = text;
2646 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2649 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2651 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
2654 memset(&bounds, 0, sizeof(bounds));
2655 bounds.left = LVIR_BOUNDS;
2656 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
2657 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
2658 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
2659 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
2662 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2663 x = pos.x + 50; /* column half width */
2664 y = pos.y + (bounds.bottom - bounds.top) / 2;
2665 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, FALSE, FALSE, __LINE__);
2666 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2667 x = pos.x + 150; /* outside column */
2668 y = pos.y + (bounds.bottom - bounds.top) / 2;
2669 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2670 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, TRUE, TRUE, TRUE, __LINE__);
2671 /* parent client area is 100x100 by default */
2672 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
2673 x = pos.x + 150; /* outside column */
2674 y = pos.y + (bounds.bottom - bounds.top) / 2;
2675 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, FALSE, FALSE, __LINE__);
2676 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2677 /* the same with LVS_EX_FULLROWSELECT */
2678 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
2679 x = pos.x + 150; /* outside column */
2680 y = pos.y + (bounds.bottom - bounds.top) / 2;
2681 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, FALSE, FALSE, __LINE__);
2682 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2683 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
2684 x = pos.x + 150; /* outside column */
2685 y = pos.y + (bounds.bottom - bounds.top) / 2;
2686 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2687 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, TRUE, TRUE, TRUE, __LINE__);
2688 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2689 himl = ImageList_Create(16, 16, 0, 4, 4);
2690 ok(himl != NULL, "failed to create imagelist\n");
2691 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2692 ok(hbmp != NULL, "failed to create bitmap\n");
2693 r = ImageList_Add(himl, hbmp, 0);
2694 ok(r == 0, "should be zero\n");
2695 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2696 ok(hbmp != NULL, "failed to create bitmap\n");
2697 r = ImageList_Add(himl, hbmp, 0);
2698 ok(r == 1, "should be one\n");
2700 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2701 ok(r == 0, "should return zero\n");
2703 item.mask = LVIF_IMAGE;
2707 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2711 y = pos.y + (bounds.bottom - bounds.top) / 2;
2712 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2713 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2715 /* state icons indices are 1 based, check with valid index */
2716 item.mask = LVIF_STATE;
2717 item.state = INDEXTOSTATEIMAGEMASK(1);
2718 item.stateMask = LVIS_STATEIMAGEMASK;
2721 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2725 y = pos.y + (bounds.bottom - bounds.top) / 2;
2726 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2727 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2729 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
2730 ok(himl2 == himl, "should return handle\n");
2732 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
2733 ok(r == 0, "should return zero\n");
2736 y = pos.y + (bounds.bottom - bounds.top) / 2;
2737 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, FALSE, FALSE, __LINE__);
2738 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
2740 DestroyWindow(hwnd);
2743 static void test_getviewrect(void)
2750 hwnd = create_listview_control(0);
2751 ok(hwnd != NULL, "failed to create a listview window\n");
2754 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2757 insert_column(hwnd, 0);
2758 insert_column(hwnd, 1);
2760 memset(&item, 0, sizeof(item));
2763 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2765 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2767 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
2770 rect.left = rect.right = rect.top = rect.bottom = -1;
2771 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2773 /* left is set to (2e31-1) - XP SP2 */
2774 expect(0, rect.right);
2775 expect(0, rect.top);
2776 expect(0, rect.bottom);
2778 /* switch to LVS_ICON */
2779 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
2781 rect.left = rect.right = rect.top = rect.bottom = -1;
2782 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2784 expect(0, rect.left);
2785 expect(0, rect.top);
2786 /* precise value differs for 2k, XP and Vista */
2787 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
2788 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
2790 DestroyWindow(hwnd);
2793 static void test_getitemposition(void)
2800 hwnd = create_listview_control(0);
2801 ok(hwnd != NULL, "failed to create a listview window\n");
2802 header = subclass_header(hwnd);
2804 /* LVS_REPORT, single item, no columns added */
2805 insert_item(hwnd, 0);
2807 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2810 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2812 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
2814 /* LVS_REPORT, single item, single column */
2815 insert_column(hwnd, 0);
2817 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2820 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2822 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
2824 memset(&rect, 0, sizeof(rect));
2825 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
2828 /* offset by header height */
2829 expect(rect.bottom - rect.top, pt.y);
2831 DestroyWindow(hwnd);
2834 static void test_columnscreation(void)
2839 hwnd = create_listview_control(0);
2840 ok(hwnd != NULL, "failed to create a listview window\n");
2842 insert_item(hwnd, 0);
2844 /* headers columns aren't created automatically */
2845 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
2846 ok(IsWindow(header), "Expected header handle\n");
2847 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
2850 DestroyWindow(hwnd);
2853 static void test_getitemrect(void)
2865 hwnd = create_listview_control(0);
2866 ok(hwnd != NULL, "failed to create a listview window\n");
2869 memset(&item, 0, sizeof(item));
2872 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2875 rect.left = LVIR_BOUNDS;
2876 rect.right = rect.top = rect.bottom = -1;
2877 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2880 /* zero width rectangle with no padding */
2881 expect(0, rect.left);
2882 expect(0, rect.right);
2884 insert_column(hwnd, 0);
2885 insert_column(hwnd, 1);
2887 col.mask = LVCF_WIDTH;
2889 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
2892 col.mask = LVCF_WIDTH;
2894 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
2897 rect.left = LVIR_BOUNDS;
2898 rect.right = rect.top = rect.bottom = -1;
2899 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2902 /* still no left padding */
2903 expect(0, rect.left);
2904 expect(150, rect.right);
2906 rect.left = LVIR_SELECTBOUNDS;
2907 rect.right = rect.top = rect.bottom = -1;
2908 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2911 expect(2, rect.left);
2913 rect.left = LVIR_LABEL;
2914 rect.right = rect.top = rect.bottom = -1;
2915 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2917 /* padding, column width */
2918 expect(2, rect.left);
2919 expect(50, rect.right);
2921 /* no icons attached */
2922 rect.left = LVIR_ICON;
2923 rect.right = rect.top = rect.bottom = -1;
2924 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2927 expect(2, rect.left);
2928 expect(2, rect.right);
2931 order[0] = 1; order[1] = 0;
2932 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
2935 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2937 /* 1 indexed column width + padding */
2938 todo_wine expect(102, pt.x);
2939 /* rect is at zero too */
2940 rect.left = LVIR_BOUNDS;
2941 rect.right = rect.top = rect.bottom = -1;
2942 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2944 expect(0, rect.left);
2945 /* just width sum */
2946 expect(150, rect.right);
2948 rect.left = LVIR_SELECTBOUNDS;
2949 rect.right = rect.top = rect.bottom = -1;
2950 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2952 /* column width + padding */
2953 todo_wine expect(102, rect.left);
2955 /* back to initial order */
2956 order[0] = 0; order[1] = 1;
2957 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
2961 himl = ImageList_Create(16, 16, 0, 2, 2);
2962 ok(himl != NULL, "failed to create imagelist\n");
2963 hbm = CreateBitmap(16, 16, 1, 1, NULL);
2964 ok(hbm != NULL, "failed to create bitmap\n");
2965 r = ImageList_Add(himl, hbm, 0);
2966 ok(r == 0, "should be zero\n");
2967 hbm = CreateBitmap(16, 16, 1, 1, NULL);
2968 ok(hbm != NULL, "failed to create bitmap\n");
2969 r = ImageList_Add(himl, hbm, 0);
2970 ok(r == 1, "should be one\n");
2972 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2973 ok(r == 0, "should return zero\n");
2975 item.mask = LVIF_STATE;
2976 item.state = INDEXTOSTATEIMAGEMASK(1);
2977 item.stateMask = LVIS_STATEIMAGEMASK;
2980 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2984 rect.left = LVIR_ICON;
2985 rect.right = rect.top = rect.bottom = -1;
2986 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2988 /* padding + stateicon width */
2989 expect(18, rect.left);
2990 expect(18, rect.right);
2992 rect.left = LVIR_LABEL;
2993 rect.right = rect.top = rect.bottom = -1;
2994 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2996 /* padding + stateicon width -> column width */
2997 expect(18, rect.left);
2998 expect(50, rect.right);
3000 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
3001 ok(r != 0, "should return current list handle\n");
3003 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3004 ok(r == 0, "should return zero\n");
3006 item.mask = LVIF_STATE | LVIF_IMAGE;
3009 item.stateMask = ~0;
3012 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3016 rect.left = LVIR_ICON;
3017 rect.right = rect.top = rect.bottom = -1;
3018 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3020 /* padding, icon width */
3021 expect(2, rect.left);
3022 expect(18, rect.right);
3024 rect.left = LVIR_LABEL;
3025 rect.right = rect.top = rect.bottom = -1;
3026 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3028 /* padding + icon width -> column width */
3029 expect(18, rect.left);
3030 expect(50, rect.right);
3033 rect.left = LVIR_SELECTBOUNDS;
3034 rect.right = rect.top = rect.bottom = -1;
3035 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3037 /* padding, column width */
3038 expect(2, rect.left);
3039 todo_wine expect(50, rect.right);
3041 /* try with indentation */
3042 item.mask = LVIF_INDENT;
3046 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3050 rect.left = LVIR_BOUNDS;
3051 rect.right = rect.top = rect.bottom = -1;
3052 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3054 /* padding + 1 icon width, column width */
3055 expect(0, rect.left);
3056 expect(150, rect.right);
3059 rect.left = LVIR_SELECTBOUNDS;
3060 rect.right = rect.top = rect.bottom = -1;
3061 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3063 /* padding + 1 icon width, column width */
3064 expect(2 + 16, rect.left);
3065 todo_wine expect(50, rect.right);
3068 rect.left = LVIR_LABEL;
3069 rect.right = rect.top = rect.bottom = -1;
3070 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3072 /* padding + 2 icon widths, column width */
3073 expect(2 + 16*2, rect.left);
3074 expect(50, rect.right);
3077 rect.left = LVIR_ICON;
3078 rect.right = rect.top = rect.bottom = -1;
3079 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3081 /* padding + 1 icon width indentation, icon width */
3082 expect(2 + 16, rect.left);
3083 expect(34, rect.right);
3086 DestroyWindow(hwnd);
3089 static void test_editbox(void)
3091 HWND hwnd, hwndedit, hwndedit2;
3094 static CHAR testitemA[] = "testitem";
3095 static CHAR testitem1A[] = "testitem1";
3096 static CHAR buffer[10];
3098 hwnd = create_listview_control(LVS_EDITLABELS);
3099 ok(hwnd != NULL, "failed to create a listview window\n");
3101 insert_column(hwnd, 0);
3103 memset(&item, 0, sizeof(item));
3104 item.mask = LVIF_TEXT;
3105 item.pszText = testitemA;
3108 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3111 /* setting focus is necessary */
3113 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3114 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3116 /* modify initial string */
3117 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3119 /* return focus to listview */
3122 memset(&item, 0, sizeof(item));
3123 item.mask = LVIF_TEXT;
3124 item.pszText = buffer;
3125 item.cchTextMax = 10;
3128 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3131 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3133 /* send LVM_EDITLABEL on already created edit */
3135 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3136 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3137 /* focus will be set to edit */
3138 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3139 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3140 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3142 /* creating label disabled when control isn't focused */
3144 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3145 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3147 /* check EN_KILLFOCUS handling */
3148 memset(&item, 0, sizeof(item));
3149 item.pszText = testitemA;
3152 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3156 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3157 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3158 /* modify edit and notify control that it lost focus */
3159 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3161 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3163 memset(&item, 0, sizeof(item));
3164 item.pszText = buffer;
3165 item.cchTextMax = 10;
3168 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3169 expect(lstrlen(item.pszText), r);
3170 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3171 /* end edit without saving */
3172 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3174 memset(&item, 0, sizeof(item));
3175 item.pszText = buffer;
3176 item.cchTextMax = 10;
3179 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3180 expect(lstrlen(item.pszText), r);
3181 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3183 /* LVM_EDITLABEL with -1 destroys current edit */
3184 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3185 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3186 /* no edit present */
3187 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3188 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3189 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3190 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3192 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3193 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3194 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3195 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3196 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3197 /* check another negative value */
3198 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3199 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3200 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3201 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3202 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3203 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3204 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3205 /* and value greater then max item index */
3206 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3207 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3208 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3209 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3210 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3211 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3212 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3213 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3215 /* messaging tests */
3217 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3219 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3220 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3221 /* testing only sizing messages */
3222 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3223 "edit box create - sizing", TRUE);
3225 DestroyWindow(hwnd);
3228 static void test_notifyformat(void)
3233 hwnd = create_listview_control(0);
3234 ok(hwnd != NULL, "failed to create a listview window\n");
3236 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3237 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3238 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3240 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3242 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3244 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3247 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3249 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3254 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3255 DestroyWindow(hwnd);
3259 DestroyWindow(hwnd);
3261 /* test failure in parent WM_NOTIFYFORMAT */
3263 hwnd = create_listview_control(0);
3264 ok(hwnd != NULL, "failed to create a listview window\n");
3265 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3266 ok(IsWindow(header), "expected header to be created\n");
3267 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3269 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3271 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3272 ok(r != 0, "Expected valid format\n");
3274 notifyFormat = NFR_UNICODE;
3275 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3276 expect(NFR_UNICODE, r);
3277 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3279 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3282 notifyFormat = NFR_ANSI;
3283 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3284 expect(NFR_ANSI, r);
3285 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3287 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3290 DestroyWindow(hwnd);
3292 /* try different unicode window combination and defaults */
3293 if (!GetModuleHandleW(NULL))
3295 win_skip("Additional notify format tests are incompatible with Win9x\n");
3299 hwndparentW = create_parent_window(TRUE);
3300 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3301 if (!IsWindow(hwndparentW)) return;
3304 hwnd = create_listview_controlW(0, hwndparentW);
3305 ok(hwnd != NULL, "failed to create a listview window\n");
3306 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3307 ok(IsWindow(header), "expected header to be created\n");
3308 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3310 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3312 DestroyWindow(hwnd);
3313 /* recieving error code defaulting to ansi */
3315 hwnd = create_listview_controlW(0, hwndparentW);
3316 ok(hwnd != NULL, "failed to create a listview window\n");
3317 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3318 ok(IsWindow(header), "expected header to be created\n");
3319 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3321 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3323 DestroyWindow(hwnd);
3324 /* recieving ansi code from unicode window, use it */
3325 notifyFormat = NFR_ANSI;
3326 hwnd = create_listview_controlW(0, hwndparentW);
3327 ok(hwnd != NULL, "failed to create a listview window\n");
3328 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3329 ok(IsWindow(header), "expected header to be created\n");
3330 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3332 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3334 DestroyWindow(hwnd);
3335 /* unicode listview with ansi parent window */
3337 hwnd = create_listview_controlW(0, hwndparent);
3338 ok(hwnd != NULL, "failed to create a listview window\n");
3339 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3340 ok(IsWindow(header), "expected header to be created\n");
3341 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3343 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3345 DestroyWindow(hwnd);
3346 /* unicode listview with ansi parent window, return error code */
3348 hwnd = create_listview_controlW(0, hwndparent);
3349 ok(hwnd != NULL, "failed to create a listview window\n");
3350 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3351 ok(IsWindow(header), "expected header to be created\n");
3352 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3354 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3356 DestroyWindow(hwnd);
3358 DestroyWindow(hwndparentW);
3361 static void test_indentation(void)
3367 hwnd = create_listview_control(0);
3368 ok(hwnd != NULL, "failed to create a listview window\n");
3370 memset(&item, 0, sizeof(item));
3371 item.mask = LVIF_INDENT;
3373 item.iIndent = I_INDENTCALLBACK;
3374 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3377 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3380 item.mask = LVIF_INDENT;
3381 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3384 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3385 "get indent dispinfo", FALSE);
3387 DestroyWindow(hwnd);
3390 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
3395 static BOOL is_below_comctl_5(void)
3400 hwnd = create_listview_control(0);
3401 ok(hwnd != NULL, "failed to create a listview window\n");
3402 insert_item(hwnd, 0);
3404 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
3406 DestroyWindow(hwnd);
3411 static BOOL load_v6_module(ULONG_PTR *pcookie)
3414 HANDLE (WINAPI *pCreateActCtxA)(ACTCTXA*);
3415 BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR*);
3423 hKernel32 = GetModuleHandleA("kernel32.dll");
3424 pCreateActCtxA = (void*)GetProcAddress(hKernel32, "CreateActCtxA");
3425 pActivateActCtx = (void*)GetProcAddress(hKernel32, "ActivateActCtx");
3426 if (!(pCreateActCtxA && pActivateActCtx))
3428 win_skip("Activation contexts unsupported. No version 6 tests possible.\n");
3432 /* create manifest */
3433 file = CreateFileA( manifest_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
3434 if (file != INVALID_HANDLE_VALUE)
3436 ret = (WriteFile( file, manifest, sizeof(manifest)-1, &written, NULL ) &&
3437 written == sizeof(manifest)-1);
3438 CloseHandle( file );
3441 DeleteFileA( manifest_name );
3442 skip("Failed to fill manifest file. Skipping comctl32 V6 tests.\n");
3446 trace("created %s\n", manifest_name);
3450 skip("Failed to create manifest file. Skipping comctl32 V6 tests.\n");
3454 memset(&ctx, 0, sizeof(ctx));
3455 ctx.cbSize = sizeof(ctx);
3456 ctx.lpSource = manifest_name;
3458 hCtx = pCreateActCtxA(&ctx);
3459 ok(hCtx != 0, "Expected context handle\n");
3461 ret = pActivateActCtx(hCtx, pcookie);
3466 win_skip("A problem during context activation occured.\n");
3467 DeleteFileA(manifest_name);
3473 static void unload_v6_module(ULONG_PTR cookie)
3476 BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
3478 hKernel32 = GetModuleHandleA("kernel32.dll");
3479 pDeactivateActCtx = (void*)GetProcAddress(hKernel32, "DeactivateActCtx");
3480 if (!pDeactivateActCtx)
3482 win_skip("Activation contexts unsupported\n");
3486 pDeactivateActCtx(0, cookie);
3488 DeleteFileA(manifest_name);
3491 static void test_get_set_view(void)
3497 /* test style->view mapping */
3498 hwnd = create_listview_control(0);
3499 ok(hwnd != NULL, "failed to create a listview window\n");
3501 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3502 expect(LV_VIEW_DETAILS, ret);
3504 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3506 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
3507 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3508 expect(LV_VIEW_ICON, ret);
3510 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3511 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
3512 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3513 expect(LV_VIEW_SMALLICON, ret);
3515 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3516 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
3517 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3518 expect(LV_VIEW_LIST, ret);
3520 /* switching view doesn't touch window style */
3521 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
3523 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3524 ok(style & LVS_LIST, "Expected style to be preserved\n");
3525 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
3527 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3528 ok(style & LVS_LIST, "Expected style to be preserved\n");
3529 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
3531 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3532 ok(style & LVS_LIST, "Expected style to be preserved\n");
3534 DestroyWindow(hwnd);
3537 static void test_canceleditlabel(void)
3539 HWND hwnd, hwndedit;
3543 static CHAR test[] = "test";
3544 static const CHAR test1[] = "test1";
3546 hwnd = create_listview_control(LVS_EDITLABELS);
3547 ok(hwnd != NULL, "failed to create a listview window\n");
3549 insert_item(hwnd, 0);
3551 /* try without edit created */
3552 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3555 /* cancel without data change */
3557 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3558 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3559 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3561 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3563 /* cancel after data change */
3564 memset(&itema, 0, sizeof(itema));
3565 itema.pszText = test;
3566 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
3569 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3570 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3571 ret = SetWindowText(hwndedit, test1);
3572 ok(ret != 0, "Expected edit text to change\n");
3573 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3575 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3576 memset(&itema, 0, sizeof(itema));
3577 itema.pszText = buff;
3578 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
3579 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
3581 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
3583 DestroyWindow(hwnd);
3586 static void test_mapidindex(void)
3591 hwnd = create_listview_control(0);
3592 ok(hwnd != NULL, "failed to create a listview window\n");
3594 insert_item(hwnd, 0);
3595 insert_item(hwnd, 1);
3597 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3599 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3600 todo_wine expect(1, ret);
3601 /* remove 0 indexed item, id retained */
3602 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
3603 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3604 todo_wine expect(1, ret);
3605 /* new id starts from previous value */
3606 insert_item(hwnd, 1);
3607 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3608 todo_wine expect(2, ret);
3610 DestroyWindow(hwnd);
3613 START_TEST(listview)
3616 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
3618 ULONG_PTR ctx_cookie;
3620 hComctl32 = GetModuleHandleA("comctl32.dll");
3621 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
3622 if (pInitCommonControlsEx)
3624 INITCOMMONCONTROLSEX iccex;
3625 iccex.dwSize = sizeof(iccex);
3626 iccex.dwICC = ICC_LISTVIEW_CLASSES;
3627 pInitCommonControlsEx(&iccex);
3630 InitCommonControls();
3632 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
3634 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3635 hwndparent = create_parent_window(FALSE);
3636 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent window", TRUE);
3637 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3639 g_is_below_5 = is_below_comctl_5();
3647 test_icon_spacing();
3650 test_item_position();
3655 test_subitem_rect();
3659 test_nosortheader();
3663 test_getitemposition();
3664 test_columnscreation();
3666 test_notifyformat();
3669 if (!load_v6_module(&ctx_cookie))
3671 DestroyWindow(hwndparent);
3675 /* comctl32 version 6 tests start here */
3676 test_get_set_view();
3677 test_canceleditlabel();
3680 unload_v6_module(ctx_cookie);
3682 DestroyWindow(hwndparent);