Release 1.6-rc2.
[wine/testsucceed.git] / dlls / comctl32 / tests / listview.c
blob1ac4333c0d7c2f63401683a8609afad4f537eb87
1 /*
2 * ListView tests
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
23 #include <stdio.h>
24 #include <windows.h>
25 #include <commctrl.h>
27 #include "wine/test.h"
28 #include "v6util.h"
29 #include "msg.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
38 #define LISTVIEW_ID 0
39 #define HEADER_ID 1
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 },
80 { 0 }
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 },
91 { 0 }
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) },
98 { 0 }
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 },
129 { 0 }
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 },
149 { 0 }
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 },
164 { 0 }
167 static const struct message listview_ownerdata_switchto_seq[] = {
168 { WM_STYLECHANGING, sent },
169 { WM_STYLECHANGED, sent },
170 { 0 }
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 },
176 { 0 }
179 static const struct message empty_seq[] = {
180 { 0 }
183 static const struct message forward_erasebkgnd_parent_seq[] = {
184 { WM_ERASEBKGND, sent },
185 { 0 }
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 */
192 { 0 }
195 static const struct message ownerdata_setstate_all_parent_seq[] = {
196 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
197 { 0 }
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 },
205 { 0 }
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 },
211 { 0 }
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 },
229 { 0 }
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 },
238 { 0 }
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 },
244 { 0 }
247 static const struct message single_getdispinfo_parent_seq[] = {
248 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
249 { 0 }
252 static const struct message getitemposition_seq1[] = {
253 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
254 { 0 }
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 },
260 { 0 }
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 },
272 { 0 }
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 },
289 { 0 }
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 },
295 { 0 }
298 static const struct message setredraw_seq[] = {
299 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
300 { 0 }
303 static const struct message lvs_ex_transparentbkgnd_seq[] = {
304 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
305 { 0 }
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 },
312 { 0 }
315 static const struct message hover_parent[] = {
316 { WM_GETDLGCODE, sent }, /* todo_wine */
317 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
318 { 0 }
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 },
330 { 0 }
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 },
337 { 0 }
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 },
343 { 0 }
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 },
352 { 0 }
355 static const struct message listview_set_imagelist[] = {
356 { LVM_SETIMAGELIST, sent|id, 0, 0, LISTVIEW_ID },
357 { 0 }
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 },
363 { 0 }
366 static const struct message parent_insert_focused_seq[] = {
367 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
368 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
369 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
370 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
371 { WM_NOTIFY, sent|id, 0, 0, LVN_INSERTITEM },
372 { 0 }
375 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
377 static LONG defwndproc_counter = 0;
378 LRESULT ret;
379 struct message msg;
381 msg.message = message;
382 msg.flags = sent|wparam|lparam;
383 if (defwndproc_counter) msg.flags |= defwinproc;
384 msg.wParam = wParam;
385 msg.lParam = lParam;
386 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
388 /* log system messages, except for painting */
389 if (message < WM_USER &&
390 message != WM_PAINT &&
391 message != WM_ERASEBKGND &&
392 message != WM_NCPAINT &&
393 message != WM_NCHITTEST &&
394 message != WM_GETTEXT &&
395 message != WM_GETICON &&
396 message != WM_DEVICECHANGE)
398 add_message(sequences, PARENT_SEQ_INDEX, &msg);
399 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
401 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
403 switch (message)
405 case WM_NOTIFY:
407 switch (((NMHDR*)lParam)->code)
409 case LVN_BEGINLABELEDIT:
411 HWND edit = NULL;
413 /* subclass edit box */
414 if (!blockEdit)
415 edit = subclass_editbox(((NMHDR*)lParam)->hwndFrom);
417 if (edit)
419 INT len = SendMessageA(edit, EM_GETLIMITTEXT, 0, 0);
420 ok(len == 259 || broken(len == 260) /* includes NULL in NT4 */,
421 "text limit %d, expected 259\n", len);
424 return blockEdit;
426 case LVN_ENDLABELEDIT:
428 HWND edit;
430 /* always accept new item text */
431 NMLVDISPINFO *di = (NMLVDISPINFO*)lParam;
432 g_editbox_disp_info = *di;
433 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText ? di->item.pszText : "(null)");
435 /* edit control still available from this notification */
436 edit = (HWND)SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETEDITCONTROL, 0, 0);
437 ok(IsWindow(edit), "expected valid edit control handle\n");
438 ok((GetWindowLongA(edit, GWL_STYLE) & ES_MULTILINE) == 0, "edit is multiline\n");
440 return TRUE;
442 case LVN_BEGINSCROLL:
443 case LVN_ENDSCROLL:
445 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
447 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
448 "BEGIN" : "END", pScroll->dx, pScroll->dy);
450 break;
451 case LVN_ITEMCHANGING:
453 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
454 g_nmlistview_changing = *nmlv;
456 break;
457 case LVN_ITEMCHANGED:
459 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
460 g_nmlistview = *nmlv;
462 break;
463 case LVN_GETDISPINFOA:
465 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
466 g_itema = dispinfo->item;
468 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
470 static const WCHAR testW[] = {'T','E','S','T',0};
471 dispinfo->hdr.code = LVN_GETDISPINFOW;
472 memcpy(dispinfo->item.pszText, testW, sizeof(testW));
475 /* test control buffer size for text, 10 used to mask cases when control
476 is using caller buffer to process LVM_GETITEM for example */
477 if (dispinfo->item.mask & LVIF_TEXT && dispinfo->item.cchTextMax > 10)
478 ok(dispinfo->item.cchTextMax == 260 ||
479 broken(dispinfo->item.cchTextMax == 264) /* NT4 reports aligned size */,
480 "buffer size %d\n", dispinfo->item.cchTextMax);
482 break;
483 case LVN_DELETEITEM:
484 if (g_focus_test_LVN_DELETEITEM)
486 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
487 UINT state;
489 state = SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETITEMSTATE, nmlv->iItem, LVIS_FOCUSED);
490 ok(state == 0, "got state %x\n", state);
492 break;
493 case NM_HOVER:
494 if (g_block_hover) return 1;
495 break;
497 break;
499 case WM_NOTIFYFORMAT:
501 /* force to return format */
502 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
503 break;
507 defwndproc_counter++;
508 ret = DefWindowProcA(hwnd, message, wParam, lParam);
509 defwndproc_counter--;
511 return ret;
514 static BOOL register_parent_wnd_class(BOOL Unicode)
516 WNDCLASSA clsA;
517 WNDCLASSW clsW;
519 if (Unicode)
521 clsW.style = 0;
522 clsW.lpfnWndProc = parent_wnd_proc;
523 clsW.cbClsExtra = 0;
524 clsW.cbWndExtra = 0;
525 clsW.hInstance = GetModuleHandleW(NULL);
526 clsW.hIcon = 0;
527 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
528 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
529 clsW.lpszMenuName = NULL;
530 clsW.lpszClassName = testparentclassW;
532 else
534 clsA.style = 0;
535 clsA.lpfnWndProc = parent_wnd_proc;
536 clsA.cbClsExtra = 0;
537 clsA.cbWndExtra = 0;
538 clsA.hInstance = GetModuleHandleA(NULL);
539 clsA.hIcon = 0;
540 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
541 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
542 clsA.lpszMenuName = NULL;
543 clsA.lpszClassName = "Listview test parent class";
546 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
549 static HWND create_parent_window(BOOL Unicode)
551 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
552 HWND hwnd;
554 if (!register_parent_wnd_class(Unicode))
555 return NULL;
557 blockEdit = FALSE;
558 notifyFormat = -1;
560 if (Unicode)
561 hwnd = CreateWindowExW(0, testparentclassW, nameW,
562 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
563 WS_MAXIMIZEBOX | WS_VISIBLE,
564 0, 0, 100, 100,
565 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
566 else
567 hwnd = CreateWindowExA(0, "Listview test parent class",
568 "Listview test parent window",
569 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
570 WS_MAXIMIZEBOX | WS_VISIBLE,
571 0, 0, 100, 100,
572 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
573 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
574 return hwnd;
577 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
579 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
580 static LONG defwndproc_counter = 0;
581 LRESULT ret;
582 struct message msg;
584 /* some debug output for style changing */
585 if ((message == WM_STYLECHANGING ||
586 message == WM_STYLECHANGED) && lParam)
588 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
589 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
592 msg.message = message;
593 msg.flags = sent|wparam|lparam;
594 if (defwndproc_counter) msg.flags |= defwinproc;
595 msg.wParam = wParam;
596 msg.lParam = lParam;
597 msg.id = LISTVIEW_ID;
598 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
599 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
601 defwndproc_counter++;
602 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
603 defwndproc_counter--;
604 return ret;
607 static HWND create_listview_control(DWORD style)
609 WNDPROC oldproc;
610 HWND hwnd;
611 RECT rect;
613 GetClientRect(hwndparent, &rect);
614 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
615 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
616 0, 0, rect.right, rect.bottom,
617 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
618 ok(hwnd != NULL, "gle=%d\n", GetLastError());
620 if (!hwnd) return NULL;
622 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
623 (LONG_PTR)listview_subclass_proc);
624 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
626 return hwnd;
629 /* unicode listview window with specified parent */
630 static HWND create_listview_controlW(DWORD style, HWND parent)
632 WNDPROC oldproc;
633 HWND hwnd;
634 RECT rect;
635 static const WCHAR nameW[] = {'f','o','o',0};
637 GetClientRect(parent, &rect);
638 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
639 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
640 0, 0, rect.right, rect.bottom,
641 parent, NULL, GetModuleHandleW(NULL), NULL);
642 ok(hwnd != NULL, "gle=%d\n", GetLastError());
644 if (!hwnd) return NULL;
646 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
647 (LONG_PTR)listview_subclass_proc);
648 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
650 return hwnd;
653 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
655 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
656 static LONG defwndproc_counter = 0;
657 LRESULT ret;
658 struct message msg;
660 msg.message = message;
661 msg.flags = sent|wparam|lparam;
662 if (defwndproc_counter) msg.flags |= defwinproc;
663 msg.wParam = wParam;
664 msg.lParam = lParam;
665 msg.id = HEADER_ID;
666 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
668 defwndproc_counter++;
669 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
670 defwndproc_counter--;
671 return ret;
674 static HWND subclass_header(HWND hwndListview)
676 WNDPROC oldproc;
677 HWND hwnd;
679 hwnd = ListView_GetHeader(hwndListview);
680 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
681 (LONG_PTR)header_subclass_proc);
682 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
684 return hwnd;
687 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
689 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
690 static LONG defwndproc_counter = 0;
691 LRESULT ret;
692 struct message msg;
694 msg.message = message;
695 msg.flags = sent|wparam|lparam;
696 if (defwndproc_counter) msg.flags |= defwinproc;
697 msg.wParam = wParam;
698 msg.lParam = lParam;
699 msg.id = 0;
701 /* all we need is sizing */
702 if (message == WM_WINDOWPOSCHANGING ||
703 message == WM_NCCALCSIZE ||
704 message == WM_WINDOWPOSCHANGED ||
705 message == WM_MOVE ||
706 message == WM_SIZE)
708 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
711 defwndproc_counter++;
712 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
713 defwndproc_counter--;
714 return ret;
717 static HWND subclass_editbox(HWND hwndListview)
719 WNDPROC oldproc;
720 HWND hwnd;
722 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
723 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
724 (LONG_PTR)editbox_subclass_proc);
725 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
727 return hwnd;
730 /* Performs a single LVM_HITTEST test */
731 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
732 BOOL todo_item, BOOL todo_flags, int line)
734 LVHITTESTINFO lpht;
735 INT ret;
737 lpht.pt.x = x;
738 lpht.pt.y = y;
739 lpht.iSubItem = 10;
741 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
743 if (todo_item)
745 todo_wine
747 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
748 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
749 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
752 else
754 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
755 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
756 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
759 if (todo_flags)
761 todo_wine
762 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
764 else if (broken_flags)
765 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
766 "Expected flags %x, got %x\n", flags, lpht.flags);
767 else
768 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
771 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
773 /* Performs a single LVM_SUBITEMHITTEST test */
774 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
775 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
777 LVHITTESTINFO lpht;
778 INT ret;
780 lpht.pt.x = x;
781 lpht.pt.y = y;
783 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
785 if (todo_item)
787 todo_wine
789 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
790 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
793 else
795 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
796 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
799 if (todo_subitem)
801 todo_wine
802 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
804 else
805 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
807 if (todo_flags)
809 todo_wine
810 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
812 else
813 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
816 #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__)
818 static void test_images(void)
820 HWND hwnd;
821 INT r;
822 LVITEM item;
823 HIMAGELIST himl;
824 HBITMAP hbmp;
825 RECT r1, r2;
826 static CHAR hello[] = "hello";
828 himl = ImageList_Create(40, 40, 0, 4, 4);
829 ok(himl != NULL, "failed to create imagelist\n");
831 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
832 ok(hbmp != NULL, "failed to create bitmap\n");
834 r = ImageList_Add(himl, hbmp, 0);
835 ok(r == 0, "should be zero\n");
837 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
838 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
839 ok(hwnd != NULL, "failed to create listview window\n");
841 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
842 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
844 ok(r == 0, "should return zero\n");
846 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
847 ok(r == 0, "should return zero\n");
849 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
850 ok(r != 0, "got 0\n");
852 /* returns dimensions */
854 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
855 ok(r == 0, "should be zero items\n");
857 item.mask = LVIF_IMAGE | LVIF_TEXT;
858 item.iItem = 0;
859 item.iSubItem = 1;
860 item.iImage = 0;
861 item.pszText = 0;
862 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
863 ok(r == -1, "should fail\n");
865 item.iSubItem = 0;
866 item.pszText = hello;
867 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
868 ok(r == 0, "should not fail\n");
870 memset(&r1, 0, sizeof r1);
871 r1.left = LVIR_ICON;
872 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
873 expect(1, r);
875 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
876 ok(r == TRUE, "should not fail\n");
878 item.iSubItem = 0;
879 item.pszText = hello;
880 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
881 ok(r == 0, "should not fail\n");
883 memset(&r2, 0, sizeof r2);
884 r2.left = LVIR_ICON;
885 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
886 expect(1, r);
888 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
890 DestroyWindow(hwnd);
893 static void test_checkboxes(void)
895 HWND hwnd;
896 LVITEMA item;
897 DWORD r;
898 static CHAR text[] = "Text",
899 text2[] = "Text2",
900 text3[] = "Text3";
902 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
903 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
904 ok(hwnd != NULL, "failed to create listview window\n");
906 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
907 item.mask = LVIF_TEXT | LVIF_STATE;
908 item.stateMask = 0xffff;
909 item.state = 0xfccc;
910 item.iItem = 0;
911 item.iSubItem = 0;
912 item.pszText = text;
913 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
914 expect(0, r);
916 item.iItem = 0;
917 item.mask = LVIF_STATE;
918 item.stateMask = 0xffff;
919 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
920 expect(1, r);
921 ok(item.state == 0xfccc, "state %x\n", item.state);
923 /* Don't set LVIF_STATE */
924 item.mask = LVIF_TEXT;
925 item.stateMask = 0xffff;
926 item.state = 0xfccc;
927 item.iItem = 1;
928 item.iSubItem = 0;
929 item.pszText = text;
930 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
931 expect(1, r);
933 item.iItem = 1;
934 item.mask = LVIF_STATE;
935 item.stateMask = 0xffff;
936 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
937 expect(1, r);
938 ok(item.state == 0, "state %x\n", item.state);
940 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
941 expect(0, r);
943 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
944 item.iItem = 0;
945 item.mask = LVIF_STATE;
946 item.stateMask = 0xffff;
947 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
948 expect(1, r);
949 if (item.state != 0x1ccc)
951 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
952 DestroyWindow(hwnd);
953 return;
956 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
957 item.iItem = 2;
958 item.mask = LVIF_TEXT;
959 item.state = 0;
960 item.pszText = text2;
961 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
962 expect(2, r);
964 item.iItem = 2;
965 item.mask = LVIF_STATE;
966 item.stateMask = 0xffff;
967 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
968 expect(1, r);
969 ok(item.state == 0x1000, "state %x\n", item.state);
971 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
972 item.iItem = 3;
973 item.mask = LVIF_TEXT | LVIF_STATE;
974 item.stateMask = 0xffff;
975 item.state = 0x2aaa;
976 item.pszText = text3;
977 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
978 expect(3, r);
980 item.iItem = 3;
981 item.mask = LVIF_STATE;
982 item.stateMask = 0xffff;
983 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
984 expect(1, r);
985 ok(item.state == 0x1aaa, "state %x\n", item.state);
987 /* Set an item's state to checked */
988 item.iItem = 3;
989 item.mask = LVIF_STATE;
990 item.stateMask = 0xf000;
991 item.state = 0x2000;
992 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
993 expect(1, r);
995 item.iItem = 3;
996 item.mask = LVIF_STATE;
997 item.stateMask = 0xffff;
998 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
999 expect(1, r);
1000 ok(item.state == 0x2aaa, "state %x\n", item.state);
1002 /* Check that only the bits we asked for are returned,
1003 * and that all the others are set to zero
1005 item.iItem = 3;
1006 item.mask = LVIF_STATE;
1007 item.stateMask = 0xf000;
1008 item.state = 0xffff;
1009 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1010 expect(1, r);
1011 ok(item.state == 0x2000, "state %x\n", item.state);
1013 /* Set the style again and check that doesn't change an item's state */
1014 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1015 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1017 item.iItem = 3;
1018 item.mask = LVIF_STATE;
1019 item.stateMask = 0xffff;
1020 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1021 expect(1, r);
1022 ok(item.state == 0x2aaa, "state %x\n", item.state);
1024 /* Unsetting the checkbox extended style doesn't change an item's state */
1025 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
1026 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1028 item.iItem = 3;
1029 item.mask = LVIF_STATE;
1030 item.stateMask = 0xffff;
1031 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1032 expect(1, r);
1033 ok(item.state == 0x2aaa, "state %x\n", item.state);
1035 /* Now setting the style again will change an item's state */
1036 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1037 expect(0, r);
1039 item.iItem = 3;
1040 item.mask = LVIF_STATE;
1041 item.stateMask = 0xffff;
1042 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1043 expect(1, r);
1044 ok(item.state == 0x1aaa, "state %x\n", item.state);
1046 /* Toggle checkbox tests (bug 9934) */
1047 memset (&item, 0xcc, sizeof(item));
1048 item.mask = LVIF_STATE;
1049 item.iItem = 3;
1050 item.iSubItem = 0;
1051 item.state = LVIS_FOCUSED;
1052 item.stateMask = LVIS_FOCUSED;
1053 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1054 expect(1, r);
1056 item.iItem = 3;
1057 item.mask = LVIF_STATE;
1058 item.stateMask = 0xffff;
1059 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1060 expect(1, r);
1061 ok(item.state == 0x1aab, "state %x\n", item.state);
1063 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1064 expect(0, r);
1065 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
1066 expect(0, r);
1068 item.iItem = 3;
1069 item.mask = LVIF_STATE;
1070 item.stateMask = 0xffff;
1071 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1072 expect(1, r);
1073 ok(item.state == 0x2aab, "state %x\n", item.state);
1075 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1076 expect(0, r);
1077 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
1078 expect(0, r);
1080 item.iItem = 3;
1081 item.mask = LVIF_STATE;
1082 item.stateMask = 0xffff;
1083 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1084 expect(1, r);
1085 ok(item.state == 0x1aab, "state %x\n", item.state);
1087 DestroyWindow(hwnd);
1090 static void insert_column(HWND hwnd, int idx)
1092 LVCOLUMN column;
1093 INT rc;
1095 memset(&column, 0xcc, sizeof(column));
1096 column.mask = LVCF_SUBITEM;
1097 column.iSubItem = idx;
1099 rc = ListView_InsertColumn(hwnd, idx, &column);
1100 expect(idx, rc);
1103 static void insert_item(HWND hwnd, int idx)
1105 static CHAR text[] = "foo";
1107 LVITEMA item;
1108 INT rc;
1110 memset(&item, 0xcc, sizeof (item));
1111 item.mask = LVIF_TEXT;
1112 item.iItem = idx;
1113 item.iSubItem = 0;
1114 item.pszText = text;
1116 rc = ListView_InsertItem(hwnd, &item);
1117 expect(idx, rc);
1120 static void test_items(void)
1122 const LPARAM lparamTest = 0x42;
1123 static CHAR text[] = "Text";
1124 char buffA[5];
1125 HWND hwnd;
1126 LVITEMA item;
1127 DWORD r;
1129 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1130 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1131 ok(hwnd != NULL, "failed to create listview window\n");
1134 * Test setting/getting item params
1137 /* Set up two columns */
1138 insert_column(hwnd, 0);
1139 insert_column(hwnd, 1);
1141 /* LVIS_SELECTED with zero stateMask */
1142 /* set */
1143 memset (&item, 0, sizeof (item));
1144 item.mask = LVIF_STATE;
1145 item.state = LVIS_SELECTED;
1146 item.stateMask = 0;
1147 item.iItem = 0;
1148 item.iSubItem = 0;
1149 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1150 expect(0, r);
1151 /* get */
1152 memset (&item, 0xcc, sizeof (item));
1153 item.mask = LVIF_STATE;
1154 item.stateMask = LVIS_SELECTED;
1155 item.state = 0;
1156 item.iItem = 0;
1157 item.iSubItem = 0;
1158 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1159 expect(1, r);
1160 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1161 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1163 /* LVIS_SELECTED with zero stateMask */
1164 /* set */
1165 memset (&item, 0, sizeof (item));
1166 item.mask = LVIF_STATE;
1167 item.state = LVIS_FOCUSED;
1168 item.stateMask = 0;
1169 item.iItem = 0;
1170 item.iSubItem = 0;
1171 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1172 expect(0, r);
1173 /* get */
1174 memset (&item, 0xcc, sizeof (item));
1175 item.mask = LVIF_STATE;
1176 item.stateMask = LVIS_FOCUSED;
1177 item.state = 0;
1178 item.iItem = 0;
1179 item.iSubItem = 0;
1180 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1181 expect(1, r);
1182 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1183 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1185 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1186 /* set */
1187 memset (&item, 0, sizeof (item));
1188 item.mask = LVIF_STATE;
1189 item.state = LVIS_CUT;
1190 item.stateMask = LVIS_FOCUSED;
1191 item.iItem = 0;
1192 item.iSubItem = 0;
1193 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1194 expect(0, r);
1195 /* get */
1196 memset (&item, 0xcc, sizeof (item));
1197 item.mask = LVIF_STATE;
1198 item.stateMask = LVIS_CUT;
1199 item.state = 0;
1200 item.iItem = 0;
1201 item.iSubItem = 0;
1202 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1203 expect(1, r);
1204 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1205 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1207 /* Insert an item with just a param */
1208 memset (&item, 0xcc, sizeof (item));
1209 item.mask = LVIF_PARAM;
1210 item.iItem = 0;
1211 item.iSubItem = 0;
1212 item.lParam = lparamTest;
1213 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1214 expect(0, r);
1216 /* Test getting of the param */
1217 memset (&item, 0xcc, sizeof (item));
1218 item.mask = LVIF_PARAM;
1219 item.iItem = 0;
1220 item.iSubItem = 0;
1221 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1222 expect(1, r);
1223 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1225 /* Set up a subitem */
1226 memset (&item, 0xcc, sizeof (item));
1227 item.mask = LVIF_TEXT;
1228 item.iItem = 0;
1229 item.iSubItem = 1;
1230 item.pszText = text;
1231 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1232 expect(1, r);
1234 item.mask = LVIF_TEXT;
1235 item.iItem = 0;
1236 item.iSubItem = 1;
1237 item.pszText = buffA;
1238 item.cchTextMax = sizeof(buffA);
1239 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1240 expect(1, r);
1241 ok(!memcmp(item.pszText, text, sizeof(text)), "got text %s, expected %s\n", item.pszText, text);
1243 /* set up with extra flag */
1244 /* 1. reset subitem text */
1245 item.mask = LVIF_TEXT;
1246 item.iItem = 0;
1247 item.iSubItem = 1;
1248 item.pszText = NULL;
1249 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1250 expect(1, r);
1252 item.mask = LVIF_TEXT;
1253 item.iItem = 0;
1254 item.iSubItem = 1;
1255 item.pszText = buffA;
1256 buffA[0] = 'a';
1257 item.cchTextMax = sizeof(buffA);
1258 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1259 expect(1, r);
1260 ok(item.pszText[0] == 0, "got %p\n", item.pszText);
1262 /* 2. set new text with extra flag specified */
1263 item.mask = LVIF_TEXT | LVIF_DI_SETITEM;
1264 item.iItem = 0;
1265 item.iSubItem = 1;
1266 item.pszText = text;
1267 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1268 ok(r == 1 || broken(r == 0) /* NT4 */, "ret %d\n", r);
1270 if (r == 1)
1272 item.mask = LVIF_TEXT;
1273 item.iItem = 0;
1274 item.iSubItem = 1;
1275 item.pszText = buffA;
1276 buffA[0] = 'a';
1277 item.cchTextMax = sizeof(buffA);
1278 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1279 expect(1, r);
1280 ok(!memcmp(item.pszText, text, sizeof(text)), "got %s, expected %s\n", item.pszText, text);
1283 /* Query param from subitem: returns main item param */
1284 memset (&item, 0xcc, sizeof (item));
1285 item.mask = LVIF_PARAM;
1286 item.iItem = 0;
1287 item.iSubItem = 1;
1288 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1289 expect(1, r);
1290 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1292 /* Set up param on first subitem: no effect */
1293 memset (&item, 0xcc, sizeof (item));
1294 item.mask = LVIF_PARAM;
1295 item.iItem = 0;
1296 item.iSubItem = 1;
1297 item.lParam = lparamTest+1;
1298 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1299 expect(0, r);
1301 /* Query param from subitem again: should still return main item param */
1302 memset (&item, 0xcc, sizeof (item));
1303 item.mask = LVIF_PARAM;
1304 item.iItem = 0;
1305 item.iSubItem = 1;
1306 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1307 expect(1, r);
1308 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1310 /**** Some tests of state highlighting ****/
1311 memset (&item, 0xcc, sizeof (item));
1312 item.mask = LVIF_STATE;
1313 item.iItem = 0;
1314 item.iSubItem = 0;
1315 item.state = LVIS_SELECTED;
1316 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1317 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1318 expect(1, r);
1319 item.iSubItem = 1;
1320 item.state = LVIS_DROPHILITED;
1321 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1322 expect(1, r);
1324 memset (&item, 0xcc, sizeof (item));
1325 item.mask = LVIF_STATE;
1326 item.iItem = 0;
1327 item.iSubItem = 0;
1328 item.stateMask = -1;
1329 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1330 expect(1, r);
1331 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1332 item.iSubItem = 1;
1333 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1334 expect(1, r);
1335 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1337 /* some notnull but meaningless masks */
1338 memset (&item, 0, sizeof(item));
1339 item.mask = LVIF_NORECOMPUTE;
1340 item.iItem = 0;
1341 item.iSubItem = 0;
1342 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1343 expect(1, r);
1344 memset (&item, 0, sizeof(item));
1345 item.mask = LVIF_DI_SETITEM;
1346 item.iItem = 0;
1347 item.iSubItem = 0;
1348 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1349 expect(1, r);
1351 /* set text to callback value already having it */
1352 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1353 expect(TRUE, r);
1354 memset (&item, 0, sizeof (item));
1355 item.mask = LVIF_TEXT;
1356 item.pszText = LPSTR_TEXTCALLBACK;
1357 item.iItem = 0;
1358 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1359 expect(0, r);
1360 memset (&item, 0, sizeof (item));
1362 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1364 item.pszText = LPSTR_TEXTCALLBACK;
1365 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1366 expect(TRUE, r);
1368 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1369 "check callback text comparison rule", FALSE);
1371 DestroyWindow(hwnd);
1374 static void test_columns(void)
1376 HWND hwnd;
1377 LVCOLUMNA column;
1378 LVITEMA item;
1379 INT order[2];
1380 CHAR buff[5];
1381 DWORD rc;
1383 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1384 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1385 ok(hwnd != NULL, "failed to create listview window\n");
1387 /* Add a column with no mask */
1388 memset(&column, 0xcc, sizeof(column));
1389 column.mask = 0;
1390 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1391 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1393 /* Check its width */
1394 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1395 ok(rc == 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1397 DestroyWindow(hwnd);
1399 /* LVM_GETCOLUMNORDERARRAY */
1400 hwnd = create_listview_control(LVS_REPORT);
1401 subclass_header(hwnd);
1403 memset(&column, 0, sizeof(column));
1404 column.mask = LVCF_WIDTH;
1405 column.cx = 100;
1406 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1407 expect(0, rc);
1409 column.cx = 200;
1410 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1411 expect(1, rc);
1413 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1415 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1416 expect(1, rc);
1417 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1418 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1420 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1422 /* after column added subitem is considered as present */
1423 insert_item(hwnd, 0);
1425 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1427 item.pszText = buff;
1428 item.cchTextMax = sizeof(buff);
1429 item.iItem = 0;
1430 item.iSubItem = 1;
1431 item.mask = LVIF_TEXT;
1432 memset(&g_itema, 0, sizeof(g_itema));
1433 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1434 expect(1, rc);
1435 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1437 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1438 "get subitem text after column added", FALSE);
1440 DestroyWindow(hwnd);
1443 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1444 static WNDPROC listviewWndProc;
1445 static HIMAGELIST test_create_imagelist;
1447 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1449 LRESULT ret;
1451 if (uMsg == WM_CREATE)
1453 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1454 lpcs->style |= LVS_REPORT;
1456 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1457 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1458 return ret;
1461 static void test_create(void)
1463 HWND hList;
1464 HWND hHeader;
1465 LONG_PTR ret;
1466 LONG r;
1467 LVCOLUMNA col;
1468 RECT rect;
1469 WNDCLASSEX cls;
1470 DWORD style;
1472 cls.cbSize = sizeof(WNDCLASSEX);
1473 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1474 listviewWndProc = cls.lpfnWndProc;
1475 cls.lpfnWndProc = create_test_wndproc;
1476 cls.lpszClassName = "MyListView32";
1477 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1479 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1480 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1481 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1482 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1484 if (!IsWindow(hHeader))
1486 /* version 4.0 */
1487 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1488 DestroyWindow(hList);
1489 return;
1492 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1493 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1494 DestroyWindow(hList);
1496 /* header isn't created on LVS_ICON and LVS_LIST styles */
1497 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1498 GetModuleHandle(NULL), 0);
1499 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1500 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1501 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1502 /* insert column */
1503 memset(&col, 0, sizeof(LVCOLUMNA));
1504 col.mask = LVCF_WIDTH;
1505 col.cx = 100;
1506 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1507 expect(0, r);
1508 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1509 ok(IsWindow(hHeader), "Header should be created\n");
1510 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1511 style = GetWindowLong(hHeader, GWL_STYLE);
1512 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1513 DestroyWindow(hList);
1515 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1516 GetModuleHandle(NULL), 0);
1517 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1518 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1519 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1520 /* insert column */
1521 memset(&col, 0, sizeof(LVCOLUMNA));
1522 col.mask = LVCF_WIDTH;
1523 col.cx = 100;
1524 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1525 expect(0, r);
1526 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1527 ok(IsWindow(hHeader), "Header should be created\n");
1528 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1529 DestroyWindow(hList);
1531 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1532 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1533 GetModuleHandle(NULL), 0);
1534 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1535 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1536 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1537 ok(IsWindow(hHeader), "Header should be created\n");
1538 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1539 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1540 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1541 ok(IsWindow(hHeader), "Header should be created\n");
1542 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1543 DestroyWindow(hList);
1545 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1546 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1547 GetModuleHandle(NULL), 0);
1548 ret = SetWindowLongPtr(hList, GWL_STYLE,
1549 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1550 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1551 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1552 ok(IsWindow(hHeader), "Header should be created\n");
1553 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1554 ret = SetWindowLongPtr(hList, GWL_STYLE,
1555 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1556 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1557 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1558 ok(IsWindow(hHeader), "Header should be created\n");
1559 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1560 DestroyWindow(hList);
1562 /* LVS_REPORT without WS_VISIBLE */
1563 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1564 GetModuleHandle(NULL), 0);
1565 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1566 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1567 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1568 /* insert column */
1569 memset(&col, 0, sizeof(LVCOLUMNA));
1570 col.mask = LVCF_WIDTH;
1571 col.cx = 100;
1572 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1573 expect(0, r);
1574 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1575 ok(IsWindow(hHeader), "Header should be created\n");
1576 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1577 DestroyWindow(hList);
1579 /* LVS_REPORT without WS_VISIBLE, try to show it */
1580 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1581 GetModuleHandle(NULL), 0);
1582 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1583 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1584 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1585 ShowWindow(hList, SW_SHOW);
1586 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1587 ok(IsWindow(hHeader), "Header should be created\n");
1588 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1589 DestroyWindow(hList);
1591 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1592 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1593 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1594 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1595 ok(IsWindow(hHeader), "Header should be created\n");
1596 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1597 /* HDS_DRAGDROP set by default */
1598 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1599 DestroyWindow(hList);
1601 /* setting LVS_EX_HEADERDRAGDROP creates header */
1602 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1603 GetModuleHandle(NULL), 0);
1604 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1605 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1606 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1607 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1608 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1609 ok(IsWindow(hHeader) ||
1610 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1611 "Header should be created\n");
1612 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1613 DestroyWindow(hList);
1615 /* setting LVS_EX_GRIDLINES creates header */
1616 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1617 GetModuleHandle(NULL), 0);
1618 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1619 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1620 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1621 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_GRIDLINES);
1622 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1623 ok(IsWindow(hHeader) ||
1624 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1625 "Header should be created\n");
1626 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1627 DestroyWindow(hList);
1629 /* setting LVS_EX_FULLROWSELECT creates header */
1630 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1631 GetModuleHandle(NULL), 0);
1632 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1633 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1634 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1635 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
1636 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1637 ok(IsWindow(hHeader) ||
1638 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1639 "Header should be created\n");
1640 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1641 DestroyWindow(hList);
1643 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1644 hList = create_listview_control(LVS_ICON);
1645 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1646 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1647 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1648 DestroyWindow(hList);
1650 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1651 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1652 GetModuleHandle(NULL), 0);
1653 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1654 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1656 rect.left = LVIR_BOUNDS;
1657 rect.top = 1;
1658 rect.right = rect.bottom = -10;
1659 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1660 /* right value contains garbage, probably because header columns are not set up */
1661 expect(0, rect.bottom);
1662 expect(1, r);
1664 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1665 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1666 ok(GetDlgItem(hList, 0) == NULL, "NULL dialog item expected\n");
1668 DestroyWindow(hList);
1670 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1671 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1672 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1673 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1674 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1675 DestroyWindow(hList);
1678 static void test_redraw(void)
1680 HWND hwnd;
1681 HDC hdc;
1682 BOOL res;
1683 DWORD r;
1685 hwnd = create_listview_control(LVS_REPORT);
1686 subclass_header(hwnd);
1688 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1690 InvalidateRect(hwnd, NULL, TRUE);
1691 UpdateWindow(hwnd);
1692 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1694 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1696 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1697 /* 1. Without backbuffer */
1698 res = ListView_SetBkColor(hwnd, CLR_NONE);
1699 expect(TRUE, res);
1701 hdc = GetWindowDC(hwndparent);
1703 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1704 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1705 ok(r == 1, "Expected not zero result\n");
1706 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1707 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1709 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1710 expect(TRUE, res);
1712 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1713 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1714 expect(1, r);
1715 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1716 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1718 /* 2. With backbuffer */
1719 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1720 LVS_EX_DOUBLEBUFFER);
1721 res = ListView_SetBkColor(hwnd, CLR_NONE);
1722 expect(TRUE, res);
1724 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1725 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1726 expect(1, r);
1727 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1728 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1730 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1731 expect(TRUE, res);
1733 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1734 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1735 todo_wine expect(1, r);
1736 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1737 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1739 ReleaseDC(hwndparent, hdc);
1741 DestroyWindow(hwnd);
1744 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1746 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1748 if(msg == WM_NOTIFY) {
1749 NMHDR *nmhdr = (PVOID)lp;
1750 if(nmhdr->code == NM_CUSTOMDRAW) {
1751 NMLVCUSTOMDRAW *nmlvcd = (NMLVCUSTOMDRAW*)nmhdr;
1753 switch(nmlvcd->nmcd.dwDrawStage) {
1754 case CDDS_PREPAINT:
1755 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1756 return CDRF_NOTIFYITEMDRAW;
1757 case CDDS_ITEMPREPAINT:
1758 nmlvcd->clrTextBk = CLR_DEFAULT;
1759 return CDRF_NOTIFYSUBITEMDRAW;
1760 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1761 clr = GetBkColor(nmlvcd->nmcd.hdc);
1762 if (nmlvcd->iSubItem)
1763 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1764 else
1765 ok(clr == c0ffee, "clr=%.8x\n", clr);
1766 return CDRF_NOTIFYPOSTPAINT;
1767 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1768 clr = GetBkColor(nmlvcd->nmcd.hdc);
1769 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1770 return CDRF_DODEFAULT;
1772 return CDRF_DODEFAULT;
1776 return DefWindowProcA(hwnd, msg, wp, lp);
1779 static void test_customdraw(void)
1781 HWND hwnd;
1782 WNDPROC oldwndproc;
1784 hwnd = create_listview_control(LVS_REPORT);
1786 insert_column(hwnd, 0);
1787 insert_column(hwnd, 1);
1788 insert_item(hwnd, 0);
1790 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1791 (LONG_PTR)cd_wndproc);
1793 InvalidateRect(hwnd, NULL, TRUE);
1794 UpdateWindow(hwnd);
1796 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1798 DestroyWindow(hwnd);
1801 static void test_icon_spacing(void)
1803 /* LVM_SETICONSPACING */
1804 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1806 HWND hwnd;
1807 WORD w, h;
1808 INT r;
1810 hwnd = create_listview_control(LVS_ICON);
1811 ok(hwnd != NULL, "failed to create a listview window\n");
1813 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1814 expect(NFR_ANSI, r);
1816 /* reset the icon spacing to defaults */
1817 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1819 /* now we can request what the defaults are */
1820 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1821 w = LOWORD(r);
1822 h = HIWORD(r);
1824 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1826 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1827 ok(r == MAKELONG(w, h) ||
1828 broken(r == MAKELONG(w, w)), /* win98 */
1829 "Expected %d, got %d\n", MAKELONG(w, h), r);
1831 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1832 if (r == 0)
1834 /* version 4.0 */
1835 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1836 DestroyWindow(hwnd);
1837 return;
1839 expect(MAKELONG(20,30), r);
1841 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1842 expect(MAKELONG(25,35), r);
1844 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1846 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1847 DestroyWindow(hwnd);
1850 static void test_color(void)
1852 RECT rect;
1853 HWND hwnd;
1854 DWORD r;
1855 int i;
1857 COLORREF color;
1858 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1860 hwnd = create_listview_control(LVS_REPORT);
1861 ok(hwnd != NULL, "failed to create a listview window\n");
1863 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1865 for (i = 0; i < 4; i++)
1867 color = colors[i];
1869 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1870 expect(TRUE, r);
1871 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
1872 expect(color, r);
1874 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1875 expect (TRUE, r);
1876 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, 0);
1877 expect(color, r);
1879 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1880 expect(TRUE, r);
1881 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, 0);
1882 expect(color, r);
1885 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1886 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1888 /* invalidation test done separately to avoid a message chain mess */
1889 r = ValidateRect(hwnd, NULL);
1890 expect(TRUE, r);
1891 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, colors[0]);
1892 expect(TRUE, r);
1894 rect.right = rect.bottom = 1;
1895 r = GetUpdateRect(hwnd, &rect, TRUE);
1896 todo_wine expect(FALSE, r);
1897 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1899 r = ValidateRect(hwnd, NULL);
1900 expect(TRUE, r);
1901 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, colors[0]);
1902 expect(TRUE, r);
1904 rect.right = rect.bottom = 1;
1905 r = GetUpdateRect(hwnd, &rect, TRUE);
1906 todo_wine expect(FALSE, r);
1907 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1909 r = ValidateRect(hwnd, NULL);
1910 expect(TRUE, r);
1911 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, colors[0]);
1912 expect(TRUE, r);
1914 rect.right = rect.bottom = 1;
1915 r = GetUpdateRect(hwnd, &rect, TRUE);
1916 todo_wine expect(FALSE, r);
1917 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1919 DestroyWindow(hwnd);
1922 static void test_item_count(void)
1924 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1926 HWND hwnd;
1927 DWORD r;
1928 HDC hdc;
1929 HFONT hOldFont;
1930 TEXTMETRICA tm;
1931 RECT rect;
1932 INT height;
1934 LVITEM item0;
1935 LVITEM item1;
1936 LVITEM item2;
1937 static CHAR item0text[] = "item0";
1938 static CHAR item1text[] = "item1";
1939 static CHAR item2text[] = "item2";
1941 hwnd = create_listview_control(LVS_REPORT);
1942 ok(hwnd != NULL, "failed to create a listview window\n");
1944 /* resize in dpiaware manner to fit all 3 items added */
1945 hdc = GetDC(0);
1946 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1947 GetTextMetricsA(hdc, &tm);
1948 /* 2 extra pixels for bounds and header border */
1949 height = tm.tmHeight + 2;
1950 SelectObject(hdc, hOldFont);
1951 ReleaseDC(0, hdc);
1953 GetWindowRect(hwnd, &rect);
1954 /* 3 items + 1 header + 1 to be sure */
1955 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1957 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1959 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1960 expect(0, r);
1962 /* [item0] */
1963 item0.mask = LVIF_TEXT;
1964 item0.iItem = 0;
1965 item0.iSubItem = 0;
1966 item0.pszText = item0text;
1967 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1968 expect(0, r);
1970 /* [item0, item1] */
1971 item1.mask = LVIF_TEXT;
1972 item1.iItem = 1;
1973 item1.iSubItem = 0;
1974 item1.pszText = item1text;
1975 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1976 expect(1, r);
1978 /* [item0, item1, item2] */
1979 item2.mask = LVIF_TEXT;
1980 item2.iItem = 2;
1981 item2.iSubItem = 0;
1982 item2.pszText = item2text;
1983 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1984 expect(2, r);
1986 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1987 expect(3, r);
1989 /* [item0, item1] */
1990 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1991 expect(TRUE, r);
1993 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1994 expect(2, r);
1996 /* [] */
1997 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1998 expect(TRUE, r);
2000 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2001 expect(0, r);
2003 /* [item0] */
2004 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
2005 expect(0, r);
2007 /* [item0, item1] */
2008 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
2009 expect(1, r);
2011 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2012 expect(2, r);
2014 /* [item0, item1, item2] */
2015 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
2016 expect(2, r);
2018 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2019 expect(3, r);
2021 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
2023 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2024 DestroyWindow(hwnd);
2027 static void test_item_position(void)
2029 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2031 HWND hwnd;
2032 DWORD r;
2033 POINT position;
2035 LVITEM item0;
2036 LVITEM item1;
2037 LVITEM item2;
2038 static CHAR item0text[] = "item0";
2039 static CHAR item1text[] = "item1";
2040 static CHAR item2text[] = "item2";
2042 hwnd = create_listview_control(LVS_ICON);
2043 ok(hwnd != NULL, "failed to create a listview window\n");
2045 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2047 /* [item0] */
2048 item0.mask = LVIF_TEXT;
2049 item0.iItem = 0;
2050 item0.iSubItem = 0;
2051 item0.pszText = item0text;
2052 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
2053 expect(0, r);
2055 /* [item0, item1] */
2056 item1.mask = LVIF_TEXT;
2057 item1.iItem = 1;
2058 item1.iSubItem = 0;
2059 item1.pszText = item1text;
2060 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
2061 expect(1, r);
2063 /* [item0, item1, item2] */
2064 item2.mask = LVIF_TEXT;
2065 item2.iItem = 2;
2066 item2.iSubItem = 0;
2067 item2.pszText = item2text;
2068 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
2069 expect(2, r);
2071 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
2072 expect(TRUE, r);
2073 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
2074 expect(TRUE, r);
2075 expect2(10, 5, position.x, position.y);
2077 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
2078 expect(TRUE, r);
2079 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
2080 expect(TRUE, r);
2081 expect2(0, 0, position.x, position.y);
2083 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
2084 expect(TRUE, r);
2085 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
2086 expect(TRUE, r);
2087 expect2(20, 20, position.x, position.y);
2089 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
2091 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2092 DestroyWindow(hwnd);
2095 static void test_getorigin(void)
2097 /* LVM_GETORIGIN */
2099 HWND hwnd;
2100 DWORD r;
2101 POINT position;
2103 position.x = position.y = 0;
2105 hwnd = create_listview_control(LVS_ICON);
2106 ok(hwnd != NULL, "failed to create a listview window\n");
2107 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2109 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2110 expect(TRUE, r);
2111 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2112 DestroyWindow(hwnd);
2114 hwnd = create_listview_control(LVS_SMALLICON);
2115 ok(hwnd != NULL, "failed to create a listview window\n");
2116 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2118 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2119 expect(TRUE, r);
2120 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2121 DestroyWindow(hwnd);
2123 hwnd = create_listview_control(LVS_LIST);
2124 ok(hwnd != NULL, "failed to create a listview window\n");
2125 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2127 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2128 expect(FALSE, r);
2129 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2130 DestroyWindow(hwnd);
2132 hwnd = create_listview_control(LVS_REPORT);
2133 ok(hwnd != NULL, "failed to create a listview window\n");
2134 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2136 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2137 expect(FALSE, r);
2138 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2139 DestroyWindow(hwnd);
2142 static void test_multiselect(void)
2144 typedef struct t_select_task
2146 const char *descr;
2147 int initPos;
2148 int loopVK;
2149 int count;
2150 int result;
2151 } select_task;
2153 HWND hwnd;
2154 INT r;
2155 int i,j,item_count,selected_count;
2156 static const int items=5;
2157 BYTE kstate[256];
2158 select_task task;
2159 LONG_PTR style;
2160 LVITEMA item;
2162 static struct t_select_task task_list[] = {
2163 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
2164 { "using VK_UP", -1, VK_UP, -1, -1 },
2165 { "using VK_END", 0, VK_END, 1, -1 },
2166 { "using VK_HOME", -1, VK_HOME, 1, -1 }
2169 hwnd = create_listview_control(LVS_REPORT);
2171 for (i = 0; i < items; i++)
2172 insert_item(hwnd, 0);
2174 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2175 expect(items, item_count);
2177 for (i = 0; i < 4; i++) {
2178 LVITEMA item;
2180 task = task_list[i];
2182 /* deselect all items */
2183 item.state = 0;
2184 item.stateMask = LVIS_SELECTED;
2185 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2186 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2188 /* set initial position */
2189 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
2191 item.state = LVIS_SELECTED;
2192 item.stateMask = LVIS_SELECTED;
2193 SendMessageA(hwnd, LVM_SETITEMSTATE, task.initPos == -1 ? item_count-1 : task.initPos, (LPARAM)&item);
2195 selected_count = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2196 ok(selected_count == 1, "expected 1, got %d\n", selected_count);
2198 /* Set SHIFT key pressed */
2199 GetKeyboardState(kstate);
2200 kstate[VK_SHIFT]=0x80;
2201 SetKeyboardState(kstate);
2203 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
2204 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
2205 expect(0,r);
2206 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
2207 expect(0,r);
2210 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2212 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);
2214 /* Set SHIFT key released */
2215 GetKeyboardState(kstate);
2216 kstate[VK_SHIFT]=0x00;
2217 SetKeyboardState(kstate);
2219 DestroyWindow(hwnd);
2221 /* make multiple selection, then switch to LVS_SINGLESEL */
2222 hwnd = create_listview_control(LVS_REPORT);
2223 for (i=0;i<items;i++) {
2224 insert_item(hwnd, 0);
2226 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2227 expect(items,item_count);
2229 /* try with NULL pointer */
2230 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
2231 expect(FALSE, r);
2233 /* select all, check notifications */
2234 item.state = 0;
2235 item.stateMask = LVIS_SELECTED;
2236 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2238 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2240 item.stateMask = LVIS_SELECTED;
2241 item.state = LVIS_SELECTED;
2242 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2243 expect(TRUE, r);
2245 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2246 "select all notification", FALSE);
2248 /* select all again (all selected already) */
2249 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2251 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2253 item.stateMask = LVIS_SELECTED;
2254 item.state = LVIS_SELECTED;
2255 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2256 expect(TRUE, r);
2258 ok(g_nmlistview_changing.uNewState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uNewState);
2259 ok(g_nmlistview_changing.uOldState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uOldState);
2260 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2262 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2263 "select all notification 2", FALSE);
2265 /* deselect all items */
2266 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2268 item.state = 0;
2269 item.stateMask = LVIS_SELECTED;
2270 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2272 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2273 "deselect all notification", FALSE);
2275 /* deselect all items again */
2276 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2277 item.state = 0;
2278 item.stateMask = LVIS_SELECTED;
2279 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2280 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "deselect all notification 2", FALSE);
2282 /* any non-zero state value does the same */
2283 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2285 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2287 item.stateMask = LVIS_SELECTED;
2288 item.state = LVIS_CUT;
2289 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2290 expect(TRUE, r);
2292 ok(g_nmlistview_changing.uNewState == 0, "got 0x%x\n", g_nmlistview_changing.uNewState);
2293 ok(g_nmlistview_changing.uOldState == 0, "got 0x%x\n", g_nmlistview_changing.uOldState);
2294 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2296 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2297 "set state all notification 3", FALSE);
2299 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2300 for (i = 0; i < 3; i++) {
2301 item.state = LVIS_SELECTED;
2302 item.stateMask = LVIS_SELECTED;
2303 SendMessageA(hwnd, LVM_SETITEMSTATE, i, (LPARAM)&item);
2306 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2307 expect(3, r);
2308 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2309 expect(-1, r);
2311 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2312 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2313 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2314 /* check that style is accepted */
2315 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2316 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2318 for (i=0;i<3;i++) {
2319 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2320 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2322 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2323 expect(3, r);
2324 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2325 expect(3, r);
2327 /* select one more */
2328 item.state = LVIS_SELECTED;
2329 item.stateMask = LVIS_SELECTED;
2330 SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
2332 for (i=0;i<3;i++) {
2333 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2334 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2336 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2337 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2339 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2340 expect(1, r);
2341 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2342 expect(-1, r);
2344 /* try to select all on LVS_SINGLESEL */
2345 memset(&item, 0, sizeof(item));
2346 item.stateMask = LVIS_SELECTED;
2347 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2348 expect(TRUE, r);
2349 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2351 item.stateMask = LVIS_SELECTED;
2352 item.state = LVIS_SELECTED;
2353 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2354 expect(FALSE, r);
2356 r = ListView_GetSelectedCount(hwnd);
2357 expect(0, r);
2358 r = ListView_GetSelectionMark(hwnd);
2359 expect(-1, r);
2361 /* try to deselect all on LVS_SINGLESEL */
2362 item.stateMask = LVIS_SELECTED;
2363 item.state = LVIS_SELECTED;
2364 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2365 expect(TRUE, r);
2367 item.stateMask = LVIS_SELECTED;
2368 item.state = 0;
2369 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2370 expect(TRUE, r);
2371 r = ListView_GetSelectedCount(hwnd);
2372 expect(0, r);
2374 /* 1. selection mark is update when new focused item is set */
2375 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2376 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2378 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2379 expect(-1, r);
2381 item.stateMask = LVIS_FOCUSED;
2382 item.state = LVIS_FOCUSED;
2383 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2384 expect(TRUE, r);
2386 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2387 expect(0, r);
2389 /* it's not updated if already set */
2390 item.stateMask = LVIS_FOCUSED;
2391 item.state = LVIS_FOCUSED;
2392 r = SendMessage(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2393 expect(TRUE, r);
2395 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2396 expect(0, r);
2398 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2399 expect(0, r);
2401 item.stateMask = LVIS_FOCUSED;
2402 item.state = LVIS_FOCUSED;
2403 r = SendMessage(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2404 expect(TRUE, r);
2406 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2407 expect(-1, r);
2409 /* need to reset focused item first */
2410 item.stateMask = LVIS_FOCUSED;
2411 item.state = 0;
2412 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2413 expect(TRUE, r);
2415 item.stateMask = LVIS_FOCUSED;
2416 item.state = LVIS_FOCUSED;
2417 r = SendMessage(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
2418 expect(TRUE, r);
2420 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2421 expect(2, r);
2423 item.stateMask = LVIS_FOCUSED;
2424 item.state = 0;
2425 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2426 expect(TRUE, r);
2428 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2429 expect(2, r);
2431 /* 2. same tests, with LVM_SETITEM */
2432 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2433 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2435 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2436 expect(2, r);
2438 item.stateMask = LVIS_FOCUSED;
2439 item.state = LVIS_FOCUSED;
2440 item.mask = LVIF_STATE;
2441 item.iItem = item.iSubItem = 0;
2442 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2443 expect(TRUE, r);
2445 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2446 expect(0, r);
2448 /* it's not updated if already set */
2449 item.stateMask = LVIS_FOCUSED;
2450 item.state = LVIS_FOCUSED;
2451 item.mask = LVIF_STATE;
2452 item.iItem = 1;
2453 item.iSubItem = 0;
2454 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2455 expect(TRUE, r);
2457 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2458 expect(0, r);
2460 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2461 expect(0, r);
2463 item.stateMask = LVIS_FOCUSED;
2464 item.state = LVIS_FOCUSED;
2465 item.mask = LVIF_STATE;
2466 item.iItem = 1;
2467 item.iSubItem = 0;
2468 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2469 expect(TRUE, r);
2471 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2472 expect(-1, r);
2474 /* need to reset focused item first */
2475 item.stateMask = LVIS_FOCUSED;
2476 item.state = 0;
2477 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2478 expect(TRUE, r);
2480 item.stateMask = LVIS_FOCUSED;
2481 item.state = LVIS_FOCUSED;
2482 item.mask = LVIF_STATE;
2483 item.iItem = 2;
2484 item.iSubItem = 0;
2485 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2486 expect(TRUE, r);
2488 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2489 expect(2, r);
2491 item.stateMask = LVIS_FOCUSED;
2492 item.state = 0;
2493 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2494 expect(TRUE, r);
2496 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2497 expect(2, r);
2499 DestroyWindow(hwnd);
2502 static void test_subitem_rect(void)
2504 HWND hwnd;
2505 DWORD r;
2506 LVCOLUMN col;
2507 RECT rect, rect2;
2508 INT arr[3];
2510 /* test LVM_GETSUBITEMRECT for header */
2511 hwnd = create_listview_control(LVS_REPORT);
2512 ok(hwnd != NULL, "failed to create a listview window\n");
2513 /* add some columns */
2514 memset(&col, 0, sizeof(LVCOLUMN));
2515 col.mask = LVCF_WIDTH;
2516 col.cx = 100;
2517 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2518 expect(0, r);
2519 col.cx = 150;
2520 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2521 expect(1, r);
2522 col.cx = 200;
2523 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2524 expect(2, r);
2525 /* item = -1 means header, subitem index is 1 based */
2526 rect.left = LVIR_BOUNDS;
2527 rect.top = 0;
2528 rect.right = rect.bottom = 0;
2529 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2530 expect(0, r);
2532 rect.left = LVIR_BOUNDS;
2533 rect.top = 1;
2534 rect.right = rect.bottom = 0;
2535 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2536 expect(1, r);
2538 expect(100, rect.left);
2539 expect(250, rect.right);
2540 expect(3, rect.top);
2542 rect.left = LVIR_BOUNDS;
2543 rect.top = 2;
2544 rect.right = rect.bottom = 0;
2545 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2546 expect(1, r);
2548 expect(250, rect.left);
2549 expect(450, rect.right);
2550 expect(3, rect.top);
2552 /* item LVS_REPORT padding isn't applied to subitems */
2553 insert_item(hwnd, 0);
2555 rect.left = LVIR_BOUNDS;
2556 rect.top = 1;
2557 rect.right = rect.bottom = 0;
2558 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2559 expect(1, r);
2560 expect(100, rect.left);
2561 expect(250, rect.right);
2563 rect.left = LVIR_ICON;
2564 rect.top = 1;
2565 rect.right = rect.bottom = 0;
2566 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2567 expect(1, r);
2568 /* no icon attached - zero width rectangle, with no left padding */
2569 expect(100, rect.left);
2570 expect(100, rect.right);
2572 rect.left = LVIR_LABEL;
2573 rect.top = 1;
2574 rect.right = rect.bottom = 0;
2575 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2576 expect(1, r);
2577 /* same as full LVIR_BOUNDS */
2578 expect(100, rect.left);
2579 expect(250, rect.right);
2581 SendMessage(hwnd, LVM_SCROLL, 10, 0);
2583 rect.left = LVIR_BOUNDS;
2584 rect.top = 1;
2585 rect.right = rect.bottom = 0;
2586 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2587 expect(1, r);
2588 expect(90, rect.left);
2589 expect(240, rect.right);
2591 SendMessage(hwnd, LVM_SCROLL, -10, 0);
2593 /* test header interaction */
2594 subclass_header(hwnd);
2595 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2597 rect.left = LVIR_BOUNDS;
2598 rect.top = 1;
2599 rect.right = rect.bottom = 0;
2600 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2601 expect(1, r);
2603 rect.left = LVIR_BOUNDS;
2604 rect.top = 1;
2605 rect.right = rect.bottom = 0;
2606 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2607 expect(1, r);
2609 rect.left = LVIR_BOUNDS;
2610 rect.top = 1;
2611 rect.right = rect.bottom = 0;
2612 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -10, (LPARAM)&rect);
2613 expect(1, r);
2615 rect.left = LVIR_BOUNDS;
2616 rect.top = 1;
2617 rect.right = rect.bottom = 0;
2618 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 20, (LPARAM)&rect);
2619 expect(1, r);
2621 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getsubitemrect_seq, "LVM_GETSUBITEMRECT negative index", FALSE);
2623 DestroyWindow(hwnd);
2625 /* test subitem rects after re-arranging columns */
2626 hwnd = create_listview_control(LVS_REPORT);
2627 ok(hwnd != NULL, "failed to create a listview window\n");
2628 memset(&col, 0, sizeof(LVCOLUMN));
2629 col.mask = LVCF_WIDTH;
2631 col.cx = 100;
2632 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2633 expect(0, r);
2635 col.cx = 200;
2636 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2637 expect(1, r);
2639 col.cx = 300;
2640 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2641 expect(2, r);
2643 insert_item(hwnd, 0);
2644 insert_item(hwnd, 1);
2646 /* wrong item is refused for main item */
2647 rect.left = LVIR_BOUNDS;
2648 rect.top = 0;
2649 rect.right = rect.bottom = -1;
2650 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect);
2651 expect(FALSE, r);
2653 /* for subitems rectangle is calculated even if there's no item added */
2654 rect.left = LVIR_BOUNDS;
2655 rect.top = 1;
2656 rect.right = rect.bottom = -1;
2657 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect);
2658 expect(TRUE, r);
2660 rect2.left = LVIR_BOUNDS;
2661 rect2.top = 1;
2662 rect2.right = rect2.bottom = -1;
2663 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect2);
2664 expect(TRUE, r);
2665 expect(rect.right, rect2.right);
2666 expect(rect.left, rect2.left);
2667 expect(rect.bottom, rect2.top);
2668 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2670 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2671 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2672 expect(TRUE, r);
2674 rect.left = LVIR_BOUNDS;
2675 rect.top = 0;
2676 rect.right = rect.bottom = -1;
2677 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2678 expect(TRUE, r);
2679 expect(0, rect.left);
2680 expect(600, rect.right);
2682 rect.left = LVIR_BOUNDS;
2683 rect.top = 1;
2684 rect.right = rect.bottom = -1;
2685 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2686 expect(TRUE, r);
2687 expect(0, rect.left);
2688 expect(200, rect.right);
2690 rect2.left = LVIR_BOUNDS;
2691 rect2.top = 1;
2692 rect2.right = rect2.bottom = -1;
2693 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect2);
2694 expect(TRUE, r);
2695 expect(0, rect2.left);
2696 expect(200, rect2.right);
2697 /* items are of the same height */
2698 ok(rect2.top > 0, "expected positive item height\n");
2699 expect(rect.bottom, rect2.top);
2700 expect(rect.bottom * 2 - rect.top, rect2.bottom);
2702 rect.left = LVIR_BOUNDS;
2703 rect.top = 2;
2704 rect.right = rect.bottom = -1;
2705 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2706 expect(TRUE, r);
2707 expect(300, rect.left);
2708 expect(600, rect.right);
2710 DestroyWindow(hwnd);
2712 /* try it for non LVS_REPORT style */
2713 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2714 GetModuleHandle(NULL), 0);
2715 rect.left = LVIR_BOUNDS;
2716 rect.top = 1;
2717 rect.right = rect.bottom = -10;
2718 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2719 expect(0, r);
2720 /* rect is unchanged */
2721 expect(0, rect.left);
2722 expect(-10, rect.right);
2723 expect(1, rect.top);
2724 expect(-10, rect.bottom);
2725 DestroyWindow(hwnd);
2728 /* comparison callback for test_sorting */
2729 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2731 if (first == second) return 0;
2732 return (first > second ? 1 : -1);
2735 static void test_sorting(void)
2737 HWND hwnd;
2738 LVITEMA item = {0};
2739 INT r;
2740 LONG_PTR style;
2741 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2742 CHAR buff[10];
2744 hwnd = create_listview_control(LVS_REPORT);
2745 ok(hwnd != NULL, "failed to create a listview window\n");
2747 /* insert some items */
2748 item.mask = LVIF_PARAM | LVIF_STATE;
2749 item.state = LVIS_SELECTED;
2750 item.iItem = 0;
2751 item.iSubItem = 0;
2752 item.lParam = 3;
2753 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2754 expect(0, r);
2756 item.mask = LVIF_PARAM;
2757 item.iItem = 1;
2758 item.iSubItem = 0;
2759 item.lParam = 2;
2760 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2761 expect(1, r);
2763 item.mask = LVIF_STATE | LVIF_PARAM;
2764 item.state = LVIS_SELECTED;
2765 item.iItem = 2;
2766 item.iSubItem = 0;
2767 item.lParam = 4;
2768 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2769 expect(2, r);
2771 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2772 expect(-1, r);
2774 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2775 expect(2, r);
2777 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2778 expect(TRUE, r);
2780 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2781 expect(2, r);
2782 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2783 expect(-1, r);
2784 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2785 expect(0, r);
2786 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2787 expect(LVIS_SELECTED, r);
2788 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2789 expect(LVIS_SELECTED, r);
2791 DestroyWindow(hwnd);
2793 /* switch to LVS_SORTASCENDING when some items added */
2794 hwnd = create_listview_control(LVS_REPORT);
2795 ok(hwnd != NULL, "failed to create a listview window\n");
2797 item.mask = LVIF_TEXT;
2798 item.iItem = 0;
2799 item.iSubItem = 0;
2800 item.pszText = names[1];
2801 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2802 expect(0, r);
2804 item.mask = LVIF_TEXT;
2805 item.iItem = 1;
2806 item.iSubItem = 0;
2807 item.pszText = names[2];
2808 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2809 expect(1, r);
2811 item.mask = LVIF_TEXT;
2812 item.iItem = 2;
2813 item.iSubItem = 0;
2814 item.pszText = names[0];
2815 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2816 expect(2, r);
2818 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2819 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2820 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2821 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2823 /* no sorting performed when switched to LVS_SORTASCENDING */
2824 item.mask = LVIF_TEXT;
2825 item.iItem = 0;
2826 item.pszText = buff;
2827 item.cchTextMax = sizeof(buff);
2828 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2829 expect(TRUE, r);
2830 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2832 item.iItem = 1;
2833 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2834 expect(TRUE, r);
2835 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2837 item.iItem = 2;
2838 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2839 expect(TRUE, r);
2840 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2842 /* adding new item doesn't resort list */
2843 item.mask = LVIF_TEXT;
2844 item.iItem = 3;
2845 item.iSubItem = 0;
2846 item.pszText = names[3];
2847 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2848 expect(3, r);
2850 item.mask = LVIF_TEXT;
2851 item.iItem = 0;
2852 item.pszText = buff;
2853 item.cchTextMax = sizeof(buff);
2854 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2855 expect(TRUE, r);
2856 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2858 item.iItem = 1;
2859 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2860 expect(TRUE, r);
2861 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2863 item.iItem = 2;
2864 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2865 expect(TRUE, r);
2866 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2868 item.iItem = 3;
2869 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2870 expect(TRUE, r);
2871 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2873 /* corner case - item should be placed at first position */
2874 item.mask = LVIF_TEXT;
2875 item.iItem = 4;
2876 item.iSubItem = 0;
2877 item.pszText = names[4];
2878 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2879 expect(0, r);
2881 item.iItem = 0;
2882 item.pszText = buff;
2883 item.cchTextMax = sizeof(buff);
2884 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2885 expect(TRUE, r);
2886 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2888 item.iItem = 1;
2889 item.pszText = buff;
2890 item.cchTextMax = sizeof(buff);
2891 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2892 expect(TRUE, r);
2893 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2895 item.iItem = 2;
2896 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2897 expect(TRUE, r);
2898 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2900 item.iItem = 3;
2901 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2902 expect(TRUE, r);
2903 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2905 item.iItem = 4;
2906 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2907 expect(TRUE, r);
2908 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2910 DestroyWindow(hwnd);
2913 static void test_ownerdata(void)
2915 static char test_str[] = "test";
2917 HWND hwnd;
2918 LONG_PTR style, ret;
2919 DWORD res;
2920 LVITEMA item;
2922 /* it isn't possible to set LVS_OWNERDATA after creation */
2923 if (g_is_below_5)
2925 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2927 else
2929 hwnd = create_listview_control(LVS_REPORT);
2930 ok(hwnd != NULL, "failed to create a listview window\n");
2931 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2932 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2934 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2936 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2937 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2938 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2939 "try to switch to LVS_OWNERDATA seq", FALSE);
2941 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2942 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2943 DestroyWindow(hwnd);
2946 /* try to set LVS_OWNERDATA after creation just having it */
2947 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2948 ok(hwnd != NULL, "failed to create a listview window\n");
2949 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2950 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2952 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2954 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2955 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2956 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2957 "try to switch to LVS_OWNERDATA seq", FALSE);
2958 DestroyWindow(hwnd);
2960 /* try to remove LVS_OWNERDATA after creation just having it */
2961 if (g_is_below_5)
2963 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2965 else
2967 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2968 ok(hwnd != NULL, "failed to create a listview window\n");
2969 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2970 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2972 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2974 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2975 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2976 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2977 "try to switch to LVS_OWNERDATA seq", FALSE);
2978 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2979 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2980 DestroyWindow(hwnd);
2983 /* try select an item */
2984 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2985 ok(hwnd != NULL, "failed to create a listview window\n");
2986 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2987 expect(1, res);
2988 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2989 expect(0, res);
2990 memset(&item, 0, sizeof(item));
2991 item.stateMask = LVIS_SELECTED;
2992 item.state = LVIS_SELECTED;
2993 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2994 expect(TRUE, res);
2995 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2996 expect(1, res);
2997 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2998 expect(1, res);
2999 DestroyWindow(hwnd);
3001 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
3002 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3003 ok(hwnd != NULL, "failed to create a listview window\n");
3004 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3005 expect(1, res);
3006 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
3007 expect(1, res);
3008 memset(&item, 0, sizeof(item));
3009 item.mask = LVIF_STATE;
3010 item.iItem = 0;
3011 item.stateMask = LVIS_SELECTED;
3012 item.state = LVIS_SELECTED;
3013 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3014 expect(FALSE, res);
3015 memset(&item, 0, sizeof(item));
3016 item.pszText = test_str;
3017 res = SendMessageA(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
3018 expect(FALSE, res);
3019 DestroyWindow(hwnd);
3021 /* check notifications after focused/selected changed */
3022 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3023 ok(hwnd != NULL, "failed to create a listview window\n");
3024 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
3025 expect(1, res);
3027 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3029 memset(&item, 0, sizeof(item));
3030 item.stateMask = LVIS_SELECTED;
3031 item.state = LVIS_SELECTED;
3032 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3033 expect(TRUE, res);
3035 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
3036 "ownerdata select notification", TRUE);
3038 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3040 memset(&item, 0, sizeof(item));
3041 item.stateMask = LVIS_FOCUSED;
3042 item.state = LVIS_FOCUSED;
3043 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3044 expect(TRUE, res);
3046 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
3047 "ownerdata focus notification", TRUE);
3049 /* select all, check notifications */
3050 item.stateMask = LVIS_SELECTED;
3051 item.state = 0;
3052 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3053 expect(TRUE, res);
3055 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3057 item.stateMask = LVIS_SELECTED;
3058 item.state = LVIS_SELECTED;
3060 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3061 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3062 expect(TRUE, res);
3063 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3064 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3065 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3066 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3067 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3068 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3069 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3071 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3072 "ownerdata select all notification", FALSE);
3074 /* select all again, note that all items are selected already */
3075 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3076 item.stateMask = LVIS_SELECTED;
3077 item.state = LVIS_SELECTED;
3079 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3080 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3081 expect(TRUE, res);
3082 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3083 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3084 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3085 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3086 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3087 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3088 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3090 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3091 "ownerdata select all notification", FALSE);
3093 /* deselect all */
3094 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3095 item.stateMask = LVIS_SELECTED;
3096 item.state = 0;
3098 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3099 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3100 expect(TRUE, res);
3101 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3102 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3103 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3104 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3105 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3106 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3107 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3109 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3110 "ownerdata deselect all notification", TRUE);
3112 /* nothing selected, deselect all again */
3113 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3114 item.stateMask = LVIS_SELECTED;
3115 item.state = 0;
3117 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3118 expect(TRUE, res);
3120 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "ownerdata deselect all notification", FALSE);
3122 /* select one, then deselect all */
3123 item.stateMask = LVIS_SELECTED;
3124 item.state = LVIS_SELECTED;
3125 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3126 expect(TRUE, res);
3127 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3128 item.stateMask = LVIS_SELECTED;
3129 item.state = 0;
3131 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3132 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3133 expect(TRUE, res);
3134 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3135 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3136 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3137 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3138 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3139 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3140 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3142 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3143 "ownerdata select all notification", TRUE);
3145 /* remove focused, try to focus all */
3146 item.stateMask = LVIS_FOCUSED;
3147 item.state = LVIS_FOCUSED;
3148 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3149 expect(TRUE, res);
3150 item.stateMask = LVIS_FOCUSED;
3151 item.state = 0;
3152 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3153 expect(TRUE, res);
3154 item.stateMask = LVIS_FOCUSED;
3155 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
3156 expect(0, res);
3158 /* setting all to focused returns failure value */
3159 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3160 item.stateMask = LVIS_FOCUSED;
3161 item.state = LVIS_FOCUSED;
3163 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3164 expect(FALSE, res);
3166 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3167 "ownerdata focus all notification", FALSE);
3169 /* focus single item, remove all */
3170 item.stateMask = LVIS_FOCUSED;
3171 item.state = LVIS_FOCUSED;
3172 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3173 expect(TRUE, res);
3174 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3175 item.stateMask = LVIS_FOCUSED;
3176 item.state = 0;
3178 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3179 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3180 expect(TRUE, res);
3181 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3182 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3183 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3184 ok(g_nmlistview.uOldState == LVIS_FOCUSED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3185 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3186 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3187 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3189 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
3190 "ownerdata remove focus all notification", TRUE);
3192 /* set all cut */
3193 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3194 item.stateMask = LVIS_CUT;
3195 item.state = LVIS_CUT;
3197 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3198 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3199 expect(TRUE, res);
3200 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3201 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3202 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3203 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3204 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3205 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3206 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3208 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3209 "ownerdata cut all notification", FALSE);
3211 /* all marked cut, try again */
3212 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3213 item.stateMask = LVIS_CUT;
3214 item.state = LVIS_CUT;
3216 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3217 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3218 expect(TRUE, res);
3219 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3220 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3221 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3222 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3223 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3224 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3225 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3227 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3228 "ownerdata cut all notification #2", FALSE);
3230 DestroyWindow(hwnd);
3232 /* check notifications on LVM_GETITEM */
3233 /* zero callback mask */
3234 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3235 ok(hwnd != NULL, "failed to create a listview window\n");
3236 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3237 expect(1, res);
3239 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3241 memset(&item, 0, sizeof(item));
3242 item.stateMask = LVIS_SELECTED;
3243 item.mask = LVIF_STATE;
3244 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3245 expect(TRUE, res);
3247 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3248 "ownerdata getitem selected state 1", FALSE);
3250 /* non zero callback mask but not we asking for */
3251 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
3252 expect(TRUE, res);
3254 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3256 memset(&item, 0, sizeof(item));
3257 item.stateMask = LVIS_SELECTED;
3258 item.mask = LVIF_STATE;
3259 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3260 expect(TRUE, res);
3262 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3263 "ownerdata getitem selected state 2", FALSE);
3265 /* LVIS_OVERLAYMASK callback mask, asking for index */
3266 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3268 memset(&item, 0, sizeof(item));
3269 item.stateMask = LVIS_OVERLAYMASK;
3270 item.mask = LVIF_STATE;
3271 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3272 expect(TRUE, res);
3274 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3275 "ownerdata getitem selected state 2", FALSE);
3277 DestroyWindow(hwnd);
3279 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3280 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
3281 ok(hwnd != NULL, "failed to create a listview window\n");
3282 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3283 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3284 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3285 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
3286 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3287 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
3288 DestroyWindow(hwnd);
3289 /* apparently it's allowed to switch these style on after creation */
3290 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3291 ok(hwnd != NULL, "failed to create a listview window\n");
3292 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3293 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3294 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
3295 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3296 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3297 DestroyWindow(hwnd);
3299 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3300 ok(hwnd != NULL, "failed to create a listview window\n");
3301 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3302 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3303 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
3304 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3305 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
3306 DestroyWindow(hwnd);
3309 static void test_norecompute(void)
3311 static CHAR testA[] = "test";
3312 CHAR buff[10];
3313 LVITEMA item;
3314 HWND hwnd;
3315 DWORD res;
3317 /* self containing control */
3318 hwnd = create_listview_control(LVS_REPORT);
3319 ok(hwnd != NULL, "failed to create a listview window\n");
3320 memset(&item, 0, sizeof(item));
3321 item.mask = LVIF_TEXT | LVIF_STATE;
3322 item.iItem = 0;
3323 item.stateMask = LVIS_SELECTED;
3324 item.state = LVIS_SELECTED;
3325 item.pszText = testA;
3326 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3327 expect(0, res);
3328 /* retrieve with LVIF_NORECOMPUTE */
3329 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3330 item.iItem = 0;
3331 item.pszText = buff;
3332 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3333 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3334 expect(TRUE, res);
3335 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
3337 item.mask = LVIF_TEXT;
3338 item.iItem = 1;
3339 item.pszText = LPSTR_TEXTCALLBACK;
3340 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3341 expect(1, res);
3343 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3344 item.iItem = 1;
3345 item.pszText = buff;
3346 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3348 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3349 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3350 expect(TRUE, res);
3351 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
3352 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
3353 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
3355 DestroyWindow(hwnd);
3357 /* LVS_OWNERDATA */
3358 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3359 ok(hwnd != NULL, "failed to create a listview window\n");
3361 item.mask = LVIF_STATE;
3362 item.stateMask = LVIS_SELECTED;
3363 item.state = LVIS_SELECTED;
3364 item.iItem = 0;
3365 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3366 expect(0, res);
3368 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3369 item.iItem = 0;
3370 item.pszText = buff;
3371 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3372 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3373 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3374 expect(TRUE, res);
3375 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
3376 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
3377 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
3379 DestroyWindow(hwnd);
3382 static void test_nosortheader(void)
3384 HWND hwnd, header;
3385 LONG_PTR style;
3387 hwnd = create_listview_control(LVS_REPORT);
3388 ok(hwnd != NULL, "failed to create a listview window\n");
3390 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3391 ok(IsWindow(header), "header expected\n");
3393 style = GetWindowLongPtr(header, GWL_STYLE);
3394 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
3396 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3397 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
3398 /* HDS_BUTTONS retained */
3399 style = GetWindowLongPtr(header, GWL_STYLE);
3400 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
3402 DestroyWindow(hwnd);
3404 /* create with LVS_NOSORTHEADER */
3405 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
3406 ok(hwnd != NULL, "failed to create a listview window\n");
3408 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3409 ok(IsWindow(header), "header expected\n");
3411 style = GetWindowLongPtr(header, GWL_STYLE);
3412 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3414 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3415 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
3416 /* not changed here */
3417 style = GetWindowLongPtr(header, GWL_STYLE);
3418 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3420 DestroyWindow(hwnd);
3423 static void test_setredraw(void)
3425 HWND hwnd;
3426 DWORD_PTR style;
3427 DWORD ret;
3428 HDC hdc;
3429 RECT rect;
3431 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3432 ok(hwnd != NULL, "failed to create a listview window\n");
3434 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3435 ListView seems to handle it internally without DefWinProc */
3437 /* default value first */
3438 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3439 expect(0, ret);
3440 /* disable */
3441 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3442 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3443 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3444 expect(0, ret);
3445 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3446 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3447 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3448 expect(0, ret);
3450 /* check update rect after redrawing */
3451 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3452 expect(0, ret);
3453 InvalidateRect(hwnd, NULL, FALSE);
3454 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
3455 rect.right = rect.bottom = 1;
3456 GetUpdateRect(hwnd, &rect, FALSE);
3457 expect(0, rect.right);
3458 expect(0, rect.bottom);
3460 /* WM_ERASEBKGND */
3461 hdc = GetWindowDC(hwndparent);
3462 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3463 expect(TRUE, ret);
3464 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3465 expect(0, ret);
3466 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3467 expect(TRUE, ret);
3468 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3469 expect(0, ret);
3470 ReleaseDC(hwndparent, hdc);
3472 /* check notification messages to show that repainting is disabled */
3473 ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
3474 expect(TRUE, ret);
3475 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3476 expect(0, ret);
3477 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3479 InvalidateRect(hwnd, NULL, TRUE);
3480 UpdateWindow(hwnd);
3481 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3482 "redraw after WM_SETREDRAW (FALSE)", FALSE);
3484 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3485 expect(TRUE, ret);
3486 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3487 InvalidateRect(hwnd, NULL, TRUE);
3488 UpdateWindow(hwnd);
3489 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3490 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3492 /* message isn't forwarded to header */
3493 subclass_header(hwnd);
3494 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3495 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3496 expect(0, ret);
3497 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3498 "WM_SETREDRAW: not forwarded to header", FALSE);
3500 DestroyWindow(hwnd);
3503 static void test_hittest(void)
3505 HWND hwnd;
3506 DWORD r;
3507 RECT bounds;
3508 LVITEMA item;
3509 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3510 POINT pos;
3511 INT x, y, i;
3512 WORD vert;
3513 HIMAGELIST himl, himl2;
3514 HBITMAP hbmp;
3516 hwnd = create_listview_control(LVS_REPORT);
3517 ok(hwnd != NULL, "failed to create a listview window\n");
3519 /* LVS_REPORT with a single subitem (2 columns) */
3520 insert_column(hwnd, 0);
3521 insert_column(hwnd, 1);
3522 insert_item(hwnd, 0);
3524 item.iSubItem = 0;
3525 /* the only purpose of that line is to be as long as a half item rect */
3526 item.pszText = text;
3527 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
3528 expect(TRUE, r);
3530 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3531 expect(TRUE, r);
3532 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3533 expect(TRUE, r);
3535 memset(&bounds, 0, sizeof(bounds));
3536 bounds.left = LVIR_BOUNDS;
3537 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3538 expect(1, r);
3539 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3540 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3541 r = SendMessage(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3542 vert = HIWORD(r);
3543 ok(bounds.bottom - bounds.top == vert,
3544 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3545 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3546 expect(TRUE, r);
3548 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3550 /* outside columns by x position - valid is [0, 199] */
3551 x = -1;
3552 y = pos.y + (bounds.bottom - bounds.top) / 2;
3553 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3554 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3556 x = pos.x + 50; /* column half width */
3557 y = pos.y + (bounds.bottom - bounds.top) / 2;
3558 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3559 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3560 x = pos.x + 150; /* outside column */
3561 y = pos.y + (bounds.bottom - bounds.top) / 2;
3562 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3563 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3564 y = (bounds.bottom - bounds.top) / 2;
3565 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3566 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3567 /* outside possible client rectangle (to right) */
3568 x = pos.x + 500;
3569 y = pos.y + (bounds.bottom - bounds.top) / 2;
3570 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3571 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3572 y = (bounds.bottom - bounds.top) / 2;
3573 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3574 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3575 /* subitem returned with -1 item too */
3576 x = pos.x + 150;
3577 y = bounds.top - vert;
3578 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3579 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3580 /* return values appear to underflow with negative indices */
3581 i = -2;
3582 y = y - vert;
3583 while (i > -10) {
3584 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3585 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3586 y = y - vert;
3587 i--;
3589 /* parent client area is 100x100 by default */
3590 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3591 x = pos.x + 150; /* outside column */
3592 y = pos.y + (bounds.bottom - bounds.top) / 2;
3593 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3594 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3595 y = (bounds.bottom - bounds.top) / 2;
3596 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3597 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3598 /* the same with LVS_EX_FULLROWSELECT */
3599 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3600 x = pos.x + 150; /* outside column */
3601 y = pos.y + (bounds.bottom - bounds.top) / 2;
3602 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3603 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3604 y = (bounds.bottom - bounds.top) / 2;
3605 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3606 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3607 x = pos.x + 150; /* outside column */
3608 y = pos.y + (bounds.bottom - bounds.top) / 2;
3609 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3610 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3611 y = (bounds.bottom - bounds.top) / 2;
3612 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3613 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3614 /* outside possible client rectangle (to right) */
3615 x = pos.x + 500;
3616 y = pos.y + (bounds.bottom - bounds.top) / 2;
3617 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3618 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3619 y = (bounds.bottom - bounds.top) / 2;
3620 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3621 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3622 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3623 himl = ImageList_Create(16, 16, 0, 4, 4);
3624 ok(himl != NULL, "failed to create imagelist\n");
3625 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3626 ok(hbmp != NULL, "failed to create bitmap\n");
3627 r = ImageList_Add(himl, hbmp, 0);
3628 ok(r == 0, "should be zero\n");
3629 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3630 ok(hbmp != NULL, "failed to create bitmap\n");
3631 r = ImageList_Add(himl, hbmp, 0);
3632 ok(r == 1, "should be one\n");
3634 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3635 expect(0, r);
3637 item.mask = LVIF_IMAGE;
3638 item.iImage = 0;
3639 item.iItem = 0;
3640 item.iSubItem = 0;
3641 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3642 expect(TRUE, r);
3643 /* on state icon */
3644 x = pos.x + 8;
3645 y = pos.y + (bounds.bottom - bounds.top) / 2;
3646 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3647 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3648 y = (bounds.bottom - bounds.top) / 2;
3649 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3651 /* state icons indices are 1 based, check with valid index */
3652 item.mask = LVIF_STATE;
3653 item.state = INDEXTOSTATEIMAGEMASK(1);
3654 item.stateMask = LVIS_STATEIMAGEMASK;
3655 item.iItem = 0;
3656 item.iSubItem = 0;
3657 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3658 expect(TRUE, r);
3659 /* on state icon */
3660 x = pos.x + 8;
3661 y = pos.y + (bounds.bottom - bounds.top) / 2;
3662 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3663 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3664 y = (bounds.bottom - bounds.top) / 2;
3665 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3667 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3668 ok(himl2 == himl, "should return handle\n");
3670 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3671 expect(0, r);
3672 /* on item icon */
3673 x = pos.x + 8;
3674 y = pos.y + (bounds.bottom - bounds.top) / 2;
3675 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3676 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3677 y = (bounds.bottom - bounds.top) / 2;
3678 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3680 DestroyWindow(hwnd);
3683 static void test_getviewrect(void)
3685 HWND hwnd;
3686 DWORD r;
3687 RECT rect;
3688 LVITEMA item;
3690 hwnd = create_listview_control(LVS_REPORT);
3691 ok(hwnd != NULL, "failed to create a listview window\n");
3693 /* empty */
3694 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3695 expect(TRUE, r);
3697 insert_column(hwnd, 0);
3698 insert_column(hwnd, 1);
3700 memset(&item, 0, sizeof(item));
3701 item.iItem = 0;
3702 item.iSubItem = 0;
3703 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3705 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3706 expect(TRUE, r);
3707 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3708 expect(TRUE, r);
3710 rect.left = rect.right = rect.top = rect.bottom = -1;
3711 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3712 expect(TRUE, r);
3713 /* left is set to (2e31-1) - XP SP2 */
3714 expect(0, rect.right);
3715 expect(0, rect.top);
3716 expect(0, rect.bottom);
3718 /* switch to LVS_ICON */
3719 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3721 rect.left = rect.right = rect.top = rect.bottom = -1;
3722 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3723 expect(TRUE, r);
3724 expect(0, rect.left);
3725 expect(0, rect.top);
3726 /* precise value differs for 2k, XP and Vista */
3727 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3728 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3730 DestroyWindow(hwnd);
3733 static void test_getitemposition(void)
3735 HWND hwnd, header;
3736 DWORD r;
3737 POINT pt;
3738 RECT rect;
3740 hwnd = create_listview_control(LVS_REPORT);
3741 ok(hwnd != NULL, "failed to create a listview window\n");
3742 header = subclass_header(hwnd);
3744 /* LVS_REPORT, single item, no columns added */
3745 insert_item(hwnd, 0);
3747 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3749 pt.x = pt.y = -1;
3750 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3751 expect(TRUE, r);
3752 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3754 /* LVS_REPORT, single item, single column */
3755 insert_column(hwnd, 0);
3757 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3759 pt.x = pt.y = -1;
3760 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3761 expect(TRUE, r);
3762 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3764 memset(&rect, 0, sizeof(rect));
3765 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3766 /* some padding? */
3767 expect(2, pt.x);
3768 /* offset by header height */
3769 expect(rect.bottom - rect.top, pt.y);
3771 DestroyWindow(hwnd);
3774 static void test_columnscreation(void)
3776 HWND hwnd, header;
3777 DWORD r;
3779 hwnd = create_listview_control(LVS_REPORT);
3780 ok(hwnd != NULL, "failed to create a listview window\n");
3782 insert_item(hwnd, 0);
3784 /* headers columns aren't created automatically */
3785 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3786 ok(IsWindow(header), "Expected header handle\n");
3787 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3788 expect(0, r);
3790 DestroyWindow(hwnd);
3793 static void test_getitemrect(void)
3795 HWND hwnd;
3796 HIMAGELIST himl, himl_ret;
3797 HBITMAP hbm;
3798 RECT rect;
3799 DWORD r;
3800 LVITEMA item;
3801 LVCOLUMNA col;
3802 INT order[2];
3803 POINT pt;
3804 HDC hdc;
3806 /* rectangle isn't empty for empty text items */
3807 hwnd = create_listview_control(LVS_LIST);
3808 memset(&item, 0, sizeof(item));
3809 item.mask = 0;
3810 item.iItem = 0;
3811 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3812 expect(0, r);
3813 rect.left = LVIR_LABEL;
3814 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3815 expect(TRUE, r);
3816 expect(0, rect.left);
3817 expect(0, rect.top);
3818 hdc = GetDC(hwnd);
3819 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, rect.right);
3820 ReleaseDC(hwnd, hdc);
3821 DestroyWindow(hwnd);
3823 hwnd = create_listview_control(LVS_REPORT);
3824 ok(hwnd != NULL, "failed to create a listview window\n");
3826 /* empty item */
3827 memset(&item, 0, sizeof(item));
3828 item.iItem = 0;
3829 item.iSubItem = 0;
3830 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3831 expect(0, r);
3833 rect.left = LVIR_BOUNDS;
3834 rect.right = rect.top = rect.bottom = -1;
3835 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3836 expect(TRUE, r);
3838 /* zero width rectangle with no padding */
3839 expect(0, rect.left);
3840 expect(0, rect.right);
3842 insert_column(hwnd, 0);
3843 insert_column(hwnd, 1);
3845 col.mask = LVCF_WIDTH;
3846 col.cx = 50;
3847 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3848 expect(TRUE, r);
3850 col.mask = LVCF_WIDTH;
3851 col.cx = 100;
3852 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3853 expect(TRUE, r);
3855 rect.left = LVIR_BOUNDS;
3856 rect.right = rect.top = rect.bottom = -1;
3857 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3858 expect(TRUE, r);
3860 /* still no left padding */
3861 expect(0, rect.left);
3862 expect(150, rect.right);
3864 rect.left = LVIR_SELECTBOUNDS;
3865 rect.right = rect.top = rect.bottom = -1;
3866 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3867 expect(TRUE, r);
3868 /* padding */
3869 expect(2, rect.left);
3871 rect.left = LVIR_LABEL;
3872 rect.right = rect.top = rect.bottom = -1;
3873 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3874 expect(TRUE, r);
3875 /* padding, column width */
3876 expect(2, rect.left);
3877 expect(50, rect.right);
3879 /* no icons attached */
3880 rect.left = LVIR_ICON;
3881 rect.right = rect.top = rect.bottom = -1;
3882 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3883 expect(TRUE, r);
3884 /* padding */
3885 expect(2, rect.left);
3886 expect(2, rect.right);
3888 /* change order */
3889 order[0] = 1; order[1] = 0;
3890 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3891 expect(TRUE, r);
3892 pt.x = -1;
3893 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3894 expect(TRUE, r);
3895 /* 1 indexed column width + padding */
3896 expect(102, pt.x);
3897 /* rect is at zero too */
3898 rect.left = LVIR_BOUNDS;
3899 rect.right = rect.top = rect.bottom = -1;
3900 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3901 expect(TRUE, r);
3902 expect(0, rect.left);
3903 /* just width sum */
3904 expect(150, rect.right);
3906 rect.left = LVIR_SELECTBOUNDS;
3907 rect.right = rect.top = rect.bottom = -1;
3908 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3909 expect(TRUE, r);
3910 /* column width + padding */
3911 expect(102, rect.left);
3913 /* back to initial order */
3914 order[0] = 0; order[1] = 1;
3915 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3916 expect(TRUE, r);
3918 /* state icons */
3919 himl = ImageList_Create(16, 16, 0, 2, 2);
3920 ok(himl != NULL, "failed to create imagelist\n");
3921 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3922 ok(hbm != NULL, "failed to create bitmap\n");
3923 r = ImageList_Add(himl, hbm, 0);
3924 expect(0, r);
3925 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3926 ok(hbm != NULL, "failed to create bitmap\n");
3927 r = ImageList_Add(himl, hbm, 0);
3928 expect(1, r);
3930 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3931 expect(0, r);
3933 item.mask = LVIF_STATE;
3934 item.state = INDEXTOSTATEIMAGEMASK(1);
3935 item.stateMask = LVIS_STATEIMAGEMASK;
3936 item.iItem = 0;
3937 item.iSubItem = 0;
3938 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3939 expect(TRUE, r);
3941 /* icon bounds */
3942 rect.left = LVIR_ICON;
3943 rect.right = rect.top = rect.bottom = -1;
3944 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3945 expect(TRUE, r);
3946 /* padding + stateicon width */
3947 expect(18, rect.left);
3948 expect(18, rect.right);
3949 /* label bounds */
3950 rect.left = LVIR_LABEL;
3951 rect.right = rect.top = rect.bottom = -1;
3952 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3953 expect(TRUE, r);
3954 /* padding + stateicon width -> column width */
3955 expect(18, rect.left);
3956 expect(50, rect.right);
3958 himl_ret = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3959 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
3961 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3962 expect(0, r);
3964 item.mask = LVIF_STATE | LVIF_IMAGE;
3965 item.iImage = 1;
3966 item.state = 0;
3967 item.stateMask = ~0;
3968 item.iItem = 0;
3969 item.iSubItem = 0;
3970 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3971 expect(TRUE, r);
3973 /* icon bounds */
3974 rect.left = LVIR_ICON;
3975 rect.right = rect.top = rect.bottom = -1;
3976 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3977 expect(TRUE, r);
3978 /* padding, icon width */
3979 expect(2, rect.left);
3980 expect(18, rect.right);
3981 /* label bounds */
3982 rect.left = LVIR_LABEL;
3983 rect.right = rect.top = rect.bottom = -1;
3984 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3985 expect(TRUE, r);
3986 /* padding + icon width -> column width */
3987 expect(18, rect.left);
3988 expect(50, rect.right);
3990 /* select bounds */
3991 rect.left = LVIR_SELECTBOUNDS;
3992 rect.right = rect.top = rect.bottom = -1;
3993 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3994 expect(TRUE, r);
3995 /* padding, column width */
3996 expect(2, rect.left);
3997 expect(50, rect.right);
3999 /* try with indentation */
4000 item.mask = LVIF_INDENT;
4001 item.iIndent = 1;
4002 item.iItem = 0;
4003 item.iSubItem = 0;
4004 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
4005 expect(TRUE, r);
4007 /* bounds */
4008 rect.left = LVIR_BOUNDS;
4009 rect.right = rect.top = rect.bottom = -1;
4010 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4011 expect(TRUE, r);
4012 /* padding + 1 icon width, column width */
4013 expect(0, rect.left);
4014 expect(150, rect.right);
4016 /* select bounds */
4017 rect.left = LVIR_SELECTBOUNDS;
4018 rect.right = rect.top = rect.bottom = -1;
4019 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4020 expect(TRUE, r);
4021 /* padding + 1 icon width, column width */
4022 expect(2 + 16, rect.left);
4023 expect(50, rect.right);
4025 /* label bounds */
4026 rect.left = LVIR_LABEL;
4027 rect.right = rect.top = rect.bottom = -1;
4028 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4029 expect(TRUE, r);
4030 /* padding + 2 icon widths, column width */
4031 expect(2 + 16*2, rect.left);
4032 expect(50, rect.right);
4034 /* icon bounds */
4035 rect.left = LVIR_ICON;
4036 rect.right = rect.top = rect.bottom = -1;
4037 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4038 expect(TRUE, r);
4039 /* padding + 1 icon width indentation, icon width */
4040 expect(2 + 16, rect.left);
4041 expect(34, rect.right);
4043 DestroyWindow(hwnd);
4046 static void test_editbox(void)
4048 static CHAR testitemA[] = "testitem";
4049 static CHAR testitem1A[] = "testitem_quitelongname";
4050 static CHAR testitem2A[] = "testITEM_quitelongname";
4051 static CHAR buffer[25];
4052 HWND hwnd, hwndedit, hwndedit2, header;
4053 LVITEMA item;
4054 INT r;
4056 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4057 ok(hwnd != NULL, "failed to create a listview window\n");
4059 insert_column(hwnd, 0);
4061 memset(&item, 0, sizeof(item));
4062 item.mask = LVIF_TEXT;
4063 item.pszText = testitemA;
4064 item.iItem = 0;
4065 item.iSubItem = 0;
4066 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4067 expect(0, r);
4069 /* test notifications without edit created */
4070 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4071 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
4072 expect(0, r);
4073 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4074 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
4075 /* same thing but with valid window */
4076 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
4077 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
4078 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4079 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
4080 expect(0, r);
4081 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4082 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
4083 DestroyWindow(hwndedit);
4085 /* setting focus is necessary */
4086 SetFocus(hwnd);
4087 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4088 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4090 /* test children Z-order after Edit box created */
4091 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4092 ok(IsWindow(header), "Expected header to be created\n");
4093 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4094 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4096 /* modify initial string */
4097 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4098 expect(TRUE, r);
4100 /* edit window is resized and repositioned,
4101 check again for Z-order - it should be preserved */
4102 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4103 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4105 /* return focus to listview */
4106 SetFocus(hwnd);
4108 memset(&item, 0, sizeof(item));
4109 item.mask = LVIF_TEXT;
4110 item.pszText = buffer;
4111 item.cchTextMax = sizeof(buffer);
4112 item.iItem = 0;
4113 item.iSubItem = 0;
4114 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4115 expect(TRUE, r);
4117 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4119 /* send LVM_EDITLABEL on already created edit */
4120 SetFocus(hwnd);
4121 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4122 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4123 /* focus will be set to edit */
4124 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
4125 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4126 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
4128 /* creating label disabled when control isn't focused */
4129 SetFocus(0);
4130 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4131 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4133 /* check EN_KILLFOCUS handling */
4134 memset(&item, 0, sizeof(item));
4135 item.pszText = testitemA;
4136 item.iItem = 0;
4137 item.iSubItem = 0;
4138 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4139 expect(TRUE, r);
4141 SetFocus(hwnd);
4142 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4143 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4144 /* modify edit and notify control that it lost focus */
4145 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4146 expect(TRUE, r);
4147 g_editbox_disp_info.item.pszText = NULL;
4148 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4149 expect(0, r);
4150 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
4152 memset(&item, 0, sizeof(item));
4153 item.pszText = buffer;
4154 item.cchTextMax = sizeof(buffer);
4155 item.iItem = 0;
4156 item.iSubItem = 0;
4157 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4158 expect(lstrlen(item.pszText), r);
4159 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4160 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4162 /* change item name to differ in casing only */
4163 SetFocus(hwnd);
4164 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4165 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4166 /* modify edit and notify control that it lost focus */
4167 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
4168 expect(TRUE, r);
4169 g_editbox_disp_info.item.pszText = NULL;
4170 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4171 expect(0, r);
4172 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
4174 memset(&item, 0, sizeof(item));
4175 item.pszText = buffer;
4176 item.cchTextMax = sizeof(buffer);
4177 item.iItem = 0;
4178 item.iSubItem = 0;
4179 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4180 expect(lstrlen(item.pszText), r);
4181 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
4182 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4184 /* end edit without saving */
4185 SetFocus(hwnd);
4186 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4187 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4188 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
4189 expect(0, r);
4190 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4191 "edit box - end edit, no change, escape", TRUE);
4192 /* end edit with saving */
4193 SetFocus(hwnd);
4194 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4195 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4196 r = SendMessage(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
4197 expect(0, r);
4198 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4199 "edit box - end edit, no change, return", TRUE);
4201 memset(&item, 0, sizeof(item));
4202 item.pszText = buffer;
4203 item.cchTextMax = sizeof(buffer);
4204 item.iItem = 0;
4205 item.iSubItem = 0;
4206 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4207 expect(lstrlen(item.pszText), r);
4208 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
4210 /* LVM_EDITLABEL with -1 destroys current edit */
4211 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
4212 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4213 /* no edit present */
4214 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
4215 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4216 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4217 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4218 /* edit present */
4219 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4220 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
4221 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4222 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4223 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4224 /* check another negative value */
4225 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4226 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4227 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4228 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
4229 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4230 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4231 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4232 /* and value greater than max item index */
4233 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4234 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4235 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4236 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
4237 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
4238 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4239 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4240 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4242 /* messaging tests */
4243 SetFocus(hwnd);
4244 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4245 blockEdit = FALSE;
4246 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4247 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4248 /* testing only sizing messages */
4249 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
4250 "edit box create - sizing", FALSE);
4252 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4253 SetFocus(hwnd);
4254 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4255 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4256 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4257 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4258 expect(0, r);
4259 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4260 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
4262 DestroyWindow(hwnd);
4265 static void test_notifyformat(void)
4267 HWND hwnd, header;
4268 DWORD r;
4270 hwnd = create_listview_control(LVS_REPORT);
4271 ok(hwnd != NULL, "failed to create a listview window\n");
4273 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4274 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4275 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4276 expect(0, r);
4277 SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4278 /* set */
4279 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
4280 expect(0, r);
4281 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4282 if (r == 1)
4284 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
4285 expect(1, r);
4286 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4287 expect(0, r);
4289 else
4291 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4292 DestroyWindow(hwnd);
4293 return;
4296 DestroyWindow(hwnd);
4298 /* test failure in parent WM_NOTIFYFORMAT */
4299 notifyFormat = 0;
4300 hwnd = create_listview_control(LVS_REPORT);
4301 ok(hwnd != NULL, "failed to create a listview window\n");
4302 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4303 ok(IsWindow(header), "expected header to be created\n");
4304 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4305 expect(0, r);
4306 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4307 ok( r == 1, "Expected 1, got %d\n", r );
4308 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4309 ok(r != 0, "Expected valid format\n");
4311 notifyFormat = NFR_UNICODE;
4312 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4313 expect(NFR_UNICODE, r);
4314 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4315 expect(1, r);
4316 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4317 ok( r == 1, "Expected 1, got %d\n", r );
4319 notifyFormat = NFR_ANSI;
4320 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4321 expect(NFR_ANSI, r);
4322 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4323 expect(0, r);
4324 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4325 ok( r == 1, "Expected 1, got %d\n", r );
4327 DestroyWindow(hwnd);
4329 hwndparentW = create_parent_window(TRUE);
4330 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
4331 if (!IsWindow(hwndparentW)) return;
4333 notifyFormat = -1;
4334 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4335 ok(hwnd != NULL, "failed to create a listview window\n");
4336 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4337 ok(IsWindow(header), "expected header to be created\n");
4338 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4339 expect(1, r);
4340 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4341 expect(1, r);
4342 DestroyWindow(hwnd);
4343 /* receiving error code defaulting to ansi */
4344 notifyFormat = 0;
4345 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4346 ok(hwnd != NULL, "failed to create a listview window\n");
4347 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4348 ok(IsWindow(header), "expected header to be created\n");
4349 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4350 expect(0, r);
4351 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4352 expect(1, r);
4353 DestroyWindow(hwnd);
4354 /* receiving ansi code from unicode window, use it */
4355 notifyFormat = NFR_ANSI;
4356 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4357 ok(hwnd != NULL, "failed to create a listview window\n");
4358 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4359 ok(IsWindow(header), "expected header to be created\n");
4360 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4361 expect(0, r);
4362 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4363 expect(1, r);
4364 DestroyWindow(hwnd);
4365 /* unicode listview with ansi parent window */
4366 notifyFormat = -1;
4367 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4368 ok(hwnd != NULL, "failed to create a listview window\n");
4369 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4370 ok(IsWindow(header), "expected header to be created\n");
4371 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4372 expect(0, r);
4373 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4374 expect(1, r);
4375 DestroyWindow(hwnd);
4376 /* unicode listview with ansi parent window, return error code */
4377 notifyFormat = 0;
4378 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4379 ok(hwnd != NULL, "failed to create a listview window\n");
4380 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4381 ok(IsWindow(header), "expected header to be created\n");
4382 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4383 expect(0, r);
4384 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4385 expect(1, r);
4386 DestroyWindow(hwnd);
4388 DestroyWindow(hwndparentW);
4391 static void test_indentation(void)
4393 HWND hwnd;
4394 LVITEMA item;
4395 DWORD r;
4397 hwnd = create_listview_control(LVS_REPORT);
4398 ok(hwnd != NULL, "failed to create a listview window\n");
4400 memset(&item, 0, sizeof(item));
4401 item.mask = LVIF_INDENT;
4402 item.iItem = 0;
4403 item.iIndent = I_INDENTCALLBACK;
4404 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4405 expect(0, r);
4407 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4409 item.iItem = 0;
4410 item.mask = LVIF_INDENT;
4411 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
4412 expect(TRUE, r);
4414 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
4415 "get indent dispinfo", FALSE);
4417 DestroyWindow(hwnd);
4420 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
4422 return 0;
4425 static BOOL is_below_comctl_5(void)
4427 HWND hwnd;
4428 BOOL ret;
4430 hwnd = create_listview_control(LVS_REPORT);
4431 ok(hwnd != NULL, "failed to create a listview window\n");
4432 insert_item(hwnd, 0);
4434 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
4436 DestroyWindow(hwnd);
4438 return !ret;
4441 static void test_get_set_view(void)
4443 HWND hwnd;
4444 DWORD ret;
4445 DWORD_PTR style;
4447 /* test style->view mapping */
4448 hwnd = create_listview_control(LVS_REPORT);
4449 ok(hwnd != NULL, "failed to create a listview window\n");
4451 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4452 expect(LV_VIEW_DETAILS, ret);
4454 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4455 /* LVS_ICON == 0 */
4456 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4457 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4458 expect(LV_VIEW_ICON, ret);
4460 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4461 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4462 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4463 expect(LV_VIEW_SMALLICON, ret);
4465 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4466 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4467 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4468 expect(LV_VIEW_LIST, ret);
4470 /* switching view doesn't touch window style */
4471 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4472 expect(1, ret);
4473 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4474 ok(style & LVS_LIST, "Expected style to be preserved\n");
4475 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4476 expect(1, ret);
4477 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4478 ok(style & LVS_LIST, "Expected style to be preserved\n");
4479 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4480 expect(1, ret);
4481 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4482 ok(style & LVS_LIST, "Expected style to be preserved\n");
4484 DestroyWindow(hwnd);
4487 static void test_canceleditlabel(void)
4489 HWND hwnd, hwndedit;
4490 DWORD ret;
4491 CHAR buff[10];
4492 LVITEMA itema;
4493 static CHAR test[] = "test";
4494 static const CHAR test1[] = "test1";
4496 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4497 ok(hwnd != NULL, "failed to create a listview window\n");
4499 insert_item(hwnd, 0);
4501 /* try without edit created */
4502 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4503 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4504 expect(TRUE, ret);
4505 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4506 "cancel edit label without edit", FALSE);
4508 /* cancel without data change */
4509 SetFocus(hwnd);
4510 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4511 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4512 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4513 expect(TRUE, ret);
4514 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4516 /* cancel after data change */
4517 memset(&itema, 0, sizeof(itema));
4518 itema.pszText = test;
4519 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4520 expect(TRUE, ret);
4521 SetFocus(hwnd);
4522 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4523 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4524 ret = SetWindowText(hwndedit, test1);
4525 expect(1, ret);
4526 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4527 expect(TRUE, ret);
4528 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4529 memset(&itema, 0, sizeof(itema));
4530 itema.pszText = buff;
4531 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4532 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
4533 expect(5, ret);
4534 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4536 DestroyWindow(hwnd);
4539 static void test_mapidindex(void)
4541 HWND hwnd;
4542 INT ret;
4544 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4545 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4546 ok(hwnd != NULL, "failed to create a listview window\n");
4547 insert_item(hwnd, 0);
4548 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4549 expect(-1, ret);
4550 DestroyWindow(hwnd);
4552 hwnd = create_listview_control(LVS_REPORT);
4553 ok(hwnd != NULL, "failed to create a listview window\n");
4555 /* LVM_MAPINDEXTOID with invalid index */
4556 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4557 expect(-1, ret);
4559 insert_item(hwnd, 0);
4560 insert_item(hwnd, 1);
4562 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
4563 expect(-1, ret);
4564 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
4565 expect(-1, ret);
4567 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4568 expect(0, ret);
4569 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4570 expect(1, ret);
4571 /* remove 0 indexed item, id retained */
4572 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
4573 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4574 expect(1, ret);
4575 /* new id starts from previous value */
4576 insert_item(hwnd, 1);
4577 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4578 expect(2, ret);
4580 /* get index by id */
4581 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4582 expect(-1, ret);
4583 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4584 expect(-1, ret);
4585 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4586 expect(0, ret);
4587 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4588 expect(1, ret);
4590 DestroyWindow(hwnd);
4593 static void test_getitemspacing(void)
4595 HWND hwnd;
4596 DWORD ret;
4597 INT cx, cy;
4598 HIMAGELIST himl40, himl80;
4600 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4601 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4603 /* LVS_ICON */
4604 hwnd = create_listview_control(LVS_ICON);
4605 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4606 expect(cx, LOWORD(ret));
4607 expect(cy, HIWORD(ret));
4609 /* now try with icons */
4610 himl40 = ImageList_Create(40, 40, 0, 4, 4);
4611 ok(himl40 != NULL, "failed to create imagelist\n");
4612 himl80 = ImageList_Create(80, 80, 0, 4, 4);
4613 ok(himl80 != NULL, "failed to create imagelist\n");
4614 ret = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4615 expect(0, ret);
4617 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4618 /* spacing + icon size returned */
4619 expect(cx + 40, LOWORD(ret));
4620 expect(cy + 40, HIWORD(ret));
4621 /* try changing icon size */
4622 SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl80);
4624 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4625 /* spacing + icon size returned */
4626 expect(cx + 80, LOWORD(ret));
4627 expect(cy + 80, HIWORD(ret));
4629 /* set own icon spacing */
4630 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(100, 100));
4631 expect(cx + 80, LOWORD(ret));
4632 expect(cy + 80, HIWORD(ret));
4634 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4635 /* set size returned */
4636 expect(100, LOWORD(ret));
4637 expect(100, HIWORD(ret));
4639 /* now change image list - icon spacing should be unaffected */
4640 SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4642 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4643 /* set size returned */
4644 expect(100, LOWORD(ret));
4645 expect(100, HIWORD(ret));
4647 /* spacing = 0 - keep previous value */
4648 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(0, -1));
4649 expect(100, LOWORD(ret));
4650 expect(100, HIWORD(ret));
4652 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4653 expect(100, LOWORD(ret));
4655 expect(0xFFFF, HIWORD(ret));
4657 if (sizeof(void*) == 8)
4659 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4660 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, (DWORD)-1);
4661 expect(100, LOWORD(ret));
4662 expect(0xFFFF, HIWORD(ret));
4664 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, -1);
4665 expect(0xFFFF, LOWORD(ret));
4666 expect(0xFFFF, HIWORD(ret));
4668 else
4670 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, -1);
4671 expect(100, LOWORD(ret));
4672 expect(0xFFFF, HIWORD(ret));
4674 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4675 /* spacing + icon size returned */
4676 expect(cx + 40, LOWORD(ret));
4677 expect(cy + 40, HIWORD(ret));
4679 SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4680 ImageList_Destroy(himl80);
4681 DestroyWindow(hwnd);
4682 /* LVS_SMALLICON */
4683 hwnd = create_listview_control(LVS_SMALLICON);
4684 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4685 expect(cx, LOWORD(ret));
4686 expect(cy, HIWORD(ret));
4688 /* spacing does not depend on selected view type */
4689 ret = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4690 expect(0, ret);
4692 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4693 /* spacing + icon size returned */
4694 expect(cx + 40, LOWORD(ret));
4695 expect(cy + 40, HIWORD(ret));
4697 SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4698 ImageList_Destroy(himl40);
4699 DestroyWindow(hwnd);
4700 /* LVS_REPORT */
4701 hwnd = create_listview_control(LVS_REPORT);
4702 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4703 expect(cx, LOWORD(ret));
4704 expect(cy, HIWORD(ret));
4706 DestroyWindow(hwnd);
4707 /* LVS_LIST */
4708 hwnd = create_listview_control(LVS_LIST);
4709 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4710 expect(cx, LOWORD(ret));
4711 expect(cy, HIWORD(ret));
4713 DestroyWindow(hwnd);
4716 static void test_getcolumnwidth(void)
4718 HWND hwnd;
4719 INT ret;
4720 DWORD_PTR style;
4721 LVCOLUMNA col;
4722 LVITEMA itema;
4723 HDC hdc;
4725 /* default column width */
4726 hwnd = create_listview_control(LVS_ICON);
4727 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4728 expect(0, ret);
4729 style = GetWindowLong(hwnd, GWL_STYLE);
4730 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
4731 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4732 todo_wine expect(8, ret);
4733 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
4734 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
4735 col.mask = 0;
4736 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4737 expect(0, ret);
4738 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4739 expect(10, ret);
4740 DestroyWindow(hwnd);
4742 /* default column width with item added */
4743 hwnd = create_listview_control(LVS_LIST);
4744 memset(&itema, 0, sizeof(itema));
4745 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4746 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4747 hdc = GetDC(hwnd);
4748 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, ret);
4749 ReleaseDC(hwnd, hdc);
4750 DestroyWindow(hwnd);
4753 static void test_scrollnotify(void)
4755 HWND hwnd;
4756 DWORD ret;
4758 hwnd = create_listview_control(LVS_REPORT);
4760 insert_column(hwnd, 0);
4761 insert_column(hwnd, 1);
4762 insert_item(hwnd, 0);
4764 /* make it scrollable - resize */
4765 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4766 expect(TRUE, ret);
4767 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4768 expect(TRUE, ret);
4770 /* try with dummy call */
4771 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4772 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
4773 expect(TRUE, ret);
4774 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4775 "scroll notify 1", TRUE);
4777 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4778 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
4779 expect(TRUE, ret);
4780 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4781 "scroll notify 2", TRUE);
4783 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4784 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4785 expect(TRUE, ret);
4786 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4787 "scroll notify 3", TRUE);
4789 DestroyWindow(hwnd);
4792 static void test_LVS_EX_TRANSPARENTBKGND(void)
4794 HWND hwnd;
4795 DWORD ret;
4796 HDC hdc;
4798 hwnd = create_listview_control(LVS_REPORT);
4800 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4801 expect(TRUE, ret);
4803 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4804 LVS_EX_TRANSPARENTBKGND);
4806 ret = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
4807 if (ret != CLR_NONE)
4809 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4810 DestroyWindow(hwnd);
4811 return;
4814 /* try to set some back color and check this style bit */
4815 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4816 expect(TRUE, ret);
4817 ret = SendMessage(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4818 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4820 /* now test what this style actually does */
4821 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4822 LVS_EX_TRANSPARENTBKGND);
4824 hdc = GetWindowDC(hwndparent);
4826 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4827 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4828 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4829 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4831 ReleaseDC(hwndparent, hdc);
4833 DestroyWindow(hwnd);
4836 static void test_approximate_viewrect(void)
4838 HWND hwnd;
4839 DWORD ret;
4840 HIMAGELIST himl;
4841 HBITMAP hbmp;
4842 LVITEMA itema;
4843 static CHAR test[] = "abracadabra, a very long item label";
4845 hwnd = create_listview_control(LVS_ICON);
4846 himl = ImageList_Create(40, 40, 0, 4, 4);
4847 ok(himl != NULL, "failed to create imagelist\n");
4848 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4849 ok(hbmp != NULL, "failed to create bitmap\n");
4850 ret = ImageList_Add(himl, hbmp, 0);
4851 expect(0, ret);
4852 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4853 expect(0, ret);
4855 itema.mask = LVIF_IMAGE;
4856 itema.iImage = 0;
4857 itema.iItem = 0;
4858 itema.iSubItem = 0;
4859 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4860 expect(0, ret);
4862 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4863 if (ret == 0)
4865 /* version 4.0 */
4866 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4867 return;
4870 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4871 expect(MAKELONG(77,827), ret);
4873 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4874 ok(ret != 0, "got 0\n");
4876 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4877 expect(MAKELONG(102,302), ret);
4879 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4880 expect(MAKELONG(52,52), ret);
4882 itema.pszText = test;
4883 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4884 expect(TRUE, ret);
4885 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4886 expect(MAKELONG(52,52), ret);
4888 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4889 expect(MAKELONG(52,2), ret);
4890 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4891 expect(MAKELONG(52,52), ret);
4892 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4893 expect(MAKELONG(102,52), ret);
4894 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4895 expect(MAKELONG(102,102), ret);
4896 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4897 expect(MAKELONG(102,102), ret);
4898 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4899 expect(MAKELONG(102,152), ret);
4900 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4901 expect(MAKELONG(102,152), ret);
4902 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4903 expect(MAKELONG(152,152), ret);
4905 DestroyWindow(hwnd);
4908 static void test_finditem(void)
4910 LVFINDINFOA fi;
4911 static char f[5];
4912 HWND hwnd;
4913 INT r;
4915 hwnd = create_listview_control(LVS_REPORT);
4916 insert_item(hwnd, 0);
4918 memset(&fi, 0, sizeof(fi));
4920 /* full string search, inserted text was "foo" */
4921 strcpy(f, "foo");
4922 fi.flags = LVFI_STRING;
4923 fi.psz = f;
4924 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4925 expect(0, r);
4926 /* partial string search, inserted text was "foo" */
4927 strcpy(f, "fo");
4928 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4929 fi.psz = f;
4930 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4931 expect(0, r);
4932 /* partial string search, part after start char */
4933 strcpy(f, "oo");
4934 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4935 fi.psz = f;
4936 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4937 expect(-1, r);
4939 /* try with LVFI_SUBSTRING */
4940 strcpy(f, "fo");
4941 fi.flags = LVFI_SUBSTRING;
4942 fi.psz = f;
4943 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4944 if (r == -1)
4946 win_skip("LVFI_SUBSTRING not supported\n");
4947 DestroyWindow(hwnd);
4948 return;
4950 expect(0, r);
4951 strcpy(f, "f");
4952 fi.flags = LVFI_SUBSTRING;
4953 fi.psz = f;
4954 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4955 expect(0, r);
4956 strcpy(f, "o");
4957 fi.flags = LVFI_SUBSTRING;
4958 fi.psz = f;
4959 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4960 expect(-1, r);
4962 strcpy(f, "f");
4963 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
4964 fi.psz = f;
4965 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4966 expect(0, r);
4968 DestroyWindow(hwnd);
4971 static void test_LVS_EX_HEADERINALLVIEWS(void)
4973 HWND hwnd, header;
4974 DWORD style;
4976 hwnd = create_listview_control(LVS_ICON);
4978 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4979 LVS_EX_HEADERINALLVIEWS);
4981 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4982 if (!IsWindow(header))
4984 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4985 DestroyWindow(hwnd);
4986 return;
4989 /* LVS_NOCOLUMNHEADER works as before */
4990 style = GetWindowLongA(hwnd, GWL_STYLE);
4991 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
4992 style = GetWindowLongA(header, GWL_STYLE);
4993 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
4994 style = GetWindowLongA(hwnd, GWL_STYLE);
4995 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
4996 style = GetWindowLongA(header, GWL_STYLE);
4997 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
4999 /* try to remove style */
5000 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
5001 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
5002 ok(IsWindow(header), "Expected header to be created\n");
5003 style = GetWindowLongA(header, GWL_STYLE);
5004 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
5006 DestroyWindow(hwnd);
5008 /* check other styles */
5009 hwnd = create_listview_control(LVS_LIST);
5010 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5011 LVS_EX_HEADERINALLVIEWS);
5012 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
5013 ok(IsWindow(header), "Expected header to be created\n");
5014 DestroyWindow(hwnd);
5016 hwnd = create_listview_control(LVS_SMALLICON);
5017 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5018 LVS_EX_HEADERINALLVIEWS);
5019 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
5020 ok(IsWindow(header), "Expected header to be created\n");
5021 DestroyWindow(hwnd);
5023 hwnd = create_listview_control(LVS_REPORT);
5024 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5025 LVS_EX_HEADERINALLVIEWS);
5026 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
5027 ok(IsWindow(header), "Expected header to be created\n");
5028 DestroyWindow(hwnd);
5031 static void test_hover(void)
5033 HWND hwnd;
5034 DWORD r;
5036 hwnd = create_listview_control(LVS_ICON);
5038 /* test WM_MOUSEHOVER forwarding */
5039 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5040 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
5041 expect(0, r);
5042 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
5043 g_block_hover = TRUE;
5044 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5045 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
5046 expect(0, r);
5047 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
5048 g_block_hover = FALSE;
5050 r = SendMessage(hwnd, LVM_SETHOVERTIME, 0, 500);
5051 expect(HOVER_DEFAULT, r);
5052 r = SendMessage(hwnd, LVM_GETHOVERTIME, 0, 0);
5053 expect(500, r);
5055 DestroyWindow(hwnd);
5058 static void test_destroynotify(void)
5060 HWND hwnd;
5062 hwnd = create_listview_control(LVS_REPORT);
5063 ok(hwnd != NULL, "failed to create listview window\n");
5065 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5066 DestroyWindow(hwnd);
5067 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
5070 static void test_header_notification(void)
5072 static char textA[] = "newtext";
5073 HWND list, header;
5074 HDITEMA item;
5075 NMHEADER nmh;
5076 LVCOLUMNA col;
5077 DWORD ret;
5078 BOOL r;
5080 list = create_listview_control(LVS_REPORT);
5081 ok(list != NULL, "failed to create listview window\n");
5083 memset(&col, 0, sizeof(col));
5084 col.mask = LVCF_WIDTH;
5085 col.cx = 100;
5086 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5087 expect(0, ret);
5089 /* check list parent notification after header item changed,
5090 this test should be placed before header subclassing to avoid
5091 Listview -> Header messages to be logged */
5092 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5094 col.mask = LVCF_TEXT;
5095 col.pszText = textA;
5096 r = SendMessage(list, LVM_SETCOLUMNA, 0, (LPARAM)&col);
5097 expect(TRUE, r);
5099 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_changed_seq,
5100 "header notify, listview", FALSE);
5101 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5102 "header notify, parent", FALSE);
5104 header = subclass_header(list);
5106 ret = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
5107 expect(1, ret);
5109 memset(&item, 0, sizeof(item));
5110 item.mask = HDI_WIDTH;
5111 ret = SendMessage(header, HDM_GETITEMA, 0, (LPARAM)&item);
5112 expect(1, ret);
5113 expect(100, item.cxy);
5115 nmh.hdr.hwndFrom = header;
5116 nmh.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
5117 nmh.hdr.code = HDN_ITEMCHANGEDA;
5118 nmh.iItem = 0;
5119 nmh.iButton = 0;
5120 item.mask = HDI_WIDTH;
5121 item.cxy = 50;
5122 nmh.pitem = &item;
5123 ret = SendMessage(list, WM_NOTIFY, 0, (LPARAM)&nmh);
5124 expect(0, ret);
5126 DestroyWindow(list);
5129 static void test_header_notification2(void)
5131 static char textA[] = "newtext";
5132 HWND list, header;
5133 HDITEMW itemW;
5134 NMHEADERW nmhdr;
5135 LVCOLUMNA col;
5136 DWORD ret;
5137 WCHAR buffer[100];
5138 struct message parent_header_notify_seq[] = {
5139 { WM_NOTIFY, sent|id, 0, 0, 0 },
5140 { 0 }
5143 list = create_listview_control(LVS_REPORT);
5144 ok(list != NULL, "failed to create listview window\n");
5146 memset(&col, 0, sizeof(col));
5147 col.mask = LVCF_WIDTH | LVCF_TEXT;
5148 col.cx = 100;
5149 col.pszText = textA;
5150 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5151 expect(0, ret);
5153 header = ListView_GetHeader(list);
5154 ok(header != 0, "No header\n");
5155 memset(&itemW, 0, sizeof(itemW));
5156 itemW.mask = HDI_WIDTH | HDI_ORDER | HDI_TEXT;
5157 itemW.pszText = buffer;
5158 itemW.cchTextMax = sizeof(buffer);
5159 ret = SendMessageW(header, HDM_GETITEMW, 0, (LPARAM)&itemW);
5160 expect(1, ret);
5162 nmhdr.hdr.hwndFrom = header;
5163 nmhdr.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
5164 nmhdr.iItem = 0;
5165 nmhdr.iButton = 0;
5166 nmhdr.pitem = &itemW;
5168 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5169 nmhdr.hdr.code = HDN_ITEMCHANGINGW;
5170 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5171 parent_header_notify_seq[0].id = HDN_ITEMCHANGINGA;
5172 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5173 "header notify, parent", TRUE);
5174 todo_wine
5175 ok(nmhdr.hdr.code == HDN_ITEMCHANGINGA, "Expected ANSI notification code\n");
5176 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5177 nmhdr.hdr.code = HDN_ITEMCHANGEDW;
5178 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5179 parent_header_notify_seq[0].id = HDN_ITEMCHANGEDA;
5180 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5181 "header notify, parent", TRUE);
5182 todo_wine
5183 ok(nmhdr.hdr.code == HDN_ITEMCHANGEDA, "Expected ANSI notification code\n");
5184 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5185 SetFocus(list);
5186 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5187 nmhdr.hdr.code = HDN_ITEMCLICKW;
5188 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5189 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_click_seq,
5190 "header notify, parent", FALSE);
5191 ok(nmhdr.hdr.code == HDN_ITEMCLICKA, "Expected ANSI notification code\n");
5192 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5193 nmhdr.hdr.code = HDN_ITEMDBLCLICKW;
5194 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5195 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5196 "header notify, parent", FALSE);
5197 ok(nmhdr.hdr.code == HDN_ITEMDBLCLICKW, "Expected Unicode notification code\n");
5198 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5199 nmhdr.hdr.code = HDN_DIVIDERDBLCLICKW;
5200 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5201 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_divider_dclick_seq,
5202 "header notify, parent", TRUE);
5203 ok(nmhdr.hdr.code == HDN_DIVIDERDBLCLICKA, "Expected ANSI notification code\n");
5204 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5205 nmhdr.hdr.code = HDN_BEGINTRACKW;
5206 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5207 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5208 "header notify, parent", FALSE);
5209 ok(nmhdr.hdr.code == HDN_BEGINTRACKW, "Expected Unicode notification code\n");
5210 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5211 nmhdr.hdr.code = HDN_ENDTRACKW;
5212 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5213 parent_header_notify_seq[0].id = HDN_ENDTRACKA;
5214 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5215 "header notify, parent", FALSE);
5216 ok(nmhdr.hdr.code == HDN_ENDTRACKA, "Expected ANSI notification code\n");
5217 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5218 nmhdr.hdr.code = HDN_TRACKW;
5219 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5220 parent_header_notify_seq[0].id = HDN_TRACKA;
5221 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5222 "header notify, parent", FALSE);
5223 ok(nmhdr.hdr.code == HDN_TRACKA, "Expected ANSI notification code\n");
5224 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5225 nmhdr.hdr.code = HDN_BEGINDRAG;
5226 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5227 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5228 "header notify, parent", FALSE);
5229 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5230 nmhdr.hdr.code = HDN_ENDDRAG;
5231 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5232 parent_header_notify_seq[0].id = HDN_ENDDRAG;
5233 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5234 "header notify, parent", FALSE);
5235 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5236 nmhdr.hdr.code = HDN_FILTERCHANGE;
5237 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5238 parent_header_notify_seq[0].id = HDN_FILTERCHANGE;
5239 parent_header_notify_seq[0].flags |= optional; /* NT4 does not send this message */
5240 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5241 "header notify, parent", FALSE);
5242 parent_header_notify_seq[0].flags &= ~optional;
5243 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5244 nmhdr.hdr.code = HDN_BEGINFILTEREDIT;
5245 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5246 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5247 "header notify, parent", FALSE);
5248 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5249 nmhdr.hdr.code = HDN_ENDFILTEREDIT;
5250 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5251 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5252 "header notify, parent", FALSE);
5253 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5254 nmhdr.hdr.code = HDN_ITEMSTATEICONCLICK;
5255 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5256 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5257 "header notify, parent", FALSE);
5258 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5259 nmhdr.hdr.code = HDN_ITEMKEYDOWN;
5260 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5261 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5262 "header notify, parent", FALSE);
5264 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5266 DestroyWindow(list);
5269 static void test_createdragimage(void)
5271 HIMAGELIST himl;
5272 POINT pt;
5273 HWND list;
5275 list = create_listview_control(LVS_ICON);
5276 ok(list != NULL, "failed to create listview window\n");
5278 insert_item(list, 0);
5280 /* NULL point */
5281 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
5282 ok(himl == NULL, "got %p\n", himl);
5284 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
5285 ok(himl != NULL, "got %p\n", himl);
5286 ImageList_Destroy(himl);
5288 DestroyWindow(list);
5291 static void test_dispinfo(void)
5293 static const char testA[] = "TEST";
5294 WCHAR buff[10];
5295 LVITEMA item;
5296 HWND hwnd;
5297 DWORD ret;
5299 hwnd = create_listview_control(LVS_ICON);
5300 ok(hwnd != NULL, "failed to create listview window\n");
5302 insert_item(hwnd, 0);
5304 memset(&item, 0, sizeof(item));
5305 item.pszText = LPSTR_TEXTCALLBACKA;
5306 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5307 expect(1, ret);
5309 g_disp_A_to_W = TRUE;
5310 item.pszText = (char*)buff;
5311 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
5312 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
5313 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
5314 g_disp_A_to_W = FALSE;
5316 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
5317 "got %s, expected %s\n", item.pszText, testA);
5319 DestroyWindow(hwnd);
5322 static void test_LVM_SETITEMTEXT(void)
5324 static char testA[] = "TEST";
5325 LVITEMA item;
5326 HWND hwnd;
5327 DWORD ret;
5329 hwnd = create_listview_control(LVS_ICON);
5330 ok(hwnd != NULL, "failed to create listview window\n");
5332 insert_item(hwnd, 0);
5334 /* null item pointer */
5335 ret = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, 0);
5336 expect(FALSE, ret);
5338 ret = SendMessage(hwnd, LVM_SETITEMTEXTW, 0, 0);
5339 expect(FALSE, ret);
5341 /* index out of bounds */
5342 item.pszText = testA;
5343 item.cchTextMax = 0; /* ignored */
5344 item.iSubItem = 0;
5346 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 1, (LPARAM)&item);
5347 expect(FALSE, ret);
5349 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, -1, (LPARAM)&item);
5350 expect(FALSE, ret);
5352 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5353 expect(TRUE, ret);
5355 DestroyWindow(hwnd);
5358 static void test_imagelists(void)
5360 HWND hwnd, header;
5361 HIMAGELIST himl1, himl2, himl3;
5362 LRESULT ret;
5364 himl1 = ImageList_Create(40, 40, 0, 4, 4);
5365 himl2 = ImageList_Create(40, 40, 0, 4, 4);
5366 himl3 = ImageList_Create(40, 40, 0, 4, 4);
5367 ok(himl1 != NULL, "Failed to create imagelist\n");
5368 ok(himl2 != NULL, "Failed to create imagelist\n");
5369 ok(himl3 != NULL, "Failed to create imagelist\n");
5371 hwnd = create_listview_control(LVS_REPORT | LVS_SHAREIMAGELISTS);
5372 header = subclass_header(hwnd);
5374 ok(header != NULL, "Expected header\n");
5375 ret = SendMessage(header, HDM_GETIMAGELIST, 0, 0);
5376 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5378 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5380 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5381 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5382 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5383 "set normal image list", FALSE);
5385 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5387 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5388 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5389 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5390 "set state image list", TRUE);
5392 ret = SendMessage(header, HDM_GETIMAGELIST, 0, 0);
5393 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5395 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5397 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5398 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5399 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_set_imagelist,
5400 "set small image list", FALSE);
5402 ret = SendMessage(header, HDM_GETIMAGELIST, 0, 0);
5403 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5404 DestroyWindow(hwnd);
5406 hwnd = create_listview_control(WS_VISIBLE | LVS_ICON);
5408 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5410 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5411 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5412 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5413 "set normal image list", FALSE);
5415 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5417 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5418 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5419 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5420 "set state image list", FALSE);
5422 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5424 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5425 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5426 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5427 "set small image list", FALSE);
5429 header = ListView_GetHeader(hwnd);
5430 ok(header == NULL, "Expected no header, got %p\n", header);
5432 SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | LVS_REPORT);
5434 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
5435 ok(header != NULL, "Expected header, got NULL\n");
5437 ret = SendMessage(header, HDM_GETIMAGELIST, 0, 0);
5438 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5440 DestroyWindow(hwnd);
5443 static void test_deleteitem(void)
5445 LVITEMA item;
5446 UINT state;
5447 HWND hwnd;
5448 BOOL ret;
5450 hwnd = create_listview_control(LVS_REPORT);
5452 insert_item(hwnd, 0);
5453 insert_item(hwnd, 0);
5454 insert_item(hwnd, 0);
5455 insert_item(hwnd, 0);
5456 insert_item(hwnd, 0);
5458 g_focus_test_LVN_DELETEITEM = TRUE;
5460 /* delete focused item (not the last index) */
5461 item.stateMask = LVIS_FOCUSED;
5462 item.state = LVIS_FOCUSED;
5463 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
5464 ok(ret == TRUE, "got %d\n", ret);
5465 ret = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
5466 ok(ret == TRUE, "got %d\n", ret);
5467 /* next item gets focus */
5468 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5469 ok(state == LVIS_FOCUSED, "got %x\n", state);
5471 /* focus last item and delete it */
5472 item.stateMask = LVIS_FOCUSED;
5473 item.state = LVIS_FOCUSED;
5474 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
5475 ok(ret == TRUE, "got %d\n", ret);
5476 ret = SendMessageA(hwnd, LVM_DELETEITEM, 3, 0);
5477 ok(ret == TRUE, "got %d\n", ret);
5478 /* new last item gets focus */
5479 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5480 ok(state == LVIS_FOCUSED, "got %x\n", state);
5482 /* focus first item and delete it */
5483 item.stateMask = LVIS_FOCUSED;
5484 item.state = LVIS_FOCUSED;
5485 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
5486 ok(ret == TRUE, "got %d\n", ret);
5487 ret = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
5488 ok(ret == TRUE, "got %d\n", ret);
5489 /* new first item gets focus */
5490 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5491 ok(state == LVIS_FOCUSED, "got %x\n", state);
5493 g_focus_test_LVN_DELETEITEM = FALSE;
5495 DestroyWindow(hwnd);
5498 static void test_insertitem(void)
5500 LVITEMA item;
5501 UINT state;
5502 HWND hwnd;
5503 INT ret;
5505 hwnd = create_listview_control(LVS_REPORT);
5507 /* insert item 0 focused */
5508 item.mask = LVIF_STATE;
5509 item.state = LVIS_FOCUSED;
5510 item.stateMask = LVIS_FOCUSED;
5511 item.iItem = 0;
5512 item.iSubItem = 0;
5513 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5514 ok(ret == 0, "got %d\n", ret);
5516 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5517 ok(state == LVIS_FOCUSED, "got %x\n", state);
5519 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5521 /* insert item 1, focus shift */
5522 item.mask = LVIF_STATE;
5523 item.state = LVIS_FOCUSED;
5524 item.stateMask = LVIS_FOCUSED;
5525 item.iItem = 1;
5526 item.iSubItem = 0;
5527 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5528 ok(ret == 1, "got %d\n", ret);
5530 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused_seq, "insert focused", TRUE);
5532 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5533 ok(state == LVIS_FOCUSED, "got %x\n", state);
5535 /* insert item 2, no focus shift */
5536 item.mask = LVIF_STATE;
5537 item.state = 0;
5538 item.stateMask = LVIS_FOCUSED;
5539 item.iItem = 2;
5540 item.iSubItem = 0;
5541 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5542 ok(ret == 2, "got %d\n", ret);
5544 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5545 ok(state == LVIS_FOCUSED, "got %x\n", state);
5547 DestroyWindow(hwnd);
5550 START_TEST(listview)
5552 HMODULE hComctl32;
5553 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
5555 ULONG_PTR ctx_cookie;
5556 HANDLE hCtx;
5557 HWND hwnd;
5559 hComctl32 = GetModuleHandleA("comctl32.dll");
5560 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
5561 if (pInitCommonControlsEx)
5563 INITCOMMONCONTROLSEX iccex;
5564 iccex.dwSize = sizeof(iccex);
5565 iccex.dwICC = ICC_LISTVIEW_CLASSES;
5566 pInitCommonControlsEx(&iccex);
5568 else
5569 InitCommonControls();
5571 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
5573 hwndparent = create_parent_window(FALSE);
5574 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5576 g_is_below_5 = is_below_comctl_5();
5578 test_header_notification();
5579 test_header_notification2();
5580 test_images();
5581 test_checkboxes();
5582 test_items();
5583 test_create();
5584 test_redraw();
5585 test_customdraw();
5586 test_icon_spacing();
5587 test_color();
5588 test_item_count();
5589 test_item_position();
5590 test_columns();
5591 test_getorigin();
5592 test_multiselect();
5593 test_getitemrect();
5594 test_subitem_rect();
5595 test_sorting();
5596 test_ownerdata();
5597 test_norecompute();
5598 test_nosortheader();
5599 test_setredraw();
5600 test_hittest();
5601 test_getviewrect();
5602 test_getitemposition();
5603 test_columnscreation();
5604 test_editbox();
5605 test_notifyformat();
5606 test_indentation();
5607 test_getitemspacing();
5608 test_getcolumnwidth();
5609 test_approximate_viewrect();
5610 test_finditem();
5611 test_hover();
5612 test_destroynotify();
5613 test_createdragimage();
5614 test_dispinfo();
5615 test_LVM_SETITEMTEXT();
5616 test_imagelists();
5617 test_deleteitem();
5618 test_insertitem();
5620 if (!load_v6_module(&ctx_cookie, &hCtx))
5622 DestroyWindow(hwndparent);
5623 return;
5626 /* this is a XP SP3 failure workaround */
5627 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
5628 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
5629 0, 0, 100, 100,
5630 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
5631 if (!IsWindow(hwnd))
5633 win_skip("FIXME: failed to create ListView window.\n");
5634 unload_v6_module(ctx_cookie, hCtx);
5635 DestroyWindow(hwndparent);
5636 return;
5638 else
5639 DestroyWindow(hwnd);
5641 /* comctl32 version 6 tests start here */
5642 test_get_set_view();
5643 test_canceleditlabel();
5644 test_mapidindex();
5645 test_scrollnotify();
5646 test_LVS_EX_TRANSPARENTBKGND();
5647 test_LVS_EX_HEADERINALLVIEWS();
5648 test_deleteitem();
5649 test_multiselect();
5650 test_insertitem();
5652 unload_v6_module(ctx_cookie, hCtx);
5654 DestroyWindow(hwndparent);