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:
346 /* subclass edit box */
348 edit = subclass_editbox(((NMHDR*)lParam)->hwndFrom);
352 INT len = SendMessageA(edit, EM_GETLIMITTEXT, 0, 0);
353 ok(len == 259 || broken(len == 260) /* includes NULL in NT4 */,
354 "text limit %d, expected 259\n", len);
359 case LVN_ENDLABELEDIT:
361 /* always accept new item text */
362 NMLVDISPINFO *di = (NMLVDISPINFO*)lParam;
363 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText);
366 case LVN_BEGINSCROLL:
369 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
371 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
372 "BEGIN" : "END", pScroll->dx, pScroll->dy);
375 case LVN_ITEMCHANGED:
376 if (g_dump_itemchanged)
378 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
379 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
380 nmlv->iItem, nmlv->uNewState, nmlv->uOldState, nmlv->uChanged);
383 case LVN_GETDISPINFOA:
385 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
386 g_itema = dispinfo->item;
388 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
390 static const WCHAR testW[] = {'T','E','S','T',0};
391 dispinfo->hdr.code = LVN_GETDISPINFOW;
392 memcpy(dispinfo->item.pszText, testW, sizeof(testW));
395 /* test control buffer size for text, 10 used to mask cases when control
396 is using caller buffer to process LVM_GETITEM for example */
397 if (dispinfo->item.mask & LVIF_TEXT && dispinfo->item.cchTextMax > 10)
398 ok(dispinfo->item.cchTextMax == 260 ||
399 broken(dispinfo->item.cchTextMax == 264) /* NT4 reports aligned size */,
400 "buffer size %d\n", dispinfo->item.cchTextMax);
404 if (g_block_hover) return 1;
409 case WM_NOTIFYFORMAT:
411 /* force to return format */
412 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
417 defwndproc_counter++;
418 ret = DefWindowProcA(hwnd, message, wParam, lParam);
419 defwndproc_counter--;
424 static BOOL register_parent_wnd_class(BOOL Unicode)
432 clsW.lpfnWndProc = parent_wnd_proc;
435 clsW.hInstance = GetModuleHandleW(NULL);
437 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
438 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
439 clsW.lpszMenuName = NULL;
440 clsW.lpszClassName = testparentclassW;
445 clsA.lpfnWndProc = parent_wnd_proc;
448 clsA.hInstance = GetModuleHandleA(NULL);
450 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
451 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
452 clsA.lpszMenuName = NULL;
453 clsA.lpszClassName = "Listview test parent class";
456 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
459 static HWND create_parent_window(BOOL Unicode)
461 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
464 if (!register_parent_wnd_class(Unicode))
471 hwnd = CreateWindowExW(0, testparentclassW, nameW,
472 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
473 WS_MAXIMIZEBOX | WS_VISIBLE,
475 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
477 hwnd = CreateWindowExA(0, "Listview test parent class",
478 "Listview test parent window",
479 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
480 WS_MAXIMIZEBOX | WS_VISIBLE,
482 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
483 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
487 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
489 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
490 static LONG defwndproc_counter = 0;
494 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
496 /* some debug output for style changing */
497 if ((message == WM_STYLECHANGING ||
498 message == WM_STYLECHANGED) && lParam)
500 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
501 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
504 msg.message = message;
505 msg.flags = sent|wparam|lparam;
506 if (defwndproc_counter) msg.flags |= defwinproc;
509 msg.id = LISTVIEW_ID;
510 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
511 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
513 defwndproc_counter++;
514 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
515 defwndproc_counter--;
519 static HWND create_listview_control(DWORD style)
525 GetClientRect(hwndparent, &rect);
526 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
527 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
528 0, 0, rect.right, rect.bottom,
529 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
530 ok(hwnd != NULL, "gle=%d\n", GetLastError());
532 if (!hwnd) return NULL;
534 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
535 (LONG_PTR)listview_subclass_proc);
536 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
541 /* unicode listview window with specified parent */
542 static HWND create_listview_controlW(DWORD style, HWND parent)
547 static const WCHAR nameW[] = {'f','o','o',0};
549 GetClientRect(parent, &rect);
550 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
551 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
552 0, 0, rect.right, rect.bottom,
553 parent, NULL, GetModuleHandleW(NULL), NULL);
554 ok(hwnd != NULL, "gle=%d\n", GetLastError());
556 if (!hwnd) return NULL;
558 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
559 (LONG_PTR)listview_subclass_proc);
560 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
565 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
567 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
568 static LONG defwndproc_counter = 0;
572 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
574 msg.message = message;
575 msg.flags = sent|wparam|lparam;
576 if (defwndproc_counter) msg.flags |= defwinproc;
580 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
582 defwndproc_counter++;
583 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
584 defwndproc_counter--;
588 static HWND subclass_header(HWND hwndListview)
593 hwnd = ListView_GetHeader(hwndListview);
594 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
595 (LONG_PTR)header_subclass_proc);
596 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
601 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
603 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
604 static LONG defwndproc_counter = 0;
608 msg.message = message;
609 msg.flags = sent|wparam|lparam;
610 if (defwndproc_counter) msg.flags |= defwinproc;
614 /* all we need is sizing */
615 if (message == WM_WINDOWPOSCHANGING ||
616 message == WM_NCCALCSIZE ||
617 message == WM_WINDOWPOSCHANGED ||
618 message == WM_MOVE ||
621 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
624 defwndproc_counter++;
625 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
626 defwndproc_counter--;
630 static HWND subclass_editbox(HWND hwndListview)
635 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
636 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
637 (LONG_PTR)editbox_subclass_proc);
638 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
643 /* Performs a single LVM_HITTEST test */
644 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
645 BOOL todo_item, BOOL todo_flags, int line)
654 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
660 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
661 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
662 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
667 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
668 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
669 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
675 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
677 else if (broken_flags)
678 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
679 "Expected flags %x, got %x\n", flags, lpht.flags);
681 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
684 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
686 /* Performs a single LVM_SUBITEMHITTEST test */
687 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
688 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
696 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
702 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
703 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
708 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
709 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
715 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
718 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
723 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
726 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
729 #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__)
731 static void test_images(void)
739 static CHAR hello[] = "hello";
741 himl = ImageList_Create(40, 40, 0, 4, 4);
742 ok(himl != NULL, "failed to create imagelist\n");
744 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
745 ok(hbmp != NULL, "failed to create bitmap\n");
747 r = ImageList_Add(himl, hbmp, 0);
748 ok(r == 0, "should be zero\n");
750 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
751 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
752 ok(hwnd != NULL, "failed to create listview window\n");
754 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
755 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
757 ok(r == 0, "should return zero\n");
759 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
760 ok(r == 0, "should return zero\n");
762 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
763 /* returns dimensions */
765 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
766 ok(r == 0, "should be zero items\n");
768 item.mask = LVIF_IMAGE | LVIF_TEXT;
773 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
774 ok(r == -1, "should fail\n");
777 item.pszText = hello;
778 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
779 ok(r == 0, "should not fail\n");
781 memset(&r1, 0, sizeof r1);
783 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
786 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
787 ok(r == TRUE, "should not fail\n");
790 item.pszText = hello;
791 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
792 ok(r == 0, "should not fail\n");
794 memset(&r2, 0, sizeof r2);
796 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
799 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
804 static void test_checkboxes(void)
809 static CHAR text[] = "Text",
813 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
814 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
815 ok(hwnd != NULL, "failed to create listview window\n");
817 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
818 item.mask = LVIF_TEXT | LVIF_STATE;
819 item.stateMask = 0xffff;
824 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
825 ok(r == 0, "ret %d\n", r);
828 item.mask = LVIF_STATE;
829 item.stateMask = 0xffff;
830 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
832 ok(item.state == 0xfccc, "state %x\n", item.state);
834 /* Don't set LVIF_STATE */
835 item.mask = LVIF_TEXT;
836 item.stateMask = 0xffff;
841 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
842 ok(r == 1, "ret %d\n", r);
845 item.mask = LVIF_STATE;
846 item.stateMask = 0xffff;
847 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
849 ok(item.state == 0, "state %x\n", item.state);
851 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
852 ok(r == 0, "should return zero\n");
854 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
856 item.mask = LVIF_STATE;
857 item.stateMask = 0xffff;
858 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
860 if (item.state != 0x1ccc)
862 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
867 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
869 item.mask = LVIF_TEXT;
871 item.pszText = text2;
872 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
873 ok(r == 2, "ret %d\n", r);
876 item.mask = LVIF_STATE;
877 item.stateMask = 0xffff;
878 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
880 ok(item.state == 0x1000, "state %x\n", item.state);
882 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
884 item.mask = LVIF_TEXT | LVIF_STATE;
885 item.stateMask = 0xffff;
887 item.pszText = text3;
888 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
889 ok(r == 3, "ret %d\n", r);
892 item.mask = LVIF_STATE;
893 item.stateMask = 0xffff;
894 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
896 ok(item.state == 0x1aaa, "state %x\n", item.state);
898 /* Set an item's state to checked */
900 item.mask = LVIF_STATE;
901 item.stateMask = 0xf000;
903 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
907 item.mask = LVIF_STATE;
908 item.stateMask = 0xffff;
909 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
911 ok(item.state == 0x2aaa, "state %x\n", item.state);
913 /* Check that only the bits we asked for are returned,
914 * and that all the others are set to zero
917 item.mask = LVIF_STATE;
918 item.stateMask = 0xf000;
920 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
922 ok(item.state == 0x2000, "state %x\n", item.state);
924 /* Set the style again and check that doesn't change an item's state */
925 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
926 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
929 item.mask = LVIF_STATE;
930 item.stateMask = 0xffff;
931 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
933 ok(item.state == 0x2aaa, "state %x\n", item.state);
935 /* Unsetting the checkbox extended style doesn't change an item's state */
936 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
937 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
940 item.mask = LVIF_STATE;
941 item.stateMask = 0xffff;
942 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
944 ok(item.state == 0x2aaa, "state %x\n", item.state);
946 /* Now setting the style again will change an item's state */
947 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
948 ok(r == 0, "ret %x\n", r);
951 item.mask = LVIF_STATE;
952 item.stateMask = 0xffff;
953 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
955 ok(item.state == 0x1aaa, "state %x\n", item.state);
957 /* Toggle checkbox tests (bug 9934) */
958 memset (&item, 0xcc, sizeof(item));
959 item.mask = LVIF_STATE;
962 item.state = LVIS_FOCUSED;
963 item.stateMask = LVIS_FOCUSED;
964 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
968 item.mask = LVIF_STATE;
969 item.stateMask = 0xffff;
970 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
972 ok(item.state == 0x1aab, "state %x\n", item.state);
974 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
976 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
980 item.mask = LVIF_STATE;
981 item.stateMask = 0xffff;
982 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
984 ok(item.state == 0x2aab, "state %x\n", item.state);
986 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
988 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
992 item.mask = LVIF_STATE;
993 item.stateMask = 0xffff;
994 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
995 ok(item.state == 0x1aab, "state %x\n", item.state);
1000 static void insert_column(HWND hwnd, int idx)
1005 memset(&column, 0xcc, sizeof(column));
1006 column.mask = LVCF_SUBITEM;
1007 column.iSubItem = idx;
1009 rc = ListView_InsertColumn(hwnd, idx, &column);
1013 static void insert_item(HWND hwnd, int idx)
1015 static CHAR text[] = "foo";
1020 memset(&item, 0xcc, sizeof (item));
1021 item.mask = LVIF_TEXT;
1024 item.pszText = text;
1026 rc = ListView_InsertItem(hwnd, &item);
1030 static void test_items(void)
1032 const LPARAM lparamTest = 0x42;
1036 static CHAR text[] = "Text";
1038 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1039 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1040 ok(hwnd != NULL, "failed to create listview window\n");
1043 * Test setting/getting item params
1046 /* Set up two columns */
1047 insert_column(hwnd, 0);
1048 insert_column(hwnd, 1);
1050 /* LVIS_SELECTED with zero stateMask */
1052 memset (&item, 0, sizeof (item));
1053 item.mask = LVIF_STATE;
1054 item.state = LVIS_SELECTED;
1058 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1059 ok(r == 0, "ret %d\n", r);
1061 memset (&item, 0xcc, sizeof (item));
1062 item.mask = LVIF_STATE;
1063 item.stateMask = LVIS_SELECTED;
1067 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1068 ok(r != 0, "ret %d\n", r);
1069 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1070 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1072 /* LVIS_SELECTED with zero stateMask */
1074 memset (&item, 0, sizeof (item));
1075 item.mask = LVIF_STATE;
1076 item.state = LVIS_FOCUSED;
1080 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1081 ok(r == 0, "ret %d\n", r);
1083 memset (&item, 0xcc, sizeof (item));
1084 item.mask = LVIF_STATE;
1085 item.stateMask = LVIS_FOCUSED;
1089 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1090 ok(r != 0, "ret %d\n", r);
1091 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1092 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1094 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1096 memset (&item, 0, sizeof (item));
1097 item.mask = LVIF_STATE;
1098 item.state = LVIS_CUT;
1099 item.stateMask = LVIS_FOCUSED;
1102 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1103 ok(r == 0, "ret %d\n", r);
1105 memset (&item, 0xcc, sizeof (item));
1106 item.mask = LVIF_STATE;
1107 item.stateMask = LVIS_CUT;
1111 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1112 ok(r != 0, "ret %d\n", r);
1113 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1114 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1116 /* Insert an item with just a param */
1117 memset (&item, 0xcc, sizeof (item));
1118 item.mask = LVIF_PARAM;
1121 item.lParam = lparamTest;
1122 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1123 ok(r == 0, "ret %d\n", r);
1125 /* Test getting of the param */
1126 memset (&item, 0xcc, sizeof (item));
1127 item.mask = LVIF_PARAM;
1130 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1131 ok(r != 0, "ret %d\n", r);
1132 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1134 /* Set up a subitem */
1135 memset (&item, 0xcc, sizeof (item));
1136 item.mask = LVIF_TEXT;
1139 item.pszText = text;
1140 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1141 ok(r != 0, "ret %d\n", r);
1143 /* Query param from subitem: returns main item param */
1144 memset (&item, 0xcc, sizeof (item));
1145 item.mask = LVIF_PARAM;
1148 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1149 ok(r != 0, "ret %d\n", r);
1150 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1152 /* Set up param on first subitem: no effect */
1153 memset (&item, 0xcc, sizeof (item));
1154 item.mask = LVIF_PARAM;
1157 item.lParam = lparamTest+1;
1158 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1159 ok(r == 0, "ret %d\n", r);
1161 /* Query param from subitem again: should still return main item param */
1162 memset (&item, 0xcc, sizeof (item));
1163 item.mask = LVIF_PARAM;
1166 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1167 ok(r != 0, "ret %d\n", r);
1168 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1170 /**** Some tests of state highlighting ****/
1171 memset (&item, 0xcc, sizeof (item));
1172 item.mask = LVIF_STATE;
1175 item.state = LVIS_SELECTED;
1176 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1177 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1178 ok(r != 0, "ret %d\n", r);
1180 item.state = LVIS_DROPHILITED;
1181 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1182 ok(r != 0, "ret %d\n", r);
1184 memset (&item, 0xcc, sizeof (item));
1185 item.mask = LVIF_STATE;
1188 item.stateMask = -1;
1189 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1190 ok(r != 0, "ret %d\n", r);
1191 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1193 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1194 ok(r != 0, "ret %d\n", r);
1195 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1197 /* some notnull but meaningless masks */
1198 memset (&item, 0, sizeof(item));
1199 item.mask = LVIF_NORECOMPUTE;
1202 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1203 ok(r != 0, "ret %d\n", r);
1204 memset (&item, 0, sizeof(item));
1205 item.mask = LVIF_DI_SETITEM;
1208 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1209 ok(r != 0, "ret %d\n", r);
1211 /* set text to callback value already having it */
1212 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1214 memset (&item, 0, sizeof (item));
1215 item.mask = LVIF_TEXT;
1216 item.pszText = LPSTR_TEXTCALLBACK;
1218 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1219 ok(r == 0, "ret %d\n", r);
1220 memset (&item, 0, sizeof (item));
1222 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1224 item.pszText = LPSTR_TEXTCALLBACK;
1225 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1228 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1229 "check callback text comparison rule", FALSE);
1231 DestroyWindow(hwnd);
1234 static void test_columns(void)
1243 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1244 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1245 ok(hwnd != NULL, "failed to create listview window\n");
1247 /* Add a column with no mask */
1248 memset(&column, 0xcc, sizeof(column));
1250 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1251 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1253 /* Check its width */
1254 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1255 ok(rc == 10 || broken(rc == 0) /* win9x */,
1256 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1258 DestroyWindow(hwnd);
1260 /* LVM_GETCOLUMNORDERARRAY */
1261 hwnd = create_listview_control(LVS_REPORT);
1262 subclass_header(hwnd);
1264 memset(&column, 0, sizeof(column));
1265 column.mask = LVCF_WIDTH;
1267 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1268 ok(rc == 0, "Inserting column failed with %d\n", rc);
1271 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1272 ok(rc == 1, "Inserting column failed with %d\n", rc);
1274 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1276 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1277 ok(rc == 1, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1278 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1279 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1281 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1283 /* after column added subitem is considered as present */
1284 insert_item(hwnd, 0);
1286 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1288 item.pszText = buff;
1289 item.cchTextMax = sizeof(buff);
1292 item.mask = LVIF_TEXT;
1293 memset(&g_itema, 0, sizeof(g_itema));
1294 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1295 ok(rc == 1, "got %d\n", rc);
1296 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1298 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1299 "get subitem text after column added", FALSE);
1301 DestroyWindow(hwnd);
1304 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1305 static WNDPROC listviewWndProc;
1306 static HIMAGELIST test_create_imagelist;
1308 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1312 if (uMsg == WM_CREATE)
1314 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1315 lpcs->style |= LVS_REPORT;
1317 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1318 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1322 static void test_create(void)
1333 cls.cbSize = sizeof(WNDCLASSEX);
1334 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1335 listviewWndProc = cls.lpfnWndProc;
1336 cls.lpfnWndProc = create_test_wndproc;
1337 cls.lpszClassName = "MyListView32";
1338 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1340 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1341 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1342 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1343 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1345 if (!IsWindow(hHeader))
1348 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1349 DestroyWindow(hList);
1353 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1354 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1355 DestroyWindow(hList);
1357 /* header isn't created on LVS_ICON and LVS_LIST styles */
1358 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1359 GetModuleHandle(NULL), 0);
1360 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1361 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1362 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1364 memset(&col, 0, sizeof(LVCOLUMNA));
1365 col.mask = LVCF_WIDTH;
1367 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1368 ok(r == 0, "Expected 0 column's inserted\n");
1369 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1370 ok(IsWindow(hHeader), "Header should be created\n");
1371 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1372 style = GetWindowLong(hHeader, GWL_STYLE);
1373 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1374 DestroyWindow(hList);
1376 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1377 GetModuleHandle(NULL), 0);
1378 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1379 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1380 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1382 memset(&col, 0, sizeof(LVCOLUMNA));
1383 col.mask = LVCF_WIDTH;
1385 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1386 ok(r == 0, "Expected 0 column's inserted\n");
1387 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1388 ok(IsWindow(hHeader), "Header should be created\n");
1389 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1390 DestroyWindow(hList);
1392 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1393 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1394 GetModuleHandle(NULL), 0);
1395 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1396 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1397 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1398 ok(IsWindow(hHeader), "Header should be created\n");
1399 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1400 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1401 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1402 ok(IsWindow(hHeader), "Header should be created\n");
1403 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1404 DestroyWindow(hList);
1406 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1407 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1408 GetModuleHandle(NULL), 0);
1409 ret = SetWindowLongPtr(hList, GWL_STYLE,
1410 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1411 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1412 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1413 ok(IsWindow(hHeader), "Header should be created\n");
1414 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1415 ret = SetWindowLongPtr(hList, GWL_STYLE,
1416 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1417 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1418 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1419 ok(IsWindow(hHeader), "Header should be created\n");
1420 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1421 DestroyWindow(hList);
1423 /* LVS_REPORT without WS_VISIBLE */
1424 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1425 GetModuleHandle(NULL), 0);
1426 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1427 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1428 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1430 memset(&col, 0, sizeof(LVCOLUMNA));
1431 col.mask = LVCF_WIDTH;
1433 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1434 ok(r == 0, "Expected 0 column's inserted\n");
1435 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1436 ok(IsWindow(hHeader), "Header should be created\n");
1437 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1438 DestroyWindow(hList);
1440 /* LVS_REPORT without WS_VISIBLE, try to show it */
1441 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1442 GetModuleHandle(NULL), 0);
1443 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1444 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1445 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1446 ShowWindow(hList, SW_SHOW);
1447 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1448 ok(IsWindow(hHeader), "Header should be created\n");
1449 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1450 DestroyWindow(hList);
1452 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1453 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1454 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1455 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1456 ok(IsWindow(hHeader), "Header should be created\n");
1457 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1458 /* HDS_DRAGDROP set by default */
1459 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1460 DestroyWindow(hList);
1462 /* setting LVS_EX_HEADERDRAGDROP creates header */
1463 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1464 GetModuleHandle(NULL), 0);
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");
1468 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1469 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1470 ok(IsWindow(hHeader) ||
1471 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1472 "Header should be created\n");
1473 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1474 DestroyWindow(hList);
1476 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1477 hList = create_listview_control(LVS_ICON);
1478 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1479 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1480 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1481 DestroyWindow(hList);
1483 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1484 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1485 GetModuleHandle(NULL), 0);
1486 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1487 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1489 rect.left = LVIR_BOUNDS;
1491 rect.right = rect.bottom = -10;
1492 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1493 ok(r != 0, "Expected not-null LRESULT\n");
1495 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1496 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1497 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1499 DestroyWindow(hList);
1501 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1502 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1503 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1504 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1505 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1506 DestroyWindow(hList);
1509 static void test_redraw(void)
1516 hwnd = create_listview_control(LVS_REPORT);
1517 subclass_header(hwnd);
1519 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1521 InvalidateRect(hwnd, NULL, TRUE);
1523 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1525 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1527 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1528 /* 1. Without backbuffer */
1529 res = ListView_SetBkColor(hwnd, CLR_NONE);
1532 hdc = GetWindowDC(hwndparent);
1534 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1535 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1536 ok(r != 0, "Expected not zero result\n");
1537 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1538 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1540 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1543 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1544 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1545 ok(r != 0, "Expected not zero result\n");
1546 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1547 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1549 /* 2. With backbuffer */
1550 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1551 LVS_EX_DOUBLEBUFFER);
1552 res = ListView_SetBkColor(hwnd, CLR_NONE);
1555 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1556 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1557 ok(r != 0, "Expected not zero result\n");
1558 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1559 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1561 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1564 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1565 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1566 todo_wine ok(r != 0, "Expected not zero result\n");
1567 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1568 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1570 ReleaseDC(hwndparent, hdc);
1572 DestroyWindow(hwnd);
1575 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1577 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1579 if(msg == WM_NOTIFY) {
1580 NMHDR *nmhdr = (PVOID)lp;
1581 if(nmhdr->code == NM_CUSTOMDRAW) {
1582 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1583 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1584 switch(nmlvcd->nmcd.dwDrawStage) {
1586 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1587 return CDRF_NOTIFYITEMDRAW;
1588 case CDDS_ITEMPREPAINT:
1589 nmlvcd->clrTextBk = CLR_DEFAULT;
1590 return CDRF_NOTIFYSUBITEMDRAW;
1591 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1592 clr = GetBkColor(nmlvcd->nmcd.hdc);
1593 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1594 return CDRF_NOTIFYPOSTPAINT;
1595 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1596 clr = GetBkColor(nmlvcd->nmcd.hdc);
1597 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1598 return CDRF_DODEFAULT;
1600 return CDRF_DODEFAULT;
1604 return DefWindowProcA(hwnd, msg, wp, lp);
1607 static void test_customdraw(void)
1612 hwnd = create_listview_control(LVS_REPORT);
1614 insert_column(hwnd, 0);
1615 insert_column(hwnd, 1);
1616 insert_item(hwnd, 0);
1618 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1619 (LONG_PTR)cd_wndproc);
1621 InvalidateRect(hwnd, NULL, TRUE);
1624 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1626 DestroyWindow(hwnd);
1629 static void test_icon_spacing(void)
1631 /* LVM_SETICONSPACING */
1632 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1638 hwnd = create_listview_control(LVS_ICON);
1639 ok(hwnd != NULL, "failed to create a listview window\n");
1641 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1642 expect(NFR_ANSI, r);
1644 /* reset the icon spacing to defaults */
1645 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1647 /* now we can request what the defaults are */
1648 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1652 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1654 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1655 ok(r == MAKELONG(w, h) ||
1656 broken(r == MAKELONG(w, w)), /* win98 */
1657 "Expected %d, got %d\n", MAKELONG(w, h), r);
1659 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1663 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1664 DestroyWindow(hwnd);
1667 expect(MAKELONG(20,30), r);
1669 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1670 expect(MAKELONG(25,35), r);
1672 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1674 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1675 DestroyWindow(hwnd);
1678 static void test_color(void)
1680 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1687 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1689 hwnd = create_listview_control(LVS_REPORT);
1690 ok(hwnd != NULL, "failed to create a listview window\n");
1692 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1694 for (i = 0; i < 4; i++)
1698 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1700 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1703 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1705 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1708 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1710 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1714 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1716 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1717 DestroyWindow(hwnd);
1720 static void test_item_count(void)
1722 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1735 static CHAR item0text[] = "item0";
1736 static CHAR item1text[] = "item1";
1737 static CHAR item2text[] = "item2";
1739 hwnd = create_listview_control(LVS_REPORT);
1740 ok(hwnd != NULL, "failed to create a listview window\n");
1742 /* resize in dpiaware manner to fit all 3 items added */
1744 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1745 GetTextMetricsA(hdc, &tm);
1746 /* 2 extra pixels for bounds and header border */
1747 height = tm.tmHeight + 2;
1748 SelectObject(hdc, hOldFont);
1751 GetWindowRect(hwnd, &rect);
1752 /* 3 items + 1 header + 1 to be sure */
1753 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1755 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1757 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1761 item0.mask = LVIF_TEXT;
1764 item0.pszText = item0text;
1765 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1768 /* [item0, item1] */
1769 item1.mask = LVIF_TEXT;
1772 item1.pszText = item1text;
1773 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1776 /* [item0, item1, item2] */
1777 item2.mask = LVIF_TEXT;
1780 item2.pszText = item2text;
1781 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1784 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1787 /* [item0, item1] */
1788 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1791 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1795 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1798 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1802 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1805 /* [item0, item1] */
1806 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1809 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1812 /* [item0, item1, item2] */
1813 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1816 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1819 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1821 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1822 DestroyWindow(hwnd);
1825 static void test_item_position(void)
1827 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1836 static CHAR item0text[] = "item0";
1837 static CHAR item1text[] = "item1";
1838 static CHAR item2text[] = "item2";
1840 hwnd = create_listview_control(LVS_ICON);
1841 ok(hwnd != NULL, "failed to create a listview window\n");
1843 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1846 item0.mask = LVIF_TEXT;
1849 item0.pszText = item0text;
1850 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1853 /* [item0, item1] */
1854 item1.mask = LVIF_TEXT;
1857 item1.pszText = item1text;
1858 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1861 /* [item0, item1, item2] */
1862 item2.mask = LVIF_TEXT;
1865 item2.pszText = item2text;
1866 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1869 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1871 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1873 expect2(10, 5, position.x, position.y);
1875 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1877 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1879 expect2(0, 0, position.x, position.y);
1881 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1883 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1885 expect2(20, 20, position.x, position.y);
1887 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1889 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1890 DestroyWindow(hwnd);
1893 static void test_getorigin(void)
1901 position.x = position.y = 0;
1903 hwnd = create_listview_control(LVS_ICON);
1904 ok(hwnd != NULL, "failed to create a listview window\n");
1905 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1907 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1909 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1910 DestroyWindow(hwnd);
1912 hwnd = create_listview_control(LVS_SMALLICON);
1913 ok(hwnd != NULL, "failed to create a listview window\n");
1914 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1916 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1918 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1919 DestroyWindow(hwnd);
1921 hwnd = create_listview_control(LVS_LIST);
1922 ok(hwnd != NULL, "failed to create a listview window\n");
1923 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1925 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1927 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1928 DestroyWindow(hwnd);
1930 hwnd = create_listview_control(LVS_REPORT);
1931 ok(hwnd != NULL, "failed to create a listview window\n");
1932 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1934 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1936 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1937 DestroyWindow(hwnd);
1940 static void test_multiselect(void)
1942 typedef struct t_select_task
1953 int i,j,item_count,selected_count;
1954 static const int items=5;
1960 static struct t_select_task task_list[] = {
1961 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1962 { "using VK_UP", -1, VK_UP, -1, -1 },
1963 { "using VK_END", 0, VK_END, 1, -1 },
1964 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1968 hwnd = create_listview_control(LVS_REPORT);
1970 for (i=0;i<items;i++) {
1971 insert_item(hwnd, 0);
1974 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1976 expect(items,item_count);
1979 task = task_list[i];
1981 /* deselect all items */
1982 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1983 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1985 /* set initial position */
1986 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1987 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1989 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1991 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1993 /* Set SHIFT key pressed */
1994 GetKeyboardState(kstate);
1995 kstate[VK_SHIFT]=0x80;
1996 SetKeyboardState(kstate);
1998 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1999 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
2001 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
2005 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2007 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);
2009 /* Set SHIFT key released */
2010 GetKeyboardState(kstate);
2011 kstate[VK_SHIFT]=0x00;
2012 SetKeyboardState(kstate);
2014 DestroyWindow(hwnd);
2016 /* make multiple selection, then switch to LVS_SINGLESEL */
2017 hwnd = create_listview_control(LVS_REPORT);
2018 for (i=0;i<items;i++) {
2019 insert_item(hwnd, 0);
2021 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2022 expect(items,item_count);
2024 /* try with NULL pointer */
2025 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
2028 /* select all, check notifications */
2029 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2031 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2033 item.stateMask = LVIS_SELECTED;
2034 item.state = LVIS_SELECTED;
2035 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2038 ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
2039 "select all notification", FALSE);
2041 /* deselect all items */
2042 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2043 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2045 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
2048 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2050 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2053 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2054 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2055 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2056 /* check that style is accepted */
2057 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2058 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2061 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2062 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2064 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2066 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2069 /* select one more */
2070 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2073 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2074 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2076 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2077 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2079 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2081 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2084 /* try to select all on LVS_SINGLESEL */
2085 memset(&item, 0, sizeof(item));
2086 item.stateMask = LVIS_SELECTED;
2087 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2089 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2091 item.stateMask = LVIS_SELECTED;
2092 item.state = LVIS_SELECTED;
2093 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2096 r = ListView_GetSelectedCount(hwnd);
2098 r = ListView_GetSelectionMark(hwnd);
2101 /* try to deselect all on LVS_SINGLESEL */
2102 item.stateMask = LVIS_SELECTED;
2103 item.state = LVIS_SELECTED;
2104 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2107 item.stateMask = LVIS_SELECTED;
2109 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2111 r = ListView_GetSelectedCount(hwnd);
2114 DestroyWindow(hwnd);
2117 static void test_subitem_rect(void)
2125 /* test LVM_GETSUBITEMRECT for header */
2126 hwnd = create_listview_control(LVS_REPORT);
2127 ok(hwnd != NULL, "failed to create a listview window\n");
2128 /* add some columns */
2129 memset(&col, 0, sizeof(LVCOLUMN));
2130 col.mask = LVCF_WIDTH;
2132 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2135 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2138 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2140 /* item = -1 means header, subitem index is 1 based */
2141 rect.left = LVIR_BOUNDS;
2143 rect.right = rect.bottom = 0;
2144 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2147 rect.left = LVIR_BOUNDS;
2149 rect.right = rect.bottom = 0;
2150 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2152 ok(r != 0, "Expected not-null LRESULT\n");
2153 expect(100, rect.left);
2154 expect(250, rect.right);
2156 expect(3, rect.top);
2158 rect.left = LVIR_BOUNDS;
2160 rect.right = rect.bottom = 0;
2161 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2163 ok(r != 0, "Expected not-null LRESULT\n");
2164 expect(250, rect.left);
2165 expect(450, rect.right);
2167 expect(3, rect.top);
2169 /* item LVS_REPORT padding isn't applied to subitems */
2170 insert_item(hwnd, 0);
2172 rect.left = LVIR_BOUNDS;
2174 rect.right = rect.bottom = 0;
2175 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2176 ok(r != 0, "Expected not-null LRESULT\n");
2177 expect(100, rect.left);
2178 expect(250, rect.right);
2180 rect.left = LVIR_ICON;
2182 rect.right = rect.bottom = 0;
2183 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2184 ok(r != 0, "Expected not-null LRESULT\n");
2185 /* no icon attached - zero width rectangle, with no left padding */
2186 expect(100, rect.left);
2187 expect(100, rect.right);
2189 rect.left = LVIR_LABEL;
2191 rect.right = rect.bottom = 0;
2192 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2193 ok(r != 0, "Expected not-null LRESULT\n");
2194 /* same as full LVIR_BOUNDS */
2195 expect(100, rect.left);
2196 expect(250, rect.right);
2198 SendMessage(hwnd, LVM_SCROLL, 10, 0);
2200 rect.left = LVIR_BOUNDS;
2202 rect.right = rect.bottom = 0;
2203 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2204 ok(r != 0, "Expected not-null LRESULT\n");
2205 expect(90, rect.left);
2206 expect(240, rect.right);
2208 SendMessage(hwnd, LVM_SCROLL, -10, 0);
2210 DestroyWindow(hwnd);
2212 /* test subitem rects after re-arranging columns */
2213 hwnd = create_listview_control(LVS_REPORT);
2214 ok(hwnd != NULL, "failed to create a listview window\n");
2215 memset(&col, 0, sizeof(LVCOLUMN));
2216 col.mask = LVCF_WIDTH;
2219 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2223 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2227 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2230 insert_item(hwnd, 0);
2231 insert_item(hwnd, 1);
2233 /* wrong item is refused for main item */
2234 rect.left = LVIR_BOUNDS;
2236 rect.right = rect.bottom = -1;
2237 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect);
2238 ok(r == FALSE, "got %d\n", r);
2240 /* for subitems rectangle is calculated even if there's no item added */
2241 rect.left = LVIR_BOUNDS;
2243 rect.right = rect.bottom = -1;
2244 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect);
2245 ok(r == TRUE, "got %d\n", r);
2247 rect2.left = LVIR_BOUNDS;
2249 rect2.right = rect2.bottom = -1;
2250 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect2);
2252 ok(r == TRUE, "got %d\n", r);
2253 expect(rect.right, rect2.right);
2254 expect(rect.left, rect2.left);
2255 expect(rect.bottom, rect2.top);
2256 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2259 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2260 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2263 rect.left = LVIR_BOUNDS;
2265 rect.right = rect.bottom = -1;
2266 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2267 ok(r == TRUE, "got %d\n", r);
2268 expect(0, rect.left);
2269 expect(600, rect.right);
2271 rect.left = LVIR_BOUNDS;
2273 rect.right = rect.bottom = -1;
2274 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2275 ok(r == TRUE, "got %d\n", r);
2276 expect(0, rect.left);
2277 expect(200, rect.right);
2279 rect2.left = LVIR_BOUNDS;
2281 rect2.right = rect2.bottom = -1;
2282 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect2);
2283 ok(r == TRUE, "got %d\n", r);
2284 expect(0, rect2.left);
2285 expect(200, rect2.right);
2286 /* items are of the same height */
2287 ok(rect2.top > 0, "expected positive item height\n");
2288 expect(rect.bottom, rect2.top);
2289 expect(rect.bottom * 2 - rect.top, rect2.bottom);
2291 rect.left = LVIR_BOUNDS;
2293 rect.right = rect.bottom = -1;
2294 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2295 ok(r == TRUE, "got %d\n", r);
2296 expect(300, rect.left);
2297 expect(600, rect.right);
2299 DestroyWindow(hwnd);
2301 /* try it for non LVS_REPORT style */
2302 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2303 GetModuleHandle(NULL), 0);
2304 rect.left = LVIR_BOUNDS;
2306 rect.right = rect.bottom = -10;
2307 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2308 ok(r == 0, "Expected not-null LRESULT\n");
2309 /* rect is unchanged */
2310 expect(0, rect.left);
2311 expect(-10, rect.right);
2312 expect(1, rect.top);
2313 expect(-10, rect.bottom);
2314 DestroyWindow(hwnd);
2317 /* comparison callback for test_sorting */
2318 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2320 if (first == second) return 0;
2321 return (first > second ? 1 : -1);
2324 static void test_sorting(void)
2330 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2333 hwnd = create_listview_control(LVS_REPORT);
2334 ok(hwnd != NULL, "failed to create a listview window\n");
2336 /* insert some items */
2337 item.mask = LVIF_PARAM | LVIF_STATE;
2338 item.state = LVIS_SELECTED;
2342 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2345 item.mask = LVIF_PARAM;
2349 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2352 item.mask = LVIF_STATE | LVIF_PARAM;
2353 item.state = LVIS_SELECTED;
2357 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2360 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2363 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2366 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2369 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2371 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2373 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2375 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2376 expect(LVIS_SELECTED, r);
2377 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2378 expect(LVIS_SELECTED, r);
2380 DestroyWindow(hwnd);
2382 /* switch to LVS_SORTASCENDING when some items added */
2383 hwnd = create_listview_control(LVS_REPORT);
2384 ok(hwnd != NULL, "failed to create a listview window\n");
2386 item.mask = LVIF_TEXT;
2389 item.pszText = names[1];
2390 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2393 item.mask = LVIF_TEXT;
2396 item.pszText = names[2];
2397 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2400 item.mask = LVIF_TEXT;
2403 item.pszText = names[0];
2404 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2407 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2408 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2409 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2410 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2412 /* no sorting performed when switched to LVS_SORTASCENDING */
2413 item.mask = LVIF_TEXT;
2415 item.pszText = buff;
2416 item.cchTextMax = sizeof(buff);
2417 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2419 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2422 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2424 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2427 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2429 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2431 /* adding new item doesn't resort list */
2432 item.mask = LVIF_TEXT;
2435 item.pszText = names[3];
2436 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2439 item.mask = LVIF_TEXT;
2441 item.pszText = buff;
2442 item.cchTextMax = sizeof(buff);
2443 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2445 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2448 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2450 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2453 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2455 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2458 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2460 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2462 /* corner case - item should be placed at first position */
2463 item.mask = LVIF_TEXT;
2466 item.pszText = names[4];
2467 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2471 item.pszText = buff;
2472 item.cchTextMax = sizeof(buff);
2473 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2475 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2478 item.pszText = buff;
2479 item.cchTextMax = sizeof(buff);
2480 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2482 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2485 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2487 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2490 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2492 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2495 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2497 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2499 DestroyWindow(hwnd);
2502 static void test_ownerdata(void)
2505 LONG_PTR style, ret;
2509 /* it isn't possible to set LVS_OWNERDATA after creation */
2512 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2516 hwnd = create_listview_control(LVS_REPORT);
2517 ok(hwnd != NULL, "failed to create a listview window\n");
2518 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2519 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2521 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2523 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2524 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2525 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2526 "try to switch to LVS_OWNERDATA seq", FALSE);
2528 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2529 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2530 DestroyWindow(hwnd);
2533 /* try to set LVS_OWNERDATA after creation just having it */
2534 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2535 ok(hwnd != NULL, "failed to create a listview window\n");
2536 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2537 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2539 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2541 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2542 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2543 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2544 "try to switch to LVS_OWNERDATA seq", FALSE);
2545 DestroyWindow(hwnd);
2547 /* try to remove LVS_OWNERDATA after creation just having it */
2550 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2554 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2555 ok(hwnd != NULL, "failed to create a listview window\n");
2556 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2557 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2559 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2561 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2562 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2563 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2564 "try to switch to LVS_OWNERDATA seq", FALSE);
2565 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2566 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2567 DestroyWindow(hwnd);
2570 /* try select an item */
2571 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2572 ok(hwnd != NULL, "failed to create a listview window\n");
2573 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2574 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2575 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2577 memset(&item, 0, sizeof(item));
2578 item.stateMask = LVIS_SELECTED;
2579 item.state = LVIS_SELECTED;
2580 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2582 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2584 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2586 DestroyWindow(hwnd);
2588 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2589 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2590 ok(hwnd != NULL, "failed to create a listview window\n");
2591 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2592 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2593 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2595 memset(&item, 0, sizeof(item));
2596 item.mask = LVIF_STATE;
2598 item.stateMask = LVIS_SELECTED;
2599 item.state = LVIS_SELECTED;
2600 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2602 DestroyWindow(hwnd);
2604 /* check notifications after focused/selected changed */
2605 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2606 ok(hwnd != NULL, "failed to create a listview window\n");
2607 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2608 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2610 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2612 memset(&item, 0, sizeof(item));
2613 item.stateMask = LVIS_SELECTED;
2614 item.state = LVIS_SELECTED;
2615 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2618 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2619 "ownerdata select notification", TRUE);
2621 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2623 memset(&item, 0, sizeof(item));
2624 item.stateMask = LVIS_FOCUSED;
2625 item.state = LVIS_FOCUSED;
2626 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2629 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2630 "ownerdata focus notification", TRUE);
2632 /* select all, check notifications */
2633 item.stateMask = LVIS_SELECTED;
2635 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2638 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2640 item.stateMask = LVIS_SELECTED;
2641 item.state = LVIS_SELECTED;
2643 g_dump_itemchanged = TRUE;
2644 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2646 g_dump_itemchanged = FALSE;
2648 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2649 "ownerdata select all notification", TRUE);
2651 /* select all again, note that all items are selected already */
2652 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2653 item.stateMask = LVIS_SELECTED;
2654 item.state = LVIS_SELECTED;
2655 g_dump_itemchanged = TRUE;
2656 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2658 g_dump_itemchanged = FALSE;
2659 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2660 "ownerdata select all notification", TRUE);
2662 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2663 item.stateMask = LVIS_SELECTED;
2665 g_dump_itemchanged = TRUE;
2666 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2668 g_dump_itemchanged = FALSE;
2669 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2670 "ownerdata deselect all notification", TRUE);
2672 /* select one, then deselect all */
2673 item.stateMask = LVIS_SELECTED;
2674 item.state = LVIS_SELECTED;
2675 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2677 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2678 item.stateMask = LVIS_SELECTED;
2680 g_dump_itemchanged = TRUE;
2681 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2683 g_dump_itemchanged = FALSE;
2684 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2685 "ownerdata select all notification", TRUE);
2687 /* remove focused, try to focus all */
2688 item.stateMask = LVIS_FOCUSED;
2689 item.state = LVIS_FOCUSED;
2690 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2692 item.stateMask = LVIS_FOCUSED;
2694 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2696 item.stateMask = LVIS_FOCUSED;
2697 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
2699 /* setting all to focused returns failure value */
2700 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2701 item.stateMask = LVIS_FOCUSED;
2702 item.state = LVIS_FOCUSED;
2703 g_dump_itemchanged = TRUE;
2704 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2706 g_dump_itemchanged = FALSE;
2707 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2708 "ownerdata focus all notification", FALSE);
2709 /* focus single item, remove all */
2710 item.stateMask = LVIS_FOCUSED;
2711 item.state = LVIS_FOCUSED;
2712 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2714 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2715 item.stateMask = LVIS_FOCUSED;
2717 g_dump_itemchanged = TRUE;
2718 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2720 g_dump_itemchanged = FALSE;
2721 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
2722 "ownerdata remove focus all notification", TRUE);
2724 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2725 item.stateMask = LVIS_CUT;
2726 item.state = LVIS_CUT;
2727 g_dump_itemchanged = TRUE;
2728 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2730 g_dump_itemchanged = FALSE;
2731 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2732 "ownerdata cut all notification", TRUE);
2733 /* all marked cut, try again */
2734 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2735 item.stateMask = LVIS_CUT;
2736 item.state = LVIS_CUT;
2737 g_dump_itemchanged = TRUE;
2738 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2740 g_dump_itemchanged = FALSE;
2741 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2742 "ownerdata cut all notification #2", TRUE);
2744 DestroyWindow(hwnd);
2746 /* check notifications on LVM_GETITEM */
2747 /* zero callback mask */
2748 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2749 ok(hwnd != NULL, "failed to create a listview window\n");
2750 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2751 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2753 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2755 memset(&item, 0, sizeof(item));
2756 item.stateMask = LVIS_SELECTED;
2757 item.mask = LVIF_STATE;
2758 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2761 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2762 "ownerdata getitem selected state 1", FALSE);
2764 /* non zero callback mask but not we asking for */
2765 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2768 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2770 memset(&item, 0, sizeof(item));
2771 item.stateMask = LVIS_SELECTED;
2772 item.mask = LVIF_STATE;
2773 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2776 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2777 "ownerdata getitem selected state 2", FALSE);
2779 /* LVIS_OVERLAYMASK callback mask, asking for index */
2780 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2782 memset(&item, 0, sizeof(item));
2783 item.stateMask = LVIS_OVERLAYMASK;
2784 item.mask = LVIF_STATE;
2785 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2788 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2789 "ownerdata getitem selected state 2", FALSE);
2791 DestroyWindow(hwnd);
2793 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2794 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
2795 ok(hwnd != NULL, "failed to create a listview window\n");
2796 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2797 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2798 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2799 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2800 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2801 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2802 DestroyWindow(hwnd);
2803 /* apparently it's allowed to switch these style on after creation */
2804 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2805 ok(hwnd != NULL, "failed to create a listview window\n");
2806 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2807 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2808 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2809 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2810 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2811 DestroyWindow(hwnd);
2813 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2814 ok(hwnd != NULL, "failed to create a listview window\n");
2815 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2816 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2817 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2818 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2819 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2820 DestroyWindow(hwnd);
2823 static void test_norecompute(void)
2825 static CHAR testA[] = "test";
2831 /* self containing control */
2832 hwnd = create_listview_control(LVS_REPORT);
2833 ok(hwnd != NULL, "failed to create a listview window\n");
2834 memset(&item, 0, sizeof(item));
2835 item.mask = LVIF_TEXT | LVIF_STATE;
2837 item.stateMask = LVIS_SELECTED;
2838 item.state = LVIS_SELECTED;
2839 item.pszText = testA;
2840 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2842 /* retrieve with LVIF_NORECOMPUTE */
2843 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2845 item.pszText = buff;
2846 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2847 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2849 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2851 item.mask = LVIF_TEXT;
2853 item.pszText = LPSTR_TEXTCALLBACK;
2854 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2857 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2859 item.pszText = buff;
2860 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2862 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2863 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2865 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2866 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2867 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2869 DestroyWindow(hwnd);
2872 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2873 ok(hwnd != NULL, "failed to create a listview window\n");
2875 item.mask = LVIF_STATE;
2876 item.stateMask = LVIS_SELECTED;
2877 item.state = LVIS_SELECTED;
2879 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2882 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2884 item.pszText = buff;
2885 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2886 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2887 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2889 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2890 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2891 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2893 DestroyWindow(hwnd);
2896 static void test_nosortheader(void)
2901 hwnd = create_listview_control(LVS_REPORT);
2902 ok(hwnd != NULL, "failed to create a listview window\n");
2904 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2905 ok(IsWindow(header), "header expected\n");
2907 style = GetWindowLongPtr(header, GWL_STYLE);
2908 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2910 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2911 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2912 /* HDS_BUTTONS retained */
2913 style = GetWindowLongPtr(header, GWL_STYLE);
2914 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2916 DestroyWindow(hwnd);
2918 /* create with LVS_NOSORTHEADER */
2919 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
2920 ok(hwnd != NULL, "failed to create a listview window\n");
2922 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2923 ok(IsWindow(header), "header expected\n");
2925 style = GetWindowLongPtr(header, GWL_STYLE);
2926 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2928 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2929 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2930 /* not changed here */
2931 style = GetWindowLongPtr(header, GWL_STYLE);
2932 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2934 DestroyWindow(hwnd);
2937 static void test_setredraw(void)
2945 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2946 ok(hwnd != NULL, "failed to create a listview window\n");
2948 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2949 ListView seems to handle it internally without DefWinProc */
2951 /* default value first */
2952 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2955 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2956 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2957 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2959 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2960 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2961 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2964 /* check update rect after redrawing */
2965 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2967 InvalidateRect(hwnd, NULL, FALSE);
2968 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
2969 rect.right = rect.bottom = 1;
2970 GetUpdateRect(hwnd, &rect, FALSE);
2971 expect(0, rect.right);
2972 expect(0, rect.bottom);
2975 hdc = GetWindowDC(hwndparent);
2976 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2978 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2980 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2982 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2984 ReleaseDC(hwndparent, hdc);
2986 /* check notification messages to show that repainting is disabled */
2987 ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
2989 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2991 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2993 InvalidateRect(hwnd, NULL, TRUE);
2995 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2996 "redraw after WM_SETREDRAW (FALSE)", FALSE);
2998 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3000 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3001 InvalidateRect(hwnd, NULL, TRUE);
3003 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3004 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3006 /* message isn't forwarded to header */
3007 subclass_header(hwnd);
3008 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3009 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3011 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3012 "WM_SETREDRAW: not forwarded to header", FALSE);
3014 DestroyWindow(hwnd);
3017 static void test_hittest(void)
3023 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3027 HIMAGELIST himl, himl2;
3030 hwnd = create_listview_control(LVS_REPORT);
3031 ok(hwnd != NULL, "failed to create a listview window\n");
3033 /* LVS_REPORT with a single subitem (2 columns) */
3034 insert_column(hwnd, 0);
3035 insert_column(hwnd, 1);
3036 insert_item(hwnd, 0);
3039 /* the only purpose of that line is to be as long as a half item rect */
3040 item.pszText = text;
3041 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
3044 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3046 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3049 memset(&bounds, 0, sizeof(bounds));
3050 bounds.left = LVIR_BOUNDS;
3051 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3053 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3054 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3055 r = SendMessage(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3057 ok(bounds.bottom - bounds.top == vert,
3058 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3059 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3062 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3064 /* outside columns by x position - valid is [0, 199] */
3066 y = pos.y + (bounds.bottom - bounds.top) / 2;
3067 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3068 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3070 x = pos.x + 50; /* column half width */
3071 y = pos.y + (bounds.bottom - bounds.top) / 2;
3072 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3073 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3074 x = pos.x + 150; /* outside column */
3075 y = pos.y + (bounds.bottom - bounds.top) / 2;
3076 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3077 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3078 y = (bounds.bottom - bounds.top) / 2;
3079 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3080 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3081 /* outside possible client rectangle (to right) */
3083 y = pos.y + (bounds.bottom - bounds.top) / 2;
3084 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3085 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3086 y = (bounds.bottom - bounds.top) / 2;
3087 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3088 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3089 /* subitem returned with -1 item too */
3091 y = bounds.top - vert;
3092 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3093 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3094 /* return values appear to underflow with negative indices */
3098 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3099 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3103 /* parent client area is 100x100 by default */
3104 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3105 x = pos.x + 150; /* outside column */
3106 y = pos.y + (bounds.bottom - bounds.top) / 2;
3107 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3108 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3109 y = (bounds.bottom - bounds.top) / 2;
3110 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3111 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3112 /* the same with LVS_EX_FULLROWSELECT */
3113 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3114 x = pos.x + 150; /* outside column */
3115 y = pos.y + (bounds.bottom - bounds.top) / 2;
3116 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3117 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3118 y = (bounds.bottom - bounds.top) / 2;
3119 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3120 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3121 x = pos.x + 150; /* outside column */
3122 y = pos.y + (bounds.bottom - bounds.top) / 2;
3123 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3124 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3125 y = (bounds.bottom - bounds.top) / 2;
3126 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3127 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3128 /* outside possible client rectangle (to right) */
3130 y = pos.y + (bounds.bottom - bounds.top) / 2;
3131 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3132 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3133 y = (bounds.bottom - bounds.top) / 2;
3134 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3135 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3136 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3137 himl = ImageList_Create(16, 16, 0, 4, 4);
3138 ok(himl != NULL, "failed to create imagelist\n");
3139 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3140 ok(hbmp != NULL, "failed to create bitmap\n");
3141 r = ImageList_Add(himl, hbmp, 0);
3142 ok(r == 0, "should be zero\n");
3143 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3144 ok(hbmp != NULL, "failed to create bitmap\n");
3145 r = ImageList_Add(himl, hbmp, 0);
3146 ok(r == 1, "should be one\n");
3148 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3149 ok(r == 0, "should return zero\n");
3151 item.mask = LVIF_IMAGE;
3155 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3159 y = pos.y + (bounds.bottom - bounds.top) / 2;
3160 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3161 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3162 y = (bounds.bottom - bounds.top) / 2;
3163 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3165 /* state icons indices are 1 based, check with valid index */
3166 item.mask = LVIF_STATE;
3167 item.state = INDEXTOSTATEIMAGEMASK(1);
3168 item.stateMask = LVIS_STATEIMAGEMASK;
3171 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3175 y = pos.y + (bounds.bottom - bounds.top) / 2;
3176 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3177 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3178 y = (bounds.bottom - bounds.top) / 2;
3179 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3181 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3182 ok(himl2 == himl, "should return handle\n");
3184 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3185 ok(r == 0, "should return zero\n");
3188 y = pos.y + (bounds.bottom - bounds.top) / 2;
3189 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3190 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3191 y = (bounds.bottom - bounds.top) / 2;
3192 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3194 DestroyWindow(hwnd);
3197 static void test_getviewrect(void)
3204 hwnd = create_listview_control(LVS_REPORT);
3205 ok(hwnd != NULL, "failed to create a listview window\n");
3208 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3211 insert_column(hwnd, 0);
3212 insert_column(hwnd, 1);
3214 memset(&item, 0, sizeof(item));
3217 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3219 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3221 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3224 rect.left = rect.right = rect.top = rect.bottom = -1;
3225 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3227 /* left is set to (2e31-1) - XP SP2 */
3228 expect(0, rect.right);
3229 expect(0, rect.top);
3230 expect(0, rect.bottom);
3232 /* switch to LVS_ICON */
3233 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3235 rect.left = rect.right = rect.top = rect.bottom = -1;
3236 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3238 expect(0, rect.left);
3239 expect(0, rect.top);
3240 /* precise value differs for 2k, XP and Vista */
3241 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3242 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3244 DestroyWindow(hwnd);
3247 static void test_getitemposition(void)
3254 hwnd = create_listview_control(LVS_REPORT);
3255 ok(hwnd != NULL, "failed to create a listview window\n");
3256 header = subclass_header(hwnd);
3258 /* LVS_REPORT, single item, no columns added */
3259 insert_item(hwnd, 0);
3261 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3264 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3266 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3268 /* LVS_REPORT, single item, single column */
3269 insert_column(hwnd, 0);
3271 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3274 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3276 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3278 memset(&rect, 0, sizeof(rect));
3279 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3282 /* offset by header height */
3283 expect(rect.bottom - rect.top, pt.y);
3285 DestroyWindow(hwnd);
3288 static void test_columnscreation(void)
3293 hwnd = create_listview_control(LVS_REPORT);
3294 ok(hwnd != NULL, "failed to create a listview window\n");
3296 insert_item(hwnd, 0);
3298 /* headers columns aren't created automatically */
3299 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3300 ok(IsWindow(header), "Expected header handle\n");
3301 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3304 DestroyWindow(hwnd);
3307 static void test_getitemrect(void)
3320 /* rectangle isn't empty for empty text items */
3321 hwnd = create_listview_control(LVS_LIST);
3322 memset(&item, 0, sizeof(item));
3325 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3327 rect.left = LVIR_LABEL;
3328 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3330 expect(0, rect.left);
3331 expect(0, rect.top);
3333 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, rect.right);
3334 ReleaseDC(hwnd, hdc);
3335 DestroyWindow(hwnd);
3337 hwnd = create_listview_control(LVS_REPORT);
3338 ok(hwnd != NULL, "failed to create a listview window\n");
3341 memset(&item, 0, sizeof(item));
3344 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3347 rect.left = LVIR_BOUNDS;
3348 rect.right = rect.top = rect.bottom = -1;
3349 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3352 /* zero width rectangle with no padding */
3353 expect(0, rect.left);
3354 expect(0, rect.right);
3356 insert_column(hwnd, 0);
3357 insert_column(hwnd, 1);
3359 col.mask = LVCF_WIDTH;
3361 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3364 col.mask = LVCF_WIDTH;
3366 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3369 rect.left = LVIR_BOUNDS;
3370 rect.right = rect.top = rect.bottom = -1;
3371 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3374 /* still no left padding */
3375 expect(0, rect.left);
3376 expect(150, rect.right);
3378 rect.left = LVIR_SELECTBOUNDS;
3379 rect.right = rect.top = rect.bottom = -1;
3380 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3383 expect(2, rect.left);
3385 rect.left = LVIR_LABEL;
3386 rect.right = rect.top = rect.bottom = -1;
3387 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3389 /* padding, column width */
3390 expect(2, rect.left);
3391 expect(50, rect.right);
3393 /* no icons attached */
3394 rect.left = LVIR_ICON;
3395 rect.right = rect.top = rect.bottom = -1;
3396 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3399 expect(2, rect.left);
3400 expect(2, rect.right);
3403 order[0] = 1; order[1] = 0;
3404 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3407 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3409 /* 1 indexed column width + padding */
3411 /* rect is at zero too */
3412 rect.left = LVIR_BOUNDS;
3413 rect.right = rect.top = rect.bottom = -1;
3414 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3416 expect(0, rect.left);
3417 /* just width sum */
3418 expect(150, rect.right);
3420 rect.left = LVIR_SELECTBOUNDS;
3421 rect.right = rect.top = rect.bottom = -1;
3422 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3424 /* column width + padding */
3425 expect(102, rect.left);
3427 /* back to initial order */
3428 order[0] = 0; order[1] = 1;
3429 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3433 himl = ImageList_Create(16, 16, 0, 2, 2);
3434 ok(himl != NULL, "failed to create imagelist\n");
3435 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3436 ok(hbm != NULL, "failed to create bitmap\n");
3437 r = ImageList_Add(himl, hbm, 0);
3438 ok(r == 0, "should be zero\n");
3439 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3440 ok(hbm != NULL, "failed to create bitmap\n");
3441 r = ImageList_Add(himl, hbm, 0);
3442 ok(r == 1, "should be one\n");
3444 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3445 ok(r == 0, "should return zero\n");
3447 item.mask = LVIF_STATE;
3448 item.state = INDEXTOSTATEIMAGEMASK(1);
3449 item.stateMask = LVIS_STATEIMAGEMASK;
3452 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3456 rect.left = LVIR_ICON;
3457 rect.right = rect.top = rect.bottom = -1;
3458 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3460 /* padding + stateicon width */
3461 expect(18, rect.left);
3462 expect(18, rect.right);
3464 rect.left = LVIR_LABEL;
3465 rect.right = rect.top = rect.bottom = -1;
3466 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3468 /* padding + stateicon width -> column width */
3469 expect(18, rect.left);
3470 expect(50, rect.right);
3472 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3473 ok(r != 0, "should return current list handle\n");
3475 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3476 ok(r == 0, "should return zero\n");
3478 item.mask = LVIF_STATE | LVIF_IMAGE;
3481 item.stateMask = ~0;
3484 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3488 rect.left = LVIR_ICON;
3489 rect.right = rect.top = rect.bottom = -1;
3490 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3492 /* padding, icon width */
3493 expect(2, rect.left);
3494 expect(18, rect.right);
3496 rect.left = LVIR_LABEL;
3497 rect.right = rect.top = rect.bottom = -1;
3498 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3500 /* padding + icon width -> column width */
3501 expect(18, rect.left);
3502 expect(50, rect.right);
3505 rect.left = LVIR_SELECTBOUNDS;
3506 rect.right = rect.top = rect.bottom = -1;
3507 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3509 /* padding, column width */
3510 expect(2, rect.left);
3511 expect(50, rect.right);
3513 /* try with indentation */
3514 item.mask = LVIF_INDENT;
3518 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3522 rect.left = LVIR_BOUNDS;
3523 rect.right = rect.top = rect.bottom = -1;
3524 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3526 /* padding + 1 icon width, column width */
3527 expect(0, rect.left);
3528 expect(150, rect.right);
3531 rect.left = LVIR_SELECTBOUNDS;
3532 rect.right = rect.top = rect.bottom = -1;
3533 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3535 /* padding + 1 icon width, column width */
3536 expect(2 + 16, rect.left);
3537 expect(50, rect.right);
3540 rect.left = LVIR_LABEL;
3541 rect.right = rect.top = rect.bottom = -1;
3542 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3544 /* padding + 2 icon widths, column width */
3545 expect(2 + 16*2, rect.left);
3546 expect(50, rect.right);
3549 rect.left = LVIR_ICON;
3550 rect.right = rect.top = rect.bottom = -1;
3551 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3553 /* padding + 1 icon width indentation, icon width */
3554 expect(2 + 16, rect.left);
3555 expect(34, rect.right);
3557 DestroyWindow(hwnd);
3560 static void test_editbox(void)
3562 static CHAR testitemA[] = "testitem";
3563 static CHAR testitem1A[] = "testitem_quitelongname";
3564 static CHAR buffer[25];
3565 HWND hwnd, hwndedit, hwndedit2, header;
3569 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3570 ok(hwnd != NULL, "failed to create a listview window\n");
3572 insert_column(hwnd, 0);
3574 memset(&item, 0, sizeof(item));
3575 item.mask = LVIF_TEXT;
3576 item.pszText = testitemA;
3579 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3582 /* test notifications without edit created */
3583 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3584 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
3586 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3587 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
3588 /* same thing but with valid window */
3589 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
3590 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
3591 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3592 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
3594 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3595 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
3596 DestroyWindow(hwndedit);
3598 /* setting focus is necessary */
3600 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3601 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3603 /* test children Z-order after Edit box created */
3604 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3605 ok(IsWindow(header), "Expected header to be created\n");
3606 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3607 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3609 /* modify initial string */
3610 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3613 /* edit window is resized and repositioned,
3614 check again for Z-order - it should be preserved */
3615 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3616 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3618 /* return focus to listview */
3621 memset(&item, 0, sizeof(item));
3622 item.mask = LVIF_TEXT;
3623 item.pszText = buffer;
3624 item.cchTextMax = sizeof(buffer);
3627 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3630 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3632 /* send LVM_EDITLABEL on already created edit */
3634 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3635 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3636 /* focus will be set to edit */
3637 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3638 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3639 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3641 /* creating label disabled when control isn't focused */
3643 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3644 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3646 /* check EN_KILLFOCUS handling */
3647 memset(&item, 0, sizeof(item));
3648 item.pszText = testitemA;
3651 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3655 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3656 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3657 /* modify edit and notify control that it lost focus */
3658 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3660 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3662 memset(&item, 0, sizeof(item));
3663 item.pszText = buffer;
3664 item.cchTextMax = sizeof(buffer);
3667 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3668 expect(lstrlen(item.pszText), r);
3669 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3670 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
3671 /* end edit without saving */
3673 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3674 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3675 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3677 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3678 "edit box - end edit, no change, escape", TRUE);
3679 /* end edit with saving */
3681 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3682 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3683 r = SendMessage(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
3685 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3686 "edit box - end edit, no change, return", TRUE);
3688 memset(&item, 0, sizeof(item));
3689 item.pszText = buffer;
3690 item.cchTextMax = sizeof(buffer);
3693 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3694 expect(lstrlen(item.pszText), r);
3695 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3697 /* LVM_EDITLABEL with -1 destroys current edit */
3698 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3699 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3700 /* no edit present */
3701 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3702 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3703 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3704 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3706 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3707 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3708 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3709 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3710 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3711 /* check another negative value */
3712 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3713 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3714 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3715 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3716 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3717 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3718 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3719 /* and value greater than max item index */
3720 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3721 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3722 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3723 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3724 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3725 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3726 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3727 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3729 /* messaging tests */
3731 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3733 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3734 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3735 /* testing only sizing messages */
3736 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3737 "edit box create - sizing", FALSE);
3739 /* WM_COMMAND with EN_KILLFOCUS isn't forwared to parent */
3741 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3742 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3743 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3744 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3746 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3747 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
3749 DestroyWindow(hwnd);
3752 static void test_notifyformat(void)
3757 hwnd = create_listview_control(LVS_REPORT);
3758 ok(hwnd != NULL, "failed to create a listview window\n");
3760 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3761 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3762 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3764 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3766 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3768 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3771 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3773 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3778 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3779 DestroyWindow(hwnd);
3783 DestroyWindow(hwnd);
3785 /* test failure in parent WM_NOTIFYFORMAT */
3787 hwnd = create_listview_control(LVS_REPORT);
3788 ok(hwnd != NULL, "failed to create a listview window\n");
3789 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3790 ok(IsWindow(header), "expected header to be created\n");
3791 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3793 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3794 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3795 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3796 ok(r != 0, "Expected valid format\n");
3798 notifyFormat = NFR_UNICODE;
3799 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3800 expect(NFR_UNICODE, r);
3801 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3803 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3804 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3806 notifyFormat = NFR_ANSI;
3807 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3808 expect(NFR_ANSI, r);
3809 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3811 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3812 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3814 DestroyWindow(hwnd);
3816 /* try different unicode window combination and defaults */
3817 if (!GetModuleHandleW(NULL))
3819 win_skip("Additional notify format tests are incompatible with Win9x\n");
3823 hwndparentW = create_parent_window(TRUE);
3824 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3825 if (!IsWindow(hwndparentW)) return;
3828 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3829 ok(hwnd != NULL, "failed to create a listview window\n");
3830 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3831 ok(IsWindow(header), "expected header to be created\n");
3832 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3834 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3836 DestroyWindow(hwnd);
3837 /* receiving error code defaulting to ansi */
3839 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3840 ok(hwnd != NULL, "failed to create a listview window\n");
3841 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3842 ok(IsWindow(header), "expected header to be created\n");
3843 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3845 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3847 DestroyWindow(hwnd);
3848 /* receiving ansi code from unicode window, use it */
3849 notifyFormat = NFR_ANSI;
3850 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3851 ok(hwnd != NULL, "failed to create a listview window\n");
3852 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3853 ok(IsWindow(header), "expected header to be created\n");
3854 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3856 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3858 DestroyWindow(hwnd);
3859 /* unicode listview with ansi parent window */
3861 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3862 ok(hwnd != NULL, "failed to create a listview window\n");
3863 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3864 ok(IsWindow(header), "expected header to be created\n");
3865 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3867 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3869 DestroyWindow(hwnd);
3870 /* unicode listview with ansi parent window, return error code */
3872 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3873 ok(hwnd != NULL, "failed to create a listview window\n");
3874 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3875 ok(IsWindow(header), "expected header to be created\n");
3876 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3878 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3880 DestroyWindow(hwnd);
3882 DestroyWindow(hwndparentW);
3885 static void test_indentation(void)
3891 hwnd = create_listview_control(LVS_REPORT);
3892 ok(hwnd != NULL, "failed to create a listview window\n");
3894 memset(&item, 0, sizeof(item));
3895 item.mask = LVIF_INDENT;
3897 item.iIndent = I_INDENTCALLBACK;
3898 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3901 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3904 item.mask = LVIF_INDENT;
3905 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3908 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3909 "get indent dispinfo", FALSE);
3911 DestroyWindow(hwnd);
3914 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
3919 static BOOL is_below_comctl_5(void)
3924 hwnd = create_listview_control(LVS_REPORT);
3925 ok(hwnd != NULL, "failed to create a listview window\n");
3926 insert_item(hwnd, 0);
3928 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
3930 DestroyWindow(hwnd);
3935 static void test_get_set_view(void)
3941 /* test style->view mapping */
3942 hwnd = create_listview_control(LVS_REPORT);
3943 ok(hwnd != NULL, "failed to create a listview window\n");
3945 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3946 expect(LV_VIEW_DETAILS, ret);
3948 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3950 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
3951 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3952 expect(LV_VIEW_ICON, ret);
3954 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3955 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
3956 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3957 expect(LV_VIEW_SMALLICON, ret);
3959 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3960 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
3961 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3962 expect(LV_VIEW_LIST, ret);
3964 /* switching view doesn't touch window style */
3965 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
3967 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3968 ok(style & LVS_LIST, "Expected style to be preserved\n");
3969 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
3971 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3972 ok(style & LVS_LIST, "Expected style to be preserved\n");
3973 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
3975 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3976 ok(style & LVS_LIST, "Expected style to be preserved\n");
3978 DestroyWindow(hwnd);
3981 static void test_canceleditlabel(void)
3983 HWND hwnd, hwndedit;
3987 static CHAR test[] = "test";
3988 static const CHAR test1[] = "test1";
3990 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3991 ok(hwnd != NULL, "failed to create a listview window\n");
3993 insert_item(hwnd, 0);
3995 /* try without edit created */
3996 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3997 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3999 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4000 "cancel edit label without edit", FALSE);
4002 /* cancel without data change */
4004 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4005 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4006 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4008 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4010 /* cancel after data change */
4011 memset(&itema, 0, sizeof(itema));
4012 itema.pszText = test;
4013 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4016 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4017 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4018 ret = SetWindowText(hwndedit, test1);
4019 ok(ret != 0, "Expected edit text to change\n");
4020 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4022 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4023 memset(&itema, 0, sizeof(itema));
4024 itema.pszText = buff;
4025 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4026 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
4028 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4030 DestroyWindow(hwnd);
4033 static void test_mapidindex(void)
4038 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4039 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4040 ok(hwnd != NULL, "failed to create a listview window\n");
4041 insert_item(hwnd, 0);
4042 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4044 DestroyWindow(hwnd);
4046 hwnd = create_listview_control(LVS_REPORT);
4047 ok(hwnd != NULL, "failed to create a listview window\n");
4049 /* LVM_MAPINDEXTOID with invalid index */
4050 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4053 insert_item(hwnd, 0);
4054 insert_item(hwnd, 1);
4056 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
4058 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
4061 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4063 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4065 /* remove 0 indexed item, id retained */
4066 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
4067 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4069 /* new id starts from previous value */
4070 insert_item(hwnd, 1);
4071 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4074 /* get index by id */
4075 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4077 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4079 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4081 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4084 DestroyWindow(hwnd);
4087 static void test_getitemspacing(void)
4096 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4097 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4100 hwnd = create_listview_control(LVS_ICON);
4101 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4103 expect(cx, LOWORD(ret));
4104 expect(cy, HIWORD(ret));
4106 /* now try with icons */
4107 himl = ImageList_Create(40, 40, 0, 4, 4);
4108 ok(himl != NULL, "failed to create imagelist\n");
4109 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4110 ok(hbmp != NULL, "failed to create bitmap\n");
4111 ret = ImageList_Add(himl, hbmp, 0);
4113 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4116 itema.mask = LVIF_IMAGE;
4120 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4122 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4124 /* spacing + icon size returned */
4125 expect(cx + 40, LOWORD(ret));
4126 expect(cy + 40, HIWORD(ret));
4128 DestroyWindow(hwnd);
4130 hwnd = create_listview_control(LVS_SMALLICON);
4131 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4133 expect(cx, LOWORD(ret));
4134 expect(cy, HIWORD(ret));
4136 DestroyWindow(hwnd);
4138 hwnd = create_listview_control(LVS_REPORT);
4139 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4141 expect(cx, LOWORD(ret));
4142 expect(cy, HIWORD(ret));
4144 DestroyWindow(hwnd);
4146 hwnd = create_listview_control(LVS_LIST);
4147 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4149 expect(cx, LOWORD(ret));
4150 expect(cy, HIWORD(ret));
4152 DestroyWindow(hwnd);
4155 static void test_getcolumnwidth(void)
4164 /* default column width */
4165 hwnd = create_listview_control(LVS_ICON);
4166 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4168 style = GetWindowLong(hwnd, GWL_STYLE);
4169 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
4170 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4171 todo_wine expect(8, ret);
4172 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
4173 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
4175 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4177 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4179 DestroyWindow(hwnd);
4181 /* default column width with item added */
4182 hwnd = create_listview_control(LVS_LIST);
4183 memset(&itema, 0, sizeof(itema));
4184 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4185 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4187 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, ret);
4188 ReleaseDC(hwnd, hdc);
4189 DestroyWindow(hwnd);
4192 static void test_scrollnotify(void)
4197 hwnd = create_listview_control(LVS_REPORT);
4199 insert_column(hwnd, 0);
4200 insert_column(hwnd, 1);
4201 insert_item(hwnd, 0);
4203 /* make it scrollable - resize */
4204 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4206 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4209 /* try with dummy call */
4210 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4211 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
4213 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4214 "scroll notify 1", TRUE);
4216 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4217 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
4219 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4220 "scroll notify 2", TRUE);
4222 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4223 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4225 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4226 "scroll notify 3", TRUE);
4228 DestroyWindow(hwnd);
4231 static void test_LVS_EX_TRANSPARENTBKGND(void)
4237 hwnd = create_listview_control(LVS_REPORT);
4239 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4242 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4243 LVS_EX_TRANSPARENTBKGND);
4245 ret = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
4246 if (ret != CLR_NONE)
4248 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4249 DestroyWindow(hwnd);
4253 /* try to set some back color and check this style bit */
4254 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4256 ret = SendMessage(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4257 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4259 /* now test what this style actually does */
4260 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4261 LVS_EX_TRANSPARENTBKGND);
4263 hdc = GetWindowDC(hwndparent);
4265 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4266 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4267 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4268 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4270 ReleaseDC(hwndparent, hdc);
4272 DestroyWindow(hwnd);
4275 static void test_approximate_viewrect(void)
4282 static CHAR test[] = "abracadabra, a very long item label";
4284 hwnd = create_listview_control(LVS_ICON);
4285 himl = ImageList_Create(40, 40, 0, 4, 4);
4286 ok(himl != NULL, "failed to create imagelist\n");
4287 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4288 ok(hbmp != NULL, "failed to create bitmap\n");
4289 ret = ImageList_Add(himl, hbmp, 0);
4291 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4294 itema.mask = LVIF_IMAGE;
4298 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4301 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4305 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4309 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4310 ok(MAKELONG(77,827)==ret,"Incorrect Approximate rect\n");
4312 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4313 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4314 ok(MAKELONG(102,302)==ret,"Incorrect Approximate rect\n");
4316 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4317 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4319 itema.pszText = test;
4320 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4322 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4323 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4325 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4326 ok(MAKELONG(52,2)==ret,"Incorrect Approximate rect\n");
4327 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4328 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4329 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4330 ok(MAKELONG(102,52)==ret,"Incorrect Approximate rect\n");
4331 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4332 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4333 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4334 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4335 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4336 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4337 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4338 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4339 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4340 ok(MAKELONG(152,152)==ret,"Incorrect Approximate rect\n");
4342 DestroyWindow(hwnd);
4345 static void test_finditem(void)
4352 hwnd = create_listview_control(LVS_REPORT);
4353 insert_item(hwnd, 0);
4355 memset(&fi, 0, sizeof(fi));
4357 /* full string search, inserted text was "foo" */
4359 fi.flags = LVFI_STRING;
4361 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4363 /* partial string search, inserted text was "foo" */
4365 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4367 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4369 /* partial string search, part after start char */
4371 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4373 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4376 /* try with LVFI_SUBSTRING */
4378 fi.flags = LVFI_SUBSTRING;
4380 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4383 win_skip("LVFI_SUBSTRING not supported\n");
4384 DestroyWindow(hwnd);
4389 fi.flags = LVFI_SUBSTRING;
4391 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4394 fi.flags = LVFI_SUBSTRING;
4396 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4400 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
4402 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4405 DestroyWindow(hwnd);
4408 static void test_LVS_EX_HEADERINALLVIEWS(void)
4413 hwnd = create_listview_control(LVS_ICON);
4415 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4416 LVS_EX_HEADERINALLVIEWS);
4418 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4419 if (!IsWindow(header))
4421 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4422 DestroyWindow(hwnd);
4426 /* LVS_NOCOLUMNHEADER works as before */
4427 style = GetWindowLongA(hwnd, GWL_STYLE);
4428 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
4429 style = GetWindowLongA(header, GWL_STYLE);
4430 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
4431 style = GetWindowLongA(hwnd, GWL_STYLE);
4432 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
4433 style = GetWindowLongA(header, GWL_STYLE);
4434 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
4436 /* try to remove style */
4437 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
4438 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4439 ok(IsWindow(header), "Expected header to be created\n");
4440 style = GetWindowLongA(header, GWL_STYLE);
4441 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
4443 DestroyWindow(hwnd);
4445 /* check other styles */
4446 hwnd = create_listview_control(LVS_LIST);
4447 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4448 LVS_EX_HEADERINALLVIEWS);
4449 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4450 ok(IsWindow(header), "Expected header to be created\n");
4451 DestroyWindow(hwnd);
4453 hwnd = create_listview_control(LVS_SMALLICON);
4454 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4455 LVS_EX_HEADERINALLVIEWS);
4456 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4457 ok(IsWindow(header), "Expected header to be created\n");
4458 DestroyWindow(hwnd);
4460 hwnd = create_listview_control(LVS_REPORT);
4461 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4462 LVS_EX_HEADERINALLVIEWS);
4463 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4464 ok(IsWindow(header), "Expected header to be created\n");
4465 DestroyWindow(hwnd);
4468 static void test_hover(void)
4473 hwnd = create_listview_control(LVS_ICON);
4475 /* test WM_MOUSEHOVER forwarding */
4476 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4477 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4479 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
4480 g_block_hover = TRUE;
4481 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4482 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4484 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
4485 g_block_hover = FALSE;
4487 r = SendMessage(hwnd, LVM_SETHOVERTIME, 0, 500);
4488 expect(HOVER_DEFAULT, r);
4489 r = SendMessage(hwnd, LVM_GETHOVERTIME, 0, 0);
4492 DestroyWindow(hwnd);
4495 static void test_destroynotify(void)
4499 hwnd = create_listview_control(LVS_REPORT);
4500 ok(hwnd != NULL, "failed to create listview window\n");
4502 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4503 DestroyWindow(hwnd);
4504 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
4507 static void test_header_notification(void)
4515 list = create_listview_control(LVS_REPORT);
4516 ok(list != 0, "failed to create listview window\n");
4518 memset(&col, 0, sizeof(col));
4519 col.mask = LVCF_WIDTH;
4521 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4522 ok(!ret, "expected 0, got %ld\n", ret);
4524 header = subclass_header(list);
4526 ret = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
4527 ok(ret == 1, "expected header item count 1, got %ld\n", ret);
4529 memset(&item, 0, sizeof(item));
4530 item.mask = HDI_WIDTH;
4531 ret = SendMessage(header, HDM_GETITEMA, 0, (LPARAM)&item);
4532 ok(ret, "HDM_GETITEM failed\n");
4533 ok(item.cxy == 100, "expected 100, got %d\n", item.cxy);
4535 nmh.hdr.hwndFrom = header;
4536 nmh.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
4537 nmh.hdr.code = HDN_ITEMCHANGEDA;
4540 item.mask = HDI_WIDTH;
4543 ret = SendMessage(list, WM_NOTIFY, 0, (LPARAM)&nmh);
4544 ok(!ret, "WM_NOTIFY/HDN_ITEMCHANGED failed\n");
4546 DestroyWindow(list);
4549 static void test_createdragimage(void)
4555 list = create_listview_control(LVS_ICON);
4556 ok(list != 0, "failed to create listview window\n");
4558 insert_item(list, 0);
4561 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
4562 ok(himl == NULL, "got %p\n", himl);
4564 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
4565 ok(himl != NULL, "got %p\n", himl);
4566 ImageList_Destroy(himl);
4568 DestroyWindow(list);
4571 static void test_dispinfo(void)
4573 static const char testA[] = "TEST";
4579 hwnd = create_listview_control(LVS_ICON);
4580 ok(hwnd != 0, "failed to create listview window\n");
4582 insert_item(hwnd, 0);
4584 memset(&item, 0, sizeof(item));
4585 item.pszText = LPSTR_TEXTCALLBACKA;
4586 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4587 ok(ret, "got %d\n", ret);
4589 g_disp_A_to_W = TRUE;
4590 item.pszText = (char*)buff;
4591 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
4592 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4593 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
4594 g_disp_A_to_W = FALSE;
4596 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
4597 "got %s, expected %s\n", item.pszText, testA);
4599 DestroyWindow(hwnd);
4602 START_TEST(listview)
4605 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
4607 ULONG_PTR ctx_cookie;
4611 hComctl32 = GetModuleHandleA("comctl32.dll");
4612 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
4613 if (pInitCommonControlsEx)
4615 INITCOMMONCONTROLSEX iccex;
4616 iccex.dwSize = sizeof(iccex);
4617 iccex.dwICC = ICC_LISTVIEW_CLASSES;
4618 pInitCommonControlsEx(&iccex);
4621 InitCommonControls();
4623 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
4625 hwndparent = create_parent_window(FALSE);
4626 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4628 g_is_below_5 = is_below_comctl_5();
4630 test_header_notification();
4637 test_icon_spacing();
4640 test_item_position();
4645 test_subitem_rect();
4649 test_nosortheader();
4653 test_getitemposition();
4654 test_columnscreation();
4656 test_notifyformat();
4658 test_getitemspacing();
4659 test_getcolumnwidth();
4660 test_approximate_viewrect();
4663 test_destroynotify();
4664 test_createdragimage();
4667 if (!load_v6_module(&ctx_cookie, &hCtx))
4669 DestroyWindow(hwndparent);
4673 /* this is a XP SP3 failure workaround */
4674 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
4675 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
4677 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
4678 if (!IsWindow(hwnd))
4680 win_skip("FIXME: failed to create ListView window.\n");
4681 unload_v6_module(ctx_cookie, hCtx);
4682 DestroyWindow(hwndparent);
4686 DestroyWindow(hwnd);
4688 /* comctl32 version 6 tests start here */
4689 test_get_set_view();
4690 test_canceleditlabel();
4692 test_scrollnotify();
4693 test_LVS_EX_TRANSPARENTBKGND();
4694 test_LVS_EX_HEADERINALLVIEWS();
4696 unload_v6_module(ctx_cookie, hCtx);
4698 DestroyWindow(hwndparent);