comctl32/listview: Edit box should be destroyed on invalid index too (LVM_EDITLABEL).
[wine] / dlls / comctl32 / tests / listview.c
1 /*
2  * ListView tests
3  *
4  * Copyright 2006 Mike McCormack for CodeWeavers
5  * Copyright 2007 George Gov
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include <stdio.h>
23 #include <windows.h>
24 #include <commctrl.h>
25
26 #include "wine/test.h"
27 #include "msg.h"
28
29 #define PARENT_SEQ_INDEX       0
30 #define PARENT_FULL_SEQ_INDEX  1
31 #define LISTVIEW_SEQ_INDEX     2
32 #define NUM_MSG_SEQUENCES      3
33
34 #define LISTVIEW_ID 0
35 #define HEADER_ID   1
36
37 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
38 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
39        "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
40
41 HWND hwndparent;
42
43 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
44
45 static const struct message create_parent_wnd_seq[] = {
46     { WM_GETMINMAXINFO,     sent },
47     { WM_NCCREATE,          sent },
48     { WM_NCCALCSIZE,        sent|wparam, 0 },
49     { WM_CREATE,            sent },
50     { WM_SHOWWINDOW,        sent|wparam, 1 },
51     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
52     { WM_QUERYNEWPALETTE,   sent|optional },
53     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
54     { WM_WINDOWPOSCHANGED,  sent|optional },
55     { WM_NCCALCSIZE,        sent|wparam|optional, 1 },
56     { WM_ACTIVATEAPP,       sent|wparam, 1 },
57     { WM_NCACTIVATE,        sent|wparam, 1 },
58     { WM_ACTIVATE,          sent|wparam, 1 },
59     { WM_IME_SETCONTEXT,    sent|wparam|defwinproc|optional, 1 },
60     { WM_IME_NOTIFY,        sent|defwinproc|optional },
61     { WM_SETFOCUS,          sent|wparam|defwinproc, 0 },
62     /* Win9x adds SWP_NOZORDER below */
63     { WM_WINDOWPOSCHANGED,  sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
64     { WM_NCCALCSIZE,        sent|wparam|optional, 1 },
65     { WM_SIZE,              sent },
66     { WM_MOVE,              sent },
67     { 0 }
68 };
69
70 static const struct message redraw_listview_seq[] = {
71     { WM_PAINT,      sent|id,            0, 0, LISTVIEW_ID },
72     { WM_PAINT,      sent|id,            0, 0, HEADER_ID },
73     { WM_NCPAINT,    sent|id|defwinproc, 0, 0, HEADER_ID },
74     { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, HEADER_ID },
75     { WM_NOTIFY,     sent|id|defwinproc, 0, 0, LISTVIEW_ID },
76     { WM_NCPAINT,    sent|id|defwinproc, 0, 0, LISTVIEW_ID },
77     { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
78     { 0 }
79 };
80
81 static const struct message listview_icon_spacing_seq[] = {
82     { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
83     { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
84     { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
85     { 0 }
86 };
87
88 static const struct message listview_color_seq[] = {
89     { LVM_SETBKCOLOR,     sent|lparam, 0, RGB(0,0,0) },
90     { LVM_GETBKCOLOR,     sent },
91     { LVM_SETTEXTCOLOR,   sent|lparam, 0, RGB(0,0,0) },
92     { LVM_GETTEXTCOLOR,   sent },
93     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
94     { LVM_GETTEXTBKCOLOR, sent },
95
96     { LVM_SETBKCOLOR,     sent|lparam, 0, RGB(100,50,200) },
97     { LVM_GETBKCOLOR,     sent },
98     { LVM_SETTEXTCOLOR,   sent|lparam, 0, RGB(100,50,200) },
99     { LVM_GETTEXTCOLOR,   sent },
100     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
101     { LVM_GETTEXTBKCOLOR, sent },
102
103     { LVM_SETBKCOLOR,     sent|lparam, 0, CLR_NONE },
104     { LVM_GETBKCOLOR,     sent },
105     { LVM_SETTEXTCOLOR,   sent|lparam, 0, CLR_NONE },
106     { LVM_GETTEXTCOLOR,   sent },
107     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
108     { LVM_GETTEXTBKCOLOR, sent },
109
110     { LVM_SETBKCOLOR,     sent|lparam, 0, RGB(255,255,255) },
111     { LVM_GETBKCOLOR,     sent },
112     { LVM_SETTEXTCOLOR,   sent|lparam, 0, RGB(255,255,255) },
113     { LVM_GETTEXTCOLOR,   sent },
114     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
115     { LVM_GETTEXTBKCOLOR, sent },
116     { 0 }
117 };
118
119 static const struct message listview_item_count_seq[] = {
120     { LVM_GETITEMCOUNT,   sent },
121     { LVM_INSERTITEM,     sent },
122     { LVM_INSERTITEM,     sent },
123     { LVM_INSERTITEM,     sent },
124     { LVM_GETITEMCOUNT,   sent },
125     { LVM_DELETEITEM,     sent|wparam, 2 },
126     { LVM_GETITEMCOUNT,   sent },
127     { LVM_DELETEALLITEMS, sent },
128     { LVM_GETITEMCOUNT,   sent },
129     { LVM_INSERTITEM,     sent },
130     { LVM_INSERTITEM,     sent },
131     { LVM_GETITEMCOUNT,   sent },
132     { LVM_INSERTITEM,     sent },
133     { LVM_GETITEMCOUNT,   sent },
134     { 0 }
135 };
136
137 static const struct message listview_itempos_seq[] = {
138     { LVM_INSERTITEM,      sent },
139     { LVM_INSERTITEM,      sent },
140     { LVM_INSERTITEM,      sent },
141     { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
142     { LVM_GETITEMPOSITION, sent|wparam,        1 },
143     { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
144     { LVM_GETITEMPOSITION, sent|wparam,        2 },
145     { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
146     { LVM_GETITEMPOSITION, sent|wparam,        0 },
147     { 0 }
148 };
149
150 static const struct message listview_ownerdata_switchto_seq[] = {
151     { WM_STYLECHANGING,    sent },
152     { WM_STYLECHANGED,     sent },
153     { 0 }
154 };
155
156 static const struct message listview_getorderarray_seq[] = {
157     { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
158     { HDM_GETORDERARRAY,       sent|id|wparam, 2, 0, HEADER_ID },
159     { 0 }
160 };
161
162 static const struct message empty_seq[] = {
163     { 0 }
164 };
165
166 static const struct message forward_erasebkgnd_parent_seq[] = {
167     { WM_ERASEBKGND, sent },
168     { 0 }
169 };
170
171 static const struct message ownderdata_select_focus_parent_seq[] = {
172     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
173     { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
174     { 0 }
175 };
176
177 static const struct message textcallback_set_again_parent_seq[] = {
178     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
179     { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED  },
180     { 0 }
181 };
182
183 static const struct message single_getdispinfo_parent_seq[] = {
184     { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
185     { 0 }
186 };
187
188 static const struct message getitemposition_seq1[] = {
189     { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
190     { 0 }
191 };
192
193 static const struct message getitemposition_seq2[] = {
194     { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
195     { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
196     { 0 }
197 };
198
199 struct subclass_info
200 {
201     WNDPROC oldproc;
202 };
203
204 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
205 {
206     static LONG defwndproc_counter = 0;
207     LRESULT ret;
208     struct message msg;
209
210     msg.message = message;
211     msg.flags = sent|wparam|lparam;
212     if (defwndproc_counter) msg.flags |= defwinproc;
213     msg.wParam = wParam;
214     msg.lParam = lParam;
215     if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
216
217     /* log system messages, except for painting */
218     if (message < WM_USER &&
219         message != WM_PAINT &&
220         message != WM_ERASEBKGND &&
221         message != WM_NCPAINT &&
222         message != WM_NCHITTEST &&
223         message != WM_GETTEXT &&
224         message != WM_GETICON &&
225         message != WM_DEVICECHANGE)
226     {
227         trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
228
229         add_message(sequences, PARENT_SEQ_INDEX, &msg);
230     }
231     add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
232
233     /* always accept new item text */
234     if (message == WM_NOTIFY && lParam && ((NMHDR*)lParam)->code == LVN_ENDLABELEDIT)
235         return TRUE;
236
237     defwndproc_counter++;
238     ret = DefWindowProcA(hwnd, message, wParam, lParam);
239     defwndproc_counter--;
240
241     return ret;
242 }
243
244 static BOOL register_parent_wnd_class(void)
245 {
246     WNDCLASSA cls;
247
248     cls.style = 0;
249     cls.lpfnWndProc = parent_wnd_proc;
250     cls.cbClsExtra = 0;
251     cls.cbWndExtra = 0;
252     cls.hInstance = GetModuleHandleA(NULL);
253     cls.hIcon = 0;
254     cls.hCursor = LoadCursorA(0, IDC_ARROW);
255     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
256     cls.lpszMenuName = NULL;
257     cls.lpszClassName = "Listview test parent class";
258     return RegisterClassA(&cls);
259 }
260
261 static HWND create_parent_window(void)
262 {
263     if (!register_parent_wnd_class())
264         return NULL;
265
266     return CreateWindowEx(0, "Listview test parent class",
267                           "Listview test parent window",
268                           WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
269                           WS_MAXIMIZEBOX | WS_VISIBLE,
270                           0, 0, 100, 100,
271                           GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
272 }
273
274 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
275 {
276     struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
277     static LONG defwndproc_counter = 0;
278     LRESULT ret;
279     struct message msg;
280
281     trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
282
283     /* some debug output for style changing */
284     if ((message == WM_STYLECHANGING ||
285          message == WM_STYLECHANGED) && lParam)
286     {
287         STYLESTRUCT *style = (STYLESTRUCT*)lParam;
288         trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
289     }
290
291     msg.message = message;
292     msg.flags = sent|wparam|lparam;
293     if (defwndproc_counter) msg.flags |= defwinproc;
294     msg.wParam = wParam;
295     msg.lParam = lParam;
296     msg.id = LISTVIEW_ID;
297     add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
298
299     defwndproc_counter++;
300     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
301     defwndproc_counter--;
302     return ret;
303 }
304
305 static HWND create_listview_control(DWORD style)
306 {
307     struct subclass_info *info;
308     HWND hwnd;
309     RECT rect;
310
311     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
312     if (!info)
313         return NULL;
314
315     GetClientRect(hwndparent, &rect);
316     hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
317                            WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
318                            0, 0, rect.right, rect.bottom,
319                            hwndparent, NULL, GetModuleHandleA(NULL), NULL);
320     ok(hwnd != NULL, "gle=%d\n", GetLastError());
321
322     if (!hwnd)
323     {
324         HeapFree(GetProcessHeap(), 0, info);
325         return NULL;
326     }
327
328     info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
329                                             (LONG_PTR)listview_subclass_proc);
330     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
331
332     return hwnd;
333 }
334
335 static HWND create_custom_listview_control(DWORD style)
336 {
337     struct subclass_info *info;
338     HWND hwnd;
339     RECT rect;
340
341     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
342     if (!info)
343         return NULL;
344
345     GetClientRect(hwndparent, &rect);
346     hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
347                            WS_CHILD | WS_BORDER | WS_VISIBLE | style,
348                            0, 0, rect.right, rect.bottom,
349                            hwndparent, NULL, GetModuleHandleA(NULL), NULL);
350     ok(hwnd != NULL, "gle=%d\n", GetLastError());
351
352     if (!hwnd)
353     {
354         HeapFree(GetProcessHeap(), 0, info);
355         return NULL;
356     }
357
358     info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
359                                             (LONG_PTR)listview_subclass_proc);
360     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
361
362     return hwnd;
363 }
364
365 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
366 {
367     struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
368     static LONG defwndproc_counter = 0;
369     LRESULT ret;
370     struct message msg;
371
372     trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
373
374     msg.message = message;
375     msg.flags = sent|wparam|lparam;
376     if (defwndproc_counter) msg.flags |= defwinproc;
377     msg.wParam = wParam;
378     msg.lParam = lParam;
379     msg.id = HEADER_ID;
380     add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
381
382     defwndproc_counter++;
383     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
384     defwndproc_counter--;
385     return ret;
386 }
387
388 static HWND subclass_header(HWND hwndListview)
389 {
390     struct subclass_info *info;
391     HWND hwnd;
392
393     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
394     if (!info)
395         return NULL;
396
397     hwnd = ListView_GetHeader(hwndListview);
398     info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
399                                             (LONG_PTR)header_subclass_proc);
400     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
401
402     return hwnd;
403 }
404
405 /* Performs a single LVM_HITTEST test */
406 static void test_lvm_hittest(HWND hwnd, INT x, INT y, INT item, UINT flags,
407                              BOOL todo_item, BOOL todo_flags, int line)
408 {
409     LVHITTESTINFO lpht;
410     DWORD ret;
411
412     lpht.pt.x = x;
413     lpht.pt.y = y;
414     lpht.iSubItem = 10;
415
416     trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
417     ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
418
419     if (todo_item)
420     {
421         todo_wine
422         {
423             ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
424             ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
425             ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
426         }
427     }
428     else
429     {
430         ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
431         ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
432         ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
433     }
434
435     if (todo_flags)
436     {
437         todo_wine
438             ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
439     }
440     else
441         ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
442 }
443
444 /* Performs a single LVM_SUBITEMHITTEST test */
445 static void test_lvm_subitemhittest(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
446                                     BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
447 {
448     LVHITTESTINFO lpht;
449     DWORD ret;
450
451     lpht.pt.x = x;
452     lpht.pt.y = y;
453
454     trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
455     ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
456
457     if (todo_item)
458     {
459         todo_wine
460         {
461             ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
462             ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
463         }
464     }
465     else
466     {
467         ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
468         ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
469     }
470
471     if (todo_subitem)
472     {
473         todo_wine
474             ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
475     }
476     else
477         ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
478
479     if (todo_flags)
480     {
481         todo_wine
482             ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
483     }
484     else
485         ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
486 }
487
488 static void test_images(void)
489 {
490     HWND hwnd;
491     DWORD r;
492     LVITEM item;
493     HIMAGELIST himl;
494     HBITMAP hbmp;
495     RECT r1, r2;
496     static CHAR hello[] = "hello";
497
498     himl = ImageList_Create(40, 40, 0, 4, 4);
499     ok(himl != NULL, "failed to create imagelist\n");
500
501     hbmp = CreateBitmap(40, 40, 1, 1, NULL);
502     ok(hbmp != NULL, "failed to create bitmap\n");
503
504     r = ImageList_Add(himl, hbmp, 0);
505     ok(r == 0, "should be zero\n");
506
507     hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED, 
508                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
509     ok(hwnd != NULL, "failed to create listview window\n");
510
511     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
512                     LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
513
514     ok(r == 0, "should return zero\n");
515
516     r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
517     ok(r == 0, "should return zero\n");
518
519     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
520     /* returns dimensions */
521
522     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
523     ok(r == 0, "should be zero items\n");
524
525     item.mask = LVIF_IMAGE | LVIF_TEXT;
526     item.iItem = 0;
527     item.iSubItem = 1;
528     item.iImage = 0;
529     item.pszText = 0;
530     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
531     ok(r == -1, "should fail\n");
532
533     item.iSubItem = 0;
534     item.pszText = hello;
535     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
536     ok(r == 0, "should not fail\n");
537
538     memset(&r1, 0, sizeof r1);
539     r1.left = LVIR_ICON;
540     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
541
542     r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
543     ok(r == TRUE, "should not fail\n");
544
545     item.iSubItem = 0;
546     item.pszText = hello;
547     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
548     ok(r == 0, "should not fail\n");
549
550     memset(&r2, 0, sizeof r2);
551     r2.left = LVIR_ICON;
552     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
553
554     ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
555
556     DestroyWindow(hwnd);
557 }
558
559 static void test_checkboxes(void)
560 {
561     HWND hwnd;
562     LVITEMA item;
563     DWORD r;
564     static CHAR text[]  = "Text",
565                 text2[] = "Text2",
566                 text3[] = "Text3";
567
568     hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT, 
569                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
570     ok(hwnd != NULL, "failed to create listview window\n");
571
572     /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
573     item.mask = LVIF_TEXT | LVIF_STATE;
574     item.stateMask = 0xffff;
575     item.state = 0xfccc;
576     item.iItem = 0;
577     item.iSubItem = 0;
578     item.pszText = text;
579     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
580     ok(r == 0, "ret %d\n", r);
581
582     item.iItem = 0;
583     item.mask = LVIF_STATE;
584     item.stateMask = 0xffff;
585     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
586     ok(item.state == 0xfccc, "state %x\n", item.state);
587
588     /* Don't set LVIF_STATE */
589     item.mask = LVIF_TEXT;
590     item.stateMask = 0xffff;
591     item.state = 0xfccc;
592     item.iItem = 1;
593     item.iSubItem = 0;
594     item.pszText = text;
595     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
596     ok(r == 1, "ret %d\n", r);
597
598     item.iItem = 1;
599     item.mask = LVIF_STATE;
600     item.stateMask = 0xffff;
601     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
602     ok(item.state == 0, "state %x\n", item.state);
603
604     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
605     ok(r == 0, "should return zero\n");
606
607     /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
608     item.iItem = 0;
609     item.mask = LVIF_STATE;
610     item.stateMask = 0xffff;
611     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
612     ok(item.state == 0x1ccc, "state %x\n", item.state);
613
614     /* Now add an item without specifying a state and check that its state goes to 0x1000 */
615     item.iItem = 2;
616     item.mask = LVIF_TEXT;
617     item.state = 0;
618     item.pszText = text2;
619     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
620     ok(r == 2, "ret %d\n", r);
621
622     item.iItem = 2;
623     item.mask = LVIF_STATE;
624     item.stateMask = 0xffff;
625     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
626     ok(item.state == 0x1000, "state %x\n", item.state);
627
628     /* Add a further item this time specifying a state and still its state goes to 0x1000 */
629     item.iItem = 3;
630     item.mask = LVIF_TEXT | LVIF_STATE;
631     item.stateMask = 0xffff;
632     item.state = 0x2aaa;
633     item.pszText = text3;
634     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
635     ok(r == 3, "ret %d\n", r);
636
637     item.iItem = 3;
638     item.mask = LVIF_STATE;
639     item.stateMask = 0xffff;
640     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
641     ok(item.state == 0x1aaa, "state %x\n", item.state);
642
643     /* Set an item's state to checked */
644     item.iItem = 3;
645     item.mask = LVIF_STATE;
646     item.stateMask = 0xf000;
647     item.state = 0x2000;
648     r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
649
650     item.iItem = 3;
651     item.mask = LVIF_STATE;
652     item.stateMask = 0xffff;
653     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
654     ok(item.state == 0x2aaa, "state %x\n", item.state);
655
656     /* Check that only the bits we asked for are returned,
657      * and that all the others are set to zero
658      */
659     item.iItem = 3;
660     item.mask = LVIF_STATE;
661     item.stateMask = 0xf000;
662     item.state = 0xffff;
663     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
664     ok(item.state == 0x2000, "state %x\n", item.state);
665
666     /* Set the style again and check that doesn't change an item's state */
667     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
668     ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
669
670     item.iItem = 3;
671     item.mask = LVIF_STATE;
672     item.stateMask = 0xffff;
673     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
674     ok(item.state == 0x2aaa, "state %x\n", item.state);
675
676     /* Unsetting the checkbox extended style doesn't change an item's state */
677     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
678     ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
679
680     item.iItem = 3;
681     item.mask = LVIF_STATE;
682     item.stateMask = 0xffff;
683     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
684     ok(item.state == 0x2aaa, "state %x\n", item.state);
685
686     /* Now setting the style again will change an item's state */
687     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
688     ok(r == 0, "ret %x\n", r);
689
690     item.iItem = 3;
691     item.mask = LVIF_STATE;
692     item.stateMask = 0xffff;
693     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
694     ok(item.state == 0x1aaa, "state %x\n", item.state);
695
696     /* Toggle checkbox tests (bug 9934) */
697     memset (&item, 0xcc, sizeof(item));
698     item.mask = LVIF_STATE;
699     item.iItem = 3;
700     item.iSubItem = 0;
701     item.state = LVIS_FOCUSED;
702     item.stateMask = LVIS_FOCUSED;
703     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
704     expect(1, r);
705
706     item.iItem = 3;
707     item.mask = LVIF_STATE;
708     item.stateMask = 0xffff;
709     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
710     ok(item.state == 0x1aab, "state %x\n", item.state);
711
712     r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
713     expect(0, r);
714     r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
715     expect(0, r);
716
717     item.iItem = 3;
718     item.mask = LVIF_STATE;
719     item.stateMask = 0xffff;
720     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
721     ok(item.state == 0x2aab, "state %x\n", item.state);
722
723     r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
724     expect(0, r);
725     r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
726     expect(0, r);
727
728     item.iItem = 3;
729     item.mask = LVIF_STATE;
730     item.stateMask = 0xffff;
731     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
732     ok(item.state == 0x1aab, "state %x\n", item.state);
733
734     DestroyWindow(hwnd);
735 }
736
737 static void insert_column(HWND hwnd, int idx)
738 {
739     LVCOLUMN column;
740     DWORD rc;
741
742     memset(&column, 0xcc, sizeof(column));
743     column.mask = LVCF_SUBITEM;
744     column.iSubItem = idx;
745
746     rc = ListView_InsertColumn(hwnd, idx, &column);
747     expect(idx, rc);
748 }
749
750 static void insert_item(HWND hwnd, int idx)
751 {
752     static CHAR text[] = "foo";
753
754     LVITEMA item;
755     DWORD rc;
756
757     memset(&item, 0xcc, sizeof (item));
758     item.mask = LVIF_TEXT;
759     item.iItem = idx;
760     item.iSubItem = 0;
761     item.pszText = text;
762
763     rc = ListView_InsertItem(hwnd, &item);
764     expect(idx, rc);
765 }
766
767 static void test_items(void)
768 {
769     const LPARAM lparamTest = 0x42;
770     HWND hwnd;
771     LVITEMA item;
772     DWORD r;
773     static CHAR text[] = "Text";
774
775     hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
776                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
777     ok(hwnd != NULL, "failed to create listview window\n");
778
779     /*
780      * Test setting/getting item params
781      */
782
783     /* Set up two columns */
784     insert_column(hwnd, 0);
785     insert_column(hwnd, 1);
786
787     /* LVIS_SELECTED with zero stateMask */
788     /* set */
789     memset (&item, 0, sizeof (item));
790     item.mask = LVIF_STATE;
791     item.state = LVIS_SELECTED;
792     item.stateMask = 0;
793     item.iItem = 0;
794     item.iSubItem = 0;
795     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
796     ok(r == 0, "ret %d\n", r);
797     /* get */
798     memset (&item, 0xcc, sizeof (item));
799     item.mask = LVIF_STATE;
800     item.stateMask = LVIS_SELECTED;
801     item.state = 0;
802     item.iItem = 0;
803     item.iSubItem = 0;
804     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
805     ok(r != 0, "ret %d\n", r);
806     ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
807     SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
808
809     /* LVIS_SELECTED with zero stateMask */
810     /* set */
811     memset (&item, 0, sizeof (item));
812     item.mask = LVIF_STATE;
813     item.state = LVIS_FOCUSED;
814     item.stateMask = 0;
815     item.iItem = 0;
816     item.iSubItem = 0;
817     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
818     ok(r == 0, "ret %d\n", r);
819     /* get */
820     memset (&item, 0xcc, sizeof (item));
821     item.mask = LVIF_STATE;
822     item.stateMask = LVIS_FOCUSED;
823     item.state = 0;
824     item.iItem = 0;
825     item.iSubItem = 0;
826     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
827     ok(r != 0, "ret %d\n", r);
828     ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
829     SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
830
831     /* LVIS_CUT with LVIS_FOCUSED stateMask */
832     /* set */
833     memset (&item, 0, sizeof (item));
834     item.mask = LVIF_STATE;
835     item.state = LVIS_CUT;
836     item.stateMask = LVIS_FOCUSED;
837     item.iItem = 0;
838     item.iSubItem = 0;
839     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
840     ok(r == 0, "ret %d\n", r);
841     /* get */
842     memset (&item, 0xcc, sizeof (item));
843     item.mask = LVIF_STATE;
844     item.stateMask = LVIS_CUT;
845     item.state = 0;
846     item.iItem = 0;
847     item.iSubItem = 0;
848     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
849     ok(r != 0, "ret %d\n", r);
850     ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
851     SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
852
853     /* Insert an item with just a param */
854     memset (&item, 0xcc, sizeof (item));
855     item.mask = LVIF_PARAM;
856     item.iItem = 0;
857     item.iSubItem = 0;
858     item.lParam = lparamTest;
859     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
860     ok(r == 0, "ret %d\n", r);
861
862     /* Test getting of the param */
863     memset (&item, 0xcc, sizeof (item));
864     item.mask = LVIF_PARAM;
865     item.iItem = 0;
866     item.iSubItem = 0;
867     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
868     ok(r != 0, "ret %d\n", r);
869     ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
870
871     /* Set up a subitem */
872     memset (&item, 0xcc, sizeof (item));
873     item.mask = LVIF_TEXT;
874     item.iItem = 0;
875     item.iSubItem = 1;
876     item.pszText = text;
877     r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
878     ok(r != 0, "ret %d\n", r);
879
880     /* Query param from subitem: returns main item param */
881     memset (&item, 0xcc, sizeof (item));
882     item.mask = LVIF_PARAM;
883     item.iItem = 0;
884     item.iSubItem = 1;
885     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
886     ok(r != 0, "ret %d\n", r);
887     ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
888
889     /* Set up param on first subitem: no effect */
890     memset (&item, 0xcc, sizeof (item));
891     item.mask = LVIF_PARAM;
892     item.iItem = 0;
893     item.iSubItem = 1;
894     item.lParam = lparamTest+1;
895     r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
896     ok(r == 0, "ret %d\n", r);
897
898     /* Query param from subitem again: should still return main item param */
899     memset (&item, 0xcc, sizeof (item));
900     item.mask = LVIF_PARAM;
901     item.iItem = 0;
902     item.iSubItem = 1;
903     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
904     ok(r != 0, "ret %d\n", r);
905     ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
906
907     /**** Some tests of state highlighting ****/
908     memset (&item, 0xcc, sizeof (item));
909     item.mask = LVIF_STATE;
910     item.iItem = 0;
911     item.iSubItem = 0;
912     item.state = LVIS_SELECTED;
913     item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
914     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
915     ok(r != 0, "ret %d\n", r);
916     item.iSubItem = 1;
917     item.state = LVIS_DROPHILITED;
918     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
919     ok(r != 0, "ret %d\n", r);
920
921     memset (&item, 0xcc, sizeof (item));
922     item.mask = LVIF_STATE;
923     item.iItem = 0;
924     item.iSubItem = 0;
925     item.stateMask = -1;
926     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
927     ok(r != 0, "ret %d\n", r);
928     ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
929     item.iSubItem = 1;
930     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
931     ok(r != 0, "ret %d\n", r);
932     todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
933
934     /* some notnull but meaningless masks */
935     memset (&item, 0, sizeof(item));
936     item.mask = LVIF_NORECOMPUTE;
937     item.iItem = 0;
938     item.iSubItem = 0;
939     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
940     ok(r != 0, "ret %d\n", r);
941     memset (&item, 0, sizeof(item));
942     item.mask = LVIF_DI_SETITEM;
943     item.iItem = 0;
944     item.iSubItem = 0;
945     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
946     ok(r != 0, "ret %d\n", r);
947
948     /* set text to callback value already having it */
949     r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
950     expect(TRUE, r);
951     memset (&item, 0, sizeof (item));
952     item.mask  = LVIF_TEXT;
953     item.pszText = LPSTR_TEXTCALLBACK;
954     item.iItem = 0;
955     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
956     ok(r == 0, "ret %d\n", r);
957     memset (&item, 0, sizeof (item));
958
959     flush_sequences(sequences, NUM_MSG_SEQUENCES);
960
961     item.pszText = LPSTR_TEXTCALLBACK;
962     r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
963     expect(TRUE, r);
964
965     ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
966                 "check callback text comparison rule", TRUE);
967
968     DestroyWindow(hwnd);
969 }
970
971 static void test_columns(void)
972 {
973     HWND hwnd, hwndheader;
974     LVCOLUMN column;
975     DWORD rc;
976     INT order[2];
977
978     hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
979                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
980     ok(hwnd != NULL, "failed to create listview window\n");
981
982     /* Add a column with no mask */
983     memset(&column, 0xcc, sizeof(column));
984     column.mask = 0;
985     rc = ListView_InsertColumn(hwnd, 0, &column);
986     ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
987
988     /* Check its width */
989     rc = ListView_GetColumnWidth(hwnd, 0);
990     ok(rc==10 ||
991        broken(rc==0), /* win9x */
992        "Inserting column with no mask failed to set width to 10 with %d\n", rc);
993
994     DestroyWindow(hwnd);
995
996     /* LVM_GETCOLUMNORDERARRAY */
997     hwnd = create_listview_control(0);
998     hwndheader = subclass_header(hwnd);
999
1000     memset(&column, 0, sizeof(column));
1001     column.mask = LVCF_WIDTH;
1002     column.cx = 100;
1003     rc = ListView_InsertColumn(hwnd, 0, &column);
1004     ok(rc == 0, "Inserting column failed with %d\n", rc);
1005
1006     column.cx = 200;
1007     rc = ListView_InsertColumn(hwnd, 1, &column);
1008     ok(rc == 1, "Inserting column failed with %d\n", rc);
1009
1010     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1011
1012     rc = SendMessage(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1013     ok(rc != 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1014     ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1015     ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1016
1017     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1018
1019     DestroyWindow(hwnd);
1020 }
1021 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1022 static WNDPROC listviewWndProc;
1023 static HIMAGELIST test_create_imagelist;
1024
1025 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1026 {
1027     LRESULT ret;
1028
1029     if (uMsg == WM_CREATE)
1030     {
1031         LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1032         lpcs->style |= LVS_REPORT;
1033     }
1034     ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1035     if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1036     return ret;
1037 }
1038
1039 static void test_create(void)
1040 {
1041     HWND hList;
1042     HWND hHeader;
1043     LONG_PTR ret;
1044     LONG r;
1045     LVCOLUMNA col;
1046     RECT rect;
1047     WNDCLASSEX cls;
1048     cls.cbSize = sizeof(WNDCLASSEX);
1049     ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1050     listviewWndProc = cls.lpfnWndProc;
1051     cls.lpfnWndProc = create_test_wndproc;
1052     cls.lpszClassName = "MyListView32";
1053     ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1054
1055     test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1056     hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1057     ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1058     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1059     ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1060     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1061     DestroyWindow(hList);
1062
1063     /* header isn't created on LVS_ICON and LVS_LIST styles */
1064     hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1065                           GetModuleHandle(NULL), 0);
1066     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1067     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1068     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1069     /* insert column */
1070     memset(&col, 0, sizeof(LVCOLUMNA));
1071     col.mask = LVCF_WIDTH;
1072     col.cx = 100;
1073     r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1074     ok(r == 0, "Expected 0 column's inserted\n");
1075     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1076     ok(IsWindow(hHeader), "Header should be created\n");
1077     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1078     DestroyWindow(hList);
1079
1080     hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1081                           GetModuleHandle(NULL), 0);
1082     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1083     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1084     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1085     /* insert column */
1086     memset(&col, 0, sizeof(LVCOLUMNA));
1087     col.mask = LVCF_WIDTH;
1088     col.cx = 100;
1089     r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1090     ok(r == 0, "Expected 0 column's inserted\n");
1091     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1092     ok(IsWindow(hHeader), "Header should be created\n");
1093     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1094     DestroyWindow(hList);
1095
1096     /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1097     hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1098                           GetModuleHandle(NULL), 0);
1099     ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1100     ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1101     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1102     ok(IsWindow(hHeader), "Header should be created\n");
1103     ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1104     ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1105     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1106     ok(IsWindow(hHeader), "Header should be created\n");
1107     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1108     DestroyWindow(hList);
1109
1110     /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1111     hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1112                           GetModuleHandle(NULL), 0);
1113     ret = SetWindowLongPtr(hList, GWL_STYLE,
1114                           (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1115     ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1116     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1117     ok(IsWindow(hHeader), "Header should be created\n");
1118     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1119     ret = SetWindowLongPtr(hList, GWL_STYLE,
1120                           (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1121     ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1122     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1123     ok(IsWindow(hHeader), "Header should be created\n");
1124     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1125     DestroyWindow(hList);
1126
1127     /* LVS_REPORT without WS_VISIBLE */
1128     hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1129                           GetModuleHandle(NULL), 0);
1130     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1131     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1132     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1133     /* insert column */
1134     memset(&col, 0, sizeof(LVCOLUMNA));
1135     col.mask = LVCF_WIDTH;
1136     col.cx = 100;
1137     r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1138     ok(r == 0, "Expected 0 column's inserted\n");
1139     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1140     ok(IsWindow(hHeader), "Header should be created\n");
1141     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1142     DestroyWindow(hList);
1143
1144     /* LVS_REPORT without WS_VISIBLE, try to show it */
1145     hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1146                           GetModuleHandle(NULL), 0);
1147     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1148     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1149     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1150     ShowWindow(hList, SW_SHOW);
1151     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1152     ok(IsWindow(hHeader), "Header should be created\n");
1153     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1154     DestroyWindow(hList);
1155
1156     /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1157     hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1158                           0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1159     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1160     ok(IsWindow(hHeader), "Header should be created\n");
1161     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1162     /* HDS_DRAGDROP set by default */
1163     ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1164     DestroyWindow(hList);
1165
1166     /* setting LVS_EX_HEADERDRAGDROP creates header */
1167     hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1168                           GetModuleHandle(NULL), 0);
1169     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1170     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1171     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1172     SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1173     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1174     ok(IsWindow(hHeader), "Header should be created\n");
1175     ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1176     DestroyWindow(hList);
1177
1178     /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1179     hList = create_custom_listview_control(0);
1180     SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1181     r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1182     ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1183     DestroyWindow(hList);
1184
1185     /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1186     hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1187                           GetModuleHandle(NULL), 0);
1188     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1189     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1190
1191     rect.left = LVIR_BOUNDS;
1192     rect.top  = 1;
1193     rect.right = rect.bottom = -10;
1194     r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1195     ok(r != 0, "Expected not-null LRESULT\n");
1196
1197     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1198     ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1199     ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1200
1201     DestroyWindow(hList);
1202 }
1203
1204 static void test_redraw(void)
1205 {
1206     HWND hwnd, hwndheader;
1207     HDC hdc;
1208     BOOL res;
1209     DWORD r;
1210
1211     hwnd = create_listview_control(0);
1212     hwndheader = subclass_header(hwnd);
1213
1214     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1215
1216     trace("invalidate & update\n");
1217     InvalidateRect(hwnd, NULL, TRUE);
1218     UpdateWindow(hwnd);
1219     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1220
1221     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1222
1223     /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1224     /* 1. Without backbuffer */
1225     res = ListView_SetBkColor(hwnd, CLR_NONE);
1226     expect(TRUE, res);
1227
1228     hdc = GetWindowDC(hwndparent);
1229
1230     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1231     r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1232     ok(r != 0, "Expected not zero result\n");
1233     ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1234                 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1235
1236     res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1237     expect(TRUE, res);
1238
1239     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1240     r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1241     ok(r != 0, "Expected not zero result\n");
1242     ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1243                 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1244
1245     /* 2. With backbuffer */
1246     SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1247                                                      LVS_EX_DOUBLEBUFFER);
1248     res = ListView_SetBkColor(hwnd, CLR_NONE);
1249     expect(TRUE, res);
1250
1251     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1252     r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1253     ok(r != 0, "Expected not zero result\n");
1254     ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1255                 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1256
1257     res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1258     expect(TRUE, res);
1259
1260     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1261     r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1262     todo_wine ok(r != 0, "Expected not zero result\n");
1263     ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1264                 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1265
1266     ReleaseDC(hwndparent, hdc);
1267
1268     DestroyWindow(hwnd);
1269 }
1270
1271 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1272 {
1273     COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1274
1275     if(msg == WM_NOTIFY) {
1276         NMHDR *nmhdr = (PVOID)lp;
1277         if(nmhdr->code == NM_CUSTOMDRAW) {
1278             NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1279             trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1280             switch(nmlvcd->nmcd.dwDrawStage) {
1281             case CDDS_PREPAINT:
1282                 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1283                 return CDRF_NOTIFYITEMDRAW;
1284             case CDDS_ITEMPREPAINT:
1285                 nmlvcd->clrTextBk = CLR_DEFAULT;
1286                 return CDRF_NOTIFYSUBITEMDRAW;
1287             case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1288                 clr = GetBkColor(nmlvcd->nmcd.hdc);
1289                 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1290                 return CDRF_NOTIFYPOSTPAINT;
1291             case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1292                 clr = GetBkColor(nmlvcd->nmcd.hdc);
1293                 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1294                 return CDRF_DODEFAULT;
1295             }
1296             return CDRF_DODEFAULT;
1297         }
1298     }
1299
1300     return DefWindowProcA(hwnd, msg, wp, lp);
1301 }
1302
1303 static void test_customdraw(void)
1304 {
1305     HWND hwnd;
1306     WNDPROC oldwndproc;
1307
1308     hwnd = create_listview_control(0);
1309
1310     insert_column(hwnd, 0);
1311     insert_column(hwnd, 1);
1312     insert_item(hwnd, 0);
1313
1314     oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1315                                            (LONG_PTR)cd_wndproc);
1316
1317     InvalidateRect(hwnd, NULL, TRUE);
1318     UpdateWindow(hwnd);
1319
1320     SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1321
1322     DestroyWindow(hwnd);
1323 }
1324
1325 static void test_icon_spacing(void)
1326 {
1327     /* LVM_SETICONSPACING */
1328     /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1329
1330     HWND hwnd;
1331     WORD w, h;
1332     DWORD r;
1333
1334     hwnd = create_custom_listview_control(LVS_ICON);
1335     ok(hwnd != NULL, "failed to create a listview window\n");
1336
1337     r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
1338     expect(NFR_ANSI, r);
1339
1340     /* reset the icon spacing to defaults */
1341     SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1342
1343     /* now we can request what the defaults are */
1344     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1345     w = LOWORD(r);
1346     h = HIWORD(r);
1347
1348     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1349
1350     trace("test icon spacing\n");
1351
1352     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1353     ok(r == MAKELONG(w, h) ||
1354        broken(r == MAKELONG(w, w)), /* win98 */
1355        "Expected %d, got %d\n", MAKELONG(w, h), r);
1356
1357     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1358     expect(MAKELONG(20,30), r);
1359
1360     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1361     expect(MAKELONG(25,35), r);
1362
1363     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1364
1365     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1366     DestroyWindow(hwnd);
1367 }
1368
1369 static void test_color(void)
1370 {
1371     /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1372
1373     HWND hwnd;
1374     DWORD r;
1375     int i;
1376
1377     COLORREF color;
1378     COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1379
1380     hwnd = create_listview_control(0);
1381     ok(hwnd != NULL, "failed to create a listview window\n");
1382
1383     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1384
1385     trace("test color seq\n");
1386     for (i = 0; i < 4; i++)
1387     {
1388         color = colors[i];
1389
1390         r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1391         expect(TRUE, r);
1392         r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1393         expect(color, r);
1394
1395         r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1396         expect (TRUE, r);
1397         r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1398         expect(color, r);
1399
1400         r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1401         expect(TRUE, r);
1402         r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1403         expect(color, r);
1404     }
1405
1406     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1407
1408     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1409     DestroyWindow(hwnd);
1410 }
1411
1412 static void test_item_count(void)
1413 {
1414     /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1415
1416     HWND hwnd;
1417     DWORD r;
1418
1419     LVITEM item0;
1420     LVITEM item1;
1421     LVITEM item2;
1422     static CHAR item0text[] = "item0";
1423     static CHAR item1text[] = "item1";
1424     static CHAR item2text[] = "item2";
1425
1426     hwnd = create_listview_control(0);
1427     ok(hwnd != NULL, "failed to create a listview window\n");
1428
1429     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1430
1431     trace("test item count\n");
1432
1433     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1434     expect(0, r);
1435
1436     /* [item0] */
1437     item0.mask = LVIF_TEXT;
1438     item0.iItem = 0;
1439     item0.iSubItem = 0;
1440     item0.pszText = item0text;
1441     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1442     expect(0, r);
1443
1444     /* [item0, item1] */
1445     item1.mask = LVIF_TEXT;
1446     item1.iItem = 1;
1447     item1.iSubItem = 0;
1448     item1.pszText = item1text;
1449     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1450     expect(1, r);
1451
1452     /* [item0, item1, item2] */
1453     item2.mask = LVIF_TEXT;
1454     item2.iItem = 2;
1455     item2.iSubItem = 0;
1456     item2.pszText = item2text;
1457     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1458     expect(2, r);
1459
1460     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1461     expect(3, r);
1462
1463     /* [item0, item1] */
1464     r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1465     expect(TRUE, r);
1466
1467     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1468     expect(2, r);
1469
1470     /* [] */
1471     r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1472     expect(TRUE, r);
1473
1474     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1475     expect(0, r);
1476
1477     /* [item0] */
1478     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1479     expect(0, r);
1480
1481     /* [item0, item1] */
1482     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1483     expect(1, r);
1484
1485     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1486     expect(2, r);
1487
1488     /* [item0, item1, item2] */
1489     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1490     expect(2, r);
1491
1492     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1493     expect(3, r);
1494
1495     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1496
1497     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1498     DestroyWindow(hwnd);
1499 }
1500
1501 static void test_item_position(void)
1502 {
1503     /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1504
1505     HWND hwnd;
1506     DWORD r;
1507     POINT position;
1508
1509     LVITEM item0;
1510     LVITEM item1;
1511     LVITEM item2;
1512     static CHAR item0text[] = "item0";
1513     static CHAR item1text[] = "item1";
1514     static CHAR item2text[] = "item2";
1515
1516     hwnd = create_custom_listview_control(LVS_ICON);
1517     ok(hwnd != NULL, "failed to create a listview window\n");
1518
1519     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1520
1521     trace("test item position\n");
1522
1523     /* [item0] */
1524     item0.mask = LVIF_TEXT;
1525     item0.iItem = 0;
1526     item0.iSubItem = 0;
1527     item0.pszText = item0text;
1528     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1529     expect(0, r);
1530
1531     /* [item0, item1] */
1532     item1.mask = LVIF_TEXT;
1533     item1.iItem = 1;
1534     item1.iSubItem = 0;
1535     item1.pszText = item1text;
1536     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1537     expect(1, r);
1538
1539     /* [item0, item1, item2] */
1540     item2.mask = LVIF_TEXT;
1541     item2.iItem = 2;
1542     item2.iSubItem = 0;
1543     item2.pszText = item2text;
1544     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1545     expect(2, r);
1546
1547     r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1548     expect(TRUE, r);
1549     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1550     expect(TRUE, r);
1551     expect2(10, 5, position.x, position.y);
1552
1553     r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1554     expect(TRUE, r);
1555     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1556     expect(TRUE, r);
1557     expect2(0, 0, position.x, position.y);
1558
1559     r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1560     expect(TRUE, r);
1561     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1562     expect(TRUE, r);
1563     expect2(20, 20, position.x, position.y);
1564
1565     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1566
1567     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1568     DestroyWindow(hwnd);
1569 }
1570
1571 static void test_getorigin(void)
1572 {
1573     /* LVM_GETORIGIN */
1574
1575     HWND hwnd;
1576     DWORD r;
1577     POINT position;
1578
1579     position.x = position.y = 0;
1580
1581     hwnd = create_custom_listview_control(LVS_ICON);
1582     ok(hwnd != NULL, "failed to create a listview window\n");
1583     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1584     trace("test get origin results\n");
1585     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1586     expect(TRUE, r);
1587     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1588     DestroyWindow(hwnd);
1589
1590     hwnd = create_custom_listview_control(LVS_SMALLICON);
1591     ok(hwnd != NULL, "failed to create a listview window\n");
1592     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1593     trace("test get origin results\n");
1594     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1595     expect(TRUE, r);
1596     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1597     DestroyWindow(hwnd);
1598
1599     hwnd = create_custom_listview_control(LVS_LIST);
1600     ok(hwnd != NULL, "failed to create a listview window\n");
1601     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1602     trace("test get origin results\n");
1603     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1604     expect(FALSE, r);
1605     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1606     DestroyWindow(hwnd);
1607
1608     hwnd = create_custom_listview_control(LVS_REPORT);
1609     ok(hwnd != NULL, "failed to create a listview window\n");
1610     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1611     trace("test get origin results\n");
1612     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1613     expect(FALSE, r);
1614     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1615     DestroyWindow(hwnd);
1616
1617 }
1618
1619 static void test_multiselect(void)
1620 {
1621     typedef struct t_select_task
1622     {
1623         const char *descr;
1624         int initPos;
1625         int loopVK;
1626         int count;
1627         int result;
1628     } select_task;
1629
1630     HWND hwnd;
1631     DWORD r;
1632     int i,j,item_count,selected_count;
1633     static const int items=5;
1634     BYTE kstate[256];
1635     select_task task;
1636     LONG_PTR style;
1637     LVITEMA item;
1638
1639     static struct t_select_task task_list[] = {
1640         { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1641         { "using VK_UP", -1, VK_UP, -1, -1 },
1642         { "using VK_END", 0, VK_END, 1, -1 },
1643         { "using VK_HOME", -1, VK_HOME, 1, -1 }
1644     };
1645
1646
1647     hwnd = create_listview_control(0);
1648
1649     for (i=0;i<items;i++) {
1650             insert_item(hwnd, 0);
1651     }
1652
1653     item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1654
1655     expect(items,item_count);
1656
1657     for (i=0;i<4;i++) {
1658         task = task_list[i];
1659
1660         /* deselect all items */
1661         ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1662         SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1663
1664         /* set initial position */
1665         SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1666         ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1667
1668         selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1669
1670         ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1671
1672         /* Set SHIFT key pressed */
1673         GetKeyboardState(kstate);
1674         kstate[VK_SHIFT]=0x80;
1675         SetKeyboardState(kstate);
1676
1677         for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1678             r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1679             expect(0,r);
1680             r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1681             expect(0,r);
1682         }
1683
1684         selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1685
1686         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);
1687
1688         /* Set SHIFT key released */
1689         GetKeyboardState(kstate);
1690         kstate[VK_SHIFT]=0x00;
1691         SetKeyboardState(kstate);
1692     }
1693     DestroyWindow(hwnd);
1694
1695     /* make multiple selection, then switch to LVS_SINGLESEL */
1696     hwnd = create_listview_control(0);
1697     for (i=0;i<items;i++) {
1698             insert_item(hwnd, 0);
1699     }
1700     item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1701     expect(items,item_count);
1702     /* deselect all items */
1703     ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1704     SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1705     for (i=0;i<3;i++) {
1706         ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
1707     }
1708
1709     r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1710     expect(3, r);
1711     r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1712 todo_wine
1713     expect(-1, r);
1714
1715     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1716     ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
1717     SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
1718     /* check that style is accepted */
1719     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1720     ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
1721
1722     for (i=0;i<3;i++) {
1723         r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
1724         ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
1725     }
1726     r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1727     expect(3, r);
1728     SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1729     expect(3, r);
1730
1731     /* select one more */
1732     ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
1733
1734     for (i=0;i<3;i++) {
1735         r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
1736         ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
1737     }
1738     r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
1739     ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
1740
1741     r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1742     expect(1, r);
1743     r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1744 todo_wine
1745     expect(-1, r);
1746
1747     /* try to select all on LVS_SINGLESEL */
1748     memset(&item, 0, sizeof(item));
1749     item.stateMask = LVIS_SELECTED;
1750     r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1751     expect(TRUE, r);
1752     SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1753
1754     item.stateMask = LVIS_SELECTED;
1755     item.state     = LVIS_SELECTED;
1756     r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1757     expect(FALSE, r);
1758
1759     r = ListView_GetSelectedCount(hwnd);
1760     expect(0, r);
1761     r = ListView_GetSelectionMark(hwnd);
1762     expect(-1, r);
1763
1764     /* try to deselect all on LVS_SINGLESEL */
1765     item.stateMask = LVIS_SELECTED;
1766     item.state     = LVIS_SELECTED;
1767     r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
1768     expect(TRUE, r);
1769
1770     item.stateMask = LVIS_SELECTED;
1771     item.state     = 0;
1772     r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1773     expect(TRUE, r);
1774     r = ListView_GetSelectedCount(hwnd);
1775     expect(0, r);
1776
1777     DestroyWindow(hwnd);
1778 }
1779
1780 static void test_subitem_rect(void)
1781 {
1782     HWND hwnd;
1783     DWORD r;
1784     LVCOLUMN col;
1785     RECT rect;
1786
1787     /* test LVM_GETSUBITEMRECT for header */
1788     hwnd = create_listview_control(0);
1789     ok(hwnd != NULL, "failed to create a listview window\n");
1790     /* add some columns */
1791     memset(&col, 0, sizeof(LVCOLUMN));
1792     col.mask = LVCF_WIDTH;
1793     col.cx = 100;
1794     r = -1;
1795     r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1796     expect(0, r);
1797     col.cx = 150;
1798     r = -1;
1799     r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
1800     expect(1, r);
1801     col.cx = 200;
1802     r = -1;
1803     r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
1804     expect(2, r);
1805     /* item = -1 means header, subitem index is 1 based */
1806     rect.left = LVIR_BOUNDS;
1807     rect.top  = 0;
1808     rect.right = rect.bottom = 0;
1809     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1810     expect(0, r);
1811
1812     rect.left = LVIR_BOUNDS;
1813     rect.top  = 1;
1814     rect.right = rect.bottom = 0;
1815     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1816
1817     ok(r != 0, "Expected not-null LRESULT\n");
1818     expect(100, rect.left);
1819     expect(250, rect.right);
1820 todo_wine
1821     expect(3, rect.top);
1822
1823     rect.left = LVIR_BOUNDS;
1824     rect.top  = 2;
1825     rect.right = rect.bottom = 0;
1826     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1827
1828     ok(r != 0, "Expected not-null LRESULT\n");
1829     expect(250, rect.left);
1830     expect(450, rect.right);
1831 todo_wine
1832     expect(3, rect.top);
1833
1834     /* item LVS_REPORT padding isn't applied to subitems */
1835     insert_item(hwnd, 0);
1836
1837     rect.left = LVIR_BOUNDS;
1838     rect.top  = 1;
1839     rect.right = rect.bottom = 0;
1840     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
1841     ok(r != 0, "Expected not-null LRESULT\n");
1842     expect(100, rect.left);
1843     expect(250, rect.right);
1844
1845     rect.left = LVIR_ICON;
1846     rect.top  = 1;
1847     rect.right = rect.bottom = 0;
1848     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
1849     ok(r != 0, "Expected not-null LRESULT\n");
1850     /* no icon attached - zero width rectangle, with no left padding */
1851     expect(100, rect.left);
1852     expect(100, rect.right);
1853
1854     rect.left = LVIR_LABEL;
1855     rect.top  = 1;
1856     rect.right = rect.bottom = 0;
1857     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
1858     ok(r != 0, "Expected not-null LRESULT\n");
1859     /* same as full LVIR_BOUNDS */
1860     expect(100, rect.left);
1861     expect(250, rect.right);
1862
1863     DestroyWindow(hwnd);
1864
1865     /* try it for non LVS_REPORT style */
1866     hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
1867                          GetModuleHandle(NULL), 0);
1868     rect.left = LVIR_BOUNDS;
1869     rect.top  = 1;
1870     rect.right = rect.bottom = -10;
1871     r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1872     ok(r == 0, "Expected not-null LRESULT\n");
1873     /* rect is unchanged */
1874     expect(0, rect.left);
1875     expect(-10, rect.right);
1876     expect(1, rect.top);
1877     expect(-10, rect.bottom);
1878     DestroyWindow(hwnd);
1879 }
1880
1881 /* comparison callback for test_sorting */
1882 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
1883 {
1884     if (first == second) return 0;
1885     return (first > second ? 1 : -1);
1886 }
1887
1888 static void test_sorting(void)
1889 {
1890     HWND hwnd;
1891     LVITEMA item = {0};
1892     DWORD r;
1893     LONG_PTR style;
1894     static CHAR names[][5] = {"A", "B", "C", "D", "0"};
1895     CHAR buff[10];
1896
1897     hwnd = create_listview_control(0);
1898     ok(hwnd != NULL, "failed to create a listview window\n");
1899
1900     /* insert some items */
1901     item.mask = LVIF_PARAM | LVIF_STATE;
1902     item.state = LVIS_SELECTED;
1903     item.iItem = 0;
1904     item.iSubItem = 0;
1905     item.lParam = 3;
1906     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
1907     expect(0, r);
1908
1909     item.mask = LVIF_PARAM;
1910     item.iItem = 1;
1911     item.iSubItem = 0;
1912     item.lParam = 2;
1913     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
1914     expect(1, r);
1915
1916     item.mask = LVIF_STATE | LVIF_PARAM;
1917     item.state = LVIS_SELECTED;
1918     item.iItem = 2;
1919     item.iSubItem = 0;
1920     item.lParam = 4;
1921     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
1922     expect(2, r);
1923
1924     r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1925     expect(-1, r);
1926
1927     r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1928     expect(2, r);
1929
1930     r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
1931     expect(TRUE, r);
1932
1933     r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1934     expect(2, r);
1935     r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1936     expect(-1, r);
1937     r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
1938     expect(0, r);
1939     r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
1940     expect(LVIS_SELECTED, r);
1941     r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
1942     expect(LVIS_SELECTED, r);
1943
1944     DestroyWindow(hwnd);
1945
1946     /* switch to LVS_SORTASCENDING when some items added */
1947     hwnd = create_listview_control(0);
1948     ok(hwnd != NULL, "failed to create a listview window\n");
1949
1950     item.mask = LVIF_TEXT;
1951     item.iItem = 0;
1952     item.iSubItem = 0;
1953     item.pszText = names[1];
1954     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
1955     expect(0, r);
1956
1957     item.mask = LVIF_TEXT;
1958     item.iItem = 1;
1959     item.iSubItem = 0;
1960     item.pszText = names[2];
1961     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
1962     expect(1, r);
1963
1964     item.mask = LVIF_TEXT;
1965     item.iItem = 2;
1966     item.iSubItem = 0;
1967     item.pszText = names[0];
1968     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
1969     expect(2, r);
1970
1971     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1972     SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
1973     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1974     ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
1975
1976     /* no sorting performed when switched to LVS_SORTASCENDING */
1977     item.mask = LVIF_TEXT;
1978     item.iItem = 0;
1979     item.pszText = buff;
1980     item.cchTextMax = sizeof(buff);
1981     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1982     expect(TRUE, r);
1983     ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
1984
1985     item.iItem = 1;
1986     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1987     expect(TRUE, r);
1988     ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
1989
1990     item.iItem = 2;
1991     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1992     expect(TRUE, r);
1993     ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
1994
1995     /* adding new item doesn't resort list */
1996     item.mask = LVIF_TEXT;
1997     item.iItem = 3;
1998     item.iSubItem = 0;
1999     item.pszText = names[3];
2000     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2001     expect(3, r);
2002
2003     item.mask = LVIF_TEXT;
2004     item.iItem = 0;
2005     item.pszText = buff;
2006     item.cchTextMax = sizeof(buff);
2007     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2008     expect(TRUE, r);
2009     ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2010
2011     item.iItem = 1;
2012     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2013     expect(TRUE, r);
2014     ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2015
2016     item.iItem = 2;
2017     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2018     expect(TRUE, r);
2019     ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2020
2021     item.iItem = 3;
2022     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2023     expect(TRUE, r);
2024     ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2025
2026     /* corner case - item should be placed at first position */
2027     item.mask = LVIF_TEXT;
2028     item.iItem = 4;
2029     item.iSubItem = 0;
2030     item.pszText = names[4];
2031     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2032     expect(0, r);
2033
2034     item.iItem = 0;
2035     item.pszText = buff;
2036     item.cchTextMax = sizeof(buff);
2037     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2038     expect(TRUE, r);
2039     ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2040
2041     item.iItem = 1;
2042     item.pszText = buff;
2043     item.cchTextMax = sizeof(buff);
2044     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2045     expect(TRUE, r);
2046     ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2047
2048     item.iItem = 2;
2049     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2050     expect(TRUE, r);
2051     ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2052
2053     item.iItem = 3;
2054     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2055     expect(TRUE, r);
2056     ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2057
2058     item.iItem = 4;
2059     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2060     expect(TRUE, r);
2061     ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2062
2063     DestroyWindow(hwnd);
2064 }
2065
2066 static void test_ownerdata(void)
2067 {
2068     HWND hwnd;
2069     LONG_PTR style, ret;
2070     DWORD res;
2071     LVITEMA item;
2072
2073     /* it isn't possible to set LVS_OWNERDATA after creation */
2074     hwnd = create_listview_control(0);
2075     ok(hwnd != NULL, "failed to create a listview window\n");
2076     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2077     ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2078
2079     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2080
2081     ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2082     ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2083     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2084                 "try to switch to LVS_OWNERDATA seq", FALSE);
2085
2086     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2087     ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2088     DestroyWindow(hwnd);
2089
2090     /* try to set LVS_OWNERDATA after creation just having it */
2091     hwnd = create_listview_control(LVS_OWNERDATA);
2092     ok(hwnd != NULL, "failed to create a listview window\n");
2093     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2094     ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2095
2096     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2097
2098     ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2099     ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2100     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2101                 "try to switch to LVS_OWNERDATA seq", FALSE);
2102     DestroyWindow(hwnd);
2103
2104     /* try to remove LVS_OWNERDATA after creation just having it */
2105     hwnd = create_listview_control(LVS_OWNERDATA);
2106     ok(hwnd != NULL, "failed to create a listview window\n");
2107     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2108     ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2109
2110     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2111
2112     ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2113     ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2114     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2115                 "try to switch to LVS_OWNERDATA seq", FALSE);
2116     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2117     ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2118     DestroyWindow(hwnd);
2119
2120     /* try select an item */
2121     hwnd = create_listview_control(LVS_OWNERDATA);
2122     ok(hwnd != NULL, "failed to create a listview window\n");
2123     res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2124     ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2125     res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2126     expect(0, res);
2127     memset(&item, 0, sizeof(item));
2128     item.stateMask = LVIS_SELECTED;
2129     item.state     = LVIS_SELECTED;
2130     res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2131     expect(TRUE, res);
2132     res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2133     expect(1, res);
2134     res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2135     expect(1, res);
2136     DestroyWindow(hwnd);
2137
2138     /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2139     hwnd = create_listview_control(LVS_OWNERDATA);
2140     ok(hwnd != NULL, "failed to create a listview window\n");
2141     res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2142     ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2143     res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2144     expect(1, res);
2145     memset(&item, 0, sizeof(item));
2146     item.mask = LVIF_STATE;
2147     item.iItem = 0;
2148     item.stateMask = LVIS_SELECTED;
2149     item.state     = LVIS_SELECTED;
2150     res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2151     expect(FALSE, res);
2152     DestroyWindow(hwnd);
2153
2154     /* check notifications after focused/selected changed */
2155     hwnd = create_listview_control(LVS_OWNERDATA);
2156     ok(hwnd != NULL, "failed to create a listview window\n");
2157     res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2158     ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2159
2160     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2161
2162     memset(&item, 0, sizeof(item));
2163     item.stateMask = LVIS_SELECTED;
2164     item.state     = LVIS_SELECTED;
2165     res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2166     expect(TRUE, res);
2167
2168     ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2169                 "ownerdata select notification", TRUE);
2170
2171     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2172
2173     memset(&item, 0, sizeof(item));
2174     item.stateMask = LVIS_FOCUSED;
2175     item.state     = LVIS_FOCUSED;
2176     res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2177     expect(TRUE, res);
2178
2179     ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2180                 "ownerdata focus notification", TRUE);
2181     DestroyWindow(hwnd);
2182
2183     /* check notifications on LVM_GETITEM */
2184     /* zero callback mask */
2185     hwnd = create_listview_control(LVS_OWNERDATA);
2186     ok(hwnd != NULL, "failed to create a listview window\n");
2187     res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2188     ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2189
2190     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2191
2192     memset(&item, 0, sizeof(item));
2193     item.stateMask = LVIS_SELECTED;
2194     item.mask      = LVIF_STATE;
2195     res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2196     expect(TRUE, res);
2197
2198     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2199                 "ownerdata getitem selected state 1", FALSE);
2200
2201     /* non zero callback mask but not we asking for */
2202     res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2203     expect(TRUE, res);
2204
2205     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2206
2207     memset(&item, 0, sizeof(item));
2208     item.stateMask = LVIS_SELECTED;
2209     item.mask      = LVIF_STATE;
2210     res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2211     expect(TRUE, res);
2212
2213     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2214                 "ownerdata getitem selected state 2", FALSE);
2215
2216     /* LVIS_OVERLAYMASK callback mask, asking for index */
2217     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2218
2219     memset(&item, 0, sizeof(item));
2220     item.stateMask = LVIS_OVERLAYMASK;
2221     item.mask      = LVIF_STATE;
2222     res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2223     expect(TRUE, res);
2224
2225     ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2226                 "ownerdata getitem selected state 2", FALSE);
2227
2228     DestroyWindow(hwnd);
2229
2230     /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2231     hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING);
2232     ok(hwnd != NULL, "failed to create a listview window\n");
2233     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2234     ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2235     ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2236     SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2237     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2238     ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2239     DestroyWindow(hwnd);
2240     /* apparently it's allowed to switch these style on after creation */
2241     hwnd = create_listview_control(LVS_OWNERDATA);
2242     ok(hwnd != NULL, "failed to create a listview window\n");
2243     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2244     ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2245     SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2246     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2247     ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2248     DestroyWindow(hwnd);
2249
2250     hwnd = create_listview_control(LVS_OWNERDATA);
2251     ok(hwnd != NULL, "failed to create a listview window\n");
2252     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2253     ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2254     SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2255     style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2256     ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2257     DestroyWindow(hwnd);
2258 }
2259
2260 static void test_norecompute(void)
2261 {
2262     static CHAR testA[] = "test";
2263     CHAR buff[10];
2264     LVITEMA item;
2265     HWND hwnd;
2266     DWORD res;
2267
2268     /* self containing control */
2269     hwnd = create_listview_control(0);
2270     ok(hwnd != NULL, "failed to create a listview window\n");
2271     memset(&item, 0, sizeof(item));
2272     item.mask = LVIF_TEXT | LVIF_STATE;
2273     item.iItem = 0;
2274     item.stateMask = LVIS_SELECTED;
2275     item.state     = LVIS_SELECTED;
2276     item.pszText   = testA;
2277     res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2278     expect(0, res);
2279     /* retrieve with LVIF_NORECOMPUTE */
2280     item.mask  = LVIF_TEXT | LVIF_NORECOMPUTE;
2281     item.iItem = 0;
2282     item.pszText    = buff;
2283     item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2284     res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2285     expect(TRUE, res);
2286     ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2287
2288     item.mask = LVIF_TEXT;
2289     item.iItem = 1;
2290     item.pszText = LPSTR_TEXTCALLBACK;
2291     res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2292     expect(1, res);
2293
2294     item.mask  = LVIF_TEXT | LVIF_NORECOMPUTE;
2295     item.iItem = 1;
2296     item.pszText    = buff;
2297     item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2298
2299     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2300     res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2301     expect(TRUE, res);
2302     ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2303        LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2304     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2305
2306     DestroyWindow(hwnd);
2307
2308     /* LVS_OWNERDATA */
2309     hwnd = create_listview_control(LVS_OWNERDATA);
2310     ok(hwnd != NULL, "failed to create a listview window\n");
2311
2312     item.mask = LVIF_STATE;
2313     item.stateMask = LVIS_SELECTED;
2314     item.state     = LVIS_SELECTED;
2315     item.iItem = 0;
2316     res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2317     expect(0, res);
2318
2319     item.mask  = LVIF_TEXT | LVIF_NORECOMPUTE;
2320     item.iItem = 0;
2321     item.pszText    = buff;
2322     item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2323     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2324     res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2325     expect(TRUE, res);
2326     ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2327        LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2328     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2329
2330     DestroyWindow(hwnd);
2331 }
2332
2333 static void test_nosortheader(void)
2334 {
2335     HWND hwnd, header;
2336     LONG_PTR style;
2337
2338     hwnd = create_listview_control(0);
2339     ok(hwnd != NULL, "failed to create a listview window\n");
2340
2341     header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2342     ok(IsWindow(header), "header expected\n");
2343
2344     style = GetWindowLongPtr(header, GWL_STYLE);
2345     ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2346
2347     style = GetWindowLongPtr(hwnd, GWL_STYLE);
2348     SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2349     /* HDS_BUTTONS retained */
2350     style = GetWindowLongPtr(header, GWL_STYLE);
2351     ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2352
2353     DestroyWindow(hwnd);
2354
2355     /* create with LVS_NOSORTHEADER */
2356     hwnd = create_listview_control(LVS_NOSORTHEADER);
2357     ok(hwnd != NULL, "failed to create a listview window\n");
2358
2359     header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2360     ok(IsWindow(header), "header expected\n");
2361
2362     style = GetWindowLongPtr(header, GWL_STYLE);
2363     ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2364
2365     style = GetWindowLongPtr(hwnd, GWL_STYLE);
2366     SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2367     /* not changed here */
2368     style = GetWindowLongPtr(header, GWL_STYLE);
2369     ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2370
2371     DestroyWindow(hwnd);
2372 }
2373
2374 static void test_setredraw(void)
2375 {
2376     HWND hwnd;
2377     DWORD_PTR style;
2378     DWORD ret;
2379
2380     hwnd = create_listview_control(0);
2381     ok(hwnd != NULL, "failed to create a listview window\n");
2382
2383     /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2384        ListView seems to handle it internally without DefWinProc */
2385
2386     /* default value first */
2387     ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2388     expect(0, ret);
2389     /* disable */
2390     style = GetWindowLongPtr(hwnd, GWL_STYLE);
2391     ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2392     ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2393     expect(0, ret);
2394     style = GetWindowLongPtr(hwnd, GWL_STYLE);
2395     ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2396
2397     DestroyWindow(hwnd);
2398 }
2399
2400 static void test_hittest(void)
2401 {
2402     HWND hwnd;
2403     DWORD r;
2404     RECT bounds;
2405     LVITEMA item;
2406     static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2407     POINT pos;
2408     INT x, y;
2409     HIMAGELIST himl, himl2;
2410     HBITMAP hbmp;
2411
2412     hwnd = create_listview_control(0);
2413     ok(hwnd != NULL, "failed to create a listview window\n");
2414
2415     /* LVS_REPORT with a single subitem (2 columns) */
2416     insert_column(hwnd, 0);
2417     insert_column(hwnd, 1);
2418     insert_item(hwnd, 0);
2419
2420     item.iSubItem = 0;
2421     /* the only purpose of that line is to be as long as a half item rect */
2422     item.pszText  = text;
2423     r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2424     expect(TRUE, r);
2425
2426     r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2427     expect(TRUE, r);
2428     r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
2429     expect(TRUE, r);
2430
2431     memset(&bounds, 0, sizeof(bounds));
2432     bounds.left = LVIR_BOUNDS;
2433     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
2434     ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
2435     ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
2436     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
2437     expect(TRUE, r);
2438
2439     /* LVS_EX_FULLROWSELECT not set, no icons attached */
2440     x = pos.x + 50; /* column half width */
2441     y = pos.y + (bounds.bottom - bounds.top) / 2;
2442     test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, FALSE, FALSE, __LINE__);
2443     test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2444     x = pos.x + 150; /* outside column */
2445     y = pos.y + (bounds.bottom - bounds.top) / 2;
2446     test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2447     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, TRUE, TRUE, TRUE, __LINE__);
2448     /* parent client area is 100x100 by default */
2449     MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
2450     x = pos.x + 150; /* outside column */
2451     y = pos.y + (bounds.bottom - bounds.top) / 2;
2452     test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, FALSE, FALSE, __LINE__);
2453     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2454     /* the same with LVS_EX_FULLROWSELECT */
2455     SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
2456     x = pos.x + 150; /* outside column */
2457     y = pos.y + (bounds.bottom - bounds.top) / 2;
2458     test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, FALSE, FALSE, __LINE__);
2459     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2460     MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
2461     x = pos.x + 150; /* outside column */
2462     y = pos.y + (bounds.bottom - bounds.top) / 2;
2463     test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2464     test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, TRUE, TRUE, TRUE, __LINE__);
2465     /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2466     himl = ImageList_Create(16, 16, 0, 4, 4);
2467     ok(himl != NULL, "failed to create imagelist\n");
2468     hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2469     ok(hbmp != NULL, "failed to create bitmap\n");
2470     r = ImageList_Add(himl, hbmp, 0);
2471     ok(r == 0, "should be zero\n");
2472     hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2473     ok(hbmp != NULL, "failed to create bitmap\n");
2474     r = ImageList_Add(himl, hbmp, 0);
2475     ok(r == 1, "should be one\n");
2476
2477     r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2478     ok(r == 0, "should return zero\n");
2479
2480     item.mask = LVIF_IMAGE;
2481     item.iImage = 0;
2482     item.iItem = 0;
2483     item.iSubItem = 0;
2484     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2485     expect(TRUE, r);
2486     /* on state icon */
2487     x = pos.x + 8;
2488     y = pos.y + (bounds.bottom - bounds.top) / 2;
2489     test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2490     test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2491
2492     /* state icons indices are 1 based, check with valid index */
2493     item.mask = LVIF_STATE;
2494     item.state = INDEXTOSTATEIMAGEMASK(1);
2495     item.stateMask = LVIS_STATEIMAGEMASK;
2496     item.iItem = 0;
2497     item.iSubItem = 0;
2498     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2499     expect(TRUE, r);
2500     /* on state icon */
2501     x = pos.x + 8;
2502     y = pos.y + (bounds.bottom - bounds.top) / 2;
2503     test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2504     test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2505
2506     himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
2507     ok(himl2 == himl, "should return handle\n");
2508
2509     r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
2510     ok(r == 0, "should return zero\n");
2511     /* on item icon */
2512     x = pos.x + 8;
2513     y = pos.y + (bounds.bottom - bounds.top) / 2;
2514     test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, FALSE, FALSE, __LINE__);
2515     test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
2516
2517     DestroyWindow(hwnd);
2518 }
2519
2520 static void test_getviewrect(void)
2521 {
2522     HWND hwnd;
2523     DWORD r;
2524     RECT rect;
2525     LVITEMA item;
2526
2527     hwnd = create_listview_control(0);
2528     ok(hwnd != NULL, "failed to create a listview window\n");
2529
2530     /* empty */
2531     r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2532     expect(TRUE, r);
2533
2534     insert_column(hwnd, 0);
2535     insert_column(hwnd, 1);
2536
2537     memset(&item, 0, sizeof(item));
2538     item.iItem = 0;
2539     item.iSubItem = 0;
2540     SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2541
2542     r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2543     expect(TRUE, r);
2544     r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
2545     expect(TRUE, r);
2546
2547     rect.left = rect.right = rect.top = rect.bottom = -1;
2548     r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2549     expect(TRUE, r);
2550     /* left is set to (2e31-1) - XP SP2 */
2551     expect(0, rect.right);
2552     expect(0, rect.top);
2553     expect(0, rect.bottom);
2554
2555     /* switch to LVS_ICON */
2556     SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
2557
2558     rect.left = rect.right = rect.top = rect.bottom = -1;
2559     r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2560     expect(TRUE, r);
2561     expect(0, rect.left);
2562     expect(0, rect.top);
2563     /* precise value differs for 2k, XP and Vista */
2564     ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
2565     ok(rect.right  > 0, "Expected positive right value, got %d\n", rect.right);
2566
2567     DestroyWindow(hwnd);
2568 }
2569
2570 static void test_getitemposition(void)
2571 {
2572     HWND hwnd, header;
2573     DWORD r;
2574     POINT pt;
2575     RECT rect;
2576
2577     hwnd = create_listview_control(0);
2578     ok(hwnd != NULL, "failed to create a listview window\n");
2579     header = subclass_header(hwnd);
2580
2581     /* LVS_REPORT, single item, no columns added */
2582     insert_item(hwnd, 0);
2583
2584     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2585
2586     pt.x = pt.y = -1;
2587     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2588     expect(TRUE, r);
2589     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
2590
2591     /* LVS_REPORT, single item, single column */
2592     insert_column(hwnd, 0);
2593
2594     flush_sequences(sequences, NUM_MSG_SEQUENCES);
2595
2596     pt.x = pt.y = -1;
2597     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2598     expect(TRUE, r);
2599     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
2600
2601     memset(&rect, 0, sizeof(rect));
2602     SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
2603     /* some padding? */
2604     expect(2, pt.x);
2605     /* offset by header height */
2606     expect(rect.bottom - rect.top, pt.y);
2607
2608     DestroyWindow(hwnd);
2609 }
2610
2611 static void test_columnscreation(void)
2612 {
2613     HWND hwnd, header;
2614     DWORD r;
2615
2616     hwnd = create_listview_control(0);
2617     ok(hwnd != NULL, "failed to create a listview window\n");
2618
2619     insert_item(hwnd, 0);
2620
2621     /* headers columns aren't created automatically */
2622     header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
2623     ok(IsWindow(header), "Expected header handle\n");
2624     r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
2625     expect(0, r);
2626
2627     DestroyWindow(hwnd);
2628 }
2629
2630 static void test_getitemrect(void)
2631 {
2632     HWND hwnd;
2633     HIMAGELIST himl;
2634     HBITMAP hbm;
2635     RECT rect;
2636     DWORD r;
2637     LVITEMA item;
2638     LVCOLUMNA col;
2639     INT order[2];
2640     POINT pt;
2641
2642     hwnd = create_listview_control(0);
2643     ok(hwnd != NULL, "failed to create a listview window\n");
2644
2645     /* empty item */
2646     memset(&item, 0, sizeof(item));
2647     item.iItem = 0;
2648     item.iSubItem = 0;
2649     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2650     expect(0, r);
2651
2652     rect.left = LVIR_BOUNDS;
2653     rect.right = rect.top = rect.bottom = -1;
2654     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2655     expect(TRUE, r);
2656
2657     /* zero width rectangle with no padding */
2658     expect(0, rect.left);
2659     todo_wine expect(0, rect.right);
2660
2661     insert_column(hwnd, 0);
2662     insert_column(hwnd, 1);
2663
2664     col.mask = LVCF_WIDTH;
2665     col.cx   = 50;
2666     r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
2667     expect(TRUE, r);
2668
2669     col.mask = LVCF_WIDTH;
2670     col.cx   = 100;
2671     r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
2672     expect(TRUE, r);
2673
2674     rect.left = LVIR_BOUNDS;
2675     rect.right = rect.top = rect.bottom = -1;
2676     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2677     expect(TRUE, r);
2678
2679     /* still no left padding */
2680     expect(0, rect.left);
2681     expect(150, rect.right);
2682
2683     rect.left = LVIR_SELECTBOUNDS;
2684     rect.right = rect.top = rect.bottom = -1;
2685     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2686     expect(TRUE, r);
2687     /* padding */
2688     expect(2, rect.left);
2689
2690     rect.left = LVIR_LABEL;
2691     rect.right = rect.top = rect.bottom = -1;
2692     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2693     expect(TRUE, r);
2694     /* padding, column width */
2695     expect(2, rect.left);
2696     expect(50, rect.right);
2697
2698     /* no icons attached */
2699     rect.left = LVIR_ICON;
2700     rect.right = rect.top = rect.bottom = -1;
2701     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2702     expect(TRUE, r);
2703     /* padding */
2704     expect(2, rect.left);
2705     expect(2, rect.right);
2706
2707     /* change order */
2708     order[0] = 1; order[1] = 0;
2709     r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
2710     expect(TRUE, r);
2711     pt.x = -1;
2712     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2713     expect(TRUE, r);
2714     /* 1 indexed column width + padding */
2715     todo_wine expect(102, pt.x);
2716     /* rect is at zero too */
2717     rect.left = LVIR_BOUNDS;
2718     rect.right = rect.top = rect.bottom = -1;
2719     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2720     expect(TRUE, r);
2721     expect(0, rect.left);
2722     /* just width sum */
2723     expect(150, rect.right);
2724
2725     rect.left = LVIR_SELECTBOUNDS;
2726     rect.right = rect.top = rect.bottom = -1;
2727     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2728     expect(TRUE, r);
2729     /* column width + padding */
2730     todo_wine expect(102, rect.left);
2731
2732     /* back to initial order */
2733     order[0] = 0; order[1] = 1;
2734     r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
2735     expect(TRUE, r);
2736
2737     /* state icons */
2738     himl = ImageList_Create(16, 16, 0, 2, 2);
2739     ok(himl != NULL, "failed to create imagelist\n");
2740     hbm = CreateBitmap(16, 16, 1, 1, NULL);
2741     ok(hbm != NULL, "failed to create bitmap\n");
2742     r = ImageList_Add(himl, hbm, 0);
2743     ok(r == 0, "should be zero\n");
2744     hbm = CreateBitmap(16, 16, 1, 1, NULL);
2745     ok(hbm != NULL, "failed to create bitmap\n");
2746     r = ImageList_Add(himl, hbm, 0);
2747     ok(r == 1, "should be one\n");
2748
2749     r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2750     ok(r == 0, "should return zero\n");
2751
2752     item.mask = LVIF_STATE;
2753     item.state = INDEXTOSTATEIMAGEMASK(1);
2754     item.stateMask = LVIS_STATEIMAGEMASK;
2755     item.iItem = 0;
2756     item.iSubItem = 0;
2757     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2758     expect(TRUE, r);
2759
2760     /* icon bounds */
2761     rect.left = LVIR_ICON;
2762     rect.right = rect.top = rect.bottom = -1;
2763     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2764     expect(TRUE, r);
2765     /* padding + stateicon width */
2766     expect(18, rect.left);
2767     expect(18, rect.right);
2768     /* label bounds */
2769     rect.left = LVIR_LABEL;
2770     rect.right = rect.top = rect.bottom = -1;
2771     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2772     expect(TRUE, r);
2773     /* padding + stateicon width -> column width */
2774     expect(18, rect.left);
2775     expect(50, rect.right);
2776
2777     r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
2778     ok(r != 0, "should return current list handle\n");
2779
2780     r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
2781     ok(r == 0, "should return zero\n");
2782
2783     item.mask = LVIF_STATE | LVIF_IMAGE;
2784     item.iImage = 1;
2785     item.state = 0;
2786     item.stateMask = ~0;
2787     item.iItem = 0;
2788     item.iSubItem = 0;
2789     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2790     expect(TRUE, r);
2791
2792     /* icon bounds */
2793     rect.left = LVIR_ICON;
2794     rect.right = rect.top = rect.bottom = -1;
2795     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2796     expect(TRUE, r);
2797     /* padding, icon width */
2798     expect(2, rect.left);
2799     expect(18, rect.right);
2800     /* label bounds */
2801     rect.left = LVIR_LABEL;
2802     rect.right = rect.top = rect.bottom = -1;
2803     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2804     expect(TRUE, r);
2805     /* padding + icon width -> column width */
2806     expect(18, rect.left);
2807     expect(50, rect.right);
2808
2809     /* select bounds */
2810     rect.left = LVIR_SELECTBOUNDS;
2811     rect.right = rect.top = rect.bottom = -1;
2812     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2813     expect(TRUE, r);
2814     /* padding, column width */
2815     expect(2, rect.left);
2816     todo_wine expect(50, rect.right);
2817
2818     /* try with indentation */
2819     item.mask = LVIF_INDENT;
2820     item.iIndent = 1;
2821     item.iItem = 0;
2822     item.iSubItem = 0;
2823     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2824     expect(TRUE, r);
2825
2826     /* bounds */
2827     rect.left = LVIR_BOUNDS;
2828     rect.right = rect.top = rect.bottom = -1;
2829     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2830     expect(TRUE, r);
2831     /* padding + 1 icon width, column width */
2832     expect(0, rect.left);
2833     expect(150, rect.right);
2834
2835     /* select bounds */
2836     rect.left = LVIR_SELECTBOUNDS;
2837     rect.right = rect.top = rect.bottom = -1;
2838     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2839     expect(TRUE, r);
2840     /* padding + 1 icon width, column width */
2841     expect(2 + 16, rect.left);
2842     todo_wine expect(50, rect.right);
2843
2844     /* label bounds */
2845     rect.left = LVIR_LABEL;
2846     rect.right = rect.top = rect.bottom = -1;
2847     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2848     expect(TRUE, r);
2849     /* padding + 2 icon widths, column width */
2850     expect(2 + 16*2, rect.left);
2851     expect(50, rect.right);
2852
2853     /* icon bounds */
2854     rect.left = LVIR_ICON;
2855     rect.right = rect.top = rect.bottom = -1;
2856     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2857     expect(TRUE, r);
2858     /* padding + 1 icon width indentation, icon width */
2859     expect(2 + 16, rect.left);
2860     expect(34, rect.right);
2861
2862
2863     DestroyWindow(hwnd);
2864 }
2865
2866 static void test_editbox(void)
2867 {
2868     HWND hwnd, hwndedit, hwndedit2;
2869     LVITEMA item;
2870     DWORD r;
2871     static CHAR testitemA[]  = "testitem";
2872     static CHAR testitem1A[] = "testitem1";
2873     static CHAR buffer[10];
2874
2875     hwnd = create_listview_control(LVS_EDITLABELS);
2876     ok(hwnd != NULL, "failed to create a listview window\n");
2877
2878     insert_column(hwnd, 0);
2879
2880     memset(&item, 0, sizeof(item));
2881     item.mask = LVIF_TEXT;
2882     item.pszText = testitemA;
2883     item.iItem = 0;
2884     item.iSubItem = 0;
2885     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2886     expect(0, r);
2887
2888     /* setting focus is necessary */
2889     SetFocus(hwnd);
2890     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
2891     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
2892
2893     /* modify initial string */
2894     r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
2895     expect(TRUE, r);
2896     /* return focus to listview */
2897     SetFocus(hwnd);
2898
2899     memset(&item, 0, sizeof(item));
2900     item.mask = LVIF_TEXT;
2901     item.pszText = buffer;
2902     item.cchTextMax = 10;
2903     item.iItem = 0;
2904     item.iSubItem = 0;
2905     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2906     expect(TRUE, r);
2907
2908     ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
2909
2910     /* send LVM_EDITLABEL on already created edit */
2911     SetFocus(hwnd);
2912     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
2913     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
2914     /* focus will be set to edit */
2915     ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
2916     hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
2917     ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
2918
2919     /* creating label disabled when control isn't focused */
2920     SetFocus(0);
2921     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
2922     todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
2923
2924     /* check EN_KILLFOCUS handling */
2925     memset(&item, 0, sizeof(item));
2926     item.pszText = testitemA;
2927     item.iItem = 0;
2928     item.iSubItem = 0;
2929     r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
2930     expect(TRUE, r);
2931
2932     SetFocus(hwnd);
2933     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
2934     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
2935     /* modify edit and notify control that it lost focus */
2936     r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
2937     expect(TRUE, r);
2938     r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
2939     expect(0, r);
2940     memset(&item, 0, sizeof(item));
2941     item.pszText = buffer;
2942     item.cchTextMax = 10;
2943     item.iItem = 0;
2944     item.iSubItem = 0;
2945     r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
2946     expect(lstrlen(item.pszText), r);
2947     ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
2948     /* end edit without saving */
2949     r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
2950     expect(0, r);
2951     memset(&item, 0, sizeof(item));
2952     item.pszText = buffer;
2953     item.cchTextMax = 10;
2954     item.iItem = 0;
2955     item.iSubItem = 0;
2956     r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
2957     expect(lstrlen(item.pszText), r);
2958     ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
2959
2960     /* LVM_EDITLABEL with -1 destroys current edit */
2961     hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
2962     ok(hwndedit == NULL, "Expected Edit window not to be created\n");
2963     /* no edit present */
2964     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
2965     ok(hwndedit == NULL, "Expected Edit window not to be created\n");
2966     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
2967     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
2968     /* edit present */
2969     ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
2970     hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
2971     ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
2972     ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
2973     ok(GetFocus() == hwnd, "Expected List to be focused\n");
2974     /* check another negative value */
2975     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
2976     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
2977     ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
2978     hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
2979     ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
2980     ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
2981     ok(GetFocus() == hwnd, "Expected List to be focused\n");
2982     /* and value greater then max item index */
2983     hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
2984     ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
2985     ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
2986     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2987     hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
2988     ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
2989     ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
2990     ok(GetFocus() == hwnd, "Expected List to be focused\n");
2991
2992     DestroyWindow(hwnd);
2993 }
2994
2995 START_TEST(listview)
2996 {
2997     HMODULE hComctl32;
2998     BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
2999
3000     hComctl32 = GetModuleHandleA("comctl32.dll");
3001     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
3002     if (pInitCommonControlsEx)
3003     {
3004         INITCOMMONCONTROLSEX iccex;
3005         iccex.dwSize = sizeof(iccex);
3006         iccex.dwICC  = ICC_LISTVIEW_CLASSES;
3007         pInitCommonControlsEx(&iccex);
3008     }
3009     else
3010         InitCommonControls();
3011
3012     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
3013
3014     flush_sequences(sequences, NUM_MSG_SEQUENCES);
3015     hwndparent = create_parent_window();
3016     ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent window", TRUE);
3017     flush_sequences(sequences, NUM_MSG_SEQUENCES);
3018
3019     test_images();
3020     test_checkboxes();
3021     test_items();
3022     test_create();
3023     test_redraw();
3024     test_customdraw();
3025     test_icon_spacing();
3026     test_color();
3027     test_item_count();
3028     test_item_position();
3029     test_columns();
3030     test_getorigin();
3031     test_multiselect();
3032     test_getitemrect();
3033     test_subitem_rect();
3034     test_sorting();
3035     test_ownerdata();
3036     test_norecompute();
3037     test_nosortheader();
3038     test_setredraw();
3039     test_hittest();
3040     test_getviewrect();
3041     test_getitemposition();
3042     test_columnscreation();
3043     test_editbox();
3044
3045     DestroyWindow(hwndparent);
3046 }