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