4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009-2013 Nikolay Sivov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
31 #define PARENT_SEQ_INDEX 0
32 #define PARENT_FULL_SEQ_INDEX 1
33 #define LISTVIEW_SEQ_INDEX 2
34 #define EDITBOX_SEQ_INDEX 3
35 #define COMBINED_SEQ_INDEX 4
36 #define NUM_MSG_SEQUENCES 5
41 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
42 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
43 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
45 static const WCHAR testparentclassW[] =
46 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
48 static HWND hwndparent, hwndparentW;
49 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
50 static BOOL blockEdit;
51 /* return nonzero on NM_HOVER */
52 static BOOL g_block_hover;
53 /* notification data for LVN_ITEMCHANGED */
54 static NMLISTVIEW g_nmlistview;
55 /* notification data for LVN_ITEMCHANGING */
56 static NMLISTVIEW g_nmlistview_changing;
57 /* format reported to control:
58 -1 falls to defproc, anything else returned */
59 static INT notifyFormat;
60 /* indicates we're running < 5.80 version */
61 static BOOL g_is_below_5;
62 /* item data passed to LVN_GETDISPINFOA */
63 static LVITEMA g_itema;
64 /* alter notification code A->W */
65 static BOOL g_disp_A_to_W;
66 /* dispinfo data sent with LVN_LVN_ENDLABELEDIT */
67 static NMLVDISPINFO g_editbox_disp_info;
68 /* when this is set focus will be tested on LVN_DELETEITEM */
69 static BOOL g_focus_test_LVN_DELETEITEM;
71 static HWND subclass_editbox(HWND hwndListview);
73 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
75 static const struct message create_ownerdrawfixed_parent_seq[] = {
76 { WM_NOTIFYFORMAT, sent },
77 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
78 { WM_MEASUREITEM, sent },
79 { WM_PARENTNOTIFY, sent },
83 static const struct message redraw_listview_seq[] = {
84 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
85 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
86 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
87 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
88 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
89 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
90 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
94 static const struct message listview_icon_spacing_seq[] = {
95 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
96 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
97 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
101 static const struct message listview_color_seq[] = {
102 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
103 { LVM_GETBKCOLOR, sent },
104 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
105 { LVM_GETTEXTCOLOR, sent },
106 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
107 { LVM_GETTEXTBKCOLOR, sent },
109 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
110 { LVM_GETBKCOLOR, sent },
111 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
112 { LVM_GETTEXTCOLOR, sent },
113 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
114 { LVM_GETTEXTBKCOLOR, sent },
116 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
117 { LVM_GETBKCOLOR, sent },
118 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
119 { LVM_GETTEXTCOLOR, sent },
120 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
121 { LVM_GETTEXTBKCOLOR, sent },
123 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
124 { LVM_GETBKCOLOR, sent },
125 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
126 { LVM_GETTEXTCOLOR, sent },
127 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
128 { LVM_GETTEXTBKCOLOR, sent },
132 static const struct message listview_item_count_seq[] = {
133 { LVM_GETITEMCOUNT, sent },
134 { LVM_INSERTITEM, sent },
135 { LVM_INSERTITEM, sent },
136 { LVM_INSERTITEM, sent },
137 { LVM_GETITEMCOUNT, sent },
138 { LVM_DELETEITEM, sent|wparam, 2 },
139 { WM_NCPAINT, sent|optional },
140 { WM_ERASEBKGND, sent|optional },
141 { LVM_GETITEMCOUNT, sent },
142 { LVM_DELETEALLITEMS, sent },
143 { LVM_GETITEMCOUNT, sent },
144 { LVM_INSERTITEM, sent },
145 { LVM_INSERTITEM, sent },
146 { LVM_GETITEMCOUNT, sent },
147 { LVM_INSERTITEM, sent },
148 { LVM_GETITEMCOUNT, sent },
152 static const struct message listview_itempos_seq[] = {
153 { LVM_INSERTITEM, sent },
154 { LVM_INSERTITEM, sent },
155 { LVM_INSERTITEM, sent },
156 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
157 { WM_NCPAINT, sent|optional },
158 { WM_ERASEBKGND, sent|optional },
159 { LVM_GETITEMPOSITION, sent|wparam, 1 },
160 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
161 { LVM_GETITEMPOSITION, sent|wparam, 2 },
162 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
163 { LVM_GETITEMPOSITION, sent|wparam, 0 },
167 static const struct message listview_ownerdata_switchto_seq[] = {
168 { WM_STYLECHANGING, sent },
169 { WM_STYLECHANGED, sent },
173 static const struct message listview_getorderarray_seq[] = {
174 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
175 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
179 static const struct message empty_seq[] = {
183 static const struct message forward_erasebkgnd_parent_seq[] = {
184 { WM_ERASEBKGND, sent },
188 static const struct message ownderdata_select_focus_parent_seq[] = {
189 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
190 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
191 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
195 static const struct message ownerdata_setstate_all_parent_seq[] = {
196 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
200 static const struct message ownerdata_defocus_all_parent_seq[] = {
201 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
202 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
203 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
204 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
208 static const struct message ownerdata_deselect_all_parent_seq[] = {
209 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
210 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
214 static const struct message change_all_parent_seq[] = {
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 },
224 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
225 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
227 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
228 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
232 static const struct message changing_all_parent_seq[] = {
233 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
234 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
235 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
236 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
237 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
241 static const struct message textcallback_set_again_parent_seq[] = {
242 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
243 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
247 static const struct message single_getdispinfo_parent_seq[] = {
248 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
252 static const struct message getitemposition_seq1[] = {
253 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
257 static const struct message getitemposition_seq2[] = {
258 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
259 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
263 static const struct message getsubitemrect_seq[] = {
264 { LVM_GETSUBITEMRECT, sent|id|wparam, -1, 0, LISTVIEW_ID },
265 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
266 { LVM_GETSUBITEMRECT, sent|id|wparam, 0, 0, LISTVIEW_ID },
267 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
268 { LVM_GETSUBITEMRECT, sent|id|wparam, -10, 0, LISTVIEW_ID },
269 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
270 { LVM_GETSUBITEMRECT, sent|id|wparam, 20, 0, LISTVIEW_ID },
271 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
275 static const struct message editbox_create_pos[] = {
276 /* sequence sent after LVN_BEGINLABELEDIT */
277 /* next two are 4.7x specific */
278 { WM_WINDOWPOSCHANGING, sent },
279 { WM_WINDOWPOSCHANGED, sent|optional },
281 { WM_WINDOWPOSCHANGING, sent|optional },
282 { WM_NCCALCSIZE, sent },
283 { WM_WINDOWPOSCHANGED, sent },
284 { WM_MOVE, sent|defwinproc },
285 { WM_SIZE, sent|defwinproc },
286 /* the rest is todo, skipped in 4.7x */
287 { WM_WINDOWPOSCHANGING, sent|optional },
288 { WM_WINDOWPOSCHANGED, sent|optional },
292 static const struct message scroll_parent_seq[] = {
293 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
294 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
298 static const struct message setredraw_seq[] = {
299 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
303 static const struct message lvs_ex_transparentbkgnd_seq[] = {
304 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
308 static const struct message edit_end_nochange[] = {
309 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
310 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW }, /* todo */
311 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
315 static const struct message hover_parent[] = {
316 { WM_GETDLGCODE, sent }, /* todo_wine */
317 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
321 static const struct message listview_destroy[] = {
322 { 0x0090, sent|optional }, /* Vista */
323 { WM_PARENTNOTIFY, sent },
324 { WM_SHOWWINDOW, sent },
325 { WM_WINDOWPOSCHANGING, sent },
326 { WM_WINDOWPOSCHANGED, sent|optional },
327 { WM_DESTROY, sent },
328 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
329 { WM_NCDESTROY, sent },
333 static const struct message listview_header_changed_seq[] = {
334 { LVM_SETCOLUMNA, sent },
335 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
336 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
340 static const struct message parent_header_click_seq[] = {
341 { WM_NOTIFY, sent|id, 0, 0, LVN_COLUMNCLICK },
342 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCLICKA },
346 static const struct message parent_header_divider_dclick_seq[] = {
347 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGINGA },
348 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
349 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
350 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGEDA },
351 { WM_NOTIFY, sent|id, 0, 0, HDN_DIVIDERDBLCLICKA },
355 static const struct message listview_set_imagelist[] = {
356 { LVM_SETIMAGELIST, sent|id, 0, 0, LISTVIEW_ID },
360 static const struct message listview_header_set_imagelist[] = {
361 { LVM_SETIMAGELIST, sent|id, 0, 0, LISTVIEW_ID },
362 { HDM_SETIMAGELIST, sent|id, 0, 0, HEADER_ID },
366 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
368 static LONG defwndproc_counter = 0;
372 msg.message = message;
373 msg.flags = sent|wparam|lparam;
374 if (defwndproc_counter) msg.flags |= defwinproc;
377 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
379 /* log system messages, except for painting */
380 if (message < WM_USER &&
381 message != WM_PAINT &&
382 message != WM_ERASEBKGND &&
383 message != WM_NCPAINT &&
384 message != WM_NCHITTEST &&
385 message != WM_GETTEXT &&
386 message != WM_GETICON &&
387 message != WM_DEVICECHANGE)
389 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
391 add_message(sequences, PARENT_SEQ_INDEX, &msg);
392 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
394 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
400 switch (((NMHDR*)lParam)->code)
402 case LVN_BEGINLABELEDIT:
406 /* subclass edit box */
408 edit = subclass_editbox(((NMHDR*)lParam)->hwndFrom);
412 INT len = SendMessageA(edit, EM_GETLIMITTEXT, 0, 0);
413 ok(len == 259 || broken(len == 260) /* includes NULL in NT4 */,
414 "text limit %d, expected 259\n", len);
419 case LVN_ENDLABELEDIT:
423 /* always accept new item text */
424 NMLVDISPINFO *di = (NMLVDISPINFO*)lParam;
425 g_editbox_disp_info = *di;
426 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText ? di->item.pszText : "(null)");
428 /* edit control still available from this notification */
429 edit = (HWND)SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETEDITCONTROL, 0, 0);
430 ok(IsWindow(edit), "expected valid edit control handle\n");
431 ok((GetWindowLongA(edit, GWL_STYLE) & ES_MULTILINE) == 0, "edit is multiline\n");
435 case LVN_BEGINSCROLL:
438 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
440 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
441 "BEGIN" : "END", pScroll->dx, pScroll->dy);
444 case LVN_ITEMCHANGING:
446 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
447 g_nmlistview_changing = *nmlv;
450 case LVN_ITEMCHANGED:
452 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
453 g_nmlistview = *nmlv;
456 case LVN_GETDISPINFOA:
458 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
459 g_itema = dispinfo->item;
461 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
463 static const WCHAR testW[] = {'T','E','S','T',0};
464 dispinfo->hdr.code = LVN_GETDISPINFOW;
465 memcpy(dispinfo->item.pszText, testW, sizeof(testW));
468 /* test control buffer size for text, 10 used to mask cases when control
469 is using caller buffer to process LVM_GETITEM for example */
470 if (dispinfo->item.mask & LVIF_TEXT && dispinfo->item.cchTextMax > 10)
471 ok(dispinfo->item.cchTextMax == 260 ||
472 broken(dispinfo->item.cchTextMax == 264) /* NT4 reports aligned size */,
473 "buffer size %d\n", dispinfo->item.cchTextMax);
477 if (g_focus_test_LVN_DELETEITEM)
479 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
482 state = SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETITEMSTATE, nmlv->iItem, LVIS_FOCUSED);
483 ok(state == 0, "got state %x\n", state);
487 if (g_block_hover) return 1;
492 case WM_NOTIFYFORMAT:
494 /* force to return format */
495 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
500 defwndproc_counter++;
501 ret = DefWindowProcA(hwnd, message, wParam, lParam);
502 defwndproc_counter--;
507 static BOOL register_parent_wnd_class(BOOL Unicode)
515 clsW.lpfnWndProc = parent_wnd_proc;
518 clsW.hInstance = GetModuleHandleW(NULL);
520 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
521 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
522 clsW.lpszMenuName = NULL;
523 clsW.lpszClassName = testparentclassW;
528 clsA.lpfnWndProc = parent_wnd_proc;
531 clsA.hInstance = GetModuleHandleA(NULL);
533 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
534 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
535 clsA.lpszMenuName = NULL;
536 clsA.lpszClassName = "Listview test parent class";
539 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
542 static HWND create_parent_window(BOOL Unicode)
544 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
547 if (!register_parent_wnd_class(Unicode))
554 hwnd = CreateWindowExW(0, testparentclassW, nameW,
555 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
556 WS_MAXIMIZEBOX | WS_VISIBLE,
558 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
560 hwnd = CreateWindowExA(0, "Listview test parent class",
561 "Listview test parent window",
562 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
563 WS_MAXIMIZEBOX | WS_VISIBLE,
565 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
566 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
570 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
572 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
573 static LONG defwndproc_counter = 0;
577 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
579 /* some debug output for style changing */
580 if ((message == WM_STYLECHANGING ||
581 message == WM_STYLECHANGED) && lParam)
583 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
584 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
587 msg.message = message;
588 msg.flags = sent|wparam|lparam;
589 if (defwndproc_counter) msg.flags |= defwinproc;
592 msg.id = LISTVIEW_ID;
593 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
594 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
596 defwndproc_counter++;
597 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
598 defwndproc_counter--;
602 static HWND create_listview_control(DWORD style)
608 GetClientRect(hwndparent, &rect);
609 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
610 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
611 0, 0, rect.right, rect.bottom,
612 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
613 ok(hwnd != NULL, "gle=%d\n", GetLastError());
615 if (!hwnd) return NULL;
617 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
618 (LONG_PTR)listview_subclass_proc);
619 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
624 /* unicode listview window with specified parent */
625 static HWND create_listview_controlW(DWORD style, HWND parent)
630 static const WCHAR nameW[] = {'f','o','o',0};
632 GetClientRect(parent, &rect);
633 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
634 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
635 0, 0, rect.right, rect.bottom,
636 parent, NULL, GetModuleHandleW(NULL), NULL);
637 ok(hwnd != NULL, "gle=%d\n", GetLastError());
639 if (!hwnd) return NULL;
641 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
642 (LONG_PTR)listview_subclass_proc);
643 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
648 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
650 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
651 static LONG defwndproc_counter = 0;
655 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
657 msg.message = message;
658 msg.flags = sent|wparam|lparam;
659 if (defwndproc_counter) msg.flags |= defwinproc;
663 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
665 defwndproc_counter++;
666 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
667 defwndproc_counter--;
671 static HWND subclass_header(HWND hwndListview)
676 hwnd = ListView_GetHeader(hwndListview);
677 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
678 (LONG_PTR)header_subclass_proc);
679 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
684 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
686 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
687 static LONG defwndproc_counter = 0;
691 msg.message = message;
692 msg.flags = sent|wparam|lparam;
693 if (defwndproc_counter) msg.flags |= defwinproc;
698 /* all we need is sizing */
699 if (message == WM_WINDOWPOSCHANGING ||
700 message == WM_NCCALCSIZE ||
701 message == WM_WINDOWPOSCHANGED ||
702 message == WM_MOVE ||
705 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
708 defwndproc_counter++;
709 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
710 defwndproc_counter--;
714 static HWND subclass_editbox(HWND hwndListview)
719 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
720 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
721 (LONG_PTR)editbox_subclass_proc);
722 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
727 /* Performs a single LVM_HITTEST test */
728 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
729 BOOL todo_item, BOOL todo_flags, int line)
738 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
744 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
745 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
746 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
751 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
752 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
753 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
759 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
761 else if (broken_flags)
762 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
763 "Expected flags %x, got %x\n", flags, lpht.flags);
765 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
768 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
770 /* Performs a single LVM_SUBITEMHITTEST test */
771 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
772 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
780 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
786 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
787 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
792 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
793 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
799 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
802 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
807 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
810 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
813 #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__)
815 static void test_images(void)
823 static CHAR hello[] = "hello";
825 himl = ImageList_Create(40, 40, 0, 4, 4);
826 ok(himl != NULL, "failed to create imagelist\n");
828 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
829 ok(hbmp != NULL, "failed to create bitmap\n");
831 r = ImageList_Add(himl, hbmp, 0);
832 ok(r == 0, "should be zero\n");
834 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
835 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
836 ok(hwnd != NULL, "failed to create listview window\n");
838 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
839 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
841 ok(r == 0, "should return zero\n");
843 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
844 ok(r == 0, "should return zero\n");
846 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
847 ok(r != 0, "got 0\n");
849 /* returns dimensions */
851 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
852 ok(r == 0, "should be zero items\n");
854 item.mask = LVIF_IMAGE | LVIF_TEXT;
859 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
860 ok(r == -1, "should fail\n");
863 item.pszText = hello;
864 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
865 ok(r == 0, "should not fail\n");
867 memset(&r1, 0, sizeof r1);
869 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
872 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
873 ok(r == TRUE, "should not fail\n");
876 item.pszText = hello;
877 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
878 ok(r == 0, "should not fail\n");
880 memset(&r2, 0, sizeof r2);
882 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
885 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
890 static void test_checkboxes(void)
895 static CHAR text[] = "Text",
899 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
900 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
901 ok(hwnd != NULL, "failed to create listview window\n");
903 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
904 item.mask = LVIF_TEXT | LVIF_STATE;
905 item.stateMask = 0xffff;
910 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
914 item.mask = LVIF_STATE;
915 item.stateMask = 0xffff;
916 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
918 ok(item.state == 0xfccc, "state %x\n", item.state);
920 /* Don't set LVIF_STATE */
921 item.mask = LVIF_TEXT;
922 item.stateMask = 0xffff;
927 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
931 item.mask = LVIF_STATE;
932 item.stateMask = 0xffff;
933 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
935 ok(item.state == 0, "state %x\n", item.state);
937 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
940 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
942 item.mask = LVIF_STATE;
943 item.stateMask = 0xffff;
944 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
946 if (item.state != 0x1ccc)
948 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
953 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
955 item.mask = LVIF_TEXT;
957 item.pszText = text2;
958 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
962 item.mask = LVIF_STATE;
963 item.stateMask = 0xffff;
964 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
966 ok(item.state == 0x1000, "state %x\n", item.state);
968 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
970 item.mask = LVIF_TEXT | LVIF_STATE;
971 item.stateMask = 0xffff;
973 item.pszText = text3;
974 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
978 item.mask = LVIF_STATE;
979 item.stateMask = 0xffff;
980 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
982 ok(item.state == 0x1aaa, "state %x\n", item.state);
984 /* Set an item's state to checked */
986 item.mask = LVIF_STATE;
987 item.stateMask = 0xf000;
989 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
993 item.mask = LVIF_STATE;
994 item.stateMask = 0xffff;
995 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
997 ok(item.state == 0x2aaa, "state %x\n", item.state);
999 /* Check that only the bits we asked for are returned,
1000 * and that all the others are set to zero
1003 item.mask = LVIF_STATE;
1004 item.stateMask = 0xf000;
1005 item.state = 0xffff;
1006 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1008 ok(item.state == 0x2000, "state %x\n", item.state);
1010 /* Set the style again and check that doesn't change an item's state */
1011 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1012 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1015 item.mask = LVIF_STATE;
1016 item.stateMask = 0xffff;
1017 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1019 ok(item.state == 0x2aaa, "state %x\n", item.state);
1021 /* Unsetting the checkbox extended style doesn't change an item's state */
1022 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
1023 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1026 item.mask = LVIF_STATE;
1027 item.stateMask = 0xffff;
1028 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1030 ok(item.state == 0x2aaa, "state %x\n", item.state);
1032 /* Now setting the style again will change an item's state */
1033 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1037 item.mask = LVIF_STATE;
1038 item.stateMask = 0xffff;
1039 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1041 ok(item.state == 0x1aaa, "state %x\n", item.state);
1043 /* Toggle checkbox tests (bug 9934) */
1044 memset (&item, 0xcc, sizeof(item));
1045 item.mask = LVIF_STATE;
1048 item.state = LVIS_FOCUSED;
1049 item.stateMask = LVIS_FOCUSED;
1050 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1054 item.mask = LVIF_STATE;
1055 item.stateMask = 0xffff;
1056 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1058 ok(item.state == 0x1aab, "state %x\n", item.state);
1060 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1062 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
1066 item.mask = LVIF_STATE;
1067 item.stateMask = 0xffff;
1068 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1070 ok(item.state == 0x2aab, "state %x\n", item.state);
1072 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1074 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
1078 item.mask = LVIF_STATE;
1079 item.stateMask = 0xffff;
1080 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1082 ok(item.state == 0x1aab, "state %x\n", item.state);
1084 DestroyWindow(hwnd);
1087 static void insert_column(HWND hwnd, int idx)
1092 memset(&column, 0xcc, sizeof(column));
1093 column.mask = LVCF_SUBITEM;
1094 column.iSubItem = idx;
1096 rc = ListView_InsertColumn(hwnd, idx, &column);
1100 static void insert_item(HWND hwnd, int idx)
1102 static CHAR text[] = "foo";
1107 memset(&item, 0xcc, sizeof (item));
1108 item.mask = LVIF_TEXT;
1111 item.pszText = text;
1113 rc = ListView_InsertItem(hwnd, &item);
1117 static void test_items(void)
1119 const LPARAM lparamTest = 0x42;
1120 static CHAR text[] = "Text";
1126 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1127 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1128 ok(hwnd != NULL, "failed to create listview window\n");
1131 * Test setting/getting item params
1134 /* Set up two columns */
1135 insert_column(hwnd, 0);
1136 insert_column(hwnd, 1);
1138 /* LVIS_SELECTED with zero stateMask */
1140 memset (&item, 0, sizeof (item));
1141 item.mask = LVIF_STATE;
1142 item.state = LVIS_SELECTED;
1146 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1149 memset (&item, 0xcc, sizeof (item));
1150 item.mask = LVIF_STATE;
1151 item.stateMask = LVIS_SELECTED;
1155 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1157 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1158 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1160 /* LVIS_SELECTED with zero stateMask */
1162 memset (&item, 0, sizeof (item));
1163 item.mask = LVIF_STATE;
1164 item.state = LVIS_FOCUSED;
1168 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1171 memset (&item, 0xcc, sizeof (item));
1172 item.mask = LVIF_STATE;
1173 item.stateMask = LVIS_FOCUSED;
1177 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1179 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1180 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1182 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1184 memset (&item, 0, sizeof (item));
1185 item.mask = LVIF_STATE;
1186 item.state = LVIS_CUT;
1187 item.stateMask = LVIS_FOCUSED;
1190 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1193 memset (&item, 0xcc, sizeof (item));
1194 item.mask = LVIF_STATE;
1195 item.stateMask = LVIS_CUT;
1199 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1201 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1202 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1204 /* Insert an item with just a param */
1205 memset (&item, 0xcc, sizeof (item));
1206 item.mask = LVIF_PARAM;
1209 item.lParam = lparamTest;
1210 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1213 /* Test getting of the param */
1214 memset (&item, 0xcc, sizeof (item));
1215 item.mask = LVIF_PARAM;
1218 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1220 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1222 /* Set up a subitem */
1223 memset (&item, 0xcc, sizeof (item));
1224 item.mask = LVIF_TEXT;
1227 item.pszText = text;
1228 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1231 item.mask = LVIF_TEXT;
1234 item.pszText = buffA;
1235 item.cchTextMax = sizeof(buffA);
1236 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1238 ok(!memcmp(item.pszText, text, sizeof(text)), "got text %s, expected %s\n", item.pszText, text);
1240 /* set up with extra flag */
1241 /* 1. reset subitem text */
1242 item.mask = LVIF_TEXT;
1245 item.pszText = NULL;
1246 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1249 item.mask = LVIF_TEXT;
1252 item.pszText = buffA;
1254 item.cchTextMax = sizeof(buffA);
1255 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1257 ok(item.pszText[0] == 0, "got %p\n", item.pszText);
1259 /* 2. set new text with extra flag specified */
1260 item.mask = LVIF_TEXT | LVIF_DI_SETITEM;
1263 item.pszText = text;
1264 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1265 ok(r == 1 || broken(r == 0) /* NT4 */, "ret %d\n", r);
1269 item.mask = LVIF_TEXT;
1272 item.pszText = buffA;
1274 item.cchTextMax = sizeof(buffA);
1275 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1277 ok(!memcmp(item.pszText, text, sizeof(text)), "got %s, expected %s\n", item.pszText, text);
1280 /* Query param from subitem: returns main item param */
1281 memset (&item, 0xcc, sizeof (item));
1282 item.mask = LVIF_PARAM;
1285 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1287 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1289 /* Set up param on first subitem: no effect */
1290 memset (&item, 0xcc, sizeof (item));
1291 item.mask = LVIF_PARAM;
1294 item.lParam = lparamTest+1;
1295 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1298 /* Query param from subitem again: should still return main item param */
1299 memset (&item, 0xcc, sizeof (item));
1300 item.mask = LVIF_PARAM;
1303 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1305 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1307 /**** Some tests of state highlighting ****/
1308 memset (&item, 0xcc, sizeof (item));
1309 item.mask = LVIF_STATE;
1312 item.state = LVIS_SELECTED;
1313 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1314 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1317 item.state = LVIS_DROPHILITED;
1318 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1321 memset (&item, 0xcc, sizeof (item));
1322 item.mask = LVIF_STATE;
1325 item.stateMask = -1;
1326 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1328 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1330 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1332 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1334 /* some notnull but meaningless masks */
1335 memset (&item, 0, sizeof(item));
1336 item.mask = LVIF_NORECOMPUTE;
1339 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1341 memset (&item, 0, sizeof(item));
1342 item.mask = LVIF_DI_SETITEM;
1345 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1348 /* set text to callback value already having it */
1349 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1351 memset (&item, 0, sizeof (item));
1352 item.mask = LVIF_TEXT;
1353 item.pszText = LPSTR_TEXTCALLBACK;
1355 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1357 memset (&item, 0, sizeof (item));
1359 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1361 item.pszText = LPSTR_TEXTCALLBACK;
1362 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1365 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1366 "check callback text comparison rule", FALSE);
1368 DestroyWindow(hwnd);
1371 static void test_columns(void)
1380 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1381 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1382 ok(hwnd != NULL, "failed to create listview window\n");
1384 /* Add a column with no mask */
1385 memset(&column, 0xcc, sizeof(column));
1387 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1388 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1390 /* Check its width */
1391 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1392 ok(rc == 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1394 DestroyWindow(hwnd);
1396 /* LVM_GETCOLUMNORDERARRAY */
1397 hwnd = create_listview_control(LVS_REPORT);
1398 subclass_header(hwnd);
1400 memset(&column, 0, sizeof(column));
1401 column.mask = LVCF_WIDTH;
1403 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1407 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1410 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1412 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1414 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1415 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1417 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1419 /* after column added subitem is considered as present */
1420 insert_item(hwnd, 0);
1422 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1424 item.pszText = buff;
1425 item.cchTextMax = sizeof(buff);
1428 item.mask = LVIF_TEXT;
1429 memset(&g_itema, 0, sizeof(g_itema));
1430 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1432 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1434 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1435 "get subitem text after column added", FALSE);
1437 DestroyWindow(hwnd);
1440 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1441 static WNDPROC listviewWndProc;
1442 static HIMAGELIST test_create_imagelist;
1444 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1448 if (uMsg == WM_CREATE)
1450 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1451 lpcs->style |= LVS_REPORT;
1453 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1454 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1458 static void test_create(void)
1469 cls.cbSize = sizeof(WNDCLASSEX);
1470 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1471 listviewWndProc = cls.lpfnWndProc;
1472 cls.lpfnWndProc = create_test_wndproc;
1473 cls.lpszClassName = "MyListView32";
1474 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1476 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1477 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1478 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1479 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1481 if (!IsWindow(hHeader))
1484 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1485 DestroyWindow(hList);
1489 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1490 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1491 DestroyWindow(hList);
1493 /* header isn't created on LVS_ICON and LVS_LIST styles */
1494 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1495 GetModuleHandle(NULL), 0);
1496 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1497 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1498 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1500 memset(&col, 0, sizeof(LVCOLUMNA));
1501 col.mask = LVCF_WIDTH;
1503 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1505 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1506 ok(IsWindow(hHeader), "Header should be created\n");
1507 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1508 style = GetWindowLong(hHeader, GWL_STYLE);
1509 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1510 DestroyWindow(hList);
1512 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1513 GetModuleHandle(NULL), 0);
1514 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1515 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1516 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1518 memset(&col, 0, sizeof(LVCOLUMNA));
1519 col.mask = LVCF_WIDTH;
1521 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1523 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1524 ok(IsWindow(hHeader), "Header should be created\n");
1525 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1526 DestroyWindow(hList);
1528 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1529 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1530 GetModuleHandle(NULL), 0);
1531 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1532 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1533 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1534 ok(IsWindow(hHeader), "Header should be created\n");
1535 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1536 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1537 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1538 ok(IsWindow(hHeader), "Header should be created\n");
1539 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1540 DestroyWindow(hList);
1542 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1543 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1544 GetModuleHandle(NULL), 0);
1545 ret = SetWindowLongPtr(hList, GWL_STYLE,
1546 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1547 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1548 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1549 ok(IsWindow(hHeader), "Header should be created\n");
1550 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1551 ret = SetWindowLongPtr(hList, GWL_STYLE,
1552 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1553 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1554 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1555 ok(IsWindow(hHeader), "Header should be created\n");
1556 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1557 DestroyWindow(hList);
1559 /* LVS_REPORT without WS_VISIBLE */
1560 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1561 GetModuleHandle(NULL), 0);
1562 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1563 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1564 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1566 memset(&col, 0, sizeof(LVCOLUMNA));
1567 col.mask = LVCF_WIDTH;
1569 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1571 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1572 ok(IsWindow(hHeader), "Header should be created\n");
1573 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1574 DestroyWindow(hList);
1576 /* LVS_REPORT without WS_VISIBLE, try to show it */
1577 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1578 GetModuleHandle(NULL), 0);
1579 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1580 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1581 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1582 ShowWindow(hList, SW_SHOW);
1583 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1584 ok(IsWindow(hHeader), "Header should be created\n");
1585 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1586 DestroyWindow(hList);
1588 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1589 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1590 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1591 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1592 ok(IsWindow(hHeader), "Header should be created\n");
1593 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1594 /* HDS_DRAGDROP set by default */
1595 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1596 DestroyWindow(hList);
1598 /* setting LVS_EX_HEADERDRAGDROP creates header */
1599 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1600 GetModuleHandle(NULL), 0);
1601 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1602 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1603 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1604 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1605 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1606 ok(IsWindow(hHeader) ||
1607 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1608 "Header should be created\n");
1609 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1610 DestroyWindow(hList);
1612 /* setting LVS_EX_GRIDLINES creates header */
1613 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1614 GetModuleHandle(NULL), 0);
1615 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1616 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1617 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1618 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_GRIDLINES);
1619 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1620 ok(IsWindow(hHeader) ||
1621 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1622 "Header should be created\n");
1623 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1624 DestroyWindow(hList);
1626 /* setting LVS_EX_FULLROWSELECT creates header */
1627 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1628 GetModuleHandle(NULL), 0);
1629 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1630 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1631 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1632 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
1633 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1634 ok(IsWindow(hHeader) ||
1635 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1636 "Header should be created\n");
1637 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1638 DestroyWindow(hList);
1640 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1641 hList = create_listview_control(LVS_ICON);
1642 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1643 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1644 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1645 DestroyWindow(hList);
1647 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1648 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1649 GetModuleHandle(NULL), 0);
1650 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1651 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1653 rect.left = LVIR_BOUNDS;
1655 rect.right = rect.bottom = -10;
1656 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1657 /* right value contains garbage, probably because header columns are not set up */
1658 expect(0, rect.bottom);
1661 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1662 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1663 ok(GetDlgItem(hList, 0) == NULL, "NULL dialog item expected\n");
1665 DestroyWindow(hList);
1667 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1668 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1669 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1670 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1671 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1672 DestroyWindow(hList);
1675 static void test_redraw(void)
1682 hwnd = create_listview_control(LVS_REPORT);
1683 subclass_header(hwnd);
1685 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1687 InvalidateRect(hwnd, NULL, TRUE);
1689 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1691 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1693 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1694 /* 1. Without backbuffer */
1695 res = ListView_SetBkColor(hwnd, CLR_NONE);
1698 hdc = GetWindowDC(hwndparent);
1700 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1701 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1702 ok(r == 1, "Expected not zero result\n");
1703 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1704 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1706 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1709 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1710 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1712 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1713 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1715 /* 2. With backbuffer */
1716 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1717 LVS_EX_DOUBLEBUFFER);
1718 res = ListView_SetBkColor(hwnd, CLR_NONE);
1721 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1722 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1724 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1725 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1727 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1730 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1731 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1732 todo_wine expect(1, r);
1733 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1734 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1736 ReleaseDC(hwndparent, hdc);
1738 DestroyWindow(hwnd);
1741 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1743 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1745 if(msg == WM_NOTIFY) {
1746 NMHDR *nmhdr = (PVOID)lp;
1747 if(nmhdr->code == NM_CUSTOMDRAW) {
1748 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1749 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1750 switch(nmlvcd->nmcd.dwDrawStage) {
1752 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1753 return CDRF_NOTIFYITEMDRAW;
1754 case CDDS_ITEMPREPAINT:
1755 nmlvcd->clrTextBk = CLR_DEFAULT;
1756 return CDRF_NOTIFYSUBITEMDRAW;
1757 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1758 clr = GetBkColor(nmlvcd->nmcd.hdc);
1759 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1760 return CDRF_NOTIFYPOSTPAINT;
1761 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1762 clr = GetBkColor(nmlvcd->nmcd.hdc);
1763 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1764 return CDRF_DODEFAULT;
1766 return CDRF_DODEFAULT;
1770 return DefWindowProcA(hwnd, msg, wp, lp);
1773 static void test_customdraw(void)
1778 hwnd = create_listview_control(LVS_REPORT);
1780 insert_column(hwnd, 0);
1781 insert_column(hwnd, 1);
1782 insert_item(hwnd, 0);
1784 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1785 (LONG_PTR)cd_wndproc);
1787 InvalidateRect(hwnd, NULL, TRUE);
1790 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1792 DestroyWindow(hwnd);
1795 static void test_icon_spacing(void)
1797 /* LVM_SETICONSPACING */
1798 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1804 hwnd = create_listview_control(LVS_ICON);
1805 ok(hwnd != NULL, "failed to create a listview window\n");
1807 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1808 expect(NFR_ANSI, r);
1810 /* reset the icon spacing to defaults */
1811 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1813 /* now we can request what the defaults are */
1814 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1818 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1820 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1821 ok(r == MAKELONG(w, h) ||
1822 broken(r == MAKELONG(w, w)), /* win98 */
1823 "Expected %d, got %d\n", MAKELONG(w, h), r);
1825 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1829 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1830 DestroyWindow(hwnd);
1833 expect(MAKELONG(20,30), r);
1835 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1836 expect(MAKELONG(25,35), r);
1838 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1840 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1841 DestroyWindow(hwnd);
1844 static void test_color(void)
1852 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1854 hwnd = create_listview_control(LVS_REPORT);
1855 ok(hwnd != NULL, "failed to create a listview window\n");
1857 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1859 for (i = 0; i < 4; i++)
1863 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1865 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
1868 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1870 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, 0);
1873 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1875 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, 0);
1879 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1880 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1882 /* invalidation test done separately to avoid a message chain mess */
1883 r = ValidateRect(hwnd, NULL);
1885 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, colors[0]);
1888 rect.right = rect.bottom = 1;
1889 r = GetUpdateRect(hwnd, &rect, TRUE);
1890 todo_wine expect(FALSE, r);
1891 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1893 r = ValidateRect(hwnd, NULL);
1895 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, colors[0]);
1898 rect.right = rect.bottom = 1;
1899 r = GetUpdateRect(hwnd, &rect, TRUE);
1900 todo_wine expect(FALSE, r);
1901 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1903 r = ValidateRect(hwnd, NULL);
1905 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, colors[0]);
1908 rect.right = rect.bottom = 1;
1909 r = GetUpdateRect(hwnd, &rect, TRUE);
1910 todo_wine expect(FALSE, r);
1911 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1913 DestroyWindow(hwnd);
1916 static void test_item_count(void)
1918 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1931 static CHAR item0text[] = "item0";
1932 static CHAR item1text[] = "item1";
1933 static CHAR item2text[] = "item2";
1935 hwnd = create_listview_control(LVS_REPORT);
1936 ok(hwnd != NULL, "failed to create a listview window\n");
1938 /* resize in dpiaware manner to fit all 3 items added */
1940 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1941 GetTextMetricsA(hdc, &tm);
1942 /* 2 extra pixels for bounds and header border */
1943 height = tm.tmHeight + 2;
1944 SelectObject(hdc, hOldFont);
1947 GetWindowRect(hwnd, &rect);
1948 /* 3 items + 1 header + 1 to be sure */
1949 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1951 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1953 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1957 item0.mask = LVIF_TEXT;
1960 item0.pszText = item0text;
1961 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1964 /* [item0, item1] */
1965 item1.mask = LVIF_TEXT;
1968 item1.pszText = item1text;
1969 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1972 /* [item0, item1, item2] */
1973 item2.mask = LVIF_TEXT;
1976 item2.pszText = item2text;
1977 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1980 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1983 /* [item0, item1] */
1984 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1987 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1991 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1994 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1998 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
2001 /* [item0, item1] */
2002 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
2005 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2008 /* [item0, item1, item2] */
2009 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
2012 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2015 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
2017 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2018 DestroyWindow(hwnd);
2021 static void test_item_position(void)
2023 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2032 static CHAR item0text[] = "item0";
2033 static CHAR item1text[] = "item1";
2034 static CHAR item2text[] = "item2";
2036 hwnd = create_listview_control(LVS_ICON);
2037 ok(hwnd != NULL, "failed to create a listview window\n");
2039 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2042 item0.mask = LVIF_TEXT;
2045 item0.pszText = item0text;
2046 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
2049 /* [item0, item1] */
2050 item1.mask = LVIF_TEXT;
2053 item1.pszText = item1text;
2054 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
2057 /* [item0, item1, item2] */
2058 item2.mask = LVIF_TEXT;
2061 item2.pszText = item2text;
2062 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
2065 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
2067 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
2069 expect2(10, 5, position.x, position.y);
2071 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
2073 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
2075 expect2(0, 0, position.x, position.y);
2077 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
2079 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
2081 expect2(20, 20, position.x, position.y);
2083 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
2085 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2086 DestroyWindow(hwnd);
2089 static void test_getorigin(void)
2097 position.x = position.y = 0;
2099 hwnd = create_listview_control(LVS_ICON);
2100 ok(hwnd != NULL, "failed to create a listview window\n");
2101 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2103 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2105 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2106 DestroyWindow(hwnd);
2108 hwnd = create_listview_control(LVS_SMALLICON);
2109 ok(hwnd != NULL, "failed to create a listview window\n");
2110 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2112 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2114 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2115 DestroyWindow(hwnd);
2117 hwnd = create_listview_control(LVS_LIST);
2118 ok(hwnd != NULL, "failed to create a listview window\n");
2119 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2121 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2123 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2124 DestroyWindow(hwnd);
2126 hwnd = create_listview_control(LVS_REPORT);
2127 ok(hwnd != NULL, "failed to create a listview window\n");
2128 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2130 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2132 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2133 DestroyWindow(hwnd);
2136 static void test_multiselect(void)
2138 typedef struct t_select_task
2149 int i,j,item_count,selected_count;
2150 static const int items=5;
2156 static struct t_select_task task_list[] = {
2157 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
2158 { "using VK_UP", -1, VK_UP, -1, -1 },
2159 { "using VK_END", 0, VK_END, 1, -1 },
2160 { "using VK_HOME", -1, VK_HOME, 1, -1 }
2163 hwnd = create_listview_control(LVS_REPORT);
2165 for (i = 0; i < items; i++)
2166 insert_item(hwnd, 0);
2168 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2169 expect(items, item_count);
2171 for (i = 0; i < 4; i++) {
2174 task = task_list[i];
2176 /* deselect all items */
2178 item.stateMask = LVIS_SELECTED;
2179 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2180 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2182 /* set initial position */
2183 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
2185 item.state = LVIS_SELECTED;
2186 item.stateMask = LVIS_SELECTED;
2187 SendMessageA(hwnd, LVM_SETITEMSTATE, task.initPos == -1 ? item_count-1 : task.initPos, (LPARAM)&item);
2189 selected_count = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2190 ok(selected_count == 1, "expected 1, got %d\n", selected_count);
2192 /* Set SHIFT key pressed */
2193 GetKeyboardState(kstate);
2194 kstate[VK_SHIFT]=0x80;
2195 SetKeyboardState(kstate);
2197 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
2198 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
2200 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
2204 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2206 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);
2208 /* Set SHIFT key released */
2209 GetKeyboardState(kstate);
2210 kstate[VK_SHIFT]=0x00;
2211 SetKeyboardState(kstate);
2213 DestroyWindow(hwnd);
2215 /* make multiple selection, then switch to LVS_SINGLESEL */
2216 hwnd = create_listview_control(LVS_REPORT);
2217 for (i=0;i<items;i++) {
2218 insert_item(hwnd, 0);
2220 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2221 expect(items,item_count);
2223 /* try with NULL pointer */
2224 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
2227 /* select all, check notifications */
2229 item.stateMask = LVIS_SELECTED;
2230 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2232 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2234 item.stateMask = LVIS_SELECTED;
2235 item.state = LVIS_SELECTED;
2236 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2239 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2240 "select all notification", FALSE);
2242 /* select all again (all selected already) */
2243 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2245 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2247 item.stateMask = LVIS_SELECTED;
2248 item.state = LVIS_SELECTED;
2249 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2252 ok(g_nmlistview_changing.uNewState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uNewState);
2253 ok(g_nmlistview_changing.uOldState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uOldState);
2254 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2256 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2257 "select all notification 2", FALSE);
2259 /* deselect all items */
2260 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2263 item.stateMask = LVIS_SELECTED;
2264 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2266 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2267 "deselect all notification", FALSE);
2269 /* deselect all items again */
2270 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2272 item.stateMask = LVIS_SELECTED;
2273 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2274 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "deselect all notification 2", FALSE);
2276 /* any non-zero state value does the same */
2277 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2279 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2281 item.stateMask = LVIS_SELECTED;
2282 item.state = LVIS_CUT;
2283 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2286 ok(g_nmlistview_changing.uNewState == 0, "got 0x%x\n", g_nmlistview_changing.uNewState);
2287 ok(g_nmlistview_changing.uOldState == 0, "got 0x%x\n", g_nmlistview_changing.uOldState);
2288 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2290 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2291 "set state all notification 3", FALSE);
2293 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2294 for (i = 0; i < 3; i++) {
2295 item.state = LVIS_SELECTED;
2296 item.stateMask = LVIS_SELECTED;
2297 SendMessageA(hwnd, LVM_SETITEMSTATE, i, (LPARAM)&item);
2300 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2302 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2305 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2306 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2307 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2308 /* check that style is accepted */
2309 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2310 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2313 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2314 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2316 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2318 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2321 /* select one more */
2322 item.state = LVIS_SELECTED;
2323 item.stateMask = LVIS_SELECTED;
2324 SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
2327 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2328 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2330 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2331 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2333 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2335 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2338 /* try to select all on LVS_SINGLESEL */
2339 memset(&item, 0, sizeof(item));
2340 item.stateMask = LVIS_SELECTED;
2341 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2343 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2345 item.stateMask = LVIS_SELECTED;
2346 item.state = LVIS_SELECTED;
2347 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2350 r = ListView_GetSelectedCount(hwnd);
2352 r = ListView_GetSelectionMark(hwnd);
2355 /* try to deselect all on LVS_SINGLESEL */
2356 item.stateMask = LVIS_SELECTED;
2357 item.state = LVIS_SELECTED;
2358 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2361 item.stateMask = LVIS_SELECTED;
2363 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2365 r = ListView_GetSelectedCount(hwnd);
2368 /* 1. selection mark is update when new focused item is set */
2369 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2370 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2372 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2375 item.stateMask = LVIS_FOCUSED;
2376 item.state = LVIS_FOCUSED;
2377 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2380 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2383 /* it's not updated if already set */
2384 item.stateMask = LVIS_FOCUSED;
2385 item.state = LVIS_FOCUSED;
2386 r = SendMessage(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2389 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2392 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2395 item.stateMask = LVIS_FOCUSED;
2396 item.state = LVIS_FOCUSED;
2397 r = SendMessage(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2400 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2403 /* need to reset focused item first */
2404 item.stateMask = LVIS_FOCUSED;
2406 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2409 item.stateMask = LVIS_FOCUSED;
2410 item.state = LVIS_FOCUSED;
2411 r = SendMessage(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
2414 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2417 item.stateMask = LVIS_FOCUSED;
2419 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2422 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2425 /* 2. same tests, with LVM_SETITEM */
2426 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2427 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2429 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2432 item.stateMask = LVIS_FOCUSED;
2433 item.state = LVIS_FOCUSED;
2434 item.mask = LVIF_STATE;
2435 item.iItem = item.iSubItem = 0;
2436 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2439 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2442 /* it's not updated if already set */
2443 item.stateMask = LVIS_FOCUSED;
2444 item.state = LVIS_FOCUSED;
2445 item.mask = LVIF_STATE;
2448 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2451 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2454 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2457 item.stateMask = LVIS_FOCUSED;
2458 item.state = LVIS_FOCUSED;
2459 item.mask = LVIF_STATE;
2462 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2465 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2468 /* need to reset focused item first */
2469 item.stateMask = LVIS_FOCUSED;
2471 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2474 item.stateMask = LVIS_FOCUSED;
2475 item.state = LVIS_FOCUSED;
2476 item.mask = LVIF_STATE;
2479 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2482 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2485 item.stateMask = LVIS_FOCUSED;
2487 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2490 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2493 DestroyWindow(hwnd);
2496 static void test_subitem_rect(void)
2504 /* test LVM_GETSUBITEMRECT for header */
2505 hwnd = create_listview_control(LVS_REPORT);
2506 ok(hwnd != NULL, "failed to create a listview window\n");
2507 /* add some columns */
2508 memset(&col, 0, sizeof(LVCOLUMN));
2509 col.mask = LVCF_WIDTH;
2511 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2514 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2517 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2519 /* item = -1 means header, subitem index is 1 based */
2520 rect.left = LVIR_BOUNDS;
2522 rect.right = rect.bottom = 0;
2523 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2526 rect.left = LVIR_BOUNDS;
2528 rect.right = rect.bottom = 0;
2529 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2532 expect(100, rect.left);
2533 expect(250, rect.right);
2534 expect(3, rect.top);
2536 rect.left = LVIR_BOUNDS;
2538 rect.right = rect.bottom = 0;
2539 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2542 expect(250, rect.left);
2543 expect(450, rect.right);
2544 expect(3, rect.top);
2546 /* item LVS_REPORT padding isn't applied to subitems */
2547 insert_item(hwnd, 0);
2549 rect.left = LVIR_BOUNDS;
2551 rect.right = rect.bottom = 0;
2552 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2554 expect(100, rect.left);
2555 expect(250, rect.right);
2557 rect.left = LVIR_ICON;
2559 rect.right = rect.bottom = 0;
2560 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2562 /* no icon attached - zero width rectangle, with no left padding */
2563 expect(100, rect.left);
2564 expect(100, rect.right);
2566 rect.left = LVIR_LABEL;
2568 rect.right = rect.bottom = 0;
2569 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2571 /* same as full LVIR_BOUNDS */
2572 expect(100, rect.left);
2573 expect(250, rect.right);
2575 SendMessage(hwnd, LVM_SCROLL, 10, 0);
2577 rect.left = LVIR_BOUNDS;
2579 rect.right = rect.bottom = 0;
2580 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2582 expect(90, rect.left);
2583 expect(240, rect.right);
2585 SendMessage(hwnd, LVM_SCROLL, -10, 0);
2587 /* test header interaction */
2588 subclass_header(hwnd);
2589 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2591 rect.left = LVIR_BOUNDS;
2593 rect.right = rect.bottom = 0;
2594 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2597 rect.left = LVIR_BOUNDS;
2599 rect.right = rect.bottom = 0;
2600 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2603 rect.left = LVIR_BOUNDS;
2605 rect.right = rect.bottom = 0;
2606 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -10, (LPARAM)&rect);
2609 rect.left = LVIR_BOUNDS;
2611 rect.right = rect.bottom = 0;
2612 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 20, (LPARAM)&rect);
2615 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getsubitemrect_seq, "LVM_GETSUBITEMRECT negative index", FALSE);
2617 DestroyWindow(hwnd);
2619 /* test subitem rects after re-arranging columns */
2620 hwnd = create_listview_control(LVS_REPORT);
2621 ok(hwnd != NULL, "failed to create a listview window\n");
2622 memset(&col, 0, sizeof(LVCOLUMN));
2623 col.mask = LVCF_WIDTH;
2626 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2630 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2634 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2637 insert_item(hwnd, 0);
2638 insert_item(hwnd, 1);
2640 /* wrong item is refused for main item */
2641 rect.left = LVIR_BOUNDS;
2643 rect.right = rect.bottom = -1;
2644 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect);
2647 /* for subitems rectangle is calculated even if there's no item added */
2648 rect.left = LVIR_BOUNDS;
2650 rect.right = rect.bottom = -1;
2651 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect);
2654 rect2.left = LVIR_BOUNDS;
2656 rect2.right = rect2.bottom = -1;
2657 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect2);
2659 expect(rect.right, rect2.right);
2660 expect(rect.left, rect2.left);
2661 expect(rect.bottom, rect2.top);
2662 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2664 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2665 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2668 rect.left = LVIR_BOUNDS;
2670 rect.right = rect.bottom = -1;
2671 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2673 expect(0, rect.left);
2674 expect(600, rect.right);
2676 rect.left = LVIR_BOUNDS;
2678 rect.right = rect.bottom = -1;
2679 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2681 expect(0, rect.left);
2682 expect(200, rect.right);
2684 rect2.left = LVIR_BOUNDS;
2686 rect2.right = rect2.bottom = -1;
2687 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect2);
2689 expect(0, rect2.left);
2690 expect(200, rect2.right);
2691 /* items are of the same height */
2692 ok(rect2.top > 0, "expected positive item height\n");
2693 expect(rect.bottom, rect2.top);
2694 expect(rect.bottom * 2 - rect.top, rect2.bottom);
2696 rect.left = LVIR_BOUNDS;
2698 rect.right = rect.bottom = -1;
2699 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2701 expect(300, rect.left);
2702 expect(600, rect.right);
2704 DestroyWindow(hwnd);
2706 /* try it for non LVS_REPORT style */
2707 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2708 GetModuleHandle(NULL), 0);
2709 rect.left = LVIR_BOUNDS;
2711 rect.right = rect.bottom = -10;
2712 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2714 /* rect is unchanged */
2715 expect(0, rect.left);
2716 expect(-10, rect.right);
2717 expect(1, rect.top);
2718 expect(-10, rect.bottom);
2719 DestroyWindow(hwnd);
2722 /* comparison callback for test_sorting */
2723 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2725 if (first == second) return 0;
2726 return (first > second ? 1 : -1);
2729 static void test_sorting(void)
2735 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2738 hwnd = create_listview_control(LVS_REPORT);
2739 ok(hwnd != NULL, "failed to create a listview window\n");
2741 /* insert some items */
2742 item.mask = LVIF_PARAM | LVIF_STATE;
2743 item.state = LVIS_SELECTED;
2747 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2750 item.mask = LVIF_PARAM;
2754 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2757 item.mask = LVIF_STATE | LVIF_PARAM;
2758 item.state = LVIS_SELECTED;
2762 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2765 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2768 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2771 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2774 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2776 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2778 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2780 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2781 expect(LVIS_SELECTED, r);
2782 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2783 expect(LVIS_SELECTED, r);
2785 DestroyWindow(hwnd);
2787 /* switch to LVS_SORTASCENDING when some items added */
2788 hwnd = create_listview_control(LVS_REPORT);
2789 ok(hwnd != NULL, "failed to create a listview window\n");
2791 item.mask = LVIF_TEXT;
2794 item.pszText = names[1];
2795 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2798 item.mask = LVIF_TEXT;
2801 item.pszText = names[2];
2802 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2805 item.mask = LVIF_TEXT;
2808 item.pszText = names[0];
2809 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2812 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2813 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2814 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2815 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2817 /* no sorting performed when switched to LVS_SORTASCENDING */
2818 item.mask = LVIF_TEXT;
2820 item.pszText = buff;
2821 item.cchTextMax = sizeof(buff);
2822 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2824 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2827 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2829 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2832 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2834 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2836 /* adding new item doesn't resort list */
2837 item.mask = LVIF_TEXT;
2840 item.pszText = names[3];
2841 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2844 item.mask = LVIF_TEXT;
2846 item.pszText = buff;
2847 item.cchTextMax = sizeof(buff);
2848 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2850 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2853 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2855 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2858 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2860 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2863 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2865 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2867 /* corner case - item should be placed at first position */
2868 item.mask = LVIF_TEXT;
2871 item.pszText = names[4];
2872 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2876 item.pszText = buff;
2877 item.cchTextMax = sizeof(buff);
2878 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2880 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2883 item.pszText = buff;
2884 item.cchTextMax = sizeof(buff);
2885 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2887 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2890 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2892 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2895 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2897 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2900 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2902 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2904 DestroyWindow(hwnd);
2907 static void test_ownerdata(void)
2909 static char test_str[] = "test";
2912 LONG_PTR style, ret;
2916 /* it isn't possible to set LVS_OWNERDATA after creation */
2919 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2923 hwnd = create_listview_control(LVS_REPORT);
2924 ok(hwnd != NULL, "failed to create a listview window\n");
2925 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2926 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2928 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2930 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2931 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2932 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2933 "try to switch to LVS_OWNERDATA seq", FALSE);
2935 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2936 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2937 DestroyWindow(hwnd);
2940 /* try to set LVS_OWNERDATA after creation just having it */
2941 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2942 ok(hwnd != NULL, "failed to create a listview window\n");
2943 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2944 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2946 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2948 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2949 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2950 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2951 "try to switch to LVS_OWNERDATA seq", FALSE);
2952 DestroyWindow(hwnd);
2954 /* try to remove LVS_OWNERDATA after creation just having it */
2957 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2961 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2962 ok(hwnd != NULL, "failed to create a listview window\n");
2963 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2964 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2966 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2968 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2969 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2970 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2971 "try to switch to LVS_OWNERDATA seq", FALSE);
2972 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2973 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2974 DestroyWindow(hwnd);
2977 /* try select an item */
2978 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2979 ok(hwnd != NULL, "failed to create a listview window\n");
2980 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2982 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2984 memset(&item, 0, sizeof(item));
2985 item.stateMask = LVIS_SELECTED;
2986 item.state = LVIS_SELECTED;
2987 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2989 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2991 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2993 DestroyWindow(hwnd);
2995 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
2996 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2997 ok(hwnd != NULL, "failed to create a listview window\n");
2998 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3000 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
3002 memset(&item, 0, sizeof(item));
3003 item.mask = LVIF_STATE;
3005 item.stateMask = LVIS_SELECTED;
3006 item.state = LVIS_SELECTED;
3007 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3009 memset(&item, 0, sizeof(item));
3010 item.pszText = test_str;
3011 res = SendMessageA(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
3013 DestroyWindow(hwnd);
3015 /* check notifications after focused/selected changed */
3016 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3017 ok(hwnd != NULL, "failed to create a listview window\n");
3018 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
3021 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3023 memset(&item, 0, sizeof(item));
3024 item.stateMask = LVIS_SELECTED;
3025 item.state = LVIS_SELECTED;
3026 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3029 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
3030 "ownerdata select notification", TRUE);
3032 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3034 memset(&item, 0, sizeof(item));
3035 item.stateMask = LVIS_FOCUSED;
3036 item.state = LVIS_FOCUSED;
3037 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3040 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
3041 "ownerdata focus notification", TRUE);
3043 /* select all, check notifications */
3044 item.stateMask = LVIS_SELECTED;
3046 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3049 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3051 item.stateMask = LVIS_SELECTED;
3052 item.state = LVIS_SELECTED;
3054 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3055 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3057 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3058 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3059 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3060 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3061 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3062 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3063 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3065 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3066 "ownerdata select all notification", FALSE);
3068 /* select all again, note that all items are selected already */
3069 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3070 item.stateMask = LVIS_SELECTED;
3071 item.state = LVIS_SELECTED;
3073 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3074 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3076 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3077 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3078 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3079 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3080 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3081 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3082 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3084 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3085 "ownerdata select all notification", FALSE);
3088 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3089 item.stateMask = LVIS_SELECTED;
3092 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3093 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3095 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3096 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3097 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3098 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3099 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3100 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3101 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3103 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3104 "ownerdata deselect all notification", TRUE);
3106 /* nothing selected, deselect all again */
3107 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3108 item.stateMask = LVIS_SELECTED;
3111 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3114 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "ownerdata deselect all notification", FALSE);
3116 /* select one, then deselect all */
3117 item.stateMask = LVIS_SELECTED;
3118 item.state = LVIS_SELECTED;
3119 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3121 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3122 item.stateMask = LVIS_SELECTED;
3125 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3126 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3128 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3129 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3130 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3131 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3132 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3133 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3134 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3136 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3137 "ownerdata select all notification", TRUE);
3139 /* remove focused, try to focus all */
3140 item.stateMask = LVIS_FOCUSED;
3141 item.state = LVIS_FOCUSED;
3142 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3144 item.stateMask = LVIS_FOCUSED;
3146 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3148 item.stateMask = LVIS_FOCUSED;
3149 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
3152 /* setting all to focused returns failure value */
3153 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3154 item.stateMask = LVIS_FOCUSED;
3155 item.state = LVIS_FOCUSED;
3157 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3160 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3161 "ownerdata focus all notification", FALSE);
3163 /* focus single item, remove all */
3164 item.stateMask = LVIS_FOCUSED;
3165 item.state = LVIS_FOCUSED;
3166 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3168 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3169 item.stateMask = LVIS_FOCUSED;
3172 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3173 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3175 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3176 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3177 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3178 ok(g_nmlistview.uOldState == LVIS_FOCUSED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3179 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3180 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3181 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3183 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
3184 "ownerdata remove focus all notification", TRUE);
3187 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3188 item.stateMask = LVIS_CUT;
3189 item.state = LVIS_CUT;
3191 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3192 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3194 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3195 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3196 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3197 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3198 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3199 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3200 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3202 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3203 "ownerdata cut all notification", FALSE);
3205 /* all marked cut, try again */
3206 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3207 item.stateMask = LVIS_CUT;
3208 item.state = LVIS_CUT;
3210 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3211 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3213 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3214 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3215 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3216 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3217 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3218 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3219 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3221 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3222 "ownerdata cut all notification #2", FALSE);
3224 DestroyWindow(hwnd);
3226 /* check notifications on LVM_GETITEM */
3227 /* zero callback mask */
3228 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3229 ok(hwnd != NULL, "failed to create a listview window\n");
3230 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3233 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3235 memset(&item, 0, sizeof(item));
3236 item.stateMask = LVIS_SELECTED;
3237 item.mask = LVIF_STATE;
3238 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3241 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3242 "ownerdata getitem selected state 1", FALSE);
3244 /* non zero callback mask but not we asking for */
3245 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
3248 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3250 memset(&item, 0, sizeof(item));
3251 item.stateMask = LVIS_SELECTED;
3252 item.mask = LVIF_STATE;
3253 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3256 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3257 "ownerdata getitem selected state 2", FALSE);
3259 /* LVIS_OVERLAYMASK callback mask, asking for index */
3260 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3262 memset(&item, 0, sizeof(item));
3263 item.stateMask = LVIS_OVERLAYMASK;
3264 item.mask = LVIF_STATE;
3265 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3268 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3269 "ownerdata getitem selected state 2", FALSE);
3271 DestroyWindow(hwnd);
3273 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3274 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
3275 ok(hwnd != NULL, "failed to create a listview window\n");
3276 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3277 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3278 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3279 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
3280 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3281 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
3282 DestroyWindow(hwnd);
3283 /* apparently it's allowed to switch these style on after creation */
3284 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3285 ok(hwnd != NULL, "failed to create a listview window\n");
3286 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3287 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3288 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
3289 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3290 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3291 DestroyWindow(hwnd);
3293 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3294 ok(hwnd != NULL, "failed to create a listview window\n");
3295 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3296 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3297 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
3298 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3299 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
3300 DestroyWindow(hwnd);
3303 static void test_norecompute(void)
3305 static CHAR testA[] = "test";
3311 /* self containing control */
3312 hwnd = create_listview_control(LVS_REPORT);
3313 ok(hwnd != NULL, "failed to create a listview window\n");
3314 memset(&item, 0, sizeof(item));
3315 item.mask = LVIF_TEXT | LVIF_STATE;
3317 item.stateMask = LVIS_SELECTED;
3318 item.state = LVIS_SELECTED;
3319 item.pszText = testA;
3320 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3322 /* retrieve with LVIF_NORECOMPUTE */
3323 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3325 item.pszText = buff;
3326 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3327 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3329 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
3331 item.mask = LVIF_TEXT;
3333 item.pszText = LPSTR_TEXTCALLBACK;
3334 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3337 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3339 item.pszText = buff;
3340 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3342 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3343 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3345 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
3346 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
3347 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
3349 DestroyWindow(hwnd);
3352 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3353 ok(hwnd != NULL, "failed to create a listview window\n");
3355 item.mask = LVIF_STATE;
3356 item.stateMask = LVIS_SELECTED;
3357 item.state = LVIS_SELECTED;
3359 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3362 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3364 item.pszText = buff;
3365 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3366 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3367 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3369 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
3370 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
3371 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
3373 DestroyWindow(hwnd);
3376 static void test_nosortheader(void)
3381 hwnd = create_listview_control(LVS_REPORT);
3382 ok(hwnd != NULL, "failed to create a listview window\n");
3384 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3385 ok(IsWindow(header), "header expected\n");
3387 style = GetWindowLongPtr(header, GWL_STYLE);
3388 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
3390 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3391 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
3392 /* HDS_BUTTONS retained */
3393 style = GetWindowLongPtr(header, GWL_STYLE);
3394 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
3396 DestroyWindow(hwnd);
3398 /* create with LVS_NOSORTHEADER */
3399 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
3400 ok(hwnd != NULL, "failed to create a listview window\n");
3402 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3403 ok(IsWindow(header), "header expected\n");
3405 style = GetWindowLongPtr(header, GWL_STYLE);
3406 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3408 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3409 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
3410 /* not changed here */
3411 style = GetWindowLongPtr(header, GWL_STYLE);
3412 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3414 DestroyWindow(hwnd);
3417 static void test_setredraw(void)
3425 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3426 ok(hwnd != NULL, "failed to create a listview window\n");
3428 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3429 ListView seems to handle it internally without DefWinProc */
3431 /* default value first */
3432 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3435 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3436 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3437 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3439 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3440 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3441 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3444 /* check update rect after redrawing */
3445 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3447 InvalidateRect(hwnd, NULL, FALSE);
3448 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
3449 rect.right = rect.bottom = 1;
3450 GetUpdateRect(hwnd, &rect, FALSE);
3451 expect(0, rect.right);
3452 expect(0, rect.bottom);
3455 hdc = GetWindowDC(hwndparent);
3456 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3458 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3460 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3462 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3464 ReleaseDC(hwndparent, hdc);
3466 /* check notification messages to show that repainting is disabled */
3467 ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
3469 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3471 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3473 InvalidateRect(hwnd, NULL, TRUE);
3475 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3476 "redraw after WM_SETREDRAW (FALSE)", FALSE);
3478 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3480 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3481 InvalidateRect(hwnd, NULL, TRUE);
3483 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3484 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3486 /* message isn't forwarded to header */
3487 subclass_header(hwnd);
3488 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3489 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3491 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3492 "WM_SETREDRAW: not forwarded to header", FALSE);
3494 DestroyWindow(hwnd);
3497 static void test_hittest(void)
3503 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3507 HIMAGELIST himl, himl2;
3510 hwnd = create_listview_control(LVS_REPORT);
3511 ok(hwnd != NULL, "failed to create a listview window\n");
3513 /* LVS_REPORT with a single subitem (2 columns) */
3514 insert_column(hwnd, 0);
3515 insert_column(hwnd, 1);
3516 insert_item(hwnd, 0);
3519 /* the only purpose of that line is to be as long as a half item rect */
3520 item.pszText = text;
3521 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
3524 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3526 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3529 memset(&bounds, 0, sizeof(bounds));
3530 bounds.left = LVIR_BOUNDS;
3531 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3533 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3534 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3535 r = SendMessage(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3537 ok(bounds.bottom - bounds.top == vert,
3538 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3539 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3542 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3544 /* outside columns by x position - valid is [0, 199] */
3546 y = pos.y + (bounds.bottom - bounds.top) / 2;
3547 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3548 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3550 x = pos.x + 50; /* column half width */
3551 y = pos.y + (bounds.bottom - bounds.top) / 2;
3552 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3553 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3554 x = pos.x + 150; /* outside column */
3555 y = pos.y + (bounds.bottom - bounds.top) / 2;
3556 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3557 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3558 y = (bounds.bottom - bounds.top) / 2;
3559 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3560 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3561 /* outside possible client rectangle (to right) */
3563 y = pos.y + (bounds.bottom - bounds.top) / 2;
3564 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3565 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3566 y = (bounds.bottom - bounds.top) / 2;
3567 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3568 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3569 /* subitem returned with -1 item too */
3571 y = bounds.top - vert;
3572 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3573 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3574 /* return values appear to underflow with negative indices */
3578 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3579 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3583 /* parent client area is 100x100 by default */
3584 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3585 x = pos.x + 150; /* outside column */
3586 y = pos.y + (bounds.bottom - bounds.top) / 2;
3587 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3588 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3589 y = (bounds.bottom - bounds.top) / 2;
3590 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3591 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3592 /* the same with LVS_EX_FULLROWSELECT */
3593 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3594 x = pos.x + 150; /* outside column */
3595 y = pos.y + (bounds.bottom - bounds.top) / 2;
3596 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3597 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3598 y = (bounds.bottom - bounds.top) / 2;
3599 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3600 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3601 x = pos.x + 150; /* outside column */
3602 y = pos.y + (bounds.bottom - bounds.top) / 2;
3603 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3604 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3605 y = (bounds.bottom - bounds.top) / 2;
3606 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3607 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3608 /* outside possible client rectangle (to right) */
3610 y = pos.y + (bounds.bottom - bounds.top) / 2;
3611 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3612 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3613 y = (bounds.bottom - bounds.top) / 2;
3614 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3615 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3616 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3617 himl = ImageList_Create(16, 16, 0, 4, 4);
3618 ok(himl != NULL, "failed to create imagelist\n");
3619 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3620 ok(hbmp != NULL, "failed to create bitmap\n");
3621 r = ImageList_Add(himl, hbmp, 0);
3622 ok(r == 0, "should be zero\n");
3623 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3624 ok(hbmp != NULL, "failed to create bitmap\n");
3625 r = ImageList_Add(himl, hbmp, 0);
3626 ok(r == 1, "should be one\n");
3628 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3631 item.mask = LVIF_IMAGE;
3635 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3639 y = pos.y + (bounds.bottom - bounds.top) / 2;
3640 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3641 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3642 y = (bounds.bottom - bounds.top) / 2;
3643 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3645 /* state icons indices are 1 based, check with valid index */
3646 item.mask = LVIF_STATE;
3647 item.state = INDEXTOSTATEIMAGEMASK(1);
3648 item.stateMask = LVIS_STATEIMAGEMASK;
3651 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3655 y = pos.y + (bounds.bottom - bounds.top) / 2;
3656 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3657 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3658 y = (bounds.bottom - bounds.top) / 2;
3659 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3661 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3662 ok(himl2 == himl, "should return handle\n");
3664 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3668 y = pos.y + (bounds.bottom - bounds.top) / 2;
3669 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3670 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3671 y = (bounds.bottom - bounds.top) / 2;
3672 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3674 DestroyWindow(hwnd);
3677 static void test_getviewrect(void)
3684 hwnd = create_listview_control(LVS_REPORT);
3685 ok(hwnd != NULL, "failed to create a listview window\n");
3688 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3691 insert_column(hwnd, 0);
3692 insert_column(hwnd, 1);
3694 memset(&item, 0, sizeof(item));
3697 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3699 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3701 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3704 rect.left = rect.right = rect.top = rect.bottom = -1;
3705 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3707 /* left is set to (2e31-1) - XP SP2 */
3708 expect(0, rect.right);
3709 expect(0, rect.top);
3710 expect(0, rect.bottom);
3712 /* switch to LVS_ICON */
3713 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3715 rect.left = rect.right = rect.top = rect.bottom = -1;
3716 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3718 expect(0, rect.left);
3719 expect(0, rect.top);
3720 /* precise value differs for 2k, XP and Vista */
3721 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3722 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3724 DestroyWindow(hwnd);
3727 static void test_getitemposition(void)
3734 hwnd = create_listview_control(LVS_REPORT);
3735 ok(hwnd != NULL, "failed to create a listview window\n");
3736 header = subclass_header(hwnd);
3738 /* LVS_REPORT, single item, no columns added */
3739 insert_item(hwnd, 0);
3741 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3744 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3746 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3748 /* LVS_REPORT, single item, single column */
3749 insert_column(hwnd, 0);
3751 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3754 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3756 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3758 memset(&rect, 0, sizeof(rect));
3759 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3762 /* offset by header height */
3763 expect(rect.bottom - rect.top, pt.y);
3765 DestroyWindow(hwnd);
3768 static void test_columnscreation(void)
3773 hwnd = create_listview_control(LVS_REPORT);
3774 ok(hwnd != NULL, "failed to create a listview window\n");
3776 insert_item(hwnd, 0);
3778 /* headers columns aren't created automatically */
3779 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3780 ok(IsWindow(header), "Expected header handle\n");
3781 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3784 DestroyWindow(hwnd);
3787 static void test_getitemrect(void)
3790 HIMAGELIST himl, himl_ret;
3800 /* rectangle isn't empty for empty text items */
3801 hwnd = create_listview_control(LVS_LIST);
3802 memset(&item, 0, sizeof(item));
3805 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3807 rect.left = LVIR_LABEL;
3808 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3810 expect(0, rect.left);
3811 expect(0, rect.top);
3813 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, rect.right);
3814 ReleaseDC(hwnd, hdc);
3815 DestroyWindow(hwnd);
3817 hwnd = create_listview_control(LVS_REPORT);
3818 ok(hwnd != NULL, "failed to create a listview window\n");
3821 memset(&item, 0, sizeof(item));
3824 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3827 rect.left = LVIR_BOUNDS;
3828 rect.right = rect.top = rect.bottom = -1;
3829 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3832 /* zero width rectangle with no padding */
3833 expect(0, rect.left);
3834 expect(0, rect.right);
3836 insert_column(hwnd, 0);
3837 insert_column(hwnd, 1);
3839 col.mask = LVCF_WIDTH;
3841 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3844 col.mask = LVCF_WIDTH;
3846 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3849 rect.left = LVIR_BOUNDS;
3850 rect.right = rect.top = rect.bottom = -1;
3851 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3854 /* still no left padding */
3855 expect(0, rect.left);
3856 expect(150, rect.right);
3858 rect.left = LVIR_SELECTBOUNDS;
3859 rect.right = rect.top = rect.bottom = -1;
3860 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3863 expect(2, rect.left);
3865 rect.left = LVIR_LABEL;
3866 rect.right = rect.top = rect.bottom = -1;
3867 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3869 /* padding, column width */
3870 expect(2, rect.left);
3871 expect(50, rect.right);
3873 /* no icons attached */
3874 rect.left = LVIR_ICON;
3875 rect.right = rect.top = rect.bottom = -1;
3876 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3879 expect(2, rect.left);
3880 expect(2, rect.right);
3883 order[0] = 1; order[1] = 0;
3884 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3887 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3889 /* 1 indexed column width + padding */
3891 /* rect is at zero too */
3892 rect.left = LVIR_BOUNDS;
3893 rect.right = rect.top = rect.bottom = -1;
3894 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3896 expect(0, rect.left);
3897 /* just width sum */
3898 expect(150, rect.right);
3900 rect.left = LVIR_SELECTBOUNDS;
3901 rect.right = rect.top = rect.bottom = -1;
3902 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3904 /* column width + padding */
3905 expect(102, rect.left);
3907 /* back to initial order */
3908 order[0] = 0; order[1] = 1;
3909 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3913 himl = ImageList_Create(16, 16, 0, 2, 2);
3914 ok(himl != NULL, "failed to create imagelist\n");
3915 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3916 ok(hbm != NULL, "failed to create bitmap\n");
3917 r = ImageList_Add(himl, hbm, 0);
3919 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3920 ok(hbm != NULL, "failed to create bitmap\n");
3921 r = ImageList_Add(himl, hbm, 0);
3924 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3927 item.mask = LVIF_STATE;
3928 item.state = INDEXTOSTATEIMAGEMASK(1);
3929 item.stateMask = LVIS_STATEIMAGEMASK;
3932 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3936 rect.left = LVIR_ICON;
3937 rect.right = rect.top = rect.bottom = -1;
3938 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3940 /* padding + stateicon width */
3941 expect(18, rect.left);
3942 expect(18, rect.right);
3944 rect.left = LVIR_LABEL;
3945 rect.right = rect.top = rect.bottom = -1;
3946 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3948 /* padding + stateicon width -> column width */
3949 expect(18, rect.left);
3950 expect(50, rect.right);
3952 himl_ret = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3953 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
3955 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3958 item.mask = LVIF_STATE | LVIF_IMAGE;
3961 item.stateMask = ~0;
3964 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3968 rect.left = LVIR_ICON;
3969 rect.right = rect.top = rect.bottom = -1;
3970 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3972 /* padding, icon width */
3973 expect(2, rect.left);
3974 expect(18, rect.right);
3976 rect.left = LVIR_LABEL;
3977 rect.right = rect.top = rect.bottom = -1;
3978 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3980 /* padding + icon width -> column width */
3981 expect(18, rect.left);
3982 expect(50, rect.right);
3985 rect.left = LVIR_SELECTBOUNDS;
3986 rect.right = rect.top = rect.bottom = -1;
3987 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3989 /* padding, column width */
3990 expect(2, rect.left);
3991 expect(50, rect.right);
3993 /* try with indentation */
3994 item.mask = LVIF_INDENT;
3998 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
4002 rect.left = LVIR_BOUNDS;
4003 rect.right = rect.top = rect.bottom = -1;
4004 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4006 /* padding + 1 icon width, column width */
4007 expect(0, rect.left);
4008 expect(150, rect.right);
4011 rect.left = LVIR_SELECTBOUNDS;
4012 rect.right = rect.top = rect.bottom = -1;
4013 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4015 /* padding + 1 icon width, column width */
4016 expect(2 + 16, rect.left);
4017 expect(50, rect.right);
4020 rect.left = LVIR_LABEL;
4021 rect.right = rect.top = rect.bottom = -1;
4022 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4024 /* padding + 2 icon widths, column width */
4025 expect(2 + 16*2, rect.left);
4026 expect(50, rect.right);
4029 rect.left = LVIR_ICON;
4030 rect.right = rect.top = rect.bottom = -1;
4031 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4033 /* padding + 1 icon width indentation, icon width */
4034 expect(2 + 16, rect.left);
4035 expect(34, rect.right);
4037 DestroyWindow(hwnd);
4040 static void test_editbox(void)
4042 static CHAR testitemA[] = "testitem";
4043 static CHAR testitem1A[] = "testitem_quitelongname";
4044 static CHAR testitem2A[] = "testITEM_quitelongname";
4045 static CHAR buffer[25];
4046 HWND hwnd, hwndedit, hwndedit2, header;
4050 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4051 ok(hwnd != NULL, "failed to create a listview window\n");
4053 insert_column(hwnd, 0);
4055 memset(&item, 0, sizeof(item));
4056 item.mask = LVIF_TEXT;
4057 item.pszText = testitemA;
4060 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4063 /* test notifications without edit created */
4064 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4065 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
4067 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4068 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
4069 /* same thing but with valid window */
4070 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
4071 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
4072 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4073 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
4075 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4076 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
4077 DestroyWindow(hwndedit);
4079 /* setting focus is necessary */
4081 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4082 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4084 /* test children Z-order after Edit box created */
4085 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4086 ok(IsWindow(header), "Expected header to be created\n");
4087 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4088 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4090 /* modify initial string */
4091 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4094 /* edit window is resized and repositioned,
4095 check again for Z-order - it should be preserved */
4096 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4097 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4099 /* return focus to listview */
4102 memset(&item, 0, sizeof(item));
4103 item.mask = LVIF_TEXT;
4104 item.pszText = buffer;
4105 item.cchTextMax = sizeof(buffer);
4108 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4111 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4113 /* send LVM_EDITLABEL on already created edit */
4115 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4116 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4117 /* focus will be set to edit */
4118 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
4119 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4120 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
4122 /* creating label disabled when control isn't focused */
4124 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4125 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4127 /* check EN_KILLFOCUS handling */
4128 memset(&item, 0, sizeof(item));
4129 item.pszText = testitemA;
4132 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4136 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4137 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4138 /* modify edit and notify control that it lost focus */
4139 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4141 g_editbox_disp_info.item.pszText = NULL;
4142 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4144 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
4146 memset(&item, 0, sizeof(item));
4147 item.pszText = buffer;
4148 item.cchTextMax = sizeof(buffer);
4151 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4152 expect(lstrlen(item.pszText), r);
4153 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4154 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4156 /* change item name to differ in casing only */
4158 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4159 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4160 /* modify edit and notify control that it lost focus */
4161 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
4163 g_editbox_disp_info.item.pszText = NULL;
4164 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4166 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
4168 memset(&item, 0, sizeof(item));
4169 item.pszText = buffer;
4170 item.cchTextMax = sizeof(buffer);
4173 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4174 expect(lstrlen(item.pszText), r);
4175 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
4176 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4178 /* end edit without saving */
4180 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4181 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4182 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
4184 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4185 "edit box - end edit, no change, escape", TRUE);
4186 /* end edit with saving */
4188 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4189 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4190 r = SendMessage(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
4192 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4193 "edit box - end edit, no change, return", TRUE);
4195 memset(&item, 0, sizeof(item));
4196 item.pszText = buffer;
4197 item.cchTextMax = sizeof(buffer);
4200 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4201 expect(lstrlen(item.pszText), r);
4202 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
4204 /* LVM_EDITLABEL with -1 destroys current edit */
4205 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
4206 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4207 /* no edit present */
4208 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
4209 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4210 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4211 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4213 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4214 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
4215 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4216 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4217 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4218 /* check another negative value */
4219 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4220 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4221 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4222 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
4223 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4224 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4225 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4226 /* and value greater than max item index */
4227 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4228 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4229 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4230 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
4231 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
4232 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4233 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4234 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4236 /* messaging tests */
4238 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4240 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4241 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4242 /* testing only sizing messages */
4243 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
4244 "edit box create - sizing", FALSE);
4246 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4248 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4249 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4250 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4251 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4253 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4254 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
4256 DestroyWindow(hwnd);
4259 static void test_notifyformat(void)
4264 hwnd = create_listview_control(LVS_REPORT);
4265 ok(hwnd != NULL, "failed to create a listview window\n");
4267 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4268 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4269 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4271 SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4273 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
4275 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4278 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
4280 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4285 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4286 DestroyWindow(hwnd);
4290 DestroyWindow(hwnd);
4292 /* test failure in parent WM_NOTIFYFORMAT */
4294 hwnd = create_listview_control(LVS_REPORT);
4295 ok(hwnd != NULL, "failed to create a listview window\n");
4296 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4297 ok(IsWindow(header), "expected header to be created\n");
4298 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4300 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4301 ok( r == 1, "Expected 1, got %d\n", r );
4302 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4303 ok(r != 0, "Expected valid format\n");
4305 notifyFormat = NFR_UNICODE;
4306 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4307 expect(NFR_UNICODE, r);
4308 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4310 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4311 ok( r == 1, "Expected 1, got %d\n", r );
4313 notifyFormat = NFR_ANSI;
4314 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4315 expect(NFR_ANSI, r);
4316 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4318 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4319 ok( r == 1, "Expected 1, got %d\n", r );
4321 DestroyWindow(hwnd);
4323 hwndparentW = create_parent_window(TRUE);
4324 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
4325 if (!IsWindow(hwndparentW)) return;
4328 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4329 ok(hwnd != NULL, "failed to create a listview window\n");
4330 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4331 ok(IsWindow(header), "expected header to be created\n");
4332 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4334 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4336 DestroyWindow(hwnd);
4337 /* receiving error code defaulting to ansi */
4339 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4340 ok(hwnd != NULL, "failed to create a listview window\n");
4341 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4342 ok(IsWindow(header), "expected header to be created\n");
4343 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4345 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4347 DestroyWindow(hwnd);
4348 /* receiving ansi code from unicode window, use it */
4349 notifyFormat = NFR_ANSI;
4350 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4351 ok(hwnd != NULL, "failed to create a listview window\n");
4352 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4353 ok(IsWindow(header), "expected header to be created\n");
4354 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4356 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4358 DestroyWindow(hwnd);
4359 /* unicode listview with ansi parent window */
4361 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4362 ok(hwnd != NULL, "failed to create a listview window\n");
4363 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4364 ok(IsWindow(header), "expected header to be created\n");
4365 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4367 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4369 DestroyWindow(hwnd);
4370 /* unicode listview with ansi parent window, return error code */
4372 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4373 ok(hwnd != NULL, "failed to create a listview window\n");
4374 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4375 ok(IsWindow(header), "expected header to be created\n");
4376 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4378 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4380 DestroyWindow(hwnd);
4382 DestroyWindow(hwndparentW);
4385 static void test_indentation(void)
4391 hwnd = create_listview_control(LVS_REPORT);
4392 ok(hwnd != NULL, "failed to create a listview window\n");
4394 memset(&item, 0, sizeof(item));
4395 item.mask = LVIF_INDENT;
4397 item.iIndent = I_INDENTCALLBACK;
4398 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4401 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4404 item.mask = LVIF_INDENT;
4405 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
4408 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
4409 "get indent dispinfo", FALSE);
4411 DestroyWindow(hwnd);
4414 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
4419 static BOOL is_below_comctl_5(void)
4424 hwnd = create_listview_control(LVS_REPORT);
4425 ok(hwnd != NULL, "failed to create a listview window\n");
4426 insert_item(hwnd, 0);
4428 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
4430 DestroyWindow(hwnd);
4435 static void test_get_set_view(void)
4441 /* test style->view mapping */
4442 hwnd = create_listview_control(LVS_REPORT);
4443 ok(hwnd != NULL, "failed to create a listview window\n");
4445 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4446 expect(LV_VIEW_DETAILS, ret);
4448 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4450 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4451 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4452 expect(LV_VIEW_ICON, ret);
4454 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4455 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4456 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4457 expect(LV_VIEW_SMALLICON, ret);
4459 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4460 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4461 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4462 expect(LV_VIEW_LIST, ret);
4464 /* switching view doesn't touch window style */
4465 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4467 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4468 ok(style & LVS_LIST, "Expected style to be preserved\n");
4469 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4471 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4472 ok(style & LVS_LIST, "Expected style to be preserved\n");
4473 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4475 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4476 ok(style & LVS_LIST, "Expected style to be preserved\n");
4478 DestroyWindow(hwnd);
4481 static void test_canceleditlabel(void)
4483 HWND hwnd, hwndedit;
4487 static CHAR test[] = "test";
4488 static const CHAR test1[] = "test1";
4490 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4491 ok(hwnd != NULL, "failed to create a listview window\n");
4493 insert_item(hwnd, 0);
4495 /* try without edit created */
4496 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4497 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4499 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4500 "cancel edit label without edit", FALSE);
4502 /* cancel without data change */
4504 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4505 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4506 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4508 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4510 /* cancel after data change */
4511 memset(&itema, 0, sizeof(itema));
4512 itema.pszText = test;
4513 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4516 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4517 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4518 ret = SetWindowText(hwndedit, test1);
4520 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4522 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4523 memset(&itema, 0, sizeof(itema));
4524 itema.pszText = buff;
4525 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4526 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
4528 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4530 DestroyWindow(hwnd);
4533 static void test_mapidindex(void)
4538 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4539 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4540 ok(hwnd != NULL, "failed to create a listview window\n");
4541 insert_item(hwnd, 0);
4542 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4544 DestroyWindow(hwnd);
4546 hwnd = create_listview_control(LVS_REPORT);
4547 ok(hwnd != NULL, "failed to create a listview window\n");
4549 /* LVM_MAPINDEXTOID with invalid index */
4550 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4553 insert_item(hwnd, 0);
4554 insert_item(hwnd, 1);
4556 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
4558 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
4561 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4563 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4565 /* remove 0 indexed item, id retained */
4566 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
4567 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4569 /* new id starts from previous value */
4570 insert_item(hwnd, 1);
4571 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4574 /* get index by id */
4575 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4577 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4579 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4581 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4584 DestroyWindow(hwnd);
4587 static void test_getitemspacing(void)
4596 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4597 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4600 hwnd = create_listview_control(LVS_ICON);
4601 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4603 expect(cx, LOWORD(ret));
4604 expect(cy, HIWORD(ret));
4606 /* now try with icons */
4607 himl = ImageList_Create(40, 40, 0, 4, 4);
4608 ok(himl != NULL, "failed to create imagelist\n");
4609 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4610 ok(hbmp != NULL, "failed to create bitmap\n");
4611 ret = ImageList_Add(himl, hbmp, 0);
4613 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4616 itema.mask = LVIF_IMAGE;
4620 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4622 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4624 /* spacing + icon size returned */
4625 expect(cx + 40, LOWORD(ret));
4626 expect(cy + 40, HIWORD(ret));
4628 DestroyWindow(hwnd);
4630 hwnd = create_listview_control(LVS_SMALLICON);
4631 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4633 expect(cx, LOWORD(ret));
4634 expect(cy, HIWORD(ret));
4636 DestroyWindow(hwnd);
4638 hwnd = create_listview_control(LVS_REPORT);
4639 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4641 expect(cx, LOWORD(ret));
4642 expect(cy, HIWORD(ret));
4644 DestroyWindow(hwnd);
4646 hwnd = create_listview_control(LVS_LIST);
4647 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4649 expect(cx, LOWORD(ret));
4650 expect(cy, HIWORD(ret));
4652 DestroyWindow(hwnd);
4655 static void test_getcolumnwidth(void)
4664 /* default column width */
4665 hwnd = create_listview_control(LVS_ICON);
4666 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4668 style = GetWindowLong(hwnd, GWL_STYLE);
4669 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
4670 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4671 todo_wine expect(8, ret);
4672 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
4673 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
4675 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4677 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4679 DestroyWindow(hwnd);
4681 /* default column width with item added */
4682 hwnd = create_listview_control(LVS_LIST);
4683 memset(&itema, 0, sizeof(itema));
4684 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4685 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4687 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, ret);
4688 ReleaseDC(hwnd, hdc);
4689 DestroyWindow(hwnd);
4692 static void test_scrollnotify(void)
4697 hwnd = create_listview_control(LVS_REPORT);
4699 insert_column(hwnd, 0);
4700 insert_column(hwnd, 1);
4701 insert_item(hwnd, 0);
4703 /* make it scrollable - resize */
4704 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4706 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4709 /* try with dummy call */
4710 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4711 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
4713 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4714 "scroll notify 1", TRUE);
4716 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4717 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
4719 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4720 "scroll notify 2", TRUE);
4722 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4723 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4725 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4726 "scroll notify 3", TRUE);
4728 DestroyWindow(hwnd);
4731 static void test_LVS_EX_TRANSPARENTBKGND(void)
4737 hwnd = create_listview_control(LVS_REPORT);
4739 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4742 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4743 LVS_EX_TRANSPARENTBKGND);
4745 ret = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
4746 if (ret != CLR_NONE)
4748 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4749 DestroyWindow(hwnd);
4753 /* try to set some back color and check this style bit */
4754 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4756 ret = SendMessage(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4757 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4759 /* now test what this style actually does */
4760 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4761 LVS_EX_TRANSPARENTBKGND);
4763 hdc = GetWindowDC(hwndparent);
4765 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4766 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4767 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4768 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4770 ReleaseDC(hwndparent, hdc);
4772 DestroyWindow(hwnd);
4775 static void test_approximate_viewrect(void)
4782 static CHAR test[] = "abracadabra, a very long item label";
4784 hwnd = create_listview_control(LVS_ICON);
4785 himl = ImageList_Create(40, 40, 0, 4, 4);
4786 ok(himl != NULL, "failed to create imagelist\n");
4787 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4788 ok(hbmp != NULL, "failed to create bitmap\n");
4789 ret = ImageList_Add(himl, hbmp, 0);
4791 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4794 itema.mask = LVIF_IMAGE;
4798 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4801 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4805 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4809 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4810 expect(MAKELONG(77,827), ret);
4812 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4813 ok(ret != 0, "got 0\n");
4815 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4816 expect(MAKELONG(102,302), ret);
4818 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4819 expect(MAKELONG(52,52), ret);
4821 itema.pszText = test;
4822 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4824 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4825 expect(MAKELONG(52,52), ret);
4827 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4828 expect(MAKELONG(52,2), ret);
4829 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4830 expect(MAKELONG(52,52), ret);
4831 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4832 expect(MAKELONG(102,52), ret);
4833 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4834 expect(MAKELONG(102,102), ret);
4835 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4836 expect(MAKELONG(102,102), ret);
4837 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4838 expect(MAKELONG(102,152), ret);
4839 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4840 expect(MAKELONG(102,152), ret);
4841 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4842 expect(MAKELONG(152,152), ret);
4844 DestroyWindow(hwnd);
4847 static void test_finditem(void)
4854 hwnd = create_listview_control(LVS_REPORT);
4855 insert_item(hwnd, 0);
4857 memset(&fi, 0, sizeof(fi));
4859 /* full string search, inserted text was "foo" */
4861 fi.flags = LVFI_STRING;
4863 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4865 /* partial string search, inserted text was "foo" */
4867 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4869 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4871 /* partial string search, part after start char */
4873 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4875 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4878 /* try with LVFI_SUBSTRING */
4880 fi.flags = LVFI_SUBSTRING;
4882 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4885 win_skip("LVFI_SUBSTRING not supported\n");
4886 DestroyWindow(hwnd);
4891 fi.flags = LVFI_SUBSTRING;
4893 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4896 fi.flags = LVFI_SUBSTRING;
4898 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4902 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
4904 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4907 DestroyWindow(hwnd);
4910 static void test_LVS_EX_HEADERINALLVIEWS(void)
4915 hwnd = create_listview_control(LVS_ICON);
4917 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4918 LVS_EX_HEADERINALLVIEWS);
4920 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4921 if (!IsWindow(header))
4923 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4924 DestroyWindow(hwnd);
4928 /* LVS_NOCOLUMNHEADER works as before */
4929 style = GetWindowLongA(hwnd, GWL_STYLE);
4930 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
4931 style = GetWindowLongA(header, GWL_STYLE);
4932 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
4933 style = GetWindowLongA(hwnd, GWL_STYLE);
4934 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
4935 style = GetWindowLongA(header, GWL_STYLE);
4936 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
4938 /* try to remove style */
4939 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
4940 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4941 ok(IsWindow(header), "Expected header to be created\n");
4942 style = GetWindowLongA(header, GWL_STYLE);
4943 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
4945 DestroyWindow(hwnd);
4947 /* check other styles */
4948 hwnd = create_listview_control(LVS_LIST);
4949 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4950 LVS_EX_HEADERINALLVIEWS);
4951 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4952 ok(IsWindow(header), "Expected header to be created\n");
4953 DestroyWindow(hwnd);
4955 hwnd = create_listview_control(LVS_SMALLICON);
4956 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4957 LVS_EX_HEADERINALLVIEWS);
4958 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4959 ok(IsWindow(header), "Expected header to be created\n");
4960 DestroyWindow(hwnd);
4962 hwnd = create_listview_control(LVS_REPORT);
4963 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4964 LVS_EX_HEADERINALLVIEWS);
4965 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4966 ok(IsWindow(header), "Expected header to be created\n");
4967 DestroyWindow(hwnd);
4970 static void test_hover(void)
4975 hwnd = create_listview_control(LVS_ICON);
4977 /* test WM_MOUSEHOVER forwarding */
4978 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4979 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4981 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
4982 g_block_hover = TRUE;
4983 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4984 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4986 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
4987 g_block_hover = FALSE;
4989 r = SendMessage(hwnd, LVM_SETHOVERTIME, 0, 500);
4990 expect(HOVER_DEFAULT, r);
4991 r = SendMessage(hwnd, LVM_GETHOVERTIME, 0, 0);
4994 DestroyWindow(hwnd);
4997 static void test_destroynotify(void)
5001 hwnd = create_listview_control(LVS_REPORT);
5002 ok(hwnd != NULL, "failed to create listview window\n");
5004 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5005 DestroyWindow(hwnd);
5006 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
5009 static void test_header_notification(void)
5011 static char textA[] = "newtext";
5019 list = create_listview_control(LVS_REPORT);
5020 ok(list != NULL, "failed to create listview window\n");
5022 memset(&col, 0, sizeof(col));
5023 col.mask = LVCF_WIDTH;
5025 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5028 /* check list parent notification after header item changed,
5029 this test should be placed before header subclassing to avoid
5030 Listview -> Header messages to be logged */
5031 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5033 col.mask = LVCF_TEXT;
5034 col.pszText = textA;
5035 r = SendMessage(list, LVM_SETCOLUMNA, 0, (LPARAM)&col);
5038 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_changed_seq,
5039 "header notify, listview", FALSE);
5040 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5041 "header notify, parent", FALSE);
5043 header = subclass_header(list);
5045 ret = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
5048 memset(&item, 0, sizeof(item));
5049 item.mask = HDI_WIDTH;
5050 ret = SendMessage(header, HDM_GETITEMA, 0, (LPARAM)&item);
5052 expect(100, item.cxy);
5054 nmh.hdr.hwndFrom = header;
5055 nmh.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
5056 nmh.hdr.code = HDN_ITEMCHANGEDA;
5059 item.mask = HDI_WIDTH;
5062 ret = SendMessage(list, WM_NOTIFY, 0, (LPARAM)&nmh);
5065 DestroyWindow(list);
5068 static void test_header_notification2(void)
5070 static char textA[] = "newtext";
5077 struct message parent_header_notify_seq[] = {
5078 { WM_NOTIFY, sent|id, 0, 0, 0 },
5082 list = create_listview_control(LVS_REPORT);
5083 ok(list != NULL, "failed to create listview window\n");
5085 memset(&col, 0, sizeof(col));
5086 col.mask = LVCF_WIDTH | LVCF_TEXT;
5088 col.pszText = textA;
5089 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5092 header = ListView_GetHeader(list);
5093 ok(header != 0, "No header\n");
5094 memset(&itemW, 0, sizeof(itemW));
5095 itemW.mask = HDI_WIDTH | HDI_ORDER | HDI_TEXT;
5096 itemW.pszText = buffer;
5097 itemW.cchTextMax = sizeof(buffer);
5098 ret = SendMessageW(header, HDM_GETITEMW, 0, (LPARAM)&itemW);
5101 nmhdr.hdr.hwndFrom = header;
5102 nmhdr.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
5105 nmhdr.pitem = &itemW;
5107 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5108 nmhdr.hdr.code = HDN_ITEMCHANGINGW;
5109 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5110 parent_header_notify_seq[0].id = HDN_ITEMCHANGINGA;
5111 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5112 "header notify, parent", TRUE);
5114 ok(nmhdr.hdr.code == HDN_ITEMCHANGINGA, "Expected ANSI notification code\n");
5115 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5116 nmhdr.hdr.code = HDN_ITEMCHANGEDW;
5117 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5118 parent_header_notify_seq[0].id = HDN_ITEMCHANGEDA;
5119 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5120 "header notify, parent", TRUE);
5122 ok(nmhdr.hdr.code == HDN_ITEMCHANGEDA, "Expected ANSI notification code\n");
5123 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5125 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5126 nmhdr.hdr.code = HDN_ITEMCLICKW;
5127 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5128 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_click_seq,
5129 "header notify, parent", FALSE);
5130 ok(nmhdr.hdr.code == HDN_ITEMCLICKA, "Expected ANSI notification code\n");
5131 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5132 nmhdr.hdr.code = HDN_ITEMDBLCLICKW;
5133 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5134 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5135 "header notify, parent", FALSE);
5136 ok(nmhdr.hdr.code == HDN_ITEMDBLCLICKW, "Expected Unicode notification code\n");
5137 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5138 nmhdr.hdr.code = HDN_DIVIDERDBLCLICKW;
5139 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5140 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_divider_dclick_seq,
5141 "header notify, parent", TRUE);
5142 ok(nmhdr.hdr.code == HDN_DIVIDERDBLCLICKA, "Expected ANSI notification code\n");
5143 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5144 nmhdr.hdr.code = HDN_BEGINTRACKW;
5145 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5146 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5147 "header notify, parent", FALSE);
5148 ok(nmhdr.hdr.code == HDN_BEGINTRACKW, "Expected Unicode notification code\n");
5149 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5150 nmhdr.hdr.code = HDN_ENDTRACKW;
5151 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5152 parent_header_notify_seq[0].id = HDN_ENDTRACKA;
5153 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5154 "header notify, parent", FALSE);
5155 ok(nmhdr.hdr.code == HDN_ENDTRACKA, "Expected ANSI notification code\n");
5156 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5157 nmhdr.hdr.code = HDN_TRACKW;
5158 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5159 parent_header_notify_seq[0].id = HDN_TRACKA;
5160 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5161 "header notify, parent", FALSE);
5162 ok(nmhdr.hdr.code == HDN_TRACKA, "Expected ANSI notification code\n");
5163 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5164 nmhdr.hdr.code = HDN_BEGINDRAG;
5165 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5166 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5167 "header notify, parent", FALSE);
5168 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5169 nmhdr.hdr.code = HDN_ENDDRAG;
5170 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5171 parent_header_notify_seq[0].id = HDN_ENDDRAG;
5172 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5173 "header notify, parent", FALSE);
5174 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5175 nmhdr.hdr.code = HDN_FILTERCHANGE;
5176 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5177 parent_header_notify_seq[0].id = HDN_FILTERCHANGE;
5178 parent_header_notify_seq[0].flags |= optional; /* NT4 does not send this message */
5179 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5180 "header notify, parent", FALSE);
5181 parent_header_notify_seq[0].flags &= ~optional;
5182 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5183 nmhdr.hdr.code = HDN_BEGINFILTEREDIT;
5184 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5185 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5186 "header notify, parent", FALSE);
5187 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5188 nmhdr.hdr.code = HDN_ENDFILTEREDIT;
5189 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5190 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5191 "header notify, parent", FALSE);
5192 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5193 nmhdr.hdr.code = HDN_ITEMSTATEICONCLICK;
5194 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5195 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5196 "header notify, parent", FALSE);
5197 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5198 nmhdr.hdr.code = HDN_ITEMKEYDOWN;
5199 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5200 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5201 "header notify, parent", FALSE);
5203 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5205 DestroyWindow(list);
5208 static void test_createdragimage(void)
5214 list = create_listview_control(LVS_ICON);
5215 ok(list != NULL, "failed to create listview window\n");
5217 insert_item(list, 0);
5220 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
5221 ok(himl == NULL, "got %p\n", himl);
5223 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
5224 ok(himl != NULL, "got %p\n", himl);
5225 ImageList_Destroy(himl);
5227 DestroyWindow(list);
5230 static void test_dispinfo(void)
5232 static const char testA[] = "TEST";
5238 hwnd = create_listview_control(LVS_ICON);
5239 ok(hwnd != NULL, "failed to create listview window\n");
5241 insert_item(hwnd, 0);
5243 memset(&item, 0, sizeof(item));
5244 item.pszText = LPSTR_TEXTCALLBACKA;
5245 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5248 g_disp_A_to_W = TRUE;
5249 item.pszText = (char*)buff;
5250 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
5251 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
5252 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
5253 g_disp_A_to_W = FALSE;
5255 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
5256 "got %s, expected %s\n", item.pszText, testA);
5258 DestroyWindow(hwnd);
5261 static void test_LVM_SETITEMTEXT(void)
5263 static char testA[] = "TEST";
5268 hwnd = create_listview_control(LVS_ICON);
5269 ok(hwnd != NULL, "failed to create listview window\n");
5271 insert_item(hwnd, 0);
5273 /* null item pointer */
5274 ret = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, 0);
5277 ret = SendMessage(hwnd, LVM_SETITEMTEXTW, 0, 0);
5280 /* index out of bounds */
5281 item.pszText = testA;
5282 item.cchTextMax = 0; /* ignored */
5285 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 1, (LPARAM)&item);
5288 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, -1, (LPARAM)&item);
5291 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5294 DestroyWindow(hwnd);
5297 static void test_imagelists(void)
5300 HIMAGELIST himl1, himl2, himl3;
5303 himl1 = ImageList_Create(40, 40, 0, 4, 4);
5304 himl2 = ImageList_Create(40, 40, 0, 4, 4);
5305 himl3 = ImageList_Create(40, 40, 0, 4, 4);
5306 ok(himl1 != NULL, "Failed to create imagelist\n");
5307 ok(himl2 != NULL, "Failed to create imagelist\n");
5308 ok(himl3 != NULL, "Failed to create imagelist\n");
5310 hwnd = create_listview_control(LVS_REPORT | LVS_SHAREIMAGELISTS);
5311 header = subclass_header(hwnd);
5313 ok(header != NULL, "Expected header\n");
5314 ret = SendMessage(header, HDM_GETIMAGELIST, 0, 0);
5315 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5317 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5319 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5320 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5321 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5322 "set normal image list", FALSE);
5324 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5326 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5327 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5328 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5329 "set state image list", TRUE);
5331 ret = SendMessage(header, HDM_GETIMAGELIST, 0, 0);
5332 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5334 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5336 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5337 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5338 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_set_imagelist,
5339 "set small image list", FALSE);
5341 ret = SendMessage(header, HDM_GETIMAGELIST, 0, 0);
5342 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5343 DestroyWindow(hwnd);
5345 hwnd = create_listview_control(WS_VISIBLE | LVS_ICON);
5347 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5349 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5350 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5351 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5352 "set normal image list", FALSE);
5354 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5356 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5357 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5358 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5359 "set state image list", FALSE);
5361 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5363 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5364 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5365 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5366 "set small image list", FALSE);
5368 header = ListView_GetHeader(hwnd);
5369 ok(header == NULL, "Expected no header, got %p\n", header);
5371 SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | LVS_REPORT);
5373 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
5374 ok(header != NULL, "Expected header, got NULL\n");
5376 ret = SendMessage(header, HDM_GETIMAGELIST, 0, 0);
5377 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5379 DestroyWindow(hwnd);
5382 static void test_deleteitem(void)
5389 hwnd = create_listview_control(LVS_REPORT);
5391 insert_item(hwnd, 0);
5392 insert_item(hwnd, 0);
5393 insert_item(hwnd, 0);
5394 insert_item(hwnd, 0);
5395 insert_item(hwnd, 0);
5397 g_focus_test_LVN_DELETEITEM = TRUE;
5399 /* delete focused item (not the last index) */
5400 item.stateMask = LVIS_FOCUSED;
5401 item.state = LVIS_FOCUSED;
5402 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
5403 ok(ret == TRUE, "got %d\n", ret);
5404 ret = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
5405 ok(ret == TRUE, "got %d\n", ret);
5406 /* next item gets focus */
5407 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5408 ok(state == LVIS_FOCUSED, "got %x\n", state);
5410 /* focus last item and delete it */
5411 item.stateMask = LVIS_FOCUSED;
5412 item.state = LVIS_FOCUSED;
5413 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
5414 ok(ret == TRUE, "got %d\n", ret);
5415 ret = SendMessageA(hwnd, LVM_DELETEITEM, 3, 0);
5416 ok(ret == TRUE, "got %d\n", ret);
5417 /* new last item gets focus */
5418 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5419 ok(state == LVIS_FOCUSED, "got %x\n", state);
5421 /* focus first item and delete it */
5422 item.stateMask = LVIS_FOCUSED;
5423 item.state = LVIS_FOCUSED;
5424 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
5425 ok(ret == TRUE, "got %d\n", ret);
5426 ret = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
5427 ok(ret == TRUE, "got %d\n", ret);
5428 /* new first item gets focus */
5429 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5430 ok(state == LVIS_FOCUSED, "got %x\n", state);
5432 g_focus_test_LVN_DELETEITEM = FALSE;
5434 DestroyWindow(hwnd);
5437 START_TEST(listview)
5440 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
5442 ULONG_PTR ctx_cookie;
5446 hComctl32 = GetModuleHandleA("comctl32.dll");
5447 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
5448 if (pInitCommonControlsEx)
5450 INITCOMMONCONTROLSEX iccex;
5451 iccex.dwSize = sizeof(iccex);
5452 iccex.dwICC = ICC_LISTVIEW_CLASSES;
5453 pInitCommonControlsEx(&iccex);
5456 InitCommonControls();
5458 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
5460 hwndparent = create_parent_window(FALSE);
5461 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5463 g_is_below_5 = is_below_comctl_5();
5465 test_header_notification();
5466 test_header_notification2();
5473 test_icon_spacing();
5476 test_item_position();
5481 test_subitem_rect();
5485 test_nosortheader();
5489 test_getitemposition();
5490 test_columnscreation();
5492 test_notifyformat();
5494 test_getitemspacing();
5495 test_getcolumnwidth();
5496 test_approximate_viewrect();
5499 test_destroynotify();
5500 test_createdragimage();
5502 test_LVM_SETITEMTEXT();
5506 if (!load_v6_module(&ctx_cookie, &hCtx))
5508 DestroyWindow(hwndparent);
5512 /* this is a XP SP3 failure workaround */
5513 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
5514 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
5516 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
5517 if (!IsWindow(hwnd))
5519 win_skip("FIXME: failed to create ListView window.\n");
5520 unload_v6_module(ctx_cookie, hCtx);
5521 DestroyWindow(hwndparent);
5525 DestroyWindow(hwnd);
5527 /* comctl32 version 6 tests start here */
5528 test_get_set_view();
5529 test_canceleditlabel();
5531 test_scrollnotify();
5532 test_LVS_EX_TRANSPARENTBKGND();
5533 test_LVS_EX_HEADERINALLVIEWS();
5537 unload_v6_module(ctx_cookie, hCtx);
5539 DestroyWindow(hwndparent);