4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009 Nikolay Sivov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
31 #define PARENT_SEQ_INDEX 0
32 #define PARENT_FULL_SEQ_INDEX 1
33 #define LISTVIEW_SEQ_INDEX 2
34 #define EDITBOX_SEQ_INDEX 3
35 #define 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 /* dumps LVN_ITEMCHANGED message data */
54 static BOOL g_dump_itemchanged;
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;
65 static HWND subclass_editbox(HWND hwndListview);
67 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
69 static const struct message create_ownerdrawfixed_parent_seq[] = {
70 { WM_NOTIFYFORMAT, sent },
71 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
72 { WM_MEASUREITEM, sent },
73 { WM_PARENTNOTIFY, sent },
77 static const struct message redraw_listview_seq[] = {
78 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
79 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
80 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
81 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
82 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
83 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
84 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
88 static const struct message listview_icon_spacing_seq[] = {
89 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
90 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
91 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
95 static const struct message listview_color_seq[] = {
96 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
97 { LVM_GETBKCOLOR, sent },
98 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
99 { LVM_GETTEXTCOLOR, sent },
100 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
101 { LVM_GETTEXTBKCOLOR, sent },
103 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
104 { LVM_GETBKCOLOR, sent },
105 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
106 { LVM_GETTEXTCOLOR, sent },
107 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
108 { LVM_GETTEXTBKCOLOR, sent },
110 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
111 { LVM_GETBKCOLOR, sent },
112 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
113 { LVM_GETTEXTCOLOR, sent },
114 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
115 { LVM_GETTEXTBKCOLOR, sent },
117 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
118 { LVM_GETBKCOLOR, sent },
119 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
120 { LVM_GETTEXTCOLOR, sent },
121 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
122 { LVM_GETTEXTBKCOLOR, sent },
126 static const struct message listview_item_count_seq[] = {
127 { LVM_GETITEMCOUNT, sent },
128 { LVM_INSERTITEM, sent },
129 { LVM_INSERTITEM, sent },
130 { LVM_INSERTITEM, sent },
131 { LVM_GETITEMCOUNT, sent },
132 { LVM_DELETEITEM, sent|wparam, 2 },
133 { WM_NCPAINT, sent|optional },
134 { WM_ERASEBKGND, sent|optional },
135 { LVM_GETITEMCOUNT, sent },
136 { LVM_DELETEALLITEMS, sent },
137 { LVM_GETITEMCOUNT, sent },
138 { LVM_INSERTITEM, sent },
139 { LVM_INSERTITEM, sent },
140 { LVM_GETITEMCOUNT, sent },
141 { LVM_INSERTITEM, sent },
142 { LVM_GETITEMCOUNT, sent },
146 static const struct message listview_itempos_seq[] = {
147 { LVM_INSERTITEM, sent },
148 { LVM_INSERTITEM, sent },
149 { LVM_INSERTITEM, sent },
150 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
151 { WM_NCPAINT, sent|optional },
152 { WM_ERASEBKGND, sent|optional },
153 { LVM_GETITEMPOSITION, sent|wparam, 1 },
154 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
155 { LVM_GETITEMPOSITION, sent|wparam, 2 },
156 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
157 { LVM_GETITEMPOSITION, sent|wparam, 0 },
161 static const struct message listview_ownerdata_switchto_seq[] = {
162 { WM_STYLECHANGING, sent },
163 { WM_STYLECHANGED, sent },
167 static const struct message listview_getorderarray_seq[] = {
168 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
169 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
173 static const struct message empty_seq[] = {
177 static const struct message forward_erasebkgnd_parent_seq[] = {
178 { WM_ERASEBKGND, sent },
182 static const struct message ownderdata_select_focus_parent_seq[] = {
183 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
184 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
185 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
189 static const struct message ownerdata_setstate_all_parent_seq[] = {
190 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
194 static const struct message ownerdata_defocus_all_parent_seq[] = {
195 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
196 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
197 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
198 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
202 static const struct message ownerdata_deselect_all_parent_seq[] = {
203 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
204 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
208 static const struct message select_all_parent_seq[] = {
209 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
210 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
212 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
213 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
215 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
216 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
218 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
219 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
221 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
222 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
226 static const struct message textcallback_set_again_parent_seq[] = {
227 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
228 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
232 static const struct message single_getdispinfo_parent_seq[] = {
233 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
237 static const struct message getitemposition_seq1[] = {
238 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
242 static const struct message getitemposition_seq2[] = {
243 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
244 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
248 static const struct message editbox_create_pos[] = {
249 /* sequence sent after LVN_BEGINLABELEDIT */
250 /* next two are 4.7x specific */
251 { WM_WINDOWPOSCHANGING, sent },
252 { WM_WINDOWPOSCHANGED, sent|optional },
254 { WM_WINDOWPOSCHANGING, sent|optional },
255 { WM_NCCALCSIZE, sent },
256 { WM_WINDOWPOSCHANGED, sent },
257 { WM_MOVE, sent|defwinproc },
258 { WM_SIZE, sent|defwinproc },
259 /* the rest is todo, skipped in 4.7x */
260 { WM_WINDOWPOSCHANGING, sent|optional },
261 { WM_WINDOWPOSCHANGED, sent|optional },
265 static const struct message scroll_parent_seq[] = {
266 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
267 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
271 static const struct message setredraw_seq[] = {
272 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
276 static const struct message lvs_ex_transparentbkgnd_seq[] = {
277 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
281 static const struct message edit_end_nochange[] = {
282 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
283 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW }, /* todo */
284 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
288 static const struct message hover_parent[] = {
289 { WM_GETDLGCODE, sent }, /* todo_wine */
290 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
294 static const struct message listview_destroy[] = {
295 { 0x0090, sent|optional }, /* Vista */
296 { WM_PARENTNOTIFY, sent },
297 { WM_SHOWWINDOW, sent },
298 { WM_WINDOWPOSCHANGING, sent },
299 { WM_WINDOWPOSCHANGED, sent|optional },
300 { WM_DESTROY, sent },
301 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
302 { WM_NCDESTROY, sent },
306 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
308 static LONG defwndproc_counter = 0;
312 msg.message = message;
313 msg.flags = sent|wparam|lparam;
314 if (defwndproc_counter) msg.flags |= defwinproc;
317 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
319 /* log system messages, except for painting */
320 if (message < WM_USER &&
321 message != WM_PAINT &&
322 message != WM_ERASEBKGND &&
323 message != WM_NCPAINT &&
324 message != WM_NCHITTEST &&
325 message != WM_GETTEXT &&
326 message != WM_GETICON &&
327 message != WM_DEVICECHANGE)
329 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
331 add_message(sequences, PARENT_SEQ_INDEX, &msg);
332 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
334 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
340 switch (((NMHDR*)lParam)->code)
342 case LVN_BEGINLABELEDIT:
343 /* subclass edit box */
345 subclass_editbox(((NMHDR*)lParam)->hwndFrom);
349 case LVN_ENDLABELEDIT:
351 /* always accept new item text */
352 NMLVDISPINFO *di = (NMLVDISPINFO*)lParam;
353 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText);
356 case LVN_BEGINSCROLL:
359 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
361 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
362 "BEGIN" : "END", pScroll->dx, pScroll->dy);
365 case LVN_ITEMCHANGED:
366 if (g_dump_itemchanged)
368 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
369 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
370 nmlv->iItem, nmlv->uNewState, nmlv->uOldState, nmlv->uChanged);
373 case LVN_GETDISPINFOA:
375 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
376 g_itema = dispinfo->item;
378 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
380 static const WCHAR testW[] = {'T','E','S','T',0};
381 dispinfo->hdr.code = LVN_GETDISPINFOW;
382 memcpy(dispinfo->item.pszText, testW, sizeof(testW));
387 if (g_block_hover) return 1;
392 case WM_NOTIFYFORMAT:
394 /* force to return format */
395 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
400 defwndproc_counter++;
401 ret = DefWindowProcA(hwnd, message, wParam, lParam);
402 defwndproc_counter--;
407 static BOOL register_parent_wnd_class(BOOL Unicode)
415 clsW.lpfnWndProc = parent_wnd_proc;
418 clsW.hInstance = GetModuleHandleW(NULL);
420 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
421 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
422 clsW.lpszMenuName = NULL;
423 clsW.lpszClassName = testparentclassW;
428 clsA.lpfnWndProc = parent_wnd_proc;
431 clsA.hInstance = GetModuleHandleA(NULL);
433 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
434 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
435 clsA.lpszMenuName = NULL;
436 clsA.lpszClassName = "Listview test parent class";
439 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
442 static HWND create_parent_window(BOOL Unicode)
444 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
447 if (!register_parent_wnd_class(Unicode))
454 hwnd = CreateWindowExW(0, testparentclassW, nameW,
455 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
456 WS_MAXIMIZEBOX | WS_VISIBLE,
458 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
460 hwnd = CreateWindowExA(0, "Listview test parent class",
461 "Listview test parent window",
462 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
463 WS_MAXIMIZEBOX | WS_VISIBLE,
465 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
466 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
470 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
472 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
473 static LONG defwndproc_counter = 0;
477 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
479 /* some debug output for style changing */
480 if ((message == WM_STYLECHANGING ||
481 message == WM_STYLECHANGED) && lParam)
483 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
484 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
487 msg.message = message;
488 msg.flags = sent|wparam|lparam;
489 if (defwndproc_counter) msg.flags |= defwinproc;
492 msg.id = LISTVIEW_ID;
493 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
494 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
496 defwndproc_counter++;
497 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
498 defwndproc_counter--;
502 static HWND create_listview_control(DWORD style)
508 GetClientRect(hwndparent, &rect);
509 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
510 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
511 0, 0, rect.right, rect.bottom,
512 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
513 ok(hwnd != NULL, "gle=%d\n", GetLastError());
515 if (!hwnd) return NULL;
517 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
518 (LONG_PTR)listview_subclass_proc);
519 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
524 /* unicode listview window with specified parent */
525 static HWND create_listview_controlW(DWORD style, HWND parent)
530 static const WCHAR nameW[] = {'f','o','o',0};
532 GetClientRect(parent, &rect);
533 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
534 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
535 0, 0, rect.right, rect.bottom,
536 parent, NULL, GetModuleHandleW(NULL), NULL);
537 ok(hwnd != NULL, "gle=%d\n", GetLastError());
539 if (!hwnd) return NULL;
541 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
542 (LONG_PTR)listview_subclass_proc);
543 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
548 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
550 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
551 static LONG defwndproc_counter = 0;
555 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
557 msg.message = message;
558 msg.flags = sent|wparam|lparam;
559 if (defwndproc_counter) msg.flags |= defwinproc;
563 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
565 defwndproc_counter++;
566 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
567 defwndproc_counter--;
571 static HWND subclass_header(HWND hwndListview)
576 hwnd = ListView_GetHeader(hwndListview);
577 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
578 (LONG_PTR)header_subclass_proc);
579 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
584 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
586 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
587 static LONG defwndproc_counter = 0;
591 msg.message = message;
592 msg.flags = sent|wparam|lparam;
593 if (defwndproc_counter) msg.flags |= defwinproc;
597 /* all we need is sizing */
598 if (message == WM_WINDOWPOSCHANGING ||
599 message == WM_NCCALCSIZE ||
600 message == WM_WINDOWPOSCHANGED ||
601 message == WM_MOVE ||
604 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
607 defwndproc_counter++;
608 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
609 defwndproc_counter--;
613 static HWND subclass_editbox(HWND hwndListview)
618 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
619 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
620 (LONG_PTR)editbox_subclass_proc);
621 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
626 /* Performs a single LVM_HITTEST test */
627 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
628 BOOL todo_item, BOOL todo_flags, int line)
637 trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
638 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
644 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
645 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
646 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
651 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
652 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
653 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
659 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
661 else if (broken_flags)
662 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
663 "Expected flags %x, got %x\n", flags, lpht.flags);
665 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
668 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
670 /* Performs a single LVM_SUBITEMHITTEST test */
671 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
672 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
680 trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
681 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
687 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
688 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
693 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
694 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
700 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
703 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
708 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
711 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
714 #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__)
716 static void test_images(void)
724 static CHAR hello[] = "hello";
726 himl = ImageList_Create(40, 40, 0, 4, 4);
727 ok(himl != NULL, "failed to create imagelist\n");
729 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
730 ok(hbmp != NULL, "failed to create bitmap\n");
732 r = ImageList_Add(himl, hbmp, 0);
733 ok(r == 0, "should be zero\n");
735 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
736 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
737 ok(hwnd != NULL, "failed to create listview window\n");
739 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
740 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
742 ok(r == 0, "should return zero\n");
744 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
745 ok(r == 0, "should return zero\n");
747 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
748 /* returns dimensions */
750 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
751 ok(r == 0, "should be zero items\n");
753 item.mask = LVIF_IMAGE | LVIF_TEXT;
758 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
759 ok(r == -1, "should fail\n");
762 item.pszText = hello;
763 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
764 ok(r == 0, "should not fail\n");
766 memset(&r1, 0, sizeof r1);
768 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
770 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
771 ok(r == TRUE, "should not fail\n");
774 item.pszText = hello;
775 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
776 ok(r == 0, "should not fail\n");
778 memset(&r2, 0, sizeof r2);
780 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
782 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
787 static void test_checkboxes(void)
792 static CHAR text[] = "Text",
796 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
797 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
798 ok(hwnd != NULL, "failed to create listview window\n");
800 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
801 item.mask = LVIF_TEXT | LVIF_STATE;
802 item.stateMask = 0xffff;
807 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
808 ok(r == 0, "ret %d\n", r);
811 item.mask = LVIF_STATE;
812 item.stateMask = 0xffff;
813 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
814 ok(item.state == 0xfccc, "state %x\n", item.state);
816 /* Don't set LVIF_STATE */
817 item.mask = LVIF_TEXT;
818 item.stateMask = 0xffff;
823 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
824 ok(r == 1, "ret %d\n", r);
827 item.mask = LVIF_STATE;
828 item.stateMask = 0xffff;
829 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
830 ok(item.state == 0, "state %x\n", item.state);
832 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
833 ok(r == 0, "should return zero\n");
835 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
837 item.mask = LVIF_STATE;
838 item.stateMask = 0xffff;
839 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
840 if (item.state != 0x1ccc)
842 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
847 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
849 item.mask = LVIF_TEXT;
851 item.pszText = text2;
852 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
853 ok(r == 2, "ret %d\n", r);
856 item.mask = LVIF_STATE;
857 item.stateMask = 0xffff;
858 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
859 ok(item.state == 0x1000, "state %x\n", item.state);
861 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
863 item.mask = LVIF_TEXT | LVIF_STATE;
864 item.stateMask = 0xffff;
866 item.pszText = text3;
867 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
868 ok(r == 3, "ret %d\n", r);
871 item.mask = LVIF_STATE;
872 item.stateMask = 0xffff;
873 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
874 ok(item.state == 0x1aaa, "state %x\n", item.state);
876 /* Set an item's state to checked */
878 item.mask = LVIF_STATE;
879 item.stateMask = 0xf000;
881 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
884 item.mask = LVIF_STATE;
885 item.stateMask = 0xffff;
886 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
887 ok(item.state == 0x2aaa, "state %x\n", item.state);
889 /* Check that only the bits we asked for are returned,
890 * and that all the others are set to zero
893 item.mask = LVIF_STATE;
894 item.stateMask = 0xf000;
896 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
897 ok(item.state == 0x2000, "state %x\n", item.state);
899 /* Set the style again and check that doesn't change an item's state */
900 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
901 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
904 item.mask = LVIF_STATE;
905 item.stateMask = 0xffff;
906 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
907 ok(item.state == 0x2aaa, "state %x\n", item.state);
909 /* Unsetting the checkbox extended style doesn't change an item's state */
910 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
911 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
914 item.mask = LVIF_STATE;
915 item.stateMask = 0xffff;
916 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
917 ok(item.state == 0x2aaa, "state %x\n", item.state);
919 /* Now setting the style again will change an item's state */
920 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
921 ok(r == 0, "ret %x\n", r);
924 item.mask = LVIF_STATE;
925 item.stateMask = 0xffff;
926 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
927 ok(item.state == 0x1aaa, "state %x\n", item.state);
929 /* Toggle checkbox tests (bug 9934) */
930 memset (&item, 0xcc, sizeof(item));
931 item.mask = LVIF_STATE;
934 item.state = LVIS_FOCUSED;
935 item.stateMask = LVIS_FOCUSED;
936 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
940 item.mask = LVIF_STATE;
941 item.stateMask = 0xffff;
942 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
943 ok(item.state == 0x1aab, "state %x\n", item.state);
945 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
947 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
951 item.mask = LVIF_STATE;
952 item.stateMask = 0xffff;
953 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
954 ok(item.state == 0x2aab, "state %x\n", item.state);
956 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
958 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
962 item.mask = LVIF_STATE;
963 item.stateMask = 0xffff;
964 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
965 ok(item.state == 0x1aab, "state %x\n", item.state);
970 static void insert_column(HWND hwnd, int idx)
975 memset(&column, 0xcc, sizeof(column));
976 column.mask = LVCF_SUBITEM;
977 column.iSubItem = idx;
979 rc = ListView_InsertColumn(hwnd, idx, &column);
983 static void insert_item(HWND hwnd, int idx)
985 static CHAR text[] = "foo";
990 memset(&item, 0xcc, sizeof (item));
991 item.mask = LVIF_TEXT;
996 rc = ListView_InsertItem(hwnd, &item);
1000 static void test_items(void)
1002 const LPARAM lparamTest = 0x42;
1006 static CHAR text[] = "Text";
1008 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1009 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1010 ok(hwnd != NULL, "failed to create listview window\n");
1013 * Test setting/getting item params
1016 /* Set up two columns */
1017 insert_column(hwnd, 0);
1018 insert_column(hwnd, 1);
1020 /* LVIS_SELECTED with zero stateMask */
1022 memset (&item, 0, sizeof (item));
1023 item.mask = LVIF_STATE;
1024 item.state = LVIS_SELECTED;
1028 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1029 ok(r == 0, "ret %d\n", r);
1031 memset (&item, 0xcc, sizeof (item));
1032 item.mask = LVIF_STATE;
1033 item.stateMask = LVIS_SELECTED;
1037 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1038 ok(r != 0, "ret %d\n", r);
1039 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1040 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1042 /* LVIS_SELECTED with zero stateMask */
1044 memset (&item, 0, sizeof (item));
1045 item.mask = LVIF_STATE;
1046 item.state = LVIS_FOCUSED;
1050 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1051 ok(r == 0, "ret %d\n", r);
1053 memset (&item, 0xcc, sizeof (item));
1054 item.mask = LVIF_STATE;
1055 item.stateMask = LVIS_FOCUSED;
1059 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1060 ok(r != 0, "ret %d\n", r);
1061 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1062 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1064 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1066 memset (&item, 0, sizeof (item));
1067 item.mask = LVIF_STATE;
1068 item.state = LVIS_CUT;
1069 item.stateMask = LVIS_FOCUSED;
1072 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1073 ok(r == 0, "ret %d\n", r);
1075 memset (&item, 0xcc, sizeof (item));
1076 item.mask = LVIF_STATE;
1077 item.stateMask = LVIS_CUT;
1081 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1082 ok(r != 0, "ret %d\n", r);
1083 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1084 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1086 /* Insert an item with just a param */
1087 memset (&item, 0xcc, sizeof (item));
1088 item.mask = LVIF_PARAM;
1091 item.lParam = lparamTest;
1092 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1093 ok(r == 0, "ret %d\n", r);
1095 /* Test getting of the param */
1096 memset (&item, 0xcc, sizeof (item));
1097 item.mask = LVIF_PARAM;
1100 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1101 ok(r != 0, "ret %d\n", r);
1102 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1104 /* Set up a subitem */
1105 memset (&item, 0xcc, sizeof (item));
1106 item.mask = LVIF_TEXT;
1109 item.pszText = text;
1110 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1111 ok(r != 0, "ret %d\n", r);
1113 /* Query param from subitem: returns main item param */
1114 memset (&item, 0xcc, sizeof (item));
1115 item.mask = LVIF_PARAM;
1118 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1119 ok(r != 0, "ret %d\n", r);
1120 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1122 /* Set up param on first subitem: no effect */
1123 memset (&item, 0xcc, sizeof (item));
1124 item.mask = LVIF_PARAM;
1127 item.lParam = lparamTest+1;
1128 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1129 ok(r == 0, "ret %d\n", r);
1131 /* Query param from subitem again: should still return main item param */
1132 memset (&item, 0xcc, sizeof (item));
1133 item.mask = LVIF_PARAM;
1136 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1137 ok(r != 0, "ret %d\n", r);
1138 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1140 /**** Some tests of state highlighting ****/
1141 memset (&item, 0xcc, sizeof (item));
1142 item.mask = LVIF_STATE;
1145 item.state = LVIS_SELECTED;
1146 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1147 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1148 ok(r != 0, "ret %d\n", r);
1150 item.state = LVIS_DROPHILITED;
1151 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1152 ok(r != 0, "ret %d\n", r);
1154 memset (&item, 0xcc, sizeof (item));
1155 item.mask = LVIF_STATE;
1158 item.stateMask = -1;
1159 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1160 ok(r != 0, "ret %d\n", r);
1161 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1163 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1164 ok(r != 0, "ret %d\n", r);
1165 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1167 /* some notnull but meaningless masks */
1168 memset (&item, 0, sizeof(item));
1169 item.mask = LVIF_NORECOMPUTE;
1172 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1173 ok(r != 0, "ret %d\n", r);
1174 memset (&item, 0, sizeof(item));
1175 item.mask = LVIF_DI_SETITEM;
1178 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1179 ok(r != 0, "ret %d\n", r);
1181 /* set text to callback value already having it */
1182 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1184 memset (&item, 0, sizeof (item));
1185 item.mask = LVIF_TEXT;
1186 item.pszText = LPSTR_TEXTCALLBACK;
1188 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1189 ok(r == 0, "ret %d\n", r);
1190 memset (&item, 0, sizeof (item));
1192 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1194 item.pszText = LPSTR_TEXTCALLBACK;
1195 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1198 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1199 "check callback text comparison rule", FALSE);
1201 DestroyWindow(hwnd);
1204 static void test_columns(void)
1213 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1214 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1215 ok(hwnd != NULL, "failed to create listview window\n");
1217 /* Add a column with no mask */
1218 memset(&column, 0xcc, sizeof(column));
1220 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1221 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1223 /* Check its width */
1224 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1225 ok(rc == 10 || broken(rc == 0) /* win9x */,
1226 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1228 DestroyWindow(hwnd);
1230 /* LVM_GETCOLUMNORDERARRAY */
1231 hwnd = create_listview_control(LVS_REPORT);
1232 subclass_header(hwnd);
1234 memset(&column, 0, sizeof(column));
1235 column.mask = LVCF_WIDTH;
1237 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1238 ok(rc == 0, "Inserting column failed with %d\n", rc);
1241 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1242 ok(rc == 1, "Inserting column failed with %d\n", rc);
1244 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1246 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1247 ok(rc == 1, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1248 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1249 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1251 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1253 /* after column added subitem is considered as present */
1254 insert_item(hwnd, 0);
1256 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1258 item.pszText = buff;
1259 item.cchTextMax = sizeof(buff);
1262 item.mask = LVIF_TEXT;
1263 memset(&g_itema, 0, sizeof(g_itema));
1264 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1265 ok(rc == 1, "got %d\n", rc);
1266 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1268 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1269 "get subitem text after column added", FALSE);
1271 DestroyWindow(hwnd);
1274 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1275 static WNDPROC listviewWndProc;
1276 static HIMAGELIST test_create_imagelist;
1278 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1282 if (uMsg == WM_CREATE)
1284 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1285 lpcs->style |= LVS_REPORT;
1287 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1288 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1292 static void test_create(void)
1303 cls.cbSize = sizeof(WNDCLASSEX);
1304 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1305 listviewWndProc = cls.lpfnWndProc;
1306 cls.lpfnWndProc = create_test_wndproc;
1307 cls.lpszClassName = "MyListView32";
1308 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1310 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1311 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1312 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1313 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1315 if (!IsWindow(hHeader))
1318 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1319 DestroyWindow(hList);
1323 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1324 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1325 DestroyWindow(hList);
1327 /* header isn't created on LVS_ICON and LVS_LIST styles */
1328 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1329 GetModuleHandle(NULL), 0);
1330 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1331 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1332 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1334 memset(&col, 0, sizeof(LVCOLUMNA));
1335 col.mask = LVCF_WIDTH;
1337 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1338 ok(r == 0, "Expected 0 column's inserted\n");
1339 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1340 ok(IsWindow(hHeader), "Header should be created\n");
1341 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1342 style = GetWindowLong(hHeader, GWL_STYLE);
1343 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1344 DestroyWindow(hList);
1346 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1347 GetModuleHandle(NULL), 0);
1348 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1349 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1350 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1352 memset(&col, 0, sizeof(LVCOLUMNA));
1353 col.mask = LVCF_WIDTH;
1355 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1356 ok(r == 0, "Expected 0 column's inserted\n");
1357 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1358 ok(IsWindow(hHeader), "Header should be created\n");
1359 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1360 DestroyWindow(hList);
1362 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1363 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1364 GetModuleHandle(NULL), 0);
1365 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1366 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1367 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1368 ok(IsWindow(hHeader), "Header should be created\n");
1369 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1370 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1371 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1372 ok(IsWindow(hHeader), "Header should be created\n");
1373 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1374 DestroyWindow(hList);
1376 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1377 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1378 GetModuleHandle(NULL), 0);
1379 ret = SetWindowLongPtr(hList, GWL_STYLE,
1380 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1381 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1382 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1383 ok(IsWindow(hHeader), "Header should be created\n");
1384 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1385 ret = SetWindowLongPtr(hList, GWL_STYLE,
1386 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1387 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1388 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1389 ok(IsWindow(hHeader), "Header should be created\n");
1390 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1391 DestroyWindow(hList);
1393 /* LVS_REPORT without WS_VISIBLE */
1394 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1395 GetModuleHandle(NULL), 0);
1396 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1397 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1398 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1400 memset(&col, 0, sizeof(LVCOLUMNA));
1401 col.mask = LVCF_WIDTH;
1403 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1404 ok(r == 0, "Expected 0 column's inserted\n");
1405 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1406 ok(IsWindow(hHeader), "Header should be created\n");
1407 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1408 DestroyWindow(hList);
1410 /* LVS_REPORT without WS_VISIBLE, try to show it */
1411 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1412 GetModuleHandle(NULL), 0);
1413 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1414 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1415 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1416 ShowWindow(hList, SW_SHOW);
1417 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1418 ok(IsWindow(hHeader), "Header should be created\n");
1419 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1420 DestroyWindow(hList);
1422 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1423 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1424 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1425 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1426 ok(IsWindow(hHeader), "Header should be created\n");
1427 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1428 /* HDS_DRAGDROP set by default */
1429 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1430 DestroyWindow(hList);
1432 /* setting LVS_EX_HEADERDRAGDROP creates header */
1433 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1434 GetModuleHandle(NULL), 0);
1435 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1436 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1437 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1438 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1439 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1440 ok(IsWindow(hHeader) ||
1441 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1442 "Header should be created\n");
1443 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1444 DestroyWindow(hList);
1446 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1447 hList = create_listview_control(LVS_ICON);
1448 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1449 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1450 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1451 DestroyWindow(hList);
1453 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1454 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1455 GetModuleHandle(NULL), 0);
1456 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1457 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1459 rect.left = LVIR_BOUNDS;
1461 rect.right = rect.bottom = -10;
1462 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1463 ok(r != 0, "Expected not-null LRESULT\n");
1465 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1466 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1467 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1469 DestroyWindow(hList);
1471 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1472 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1473 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1474 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1475 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1476 DestroyWindow(hList);
1479 static void test_redraw(void)
1486 hwnd = create_listview_control(LVS_REPORT);
1487 subclass_header(hwnd);
1489 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1491 trace("invalidate & update\n");
1492 InvalidateRect(hwnd, NULL, TRUE);
1494 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1496 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1498 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1499 /* 1. Without backbuffer */
1500 res = ListView_SetBkColor(hwnd, CLR_NONE);
1503 hdc = GetWindowDC(hwndparent);
1505 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1506 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1507 ok(r != 0, "Expected not zero result\n");
1508 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1509 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1511 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1514 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1515 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1516 ok(r != 0, "Expected not zero result\n");
1517 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1518 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1520 /* 2. With backbuffer */
1521 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1522 LVS_EX_DOUBLEBUFFER);
1523 res = ListView_SetBkColor(hwnd, CLR_NONE);
1526 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1527 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1528 ok(r != 0, "Expected not zero result\n");
1529 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1530 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1532 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1535 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1536 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1537 todo_wine ok(r != 0, "Expected not zero result\n");
1538 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1539 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1541 ReleaseDC(hwndparent, hdc);
1543 DestroyWindow(hwnd);
1546 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1548 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1550 if(msg == WM_NOTIFY) {
1551 NMHDR *nmhdr = (PVOID)lp;
1552 if(nmhdr->code == NM_CUSTOMDRAW) {
1553 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1554 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1555 switch(nmlvcd->nmcd.dwDrawStage) {
1557 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1558 return CDRF_NOTIFYITEMDRAW;
1559 case CDDS_ITEMPREPAINT:
1560 nmlvcd->clrTextBk = CLR_DEFAULT;
1561 return CDRF_NOTIFYSUBITEMDRAW;
1562 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1563 clr = GetBkColor(nmlvcd->nmcd.hdc);
1564 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1565 return CDRF_NOTIFYPOSTPAINT;
1566 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1567 clr = GetBkColor(nmlvcd->nmcd.hdc);
1568 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1569 return CDRF_DODEFAULT;
1571 return CDRF_DODEFAULT;
1575 return DefWindowProcA(hwnd, msg, wp, lp);
1578 static void test_customdraw(void)
1583 hwnd = create_listview_control(LVS_REPORT);
1585 insert_column(hwnd, 0);
1586 insert_column(hwnd, 1);
1587 insert_item(hwnd, 0);
1589 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1590 (LONG_PTR)cd_wndproc);
1592 InvalidateRect(hwnd, NULL, TRUE);
1595 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1597 DestroyWindow(hwnd);
1600 static void test_icon_spacing(void)
1602 /* LVM_SETICONSPACING */
1603 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1609 hwnd = create_listview_control(LVS_ICON);
1610 ok(hwnd != NULL, "failed to create a listview window\n");
1612 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1613 expect(NFR_ANSI, r);
1615 /* reset the icon spacing to defaults */
1616 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1618 /* now we can request what the defaults are */
1619 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1623 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1625 trace("test icon spacing\n");
1627 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1628 ok(r == MAKELONG(w, h) ||
1629 broken(r == MAKELONG(w, w)), /* win98 */
1630 "Expected %d, got %d\n", MAKELONG(w, h), r);
1632 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1636 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1637 DestroyWindow(hwnd);
1640 expect(MAKELONG(20,30), r);
1642 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1643 expect(MAKELONG(25,35), r);
1645 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1647 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1648 DestroyWindow(hwnd);
1651 static void test_color(void)
1653 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1660 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1662 hwnd = create_listview_control(LVS_REPORT);
1663 ok(hwnd != NULL, "failed to create a listview window\n");
1665 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1667 trace("test color seq\n");
1668 for (i = 0; i < 4; i++)
1672 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1674 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1677 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1679 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1682 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1684 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1688 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1690 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1691 DestroyWindow(hwnd);
1694 static void test_item_count(void)
1696 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1709 static CHAR item0text[] = "item0";
1710 static CHAR item1text[] = "item1";
1711 static CHAR item2text[] = "item2";
1713 hwnd = create_listview_control(LVS_REPORT);
1714 ok(hwnd != NULL, "failed to create a listview window\n");
1716 /* resize in dpiaware manner to fit all 3 items added */
1718 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1719 GetTextMetricsA(hdc, &tm);
1720 /* 2 extra pixels for bounds and header border */
1721 height = tm.tmHeight + 2;
1722 SelectObject(hdc, hOldFont);
1725 GetWindowRect(hwnd, &rect);
1726 /* 3 items + 1 header + 1 to be sure */
1727 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1729 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1731 trace("test item count\n");
1733 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1737 item0.mask = LVIF_TEXT;
1740 item0.pszText = item0text;
1741 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1744 /* [item0, item1] */
1745 item1.mask = LVIF_TEXT;
1748 item1.pszText = item1text;
1749 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1752 /* [item0, item1, item2] */
1753 item2.mask = LVIF_TEXT;
1756 item2.pszText = item2text;
1757 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1760 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1763 /* [item0, item1] */
1764 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1767 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1771 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1774 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1778 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1781 /* [item0, item1] */
1782 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1785 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1788 /* [item0, item1, item2] */
1789 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1792 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1795 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1797 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1798 DestroyWindow(hwnd);
1801 static void test_item_position(void)
1803 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1812 static CHAR item0text[] = "item0";
1813 static CHAR item1text[] = "item1";
1814 static CHAR item2text[] = "item2";
1816 hwnd = create_listview_control(LVS_ICON);
1817 ok(hwnd != NULL, "failed to create a listview window\n");
1819 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1821 trace("test item position\n");
1824 item0.mask = LVIF_TEXT;
1827 item0.pszText = item0text;
1828 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1831 /* [item0, item1] */
1832 item1.mask = LVIF_TEXT;
1835 item1.pszText = item1text;
1836 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1839 /* [item0, item1, item2] */
1840 item2.mask = LVIF_TEXT;
1843 item2.pszText = item2text;
1844 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1847 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1849 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1851 expect2(10, 5, position.x, position.y);
1853 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1855 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1857 expect2(0, 0, position.x, position.y);
1859 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1861 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1863 expect2(20, 20, position.x, position.y);
1865 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1867 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1868 DestroyWindow(hwnd);
1871 static void test_getorigin(void)
1879 position.x = position.y = 0;
1881 hwnd = create_listview_control(LVS_ICON);
1882 ok(hwnd != NULL, "failed to create a listview window\n");
1883 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1884 trace("test get origin results\n");
1885 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1887 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1888 DestroyWindow(hwnd);
1890 hwnd = create_listview_control(LVS_SMALLICON);
1891 ok(hwnd != NULL, "failed to create a listview window\n");
1892 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1893 trace("test get origin results\n");
1894 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1896 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1897 DestroyWindow(hwnd);
1899 hwnd = create_listview_control(LVS_LIST);
1900 ok(hwnd != NULL, "failed to create a listview window\n");
1901 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1902 trace("test get origin results\n");
1903 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1905 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1906 DestroyWindow(hwnd);
1908 hwnd = create_listview_control(LVS_REPORT);
1909 ok(hwnd != NULL, "failed to create a listview window\n");
1910 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1911 trace("test get origin results\n");
1912 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1914 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1915 DestroyWindow(hwnd);
1919 static void test_multiselect(void)
1921 typedef struct t_select_task
1932 int i,j,item_count,selected_count;
1933 static const int items=5;
1939 static struct t_select_task task_list[] = {
1940 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1941 { "using VK_UP", -1, VK_UP, -1, -1 },
1942 { "using VK_END", 0, VK_END, 1, -1 },
1943 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1947 hwnd = create_listview_control(LVS_REPORT);
1949 for (i=0;i<items;i++) {
1950 insert_item(hwnd, 0);
1953 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1955 expect(items,item_count);
1958 task = task_list[i];
1960 /* deselect all items */
1961 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1962 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1964 /* set initial position */
1965 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1966 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1968 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1970 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1972 /* Set SHIFT key pressed */
1973 GetKeyboardState(kstate);
1974 kstate[VK_SHIFT]=0x80;
1975 SetKeyboardState(kstate);
1977 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1978 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1980 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1984 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1986 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);
1988 /* Set SHIFT key released */
1989 GetKeyboardState(kstate);
1990 kstate[VK_SHIFT]=0x00;
1991 SetKeyboardState(kstate);
1993 DestroyWindow(hwnd);
1995 /* make multiple selection, then switch to LVS_SINGLESEL */
1996 hwnd = create_listview_control(LVS_REPORT);
1997 for (i=0;i<items;i++) {
1998 insert_item(hwnd, 0);
2000 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2001 expect(items,item_count);
2003 /* try with NULL pointer */
2004 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
2007 /* select all, check notifications */
2008 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2010 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2012 item.stateMask = LVIS_SELECTED;
2013 item.state = LVIS_SELECTED;
2014 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2017 ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
2018 "select all notification", FALSE);
2020 /* deselect all items */
2021 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2022 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2024 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
2027 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2029 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2032 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2033 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2034 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2035 /* check that style is accepted */
2036 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2037 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2040 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2041 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2043 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2045 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2048 /* select one more */
2049 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2052 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2053 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2055 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2056 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2058 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2060 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2063 /* try to select all on LVS_SINGLESEL */
2064 memset(&item, 0, sizeof(item));
2065 item.stateMask = LVIS_SELECTED;
2066 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2068 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2070 item.stateMask = LVIS_SELECTED;
2071 item.state = LVIS_SELECTED;
2072 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2075 r = ListView_GetSelectedCount(hwnd);
2077 r = ListView_GetSelectionMark(hwnd);
2080 /* try to deselect all on LVS_SINGLESEL */
2081 item.stateMask = LVIS_SELECTED;
2082 item.state = LVIS_SELECTED;
2083 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2086 item.stateMask = LVIS_SELECTED;
2088 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2090 r = ListView_GetSelectedCount(hwnd);
2093 DestroyWindow(hwnd);
2096 static void test_subitem_rect(void)
2104 /* test LVM_GETSUBITEMRECT for header */
2105 hwnd = create_listview_control(LVS_REPORT);
2106 ok(hwnd != NULL, "failed to create a listview window\n");
2107 /* add some columns */
2108 memset(&col, 0, sizeof(LVCOLUMN));
2109 col.mask = LVCF_WIDTH;
2111 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2114 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2117 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2119 /* item = -1 means header, subitem index is 1 based */
2120 rect.left = LVIR_BOUNDS;
2122 rect.right = rect.bottom = 0;
2123 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2126 rect.left = LVIR_BOUNDS;
2128 rect.right = rect.bottom = 0;
2129 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2131 ok(r != 0, "Expected not-null LRESULT\n");
2132 expect(100, rect.left);
2133 expect(250, rect.right);
2135 expect(3, rect.top);
2137 rect.left = LVIR_BOUNDS;
2139 rect.right = rect.bottom = 0;
2140 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2142 ok(r != 0, "Expected not-null LRESULT\n");
2143 expect(250, rect.left);
2144 expect(450, rect.right);
2146 expect(3, rect.top);
2148 /* item LVS_REPORT padding isn't applied to subitems */
2149 insert_item(hwnd, 0);
2151 rect.left = LVIR_BOUNDS;
2153 rect.right = rect.bottom = 0;
2154 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2155 ok(r != 0, "Expected not-null LRESULT\n");
2156 expect(100, rect.left);
2157 expect(250, rect.right);
2159 rect.left = LVIR_ICON;
2161 rect.right = rect.bottom = 0;
2162 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2163 ok(r != 0, "Expected not-null LRESULT\n");
2164 /* no icon attached - zero width rectangle, with no left padding */
2165 expect(100, rect.left);
2166 expect(100, rect.right);
2168 rect.left = LVIR_LABEL;
2170 rect.right = rect.bottom = 0;
2171 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2172 ok(r != 0, "Expected not-null LRESULT\n");
2173 /* same as full LVIR_BOUNDS */
2174 expect(100, rect.left);
2175 expect(250, rect.right);
2177 SendMessage(hwnd, LVM_SCROLL, 10, 0);
2179 rect.left = LVIR_BOUNDS;
2181 rect.right = rect.bottom = 0;
2182 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2183 ok(r != 0, "Expected not-null LRESULT\n");
2184 expect(90, rect.left);
2185 expect(240, rect.right);
2187 SendMessage(hwnd, LVM_SCROLL, -10, 0);
2189 DestroyWindow(hwnd);
2191 /* test subitem rects after re-arranging columns */
2192 hwnd = create_listview_control(LVS_REPORT);
2193 ok(hwnd != NULL, "failed to create a listview window\n");
2194 memset(&col, 0, sizeof(LVCOLUMN));
2195 col.mask = LVCF_WIDTH;
2198 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2202 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2206 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2209 insert_item(hwnd, 0);
2210 insert_item(hwnd, 1);
2212 /* wrong item is refused for main item */
2213 rect.left = LVIR_BOUNDS;
2215 rect.right = rect.bottom = -1;
2216 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect);
2217 ok(r == FALSE, "got %d\n", r);
2219 /* for subitems rectangle is calculated even if there's no item added */
2220 rect.left = LVIR_BOUNDS;
2222 rect.right = rect.bottom = -1;
2223 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect);
2224 ok(r == TRUE, "got %d\n", r);
2226 rect2.left = LVIR_BOUNDS;
2228 rect2.right = rect2.bottom = -1;
2229 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect2);
2231 ok(r == TRUE, "got %d\n", r);
2232 expect(rect.right, rect2.right);
2233 expect(rect.left, rect2.left);
2234 expect(rect.bottom, rect2.top);
2235 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2238 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2239 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2242 rect.left = LVIR_BOUNDS;
2244 rect.right = rect.bottom = -1;
2245 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2246 ok(r == TRUE, "got %d\n", r);
2247 expect(0, rect.left);
2248 expect(600, rect.right);
2250 rect.left = LVIR_BOUNDS;
2252 rect.right = rect.bottom = -1;
2253 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2254 ok(r == TRUE, "got %d\n", r);
2255 expect(0, rect.left);
2256 expect(200, rect.right);
2258 rect2.left = LVIR_BOUNDS;
2260 rect2.right = rect2.bottom = -1;
2261 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect2);
2262 ok(r == TRUE, "got %d\n", r);
2263 expect(0, rect2.left);
2264 expect(200, rect2.right);
2265 /* items are of the same height */
2266 ok(rect2.top > 0, "expected positive item height\n");
2267 expect(rect.bottom, rect2.top);
2268 expect(rect.bottom * 2 - rect.top, rect2.bottom);
2270 rect.left = LVIR_BOUNDS;
2272 rect.right = rect.bottom = -1;
2273 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2274 ok(r == TRUE, "got %d\n", r);
2275 expect(300, rect.left);
2276 expect(600, rect.right);
2278 DestroyWindow(hwnd);
2280 /* try it for non LVS_REPORT style */
2281 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2282 GetModuleHandle(NULL), 0);
2283 rect.left = LVIR_BOUNDS;
2285 rect.right = rect.bottom = -10;
2286 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2287 ok(r == 0, "Expected not-null LRESULT\n");
2288 /* rect is unchanged */
2289 expect(0, rect.left);
2290 expect(-10, rect.right);
2291 expect(1, rect.top);
2292 expect(-10, rect.bottom);
2293 DestroyWindow(hwnd);
2296 /* comparison callback for test_sorting */
2297 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2299 if (first == second) return 0;
2300 return (first > second ? 1 : -1);
2303 static void test_sorting(void)
2309 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2312 hwnd = create_listview_control(LVS_REPORT);
2313 ok(hwnd != NULL, "failed to create a listview window\n");
2315 /* insert some items */
2316 item.mask = LVIF_PARAM | LVIF_STATE;
2317 item.state = LVIS_SELECTED;
2321 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2324 item.mask = LVIF_PARAM;
2328 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2331 item.mask = LVIF_STATE | LVIF_PARAM;
2332 item.state = LVIS_SELECTED;
2336 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2339 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2342 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2345 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2348 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2350 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2352 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2354 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2355 expect(LVIS_SELECTED, r);
2356 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2357 expect(LVIS_SELECTED, r);
2359 DestroyWindow(hwnd);
2361 /* switch to LVS_SORTASCENDING when some items added */
2362 hwnd = create_listview_control(LVS_REPORT);
2363 ok(hwnd != NULL, "failed to create a listview window\n");
2365 item.mask = LVIF_TEXT;
2368 item.pszText = names[1];
2369 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2372 item.mask = LVIF_TEXT;
2375 item.pszText = names[2];
2376 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2379 item.mask = LVIF_TEXT;
2382 item.pszText = names[0];
2383 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2386 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2387 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2388 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2389 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2391 /* no sorting performed when switched to LVS_SORTASCENDING */
2392 item.mask = LVIF_TEXT;
2394 item.pszText = buff;
2395 item.cchTextMax = sizeof(buff);
2396 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2398 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2401 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2403 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2406 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2408 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2410 /* adding new item doesn't resort list */
2411 item.mask = LVIF_TEXT;
2414 item.pszText = names[3];
2415 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2418 item.mask = LVIF_TEXT;
2420 item.pszText = buff;
2421 item.cchTextMax = sizeof(buff);
2422 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2424 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2427 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2429 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2432 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2434 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2437 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2439 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2441 /* corner case - item should be placed at first position */
2442 item.mask = LVIF_TEXT;
2445 item.pszText = names[4];
2446 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2450 item.pszText = buff;
2451 item.cchTextMax = sizeof(buff);
2452 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2454 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2457 item.pszText = buff;
2458 item.cchTextMax = sizeof(buff);
2459 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2461 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2464 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2466 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2469 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2471 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2474 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2476 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2478 DestroyWindow(hwnd);
2481 static void test_ownerdata(void)
2484 LONG_PTR style, ret;
2488 /* it isn't possible to set LVS_OWNERDATA after creation */
2491 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2495 hwnd = create_listview_control(LVS_REPORT);
2496 ok(hwnd != NULL, "failed to create a listview window\n");
2497 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2498 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2500 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2502 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2503 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2504 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2505 "try to switch to LVS_OWNERDATA seq", FALSE);
2507 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2508 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2509 DestroyWindow(hwnd);
2512 /* try to set LVS_OWNERDATA after creation just having it */
2513 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2514 ok(hwnd != NULL, "failed to create a listview window\n");
2515 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2516 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2518 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2520 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2521 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2522 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2523 "try to switch to LVS_OWNERDATA seq", FALSE);
2524 DestroyWindow(hwnd);
2526 /* try to remove LVS_OWNERDATA after creation just having it */
2529 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2533 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2534 ok(hwnd != NULL, "failed to create a listview window\n");
2535 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2536 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2538 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2540 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2541 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2542 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2543 "try to switch to LVS_OWNERDATA seq", FALSE);
2544 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2545 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2546 DestroyWindow(hwnd);
2549 /* try select an item */
2550 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2551 ok(hwnd != NULL, "failed to create a listview window\n");
2552 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2553 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2554 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2556 memset(&item, 0, sizeof(item));
2557 item.stateMask = LVIS_SELECTED;
2558 item.state = LVIS_SELECTED;
2559 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2561 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2563 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2565 DestroyWindow(hwnd);
2567 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2568 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2569 ok(hwnd != NULL, "failed to create a listview window\n");
2570 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2571 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2572 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2574 memset(&item, 0, sizeof(item));
2575 item.mask = LVIF_STATE;
2577 item.stateMask = LVIS_SELECTED;
2578 item.state = LVIS_SELECTED;
2579 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2581 DestroyWindow(hwnd);
2583 /* check notifications after focused/selected changed */
2584 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2585 ok(hwnd != NULL, "failed to create a listview window\n");
2586 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2587 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2589 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2591 memset(&item, 0, sizeof(item));
2592 item.stateMask = LVIS_SELECTED;
2593 item.state = LVIS_SELECTED;
2594 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2597 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2598 "ownerdata select notification", TRUE);
2600 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2602 memset(&item, 0, sizeof(item));
2603 item.stateMask = LVIS_FOCUSED;
2604 item.state = LVIS_FOCUSED;
2605 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2608 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2609 "ownerdata focus notification", TRUE);
2611 /* select all, check notifications */
2612 item.stateMask = LVIS_SELECTED;
2614 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2617 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2619 item.stateMask = LVIS_SELECTED;
2620 item.state = LVIS_SELECTED;
2622 g_dump_itemchanged = TRUE;
2623 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2625 g_dump_itemchanged = FALSE;
2627 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2628 "ownerdata select all notification", TRUE);
2630 /* select all again, note that all items are selected already */
2631 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2632 item.stateMask = LVIS_SELECTED;
2633 item.state = LVIS_SELECTED;
2634 g_dump_itemchanged = TRUE;
2635 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2637 g_dump_itemchanged = FALSE;
2638 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2639 "ownerdata select all notification", TRUE);
2641 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2642 item.stateMask = LVIS_SELECTED;
2644 g_dump_itemchanged = TRUE;
2645 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2647 g_dump_itemchanged = FALSE;
2648 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2649 "ownerdata deselect all notification", TRUE);
2651 /* select one, then deselect all */
2652 item.stateMask = LVIS_SELECTED;
2653 item.state = LVIS_SELECTED;
2654 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2656 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2657 item.stateMask = LVIS_SELECTED;
2659 g_dump_itemchanged = TRUE;
2660 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2662 g_dump_itemchanged = FALSE;
2663 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2664 "ownerdata select all notification", TRUE);
2666 /* remove focused, try to focus all */
2667 item.stateMask = LVIS_FOCUSED;
2668 item.state = LVIS_FOCUSED;
2669 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2671 item.stateMask = LVIS_FOCUSED;
2673 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2675 item.stateMask = LVIS_FOCUSED;
2676 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
2678 /* setting all to focused returns failure value */
2679 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2680 item.stateMask = LVIS_FOCUSED;
2681 item.state = LVIS_FOCUSED;
2682 g_dump_itemchanged = TRUE;
2683 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2685 g_dump_itemchanged = FALSE;
2686 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2687 "ownerdata focus all notification", FALSE);
2688 /* focus single item, remove all */
2689 item.stateMask = LVIS_FOCUSED;
2690 item.state = LVIS_FOCUSED;
2691 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2693 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2694 item.stateMask = LVIS_FOCUSED;
2696 g_dump_itemchanged = TRUE;
2697 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2699 g_dump_itemchanged = FALSE;
2700 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
2701 "ownerdata remove focus all notification", TRUE);
2703 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2704 item.stateMask = LVIS_CUT;
2705 item.state = LVIS_CUT;
2706 g_dump_itemchanged = TRUE;
2707 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2709 g_dump_itemchanged = FALSE;
2710 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2711 "ownerdata cut all notification", TRUE);
2712 /* all marked cut, try again */
2713 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2714 item.stateMask = LVIS_CUT;
2715 item.state = LVIS_CUT;
2716 g_dump_itemchanged = TRUE;
2717 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2719 g_dump_itemchanged = FALSE;
2720 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2721 "ownerdata cut all notification #2", TRUE);
2723 DestroyWindow(hwnd);
2725 /* check notifications on LVM_GETITEM */
2726 /* zero callback mask */
2727 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2728 ok(hwnd != NULL, "failed to create a listview window\n");
2729 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2730 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2732 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2734 memset(&item, 0, sizeof(item));
2735 item.stateMask = LVIS_SELECTED;
2736 item.mask = LVIF_STATE;
2737 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2740 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2741 "ownerdata getitem selected state 1", FALSE);
2743 /* non zero callback mask but not we asking for */
2744 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2747 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2749 memset(&item, 0, sizeof(item));
2750 item.stateMask = LVIS_SELECTED;
2751 item.mask = LVIF_STATE;
2752 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2755 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2756 "ownerdata getitem selected state 2", FALSE);
2758 /* LVIS_OVERLAYMASK callback mask, asking for index */
2759 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2761 memset(&item, 0, sizeof(item));
2762 item.stateMask = LVIS_OVERLAYMASK;
2763 item.mask = LVIF_STATE;
2764 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2767 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2768 "ownerdata getitem selected state 2", FALSE);
2770 DestroyWindow(hwnd);
2772 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2773 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
2774 ok(hwnd != NULL, "failed to create a listview window\n");
2775 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2776 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2777 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2778 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2779 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2780 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2781 DestroyWindow(hwnd);
2782 /* apparently it's allowed to switch these style on after creation */
2783 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2784 ok(hwnd != NULL, "failed to create a listview window\n");
2785 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2786 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2787 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2788 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2789 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2790 DestroyWindow(hwnd);
2792 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2793 ok(hwnd != NULL, "failed to create a listview window\n");
2794 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2795 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2796 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2797 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2798 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2799 DestroyWindow(hwnd);
2802 static void test_norecompute(void)
2804 static CHAR testA[] = "test";
2810 /* self containing control */
2811 hwnd = create_listview_control(LVS_REPORT);
2812 ok(hwnd != NULL, "failed to create a listview window\n");
2813 memset(&item, 0, sizeof(item));
2814 item.mask = LVIF_TEXT | LVIF_STATE;
2816 item.stateMask = LVIS_SELECTED;
2817 item.state = LVIS_SELECTED;
2818 item.pszText = testA;
2819 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2821 /* retrieve with LVIF_NORECOMPUTE */
2822 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2824 item.pszText = buff;
2825 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2826 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2828 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2830 item.mask = LVIF_TEXT;
2832 item.pszText = LPSTR_TEXTCALLBACK;
2833 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2836 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2838 item.pszText = buff;
2839 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2841 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2842 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2844 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2845 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2846 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2848 DestroyWindow(hwnd);
2851 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2852 ok(hwnd != NULL, "failed to create a listview window\n");
2854 item.mask = LVIF_STATE;
2855 item.stateMask = LVIS_SELECTED;
2856 item.state = LVIS_SELECTED;
2858 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2861 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2863 item.pszText = buff;
2864 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2865 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2866 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2868 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2869 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2870 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2872 DestroyWindow(hwnd);
2875 static void test_nosortheader(void)
2880 hwnd = create_listview_control(LVS_REPORT);
2881 ok(hwnd != NULL, "failed to create a listview window\n");
2883 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2884 ok(IsWindow(header), "header expected\n");
2886 style = GetWindowLongPtr(header, GWL_STYLE);
2887 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2889 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2890 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2891 /* HDS_BUTTONS retained */
2892 style = GetWindowLongPtr(header, GWL_STYLE);
2893 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2895 DestroyWindow(hwnd);
2897 /* create with LVS_NOSORTHEADER */
2898 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
2899 ok(hwnd != NULL, "failed to create a listview window\n");
2901 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2902 ok(IsWindow(header), "header expected\n");
2904 style = GetWindowLongPtr(header, GWL_STYLE);
2905 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2907 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2908 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2909 /* not changed here */
2910 style = GetWindowLongPtr(header, GWL_STYLE);
2911 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2913 DestroyWindow(hwnd);
2916 static void test_setredraw(void)
2924 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2925 ok(hwnd != NULL, "failed to create a listview window\n");
2927 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2928 ListView seems to handle it internally without DefWinProc */
2930 /* default value first */
2931 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2934 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2935 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2936 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2938 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2939 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2940 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2943 /* check update rect after redrawing */
2944 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2946 InvalidateRect(hwnd, NULL, FALSE);
2947 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
2948 rect.right = rect.bottom = 1;
2949 GetUpdateRect(hwnd, &rect, FALSE);
2950 expect(0, rect.right);
2951 expect(0, rect.bottom);
2954 hdc = GetWindowDC(hwndparent);
2955 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2957 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2959 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2961 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2963 ReleaseDC(hwndparent, hdc);
2965 /* check notification messages to show that repainting is disabled */
2966 ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
2968 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2970 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2972 InvalidateRect(hwnd, NULL, TRUE);
2974 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2975 "redraw after WM_SETREDRAW (FALSE)", FALSE);
2977 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
2979 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2980 InvalidateRect(hwnd, NULL, TRUE);
2982 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2983 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
2985 /* message isn't forwarded to header */
2986 subclass_header(hwnd);
2987 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2988 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2990 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
2991 "WM_SETREDRAW: not forwarded to header", FALSE);
2993 DestroyWindow(hwnd);
2996 static void test_hittest(void)
3002 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3006 HIMAGELIST himl, himl2;
3009 hwnd = create_listview_control(LVS_REPORT);
3010 ok(hwnd != NULL, "failed to create a listview window\n");
3012 /* LVS_REPORT with a single subitem (2 columns) */
3013 insert_column(hwnd, 0);
3014 insert_column(hwnd, 1);
3015 insert_item(hwnd, 0);
3018 /* the only purpose of that line is to be as long as a half item rect */
3019 item.pszText = text;
3020 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
3023 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3025 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3028 memset(&bounds, 0, sizeof(bounds));
3029 bounds.left = LVIR_BOUNDS;
3030 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3031 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3032 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3033 r = SendMessage(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3036 ok(bounds.bottom - bounds.top == vert,
3037 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3038 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3041 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3043 /* outside columns by x position - valid is [0, 199] */
3045 y = pos.y + (bounds.bottom - bounds.top) / 2;
3046 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3047 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3049 x = pos.x + 50; /* column half width */
3050 y = pos.y + (bounds.bottom - bounds.top) / 2;
3051 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3052 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3053 x = pos.x + 150; /* outside column */
3054 y = pos.y + (bounds.bottom - bounds.top) / 2;
3055 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3056 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3057 y = (bounds.bottom - bounds.top) / 2;
3058 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3059 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3060 /* outside possible client rectangle (to right) */
3062 y = pos.y + (bounds.bottom - bounds.top) / 2;
3063 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3064 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3065 y = (bounds.bottom - bounds.top) / 2;
3066 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3067 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3068 /* subitem returned with -1 item too */
3070 y = bounds.top - vert;
3071 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3072 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3073 /* return values appear to underflow with negative indices */
3077 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3078 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3082 /* parent client area is 100x100 by default */
3083 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3084 x = pos.x + 150; /* outside column */
3085 y = pos.y + (bounds.bottom - bounds.top) / 2;
3086 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3087 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3088 y = (bounds.bottom - bounds.top) / 2;
3089 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3090 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3091 /* the same with LVS_EX_FULLROWSELECT */
3092 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3093 x = pos.x + 150; /* outside column */
3094 y = pos.y + (bounds.bottom - bounds.top) / 2;
3095 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3096 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3097 y = (bounds.bottom - bounds.top) / 2;
3098 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3099 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3100 x = pos.x + 150; /* outside column */
3101 y = pos.y + (bounds.bottom - bounds.top) / 2;
3102 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3103 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3104 y = (bounds.bottom - bounds.top) / 2;
3105 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3106 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3107 /* outside possible client rectangle (to right) */
3109 y = pos.y + (bounds.bottom - bounds.top) / 2;
3110 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3111 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3112 y = (bounds.bottom - bounds.top) / 2;
3113 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3114 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3115 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3116 himl = ImageList_Create(16, 16, 0, 4, 4);
3117 ok(himl != NULL, "failed to create imagelist\n");
3118 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3119 ok(hbmp != NULL, "failed to create bitmap\n");
3120 r = ImageList_Add(himl, hbmp, 0);
3121 ok(r == 0, "should be zero\n");
3122 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3123 ok(hbmp != NULL, "failed to create bitmap\n");
3124 r = ImageList_Add(himl, hbmp, 0);
3125 ok(r == 1, "should be one\n");
3127 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3128 ok(r == 0, "should return zero\n");
3130 item.mask = LVIF_IMAGE;
3134 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3138 y = pos.y + (bounds.bottom - bounds.top) / 2;
3139 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3140 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3141 y = (bounds.bottom - bounds.top) / 2;
3142 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3144 /* state icons indices are 1 based, check with valid index */
3145 item.mask = LVIF_STATE;
3146 item.state = INDEXTOSTATEIMAGEMASK(1);
3147 item.stateMask = LVIS_STATEIMAGEMASK;
3150 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3154 y = pos.y + (bounds.bottom - bounds.top) / 2;
3155 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3156 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3157 y = (bounds.bottom - bounds.top) / 2;
3158 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3160 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3161 ok(himl2 == himl, "should return handle\n");
3163 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3164 ok(r == 0, "should return zero\n");
3167 y = pos.y + (bounds.bottom - bounds.top) / 2;
3168 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3169 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3170 y = (bounds.bottom - bounds.top) / 2;
3171 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3173 DestroyWindow(hwnd);
3176 static void test_getviewrect(void)
3183 hwnd = create_listview_control(LVS_REPORT);
3184 ok(hwnd != NULL, "failed to create a listview window\n");
3187 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3190 insert_column(hwnd, 0);
3191 insert_column(hwnd, 1);
3193 memset(&item, 0, sizeof(item));
3196 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3198 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3200 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3203 rect.left = rect.right = rect.top = rect.bottom = -1;
3204 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3206 /* left is set to (2e31-1) - XP SP2 */
3207 expect(0, rect.right);
3208 expect(0, rect.top);
3209 expect(0, rect.bottom);
3211 /* switch to LVS_ICON */
3212 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3214 rect.left = rect.right = rect.top = rect.bottom = -1;
3215 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3217 expect(0, rect.left);
3218 expect(0, rect.top);
3219 /* precise value differs for 2k, XP and Vista */
3220 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3221 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3223 DestroyWindow(hwnd);
3226 static void test_getitemposition(void)
3233 hwnd = create_listview_control(LVS_REPORT);
3234 ok(hwnd != NULL, "failed to create a listview window\n");
3235 header = subclass_header(hwnd);
3237 /* LVS_REPORT, single item, no columns added */
3238 insert_item(hwnd, 0);
3240 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3243 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3245 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3247 /* LVS_REPORT, single item, single column */
3248 insert_column(hwnd, 0);
3250 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3253 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3255 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3257 memset(&rect, 0, sizeof(rect));
3258 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3261 /* offset by header height */
3262 expect(rect.bottom - rect.top, pt.y);
3264 DestroyWindow(hwnd);
3267 static void test_columnscreation(void)
3272 hwnd = create_listview_control(LVS_REPORT);
3273 ok(hwnd != NULL, "failed to create a listview window\n");
3275 insert_item(hwnd, 0);
3277 /* headers columns aren't created automatically */
3278 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3279 ok(IsWindow(header), "Expected header handle\n");
3280 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3283 DestroyWindow(hwnd);
3286 static void test_getitemrect(void)
3299 /* rectangle isn't empty for empty text items */
3300 hwnd = create_listview_control(LVS_LIST);
3301 memset(&item, 0, sizeof(item));
3304 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3306 rect.left = LVIR_LABEL;
3307 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3309 expect(0, rect.left);
3310 expect(0, rect.top);
3312 todo_wine expect(GetDeviceCaps(hdc, LOGPIXELSX), rect.right);
3313 ReleaseDC(hwnd, hdc);
3314 DestroyWindow(hwnd);
3316 hwnd = create_listview_control(LVS_REPORT);
3317 ok(hwnd != NULL, "failed to create a listview window\n");
3320 memset(&item, 0, sizeof(item));
3323 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3326 rect.left = LVIR_BOUNDS;
3327 rect.right = rect.top = rect.bottom = -1;
3328 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3331 /* zero width rectangle with no padding */
3332 expect(0, rect.left);
3333 expect(0, rect.right);
3335 insert_column(hwnd, 0);
3336 insert_column(hwnd, 1);
3338 col.mask = LVCF_WIDTH;
3340 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3343 col.mask = LVCF_WIDTH;
3345 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3348 rect.left = LVIR_BOUNDS;
3349 rect.right = rect.top = rect.bottom = -1;
3350 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3353 /* still no left padding */
3354 expect(0, rect.left);
3355 expect(150, rect.right);
3357 rect.left = LVIR_SELECTBOUNDS;
3358 rect.right = rect.top = rect.bottom = -1;
3359 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3362 expect(2, rect.left);
3364 rect.left = LVIR_LABEL;
3365 rect.right = rect.top = rect.bottom = -1;
3366 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3368 /* padding, column width */
3369 expect(2, rect.left);
3370 expect(50, rect.right);
3372 /* no icons attached */
3373 rect.left = LVIR_ICON;
3374 rect.right = rect.top = rect.bottom = -1;
3375 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3378 expect(2, rect.left);
3379 expect(2, rect.right);
3382 order[0] = 1; order[1] = 0;
3383 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3386 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3388 /* 1 indexed column width + padding */
3390 /* rect is at zero too */
3391 rect.left = LVIR_BOUNDS;
3392 rect.right = rect.top = rect.bottom = -1;
3393 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3395 expect(0, rect.left);
3396 /* just width sum */
3397 expect(150, rect.right);
3399 rect.left = LVIR_SELECTBOUNDS;
3400 rect.right = rect.top = rect.bottom = -1;
3401 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3403 /* column width + padding */
3404 expect(102, rect.left);
3406 /* back to initial order */
3407 order[0] = 0; order[1] = 1;
3408 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3412 himl = ImageList_Create(16, 16, 0, 2, 2);
3413 ok(himl != NULL, "failed to create imagelist\n");
3414 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3415 ok(hbm != NULL, "failed to create bitmap\n");
3416 r = ImageList_Add(himl, hbm, 0);
3417 ok(r == 0, "should be zero\n");
3418 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3419 ok(hbm != NULL, "failed to create bitmap\n");
3420 r = ImageList_Add(himl, hbm, 0);
3421 ok(r == 1, "should be one\n");
3423 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3424 ok(r == 0, "should return zero\n");
3426 item.mask = LVIF_STATE;
3427 item.state = INDEXTOSTATEIMAGEMASK(1);
3428 item.stateMask = LVIS_STATEIMAGEMASK;
3431 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3435 rect.left = LVIR_ICON;
3436 rect.right = rect.top = rect.bottom = -1;
3437 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3439 /* padding + stateicon width */
3440 expect(18, rect.left);
3441 expect(18, rect.right);
3443 rect.left = LVIR_LABEL;
3444 rect.right = rect.top = rect.bottom = -1;
3445 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3447 /* padding + stateicon width -> column width */
3448 expect(18, rect.left);
3449 expect(50, rect.right);
3451 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3452 ok(r != 0, "should return current list handle\n");
3454 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3455 ok(r == 0, "should return zero\n");
3457 item.mask = LVIF_STATE | LVIF_IMAGE;
3460 item.stateMask = ~0;
3463 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3467 rect.left = LVIR_ICON;
3468 rect.right = rect.top = rect.bottom = -1;
3469 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3471 /* padding, icon width */
3472 expect(2, rect.left);
3473 expect(18, rect.right);
3475 rect.left = LVIR_LABEL;
3476 rect.right = rect.top = rect.bottom = -1;
3477 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3479 /* padding + icon width -> column width */
3480 expect(18, rect.left);
3481 expect(50, rect.right);
3484 rect.left = LVIR_SELECTBOUNDS;
3485 rect.right = rect.top = rect.bottom = -1;
3486 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3488 /* padding, column width */
3489 expect(2, rect.left);
3490 expect(50, rect.right);
3492 /* try with indentation */
3493 item.mask = LVIF_INDENT;
3497 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3501 rect.left = LVIR_BOUNDS;
3502 rect.right = rect.top = rect.bottom = -1;
3503 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3505 /* padding + 1 icon width, column width */
3506 expect(0, rect.left);
3507 expect(150, rect.right);
3510 rect.left = LVIR_SELECTBOUNDS;
3511 rect.right = rect.top = rect.bottom = -1;
3512 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3514 /* padding + 1 icon width, column width */
3515 expect(2 + 16, rect.left);
3516 expect(50, rect.right);
3519 rect.left = LVIR_LABEL;
3520 rect.right = rect.top = rect.bottom = -1;
3521 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3523 /* padding + 2 icon widths, column width */
3524 expect(2 + 16*2, rect.left);
3525 expect(50, rect.right);
3528 rect.left = LVIR_ICON;
3529 rect.right = rect.top = rect.bottom = -1;
3530 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3532 /* padding + 1 icon width indentation, icon width */
3533 expect(2 + 16, rect.left);
3534 expect(34, rect.right);
3536 DestroyWindow(hwnd);
3539 static void test_editbox(void)
3541 static CHAR testitemA[] = "testitem";
3542 static CHAR testitem1A[] = "testitem_quitelongname";
3543 static CHAR buffer[25];
3544 HWND hwnd, hwndedit, hwndedit2, header;
3548 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3549 ok(hwnd != NULL, "failed to create a listview window\n");
3551 insert_column(hwnd, 0);
3553 memset(&item, 0, sizeof(item));
3554 item.mask = LVIF_TEXT;
3555 item.pszText = testitemA;
3558 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3561 /* test notifications without edit created */
3562 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3563 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
3565 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3566 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
3567 /* same thing but with valid window */
3568 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
3569 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
3570 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3571 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
3573 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3574 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
3575 DestroyWindow(hwndedit);
3577 /* setting focus is necessary */
3579 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3580 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3582 /* test children Z-order after Edit box created */
3583 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3584 ok(IsWindow(header), "Expected header to be created\n");
3585 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3586 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3588 /* modify initial string */
3589 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3592 /* edit window is resized and repositioned,
3593 check again for Z-order - it should be preserved */
3594 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3595 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3597 /* return focus to listview */
3600 memset(&item, 0, sizeof(item));
3601 item.mask = LVIF_TEXT;
3602 item.pszText = buffer;
3603 item.cchTextMax = sizeof(buffer);
3606 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3609 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3611 /* send LVM_EDITLABEL on already created edit */
3613 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3614 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3615 /* focus will be set to edit */
3616 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3617 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3618 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3620 /* creating label disabled when control isn't focused */
3622 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3623 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3625 /* check EN_KILLFOCUS handling */
3626 memset(&item, 0, sizeof(item));
3627 item.pszText = testitemA;
3630 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3634 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3635 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3636 /* modify edit and notify control that it lost focus */
3637 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3639 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3641 memset(&item, 0, sizeof(item));
3642 item.pszText = buffer;
3643 item.cchTextMax = sizeof(buffer);
3646 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3647 expect(lstrlen(item.pszText), r);
3648 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3649 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
3650 /* end edit without saving */
3652 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3653 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3654 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3656 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3657 "edit box - end edit, no change, escape", TRUE);
3658 /* end edit with saving */
3660 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3661 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3662 r = SendMessage(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
3664 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3665 "edit box - end edit, no change, return", TRUE);
3667 memset(&item, 0, sizeof(item));
3668 item.pszText = buffer;
3669 item.cchTextMax = sizeof(buffer);
3672 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3673 expect(lstrlen(item.pszText), r);
3674 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3676 /* LVM_EDITLABEL with -1 destroys current edit */
3677 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3678 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3679 /* no edit present */
3680 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3681 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3682 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3683 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3685 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3686 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3687 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3688 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3689 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3690 /* check another negative value */
3691 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3692 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3693 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3694 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3695 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3696 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3697 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3698 /* and value greater than max item index */
3699 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3700 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3701 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3702 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3703 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3704 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3705 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3706 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3708 /* messaging tests */
3710 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3712 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3713 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3714 /* testing only sizing messages */
3715 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3716 "edit box create - sizing", FALSE);
3718 /* WM_COMMAND with EN_KILLFOCUS isn't forwared to parent */
3720 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3721 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3722 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3723 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3725 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3726 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
3728 DestroyWindow(hwnd);
3731 static void test_notifyformat(void)
3736 hwnd = create_listview_control(LVS_REPORT);
3737 ok(hwnd != NULL, "failed to create a listview window\n");
3739 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3740 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3741 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3743 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3745 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3747 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3750 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3752 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3757 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3758 DestroyWindow(hwnd);
3762 DestroyWindow(hwnd);
3764 /* test failure in parent WM_NOTIFYFORMAT */
3766 hwnd = create_listview_control(LVS_REPORT);
3767 ok(hwnd != NULL, "failed to create a listview window\n");
3768 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3769 ok(IsWindow(header), "expected header to be created\n");
3770 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3772 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3773 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3774 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3775 ok(r != 0, "Expected valid format\n");
3777 notifyFormat = NFR_UNICODE;
3778 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3779 expect(NFR_UNICODE, r);
3780 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3782 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3783 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3785 notifyFormat = NFR_ANSI;
3786 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3787 expect(NFR_ANSI, r);
3788 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3790 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3791 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3793 DestroyWindow(hwnd);
3795 /* try different unicode window combination and defaults */
3796 if (!GetModuleHandleW(NULL))
3798 win_skip("Additional notify format tests are incompatible with Win9x\n");
3802 hwndparentW = create_parent_window(TRUE);
3803 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3804 if (!IsWindow(hwndparentW)) return;
3807 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3808 ok(hwnd != NULL, "failed to create a listview window\n");
3809 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3810 ok(IsWindow(header), "expected header to be created\n");
3811 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3813 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3815 DestroyWindow(hwnd);
3816 /* receiving error code defaulting to ansi */
3818 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3819 ok(hwnd != NULL, "failed to create a listview window\n");
3820 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3821 ok(IsWindow(header), "expected header to be created\n");
3822 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3824 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3826 DestroyWindow(hwnd);
3827 /* receiving ansi code from unicode window, use it */
3828 notifyFormat = NFR_ANSI;
3829 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3830 ok(hwnd != NULL, "failed to create a listview window\n");
3831 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3832 ok(IsWindow(header), "expected header to be created\n");
3833 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3835 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3837 DestroyWindow(hwnd);
3838 /* unicode listview with ansi parent window */
3840 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3841 ok(hwnd != NULL, "failed to create a listview window\n");
3842 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3843 ok(IsWindow(header), "expected header to be created\n");
3844 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3846 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3848 DestroyWindow(hwnd);
3849 /* unicode listview with ansi parent window, return error code */
3851 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3852 ok(hwnd != NULL, "failed to create a listview window\n");
3853 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3854 ok(IsWindow(header), "expected header to be created\n");
3855 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3857 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3859 DestroyWindow(hwnd);
3861 DestroyWindow(hwndparentW);
3864 static void test_indentation(void)
3870 hwnd = create_listview_control(LVS_REPORT);
3871 ok(hwnd != NULL, "failed to create a listview window\n");
3873 memset(&item, 0, sizeof(item));
3874 item.mask = LVIF_INDENT;
3876 item.iIndent = I_INDENTCALLBACK;
3877 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3880 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3883 item.mask = LVIF_INDENT;
3884 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3887 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3888 "get indent dispinfo", FALSE);
3890 DestroyWindow(hwnd);
3893 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
3898 static BOOL is_below_comctl_5(void)
3903 hwnd = create_listview_control(LVS_REPORT);
3904 ok(hwnd != NULL, "failed to create a listview window\n");
3905 insert_item(hwnd, 0);
3907 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
3909 DestroyWindow(hwnd);
3914 static void test_get_set_view(void)
3920 /* test style->view mapping */
3921 hwnd = create_listview_control(LVS_REPORT);
3922 ok(hwnd != NULL, "failed to create a listview window\n");
3924 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3925 expect(LV_VIEW_DETAILS, ret);
3927 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3929 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
3930 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3931 expect(LV_VIEW_ICON, ret);
3933 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3934 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
3935 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3936 expect(LV_VIEW_SMALLICON, ret);
3938 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3939 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
3940 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3941 expect(LV_VIEW_LIST, ret);
3943 /* switching view doesn't touch window style */
3944 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
3946 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3947 ok(style & LVS_LIST, "Expected style to be preserved\n");
3948 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
3950 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3951 ok(style & LVS_LIST, "Expected style to be preserved\n");
3952 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
3954 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3955 ok(style & LVS_LIST, "Expected style to be preserved\n");
3957 DestroyWindow(hwnd);
3960 static void test_canceleditlabel(void)
3962 HWND hwnd, hwndedit;
3966 static CHAR test[] = "test";
3967 static const CHAR test1[] = "test1";
3969 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3970 ok(hwnd != NULL, "failed to create a listview window\n");
3972 insert_item(hwnd, 0);
3974 /* try without edit created */
3975 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3976 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3978 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3979 "cancel edit label without edit", FALSE);
3981 /* cancel without data change */
3983 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3984 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3985 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3987 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3989 /* cancel after data change */
3990 memset(&itema, 0, sizeof(itema));
3991 itema.pszText = test;
3992 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
3995 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3996 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3997 ret = SetWindowText(hwndedit, test1);
3998 ok(ret != 0, "Expected edit text to change\n");
3999 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4001 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4002 memset(&itema, 0, sizeof(itema));
4003 itema.pszText = buff;
4004 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4005 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
4007 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4009 DestroyWindow(hwnd);
4012 static void test_mapidindex(void)
4017 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4018 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4019 ok(hwnd != NULL, "failed to create a listview window\n");
4020 insert_item(hwnd, 0);
4021 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4023 DestroyWindow(hwnd);
4025 hwnd = create_listview_control(LVS_REPORT);
4026 ok(hwnd != NULL, "failed to create a listview window\n");
4028 /* LVM_MAPINDEXTOID with invalid index */
4029 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4032 insert_item(hwnd, 0);
4033 insert_item(hwnd, 1);
4035 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
4037 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
4040 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4042 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4044 /* remove 0 indexed item, id retained */
4045 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
4046 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4048 /* new id starts from previous value */
4049 insert_item(hwnd, 1);
4050 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4053 /* get index by id */
4054 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4056 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4058 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4060 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4063 DestroyWindow(hwnd);
4066 static void test_getitemspacing(void)
4075 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4076 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4079 hwnd = create_listview_control(LVS_ICON);
4080 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4082 expect(cx, LOWORD(ret));
4083 expect(cy, HIWORD(ret));
4085 /* now try with icons */
4086 himl = ImageList_Create(40, 40, 0, 4, 4);
4087 ok(himl != NULL, "failed to create imagelist\n");
4088 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4089 ok(hbmp != NULL, "failed to create bitmap\n");
4090 ret = ImageList_Add(himl, hbmp, 0);
4092 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4095 itema.mask = LVIF_IMAGE;
4099 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4101 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4103 /* spacing + icon size returned */
4104 expect(cx + 40, LOWORD(ret));
4105 expect(cy + 40, HIWORD(ret));
4107 DestroyWindow(hwnd);
4109 hwnd = create_listview_control(LVS_SMALLICON);
4110 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4112 expect(cx, LOWORD(ret));
4113 expect(cy, HIWORD(ret));
4115 DestroyWindow(hwnd);
4117 hwnd = create_listview_control(LVS_REPORT);
4118 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4120 expect(cx, LOWORD(ret));
4121 expect(cy, HIWORD(ret));
4123 DestroyWindow(hwnd);
4125 hwnd = create_listview_control(LVS_LIST);
4126 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4128 expect(cx, LOWORD(ret));
4129 expect(cy, HIWORD(ret));
4131 DestroyWindow(hwnd);
4134 static void test_getcolumnwidth(void)
4143 /* default column width */
4144 hwnd = create_listview_control(LVS_ICON);
4145 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4147 style = GetWindowLong(hwnd, GWL_STYLE);
4148 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
4149 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4150 todo_wine expect(8, ret);
4151 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
4152 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
4154 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4156 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4158 DestroyWindow(hwnd);
4160 /* default column width with item added */
4161 hwnd = create_listview_control(LVS_LIST);
4162 memset(&itema, 0, sizeof(itema));
4163 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4164 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4166 todo_wine expect(GetDeviceCaps(hdc, LOGPIXELSX), ret);
4167 ReleaseDC(hwnd, hdc);
4168 DestroyWindow(hwnd);
4171 static void test_scrollnotify(void)
4176 hwnd = create_listview_control(LVS_REPORT);
4178 insert_column(hwnd, 0);
4179 insert_column(hwnd, 1);
4180 insert_item(hwnd, 0);
4182 /* make it scrollable - resize */
4183 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4185 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4188 /* try with dummy call */
4189 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4190 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
4192 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4193 "scroll notify 1", TRUE);
4195 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4196 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
4198 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4199 "scroll notify 2", TRUE);
4201 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4202 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4204 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4205 "scroll notify 3", TRUE);
4207 DestroyWindow(hwnd);
4210 static void test_LVS_EX_TRANSPARENTBKGND(void)
4216 hwnd = create_listview_control(LVS_REPORT);
4218 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4221 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4222 LVS_EX_TRANSPARENTBKGND);
4224 ret = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
4225 if (ret != CLR_NONE)
4227 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4228 DestroyWindow(hwnd);
4232 /* try to set some back color and check this style bit */
4233 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4235 ret = SendMessage(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4236 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4238 /* now test what this style actually does */
4239 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4240 LVS_EX_TRANSPARENTBKGND);
4242 hdc = GetWindowDC(hwndparent);
4244 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4245 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4246 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4247 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4249 ReleaseDC(hwndparent, hdc);
4251 DestroyWindow(hwnd);
4254 static void test_approximate_viewrect(void)
4261 static CHAR test[] = "abracadabra, a very long item label";
4263 hwnd = create_listview_control(LVS_ICON);
4264 himl = ImageList_Create(40, 40, 0, 4, 4);
4265 ok(himl != NULL, "failed to create imagelist\n");
4266 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4267 ok(hbmp != NULL, "failed to create bitmap\n");
4268 ret = ImageList_Add(himl, hbmp, 0);
4270 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4273 itema.mask = LVIF_IMAGE;
4277 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4280 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4284 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4288 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4289 ok(MAKELONG(77,827)==ret,"Incorrect Approximate rect\n");
4291 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4292 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4293 ok(MAKELONG(102,302)==ret,"Incorrect Approximate rect\n");
4295 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4296 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4298 itema.pszText = test;
4299 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4301 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4302 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4304 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4305 ok(MAKELONG(52,2)==ret,"Incorrect Approximate rect\n");
4306 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4307 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4308 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4309 ok(MAKELONG(102,52)==ret,"Incorrect Approximate rect\n");
4310 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4311 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4312 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4313 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4314 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4315 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4316 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4317 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4318 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4319 ok(MAKELONG(152,152)==ret,"Incorrect Approximate rect\n");
4321 DestroyWindow(hwnd);
4324 static void test_finditem(void)
4331 hwnd = create_listview_control(LVS_REPORT);
4332 insert_item(hwnd, 0);
4334 memset(&fi, 0, sizeof(fi));
4336 /* full string search, inserted text was "foo" */
4338 fi.flags = LVFI_STRING;
4340 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4342 /* partial string search, inserted text was "foo" */
4344 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4346 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4348 /* partial string search, part after start char */
4350 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4352 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4355 /* try with LVFI_SUBSTRING */
4357 fi.flags = LVFI_SUBSTRING;
4359 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4362 win_skip("LVFI_SUBSTRING not supported\n");
4363 DestroyWindow(hwnd);
4368 fi.flags = LVFI_SUBSTRING;
4370 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4373 fi.flags = LVFI_SUBSTRING;
4375 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4379 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
4381 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4384 DestroyWindow(hwnd);
4387 static void test_LVS_EX_HEADERINALLVIEWS(void)
4392 hwnd = create_listview_control(LVS_ICON);
4394 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4395 LVS_EX_HEADERINALLVIEWS);
4397 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4398 if (!IsWindow(header))
4400 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4401 DestroyWindow(hwnd);
4405 /* LVS_NOCOLUMNHEADER works as before */
4406 style = GetWindowLongA(hwnd, GWL_STYLE);
4407 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
4408 style = GetWindowLongA(header, GWL_STYLE);
4409 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
4410 style = GetWindowLongA(hwnd, GWL_STYLE);
4411 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
4412 style = GetWindowLongA(header, GWL_STYLE);
4413 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
4415 /* try to remove style */
4416 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
4417 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4418 ok(IsWindow(header), "Expected header to be created\n");
4419 style = GetWindowLongA(header, GWL_STYLE);
4420 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
4422 DestroyWindow(hwnd);
4424 /* check other styles */
4425 hwnd = create_listview_control(LVS_LIST);
4426 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4427 LVS_EX_HEADERINALLVIEWS);
4428 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4429 ok(IsWindow(header), "Expected header to be created\n");
4430 DestroyWindow(hwnd);
4432 hwnd = create_listview_control(LVS_SMALLICON);
4433 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4434 LVS_EX_HEADERINALLVIEWS);
4435 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4436 ok(IsWindow(header), "Expected header to be created\n");
4437 DestroyWindow(hwnd);
4439 hwnd = create_listview_control(LVS_REPORT);
4440 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4441 LVS_EX_HEADERINALLVIEWS);
4442 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4443 ok(IsWindow(header), "Expected header to be created\n");
4444 DestroyWindow(hwnd);
4447 static void test_hover(void)
4452 hwnd = create_listview_control(LVS_ICON);
4454 /* test WM_MOUSEHOVER forwarding */
4455 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4456 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4458 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
4459 g_block_hover = TRUE;
4460 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4461 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4463 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
4464 g_block_hover = FALSE;
4466 r = SendMessage(hwnd, LVM_SETHOVERTIME, 0, 500);
4467 expect(HOVER_DEFAULT, r);
4468 r = SendMessage(hwnd, LVM_GETHOVERTIME, 0, 0);
4471 DestroyWindow(hwnd);
4474 static void test_destroynotify(void)
4478 hwnd = create_listview_control(LVS_REPORT);
4479 ok(hwnd != NULL, "failed to create listview window\n");
4481 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4482 DestroyWindow(hwnd);
4483 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
4486 static void test_header_notification(void)
4494 list = create_listview_control(LVS_REPORT);
4495 ok(list != 0, "failed to create listview window\n");
4497 memset(&col, 0, sizeof(col));
4498 col.mask = LVCF_WIDTH;
4500 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4501 ok(!ret, "expected 0, got %ld\n", ret);
4503 header = subclass_header(list);
4505 ret = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
4506 ok(ret == 1, "expected header item count 1, got %ld\n", ret);
4508 memset(&item, 0, sizeof(item));
4509 item.mask = HDI_WIDTH;
4510 ret = SendMessage(header, HDM_GETITEMA, 0, (LPARAM)&item);
4511 ok(ret, "HDM_GETITEM failed\n");
4512 ok(item.cxy == 100, "expected 100, got %d\n", item.cxy);
4514 nmh.hdr.hwndFrom = header;
4515 nmh.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
4516 nmh.hdr.code = HDN_ITEMCHANGEDA;
4519 item.mask = HDI_WIDTH;
4522 ret = SendMessage(list, WM_NOTIFY, 0, (LPARAM)&nmh);
4523 ok(!ret, "WM_NOTIFY/HDN_ITEMCHANGED failed\n");
4525 DestroyWindow(list);
4528 static void test_createdragimage(void)
4534 list = create_listview_control(LVS_ICON);
4535 ok(list != 0, "failed to create listview window\n");
4537 insert_item(list, 0);
4540 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
4541 ok(himl == NULL, "got %p\n", himl);
4543 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
4544 ok(himl != NULL, "got %p\n", himl);
4545 ImageList_Destroy(himl);
4547 DestroyWindow(list);
4550 static void test_dispinfo(void)
4552 static const char testA[] = "TEST";
4558 hwnd = create_listview_control(LVS_ICON);
4559 ok(hwnd != 0, "failed to create listview window\n");
4561 insert_item(hwnd, 0);
4563 memset(&item, 0, sizeof(item));
4564 item.pszText = LPSTR_TEXTCALLBACKA;
4565 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4566 ok(ret, "got %d\n", ret);
4568 g_disp_A_to_W = TRUE;
4569 item.pszText = (char*)buff;
4570 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
4571 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4572 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
4573 g_disp_A_to_W = FALSE;
4575 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
4576 "got %s, expected %s\n", item.pszText, testA);
4578 DestroyWindow(hwnd);
4581 START_TEST(listview)
4584 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
4586 ULONG_PTR ctx_cookie;
4590 hComctl32 = GetModuleHandleA("comctl32.dll");
4591 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
4592 if (pInitCommonControlsEx)
4594 INITCOMMONCONTROLSEX iccex;
4595 iccex.dwSize = sizeof(iccex);
4596 iccex.dwICC = ICC_LISTVIEW_CLASSES;
4597 pInitCommonControlsEx(&iccex);
4600 InitCommonControls();
4602 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
4604 hwndparent = create_parent_window(FALSE);
4605 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4607 g_is_below_5 = is_below_comctl_5();
4609 test_header_notification();
4616 test_icon_spacing();
4619 test_item_position();
4624 test_subitem_rect();
4628 test_nosortheader();
4632 test_getitemposition();
4633 test_columnscreation();
4635 test_notifyformat();
4637 test_getitemspacing();
4638 test_getcolumnwidth();
4639 test_approximate_viewrect();
4642 test_destroynotify();
4643 test_createdragimage();
4646 if (!load_v6_module(&ctx_cookie, &hCtx))
4648 DestroyWindow(hwndparent);
4652 /* this is a XP SP3 failure workaround */
4653 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
4654 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
4656 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
4657 if (!IsWindow(hwnd))
4659 win_skip("FIXME: failed to create ListView window.\n");
4660 unload_v6_module(ctx_cookie, hCtx);
4661 DestroyWindow(hwndparent);
4665 DestroyWindow(hwnd);
4667 /* comctl32 version 6 tests start here */
4668 test_get_set_view();
4669 test_canceleditlabel();
4671 test_scrollnotify();
4672 test_LVS_EX_TRANSPARENTBKGND();
4673 test_LVS_EX_HEADERINALLVIEWS();
4675 unload_v6_module(ctx_cookie, hCtx);
4677 DestroyWindow(hwndparent);