4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009-2012 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 COMBINED_SEQ_INDEX 4
36 #define NUM_MSG_SEQUENCES 5
41 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
42 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
43 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
45 static const WCHAR testparentclassW[] =
46 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
48 static HWND hwndparent, hwndparentW;
49 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
50 static BOOL blockEdit;
51 /* return nonzero on NM_HOVER */
52 static BOOL g_block_hover;
53 /* notification data for LVN_ITEMCHANGED */
54 static NMLISTVIEW g_nmlistview;
55 /* format reported to control:
56 -1 falls to defproc, anything else returned */
57 static INT notifyFormat;
58 /* indicates we're running < 5.80 version */
59 static BOOL g_is_below_5;
60 /* item data passed to LVN_GETDISPINFOA */
61 static LVITEMA g_itema;
62 /* alter notification code A->W */
63 static BOOL g_disp_A_to_W;
64 /* dispinfo data sent with LVN_LVN_ENDLABELEDIT */
65 static NMLVDISPINFO g_editbox_disp_info;
67 static HWND subclass_editbox(HWND hwndListview);
69 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
71 static const struct message create_ownerdrawfixed_parent_seq[] = {
72 { WM_NOTIFYFORMAT, sent },
73 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
74 { WM_MEASUREITEM, sent },
75 { WM_PARENTNOTIFY, sent },
79 static const struct message redraw_listview_seq[] = {
80 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
81 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
82 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
83 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
84 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
85 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
86 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
90 static const struct message listview_icon_spacing_seq[] = {
91 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
92 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
93 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
97 static const struct message listview_color_seq[] = {
98 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
99 { LVM_GETBKCOLOR, sent },
100 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
101 { LVM_GETTEXTCOLOR, sent },
102 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
103 { LVM_GETTEXTBKCOLOR, sent },
105 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
106 { LVM_GETBKCOLOR, sent },
107 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
108 { LVM_GETTEXTCOLOR, sent },
109 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
110 { LVM_GETTEXTBKCOLOR, sent },
112 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
113 { LVM_GETBKCOLOR, sent },
114 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
115 { LVM_GETTEXTCOLOR, sent },
116 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
117 { LVM_GETTEXTBKCOLOR, sent },
119 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
120 { LVM_GETBKCOLOR, sent },
121 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
122 { LVM_GETTEXTCOLOR, sent },
123 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
124 { LVM_GETTEXTBKCOLOR, sent },
128 static const struct message listview_item_count_seq[] = {
129 { LVM_GETITEMCOUNT, sent },
130 { LVM_INSERTITEM, sent },
131 { LVM_INSERTITEM, sent },
132 { LVM_INSERTITEM, sent },
133 { LVM_GETITEMCOUNT, sent },
134 { LVM_DELETEITEM, sent|wparam, 2 },
135 { WM_NCPAINT, sent|optional },
136 { WM_ERASEBKGND, sent|optional },
137 { LVM_GETITEMCOUNT, sent },
138 { LVM_DELETEALLITEMS, sent },
139 { LVM_GETITEMCOUNT, sent },
140 { LVM_INSERTITEM, sent },
141 { LVM_INSERTITEM, sent },
142 { LVM_GETITEMCOUNT, sent },
143 { LVM_INSERTITEM, sent },
144 { LVM_GETITEMCOUNT, sent },
148 static const struct message listview_itempos_seq[] = {
149 { LVM_INSERTITEM, sent },
150 { LVM_INSERTITEM, sent },
151 { LVM_INSERTITEM, sent },
152 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
153 { WM_NCPAINT, sent|optional },
154 { WM_ERASEBKGND, sent|optional },
155 { LVM_GETITEMPOSITION, sent|wparam, 1 },
156 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
157 { LVM_GETITEMPOSITION, sent|wparam, 2 },
158 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
159 { LVM_GETITEMPOSITION, sent|wparam, 0 },
163 static const struct message listview_ownerdata_switchto_seq[] = {
164 { WM_STYLECHANGING, sent },
165 { WM_STYLECHANGED, sent },
169 static const struct message listview_getorderarray_seq[] = {
170 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
171 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
175 static const struct message empty_seq[] = {
179 static const struct message forward_erasebkgnd_parent_seq[] = {
180 { WM_ERASEBKGND, sent },
184 static const struct message ownderdata_select_focus_parent_seq[] = {
185 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
186 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
187 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
191 static const struct message ownerdata_setstate_all_parent_seq[] = {
192 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
196 static const struct message ownerdata_defocus_all_parent_seq[] = {
197 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
198 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
199 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
200 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
204 static const struct message ownerdata_deselect_all_parent_seq[] = {
205 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
206 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
210 static const struct message select_all_parent_seq[] = {
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 },
217 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
218 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
220 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
221 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
223 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
224 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
228 static const struct message textcallback_set_again_parent_seq[] = {
229 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
230 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
234 static const struct message single_getdispinfo_parent_seq[] = {
235 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
239 static const struct message getitemposition_seq1[] = {
240 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
244 static const struct message getitemposition_seq2[] = {
245 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
246 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
250 static const struct message editbox_create_pos[] = {
251 /* sequence sent after LVN_BEGINLABELEDIT */
252 /* next two are 4.7x specific */
253 { WM_WINDOWPOSCHANGING, sent },
254 { WM_WINDOWPOSCHANGED, sent|optional },
256 { WM_WINDOWPOSCHANGING, sent|optional },
257 { WM_NCCALCSIZE, sent },
258 { WM_WINDOWPOSCHANGED, sent },
259 { WM_MOVE, sent|defwinproc },
260 { WM_SIZE, sent|defwinproc },
261 /* the rest is todo, skipped in 4.7x */
262 { WM_WINDOWPOSCHANGING, sent|optional },
263 { WM_WINDOWPOSCHANGED, sent|optional },
267 static const struct message scroll_parent_seq[] = {
268 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
269 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
273 static const struct message setredraw_seq[] = {
274 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
278 static const struct message lvs_ex_transparentbkgnd_seq[] = {
279 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
283 static const struct message edit_end_nochange[] = {
284 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
285 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW }, /* todo */
286 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
290 static const struct message hover_parent[] = {
291 { WM_GETDLGCODE, sent }, /* todo_wine */
292 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
296 static const struct message listview_destroy[] = {
297 { 0x0090, sent|optional }, /* Vista */
298 { WM_PARENTNOTIFY, sent },
299 { WM_SHOWWINDOW, sent },
300 { WM_WINDOWPOSCHANGING, sent },
301 { WM_WINDOWPOSCHANGED, sent|optional },
302 { WM_DESTROY, sent },
303 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
304 { WM_NCDESTROY, sent },
308 static const struct message listview_header_changed_seq[] = {
309 { LVM_SETCOLUMNA, sent },
310 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
311 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
315 static const struct message parent_header_click_seq[] = {
316 { WM_NOTIFY, sent|id, 0, 0, LVN_COLUMNCLICK },
317 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCLICKA },
321 static const struct message parent_header_divider_dclick_seq[] = {
322 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGINGA },
323 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
324 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
325 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGEDA },
326 { WM_NOTIFY, sent|id, 0, 0, HDN_DIVIDERDBLCLICKA },
330 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
332 static LONG defwndproc_counter = 0;
336 msg.message = message;
337 msg.flags = sent|wparam|lparam;
338 if (defwndproc_counter) msg.flags |= defwinproc;
341 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
343 /* log system messages, except for painting */
344 if (message < WM_USER &&
345 message != WM_PAINT &&
346 message != WM_ERASEBKGND &&
347 message != WM_NCPAINT &&
348 message != WM_NCHITTEST &&
349 message != WM_GETTEXT &&
350 message != WM_GETICON &&
351 message != WM_DEVICECHANGE)
353 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
355 add_message(sequences, PARENT_SEQ_INDEX, &msg);
356 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
358 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
364 switch (((NMHDR*)lParam)->code)
366 case LVN_BEGINLABELEDIT:
370 /* subclass edit box */
372 edit = subclass_editbox(((NMHDR*)lParam)->hwndFrom);
376 INT len = SendMessageA(edit, EM_GETLIMITTEXT, 0, 0);
377 ok(len == 259 || broken(len == 260) /* includes NULL in NT4 */,
378 "text limit %d, expected 259\n", len);
383 case LVN_ENDLABELEDIT:
387 /* always accept new item text */
388 NMLVDISPINFO *di = (NMLVDISPINFO*)lParam;
389 g_editbox_disp_info = *di;
390 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText ? di->item.pszText : "(null)");
392 /* edit control still available from this notification */
393 edit = (HWND)SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETEDITCONTROL, 0, 0);
394 ok(IsWindow(edit), "expected valid edit control handle\n");
395 ok((GetWindowLongA(edit, GWL_STYLE) & ES_MULTILINE) == 0, "edit is multiline\n");
399 case LVN_BEGINSCROLL:
402 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
404 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
405 "BEGIN" : "END", pScroll->dx, pScroll->dy);
408 case LVN_ITEMCHANGED:
410 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
411 g_nmlistview = *nmlv;
414 case LVN_GETDISPINFOA:
416 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
417 g_itema = dispinfo->item;
419 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
421 static const WCHAR testW[] = {'T','E','S','T',0};
422 dispinfo->hdr.code = LVN_GETDISPINFOW;
423 memcpy(dispinfo->item.pszText, testW, sizeof(testW));
426 /* test control buffer size for text, 10 used to mask cases when control
427 is using caller buffer to process LVM_GETITEM for example */
428 if (dispinfo->item.mask & LVIF_TEXT && dispinfo->item.cchTextMax > 10)
429 ok(dispinfo->item.cchTextMax == 260 ||
430 broken(dispinfo->item.cchTextMax == 264) /* NT4 reports aligned size */,
431 "buffer size %d\n", dispinfo->item.cchTextMax);
435 if (g_block_hover) return 1;
440 case WM_NOTIFYFORMAT:
442 /* force to return format */
443 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
448 defwndproc_counter++;
449 ret = DefWindowProcA(hwnd, message, wParam, lParam);
450 defwndproc_counter--;
455 static BOOL register_parent_wnd_class(BOOL Unicode)
463 clsW.lpfnWndProc = parent_wnd_proc;
466 clsW.hInstance = GetModuleHandleW(NULL);
468 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
469 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
470 clsW.lpszMenuName = NULL;
471 clsW.lpszClassName = testparentclassW;
476 clsA.lpfnWndProc = parent_wnd_proc;
479 clsA.hInstance = GetModuleHandleA(NULL);
481 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
482 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
483 clsA.lpszMenuName = NULL;
484 clsA.lpszClassName = "Listview test parent class";
487 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
490 static HWND create_parent_window(BOOL Unicode)
492 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
495 if (!register_parent_wnd_class(Unicode))
502 hwnd = CreateWindowExW(0, testparentclassW, nameW,
503 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
504 WS_MAXIMIZEBOX | WS_VISIBLE,
506 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
508 hwnd = CreateWindowExA(0, "Listview test parent class",
509 "Listview test parent window",
510 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
511 WS_MAXIMIZEBOX | WS_VISIBLE,
513 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
514 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
518 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
520 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
521 static LONG defwndproc_counter = 0;
525 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
527 /* some debug output for style changing */
528 if ((message == WM_STYLECHANGING ||
529 message == WM_STYLECHANGED) && lParam)
531 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
532 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
535 msg.message = message;
536 msg.flags = sent|wparam|lparam;
537 if (defwndproc_counter) msg.flags |= defwinproc;
540 msg.id = LISTVIEW_ID;
541 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
542 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
544 defwndproc_counter++;
545 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
546 defwndproc_counter--;
550 static HWND create_listview_control(DWORD style)
556 GetClientRect(hwndparent, &rect);
557 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
558 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
559 0, 0, rect.right, rect.bottom,
560 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
561 ok(hwnd != NULL, "gle=%d\n", GetLastError());
563 if (!hwnd) return NULL;
565 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
566 (LONG_PTR)listview_subclass_proc);
567 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
572 /* unicode listview window with specified parent */
573 static HWND create_listview_controlW(DWORD style, HWND parent)
578 static const WCHAR nameW[] = {'f','o','o',0};
580 GetClientRect(parent, &rect);
581 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
582 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
583 0, 0, rect.right, rect.bottom,
584 parent, NULL, GetModuleHandleW(NULL), NULL);
585 ok(hwnd != NULL, "gle=%d\n", GetLastError());
587 if (!hwnd) return NULL;
589 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
590 (LONG_PTR)listview_subclass_proc);
591 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
596 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
598 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
599 static LONG defwndproc_counter = 0;
603 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
605 msg.message = message;
606 msg.flags = sent|wparam|lparam;
607 if (defwndproc_counter) msg.flags |= defwinproc;
611 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
613 defwndproc_counter++;
614 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
615 defwndproc_counter--;
619 static HWND subclass_header(HWND hwndListview)
624 hwnd = ListView_GetHeader(hwndListview);
625 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
626 (LONG_PTR)header_subclass_proc);
627 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
632 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
634 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
635 static LONG defwndproc_counter = 0;
639 msg.message = message;
640 msg.flags = sent|wparam|lparam;
641 if (defwndproc_counter) msg.flags |= defwinproc;
646 /* all we need is sizing */
647 if (message == WM_WINDOWPOSCHANGING ||
648 message == WM_NCCALCSIZE ||
649 message == WM_WINDOWPOSCHANGED ||
650 message == WM_MOVE ||
653 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
656 defwndproc_counter++;
657 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
658 defwndproc_counter--;
662 static HWND subclass_editbox(HWND hwndListview)
667 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
668 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
669 (LONG_PTR)editbox_subclass_proc);
670 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
675 /* Performs a single LVM_HITTEST test */
676 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
677 BOOL todo_item, BOOL todo_flags, int line)
686 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
692 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
693 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
694 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
699 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
700 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
701 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
707 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
709 else if (broken_flags)
710 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
711 "Expected flags %x, got %x\n", flags, lpht.flags);
713 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
716 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
718 /* Performs a single LVM_SUBITEMHITTEST test */
719 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
720 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
728 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
734 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
735 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
740 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
741 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
747 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
750 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
755 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
758 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
761 #define test_lvm_subitemhittest(a,b,c,d,e,f,g,h,i) test_lvm_subitemhittest_(a,b,c,d,e,f,g,h,i,__LINE__)
763 static void test_images(void)
771 static CHAR hello[] = "hello";
773 himl = ImageList_Create(40, 40, 0, 4, 4);
774 ok(himl != NULL, "failed to create imagelist\n");
776 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
777 ok(hbmp != NULL, "failed to create bitmap\n");
779 r = ImageList_Add(himl, hbmp, 0);
780 ok(r == 0, "should be zero\n");
782 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
783 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
784 ok(hwnd != NULL, "failed to create listview window\n");
786 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
787 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
789 ok(r == 0, "should return zero\n");
791 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
792 ok(r == 0, "should return zero\n");
794 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
795 ok(r != 0, "got 0\n");
797 /* returns dimensions */
799 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
800 ok(r == 0, "should be zero items\n");
802 item.mask = LVIF_IMAGE | LVIF_TEXT;
807 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
808 ok(r == -1, "should fail\n");
811 item.pszText = hello;
812 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
813 ok(r == 0, "should not fail\n");
815 memset(&r1, 0, sizeof r1);
817 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
820 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
821 ok(r == TRUE, "should not fail\n");
824 item.pszText = hello;
825 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
826 ok(r == 0, "should not fail\n");
828 memset(&r2, 0, sizeof r2);
830 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
833 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
838 static void test_checkboxes(void)
843 static CHAR text[] = "Text",
847 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
848 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
849 ok(hwnd != NULL, "failed to create listview window\n");
851 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
852 item.mask = LVIF_TEXT | LVIF_STATE;
853 item.stateMask = 0xffff;
858 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
862 item.mask = LVIF_STATE;
863 item.stateMask = 0xffff;
864 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
866 ok(item.state == 0xfccc, "state %x\n", item.state);
868 /* Don't set LVIF_STATE */
869 item.mask = LVIF_TEXT;
870 item.stateMask = 0xffff;
875 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
879 item.mask = LVIF_STATE;
880 item.stateMask = 0xffff;
881 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
883 ok(item.state == 0, "state %x\n", item.state);
885 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
888 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
890 item.mask = LVIF_STATE;
891 item.stateMask = 0xffff;
892 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
894 if (item.state != 0x1ccc)
896 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
901 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
903 item.mask = LVIF_TEXT;
905 item.pszText = text2;
906 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
910 item.mask = LVIF_STATE;
911 item.stateMask = 0xffff;
912 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
914 ok(item.state == 0x1000, "state %x\n", item.state);
916 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
918 item.mask = LVIF_TEXT | LVIF_STATE;
919 item.stateMask = 0xffff;
921 item.pszText = text3;
922 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
926 item.mask = LVIF_STATE;
927 item.stateMask = 0xffff;
928 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
930 ok(item.state == 0x1aaa, "state %x\n", item.state);
932 /* Set an item's state to checked */
934 item.mask = LVIF_STATE;
935 item.stateMask = 0xf000;
937 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
941 item.mask = LVIF_STATE;
942 item.stateMask = 0xffff;
943 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
945 ok(item.state == 0x2aaa, "state %x\n", item.state);
947 /* Check that only the bits we asked for are returned,
948 * and that all the others are set to zero
951 item.mask = LVIF_STATE;
952 item.stateMask = 0xf000;
954 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
956 ok(item.state == 0x2000, "state %x\n", item.state);
958 /* Set the style again and check that doesn't change an item's state */
959 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
960 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
963 item.mask = LVIF_STATE;
964 item.stateMask = 0xffff;
965 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
967 ok(item.state == 0x2aaa, "state %x\n", item.state);
969 /* Unsetting the checkbox extended style doesn't change an item's state */
970 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
971 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
974 item.mask = LVIF_STATE;
975 item.stateMask = 0xffff;
976 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
978 ok(item.state == 0x2aaa, "state %x\n", item.state);
980 /* Now setting the style again will change an item's state */
981 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
985 item.mask = LVIF_STATE;
986 item.stateMask = 0xffff;
987 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
989 ok(item.state == 0x1aaa, "state %x\n", item.state);
991 /* Toggle checkbox tests (bug 9934) */
992 memset (&item, 0xcc, sizeof(item));
993 item.mask = LVIF_STATE;
996 item.state = LVIS_FOCUSED;
997 item.stateMask = LVIS_FOCUSED;
998 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1002 item.mask = LVIF_STATE;
1003 item.stateMask = 0xffff;
1004 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1006 ok(item.state == 0x1aab, "state %x\n", item.state);
1008 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1010 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
1014 item.mask = LVIF_STATE;
1015 item.stateMask = 0xffff;
1016 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1018 ok(item.state == 0x2aab, "state %x\n", item.state);
1020 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1022 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
1026 item.mask = LVIF_STATE;
1027 item.stateMask = 0xffff;
1028 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1030 ok(item.state == 0x1aab, "state %x\n", item.state);
1032 DestroyWindow(hwnd);
1035 static void insert_column(HWND hwnd, int idx)
1040 memset(&column, 0xcc, sizeof(column));
1041 column.mask = LVCF_SUBITEM;
1042 column.iSubItem = idx;
1044 rc = ListView_InsertColumn(hwnd, idx, &column);
1048 static void insert_item(HWND hwnd, int idx)
1050 static CHAR text[] = "foo";
1055 memset(&item, 0xcc, sizeof (item));
1056 item.mask = LVIF_TEXT;
1059 item.pszText = text;
1061 rc = ListView_InsertItem(hwnd, &item);
1065 static void test_items(void)
1067 const LPARAM lparamTest = 0x42;
1068 static CHAR text[] = "Text";
1074 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1075 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1076 ok(hwnd != NULL, "failed to create listview window\n");
1079 * Test setting/getting item params
1082 /* Set up two columns */
1083 insert_column(hwnd, 0);
1084 insert_column(hwnd, 1);
1086 /* LVIS_SELECTED with zero stateMask */
1088 memset (&item, 0, sizeof (item));
1089 item.mask = LVIF_STATE;
1090 item.state = LVIS_SELECTED;
1094 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1097 memset (&item, 0xcc, sizeof (item));
1098 item.mask = LVIF_STATE;
1099 item.stateMask = LVIS_SELECTED;
1103 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1105 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1106 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1108 /* LVIS_SELECTED with zero stateMask */
1110 memset (&item, 0, sizeof (item));
1111 item.mask = LVIF_STATE;
1112 item.state = LVIS_FOCUSED;
1116 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1119 memset (&item, 0xcc, sizeof (item));
1120 item.mask = LVIF_STATE;
1121 item.stateMask = LVIS_FOCUSED;
1125 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1127 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1128 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1130 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1132 memset (&item, 0, sizeof (item));
1133 item.mask = LVIF_STATE;
1134 item.state = LVIS_CUT;
1135 item.stateMask = LVIS_FOCUSED;
1138 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1141 memset (&item, 0xcc, sizeof (item));
1142 item.mask = LVIF_STATE;
1143 item.stateMask = LVIS_CUT;
1147 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1149 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1150 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1152 /* Insert an item with just a param */
1153 memset (&item, 0xcc, sizeof (item));
1154 item.mask = LVIF_PARAM;
1157 item.lParam = lparamTest;
1158 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1161 /* Test getting of the param */
1162 memset (&item, 0xcc, sizeof (item));
1163 item.mask = LVIF_PARAM;
1166 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1168 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1170 /* Set up a subitem */
1171 memset (&item, 0xcc, sizeof (item));
1172 item.mask = LVIF_TEXT;
1175 item.pszText = text;
1176 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1179 item.mask = LVIF_TEXT;
1182 item.pszText = buffA;
1183 item.cchTextMax = sizeof(buffA);
1184 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1186 ok(!memcmp(item.pszText, text, sizeof(text)), "got text %s, expected %s\n", item.pszText, text);
1188 /* set up with extra flag */
1189 /* 1. reset subitem text */
1190 item.mask = LVIF_TEXT;
1193 item.pszText = NULL;
1194 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1197 item.mask = LVIF_TEXT;
1200 item.pszText = buffA;
1202 item.cchTextMax = sizeof(buffA);
1203 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1205 ok(item.pszText[0] == 0, "got %p\n", item.pszText);
1207 /* 2. set new text with extra flag specified */
1208 item.mask = LVIF_TEXT | LVIF_DI_SETITEM;
1211 item.pszText = text;
1212 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1213 ok(r == 1 || broken(r == 0) /* NT4 */, "ret %d\n", r);
1217 item.mask = LVIF_TEXT;
1220 item.pszText = buffA;
1222 item.cchTextMax = sizeof(buffA);
1223 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1225 ok(!memcmp(item.pszText, text, sizeof(text)), "got %s, expected %s\n", item.pszText, text);
1228 /* Query param from subitem: returns main item param */
1229 memset (&item, 0xcc, sizeof (item));
1230 item.mask = LVIF_PARAM;
1233 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1235 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1237 /* Set up param on first subitem: no effect */
1238 memset (&item, 0xcc, sizeof (item));
1239 item.mask = LVIF_PARAM;
1242 item.lParam = lparamTest+1;
1243 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1246 /* Query param from subitem again: should still return main item param */
1247 memset (&item, 0xcc, sizeof (item));
1248 item.mask = LVIF_PARAM;
1251 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1253 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1255 /**** Some tests of state highlighting ****/
1256 memset (&item, 0xcc, sizeof (item));
1257 item.mask = LVIF_STATE;
1260 item.state = LVIS_SELECTED;
1261 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1262 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1265 item.state = LVIS_DROPHILITED;
1266 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1269 memset (&item, 0xcc, sizeof (item));
1270 item.mask = LVIF_STATE;
1273 item.stateMask = -1;
1274 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1276 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1278 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1280 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1282 /* some notnull but meaningless masks */
1283 memset (&item, 0, sizeof(item));
1284 item.mask = LVIF_NORECOMPUTE;
1287 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1289 memset (&item, 0, sizeof(item));
1290 item.mask = LVIF_DI_SETITEM;
1293 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1296 /* set text to callback value already having it */
1297 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1299 memset (&item, 0, sizeof (item));
1300 item.mask = LVIF_TEXT;
1301 item.pszText = LPSTR_TEXTCALLBACK;
1303 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1305 memset (&item, 0, sizeof (item));
1307 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1309 item.pszText = LPSTR_TEXTCALLBACK;
1310 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1313 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1314 "check callback text comparison rule", FALSE);
1316 DestroyWindow(hwnd);
1319 static void test_columns(void)
1328 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1329 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1330 ok(hwnd != NULL, "failed to create listview window\n");
1332 /* Add a column with no mask */
1333 memset(&column, 0xcc, sizeof(column));
1335 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1336 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1338 /* Check its width */
1339 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1340 ok(rc == 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1342 DestroyWindow(hwnd);
1344 /* LVM_GETCOLUMNORDERARRAY */
1345 hwnd = create_listview_control(LVS_REPORT);
1346 subclass_header(hwnd);
1348 memset(&column, 0, sizeof(column));
1349 column.mask = LVCF_WIDTH;
1351 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1355 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1358 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1360 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1362 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1363 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1365 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1367 /* after column added subitem is considered as present */
1368 insert_item(hwnd, 0);
1370 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1372 item.pszText = buff;
1373 item.cchTextMax = sizeof(buff);
1376 item.mask = LVIF_TEXT;
1377 memset(&g_itema, 0, sizeof(g_itema));
1378 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1380 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1382 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1383 "get subitem text after column added", FALSE);
1385 DestroyWindow(hwnd);
1388 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1389 static WNDPROC listviewWndProc;
1390 static HIMAGELIST test_create_imagelist;
1392 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1396 if (uMsg == WM_CREATE)
1398 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1399 lpcs->style |= LVS_REPORT;
1401 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1402 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1406 static void test_create(void)
1417 cls.cbSize = sizeof(WNDCLASSEX);
1418 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1419 listviewWndProc = cls.lpfnWndProc;
1420 cls.lpfnWndProc = create_test_wndproc;
1421 cls.lpszClassName = "MyListView32";
1422 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1424 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1425 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1426 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1427 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1429 if (!IsWindow(hHeader))
1432 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1433 DestroyWindow(hList);
1437 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1438 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1439 DestroyWindow(hList);
1441 /* header isn't created on LVS_ICON and LVS_LIST styles */
1442 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1443 GetModuleHandle(NULL), 0);
1444 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1445 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1446 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1448 memset(&col, 0, sizeof(LVCOLUMNA));
1449 col.mask = LVCF_WIDTH;
1451 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1453 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1454 ok(IsWindow(hHeader), "Header should be created\n");
1455 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1456 style = GetWindowLong(hHeader, GWL_STYLE);
1457 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1458 DestroyWindow(hList);
1460 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1461 GetModuleHandle(NULL), 0);
1462 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1463 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1464 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1466 memset(&col, 0, sizeof(LVCOLUMNA));
1467 col.mask = LVCF_WIDTH;
1469 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1471 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1472 ok(IsWindow(hHeader), "Header should be created\n");
1473 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1474 DestroyWindow(hList);
1476 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1477 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1478 GetModuleHandle(NULL), 0);
1479 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1480 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1481 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1482 ok(IsWindow(hHeader), "Header should be created\n");
1483 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1484 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1485 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1486 ok(IsWindow(hHeader), "Header should be created\n");
1487 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1488 DestroyWindow(hList);
1490 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1491 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1492 GetModuleHandle(NULL), 0);
1493 ret = SetWindowLongPtr(hList, GWL_STYLE,
1494 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1495 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1496 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1497 ok(IsWindow(hHeader), "Header should be created\n");
1498 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1499 ret = SetWindowLongPtr(hList, GWL_STYLE,
1500 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1501 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1502 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1503 ok(IsWindow(hHeader), "Header should be created\n");
1504 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1505 DestroyWindow(hList);
1507 /* LVS_REPORT without WS_VISIBLE */
1508 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1509 GetModuleHandle(NULL), 0);
1510 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1511 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1512 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1514 memset(&col, 0, sizeof(LVCOLUMNA));
1515 col.mask = LVCF_WIDTH;
1517 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1519 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1520 ok(IsWindow(hHeader), "Header should be created\n");
1521 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1522 DestroyWindow(hList);
1524 /* LVS_REPORT without WS_VISIBLE, try to show it */
1525 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1526 GetModuleHandle(NULL), 0);
1527 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1528 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1529 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1530 ShowWindow(hList, SW_SHOW);
1531 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1532 ok(IsWindow(hHeader), "Header should be created\n");
1533 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1534 DestroyWindow(hList);
1536 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1537 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1538 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1539 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1540 ok(IsWindow(hHeader), "Header should be created\n");
1541 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1542 /* HDS_DRAGDROP set by default */
1543 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1544 DestroyWindow(hList);
1546 /* setting LVS_EX_HEADERDRAGDROP creates header */
1547 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1548 GetModuleHandle(NULL), 0);
1549 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1550 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1551 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1552 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1553 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1554 ok(IsWindow(hHeader) ||
1555 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1556 "Header should be created\n");
1557 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1558 DestroyWindow(hList);
1560 /* setting LVS_EX_GRIDLINES creates header */
1561 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1562 GetModuleHandle(NULL), 0);
1563 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1564 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1565 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1566 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_GRIDLINES);
1567 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1568 ok(IsWindow(hHeader) ||
1569 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1570 "Header should be created\n");
1571 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1572 DestroyWindow(hList);
1574 /* setting LVS_EX_FULLROWSELECT creates header */
1575 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1576 GetModuleHandle(NULL), 0);
1577 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1578 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1579 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1580 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
1581 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1582 ok(IsWindow(hHeader) ||
1583 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1584 "Header should be created\n");
1585 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1586 DestroyWindow(hList);
1588 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1589 hList = create_listview_control(LVS_ICON);
1590 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1591 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1592 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1593 DestroyWindow(hList);
1595 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1596 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1597 GetModuleHandle(NULL), 0);
1598 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1599 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1601 rect.left = LVIR_BOUNDS;
1603 rect.right = rect.bottom = -10;
1604 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1607 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1608 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1609 ok(GetDlgItem(hList, 0) == NULL, "NULL dialog item expected\n");
1611 DestroyWindow(hList);
1613 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1614 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1615 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1616 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1617 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1618 DestroyWindow(hList);
1621 static void test_redraw(void)
1628 hwnd = create_listview_control(LVS_REPORT);
1629 subclass_header(hwnd);
1631 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1633 InvalidateRect(hwnd, NULL, TRUE);
1635 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1637 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1639 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1640 /* 1. Without backbuffer */
1641 res = ListView_SetBkColor(hwnd, CLR_NONE);
1644 hdc = GetWindowDC(hwndparent);
1646 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1647 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1648 ok(r == 1, "Expected not zero result\n");
1649 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1650 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1652 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1655 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1656 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1658 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1659 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1661 /* 2. With backbuffer */
1662 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1663 LVS_EX_DOUBLEBUFFER);
1664 res = ListView_SetBkColor(hwnd, CLR_NONE);
1667 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1668 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1670 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1671 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1673 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1676 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1677 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1678 todo_wine expect(1, r);
1679 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1680 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1682 ReleaseDC(hwndparent, hdc);
1684 DestroyWindow(hwnd);
1687 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1689 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1691 if(msg == WM_NOTIFY) {
1692 NMHDR *nmhdr = (PVOID)lp;
1693 if(nmhdr->code == NM_CUSTOMDRAW) {
1694 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1695 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1696 switch(nmlvcd->nmcd.dwDrawStage) {
1698 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1699 return CDRF_NOTIFYITEMDRAW;
1700 case CDDS_ITEMPREPAINT:
1701 nmlvcd->clrTextBk = CLR_DEFAULT;
1702 return CDRF_NOTIFYSUBITEMDRAW;
1703 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1704 clr = GetBkColor(nmlvcd->nmcd.hdc);
1705 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1706 return CDRF_NOTIFYPOSTPAINT;
1707 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1708 clr = GetBkColor(nmlvcd->nmcd.hdc);
1709 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1710 return CDRF_DODEFAULT;
1712 return CDRF_DODEFAULT;
1716 return DefWindowProcA(hwnd, msg, wp, lp);
1719 static void test_customdraw(void)
1724 hwnd = create_listview_control(LVS_REPORT);
1726 insert_column(hwnd, 0);
1727 insert_column(hwnd, 1);
1728 insert_item(hwnd, 0);
1730 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1731 (LONG_PTR)cd_wndproc);
1733 InvalidateRect(hwnd, NULL, TRUE);
1736 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1738 DestroyWindow(hwnd);
1741 static void test_icon_spacing(void)
1743 /* LVM_SETICONSPACING */
1744 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1750 hwnd = create_listview_control(LVS_ICON);
1751 ok(hwnd != NULL, "failed to create a listview window\n");
1753 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1754 expect(NFR_ANSI, r);
1756 /* reset the icon spacing to defaults */
1757 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1759 /* now we can request what the defaults are */
1760 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1764 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1766 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1767 ok(r == MAKELONG(w, h) ||
1768 broken(r == MAKELONG(w, w)), /* win98 */
1769 "Expected %d, got %d\n", MAKELONG(w, h), r);
1771 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1775 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1776 DestroyWindow(hwnd);
1779 expect(MAKELONG(20,30), r);
1781 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1782 expect(MAKELONG(25,35), r);
1784 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1786 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1787 DestroyWindow(hwnd);
1790 static void test_color(void)
1798 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1800 hwnd = create_listview_control(LVS_REPORT);
1801 ok(hwnd != NULL, "failed to create a listview window\n");
1803 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1805 for (i = 0; i < 4; i++)
1809 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1811 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
1814 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1816 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, 0);
1819 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1821 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, 0);
1825 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1826 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1828 /* invalidation test done separately to avoid a message chain mess */
1829 r = ValidateRect(hwnd, NULL);
1831 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, colors[0]);
1834 rect.right = rect.bottom = 1;
1835 r = GetUpdateRect(hwnd, &rect, TRUE);
1836 todo_wine expect(FALSE, r);
1837 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1839 r = ValidateRect(hwnd, NULL);
1841 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, colors[0]);
1844 rect.right = rect.bottom = 1;
1845 r = GetUpdateRect(hwnd, &rect, TRUE);
1846 todo_wine expect(FALSE, r);
1847 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1849 r = ValidateRect(hwnd, NULL);
1851 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, colors[0]);
1854 rect.right = rect.bottom = 1;
1855 r = GetUpdateRect(hwnd, &rect, TRUE);
1856 todo_wine expect(FALSE, r);
1857 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1859 DestroyWindow(hwnd);
1862 static void test_item_count(void)
1864 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1877 static CHAR item0text[] = "item0";
1878 static CHAR item1text[] = "item1";
1879 static CHAR item2text[] = "item2";
1881 hwnd = create_listview_control(LVS_REPORT);
1882 ok(hwnd != NULL, "failed to create a listview window\n");
1884 /* resize in dpiaware manner to fit all 3 items added */
1886 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1887 GetTextMetricsA(hdc, &tm);
1888 /* 2 extra pixels for bounds and header border */
1889 height = tm.tmHeight + 2;
1890 SelectObject(hdc, hOldFont);
1893 GetWindowRect(hwnd, &rect);
1894 /* 3 items + 1 header + 1 to be sure */
1895 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1897 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1899 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1903 item0.mask = LVIF_TEXT;
1906 item0.pszText = item0text;
1907 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1910 /* [item0, item1] */
1911 item1.mask = LVIF_TEXT;
1914 item1.pszText = item1text;
1915 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1918 /* [item0, item1, item2] */
1919 item2.mask = LVIF_TEXT;
1922 item2.pszText = item2text;
1923 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1926 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1929 /* [item0, item1] */
1930 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1933 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1937 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1940 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1944 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1947 /* [item0, item1] */
1948 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1951 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1954 /* [item0, item1, item2] */
1955 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1958 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1961 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1963 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1964 DestroyWindow(hwnd);
1967 static void test_item_position(void)
1969 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1978 static CHAR item0text[] = "item0";
1979 static CHAR item1text[] = "item1";
1980 static CHAR item2text[] = "item2";
1982 hwnd = create_listview_control(LVS_ICON);
1983 ok(hwnd != NULL, "failed to create a listview window\n");
1985 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1988 item0.mask = LVIF_TEXT;
1991 item0.pszText = item0text;
1992 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1995 /* [item0, item1] */
1996 item1.mask = LVIF_TEXT;
1999 item1.pszText = item1text;
2000 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
2003 /* [item0, item1, item2] */
2004 item2.mask = LVIF_TEXT;
2007 item2.pszText = item2text;
2008 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
2011 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
2013 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
2015 expect2(10, 5, position.x, position.y);
2017 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
2019 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
2021 expect2(0, 0, position.x, position.y);
2023 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
2025 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
2027 expect2(20, 20, position.x, position.y);
2029 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
2031 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2032 DestroyWindow(hwnd);
2035 static void test_getorigin(void)
2043 position.x = position.y = 0;
2045 hwnd = create_listview_control(LVS_ICON);
2046 ok(hwnd != NULL, "failed to create a listview window\n");
2047 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2049 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2051 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2052 DestroyWindow(hwnd);
2054 hwnd = create_listview_control(LVS_SMALLICON);
2055 ok(hwnd != NULL, "failed to create a listview window\n");
2056 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2058 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2060 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2061 DestroyWindow(hwnd);
2063 hwnd = create_listview_control(LVS_LIST);
2064 ok(hwnd != NULL, "failed to create a listview window\n");
2065 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2067 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2069 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2070 DestroyWindow(hwnd);
2072 hwnd = create_listview_control(LVS_REPORT);
2073 ok(hwnd != NULL, "failed to create a listview window\n");
2074 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2076 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2078 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2079 DestroyWindow(hwnd);
2082 static void test_multiselect(void)
2084 typedef struct t_select_task
2095 int i,j,item_count,selected_count;
2096 static const int items=5;
2102 static struct t_select_task task_list[] = {
2103 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
2104 { "using VK_UP", -1, VK_UP, -1, -1 },
2105 { "using VK_END", 0, VK_END, 1, -1 },
2106 { "using VK_HOME", -1, VK_HOME, 1, -1 }
2109 hwnd = create_listview_control(LVS_REPORT);
2111 for (i=0;i<items;i++) {
2112 insert_item(hwnd, 0);
2115 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2117 expect(items,item_count);
2120 task = task_list[i];
2122 /* deselect all items */
2123 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2124 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2126 /* set initial position */
2127 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
2128 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
2130 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2132 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
2134 /* Set SHIFT key pressed */
2135 GetKeyboardState(kstate);
2136 kstate[VK_SHIFT]=0x80;
2137 SetKeyboardState(kstate);
2139 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
2140 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
2142 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
2146 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2148 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);
2150 /* Set SHIFT key released */
2151 GetKeyboardState(kstate);
2152 kstate[VK_SHIFT]=0x00;
2153 SetKeyboardState(kstate);
2155 DestroyWindow(hwnd);
2157 /* make multiple selection, then switch to LVS_SINGLESEL */
2158 hwnd = create_listview_control(LVS_REPORT);
2159 for (i=0;i<items;i++) {
2160 insert_item(hwnd, 0);
2162 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2163 expect(items,item_count);
2165 /* try with NULL pointer */
2166 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
2169 /* select all, check notifications */
2170 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2172 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2174 item.stateMask = LVIS_SELECTED;
2175 item.state = LVIS_SELECTED;
2176 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2179 ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
2180 "select all notification", FALSE);
2182 /* deselect all items */
2183 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2184 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2186 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
2189 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2191 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2194 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2195 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2196 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2197 /* check that style is accepted */
2198 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2199 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2202 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2203 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2205 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2207 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2210 /* select one more */
2211 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2214 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2215 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2217 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2218 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2220 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2222 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2225 /* try to select all on LVS_SINGLESEL */
2226 memset(&item, 0, sizeof(item));
2227 item.stateMask = LVIS_SELECTED;
2228 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2230 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2232 item.stateMask = LVIS_SELECTED;
2233 item.state = LVIS_SELECTED;
2234 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2237 r = ListView_GetSelectedCount(hwnd);
2239 r = ListView_GetSelectionMark(hwnd);
2242 /* try to deselect all on LVS_SINGLESEL */
2243 item.stateMask = LVIS_SELECTED;
2244 item.state = LVIS_SELECTED;
2245 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2248 item.stateMask = LVIS_SELECTED;
2250 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2252 r = ListView_GetSelectedCount(hwnd);
2255 /* 1. selection mark is update when new focused item is set */
2256 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2257 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2259 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2262 item.stateMask = LVIS_FOCUSED;
2263 item.state = LVIS_FOCUSED;
2264 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2267 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2270 /* it's not updated if already set */
2271 item.stateMask = LVIS_FOCUSED;
2272 item.state = LVIS_FOCUSED;
2273 r = SendMessage(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2276 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2279 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2282 item.stateMask = LVIS_FOCUSED;
2283 item.state = LVIS_FOCUSED;
2284 r = SendMessage(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2287 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2290 /* need to reset focused item first */
2291 item.stateMask = LVIS_FOCUSED;
2293 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2296 item.stateMask = LVIS_FOCUSED;
2297 item.state = LVIS_FOCUSED;
2298 r = SendMessage(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
2301 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2304 item.stateMask = LVIS_FOCUSED;
2306 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2309 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2312 /* 2. same tests, with LVM_SETITEM */
2313 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2314 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2316 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2319 item.stateMask = LVIS_FOCUSED;
2320 item.state = LVIS_FOCUSED;
2321 item.mask = LVIF_STATE;
2322 item.iItem = item.iSubItem = 0;
2323 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2326 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2329 /* it's not updated if already set */
2330 item.stateMask = LVIS_FOCUSED;
2331 item.state = LVIS_FOCUSED;
2332 item.mask = LVIF_STATE;
2335 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2338 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2341 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2344 item.stateMask = LVIS_FOCUSED;
2345 item.state = LVIS_FOCUSED;
2346 item.mask = LVIF_STATE;
2349 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2352 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2355 /* need to reset focused item first */
2356 item.stateMask = LVIS_FOCUSED;
2358 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2361 item.stateMask = LVIS_FOCUSED;
2362 item.state = LVIS_FOCUSED;
2363 item.mask = LVIF_STATE;
2366 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2369 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2372 item.stateMask = LVIS_FOCUSED;
2374 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2377 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2380 DestroyWindow(hwnd);
2383 static void test_subitem_rect(void)
2391 /* test LVM_GETSUBITEMRECT for header */
2392 hwnd = create_listview_control(LVS_REPORT);
2393 ok(hwnd != NULL, "failed to create a listview window\n");
2394 /* add some columns */
2395 memset(&col, 0, sizeof(LVCOLUMN));
2396 col.mask = LVCF_WIDTH;
2398 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2401 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2404 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2406 /* item = -1 means header, subitem index is 1 based */
2407 rect.left = LVIR_BOUNDS;
2409 rect.right = rect.bottom = 0;
2410 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2413 rect.left = LVIR_BOUNDS;
2415 rect.right = rect.bottom = 0;
2416 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2419 expect(100, rect.left);
2420 expect(250, rect.right);
2422 expect(3, rect.top);
2424 rect.left = LVIR_BOUNDS;
2426 rect.right = rect.bottom = 0;
2427 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2430 expect(250, rect.left);
2431 expect(450, rect.right);
2433 expect(3, rect.top);
2435 /* item LVS_REPORT padding isn't applied to subitems */
2436 insert_item(hwnd, 0);
2438 rect.left = LVIR_BOUNDS;
2440 rect.right = rect.bottom = 0;
2441 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2443 expect(100, rect.left);
2444 expect(250, rect.right);
2446 rect.left = LVIR_ICON;
2448 rect.right = rect.bottom = 0;
2449 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2451 /* no icon attached - zero width rectangle, with no left padding */
2452 expect(100, rect.left);
2453 expect(100, rect.right);
2455 rect.left = LVIR_LABEL;
2457 rect.right = rect.bottom = 0;
2458 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2460 /* same as full LVIR_BOUNDS */
2461 expect(100, rect.left);
2462 expect(250, rect.right);
2464 SendMessage(hwnd, LVM_SCROLL, 10, 0);
2466 rect.left = LVIR_BOUNDS;
2468 rect.right = rect.bottom = 0;
2469 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2471 expect(90, rect.left);
2472 expect(240, rect.right);
2474 SendMessage(hwnd, LVM_SCROLL, -10, 0);
2476 DestroyWindow(hwnd);
2478 /* test subitem rects after re-arranging columns */
2479 hwnd = create_listview_control(LVS_REPORT);
2480 ok(hwnd != NULL, "failed to create a listview window\n");
2481 memset(&col, 0, sizeof(LVCOLUMN));
2482 col.mask = LVCF_WIDTH;
2485 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2489 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2493 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2496 insert_item(hwnd, 0);
2497 insert_item(hwnd, 1);
2499 /* wrong item is refused for main item */
2500 rect.left = LVIR_BOUNDS;
2502 rect.right = rect.bottom = -1;
2503 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect);
2506 /* for subitems rectangle is calculated even if there's no item added */
2507 rect.left = LVIR_BOUNDS;
2509 rect.right = rect.bottom = -1;
2510 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect);
2513 rect2.left = LVIR_BOUNDS;
2515 rect2.right = rect2.bottom = -1;
2516 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect2);
2519 expect(rect.right, rect2.right);
2520 expect(rect.left, rect2.left);
2521 expect(rect.bottom, rect2.top);
2522 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2525 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2526 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2529 rect.left = LVIR_BOUNDS;
2531 rect.right = rect.bottom = -1;
2532 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2534 expect(0, rect.left);
2535 expect(600, rect.right);
2537 rect.left = LVIR_BOUNDS;
2539 rect.right = rect.bottom = -1;
2540 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2542 expect(0, rect.left);
2543 expect(200, rect.right);
2545 rect2.left = LVIR_BOUNDS;
2547 rect2.right = rect2.bottom = -1;
2548 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect2);
2550 expect(0, rect2.left);
2551 expect(200, rect2.right);
2552 /* items are of the same height */
2553 ok(rect2.top > 0, "expected positive item height\n");
2554 expect(rect.bottom, rect2.top);
2555 expect(rect.bottom * 2 - rect.top, rect2.bottom);
2557 rect.left = LVIR_BOUNDS;
2559 rect.right = rect.bottom = -1;
2560 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2562 expect(300, rect.left);
2563 expect(600, rect.right);
2565 DestroyWindow(hwnd);
2567 /* try it for non LVS_REPORT style */
2568 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2569 GetModuleHandle(NULL), 0);
2570 rect.left = LVIR_BOUNDS;
2572 rect.right = rect.bottom = -10;
2573 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2575 /* rect is unchanged */
2576 expect(0, rect.left);
2577 expect(-10, rect.right);
2578 expect(1, rect.top);
2579 expect(-10, rect.bottom);
2580 DestroyWindow(hwnd);
2583 /* comparison callback for test_sorting */
2584 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2586 if (first == second) return 0;
2587 return (first > second ? 1 : -1);
2590 static void test_sorting(void)
2596 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2599 hwnd = create_listview_control(LVS_REPORT);
2600 ok(hwnd != NULL, "failed to create a listview window\n");
2602 /* insert some items */
2603 item.mask = LVIF_PARAM | LVIF_STATE;
2604 item.state = LVIS_SELECTED;
2608 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2611 item.mask = LVIF_PARAM;
2615 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2618 item.mask = LVIF_STATE | LVIF_PARAM;
2619 item.state = LVIS_SELECTED;
2623 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2626 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2629 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2632 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2635 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2637 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2639 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2641 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2642 expect(LVIS_SELECTED, r);
2643 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2644 expect(LVIS_SELECTED, r);
2646 DestroyWindow(hwnd);
2648 /* switch to LVS_SORTASCENDING when some items added */
2649 hwnd = create_listview_control(LVS_REPORT);
2650 ok(hwnd != NULL, "failed to create a listview window\n");
2652 item.mask = LVIF_TEXT;
2655 item.pszText = names[1];
2656 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2659 item.mask = LVIF_TEXT;
2662 item.pszText = names[2];
2663 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2666 item.mask = LVIF_TEXT;
2669 item.pszText = names[0];
2670 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2673 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2674 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2675 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2676 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2678 /* no sorting performed when switched to LVS_SORTASCENDING */
2679 item.mask = LVIF_TEXT;
2681 item.pszText = buff;
2682 item.cchTextMax = sizeof(buff);
2683 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2685 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2688 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2690 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2693 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2695 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2697 /* adding new item doesn't resort list */
2698 item.mask = LVIF_TEXT;
2701 item.pszText = names[3];
2702 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2705 item.mask = LVIF_TEXT;
2707 item.pszText = buff;
2708 item.cchTextMax = sizeof(buff);
2709 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2711 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2714 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2716 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2719 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2721 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2724 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2726 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2728 /* corner case - item should be placed at first position */
2729 item.mask = LVIF_TEXT;
2732 item.pszText = names[4];
2733 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2737 item.pszText = buff;
2738 item.cchTextMax = sizeof(buff);
2739 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2741 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2744 item.pszText = buff;
2745 item.cchTextMax = sizeof(buff);
2746 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2748 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2751 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2753 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2756 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2758 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2761 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2763 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2765 DestroyWindow(hwnd);
2768 static void test_ownerdata(void)
2770 static char test_str[] = "test";
2773 LONG_PTR style, ret;
2777 /* it isn't possible to set LVS_OWNERDATA after creation */
2780 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2784 hwnd = create_listview_control(LVS_REPORT);
2785 ok(hwnd != NULL, "failed to create a listview window\n");
2786 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2787 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2789 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2791 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2792 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2793 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2794 "try to switch to LVS_OWNERDATA seq", FALSE);
2796 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2797 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2798 DestroyWindow(hwnd);
2801 /* try to set LVS_OWNERDATA after creation just having it */
2802 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2803 ok(hwnd != NULL, "failed to create a listview window\n");
2804 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2805 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2807 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2809 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2810 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2811 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2812 "try to switch to LVS_OWNERDATA seq", FALSE);
2813 DestroyWindow(hwnd);
2815 /* try to remove LVS_OWNERDATA after creation just having it */
2818 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2822 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2823 ok(hwnd != NULL, "failed to create a listview window\n");
2824 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2825 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2827 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2829 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2830 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2831 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2832 "try to switch to LVS_OWNERDATA seq", FALSE);
2833 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2834 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2835 DestroyWindow(hwnd);
2838 /* try select an item */
2839 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2840 ok(hwnd != NULL, "failed to create a listview window\n");
2841 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2843 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2845 memset(&item, 0, sizeof(item));
2846 item.stateMask = LVIS_SELECTED;
2847 item.state = LVIS_SELECTED;
2848 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2850 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2852 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2854 DestroyWindow(hwnd);
2856 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
2857 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2858 ok(hwnd != NULL, "failed to create a listview window\n");
2859 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2861 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2863 memset(&item, 0, sizeof(item));
2864 item.mask = LVIF_STATE;
2866 item.stateMask = LVIS_SELECTED;
2867 item.state = LVIS_SELECTED;
2868 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2870 memset(&item, 0, sizeof(item));
2871 item.pszText = test_str;
2872 res = SendMessageA(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2874 DestroyWindow(hwnd);
2876 /* check notifications after focused/selected changed */
2877 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2878 ok(hwnd != NULL, "failed to create a listview window\n");
2879 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2882 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2884 memset(&item, 0, sizeof(item));
2885 item.stateMask = LVIS_SELECTED;
2886 item.state = LVIS_SELECTED;
2887 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2890 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2891 "ownerdata select notification", TRUE);
2893 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2895 memset(&item, 0, sizeof(item));
2896 item.stateMask = LVIS_FOCUSED;
2897 item.state = LVIS_FOCUSED;
2898 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2901 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2902 "ownerdata focus notification", TRUE);
2904 /* select all, check notifications */
2905 item.stateMask = LVIS_SELECTED;
2907 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2910 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2912 item.stateMask = LVIS_SELECTED;
2913 item.state = LVIS_SELECTED;
2915 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
2916 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2918 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
2919 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
2920 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
2921 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
2922 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
2923 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
2924 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
2926 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2927 "ownerdata select all notification", FALSE);
2929 /* select all again, note that all items are selected already */
2930 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2931 item.stateMask = LVIS_SELECTED;
2932 item.state = LVIS_SELECTED;
2934 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
2935 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2937 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
2938 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
2939 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
2940 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
2941 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
2942 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
2943 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
2945 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2946 "ownerdata select all notification", FALSE);
2949 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2950 item.stateMask = LVIS_SELECTED;
2953 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
2954 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2956 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
2957 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
2958 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
2959 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
2960 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
2961 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
2962 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
2964 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2965 "ownerdata deselect all notification", TRUE);
2967 /* nothing selected, deselect all again */
2968 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2969 item.stateMask = LVIS_SELECTED;
2972 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2975 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "ownerdata deselect all notification", TRUE);
2977 /* select one, then deselect all */
2978 item.stateMask = LVIS_SELECTED;
2979 item.state = LVIS_SELECTED;
2980 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2982 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2983 item.stateMask = LVIS_SELECTED;
2986 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
2987 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2989 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
2990 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
2991 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
2992 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
2993 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
2994 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
2995 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
2997 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2998 "ownerdata select all notification", TRUE);
3000 /* remove focused, try to focus all */
3001 item.stateMask = LVIS_FOCUSED;
3002 item.state = LVIS_FOCUSED;
3003 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3005 item.stateMask = LVIS_FOCUSED;
3007 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3009 item.stateMask = LVIS_FOCUSED;
3010 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
3013 /* setting all to focused returns failure value */
3014 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3015 item.stateMask = LVIS_FOCUSED;
3016 item.state = LVIS_FOCUSED;
3018 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3021 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3022 "ownerdata focus all notification", FALSE);
3024 /* focus single item, remove all */
3025 item.stateMask = LVIS_FOCUSED;
3026 item.state = LVIS_FOCUSED;
3027 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3029 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3030 item.stateMask = LVIS_FOCUSED;
3033 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3034 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3036 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3037 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3038 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3039 ok(g_nmlistview.uOldState == LVIS_FOCUSED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3040 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3041 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3042 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3044 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
3045 "ownerdata remove focus all notification", TRUE);
3048 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3049 item.stateMask = LVIS_CUT;
3050 item.state = LVIS_CUT;
3052 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3053 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3055 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3056 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3057 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3058 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3059 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3060 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3061 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3063 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3064 "ownerdata cut all notification", FALSE);
3066 /* all marked cut, try again */
3067 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3068 item.stateMask = LVIS_CUT;
3069 item.state = LVIS_CUT;
3071 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3072 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3074 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3075 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3076 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3077 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3078 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3079 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3080 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3082 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3083 "ownerdata cut all notification #2", FALSE);
3085 DestroyWindow(hwnd);
3087 /* check notifications on LVM_GETITEM */
3088 /* zero callback mask */
3089 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3090 ok(hwnd != NULL, "failed to create a listview window\n");
3091 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3094 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3096 memset(&item, 0, sizeof(item));
3097 item.stateMask = LVIS_SELECTED;
3098 item.mask = LVIF_STATE;
3099 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3102 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3103 "ownerdata getitem selected state 1", FALSE);
3105 /* non zero callback mask but not we asking for */
3106 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
3109 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3111 memset(&item, 0, sizeof(item));
3112 item.stateMask = LVIS_SELECTED;
3113 item.mask = LVIF_STATE;
3114 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3117 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3118 "ownerdata getitem selected state 2", FALSE);
3120 /* LVIS_OVERLAYMASK callback mask, asking for index */
3121 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3123 memset(&item, 0, sizeof(item));
3124 item.stateMask = LVIS_OVERLAYMASK;
3125 item.mask = LVIF_STATE;
3126 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3129 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3130 "ownerdata getitem selected state 2", FALSE);
3132 DestroyWindow(hwnd);
3134 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3135 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
3136 ok(hwnd != NULL, "failed to create a listview window\n");
3137 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3138 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3139 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3140 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
3141 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3142 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
3143 DestroyWindow(hwnd);
3144 /* apparently it's allowed to switch these style on after creation */
3145 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3146 ok(hwnd != NULL, "failed to create a listview window\n");
3147 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3148 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3149 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
3150 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3151 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3152 DestroyWindow(hwnd);
3154 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3155 ok(hwnd != NULL, "failed to create a listview window\n");
3156 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3157 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3158 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
3159 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3160 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
3161 DestroyWindow(hwnd);
3164 static void test_norecompute(void)
3166 static CHAR testA[] = "test";
3172 /* self containing control */
3173 hwnd = create_listview_control(LVS_REPORT);
3174 ok(hwnd != NULL, "failed to create a listview window\n");
3175 memset(&item, 0, sizeof(item));
3176 item.mask = LVIF_TEXT | LVIF_STATE;
3178 item.stateMask = LVIS_SELECTED;
3179 item.state = LVIS_SELECTED;
3180 item.pszText = testA;
3181 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3183 /* retrieve with LVIF_NORECOMPUTE */
3184 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3186 item.pszText = buff;
3187 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3188 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3190 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
3192 item.mask = LVIF_TEXT;
3194 item.pszText = LPSTR_TEXTCALLBACK;
3195 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3198 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3200 item.pszText = buff;
3201 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3203 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3204 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3206 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
3207 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
3208 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
3210 DestroyWindow(hwnd);
3213 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3214 ok(hwnd != NULL, "failed to create a listview window\n");
3216 item.mask = LVIF_STATE;
3217 item.stateMask = LVIS_SELECTED;
3218 item.state = LVIS_SELECTED;
3220 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3223 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3225 item.pszText = buff;
3226 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3227 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3228 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3230 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
3231 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
3232 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
3234 DestroyWindow(hwnd);
3237 static void test_nosortheader(void)
3242 hwnd = create_listview_control(LVS_REPORT);
3243 ok(hwnd != NULL, "failed to create a listview window\n");
3245 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3246 ok(IsWindow(header), "header expected\n");
3248 style = GetWindowLongPtr(header, GWL_STYLE);
3249 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
3251 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3252 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
3253 /* HDS_BUTTONS retained */
3254 style = GetWindowLongPtr(header, GWL_STYLE);
3255 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
3257 DestroyWindow(hwnd);
3259 /* create with LVS_NOSORTHEADER */
3260 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
3261 ok(hwnd != NULL, "failed to create a listview window\n");
3263 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3264 ok(IsWindow(header), "header expected\n");
3266 style = GetWindowLongPtr(header, GWL_STYLE);
3267 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3269 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3270 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
3271 /* not changed here */
3272 style = GetWindowLongPtr(header, GWL_STYLE);
3273 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3275 DestroyWindow(hwnd);
3278 static void test_setredraw(void)
3286 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3287 ok(hwnd != NULL, "failed to create a listview window\n");
3289 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3290 ListView seems to handle it internally without DefWinProc */
3292 /* default value first */
3293 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3296 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3297 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3298 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3300 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3301 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3302 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3305 /* check update rect after redrawing */
3306 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3308 InvalidateRect(hwnd, NULL, FALSE);
3309 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
3310 rect.right = rect.bottom = 1;
3311 GetUpdateRect(hwnd, &rect, FALSE);
3312 expect(0, rect.right);
3313 expect(0, rect.bottom);
3316 hdc = GetWindowDC(hwndparent);
3317 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3319 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3321 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3323 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3325 ReleaseDC(hwndparent, hdc);
3327 /* check notification messages to show that repainting is disabled */
3328 ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
3330 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3332 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3334 InvalidateRect(hwnd, NULL, TRUE);
3336 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3337 "redraw after WM_SETREDRAW (FALSE)", FALSE);
3339 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3341 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3342 InvalidateRect(hwnd, NULL, TRUE);
3344 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3345 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3347 /* message isn't forwarded to header */
3348 subclass_header(hwnd);
3349 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3350 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3352 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3353 "WM_SETREDRAW: not forwarded to header", FALSE);
3355 DestroyWindow(hwnd);
3358 static void test_hittest(void)
3364 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3368 HIMAGELIST himl, himl2;
3371 hwnd = create_listview_control(LVS_REPORT);
3372 ok(hwnd != NULL, "failed to create a listview window\n");
3374 /* LVS_REPORT with a single subitem (2 columns) */
3375 insert_column(hwnd, 0);
3376 insert_column(hwnd, 1);
3377 insert_item(hwnd, 0);
3380 /* the only purpose of that line is to be as long as a half item rect */
3381 item.pszText = text;
3382 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
3385 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3387 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3390 memset(&bounds, 0, sizeof(bounds));
3391 bounds.left = LVIR_BOUNDS;
3392 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3394 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3395 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3396 r = SendMessage(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3398 ok(bounds.bottom - bounds.top == vert,
3399 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3400 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3403 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3405 /* outside columns by x position - valid is [0, 199] */
3407 y = pos.y + (bounds.bottom - bounds.top) / 2;
3408 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3409 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3411 x = pos.x + 50; /* column half width */
3412 y = pos.y + (bounds.bottom - bounds.top) / 2;
3413 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3414 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3415 x = pos.x + 150; /* outside column */
3416 y = pos.y + (bounds.bottom - bounds.top) / 2;
3417 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3418 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3419 y = (bounds.bottom - bounds.top) / 2;
3420 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3421 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3422 /* outside possible client rectangle (to right) */
3424 y = pos.y + (bounds.bottom - bounds.top) / 2;
3425 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3426 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3427 y = (bounds.bottom - bounds.top) / 2;
3428 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3429 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3430 /* subitem returned with -1 item too */
3432 y = bounds.top - vert;
3433 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3434 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3435 /* return values appear to underflow with negative indices */
3439 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3440 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3444 /* parent client area is 100x100 by default */
3445 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3446 x = pos.x + 150; /* outside column */
3447 y = pos.y + (bounds.bottom - bounds.top) / 2;
3448 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3449 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3450 y = (bounds.bottom - bounds.top) / 2;
3451 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3452 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3453 /* the same with LVS_EX_FULLROWSELECT */
3454 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3455 x = pos.x + 150; /* outside column */
3456 y = pos.y + (bounds.bottom - bounds.top) / 2;
3457 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3458 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3459 y = (bounds.bottom - bounds.top) / 2;
3460 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3461 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3462 x = pos.x + 150; /* outside column */
3463 y = pos.y + (bounds.bottom - bounds.top) / 2;
3464 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3465 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3466 y = (bounds.bottom - bounds.top) / 2;
3467 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3468 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3469 /* outside possible client rectangle (to right) */
3471 y = pos.y + (bounds.bottom - bounds.top) / 2;
3472 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3473 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3474 y = (bounds.bottom - bounds.top) / 2;
3475 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3476 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3477 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3478 himl = ImageList_Create(16, 16, 0, 4, 4);
3479 ok(himl != NULL, "failed to create imagelist\n");
3480 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3481 ok(hbmp != NULL, "failed to create bitmap\n");
3482 r = ImageList_Add(himl, hbmp, 0);
3483 ok(r == 0, "should be zero\n");
3484 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3485 ok(hbmp != NULL, "failed to create bitmap\n");
3486 r = ImageList_Add(himl, hbmp, 0);
3487 ok(r == 1, "should be one\n");
3489 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3492 item.mask = LVIF_IMAGE;
3496 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3500 y = pos.y + (bounds.bottom - bounds.top) / 2;
3501 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3502 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3503 y = (bounds.bottom - bounds.top) / 2;
3504 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3506 /* state icons indices are 1 based, check with valid index */
3507 item.mask = LVIF_STATE;
3508 item.state = INDEXTOSTATEIMAGEMASK(1);
3509 item.stateMask = LVIS_STATEIMAGEMASK;
3512 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3516 y = pos.y + (bounds.bottom - bounds.top) / 2;
3517 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3518 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3519 y = (bounds.bottom - bounds.top) / 2;
3520 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3522 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3523 ok(himl2 == himl, "should return handle\n");
3525 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3529 y = pos.y + (bounds.bottom - bounds.top) / 2;
3530 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3531 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3532 y = (bounds.bottom - bounds.top) / 2;
3533 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3535 DestroyWindow(hwnd);
3538 static void test_getviewrect(void)
3545 hwnd = create_listview_control(LVS_REPORT);
3546 ok(hwnd != NULL, "failed to create a listview window\n");
3549 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3552 insert_column(hwnd, 0);
3553 insert_column(hwnd, 1);
3555 memset(&item, 0, sizeof(item));
3558 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3560 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3562 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3565 rect.left = rect.right = rect.top = rect.bottom = -1;
3566 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3568 /* left is set to (2e31-1) - XP SP2 */
3569 expect(0, rect.right);
3570 expect(0, rect.top);
3571 expect(0, rect.bottom);
3573 /* switch to LVS_ICON */
3574 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3576 rect.left = rect.right = rect.top = rect.bottom = -1;
3577 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3579 expect(0, rect.left);
3580 expect(0, rect.top);
3581 /* precise value differs for 2k, XP and Vista */
3582 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3583 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3585 DestroyWindow(hwnd);
3588 static void test_getitemposition(void)
3595 hwnd = create_listview_control(LVS_REPORT);
3596 ok(hwnd != NULL, "failed to create a listview window\n");
3597 header = subclass_header(hwnd);
3599 /* LVS_REPORT, single item, no columns added */
3600 insert_item(hwnd, 0);
3602 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3605 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3607 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3609 /* LVS_REPORT, single item, single column */
3610 insert_column(hwnd, 0);
3612 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3615 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3617 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3619 memset(&rect, 0, sizeof(rect));
3620 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3623 /* offset by header height */
3624 expect(rect.bottom - rect.top, pt.y);
3626 DestroyWindow(hwnd);
3629 static void test_columnscreation(void)
3634 hwnd = create_listview_control(LVS_REPORT);
3635 ok(hwnd != NULL, "failed to create a listview window\n");
3637 insert_item(hwnd, 0);
3639 /* headers columns aren't created automatically */
3640 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3641 ok(IsWindow(header), "Expected header handle\n");
3642 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3645 DestroyWindow(hwnd);
3648 static void test_getitemrect(void)
3651 HIMAGELIST himl, himl_ret;
3661 /* rectangle isn't empty for empty text items */
3662 hwnd = create_listview_control(LVS_LIST);
3663 memset(&item, 0, sizeof(item));
3666 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3668 rect.left = LVIR_LABEL;
3669 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3671 expect(0, rect.left);
3672 expect(0, rect.top);
3674 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, rect.right);
3675 ReleaseDC(hwnd, hdc);
3676 DestroyWindow(hwnd);
3678 hwnd = create_listview_control(LVS_REPORT);
3679 ok(hwnd != NULL, "failed to create a listview window\n");
3682 memset(&item, 0, sizeof(item));
3685 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3688 rect.left = LVIR_BOUNDS;
3689 rect.right = rect.top = rect.bottom = -1;
3690 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3693 /* zero width rectangle with no padding */
3694 expect(0, rect.left);
3695 expect(0, rect.right);
3697 insert_column(hwnd, 0);
3698 insert_column(hwnd, 1);
3700 col.mask = LVCF_WIDTH;
3702 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3705 col.mask = LVCF_WIDTH;
3707 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3710 rect.left = LVIR_BOUNDS;
3711 rect.right = rect.top = rect.bottom = -1;
3712 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3715 /* still no left padding */
3716 expect(0, rect.left);
3717 expect(150, rect.right);
3719 rect.left = LVIR_SELECTBOUNDS;
3720 rect.right = rect.top = rect.bottom = -1;
3721 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3724 expect(2, rect.left);
3726 rect.left = LVIR_LABEL;
3727 rect.right = rect.top = rect.bottom = -1;
3728 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3730 /* padding, column width */
3731 expect(2, rect.left);
3732 expect(50, rect.right);
3734 /* no icons attached */
3735 rect.left = LVIR_ICON;
3736 rect.right = rect.top = rect.bottom = -1;
3737 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3740 expect(2, rect.left);
3741 expect(2, rect.right);
3744 order[0] = 1; order[1] = 0;
3745 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3748 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3750 /* 1 indexed column width + padding */
3752 /* rect is at zero too */
3753 rect.left = LVIR_BOUNDS;
3754 rect.right = rect.top = rect.bottom = -1;
3755 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3757 expect(0, rect.left);
3758 /* just width sum */
3759 expect(150, rect.right);
3761 rect.left = LVIR_SELECTBOUNDS;
3762 rect.right = rect.top = rect.bottom = -1;
3763 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3765 /* column width + padding */
3766 expect(102, rect.left);
3768 /* back to initial order */
3769 order[0] = 0; order[1] = 1;
3770 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3774 himl = ImageList_Create(16, 16, 0, 2, 2);
3775 ok(himl != NULL, "failed to create imagelist\n");
3776 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3777 ok(hbm != NULL, "failed to create bitmap\n");
3778 r = ImageList_Add(himl, hbm, 0);
3780 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3781 ok(hbm != NULL, "failed to create bitmap\n");
3782 r = ImageList_Add(himl, hbm, 0);
3785 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3788 item.mask = LVIF_STATE;
3789 item.state = INDEXTOSTATEIMAGEMASK(1);
3790 item.stateMask = LVIS_STATEIMAGEMASK;
3793 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3797 rect.left = LVIR_ICON;
3798 rect.right = rect.top = rect.bottom = -1;
3799 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3801 /* padding + stateicon width */
3802 expect(18, rect.left);
3803 expect(18, rect.right);
3805 rect.left = LVIR_LABEL;
3806 rect.right = rect.top = rect.bottom = -1;
3807 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3809 /* padding + stateicon width -> column width */
3810 expect(18, rect.left);
3811 expect(50, rect.right);
3813 himl_ret = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3814 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
3816 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3819 item.mask = LVIF_STATE | LVIF_IMAGE;
3822 item.stateMask = ~0;
3825 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3829 rect.left = LVIR_ICON;
3830 rect.right = rect.top = rect.bottom = -1;
3831 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3833 /* padding, icon width */
3834 expect(2, rect.left);
3835 expect(18, rect.right);
3837 rect.left = LVIR_LABEL;
3838 rect.right = rect.top = rect.bottom = -1;
3839 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3841 /* padding + icon width -> column width */
3842 expect(18, rect.left);
3843 expect(50, rect.right);
3846 rect.left = LVIR_SELECTBOUNDS;
3847 rect.right = rect.top = rect.bottom = -1;
3848 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3850 /* padding, column width */
3851 expect(2, rect.left);
3852 expect(50, rect.right);
3854 /* try with indentation */
3855 item.mask = LVIF_INDENT;
3859 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3863 rect.left = LVIR_BOUNDS;
3864 rect.right = rect.top = rect.bottom = -1;
3865 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3867 /* padding + 1 icon width, column width */
3868 expect(0, rect.left);
3869 expect(150, rect.right);
3872 rect.left = LVIR_SELECTBOUNDS;
3873 rect.right = rect.top = rect.bottom = -1;
3874 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3876 /* padding + 1 icon width, column width */
3877 expect(2 + 16, rect.left);
3878 expect(50, rect.right);
3881 rect.left = LVIR_LABEL;
3882 rect.right = rect.top = rect.bottom = -1;
3883 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3885 /* padding + 2 icon widths, column width */
3886 expect(2 + 16*2, rect.left);
3887 expect(50, rect.right);
3890 rect.left = LVIR_ICON;
3891 rect.right = rect.top = rect.bottom = -1;
3892 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3894 /* padding + 1 icon width indentation, icon width */
3895 expect(2 + 16, rect.left);
3896 expect(34, rect.right);
3898 DestroyWindow(hwnd);
3901 static void test_editbox(void)
3903 static CHAR testitemA[] = "testitem";
3904 static CHAR testitem1A[] = "testitem_quitelongname";
3905 static CHAR testitem2A[] = "testITEM_quitelongname";
3906 static CHAR buffer[25];
3907 HWND hwnd, hwndedit, hwndedit2, header;
3911 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3912 ok(hwnd != NULL, "failed to create a listview window\n");
3914 insert_column(hwnd, 0);
3916 memset(&item, 0, sizeof(item));
3917 item.mask = LVIF_TEXT;
3918 item.pszText = testitemA;
3921 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3924 /* test notifications without edit created */
3925 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3926 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
3928 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3929 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
3930 /* same thing but with valid window */
3931 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
3932 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
3933 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3934 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
3936 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3937 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
3938 DestroyWindow(hwndedit);
3940 /* setting focus is necessary */
3942 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3943 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3945 /* test children Z-order after Edit box created */
3946 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3947 ok(IsWindow(header), "Expected header to be created\n");
3948 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3949 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3951 /* modify initial string */
3952 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3955 /* edit window is resized and repositioned,
3956 check again for Z-order - it should be preserved */
3957 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3958 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3960 /* return focus to listview */
3963 memset(&item, 0, sizeof(item));
3964 item.mask = LVIF_TEXT;
3965 item.pszText = buffer;
3966 item.cchTextMax = sizeof(buffer);
3969 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3972 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3974 /* send LVM_EDITLABEL on already created edit */
3976 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3977 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3978 /* focus will be set to edit */
3979 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3980 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3981 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3983 /* creating label disabled when control isn't focused */
3985 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3986 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3988 /* check EN_KILLFOCUS handling */
3989 memset(&item, 0, sizeof(item));
3990 item.pszText = testitemA;
3993 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3997 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3998 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3999 /* modify edit and notify control that it lost focus */
4000 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4002 g_editbox_disp_info.item.pszText = NULL;
4003 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4005 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
4007 memset(&item, 0, sizeof(item));
4008 item.pszText = buffer;
4009 item.cchTextMax = sizeof(buffer);
4012 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4013 expect(lstrlen(item.pszText), r);
4014 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4015 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4017 /* change item name to differ in casing only */
4019 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4020 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4021 /* modify edit and notify control that it lost focus */
4022 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
4024 g_editbox_disp_info.item.pszText = NULL;
4025 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4027 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
4029 memset(&item, 0, sizeof(item));
4030 item.pszText = buffer;
4031 item.cchTextMax = sizeof(buffer);
4034 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4035 expect(lstrlen(item.pszText), r);
4036 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
4037 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4039 /* end edit without saving */
4041 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4042 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4043 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
4045 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4046 "edit box - end edit, no change, escape", TRUE);
4047 /* end edit with saving */
4049 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4050 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4051 r = SendMessage(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
4053 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4054 "edit box - end edit, no change, return", TRUE);
4056 memset(&item, 0, sizeof(item));
4057 item.pszText = buffer;
4058 item.cchTextMax = sizeof(buffer);
4061 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4062 expect(lstrlen(item.pszText), r);
4063 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
4065 /* LVM_EDITLABEL with -1 destroys current edit */
4066 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
4067 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4068 /* no edit present */
4069 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
4070 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4071 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4072 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4074 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4075 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
4076 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4077 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4078 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4079 /* check another negative value */
4080 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4081 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4082 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4083 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
4084 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4085 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4086 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4087 /* and value greater than max item index */
4088 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4089 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4090 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4091 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
4092 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
4093 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4094 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4095 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4097 /* messaging tests */
4099 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4101 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4102 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4103 /* testing only sizing messages */
4104 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
4105 "edit box create - sizing", FALSE);
4107 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4109 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4110 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4111 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4112 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4114 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4115 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
4117 DestroyWindow(hwnd);
4120 static void test_notifyformat(void)
4125 hwnd = create_listview_control(LVS_REPORT);
4126 ok(hwnd != NULL, "failed to create a listview window\n");
4128 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4129 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4130 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4132 SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4134 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
4136 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4139 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
4141 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4146 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4147 DestroyWindow(hwnd);
4151 DestroyWindow(hwnd);
4153 /* test failure in parent WM_NOTIFYFORMAT */
4155 hwnd = create_listview_control(LVS_REPORT);
4156 ok(hwnd != NULL, "failed to create a listview window\n");
4157 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4158 ok(IsWindow(header), "expected header to be created\n");
4159 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4161 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4162 ok( r == 1, "Expected 1, got %d\n", r );
4163 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4164 ok(r != 0, "Expected valid format\n");
4166 notifyFormat = NFR_UNICODE;
4167 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4168 expect(NFR_UNICODE, r);
4169 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4171 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4172 ok( r == 1, "Expected 1, got %d\n", r );
4174 notifyFormat = NFR_ANSI;
4175 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4176 expect(NFR_ANSI, r);
4177 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4179 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4180 ok( r == 1, "Expected 1, got %d\n", r );
4182 DestroyWindow(hwnd);
4184 hwndparentW = create_parent_window(TRUE);
4185 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
4186 if (!IsWindow(hwndparentW)) return;
4189 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4190 ok(hwnd != NULL, "failed to create a listview window\n");
4191 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4192 ok(IsWindow(header), "expected header to be created\n");
4193 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4195 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4197 DestroyWindow(hwnd);
4198 /* receiving error code defaulting to ansi */
4200 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4201 ok(hwnd != NULL, "failed to create a listview window\n");
4202 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4203 ok(IsWindow(header), "expected header to be created\n");
4204 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4206 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4208 DestroyWindow(hwnd);
4209 /* receiving ansi code from unicode window, use it */
4210 notifyFormat = NFR_ANSI;
4211 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4212 ok(hwnd != NULL, "failed to create a listview window\n");
4213 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4214 ok(IsWindow(header), "expected header to be created\n");
4215 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4217 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4219 DestroyWindow(hwnd);
4220 /* unicode listview with ansi parent window */
4222 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4223 ok(hwnd != NULL, "failed to create a listview window\n");
4224 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4225 ok(IsWindow(header), "expected header to be created\n");
4226 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4228 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4230 DestroyWindow(hwnd);
4231 /* unicode listview with ansi parent window, return error code */
4233 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4234 ok(hwnd != NULL, "failed to create a listview window\n");
4235 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4236 ok(IsWindow(header), "expected header to be created\n");
4237 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4239 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4241 DestroyWindow(hwnd);
4243 DestroyWindow(hwndparentW);
4246 static void test_indentation(void)
4252 hwnd = create_listview_control(LVS_REPORT);
4253 ok(hwnd != NULL, "failed to create a listview window\n");
4255 memset(&item, 0, sizeof(item));
4256 item.mask = LVIF_INDENT;
4258 item.iIndent = I_INDENTCALLBACK;
4259 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4262 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4265 item.mask = LVIF_INDENT;
4266 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
4269 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
4270 "get indent dispinfo", FALSE);
4272 DestroyWindow(hwnd);
4275 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
4280 static BOOL is_below_comctl_5(void)
4285 hwnd = create_listview_control(LVS_REPORT);
4286 ok(hwnd != NULL, "failed to create a listview window\n");
4287 insert_item(hwnd, 0);
4289 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
4291 DestroyWindow(hwnd);
4296 static void test_get_set_view(void)
4302 /* test style->view mapping */
4303 hwnd = create_listview_control(LVS_REPORT);
4304 ok(hwnd != NULL, "failed to create a listview window\n");
4306 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4307 expect(LV_VIEW_DETAILS, ret);
4309 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4311 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4312 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4313 expect(LV_VIEW_ICON, ret);
4315 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4316 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4317 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4318 expect(LV_VIEW_SMALLICON, ret);
4320 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4321 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4322 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4323 expect(LV_VIEW_LIST, ret);
4325 /* switching view doesn't touch window style */
4326 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4328 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4329 ok(style & LVS_LIST, "Expected style to be preserved\n");
4330 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4332 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4333 ok(style & LVS_LIST, "Expected style to be preserved\n");
4334 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4336 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4337 ok(style & LVS_LIST, "Expected style to be preserved\n");
4339 DestroyWindow(hwnd);
4342 static void test_canceleditlabel(void)
4344 HWND hwnd, hwndedit;
4348 static CHAR test[] = "test";
4349 static const CHAR test1[] = "test1";
4351 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4352 ok(hwnd != NULL, "failed to create a listview window\n");
4354 insert_item(hwnd, 0);
4356 /* try without edit created */
4357 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4358 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4360 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4361 "cancel edit label without edit", FALSE);
4363 /* cancel without data change */
4365 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4366 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4367 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4369 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4371 /* cancel after data change */
4372 memset(&itema, 0, sizeof(itema));
4373 itema.pszText = test;
4374 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4377 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4378 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4379 ret = SetWindowText(hwndedit, test1);
4381 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4383 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4384 memset(&itema, 0, sizeof(itema));
4385 itema.pszText = buff;
4386 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4387 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
4389 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4391 DestroyWindow(hwnd);
4394 static void test_mapidindex(void)
4399 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4400 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4401 ok(hwnd != NULL, "failed to create a listview window\n");
4402 insert_item(hwnd, 0);
4403 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4405 DestroyWindow(hwnd);
4407 hwnd = create_listview_control(LVS_REPORT);
4408 ok(hwnd != NULL, "failed to create a listview window\n");
4410 /* LVM_MAPINDEXTOID with invalid index */
4411 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4414 insert_item(hwnd, 0);
4415 insert_item(hwnd, 1);
4417 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
4419 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
4422 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4424 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4426 /* remove 0 indexed item, id retained */
4427 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
4428 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4430 /* new id starts from previous value */
4431 insert_item(hwnd, 1);
4432 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4435 /* get index by id */
4436 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4438 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4440 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4442 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4445 DestroyWindow(hwnd);
4448 static void test_getitemspacing(void)
4457 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4458 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4461 hwnd = create_listview_control(LVS_ICON);
4462 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4464 expect(cx, LOWORD(ret));
4465 expect(cy, HIWORD(ret));
4467 /* now try with icons */
4468 himl = ImageList_Create(40, 40, 0, 4, 4);
4469 ok(himl != NULL, "failed to create imagelist\n");
4470 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4471 ok(hbmp != NULL, "failed to create bitmap\n");
4472 ret = ImageList_Add(himl, hbmp, 0);
4474 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4477 itema.mask = LVIF_IMAGE;
4481 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4483 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4485 /* spacing + icon size returned */
4486 expect(cx + 40, LOWORD(ret));
4487 expect(cy + 40, HIWORD(ret));
4489 DestroyWindow(hwnd);
4491 hwnd = create_listview_control(LVS_SMALLICON);
4492 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4494 expect(cx, LOWORD(ret));
4495 expect(cy, HIWORD(ret));
4497 DestroyWindow(hwnd);
4499 hwnd = create_listview_control(LVS_REPORT);
4500 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4502 expect(cx, LOWORD(ret));
4503 expect(cy, HIWORD(ret));
4505 DestroyWindow(hwnd);
4507 hwnd = create_listview_control(LVS_LIST);
4508 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4510 expect(cx, LOWORD(ret));
4511 expect(cy, HIWORD(ret));
4513 DestroyWindow(hwnd);
4516 static void test_getcolumnwidth(void)
4525 /* default column width */
4526 hwnd = create_listview_control(LVS_ICON);
4527 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4529 style = GetWindowLong(hwnd, GWL_STYLE);
4530 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
4531 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4532 todo_wine expect(8, ret);
4533 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
4534 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
4536 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4538 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4540 DestroyWindow(hwnd);
4542 /* default column width with item added */
4543 hwnd = create_listview_control(LVS_LIST);
4544 memset(&itema, 0, sizeof(itema));
4545 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4546 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4548 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, ret);
4549 ReleaseDC(hwnd, hdc);
4550 DestroyWindow(hwnd);
4553 static void test_scrollnotify(void)
4558 hwnd = create_listview_control(LVS_REPORT);
4560 insert_column(hwnd, 0);
4561 insert_column(hwnd, 1);
4562 insert_item(hwnd, 0);
4564 /* make it scrollable - resize */
4565 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4567 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4570 /* try with dummy call */
4571 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4572 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
4574 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4575 "scroll notify 1", TRUE);
4577 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4578 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
4580 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4581 "scroll notify 2", TRUE);
4583 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4584 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4586 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4587 "scroll notify 3", TRUE);
4589 DestroyWindow(hwnd);
4592 static void test_LVS_EX_TRANSPARENTBKGND(void)
4598 hwnd = create_listview_control(LVS_REPORT);
4600 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4603 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4604 LVS_EX_TRANSPARENTBKGND);
4606 ret = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
4607 if (ret != CLR_NONE)
4609 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4610 DestroyWindow(hwnd);
4614 /* try to set some back color and check this style bit */
4615 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4617 ret = SendMessage(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4618 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4620 /* now test what this style actually does */
4621 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4622 LVS_EX_TRANSPARENTBKGND);
4624 hdc = GetWindowDC(hwndparent);
4626 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4627 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4628 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4629 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4631 ReleaseDC(hwndparent, hdc);
4633 DestroyWindow(hwnd);
4636 static void test_approximate_viewrect(void)
4643 static CHAR test[] = "abracadabra, a very long item label";
4645 hwnd = create_listview_control(LVS_ICON);
4646 himl = ImageList_Create(40, 40, 0, 4, 4);
4647 ok(himl != NULL, "failed to create imagelist\n");
4648 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4649 ok(hbmp != NULL, "failed to create bitmap\n");
4650 ret = ImageList_Add(himl, hbmp, 0);
4652 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4655 itema.mask = LVIF_IMAGE;
4659 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4662 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4666 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4670 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4671 expect(MAKELONG(77,827), ret);
4673 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4674 ok(ret != 0, "got 0\n");
4676 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4677 expect(MAKELONG(102,302), ret);
4679 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4680 expect(MAKELONG(52,52), ret);
4682 itema.pszText = test;
4683 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4685 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4686 expect(MAKELONG(52,52), ret);
4688 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4689 expect(MAKELONG(52,2), ret);
4690 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4691 expect(MAKELONG(52,52), ret);
4692 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4693 expect(MAKELONG(102,52), ret);
4694 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4695 expect(MAKELONG(102,102), ret);
4696 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4697 expect(MAKELONG(102,102), ret);
4698 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4699 expect(MAKELONG(102,152), ret);
4700 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4701 expect(MAKELONG(102,152), ret);
4702 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4703 expect(MAKELONG(152,152), ret);
4705 DestroyWindow(hwnd);
4708 static void test_finditem(void)
4715 hwnd = create_listview_control(LVS_REPORT);
4716 insert_item(hwnd, 0);
4718 memset(&fi, 0, sizeof(fi));
4720 /* full string search, inserted text was "foo" */
4722 fi.flags = LVFI_STRING;
4724 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4726 /* partial string search, inserted text was "foo" */
4728 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4730 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4732 /* partial string search, part after start char */
4734 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4736 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4739 /* try with LVFI_SUBSTRING */
4741 fi.flags = LVFI_SUBSTRING;
4743 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4746 win_skip("LVFI_SUBSTRING not supported\n");
4747 DestroyWindow(hwnd);
4752 fi.flags = LVFI_SUBSTRING;
4754 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4757 fi.flags = LVFI_SUBSTRING;
4759 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4763 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
4765 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4768 DestroyWindow(hwnd);
4771 static void test_LVS_EX_HEADERINALLVIEWS(void)
4776 hwnd = create_listview_control(LVS_ICON);
4778 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4779 LVS_EX_HEADERINALLVIEWS);
4781 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4782 if (!IsWindow(header))
4784 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4785 DestroyWindow(hwnd);
4789 /* LVS_NOCOLUMNHEADER works as before */
4790 style = GetWindowLongA(hwnd, GWL_STYLE);
4791 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
4792 style = GetWindowLongA(header, GWL_STYLE);
4793 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
4794 style = GetWindowLongA(hwnd, GWL_STYLE);
4795 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
4796 style = GetWindowLongA(header, GWL_STYLE);
4797 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
4799 /* try to remove style */
4800 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
4801 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4802 ok(IsWindow(header), "Expected header to be created\n");
4803 style = GetWindowLongA(header, GWL_STYLE);
4804 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
4806 DestroyWindow(hwnd);
4808 /* check other styles */
4809 hwnd = create_listview_control(LVS_LIST);
4810 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4811 LVS_EX_HEADERINALLVIEWS);
4812 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4813 ok(IsWindow(header), "Expected header to be created\n");
4814 DestroyWindow(hwnd);
4816 hwnd = create_listview_control(LVS_SMALLICON);
4817 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4818 LVS_EX_HEADERINALLVIEWS);
4819 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4820 ok(IsWindow(header), "Expected header to be created\n");
4821 DestroyWindow(hwnd);
4823 hwnd = create_listview_control(LVS_REPORT);
4824 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4825 LVS_EX_HEADERINALLVIEWS);
4826 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4827 ok(IsWindow(header), "Expected header to be created\n");
4828 DestroyWindow(hwnd);
4831 static void test_hover(void)
4836 hwnd = create_listview_control(LVS_ICON);
4838 /* test WM_MOUSEHOVER forwarding */
4839 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4840 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4842 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
4843 g_block_hover = TRUE;
4844 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4845 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4847 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
4848 g_block_hover = FALSE;
4850 r = SendMessage(hwnd, LVM_SETHOVERTIME, 0, 500);
4851 expect(HOVER_DEFAULT, r);
4852 r = SendMessage(hwnd, LVM_GETHOVERTIME, 0, 0);
4855 DestroyWindow(hwnd);
4858 static void test_destroynotify(void)
4862 hwnd = create_listview_control(LVS_REPORT);
4863 ok(hwnd != NULL, "failed to create listview window\n");
4865 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4866 DestroyWindow(hwnd);
4867 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
4870 static void test_header_notification(void)
4872 static char textA[] = "newtext";
4880 list = create_listview_control(LVS_REPORT);
4881 ok(list != NULL, "failed to create listview window\n");
4883 memset(&col, 0, sizeof(col));
4884 col.mask = LVCF_WIDTH;
4886 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4889 /* check list parent notification after header item changed,
4890 this test should be placed before header subclassing to avoid
4891 Listview -> Header messages to be logged */
4892 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4894 col.mask = LVCF_TEXT;
4895 col.pszText = textA;
4896 r = SendMessage(list, LVM_SETCOLUMNA, 0, (LPARAM)&col);
4899 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_changed_seq,
4900 "header notify, listview", FALSE);
4901 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4902 "header notify, parent", FALSE);
4904 header = subclass_header(list);
4906 ret = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
4909 memset(&item, 0, sizeof(item));
4910 item.mask = HDI_WIDTH;
4911 ret = SendMessage(header, HDM_GETITEMA, 0, (LPARAM)&item);
4913 expect(100, item.cxy);
4915 nmh.hdr.hwndFrom = header;
4916 nmh.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
4917 nmh.hdr.code = HDN_ITEMCHANGEDA;
4920 item.mask = HDI_WIDTH;
4923 ret = SendMessage(list, WM_NOTIFY, 0, (LPARAM)&nmh);
4926 DestroyWindow(list);
4929 static void test_header_notification2(void)
4931 static char textA[] = "newtext";
4938 struct message parent_header_notify_seq[] = {
4939 { WM_NOTIFY, sent|id, 0, 0, 0 },
4943 list = create_listview_control(LVS_REPORT);
4944 ok(list != NULL, "failed to create listview window\n");
4946 memset(&col, 0, sizeof(col));
4947 col.mask = LVCF_WIDTH | LVCF_TEXT;
4949 col.pszText = textA;
4950 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4953 header = ListView_GetHeader(list);
4954 ok(header != 0, "No header\n");
4955 memset(&itemW, 0, sizeof(itemW));
4956 itemW.mask = HDI_WIDTH | HDI_ORDER | HDI_TEXT;
4957 itemW.pszText = buffer;
4958 itemW.cchTextMax = sizeof(buffer);
4959 ret = SendMessageW(header, HDM_GETITEMW, 0, (LPARAM)&itemW);
4962 nmhdr.hdr.hwndFrom = header;
4963 nmhdr.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
4966 nmhdr.pitem = &itemW;
4968 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4969 nmhdr.hdr.code = HDN_ITEMCHANGINGW;
4970 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
4971 parent_header_notify_seq[0].id = HDN_ITEMCHANGINGA;
4972 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
4973 "header notify, parent", TRUE);
4975 ok(nmhdr.hdr.code == HDN_ITEMCHANGINGA, "Expected ANSI notification code\n");
4976 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4977 nmhdr.hdr.code = HDN_ITEMCHANGEDW;
4978 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
4979 parent_header_notify_seq[0].id = HDN_ITEMCHANGEDA;
4980 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
4981 "header notify, parent", TRUE);
4983 ok(nmhdr.hdr.code == HDN_ITEMCHANGEDA, "Expected ANSI notification code\n");
4984 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
4986 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4987 nmhdr.hdr.code = HDN_ITEMCLICKW;
4988 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
4989 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_click_seq,
4990 "header notify, parent", FALSE);
4991 ok(nmhdr.hdr.code == HDN_ITEMCLICKA, "Expected ANSI notification code\n");
4992 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4993 nmhdr.hdr.code = HDN_ITEMDBLCLICKW;
4994 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
4995 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4996 "header notify, parent", FALSE);
4997 ok(nmhdr.hdr.code == HDN_ITEMDBLCLICKW, "Expected Unicode notification code\n");
4998 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4999 nmhdr.hdr.code = HDN_DIVIDERDBLCLICKW;
5000 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5001 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_divider_dclick_seq,
5002 "header notify, parent", TRUE);
5003 ok(nmhdr.hdr.code == HDN_DIVIDERDBLCLICKA, "Expected ANSI notification code\n");
5004 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5005 nmhdr.hdr.code = HDN_BEGINTRACKW;
5006 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5007 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5008 "header notify, parent", FALSE);
5009 ok(nmhdr.hdr.code == HDN_BEGINTRACKW, "Expected Unicode notification code\n");
5010 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5011 nmhdr.hdr.code = HDN_ENDTRACKW;
5012 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5013 parent_header_notify_seq[0].id = HDN_ENDTRACKA;
5014 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5015 "header notify, parent", FALSE);
5016 ok(nmhdr.hdr.code == HDN_ENDTRACKA, "Expected ANSI notification code\n");
5017 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5018 nmhdr.hdr.code = HDN_TRACKW;
5019 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5020 parent_header_notify_seq[0].id = HDN_TRACKA;
5021 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5022 "header notify, parent", FALSE);
5023 ok(nmhdr.hdr.code == HDN_TRACKA, "Expected ANSI notification code\n");
5024 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5025 nmhdr.hdr.code = HDN_BEGINDRAG;
5026 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5027 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5028 "header notify, parent", FALSE);
5029 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5030 nmhdr.hdr.code = HDN_ENDDRAG;
5031 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5032 parent_header_notify_seq[0].id = HDN_ENDDRAG;
5033 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5034 "header notify, parent", FALSE);
5035 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5036 nmhdr.hdr.code = HDN_FILTERCHANGE;
5037 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5038 parent_header_notify_seq[0].id = HDN_FILTERCHANGE;
5039 parent_header_notify_seq[0].flags |= optional; /* NT4 does not send this message */
5040 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5041 "header notify, parent", FALSE);
5042 parent_header_notify_seq[0].flags &= ~optional;
5043 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5044 nmhdr.hdr.code = HDN_BEGINFILTEREDIT;
5045 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5046 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5047 "header notify, parent", FALSE);
5048 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5049 nmhdr.hdr.code = HDN_ENDFILTEREDIT;
5050 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5051 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5052 "header notify, parent", FALSE);
5053 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5054 nmhdr.hdr.code = HDN_ITEMSTATEICONCLICK;
5055 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5056 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5057 "header notify, parent", FALSE);
5058 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5059 nmhdr.hdr.code = HDN_ITEMKEYDOWN;
5060 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5061 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5062 "header notify, parent", FALSE);
5064 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5066 DestroyWindow(list);
5069 static void test_createdragimage(void)
5075 list = create_listview_control(LVS_ICON);
5076 ok(list != NULL, "failed to create listview window\n");
5078 insert_item(list, 0);
5081 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
5082 ok(himl == NULL, "got %p\n", himl);
5084 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
5085 ok(himl != NULL, "got %p\n", himl);
5086 ImageList_Destroy(himl);
5088 DestroyWindow(list);
5091 static void test_dispinfo(void)
5093 static const char testA[] = "TEST";
5099 hwnd = create_listview_control(LVS_ICON);
5100 ok(hwnd != NULL, "failed to create listview window\n");
5102 insert_item(hwnd, 0);
5104 memset(&item, 0, sizeof(item));
5105 item.pszText = LPSTR_TEXTCALLBACKA;
5106 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5109 g_disp_A_to_W = TRUE;
5110 item.pszText = (char*)buff;
5111 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
5112 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
5113 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
5114 g_disp_A_to_W = FALSE;
5116 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
5117 "got %s, expected %s\n", item.pszText, testA);
5119 DestroyWindow(hwnd);
5122 static void test_LVM_SETITEMTEXT(void)
5124 static char testA[] = "TEST";
5129 hwnd = create_listview_control(LVS_ICON);
5130 ok(hwnd != NULL, "failed to create listview window\n");
5132 insert_item(hwnd, 0);
5134 /* null item pointer */
5135 ret = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, 0);
5138 ret = SendMessage(hwnd, LVM_SETITEMTEXTW, 0, 0);
5141 /* index out of bounds */
5142 item.pszText = testA;
5143 item.cchTextMax = 0; /* ignored */
5146 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 1, (LPARAM)&item);
5149 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, -1, (LPARAM)&item);
5152 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5155 DestroyWindow(hwnd);
5158 START_TEST(listview)
5161 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
5163 ULONG_PTR ctx_cookie;
5167 hComctl32 = GetModuleHandleA("comctl32.dll");
5168 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
5169 if (pInitCommonControlsEx)
5171 INITCOMMONCONTROLSEX iccex;
5172 iccex.dwSize = sizeof(iccex);
5173 iccex.dwICC = ICC_LISTVIEW_CLASSES;
5174 pInitCommonControlsEx(&iccex);
5177 InitCommonControls();
5179 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
5181 hwndparent = create_parent_window(FALSE);
5182 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5184 g_is_below_5 = is_below_comctl_5();
5186 test_header_notification();
5187 test_header_notification2();
5194 test_icon_spacing();
5197 test_item_position();
5202 test_subitem_rect();
5206 test_nosortheader();
5210 test_getitemposition();
5211 test_columnscreation();
5213 test_notifyformat();
5215 test_getitemspacing();
5216 test_getcolumnwidth();
5217 test_approximate_viewrect();
5220 test_destroynotify();
5221 test_createdragimage();
5223 test_LVM_SETITEMTEXT();
5225 if (!load_v6_module(&ctx_cookie, &hCtx))
5227 DestroyWindow(hwndparent);
5231 /* this is a XP SP3 failure workaround */
5232 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
5233 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
5235 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
5236 if (!IsWindow(hwnd))
5238 win_skip("FIXME: failed to create ListView window.\n");
5239 unload_v6_module(ctx_cookie, hCtx);
5240 DestroyWindow(hwndparent);
5244 DestroyWindow(hwnd);
5246 /* comctl32 version 6 tests start here */
5247 test_get_set_view();
5248 test_canceleditlabel();
5250 test_scrollnotify();
5251 test_LVS_EX_TRANSPARENTBKGND();
5252 test_LVS_EX_HEADERINALLVIEWS();
5254 unload_v6_module(ctx_cookie, hCtx);
5256 DestroyWindow(hwndparent);