[COMCTL32_WINETEST]
[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 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3140 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3141 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3142 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3143 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3144 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3145 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3146
3147 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3148 "ownerdata select all notification", FALSE);
3149
3150 /* select all again, note that all items are selected already */
3151 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3152 item.stateMask = LVIS_SELECTED;
3153 item.state = LVIS_SELECTED;
3154
3155 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3156 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3157 expect(TRUE, res);
3158 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3159 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3160 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3161 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3162 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3163 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3164 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3165
3166 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3167 "ownerdata select all notification", FALSE);
3168
3169 /* deselect all */
3170 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3171 item.stateMask = LVIS_SELECTED;
3172 item.state = 0;
3173
3174 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3175 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3176 expect(TRUE, res);
3177 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3178 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3179 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3180 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3181 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3182 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3183 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3184
3185 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3186 "ownerdata deselect all notification", TRUE);
3187
3188 /* nothing selected, deselect all again */
3189 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3190 item.stateMask = LVIS_SELECTED;
3191 item.state = 0;
3192
3193 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3194 expect(TRUE, res);
3195
3196 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "ownerdata deselect all notification", FALSE);
3197
3198 /* select one, then deselect all */
3199 item.stateMask = LVIS_SELECTED;
3200 item.state = LVIS_SELECTED;
3201 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3202 expect(TRUE, res);
3203 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3204 item.stateMask = LVIS_SELECTED;
3205 item.state = 0;
3206
3207 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3208 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3209 expect(TRUE, res);
3210 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3211 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3212 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3213 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3214 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3215 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3216 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3217
3218 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3219 "ownerdata select all notification", TRUE);
3220
3221 /* remove focused, try to focus all */
3222 item.stateMask = LVIS_FOCUSED;
3223 item.state = LVIS_FOCUSED;
3224 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3225 expect(TRUE, res);
3226 item.stateMask = LVIS_FOCUSED;
3227 item.state = 0;
3228 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3229 expect(TRUE, res);
3230 item.stateMask = LVIS_FOCUSED;
3231 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
3232 expect(0, res);
3233
3234 /* setting all to focused returns failure value */
3235 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3236 item.stateMask = LVIS_FOCUSED;
3237 item.state = LVIS_FOCUSED;
3238
3239 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3240 expect(FALSE, res);
3241
3242 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3243 "ownerdata focus all notification", FALSE);
3244
3245 /* focus single item, remove all */
3246 item.stateMask = LVIS_FOCUSED;
3247 item.state = LVIS_FOCUSED;
3248 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3249 expect(TRUE, res);
3250 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3251 item.stateMask = LVIS_FOCUSED;
3252 item.state = 0;
3253
3254 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3255 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3256 expect(TRUE, res);
3257 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3258 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3259 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3260 ok(g_nmlistview.uOldState == LVIS_FOCUSED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3261 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3262 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3263 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3264
3265 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
3266 "ownerdata remove focus all notification", TRUE);
3267
3268 /* set all cut */
3269 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3270 item.stateMask = LVIS_CUT;
3271 item.state = LVIS_CUT;
3272
3273 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3274 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3275 expect(TRUE, res);
3276 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3277 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3278 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3279 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3280 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3281 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3282 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3283
3284 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3285 "ownerdata cut all notification", FALSE);
3286
3287 /* all marked cut, try again */
3288 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3289 item.stateMask = LVIS_CUT;
3290 item.state = LVIS_CUT;
3291
3292 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3293 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3294 expect(TRUE, res);
3295 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3296 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3297 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3298 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3299 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3300 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3301 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3302
3303 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3304 "ownerdata cut all notification #2", FALSE);
3305
3306 DestroyWindow(hwnd);
3307
3308 /* check notifications on LVM_GETITEM */
3309 /* zero callback mask */
3310 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3311 ok(hwnd != NULL, "failed to create a listview window\n");
3312 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3313 expect(1, res);
3314
3315 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3316
3317 memset(&item, 0, sizeof(item));
3318 item.stateMask = LVIS_SELECTED;
3319 item.mask = LVIF_STATE;
3320 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3321 expect(TRUE, res);
3322
3323 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3324 "ownerdata getitem selected state 1", FALSE);
3325
3326 /* non zero callback mask but not we asking for */
3327 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
3328 expect(TRUE, res);
3329
3330 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3331
3332 memset(&item, 0, sizeof(item));
3333 item.stateMask = LVIS_SELECTED;
3334 item.mask = LVIF_STATE;
3335 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3336 expect(TRUE, res);
3337
3338 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3339 "ownerdata getitem selected state 2", FALSE);
3340
3341 /* LVIS_OVERLAYMASK callback mask, asking for index */
3342 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3343
3344 memset(&item, 0, sizeof(item));
3345 item.stateMask = LVIS_OVERLAYMASK;
3346 item.mask = LVIF_STATE;
3347 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3348 expect(TRUE, res);
3349
3350 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3351 "ownerdata getitem selected state 2", FALSE);
3352
3353 DestroyWindow(hwnd);
3354
3355 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3356 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
3357 ok(hwnd != NULL, "failed to create a listview window\n");
3358 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3359 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3360 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3361 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
3362 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3363 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
3364 DestroyWindow(hwnd);
3365 /* apparently it's allowed to switch these style on after creation */
3366 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3367 ok(hwnd != NULL, "failed to create a listview window\n");
3368 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3369 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3370 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
3371 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3372 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3373 DestroyWindow(hwnd);
3374
3375 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3376 ok(hwnd != NULL, "failed to create a listview window\n");
3377 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3378 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3379 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
3380 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3381 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
3382 DestroyWindow(hwnd);
3383 }
3384
3385 static void test_norecompute(void)
3386 {
3387 static CHAR testA[] = "test";
3388 CHAR buff[10];
3389 LVITEMA item;
3390 HWND hwnd;
3391 DWORD res;
3392
3393 /* self containing control */
3394 hwnd = create_listview_control(LVS_REPORT);
3395 ok(hwnd != NULL, "failed to create a listview window\n");
3396 memset(&item, 0, sizeof(item));
3397 item.mask = LVIF_TEXT | LVIF_STATE;
3398 item.iItem = 0;
3399 item.stateMask = LVIS_SELECTED;
3400 item.state = LVIS_SELECTED;
3401 item.pszText = testA;
3402 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3403 expect(0, res);
3404 /* retrieve with LVIF_NORECOMPUTE */
3405 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3406 item.iItem = 0;
3407 item.pszText = buff;
3408 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3409 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3410 expect(TRUE, res);
3411 ok(lstrcmpA(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
3412
3413 item.mask = LVIF_TEXT;
3414 item.iItem = 1;
3415 item.pszText = LPSTR_TEXTCALLBACKA;
3416 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3417 expect(1, res);
3418
3419 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3420 item.iItem = 1;
3421 item.pszText = buff;
3422 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3423
3424 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3425 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3426 expect(TRUE, res);
3427 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3428 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3429 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
3430
3431 DestroyWindow(hwnd);
3432
3433 /* LVS_OWNERDATA */
3434 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3435 ok(hwnd != NULL, "failed to create a listview window\n");
3436
3437 item.mask = LVIF_STATE;
3438 item.stateMask = LVIS_SELECTED;
3439 item.state = LVIS_SELECTED;
3440 item.iItem = 0;
3441 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3442 expect(0, res);
3443
3444 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3445 item.iItem = 0;
3446 item.pszText = buff;
3447 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3448 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3449 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3450 expect(TRUE, res);
3451 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3452 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3453 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
3454
3455 DestroyWindow(hwnd);
3456 }
3457
3458 static void test_nosortheader(void)
3459 {
3460 HWND hwnd, header;
3461 LONG_PTR style;
3462
3463 hwnd = create_listview_control(LVS_REPORT);
3464 ok(hwnd != NULL, "failed to create a listview window\n");
3465
3466 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3467 ok(IsWindow(header), "header expected\n");
3468
3469 style = GetWindowLongPtrA(header, GWL_STYLE);
3470 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
3471
3472 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3473 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
3474 /* HDS_BUTTONS retained */
3475 style = GetWindowLongPtrA(header, GWL_STYLE);
3476 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
3477
3478 DestroyWindow(hwnd);
3479
3480 /* create with LVS_NOSORTHEADER */
3481 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
3482 ok(hwnd != NULL, "failed to create a listview window\n");
3483
3484 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3485 ok(IsWindow(header), "header expected\n");
3486
3487 style = GetWindowLongPtrA(header, GWL_STYLE);
3488 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3489
3490 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3491 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
3492 /* not changed here */
3493 style = GetWindowLongPtrA(header, GWL_STYLE);
3494 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3495
3496 DestroyWindow(hwnd);
3497 }
3498
3499 static void test_setredraw(void)
3500 {
3501 HWND hwnd;
3502 DWORD_PTR style;
3503 DWORD ret;
3504 HDC hdc;
3505 RECT rect;
3506
3507 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3508 ok(hwnd != NULL, "failed to create a listview window\n");
3509
3510 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3511 ListView seems to handle it internally without DefWinProc */
3512
3513 /* default value first */
3514 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3515 expect(0, ret);
3516 /* disable */
3517 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3518 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3519 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3520 expect(0, ret);
3521 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3522 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3523 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3524 expect(0, ret);
3525
3526 /* check update rect after redrawing */
3527 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3528 expect(0, ret);
3529 InvalidateRect(hwnd, NULL, FALSE);
3530 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
3531 rect.right = rect.bottom = 1;
3532 GetUpdateRect(hwnd, &rect, FALSE);
3533 expect(0, rect.right);
3534 expect(0, rect.bottom);
3535
3536 /* WM_ERASEBKGND */
3537 hdc = GetWindowDC(hwndparent);
3538 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3539 expect(TRUE, ret);
3540 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3541 expect(0, ret);
3542 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3543 expect(TRUE, ret);
3544 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3545 expect(0, ret);
3546 ReleaseDC(hwndparent, hdc);
3547
3548 /* check notification messages to show that repainting is disabled */
3549 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3550 expect(TRUE, ret);
3551 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3552 expect(0, ret);
3553 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3554
3555 InvalidateRect(hwnd, NULL, TRUE);
3556 UpdateWindow(hwnd);
3557 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3558 "redraw after WM_SETREDRAW (FALSE)", FALSE);
3559
3560 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3561 expect(TRUE, ret);
3562 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3563 InvalidateRect(hwnd, NULL, TRUE);
3564 UpdateWindow(hwnd);
3565 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3566 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3567
3568 /* message isn't forwarded to header */
3569 subclass_header(hwnd);
3570 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3571 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3572 expect(0, ret);
3573 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3574 "WM_SETREDRAW: not forwarded to header", FALSE);
3575
3576 DestroyWindow(hwnd);
3577 }
3578
3579 static void test_hittest(void)
3580 {
3581 HWND hwnd;
3582 DWORD r;
3583 RECT bounds;
3584 LVITEMA item;
3585 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3586 POINT pos;
3587 INT x, y, i;
3588 WORD vert;
3589 HIMAGELIST himl, himl2;
3590 HBITMAP hbmp;
3591
3592 hwnd = create_listview_control(LVS_REPORT);
3593 ok(hwnd != NULL, "failed to create a listview window\n");
3594
3595 /* LVS_REPORT with a single subitem (2 columns) */
3596 insert_column(hwnd, 0);
3597 insert_column(hwnd, 1);
3598 insert_item(hwnd, 0);
3599
3600 item.iSubItem = 0;
3601 /* the only purpose of that line is to be as long as a half item rect */
3602 item.pszText = text;
3603 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3604 expect(TRUE, r);
3605
3606 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3607 expect(TRUE, r);
3608 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3609 expect(TRUE, r);
3610
3611 memset(&bounds, 0, sizeof(bounds));
3612 bounds.left = LVIR_BOUNDS;
3613 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3614 expect(1, r);
3615 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3616 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3617 r = SendMessageA(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3618 vert = HIWORD(r);
3619 ok(bounds.bottom - bounds.top == vert,
3620 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3621 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3622 expect(TRUE, r);
3623
3624 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3625
3626 /* outside columns by x position - valid is [0, 199] */
3627 x = -1;
3628 y = pos.y + (bounds.bottom - bounds.top) / 2;
3629 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3630 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3631
3632 x = pos.x + 50; /* column half width */
3633 y = pos.y + (bounds.bottom - bounds.top) / 2;
3634 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3635 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3636 x = pos.x + 150; /* outside column */
3637 y = pos.y + (bounds.bottom - bounds.top) / 2;
3638 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3639 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3640 y = (bounds.bottom - bounds.top) / 2;
3641 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3642 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3643 /* outside possible client rectangle (to right) */
3644 x = pos.x + 500;
3645 y = pos.y + (bounds.bottom - bounds.top) / 2;
3646 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3647 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3648 y = (bounds.bottom - bounds.top) / 2;
3649 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3650 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3651 /* subitem returned with -1 item too */
3652 x = pos.x + 150;
3653 y = bounds.top - vert;
3654 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3655 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3656 /* return values appear to underflow with negative indices */
3657 i = -2;
3658 y = y - vert;
3659 while (i > -10) {
3660 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3661 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3662 y = y - vert;
3663 i--;
3664 }
3665 /* parent client area is 100x100 by default */
3666 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3667 x = pos.x + 150; /* outside column */
3668 y = pos.y + (bounds.bottom - bounds.top) / 2;
3669 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3670 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3671 y = (bounds.bottom - bounds.top) / 2;
3672 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3673 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3674 /* the same with LVS_EX_FULLROWSELECT */
3675 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3676 x = pos.x + 150; /* outside column */
3677 y = pos.y + (bounds.bottom - bounds.top) / 2;
3678 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3679 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3680 y = (bounds.bottom - bounds.top) / 2;
3681 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3682 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3683 x = pos.x + 150; /* outside column */
3684 y = pos.y + (bounds.bottom - bounds.top) / 2;
3685 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3686 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3687 y = (bounds.bottom - bounds.top) / 2;
3688 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3689 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3690 /* outside possible client rectangle (to right) */
3691 x = pos.x + 500;
3692 y = pos.y + (bounds.bottom - bounds.top) / 2;
3693 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3694 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3695 y = (bounds.bottom - bounds.top) / 2;
3696 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3697 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3698 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3699 himl = ImageList_Create(16, 16, 0, 4, 4);
3700 ok(himl != NULL, "failed to create imagelist\n");
3701 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3702 ok(hbmp != NULL, "failed to create bitmap\n");
3703 r = ImageList_Add(himl, hbmp, 0);
3704 ok(r == 0, "should be zero\n");
3705 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3706 ok(hbmp != NULL, "failed to create bitmap\n");
3707 r = ImageList_Add(himl, hbmp, 0);
3708 ok(r == 1, "should be one\n");
3709
3710 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3711 expect(0, r);
3712
3713 item.mask = LVIF_IMAGE;
3714 item.iImage = 0;
3715 item.iItem = 0;
3716 item.iSubItem = 0;
3717 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3718 expect(TRUE, r);
3719 /* on state icon */
3720 x = pos.x + 8;
3721 y = pos.y + (bounds.bottom - bounds.top) / 2;
3722 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3723 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3724 y = (bounds.bottom - bounds.top) / 2;
3725 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3726
3727 /* state icons indices are 1 based, check with valid index */
3728 item.mask = LVIF_STATE;
3729 item.state = INDEXTOSTATEIMAGEMASK(1);
3730 item.stateMask = LVIS_STATEIMAGEMASK;
3731 item.iItem = 0;
3732 item.iSubItem = 0;
3733 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3734 expect(TRUE, r);
3735 /* on state icon */
3736 x = pos.x + 8;
3737 y = pos.y + (bounds.bottom - bounds.top) / 2;
3738 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3739 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3740 y = (bounds.bottom - bounds.top) / 2;
3741 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3742
3743 himl2 = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3744 ok(himl2 == himl, "should return handle\n");
3745
3746 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3747 expect(0, r);
3748 /* on item icon */
3749 x = pos.x + 8;
3750 y = pos.y + (bounds.bottom - bounds.top) / 2;
3751 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3752 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3753 y = (bounds.bottom - bounds.top) / 2;
3754 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3755
3756 DestroyWindow(hwnd);
3757 }
3758
3759 static void test_getviewrect(void)
3760 {
3761 HWND hwnd;
3762 DWORD r;
3763 RECT rect;
3764 LVITEMA item;
3765
3766 hwnd = create_listview_control(LVS_REPORT);
3767 ok(hwnd != NULL, "failed to create a listview window\n");
3768
3769 /* empty */
3770 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3771 expect(TRUE, r);
3772
3773 insert_column(hwnd, 0);
3774 insert_column(hwnd, 1);
3775
3776 memset(&item, 0, sizeof(item));
3777 item.iItem = 0;
3778 item.iSubItem = 0;
3779 SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3780
3781 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3782 expect(TRUE, r);
3783 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3784 expect(TRUE, r);
3785
3786 rect.left = rect.right = rect.top = rect.bottom = -1;
3787 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3788 expect(TRUE, r);
3789 /* left is set to (2e31-1) - XP SP2 */
3790 expect(0, rect.right);
3791 expect(0, rect.top);
3792 expect(0, rect.bottom);
3793
3794 /* switch to LVS_ICON */
3795 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_REPORT);
3796
3797 rect.left = rect.right = rect.top = rect.bottom = -1;
3798 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3799 expect(TRUE, r);
3800 expect(0, rect.left);
3801 expect(0, rect.top);
3802 /* precise value differs for 2k, XP and Vista */
3803 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3804 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3805
3806 DestroyWindow(hwnd);
3807 }
3808
3809 static void test_getitemposition(void)
3810 {
3811 HWND hwnd, header;
3812 DWORD r;
3813 POINT pt;
3814 RECT rect;
3815
3816 hwnd = create_listview_control(LVS_REPORT);
3817 ok(hwnd != NULL, "failed to create a listview window\n");
3818 header = subclass_header(hwnd);
3819
3820 /* LVS_REPORT, single item, no columns added */
3821 insert_item(hwnd, 0);
3822
3823 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3824
3825 pt.x = pt.y = -1;
3826 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3827 expect(TRUE, r);
3828 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3829
3830 /* LVS_REPORT, single item, single column */
3831 insert_column(hwnd, 0);
3832
3833 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3834
3835 pt.x = pt.y = -1;
3836 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3837 expect(TRUE, r);
3838 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3839
3840 memset(&rect, 0, sizeof(rect));
3841 SendMessageA(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3842 /* some padding? */
3843 expect(2, pt.x);
3844 /* offset by header height */
3845 expect(rect.bottom - rect.top, pt.y);
3846
3847 DestroyWindow(hwnd);
3848 }
3849
3850 static void test_columnscreation(void)
3851 {
3852 HWND hwnd, header;
3853 DWORD r;
3854
3855 hwnd = create_listview_control(LVS_REPORT);
3856 ok(hwnd != NULL, "failed to create a listview window\n");
3857
3858 insert_item(hwnd, 0);
3859
3860 /* headers columns aren't created automatically */
3861 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3862 ok(IsWindow(header), "Expected header handle\n");
3863 r = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
3864 expect(0, r);
3865
3866 DestroyWindow(hwnd);
3867 }
3868
3869 static void test_getitemrect(void)
3870 {
3871 HWND hwnd;
3872 HIMAGELIST himl, himl_ret;
3873 HBITMAP hbm;
3874 RECT rect;
3875 DWORD r;
3876 LVITEMA item;
3877 LVCOLUMNA col;
3878 INT order[2];
3879 POINT pt;
3880 HDC hdc;
3881
3882 /* rectangle isn't empty for empty text items */
3883 hwnd = create_listview_control(LVS_LIST);
3884 memset(&item, 0, sizeof(item));
3885 item.mask = 0;
3886 item.iItem = 0;
3887 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3888 expect(0, r);
3889 rect.left = LVIR_LABEL;
3890 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3891 expect(TRUE, r);
3892 expect(0, rect.left);
3893 expect(0, rect.top);
3894 hdc = GetDC(hwnd);
3895 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, rect.right);
3896 ReleaseDC(hwnd, hdc);
3897 DestroyWindow(hwnd);
3898
3899 hwnd = create_listview_control(LVS_REPORT);
3900 ok(hwnd != NULL, "failed to create a listview window\n");
3901
3902 /* empty item */
3903 memset(&item, 0, sizeof(item));
3904 item.iItem = 0;
3905 item.iSubItem = 0;
3906 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3907 expect(0, r);
3908
3909 rect.left = LVIR_BOUNDS;
3910 rect.right = rect.top = rect.bottom = -1;
3911 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3912 expect(TRUE, r);
3913
3914 /* zero width rectangle with no padding */
3915 expect(0, rect.left);
3916 expect(0, rect.right);
3917
3918 insert_column(hwnd, 0);
3919 insert_column(hwnd, 1);
3920
3921 col.mask = LVCF_WIDTH;
3922 col.cx = 50;
3923 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 0, (LPARAM)&col);
3924 expect(TRUE, r);
3925
3926 col.mask = LVCF_WIDTH;
3927 col.cx = 100;
3928 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 1, (LPARAM)&col);
3929 expect(TRUE, r);
3930
3931 rect.left = LVIR_BOUNDS;
3932 rect.right = rect.top = rect.bottom = -1;
3933 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3934 expect(TRUE, r);
3935
3936 /* still no left padding */
3937 expect(0, rect.left);
3938 expect(150, rect.right);
3939
3940 rect.left = LVIR_SELECTBOUNDS;
3941 rect.right = rect.top = rect.bottom = -1;
3942 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3943 expect(TRUE, r);
3944 /* padding */
3945 expect(2, rect.left);
3946
3947 rect.left = LVIR_LABEL;
3948 rect.right = rect.top = rect.bottom = -1;
3949 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3950 expect(TRUE, r);
3951 /* padding, column width */
3952 expect(2, rect.left);
3953 expect(50, rect.right);
3954
3955 /* no icons attached */
3956 rect.left = LVIR_ICON;
3957 rect.right = rect.top = rect.bottom = -1;
3958 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3959 expect(TRUE, r);
3960 /* padding */
3961 expect(2, rect.left);
3962 expect(2, rect.right);
3963
3964 /* change order */
3965 order[0] = 1; order[1] = 0;
3966 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3967 expect(TRUE, r);
3968 pt.x = -1;
3969 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3970 expect(TRUE, r);
3971 /* 1 indexed column width + padding */
3972 expect(102, pt.x);
3973 /* rect is at zero too */
3974 rect.left = LVIR_BOUNDS;
3975 rect.right = rect.top = rect.bottom = -1;
3976 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3977 expect(TRUE, r);
3978 expect(0, rect.left);
3979 /* just width sum */
3980 expect(150, rect.right);
3981
3982 rect.left = LVIR_SELECTBOUNDS;
3983 rect.right = rect.top = rect.bottom = -1;
3984 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3985 expect(TRUE, r);
3986 /* column width + padding */
3987 expect(102, rect.left);
3988
3989 /* back to initial order */
3990 order[0] = 0; order[1] = 1;
3991 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3992 expect(TRUE, r);
3993
3994 /* state icons */
3995 himl = ImageList_Create(16, 16, 0, 2, 2);
3996 ok(himl != NULL, "failed to create imagelist\n");
3997 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3998 ok(hbm != NULL, "failed to create bitmap\n");
3999 r = ImageList_Add(himl, hbm, 0);
4000 expect(0, r);
4001 hbm = CreateBitmap(16, 16, 1, 1, NULL);
4002 ok(hbm != NULL, "failed to create bitmap\n");
4003 r = ImageList_Add(himl, hbm, 0);
4004 expect(1, r);
4005
4006 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
4007 expect(0, r);
4008
4009 item.mask = LVIF_STATE;
4010 item.state = INDEXTOSTATEIMAGEMASK(1);
4011 item.stateMask = LVIS_STATEIMAGEMASK;
4012 item.iItem = 0;
4013 item.iSubItem = 0;
4014 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4015 expect(TRUE, r);
4016
4017 /* icon bounds */
4018 rect.left = LVIR_ICON;
4019 rect.right = rect.top = rect.bottom = -1;
4020 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4021 expect(TRUE, r);
4022 /* padding + stateicon width */
4023 expect(18, rect.left);
4024 expect(18, rect.right);
4025 /* label bounds */
4026 rect.left = LVIR_LABEL;
4027 rect.right = rect.top = rect.bottom = -1;
4028 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4029 expect(TRUE, r);
4030 /* padding + stateicon width -> column width */
4031 expect(18, rect.left);
4032 expect(50, rect.right);
4033
4034 himl_ret = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
4035 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
4036
4037 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
4038 expect(0, r);
4039
4040 item.mask = LVIF_STATE | LVIF_IMAGE;
4041 item.iImage = 1;
4042 item.state = 0;
4043 item.stateMask = ~0;
4044 item.iItem = 0;
4045 item.iSubItem = 0;
4046 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4047 expect(TRUE, r);
4048
4049 /* icon bounds */
4050 rect.left = LVIR_ICON;
4051 rect.right = rect.top = rect.bottom = -1;
4052 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4053 expect(TRUE, r);
4054 /* padding, icon width */
4055 expect(2, rect.left);
4056 expect(18, rect.right);
4057 /* label bounds */
4058 rect.left = LVIR_LABEL;
4059 rect.right = rect.top = rect.bottom = -1;
4060 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4061 expect(TRUE, r);
4062 /* padding + icon width -> column width */
4063 expect(18, rect.left);
4064 expect(50, rect.right);
4065
4066 /* select bounds */
4067 rect.left = LVIR_SELECTBOUNDS;
4068 rect.right = rect.top = rect.bottom = -1;
4069 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4070 expect(TRUE, r);
4071 /* padding, column width */
4072 expect(2, rect.left);
4073 expect(50, rect.right);
4074
4075 /* try with indentation */
4076 item.mask = LVIF_INDENT;
4077 item.iIndent = 1;
4078 item.iItem = 0;
4079 item.iSubItem = 0;
4080 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4081 expect(TRUE, r);
4082
4083 /* bounds */
4084 rect.left = LVIR_BOUNDS;
4085 rect.right = rect.top = rect.bottom = -1;
4086 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4087 expect(TRUE, r);
4088 /* padding + 1 icon width, column width */
4089 expect(0, rect.left);
4090 expect(150, rect.right);
4091
4092 /* select bounds */
4093 rect.left = LVIR_SELECTBOUNDS;
4094 rect.right = rect.top = rect.bottom = -1;
4095 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4096 expect(TRUE, r);
4097 /* padding + 1 icon width, column width */
4098 expect(2 + 16, rect.left);
4099 expect(50, rect.right);
4100
4101 /* label bounds */
4102 rect.left = LVIR_LABEL;
4103 rect.right = rect.top = rect.bottom = -1;
4104 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4105 expect(TRUE, r);
4106 /* padding + 2 icon widths, column width */
4107 expect(2 + 16*2, rect.left);
4108 expect(50, rect.right);
4109
4110 /* icon bounds */
4111 rect.left = LVIR_ICON;
4112 rect.right = rect.top = rect.bottom = -1;
4113 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4114 expect(TRUE, r);
4115 /* padding + 1 icon width indentation, icon width */
4116 expect(2 + 16, rect.left);
4117 expect(34, rect.right);
4118
4119 DestroyWindow(hwnd);
4120 }
4121
4122 static void test_editbox(void)
4123 {
4124 static CHAR testitemA[] = "testitem";
4125 static CHAR testitem1A[] = "testitem_quitelongname";
4126 static CHAR testitem2A[] = "testITEM_quitelongname";
4127 static CHAR buffer[25];
4128 HWND hwnd, hwndedit, hwndedit2, header;
4129 LVITEMA item;
4130 INT r;
4131
4132 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4133 ok(hwnd != NULL, "failed to create a listview window\n");
4134
4135 insert_column(hwnd, 0);
4136
4137 memset(&item, 0, sizeof(item));
4138 item.mask = LVIF_TEXT;
4139 item.pszText = testitemA;
4140 item.iItem = 0;
4141 item.iSubItem = 0;
4142 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4143 expect(0, r);
4144
4145 /* test notifications without edit created */
4146 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4147 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
4148 expect(0, r);
4149 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4150 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
4151 /* same thing but with valid window */
4152 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
4153 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
4154 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4155 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
4156 expect(0, r);
4157 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4158 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
4159 DestroyWindow(hwndedit);
4160
4161 /* setting focus is necessary */
4162 SetFocus(hwnd);
4163 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4164 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4165
4166 /* test children Z-order after Edit box created */
4167 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4168 ok(IsWindow(header), "Expected header to be created\n");
4169 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4170 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4171
4172 /* modify initial string */
4173 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4174 expect(TRUE, r);
4175
4176 /* edit window is resized and repositioned,
4177 check again for Z-order - it should be preserved */
4178 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4179 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4180
4181 /* return focus to listview */
4182 SetFocus(hwnd);
4183
4184 memset(&item, 0, sizeof(item));
4185 item.mask = LVIF_TEXT;
4186 item.pszText = buffer;
4187 item.cchTextMax = sizeof(buffer);
4188 item.iItem = 0;
4189 item.iSubItem = 0;
4190 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4191 expect(TRUE, r);
4192
4193 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4194
4195 /* send LVM_EDITLABEL on already created edit */
4196 SetFocus(hwnd);
4197 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4198 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4199 /* focus will be set to edit */
4200 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
4201 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4202 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
4203
4204 /* creating label disabled when control isn't focused */
4205 SetFocus(0);
4206 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4207 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4208
4209 /* check EN_KILLFOCUS handling */
4210 memset(&item, 0, sizeof(item));
4211 item.pszText = testitemA;
4212 item.iItem = 0;
4213 item.iSubItem = 0;
4214 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4215 expect(TRUE, r);
4216
4217 SetFocus(hwnd);
4218 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4219 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4220 /* modify edit and notify control that it lost focus */
4221 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4222 expect(TRUE, r);
4223 g_editbox_disp_info.item.pszText = NULL;
4224 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4225 expect(0, r);
4226 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
4227
4228 memset(&item, 0, sizeof(item));
4229 item.pszText = buffer;
4230 item.cchTextMax = sizeof(buffer);
4231 item.iItem = 0;
4232 item.iSubItem = 0;
4233 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4234 expect(lstrlenA(item.pszText), r);
4235 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4236 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4237
4238 /* change item name to differ in casing only */
4239 SetFocus(hwnd);
4240 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4241 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4242 /* modify edit and notify control that it lost focus */
4243 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
4244 expect(TRUE, r);
4245 g_editbox_disp_info.item.pszText = NULL;
4246 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4247 expect(0, r);
4248 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
4249
4250 memset(&item, 0, sizeof(item));
4251 item.pszText = buffer;
4252 item.cchTextMax = sizeof(buffer);
4253 item.iItem = 0;
4254 item.iSubItem = 0;
4255 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4256 expect(lstrlenA(item.pszText), r);
4257 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
4258 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4259
4260 /* end edit without saving */
4261 SetFocus(hwnd);
4262 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4263 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4264 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
4265 expect(0, r);
4266 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4267 "edit box - end edit, no change, escape", TRUE);
4268 /* end edit with saving */
4269 SetFocus(hwnd);
4270 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4271 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4272 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
4273 expect(0, r);
4274 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4275 "edit box - end edit, no change, return", TRUE);
4276
4277 memset(&item, 0, sizeof(item));
4278 item.pszText = buffer;
4279 item.cchTextMax = sizeof(buffer);
4280 item.iItem = 0;
4281 item.iSubItem = 0;
4282 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4283 expect(lstrlenA(item.pszText), r);
4284 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
4285
4286 /* LVM_EDITLABEL with -1 destroys current edit */
4287 hwndedit = (HWND)SendMessageA(hwnd, LVM_GETEDITCONTROL, 0, 0);
4288 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4289 /* no edit present */
4290 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4291 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4292 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4293 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4294 /* edit present */
4295 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4296 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4297 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4298 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4299 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4300 /* check another negative value */
4301 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4302 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4303 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4304 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -2, 0);
4305 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4306 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4307 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4308 /* and value greater than max item index */
4309 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4310 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4311 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4312 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
4313 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, r, 0);
4314 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4315 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4316 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4317
4318 /* messaging tests */
4319 SetFocus(hwnd);
4320 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4321 blockEdit = FALSE;
4322 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4323 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4324 /* testing only sizing messages */
4325 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
4326 "edit box create - sizing", FALSE);
4327
4328 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4329 SetFocus(hwnd);
4330 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4331 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4332 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4333 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4334 expect(0, r);
4335 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4336 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
4337
4338 DestroyWindow(hwnd);
4339 }
4340
4341 static void test_notifyformat(void)
4342 {
4343 HWND hwnd, header;
4344 DWORD r;
4345
4346 hwnd = create_listview_control(LVS_REPORT);
4347 ok(hwnd != NULL, "failed to create a listview window\n");
4348
4349 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4350 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4351 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4352 expect(0, r);
4353 SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4354 /* set */
4355 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
4356 expect(0, r);
4357 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4358 if (r == 1)
4359 {
4360 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
4361 expect(1, r);
4362 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4363 expect(0, r);
4364 }
4365 else
4366 {
4367 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4368 DestroyWindow(hwnd);
4369 return;
4370 }
4371
4372 DestroyWindow(hwnd);
4373
4374 /* test failure in parent WM_NOTIFYFORMAT */
4375 notifyFormat = 0;
4376 hwnd = create_listview_control(LVS_REPORT);
4377 ok(hwnd != NULL, "failed to create a listview window\n");
4378 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4379 ok(IsWindow(header), "expected header to be created\n");
4380 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4381 expect(0, r);
4382 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4383 ok( r == 1, "Expected 1, got %d\n", r );
4384 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4385 ok(r != 0, "Expected valid format\n");
4386
4387 notifyFormat = NFR_UNICODE;
4388 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4389 expect(NFR_UNICODE, r);
4390 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4391 expect(1, r);
4392 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4393 ok( r == 1, "Expected 1, got %d\n", r );
4394
4395 notifyFormat = NFR_ANSI;
4396 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4397 expect(NFR_ANSI, r);
4398 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4399 expect(0, r);
4400 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4401 ok( r == 1, "Expected 1, got %d\n", r );
4402
4403 DestroyWindow(hwnd);
4404
4405 hwndparentW = create_parent_window(TRUE);
4406 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
4407 if (!IsWindow(hwndparentW)) return;
4408
4409 notifyFormat = -1;
4410 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4411 ok(hwnd != NULL, "failed to create a listview window\n");
4412 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4413 ok(IsWindow(header), "expected header to be created\n");
4414 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4415 expect(1, r);
4416 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4417 expect(1, r);
4418 DestroyWindow(hwnd);
4419 /* receiving error code defaulting to ansi */
4420 notifyFormat = 0;
4421 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4422 ok(hwnd != NULL, "failed to create a listview window\n");
4423 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4424 ok(IsWindow(header), "expected header to be created\n");
4425 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4426 expect(0, r);
4427 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4428 expect(1, r);
4429 DestroyWindow(hwnd);
4430 /* receiving ansi code from unicode window, use it */
4431 notifyFormat = NFR_ANSI;
4432 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4433 ok(hwnd != NULL, "failed to create a listview window\n");
4434 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4435 ok(IsWindow(header), "expected header to be created\n");
4436 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4437 expect(0, r);
4438 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4439 expect(1, r);
4440 DestroyWindow(hwnd);
4441 /* unicode listview with ansi parent window */
4442 notifyFormat = -1;
4443 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4444 ok(hwnd != NULL, "failed to create a listview window\n");
4445 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4446 ok(IsWindow(header), "expected header to be created\n");
4447 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4448 expect(0, r);
4449 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4450 expect(1, r);
4451 DestroyWindow(hwnd);
4452 /* unicode listview with ansi parent window, return error code */
4453 notifyFormat = 0;
4454 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4455 ok(hwnd != NULL, "failed to create a listview window\n");
4456 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4457 ok(IsWindow(header), "expected header to be created\n");
4458 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4459 expect(0, r);
4460 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4461 expect(1, r);
4462 DestroyWindow(hwnd);
4463
4464 DestroyWindow(hwndparentW);
4465 }
4466
4467 static void test_indentation(void)
4468 {
4469 HWND hwnd;
4470 LVITEMA item;
4471 DWORD r;
4472
4473 hwnd = create_listview_control(LVS_REPORT);
4474 ok(hwnd != NULL, "failed to create a listview window\n");
4475
4476 memset(&item, 0, sizeof(item));
4477 item.mask = LVIF_INDENT;
4478 item.iItem = 0;
4479 item.iIndent = I_INDENTCALLBACK;
4480 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4481 expect(0, r);
4482
4483 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4484
4485 item.iItem = 0;
4486 item.mask = LVIF_INDENT;
4487 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4488 expect(TRUE, r);
4489
4490 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
4491 "get indent dispinfo", FALSE);
4492
4493 DestroyWindow(hwnd);
4494 }
4495
4496 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
4497 {
4498 return 0;
4499 }
4500
4501 static BOOL is_below_comctl_5(void)
4502 {
4503 HWND hwnd;
4504 BOOL ret;
4505
4506 hwnd = create_listview_control(LVS_REPORT);
4507 ok(hwnd != NULL, "failed to create a listview window\n");
4508 insert_item(hwnd, 0);
4509
4510 ret = SendMessageA(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
4511
4512 DestroyWindow(hwnd);
4513
4514 return !ret;
4515 }
4516
4517 static void test_get_set_view(void)
4518 {
4519 HWND hwnd;
4520 DWORD ret;
4521 DWORD_PTR style;
4522
4523 /* test style->view mapping */
4524 hwnd = create_listview_control(LVS_REPORT);
4525 ok(hwnd != NULL, "failed to create a listview window\n");
4526
4527 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4528 expect(LV_VIEW_DETAILS, ret);
4529
4530 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4531 /* LVS_ICON == 0 */
4532 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4533 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4534 expect(LV_VIEW_ICON, ret);
4535
4536 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4537 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4538 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4539 expect(LV_VIEW_SMALLICON, ret);
4540
4541 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4542 SetWindowLongPtrA(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4543 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4544 expect(LV_VIEW_LIST, ret);
4545
4546 /* switching view doesn't touch window style */
4547 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4548 expect(1, ret);
4549 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4550 ok(style & LVS_LIST, "Expected style to be preserved\n");
4551 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4552 expect(1, ret);
4553 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4554 ok(style & LVS_LIST, "Expected style to be preserved\n");
4555 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4556 expect(1, ret);
4557 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4558 ok(style & LVS_LIST, "Expected style to be preserved\n");
4559
4560 DestroyWindow(hwnd);
4561 }
4562
4563 static void test_canceleditlabel(void)
4564 {
4565 HWND hwnd, hwndedit;
4566 DWORD ret;
4567 CHAR buff[10];
4568 LVITEMA itema;
4569 static CHAR test[] = "test";
4570 static const CHAR test1[] = "test1";
4571
4572 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4573 ok(hwnd != NULL, "failed to create a listview window\n");
4574
4575 insert_item(hwnd, 0);
4576
4577 /* try without edit created */
4578 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4579 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4580 expect(TRUE, ret);
4581 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4582 "cancel edit label without edit", FALSE);
4583
4584 /* cancel without data change */
4585 SetFocus(hwnd);
4586 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4587 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4588 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4589 expect(TRUE, ret);
4590 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4591
4592 /* cancel after data change */
4593 memset(&itema, 0, sizeof(itema));
4594 itema.pszText = test;
4595 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
4596 expect(TRUE, ret);
4597 SetFocus(hwnd);
4598 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4599 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4600 ret = SetWindowTextA(hwndedit, test1);
4601 expect(1, ret);
4602 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4603 expect(TRUE, ret);
4604 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4605 memset(&itema, 0, sizeof(itema));
4606 itema.pszText = buff;
4607 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4608 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&itema);
4609 expect(5, ret);
4610 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4611
4612 DestroyWindow(hwnd);
4613 }
4614
4615 static void test_mapidindex(void)
4616 {
4617 HWND hwnd;
4618 INT ret;
4619
4620 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4621 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4622 ok(hwnd != NULL, "failed to create a listview window\n");
4623 insert_item(hwnd, 0);
4624 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4625 expect(-1, ret);
4626 DestroyWindow(hwnd);
4627
4628 hwnd = create_listview_control(LVS_REPORT);
4629 ok(hwnd != NULL, "failed to create a listview window\n");
4630
4631 /* LVM_MAPINDEXTOID with invalid index */
4632 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4633 expect(-1, ret);
4634
4635 insert_item(hwnd, 0);
4636 insert_item(hwnd, 1);
4637
4638 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, -1, 0);
4639 expect(-1, ret);
4640 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 2, 0);
4641 expect(-1, ret);
4642
4643 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4644 expect(0, ret);
4645 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4646 expect(1, ret);
4647 /* remove 0 indexed item, id retained */
4648 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
4649 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4650 expect(1, ret);
4651 /* new id starts from previous value */
4652 insert_item(hwnd, 1);
4653 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4654 expect(2, ret);
4655
4656 /* get index by id */
4657 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4658 expect(-1, ret);
4659 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4660 expect(-1, ret);
4661 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4662 expect(0, ret);
4663 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4664 expect(1, ret);
4665
4666 DestroyWindow(hwnd);
4667 }
4668
4669 static void test_getitemspacing(void)
4670 {
4671 HWND hwnd;
4672 DWORD ret;
4673 INT cx, cy;
4674 HIMAGELIST himl40, himl80;
4675
4676 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4677 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4678
4679 /* LVS_ICON */
4680 hwnd = create_listview_control(LVS_ICON);
4681 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4682 expect(cx, LOWORD(ret));
4683 expect(cy, HIWORD(ret));
4684
4685 /* now try with icons */
4686 himl40 = ImageList_Create(40, 40, 0, 4, 4);
4687 ok(himl40 != NULL, "failed to create imagelist\n");
4688 himl80 = ImageList_Create(80, 80, 0, 4, 4);
4689 ok(himl80 != NULL, "failed to create imagelist\n");
4690 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4691 expect(0, ret);
4692
4693 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4694 /* spacing + icon size returned */
4695 expect(cx + 40, LOWORD(ret));
4696 expect(cy + 40, HIWORD(ret));
4697 /* try changing icon size */
4698 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl80);
4699
4700 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4701 /* spacing + icon size returned */
4702 expect(cx + 80, LOWORD(ret));
4703 expect(cy + 80, HIWORD(ret));
4704
4705 /* set own icon spacing */
4706 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(100, 100));
4707 expect(cx + 80, LOWORD(ret));
4708 expect(cy + 80, HIWORD(ret));
4709
4710 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4711 /* set size returned */
4712 expect(100, LOWORD(ret));
4713 expect(100, HIWORD(ret));
4714
4715 /* now change image list - icon spacing should be unaffected */
4716 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4717
4718 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4719 /* set size returned */
4720 expect(100, LOWORD(ret));
4721 expect(100, HIWORD(ret));
4722
4723 /* spacing = 0 - keep previous value */
4724 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(0, -1));
4725 expect(100, LOWORD(ret));
4726 expect(100, HIWORD(ret));
4727
4728 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4729 expect(100, LOWORD(ret));
4730
4731 expect(0xFFFF, HIWORD(ret));
4732
4733 if (sizeof(void*) == 8)
4734 {
4735 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4736 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, (DWORD)-1);
4737 expect(100, LOWORD(ret));
4738 expect(0xFFFF, HIWORD(ret));
4739
4740 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4741 expect(0xFFFF, LOWORD(ret));
4742 expect(0xFFFF, HIWORD(ret));
4743 }
4744 else
4745 {
4746 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4747 expect(100, LOWORD(ret));
4748 expect(0xFFFF, HIWORD(ret));
4749 }
4750 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4751 /* spacing + icon size returned */
4752 expect(cx + 40, LOWORD(ret));
4753 expect(cy + 40, HIWORD(ret));
4754
4755 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4756 ImageList_Destroy(himl80);
4757 DestroyWindow(hwnd);
4758 /* LVS_SMALLICON */
4759 hwnd = create_listview_control(LVS_SMALLICON);
4760 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4761 expect(cx, LOWORD(ret));
4762 expect(cy, HIWORD(ret));
4763
4764 /* spacing does not depend on selected view type */
4765 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4766 expect(0, ret);
4767
4768 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4769 /* spacing + icon size returned */
4770 expect(cx + 40, LOWORD(ret));
4771 expect(cy + 40, HIWORD(ret));
4772
4773 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4774 ImageList_Destroy(himl40);
4775 DestroyWindow(hwnd);
4776 /* LVS_REPORT */
4777 hwnd = create_listview_control(LVS_REPORT);
4778 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4779 expect(cx, LOWORD(ret));
4780 expect(cy, HIWORD(ret));
4781
4782 DestroyWindow(hwnd);
4783 /* LVS_LIST */
4784 hwnd = create_listview_control(LVS_LIST);
4785 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4786 expect(cx, LOWORD(ret));
4787 expect(cy, HIWORD(ret));
4788
4789 DestroyWindow(hwnd);
4790 }
4791
4792 static void test_getcolumnwidth(void)
4793 {
4794 HWND hwnd;
4795 INT ret;
4796 DWORD_PTR style;
4797 LVCOLUMNA col;
4798 LVITEMA itema;
4799 HDC hdc;
4800
4801 /* default column width */
4802 hwnd = create_listview_control(LVS_ICON);
4803 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4804 expect(0, ret);
4805 style = GetWindowLongA(hwnd, GWL_STYLE);
4806 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_LIST);
4807 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4808 todo_wine expect(8, ret);
4809 style = GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_LIST;
4810 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_REPORT);
4811 col.mask = 0;
4812 ret = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4813 expect(0, ret);
4814 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4815 expect(10, ret);
4816 DestroyWindow(hwnd);
4817
4818 /* default column width with item added */
4819 hwnd = create_listview_control(LVS_LIST);
4820 memset(&itema, 0, sizeof(itema));
4821 SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4822 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4823 hdc = GetDC(hwnd);
4824 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, ret);
4825 ReleaseDC(hwnd, hdc);
4826 DestroyWindow(hwnd);
4827 }
4828
4829 static void test_scrollnotify(void)
4830 {
4831 HWND hwnd;
4832 DWORD ret;
4833
4834 hwnd = create_listview_control(LVS_REPORT);
4835
4836 insert_column(hwnd, 0);
4837 insert_column(hwnd, 1);
4838 insert_item(hwnd, 0);
4839
4840 /* make it scrollable - resize */
4841 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4842 expect(TRUE, ret);
4843 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4844 expect(TRUE, ret);
4845
4846 /* try with dummy call */
4847 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4848 ret = SendMessageA(hwnd, LVM_SCROLL, 0, 0);
4849 expect(TRUE, ret);
4850 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4851 "scroll notify 1", TRUE);
4852
4853 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4854 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 0);
4855 expect(TRUE, ret);
4856 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4857 "scroll notify 2", TRUE);
4858
4859 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4860 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 1);
4861 expect(TRUE, ret);
4862 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4863 "scroll notify 3", TRUE);
4864
4865 DestroyWindow(hwnd);
4866 }
4867
4868 static void test_LVS_EX_TRANSPARENTBKGND(void)
4869 {
4870 HWND hwnd;
4871 DWORD ret;
4872 HDC hdc;
4873
4874 hwnd = create_listview_control(LVS_REPORT);
4875
4876 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4877 expect(TRUE, ret);
4878
4879 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4880 LVS_EX_TRANSPARENTBKGND);
4881
4882 ret = SendMessageA(hwnd, LVM_GETBKCOLOR, 0, 0);
4883 if (ret != CLR_NONE)
4884 {
4885 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4886 DestroyWindow(hwnd);
4887 return;
4888 }
4889
4890 /* try to set some back color and check this style bit */
4891 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4892 expect(TRUE, ret);
4893 ret = SendMessageA(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4894 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4895
4896 /* now test what this style actually does */
4897 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4898 LVS_EX_TRANSPARENTBKGND);
4899
4900 hdc = GetWindowDC(hwndparent);
4901
4902 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4903 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4904 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4905 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4906
4907 ReleaseDC(hwndparent, hdc);
4908
4909 DestroyWindow(hwnd);
4910 }
4911
4912 static void test_approximate_viewrect(void)
4913 {
4914 HWND hwnd;
4915 DWORD ret;
4916 HIMAGELIST himl;
4917 HBITMAP hbmp;
4918 LVITEMA itema;
4919 static CHAR test[] = "abracadabra, a very long item label";
4920
4921 hwnd = create_listview_control(LVS_ICON);
4922 himl = ImageList_Create(40, 40, 0, 4, 4);
4923 ok(himl != NULL, "failed to create imagelist\n");
4924 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4925 ok(hbmp != NULL, "failed to create bitmap\n");
4926 ret = ImageList_Add(himl, hbmp, 0);
4927 expect(0, ret);
4928 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4929 expect(0, ret);
4930
4931 itema.mask = LVIF_IMAGE;
4932 itema.iImage = 0;
4933 itema.iItem = 0;
4934 itema.iSubItem = 0;
4935 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4936 expect(0, ret);
4937
4938 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4939 if (ret == 0)
4940 {
4941 /* version 4.0 */
4942 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4943 return;
4944 }
4945
4946 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4947 expect(MAKELONG(77,827), ret);
4948
4949 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4950 ok(ret != 0, "got 0\n");
4951
4952 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4953 expect(MAKELONG(102,302), ret);
4954
4955 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4956 expect(MAKELONG(52,52), ret);
4957
4958 itema.pszText = test;
4959 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
4960 expect(TRUE, ret);
4961 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4962 expect(MAKELONG(52,52), ret);
4963
4964 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4965 expect(MAKELONG(52,2), ret);
4966 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4967 expect(MAKELONG(52,52), ret);
4968 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4969 expect(MAKELONG(102,52), ret);
4970 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4971 expect(MAKELONG(102,102), ret);
4972 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4973 expect(MAKELONG(102,102), ret);
4974 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4975 expect(MAKELONG(102,152), ret);
4976 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4977 expect(MAKELONG(102,152), ret);
4978 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4979 expect(MAKELONG(152,152), ret);
4980
4981 DestroyWindow(hwnd);
4982 }
4983
4984 static void test_finditem(void)
4985 {
4986 LVFINDINFOA fi;
4987 static char f[5];
4988 HWND hwnd;
4989 INT r;
4990
4991 hwnd = create_listview_control(LVS_REPORT);
4992 insert_item(hwnd, 0);
4993
4994 memset(&fi, 0, sizeof(fi));
4995
4996 /* full string search, inserted text was "foo" */
4997 strcpy(f, "foo");
4998 fi.flags = LVFI_STRING;
4999 fi.psz = f;
5000 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5001 expect(0, r);
5002 /* partial string search, inserted text was "foo" */
5003 strcpy(f, "fo");
5004 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5005 fi.psz = f;
5006 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5007 expect(0, r);
5008 /* partial string search, part after start char */
5009 strcpy(f, "oo");
5010 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5011 fi.psz = f;
5012 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5013 expect(-1, r);
5014
5015 /* try with LVFI_SUBSTRING */
5016 strcpy(f, "fo");
5017 fi.flags = LVFI_SUBSTRING;
5018 fi.psz = f;
5019 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5020 if (r == -1)
5021 {
5022 win_skip("LVFI_SUBSTRING not supported\n");
5023 DestroyWindow(hwnd);
5024 return;
5025 }
5026 expect(0, r);
5027 strcpy(f, "f");
5028 fi.flags = LVFI_SUBSTRING;
5029 fi.psz = f;
5030 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5031 expect(0, r);
5032 strcpy(f, "o");
5033 fi.flags = LVFI_SUBSTRING;
5034 fi.psz = f;
5035 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5036 expect(-1, r);
5037
5038 strcpy(f, "f");
5039 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
5040 fi.psz = f;
5041 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5042 expect(0, r);
5043
5044 DestroyWindow(hwnd);
5045 }
5046
5047 static void test_LVS_EX_HEADERINALLVIEWS(void)
5048 {
5049 HWND hwnd, header;
5050 DWORD style;
5051
5052 hwnd = create_listview_control(LVS_ICON);
5053
5054 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5055 LVS_EX_HEADERINALLVIEWS);
5056
5057 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5058 if (!IsWindow(header))
5059 {
5060 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
5061 DestroyWindow(hwnd);
5062 return;
5063 }
5064
5065 /* LVS_NOCOLUMNHEADER works as before */
5066 style = GetWindowLongA(hwnd, GWL_STYLE);
5067 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
5068 style = GetWindowLongA(header, GWL_STYLE);
5069 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
5070 style = GetWindowLongA(hwnd, GWL_STYLE);
5071 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
5072 style = GetWindowLongA(header, GWL_STYLE);
5073 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
5074
5075 /* try to remove style */
5076 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
5077 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5078 ok(IsWindow(header), "Expected header to be created\n");
5079 style = GetWindowLongA(header, GWL_STYLE);
5080 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
5081
5082 DestroyWindow(hwnd);
5083
5084 /* check other styles */
5085 hwnd = create_listview_control(LVS_LIST);
5086 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5087 LVS_EX_HEADERINALLVIEWS);
5088 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5089 ok(IsWindow(header), "Expected header to be created\n");
5090 DestroyWindow(hwnd);
5091
5092 hwnd = create_listview_control(LVS_SMALLICON);
5093 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5094 LVS_EX_HEADERINALLVIEWS);
5095 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5096 ok(IsWindow(header), "Expected header to be created\n");
5097 DestroyWindow(hwnd);
5098
5099 hwnd = create_listview_control(LVS_REPORT);
5100 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5101 LVS_EX_HEADERINALLVIEWS);
5102 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5103 ok(IsWindow(header), "Expected header to be created\n");
5104 DestroyWindow(hwnd);
5105 }
5106
5107 static void test_hover(void)
5108 {
5109 HWND hwnd;
5110 DWORD r;
5111
5112 hwnd = create_listview_control(LVS_ICON);
5113
5114 /* test WM_MOUSEHOVER forwarding */
5115 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5116 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5117 expect(0, r);
5118 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
5119 g_block_hover = TRUE;
5120 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5121 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5122 expect(0, r);
5123 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
5124 g_block_hover = FALSE;
5125
5126 r = SendMessageA(hwnd, LVM_SETHOVERTIME, 0, 500);
5127 expect(HOVER_DEFAULT, r);
5128 r = SendMessageA(hwnd, LVM_GETHOVERTIME, 0, 0);
5129 expect(500, r);
5130
5131 DestroyWindow(hwnd);
5132 }
5133
5134 static void test_destroynotify(void)
5135 {
5136 HWND hwnd;
5137 BOOL ret;
5138
5139 hwnd = create_listview_control(LVS_REPORT);
5140 ok(hwnd != NULL, "failed to create listview window\n");
5141
5142 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5143 DestroyWindow(hwnd);
5144 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
5145
5146 /* same for ownerdata list */
5147 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5148 ok(hwnd != NULL, "failed to create listview window\n");
5149
5150 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5151 DestroyWindow(hwnd);
5152 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_destroy, "check destroy order, ownerdata", FALSE);
5153
5154 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5155 ok(hwnd != NULL, "failed to create listview window\n");
5156
5157 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5158 ret = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
5159 ok(ret == TRUE, "got %d\n", ret);
5160 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_deleteall, "deleteall ownerdata", FALSE);
5161 DestroyWindow(hwnd);
5162 }
5163
5164 static void test_header_notification(void)
5165 {
5166 static char textA[] = "newtext";
5167 HWND list, header;
5168 HDITEMA item;
5169 NMHEADERA nmh;
5170 LVCOLUMNA col;
5171 DWORD ret;
5172 BOOL r;
5173
5174 list = create_listview_control(LVS_REPORT);
5175 ok(list != NULL, "failed to create listview window\n");
5176
5177 memset(&col, 0, sizeof(col));
5178 col.mask = LVCF_WIDTH;
5179 col.cx = 100;
5180 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5181 expect(0, ret);
5182
5183 /* check list parent notification after header item changed,
5184 this test should be placed before header subclassing to avoid
5185 Listview -> Header messages to be logged */
5186 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5187
5188 col.mask = LVCF_TEXT;
5189 col.pszText = textA;
5190 r = SendMessageA(list, LVM_SETCOLUMNA, 0, (LPARAM)&col);
5191 expect(TRUE, r);
5192
5193 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_changed_seq,
5194 "header notify, listview", FALSE);
5195 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5196 "header notify, parent", FALSE);
5197
5198 header = subclass_header(list);
5199
5200 ret = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
5201 expect(1, ret);
5202
5203 memset(&item, 0, sizeof(item));
5204 item.mask = HDI_WIDTH;
5205 ret = SendMessageA(header, HDM_GETITEMA, 0, (LPARAM)&item);
5206 expect(1, ret);
5207 expect(100, item.cxy);
5208
5209 nmh.hdr.hwndFrom = header;
5210 nmh.hdr.idFrom = GetWindowLongPtrA(header, GWLP_ID);
5211 nmh.hdr.code = HDN_ITEMCHANGEDA;
5212 nmh.iItem = 0;
5213 nmh.iButton = 0;
5214 item.mask = HDI_WIDTH;
5215 item.cxy = 50;
5216 nmh.pitem = &item;
5217 ret = SendMessageA(list, WM_NOTIFY, 0, (LPARAM)&nmh);
5218 expect(0, ret);
5219
5220 DestroyWindow(list);
5221 }
5222
5223 static void test_header_notification2(void)
5224 {
5225 static char textA[] = "newtext";
5226 HWND list, header;
5227 HDITEMW itemW;
5228 NMHEADERW nmhdr;
5229 LVCOLUMNA col;
5230 DWORD ret;
5231 WCHAR buffer[100];
5232 struct message parent_header_notify_seq[] = {
5233 { WM_NOTIFY, sent|id, 0, 0, 0 },
5234 { 0 }
5235 };
5236
5237 list = create_listview_control(LVS_REPORT);
5238 ok(list != NULL, "failed to create listview window\n");
5239
5240 memset(&col, 0, sizeof(col));
5241 col.mask = LVCF_WIDTH | LVCF_TEXT;
5242 col.cx = 100;
5243 col.pszText = textA;
5244 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5245 expect(0, ret);
5246
5247 header = (HWND)SendMessageA(list, LVM_GETHEADER, 0, 0);
5248 ok(header != 0, "No header\n");
5249 memset(&itemW, 0, sizeof(itemW));
5250 itemW.mask = HDI_WIDTH | HDI_ORDER | HDI_TEXT;
5251 itemW.pszText = buffer;
5252 itemW.cchTextMax = sizeof(buffer);
5253 ret = SendMessageW(header, HDM_GETITEMW, 0, (LPARAM)&itemW);
5254 expect(1, ret);
5255
5256 nmhdr.hdr.hwndFrom = header;
5257 nmhdr.hdr.idFrom = GetWindowLongPtrW(header, GWLP_ID);
5258 nmhdr.iItem = 0;
5259 nmhdr.iButton = 0;
5260 nmhdr.pitem = &itemW;
5261
5262 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5263 nmhdr.hdr.code = HDN_ITEMCHANGINGW;
5264 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5265 parent_header_notify_seq[0].id = HDN_ITEMCHANGINGA;
5266 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5267 "header notify, parent", TRUE);
5268 todo_wine
5269 ok(nmhdr.hdr.code == HDN_ITEMCHANGINGA, "Expected ANSI notification code\n");
5270 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5271 nmhdr.hdr.code = HDN_ITEMCHANGEDW;
5272 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5273 parent_header_notify_seq[0].id = HDN_ITEMCHANGEDA;
5274 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5275 "header notify, parent", TRUE);
5276 todo_wine
5277 ok(nmhdr.hdr.code == HDN_ITEMCHANGEDA, "Expected ANSI notification code\n");
5278 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5279 SetFocus(list);
5280 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5281 nmhdr.hdr.code = HDN_ITEMCLICKW;
5282 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5283 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_click_seq,
5284 "header notify, parent", FALSE);
5285 ok(nmhdr.hdr.code == HDN_ITEMCLICKA, "Expected ANSI notification code\n");
5286 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5287 nmhdr.hdr.code = HDN_ITEMDBLCLICKW;
5288 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5289 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5290 "header notify, parent", FALSE);
5291 ok(nmhdr.hdr.code == HDN_ITEMDBLCLICKW, "Expected Unicode notification code\n");
5292 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5293 nmhdr.hdr.code = HDN_DIVIDERDBLCLICKW;
5294 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5295 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_divider_dclick_seq,
5296 "header notify, parent", TRUE);
5297 ok(nmhdr.hdr.code == HDN_DIVIDERDBLCLICKA, "Expected ANSI notification code\n");
5298 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5299 nmhdr.hdr.code = HDN_BEGINTRACKW;
5300 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5301 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5302 "header notify, parent", FALSE);
5303 ok(nmhdr.hdr.code == HDN_BEGINTRACKW, "Expected Unicode notification code\n");
5304 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5305 nmhdr.hdr.code = HDN_ENDTRACKW;
5306 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5307 parent_header_notify_seq[0].id = HDN_ENDTRACKA;
5308 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5309 "header notify, parent", FALSE);
5310 ok(nmhdr.hdr.code == HDN_ENDTRACKA, "Expected ANSI notification code\n");
5311 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5312 nmhdr.hdr.code = HDN_TRACKW;
5313 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5314 parent_header_notify_seq[0].id = HDN_TRACKA;
5315 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5316 "header notify, parent", FALSE);
5317 ok(nmhdr.hdr.code == HDN_TRACKA, "Expected ANSI notification code\n");
5318 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5319 nmhdr.hdr.code = HDN_BEGINDRAG;
5320 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5321 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5322 "header notify, parent", FALSE);
5323 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5324 nmhdr.hdr.code = HDN_ENDDRAG;
5325 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5326 parent_header_notify_seq[0].id = HDN_ENDDRAG;
5327 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5328 "header notify, parent", FALSE);
5329 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5330 nmhdr.hdr.code = HDN_FILTERCHANGE;
5331 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5332 parent_header_notify_seq[0].id = HDN_FILTERCHANGE;
5333 parent_header_notify_seq[0].flags |= optional; /* NT4 does not send this message */
5334 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5335 "header notify, parent", FALSE);
5336 parent_header_notify_seq[0].flags &= ~optional;
5337 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5338 nmhdr.hdr.code = HDN_BEGINFILTEREDIT;
5339 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5340 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5341 "header notify, parent", FALSE);
5342 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5343 nmhdr.hdr.code = HDN_ENDFILTEREDIT;
5344 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5345 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5346 "header notify, parent", FALSE);
5347 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5348 nmhdr.hdr.code = HDN_ITEMSTATEICONCLICK;
5349 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5350 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5351 "header notify, parent", FALSE);
5352 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5353 nmhdr.hdr.code = HDN_ITEMKEYDOWN;
5354 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5355 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5356 "header notify, parent", FALSE);
5357
5358 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5359
5360 DestroyWindow(list);
5361 }
5362
5363 static void test_createdragimage(void)
5364 {
5365 HIMAGELIST himl;
5366 POINT pt;
5367 HWND list;
5368
5369 list = create_listview_control(LVS_ICON);
5370 ok(list != NULL, "failed to create listview window\n");
5371
5372 insert_item(list, 0);
5373
5374 /* NULL point */
5375 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
5376 ok(himl == NULL, "got %p\n", himl);
5377
5378 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
5379 ok(himl != NULL, "got %p\n", himl);
5380 ImageList_Destroy(himl);
5381
5382 DestroyWindow(list);
5383 }
5384
5385 static void test_dispinfo(void)
5386 {
5387 static const char testA[] = "TEST";
5388 WCHAR buff[10];
5389 LVITEMA item;
5390 HWND hwnd;
5391 DWORD ret;
5392
5393 hwnd = create_listview_control(LVS_ICON);
5394 ok(hwnd != NULL, "failed to create listview window\n");
5395
5396 insert_item(hwnd, 0);
5397
5398 memset(&item, 0, sizeof(item));
5399 item.pszText = LPSTR_TEXTCALLBACKA;
5400 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5401 expect(1, ret);
5402
5403 g_disp_A_to_W = TRUE;
5404 item.pszText = (char*)buff;
5405 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
5406 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
5407 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
5408 g_disp_A_to_W = FALSE;
5409
5410 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
5411 "got %s, expected %s\n", item.pszText, testA);
5412
5413 DestroyWindow(hwnd);
5414 }
5415
5416 static void test_LVM_SETITEMTEXT(void)
5417 {
5418 static char testA[] = "TEST";
5419 LVITEMA item;
5420 HWND hwnd;
5421 DWORD ret;
5422
5423 hwnd = create_listview_control(LVS_ICON);
5424 ok(hwnd != NULL, "failed to create listview window\n");
5425
5426 insert_item(hwnd, 0);
5427
5428 /* null item pointer */
5429 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, 0);
5430 expect(FALSE, ret);
5431
5432 ret = SendMessageA(hwnd, LVM_SETITEMTEXTW, 0, 0);
5433 expect(FALSE, ret);
5434
5435 /* index out of bounds */
5436 item.pszText = testA;
5437 item.cchTextMax = 0; /* ignored */
5438 item.iSubItem = 0;
5439
5440 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 1, (LPARAM)&item);
5441 expect(FALSE, ret);
5442
5443 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, -1, (LPARAM)&item);
5444 expect(FALSE, ret);
5445
5446 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5447 expect(TRUE, ret);
5448
5449 DestroyWindow(hwnd);
5450 }
5451
5452 static void test_imagelists(void)
5453 {
5454 HWND hwnd, header;
5455 HIMAGELIST himl1, himl2, himl3;
5456 LRESULT ret;
5457
5458 himl1 = ImageList_Create(40, 40, 0, 4, 4);
5459 himl2 = ImageList_Create(40, 40, 0, 4, 4);
5460 himl3 = ImageList_Create(40, 40, 0, 4, 4);
5461 ok(himl1 != NULL, "Failed to create imagelist\n");
5462 ok(himl2 != NULL, "Failed to create imagelist\n");
5463 ok(himl3 != NULL, "Failed to create imagelist\n");
5464
5465 hwnd = create_listview_control(LVS_REPORT | LVS_SHAREIMAGELISTS);
5466 header = subclass_header(hwnd);
5467
5468 ok(header != NULL, "Expected header\n");
5469 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5470 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5471
5472 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5473
5474 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5475 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5476 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5477 "set normal image list", FALSE);
5478
5479 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5480
5481 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5482 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5483 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5484 "set state image list", TRUE);
5485
5486 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5487 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5488
5489 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5490
5491 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5492 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5493 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_set_imagelist,
5494 "set small image list", FALSE);
5495
5496 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5497 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5498 DestroyWindow(hwnd);
5499
5500 hwnd = create_listview_control(WS_VISIBLE | LVS_ICON);
5501
5502 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5503
5504 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5505 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5506 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5507 "set normal image list", FALSE);
5508
5509 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5510
5511 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5512 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5513 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5514 "set state image list", FALSE);
5515
5516 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5517
5518 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5519 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5520 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5521 "set small image list", FALSE);
5522
5523 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5524 ok(header == NULL, "Expected no header, got %p\n", header);
5525
5526 SetWindowLongPtrA(hwnd, GWL_STYLE, GetWindowLongPtrA(hwnd, GWL_STYLE) | LVS_REPORT);
5527
5528 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5529 ok(header != NULL, "Expected header, got NULL\n");
5530
5531 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5532 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5533
5534 DestroyWindow(hwnd);
5535 }
5536
5537 static void test_deleteitem(void)
5538 {
5539 LVITEMA item;
5540 UINT state;
5541 HWND hwnd;
5542 BOOL ret;
5543
5544 hwnd = create_listview_control(LVS_REPORT);
5545
5546 insert_item(hwnd, 0);
5547 insert_item(hwnd, 0);
5548 insert_item(hwnd, 0);
5549 insert_item(hwnd, 0);
5550 insert_item(hwnd, 0);
5551
5552 g_focus_test_LVN_DELETEITEM = TRUE;
5553
5554 /* delete focused item (not the last index) */
5555 item.stateMask = LVIS_FOCUSED;
5556 item.state = LVIS_FOCUSED;
5557 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
5558 ok(ret == TRUE, "got %d\n", ret);
5559 ret = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
5560 ok(ret == TRUE, "got %d\n", ret);
5561 /* next item gets focus */
5562 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5563 ok(state == LVIS_FOCUSED, "got %x\n", state);
5564
5565 /* focus last item and delete it */
5566 item.stateMask = LVIS_FOCUSED;
5567 item.state = LVIS_FOCUSED;
5568 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
5569 ok(ret == TRUE, "got %d\n", ret);
5570 ret = SendMessageA(hwnd, LVM_DELETEITEM, 3, 0);
5571 ok(ret == TRUE, "got %d\n", ret);
5572 /* new last item gets focus */
5573 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5574 ok(state == LVIS_FOCUSED, "got %x\n", state);
5575
5576 /* focus first item and delete it */
5577 item.stateMask = LVIS_FOCUSED;
5578 item.state = LVIS_FOCUSED;
5579 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
5580 ok(ret == TRUE, "got %d\n", ret);
5581 ret = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
5582 ok(ret == TRUE, "got %d\n", ret);
5583 /* new first item gets focus */
5584 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5585 ok(state == LVIS_FOCUSED, "got %x\n", state);
5586
5587 g_focus_test_LVN_DELETEITEM = FALSE;
5588
5589 DestroyWindow(hwnd);
5590 }
5591
5592 static void test_insertitem(void)
5593 {
5594 LVITEMA item;
5595 UINT state;
5596 HWND hwnd;
5597 INT ret;
5598
5599 hwnd = create_listview_control(LVS_REPORT);
5600
5601 /* insert item 0 focused */
5602 item.mask = LVIF_STATE;
5603 item.state = LVIS_FOCUSED;
5604 item.stateMask = LVIS_FOCUSED;
5605 item.iItem = 0;
5606 item.iSubItem = 0;
5607 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5608 ok(ret == 0, "got %d\n", ret);
5609
5610 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5611 ok(state == LVIS_FOCUSED, "got %x\n", state);
5612
5613 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5614
5615 /* insert item 1, focus shift */
5616 item.mask = LVIF_STATE;
5617 item.state = LVIS_FOCUSED;
5618 item.stateMask = LVIS_FOCUSED;
5619 item.iItem = 1;
5620 item.iSubItem = 0;
5621 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5622 ok(ret == 1, "got %d\n", ret);
5623
5624 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused_seq, "insert focused", TRUE);
5625
5626 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5627 ok(state == LVIS_FOCUSED, "got %x\n", state);
5628
5629 /* insert item 2, no focus shift */
5630 item.mask = LVIF_STATE;
5631 item.state = 0;
5632 item.stateMask = LVIS_FOCUSED;
5633 item.iItem = 2;
5634 item.iSubItem = 0;
5635 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5636 ok(ret == 2, "got %d\n", ret);
5637
5638 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5639 ok(state == LVIS_FOCUSED, "got %x\n", state);
5640
5641 DestroyWindow(hwnd);
5642 }
5643
5644 START_TEST(listview)
5645 {
5646 HMODULE hComctl32;
5647 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
5648
5649 ULONG_PTR ctx_cookie;
5650 HANDLE hCtx;
5651
5652 hComctl32 = GetModuleHandleA("comctl32.dll");
5653 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
5654 if (pInitCommonControlsEx)
5655 {
5656 INITCOMMONCONTROLSEX iccex;
5657 iccex.dwSize = sizeof(iccex);
5658 iccex.dwICC = ICC_LISTVIEW_CLASSES;
5659 pInitCommonControlsEx(&iccex);
5660 }
5661 else
5662 InitCommonControls();
5663
5664 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
5665
5666 hwndparent = create_parent_window(FALSE);
5667 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5668
5669 g_is_below_5 = is_below_comctl_5();
5670
5671 test_header_notification();
5672 test_header_notification2();
5673 test_images();
5674 test_checkboxes();
5675 test_items();
5676 test_create();
5677 test_redraw();
5678 test_customdraw();
5679 test_icon_spacing();
5680 test_color();
5681 test_item_count();
5682 test_item_position();
5683 test_columns();
5684 test_getorigin();
5685 test_multiselect();
5686 test_getitemrect();
5687 test_subitem_rect();
5688 test_sorting();
5689 test_ownerdata();
5690 test_norecompute();
5691 test_nosortheader();
5692 test_setredraw();
5693 test_hittest();
5694 test_getviewrect();
5695 test_getitemposition();
5696 test_columnscreation();
5697 test_editbox();
5698 test_notifyformat();
5699 test_indentation();
5700 test_getitemspacing();
5701 test_getcolumnwidth();
5702 test_approximate_viewrect();
5703 test_finditem();
5704 test_hover();
5705 test_destroynotify();
5706 test_createdragimage();
5707 test_dispinfo();
5708 test_LVM_SETITEMTEXT();
5709 test_imagelists();
5710 test_deleteitem();
5711 test_insertitem();
5712
5713 if (!load_v6_module(&ctx_cookie, &hCtx))
5714 {
5715 DestroyWindow(hwndparent);
5716 return;
5717 }
5718
5719 /* comctl32 version 6 tests start here */
5720 test_get_set_view();
5721 test_canceleditlabel();
5722 test_mapidindex();
5723 test_scrollnotify();
5724 test_LVS_EX_TRANSPARENTBKGND();
5725 test_LVS_EX_HEADERINALLVIEWS();
5726 test_deleteitem();
5727 test_multiselect();
5728 test_insertitem();
5729
5730 unload_v6_module(ctx_cookie, hCtx);
5731
5732 DestroyWindow(hwndparent);
5733 }