4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009 Nikolay Sivov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
31 #define PARENT_SEQ_INDEX 0
32 #define PARENT_FULL_SEQ_INDEX 1
33 #define LISTVIEW_SEQ_INDEX 2
34 #define EDITBOX_SEQ_INDEX 3
35 #define NUM_MSG_SEQUENCES 4
40 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
41 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
42 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
44 static const WCHAR testparentclassW[] =
45 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
47 HWND hwndparent, hwndparentW;
48 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
50 /* dumps LVN_ITEMCHANGED message data */
51 static BOOL g_dump_itemchanged;
52 /* format reported to control:
53 -1 falls to defproc, anything else returned */
55 /* indicates we're running < 5.80 version */
58 static HWND subclass_editbox(HWND hwndListview);
60 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
62 static const struct message create_ownerdrawfixed_parent_seq[] = {
63 { WM_NOTIFYFORMAT, sent },
64 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
65 { WM_MEASUREITEM, sent },
66 { WM_PARENTNOTIFY, sent },
70 static const struct message redraw_listview_seq[] = {
71 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
72 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
73 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
74 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
75 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
76 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
77 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
81 static const struct message listview_icon_spacing_seq[] = {
82 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
83 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
84 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
88 static const struct message listview_color_seq[] = {
89 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
90 { LVM_GETBKCOLOR, sent },
91 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
92 { LVM_GETTEXTCOLOR, sent },
93 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
94 { LVM_GETTEXTBKCOLOR, sent },
96 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
97 { LVM_GETBKCOLOR, sent },
98 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
99 { LVM_GETTEXTCOLOR, sent },
100 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
101 { LVM_GETTEXTBKCOLOR, sent },
103 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
104 { LVM_GETBKCOLOR, sent },
105 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
106 { LVM_GETTEXTCOLOR, sent },
107 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
108 { LVM_GETTEXTBKCOLOR, sent },
110 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
111 { LVM_GETBKCOLOR, sent },
112 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
113 { LVM_GETTEXTCOLOR, sent },
114 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
115 { LVM_GETTEXTBKCOLOR, sent },
119 static const struct message listview_item_count_seq[] = {
120 { LVM_GETITEMCOUNT, sent },
121 { LVM_INSERTITEM, sent },
122 { LVM_INSERTITEM, sent },
123 { LVM_INSERTITEM, sent },
124 { LVM_GETITEMCOUNT, sent },
125 { LVM_DELETEITEM, sent|wparam, 2 },
126 { WM_NCPAINT, sent|optional },
127 { WM_ERASEBKGND, sent|optional },
128 { LVM_GETITEMCOUNT, sent },
129 { LVM_DELETEALLITEMS, sent },
130 { LVM_GETITEMCOUNT, sent },
131 { LVM_INSERTITEM, sent },
132 { LVM_INSERTITEM, sent },
133 { LVM_GETITEMCOUNT, sent },
134 { LVM_INSERTITEM, sent },
135 { LVM_GETITEMCOUNT, sent },
139 static const struct message listview_itempos_seq[] = {
140 { LVM_INSERTITEM, sent },
141 { LVM_INSERTITEM, sent },
142 { LVM_INSERTITEM, sent },
143 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
144 { WM_NCPAINT, sent|optional },
145 { WM_ERASEBKGND, sent|optional },
146 { LVM_GETITEMPOSITION, sent|wparam, 1 },
147 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
148 { LVM_GETITEMPOSITION, sent|wparam, 2 },
149 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
150 { LVM_GETITEMPOSITION, sent|wparam, 0 },
154 static const struct message listview_ownerdata_switchto_seq[] = {
155 { WM_STYLECHANGING, sent },
156 { WM_STYLECHANGED, sent },
160 static const struct message listview_getorderarray_seq[] = {
161 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
162 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
166 static const struct message empty_seq[] = {
170 static const struct message forward_erasebkgnd_parent_seq[] = {
171 { WM_ERASEBKGND, sent },
175 static const struct message ownderdata_select_focus_parent_seq[] = {
176 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
177 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
178 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
182 static const struct message ownerdata_setstate_all_parent_seq[] = {
183 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
187 static const struct message ownerdata_defocus_all_parent_seq[] = {
188 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
189 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
190 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
191 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
195 static const struct message ownerdata_deselect_all_parent_seq[] = {
196 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
197 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
201 static const struct message select_all_parent_seq[] = {
202 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
203 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
205 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
206 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
208 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
209 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
211 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
212 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
214 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
215 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
219 static const struct message textcallback_set_again_parent_seq[] = {
220 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
221 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
225 static const struct message single_getdispinfo_parent_seq[] = {
226 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
230 static const struct message getitemposition_seq1[] = {
231 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
235 static const struct message getitemposition_seq2[] = {
236 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
237 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
241 static const struct message editbox_create_pos[] = {
242 /* sequence sent after LVN_BEGINLABELEDIT */
243 /* next two are 4.7x specific */
244 { WM_WINDOWPOSCHANGING, sent },
245 { WM_WINDOWPOSCHANGED, sent|optional },
247 { WM_WINDOWPOSCHANGING, sent|optional },
248 { WM_NCCALCSIZE, sent },
249 { WM_WINDOWPOSCHANGED, sent },
250 { WM_MOVE, sent|defwinproc },
251 { WM_SIZE, sent|defwinproc },
252 /* the rest is todo, skipped in 4.7x */
253 { WM_WINDOWPOSCHANGING, sent|optional },
254 { WM_WINDOWPOSCHANGED, sent|optional },
258 static const struct message scroll_parent_seq[] = {
259 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
260 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
264 static const struct message setredraw_seq[] = {
265 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
269 static const struct message lvs_ex_transparentbkgnd_seq[] = {
270 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
279 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
281 static LONG defwndproc_counter = 0;
285 msg.message = message;
286 msg.flags = sent|wparam|lparam;
287 if (defwndproc_counter) msg.flags |= defwinproc;
290 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
292 /* log system messages, except for painting */
293 if (message < WM_USER &&
294 message != WM_PAINT &&
295 message != WM_ERASEBKGND &&
296 message != WM_NCPAINT &&
297 message != WM_NCHITTEST &&
298 message != WM_GETTEXT &&
299 message != WM_GETICON &&
300 message != WM_DEVICECHANGE)
302 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
304 add_message(sequences, PARENT_SEQ_INDEX, &msg);
306 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
312 switch (((NMHDR*)lParam)->code)
314 case LVN_BEGINLABELEDIT:
315 /* subclass edit box */
317 subclass_editbox(((NMHDR*)lParam)->hwndFrom);
321 case LVN_ENDLABELEDIT:
322 /* always accept new item text */
324 case LVN_BEGINSCROLL:
327 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
329 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
330 "BEGIN" : "END", pScroll->dx, pScroll->dy);
333 case LVN_ITEMCHANGED:
334 if (g_dump_itemchanged)
336 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
337 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
338 nmlv->iItem, nmlv->uNewState, nmlv->uOldState, nmlv->uChanged);
344 case WM_NOTIFYFORMAT:
346 /* force to return format */
347 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
352 defwndproc_counter++;
353 ret = DefWindowProcA(hwnd, message, wParam, lParam);
354 defwndproc_counter--;
359 static BOOL register_parent_wnd_class(BOOL Unicode)
367 clsW.lpfnWndProc = parent_wnd_proc;
370 clsW.hInstance = GetModuleHandleW(NULL);
372 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
373 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
374 clsW.lpszMenuName = NULL;
375 clsW.lpszClassName = testparentclassW;
380 clsA.lpfnWndProc = parent_wnd_proc;
383 clsA.hInstance = GetModuleHandleA(NULL);
385 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
386 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
387 clsA.lpszMenuName = NULL;
388 clsA.lpszClassName = "Listview test parent class";
391 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
394 static HWND create_parent_window(BOOL Unicode)
396 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W'};
399 if (!register_parent_wnd_class(Unicode))
406 hwnd = CreateWindowExW(0, testparentclassW, nameW,
407 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
408 WS_MAXIMIZEBOX | WS_VISIBLE,
410 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
412 hwnd = CreateWindowExA(0, "Listview test parent class",
413 "Listview test parent window",
414 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
415 WS_MAXIMIZEBOX | WS_VISIBLE,
417 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
418 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
422 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
424 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
425 static LONG defwndproc_counter = 0;
429 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
431 /* some debug output for style changing */
432 if ((message == WM_STYLECHANGING ||
433 message == WM_STYLECHANGED) && lParam)
435 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
436 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
439 msg.message = message;
440 msg.flags = sent|wparam|lparam;
441 if (defwndproc_counter) msg.flags |= defwinproc;
444 msg.id = LISTVIEW_ID;
445 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
447 defwndproc_counter++;
448 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
449 defwndproc_counter--;
453 static HWND create_listview_control(DWORD style)
455 struct subclass_info *info;
459 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
463 GetClientRect(hwndparent, &rect);
464 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
465 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
466 0, 0, rect.right, rect.bottom,
467 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
468 ok(hwnd != NULL, "gle=%d\n", GetLastError());
472 HeapFree(GetProcessHeap(), 0, info);
476 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
477 (LONG_PTR)listview_subclass_proc);
478 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
483 /* unicode listview window with specified parent */
484 static HWND create_listview_controlW(DWORD style, HWND parent)
486 struct subclass_info *info;
489 static const WCHAR nameW[] = {'f','o','o',0};
491 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
495 GetClientRect(parent, &rect);
496 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
497 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
498 0, 0, rect.right, rect.bottom,
499 parent, NULL, GetModuleHandleW(NULL), NULL);
500 ok(hwnd != NULL, "gle=%d\n", GetLastError());
504 HeapFree(GetProcessHeap(), 0, info);
508 info->oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
509 (LONG_PTR)listview_subclass_proc);
510 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)info);
515 static HWND create_custom_listview_control(DWORD style)
517 struct subclass_info *info;
521 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
525 GetClientRect(hwndparent, &rect);
526 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
527 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
528 0, 0, rect.right, rect.bottom,
529 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
530 ok(hwnd != NULL, "gle=%d\n", GetLastError());
534 HeapFree(GetProcessHeap(), 0, info);
538 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
539 (LONG_PTR)listview_subclass_proc);
540 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
545 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
547 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
548 static LONG defwndproc_counter = 0;
552 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
554 msg.message = message;
555 msg.flags = sent|wparam|lparam;
556 if (defwndproc_counter) msg.flags |= defwinproc;
560 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
562 defwndproc_counter++;
563 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
564 defwndproc_counter--;
568 static HWND subclass_header(HWND hwndListview)
570 struct subclass_info *info;
573 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
577 hwnd = ListView_GetHeader(hwndListview);
578 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
579 (LONG_PTR)header_subclass_proc);
580 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
585 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
587 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
588 static LONG defwndproc_counter = 0;
592 msg.message = message;
593 msg.flags = sent|wparam|lparam;
594 if (defwndproc_counter) msg.flags |= defwinproc;
598 /* all we need is sizing */
599 if (message == WM_WINDOWPOSCHANGING ||
600 message == WM_NCCALCSIZE ||
601 message == WM_WINDOWPOSCHANGED ||
602 message == WM_MOVE ||
605 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
608 defwndproc_counter++;
609 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
610 defwndproc_counter--;
614 static HWND subclass_editbox(HWND hwndListview)
616 struct subclass_info *info;
619 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
623 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
624 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
625 (LONG_PTR)editbox_subclass_proc);
626 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
631 /* Performs a single LVM_HITTEST test */
632 static void test_lvm_hittest(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
633 BOOL todo_item, BOOL todo_flags, int line)
642 trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
643 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
649 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
650 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
651 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
656 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
657 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
658 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
664 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
666 else if (broken_flags)
667 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
668 "Expected flags %x, got %x\n", flags, lpht.flags);
670 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
673 /* Performs a single LVM_SUBITEMHITTEST test */
674 static void test_lvm_subitemhittest(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
675 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
683 trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
684 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
690 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
691 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
696 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
697 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
703 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
706 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
711 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
714 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
717 static void test_images(void)
725 static CHAR hello[] = "hello";
727 himl = ImageList_Create(40, 40, 0, 4, 4);
728 ok(himl != NULL, "failed to create imagelist\n");
730 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
731 ok(hbmp != NULL, "failed to create bitmap\n");
733 r = ImageList_Add(himl, hbmp, 0);
734 ok(r == 0, "should be zero\n");
736 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
737 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
738 ok(hwnd != NULL, "failed to create listview window\n");
740 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
741 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
743 ok(r == 0, "should return zero\n");
745 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
746 ok(r == 0, "should return zero\n");
748 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
749 /* returns dimensions */
751 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
752 ok(r == 0, "should be zero items\n");
754 item.mask = LVIF_IMAGE | LVIF_TEXT;
759 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
760 ok(r == -1, "should fail\n");
763 item.pszText = hello;
764 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
765 ok(r == 0, "should not fail\n");
767 memset(&r1, 0, sizeof r1);
769 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
771 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
772 ok(r == TRUE, "should not fail\n");
775 item.pszText = hello;
776 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
777 ok(r == 0, "should not fail\n");
779 memset(&r2, 0, sizeof r2);
781 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
783 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
788 static void test_checkboxes(void)
793 static CHAR text[] = "Text",
797 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
798 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
799 ok(hwnd != NULL, "failed to create listview window\n");
801 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
802 item.mask = LVIF_TEXT | LVIF_STATE;
803 item.stateMask = 0xffff;
808 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
809 ok(r == 0, "ret %d\n", r);
812 item.mask = LVIF_STATE;
813 item.stateMask = 0xffff;
814 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
815 ok(item.state == 0xfccc, "state %x\n", item.state);
817 /* Don't set LVIF_STATE */
818 item.mask = LVIF_TEXT;
819 item.stateMask = 0xffff;
824 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
825 ok(r == 1, "ret %d\n", r);
828 item.mask = LVIF_STATE;
829 item.stateMask = 0xffff;
830 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
831 ok(item.state == 0, "state %x\n", item.state);
833 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
834 ok(r == 0, "should return zero\n");
836 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
838 item.mask = LVIF_STATE;
839 item.stateMask = 0xffff;
840 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
841 if (item.state != 0x1ccc)
843 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
848 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
850 item.mask = LVIF_TEXT;
852 item.pszText = text2;
853 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
854 ok(r == 2, "ret %d\n", r);
857 item.mask = LVIF_STATE;
858 item.stateMask = 0xffff;
859 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
860 ok(item.state == 0x1000, "state %x\n", item.state);
862 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
864 item.mask = LVIF_TEXT | LVIF_STATE;
865 item.stateMask = 0xffff;
867 item.pszText = text3;
868 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
869 ok(r == 3, "ret %d\n", r);
872 item.mask = LVIF_STATE;
873 item.stateMask = 0xffff;
874 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
875 ok(item.state == 0x1aaa, "state %x\n", item.state);
877 /* Set an item's state to checked */
879 item.mask = LVIF_STATE;
880 item.stateMask = 0xf000;
882 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
885 item.mask = LVIF_STATE;
886 item.stateMask = 0xffff;
887 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
888 ok(item.state == 0x2aaa, "state %x\n", item.state);
890 /* Check that only the bits we asked for are returned,
891 * and that all the others are set to zero
894 item.mask = LVIF_STATE;
895 item.stateMask = 0xf000;
897 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
898 ok(item.state == 0x2000, "state %x\n", item.state);
900 /* Set the style again and check that doesn't change an item's state */
901 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
902 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
905 item.mask = LVIF_STATE;
906 item.stateMask = 0xffff;
907 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
908 ok(item.state == 0x2aaa, "state %x\n", item.state);
910 /* Unsetting the checkbox extended style doesn't change an item's state */
911 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
912 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
915 item.mask = LVIF_STATE;
916 item.stateMask = 0xffff;
917 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
918 ok(item.state == 0x2aaa, "state %x\n", item.state);
920 /* Now setting the style again will change an item's state */
921 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
922 ok(r == 0, "ret %x\n", r);
925 item.mask = LVIF_STATE;
926 item.stateMask = 0xffff;
927 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
928 ok(item.state == 0x1aaa, "state %x\n", item.state);
930 /* Toggle checkbox tests (bug 9934) */
931 memset (&item, 0xcc, sizeof(item));
932 item.mask = LVIF_STATE;
935 item.state = LVIS_FOCUSED;
936 item.stateMask = LVIS_FOCUSED;
937 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
941 item.mask = LVIF_STATE;
942 item.stateMask = 0xffff;
943 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
944 ok(item.state == 0x1aab, "state %x\n", item.state);
946 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
948 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
952 item.mask = LVIF_STATE;
953 item.stateMask = 0xffff;
954 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
955 ok(item.state == 0x2aab, "state %x\n", item.state);
957 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
959 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
963 item.mask = LVIF_STATE;
964 item.stateMask = 0xffff;
965 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
966 ok(item.state == 0x1aab, "state %x\n", item.state);
971 static void insert_column(HWND hwnd, int idx)
976 memset(&column, 0xcc, sizeof(column));
977 column.mask = LVCF_SUBITEM;
978 column.iSubItem = idx;
980 rc = ListView_InsertColumn(hwnd, idx, &column);
984 static void insert_item(HWND hwnd, int idx)
986 static CHAR text[] = "foo";
991 memset(&item, 0xcc, sizeof (item));
992 item.mask = LVIF_TEXT;
997 rc = ListView_InsertItem(hwnd, &item);
1001 static void test_items(void)
1003 const LPARAM lparamTest = 0x42;
1007 static CHAR text[] = "Text";
1009 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1010 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1011 ok(hwnd != NULL, "failed to create listview window\n");
1014 * Test setting/getting item params
1017 /* Set up two columns */
1018 insert_column(hwnd, 0);
1019 insert_column(hwnd, 1);
1021 /* LVIS_SELECTED with zero stateMask */
1023 memset (&item, 0, sizeof (item));
1024 item.mask = LVIF_STATE;
1025 item.state = LVIS_SELECTED;
1029 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1030 ok(r == 0, "ret %d\n", r);
1032 memset (&item, 0xcc, sizeof (item));
1033 item.mask = LVIF_STATE;
1034 item.stateMask = LVIS_SELECTED;
1038 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1039 ok(r != 0, "ret %d\n", r);
1040 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1041 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1043 /* LVIS_SELECTED with zero stateMask */
1045 memset (&item, 0, sizeof (item));
1046 item.mask = LVIF_STATE;
1047 item.state = LVIS_FOCUSED;
1051 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1052 ok(r == 0, "ret %d\n", r);
1054 memset (&item, 0xcc, sizeof (item));
1055 item.mask = LVIF_STATE;
1056 item.stateMask = LVIS_FOCUSED;
1060 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1061 ok(r != 0, "ret %d\n", r);
1062 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1063 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1065 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1067 memset (&item, 0, sizeof (item));
1068 item.mask = LVIF_STATE;
1069 item.state = LVIS_CUT;
1070 item.stateMask = LVIS_FOCUSED;
1073 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1074 ok(r == 0, "ret %d\n", r);
1076 memset (&item, 0xcc, sizeof (item));
1077 item.mask = LVIF_STATE;
1078 item.stateMask = LVIS_CUT;
1082 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1083 ok(r != 0, "ret %d\n", r);
1084 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1085 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1087 /* Insert an item with just a param */
1088 memset (&item, 0xcc, sizeof (item));
1089 item.mask = LVIF_PARAM;
1092 item.lParam = lparamTest;
1093 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1094 ok(r == 0, "ret %d\n", r);
1096 /* Test getting of the param */
1097 memset (&item, 0xcc, sizeof (item));
1098 item.mask = LVIF_PARAM;
1101 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1102 ok(r != 0, "ret %d\n", r);
1103 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1105 /* Set up a subitem */
1106 memset (&item, 0xcc, sizeof (item));
1107 item.mask = LVIF_TEXT;
1110 item.pszText = text;
1111 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1112 ok(r != 0, "ret %d\n", r);
1114 /* Query param from subitem: returns main item param */
1115 memset (&item, 0xcc, sizeof (item));
1116 item.mask = LVIF_PARAM;
1119 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1120 ok(r != 0, "ret %d\n", r);
1121 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1123 /* Set up param on first subitem: no effect */
1124 memset (&item, 0xcc, sizeof (item));
1125 item.mask = LVIF_PARAM;
1128 item.lParam = lparamTest+1;
1129 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1130 ok(r == 0, "ret %d\n", r);
1132 /* Query param from subitem again: should still return main item param */
1133 memset (&item, 0xcc, sizeof (item));
1134 item.mask = LVIF_PARAM;
1137 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1138 ok(r != 0, "ret %d\n", r);
1139 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1141 /**** Some tests of state highlighting ****/
1142 memset (&item, 0xcc, sizeof (item));
1143 item.mask = LVIF_STATE;
1146 item.state = LVIS_SELECTED;
1147 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1148 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1149 ok(r != 0, "ret %d\n", r);
1151 item.state = LVIS_DROPHILITED;
1152 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1153 ok(r != 0, "ret %d\n", r);
1155 memset (&item, 0xcc, sizeof (item));
1156 item.mask = LVIF_STATE;
1159 item.stateMask = -1;
1160 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1161 ok(r != 0, "ret %d\n", r);
1162 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1164 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1165 ok(r != 0, "ret %d\n", r);
1166 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1168 /* some notnull but meaningless masks */
1169 memset (&item, 0, sizeof(item));
1170 item.mask = LVIF_NORECOMPUTE;
1173 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1174 ok(r != 0, "ret %d\n", r);
1175 memset (&item, 0, sizeof(item));
1176 item.mask = LVIF_DI_SETITEM;
1179 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1180 ok(r != 0, "ret %d\n", r);
1182 /* set text to callback value already having it */
1183 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1185 memset (&item, 0, sizeof (item));
1186 item.mask = LVIF_TEXT;
1187 item.pszText = LPSTR_TEXTCALLBACK;
1189 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1190 ok(r == 0, "ret %d\n", r);
1191 memset (&item, 0, sizeof (item));
1193 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1195 item.pszText = LPSTR_TEXTCALLBACK;
1196 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1199 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1200 "check callback text comparison rule", FALSE);
1202 DestroyWindow(hwnd);
1205 static void test_columns(void)
1207 HWND hwnd, hwndheader;
1212 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1213 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1214 ok(hwnd != NULL, "failed to create listview window\n");
1216 /* Add a column with no mask */
1217 memset(&column, 0xcc, sizeof(column));
1219 rc = ListView_InsertColumn(hwnd, 0, &column);
1220 ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
1222 /* Check its width */
1223 rc = ListView_GetColumnWidth(hwnd, 0);
1225 broken(rc==0), /* win9x */
1226 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1228 DestroyWindow(hwnd);
1230 /* LVM_GETCOLUMNORDERARRAY */
1231 hwnd = create_listview_control(0);
1232 hwndheader = subclass_header(hwnd);
1234 memset(&column, 0, sizeof(column));
1235 column.mask = LVCF_WIDTH;
1237 rc = ListView_InsertColumn(hwnd, 0, &column);
1238 ok(rc == 0, "Inserting column failed with %d\n", rc);
1241 rc = ListView_InsertColumn(hwnd, 1, &column);
1242 ok(rc == 1, "Inserting column failed with %d\n", rc);
1244 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1246 rc = SendMessage(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1247 ok(rc != 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1248 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1249 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1251 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1253 DestroyWindow(hwnd);
1255 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1256 static WNDPROC listviewWndProc;
1257 static HIMAGELIST test_create_imagelist;
1259 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1263 if (uMsg == WM_CREATE)
1265 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1266 lpcs->style |= LVS_REPORT;
1268 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1269 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1273 static void test_create(void)
1282 cls.cbSize = sizeof(WNDCLASSEX);
1283 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1284 listviewWndProc = cls.lpfnWndProc;
1285 cls.lpfnWndProc = create_test_wndproc;
1286 cls.lpszClassName = "MyListView32";
1287 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1289 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1290 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1291 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1292 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1294 if (!IsWindow(hHeader))
1297 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1298 DestroyWindow(hList);
1302 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1303 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1304 DestroyWindow(hList);
1306 /* header isn't created on LVS_ICON and LVS_LIST styles */
1307 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1308 GetModuleHandle(NULL), 0);
1309 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1310 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1311 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1313 memset(&col, 0, sizeof(LVCOLUMNA));
1314 col.mask = LVCF_WIDTH;
1316 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1317 ok(r == 0, "Expected 0 column's inserted\n");
1318 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1319 ok(IsWindow(hHeader), "Header should be created\n");
1320 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1321 DestroyWindow(hList);
1323 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1324 GetModuleHandle(NULL), 0);
1325 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1326 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1327 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1329 memset(&col, 0, sizeof(LVCOLUMNA));
1330 col.mask = LVCF_WIDTH;
1332 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1333 ok(r == 0, "Expected 0 column's inserted\n");
1334 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1335 ok(IsWindow(hHeader), "Header should be created\n");
1336 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1337 DestroyWindow(hList);
1339 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1340 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1341 GetModuleHandle(NULL), 0);
1342 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1343 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1344 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1345 ok(IsWindow(hHeader), "Header should be created\n");
1346 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1347 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1348 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1349 ok(IsWindow(hHeader), "Header should be created\n");
1350 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1351 DestroyWindow(hList);
1353 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1354 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1355 GetModuleHandle(NULL), 0);
1356 ret = SetWindowLongPtr(hList, GWL_STYLE,
1357 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1358 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1359 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1360 ok(IsWindow(hHeader), "Header should be created\n");
1361 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1362 ret = SetWindowLongPtr(hList, GWL_STYLE,
1363 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1364 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1365 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1366 ok(IsWindow(hHeader), "Header should be created\n");
1367 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1368 DestroyWindow(hList);
1370 /* LVS_REPORT without WS_VISIBLE */
1371 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1372 GetModuleHandle(NULL), 0);
1373 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1374 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1375 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1377 memset(&col, 0, sizeof(LVCOLUMNA));
1378 col.mask = LVCF_WIDTH;
1380 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1381 ok(r == 0, "Expected 0 column's inserted\n");
1382 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1383 ok(IsWindow(hHeader), "Header should be created\n");
1384 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1385 DestroyWindow(hList);
1387 /* LVS_REPORT without WS_VISIBLE, try to show it */
1388 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1389 GetModuleHandle(NULL), 0);
1390 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1391 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1392 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1393 ShowWindow(hList, SW_SHOW);
1394 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1395 ok(IsWindow(hHeader), "Header should be created\n");
1396 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1397 DestroyWindow(hList);
1399 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1400 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1401 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1402 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1403 ok(IsWindow(hHeader), "Header should be created\n");
1404 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1405 /* HDS_DRAGDROP set by default */
1406 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1407 DestroyWindow(hList);
1409 /* setting LVS_EX_HEADERDRAGDROP creates header */
1410 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1411 GetModuleHandle(NULL), 0);
1412 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1413 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1414 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1415 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1416 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1417 ok(IsWindow(hHeader) ||
1418 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1419 "Header should be created\n");
1420 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1421 DestroyWindow(hList);
1423 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1424 hList = create_custom_listview_control(0);
1425 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1426 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1427 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1428 DestroyWindow(hList);
1430 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1431 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1432 GetModuleHandle(NULL), 0);
1433 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1434 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1436 rect.left = LVIR_BOUNDS;
1438 rect.right = rect.bottom = -10;
1439 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1440 ok(r != 0, "Expected not-null LRESULT\n");
1442 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1443 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1444 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1446 DestroyWindow(hList);
1448 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1449 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1450 hList = create_listview_control(LVS_OWNERDRAWFIXED);
1451 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1452 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1453 DestroyWindow(hList);
1456 static void test_redraw(void)
1458 HWND hwnd, hwndheader;
1463 hwnd = create_listview_control(0);
1464 hwndheader = subclass_header(hwnd);
1466 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1468 trace("invalidate & update\n");
1469 InvalidateRect(hwnd, NULL, TRUE);
1471 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1473 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1475 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1476 /* 1. Without backbuffer */
1477 res = ListView_SetBkColor(hwnd, CLR_NONE);
1480 hdc = GetWindowDC(hwndparent);
1482 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1483 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1484 ok(r != 0, "Expected not zero result\n");
1485 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1486 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1488 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1491 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1492 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1493 ok(r != 0, "Expected not zero result\n");
1494 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1495 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1497 /* 2. With backbuffer */
1498 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1499 LVS_EX_DOUBLEBUFFER);
1500 res = ListView_SetBkColor(hwnd, CLR_NONE);
1503 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1504 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1505 ok(r != 0, "Expected not zero result\n");
1506 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1507 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1509 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1512 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1513 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1514 todo_wine ok(r != 0, "Expected not zero result\n");
1515 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1516 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1518 ReleaseDC(hwndparent, hdc);
1520 DestroyWindow(hwnd);
1523 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1525 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1527 if(msg == WM_NOTIFY) {
1528 NMHDR *nmhdr = (PVOID)lp;
1529 if(nmhdr->code == NM_CUSTOMDRAW) {
1530 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1531 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1532 switch(nmlvcd->nmcd.dwDrawStage) {
1534 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1535 return CDRF_NOTIFYITEMDRAW;
1536 case CDDS_ITEMPREPAINT:
1537 nmlvcd->clrTextBk = CLR_DEFAULT;
1538 return CDRF_NOTIFYSUBITEMDRAW;
1539 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1540 clr = GetBkColor(nmlvcd->nmcd.hdc);
1541 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1542 return CDRF_NOTIFYPOSTPAINT;
1543 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1544 clr = GetBkColor(nmlvcd->nmcd.hdc);
1545 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1546 return CDRF_DODEFAULT;
1548 return CDRF_DODEFAULT;
1552 return DefWindowProcA(hwnd, msg, wp, lp);
1555 static void test_customdraw(void)
1560 hwnd = create_listview_control(0);
1562 insert_column(hwnd, 0);
1563 insert_column(hwnd, 1);
1564 insert_item(hwnd, 0);
1566 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1567 (LONG_PTR)cd_wndproc);
1569 InvalidateRect(hwnd, NULL, TRUE);
1572 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1574 DestroyWindow(hwnd);
1577 static void test_icon_spacing(void)
1579 /* LVM_SETICONSPACING */
1580 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1586 hwnd = create_custom_listview_control(LVS_ICON);
1587 ok(hwnd != NULL, "failed to create a listview window\n");
1589 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
1590 expect(NFR_ANSI, r);
1592 /* reset the icon spacing to defaults */
1593 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1595 /* now we can request what the defaults are */
1596 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1600 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1602 trace("test icon spacing\n");
1604 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1605 ok(r == MAKELONG(w, h) ||
1606 broken(r == MAKELONG(w, w)), /* win98 */
1607 "Expected %d, got %d\n", MAKELONG(w, h), r);
1609 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1613 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1614 DestroyWindow(hwnd);
1617 expect(MAKELONG(20,30), r);
1619 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1620 expect(MAKELONG(25,35), r);
1622 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1624 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1625 DestroyWindow(hwnd);
1628 static void test_color(void)
1630 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1637 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1639 hwnd = create_listview_control(0);
1640 ok(hwnd != NULL, "failed to create a listview window\n");
1642 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1644 trace("test color seq\n");
1645 for (i = 0; i < 4; i++)
1649 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1651 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1654 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1656 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1659 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1661 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1665 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1667 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1668 DestroyWindow(hwnd);
1671 static void test_item_count(void)
1673 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1686 static CHAR item0text[] = "item0";
1687 static CHAR item1text[] = "item1";
1688 static CHAR item2text[] = "item2";
1690 hwnd = create_listview_control(0);
1691 ok(hwnd != NULL, "failed to create a listview window\n");
1693 /* resize in dpiaware manner to fit all 3 items added */
1695 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1696 GetTextMetricsA(hdc, &tm);
1697 /* 2 extra pixels for bounds and header border */
1698 height = tm.tmHeight + 2;
1699 SelectObject(hdc, hOldFont);
1702 GetWindowRect(hwnd, &rect);
1703 /* 3 items + 1 header + 1 to be sure */
1704 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1706 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1708 trace("test item count\n");
1710 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1714 item0.mask = LVIF_TEXT;
1717 item0.pszText = item0text;
1718 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1721 /* [item0, item1] */
1722 item1.mask = LVIF_TEXT;
1725 item1.pszText = item1text;
1726 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1729 /* [item0, item1, item2] */
1730 item2.mask = LVIF_TEXT;
1733 item2.pszText = item2text;
1734 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1737 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1740 /* [item0, item1] */
1741 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1744 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1748 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1751 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1755 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1758 /* [item0, item1] */
1759 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1762 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1765 /* [item0, item1, item2] */
1766 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1769 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1772 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1774 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1775 DestroyWindow(hwnd);
1778 static void test_item_position(void)
1780 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1789 static CHAR item0text[] = "item0";
1790 static CHAR item1text[] = "item1";
1791 static CHAR item2text[] = "item2";
1793 hwnd = create_custom_listview_control(LVS_ICON);
1794 ok(hwnd != NULL, "failed to create a listview window\n");
1796 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1798 trace("test item position\n");
1801 item0.mask = LVIF_TEXT;
1804 item0.pszText = item0text;
1805 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1808 /* [item0, item1] */
1809 item1.mask = LVIF_TEXT;
1812 item1.pszText = item1text;
1813 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1816 /* [item0, item1, item2] */
1817 item2.mask = LVIF_TEXT;
1820 item2.pszText = item2text;
1821 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1824 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1826 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1828 expect2(10, 5, position.x, position.y);
1830 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1832 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1834 expect2(0, 0, position.x, position.y);
1836 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1838 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1840 expect2(20, 20, position.x, position.y);
1842 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1844 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1845 DestroyWindow(hwnd);
1848 static void test_getorigin(void)
1856 position.x = position.y = 0;
1858 hwnd = create_custom_listview_control(LVS_ICON);
1859 ok(hwnd != NULL, "failed to create a listview window\n");
1860 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1861 trace("test get origin results\n");
1862 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1864 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1865 DestroyWindow(hwnd);
1867 hwnd = create_custom_listview_control(LVS_SMALLICON);
1868 ok(hwnd != NULL, "failed to create a listview window\n");
1869 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1870 trace("test get origin results\n");
1871 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1873 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1874 DestroyWindow(hwnd);
1876 hwnd = create_custom_listview_control(LVS_LIST);
1877 ok(hwnd != NULL, "failed to create a listview window\n");
1878 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1879 trace("test get origin results\n");
1880 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1882 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1883 DestroyWindow(hwnd);
1885 hwnd = create_custom_listview_control(LVS_REPORT);
1886 ok(hwnd != NULL, "failed to create a listview window\n");
1887 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1888 trace("test get origin results\n");
1889 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1891 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1892 DestroyWindow(hwnd);
1896 static void test_multiselect(void)
1898 typedef struct t_select_task
1909 int i,j,item_count,selected_count;
1910 static const int items=5;
1916 static struct t_select_task task_list[] = {
1917 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1918 { "using VK_UP", -1, VK_UP, -1, -1 },
1919 { "using VK_END", 0, VK_END, 1, -1 },
1920 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1924 hwnd = create_listview_control(0);
1926 for (i=0;i<items;i++) {
1927 insert_item(hwnd, 0);
1930 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1932 expect(items,item_count);
1935 task = task_list[i];
1937 /* deselect all items */
1938 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1939 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1941 /* set initial position */
1942 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1943 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1945 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1947 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1949 /* Set SHIFT key pressed */
1950 GetKeyboardState(kstate);
1951 kstate[VK_SHIFT]=0x80;
1952 SetKeyboardState(kstate);
1954 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1955 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1957 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1961 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1963 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);
1965 /* Set SHIFT key released */
1966 GetKeyboardState(kstate);
1967 kstate[VK_SHIFT]=0x00;
1968 SetKeyboardState(kstate);
1970 DestroyWindow(hwnd);
1972 /* make multiple selection, then switch to LVS_SINGLESEL */
1973 hwnd = create_listview_control(0);
1974 for (i=0;i<items;i++) {
1975 insert_item(hwnd, 0);
1977 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1978 expect(items,item_count);
1980 /* try with NULL pointer */
1981 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)NULL);
1984 /* select all, check notifications */
1985 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1987 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1989 item.stateMask = LVIS_SELECTED;
1990 item.state = LVIS_SELECTED;
1991 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1994 ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
1995 "select all notification", FALSE);
1997 /* deselect all items */
1998 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1999 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2001 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
2004 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2006 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2009 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2010 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2011 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2012 /* check that style is accepted */
2013 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2014 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2017 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2018 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2020 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2022 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2025 /* select one more */
2026 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2029 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2030 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2032 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2033 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2035 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2037 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2040 /* try to select all on LVS_SINGLESEL */
2041 memset(&item, 0, sizeof(item));
2042 item.stateMask = LVIS_SELECTED;
2043 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2045 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2047 item.stateMask = LVIS_SELECTED;
2048 item.state = LVIS_SELECTED;
2049 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2052 r = ListView_GetSelectedCount(hwnd);
2054 r = ListView_GetSelectionMark(hwnd);
2057 /* try to deselect all on LVS_SINGLESEL */
2058 item.stateMask = LVIS_SELECTED;
2059 item.state = LVIS_SELECTED;
2060 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2063 item.stateMask = LVIS_SELECTED;
2065 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2067 r = ListView_GetSelectedCount(hwnd);
2070 DestroyWindow(hwnd);
2073 static void test_subitem_rect(void)
2080 /* test LVM_GETSUBITEMRECT for header */
2081 hwnd = create_listview_control(0);
2082 ok(hwnd != NULL, "failed to create a listview window\n");
2083 /* add some columns */
2084 memset(&col, 0, sizeof(LVCOLUMN));
2085 col.mask = LVCF_WIDTH;
2088 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2092 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2096 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2098 /* item = -1 means header, subitem index is 1 based */
2099 rect.left = LVIR_BOUNDS;
2101 rect.right = rect.bottom = 0;
2102 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2105 rect.left = LVIR_BOUNDS;
2107 rect.right = rect.bottom = 0;
2108 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2110 ok(r != 0, "Expected not-null LRESULT\n");
2111 expect(100, rect.left);
2112 expect(250, rect.right);
2114 expect(3, rect.top);
2116 rect.left = LVIR_BOUNDS;
2118 rect.right = rect.bottom = 0;
2119 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2121 ok(r != 0, "Expected not-null LRESULT\n");
2122 expect(250, rect.left);
2123 expect(450, rect.right);
2125 expect(3, rect.top);
2127 /* item LVS_REPORT padding isn't applied to subitems */
2128 insert_item(hwnd, 0);
2130 rect.left = LVIR_BOUNDS;
2132 rect.right = rect.bottom = 0;
2133 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2134 ok(r != 0, "Expected not-null LRESULT\n");
2135 expect(100, rect.left);
2136 expect(250, rect.right);
2138 rect.left = LVIR_ICON;
2140 rect.right = rect.bottom = 0;
2141 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2142 ok(r != 0, "Expected not-null LRESULT\n");
2143 /* no icon attached - zero width rectangle, with no left padding */
2144 expect(100, rect.left);
2145 expect(100, rect.right);
2147 rect.left = LVIR_LABEL;
2149 rect.right = rect.bottom = 0;
2150 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2151 ok(r != 0, "Expected not-null LRESULT\n");
2152 /* same as full LVIR_BOUNDS */
2153 expect(100, rect.left);
2154 expect(250, rect.right);
2156 DestroyWindow(hwnd);
2158 /* try it for non LVS_REPORT style */
2159 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2160 GetModuleHandle(NULL), 0);
2161 rect.left = LVIR_BOUNDS;
2163 rect.right = rect.bottom = -10;
2164 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2165 ok(r == 0, "Expected not-null LRESULT\n");
2166 /* rect is unchanged */
2167 expect(0, rect.left);
2168 expect(-10, rect.right);
2169 expect(1, rect.top);
2170 expect(-10, rect.bottom);
2171 DestroyWindow(hwnd);
2174 /* comparison callback for test_sorting */
2175 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2177 if (first == second) return 0;
2178 return (first > second ? 1 : -1);
2181 static void test_sorting(void)
2187 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2190 hwnd = create_listview_control(0);
2191 ok(hwnd != NULL, "failed to create a listview window\n");
2193 /* insert some items */
2194 item.mask = LVIF_PARAM | LVIF_STATE;
2195 item.state = LVIS_SELECTED;
2199 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2202 item.mask = LVIF_PARAM;
2206 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2209 item.mask = LVIF_STATE | LVIF_PARAM;
2210 item.state = LVIS_SELECTED;
2214 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2217 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2220 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2223 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2226 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2228 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2230 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2232 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2233 expect(LVIS_SELECTED, r);
2234 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2235 expect(LVIS_SELECTED, r);
2237 DestroyWindow(hwnd);
2239 /* switch to LVS_SORTASCENDING when some items added */
2240 hwnd = create_listview_control(0);
2241 ok(hwnd != NULL, "failed to create a listview window\n");
2243 item.mask = LVIF_TEXT;
2246 item.pszText = names[1];
2247 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2250 item.mask = LVIF_TEXT;
2253 item.pszText = names[2];
2254 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2257 item.mask = LVIF_TEXT;
2260 item.pszText = names[0];
2261 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2264 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2265 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2266 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2267 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2269 /* no sorting performed when switched to LVS_SORTASCENDING */
2270 item.mask = LVIF_TEXT;
2272 item.pszText = buff;
2273 item.cchTextMax = sizeof(buff);
2274 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2276 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2279 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2281 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2284 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2286 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2288 /* adding new item doesn't resort list */
2289 item.mask = LVIF_TEXT;
2292 item.pszText = names[3];
2293 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2296 item.mask = LVIF_TEXT;
2298 item.pszText = buff;
2299 item.cchTextMax = sizeof(buff);
2300 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2302 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2305 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2307 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2310 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2312 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2315 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2317 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2319 /* corner case - item should be placed at first position */
2320 item.mask = LVIF_TEXT;
2323 item.pszText = names[4];
2324 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2328 item.pszText = buff;
2329 item.cchTextMax = sizeof(buff);
2330 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2332 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2335 item.pszText = buff;
2336 item.cchTextMax = sizeof(buff);
2337 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2339 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2342 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2344 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2347 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2349 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2352 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2354 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2356 DestroyWindow(hwnd);
2359 static void test_ownerdata(void)
2362 LONG_PTR style, ret;
2366 /* it isn't possible to set LVS_OWNERDATA after creation */
2369 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2373 hwnd = create_listview_control(0);
2374 ok(hwnd != NULL, "failed to create a listview window\n");
2375 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2376 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2378 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2380 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2381 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2382 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2383 "try to switch to LVS_OWNERDATA seq", FALSE);
2385 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2386 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2387 DestroyWindow(hwnd);
2390 /* try to set LVS_OWNERDATA after creation just having it */
2391 hwnd = create_listview_control(LVS_OWNERDATA);
2392 ok(hwnd != NULL, "failed to create a listview window\n");
2393 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2394 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2396 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2398 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2399 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2400 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2401 "try to switch to LVS_OWNERDATA seq", FALSE);
2402 DestroyWindow(hwnd);
2404 /* try to remove LVS_OWNERDATA after creation just having it */
2407 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2411 hwnd = create_listview_control(LVS_OWNERDATA);
2412 ok(hwnd != NULL, "failed to create a listview window\n");
2413 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2414 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2416 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2418 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2419 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2420 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2421 "try to switch to LVS_OWNERDATA seq", FALSE);
2422 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2423 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2424 DestroyWindow(hwnd);
2427 /* try select an item */
2428 hwnd = create_listview_control(LVS_OWNERDATA);
2429 ok(hwnd != NULL, "failed to create a listview window\n");
2430 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2431 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2432 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2434 memset(&item, 0, sizeof(item));
2435 item.stateMask = LVIS_SELECTED;
2436 item.state = LVIS_SELECTED;
2437 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2439 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2441 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2443 DestroyWindow(hwnd);
2445 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2446 hwnd = create_listview_control(LVS_OWNERDATA);
2447 ok(hwnd != NULL, "failed to create a listview window\n");
2448 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2449 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2450 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2452 memset(&item, 0, sizeof(item));
2453 item.mask = LVIF_STATE;
2455 item.stateMask = LVIS_SELECTED;
2456 item.state = LVIS_SELECTED;
2457 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2459 DestroyWindow(hwnd);
2461 /* check notifications after focused/selected changed */
2462 hwnd = create_listview_control(LVS_OWNERDATA);
2463 ok(hwnd != NULL, "failed to create a listview window\n");
2464 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2465 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2467 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2469 memset(&item, 0, sizeof(item));
2470 item.stateMask = LVIS_SELECTED;
2471 item.state = LVIS_SELECTED;
2472 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2475 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2476 "ownerdata select notification", TRUE);
2478 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2480 memset(&item, 0, sizeof(item));
2481 item.stateMask = LVIS_FOCUSED;
2482 item.state = LVIS_FOCUSED;
2483 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2486 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2487 "ownerdata focus notification", TRUE);
2489 /* select all, check notifications */
2490 item.stateMask = LVIS_SELECTED;
2492 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2495 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2497 item.stateMask = LVIS_SELECTED;
2498 item.state = LVIS_SELECTED;
2500 g_dump_itemchanged = TRUE;
2501 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2503 g_dump_itemchanged = FALSE;
2505 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2506 "ownerdata select all notification", TRUE);
2508 /* select all again, note that all items are selected already */
2509 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2510 item.stateMask = LVIS_SELECTED;
2511 item.state = LVIS_SELECTED;
2512 g_dump_itemchanged = TRUE;
2513 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2515 g_dump_itemchanged = FALSE;
2516 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2517 "ownerdata select all notification", TRUE);
2519 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2520 item.stateMask = LVIS_SELECTED;
2522 g_dump_itemchanged = TRUE;
2523 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2525 g_dump_itemchanged = FALSE;
2526 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2527 "ownerdata deselect all notification", TRUE);
2529 /* select one, then deselect all */
2530 item.stateMask = LVIS_SELECTED;
2531 item.state = LVIS_SELECTED;
2532 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2534 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2535 item.stateMask = LVIS_SELECTED;
2537 g_dump_itemchanged = TRUE;
2538 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2540 g_dump_itemchanged = FALSE;
2541 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2542 "ownerdata select all notification", TRUE);
2544 /* remove focused, try to focus all */
2545 item.stateMask = LVIS_FOCUSED;
2546 item.state = LVIS_FOCUSED;
2547 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2549 item.stateMask = LVIS_FOCUSED;
2551 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2553 item.stateMask = LVIS_FOCUSED;
2554 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
2556 /* setting all to focused returns failure value */
2557 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2558 item.stateMask = LVIS_FOCUSED;
2559 item.state = LVIS_FOCUSED;
2560 g_dump_itemchanged = TRUE;
2561 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2563 g_dump_itemchanged = FALSE;
2564 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2565 "ownerdata focus all notification", FALSE);
2566 /* focus single item, remove all */
2567 item.stateMask = LVIS_FOCUSED;
2568 item.state = LVIS_FOCUSED;
2569 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2571 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2572 item.stateMask = LVIS_FOCUSED;
2574 g_dump_itemchanged = TRUE;
2575 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2577 g_dump_itemchanged = FALSE;
2578 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
2579 "ownerdata remove focus all notification", TRUE);
2581 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2582 item.stateMask = LVIS_CUT;
2583 item.state = LVIS_CUT;
2584 g_dump_itemchanged = TRUE;
2585 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2587 g_dump_itemchanged = FALSE;
2588 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2589 "ownerdata cut all notification", TRUE);
2590 /* all marked cut, try again */
2591 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2592 item.stateMask = LVIS_CUT;
2593 item.state = LVIS_CUT;
2594 g_dump_itemchanged = TRUE;
2595 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2597 g_dump_itemchanged = FALSE;
2598 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2599 "ownerdata cut all notification #2", TRUE);
2601 DestroyWindow(hwnd);
2603 /* check notifications on LVM_GETITEM */
2604 /* zero callback mask */
2605 hwnd = create_listview_control(LVS_OWNERDATA);
2606 ok(hwnd != NULL, "failed to create a listview window\n");
2607 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2608 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2610 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2612 memset(&item, 0, sizeof(item));
2613 item.stateMask = LVIS_SELECTED;
2614 item.mask = LVIF_STATE;
2615 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2618 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2619 "ownerdata getitem selected state 1", FALSE);
2621 /* non zero callback mask but not we asking for */
2622 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2625 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2627 memset(&item, 0, sizeof(item));
2628 item.stateMask = LVIS_SELECTED;
2629 item.mask = LVIF_STATE;
2630 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2633 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2634 "ownerdata getitem selected state 2", FALSE);
2636 /* LVIS_OVERLAYMASK callback mask, asking for index */
2637 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2639 memset(&item, 0, sizeof(item));
2640 item.stateMask = LVIS_OVERLAYMASK;
2641 item.mask = LVIF_STATE;
2642 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2645 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2646 "ownerdata getitem selected state 2", FALSE);
2648 DestroyWindow(hwnd);
2650 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2651 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING);
2652 ok(hwnd != NULL, "failed to create a listview window\n");
2653 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2654 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2655 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2656 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2657 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2658 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2659 DestroyWindow(hwnd);
2660 /* apparently it's allowed to switch these style on after creation */
2661 hwnd = create_listview_control(LVS_OWNERDATA);
2662 ok(hwnd != NULL, "failed to create a listview window\n");
2663 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2664 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2665 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2666 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2667 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2668 DestroyWindow(hwnd);
2670 hwnd = create_listview_control(LVS_OWNERDATA);
2671 ok(hwnd != NULL, "failed to create a listview window\n");
2672 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2673 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2674 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2675 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2676 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2677 DestroyWindow(hwnd);
2680 static void test_norecompute(void)
2682 static CHAR testA[] = "test";
2688 /* self containing control */
2689 hwnd = create_listview_control(0);
2690 ok(hwnd != NULL, "failed to create a listview window\n");
2691 memset(&item, 0, sizeof(item));
2692 item.mask = LVIF_TEXT | LVIF_STATE;
2694 item.stateMask = LVIS_SELECTED;
2695 item.state = LVIS_SELECTED;
2696 item.pszText = testA;
2697 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2699 /* retrieve with LVIF_NORECOMPUTE */
2700 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2702 item.pszText = buff;
2703 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2704 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2706 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2708 item.mask = LVIF_TEXT;
2710 item.pszText = LPSTR_TEXTCALLBACK;
2711 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2714 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2716 item.pszText = buff;
2717 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2719 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2720 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2722 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2723 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2724 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2726 DestroyWindow(hwnd);
2729 hwnd = create_listview_control(LVS_OWNERDATA);
2730 ok(hwnd != NULL, "failed to create a listview window\n");
2732 item.mask = LVIF_STATE;
2733 item.stateMask = LVIS_SELECTED;
2734 item.state = LVIS_SELECTED;
2736 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2739 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2741 item.pszText = buff;
2742 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2743 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2744 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2746 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2747 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2748 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2750 DestroyWindow(hwnd);
2753 static void test_nosortheader(void)
2758 hwnd = create_listview_control(0);
2759 ok(hwnd != NULL, "failed to create a listview window\n");
2761 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2762 ok(IsWindow(header), "header expected\n");
2764 style = GetWindowLongPtr(header, GWL_STYLE);
2765 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2767 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2768 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2769 /* HDS_BUTTONS retained */
2770 style = GetWindowLongPtr(header, GWL_STYLE);
2771 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2773 DestroyWindow(hwnd);
2775 /* create with LVS_NOSORTHEADER */
2776 hwnd = create_listview_control(LVS_NOSORTHEADER);
2777 ok(hwnd != NULL, "failed to create a listview window\n");
2779 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2780 ok(IsWindow(header), "header expected\n");
2782 style = GetWindowLongPtr(header, GWL_STYLE);
2783 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2785 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2786 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2787 /* not changed here */
2788 style = GetWindowLongPtr(header, GWL_STYLE);
2789 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2791 DestroyWindow(hwnd);
2794 static void test_setredraw(void)
2802 hwnd = create_listview_control(LVS_OWNERDATA);
2803 ok(hwnd != NULL, "failed to create a listview window\n");
2805 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2806 ListView seems to handle it internally without DefWinProc */
2808 /* default value first */
2809 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2812 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2813 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2814 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2816 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2817 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2818 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2821 /* check update rect after redrawing */
2822 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2824 InvalidateRect(hwnd, NULL, FALSE);
2825 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
2826 rect.right = rect.bottom = 1;
2827 GetUpdateRect(hwnd, &rect, FALSE);
2828 expect(0, rect.right);
2829 expect(0, rect.bottom);
2832 hdc = GetWindowDC(hwndparent);
2833 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2835 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2837 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2839 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2841 ReleaseDC(hwndparent, hdc);
2843 /* check notification messages to show that repainting is disabled */
2844 ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
2846 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2848 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2850 InvalidateRect(hwnd, NULL, TRUE);
2852 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2853 "redraw after WM_SETREDRAW (FALSE)", FALSE);
2855 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
2857 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2858 InvalidateRect(hwnd, NULL, TRUE);
2860 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2861 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
2863 /* message isn't forwarded to header */
2864 subclass_header(hwnd);
2865 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2866 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2868 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
2869 "WM_SETREDRAW: not forwarded to header", FALSE);
2871 DestroyWindow(hwnd);
2874 static void test_hittest(void)
2880 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2883 HIMAGELIST himl, himl2;
2886 hwnd = create_listview_control(0);
2887 ok(hwnd != NULL, "failed to create a listview window\n");
2889 /* LVS_REPORT with a single subitem (2 columns) */
2890 insert_column(hwnd, 0);
2891 insert_column(hwnd, 1);
2892 insert_item(hwnd, 0);
2895 /* the only purpose of that line is to be as long as a half item rect */
2896 item.pszText = text;
2897 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2900 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2902 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
2905 memset(&bounds, 0, sizeof(bounds));
2906 bounds.left = LVIR_BOUNDS;
2907 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
2908 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
2909 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
2910 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
2913 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2914 x = pos.x + 50; /* column half width */
2915 y = pos.y + (bounds.bottom - bounds.top) / 2;
2916 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE, __LINE__);
2917 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2918 x = pos.x + 150; /* outside column */
2919 y = pos.y + (bounds.bottom - bounds.top) / 2;
2920 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2921 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2922 y = (bounds.bottom - bounds.top) / 2;
2923 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2924 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2925 /* outside possible client rectangle (to right) */
2927 y = pos.y + (bounds.bottom - bounds.top) / 2;
2928 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2929 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2930 y = (bounds.bottom - bounds.top) / 2;
2931 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2932 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2933 /* subitem returned with -1 item too */
2936 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2937 /* parent client area is 100x100 by default */
2938 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
2939 x = pos.x + 150; /* outside column */
2940 y = pos.y + (bounds.bottom - bounds.top) / 2;
2941 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE, __LINE__);
2942 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2943 y = (bounds.bottom - bounds.top) / 2;
2944 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE, __LINE__);
2945 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2946 /* the same with LVS_EX_FULLROWSELECT */
2947 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
2948 x = pos.x + 150; /* outside column */
2949 y = pos.y + (bounds.bottom - bounds.top) / 2;
2950 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE, __LINE__);
2951 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2952 y = (bounds.bottom - bounds.top) / 2;
2953 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2954 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
2955 x = pos.x + 150; /* outside column */
2956 y = pos.y + (bounds.bottom - bounds.top) / 2;
2957 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2958 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2959 y = (bounds.bottom - bounds.top) / 2;
2960 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2961 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2962 /* outside possible client rectangle (to right) */
2964 y = pos.y + (bounds.bottom - bounds.top) / 2;
2965 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2966 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2967 y = (bounds.bottom - bounds.top) / 2;
2968 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2969 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2970 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2971 himl = ImageList_Create(16, 16, 0, 4, 4);
2972 ok(himl != NULL, "failed to create imagelist\n");
2973 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2974 ok(hbmp != NULL, "failed to create bitmap\n");
2975 r = ImageList_Add(himl, hbmp, 0);
2976 ok(r == 0, "should be zero\n");
2977 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2978 ok(hbmp != NULL, "failed to create bitmap\n");
2979 r = ImageList_Add(himl, hbmp, 0);
2980 ok(r == 1, "should be one\n");
2982 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2983 ok(r == 0, "should return zero\n");
2985 item.mask = LVIF_IMAGE;
2989 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2993 y = pos.y + (bounds.bottom - bounds.top) / 2;
2994 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE, __LINE__);
2995 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2996 y = (bounds.bottom - bounds.top) / 2;
2997 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2999 /* state icons indices are 1 based, check with valid index */
3000 item.mask = LVIF_STATE;
3001 item.state = INDEXTOSTATEIMAGEMASK(1);
3002 item.stateMask = LVIS_STATEIMAGEMASK;
3005 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3009 y = pos.y + (bounds.bottom - bounds.top) / 2;
3010 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE, __LINE__);
3011 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
3012 y = (bounds.bottom - bounds.top) / 2;
3013 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
3015 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
3016 ok(himl2 == himl, "should return handle\n");
3018 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3019 ok(r == 0, "should return zero\n");
3022 y = pos.y + (bounds.bottom - bounds.top) / 2;
3023 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE, __LINE__);
3024 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
3025 y = (bounds.bottom - bounds.top) / 2;
3026 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
3028 DestroyWindow(hwnd);
3031 static void test_getviewrect(void)
3038 hwnd = create_listview_control(0);
3039 ok(hwnd != NULL, "failed to create a listview window\n");
3042 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3045 insert_column(hwnd, 0);
3046 insert_column(hwnd, 1);
3048 memset(&item, 0, sizeof(item));
3051 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3053 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3055 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3058 rect.left = rect.right = rect.top = rect.bottom = -1;
3059 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3061 /* left is set to (2e31-1) - XP SP2 */
3062 expect(0, rect.right);
3063 expect(0, rect.top);
3064 expect(0, rect.bottom);
3066 /* switch to LVS_ICON */
3067 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3069 rect.left = rect.right = rect.top = rect.bottom = -1;
3070 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3072 expect(0, rect.left);
3073 expect(0, rect.top);
3074 /* precise value differs for 2k, XP and Vista */
3075 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3076 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3078 DestroyWindow(hwnd);
3081 static void test_getitemposition(void)
3088 hwnd = create_listview_control(0);
3089 ok(hwnd != NULL, "failed to create a listview window\n");
3090 header = subclass_header(hwnd);
3092 /* LVS_REPORT, single item, no columns added */
3093 insert_item(hwnd, 0);
3095 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3098 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3100 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3102 /* LVS_REPORT, single item, single column */
3103 insert_column(hwnd, 0);
3105 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3108 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3110 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3112 memset(&rect, 0, sizeof(rect));
3113 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3116 /* offset by header height */
3117 expect(rect.bottom - rect.top, pt.y);
3119 DestroyWindow(hwnd);
3122 static void test_columnscreation(void)
3127 hwnd = create_listview_control(0);
3128 ok(hwnd != NULL, "failed to create a listview window\n");
3130 insert_item(hwnd, 0);
3132 /* headers columns aren't created automatically */
3133 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3134 ok(IsWindow(header), "Expected header handle\n");
3135 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3138 DestroyWindow(hwnd);
3141 static void test_getitemrect(void)
3153 hwnd = create_listview_control(0);
3154 ok(hwnd != NULL, "failed to create a listview window\n");
3157 memset(&item, 0, sizeof(item));
3160 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3163 rect.left = LVIR_BOUNDS;
3164 rect.right = rect.top = rect.bottom = -1;
3165 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3168 /* zero width rectangle with no padding */
3169 expect(0, rect.left);
3170 expect(0, rect.right);
3172 insert_column(hwnd, 0);
3173 insert_column(hwnd, 1);
3175 col.mask = LVCF_WIDTH;
3177 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3180 col.mask = LVCF_WIDTH;
3182 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3185 rect.left = LVIR_BOUNDS;
3186 rect.right = rect.top = rect.bottom = -1;
3187 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3190 /* still no left padding */
3191 expect(0, rect.left);
3192 expect(150, rect.right);
3194 rect.left = LVIR_SELECTBOUNDS;
3195 rect.right = rect.top = rect.bottom = -1;
3196 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3199 expect(2, rect.left);
3201 rect.left = LVIR_LABEL;
3202 rect.right = rect.top = rect.bottom = -1;
3203 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3205 /* padding, column width */
3206 expect(2, rect.left);
3207 expect(50, rect.right);
3209 /* no icons attached */
3210 rect.left = LVIR_ICON;
3211 rect.right = rect.top = rect.bottom = -1;
3212 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3215 expect(2, rect.left);
3216 expect(2, rect.right);
3219 order[0] = 1; order[1] = 0;
3220 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3223 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3225 /* 1 indexed column width + padding */
3227 /* rect is at zero too */
3228 rect.left = LVIR_BOUNDS;
3229 rect.right = rect.top = rect.bottom = -1;
3230 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3232 expect(0, rect.left);
3233 /* just width sum */
3234 expect(150, rect.right);
3236 rect.left = LVIR_SELECTBOUNDS;
3237 rect.right = rect.top = rect.bottom = -1;
3238 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3240 /* column width + padding */
3241 expect(102, rect.left);
3243 /* back to initial order */
3244 order[0] = 0; order[1] = 1;
3245 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3249 himl = ImageList_Create(16, 16, 0, 2, 2);
3250 ok(himl != NULL, "failed to create imagelist\n");
3251 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3252 ok(hbm != NULL, "failed to create bitmap\n");
3253 r = ImageList_Add(himl, hbm, 0);
3254 ok(r == 0, "should be zero\n");
3255 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3256 ok(hbm != NULL, "failed to create bitmap\n");
3257 r = ImageList_Add(himl, hbm, 0);
3258 ok(r == 1, "should be one\n");
3260 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3261 ok(r == 0, "should return zero\n");
3263 item.mask = LVIF_STATE;
3264 item.state = INDEXTOSTATEIMAGEMASK(1);
3265 item.stateMask = LVIS_STATEIMAGEMASK;
3268 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3272 rect.left = LVIR_ICON;
3273 rect.right = rect.top = rect.bottom = -1;
3274 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3276 /* padding + stateicon width */
3277 expect(18, rect.left);
3278 expect(18, rect.right);
3280 rect.left = LVIR_LABEL;
3281 rect.right = rect.top = rect.bottom = -1;
3282 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3284 /* padding + stateicon width -> column width */
3285 expect(18, rect.left);
3286 expect(50, rect.right);
3288 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
3289 ok(r != 0, "should return current list handle\n");
3291 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3292 ok(r == 0, "should return zero\n");
3294 item.mask = LVIF_STATE | LVIF_IMAGE;
3297 item.stateMask = ~0;
3300 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3304 rect.left = LVIR_ICON;
3305 rect.right = rect.top = rect.bottom = -1;
3306 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3308 /* padding, icon width */
3309 expect(2, rect.left);
3310 expect(18, rect.right);
3312 rect.left = LVIR_LABEL;
3313 rect.right = rect.top = rect.bottom = -1;
3314 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3316 /* padding + icon width -> column width */
3317 expect(18, rect.left);
3318 expect(50, rect.right);
3321 rect.left = LVIR_SELECTBOUNDS;
3322 rect.right = rect.top = rect.bottom = -1;
3323 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3325 /* padding, column width */
3326 expect(2, rect.left);
3327 expect(50, rect.right);
3329 /* try with indentation */
3330 item.mask = LVIF_INDENT;
3334 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3338 rect.left = LVIR_BOUNDS;
3339 rect.right = rect.top = rect.bottom = -1;
3340 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3342 /* padding + 1 icon width, column width */
3343 expect(0, rect.left);
3344 expect(150, rect.right);
3347 rect.left = LVIR_SELECTBOUNDS;
3348 rect.right = rect.top = rect.bottom = -1;
3349 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3351 /* padding + 1 icon width, column width */
3352 expect(2 + 16, rect.left);
3353 expect(50, rect.right);
3356 rect.left = LVIR_LABEL;
3357 rect.right = rect.top = rect.bottom = -1;
3358 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3360 /* padding + 2 icon widths, column width */
3361 expect(2 + 16*2, rect.left);
3362 expect(50, rect.right);
3365 rect.left = LVIR_ICON;
3366 rect.right = rect.top = rect.bottom = -1;
3367 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3369 /* padding + 1 icon width indentation, icon width */
3370 expect(2 + 16, rect.left);
3371 expect(34, rect.right);
3374 DestroyWindow(hwnd);
3377 static void test_editbox(void)
3379 HWND hwnd, hwndedit, hwndedit2;
3382 static CHAR testitemA[] = "testitem";
3383 static CHAR testitem1A[] = "testitem1";
3384 static CHAR buffer[10];
3386 hwnd = create_listview_control(LVS_EDITLABELS);
3387 ok(hwnd != NULL, "failed to create a listview window\n");
3389 insert_column(hwnd, 0);
3391 memset(&item, 0, sizeof(item));
3392 item.mask = LVIF_TEXT;
3393 item.pszText = testitemA;
3396 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3399 /* setting focus is necessary */
3401 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3402 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3404 /* modify initial string */
3405 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3407 /* return focus to listview */
3410 memset(&item, 0, sizeof(item));
3411 item.mask = LVIF_TEXT;
3412 item.pszText = buffer;
3413 item.cchTextMax = 10;
3416 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3419 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3421 /* send LVM_EDITLABEL on already created edit */
3423 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3424 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3425 /* focus will be set to edit */
3426 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3427 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3428 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3430 /* creating label disabled when control isn't focused */
3432 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3433 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3435 /* check EN_KILLFOCUS handling */
3436 memset(&item, 0, sizeof(item));
3437 item.pszText = testitemA;
3440 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3444 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3445 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3446 /* modify edit and notify control that it lost focus */
3447 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3449 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3451 memset(&item, 0, sizeof(item));
3452 item.pszText = buffer;
3453 item.cchTextMax = 10;
3456 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3457 expect(lstrlen(item.pszText), r);
3458 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3459 /* end edit without saving */
3460 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3462 memset(&item, 0, sizeof(item));
3463 item.pszText = buffer;
3464 item.cchTextMax = 10;
3467 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3468 expect(lstrlen(item.pszText), r);
3469 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3471 /* LVM_EDITLABEL with -1 destroys current edit */
3472 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3473 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3474 /* no edit present */
3475 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3476 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3477 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3478 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3480 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3481 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3482 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3483 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3484 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3485 /* check another negative value */
3486 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3487 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3488 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3489 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3490 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3491 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3492 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3493 /* and value greater than max item index */
3494 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3495 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3496 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3497 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3498 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3499 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3500 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3501 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3503 /* messaging tests */
3505 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3507 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3508 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3509 /* testing only sizing messages */
3510 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3511 "edit box create - sizing", FALSE);
3513 DestroyWindow(hwnd);
3516 static void test_notifyformat(void)
3521 hwnd = create_listview_control(0);
3522 ok(hwnd != NULL, "failed to create a listview window\n");
3524 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3525 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3526 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3528 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3530 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3532 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3535 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3537 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3542 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3543 DestroyWindow(hwnd);
3547 DestroyWindow(hwnd);
3549 /* test failure in parent WM_NOTIFYFORMAT */
3551 hwnd = create_listview_control(0);
3552 ok(hwnd != NULL, "failed to create a listview window\n");
3553 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3554 ok(IsWindow(header), "expected header to be created\n");
3555 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3557 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3558 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3559 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3560 ok(r != 0, "Expected valid format\n");
3562 notifyFormat = NFR_UNICODE;
3563 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3564 expect(NFR_UNICODE, r);
3565 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3567 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3568 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3570 notifyFormat = NFR_ANSI;
3571 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3572 expect(NFR_ANSI, r);
3573 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3575 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3576 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3578 DestroyWindow(hwnd);
3580 /* try different unicode window combination and defaults */
3581 if (!GetModuleHandleW(NULL))
3583 win_skip("Additional notify format tests are incompatible with Win9x\n");
3587 hwndparentW = create_parent_window(TRUE);
3588 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3589 if (!IsWindow(hwndparentW)) return;
3592 hwnd = create_listview_controlW(0, hwndparentW);
3593 ok(hwnd != NULL, "failed to create a listview window\n");
3594 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3595 ok(IsWindow(header), "expected header to be created\n");
3596 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3598 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3600 DestroyWindow(hwnd);
3601 /* receiving error code defaulting to ansi */
3603 hwnd = create_listview_controlW(0, hwndparentW);
3604 ok(hwnd != NULL, "failed to create a listview window\n");
3605 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3606 ok(IsWindow(header), "expected header to be created\n");
3607 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3609 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3611 DestroyWindow(hwnd);
3612 /* receiving ansi code from unicode window, use it */
3613 notifyFormat = NFR_ANSI;
3614 hwnd = create_listview_controlW(0, hwndparentW);
3615 ok(hwnd != NULL, "failed to create a listview window\n");
3616 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3617 ok(IsWindow(header), "expected header to be created\n");
3618 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3620 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3622 DestroyWindow(hwnd);
3623 /* unicode listview with ansi parent window */
3625 hwnd = create_listview_controlW(0, hwndparent);
3626 ok(hwnd != NULL, "failed to create a listview window\n");
3627 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3628 ok(IsWindow(header), "expected header to be created\n");
3629 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3631 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3633 DestroyWindow(hwnd);
3634 /* unicode listview with ansi parent window, return error code */
3636 hwnd = create_listview_controlW(0, hwndparent);
3637 ok(hwnd != NULL, "failed to create a listview window\n");
3638 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3639 ok(IsWindow(header), "expected header to be created\n");
3640 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3642 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3644 DestroyWindow(hwnd);
3646 DestroyWindow(hwndparentW);
3649 static void test_indentation(void)
3655 hwnd = create_listview_control(0);
3656 ok(hwnd != NULL, "failed to create a listview window\n");
3658 memset(&item, 0, sizeof(item));
3659 item.mask = LVIF_INDENT;
3661 item.iIndent = I_INDENTCALLBACK;
3662 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3665 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3668 item.mask = LVIF_INDENT;
3669 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3672 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3673 "get indent dispinfo", FALSE);
3675 DestroyWindow(hwnd);
3678 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
3683 static BOOL is_below_comctl_5(void)
3688 hwnd = create_listview_control(0);
3689 ok(hwnd != NULL, "failed to create a listview window\n");
3690 insert_item(hwnd, 0);
3692 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
3694 DestroyWindow(hwnd);
3699 static void test_get_set_view(void)
3705 /* test style->view mapping */
3706 hwnd = create_listview_control(0);
3707 ok(hwnd != NULL, "failed to create a listview window\n");
3709 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3710 expect(LV_VIEW_DETAILS, ret);
3712 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3714 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
3715 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3716 expect(LV_VIEW_ICON, ret);
3718 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3719 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
3720 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3721 expect(LV_VIEW_SMALLICON, ret);
3723 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3724 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
3725 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3726 expect(LV_VIEW_LIST, ret);
3728 /* switching view doesn't touch window style */
3729 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
3731 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3732 ok(style & LVS_LIST, "Expected style to be preserved\n");
3733 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
3735 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3736 ok(style & LVS_LIST, "Expected style to be preserved\n");
3737 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
3739 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3740 ok(style & LVS_LIST, "Expected style to be preserved\n");
3742 DestroyWindow(hwnd);
3745 static void test_canceleditlabel(void)
3747 HWND hwnd, hwndedit;
3751 static CHAR test[] = "test";
3752 static const CHAR test1[] = "test1";
3754 hwnd = create_listview_control(LVS_EDITLABELS);
3755 ok(hwnd != NULL, "failed to create a listview window\n");
3757 insert_item(hwnd, 0);
3759 /* try without edit created */
3760 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3763 /* cancel without data change */
3765 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3766 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3767 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3769 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3771 /* cancel after data change */
3772 memset(&itema, 0, sizeof(itema));
3773 itema.pszText = test;
3774 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
3777 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3778 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3779 ret = SetWindowText(hwndedit, test1);
3780 ok(ret != 0, "Expected edit text to change\n");
3781 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3783 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3784 memset(&itema, 0, sizeof(itema));
3785 itema.pszText = buff;
3786 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
3787 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
3789 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
3791 DestroyWindow(hwnd);
3794 static void test_mapidindex(void)
3799 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3800 hwnd = create_listview_control(LVS_OWNERDATA);
3801 ok(hwnd != NULL, "failed to create a listview window\n");
3802 insert_item(hwnd, 0);
3803 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3805 DestroyWindow(hwnd);
3807 hwnd = create_listview_control(0);
3808 ok(hwnd != NULL, "failed to create a listview window\n");
3810 /* LVM_MAPINDEXTOID with invalid index */
3811 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3814 insert_item(hwnd, 0);
3815 insert_item(hwnd, 1);
3817 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
3819 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
3822 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3824 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3826 /* remove 0 indexed item, id retained */
3827 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
3828 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3830 /* new id starts from previous value */
3831 insert_item(hwnd, 1);
3832 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3835 /* get index by id */
3836 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
3838 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
3840 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
3842 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
3845 DestroyWindow(hwnd);
3848 static void test_getitemspacing(void)
3857 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
3858 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
3861 hwnd = create_custom_listview_control(0);
3862 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3864 expect(cx, LOWORD(ret));
3865 expect(cy, HIWORD(ret));
3867 /* now try with icons */
3868 himl = ImageList_Create(40, 40, 0, 4, 4);
3869 ok(himl != NULL, "failed to create imagelist\n");
3870 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
3871 ok(hbmp != NULL, "failed to create bitmap\n");
3872 ret = ImageList_Add(himl, hbmp, 0);
3874 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
3877 itema.mask = LVIF_IMAGE;
3881 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
3883 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3885 /* spacing + icon size returned */
3886 expect(cx + 40, LOWORD(ret));
3887 expect(cy + 40, HIWORD(ret));
3889 DestroyWindow(hwnd);
3891 hwnd = create_custom_listview_control(LVS_SMALLICON);
3892 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3894 expect(cx, LOWORD(ret));
3895 expect(cy, HIWORD(ret));
3897 DestroyWindow(hwnd);
3899 hwnd = create_custom_listview_control(LVS_REPORT);
3900 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3902 expect(cx, LOWORD(ret));
3903 expect(cy, HIWORD(ret));
3905 DestroyWindow(hwnd);
3907 hwnd = create_custom_listview_control(LVS_LIST);
3908 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3910 expect(cx, LOWORD(ret));
3911 expect(cy, HIWORD(ret));
3913 DestroyWindow(hwnd);
3916 static void test_getcolumnwidth(void)
3923 /* default column width */
3924 hwnd = create_custom_listview_control(0);
3925 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3927 style = GetWindowLong(hwnd, GWL_STYLE);
3928 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
3929 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3930 todo_wine expect(8, ret);
3931 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
3932 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
3934 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
3936 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3938 DestroyWindow(hwnd);
3941 static void test_scrollnotify(void)
3946 hwnd = create_listview_control(0);
3948 insert_column(hwnd, 0);
3949 insert_column(hwnd, 1);
3950 insert_item(hwnd, 0);
3952 /* make it scrollable - resize */
3953 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3955 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3958 /* try with dummy call */
3959 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3960 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
3962 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
3963 "scroll notify 1", TRUE);
3965 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3966 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
3968 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
3969 "scroll notify 2", TRUE);
3971 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3972 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
3974 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
3975 "scroll notify 3", TRUE);
3977 DestroyWindow(hwnd);
3980 static void test_LVS_EX_TRANSPARENTBKGND(void)
3986 hwnd = create_listview_control(0);
3988 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
3991 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
3992 LVS_EX_TRANSPARENTBKGND);
3994 ret = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
3995 if (ret != CLR_NONE)
3997 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
3998 DestroyWindow(hwnd);
4002 /* try to set some back color and check this style bit */
4003 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4005 ret = SendMessage(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4006 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4008 /* now test what this style actually does */
4009 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4010 LVS_EX_TRANSPARENTBKGND);
4012 hdc = GetWindowDC(hwndparent);
4014 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4015 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4016 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4017 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4019 ReleaseDC(hwndparent, hdc);
4021 DestroyWindow(hwnd);
4024 static void test_ApproximateViewRect(void)
4032 static CHAR test[] = "abracadabra, a very long item label";
4034 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4035 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4037 hwnd = create_custom_listview_control(LVS_ICON);
4038 himl = ImageList_Create(40, 40, 0, 4, 4);
4039 ok(himl != NULL, "failed to create imagelist\n");
4040 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4041 ok(hbmp != NULL, "failed to create bitmap\n");
4042 ret = ImageList_Add(himl, hbmp, 0);
4044 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4047 itema.mask = LVIF_IMAGE;
4051 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4054 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4058 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4062 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4063 ok(MAKELONG(77,827)==ret,"Incorrect Approximate rect\n");
4065 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4066 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4067 ok(MAKELONG(102,302)==ret,"Incorrect Approximate rect\n");
4069 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4070 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4072 itema.pszText = test;
4073 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4075 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4076 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4078 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4079 ok(MAKELONG(52,2)==ret,"Incorrect Approximate rect\n");
4080 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4081 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4082 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4083 ok(MAKELONG(102,52)==ret,"Incorrect Approximate rect\n");
4084 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4085 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4086 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4087 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4088 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4089 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4090 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4091 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4092 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4093 ok(MAKELONG(152,152)==ret,"Incorrect Approximate rect\n");
4095 DestroyWindow(hwnd);
4098 START_TEST(listview)
4101 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
4103 ULONG_PTR ctx_cookie;
4106 hComctl32 = GetModuleHandleA("comctl32.dll");
4107 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
4108 if (pInitCommonControlsEx)
4110 INITCOMMONCONTROLSEX iccex;
4111 iccex.dwSize = sizeof(iccex);
4112 iccex.dwICC = ICC_LISTVIEW_CLASSES;
4113 pInitCommonControlsEx(&iccex);
4116 InitCommonControls();
4118 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
4120 hwndparent = create_parent_window(FALSE);
4121 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4123 g_is_below_5 = is_below_comctl_5();
4131 test_icon_spacing();
4134 test_item_position();
4139 test_subitem_rect();
4143 test_nosortheader();
4147 test_getitemposition();
4148 test_columnscreation();
4150 test_notifyformat();
4152 test_getitemspacing();
4153 test_getcolumnwidth();
4154 test_ApproximateViewRect();
4156 if (!load_v6_module(&ctx_cookie))
4158 DestroyWindow(hwndparent);
4162 /* this is a XP SP3 failure workaround */
4163 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
4164 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
4166 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
4167 if (!IsWindow(hwnd))
4169 win_skip("FIXME: failed to create ListView window.\n");
4170 unload_v6_module(ctx_cookie);
4171 DestroyWindow(hwndparent);
4175 DestroyWindow(hwnd);
4177 /* comctl32 version 6 tests start here */
4178 test_get_set_view();
4179 test_canceleditlabel();
4181 test_scrollnotify();
4182 test_LVS_EX_TRANSPARENTBKGND();
4184 unload_v6_module(ctx_cookie);
4186 DestroyWindow(hwndparent);