msi: Set all folders' source paths to the root directory if the source type is compre...
[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 LISTVIEW_SEQ_INDEX  1
31 #define NUM_MSG_SEQUENCES   2
32
33 #define LISTVIEW_ID 0
34 #define HEADER_ID   1
35
36 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
37 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
38        "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
39
40 HWND hwndparent;
41
42 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
43
44 static const struct message create_parent_wnd_seq[] = {
45     { WM_GETMINMAXINFO,     sent },
46     { WM_NCCREATE,          sent },
47     { WM_NCCALCSIZE,        sent|wparam, 0 },
48     { WM_CREATE,            sent },
49     { WM_SHOWWINDOW,        sent|wparam, 1 },
50     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
51     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
52     { WM_ACTIVATEAPP,       sent|wparam, 1 },
53     { WM_NCACTIVATE,        sent|wparam, 1 },
54     { WM_ACTIVATE,          sent|wparam, 1 },
55     { WM_IME_SETCONTEXT,    sent|wparam|defwinproc|optional, 1 },
56     { WM_IME_NOTIFY,        sent|defwinproc|optional },
57     { WM_SETFOCUS,          sent|wparam|defwinproc, 0 },
58     /* Win9x adds SWP_NOZORDER below */
59     { WM_WINDOWPOSCHANGED,  sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
60     { WM_NCCALCSIZE,        sent|wparam|optional, 1 },
61     { WM_SIZE,              sent },
62     { WM_MOVE,              sent },
63     { 0 }
64 };
65
66 static const struct message redraw_listview_seq[] = {
67     { WM_PAINT,      sent|id,            0, 0, LISTVIEW_ID },
68     { WM_PAINT,      sent|id,            0, 0, HEADER_ID },
69     { WM_NCPAINT,    sent|id|defwinproc, 0, 0, HEADER_ID },
70     { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, HEADER_ID },
71     { WM_NOTIFY,     sent|id|defwinproc, 0, 0, LISTVIEW_ID },
72     { WM_NCPAINT,    sent|id|defwinproc, 0, 0, LISTVIEW_ID },
73     { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
74     { 0 }
75 };
76
77 static const struct message listview_icon_spacing_seq[] = {
78     { LVM_SETICONSPACING, sent|lparam, 0, (LPARAM) MAKELONG(20, 30) },
79     { LVM_SETICONSPACING, sent|lparam, 0, (LPARAM) MAKELONG(25, 35) },
80     { LVM_SETICONSPACING, sent|lparam, 0, (LPARAM) MAKELONG(-1, -1) },
81     { 0 }
82 };
83
84 static const struct message listview_color_seq[] = {
85     { LVM_SETBKCOLOR,     sent|lparam, 0, RGB(0,0,0) },
86     { LVM_GETBKCOLOR,     sent },
87     { LVM_SETTEXTCOLOR,   sent|lparam, 0, RGB(0,0,0) },
88     { LVM_GETTEXTCOLOR,   sent },
89     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
90     { LVM_GETTEXTBKCOLOR, sent },
91
92     { LVM_SETBKCOLOR,     sent|lparam, 0, RGB(100,50,200) },
93     { LVM_GETBKCOLOR,     sent },
94     { LVM_SETTEXTCOLOR,   sent|lparam, 0, RGB(100,50,200) },
95     { LVM_GETTEXTCOLOR,   sent },
96     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
97     { LVM_GETTEXTBKCOLOR, sent },
98
99     { LVM_SETBKCOLOR,     sent|lparam, 0, CLR_NONE },
100     { LVM_GETBKCOLOR,     sent },
101     { LVM_SETTEXTCOLOR,   sent|lparam, 0, CLR_NONE },
102     { LVM_GETTEXTCOLOR,   sent },
103     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
104     { LVM_GETTEXTBKCOLOR, sent },
105
106     { LVM_SETBKCOLOR,     sent|lparam, 0, RGB(255,255,255) },
107     { LVM_GETBKCOLOR,     sent },
108     { LVM_SETTEXTCOLOR,   sent|lparam, 0, RGB(255,255,255) },
109     { LVM_GETTEXTCOLOR,   sent },
110     { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
111     { LVM_GETTEXTBKCOLOR, sent },
112     { 0 }
113 };
114
115 static const struct message listview_item_count_seq[] = {
116     { LVM_GETITEMCOUNT,   sent },
117     { LVM_INSERTITEM,     sent },
118     { LVM_INSERTITEM,     sent },
119     { LVM_INSERTITEM,     sent },
120     { LVM_GETITEMCOUNT,   sent },
121     { LVM_DELETEITEM,     sent|wparam, 2 },
122     { LVM_GETITEMCOUNT,   sent },
123     { LVM_DELETEALLITEMS, sent },
124     { LVM_GETITEMCOUNT,   sent },
125     { LVM_INSERTITEM,     sent },
126     { LVM_INSERTITEM,     sent },
127     { LVM_GETITEMCOUNT,   sent },
128     { LVM_INSERTITEM,     sent },
129     { LVM_GETITEMCOUNT,   sent },
130     { 0 }
131 };
132
133 static const struct message listview_itempos_seq[] = {
134     { LVM_INSERTITEM,      sent },
135     { LVM_INSERTITEM,      sent },
136     { LVM_INSERTITEM,      sent },
137     { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
138     { LVM_GETITEMPOSITION, sent|wparam,        1 },
139     { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
140     { LVM_GETITEMPOSITION, sent|wparam,        2 },
141     { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
142     { LVM_GETITEMPOSITION, sent|wparam,        0 },
143     { 0 }
144 };
145
146 struct subclass_info
147 {
148     WNDPROC oldproc;
149 };
150
151 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
152 {
153     static long defwndproc_counter = 0;
154     LRESULT ret;
155     struct message msg;
156
157     /* do not log painting messages */
158     if (message != WM_PAINT &&
159         message != WM_ERASEBKGND &&
160         message != WM_NCPAINT &&
161         message != WM_NCHITTEST &&
162         message != WM_GETTEXT &&
163         message != WM_GETICON &&
164         message != WM_DEVICECHANGE)
165     {
166         trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
167
168         msg.message = message;
169         msg.flags = sent|wparam|lparam;
170         if (defwndproc_counter) msg.flags |= defwinproc;
171         msg.wParam = wParam;
172         msg.lParam = lParam;
173         add_message(sequences, PARENT_SEQ_INDEX, &msg);
174     }
175
176     defwndproc_counter++;
177     ret = DefWindowProcA(hwnd, message, wParam, lParam);
178     defwndproc_counter--;
179
180     return ret;
181 }
182
183 static BOOL register_parent_wnd_class(void)
184 {
185     WNDCLASSA cls;
186
187     cls.style = 0;
188     cls.lpfnWndProc = parent_wnd_proc;
189     cls.cbClsExtra = 0;
190     cls.cbWndExtra = 0;
191     cls.hInstance = GetModuleHandleA(NULL);
192     cls.hIcon = 0;
193     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
194     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
195     cls.lpszMenuName = NULL;
196     cls.lpszClassName = "Listview test parent class";
197     return RegisterClassA(&cls);
198 }
199
200 static HWND create_parent_window(void)
201 {
202     if (!register_parent_wnd_class())
203         return NULL;
204
205     return CreateWindowEx(0, "Listview test parent class",
206                           "Listview test parent window",
207                           WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
208                           WS_MAXIMIZEBOX | WS_VISIBLE,
209                           0, 0, 100, 100,
210                           GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
211 }
212
213 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
214 {
215     struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
216     static long defwndproc_counter = 0;
217     LRESULT ret;
218     struct message msg;
219
220     trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
221
222     msg.message = message;
223     msg.flags = sent|wparam|lparam;
224     if (defwndproc_counter) msg.flags |= defwinproc;
225     msg.wParam = wParam;
226     msg.lParam = lParam;
227     msg.id = LISTVIEW_ID;
228     add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
229
230     defwndproc_counter++;
231     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
232     defwndproc_counter--;
233     return ret;
234 }
235
236 static HWND create_listview_control(void)
237 {
238     struct subclass_info *info;
239     HWND hwnd;
240     RECT rect;
241
242     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
243     if (!info)
244         return NULL;
245
246     GetClientRect(hwndparent, &rect);
247     hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
248                            WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
249                            0, 0, rect.right, rect.bottom,
250                            hwndparent, NULL, GetModuleHandleA(NULL), NULL);
251     ok(hwnd != NULL, "gle=%d\n", GetLastError());
252
253     if (!hwnd)
254     {
255         HeapFree(GetProcessHeap(), 0, info);
256         return NULL;
257     }
258
259     info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
260                                             (LONG_PTR)listview_subclass_proc);
261     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
262
263     return hwnd;
264 }
265
266 static HWND create_custom_listview_control(DWORD style)
267 {
268     struct subclass_info *info;
269     HWND hwnd;
270     RECT rect;
271
272     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
273     if (!info)
274         return NULL;
275
276     GetClientRect(hwndparent, &rect);
277     hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
278                            WS_CHILD | WS_BORDER | WS_VISIBLE | style,
279                            0, 0, rect.right, rect.bottom,
280                            hwndparent, NULL, GetModuleHandleA(NULL), NULL);
281     ok(hwnd != NULL, "gle=%d\n", GetLastError());
282
283     if (!hwnd)
284     {
285         HeapFree(GetProcessHeap(), 0, info);
286         return NULL;
287     }
288
289     info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
290                                             (LONG_PTR)listview_subclass_proc);
291     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
292
293     return hwnd;
294 }
295
296 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
297 {
298     struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
299     static long defwndproc_counter = 0;
300     LRESULT ret;
301     struct message msg;
302
303     trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
304
305     msg.message = message;
306     msg.flags = sent|wparam|lparam;
307     if (defwndproc_counter) msg.flags |= defwinproc;
308     msg.wParam = wParam;
309     msg.lParam = lParam;
310     msg.id = HEADER_ID;
311     add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
312
313     defwndproc_counter++;
314     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
315     defwndproc_counter--;
316     return ret;
317 }
318
319 static HWND subclass_header(HWND hwndListview)
320 {
321     struct subclass_info *info;
322     HWND hwnd;
323
324     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
325     if (!info)
326         return NULL;
327
328     hwnd = ListView_GetHeader(hwndListview);
329     info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
330                                             (LONG_PTR)header_subclass_proc);
331     SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
332
333     return hwnd;
334 }
335
336 static void test_images(void)
337 {
338     HWND hwnd;
339     DWORD r;
340     LVITEM item;
341     HIMAGELIST himl;
342     HBITMAP hbmp;
343     RECT r1, r2;
344     static CHAR hello[] = "hello";
345
346     himl = ImageList_Create(40, 40, 0, 4, 4);
347     ok(himl != NULL, "failed to create imagelist\n");
348
349     hbmp = CreateBitmap(40, 40, 1, 1, NULL);
350     ok(hbmp != NULL, "failed to create bitmap\n");
351
352     r = ImageList_Add(himl, hbmp, 0);
353     ok(r == 0, "should be zero\n");
354
355     hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED, 
356                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
357     ok(hwnd != NULL, "failed to create listview window\n");
358
359     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, 0x940);
360     ok(r == 0, "should return zero\n");
361
362     r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
363     ok(r == 0, "should return zero\n");
364
365     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
366     /* returns dimensions */
367
368     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
369     ok(r == 0, "should be zero items\n");
370
371     item.mask = LVIF_IMAGE | LVIF_TEXT;
372     item.iItem = 0;
373     item.iSubItem = 1;
374     item.iImage = 0;
375     item.pszText = 0;
376     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
377     ok(r == -1, "should fail\n");
378
379     item.iSubItem = 0;
380     item.pszText = hello;
381     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
382     ok(r == 0, "should not fail\n");
383
384     memset(&r1, 0, sizeof r1);
385     r1.left = LVIR_ICON;
386     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
387
388     r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
389     ok(r == TRUE, "should not fail\n");
390
391     item.iSubItem = 0;
392     item.pszText = hello;
393     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
394     ok(r == 0, "should not fail\n");
395
396     memset(&r2, 0, sizeof r2);
397     r2.left = LVIR_ICON;
398     r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
399
400     ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
401
402     DestroyWindow(hwnd);
403 }
404
405 static void test_checkboxes(void)
406 {
407     HWND hwnd;
408     LVITEMA item;
409     DWORD r;
410     static CHAR text[]  = "Text",
411                 text2[] = "Text2",
412                 text3[] = "Text3";
413
414     hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT, 
415                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
416     ok(hwnd != NULL, "failed to create listview window\n");
417
418     /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
419     item.mask = LVIF_TEXT | LVIF_STATE;
420     item.stateMask = 0xffff;
421     item.state = 0xfccc;
422     item.iItem = 0;
423     item.iSubItem = 0;
424     item.pszText = text;
425     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
426     ok(r == 0, "ret %d\n", r);
427
428     item.iItem = 0;
429     item.mask = LVIF_STATE;
430     item.stateMask = 0xffff;
431     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
432     ok(item.state == 0xfccc, "state %x\n", item.state);
433
434     /* Don't set LVIF_STATE */
435     item.mask = LVIF_TEXT;
436     item.stateMask = 0xffff;
437     item.state = 0xfccc;
438     item.iItem = 1;
439     item.iSubItem = 0;
440     item.pszText = text;
441     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
442     ok(r == 1, "ret %d\n", r);
443
444     item.iItem = 1;
445     item.mask = LVIF_STATE;
446     item.stateMask = 0xffff;
447     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
448     ok(item.state == 0, "state %x\n", item.state);
449
450     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
451     ok(r == 0, "should return zero\n");
452
453     /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
454     item.iItem = 0;
455     item.mask = LVIF_STATE;
456     item.stateMask = 0xffff;
457     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
458     ok(item.state == 0x1ccc, "state %x\n", item.state);
459
460     /* Now add an item without specifying a state and check that its state goes to 0x1000 */
461     item.iItem = 2;
462     item.mask = LVIF_TEXT;
463     item.state = 0;
464     item.pszText = text2;
465     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
466     ok(r == 2, "ret %d\n", r);
467
468     item.iItem = 2;
469     item.mask = LVIF_STATE;
470     item.stateMask = 0xffff;
471     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
472     ok(item.state == 0x1000, "state %x\n", item.state);
473
474     /* Add a further item this time specifying a state and still its state goes to 0x1000 */
475     item.iItem = 3;
476     item.mask = LVIF_TEXT | LVIF_STATE;
477     item.stateMask = 0xffff;
478     item.state = 0x2aaa;
479     item.pszText = text3;
480     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
481     ok(r == 3, "ret %d\n", r);
482
483     item.iItem = 3;
484     item.mask = LVIF_STATE;
485     item.stateMask = 0xffff;
486     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
487     ok(item.state == 0x1aaa, "state %x\n", item.state);
488
489     /* Set an item's state to checked */
490     item.iItem = 3;
491     item.mask = LVIF_STATE;
492     item.stateMask = 0xf000;
493     item.state = 0x2000;
494     r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
495
496     item.iItem = 3;
497     item.mask = LVIF_STATE;
498     item.stateMask = 0xffff;
499     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
500     ok(item.state == 0x2aaa, "state %x\n", item.state);
501
502     /* Check that only the bits we asked for are returned,
503      * and that all the others are set to zero
504      */
505     item.iItem = 3;
506     item.mask = LVIF_STATE;
507     item.stateMask = 0xf000;
508     item.state = 0xffff;
509     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
510     ok(item.state == 0x2000, "state %x\n", item.state);
511
512     /* Set the style again and check that doesn't change an item's state */
513     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
514     ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
515
516     item.iItem = 3;
517     item.mask = LVIF_STATE;
518     item.stateMask = 0xffff;
519     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
520     ok(item.state == 0x2aaa, "state %x\n", item.state);
521
522     /* Unsetting the checkbox extended style doesn't change an item's state */
523     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
524     ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
525
526     item.iItem = 3;
527     item.mask = LVIF_STATE;
528     item.stateMask = 0xffff;
529     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
530     ok(item.state == 0x2aaa, "state %x\n", item.state);
531
532     /* Now setting the style again will change an item's state */
533     r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
534     ok(r == 0, "ret %x\n", r);
535
536     item.iItem = 3;
537     item.mask = LVIF_STATE;
538     item.stateMask = 0xffff;
539     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
540     ok(item.state == 0x1aaa, "state %x\n", item.state);
541
542     /* Toggle checkbox tests (bug 9934) */
543     memset (&item, 0xcc, sizeof(item));
544     item.mask = LVIF_STATE;
545     item.iItem = 3;
546     item.iSubItem = 0;
547     item.state = LVIS_FOCUSED;
548     item.stateMask = LVIS_FOCUSED;
549     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
550     expect(1, r);
551
552     item.iItem = 3;
553     item.mask = LVIF_STATE;
554     item.stateMask = 0xffff;
555     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
556     ok(item.state == 0x1aab, "state %x\n", item.state);
557
558     r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
559     expect(0, r);
560     r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
561     expect(0, r);
562
563     item.iItem = 3;
564     item.mask = LVIF_STATE;
565     item.stateMask = 0xffff;
566     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
567     ok(item.state == 0x2aab, "state %x\n", item.state);
568
569     r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
570     expect(0, r);
571     r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
572     expect(0, r);
573
574     item.iItem = 3;
575     item.mask = LVIF_STATE;
576     item.stateMask = 0xffff;
577     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
578     ok(item.state == 0x1aab, "state %x\n", item.state);
579
580     DestroyWindow(hwnd);
581 }
582
583 static void insert_column(HWND hwnd, int idx)
584 {
585     LVCOLUMN column;
586     DWORD rc;
587
588     memset(&column, 0xcc, sizeof(column));
589     column.mask = LVCF_SUBITEM;
590     column.iSubItem = idx;
591
592     rc = ListView_InsertColumn(hwnd, idx, &column);
593     expect(idx, rc);
594 }
595
596 static void insert_item(HWND hwnd, int idx)
597 {
598     static CHAR text[] = "foo";
599
600     LVITEMA item;
601     DWORD rc;
602
603     memset(&item, 0xcc, sizeof (item));
604     item.mask = LVIF_TEXT;
605     item.iItem = idx;
606     item.iSubItem = 0;
607     item.pszText = text;
608
609     rc = ListView_InsertItem(hwnd, &item);
610     expect(idx, rc);
611 }
612
613 static void test_items(void)
614 {
615     const LPARAM lparamTest = 0x42;
616     HWND hwnd;
617     LVITEMA item;
618     DWORD r;
619     static CHAR text[] = "Text";
620
621     hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
622                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
623     ok(hwnd != NULL, "failed to create listview window\n");
624
625     /*
626      * Test setting/getting item params
627      */
628
629     /* Set up two columns */
630     insert_column(hwnd, 0);
631     insert_column(hwnd, 1);
632
633     /* Insert an item with just a param */
634     memset (&item, 0xcc, sizeof (item));
635     item.mask = LVIF_PARAM;
636     item.iItem = 0;
637     item.iSubItem = 0;
638     item.lParam = lparamTest;
639     r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
640     ok(r == 0, "ret %d\n", r);
641
642     /* Test getting of the param */
643     memset (&item, 0xcc, sizeof (item));
644     item.mask = LVIF_PARAM;
645     item.iItem = 0;
646     item.iSubItem = 0;
647     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
648     ok(r != 0, "ret %d\n", r);
649     ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
650
651     /* Set up a subitem */
652     memset (&item, 0xcc, sizeof (item));
653     item.mask = LVIF_TEXT;
654     item.iItem = 0;
655     item.iSubItem = 1;
656     item.pszText = text;
657     r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
658     ok(r != 0, "ret %d\n", r);
659
660     /* Query param from subitem: returns main item param */
661     memset (&item, 0xcc, sizeof (item));
662     item.mask = LVIF_PARAM;
663     item.iItem = 0;
664     item.iSubItem = 1;
665     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
666     ok(r != 0, "ret %d\n", r);
667     ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
668
669     /* Set up param on first subitem: no effect */
670     memset (&item, 0xcc, sizeof (item));
671     item.mask = LVIF_PARAM;
672     item.iItem = 0;
673     item.iSubItem = 1;
674     item.lParam = lparamTest+1;
675     r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
676     ok(r == 0, "ret %d\n", r);
677
678     /* Query param from subitem again: should still return main item param */
679     memset (&item, 0xcc, sizeof (item));
680     item.mask = LVIF_PARAM;
681     item.iItem = 0;
682     item.iSubItem = 1;
683     r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
684     ok(r != 0, "ret %d\n", r);
685     ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
686
687     /**** Some tests of state highlighting ****/
688     memset (&item, 0xcc, sizeof (item));
689     item.mask = LVIF_STATE;
690     item.iItem = 0;
691     item.iSubItem = 0;
692     item.state = LVIS_SELECTED;
693     item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
694     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
695     ok(r != 0, "ret %d\n", r);
696     item.iSubItem = 1;
697     item.state = LVIS_DROPHILITED;
698     r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
699     ok(r != 0, "ret %d\n", r);
700
701     memset (&item, 0xcc, sizeof (item));
702     item.mask = LVIF_STATE;
703     item.iItem = 0;
704     item.iSubItem = 0;
705     item.stateMask = -1;
706     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
707     ok(r != 0, "ret %d\n", r);
708     ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
709     item.iSubItem = 1;
710     r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
711     ok(r != 0, "ret %d\n", r);
712     todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
713
714     DestroyWindow(hwnd);
715 }
716
717 static void test_columns(void)
718 {
719     HWND hwnd;
720     LVCOLUMN column;
721     DWORD rc;
722
723     hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
724                 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
725     ok(hwnd != NULL, "failed to create listview window\n");
726
727     /* Add a column with no mask */
728     memset(&column, 0xcc, sizeof(column));
729     column.mask = 0;
730     rc = ListView_InsertColumn(hwnd, 0, &column);
731     ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
732
733     /* Check its width */
734     rc = ListView_GetColumnWidth(hwnd, 0);
735     ok(rc==10, "Inserting column with no mask failed to set width to 10 with %d\n", rc);
736
737     DestroyWindow(hwnd);
738 }
739 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
740 static WNDPROC listviewWndProc;
741 static HIMAGELIST test_create_imagelist;
742
743 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
744 {
745     if (uMsg == WM_CREATE)
746     {
747         LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
748         lpcs->style |= LVS_REPORT;
749         SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
750     }
751     return CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
752 }
753
754 static void test_create(void)
755 {
756     HWND hList;
757     HWND hHeader;
758     WNDCLASSEX cls;
759     cls.cbSize = sizeof(WNDCLASSEX);
760     ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
761     listviewWndProc = cls.lpfnWndProc;
762     cls.lpfnWndProc = create_test_wndproc;
763     cls.lpszClassName = "MyListView32";
764     ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
765
766     test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
767     hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
768     ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
769     hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
770     ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
771     DestroyWindow(hList);
772 }
773
774 static void test_redraw(void)
775 {
776     HWND hwnd, hwndheader;
777
778     hwnd = create_listview_control();
779     hwndheader = subclass_header(hwnd);
780
781     flush_sequences(sequences, NUM_MSG_SEQUENCES);
782
783     trace("invalidate & update\n");
784     InvalidateRect(hwnd, NULL, TRUE);
785     UpdateWindow(hwnd);
786     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
787
788     flush_sequences(sequences, NUM_MSG_SEQUENCES);
789
790     DestroyWindow(hwnd);
791 }
792
793 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
794 {
795     COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
796
797     if(msg == WM_NOTIFY) {
798         NMHDR *nmhdr = (PVOID)lp;
799         if(nmhdr->code == NM_CUSTOMDRAW) {
800             NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
801             trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
802             switch(nmlvcd->nmcd.dwDrawStage) {
803             case CDDS_PREPAINT:
804                 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
805                 return CDRF_NOTIFYITEMDRAW;
806             case CDDS_ITEMPREPAINT:
807                 nmlvcd->clrTextBk = CLR_DEFAULT;
808                 return CDRF_NOTIFYSUBITEMDRAW;
809             case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
810                 clr = GetBkColor(nmlvcd->nmcd.hdc);
811                 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
812                 return CDRF_NOTIFYPOSTPAINT;
813             case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
814                 clr = GetBkColor(nmlvcd->nmcd.hdc);
815                 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
816                 return CDRF_DODEFAULT;
817             }
818             return CDRF_DODEFAULT;
819         }
820     }
821
822     return DefWindowProcA(hwnd, msg, wp, lp);
823 }
824
825 static void test_customdraw(void)
826 {
827     HWND hwnd;
828     WNDPROC oldwndproc;
829
830     hwnd = create_listview_control();
831
832     insert_column(hwnd, 0);
833     insert_column(hwnd, 1);
834     insert_item(hwnd, 0);
835
836     oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
837                                            (LONG_PTR)cd_wndproc);
838
839     InvalidateRect(hwnd, NULL, TRUE);
840     UpdateWindow(hwnd);
841
842     SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
843
844     DestroyWindow(hwnd);
845 }
846
847 static void test_icon_spacing(void)
848 {
849     /* LVM_SETICONSPACING */
850     /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
851
852     HWND hwnd;
853     WORD w, h;
854     DWORD r;
855
856     hwnd = create_custom_listview_control(LVS_ICON);
857     ok(hwnd != NULL, "failed to create a listview window\n");
858
859     r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
860     expect(NFR_ANSI, r);
861
862     /* reset the icon spacing to defaults */
863     SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(-1, -1));
864
865     /* now we can request what the defaults are */
866     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(-1, -1));
867     w = LOWORD(r);
868     h = LOWORD(r);
869
870     flush_sequences(sequences, NUM_MSG_SEQUENCES);
871
872     trace("test icon spacing\n");
873
874     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(20, 30));
875     expect(MAKELONG(w,h), r);
876
877     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(25, 35));
878     expect(MAKELONG(20,30), r);
879
880     r = SendMessage(hwnd, LVM_SETICONSPACING, 0, (LPARAM) MAKELONG(-1,-1));
881     expect(MAKELONG(25,35), r);
882
883     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
884
885     flush_sequences(sequences, NUM_MSG_SEQUENCES);
886     DestroyWindow(hwnd);
887 }
888
889 static void test_color(void)
890 {
891     /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
892
893     HWND hwnd;
894     DWORD r;
895     int i;
896
897     COLORREF color;
898     COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
899
900     hwnd = create_listview_control();
901     ok(hwnd != NULL, "failed to create a listview window\n");
902
903     flush_sequences(sequences, NUM_MSG_SEQUENCES);
904
905     trace("test color seq\n");
906     for (i = 0; i < 4; i++)
907     {
908         color = colors[i];
909
910         r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
911         expect(TRUE, r);
912         r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
913         expect(color, r);
914
915         r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
916         expect (TRUE, r);
917         r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
918         expect(color, r);
919
920         r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
921         expect(TRUE, r);
922         r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
923         expect(color, r);
924     }
925
926     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
927
928     flush_sequences(sequences, NUM_MSG_SEQUENCES);
929     DestroyWindow(hwnd);
930 }
931
932 static void test_item_count(void)
933 {
934     /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
935
936     HWND hwnd;
937     DWORD r;
938
939     LVITEM item0;
940     LVITEM item1;
941     LVITEM item2;
942     static CHAR item0text[] = "item0";
943     static CHAR item1text[] = "item1";
944     static CHAR item2text[] = "item2";
945
946     hwnd = create_listview_control();
947     ok(hwnd != NULL, "failed to create a listview window\n");
948
949     flush_sequences(sequences, NUM_MSG_SEQUENCES);
950
951     trace("test item count\n");
952
953     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
954     expect(0, r);
955
956     /* [item0] */
957     item0.mask = LVIF_TEXT;
958     item0.iItem = 0;
959     item0.iSubItem = 0;
960     item0.pszText = item0text;
961     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
962     expect(0, r);
963
964     /* [item0, item1] */
965     item1.mask = LVIF_TEXT;
966     item1.iItem = 1;
967     item1.iSubItem = 0;
968     item1.pszText = item1text;
969     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
970     expect(1, r);
971
972     /* [item0, item1, item2] */
973     item2.mask = LVIF_TEXT;
974     item2.iItem = 2;
975     item2.iSubItem = 0;
976     item2.pszText = item2text;
977     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
978     expect(2, r);
979
980     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
981     expect(3, r);
982
983     /* [item0, item1] */
984     r = SendMessage(hwnd, LVM_DELETEITEM, (WPARAM) 2, 0);
985     expect(TRUE, r);
986
987     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
988     expect(2, r);
989
990     /* [] */
991     r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
992     expect(TRUE, r);
993
994     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
995     expect(0, r);
996
997     /* [item0] */
998     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
999     expect(0, r);
1000
1001     /* [item0, item1] */
1002     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1003     expect(1, r);
1004
1005     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1006     expect(2, r);
1007
1008     /* [item0, item1, item2] */
1009     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1010     expect(2, r);
1011
1012     r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1013     expect(3, r);
1014
1015     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1016
1017     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1018     DestroyWindow(hwnd);
1019 }
1020
1021 static void test_item_position(void)
1022 {
1023     /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1024
1025     HWND hwnd;
1026     DWORD r;
1027     POINT position;
1028
1029     LVITEM item0;
1030     LVITEM item1;
1031     LVITEM item2;
1032     static CHAR item0text[] = "item0";
1033     static CHAR item1text[] = "item1";
1034     static CHAR item2text[] = "item2";
1035
1036     hwnd = create_custom_listview_control(LVS_ICON);
1037     ok(hwnd != NULL, "failed to create a listview window\n");
1038
1039     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1040
1041     trace("test item position\n");
1042
1043     /* [item0] */
1044     item0.mask = LVIF_TEXT;
1045     item0.iItem = 0;
1046     item0.iSubItem = 0;
1047     item0.pszText = item0text;
1048     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1049     expect(0, r);
1050
1051     /* [item0, item1] */
1052     item1.mask = LVIF_TEXT;
1053     item1.iItem = 1;
1054     item1.iSubItem = 0;
1055     item1.pszText = item1text;
1056     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1057     expect(1, r);
1058
1059     /* [item0, item1, item2] */
1060     item2.mask = LVIF_TEXT;
1061     item2.iItem = 2;
1062     item2.iSubItem = 0;
1063     item2.pszText = item2text;
1064     r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1065     expect(2, r);
1066
1067     r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1068     expect(TRUE, r);
1069     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1070     expect(TRUE, r);
1071     expect2(10, 5, position.x, position.y);
1072
1073     r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1074     expect(TRUE, r);
1075     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1076     expect(TRUE, r);
1077     expect2(0, 0, position.x, position.y);
1078
1079     r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1080     expect(TRUE, r);
1081     r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1082     expect(TRUE, r);
1083     expect2(20, 20, position.x, position.y);
1084
1085     ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1086
1087     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1088     DestroyWindow(hwnd);
1089 }
1090
1091 static void test_getorigin(void)
1092 {
1093     /* LVM_GETORIGIN */
1094
1095     HWND hwnd;
1096     DWORD r;
1097     POINT position;
1098
1099     position.x = position.y = 0;
1100
1101     hwnd = create_custom_listview_control(LVS_ICON);
1102     ok(hwnd != NULL, "failed to create a listview window\n");
1103     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1104     trace("test get origin results\n");
1105     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1106     expect(TRUE, r);
1107     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1108     DestroyWindow(hwnd);
1109
1110     hwnd = create_custom_listview_control(LVS_SMALLICON);
1111     ok(hwnd != NULL, "failed to create a listview window\n");
1112     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1113     trace("test get origin results\n");
1114     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1115     expect(TRUE, r);
1116     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1117     DestroyWindow(hwnd);
1118
1119     hwnd = create_custom_listview_control(LVS_LIST);
1120     ok(hwnd != NULL, "failed to create a listview window\n");
1121     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1122     trace("test get origin results\n");
1123     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1124     expect(FALSE, r);
1125     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1126     DestroyWindow(hwnd);
1127
1128     hwnd = create_custom_listview_control(LVS_REPORT);
1129     ok(hwnd != NULL, "failed to create a listview window\n");
1130     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1131     trace("test get origin results\n");
1132     r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1133     expect(FALSE, r);
1134     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1135     DestroyWindow(hwnd);
1136
1137 }
1138
1139 static void test_multiselect(void)
1140 {
1141     typedef struct t_select_task
1142     {
1143         const char *descr;
1144         int initPos;
1145         int loopVK;
1146         int count;
1147         int result;
1148     } select_task;
1149
1150     HWND hwnd;
1151     DWORD r;
1152     int i,j,item_count,selected_count;
1153     static const int items=5;
1154     BYTE kstate[256];
1155     select_task task;
1156
1157     static struct t_select_task task_list[] = {
1158         { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1159         { "using VK_UP", -1, VK_UP, -1, -1 },
1160         { "using VK_END", 0, VK_END, 1, -1 },
1161         { "using VK_HOME", -1, VK_HOME, 1, -1 }
1162     };
1163
1164
1165     hwnd = create_listview_control();
1166
1167     for (i=0;i<items;i++) {
1168             insert_item(hwnd, 0);
1169     }
1170
1171     item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1172
1173     expect(items,item_count);
1174
1175     for (i=0;i<4;i++) {
1176         task = task_list[i];
1177
1178         /* deselect all items */
1179         ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1180         SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1181
1182         /* set initial position */
1183         SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1184         ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1185
1186         selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1187
1188         ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1189
1190         /* Set SHIFT key pressed */
1191         GetKeyboardState(kstate);
1192         kstate[VK_SHIFT]=0x80;
1193         SetKeyboardState(kstate);
1194
1195         for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1196             r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1197             expect(0,r);
1198             r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1199             expect(0,r);
1200         }
1201
1202         selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1203
1204         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);
1205
1206         /* Set SHIFT key released */
1207         GetKeyboardState(kstate);
1208         kstate[VK_SHIFT]=0x00;
1209         SetKeyboardState(kstate);
1210     }
1211     DestroyWindow(hwnd);
1212 }
1213
1214 START_TEST(listview)
1215 {
1216     HMODULE hComctl32;
1217     BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1218
1219     hComctl32 = GetModuleHandleA("comctl32.dll");
1220     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1221     if (pInitCommonControlsEx)
1222     {
1223         INITCOMMONCONTROLSEX iccex;
1224         iccex.dwSize = sizeof(iccex);
1225         iccex.dwICC  = ICC_LISTVIEW_CLASSES;
1226         pInitCommonControlsEx(&iccex);
1227     }
1228     else
1229         InitCommonControls();
1230
1231     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1232
1233     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1234     hwndparent = create_parent_window();
1235     ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent window", TRUE);
1236     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1237
1238     test_images();
1239     test_checkboxes();
1240     test_items();
1241     test_create();
1242     test_redraw();
1243     test_customdraw();
1244     test_icon_spacing();
1245     test_color();
1246     test_item_count();
1247     test_item_position();
1248     test_columns();
1249     test_getorigin();
1250     test_multiselect();
1251 }