comctl32: Generate an alpha channel if necessary when adding images to a 32-bit image...
[wine] / dlls / comctl32 / tests / listview.c
1 /*
2  * ListView tests
3  *
4  * Copyright 2006 Mike McCormack for CodeWeavers
5  * Copyright 2007 George Gov
6  * Copyright 2009 Nikolay Sivov
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include <stdio.h>
24 #include <windows.h>
25 #include <commctrl.h>
26
27 #include "wine/test.h"
28 #include "v6util.h"
29 #include "msg.h"
30
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
37
38 #define LISTVIEW_ID 0
39 #define HEADER_ID   1
40
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)
44
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};
47
48 static HWND hwndparent, hwndparentW;
49 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
50 static BOOL blockEdit;
51 /* return nonzero on NM_HOVER */
52 static BOOL g_block_hover;
53 /* dumps LVN_ITEMCHANGED message data */
54 static BOOL g_dump_itemchanged;
55 /* format reported to control:
56    -1 falls to defproc, anything else returned */
57 static INT  notifyFormat;
58 /* indicates we're running < 5.80 version */
59 static BOOL g_is_below_5;
60 /* item data passed to LVN_GETDISPINFOA */
61 static LVITEMA g_itema;
62
63 static HWND subclass_editbox(HWND hwndListview);
64
65 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
66
67 static const struct message create_ownerdrawfixed_parent_seq[] = {
68     { WM_NOTIFYFORMAT, sent },
69     { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
70     { WM_MEASUREITEM, sent },
71     { WM_PARENTNOTIFY, sent },
72     { 0 }
73 };
74
75 static const struct message redraw_listview_seq[] = {
76     { WM_PAINT,      sent|id,            0, 0, LISTVIEW_ID },
77     { WM_PAINT,      sent|id,            0, 0, HEADER_ID },
78     { WM_NCPAINT,    sent|id|defwinproc, 0, 0, HEADER_ID },
79     { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
80     { WM_NOTIFY,     sent|id|defwinproc, 0, 0, LISTVIEW_ID },
81     { WM_NCPAINT,    sent|id|defwinproc, 0, 0, LISTVIEW_ID },
82     { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
83     { 0 }
84 };
85
86 static const struct message listview_icon_spacing_seq[] = {
87     { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
88     { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
89     { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
90     { 0 }
91 };
92
93 static const struct message listview_color_seq[] = {
94     { LVM_SETBKCOLOR,     sent|lparam, 0, RGB(0,0,0) },
95     { LVM_GETBKCOLOR,     sent },
96     { LVM_SETTEXTCOLOR,   sent|lparam, 0, RGB(0,0,0) },
97     { LVM_GETTEXTCOLOR,   sent },
98     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
99     { LVM_GETTEXTBKCOLOR, sent },
100
101     { LVM_SETBKCOLOR,     sent|lparam, 0, RGB(100,50,200) },
102     { LVM_GETBKCOLOR,     sent },
103     { LVM_SETTEXTCOLOR,   sent|lparam, 0, RGB(100,50,200) },
104     { LVM_GETTEXTCOLOR,   sent },
105     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
106     { LVM_GETTEXTBKCOLOR, sent },
107
108     { LVM_SETBKCOLOR,     sent|lparam, 0, CLR_NONE },
109     { LVM_GETBKCOLOR,     sent },
110     { LVM_SETTEXTCOLOR,   sent|lparam, 0, CLR_NONE },
111     { LVM_GETTEXTCOLOR,   sent },
112     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
113     { LVM_GETTEXTBKCOLOR, sent },
114
115     { LVM_SETBKCOLOR,     sent|lparam, 0, RGB(255,255,255) },
116     { LVM_GETBKCOLOR,     sent },
117     { LVM_SETTEXTCOLOR,   sent|lparam, 0, RGB(255,255,255) },
118     { LVM_GETTEXTCOLOR,   sent },
119     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
120     { LVM_GETTEXTBKCOLOR, sent },
121     { 0 }
122 };
123
124 static const struct message listview_item_count_seq[] = {
125     { LVM_GETITEMCOUNT,   sent },
126     { LVM_INSERTITEM,     sent },
127     { LVM_INSERTITEM,     sent },
128     { LVM_INSERTITEM,     sent },
129     { LVM_GETITEMCOUNT,   sent },
130     { LVM_DELETEITEM,     sent|wparam, 2 },
131     { WM_NCPAINT,         sent|optional },
132     { WM_ERASEBKGND,      sent|optional },
133     { LVM_GETITEMCOUNT,   sent },
134     { LVM_DELETEALLITEMS, sent },
135     { LVM_GETITEMCOUNT,   sent },
136     { LVM_INSERTITEM,     sent },
137     { LVM_INSERTITEM,     sent },
138     { LVM_GETITEMCOUNT,   sent },
139     { LVM_INSERTITEM,     sent },
140     { LVM_GETITEMCOUNT,   sent },
141     { 0 }
142 };
143
144 static const struct message listview_itempos_seq[] = {
145     { LVM_INSERTITEM,      sent },
146     { LVM_INSERTITEM,      sent },
147     { LVM_INSERTITEM,      sent },
148     { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
149     { WM_NCPAINT,          sent|optional },
150     { WM_ERASEBKGND,       sent|optional },
151     { LVM_GETITEMPOSITION, sent|wparam,        1 },
152     { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
153     { LVM_GETITEMPOSITION, sent|wparam,        2 },
154     { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
155     { LVM_GETITEMPOSITION, sent|wparam,        0 },
156     { 0 }
157 };
158
159 static const struct message listview_ownerdata_switchto_seq[] = {
160     { WM_STYLECHANGING,    sent },
161     { WM_STYLECHANGED,     sent },
162     { 0 }
163 };
164
165 static const struct message listview_getorderarray_seq[] = {
166     { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
167     { HDM_GETORDERARRAY,       sent|id|wparam, 2, 0, HEADER_ID },
168     { 0 }
169 };
170
171 static const struct message empty_seq[] = {
172     { 0 }
173 };
174
175 static const struct message forward_erasebkgnd_parent_seq[] = {
176     { WM_ERASEBKGND, sent },
177     { 0 }
178 };
179
180 static const struct message ownderdata_select_focus_parent_seq[] = {
181     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
182     { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
183     { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
184     { 0 }
185 };
186
187 static const struct message ownerdata_setstate_all_parent_seq[] = {
188     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
189     { 0 }
190 };
191
192 static const struct message ownerdata_defocus_all_parent_seq[] = {
193     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
194     { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
195     { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
196     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
197     { 0 }
198 };
199
200 static const struct message ownerdata_deselect_all_parent_seq[] = {
201     { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
202     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
203     { 0 }
204 };
205
206 static const struct message select_all_parent_seq[] = {
207     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
208     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
209
210     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
211     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
212
213     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
214     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
215
216     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
217     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
218
219     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
220     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
221     { 0 }
222 };
223
224 static const struct message textcallback_set_again_parent_seq[] = {
225     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
226     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED  },
227     { 0 }
228 };
229
230 static const struct message single_getdispinfo_parent_seq[] = {
231     { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
232     { 0 }
233 };
234
235 static const struct message getitemposition_seq1[] = {
236     { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
237     { 0 }
238 };
239
240 static const struct message getitemposition_seq2[] = {
241     { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
242     { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
243     { 0 }
244 };
245
246 static const struct message editbox_create_pos[] = {
247     /* sequence sent after LVN_BEGINLABELEDIT */
248     /* next two are 4.7x specific */
249     { WM_WINDOWPOSCHANGING, sent },
250     { WM_WINDOWPOSCHANGED, sent|optional },
251
252     { WM_WINDOWPOSCHANGING, sent|optional },
253     { WM_NCCALCSIZE, sent },
254     { WM_WINDOWPOSCHANGED, sent },
255     { WM_MOVE, sent|defwinproc },
256     { WM_SIZE, sent|defwinproc },
257     /* the rest is todo, skipped in 4.7x */
258     { WM_WINDOWPOSCHANGING, sent|optional },
259     { WM_WINDOWPOSCHANGED, sent|optional },
260     { 0 }
261 };
262
263 static const struct message scroll_parent_seq[] = {
264     { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
265     { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
266     { 0 }
267 };
268
269 static const struct message setredraw_seq[] = {
270     { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
271     { 0 }
272 };
273
274 static const struct message lvs_ex_transparentbkgnd_seq[] = {
275     { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
276     { 0 }
277 };
278
279 static const struct message edit_end_nochange[] = {
280     { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
281     { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },     /* todo */
282     { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
283     { 0 }
284 };
285
286 static const struct message hover_parent[] = {
287     { WM_GETDLGCODE, sent }, /* todo_wine */
288     { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
289     { 0 }
290 };
291
292 static const struct message listview_destroy[] = {
293     { 0x0090, sent|optional }, /* Vista */
294     { WM_PARENTNOTIFY, sent },
295     { WM_SHOWWINDOW, sent },
296     { WM_WINDOWPOSCHANGING, sent },
297     { WM_WINDOWPOSCHANGED, sent|optional },
298     { WM_DESTROY, sent },
299     { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
300     { WM_NCDESTROY, sent },
301     { 0 }
302 };
303
304 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
305 {
306     static LONG defwndproc_counter = 0;
307     LRESULT ret;
308     struct message msg;
309
310     msg.message = message;
311     msg.flags = sent|wparam|lparam;
312     if (defwndproc_counter) msg.flags |= defwinproc;
313     msg.wParam = wParam;
314     msg.lParam = lParam;
315     if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
316
317     /* log system messages, except for painting */
318     if (message < WM_USER &&
319         message != WM_PAINT &&
320         message != WM_ERASEBKGND &&
321         message != WM_NCPAINT &&
322         message != WM_NCHITTEST &&
323         message != WM_GETTEXT &&
324         message != WM_GETICON &&
325         message != WM_DEVICECHANGE)
326     {
327         trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
328
329         add_message(sequences, PARENT_SEQ_INDEX, &msg);
330         add_message(sequences, COMBINED_SEQ_INDEX, &msg);
331     }
332     add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
333
334     switch (message)
335     {
336       case WM_NOTIFY:
337       {
338           switch (((NMHDR*)lParam)->code)
339           {
340           case LVN_BEGINLABELEDIT:
341               /* subclass edit box */
342               if (!blockEdit)
343                   subclass_editbox(((NMHDR*)lParam)->hwndFrom);
344
345               return blockEdit;
346
347           case LVN_ENDLABELEDIT:
348               {
349               /* always accept new item text */
350               NMLVDISPINFO *di = (NMLVDISPINFO*)lParam;
351               trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText);
352               return TRUE;
353               }
354           case LVN_BEGINSCROLL:
355           case LVN_ENDSCROLL:
356               {
357               NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
358
359               trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
360                                                "BEGIN" : "END", pScroll->dx, pScroll->dy);
361               }
362               break;
363           case LVN_ITEMCHANGED:
364               if (g_dump_itemchanged)
365               {
366                   NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
367                   trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
368                          nmlv->iItem, nmlv->uNewState, nmlv->uOldState, nmlv->uChanged);
369               }
370               break;
371           case LVN_GETDISPINFOA:
372               {
373                   NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
374                   g_itema = dispinfo->item;
375               }
376               break;
377           case NM_HOVER:
378               if (g_block_hover) return 1;
379               break;
380           }
381           break;
382       }
383       case WM_NOTIFYFORMAT:
384       {
385           /* force to return format */
386           if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
387           break;
388       }
389     }
390
391     defwndproc_counter++;
392     ret = DefWindowProcA(hwnd, message, wParam, lParam);
393     defwndproc_counter--;
394
395     return ret;
396 }
397
398 static BOOL register_parent_wnd_class(BOOL Unicode)
399 {
400     WNDCLASSA clsA;
401     WNDCLASSW clsW;
402
403     if (Unicode)
404     {
405         clsW.style = 0;
406         clsW.lpfnWndProc = parent_wnd_proc;
407         clsW.cbClsExtra = 0;
408         clsW.cbWndExtra = 0;
409         clsW.hInstance = GetModuleHandleW(NULL);
410         clsW.hIcon = 0;
411         clsW.hCursor = LoadCursorA(0, IDC_ARROW);
412         clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
413         clsW.lpszMenuName = NULL;
414         clsW.lpszClassName = testparentclassW;
415     }
416     else
417     {
418         clsA.style = 0;
419         clsA.lpfnWndProc = parent_wnd_proc;
420         clsA.cbClsExtra = 0;
421         clsA.cbWndExtra = 0;
422         clsA.hInstance = GetModuleHandleA(NULL);
423         clsA.hIcon = 0;
424         clsA.hCursor = LoadCursorA(0, IDC_ARROW);
425         clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
426         clsA.lpszMenuName = NULL;
427         clsA.lpszClassName = "Listview test parent class";
428     }
429
430     return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
431 }
432
433 static HWND create_parent_window(BOOL Unicode)
434 {
435     static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
436     HWND hwnd;
437
438     if (!register_parent_wnd_class(Unicode))
439         return NULL;
440
441     blockEdit = FALSE;
442     notifyFormat = -1;
443
444     if (Unicode)
445         hwnd = CreateWindowExW(0, testparentclassW, nameW,
446                                WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
447                                WS_MAXIMIZEBOX | WS_VISIBLE,
448                                0, 0, 100, 100,
449                                GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
450     else
451         hwnd = CreateWindowExA(0, "Listview test parent class",
452                                "Listview test parent window",
453                                WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
454                                WS_MAXIMIZEBOX | WS_VISIBLE,
455                                0, 0, 100, 100,
456                                GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
457     SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
458     return hwnd;
459 }
460
461 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
462 {
463     WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
464     static LONG defwndproc_counter = 0;
465     LRESULT ret;
466     struct message msg;
467
468     trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
469
470     /* some debug output for style changing */
471     if ((message == WM_STYLECHANGING ||
472          message == WM_STYLECHANGED) && lParam)
473     {
474         STYLESTRUCT *style = (STYLESTRUCT*)lParam;
475         trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
476     }
477
478     msg.message = message;
479     msg.flags = sent|wparam|lparam;
480     if (defwndproc_counter) msg.flags |= defwinproc;
481     msg.wParam = wParam;
482     msg.lParam = lParam;
483     msg.id = LISTVIEW_ID;
484     add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
485     add_message(sequences, COMBINED_SEQ_INDEX, &msg);
486
487     defwndproc_counter++;
488     ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
489     defwndproc_counter--;
490     return ret;
491 }
492
493 static HWND create_listview_control(DWORD style)
494 {
495     WNDPROC oldproc;
496     HWND hwnd;
497     RECT rect;
498
499     GetClientRect(hwndparent, &rect);
500     hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
501                            WS_CHILD | WS_BORDER | WS_VISIBLE | style,
502                            0, 0, rect.right, rect.bottom,
503                            hwndparent, NULL, GetModuleHandleA(NULL), NULL);
504     ok(hwnd != NULL, "gle=%d\n", GetLastError());
505
506     if (!hwnd) return NULL;
507
508     oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
509                                         (LONG_PTR)listview_subclass_proc);
510     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
511
512     return hwnd;
513 }
514
515 /* unicode listview window with specified parent */
516 static HWND create_listview_controlW(DWORD style, HWND parent)
517 {
518     WNDPROC oldproc;
519     HWND hwnd;
520     RECT rect;
521     static const WCHAR nameW[] = {'f','o','o',0};
522
523     GetClientRect(parent, &rect);
524     hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
525                            WS_CHILD | WS_BORDER | WS_VISIBLE | style,
526                            0, 0, rect.right, rect.bottom,
527                            parent, NULL, GetModuleHandleW(NULL), NULL);
528     ok(hwnd != NULL, "gle=%d\n", GetLastError());
529
530     if (!hwnd) return NULL;
531
532     oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
533                                         (LONG_PTR)listview_subclass_proc);
534     SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
535
536     return hwnd;
537 }
538
539 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
540 {
541     WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
542     static LONG defwndproc_counter = 0;
543     LRESULT ret;
544     struct message msg;
545
546     trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
547
548     msg.message = message;
549     msg.flags = sent|wparam|lparam;
550     if (defwndproc_counter) msg.flags |= defwinproc;
551     msg.wParam = wParam;
552     msg.lParam = lParam;
553     msg.id = HEADER_ID;
554     add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
555
556     defwndproc_counter++;
557     ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
558     defwndproc_counter--;
559     return ret;
560 }
561
562 static HWND subclass_header(HWND hwndListview)
563 {
564     WNDPROC oldproc;
565     HWND hwnd;
566
567     hwnd = ListView_GetHeader(hwndListview);
568     oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
569                                          (LONG_PTR)header_subclass_proc);
570     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
571
572     return hwnd;
573 }
574
575 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
576 {
577     WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
578     static LONG defwndproc_counter = 0;
579     LRESULT ret;
580     struct message msg;
581
582     msg.message = message;
583     msg.flags = sent|wparam|lparam;
584     if (defwndproc_counter) msg.flags |= defwinproc;
585     msg.wParam = wParam;
586     msg.lParam = lParam;
587
588     /* all we need is sizing */
589     if (message == WM_WINDOWPOSCHANGING ||
590         message == WM_NCCALCSIZE ||
591         message == WM_WINDOWPOSCHANGED ||
592         message == WM_MOVE ||
593         message == WM_SIZE)
594     {
595         add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
596     }
597
598     defwndproc_counter++;
599     ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
600     defwndproc_counter--;
601     return ret;
602 }
603
604 static HWND subclass_editbox(HWND hwndListview)
605 {
606     WNDPROC oldproc;
607     HWND hwnd;
608
609     hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
610     oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
611                                          (LONG_PTR)editbox_subclass_proc);
612     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
613
614     return hwnd;
615 }
616
617 /* Performs a single LVM_HITTEST test */
618 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
619                               BOOL todo_item, BOOL todo_flags, int line)
620 {
621     LVHITTESTINFO lpht;
622     DWORD ret;
623
624     lpht.pt.x = x;
625     lpht.pt.y = y;
626     lpht.iSubItem = 10;
627
628     trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
629     ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
630
631     if (todo_item)
632     {
633         todo_wine
634         {
635             ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
636             ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
637             ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
638         }
639     }
640     else
641     {
642         ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
643         ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
644         ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
645     }
646
647     if (todo_flags)
648     {
649         todo_wine
650             ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
651     }
652     else if (broken_flags)
653         ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
654                             "Expected flags %x, got %x\n", flags, lpht.flags);
655     else
656         ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
657 }
658
659 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
660
661 /* Performs a single LVM_SUBITEMHITTEST test */
662 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
663                                      BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
664 {
665     LVHITTESTINFO lpht;
666     DWORD ret;
667
668     lpht.pt.x = x;
669     lpht.pt.y = y;
670
671     trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
672     ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
673
674     if (todo_item)
675     {
676         todo_wine
677         {
678             ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
679             ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
680         }
681     }
682     else
683     {
684         ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
685         ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
686     }
687
688     if (todo_subitem)
689     {
690         todo_wine
691             ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
692     }
693     else
694         ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
695
696     if (todo_flags)
697     {
698         todo_wine
699             ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
700     }
701     else
702         ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
703 }
704
705 #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__)
706
707 static void test_images(void)
708 {
709     HWND hwnd;
710     DWORD r;
711     LVITEM item;
712     HIMAGELIST himl;
713     HBITMAP hbmp;
714     RECT r1, r2;
715     static CHAR hello[] = "hello";
716
717     himl = ImageList_Create(40, 40, 0, 4, 4);
718     ok(himl != NULL, "failed to create imagelist\n");
719
720     hbmp = CreateBitmap(40, 40, 1, 1, NULL);
721     ok(hbmp != NULL, "failed to create bitmap\n");
722
723     r = ImageList_Add(himl, hbmp, 0);
724     ok(r == 0, "should be zero\n");
725
726     hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED, 
727                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
728     ok(hwnd != NULL, "failed to create listview window\n");
729
730     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
731                     LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
732
733     ok(r == 0, "should return zero\n");
734
735     r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
736     ok(r == 0, "should return zero\n");
737
738     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
739     /* returns dimensions */
740
741     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
742     ok(r == 0, "should be zero items\n");
743
744     item.mask = LVIF_IMAGE | LVIF_TEXT;
745     item.iItem = 0;
746     item.iSubItem = 1;
747     item.iImage = 0;
748     item.pszText = 0;
749     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
750     ok(r == -1, "should fail\n");
751
752     item.iSubItem = 0;
753     item.pszText = hello;
754     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
755     ok(r == 0, "should not fail\n");
756
757     memset(&r1, 0, sizeof r1);
758     r1.left = LVIR_ICON;
759     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
760
761     r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
762     ok(r == TRUE, "should not fail\n");
763
764     item.iSubItem = 0;
765     item.pszText = hello;
766     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
767     ok(r == 0, "should not fail\n");
768
769     memset(&r2, 0, sizeof r2);
770     r2.left = LVIR_ICON;
771     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
772
773     ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
774
775     DestroyWindow(hwnd);
776 }
777
778 static void test_checkboxes(void)
779 {
780     HWND hwnd;
781     LVITEMA item;
782     DWORD r;
783     static CHAR text[]  = "Text",
784                 text2[] = "Text2",
785                 text3[] = "Text3";
786
787     hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT, 
788                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
789     ok(hwnd != NULL, "failed to create listview window\n");
790
791     /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
792     item.mask = LVIF_TEXT | LVIF_STATE;
793     item.stateMask = 0xffff;
794     item.state = 0xfccc;
795     item.iItem = 0;
796     item.iSubItem = 0;
797     item.pszText = text;
798     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
799     ok(r == 0, "ret %d\n", r);
800
801     item.iItem = 0;
802     item.mask = LVIF_STATE;
803     item.stateMask = 0xffff;
804     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
805     ok(item.state == 0xfccc, "state %x\n", item.state);
806
807     /* Don't set LVIF_STATE */
808     item.mask = LVIF_TEXT;
809     item.stateMask = 0xffff;
810     item.state = 0xfccc;
811     item.iItem = 1;
812     item.iSubItem = 0;
813     item.pszText = text;
814     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
815     ok(r == 1, "ret %d\n", r);
816
817     item.iItem = 1;
818     item.mask = LVIF_STATE;
819     item.stateMask = 0xffff;
820     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
821     ok(item.state == 0, "state %x\n", item.state);
822
823     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
824     ok(r == 0, "should return zero\n");
825
826     /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
827     item.iItem = 0;
828     item.mask = LVIF_STATE;
829     item.stateMask = 0xffff;
830     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
831     if (item.state != 0x1ccc)
832     {
833         win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
834         DestroyWindow(hwnd);
835         return;
836     }
837
838     /* Now add an item without specifying a state and check that its state goes to 0x1000 */
839     item.iItem = 2;
840     item.mask = LVIF_TEXT;
841     item.state = 0;
842     item.pszText = text2;
843     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
844     ok(r == 2, "ret %d\n", r);
845
846     item.iItem = 2;
847     item.mask = LVIF_STATE;
848     item.stateMask = 0xffff;
849     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
850     ok(item.state == 0x1000, "state %x\n", item.state);
851
852     /* Add a further item this time specifying a state and still its state goes to 0x1000 */
853     item.iItem = 3;
854     item.mask = LVIF_TEXT | LVIF_STATE;
855     item.stateMask = 0xffff;
856     item.state = 0x2aaa;
857     item.pszText = text3;
858     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
859     ok(r == 3, "ret %d\n", r);
860
861     item.iItem = 3;
862     item.mask = LVIF_STATE;
863     item.stateMask = 0xffff;
864     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
865     ok(item.state == 0x1aaa, "state %x\n", item.state);
866
867     /* Set an item's state to checked */
868     item.iItem = 3;
869     item.mask = LVIF_STATE;
870     item.stateMask = 0xf000;
871     item.state = 0x2000;
872     r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
873
874     item.iItem = 3;
875     item.mask = LVIF_STATE;
876     item.stateMask = 0xffff;
877     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
878     ok(item.state == 0x2aaa, "state %x\n", item.state);
879
880     /* Check that only the bits we asked for are returned,
881      * and that all the others are set to zero
882      */
883     item.iItem = 3;
884     item.mask = LVIF_STATE;
885     item.stateMask = 0xf000;
886     item.state = 0xffff;
887     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
888     ok(item.state == 0x2000, "state %x\n", item.state);
889
890     /* Set the style again and check that doesn't change an item's state */
891     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
892     ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
893
894     item.iItem = 3;
895     item.mask = LVIF_STATE;
896     item.stateMask = 0xffff;
897     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
898     ok(item.state == 0x2aaa, "state %x\n", item.state);
899
900     /* Unsetting the checkbox extended style doesn't change an item's state */
901     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
902     ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
903
904     item.iItem = 3;
905     item.mask = LVIF_STATE;
906     item.stateMask = 0xffff;
907     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
908     ok(item.state == 0x2aaa, "state %x\n", item.state);
909
910     /* Now setting the style again will change an item's state */
911     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
912     ok(r == 0, "ret %x\n", r);
913
914     item.iItem = 3;
915     item.mask = LVIF_STATE;
916     item.stateMask = 0xffff;
917     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
918     ok(item.state == 0x1aaa, "state %x\n", item.state);
919
920     /* Toggle checkbox tests (bug 9934) */
921     memset (&item, 0xcc, sizeof(item));
922     item.mask = LVIF_STATE;
923     item.iItem = 3;
924     item.iSubItem = 0;
925     item.state = LVIS_FOCUSED;
926     item.stateMask = LVIS_FOCUSED;
927     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
928     expect(1, r);
929
930     item.iItem = 3;
931     item.mask = LVIF_STATE;
932     item.stateMask = 0xffff;
933     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
934     ok(item.state == 0x1aab, "state %x\n", item.state);
935
936     r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
937     expect(0, r);
938     r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
939     expect(0, r);
940
941     item.iItem = 3;
942     item.mask = LVIF_STATE;
943     item.stateMask = 0xffff;
944     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
945     ok(item.state == 0x2aab, "state %x\n", item.state);
946
947     r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
948     expect(0, r);
949     r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
950     expect(0, r);
951
952     item.iItem = 3;
953     item.mask = LVIF_STATE;
954     item.stateMask = 0xffff;
955     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
956     ok(item.state == 0x1aab, "state %x\n", item.state);
957
958     DestroyWindow(hwnd);
959 }
960
961 static void insert_column(HWND hwnd, int idx)
962 {
963     LVCOLUMN column;
964     DWORD rc;
965
966     memset(&column, 0xcc, sizeof(column));
967     column.mask = LVCF_SUBITEM;
968     column.iSubItem = idx;
969
970     rc = ListView_InsertColumn(hwnd, idx, &column);
971     expect(idx, rc);
972 }
973
974 static void insert_item(HWND hwnd, int idx)
975 {
976     static CHAR text[] = "foo";
977
978     LVITEMA item;
979     DWORD rc;
980
981     memset(&item, 0xcc, sizeof (item));
982     item.mask = LVIF_TEXT;
983     item.iItem = idx;
984     item.iSubItem = 0;
985     item.pszText = text;
986
987     rc = ListView_InsertItem(hwnd, &item);
988     expect(idx, rc);
989 }
990
991 static void test_items(void)
992 {
993     const LPARAM lparamTest = 0x42;
994     HWND hwnd;
995     LVITEMA item;
996     DWORD r;
997     static CHAR text[] = "Text";
998
999     hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1000                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1001     ok(hwnd != NULL, "failed to create listview window\n");
1002
1003     /*
1004      * Test setting/getting item params
1005      */
1006
1007     /* Set up two columns */
1008     insert_column(hwnd, 0);
1009     insert_column(hwnd, 1);
1010
1011     /* LVIS_SELECTED with zero stateMask */
1012     /* set */
1013     memset (&item, 0, sizeof (item));
1014     item.mask = LVIF_STATE;
1015     item.state = LVIS_SELECTED;
1016     item.stateMask = 0;
1017     item.iItem = 0;
1018     item.iSubItem = 0;
1019     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1020     ok(r == 0, "ret %d\n", r);
1021     /* get */
1022     memset (&item, 0xcc, sizeof (item));
1023     item.mask = LVIF_STATE;
1024     item.stateMask = LVIS_SELECTED;
1025     item.state = 0;
1026     item.iItem = 0;
1027     item.iSubItem = 0;
1028     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1029     ok(r != 0, "ret %d\n", r);
1030     ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1031     SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1032
1033     /* LVIS_SELECTED with zero stateMask */
1034     /* set */
1035     memset (&item, 0, sizeof (item));
1036     item.mask = LVIF_STATE;
1037     item.state = LVIS_FOCUSED;
1038     item.stateMask = 0;
1039     item.iItem = 0;
1040     item.iSubItem = 0;
1041     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1042     ok(r == 0, "ret %d\n", r);
1043     /* get */
1044     memset (&item, 0xcc, sizeof (item));
1045     item.mask = LVIF_STATE;
1046     item.stateMask = LVIS_FOCUSED;
1047     item.state = 0;
1048     item.iItem = 0;
1049     item.iSubItem = 0;
1050     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1051     ok(r != 0, "ret %d\n", r);
1052     ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1053     SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1054
1055     /* LVIS_CUT with LVIS_FOCUSED stateMask */
1056     /* set */
1057     memset (&item, 0, sizeof (item));
1058     item.mask = LVIF_STATE;
1059     item.state = LVIS_CUT;
1060     item.stateMask = LVIS_FOCUSED;
1061     item.iItem = 0;
1062     item.iSubItem = 0;
1063     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1064     ok(r == 0, "ret %d\n", r);
1065     /* get */
1066     memset (&item, 0xcc, sizeof (item));
1067     item.mask = LVIF_STATE;
1068     item.stateMask = LVIS_CUT;
1069     item.state = 0;
1070     item.iItem = 0;
1071     item.iSubItem = 0;
1072     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1073     ok(r != 0, "ret %d\n", r);
1074     ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1075     SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1076
1077     /* Insert an item with just a param */
1078     memset (&item, 0xcc, sizeof (item));
1079     item.mask = LVIF_PARAM;
1080     item.iItem = 0;
1081     item.iSubItem = 0;
1082     item.lParam = lparamTest;
1083     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1084     ok(r == 0, "ret %d\n", r);
1085
1086     /* Test getting of the param */
1087     memset (&item, 0xcc, sizeof (item));
1088     item.mask = LVIF_PARAM;
1089     item.iItem = 0;
1090     item.iSubItem = 0;
1091     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1092     ok(r != 0, "ret %d\n", r);
1093     ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1094
1095     /* Set up a subitem */
1096     memset (&item, 0xcc, sizeof (item));
1097     item.mask = LVIF_TEXT;
1098     item.iItem = 0;
1099     item.iSubItem = 1;
1100     item.pszText = text;
1101     r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1102     ok(r != 0, "ret %d\n", r);
1103
1104     /* Query param from subitem: returns main item param */
1105     memset (&item, 0xcc, sizeof (item));
1106     item.mask = LVIF_PARAM;
1107     item.iItem = 0;
1108     item.iSubItem = 1;
1109     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1110     ok(r != 0, "ret %d\n", r);
1111     ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1112
1113     /* Set up param on first subitem: no effect */
1114     memset (&item, 0xcc, sizeof (item));
1115     item.mask = LVIF_PARAM;
1116     item.iItem = 0;
1117     item.iSubItem = 1;
1118     item.lParam = lparamTest+1;
1119     r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1120     ok(r == 0, "ret %d\n", r);
1121
1122     /* Query param from subitem again: should still return main item param */
1123     memset (&item, 0xcc, sizeof (item));
1124     item.mask = LVIF_PARAM;
1125     item.iItem = 0;
1126     item.iSubItem = 1;
1127     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1128     ok(r != 0, "ret %d\n", r);
1129     ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1130
1131     /**** Some tests of state highlighting ****/
1132     memset (&item, 0xcc, sizeof (item));
1133     item.mask = LVIF_STATE;
1134     item.iItem = 0;
1135     item.iSubItem = 0;
1136     item.state = LVIS_SELECTED;
1137     item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1138     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1139     ok(r != 0, "ret %d\n", r);
1140     item.iSubItem = 1;
1141     item.state = LVIS_DROPHILITED;
1142     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1143     ok(r != 0, "ret %d\n", r);
1144
1145     memset (&item, 0xcc, sizeof (item));
1146     item.mask = LVIF_STATE;
1147     item.iItem = 0;
1148     item.iSubItem = 0;
1149     item.stateMask = -1;
1150     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1151     ok(r != 0, "ret %d\n", r);
1152     ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1153     item.iSubItem = 1;
1154     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1155     ok(r != 0, "ret %d\n", r);
1156     todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1157
1158     /* some notnull but meaningless masks */
1159     memset (&item, 0, sizeof(item));
1160     item.mask = LVIF_NORECOMPUTE;
1161     item.iItem = 0;
1162     item.iSubItem = 0;
1163     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1164     ok(r != 0, "ret %d\n", r);
1165     memset (&item, 0, sizeof(item));
1166     item.mask = LVIF_DI_SETITEM;
1167     item.iItem = 0;
1168     item.iSubItem = 0;
1169     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1170     ok(r != 0, "ret %d\n", r);
1171
1172     /* set text to callback value already having it */
1173     r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1174     expect(TRUE, r);
1175     memset (&item, 0, sizeof (item));
1176     item.mask  = LVIF_TEXT;
1177     item.pszText = LPSTR_TEXTCALLBACK;
1178     item.iItem = 0;
1179     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1180     ok(r == 0, "ret %d\n", r);
1181     memset (&item, 0, sizeof (item));
1182
1183     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1184
1185     item.pszText = LPSTR_TEXTCALLBACK;
1186     r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1187     expect(TRUE, r);
1188
1189     ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1190                 "check callback text comparison rule", FALSE);
1191
1192     DestroyWindow(hwnd);
1193 }
1194
1195 static void test_columns(void)
1196 {
1197     HWND hwnd;
1198     LVCOLUMNA column;
1199     LVITEMA item;
1200     INT order[2];
1201     CHAR buff[5];
1202     DWORD rc;
1203
1204     hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1205                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1206     ok(hwnd != NULL, "failed to create listview window\n");
1207
1208     /* Add a column with no mask */
1209     memset(&column, 0xcc, sizeof(column));
1210     column.mask = 0;
1211     rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1212     ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1213
1214     /* Check its width */
1215     rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1216     ok(rc == 10 || broken(rc == 0) /* win9x */,
1217        "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1218
1219     DestroyWindow(hwnd);
1220
1221     /* LVM_GETCOLUMNORDERARRAY */
1222     hwnd = create_listview_control(LVS_REPORT);
1223     subclass_header(hwnd);
1224
1225     memset(&column, 0, sizeof(column));
1226     column.mask = LVCF_WIDTH;
1227     column.cx = 100;
1228     rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1229     ok(rc == 0, "Inserting column failed with %d\n", rc);
1230
1231     column.cx = 200;
1232     rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1233     ok(rc == 1, "Inserting column failed with %d\n", rc);
1234
1235     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1236
1237     rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1238     ok(rc == 1, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1239     ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1240     ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1241
1242     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1243
1244     /* after column added subitem is considered as present */
1245     insert_item(hwnd, 0);
1246
1247     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1248
1249     item.pszText = buff;
1250     item.cchTextMax = sizeof(buff);
1251     item.iItem = 0;
1252     item.iSubItem = 1;
1253     item.mask = LVIF_TEXT;
1254     memset(&g_itema, 0, sizeof(g_itema));
1255     rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1256     ok(rc == 1, "got %d\n", rc);
1257     ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1258
1259     ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1260         "get subitem text after column added", FALSE);
1261
1262     DestroyWindow(hwnd);
1263 }
1264
1265 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1266 static WNDPROC listviewWndProc;
1267 static HIMAGELIST test_create_imagelist;
1268
1269 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1270 {
1271     LRESULT ret;
1272
1273     if (uMsg == WM_CREATE)
1274     {
1275         LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1276         lpcs->style |= LVS_REPORT;
1277     }
1278     ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1279     if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1280     return ret;
1281 }
1282
1283 static void test_create(void)
1284 {
1285     HWND hList;
1286     HWND hHeader;
1287     LONG_PTR ret;
1288     LONG r;
1289     LVCOLUMNA col;
1290     RECT rect;
1291     WNDCLASSEX cls;
1292     DWORD style;
1293
1294     cls.cbSize = sizeof(WNDCLASSEX);
1295     ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1296     listviewWndProc = cls.lpfnWndProc;
1297     cls.lpfnWndProc = create_test_wndproc;
1298     cls.lpszClassName = "MyListView32";
1299     ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1300
1301     test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1302     hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1303     ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1304     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1305
1306     if (!IsWindow(hHeader))
1307     {
1308         /* version 4.0 */
1309         win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1310         DestroyWindow(hList);
1311         return;
1312     }
1313
1314     ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1315     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1316     DestroyWindow(hList);
1317
1318     /* header isn't created on LVS_ICON and LVS_LIST styles */
1319     hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1320                           GetModuleHandle(NULL), 0);
1321     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1322     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1323     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1324     /* insert column */
1325     memset(&col, 0, sizeof(LVCOLUMNA));
1326     col.mask = LVCF_WIDTH;
1327     col.cx = 100;
1328     r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1329     ok(r == 0, "Expected 0 column's inserted\n");
1330     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1331     ok(IsWindow(hHeader), "Header should be created\n");
1332     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1333     style = GetWindowLong(hHeader, GWL_STYLE);
1334     ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1335     DestroyWindow(hList);
1336
1337     hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1338                           GetModuleHandle(NULL), 0);
1339     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1340     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1341     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1342     /* insert column */
1343     memset(&col, 0, sizeof(LVCOLUMNA));
1344     col.mask = LVCF_WIDTH;
1345     col.cx = 100;
1346     r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1347     ok(r == 0, "Expected 0 column's inserted\n");
1348     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1349     ok(IsWindow(hHeader), "Header should be created\n");
1350     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1351     DestroyWindow(hList);
1352
1353     /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1354     hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1355                           GetModuleHandle(NULL), 0);
1356     ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1357     ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1358     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1359     ok(IsWindow(hHeader), "Header should be created\n");
1360     ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1361     ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1362     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1363     ok(IsWindow(hHeader), "Header should be created\n");
1364     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1365     DestroyWindow(hList);
1366
1367     /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1368     hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1369                           GetModuleHandle(NULL), 0);
1370     ret = SetWindowLongPtr(hList, GWL_STYLE,
1371                           (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1372     ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1373     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1374     ok(IsWindow(hHeader), "Header should be created\n");
1375     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1376     ret = SetWindowLongPtr(hList, GWL_STYLE,
1377                           (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1378     ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1379     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1380     ok(IsWindow(hHeader), "Header should be created\n");
1381     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1382     DestroyWindow(hList);
1383
1384     /* LVS_REPORT without WS_VISIBLE */
1385     hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1386                           GetModuleHandle(NULL), 0);
1387     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1388     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1389     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1390     /* insert column */
1391     memset(&col, 0, sizeof(LVCOLUMNA));
1392     col.mask = LVCF_WIDTH;
1393     col.cx = 100;
1394     r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1395     ok(r == 0, "Expected 0 column's inserted\n");
1396     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1397     ok(IsWindow(hHeader), "Header should be created\n");
1398     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1399     DestroyWindow(hList);
1400
1401     /* LVS_REPORT without WS_VISIBLE, try to show it */
1402     hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1403                           GetModuleHandle(NULL), 0);
1404     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1405     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1406     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1407     ShowWindow(hList, SW_SHOW);
1408     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1409     ok(IsWindow(hHeader), "Header should be created\n");
1410     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1411     DestroyWindow(hList);
1412
1413     /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1414     hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1415                           0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1416     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1417     ok(IsWindow(hHeader), "Header should be created\n");
1418     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1419     /* HDS_DRAGDROP set by default */
1420     ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1421     DestroyWindow(hList);
1422
1423     /* setting LVS_EX_HEADERDRAGDROP creates header */
1424     hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1425                           GetModuleHandle(NULL), 0);
1426     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1427     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1428     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1429     SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1430     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1431     ok(IsWindow(hHeader) ||
1432        broken(!IsWindow(hHeader)), /* 4.7x common controls */
1433        "Header should be created\n");
1434     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1435     DestroyWindow(hList);
1436
1437     /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1438     hList = create_listview_control(LVS_ICON);
1439     SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1440     r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1441     ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1442     DestroyWindow(hList);
1443
1444     /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1445     hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1446                           GetModuleHandle(NULL), 0);
1447     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1448     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1449
1450     rect.left = LVIR_BOUNDS;
1451     rect.top  = 1;
1452     rect.right = rect.bottom = -10;
1453     r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1454     ok(r != 0, "Expected not-null LRESULT\n");
1455
1456     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1457     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1458     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1459
1460     DestroyWindow(hList);
1461
1462     /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1463     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1464     hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1465     ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1466                 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1467     DestroyWindow(hList);
1468 }
1469
1470 static void test_redraw(void)
1471 {
1472     HWND hwnd;
1473     HDC hdc;
1474     BOOL res;
1475     DWORD r;
1476
1477     hwnd = create_listview_control(LVS_REPORT);
1478     subclass_header(hwnd);
1479
1480     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1481
1482     trace("invalidate & update\n");
1483     InvalidateRect(hwnd, NULL, TRUE);
1484     UpdateWindow(hwnd);
1485     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1486
1487     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1488
1489     /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1490     /* 1. Without backbuffer */
1491     res = ListView_SetBkColor(hwnd, CLR_NONE);
1492     expect(TRUE, res);
1493
1494     hdc = GetWindowDC(hwndparent);
1495
1496     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1497     r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1498     ok(r != 0, "Expected not zero result\n");
1499     ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1500                 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1501
1502     res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1503     expect(TRUE, res);
1504
1505     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1506     r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1507     ok(r != 0, "Expected not zero result\n");
1508     ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1509                 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1510
1511     /* 2. With backbuffer */
1512     SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1513                                                      LVS_EX_DOUBLEBUFFER);
1514     res = ListView_SetBkColor(hwnd, CLR_NONE);
1515     expect(TRUE, res);
1516
1517     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1518     r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1519     ok(r != 0, "Expected not zero result\n");
1520     ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1521                 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1522
1523     res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1524     expect(TRUE, res);
1525
1526     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1527     r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1528     todo_wine ok(r != 0, "Expected not zero result\n");
1529     ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1530                 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1531
1532     ReleaseDC(hwndparent, hdc);
1533
1534     DestroyWindow(hwnd);
1535 }
1536
1537 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1538 {
1539     COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1540
1541     if(msg == WM_NOTIFY) {
1542         NMHDR *nmhdr = (PVOID)lp;
1543         if(nmhdr->code == NM_CUSTOMDRAW) {
1544             NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1545             trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1546             switch(nmlvcd->nmcd.dwDrawStage) {
1547             case CDDS_PREPAINT:
1548                 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1549                 return CDRF_NOTIFYITEMDRAW;
1550             case CDDS_ITEMPREPAINT:
1551                 nmlvcd->clrTextBk = CLR_DEFAULT;
1552                 return CDRF_NOTIFYSUBITEMDRAW;
1553             case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1554                 clr = GetBkColor(nmlvcd->nmcd.hdc);
1555                 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1556                 return CDRF_NOTIFYPOSTPAINT;
1557             case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1558                 clr = GetBkColor(nmlvcd->nmcd.hdc);
1559                 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1560                 return CDRF_DODEFAULT;
1561             }
1562             return CDRF_DODEFAULT;
1563         }
1564     }
1565
1566     return DefWindowProcA(hwnd, msg, wp, lp);
1567 }
1568
1569 static void test_customdraw(void)
1570 {
1571     HWND hwnd;
1572     WNDPROC oldwndproc;
1573
1574     hwnd = create_listview_control(LVS_REPORT);
1575
1576     insert_column(hwnd, 0);
1577     insert_column(hwnd, 1);
1578     insert_item(hwnd, 0);
1579
1580     oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1581                                            (LONG_PTR)cd_wndproc);
1582
1583     InvalidateRect(hwnd, NULL, TRUE);
1584     UpdateWindow(hwnd);
1585
1586     SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1587
1588     DestroyWindow(hwnd);
1589 }
1590
1591 static void test_icon_spacing(void)
1592 {
1593     /* LVM_SETICONSPACING */
1594     /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1595
1596     HWND hwnd;
1597     WORD w, h;
1598     DWORD r;
1599
1600     hwnd = create_listview_control(LVS_ICON);
1601     ok(hwnd != NULL, "failed to create a listview window\n");
1602
1603     r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1604     expect(NFR_ANSI, r);
1605
1606     /* reset the icon spacing to defaults */
1607     SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1608
1609     /* now we can request what the defaults are */
1610     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1611     w = LOWORD(r);
1612     h = HIWORD(r);
1613
1614     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1615
1616     trace("test icon spacing\n");
1617
1618     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1619     ok(r == MAKELONG(w, h) ||
1620        broken(r == MAKELONG(w, w)), /* win98 */
1621        "Expected %d, got %d\n", MAKELONG(w, h), r);
1622
1623     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1624     if (r == 0)
1625     {
1626         /* version 4.0 */
1627         win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1628         DestroyWindow(hwnd);
1629         return;
1630     }
1631     expect(MAKELONG(20,30), r);
1632
1633     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1634     expect(MAKELONG(25,35), r);
1635
1636     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1637
1638     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1639     DestroyWindow(hwnd);
1640 }
1641
1642 static void test_color(void)
1643 {
1644     /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1645
1646     HWND hwnd;
1647     DWORD r;
1648     int i;
1649
1650     COLORREF color;
1651     COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1652
1653     hwnd = create_listview_control(LVS_REPORT);
1654     ok(hwnd != NULL, "failed to create a listview window\n");
1655
1656     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1657
1658     trace("test color seq\n");
1659     for (i = 0; i < 4; i++)
1660     {
1661         color = colors[i];
1662
1663         r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1664         expect(TRUE, r);
1665         r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1666         expect(color, r);
1667
1668         r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1669         expect (TRUE, r);
1670         r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1671         expect(color, r);
1672
1673         r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1674         expect(TRUE, r);
1675         r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1676         expect(color, r);
1677     }
1678
1679     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1680
1681     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1682     DestroyWindow(hwnd);
1683 }
1684
1685 static void test_item_count(void)
1686 {
1687     /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1688
1689     HWND hwnd;
1690     DWORD r;
1691     HDC hdc;
1692     HFONT hOldFont;
1693     TEXTMETRICA tm;
1694     RECT rect;
1695     INT height;
1696
1697     LVITEM item0;
1698     LVITEM item1;
1699     LVITEM item2;
1700     static CHAR item0text[] = "item0";
1701     static CHAR item1text[] = "item1";
1702     static CHAR item2text[] = "item2";
1703
1704     hwnd = create_listview_control(LVS_REPORT);
1705     ok(hwnd != NULL, "failed to create a listview window\n");
1706
1707     /* resize in dpiaware manner to fit all 3 items added */
1708     hdc = GetDC(0);
1709     hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1710     GetTextMetricsA(hdc, &tm);
1711     /* 2 extra pixels for bounds and header border */
1712     height = tm.tmHeight + 2;
1713     SelectObject(hdc, hOldFont);
1714     ReleaseDC(0, hdc);
1715
1716     GetWindowRect(hwnd, &rect);
1717     /* 3 items + 1 header + 1 to be sure */
1718     MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1719
1720     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1721
1722     trace("test item count\n");
1723
1724     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1725     expect(0, r);
1726
1727     /* [item0] */
1728     item0.mask = LVIF_TEXT;
1729     item0.iItem = 0;
1730     item0.iSubItem = 0;
1731     item0.pszText = item0text;
1732     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1733     expect(0, r);
1734
1735     /* [item0, item1] */
1736     item1.mask = LVIF_TEXT;
1737     item1.iItem = 1;
1738     item1.iSubItem = 0;
1739     item1.pszText = item1text;
1740     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1741     expect(1, r);
1742
1743     /* [item0, item1, item2] */
1744     item2.mask = LVIF_TEXT;
1745     item2.iItem = 2;
1746     item2.iSubItem = 0;
1747     item2.pszText = item2text;
1748     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1749     expect(2, r);
1750
1751     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1752     expect(3, r);
1753
1754     /* [item0, item1] */
1755     r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1756     expect(TRUE, r);
1757
1758     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1759     expect(2, r);
1760
1761     /* [] */
1762     r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1763     expect(TRUE, r);
1764
1765     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1766     expect(0, r);
1767
1768     /* [item0] */
1769     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1770     expect(0, r);
1771
1772     /* [item0, item1] */
1773     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1774     expect(1, r);
1775
1776     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1777     expect(2, r);
1778
1779     /* [item0, item1, item2] */
1780     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1781     expect(2, r);
1782
1783     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1784     expect(3, r);
1785
1786     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1787
1788     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1789     DestroyWindow(hwnd);
1790 }
1791
1792 static void test_item_position(void)
1793 {
1794     /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1795
1796     HWND hwnd;
1797     DWORD r;
1798     POINT position;
1799
1800     LVITEM item0;
1801     LVITEM item1;
1802     LVITEM item2;
1803     static CHAR item0text[] = "item0";
1804     static CHAR item1text[] = "item1";
1805     static CHAR item2text[] = "item2";
1806
1807     hwnd = create_listview_control(LVS_ICON);
1808     ok(hwnd != NULL, "failed to create a listview window\n");
1809
1810     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1811
1812     trace("test item position\n");
1813
1814     /* [item0] */
1815     item0.mask = LVIF_TEXT;
1816     item0.iItem = 0;
1817     item0.iSubItem = 0;
1818     item0.pszText = item0text;
1819     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1820     expect(0, r);
1821
1822     /* [item0, item1] */
1823     item1.mask = LVIF_TEXT;
1824     item1.iItem = 1;
1825     item1.iSubItem = 0;
1826     item1.pszText = item1text;
1827     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1828     expect(1, r);
1829
1830     /* [item0, item1, item2] */
1831     item2.mask = LVIF_TEXT;
1832     item2.iItem = 2;
1833     item2.iSubItem = 0;
1834     item2.pszText = item2text;
1835     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1836     expect(2, r);
1837
1838     r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1839     expect(TRUE, r);
1840     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1841     expect(TRUE, r);
1842     expect2(10, 5, position.x, position.y);
1843
1844     r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1845     expect(TRUE, r);
1846     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1847     expect(TRUE, r);
1848     expect2(0, 0, position.x, position.y);
1849
1850     r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1851     expect(TRUE, r);
1852     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1853     expect(TRUE, r);
1854     expect2(20, 20, position.x, position.y);
1855
1856     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1857
1858     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1859     DestroyWindow(hwnd);
1860 }
1861
1862 static void test_getorigin(void)
1863 {
1864     /* LVM_GETORIGIN */
1865
1866     HWND hwnd;
1867     DWORD r;
1868     POINT position;
1869
1870     position.x = position.y = 0;
1871
1872     hwnd = create_listview_control(LVS_ICON);
1873     ok(hwnd != NULL, "failed to create a listview window\n");
1874     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1875     trace("test get origin results\n");
1876     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1877     expect(TRUE, r);
1878     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1879     DestroyWindow(hwnd);
1880
1881     hwnd = create_listview_control(LVS_SMALLICON);
1882     ok(hwnd != NULL, "failed to create a listview window\n");
1883     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1884     trace("test get origin results\n");
1885     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1886     expect(TRUE, r);
1887     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1888     DestroyWindow(hwnd);
1889
1890     hwnd = create_listview_control(LVS_LIST);
1891     ok(hwnd != NULL, "failed to create a listview window\n");
1892     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1893     trace("test get origin results\n");
1894     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1895     expect(FALSE, r);
1896     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1897     DestroyWindow(hwnd);
1898
1899     hwnd = create_listview_control(LVS_REPORT);
1900     ok(hwnd != NULL, "failed to create a listview window\n");
1901     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1902     trace("test get origin results\n");
1903     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1904     expect(FALSE, r);
1905     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1906     DestroyWindow(hwnd);
1907
1908 }
1909
1910 static void test_multiselect(void)
1911 {
1912     typedef struct t_select_task
1913     {
1914         const char *descr;
1915         int initPos;
1916         int loopVK;
1917         int count;
1918         int result;
1919     } select_task;
1920
1921     HWND hwnd;
1922     DWORD r;
1923     int i,j,item_count,selected_count;
1924     static const int items=5;
1925     BYTE kstate[256];
1926     select_task task;
1927     LONG_PTR style;
1928     LVITEMA item;
1929
1930     static struct t_select_task task_list[] = {
1931         { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1932         { "using VK_UP", -1, VK_UP, -1, -1 },
1933         { "using VK_END", 0, VK_END, 1, -1 },
1934         { "using VK_HOME", -1, VK_HOME, 1, -1 }
1935     };
1936
1937
1938     hwnd = create_listview_control(LVS_REPORT);
1939
1940     for (i=0;i<items;i++) {
1941             insert_item(hwnd, 0);
1942     }
1943
1944     item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1945
1946     expect(items,item_count);
1947
1948     for (i=0;i<4;i++) {
1949         task = task_list[i];
1950
1951         /* deselect all items */
1952         ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1953         SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1954
1955         /* set initial position */
1956         SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1957         ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1958
1959         selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1960
1961         ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1962
1963         /* Set SHIFT key pressed */
1964         GetKeyboardState(kstate);
1965         kstate[VK_SHIFT]=0x80;
1966         SetKeyboardState(kstate);
1967
1968         for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1969             r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1970             expect(0,r);
1971             r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1972             expect(0,r);
1973         }
1974
1975         selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1976
1977         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);
1978
1979         /* Set SHIFT key released */
1980         GetKeyboardState(kstate);
1981         kstate[VK_SHIFT]=0x00;
1982         SetKeyboardState(kstate);
1983     }
1984     DestroyWindow(hwnd);
1985
1986     /* make multiple selection, then switch to LVS_SINGLESEL */
1987     hwnd = create_listview_control(LVS_REPORT);
1988     for (i=0;i<items;i++) {
1989             insert_item(hwnd, 0);
1990     }
1991     item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1992     expect(items,item_count);
1993
1994     /* try with NULL pointer */
1995     r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
1996     expect(FALSE, r);
1997
1998     /* select all, check notifications */
1999     ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2000
2001     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2002
2003     item.stateMask = LVIS_SELECTED;
2004     item.state     = LVIS_SELECTED;
2005     r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2006     expect(TRUE, r);
2007
2008     ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
2009                 "select all notification", FALSE);
2010
2011     /* deselect all items */
2012     ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2013     SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2014     for (i=0;i<3;i++) {
2015         ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
2016     }
2017
2018     r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2019     expect(3, r);
2020     r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2021     expect(-1, r);
2022
2023     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2024     ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2025     SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2026     /* check that style is accepted */
2027     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2028     ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2029
2030     for (i=0;i<3;i++) {
2031         r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2032         ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2033     }
2034     r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2035     expect(3, r);
2036     SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2037     expect(3, r);
2038
2039     /* select one more */
2040     ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2041
2042     for (i=0;i<3;i++) {
2043         r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2044         ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2045     }
2046     r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2047     ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2048
2049     r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2050     expect(1, r);
2051     r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2052     expect(-1, r);
2053
2054     /* try to select all on LVS_SINGLESEL */
2055     memset(&item, 0, sizeof(item));
2056     item.stateMask = LVIS_SELECTED;
2057     r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2058     expect(TRUE, r);
2059     SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2060
2061     item.stateMask = LVIS_SELECTED;
2062     item.state     = LVIS_SELECTED;
2063     r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2064     expect(FALSE, r);
2065
2066     r = ListView_GetSelectedCount(hwnd);
2067     expect(0, r);
2068     r = ListView_GetSelectionMark(hwnd);
2069     expect(-1, r);
2070
2071     /* try to deselect all on LVS_SINGLESEL */
2072     item.stateMask = LVIS_SELECTED;
2073     item.state     = LVIS_SELECTED;
2074     r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2075     expect(TRUE, r);
2076
2077     item.stateMask = LVIS_SELECTED;
2078     item.state     = 0;
2079     r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2080     expect(TRUE, r);
2081     r = ListView_GetSelectedCount(hwnd);
2082     expect(0, r);
2083
2084     DestroyWindow(hwnd);
2085 }
2086
2087 static void test_subitem_rect(void)
2088 {
2089     HWND hwnd;
2090     DWORD r;
2091     LVCOLUMN col;
2092     RECT rect;
2093
2094     /* test LVM_GETSUBITEMRECT for header */
2095     hwnd = create_listview_control(LVS_REPORT);
2096     ok(hwnd != NULL, "failed to create a listview window\n");
2097     /* add some columns */
2098     memset(&col, 0, sizeof(LVCOLUMN));
2099     col.mask = LVCF_WIDTH;
2100     col.cx = 100;
2101     r = -1;
2102     r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2103     expect(0, r);
2104     col.cx = 150;
2105     r = -1;
2106     r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2107     expect(1, r);
2108     col.cx = 200;
2109     r = -1;
2110     r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2111     expect(2, r);
2112     /* item = -1 means header, subitem index is 1 based */
2113     rect.left = LVIR_BOUNDS;
2114     rect.top  = 0;
2115     rect.right = rect.bottom = 0;
2116     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2117     expect(0, r);
2118
2119     rect.left = LVIR_BOUNDS;
2120     rect.top  = 1;
2121     rect.right = rect.bottom = 0;
2122     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2123
2124     ok(r != 0, "Expected not-null LRESULT\n");
2125     expect(100, rect.left);
2126     expect(250, rect.right);
2127 todo_wine
2128     expect(3, rect.top);
2129
2130     rect.left = LVIR_BOUNDS;
2131     rect.top  = 2;
2132     rect.right = rect.bottom = 0;
2133     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2134
2135     ok(r != 0, "Expected not-null LRESULT\n");
2136     expect(250, rect.left);
2137     expect(450, rect.right);
2138 todo_wine
2139     expect(3, rect.top);
2140
2141     /* item LVS_REPORT padding isn't applied to subitems */
2142     insert_item(hwnd, 0);
2143
2144     rect.left = LVIR_BOUNDS;
2145     rect.top  = 1;
2146     rect.right = rect.bottom = 0;
2147     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2148     ok(r != 0, "Expected not-null LRESULT\n");
2149     expect(100, rect.left);
2150     expect(250, rect.right);
2151
2152     rect.left = LVIR_ICON;
2153     rect.top  = 1;
2154     rect.right = rect.bottom = 0;
2155     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2156     ok(r != 0, "Expected not-null LRESULT\n");
2157     /* no icon attached - zero width rectangle, with no left padding */
2158     expect(100, rect.left);
2159     expect(100, rect.right);
2160
2161     rect.left = LVIR_LABEL;
2162     rect.top  = 1;
2163     rect.right = rect.bottom = 0;
2164     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2165     ok(r != 0, "Expected not-null LRESULT\n");
2166     /* same as full LVIR_BOUNDS */
2167     expect(100, rect.left);
2168     expect(250, rect.right);
2169
2170     SendMessage(hwnd, LVM_SCROLL, 10, 0);
2171
2172     rect.left = LVIR_BOUNDS;
2173     rect.top  = 1;
2174     rect.right = rect.bottom = 0;
2175     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2176     ok(r != 0, "Expected not-null LRESULT\n");
2177     expect(90, rect.left);
2178     expect(240, rect.right);
2179
2180     SendMessage(hwnd, LVM_SCROLL, -10, 0);
2181
2182     DestroyWindow(hwnd);
2183
2184     /* try it for non LVS_REPORT style */
2185     hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2186                          GetModuleHandle(NULL), 0);
2187     rect.left = LVIR_BOUNDS;
2188     rect.top  = 1;
2189     rect.right = rect.bottom = -10;
2190     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2191     ok(r == 0, "Expected not-null LRESULT\n");
2192     /* rect is unchanged */
2193     expect(0, rect.left);
2194     expect(-10, rect.right);
2195     expect(1, rect.top);
2196     expect(-10, rect.bottom);
2197     DestroyWindow(hwnd);
2198 }
2199
2200 /* comparison callback for test_sorting */
2201 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2202 {
2203     if (first == second) return 0;
2204     return (first > second ? 1 : -1);
2205 }
2206
2207 static void test_sorting(void)
2208 {
2209     HWND hwnd;
2210     LVITEMA item = {0};
2211     DWORD r;
2212     LONG_PTR style;
2213     static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2214     CHAR buff[10];
2215
2216     hwnd = create_listview_control(LVS_REPORT);
2217     ok(hwnd != NULL, "failed to create a listview window\n");
2218
2219     /* insert some items */
2220     item.mask = LVIF_PARAM | LVIF_STATE;
2221     item.state = LVIS_SELECTED;
2222     item.iItem = 0;
2223     item.iSubItem = 0;
2224     item.lParam = 3;
2225     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2226     expect(0, r);
2227
2228     item.mask = LVIF_PARAM;
2229     item.iItem = 1;
2230     item.iSubItem = 0;
2231     item.lParam = 2;
2232     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2233     expect(1, r);
2234
2235     item.mask = LVIF_STATE | LVIF_PARAM;
2236     item.state = LVIS_SELECTED;
2237     item.iItem = 2;
2238     item.iSubItem = 0;
2239     item.lParam = 4;
2240     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2241     expect(2, r);
2242
2243     r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2244     expect(-1, r);
2245
2246     r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2247     expect(2, r);
2248
2249     r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2250     expect(TRUE, r);
2251
2252     r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2253     expect(2, r);
2254     r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2255     expect(-1, r);
2256     r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2257     expect(0, r);
2258     r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2259     expect(LVIS_SELECTED, r);
2260     r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2261     expect(LVIS_SELECTED, r);
2262
2263     DestroyWindow(hwnd);
2264
2265     /* switch to LVS_SORTASCENDING when some items added */
2266     hwnd = create_listview_control(LVS_REPORT);
2267     ok(hwnd != NULL, "failed to create a listview window\n");
2268
2269     item.mask = LVIF_TEXT;
2270     item.iItem = 0;
2271     item.iSubItem = 0;
2272     item.pszText = names[1];
2273     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2274     expect(0, r);
2275
2276     item.mask = LVIF_TEXT;
2277     item.iItem = 1;
2278     item.iSubItem = 0;
2279     item.pszText = names[2];
2280     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2281     expect(1, r);
2282
2283     item.mask = LVIF_TEXT;
2284     item.iItem = 2;
2285     item.iSubItem = 0;
2286     item.pszText = names[0];
2287     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2288     expect(2, r);
2289
2290     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2291     SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2292     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2293     ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2294
2295     /* no sorting performed when switched to LVS_SORTASCENDING */
2296     item.mask = LVIF_TEXT;
2297     item.iItem = 0;
2298     item.pszText = buff;
2299     item.cchTextMax = sizeof(buff);
2300     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2301     expect(TRUE, r);
2302     ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2303
2304     item.iItem = 1;
2305     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2306     expect(TRUE, r);
2307     ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2308
2309     item.iItem = 2;
2310     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2311     expect(TRUE, r);
2312     ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2313
2314     /* adding new item doesn't resort list */
2315     item.mask = LVIF_TEXT;
2316     item.iItem = 3;
2317     item.iSubItem = 0;
2318     item.pszText = names[3];
2319     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2320     expect(3, r);
2321
2322     item.mask = LVIF_TEXT;
2323     item.iItem = 0;
2324     item.pszText = buff;
2325     item.cchTextMax = sizeof(buff);
2326     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2327     expect(TRUE, r);
2328     ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2329
2330     item.iItem = 1;
2331     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2332     expect(TRUE, r);
2333     ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2334
2335     item.iItem = 2;
2336     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2337     expect(TRUE, r);
2338     ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2339
2340     item.iItem = 3;
2341     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2342     expect(TRUE, r);
2343     ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2344
2345     /* corner case - item should be placed at first position */
2346     item.mask = LVIF_TEXT;
2347     item.iItem = 4;
2348     item.iSubItem = 0;
2349     item.pszText = names[4];
2350     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2351     expect(0, r);
2352
2353     item.iItem = 0;
2354     item.pszText = buff;
2355     item.cchTextMax = sizeof(buff);
2356     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2357     expect(TRUE, r);
2358     ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2359
2360     item.iItem = 1;
2361     item.pszText = buff;
2362     item.cchTextMax = sizeof(buff);
2363     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2364     expect(TRUE, r);
2365     ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2366
2367     item.iItem = 2;
2368     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2369     expect(TRUE, r);
2370     ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2371
2372     item.iItem = 3;
2373     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2374     expect(TRUE, r);
2375     ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2376
2377     item.iItem = 4;
2378     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2379     expect(TRUE, r);
2380     ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2381
2382     DestroyWindow(hwnd);
2383 }
2384
2385 static void test_ownerdata(void)
2386 {
2387     HWND hwnd;
2388     LONG_PTR style, ret;
2389     DWORD res;
2390     LVITEMA item;
2391
2392     /* it isn't possible to set LVS_OWNERDATA after creation */
2393     if (g_is_below_5)
2394     {
2395         win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2396     }
2397     else
2398     {
2399         hwnd = create_listview_control(LVS_REPORT);
2400         ok(hwnd != NULL, "failed to create a listview window\n");
2401         style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2402         ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2403
2404         flush_sequences(sequences, NUM_MSG_SEQUENCES);
2405
2406         ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2407         ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2408         ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2409                 "try to switch to LVS_OWNERDATA seq", FALSE);
2410
2411         style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2412         ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2413         DestroyWindow(hwnd);
2414     }
2415
2416     /* try to set LVS_OWNERDATA after creation just having it */
2417     hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2418     ok(hwnd != NULL, "failed to create a listview window\n");
2419     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2420     ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2421
2422     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2423
2424     ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2425     ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2426     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2427                 "try to switch to LVS_OWNERDATA seq", FALSE);
2428     DestroyWindow(hwnd);
2429
2430     /* try to remove LVS_OWNERDATA after creation just having it */
2431     if (g_is_below_5)
2432     {
2433         win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2434     }
2435     else
2436     {
2437         hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2438         ok(hwnd != NULL, "failed to create a listview window\n");
2439         style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2440         ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2441
2442         flush_sequences(sequences, NUM_MSG_SEQUENCES);
2443
2444         ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2445         ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2446         ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2447                 "try to switch to LVS_OWNERDATA seq", FALSE);
2448         style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2449         ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2450         DestroyWindow(hwnd);
2451     }
2452
2453     /* try select an item */
2454     hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2455     ok(hwnd != NULL, "failed to create a listview window\n");
2456     res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2457     ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2458     res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2459     expect(0, res);
2460     memset(&item, 0, sizeof(item));
2461     item.stateMask = LVIS_SELECTED;
2462     item.state     = LVIS_SELECTED;
2463     res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2464     expect(TRUE, res);
2465     res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2466     expect(1, res);
2467     res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2468     expect(1, res);
2469     DestroyWindow(hwnd);
2470
2471     /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2472     hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2473     ok(hwnd != NULL, "failed to create a listview window\n");
2474     res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2475     ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2476     res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2477     expect(1, res);
2478     memset(&item, 0, sizeof(item));
2479     item.mask = LVIF_STATE;
2480     item.iItem = 0;
2481     item.stateMask = LVIS_SELECTED;
2482     item.state     = LVIS_SELECTED;
2483     res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2484     expect(FALSE, res);
2485     DestroyWindow(hwnd);
2486
2487     /* check notifications after focused/selected changed */
2488     hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2489     ok(hwnd != NULL, "failed to create a listview window\n");
2490     res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2491     ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2492
2493     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2494
2495     memset(&item, 0, sizeof(item));
2496     item.stateMask = LVIS_SELECTED;
2497     item.state     = LVIS_SELECTED;
2498     res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2499     expect(TRUE, res);
2500
2501     ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2502                 "ownerdata select notification", TRUE);
2503
2504     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2505
2506     memset(&item, 0, sizeof(item));
2507     item.stateMask = LVIS_FOCUSED;
2508     item.state     = LVIS_FOCUSED;
2509     res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2510     expect(TRUE, res);
2511
2512     ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2513                 "ownerdata focus notification", TRUE);
2514
2515     /* select all, check notifications */
2516     item.stateMask = LVIS_SELECTED;
2517     item.state     = 0;
2518     res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2519     expect(TRUE, res);
2520
2521     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2522
2523     item.stateMask = LVIS_SELECTED;
2524     item.state     = LVIS_SELECTED;
2525
2526     g_dump_itemchanged = TRUE;
2527     res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2528     expect(TRUE, res);
2529     g_dump_itemchanged = FALSE;
2530
2531     ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2532                 "ownerdata select all notification", TRUE);
2533
2534     /* select all again, note that all items are selected already */
2535     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2536     item.stateMask = LVIS_SELECTED;
2537     item.state     = LVIS_SELECTED;
2538     g_dump_itemchanged = TRUE;
2539     res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2540     expect(TRUE, res);
2541     g_dump_itemchanged = FALSE;
2542     ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2543                 "ownerdata select all notification", TRUE);
2544     /* deselect all */
2545     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2546     item.stateMask = LVIS_SELECTED;
2547     item.state     = 0;
2548     g_dump_itemchanged = TRUE;
2549     res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2550     expect(TRUE, res);
2551     g_dump_itemchanged = FALSE;
2552     ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2553                 "ownerdata deselect all notification", TRUE);
2554
2555     /* select one, then deselect all */
2556     item.stateMask = LVIS_SELECTED;
2557     item.state     = LVIS_SELECTED;
2558     res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2559     expect(TRUE, res);
2560     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2561     item.stateMask = LVIS_SELECTED;
2562     item.state     = 0;
2563     g_dump_itemchanged = TRUE;
2564     res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2565     expect(TRUE, res);
2566     g_dump_itemchanged = FALSE;
2567     ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2568                 "ownerdata select all notification", TRUE);
2569
2570     /* remove focused, try to focus all */
2571     item.stateMask = LVIS_FOCUSED;
2572     item.state     = LVIS_FOCUSED;
2573     res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2574     expect(TRUE, res);
2575     item.stateMask = LVIS_FOCUSED;
2576     item.state     = 0;
2577     res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2578     expect(TRUE, res);
2579     item.stateMask = LVIS_FOCUSED;
2580     res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
2581     expect(0, res);
2582     /* setting all to focused returns failure value */
2583     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2584     item.stateMask = LVIS_FOCUSED;
2585     item.state     = LVIS_FOCUSED;
2586     g_dump_itemchanged = TRUE;
2587     res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2588     expect(FALSE, res);
2589     g_dump_itemchanged = FALSE;
2590     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2591                 "ownerdata focus all notification", FALSE);
2592     /* focus single item, remove all */
2593     item.stateMask = LVIS_FOCUSED;
2594     item.state     = LVIS_FOCUSED;
2595     res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2596     expect(TRUE, res);
2597     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2598     item.stateMask = LVIS_FOCUSED;
2599     item.state     = 0;
2600     g_dump_itemchanged = TRUE;
2601     res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2602     expect(TRUE, res);
2603     g_dump_itemchanged = FALSE;
2604     ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
2605                 "ownerdata remove focus all notification", TRUE);
2606     /* set all cut */
2607     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2608     item.stateMask = LVIS_CUT;
2609     item.state     = LVIS_CUT;
2610     g_dump_itemchanged = TRUE;
2611     res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2612     expect(TRUE, res);
2613     g_dump_itemchanged = FALSE;
2614     ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2615                 "ownerdata cut all notification", TRUE);
2616     /* all marked cut, try again */
2617     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2618     item.stateMask = LVIS_CUT;
2619     item.state     = LVIS_CUT;
2620     g_dump_itemchanged = TRUE;
2621     res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2622     expect(TRUE, res);
2623     g_dump_itemchanged = FALSE;
2624     ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2625                 "ownerdata cut all notification #2", TRUE);
2626
2627     DestroyWindow(hwnd);
2628
2629     /* check notifications on LVM_GETITEM */
2630     /* zero callback mask */
2631     hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2632     ok(hwnd != NULL, "failed to create a listview window\n");
2633     res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2634     ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2635
2636     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2637
2638     memset(&item, 0, sizeof(item));
2639     item.stateMask = LVIS_SELECTED;
2640     item.mask      = LVIF_STATE;
2641     res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2642     expect(TRUE, res);
2643
2644     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2645                 "ownerdata getitem selected state 1", FALSE);
2646
2647     /* non zero callback mask but not we asking for */
2648     res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2649     expect(TRUE, res);
2650
2651     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2652
2653     memset(&item, 0, sizeof(item));
2654     item.stateMask = LVIS_SELECTED;
2655     item.mask      = LVIF_STATE;
2656     res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2657     expect(TRUE, res);
2658
2659     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2660                 "ownerdata getitem selected state 2", FALSE);
2661
2662     /* LVIS_OVERLAYMASK callback mask, asking for index */
2663     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2664
2665     memset(&item, 0, sizeof(item));
2666     item.stateMask = LVIS_OVERLAYMASK;
2667     item.mask      = LVIF_STATE;
2668     res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2669     expect(TRUE, res);
2670
2671     ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2672                 "ownerdata getitem selected state 2", FALSE);
2673
2674     DestroyWindow(hwnd);
2675
2676     /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2677     hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
2678     ok(hwnd != NULL, "failed to create a listview window\n");
2679     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2680     ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2681     ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2682     SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2683     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2684     ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2685     DestroyWindow(hwnd);
2686     /* apparently it's allowed to switch these style on after creation */
2687     hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2688     ok(hwnd != NULL, "failed to create a listview window\n");
2689     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2690     ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2691     SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2692     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2693     ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2694     DestroyWindow(hwnd);
2695
2696     hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2697     ok(hwnd != NULL, "failed to create a listview window\n");
2698     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2699     ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2700     SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2701     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2702     ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2703     DestroyWindow(hwnd);
2704 }
2705
2706 static void test_norecompute(void)
2707 {
2708     static CHAR testA[] = "test";
2709     CHAR buff[10];
2710     LVITEMA item;
2711     HWND hwnd;
2712     DWORD res;
2713
2714     /* self containing control */
2715     hwnd = create_listview_control(LVS_REPORT);
2716     ok(hwnd != NULL, "failed to create a listview window\n");
2717     memset(&item, 0, sizeof(item));
2718     item.mask = LVIF_TEXT | LVIF_STATE;
2719     item.iItem = 0;
2720     item.stateMask = LVIS_SELECTED;
2721     item.state     = LVIS_SELECTED;
2722     item.pszText   = testA;
2723     res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2724     expect(0, res);
2725     /* retrieve with LVIF_NORECOMPUTE */
2726     item.mask  = LVIF_TEXT | LVIF_NORECOMPUTE;
2727     item.iItem = 0;
2728     item.pszText    = buff;
2729     item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2730     res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2731     expect(TRUE, res);
2732     ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2733
2734     item.mask = LVIF_TEXT;
2735     item.iItem = 1;
2736     item.pszText = LPSTR_TEXTCALLBACK;
2737     res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2738     expect(1, res);
2739
2740     item.mask  = LVIF_TEXT | LVIF_NORECOMPUTE;
2741     item.iItem = 1;
2742     item.pszText    = buff;
2743     item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2744
2745     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2746     res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2747     expect(TRUE, res);
2748     ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2749        LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2750     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2751
2752     DestroyWindow(hwnd);
2753
2754     /* LVS_OWNERDATA */
2755     hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2756     ok(hwnd != NULL, "failed to create a listview window\n");
2757
2758     item.mask = LVIF_STATE;
2759     item.stateMask = LVIS_SELECTED;
2760     item.state     = LVIS_SELECTED;
2761     item.iItem = 0;
2762     res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2763     expect(0, res);
2764
2765     item.mask  = LVIF_TEXT | LVIF_NORECOMPUTE;
2766     item.iItem = 0;
2767     item.pszText    = buff;
2768     item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2769     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2770     res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2771     expect(TRUE, res);
2772     ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2773        LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2774     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2775
2776     DestroyWindow(hwnd);
2777 }
2778
2779 static void test_nosortheader(void)
2780 {
2781     HWND hwnd, header;
2782     LONG_PTR style;
2783
2784     hwnd = create_listview_control(LVS_REPORT);
2785     ok(hwnd != NULL, "failed to create a listview window\n");
2786
2787     header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2788     ok(IsWindow(header), "header expected\n");
2789
2790     style = GetWindowLongPtr(header, GWL_STYLE);
2791     ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2792
2793     style = GetWindowLongPtr(hwnd, GWL_STYLE);
2794     SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2795     /* HDS_BUTTONS retained */
2796     style = GetWindowLongPtr(header, GWL_STYLE);
2797     ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2798
2799     DestroyWindow(hwnd);
2800
2801     /* create with LVS_NOSORTHEADER */
2802     hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
2803     ok(hwnd != NULL, "failed to create a listview window\n");
2804
2805     header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2806     ok(IsWindow(header), "header expected\n");
2807
2808     style = GetWindowLongPtr(header, GWL_STYLE);
2809     ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2810
2811     style = GetWindowLongPtr(hwnd, GWL_STYLE);
2812     SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2813     /* not changed here */
2814     style = GetWindowLongPtr(header, GWL_STYLE);
2815     ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2816
2817     DestroyWindow(hwnd);
2818 }
2819
2820 static void test_setredraw(void)
2821 {
2822     HWND hwnd;
2823     DWORD_PTR style;
2824     DWORD ret;
2825     HDC hdc;
2826     RECT rect;
2827
2828     hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2829     ok(hwnd != NULL, "failed to create a listview window\n");
2830
2831     /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2832        ListView seems to handle it internally without DefWinProc */
2833
2834     /* default value first */
2835     ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2836     expect(0, ret);
2837     /* disable */
2838     style = GetWindowLongPtr(hwnd, GWL_STYLE);
2839     ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2840     ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2841     expect(0, ret);
2842     style = GetWindowLongPtr(hwnd, GWL_STYLE);
2843     ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2844     ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2845     expect(0, ret);
2846
2847     /* check update rect after redrawing */
2848     ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2849     expect(0, ret);
2850     InvalidateRect(hwnd, NULL, FALSE);
2851     RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
2852     rect.right = rect.bottom = 1;
2853     GetUpdateRect(hwnd, &rect, FALSE);
2854     expect(0, rect.right);
2855     expect(0, rect.bottom);
2856
2857     /* WM_ERASEBKGND */
2858     hdc = GetWindowDC(hwndparent);
2859     ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2860     expect(TRUE, ret);
2861     ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2862     expect(0, ret);
2863     ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2864     expect(TRUE, ret);
2865     ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2866     expect(0, ret);
2867     ReleaseDC(hwndparent, hdc);
2868
2869     /* check notification messages to show that repainting is disabled */
2870     ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
2871     expect(TRUE, ret);
2872     ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2873     expect(0, ret);
2874     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2875
2876     InvalidateRect(hwnd, NULL, TRUE);
2877     UpdateWindow(hwnd);
2878     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2879                 "redraw after WM_SETREDRAW (FALSE)", FALSE);
2880
2881     ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
2882     expect(TRUE, ret);
2883     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2884     InvalidateRect(hwnd, NULL, TRUE);
2885     UpdateWindow(hwnd);
2886     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2887                 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
2888
2889     /* message isn't forwarded to header */
2890     subclass_header(hwnd);
2891     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2892     ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2893     expect(0, ret);
2894     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
2895                 "WM_SETREDRAW: not forwarded to header", FALSE);
2896
2897     DestroyWindow(hwnd);
2898 }
2899
2900 static void test_hittest(void)
2901 {
2902     HWND hwnd;
2903     DWORD r;
2904     RECT bounds;
2905     LVITEMA item;
2906     static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2907     POINT pos;
2908     INT x, y;
2909     HIMAGELIST himl, himl2;
2910     HBITMAP hbmp;
2911
2912     hwnd = create_listview_control(LVS_REPORT);
2913     ok(hwnd != NULL, "failed to create a listview window\n");
2914
2915     /* LVS_REPORT with a single subitem (2 columns) */
2916     insert_column(hwnd, 0);
2917     insert_column(hwnd, 1);
2918     insert_item(hwnd, 0);
2919
2920     item.iSubItem = 0;
2921     /* the only purpose of that line is to be as long as a half item rect */
2922     item.pszText  = text;
2923     r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2924     expect(TRUE, r);
2925
2926     r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2927     expect(TRUE, r);
2928     r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
2929     expect(TRUE, r);
2930
2931     memset(&bounds, 0, sizeof(bounds));
2932     bounds.left = LVIR_BOUNDS;
2933     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
2934     ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
2935     ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
2936     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
2937     expect(TRUE, r);
2938
2939     /* LVS_EX_FULLROWSELECT not set, no icons attached */
2940
2941     /* outside columns by x position - valid is [0, 199] */
2942     x = -1;
2943     y = pos.y + (bounds.bottom - bounds.top) / 2;
2944     test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
2945     test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
2946
2947     x = pos.x + 50; /* column half width */
2948     y = pos.y + (bounds.bottom - bounds.top) / 2;
2949     test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
2950     test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
2951     x = pos.x + 150; /* outside column */
2952     y = pos.y + (bounds.bottom - bounds.top) / 2;
2953     test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
2954     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
2955     y = (bounds.bottom - bounds.top) / 2;
2956     test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
2957     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
2958     /* outside possible client rectangle (to right) */
2959     x = pos.x + 500;
2960     y = pos.y + (bounds.bottom - bounds.top) / 2;
2961     test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
2962     test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
2963     y = (bounds.bottom - bounds.top) / 2;
2964     test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
2965     test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
2966     /* subitem returned with -1 item too */
2967     x = pos.x + 150;
2968     y = -10;
2969     test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
2970     /* parent client area is 100x100 by default */
2971     MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
2972     x = pos.x + 150; /* outside column */
2973     y = pos.y + (bounds.bottom - bounds.top) / 2;
2974     test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
2975     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
2976     y = (bounds.bottom - bounds.top) / 2;
2977     test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
2978     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
2979     /* the same with LVS_EX_FULLROWSELECT */
2980     SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
2981     x = pos.x + 150; /* outside column */
2982     y = pos.y + (bounds.bottom - bounds.top) / 2;
2983     test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
2984     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
2985     y = (bounds.bottom - bounds.top) / 2;
2986     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
2987     MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
2988     x = pos.x + 150; /* outside column */
2989     y = pos.y + (bounds.bottom - bounds.top) / 2;
2990     test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
2991     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
2992     y = (bounds.bottom - bounds.top) / 2;
2993     test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
2994     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
2995     /* outside possible client rectangle (to right) */
2996     x = pos.x + 500;
2997     y = pos.y + (bounds.bottom - bounds.top) / 2;
2998     test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
2999     test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3000     y = (bounds.bottom - bounds.top) / 2;
3001     test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3002     test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3003     /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3004     himl = ImageList_Create(16, 16, 0, 4, 4);
3005     ok(himl != NULL, "failed to create imagelist\n");
3006     hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3007     ok(hbmp != NULL, "failed to create bitmap\n");
3008     r = ImageList_Add(himl, hbmp, 0);
3009     ok(r == 0, "should be zero\n");
3010     hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3011     ok(hbmp != NULL, "failed to create bitmap\n");
3012     r = ImageList_Add(himl, hbmp, 0);
3013     ok(r == 1, "should be one\n");
3014
3015     r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3016     ok(r == 0, "should return zero\n");
3017
3018     item.mask = LVIF_IMAGE;
3019     item.iImage = 0;
3020     item.iItem = 0;
3021     item.iSubItem = 0;
3022     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3023     expect(TRUE, r);
3024     /* on state icon */
3025     x = pos.x + 8;
3026     y = pos.y + (bounds.bottom - bounds.top) / 2;
3027     test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3028     test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3029     y = (bounds.bottom - bounds.top) / 2;
3030     test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3031
3032     /* state icons indices are 1 based, check with valid index */
3033     item.mask = LVIF_STATE;
3034     item.state = INDEXTOSTATEIMAGEMASK(1);
3035     item.stateMask = LVIS_STATEIMAGEMASK;
3036     item.iItem = 0;
3037     item.iSubItem = 0;
3038     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3039     expect(TRUE, r);
3040     /* on state icon */
3041     x = pos.x + 8;
3042     y = pos.y + (bounds.bottom - bounds.top) / 2;
3043     test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3044     test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3045     y = (bounds.bottom - bounds.top) / 2;
3046     test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3047
3048     himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3049     ok(himl2 == himl, "should return handle\n");
3050
3051     r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3052     ok(r == 0, "should return zero\n");
3053     /* on item icon */
3054     x = pos.x + 8;
3055     y = pos.y + (bounds.bottom - bounds.top) / 2;
3056     test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3057     test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3058     y = (bounds.bottom - bounds.top) / 2;
3059     test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3060
3061     DestroyWindow(hwnd);
3062 }
3063
3064 static void test_getviewrect(void)
3065 {
3066     HWND hwnd;
3067     DWORD r;
3068     RECT rect;
3069     LVITEMA item;
3070
3071     hwnd = create_listview_control(LVS_REPORT);
3072     ok(hwnd != NULL, "failed to create a listview window\n");
3073
3074     /* empty */
3075     r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3076     expect(TRUE, r);
3077
3078     insert_column(hwnd, 0);
3079     insert_column(hwnd, 1);
3080
3081     memset(&item, 0, sizeof(item));
3082     item.iItem = 0;
3083     item.iSubItem = 0;
3084     SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3085
3086     r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3087     expect(TRUE, r);
3088     r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3089     expect(TRUE, r);
3090
3091     rect.left = rect.right = rect.top = rect.bottom = -1;
3092     r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3093     expect(TRUE, r);
3094     /* left is set to (2e31-1) - XP SP2 */
3095     expect(0, rect.right);
3096     expect(0, rect.top);
3097     expect(0, rect.bottom);
3098
3099     /* switch to LVS_ICON */
3100     SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3101
3102     rect.left = rect.right = rect.top = rect.bottom = -1;
3103     r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3104     expect(TRUE, r);
3105     expect(0, rect.left);
3106     expect(0, rect.top);
3107     /* precise value differs for 2k, XP and Vista */
3108     ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3109     ok(rect.right  > 0, "Expected positive right value, got %d\n", rect.right);
3110
3111     DestroyWindow(hwnd);
3112 }
3113
3114 static void test_getitemposition(void)
3115 {
3116     HWND hwnd, header;
3117     DWORD r;
3118     POINT pt;
3119     RECT rect;
3120
3121     hwnd = create_listview_control(LVS_REPORT);
3122     ok(hwnd != NULL, "failed to create a listview window\n");
3123     header = subclass_header(hwnd);
3124
3125     /* LVS_REPORT, single item, no columns added */
3126     insert_item(hwnd, 0);
3127
3128     flush_sequences(sequences, NUM_MSG_SEQUENCES);
3129
3130     pt.x = pt.y = -1;
3131     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3132     expect(TRUE, r);
3133     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3134
3135     /* LVS_REPORT, single item, single column */
3136     insert_column(hwnd, 0);
3137
3138     flush_sequences(sequences, NUM_MSG_SEQUENCES);
3139
3140     pt.x = pt.y = -1;
3141     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3142     expect(TRUE, r);
3143     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3144
3145     memset(&rect, 0, sizeof(rect));
3146     SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3147     /* some padding? */
3148     expect(2, pt.x);
3149     /* offset by header height */
3150     expect(rect.bottom - rect.top, pt.y);
3151
3152     DestroyWindow(hwnd);
3153 }
3154
3155 static void test_columnscreation(void)
3156 {
3157     HWND hwnd, header;
3158     DWORD r;
3159
3160     hwnd = create_listview_control(LVS_REPORT);
3161     ok(hwnd != NULL, "failed to create a listview window\n");
3162
3163     insert_item(hwnd, 0);
3164
3165     /* headers columns aren't created automatically */
3166     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3167     ok(IsWindow(header), "Expected header handle\n");
3168     r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3169     expect(0, r);
3170
3171     DestroyWindow(hwnd);
3172 }
3173
3174 static void test_getitemrect(void)
3175 {
3176     HWND hwnd;
3177     HIMAGELIST himl;
3178     HBITMAP hbm;
3179     RECT rect;
3180     DWORD r;
3181     LVITEMA item;
3182     LVCOLUMNA col;
3183     INT order[2];
3184     POINT pt;
3185
3186     /* rectangle isn't empty for empty text items */
3187     hwnd = create_listview_control(LVS_LIST);
3188     memset(&item, 0, sizeof(item));
3189     item.mask = 0;
3190     item.iItem = 0;
3191     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3192     expect(0, r);
3193     rect.left = LVIR_LABEL;
3194     SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3195     expect(0, rect.left);
3196     expect(0, rect.top);
3197     todo_wine expect(96, rect.right);
3198     DestroyWindow(hwnd);
3199
3200     hwnd = create_listview_control(LVS_REPORT);
3201     ok(hwnd != NULL, "failed to create a listview window\n");
3202
3203     /* empty item */
3204     memset(&item, 0, sizeof(item));
3205     item.iItem = 0;
3206     item.iSubItem = 0;
3207     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3208     expect(0, r);
3209
3210     rect.left = LVIR_BOUNDS;
3211     rect.right = rect.top = rect.bottom = -1;
3212     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3213     expect(TRUE, r);
3214
3215     /* zero width rectangle with no padding */
3216     expect(0, rect.left);
3217     expect(0, rect.right);
3218
3219     insert_column(hwnd, 0);
3220     insert_column(hwnd, 1);
3221
3222     col.mask = LVCF_WIDTH;
3223     col.cx   = 50;
3224     r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3225     expect(TRUE, r);
3226
3227     col.mask = LVCF_WIDTH;
3228     col.cx   = 100;
3229     r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3230     expect(TRUE, r);
3231
3232     rect.left = LVIR_BOUNDS;
3233     rect.right = rect.top = rect.bottom = -1;
3234     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3235     expect(TRUE, r);
3236
3237     /* still no left padding */
3238     expect(0, rect.left);
3239     expect(150, rect.right);
3240
3241     rect.left = LVIR_SELECTBOUNDS;
3242     rect.right = rect.top = rect.bottom = -1;
3243     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3244     expect(TRUE, r);
3245     /* padding */
3246     expect(2, rect.left);
3247
3248     rect.left = LVIR_LABEL;
3249     rect.right = rect.top = rect.bottom = -1;
3250     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3251     expect(TRUE, r);
3252     /* padding, column width */
3253     expect(2, rect.left);
3254     expect(50, rect.right);
3255
3256     /* no icons attached */
3257     rect.left = LVIR_ICON;
3258     rect.right = rect.top = rect.bottom = -1;
3259     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3260     expect(TRUE, r);
3261     /* padding */
3262     expect(2, rect.left);
3263     expect(2, rect.right);
3264
3265     /* change order */
3266     order[0] = 1; order[1] = 0;
3267     r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3268     expect(TRUE, r);
3269     pt.x = -1;
3270     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3271     expect(TRUE, r);
3272     /* 1 indexed column width + padding */
3273     expect(102, pt.x);
3274     /* rect is at zero too */
3275     rect.left = LVIR_BOUNDS;
3276     rect.right = rect.top = rect.bottom = -1;
3277     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3278     expect(TRUE, r);
3279     expect(0, rect.left);
3280     /* just width sum */
3281     expect(150, rect.right);
3282
3283     rect.left = LVIR_SELECTBOUNDS;
3284     rect.right = rect.top = rect.bottom = -1;
3285     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3286     expect(TRUE, r);
3287     /* column width + padding */
3288     expect(102, rect.left);
3289
3290     /* back to initial order */
3291     order[0] = 0; order[1] = 1;
3292     r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3293     expect(TRUE, r);
3294
3295     /* state icons */
3296     himl = ImageList_Create(16, 16, 0, 2, 2);
3297     ok(himl != NULL, "failed to create imagelist\n");
3298     hbm = CreateBitmap(16, 16, 1, 1, NULL);
3299     ok(hbm != NULL, "failed to create bitmap\n");
3300     r = ImageList_Add(himl, hbm, 0);
3301     ok(r == 0, "should be zero\n");
3302     hbm = CreateBitmap(16, 16, 1, 1, NULL);
3303     ok(hbm != NULL, "failed to create bitmap\n");
3304     r = ImageList_Add(himl, hbm, 0);
3305     ok(r == 1, "should be one\n");
3306
3307     r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3308     ok(r == 0, "should return zero\n");
3309
3310     item.mask = LVIF_STATE;
3311     item.state = INDEXTOSTATEIMAGEMASK(1);
3312     item.stateMask = LVIS_STATEIMAGEMASK;
3313     item.iItem = 0;
3314     item.iSubItem = 0;
3315     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3316     expect(TRUE, r);
3317
3318     /* icon bounds */
3319     rect.left = LVIR_ICON;
3320     rect.right = rect.top = rect.bottom = -1;
3321     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3322     expect(TRUE, r);
3323     /* padding + stateicon width */
3324     expect(18, rect.left);
3325     expect(18, rect.right);
3326     /* label bounds */
3327     rect.left = LVIR_LABEL;
3328     rect.right = rect.top = rect.bottom = -1;
3329     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3330     expect(TRUE, r);
3331     /* padding + stateicon width -> column width */
3332     expect(18, rect.left);
3333     expect(50, rect.right);
3334
3335     r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3336     ok(r != 0, "should return current list handle\n");
3337
3338     r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3339     ok(r == 0, "should return zero\n");
3340
3341     item.mask = LVIF_STATE | LVIF_IMAGE;
3342     item.iImage = 1;
3343     item.state = 0;
3344     item.stateMask = ~0;
3345     item.iItem = 0;
3346     item.iSubItem = 0;
3347     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3348     expect(TRUE, r);
3349
3350     /* icon bounds */
3351     rect.left = LVIR_ICON;
3352     rect.right = rect.top = rect.bottom = -1;
3353     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3354     expect(TRUE, r);
3355     /* padding, icon width */
3356     expect(2, rect.left);
3357     expect(18, rect.right);
3358     /* label bounds */
3359     rect.left = LVIR_LABEL;
3360     rect.right = rect.top = rect.bottom = -1;
3361     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3362     expect(TRUE, r);
3363     /* padding + icon width -> column width */
3364     expect(18, rect.left);
3365     expect(50, rect.right);
3366
3367     /* select bounds */
3368     rect.left = LVIR_SELECTBOUNDS;
3369     rect.right = rect.top = rect.bottom = -1;
3370     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3371     expect(TRUE, r);
3372     /* padding, column width */
3373     expect(2, rect.left);
3374     expect(50, rect.right);
3375
3376     /* try with indentation */
3377     item.mask = LVIF_INDENT;
3378     item.iIndent = 1;
3379     item.iItem = 0;
3380     item.iSubItem = 0;
3381     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3382     expect(TRUE, r);
3383
3384     /* bounds */
3385     rect.left = LVIR_BOUNDS;
3386     rect.right = rect.top = rect.bottom = -1;
3387     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3388     expect(TRUE, r);
3389     /* padding + 1 icon width, column width */
3390     expect(0, rect.left);
3391     expect(150, rect.right);
3392
3393     /* select bounds */
3394     rect.left = LVIR_SELECTBOUNDS;
3395     rect.right = rect.top = rect.bottom = -1;
3396     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3397     expect(TRUE, r);
3398     /* padding + 1 icon width, column width */
3399     expect(2 + 16, rect.left);
3400     expect(50, rect.right);
3401
3402     /* label bounds */
3403     rect.left = LVIR_LABEL;
3404     rect.right = rect.top = rect.bottom = -1;
3405     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3406     expect(TRUE, r);
3407     /* padding + 2 icon widths, column width */
3408     expect(2 + 16*2, rect.left);
3409     expect(50, rect.right);
3410
3411     /* icon bounds */
3412     rect.left = LVIR_ICON;
3413     rect.right = rect.top = rect.bottom = -1;
3414     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3415     expect(TRUE, r);
3416     /* padding + 1 icon width indentation, icon width */
3417     expect(2 + 16, rect.left);
3418     expect(34, rect.right);
3419
3420     DestroyWindow(hwnd);
3421 }
3422
3423 static void test_editbox(void)
3424 {
3425     static CHAR testitemA[]  = "testitem";
3426     static CHAR testitem1A[] = "testitem_quitelongname";
3427     static CHAR buffer[25];
3428     HWND hwnd, hwndedit, hwndedit2, header;
3429     LVITEMA item;
3430     DWORD r;
3431
3432     hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3433     ok(hwnd != NULL, "failed to create a listview window\n");
3434
3435     insert_column(hwnd, 0);
3436
3437     memset(&item, 0, sizeof(item));
3438     item.mask = LVIF_TEXT;
3439     item.pszText = testitemA;
3440     item.iItem = 0;
3441     item.iSubItem = 0;
3442     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3443     expect(0, r);
3444
3445     /* setting focus is necessary */
3446     SetFocus(hwnd);
3447     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3448     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3449
3450     /* test children Z-order after Edit box created */
3451     header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3452     ok(IsWindow(header), "Expected header to be created\n");
3453     ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3454     ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3455
3456     /* modify initial string */
3457     r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3458     expect(TRUE, r);
3459
3460     /* edit window is resized and repositioned,
3461        check again for Z-order - it should be preserved */
3462     ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3463     ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3464
3465     /* return focus to listview */
3466     SetFocus(hwnd);
3467
3468     memset(&item, 0, sizeof(item));
3469     item.mask = LVIF_TEXT;
3470     item.pszText = buffer;
3471     item.cchTextMax = sizeof(buffer);
3472     item.iItem = 0;
3473     item.iSubItem = 0;
3474     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3475     expect(TRUE, r);
3476
3477     ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3478
3479     /* send LVM_EDITLABEL on already created edit */
3480     SetFocus(hwnd);
3481     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3482     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3483     /* focus will be set to edit */
3484     ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3485     hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3486     ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3487
3488     /* creating label disabled when control isn't focused */
3489     SetFocus(0);
3490     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3491     todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3492
3493     /* check EN_KILLFOCUS handling */
3494     memset(&item, 0, sizeof(item));
3495     item.pszText = testitemA;
3496     item.iItem = 0;
3497     item.iSubItem = 0;
3498     r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3499     expect(TRUE, r);
3500
3501     SetFocus(hwnd);
3502     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3503     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3504     /* modify edit and notify control that it lost focus */
3505     r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3506     expect(TRUE, r);
3507     r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3508     expect(0, r);
3509     memset(&item, 0, sizeof(item));
3510     item.pszText = buffer;
3511     item.cchTextMax = sizeof(buffer);
3512     item.iItem = 0;
3513     item.iSubItem = 0;
3514     r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3515     expect(lstrlen(item.pszText), r);
3516     ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3517     ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
3518     /* end edit without saving */
3519     SetFocus(hwnd);
3520     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3521     flush_sequences(sequences, NUM_MSG_SEQUENCES);
3522     r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3523     expect(0, r);
3524     ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3525                 "edit box - end edit, no change, escape", TRUE);
3526     /* end edit with saving */
3527     SetFocus(hwnd);
3528     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3529     flush_sequences(sequences, NUM_MSG_SEQUENCES);
3530     r = SendMessage(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
3531     expect(0, r);
3532     ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3533                 "edit box - end edit, no change, return", TRUE);
3534
3535     memset(&item, 0, sizeof(item));
3536     item.pszText = buffer;
3537     item.cchTextMax = sizeof(buffer);
3538     item.iItem = 0;
3539     item.iSubItem = 0;
3540     r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3541     expect(lstrlen(item.pszText), r);
3542     ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3543
3544     /* LVM_EDITLABEL with -1 destroys current edit */
3545     hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3546     ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3547     /* no edit present */
3548     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3549     ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3550     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3551     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3552     /* edit present */
3553     ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3554     hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3555     ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3556     ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3557     ok(GetFocus() == hwnd, "Expected List to be focused\n");
3558     /* check another negative value */
3559     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3560     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3561     ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3562     hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3563     ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3564     ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3565     ok(GetFocus() == hwnd, "Expected List to be focused\n");
3566     /* and value greater than max item index */
3567     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3568     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3569     ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3570     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3571     hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3572     ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3573     ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3574     ok(GetFocus() == hwnd, "Expected List to be focused\n");
3575
3576     /* messaging tests */
3577     SetFocus(hwnd);
3578     flush_sequences(sequences, NUM_MSG_SEQUENCES);
3579     blockEdit = FALSE;
3580     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3581     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3582     /* testing only sizing messages */
3583     ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3584                 "edit box create - sizing", FALSE);
3585
3586     /* WM_COMMAND with EN_KILLFOCUS isn't forwared to parent */
3587     SetFocus(hwnd);
3588     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3589     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3590     flush_sequences(sequences, NUM_MSG_SEQUENCES);
3591     r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3592     expect(0, r);
3593     ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3594                 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
3595
3596     DestroyWindow(hwnd);
3597 }
3598
3599 static void test_notifyformat(void)
3600 {
3601     HWND hwnd, header;
3602     DWORD r;
3603
3604     hwnd = create_listview_control(LVS_REPORT);
3605     ok(hwnd != NULL, "failed to create a listview window\n");
3606
3607     /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3608        CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3609     r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3610     expect(0, r);
3611     r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3612     /* set */
3613     r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3614     expect(0, r);
3615     r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3616     if (r == 1)
3617     {
3618         r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3619         expect(1, r);
3620         r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3621         expect(0, r);
3622     }
3623     else
3624     {
3625         win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3626         DestroyWindow(hwnd);
3627         return;
3628     }
3629
3630     DestroyWindow(hwnd);
3631
3632     /* test failure in parent WM_NOTIFYFORMAT  */
3633     notifyFormat = 0;
3634     hwnd = create_listview_control(LVS_REPORT);
3635     ok(hwnd != NULL, "failed to create a listview window\n");
3636     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3637     ok(IsWindow(header), "expected header to be created\n");
3638     r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3639     expect(0, r);
3640     r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3641     ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3642     r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3643     ok(r != 0, "Expected valid format\n");
3644
3645     notifyFormat = NFR_UNICODE;
3646     r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3647     expect(NFR_UNICODE, r);
3648     r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3649     expect(1, r);
3650     r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3651     ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3652
3653     notifyFormat = NFR_ANSI;
3654     r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3655     expect(NFR_ANSI, r);
3656     r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3657     expect(0, r);
3658     r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3659     ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3660
3661     DestroyWindow(hwnd);
3662
3663     /* try different unicode window combination and defaults */
3664     if (!GetModuleHandleW(NULL))
3665     {
3666         win_skip("Additional notify format tests are incompatible with Win9x\n");
3667         return;
3668     }
3669
3670     hwndparentW = create_parent_window(TRUE);
3671     ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3672     if (!IsWindow(hwndparentW))  return;
3673
3674     notifyFormat = -1;
3675     hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3676     ok(hwnd != NULL, "failed to create a listview window\n");
3677     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3678     ok(IsWindow(header), "expected header to be created\n");
3679     r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3680     expect(1, r);
3681     r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3682     expect(1, r);
3683     DestroyWindow(hwnd);
3684     /* receiving error code defaulting to ansi */
3685     notifyFormat = 0;
3686     hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3687     ok(hwnd != NULL, "failed to create a listview window\n");
3688     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3689     ok(IsWindow(header), "expected header to be created\n");
3690     r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3691     expect(0, r);
3692     r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3693     expect(1, r);
3694     DestroyWindow(hwnd);
3695     /* receiving ansi code from unicode window, use it */
3696     notifyFormat = NFR_ANSI;
3697     hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3698     ok(hwnd != NULL, "failed to create a listview window\n");
3699     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3700     ok(IsWindow(header), "expected header to be created\n");
3701     r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3702     expect(0, r);
3703     r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3704     expect(1, r);
3705     DestroyWindow(hwnd);
3706     /* unicode listview with ansi parent window */
3707     notifyFormat = -1;
3708     hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3709     ok(hwnd != NULL, "failed to create a listview window\n");
3710     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3711     ok(IsWindow(header), "expected header to be created\n");
3712     r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3713     expect(0, r);
3714     r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3715     expect(1, r);
3716     DestroyWindow(hwnd);
3717     /* unicode listview with ansi parent window, return error code */
3718     notifyFormat = 0;
3719     hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3720     ok(hwnd != NULL, "failed to create a listview window\n");
3721     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3722     ok(IsWindow(header), "expected header to be created\n");
3723     r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3724     expect(0, r);
3725     r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3726     expect(1, r);
3727     DestroyWindow(hwnd);
3728
3729     DestroyWindow(hwndparentW);
3730 }
3731
3732 static void test_indentation(void)
3733 {
3734     HWND hwnd;
3735     LVITEMA item;
3736     DWORD r;
3737
3738     hwnd = create_listview_control(LVS_REPORT);
3739     ok(hwnd != NULL, "failed to create a listview window\n");
3740
3741     memset(&item, 0, sizeof(item));
3742     item.mask = LVIF_INDENT;
3743     item.iItem = 0;
3744     item.iIndent = I_INDENTCALLBACK;
3745     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3746     expect(0, r);
3747
3748     flush_sequences(sequences, NUM_MSG_SEQUENCES);
3749
3750     item.iItem = 0;
3751     item.mask = LVIF_INDENT;
3752     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3753     expect(TRUE, r);
3754
3755     ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3756                 "get indent dispinfo", FALSE);
3757
3758     DestroyWindow(hwnd);
3759 }
3760
3761 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
3762 {
3763     return 0;
3764 }
3765
3766 static BOOL is_below_comctl_5(void)
3767 {
3768     HWND hwnd;
3769     BOOL ret;
3770
3771     hwnd = create_listview_control(LVS_REPORT);
3772     ok(hwnd != NULL, "failed to create a listview window\n");
3773     insert_item(hwnd, 0);
3774
3775     ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
3776
3777     DestroyWindow(hwnd);
3778
3779     return !ret;
3780 }
3781
3782 static void test_get_set_view(void)
3783 {
3784     HWND hwnd;
3785     DWORD ret;
3786     DWORD_PTR style;
3787
3788     /* test style->view mapping */
3789     hwnd = create_listview_control(LVS_REPORT);
3790     ok(hwnd != NULL, "failed to create a listview window\n");
3791
3792     ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3793     expect(LV_VIEW_DETAILS, ret);
3794
3795     style = GetWindowLongPtr(hwnd, GWL_STYLE);
3796     /* LVS_ICON == 0 */
3797     SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
3798     ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3799     expect(LV_VIEW_ICON, ret);
3800
3801     style = GetWindowLongPtr(hwnd, GWL_STYLE);
3802     SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
3803     ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3804     expect(LV_VIEW_SMALLICON, ret);
3805
3806     style = GetWindowLongPtr(hwnd, GWL_STYLE);
3807     SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
3808     ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3809     expect(LV_VIEW_LIST, ret);
3810
3811     /* switching view doesn't touch window style */
3812     ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
3813     expect(1, ret);
3814     style = GetWindowLongPtr(hwnd, GWL_STYLE);
3815     ok(style & LVS_LIST, "Expected style to be preserved\n");
3816     ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
3817     expect(1, ret);
3818     style = GetWindowLongPtr(hwnd, GWL_STYLE);
3819     ok(style & LVS_LIST, "Expected style to be preserved\n");
3820     ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
3821     expect(1, ret);
3822     style = GetWindowLongPtr(hwnd, GWL_STYLE);
3823     ok(style & LVS_LIST, "Expected style to be preserved\n");
3824
3825     DestroyWindow(hwnd);
3826 }
3827
3828 static void test_canceleditlabel(void)
3829 {
3830     HWND hwnd, hwndedit;
3831     DWORD ret;
3832     CHAR buff[10];
3833     LVITEMA itema;
3834     static CHAR test[] = "test";
3835     static const CHAR test1[] = "test1";
3836
3837     hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3838     ok(hwnd != NULL, "failed to create a listview window\n");
3839
3840     insert_item(hwnd, 0);
3841
3842     /* try without edit created */
3843     flush_sequences(sequences, NUM_MSG_SEQUENCES);
3844     ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3845     expect(TRUE, ret);
3846     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3847                 "cancel edit label without edit", FALSE);
3848
3849     /* cancel without data change */
3850     SetFocus(hwnd);
3851     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3852     ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3853     ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3854     expect(TRUE, ret);
3855     ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3856
3857     /* cancel after data change */
3858     memset(&itema, 0, sizeof(itema));
3859     itema.pszText = test;
3860     ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
3861     expect(TRUE, ret);
3862     SetFocus(hwnd);
3863     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3864     ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3865     ret = SetWindowText(hwndedit, test1);
3866     ok(ret != 0, "Expected edit text to change\n");
3867     ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3868     expect(TRUE, ret);
3869     ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3870     memset(&itema, 0, sizeof(itema));
3871     itema.pszText = buff;
3872     itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
3873     ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
3874     expect(5, ret);
3875     ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
3876
3877     DestroyWindow(hwnd);
3878 }
3879
3880 static void test_mapidindex(void)
3881 {
3882     HWND hwnd;
3883     DWORD ret;
3884
3885     /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3886     hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3887     ok(hwnd != NULL, "failed to create a listview window\n");
3888     insert_item(hwnd, 0);
3889     ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3890     expect(-1, ret);
3891     DestroyWindow(hwnd);
3892
3893     hwnd = create_listview_control(LVS_REPORT);
3894     ok(hwnd != NULL, "failed to create a listview window\n");
3895
3896     /* LVM_MAPINDEXTOID with invalid index */
3897     ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3898     expect(-1, ret);
3899
3900     insert_item(hwnd, 0);
3901     insert_item(hwnd, 1);
3902
3903     ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
3904     expect(-1, ret);
3905     ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
3906     expect(-1, ret);
3907
3908     ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3909     expect(0, ret);
3910     ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3911     expect(1, ret);
3912     /* remove 0 indexed item, id retained */
3913     SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
3914     ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3915     expect(1, ret);
3916     /* new id starts from previous value */
3917     insert_item(hwnd, 1);
3918     ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3919     expect(2, ret);
3920
3921     /* get index by id */
3922     ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
3923     expect(-1, ret);
3924     ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
3925     expect(-1, ret);
3926     ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
3927     expect(0, ret);
3928     ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
3929     expect(1, ret);
3930
3931     DestroyWindow(hwnd);
3932 }
3933
3934 static void test_getitemspacing(void)
3935 {
3936     HWND hwnd;
3937     DWORD ret;
3938     INT cx, cy;
3939     HIMAGELIST himl;
3940     HBITMAP hbmp;
3941     LVITEMA itema;
3942
3943     cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
3944     cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
3945
3946     /* LVS_ICON */
3947     hwnd = create_listview_control(LVS_ICON);
3948     ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3949 todo_wine {
3950     expect(cx, LOWORD(ret));
3951     expect(cy, HIWORD(ret));
3952 }
3953     /* now try with icons */
3954     himl = ImageList_Create(40, 40, 0, 4, 4);
3955     ok(himl != NULL, "failed to create imagelist\n");
3956     hbmp = CreateBitmap(40, 40, 1, 1, NULL);
3957     ok(hbmp != NULL, "failed to create bitmap\n");
3958     ret = ImageList_Add(himl, hbmp, 0);
3959     expect(0, ret);
3960     ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
3961     expect(0, ret);
3962
3963     itema.mask = LVIF_IMAGE;
3964     itema.iImage = 0;
3965     itema.iItem = 0;
3966     itema.iSubItem = 0;
3967     ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
3968     expect(0, ret);
3969     ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3970 todo_wine {
3971     /* spacing + icon size returned */
3972     expect(cx + 40, LOWORD(ret));
3973     expect(cy + 40, HIWORD(ret));
3974 }
3975     DestroyWindow(hwnd);
3976     /* LVS_SMALLICON */
3977     hwnd = create_listview_control(LVS_SMALLICON);
3978     ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3979 todo_wine {
3980     expect(cx, LOWORD(ret));
3981     expect(cy, HIWORD(ret));
3982 }
3983     DestroyWindow(hwnd);
3984     /* LVS_REPORT */
3985     hwnd = create_listview_control(LVS_REPORT);
3986     ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3987 todo_wine {
3988     expect(cx, LOWORD(ret));
3989     expect(cy, HIWORD(ret));
3990 }
3991     DestroyWindow(hwnd);
3992     /* LVS_LIST */
3993     hwnd = create_listview_control(LVS_LIST);
3994     ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3995 todo_wine {
3996     expect(cx, LOWORD(ret));
3997     expect(cy, HIWORD(ret));
3998 }
3999     DestroyWindow(hwnd);
4000 }
4001
4002 static void test_getcolumnwidth(void)
4003 {
4004     HWND hwnd;
4005     DWORD ret;
4006     DWORD_PTR style;
4007     LVCOLUMNA col;
4008     LVITEMA itema;
4009
4010     /* default column width */
4011     hwnd = create_listview_control(LVS_ICON);
4012     ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4013     expect(0, ret);
4014     style = GetWindowLong(hwnd, GWL_STYLE);
4015     SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
4016     ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4017     todo_wine expect(8, ret);
4018     style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
4019     SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
4020     col.mask = 0;
4021     ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4022     expect(0, ret);
4023     ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4024     expect(10, ret);
4025     DestroyWindow(hwnd);
4026
4027     /* default column width with item added */
4028     hwnd = create_listview_control(LVS_LIST);
4029     memset(&itema, 0, sizeof(itema));
4030     SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4031     ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4032     todo_wine expect(96, ret);
4033     DestroyWindow(hwnd);
4034 }
4035
4036 static void test_scrollnotify(void)
4037 {
4038     HWND hwnd;
4039     DWORD ret;
4040
4041     hwnd = create_listview_control(LVS_REPORT);
4042
4043     insert_column(hwnd, 0);
4044     insert_column(hwnd, 1);
4045     insert_item(hwnd, 0);
4046
4047     /* make it scrollable - resize */
4048     ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4049     expect(TRUE, ret);
4050     ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4051     expect(TRUE, ret);
4052
4053     /* try with dummy call */
4054     flush_sequences(sequences, NUM_MSG_SEQUENCES);
4055     ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
4056     expect(TRUE, ret);
4057     ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4058                 "scroll notify 1", TRUE);
4059
4060     flush_sequences(sequences, NUM_MSG_SEQUENCES);
4061     ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
4062     expect(TRUE, ret);
4063     ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4064                 "scroll notify 2", TRUE);
4065
4066     flush_sequences(sequences, NUM_MSG_SEQUENCES);
4067     ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4068     expect(TRUE, ret);
4069     ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4070                 "scroll notify 3", TRUE);
4071
4072     DestroyWindow(hwnd);
4073 }
4074
4075 static void test_LVS_EX_TRANSPARENTBKGND(void)
4076 {
4077     HWND hwnd;
4078     DWORD ret;
4079     HDC hdc;
4080
4081     hwnd = create_listview_control(LVS_REPORT);
4082
4083     ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4084     expect(TRUE, ret);
4085
4086     SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4087                                                     LVS_EX_TRANSPARENTBKGND);
4088
4089     ret = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
4090     if (ret != CLR_NONE)
4091     {
4092         win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4093         DestroyWindow(hwnd);
4094         return;
4095     }
4096
4097     /* try to set some back color and check this style bit */
4098     ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4099     expect(TRUE, ret);
4100     ret = SendMessage(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4101     ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4102
4103     /* now test what this style actually does */
4104     SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4105                                                     LVS_EX_TRANSPARENTBKGND);
4106
4107     hdc = GetWindowDC(hwndparent);
4108
4109     flush_sequences(sequences, NUM_MSG_SEQUENCES);
4110     SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4111     ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4112                 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4113
4114     ReleaseDC(hwndparent, hdc);
4115
4116     DestroyWindow(hwnd);
4117 }
4118
4119 static void test_approximate_viewrect(void)
4120 {
4121     HWND hwnd;
4122     DWORD ret;
4123     HIMAGELIST himl;
4124     HBITMAP hbmp;
4125     LVITEMA itema;
4126     static CHAR test[] = "abracadabra, a very long item label";
4127
4128     hwnd = create_listview_control(LVS_ICON);
4129     himl = ImageList_Create(40, 40, 0, 4, 4);
4130     ok(himl != NULL, "failed to create imagelist\n");
4131     hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4132     ok(hbmp != NULL, "failed to create bitmap\n");
4133     ret = ImageList_Add(himl, hbmp, 0);
4134     expect(0, ret);
4135     ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4136     expect(0, ret);
4137
4138     itema.mask = LVIF_IMAGE;
4139     itema.iImage = 0;
4140     itema.iItem = 0;
4141     itema.iSubItem = 0;
4142     ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4143     expect(0, ret);
4144
4145     ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4146     if (ret == 0)
4147     {
4148         /* version 4.0 */
4149         win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4150         return;
4151     }
4152
4153     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4154     ok(MAKELONG(77,827)==ret,"Incorrect Approximate rect\n");
4155
4156     ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4157     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4158     ok(MAKELONG(102,302)==ret,"Incorrect Approximate rect\n");
4159
4160     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4161     ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4162
4163     itema.pszText = test;
4164     ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4165     expect(TRUE, ret);
4166     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4167     ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4168
4169     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4170     ok(MAKELONG(52,2)==ret,"Incorrect Approximate rect\n");
4171     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4172     ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4173     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4174     ok(MAKELONG(102,52)==ret,"Incorrect Approximate rect\n");
4175     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4176     ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4177     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4178     ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4179     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4180     ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4181     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4182     ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4183     ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4184     ok(MAKELONG(152,152)==ret,"Incorrect Approximate rect\n");
4185
4186     DestroyWindow(hwnd);
4187 }
4188
4189 static void test_finditem(void)
4190 {
4191     LVFINDINFOA fi;
4192     static char f[5];
4193     HWND hwnd;
4194     DWORD r;
4195
4196     hwnd = create_listview_control(LVS_REPORT);
4197     insert_item(hwnd, 0);
4198
4199     memset(&fi, 0, sizeof(fi));
4200
4201     /* full string search, inserted text was "foo" */
4202     strcpy(f, "foo");
4203     fi.flags = LVFI_STRING;
4204     fi.psz = f;
4205     r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4206     expect(0, r);
4207     /* partial string search, inserted text was "foo" */
4208     strcpy(f, "fo");
4209     fi.flags = LVFI_STRING | LVFI_PARTIAL;
4210     fi.psz = f;
4211     r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4212     expect(0, r);
4213     /* partial string search, part after start char */
4214     strcpy(f, "oo");
4215     fi.flags = LVFI_STRING | LVFI_PARTIAL;
4216     fi.psz = f;
4217     r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4218     expect(-1, r);
4219
4220     /* try with LVFI_SUBSTRING */
4221     strcpy(f, "fo");
4222     fi.flags = LVFI_SUBSTRING;
4223     fi.psz = f;
4224     r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4225     if (r == -1)
4226     {
4227         win_skip("LVFI_SUBSTRING not supported\n");
4228         DestroyWindow(hwnd);
4229         return;
4230     }
4231     expect(0, r);
4232     strcpy(f, "f");
4233     fi.flags = LVFI_SUBSTRING;
4234     fi.psz = f;
4235     r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4236     expect(0, r);
4237     strcpy(f, "o");
4238     fi.flags = LVFI_SUBSTRING;
4239     fi.psz = f;
4240     r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4241     expect(-1, r);
4242
4243     strcpy(f, "f");
4244     fi.flags = LVFI_SUBSTRING | LVFI_STRING;
4245     fi.psz = f;
4246     r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4247     expect(0, r);
4248
4249     DestroyWindow(hwnd);
4250 }
4251
4252 static void test_LVS_EX_HEADERINALLVIEWS(void)
4253 {
4254     HWND hwnd, header;
4255     DWORD style;
4256
4257     hwnd = create_listview_control(LVS_ICON);
4258
4259     SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4260                                                     LVS_EX_HEADERINALLVIEWS);
4261
4262     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4263     if (!IsWindow(header))
4264     {
4265         win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4266         DestroyWindow(hwnd);
4267         return;
4268     }
4269
4270     /* LVS_NOCOLUMNHEADER works as before */
4271     style = GetWindowLongA(hwnd, GWL_STYLE);
4272     SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
4273     style = GetWindowLongA(header, GWL_STYLE);
4274     ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
4275     style = GetWindowLongA(hwnd, GWL_STYLE);
4276     SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
4277     style = GetWindowLongA(header, GWL_STYLE);
4278     ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
4279
4280     /* try to remove style */
4281     SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
4282     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4283     ok(IsWindow(header), "Expected header to be created\n");
4284     style = GetWindowLongA(header, GWL_STYLE);
4285     ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
4286
4287     DestroyWindow(hwnd);
4288
4289     /* check other styles */
4290     hwnd = create_listview_control(LVS_LIST);
4291     SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4292                                                     LVS_EX_HEADERINALLVIEWS);
4293     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4294     ok(IsWindow(header), "Expected header to be created\n");
4295     DestroyWindow(hwnd);
4296
4297     hwnd = create_listview_control(LVS_SMALLICON);
4298     SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4299                                                     LVS_EX_HEADERINALLVIEWS);
4300     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4301     ok(IsWindow(header), "Expected header to be created\n");
4302     DestroyWindow(hwnd);
4303
4304     hwnd = create_listview_control(LVS_REPORT);
4305     SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4306                                                     LVS_EX_HEADERINALLVIEWS);
4307     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4308     ok(IsWindow(header), "Expected header to be created\n");
4309     DestroyWindow(hwnd);
4310 }
4311
4312 static void test_hover(void)
4313 {
4314     HWND hwnd;
4315     DWORD r;
4316
4317     hwnd = create_listview_control(LVS_ICON);
4318
4319     /* test WM_MOUSEHOVER forwarding */
4320     flush_sequences(sequences, NUM_MSG_SEQUENCES);
4321     r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4322     expect(0, r);
4323     ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
4324     g_block_hover = TRUE;
4325     flush_sequences(sequences, NUM_MSG_SEQUENCES);
4326     r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4327     expect(0, r);
4328     ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
4329     g_block_hover = FALSE;
4330
4331     r = SendMessage(hwnd, LVM_SETHOVERTIME, 0, 500);
4332     expect(HOVER_DEFAULT, r);
4333     r = SendMessage(hwnd, LVM_GETHOVERTIME, 0, 0);
4334     expect(500, r);
4335
4336     DestroyWindow(hwnd);
4337 }
4338
4339 static void test_destroynotify(void)
4340 {
4341     HWND hwnd;
4342
4343     hwnd = create_listview_control(LVS_REPORT);
4344     ok(hwnd != NULL, "failed to create listview window\n");
4345
4346     flush_sequences(sequences, NUM_MSG_SEQUENCES);
4347     DestroyWindow(hwnd);
4348     ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
4349 }
4350
4351 static void test_header_notification(void)
4352 {
4353     HWND list, header;
4354     HDITEMA item;
4355     NMHEADER nmh;
4356     LVCOLUMNA col;
4357     LRESULT ret;
4358
4359     list = create_listview_control(LVS_REPORT);
4360     ok(list != 0, "failed to create listview window\n");
4361
4362     memset(&col, 0, sizeof(col));
4363     col.mask = LVCF_WIDTH;
4364     col.cx = 100;
4365     ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4366     ok(!ret, "expected 0, got %ld\n", ret);
4367
4368     header = subclass_header(list);
4369
4370     ret = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
4371     ok(ret == 1, "expected header item count 1, got %ld\n", ret);
4372
4373     memset(&item, 0, sizeof(item));
4374     item.mask = HDI_WIDTH;
4375     ret = SendMessage(header, HDM_GETITEMA, 0, (LPARAM)&item);
4376     ok(ret, "HDM_GETITEM failed\n");
4377     ok(item.cxy == 100, "expected 100, got %d\n", item.cxy);
4378
4379     nmh.hdr.hwndFrom = header;
4380     nmh.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
4381     nmh.hdr.code = HDN_ITEMCHANGEDA;
4382     nmh.iItem = 0;
4383     nmh.iButton = 0;
4384     item.mask = HDI_WIDTH;
4385     item.cxy = 50;
4386     nmh.pitem = &item;
4387     ret = SendMessage(list, WM_NOTIFY, 0, (LPARAM)&nmh);
4388     ok(!ret, "WM_NOTIFY/HDN_ITEMCHANGED failed\n");
4389
4390     DestroyWindow(list);
4391 }
4392
4393 static void test_createdragimage(void)
4394 {
4395     HIMAGELIST himl;
4396     POINT pt;
4397     HWND list;
4398
4399     list = create_listview_control(LVS_ICON);
4400     ok(list != 0, "failed to create listview window\n");
4401
4402     insert_item(list, 0);
4403
4404     /* NULL point */
4405     himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
4406     ok(himl == NULL, "got %p\n", himl);
4407
4408     himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
4409     ok(himl != NULL, "got %p\n", himl);
4410     ImageList_Destroy(himl);
4411
4412     DestroyWindow(list);
4413 }
4414
4415 START_TEST(listview)
4416 {
4417     HMODULE hComctl32;
4418     BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
4419
4420     ULONG_PTR ctx_cookie;
4421     HANDLE hCtx;
4422     HWND hwnd;
4423
4424     hComctl32 = GetModuleHandleA("comctl32.dll");
4425     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
4426     if (pInitCommonControlsEx)
4427     {
4428         INITCOMMONCONTROLSEX iccex;
4429         iccex.dwSize = sizeof(iccex);
4430         iccex.dwICC  = ICC_LISTVIEW_CLASSES;
4431         pInitCommonControlsEx(&iccex);
4432     }
4433     else
4434         InitCommonControls();
4435
4436     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
4437
4438     hwndparent = create_parent_window(FALSE);
4439     flush_sequences(sequences, NUM_MSG_SEQUENCES);
4440
4441     g_is_below_5 = is_below_comctl_5();
4442
4443     test_header_notification();
4444     test_images();
4445     test_checkboxes();
4446     test_items();
4447     test_create();
4448     test_redraw();
4449     test_customdraw();
4450     test_icon_spacing();
4451     test_color();
4452     test_item_count();
4453     test_item_position();
4454     test_columns();
4455     test_getorigin();
4456     test_multiselect();
4457     test_getitemrect();
4458     test_subitem_rect();
4459     test_sorting();
4460     test_ownerdata();
4461     test_norecompute();
4462     test_nosortheader();
4463     test_setredraw();
4464     test_hittest();
4465     test_getviewrect();
4466     test_getitemposition();
4467     test_columnscreation();
4468     test_editbox();
4469     test_notifyformat();
4470     test_indentation();
4471     test_getitemspacing();
4472     test_getcolumnwidth();
4473     test_approximate_viewrect();
4474     test_finditem();
4475     test_hover();
4476     test_destroynotify();
4477     test_createdragimage();
4478
4479     if (!load_v6_module(&ctx_cookie, &hCtx))
4480     {
4481         DestroyWindow(hwndparent);
4482         return;
4483     }
4484
4485     /* this is a XP SP3 failure workaround */
4486     hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
4487                            WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
4488                            0, 0, 100, 100,
4489                            hwndparent, NULL, GetModuleHandleA(NULL), NULL);
4490     if (!IsWindow(hwnd))
4491     {
4492         win_skip("FIXME: failed to create ListView window.\n");
4493         unload_v6_module(ctx_cookie, hCtx);
4494         DestroyWindow(hwndparent);
4495         return;
4496     }
4497     else
4498         DestroyWindow(hwnd);
4499
4500     /* comctl32 version 6 tests start here */
4501     test_get_set_view();
4502     test_canceleditlabel();
4503     test_mapidindex();
4504     test_scrollnotify();
4505     test_LVS_EX_TRANSPARENTBKGND();
4506     test_LVS_EX_HEADERINALLVIEWS();
4507
4508     unload_v6_module(ctx_cookie, hCtx);
4509
4510     DestroyWindow(hwndparent);
4511 }