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