2c4a7f36818fb363694c1c39612b6a6842e985ac
[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 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 0, 0, LISTVIEW_ID },
183 { HDM_GETORDERARRAY, sent|id|wparam, 0, 0, HEADER_ID },
184 { 0 }
185 };
186
187 static const struct message listview_setorderarray_seq[] = {
188 { LVM_SETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
189 { HDM_SETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
190 { LVM_SETCOLUMNORDERARRAY, sent|id|wparam, 0, 0, LISTVIEW_ID },
191 { HDM_SETORDERARRAY, sent|id|wparam, 0, 0, HEADER_ID },
192 { 0 }
193 };
194
195 static const struct message empty_seq[] = {
196 { 0 }
197 };
198
199 static const struct message forward_erasebkgnd_parent_seq[] = {
200 { WM_ERASEBKGND, sent },
201 { 0 }
202 };
203
204 static const struct message ownerdata_select_focus_parent_seq[] = {
205 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
206 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
207 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
208 { 0 }
209 };
210
211 static const struct message ownerdata_setstate_all_parent_seq[] = {
212 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
213 { 0 }
214 };
215
216 static const struct message ownerdata_defocus_all_parent_seq[] = {
217 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
218 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
219 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
220 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
221 { 0 }
222 };
223
224 static const struct message ownerdata_deselect_all_parent_seq[] = {
225 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
226 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
227 { 0 }
228 };
229
230 static const struct message change_all_parent_seq[] = {
231 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
232 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
233
234 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
235 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
236
237 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
238 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
239
240 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
241 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
242
243 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
244 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
245 { 0 }
246 };
247
248 static const struct message changing_all_parent_seq[] = {
249 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
250 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
251 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
252 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
253 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
254 { 0 }
255 };
256
257 static const struct message textcallback_set_again_parent_seq[] = {
258 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
259 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
260 { 0 }
261 };
262
263 static const struct message single_getdispinfo_parent_seq[] = {
264 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
265 { 0 }
266 };
267
268 static const struct message getitemposition_seq1[] = {
269 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
270 { 0 }
271 };
272
273 static const struct message getitemposition_seq2[] = {
274 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
275 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
276 { 0 }
277 };
278
279 static const struct message getsubitemrect_seq[] = {
280 { LVM_GETSUBITEMRECT, sent|id|wparam, -1, 0, LISTVIEW_ID },
281 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
282 { LVM_GETSUBITEMRECT, sent|id|wparam, 0, 0, LISTVIEW_ID },
283 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
284 { LVM_GETSUBITEMRECT, sent|id|wparam, -10, 0, LISTVIEW_ID },
285 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
286 { LVM_GETSUBITEMRECT, sent|id|wparam, 20, 0, LISTVIEW_ID },
287 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
288 { 0 }
289 };
290
291 static const struct message editbox_create_pos[] = {
292 /* sequence sent after LVN_BEGINLABELEDIT */
293 /* next two are 4.7x specific */
294 { WM_WINDOWPOSCHANGING, sent },
295 { WM_WINDOWPOSCHANGED, sent|optional },
296
297 { WM_WINDOWPOSCHANGING, sent|optional },
298 { WM_NCCALCSIZE, sent },
299 { WM_WINDOWPOSCHANGED, sent },
300 { WM_MOVE, sent|defwinproc },
301 { WM_SIZE, sent|defwinproc },
302 /* the rest is todo, skipped in 4.7x */
303 { WM_WINDOWPOSCHANGING, sent|optional },
304 { WM_WINDOWPOSCHANGED, sent|optional },
305 { 0 }
306 };
307
308 static const struct message scroll_parent_seq[] = {
309 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
310 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
311 { 0 }
312 };
313
314 static const struct message setredraw_seq[] = {
315 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
316 { 0 }
317 };
318
319 static const struct message lvs_ex_transparentbkgnd_seq[] = {
320 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
321 { 0 }
322 };
323
324 static const struct message edit_end_nochange[] = {
325 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
326 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW }, /* todo */
327 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
328 { 0 }
329 };
330
331 static const struct message hover_parent[] = {
332 { WM_GETDLGCODE, sent }, /* todo_wine */
333 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
334 { 0 }
335 };
336
337 static const struct message listview_destroy[] = {
338 { 0x0090, sent|optional }, /* Vista */
339 { WM_PARENTNOTIFY, sent },
340 { WM_SHOWWINDOW, sent },
341 { WM_WINDOWPOSCHANGING, sent },
342 { WM_WINDOWPOSCHANGED, sent|optional },
343 { WM_DESTROY, sent },
344 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
345 { WM_NCDESTROY, sent },
346 { 0 }
347 };
348
349 static const struct message listview_ownerdata_destroy[] = {
350 { 0x0090, sent|optional }, /* Vista */
351 { WM_PARENTNOTIFY, sent },
352 { WM_SHOWWINDOW, sent },
353 { WM_WINDOWPOSCHANGING, sent },
354 { WM_WINDOWPOSCHANGED, sent|optional },
355 { WM_DESTROY, sent },
356 { WM_NCDESTROY, sent },
357 { 0 }
358 };
359
360 static const struct message listview_ownerdata_deleteall[] = {
361 { LVM_DELETEALLITEMS, sent },
362 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
363 { 0 }
364 };
365
366 static const struct message listview_header_changed_seq[] = {
367 { LVM_SETCOLUMNA, sent },
368 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
369 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
370 { 0 }
371 };
372
373 static const struct message parent_header_click_seq[] = {
374 { WM_NOTIFY, sent|id, 0, 0, LVN_COLUMNCLICK },
375 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCLICKA },
376 { 0 }
377 };
378
379 static const struct message parent_header_divider_dclick_seq[] = {
380 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGINGA },
381 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
382 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
383 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGEDA },
384 { WM_NOTIFY, sent|id, 0, 0, HDN_DIVIDERDBLCLICKA },
385 { 0 }
386 };
387
388 static const struct message listview_set_imagelist[] = {
389 { LVM_SETIMAGELIST, sent|id, 0, 0, LISTVIEW_ID },
390 { 0 }
391 };
392
393 static const struct message listview_header_set_imagelist[] = {
394 { LVM_SETIMAGELIST, sent|id, 0, 0, LISTVIEW_ID },
395 { HDM_SETIMAGELIST, sent|id, 0, 0, HEADER_ID },
396 { 0 }
397 };
398
399 static const struct message parent_insert_focused_seq[] = {
400 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
401 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
402 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
403 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
404 { WM_NOTIFY, sent|id, 0, 0, LVN_INSERTITEM },
405 { 0 }
406 };
407
408 static const struct message parent_report_cd_seq[] = {
409 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_PREPAINT },
410 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT },
411 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT|CDDS_SUBITEM },
412 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT|CDDS_SUBITEM },
413 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT|CDDS_SUBITEM },
414 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT|CDDS_SUBITEM },
415 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT },
416 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_POSTPAINT },
417 { 0 }
418 };
419
420 static const struct message parent_list_cd_seq[] = {
421 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_PREPAINT },
422 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT },
423 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT },
424 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_POSTPAINT },
425 { 0 }
426 };
427
428 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
429 {
430 static LONG defwndproc_counter = 0;
431 LRESULT ret;
432 struct message msg;
433
434 msg.message = message;
435 msg.flags = sent|wparam|lparam;
436 if (defwndproc_counter) msg.flags |= defwinproc;
437 msg.wParam = wParam;
438 msg.lParam = lParam;
439 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
440
441 /* log system messages, except for painting */
442 if (message < WM_USER &&
443 message != WM_PAINT &&
444 message != WM_ERASEBKGND &&
445 message != WM_NCPAINT &&
446 message != WM_NCHITTEST &&
447 message != WM_GETTEXT &&
448 message != WM_GETICON &&
449 message != WM_DEVICECHANGE)
450 {
451 add_message(sequences, PARENT_SEQ_INDEX, &msg);
452 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
453 }
454 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
455
456 switch (message)
457 {
458 case WM_NOTIFY:
459 {
460 switch (((NMHDR*)lParam)->code)
461 {
462 case LVN_BEGINLABELEDITA:
463 {
464 HWND edit = NULL;
465
466 /* subclass edit box */
467 if (!blockEdit)
468 edit = subclass_editbox(((NMHDR*)lParam)->hwndFrom);
469
470 if (edit)
471 {
472 INT len = SendMessageA(edit, EM_GETLIMITTEXT, 0, 0);
473 ok(len == 259 || broken(len == 260) /* includes NULL in NT4 */,
474 "text limit %d, expected 259\n", len);
475 }
476
477 return blockEdit;
478 }
479 case LVN_ENDLABELEDITA:
480 {
481 HWND edit;
482
483 /* always accept new item text */
484 NMLVDISPINFOA *di = (NMLVDISPINFOA*)lParam;
485 g_editbox_disp_info = *di;
486 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText ? di->item.pszText : "(null)");
487
488 /* edit control still available from this notification */
489 edit = (HWND)SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETEDITCONTROL, 0, 0);
490 ok(IsWindow(edit), "expected valid edit control handle\n");
491 ok((GetWindowLongA(edit, GWL_STYLE) & ES_MULTILINE) == 0, "edit is multiline\n");
492
493 return TRUE;
494 }
495 case LVN_BEGINSCROLL:
496 case LVN_ENDSCROLL:
497 {
498 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
499
500 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
501 "BEGIN" : "END", pScroll->dx, pScroll->dy);
502 }
503 break;
504 case LVN_ITEMCHANGING:
505 {
506 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
507 g_nmlistview_changing = *nmlv;
508 }
509 break;
510 case LVN_ITEMCHANGED:
511 {
512 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
513 g_nmlistview = *nmlv;
514 }
515 break;
516 case LVN_GETDISPINFOA:
517 {
518 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
519 g_itema = dispinfo->item;
520
521 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
522 {
523 static const WCHAR testW[] = {'T','E','S','T',0};
524 dispinfo->hdr.code = LVN_GETDISPINFOW;
525 memcpy(dispinfo->item.pszText, testW, sizeof(testW));
526 }
527
528 /* test control buffer size for text, 10 used to mask cases when control
529 is using caller buffer to process LVM_GETITEM for example */
530 if (dispinfo->item.mask & LVIF_TEXT && dispinfo->item.cchTextMax > 10)
531 ok(dispinfo->item.cchTextMax == 260 ||
532 broken(dispinfo->item.cchTextMax == 264) /* NT4 reports aligned size */,
533 "buffer size %d\n", dispinfo->item.cchTextMax);
534 }
535 break;
536 case LVN_DELETEITEM:
537 if (g_focus_test_LVN_DELETEITEM)
538 {
539 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
540 UINT state;
541
542 state = SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETITEMSTATE, nmlv->iItem, LVIS_FOCUSED);
543 ok(state == 0, "got state %x\n", state);
544 }
545 break;
546 case NM_HOVER:
547 if (g_block_hover) return 1;
548 break;
549 }
550 break;
551 }
552 case WM_NOTIFYFORMAT:
553 {
554 /* force to return format */
555 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
556 break;
557 }
558 }
559
560 defwndproc_counter++;
561 if (IsWindowUnicode(hwnd))
562 ret = DefWindowProcW(hwnd, message, wParam, lParam);
563 else
564 ret = DefWindowProcA(hwnd, message, wParam, lParam);
565 defwndproc_counter--;
566
567 return ret;
568 }
569
570 static BOOL register_parent_wnd_class(BOOL Unicode)
571 {
572 WNDCLASSA clsA;
573 WNDCLASSW clsW;
574
575 if (Unicode)
576 {
577 clsW.style = 0;
578 clsW.lpfnWndProc = parent_wnd_proc;
579 clsW.cbClsExtra = 0;
580 clsW.cbWndExtra = 0;
581 clsW.hInstance = GetModuleHandleW(NULL);
582 clsW.hIcon = 0;
583 clsW.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
584 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
585 clsW.lpszMenuName = NULL;
586 clsW.lpszClassName = testparentclassW;
587 }
588 else
589 {
590 clsA.style = 0;
591 clsA.lpfnWndProc = parent_wnd_proc;
592 clsA.cbClsExtra = 0;
593 clsA.cbWndExtra = 0;
594 clsA.hInstance = GetModuleHandleA(NULL);
595 clsA.hIcon = 0;
596 clsA.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
597 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
598 clsA.lpszMenuName = NULL;
599 clsA.lpszClassName = "Listview test parent class";
600 }
601
602 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
603 }
604
605 static HWND create_parent_window(BOOL Unicode)
606 {
607 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
608 HWND hwnd;
609
610 if (!register_parent_wnd_class(Unicode))
611 return NULL;
612
613 blockEdit = FALSE;
614 notifyFormat = -1;
615
616 if (Unicode)
617 hwnd = CreateWindowExW(0, testparentclassW, nameW,
618 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
619 WS_MAXIMIZEBOX | WS_VISIBLE,
620 0, 0, 100, 100,
621 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
622 else
623 hwnd = CreateWindowExA(0, "Listview test parent class",
624 "Listview test parent window",
625 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
626 WS_MAXIMIZEBOX | WS_VISIBLE,
627 0, 0, 100, 100,
628 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
629 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
630 return hwnd;
631 }
632
633 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
634 {
635 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
636 static LONG defwndproc_counter = 0;
637 LRESULT ret;
638 struct message msg;
639
640 /* some debug output for style changing */
641 if ((message == WM_STYLECHANGING ||
642 message == WM_STYLECHANGED) && lParam)
643 {
644 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
645 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
646 }
647
648 msg.message = message;
649 msg.flags = sent|wparam|lparam;
650 if (defwndproc_counter) msg.flags |= defwinproc;
651 msg.wParam = wParam;
652 msg.lParam = lParam;
653 msg.id = LISTVIEW_ID;
654 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
655 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
656
657 defwndproc_counter++;
658 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
659 defwndproc_counter--;
660 return ret;
661 }
662
663 static HWND create_listview_control(DWORD style)
664 {
665 WNDPROC oldproc;
666 HWND hwnd;
667 RECT rect;
668
669 GetClientRect(hwndparent, &rect);
670 hwnd = CreateWindowExA(0, WC_LISTVIEWA, "foo",
671 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
672 0, 0, rect.right, rect.bottom,
673 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
674 ok(hwnd != NULL, "gle=%d\n", GetLastError());
675
676 if (!hwnd) return NULL;
677
678 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
679 (LONG_PTR)listview_subclass_proc);
680 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
681
682 return hwnd;
683 }
684
685 /* unicode listview window with specified parent */
686 static HWND create_listview_controlW(DWORD style, HWND parent)
687 {
688 WNDPROC oldproc;
689 HWND hwnd;
690 RECT rect;
691 static const WCHAR nameW[] = {'f','o','o',0};
692
693 GetClientRect(parent, &rect);
694 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
695 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
696 0, 0, rect.right, rect.bottom,
697 parent, NULL, GetModuleHandleW(NULL), NULL);
698 ok(hwnd != NULL, "gle=%d\n", GetLastError());
699
700 if (!hwnd) return NULL;
701
702 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
703 (LONG_PTR)listview_subclass_proc);
704 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
705
706 return hwnd;
707 }
708
709 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
710 {
711 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
712 static LONG defwndproc_counter = 0;
713 LRESULT ret;
714 struct message msg;
715
716 msg.message = message;
717 msg.flags = sent|wparam|lparam;
718 if (defwndproc_counter) msg.flags |= defwinproc;
719 msg.wParam = wParam;
720 msg.lParam = lParam;
721 msg.id = HEADER_ID;
722 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
723
724 defwndproc_counter++;
725 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
726 defwndproc_counter--;
727 return ret;
728 }
729
730 static HWND subclass_header(HWND hwndListview)
731 {
732 WNDPROC oldproc;
733 HWND hwnd;
734
735 hwnd = (HWND)SendMessageA(hwndListview, LVM_GETHEADER, 0, 0);
736 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
737 (LONG_PTR)header_subclass_proc);
738 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
739
740 return hwnd;
741 }
742
743 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
744 {
745 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
746 static LONG defwndproc_counter = 0;
747 LRESULT ret;
748 struct message msg;
749
750 msg.message = message;
751 msg.flags = sent|wparam|lparam;
752 if (defwndproc_counter) msg.flags |= defwinproc;
753 msg.wParam = wParam;
754 msg.lParam = lParam;
755 msg.id = 0;
756
757 /* all we need is sizing */
758 if (message == WM_WINDOWPOSCHANGING ||
759 message == WM_NCCALCSIZE ||
760 message == WM_WINDOWPOSCHANGED ||
761 message == WM_MOVE ||
762 message == WM_SIZE)
763 {
764 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
765 }
766
767 defwndproc_counter++;
768 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
769 defwndproc_counter--;
770 return ret;
771 }
772
773 static HWND subclass_editbox(HWND hwndListview)
774 {
775 WNDPROC oldproc;
776 HWND hwnd;
777
778 hwnd = (HWND)SendMessageA(hwndListview, LVM_GETEDITCONTROL, 0, 0);
779 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
780 (LONG_PTR)editbox_subclass_proc);
781 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
782
783 return hwnd;
784 }
785
786 /* Performs a single LVM_HITTEST test */
787 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
788 BOOL todo_item, BOOL todo_flags, int line)
789 {
790 LVHITTESTINFO lpht;
791 INT ret;
792
793 lpht.pt.x = x;
794 lpht.pt.y = y;
795 lpht.iSubItem = 10;
796
797 ret = SendMessageA(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
798
799 todo_wine_if(todo_item)
800 {
801 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
802 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
803 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
804 }
805
806 if (todo_flags)
807 {
808 todo_wine
809 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
810 }
811 else if (broken_flags)
812 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
813 "Expected flags %x, got %x\n", flags, lpht.flags);
814 else
815 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
816 }
817
818 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
819
820 /* Performs a single LVM_SUBITEMHITTEST test */
821 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
822 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
823 {
824 LVHITTESTINFO lpht;
825 INT ret;
826
827 lpht.pt.x = x;
828 lpht.pt.y = y;
829
830 ret = SendMessageA(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
831
832 todo_wine_if(todo_item)
833 {
834 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
835 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
836 }
837
838 todo_wine_if(todo_subitem)
839 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
840
841 todo_wine_if(todo_flags)
842 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
843 }
844
845 #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__)
846
847 static void test_images(void)
848 {
849 HWND hwnd;
850 INT r;
851 LVITEMA item;
852 HIMAGELIST himl;
853 HBITMAP hbmp;
854 RECT r1, r2;
855 static CHAR hello[] = "hello";
856
857 himl = ImageList_Create(40, 40, 0, 4, 4);
858 ok(himl != NULL, "failed to create imagelist\n");
859
860 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
861 ok(hbmp != NULL, "failed to create bitmap\n");
862
863 r = ImageList_Add(himl, hbmp, 0);
864 ok(r == 0, "should be zero\n");
865
866 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
867 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
868 ok(hwnd != NULL, "failed to create listview window\n");
869
870 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
871 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
872
873 ok(r == 0, "should return zero\n");
874
875 r = SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
876 ok(r == 0, "should return zero\n");
877
878 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
879 ok(r != 0, "got 0\n");
880
881 /* returns dimensions */
882
883 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
884 ok(r == 0, "should be zero items\n");
885
886 item.mask = LVIF_IMAGE | LVIF_TEXT;
887 item.iItem = 0;
888 item.iSubItem = 1;
889 item.iImage = 0;
890 item.pszText = 0;
891 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
892 ok(r == -1, "should fail\n");
893
894 item.iSubItem = 0;
895 item.pszText = hello;
896 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
897 ok(r == 0, "should not fail\n");
898
899 SetRect(&r1, LVIR_ICON, 0, 0, 0);
900 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
901 expect(1, r);
902
903 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
904 ok(r == TRUE, "should not fail\n");
905
906 item.iSubItem = 0;
907 item.pszText = hello;
908 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
909 ok(r == 0, "should not fail\n");
910
911 SetRect(&r2, LVIR_ICON, 0, 0, 0);
912 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
913 expect(1, r);
914
915 ok(EqualRect(&r1, &r2), "rectangle should be the same\n");
916
917 DestroyWindow(hwnd);
918 }
919
920 static void test_checkboxes(void)
921 {
922 HWND hwnd;
923 LVITEMA item;
924 DWORD r;
925 static CHAR text[] = "Text",
926 text2[] = "Text2",
927 text3[] = "Text3";
928
929 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
930 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
931 ok(hwnd != NULL, "failed to create listview window\n");
932
933 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
934 item.mask = LVIF_TEXT | LVIF_STATE;
935 item.stateMask = 0xffff;
936 item.state = 0xfccc;
937 item.iItem = 0;
938 item.iSubItem = 0;
939 item.pszText = text;
940 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
941 expect(0, r);
942
943 item.iItem = 0;
944 item.mask = LVIF_STATE;
945 item.stateMask = 0xffff;
946 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
947 expect(1, r);
948 ok(item.state == 0xfccc, "state %x\n", item.state);
949
950 /* Don't set LVIF_STATE */
951 item.mask = LVIF_TEXT;
952 item.stateMask = 0xffff;
953 item.state = 0xfccc;
954 item.iItem = 1;
955 item.iSubItem = 0;
956 item.pszText = text;
957 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
958 expect(1, r);
959
960 item.iItem = 1;
961 item.mask = LVIF_STATE;
962 item.stateMask = 0xffff;
963 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
964 expect(1, r);
965 ok(item.state == 0, "state %x\n", item.state);
966
967 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
968 expect(0, r);
969
970 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
971 item.iItem = 0;
972 item.mask = LVIF_STATE;
973 item.stateMask = 0xffff;
974 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
975 expect(1, r);
976 if (item.state != 0x1ccc)
977 {
978 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
979 DestroyWindow(hwnd);
980 return;
981 }
982
983 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
984 item.iItem = 2;
985 item.mask = LVIF_TEXT;
986 item.state = 0;
987 item.pszText = text2;
988 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
989 expect(2, r);
990
991 item.iItem = 2;
992 item.mask = LVIF_STATE;
993 item.stateMask = 0xffff;
994 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
995 expect(1, r);
996 ok(item.state == 0x1000, "state %x\n", item.state);
997
998 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
999 item.iItem = 3;
1000 item.mask = LVIF_TEXT | LVIF_STATE;
1001 item.stateMask = 0xffff;
1002 item.state = 0x2aaa;
1003 item.pszText = text3;
1004 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1005 expect(3, r);
1006
1007 item.iItem = 3;
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 == 0x1aaa, "state %x\n", item.state);
1013
1014 /* Set an item's state to checked */
1015 item.iItem = 3;
1016 item.mask = LVIF_STATE;
1017 item.stateMask = 0xf000;
1018 item.state = 0x2000;
1019 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1020 expect(1, r);
1021
1022 item.iItem = 3;
1023 item.mask = LVIF_STATE;
1024 item.stateMask = 0xffff;
1025 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1026 expect(1, r);
1027 ok(item.state == 0x2aaa, "state %x\n", item.state);
1028
1029 /* Check that only the bits we asked for are returned,
1030 * and that all the others are set to zero
1031 */
1032 item.iItem = 3;
1033 item.mask = LVIF_STATE;
1034 item.stateMask = 0xf000;
1035 item.state = 0xffff;
1036 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1037 expect(1, r);
1038 ok(item.state == 0x2000, "state %x\n", item.state);
1039
1040 /* Set the style again and check that doesn't change an item's state */
1041 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1042 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1043
1044 item.iItem = 3;
1045 item.mask = LVIF_STATE;
1046 item.stateMask = 0xffff;
1047 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1048 expect(1, r);
1049 ok(item.state == 0x2aaa, "state %x\n", item.state);
1050
1051 /* Unsetting the checkbox extended style doesn't change an item's state */
1052 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
1053 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1054
1055 item.iItem = 3;
1056 item.mask = LVIF_STATE;
1057 item.stateMask = 0xffff;
1058 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1059 expect(1, r);
1060 ok(item.state == 0x2aaa, "state %x\n", item.state);
1061
1062 /* Now setting the style again will change an item's state */
1063 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1064 expect(0, r);
1065
1066 item.iItem = 3;
1067 item.mask = LVIF_STATE;
1068 item.stateMask = 0xffff;
1069 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1070 expect(1, r);
1071 ok(item.state == 0x1aaa, "state %x\n", item.state);
1072
1073 /* Toggle checkbox tests (bug 9934) */
1074 memset (&item, 0xcc, sizeof(item));
1075 item.mask = LVIF_STATE;
1076 item.iItem = 3;
1077 item.iSubItem = 0;
1078 item.state = LVIS_FOCUSED;
1079 item.stateMask = LVIS_FOCUSED;
1080 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1081 expect(1, r);
1082
1083 item.iItem = 3;
1084 item.mask = LVIF_STATE;
1085 item.stateMask = 0xffff;
1086 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1087 expect(1, r);
1088 ok(item.state == 0x1aab, "state %x\n", item.state);
1089
1090 r = SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1091 expect(0, r);
1092 r = SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
1093 expect(0, r);
1094
1095 item.iItem = 3;
1096 item.mask = LVIF_STATE;
1097 item.stateMask = 0xffff;
1098 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1099 expect(1, r);
1100 ok(item.state == 0x2aab, "state %x\n", item.state);
1101
1102 r = SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1103 expect(0, r);
1104 r = SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
1105 expect(0, r);
1106
1107 item.iItem = 3;
1108 item.mask = LVIF_STATE;
1109 item.stateMask = 0xffff;
1110 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1111 expect(1, r);
1112 ok(item.state == 0x1aab, "state %x\n", item.state);
1113
1114 DestroyWindow(hwnd);
1115 }
1116
1117 static void insert_column(HWND hwnd, int idx)
1118 {
1119 LVCOLUMNA column;
1120 INT rc;
1121
1122 memset(&column, 0xcc, sizeof(column));
1123 column.mask = LVCF_SUBITEM;
1124 column.iSubItem = idx;
1125
1126 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, idx, (LPARAM)&column);
1127 expect(idx, rc);
1128 }
1129
1130 static void insert_item(HWND hwnd, int idx)
1131 {
1132 static CHAR text[] = "foo";
1133
1134 LVITEMA item;
1135 INT rc;
1136
1137 memset(&item, 0xcc, sizeof (item));
1138 item.mask = LVIF_TEXT;
1139 item.iItem = idx;
1140 item.iSubItem = 0;
1141 item.pszText = text;
1142
1143 rc = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
1144 expect(idx, rc);
1145 }
1146
1147 static void test_items(void)
1148 {
1149 const LPARAM lparamTest = 0x42;
1150 static CHAR text[] = "Text";
1151 char buffA[5];
1152 HWND hwnd;
1153 LVITEMA item;
1154 DWORD r;
1155
1156 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1157 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1158 ok(hwnd != NULL, "failed to create listview window\n");
1159
1160 /*
1161 * Test setting/getting item params
1162 */
1163
1164 /* Set up two columns */
1165 insert_column(hwnd, 0);
1166 insert_column(hwnd, 1);
1167
1168 /* LVIS_SELECTED with zero stateMask */
1169 /* set */
1170 memset (&item, 0, sizeof (item));
1171 item.mask = LVIF_STATE;
1172 item.state = LVIS_SELECTED;
1173 item.stateMask = 0;
1174 item.iItem = 0;
1175 item.iSubItem = 0;
1176 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1177 expect(0, r);
1178 /* get */
1179 memset (&item, 0xcc, sizeof (item));
1180 item.mask = LVIF_STATE;
1181 item.stateMask = LVIS_SELECTED;
1182 item.state = 0;
1183 item.iItem = 0;
1184 item.iSubItem = 0;
1185 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1186 expect(1, r);
1187 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1188 r = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1189 ok(r, "got %d\n", r);
1190
1191 /* LVIS_SELECTED with zero stateMask */
1192 /* set */
1193 memset (&item, 0, sizeof (item));
1194 item.mask = LVIF_STATE;
1195 item.state = LVIS_FOCUSED;
1196 item.stateMask = 0;
1197 item.iItem = 0;
1198 item.iSubItem = 0;
1199 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1200 expect(0, r);
1201 /* get */
1202 memset (&item, 0xcc, sizeof (item));
1203 item.mask = LVIF_STATE;
1204 item.stateMask = LVIS_FOCUSED;
1205 item.state = 0;
1206 item.iItem = 0;
1207 item.iSubItem = 0;
1208 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1209 expect(1, r);
1210 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1211 r = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1212 ok(r, "got %d\n", r);
1213
1214 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1215 /* set */
1216 memset (&item, 0, sizeof (item));
1217 item.mask = LVIF_STATE;
1218 item.state = LVIS_CUT;
1219 item.stateMask = LVIS_FOCUSED;
1220 item.iItem = 0;
1221 item.iSubItem = 0;
1222 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1223 expect(0, r);
1224 /* get */
1225 memset (&item, 0xcc, sizeof (item));
1226 item.mask = LVIF_STATE;
1227 item.stateMask = LVIS_CUT;
1228 item.state = 0;
1229 item.iItem = 0;
1230 item.iSubItem = 0;
1231 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1232 expect(1, r);
1233 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1234 r = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1235 ok(r, "got %d\n", r);
1236
1237 /* Insert an item with just a param */
1238 memset (&item, 0xcc, sizeof (item));
1239 item.mask = LVIF_PARAM;
1240 item.iItem = 0;
1241 item.iSubItem = 0;
1242 item.lParam = lparamTest;
1243 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1244 expect(0, r);
1245
1246 /* Test getting of the param */
1247 memset (&item, 0xcc, sizeof (item));
1248 item.mask = LVIF_PARAM;
1249 item.iItem = 0;
1250 item.iSubItem = 0;
1251 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1252 expect(1, r);
1253 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1254
1255 /* Set up a subitem */
1256 memset (&item, 0xcc, sizeof (item));
1257 item.mask = LVIF_TEXT;
1258 item.iItem = 0;
1259 item.iSubItem = 1;
1260 item.pszText = text;
1261 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1262 expect(1, r);
1263
1264 item.mask = LVIF_TEXT;
1265 item.iItem = 0;
1266 item.iSubItem = 1;
1267 item.pszText = buffA;
1268 item.cchTextMax = sizeof(buffA);
1269 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1270 expect(1, r);
1271 ok(!memcmp(item.pszText, text, sizeof(text)), "got text %s, expected %s\n", item.pszText, text);
1272
1273 /* set up with extra flag */
1274 /* 1. reset subitem text */
1275 item.mask = LVIF_TEXT;
1276 item.iItem = 0;
1277 item.iSubItem = 1;
1278 item.pszText = NULL;
1279 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1280 expect(1, r);
1281
1282 item.mask = LVIF_TEXT;
1283 item.iItem = 0;
1284 item.iSubItem = 1;
1285 item.pszText = buffA;
1286 buffA[0] = 'a';
1287 item.cchTextMax = sizeof(buffA);
1288 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1289 expect(1, r);
1290 ok(item.pszText[0] == 0, "got %p\n", item.pszText);
1291
1292 /* 2. set new text with extra flag specified */
1293 item.mask = LVIF_TEXT | LVIF_DI_SETITEM;
1294 item.iItem = 0;
1295 item.iSubItem = 1;
1296 item.pszText = text;
1297 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1298 ok(r == 1 || broken(r == 0) /* NT4 */, "ret %d\n", r);
1299
1300 if (r == 1)
1301 {
1302 item.mask = LVIF_TEXT;
1303 item.iItem = 0;
1304 item.iSubItem = 1;
1305 item.pszText = buffA;
1306 buffA[0] = 'a';
1307 item.cchTextMax = sizeof(buffA);
1308 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1309 expect(1, r);
1310 ok(!memcmp(item.pszText, text, sizeof(text)), "got %s, expected %s\n", item.pszText, text);
1311 }
1312
1313 /* Query param from subitem: returns main item param */
1314 memset (&item, 0xcc, sizeof (item));
1315 item.mask = LVIF_PARAM;
1316 item.iItem = 0;
1317 item.iSubItem = 1;
1318 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1319 expect(1, r);
1320 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1321
1322 /* Set up param on first subitem: no effect */
1323 memset (&item, 0xcc, sizeof (item));
1324 item.mask = LVIF_PARAM;
1325 item.iItem = 0;
1326 item.iSubItem = 1;
1327 item.lParam = lparamTest+1;
1328 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1329 expect(0, r);
1330
1331 /* Query param from subitem again: should still return main item param */
1332 memset (&item, 0xcc, sizeof (item));
1333 item.mask = LVIF_PARAM;
1334 item.iItem = 0;
1335 item.iSubItem = 1;
1336 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1337 expect(1, r);
1338 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1339
1340 /**** Some tests of state highlighting ****/
1341 memset (&item, 0xcc, sizeof (item));
1342 item.mask = LVIF_STATE;
1343 item.iItem = 0;
1344 item.iSubItem = 0;
1345 item.state = LVIS_SELECTED;
1346 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1347 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1348 expect(1, r);
1349 item.iSubItem = 1;
1350 item.state = LVIS_DROPHILITED;
1351 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1352 expect(1, r);
1353
1354 memset (&item, 0xcc, sizeof (item));
1355 item.mask = LVIF_STATE;
1356 item.iItem = 0;
1357 item.iSubItem = 0;
1358 item.stateMask = -1;
1359 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1360 expect(1, r);
1361 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1362 item.iSubItem = 1;
1363 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1364 expect(1, r);
1365 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1366
1367 /* some notnull but meaningless masks */
1368 memset (&item, 0, sizeof(item));
1369 item.mask = LVIF_NORECOMPUTE;
1370 item.iItem = 0;
1371 item.iSubItem = 0;
1372 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1373 expect(1, r);
1374 memset (&item, 0, sizeof(item));
1375 item.mask = LVIF_DI_SETITEM;
1376 item.iItem = 0;
1377 item.iSubItem = 0;
1378 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1379 expect(1, r);
1380
1381 /* set text to callback value already having it */
1382 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
1383 expect(TRUE, r);
1384 memset (&item, 0, sizeof (item));
1385 item.mask = LVIF_TEXT;
1386 item.pszText = LPSTR_TEXTCALLBACKA;
1387 item.iItem = 0;
1388 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1389 expect(0, r);
1390 memset (&item, 0, sizeof (item));
1391
1392 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1393
1394 item.pszText = LPSTR_TEXTCALLBACKA;
1395 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0 , (LPARAM) &item);
1396 expect(TRUE, r);
1397
1398 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1399 "check callback text comparison rule", FALSE);
1400
1401 DestroyWindow(hwnd);
1402 }
1403
1404 static void test_columns(void)
1405 {
1406 HWND hwnd, header;
1407 LVCOLUMNA column;
1408 LVITEMA item;
1409 INT order[2];
1410 CHAR buff[5];
1411 DWORD rc;
1412
1413 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_LIST,
1414 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1415 ok(hwnd != NULL, "failed to create listview window\n");
1416
1417 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
1418 ok(header == NULL, "got %p\n", header);
1419
1420 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1421 ok(rc == 0, "got %d\n", rc);
1422
1423 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
1424 ok(header == NULL, "got %p\n", header);
1425
1426 DestroyWindow(hwnd);
1427
1428 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1429 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1430 ok(hwnd != NULL, "failed to create listview window\n");
1431
1432 rc = SendMessageA(hwnd, LVM_DELETECOLUMN, -1, 0);
1433 ok(!rc, "got %d\n", rc);
1434
1435 rc = SendMessageA(hwnd, LVM_DELETECOLUMN, 0, 0);
1436 ok(!rc, "got %d\n", rc);
1437
1438 /* Add a column with no mask */
1439 memset(&column, 0xcc, sizeof(column));
1440 column.mask = 0;
1441 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1442 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1443
1444 /* Check its width */
1445 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1446 ok(rc == 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1447
1448 DestroyWindow(hwnd);
1449
1450 /* LVM_GETCOLUMNORDERARRAY */
1451 hwnd = create_listview_control(LVS_REPORT);
1452 subclass_header(hwnd);
1453
1454 memset(&column, 0, sizeof(column));
1455 column.mask = LVCF_WIDTH;
1456 column.cx = 100;
1457 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1458 expect(0, rc);
1459
1460 column.cx = 200;
1461 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1462 expect(1, rc);
1463
1464 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1465
1466 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1467 expect(1, rc);
1468 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1469 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1470
1471 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 0, 0);
1472 expect(0, rc);
1473
1474 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1475
1476 /* LVM_SETCOLUMNORDERARRAY */
1477 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1478
1479 order[0] = 0;
1480 order[1] = 1;
1481 rc = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1482 expect(1, rc);
1483
1484 rc = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 0, 0);
1485 expect(0, rc);
1486
1487 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_setorderarray_seq, "set order array", FALSE);
1488
1489 /* after column added subitem is considered as present */
1490 insert_item(hwnd, 0);
1491
1492 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1493
1494 item.pszText = buff;
1495 item.cchTextMax = sizeof(buff);
1496 item.iItem = 0;
1497 item.iSubItem = 1;
1498 item.mask = LVIF_TEXT;
1499 memset(&g_itema, 0, sizeof(g_itema));
1500 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1501 expect(1, rc);
1502 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1503
1504 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1505 "get subitem text after column added", FALSE);
1506
1507 DestroyWindow(hwnd);
1508 }
1509
1510 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1511 static WNDPROC listviewWndProc;
1512 static HIMAGELIST test_create_imagelist;
1513
1514 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1515 {
1516 LRESULT ret;
1517
1518 if (uMsg == WM_CREATE)
1519 {
1520 CREATESTRUCTA *lpcs = (CREATESTRUCTA*)lParam;
1521 lpcs->style |= LVS_REPORT;
1522 }
1523 ret = CallWindowProcA(listviewWndProc, hwnd, uMsg, wParam, lParam);
1524 if (uMsg == WM_CREATE) SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1525 return ret;
1526 }
1527
1528 static void test_create(void)
1529 {
1530 HWND hList;
1531 HWND hHeader;
1532 LONG_PTR ret;
1533 LONG r;
1534 LVCOLUMNA col;
1535 RECT rect;
1536 WNDCLASSEXA cls;
1537 DWORD style;
1538
1539 cls.cbSize = sizeof(WNDCLASSEXA);
1540 ok(GetClassInfoExA(GetModuleHandleA(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1541 listviewWndProc = cls.lpfnWndProc;
1542 cls.lpfnWndProc = create_test_wndproc;
1543 cls.lpszClassName = "MyListView32";
1544 ok(RegisterClassExA(&cls), "RegisterClassEx failed\n");
1545
1546 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1547 hList = CreateWindowA("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1548 ok((HIMAGELIST)SendMessageA(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1549 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1550
1551 if (!IsWindow(hHeader))
1552 {
1553 /* version 4.0 */
1554 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1555 DestroyWindow(hList);
1556 return;
1557 }
1558
1559 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1560 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1561 DestroyWindow(hList);
1562
1563 /* header isn't created on LVS_ICON and LVS_LIST styles */
1564 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1565 GetModuleHandleA(NULL), 0);
1566 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1567 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1568 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1569 /* insert column */
1570 memset(&col, 0, sizeof(LVCOLUMNA));
1571 col.mask = LVCF_WIDTH;
1572 col.cx = 100;
1573 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1574 expect(0, r);
1575 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1576 ok(IsWindow(hHeader), "Header should be created\n");
1577 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1578 style = GetWindowLongA(hHeader, GWL_STYLE);
1579 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1580 DestroyWindow(hList);
1581
1582 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1583 GetModuleHandleA(NULL), 0);
1584 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1585 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1586 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1587 /* insert column */
1588 memset(&col, 0, sizeof(LVCOLUMNA));
1589 col.mask = LVCF_WIDTH;
1590 col.cx = 100;
1591 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1592 expect(0, r);
1593 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1594 ok(IsWindow(hHeader), "Header should be created\n");
1595 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1596 DestroyWindow(hList);
1597
1598 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1599 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1600 GetModuleHandleA(NULL), 0);
1601 ret = SetWindowLongPtrA(hList, GWL_STYLE, GetWindowLongPtrA(hList, GWL_STYLE) | LVS_REPORT);
1602 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1603 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1604 ok(IsWindow(hHeader), "Header should be created\n");
1605 ret = SetWindowLongPtrA(hList, GWL_STYLE, GetWindowLongA(hList, GWL_STYLE) & ~LVS_REPORT);
1606 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1607 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1608 ok(IsWindow(hHeader), "Header should be created\n");
1609 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1610 DestroyWindow(hList);
1611
1612 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1613 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1614 GetModuleHandleA(NULL), 0);
1615 ret = SetWindowLongPtrA(hList, GWL_STYLE,
1616 (GetWindowLongPtrA(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1617 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1618 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1619 ok(IsWindow(hHeader), "Header should be created\n");
1620 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1621 ret = SetWindowLongPtrA(hList, GWL_STYLE,
1622 (GetWindowLongPtrA(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1623 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1624 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1625 ok(IsWindow(hHeader), "Header should be created\n");
1626 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1627 DestroyWindow(hList);
1628
1629 /* LVS_REPORT without WS_VISIBLE */
1630 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1631 GetModuleHandleA(NULL), 0);
1632 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1633 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1634 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1635 /* insert column */
1636 memset(&col, 0, sizeof(LVCOLUMNA));
1637 col.mask = LVCF_WIDTH;
1638 col.cx = 100;
1639 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1640 expect(0, r);
1641 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1642 ok(IsWindow(hHeader), "Header should be created\n");
1643 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1644 DestroyWindow(hList);
1645
1646 /* LVS_REPORT without WS_VISIBLE, try to show it */
1647 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1648 GetModuleHandleA(NULL), 0);
1649 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1650 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1651 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1652 ShowWindow(hList, SW_SHOW);
1653 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1654 ok(IsWindow(hHeader), "Header should be created\n");
1655 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1656 DestroyWindow(hList);
1657
1658 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1659 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1660 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1661 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1662 ok(IsWindow(hHeader), "Header should be created\n");
1663 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1664 /* HDS_DRAGDROP set by default */
1665 ok(GetWindowLongPtrA(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1666 DestroyWindow(hList);
1667
1668 /* setting LVS_EX_HEADERDRAGDROP creates header */
1669 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1670 GetModuleHandleA(NULL), 0);
1671 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1672 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1673 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1674 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1675 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1676 ok(IsWindow(hHeader) ||
1677 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1678 "Header should be created\n");
1679 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1680 DestroyWindow(hList);
1681
1682 /* setting LVS_EX_GRIDLINES creates header */
1683 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1684 GetModuleHandleA(NULL), 0);
1685 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1686 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1687 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1688 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_GRIDLINES);
1689 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1690 ok(IsWindow(hHeader) ||
1691 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1692 "Header should be created\n");
1693 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1694 DestroyWindow(hList);
1695
1696 /* setting LVS_EX_FULLROWSELECT creates header */
1697 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1698 GetModuleHandleA(NULL), 0);
1699 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1700 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1701 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1702 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
1703 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1704 ok(IsWindow(hHeader) ||
1705 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1706 "Header should be created\n");
1707 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1708 DestroyWindow(hList);
1709
1710 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1711 hList = create_listview_control(LVS_ICON);
1712 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1713 r = SendMessageA(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1714 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1715 DestroyWindow(hList);
1716
1717 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1718 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1719 GetModuleHandleA(NULL), 0);
1720 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1721 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1722
1723 SetRect(&rect, LVIR_BOUNDS, 1, -10, -10);
1724 r = SendMessageA(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1725 /* right value contains garbage, probably because header columns are not set up */
1726 expect(0, rect.bottom);
1727 expect(1, r);
1728
1729 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1730 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1731 ok(GetDlgItem(hList, 0) == NULL, "NULL dialog item expected\n");
1732
1733 DestroyWindow(hList);
1734
1735 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1736 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1737 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1738 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1739 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1740 DestroyWindow(hList);
1741 }
1742
1743 static void test_redraw(void)
1744 {
1745 HWND hwnd;
1746 HDC hdc;
1747 BOOL res;
1748 DWORD r;
1749
1750 hwnd = create_listview_control(LVS_REPORT);
1751 subclass_header(hwnd);
1752
1753 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1754
1755 InvalidateRect(hwnd, NULL, TRUE);
1756 UpdateWindow(hwnd);
1757 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1758
1759 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1760
1761 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1762 /* 1. Without backbuffer */
1763 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
1764 expect(TRUE, res);
1765
1766 hdc = GetWindowDC(hwndparent);
1767
1768 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1769 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1770 ok(r == 1, "Expected not zero result\n");
1771 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1772 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1773
1774 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_DEFAULT);
1775 expect(TRUE, res);
1776
1777 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1778 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1779 expect(1, r);
1780 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1781 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1782
1783 /* 2. With backbuffer */
1784 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1785 LVS_EX_DOUBLEBUFFER);
1786 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
1787 expect(TRUE, res);
1788
1789 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1790 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1791 expect(1, r);
1792 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1793 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1794
1795 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_DEFAULT);
1796 expect(TRUE, res);
1797
1798 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1799 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1800 todo_wine expect(1, r);
1801 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1802 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1803
1804 ReleaseDC(hwndparent, hdc);
1805
1806 DestroyWindow(hwnd);
1807 }
1808
1809 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1810 {
1811 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1812
1813 if(message == WM_NOTIFY) {
1814 NMHDR *nmhdr = (NMHDR*)lParam;
1815 if(nmhdr->code == NM_CUSTOMDRAW) {
1816 NMLVCUSTOMDRAW *nmlvcd = (NMLVCUSTOMDRAW*)nmhdr;
1817 struct message msg;
1818
1819 msg.message = message;
1820 msg.flags = sent|wparam|lparam|custdraw;
1821 msg.wParam = wParam;
1822 msg.lParam = lParam;
1823 msg.id = nmhdr->code;
1824 msg.stage = nmlvcd->nmcd.dwDrawStage;
1825 add_message(sequences, PARENT_CD_SEQ_INDEX, &msg);
1826
1827 switch(nmlvcd->nmcd.dwDrawStage) {
1828 case CDDS_PREPAINT:
1829 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1830 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1831 case CDDS_ITEMPREPAINT:
1832 nmlvcd->clrTextBk = CLR_DEFAULT;
1833 nmlvcd->clrText = RGB(0, 255, 0);
1834 return CDRF_NOTIFYSUBITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1835 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1836 clr = GetBkColor(nmlvcd->nmcd.hdc);
1837 ok(nmlvcd->clrTextBk == CLR_DEFAULT, "got 0x%x\n", nmlvcd->clrTextBk);
1838 ok(nmlvcd->clrText == RGB(0, 255, 0), "got 0x%x\n", nmlvcd->clrText);
1839 if (!(GetWindowLongW(nmhdr->hwndFrom, GWL_STYLE) & LVS_SHOWSELALWAYS))
1840 {
1841 todo_wine_if(nmlvcd->iSubItem)
1842 ok(clr == c0ffee, "clr=%.8x\n", clr);
1843 }
1844 return CDRF_NOTIFYPOSTPAINT;
1845 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1846 clr = GetBkColor(nmlvcd->nmcd.hdc);
1847 if (!(GetWindowLongW(nmhdr->hwndFrom, GWL_STYLE) & LVS_SHOWSELALWAYS))
1848 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1849 ok(nmlvcd->clrTextBk == CLR_DEFAULT, "got 0x%x\n", nmlvcd->clrTextBk);
1850 ok(nmlvcd->clrText == RGB(0, 255, 0), "got 0x%x\n", nmlvcd->clrText);
1851 return CDRF_DODEFAULT;
1852 }
1853 return CDRF_DODEFAULT;
1854 }
1855 }
1856
1857 return DefWindowProcA(hwnd, message, wParam, lParam);
1858 }
1859
1860 static void test_customdraw(void)
1861 {
1862 HWND hwnd;
1863 WNDPROC oldwndproc;
1864 LVITEMA item;
1865
1866 hwnd = create_listview_control(LVS_REPORT);
1867
1868 insert_column(hwnd, 0);
1869 insert_column(hwnd, 1);
1870 insert_item(hwnd, 0);
1871
1872 oldwndproc = (WNDPROC)SetWindowLongPtrA(hwndparent, GWLP_WNDPROC,
1873 (LONG_PTR)cd_wndproc);
1874
1875 InvalidateRect(hwnd, NULL, TRUE);
1876 UpdateWindow(hwnd);
1877
1878 /* message tests */
1879 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1880 InvalidateRect(hwnd, NULL, TRUE);
1881 UpdateWindow(hwnd);
1882 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_report_cd_seq, "parent customdraw, LVS_REPORT", FALSE);
1883
1884 /* check colors when item is selected */
1885 SetWindowLongW(hwnd, GWL_STYLE, GetWindowLongW(hwnd, GWL_STYLE) | LVS_SHOWSELALWAYS);
1886 item.mask = LVIF_STATE;
1887 item.stateMask = LVIS_SELECTED;
1888 item.state = LVIS_SELECTED;
1889 SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
1890
1891 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1892 InvalidateRect(hwnd, NULL, TRUE);
1893 UpdateWindow(hwnd);
1894 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_report_cd_seq, "parent customdraw, LVS_REPORT, selection", FALSE);
1895
1896 DestroyWindow(hwnd);
1897
1898 hwnd = create_listview_control(LVS_LIST);
1899
1900 insert_column(hwnd, 0);
1901 insert_column(hwnd, 1);
1902 insert_item(hwnd, 0);
1903
1904 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1905 InvalidateRect(hwnd, NULL, TRUE);
1906 UpdateWindow(hwnd);
1907 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_list_cd_seq, "parent customdraw, LVS_LIST", FALSE);
1908
1909 SetWindowLongPtrA(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1910 DestroyWindow(hwnd);
1911 }
1912
1913 static void test_icon_spacing(void)
1914 {
1915 /* LVM_SETICONSPACING */
1916 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1917
1918 HWND hwnd;
1919 WORD w, h;
1920 INT r;
1921
1922 hwnd = create_listview_control(LVS_ICON);
1923 ok(hwnd != NULL, "failed to create a listview window\n");
1924
1925 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1926 expect(NFR_ANSI, r);
1927
1928 /* reset the icon spacing to defaults */
1929 SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1930
1931 /* now we can request what the defaults are */
1932 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1933 w = LOWORD(r);
1934 h = HIWORD(r);
1935
1936 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1937
1938 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1939 ok(r == MAKELONG(w, h) ||
1940 broken(r == MAKELONG(w, w)), /* win98 */
1941 "Expected %d, got %d\n", MAKELONG(w, h), r);
1942
1943 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1944 if (r == 0)
1945 {
1946 /* version 4.0 */
1947 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1948 DestroyWindow(hwnd);
1949 return;
1950 }
1951 expect(MAKELONG(20,30), r);
1952
1953 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1954 expect(MAKELONG(25,35), r);
1955
1956 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1957
1958 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1959 DestroyWindow(hwnd);
1960 }
1961
1962 static void test_color(void)
1963 {
1964 RECT rect;
1965 HWND hwnd;
1966 DWORD r;
1967 int i;
1968
1969 COLORREF color;
1970 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1971
1972 hwnd = create_listview_control(LVS_REPORT);
1973 ok(hwnd != NULL, "failed to create a listview window\n");
1974
1975 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1976
1977 for (i = 0; i < 4; i++)
1978 {
1979 color = colors[i];
1980
1981 r = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, color);
1982 expect(TRUE, r);
1983 r = SendMessageA(hwnd, LVM_GETBKCOLOR, 0, 0);
1984 expect(color, r);
1985
1986 r = SendMessageA(hwnd, LVM_SETTEXTCOLOR, 0, color);
1987 expect (TRUE, r);
1988 r = SendMessageA(hwnd, LVM_GETTEXTCOLOR, 0, 0);
1989 expect(color, r);
1990
1991 r = SendMessageA(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1992 expect(TRUE, r);
1993 r = SendMessageA(hwnd, LVM_GETTEXTBKCOLOR, 0, 0);
1994 expect(color, r);
1995 }
1996
1997 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1998 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1999
2000 /* invalidation test done separately to avoid a message chain mess */
2001 r = ValidateRect(hwnd, NULL);
2002 expect(TRUE, r);
2003 r = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, colors[0]);
2004 expect(TRUE, r);
2005
2006 rect.right = rect.bottom = 1;
2007 r = GetUpdateRect(hwnd, &rect, TRUE);
2008 todo_wine expect(FALSE, r);
2009 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2010
2011 r = ValidateRect(hwnd, NULL);
2012 expect(TRUE, r);
2013 r = SendMessageA(hwnd, LVM_SETTEXTCOLOR, 0, colors[0]);
2014 expect(TRUE, r);
2015
2016 rect.right = rect.bottom = 1;
2017 r = GetUpdateRect(hwnd, &rect, TRUE);
2018 todo_wine expect(FALSE, r);
2019 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2020
2021 r = ValidateRect(hwnd, NULL);
2022 expect(TRUE, r);
2023 r = SendMessageA(hwnd, LVM_SETTEXTBKCOLOR, 0, colors[0]);
2024 expect(TRUE, r);
2025
2026 rect.right = rect.bottom = 1;
2027 r = GetUpdateRect(hwnd, &rect, TRUE);
2028 todo_wine expect(FALSE, r);
2029 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2030
2031 DestroyWindow(hwnd);
2032 }
2033
2034 static void test_item_count(void)
2035 {
2036 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
2037
2038 HWND hwnd;
2039 DWORD r;
2040 HDC hdc;
2041 HFONT hOldFont;
2042 TEXTMETRICA tm;
2043 RECT rect;
2044 INT height;
2045
2046 LVITEMA item0;
2047 LVITEMA item1;
2048 LVITEMA item2;
2049 static CHAR item0text[] = "item0";
2050 static CHAR item1text[] = "item1";
2051 static CHAR item2text[] = "item2";
2052
2053 hwnd = create_listview_control(LVS_REPORT);
2054 ok(hwnd != NULL, "failed to create a listview window\n");
2055
2056 /* resize in dpiaware manner to fit all 3 items added */
2057 hdc = GetDC(0);
2058 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
2059 GetTextMetricsA(hdc, &tm);
2060 /* 2 extra pixels for bounds and header border */
2061 height = tm.tmHeight + 2;
2062 SelectObject(hdc, hOldFont);
2063 ReleaseDC(0, hdc);
2064
2065 GetWindowRect(hwnd, &rect);
2066 /* 3 items + 1 header + 1 to be sure */
2067 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
2068
2069 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2070
2071 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2072 expect(0, r);
2073
2074 /* [item0] */
2075 item0.mask = LVIF_TEXT;
2076 item0.iItem = 0;
2077 item0.iSubItem = 0;
2078 item0.pszText = item0text;
2079 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item0);
2080 expect(0, r);
2081
2082 /* [item0, item1] */
2083 item1.mask = LVIF_TEXT;
2084 item1.iItem = 1;
2085 item1.iSubItem = 0;
2086 item1.pszText = item1text;
2087 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2088 expect(1, r);
2089
2090 /* [item0, item1, item2] */
2091 item2.mask = LVIF_TEXT;
2092 item2.iItem = 2;
2093 item2.iSubItem = 0;
2094 item2.pszText = item2text;
2095 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2096 expect(2, r);
2097
2098 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2099 expect(3, r);
2100
2101 /* [item0, item1] */
2102 r = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
2103 expect(TRUE, r);
2104
2105 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2106 expect(2, r);
2107
2108 /* [] */
2109 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
2110 expect(TRUE, r);
2111
2112 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2113 expect(0, r);
2114
2115 /* [item0] */
2116 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2117 expect(0, r);
2118
2119 /* [item0, item1] */
2120 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2121 expect(1, r);
2122
2123 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2124 expect(2, r);
2125
2126 /* [item0, item1, item2] */
2127 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2128 expect(2, r);
2129
2130 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2131 expect(3, r);
2132
2133 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
2134
2135 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2136 DestroyWindow(hwnd);
2137 }
2138
2139 static void test_item_position(void)
2140 {
2141 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2142
2143 HWND hwnd;
2144 DWORD r;
2145 POINT position;
2146
2147 LVITEMA item0;
2148 LVITEMA item1;
2149 LVITEMA item2;
2150 static CHAR item0text[] = "item0";
2151 static CHAR item1text[] = "item1";
2152 static CHAR item2text[] = "item2";
2153
2154 hwnd = create_listview_control(LVS_ICON);
2155 ok(hwnd != NULL, "failed to create a listview window\n");
2156
2157 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2158
2159 /* [item0] */
2160 item0.mask = LVIF_TEXT;
2161 item0.iItem = 0;
2162 item0.iSubItem = 0;
2163 item0.pszText = item0text;
2164 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item0);
2165 expect(0, r);
2166
2167 /* [item0, item1] */
2168 item1.mask = LVIF_TEXT;
2169 item1.iItem = 1;
2170 item1.iSubItem = 0;
2171 item1.pszText = item1text;
2172 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2173 expect(1, r);
2174
2175 /* [item0, item1, item2] */
2176 item2.mask = LVIF_TEXT;
2177 item2.iItem = 2;
2178 item2.iSubItem = 0;
2179 item2.pszText = item2text;
2180 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2181 expect(2, r);
2182
2183 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
2184 expect(TRUE, r);
2185 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
2186 expect(TRUE, r);
2187 expect2(10, 5, position.x, position.y);
2188
2189 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
2190 expect(TRUE, r);
2191 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
2192 expect(TRUE, r);
2193 expect2(0, 0, position.x, position.y);
2194
2195 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
2196 expect(TRUE, r);
2197 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
2198 expect(TRUE, r);
2199 expect2(20, 20, position.x, position.y);
2200
2201 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
2202
2203 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2204 DestroyWindow(hwnd);
2205 }
2206
2207 static void test_getorigin(void)
2208 {
2209 /* LVM_GETORIGIN */
2210
2211 HWND hwnd;
2212 DWORD r;
2213 POINT position;
2214
2215 position.x = position.y = 0;
2216
2217 hwnd = create_listview_control(LVS_ICON);
2218 ok(hwnd != NULL, "failed to create a listview window\n");
2219 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2220
2221 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2222 expect(TRUE, r);
2223 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2224 DestroyWindow(hwnd);
2225
2226 hwnd = create_listview_control(LVS_SMALLICON);
2227 ok(hwnd != NULL, "failed to create a listview window\n");
2228 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2229
2230 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2231 expect(TRUE, r);
2232 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2233 DestroyWindow(hwnd);
2234
2235 hwnd = create_listview_control(LVS_LIST);
2236 ok(hwnd != NULL, "failed to create a listview window\n");
2237 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2238
2239 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2240 expect(FALSE, r);
2241 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2242 DestroyWindow(hwnd);
2243
2244 hwnd = create_listview_control(LVS_REPORT);
2245 ok(hwnd != NULL, "failed to create a listview window\n");
2246 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2247
2248 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2249 expect(FALSE, r);
2250 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2251 DestroyWindow(hwnd);
2252 }
2253
2254 static void test_multiselect(void)
2255 {
2256 typedef struct t_select_task
2257 {
2258 const char *descr;
2259 int initPos;
2260 int loopVK;
2261 int count;
2262 int result;
2263 } select_task;
2264
2265 HWND hwnd;
2266 INT r;
2267 int i, j;
2268 static const int items=5;
2269 DWORD item_count;
2270 BYTE kstate[256];
2271 select_task task;
2272 LONG_PTR style;
2273 LVITEMA item;
2274
2275 static struct t_select_task task_list[] = {
2276 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
2277 { "using VK_UP", -1, VK_UP, -1, -1 },
2278 { "using VK_END", 0, VK_END, 1, -1 },
2279 { "using VK_HOME", -1, VK_HOME, 1, -1 }
2280 };
2281
2282 hwnd = create_listview_control(LVS_REPORT);
2283
2284 for (i = 0; i < items; i++)
2285 insert_item(hwnd, 0);
2286
2287 item_count = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2288 expect(items, item_count);
2289
2290 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2291 ok(r == -1, "got %d\n", r);
2292
2293 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, 0);
2294 ok(r == -1, "got %d\n", r);
2295
2296 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, 0);
2297 ok(r == 0, "got %d\n", r);
2298
2299 /* out of range index */
2300 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, items);
2301 ok(r == 0, "got %d\n", r);
2302
2303 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2304 ok(r == 0, "got %d\n", r);
2305
2306 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -2);
2307 ok(r == 0, "got %d\n", r);
2308
2309 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2310 ok(r == 0, "got %d\n", r);
2311
2312 for (i = 0; i < sizeof(task_list)/sizeof(task_list[0]); i++) {
2313 DWORD selected_count;
2314 LVITEMA item;
2315
2316 task = task_list[i];
2317
2318 /* deselect all items */
2319 item.state = 0;
2320 item.stateMask = LVIS_SELECTED;
2321 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2322 ok(r, "got %d\n", r);
2323 SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2324
2325 /* set initial position */
2326 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
2327 ok(r, "got %d\n", r);
2328
2329 item.state = LVIS_SELECTED;
2330 item.stateMask = LVIS_SELECTED;
2331 r = SendMessageA(hwnd, LVM_SETITEMSTATE, task.initPos == -1 ? item_count-1 : task.initPos, (LPARAM)&item);
2332 ok(r, "got %d\n", r);
2333
2334 selected_count = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2335 ok(selected_count == 1, "expected 1, got %d\n", selected_count);
2336
2337 /* Set SHIFT key pressed */
2338 GetKeyboardState(kstate);
2339 kstate[VK_SHIFT]=0x80;
2340 SetKeyboardState(kstate);
2341
2342 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
2343 r = SendMessageA(hwnd, WM_KEYDOWN, task.loopVK, 0);
2344 expect(0,r);
2345 r = SendMessageA(hwnd, WM_KEYUP, task.loopVK, 0);
2346 expect(0,r);
2347 }
2348
2349 selected_count = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2350
2351 ok((task.result == -1 ? item_count : task.result) == selected_count,
2352 "Failed multiple selection %s. There should be %d selected items (is %d)\n",
2353 task.descr, item_count, selected_count);
2354
2355 /* Set SHIFT key released */
2356 GetKeyboardState(kstate);
2357 kstate[VK_SHIFT]=0x00;
2358 SetKeyboardState(kstate);
2359 }
2360 DestroyWindow(hwnd);
2361
2362 /* make multiple selection, then switch to LVS_SINGLESEL */
2363 hwnd = create_listview_control(LVS_REPORT);
2364 for (i=0;i<items;i++) {
2365 insert_item(hwnd, 0);
2366 }
2367 item_count = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2368 expect(items,item_count);
2369
2370 /* try with NULL pointer */
2371 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
2372 expect(FALSE, r);
2373
2374 /* select all, check notifications */
2375 item.state = 0;
2376 item.stateMask = LVIS_SELECTED;
2377 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2378 ok(r, "got %d\n", r);
2379
2380 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2381
2382 item.stateMask = LVIS_SELECTED;
2383 item.state = LVIS_SELECTED;
2384 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2385 expect(TRUE, r);
2386
2387 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2388 "select all notification", FALSE);
2389
2390 /* select all again (all selected already) */
2391 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2392
2393 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2394
2395 item.stateMask = LVIS_SELECTED;
2396 item.state = LVIS_SELECTED;
2397 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2398 expect(TRUE, r);
2399
2400 ok(g_nmlistview_changing.uNewState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uNewState);
2401 ok(g_nmlistview_changing.uOldState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uOldState);
2402 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2403
2404 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2405 "select all notification 2", FALSE);
2406
2407 /* deselect all items */
2408 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2409
2410 item.state = 0;
2411 item.stateMask = LVIS_SELECTED;
2412 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2413 ok(r, "got %d\n", r);
2414
2415 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2416 "deselect all notification", FALSE);
2417
2418 /* deselect all items again */
2419 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2420 item.state = 0;
2421 item.stateMask = LVIS_SELECTED;
2422 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2423 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "deselect all notification 2", FALSE);
2424
2425 /* any non-zero state value does the same */
2426 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2427
2428 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2429
2430 item.stateMask = LVIS_SELECTED;
2431 item.state = LVIS_CUT;
2432 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2433 expect(TRUE, r);
2434
2435 ok(g_nmlistview_changing.uNewState == 0, "got 0x%x\n", g_nmlistview_changing.uNewState);
2436 ok(g_nmlistview_changing.uOldState == 0, "got 0x%x\n", g_nmlistview_changing.uOldState);
2437 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2438
2439 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2440 "set state all notification 3", FALSE);
2441
2442 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2443 ok(r, "got %d\n", r);
2444 for (i = 0; i < 3; i++) {
2445 item.state = LVIS_SELECTED;
2446 item.stateMask = LVIS_SELECTED;
2447 r = SendMessageA(hwnd, LVM_SETITEMSTATE, i, (LPARAM)&item);
2448 ok(r, "got %d\n", r);
2449 }
2450
2451 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2452 expect(3, r);
2453 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2454 expect(-1, r);
2455
2456 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2457 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2458 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2459 /* check that style is accepted */
2460 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2461 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2462
2463 for (i=0;i<3;i++) {
2464 r = SendMessageA(hwnd, LVM_GETITEMSTATE, i, LVIS_SELECTED);
2465 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2466 }
2467 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2468 expect(3, r);
2469 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2470 ok(r == -1, "got %d\n", r);
2471
2472 /* select one more */
2473 item.state = LVIS_SELECTED;
2474 item.stateMask = LVIS_SELECTED;
2475 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
2476 ok(r, "got %d\n", r);
2477
2478 for (i=0;i<3;i++) {
2479 r = SendMessageA(hwnd, LVM_GETITEMSTATE, i, LVIS_SELECTED);
2480 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2481 }
2482
2483 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 3, LVIS_SELECTED);
2484 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2485
2486 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2487 expect(1, r);
2488 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2489 expect(-1, r);
2490
2491 /* try to select all on LVS_SINGLESEL */
2492 memset(&item, 0, sizeof(item));
2493 item.stateMask = LVIS_SELECTED;
2494 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2495 expect(TRUE, r);
2496 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2497 ok(r == -1, "got %d\n", r);
2498
2499 item.stateMask = LVIS_SELECTED;
2500 item.state = LVIS_SELECTED;
2501 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2502 expect(FALSE, r);
2503
2504 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2505 expect(0, r);
2506 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2507 expect(-1, r);
2508
2509 /* try to deselect all on LVS_SINGLESEL */
2510 item.stateMask = LVIS_SELECTED;
2511 item.state = LVIS_SELECTED;
2512 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2513 expect(TRUE, r);
2514
2515 item.stateMask = LVIS_SELECTED;
2516 item.state = 0;
2517 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2518 expect(TRUE, r);
2519 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2520 expect(0, r);
2521
2522 /* 1. selection mark is update when new focused item is set */
2523 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2524 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2525
2526 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2527 expect(-1, r);
2528
2529 item.stateMask = LVIS_FOCUSED;
2530 item.state = LVIS_FOCUSED;
2531 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2532 expect(TRUE, r);
2533
2534 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2535 expect(0, r);
2536
2537 /* it's not updated if already set */
2538 item.stateMask = LVIS_FOCUSED;
2539 item.state = LVIS_FOCUSED;
2540 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2541 expect(TRUE, r);
2542
2543 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2544 expect(0, r);
2545
2546 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2547 expect(0, r);
2548
2549 item.stateMask = LVIS_FOCUSED;
2550 item.state = LVIS_FOCUSED;
2551 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2552 expect(TRUE, r);
2553
2554 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2555 expect(-1, r);
2556
2557 /* need to reset focused item first */
2558 item.stateMask = LVIS_FOCUSED;
2559 item.state = 0;
2560 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2561 expect(TRUE, r);
2562
2563 item.stateMask = LVIS_FOCUSED;
2564 item.state = LVIS_FOCUSED;
2565 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
2566 expect(TRUE, r);
2567
2568 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2569 expect(2, r);
2570
2571 item.stateMask = LVIS_FOCUSED;
2572 item.state = 0;
2573 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2574 expect(TRUE, r);
2575
2576 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2577 expect(2, r);
2578
2579 /* 2. same tests, with LVM_SETITEM */
2580 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2581 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2582
2583 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2584 expect(2, r);
2585
2586 item.stateMask = LVIS_FOCUSED;
2587 item.state = LVIS_FOCUSED;
2588 item.mask = LVIF_STATE;
2589 item.iItem = item.iSubItem = 0;
2590 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2591 expect(TRUE, r);
2592
2593 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2594 expect(0, r);
2595
2596 /* it's not updated if already set */
2597 item.stateMask = LVIS_FOCUSED;
2598 item.state = LVIS_FOCUSED;
2599 item.mask = LVIF_STATE;
2600 item.iItem = 1;
2601 item.iSubItem = 0;
2602 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2603 expect(TRUE, r);
2604
2605 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2606 expect(0, r);
2607
2608 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2609 expect(0, r);
2610
2611 item.stateMask = LVIS_FOCUSED;
2612 item.state = LVIS_FOCUSED;
2613 item.mask = LVIF_STATE;
2614 item.iItem = 1;
2615 item.iSubItem = 0;
2616 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2617 expect(TRUE, r);
2618
2619 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2620 expect(-1, r);
2621
2622 /* need to reset focused item first */
2623 item.stateMask = LVIS_FOCUSED;
2624 item.state = 0;
2625 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2626 expect(TRUE, r);
2627
2628 item.stateMask = LVIS_FOCUSED;
2629 item.state = LVIS_FOCUSED;
2630 item.mask = LVIF_STATE;
2631 item.iItem = 2;
2632 item.iSubItem = 0;
2633 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2634 expect(TRUE, r);
2635
2636 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2637 expect(2, r);
2638
2639 item.stateMask = LVIS_FOCUSED;
2640 item.state = 0;
2641 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2642 expect(TRUE, r);
2643
2644 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2645 expect(2, r);
2646
2647 DestroyWindow(hwnd);
2648 }
2649
2650 static void test_subitem_rect(void)
2651 {
2652 HWND hwnd;
2653 DWORD r;
2654 LVCOLUMNA col;
2655 RECT rect, rect2;
2656 INT arr[3];
2657
2658 /* test LVM_GETSUBITEMRECT for header */
2659 hwnd = create_listview_control(LVS_REPORT);
2660 ok(hwnd != NULL, "failed to create a listview window\n");
2661 /* add some columns */
2662 memset(&col, 0, sizeof(LVCOLUMNA));
2663 col.mask = LVCF_WIDTH;
2664 col.cx = 100;
2665 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
2666 expect(0, r);
2667 col.cx = 150;
2668 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&col);
2669 expect(1, r);
2670 col.cx = 200;
2671 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 2, (LPARAM)&col);
2672 expect(2, r);
2673 /* item = -1 means header, subitem index is 1 based */
2674 SetRect(&rect, LVIR_BOUNDS, 0, 0, 0);
2675 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2676 expect(0, r);
2677
2678 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2679 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2680 expect(1, r);
2681
2682 expect(100, rect.left);
2683 expect(250, rect.right);
2684 expect(3, rect.top);
2685
2686 SetRect(&rect, LVIR_BOUNDS, 2, 0, 0);
2687 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2688 expect(1, r);
2689
2690 expect(250, rect.left);
2691 expect(450, rect.right);
2692 expect(3, rect.top);
2693
2694 /* item LVS_REPORT padding isn't applied to subitems */
2695 insert_item(hwnd, 0);
2696
2697 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2698 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2699 expect(1, r);
2700 expect(100, rect.left);
2701 expect(250, rect.right);
2702
2703 SetRect(&rect, LVIR_ICON, 1, 0, 0);
2704 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2705 expect(1, r);
2706 /* no icon attached - zero width rectangle, with no left padding */
2707 expect(100, rect.left);
2708 expect(100, rect.right);
2709
2710 SetRect(&rect, LVIR_LABEL, 1, 0, 0);
2711 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2712 expect(1, r);
2713 /* same as full LVIR_BOUNDS */
2714 expect(100, rect.left);
2715 expect(250, rect.right);
2716
2717 r = SendMessageA(hwnd, LVM_SCROLL, 10, 0);
2718 ok(r, "got %d\n", r);
2719
2720 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2721 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2722 expect(1, r);
2723 expect(90, rect.left);
2724 expect(240, rect.right);
2725
2726 SendMessageA(hwnd, LVM_SCROLL, -10, 0);
2727
2728 /* test header interaction */
2729 subclass_header(hwnd);
2730 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2731
2732 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2733 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2734 expect(1, r);
2735
2736 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2737 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2738 expect(1, r);
2739
2740 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2741 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -10, (LPARAM)&rect);
2742 expect(1, r);
2743
2744 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2745 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 20, (LPARAM)&rect);
2746 expect(1, r);
2747
2748 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getsubitemrect_seq, "LVM_GETSUBITEMRECT negative index", FALSE);
2749
2750 DestroyWindow(hwnd);
2751
2752 /* test subitem rects after re-arranging columns */
2753 hwnd = create_listview_control(LVS_REPORT);
2754 ok(hwnd != NULL, "failed to create a listview window\n");
2755 memset(&col, 0, sizeof(LVCOLUMNA));
2756 col.mask = LVCF_WIDTH;
2757
2758 col.cx = 100;
2759 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
2760 expect(0, r);
2761
2762 col.cx = 200;
2763 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&col);
2764 expect(1, r);
2765
2766 col.cx = 300;
2767 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 2, (LPARAM)&col);
2768 expect(2, r);
2769
2770 insert_item(hwnd, 0);
2771 insert_item(hwnd, 1);
2772
2773 /* wrong item is refused for main item */
2774 SetRect(&rect, LVIR_BOUNDS, 0, -1, -1);
2775 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect);
2776 expect(FALSE, r);
2777
2778 /* for subitems rectangle is calculated even if there's no item added */
2779 SetRect(&rect, LVIR_BOUNDS, 1, -1, -1);
2780 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect);
2781 expect(TRUE, r);
2782
2783 SetRect(&rect2, LVIR_BOUNDS, 1, -1, -1);
2784 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect2);
2785 expect(TRUE, r);
2786 expect(rect.right, rect2.right);
2787 expect(rect.left, rect2.left);
2788 expect(rect.bottom, rect2.top);
2789 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2790
2791 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2792 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2793 expect(TRUE, r);
2794
2795 SetRect(&rect, LVIR_BOUNDS, 0, -1, -1);
2796 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2797 expect(TRUE, r);
2798 expect(0, rect.left);
2799 expect(600, rect.right);
2800
2801 SetRect(&rect, LVIR_BOUNDS, 1, -1, -1);
2802 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2803 expect(TRUE, r);
2804 expect(0, rect.left);
2805 expect(200, rect.right);
2806
2807 SetRect(&rect2, LVIR_BOUNDS, 1, -1, -1);
2808 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect2);
2809 expect(TRUE, r);
2810 expect(0, rect2.left);
2811 expect(200, rect2.right);
2812 /* items are of the same height */
2813 ok(rect2.top > 0, "expected positive item height\n");
2814 expect(rect.bottom, rect2.top);
2815 expect(rect.bottom * 2 - rect.top, rect2.bottom);
2816
2817 SetRect(&rect, LVIR_BOUNDS, 2, -1, -1);
2818 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2819 expect(TRUE, r);
2820 expect(300, rect.left);
2821 expect(600, rect.right);
2822
2823 DestroyWindow(hwnd);
2824
2825 /* try it for non LVS_REPORT style */
2826 hwnd = CreateWindowA("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2827 GetModuleHandleA(NULL), 0);
2828 SetRect(&rect, LVIR_BOUNDS, 1, -10, -10);
2829 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2830 expect(0, r);
2831 /* rect is unchanged */
2832 expect(0, rect.left);
2833 expect(-10, rect.right);
2834 expect(1, rect.top);
2835 expect(-10, rect.bottom);
2836 DestroyWindow(hwnd);
2837 }
2838
2839 /* comparison callback for test_sorting */
2840 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2841 {
2842 if (first == second) return 0;
2843 return (first > second ? 1 : -1);
2844 }
2845
2846 static void test_sorting(void)
2847 {
2848 HWND hwnd;
2849 LVITEMA item = {0};
2850 INT r;
2851 LONG_PTR style;
2852 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2853 CHAR buff[10];
2854
2855 hwnd = create_listview_control(LVS_REPORT);
2856 ok(hwnd != NULL, "failed to create a listview window\n");
2857
2858 /* insert some items */
2859 item.mask = LVIF_PARAM | LVIF_STATE;
2860 item.state = LVIS_SELECTED;
2861 item.iItem = 0;
2862 item.iSubItem = 0;
2863 item.lParam = 3;
2864 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2865 expect(0, r);
2866
2867 item.mask = LVIF_PARAM;
2868 item.iItem = 1;
2869 item.iSubItem = 0;
2870 item.lParam = 2;
2871 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2872 expect(1, r);
2873
2874 item.mask = LVIF_STATE | LVIF_PARAM;
2875 item.state = LVIS_SELECTED;
2876 item.iItem = 2;
2877 item.iSubItem = 0;
2878 item.lParam = 4;
2879 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2880 expect(2, r);
2881
2882 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2883 expect(-1, r);
2884
2885 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2886 expect(2, r);
2887
2888 r = SendMessageA(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2889 expect(TRUE, r);
2890
2891 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2892 expect(2, r);
2893 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2894 expect(-1, r);
2895 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2896 expect(0, r);
2897 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2898 expect(LVIS_SELECTED, r);
2899 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2900 expect(LVIS_SELECTED, r);
2901
2902 DestroyWindow(hwnd);
2903
2904 /* switch to LVS_SORTASCENDING when some items added */
2905 hwnd = create_listview_control(LVS_REPORT);
2906 ok(hwnd != NULL, "failed to create a listview window\n");
2907
2908 item.mask = LVIF_TEXT;
2909 item.iItem = 0;
2910 item.iSubItem = 0;
2911 item.pszText = names[1];
2912 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2913 expect(0, r);
2914
2915 item.mask = LVIF_TEXT;
2916 item.iItem = 1;
2917 item.iSubItem = 0;
2918 item.pszText = names[2];
2919 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2920 expect(1, r);
2921
2922 item.mask = LVIF_TEXT;
2923 item.iItem = 2;
2924 item.iSubItem = 0;
2925 item.pszText = names[0];
2926 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2927 expect(2, r);
2928
2929 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2930 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2931 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2932 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2933
2934 /* no sorting performed when switched to LVS_SORTASCENDING */
2935 item.mask = LVIF_TEXT;
2936 item.iItem = 0;
2937 item.pszText = buff;
2938 item.cchTextMax = sizeof(buff);
2939 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2940 expect(TRUE, r);
2941 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2942
2943 item.iItem = 1;
2944 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2945 expect(TRUE, r);
2946 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2947
2948 item.iItem = 2;
2949 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2950 expect(TRUE, r);
2951 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2952
2953 /* adding new item doesn't resort list */
2954 item.mask = LVIF_TEXT;
2955 item.iItem = 3;
2956 item.iSubItem = 0;
2957 item.pszText = names[3];
2958 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2959 expect(3, r);
2960
2961 item.mask = LVIF_TEXT;
2962 item.iItem = 0;
2963 item.pszText = buff;
2964 item.cchTextMax = sizeof(buff);
2965 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2966 expect(TRUE, r);
2967 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2968
2969 item.iItem = 1;
2970 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2971 expect(TRUE, r);
2972 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2973
2974 item.iItem = 2;
2975 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2976 expect(TRUE, r);
2977 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2978
2979 item.iItem = 3;
2980 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2981 expect(TRUE, r);
2982 ok(lstrcmpA(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2983
2984 /* corner case - item should be placed at first position */
2985 item.mask = LVIF_TEXT;
2986 item.iItem = 4;
2987 item.iSubItem = 0;
2988 item.pszText = names[4];
2989 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2990 expect(0, r);
2991
2992 item.iItem = 0;
2993 item.pszText = buff;
2994 item.cchTextMax = sizeof(buff);
2995 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2996 expect(TRUE, r);
2997 ok(lstrcmpA(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2998
2999 item.iItem = 1;
3000 item.pszText = buff;
3001 item.cchTextMax = sizeof(buff);
3002 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3003 expect(TRUE, r);
3004 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
3005
3006 item.iItem = 2;
3007 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3008 expect(TRUE, r);
3009 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
3010
3011 item.iItem = 3;
3012 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3013 expect(TRUE, r);
3014 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
3015
3016 item.iItem = 4;
3017 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3018 expect(TRUE, r);
3019 ok(lstrcmpA(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
3020
3021 DestroyWindow(hwnd);
3022 }
3023
3024 static void test_ownerdata(void)
3025 {
3026 static char test_str[] = "test";
3027
3028 HWND hwnd;
3029 LONG_PTR style, ret;
3030 DWORD res;
3031 LVITEMA item;
3032
3033 /* it isn't possible to set LVS_OWNERDATA after creation */
3034 if (g_is_below_5)
3035 {
3036 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
3037 }
3038 else
3039 {
3040 hwnd = create_listview_control(LVS_REPORT);
3041 ok(hwnd != NULL, "failed to create a listview window\n");
3042 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3043 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
3044
3045 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3046
3047 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
3048 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
3049 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
3050 "try to switch to LVS_OWNERDATA seq", FALSE);
3051
3052 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3053 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
3054 DestroyWindow(hwnd);
3055 }
3056
3057 /* try to set LVS_OWNERDATA after creation just having it */
3058 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3059 ok(hwnd != NULL, "failed to create a listview window\n");
3060 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3061 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
3062
3063 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3064
3065 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
3066 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
3067 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
3068 "try to switch to LVS_OWNERDATA seq", FALSE);
3069 DestroyWindow(hwnd);
3070
3071 /* try to remove LVS_OWNERDATA after creation just having it */
3072 if (g_is_below_5)
3073 {
3074 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
3075 }
3076 else
3077 {
3078 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3079 ok(hwnd != NULL, "failed to create a listview window\n");
3080 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3081 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
3082
3083 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3084
3085 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
3086 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
3087 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
3088 "try to switch to LVS_OWNERDATA seq", FALSE);
3089 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3090 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
3091 DestroyWindow(hwnd);
3092 }
3093
3094 /* try select an item */
3095 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3096 ok(hwnd != NULL, "failed to create a listview window\n");
3097 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3098 expect(1, res);
3099 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
3100 expect(0, res);
3101 memset(&item, 0, sizeof(item));
3102 item.stateMask = LVIS_SELECTED;
3103 item.state = LVIS_SELECTED;
3104 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3105 expect(TRUE, res);
3106 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
3107 expect(1, res);
3108 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
3109 expect(1, res);
3110 DestroyWindow(hwnd);
3111
3112 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
3113 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3114 ok(hwnd != NULL, "failed to create a listview window\n");
3115 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3116 expect(1, res);
3117 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
3118 expect(1, res);
3119 memset(&item, 0, sizeof(item));
3120 item.mask = LVIF_STATE;
3121 item.iItem = 0;
3122 item.stateMask = LVIS_SELECTED;
3123 item.state = LVIS_SELECTED;
3124 res = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3125 expect(FALSE, res);
3126 memset(&item, 0, sizeof(item));
3127 item.pszText = test_str;
3128 res = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3129 expect(FALSE, res);
3130 DestroyWindow(hwnd);
3131
3132 /* check notifications after focused/selected changed */
3133 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3134 ok(hwnd != NULL, "failed to create a listview window\n");
3135 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
3136 expect(1, res);
3137
3138 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3139
3140 memset(&item, 0, sizeof(item));
3141 item.stateMask = LVIS_SELECTED;
3142 item.state = LVIS_SELECTED;
3143 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3144 expect(TRUE, res);
3145
3146 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_select_focus_parent_seq,
3147 "ownerdata select notification", TRUE);
3148
3149 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3150
3151 memset(&item, 0, sizeof(item));
3152 item.stateMask = LVIS_FOCUSED;
3153 item.state = LVIS_FOCUSED;
3154 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3155 expect(TRUE, res);
3156
3157 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_select_focus_parent_seq,
3158 "ownerdata focus notification", TRUE);
3159
3160 /* select all, check notifications */
3161 item.stateMask = LVIS_SELECTED;
3162 item.state = 0;
3163 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3164 expect(TRUE, res);
3165
3166 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3167
3168 item.stateMask = LVIS_SELECTED;
3169 item.state = LVIS_SELECTED;
3170
3171 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3172 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3173 expect(TRUE, res);
3174 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3175 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3176 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3177 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3178 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3179 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3180 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3181
3182 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3183 "ownerdata select all notification", FALSE);
3184
3185 /* select all again, note that all items are selected already */
3186 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3187 item.stateMask = LVIS_SELECTED;
3188 item.state = LVIS_SELECTED;
3189
3190 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3191 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3192 expect(TRUE, res);
3193 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3194 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3195 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3196 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3197 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3198 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3199 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3200
3201 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3202 "ownerdata select all notification", FALSE);
3203
3204 /* deselect all */
3205 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3206 item.stateMask = LVIS_SELECTED;
3207 item.state = 0;
3208
3209 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3210 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3211 expect(TRUE, res);
3212 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3213 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3214 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3215 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3216 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3217 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3218 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3219
3220 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3221 "ownerdata deselect all notification", TRUE);
3222
3223 /* nothing selected, deselect all again */
3224 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3225 item.stateMask = LVIS_SELECTED;
3226 item.state = 0;
3227
3228 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3229 expect(TRUE, res);
3230
3231 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "ownerdata deselect all notification", FALSE);
3232
3233 /* select one, then deselect all */
3234 item.stateMask = LVIS_SELECTED;
3235 item.state = LVIS_SELECTED;
3236 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3237 expect(TRUE, res);
3238 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3239 item.stateMask = LVIS_SELECTED;
3240 item.state = 0;
3241
3242 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3243 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3244 expect(TRUE, res);
3245 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3246 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3247 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3248 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3249 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3250 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3251 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3252
3253 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3254 "ownerdata select all notification", TRUE);
3255
3256 /* remove focused, try to focus all */
3257 item.stateMask = LVIS_FOCUSED;
3258 item.state = LVIS_FOCUSED;
3259 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3260 expect(TRUE, res);
3261 item.stateMask = LVIS_FOCUSED;
3262 item.state = 0;
3263 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3264 expect(TRUE, res);
3265 item.stateMask = LVIS_FOCUSED;
3266 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
3267 expect(0, res);
3268
3269 /* setting all to focused returns failure value */
3270 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3271 item.stateMask = LVIS_FOCUSED;
3272 item.state = LVIS_FOCUSED;
3273
3274 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3275 expect(FALSE, res);
3276
3277 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3278 "ownerdata focus all notification", FALSE);
3279
3280 /* focus single item, remove all */
3281 item.stateMask = LVIS_FOCUSED;
3282 item.state = LVIS_FOCUSED;
3283 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3284 expect(TRUE, res);
3285 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3286 item.stateMask = LVIS_FOCUSED;
3287 item.state = 0;
3288
3289 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3290 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3291 expect(TRUE, res);
3292 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3293 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3294 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3295 ok(g_nmlistview.uOldState == LVIS_FOCUSED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3296 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3297 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3298 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3299
3300 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
3301 "ownerdata remove focus all notification", TRUE);
3302
3303 /* set all cut */
3304 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3305 item.stateMask = LVIS_CUT;
3306 item.state = LVIS_CUT;
3307
3308 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3309 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3310 expect(TRUE, res);
3311 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3312 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3313 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3314 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3315 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3316 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3317 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3318
3319 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3320 "ownerdata cut all notification", FALSE);
3321
3322 /* all marked cut, try again */
3323 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3324 item.stateMask = LVIS_CUT;
3325 item.state = LVIS_CUT;
3326
3327 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3328 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3329 expect(TRUE, res);
3330 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3331 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3332 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3333 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3334 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3335 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3336 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3337
3338 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3339 "ownerdata cut all notification #2", FALSE);
3340
3341 DestroyWindow(hwnd);
3342
3343 /* check notifications on LVM_GETITEM */
3344 /* zero callback mask */
3345 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3346 ok(hwnd != NULL, "failed to create a listview window\n");
3347 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3348 expect(1, res);
3349
3350 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3351
3352 memset(&item, 0, sizeof(item));
3353 item.stateMask = LVIS_SELECTED;
3354 item.mask = LVIF_STATE;
3355 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3356 expect(TRUE, res);
3357
3358 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3359 "ownerdata getitem selected state 1", FALSE);
3360
3361 /* non zero callback mask but not we asking for */
3362 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
3363 expect(TRUE, res);
3364
3365 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3366
3367 memset(&item, 0, sizeof(item));
3368 item.stateMask = LVIS_SELECTED;
3369 item.mask = LVIF_STATE;
3370 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3371 expect(TRUE, res);
3372
3373 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3374 "ownerdata getitem selected state 2", FALSE);
3375
3376 /* LVIS_OVERLAYMASK callback mask, asking for index */
3377 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3378
3379 memset(&item, 0, sizeof(item));
3380 item.stateMask = LVIS_OVERLAYMASK;
3381 item.mask = LVIF_STATE;
3382 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3383 expect(TRUE, res);
3384
3385 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3386 "ownerdata getitem selected state 2", FALSE);
3387
3388 DestroyWindow(hwnd);
3389
3390 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3391 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
3392 ok(hwnd != NULL, "failed to create a listview window\n");
3393 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3394 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3395 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3396 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
3397 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3398 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
3399 DestroyWindow(hwnd);
3400 /* apparently it's allowed to switch these style on after creation */
3401 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3402 ok(hwnd != NULL, "failed to create a listview window\n");
3403 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3404 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3405 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
3406 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3407 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3408 DestroyWindow(hwnd);
3409
3410 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3411 ok(hwnd != NULL, "failed to create a listview window\n");
3412 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3413 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3414 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
3415 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3416 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
3417 DestroyWindow(hwnd);
3418
3419 /* The focused item is updated after the invalidation */
3420 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3421 ok(hwnd != NULL, "failed to create a listview window\n");
3422 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 3, 0);
3423 expect(TRUE, res);
3424
3425 memset(&item, 0, sizeof(item));
3426 item.stateMask = LVIS_FOCUSED;
3427 item.state = LVIS_FOCUSED;
3428 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3429 expect(TRUE, res);
3430
3431 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3432 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 0, 0);
3433 expect(TRUE, res);
3434 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3435 "ownerdata setitemcount", FALSE);
3436
3437 res = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
3438 expect(-1, res);
3439 DestroyWindow(hwnd);
3440 }
3441
3442 static void test_norecompute(void)
3443 {
3444 static CHAR testA[] = "test";
3445 CHAR buff[10];
3446 LVITEMA item;
3447 HWND hwnd;
3448 DWORD res;
3449
3450 /* self containing control */
3451 hwnd = create_listview_control(LVS_REPORT);
3452 ok(hwnd != NULL, "failed to create a listview window\n");
3453 memset(&item, 0, sizeof(item));
3454 item.mask = LVIF_TEXT | LVIF_STATE;
3455 item.iItem = 0;
3456 item.stateMask = LVIS_SELECTED;
3457 item.state = LVIS_SELECTED;
3458 item.pszText = testA;
3459 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3460 expect(0, res);
3461 /* retrieve with LVIF_NORECOMPUTE */
3462 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3463 item.iItem = 0;
3464 item.pszText = buff;
3465 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3466 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3467 expect(TRUE, res);
3468 ok(lstrcmpA(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
3469
3470 item.mask = LVIF_TEXT;
3471 item.iItem = 1;
3472 item.pszText = LPSTR_TEXTCALLBACKA;
3473 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3474 expect(1, res);
3475
3476 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3477 item.iItem = 1;
3478 item.pszText = buff;
3479 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3480
3481 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3482 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3483 expect(TRUE, res);
3484 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3485 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3486 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
3487
3488 DestroyWindow(hwnd);
3489
3490 /* LVS_OWNERDATA */
3491 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3492 ok(hwnd != NULL, "failed to create a listview window\n");
3493
3494 item.mask = LVIF_STATE;
3495 item.stateMask = LVIS_SELECTED;
3496 item.state = LVIS_SELECTED;
3497 item.iItem = 0;
3498 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3499 expect(0, res);
3500
3501 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3502 item.iItem = 0;
3503 item.pszText = buff;
3504 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3505 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3506 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3507 expect(TRUE, res);
3508 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3509 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3510 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
3511
3512 DestroyWindow(hwnd);
3513 }
3514
3515 static void test_nosortheader(void)
3516 {
3517 HWND hwnd, header;
3518 LONG_PTR style;
3519
3520 hwnd = create_listview_control(LVS_REPORT);
3521 ok(hwnd != NULL, "failed to create a listview window\n");
3522
3523 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3524 ok(IsWindow(header), "header expected\n");
3525
3526 style = GetWindowLongPtrA(header, GWL_STYLE);
3527 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
3528
3529 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3530 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
3531 /* HDS_BUTTONS retained */
3532 style = GetWindowLongPtrA(header, GWL_STYLE);
3533 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
3534
3535 DestroyWindow(hwnd);
3536
3537 /* create with LVS_NOSORTHEADER */
3538 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
3539 ok(hwnd != NULL, "failed to create a listview window\n");
3540
3541 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3542 ok(IsWindow(header), "header expected\n");
3543
3544 style = GetWindowLongPtrA(header, GWL_STYLE);
3545 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3546
3547 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3548 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
3549 /* not changed here */
3550 style = GetWindowLongPtrA(header, GWL_STYLE);
3551 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3552
3553 DestroyWindow(hwnd);
3554 }
3555
3556 static void test_setredraw(void)
3557 {
3558 HWND hwnd;
3559 DWORD_PTR style;
3560 DWORD ret;
3561 HDC hdc;
3562 RECT rect;
3563
3564 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3565 ok(hwnd != NULL, "failed to create a listview window\n");
3566
3567 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3568 ListView seems to handle it internally without DefWinProc */
3569
3570 /* default value first */
3571 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3572 expect(0, ret);
3573 /* disable */
3574 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3575 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3576 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3577 expect(0, ret);
3578 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3579 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3580 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3581 expect(0, ret);
3582
3583 /* check update rect after redrawing */
3584 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3585 expect(0, ret);
3586 InvalidateRect(hwnd, NULL, FALSE);
3587 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
3588 rect.right = rect.bottom = 1;
3589 GetUpdateRect(hwnd, &rect, FALSE);
3590 expect(0, rect.right);
3591 expect(0, rect.bottom);
3592
3593 /* WM_ERASEBKGND */
3594 hdc = GetWindowDC(hwndparent);
3595 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3596 expect(TRUE, ret);
3597 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3598 expect(0, ret);
3599 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3600 expect(TRUE, ret);
3601 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3602 expect(0, ret);
3603 ReleaseDC(hwndparent, hdc);
3604
3605 /* check notification messages to show that repainting is disabled */
3606 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3607 expect(TRUE, ret);
3608 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3609 expect(0, ret);
3610 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3611
3612 InvalidateRect(hwnd, NULL, TRUE);
3613 UpdateWindow(hwnd);
3614 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3615 "redraw after WM_SETREDRAW (FALSE)", FALSE);
3616
3617 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3618 expect(TRUE, ret);
3619 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3620 InvalidateRect(hwnd, NULL, TRUE);
3621 UpdateWindow(hwnd);
3622 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3623 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3624
3625 /* message isn't forwarded to header */
3626 subclass_header(hwnd);
3627 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3628 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3629 expect(0, ret);
3630 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3631 "WM_SETREDRAW: not forwarded to header", FALSE);
3632
3633 DestroyWindow(hwnd);
3634 }
3635
3636 static void test_hittest(void)
3637 {
3638 HWND hwnd;
3639 DWORD r;
3640 RECT bounds;
3641 LVITEMA item;
3642 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3643 POINT pos;
3644 INT x, y, i;
3645 WORD vert;
3646 HIMAGELIST himl, himl2;
3647 HBITMAP hbmp;
3648
3649 hwnd = create_listview_control(LVS_REPORT);
3650 ok(hwnd != NULL, "failed to create a listview window\n");
3651
3652 /* LVS_REPORT with a single subitem (2 columns) */
3653 insert_column(hwnd, 0);
3654 insert_column(hwnd, 1);
3655 insert_item(hwnd, 0);
3656
3657 item.iSubItem = 0;
3658 /* the only purpose of that line is to be as long as a half item rect */
3659 item.pszText = text;
3660 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3661 expect(TRUE, r);
3662
3663 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3664 expect(TRUE, r);
3665 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3666 expect(TRUE, r);
3667
3668 SetRect(&bounds, LVIR_BOUNDS, 0, 0, 0);
3669 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3670 expect(1, r);
3671 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3672 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3673 r = SendMessageA(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3674 vert = HIWORD(r);
3675 ok(bounds.bottom - bounds.top == vert,
3676 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3677 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3678 expect(TRUE, r);
3679
3680 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3681
3682 /* outside columns by x position - valid is [0, 199] */
3683 x = -1;
3684 y = pos.y + (bounds.bottom - bounds.top) / 2;
3685 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3686 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3687
3688 x = pos.x + 50; /* column half width */
3689 y = pos.y + (bounds.bottom - bounds.top) / 2;
3690 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3691 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3692 x = pos.x + 150; /* outside column */
3693 y = pos.y + (bounds.bottom - bounds.top) / 2;
3694 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3695 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3696 y = (bounds.bottom - bounds.top) / 2;
3697 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3698 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3699 /* outside possible client rectangle (to right) */
3700 x = pos.x + 500;
3701 y = pos.y + (bounds.bottom - bounds.top) / 2;
3702 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3703 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3704 y = (bounds.bottom - bounds.top) / 2;
3705 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3706 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3707 /* subitem returned with -1 item too */
3708 x = pos.x + 150;
3709 y = bounds.top - vert;
3710 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3711 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3712 /* return values appear to underflow with negative indices */
3713 i = -2;
3714 y = y - vert;
3715 while (i > -10) {
3716 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3717 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3718 y = y - vert;
3719 i--;
3720 }
3721 /* parent client area is 100x100 by default */
3722 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3723 x = pos.x + 150; /* outside column */
3724 y = pos.y + (bounds.bottom - bounds.top) / 2;
3725 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3726 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3727 y = (bounds.bottom - bounds.top) / 2;
3728 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3729 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3730 /* the same with LVS_EX_FULLROWSELECT */
3731 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3732 x = pos.x + 150; /* outside column */
3733 y = pos.y + (bounds.bottom - bounds.top) / 2;
3734 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3735 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3736 y = (bounds.bottom - bounds.top) / 2;
3737 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3738 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3739 x = pos.x + 150; /* outside column */
3740 y = pos.y + (bounds.bottom - bounds.top) / 2;
3741 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3742 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3743 y = (bounds.bottom - bounds.top) / 2;
3744 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3745 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3746 /* outside possible client rectangle (to right) */
3747 x = pos.x + 500;
3748 y = pos.y + (bounds.bottom - bounds.top) / 2;
3749 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3750 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3751 y = (bounds.bottom - bounds.top) / 2;
3752 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3753 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3754 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3755 himl = ImageList_Create(16, 16, 0, 4, 4);
3756 ok(himl != NULL, "failed to create imagelist\n");
3757 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3758 ok(hbmp != NULL, "failed to create bitmap\n");
3759 r = ImageList_Add(himl, hbmp, 0);
3760 ok(r == 0, "should be zero\n");
3761 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3762 ok(hbmp != NULL, "failed to create bitmap\n");
3763 r = ImageList_Add(himl, hbmp, 0);
3764 ok(r == 1, "should be one\n");
3765
3766 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3767 expect(0, r);
3768
3769 item.mask = LVIF_IMAGE;
3770 item.iImage = 0;
3771 item.iItem = 0;
3772 item.iSubItem = 0;
3773 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3774 expect(TRUE, r);
3775 /* on state icon */
3776 x = pos.x + 8;
3777 y = pos.y + (bounds.bottom - bounds.top) / 2;
3778 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3779 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3780 y = (bounds.bottom - bounds.top) / 2;
3781 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3782
3783 /* state icons indices are 1 based, check with valid index */
3784 item.mask = LVIF_STATE;
3785 item.state = INDEXTOSTATEIMAGEMASK(1);
3786 item.stateMask = LVIS_STATEIMAGEMASK;
3787 item.iItem = 0;
3788 item.iSubItem = 0;
3789 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3790 expect(TRUE, r);
3791 /* on state icon */
3792 x = pos.x + 8;
3793 y = pos.y + (bounds.bottom - bounds.top) / 2;
3794 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3795 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3796 y = (bounds.bottom - bounds.top) / 2;
3797 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3798
3799 himl2 = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3800 ok(himl2 == himl, "should return handle\n");
3801
3802 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3803 expect(0, r);
3804 /* on item icon */
3805 x = pos.x + 8;
3806 y = pos.y + (bounds.bottom - bounds.top) / 2;
3807 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3808 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3809 y = (bounds.bottom - bounds.top) / 2;
3810 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3811
3812 DestroyWindow(hwnd);
3813 }
3814
3815 static void test_getviewrect(void)
3816 {
3817 HWND hwnd;
3818 DWORD r;
3819 RECT rect;
3820 LVITEMA item;
3821
3822 hwnd = create_listview_control(LVS_REPORT);
3823 ok(hwnd != NULL, "failed to create a listview window\n");
3824
3825 /* empty */
3826 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3827 expect(TRUE, r);
3828
3829 insert_column(hwnd, 0);
3830 insert_column(hwnd, 1);
3831
3832 memset(&item, 0, sizeof(item));
3833 item.iItem = 0;
3834 item.iSubItem = 0;
3835 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3836 ok(!r, "got %d\n", r);
3837
3838 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3839 expect(TRUE, r);
3840 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3841 expect(TRUE, r);
3842
3843 SetRect(&rect, -1, -1, -1, -1);
3844 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3845 expect(TRUE, r);
3846 /* left is set to (2e31-1) - XP SP2 */
3847 expect(0, rect.right);
3848 expect(0, rect.top);
3849 expect(0, rect.bottom);
3850
3851 /* switch to LVS_ICON */
3852 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_REPORT);
3853
3854 SetRect(&rect, -1, -1, -1, -1);
3855 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3856 expect(TRUE, r);
3857 expect(0, rect.left);
3858 expect(0, rect.top);
3859 /* precise value differs for 2k, XP and Vista */
3860 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3861 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3862
3863 DestroyWindow(hwnd);
3864 }
3865
3866 static void test_getitemposition(void)
3867 {
3868 HWND hwnd, header;
3869 DWORD r;
3870 POINT pt;
3871 RECT rect;
3872
3873 hwnd = create_listview_control(LVS_REPORT);
3874 ok(hwnd != NULL, "failed to create a listview window\n");
3875 header = subclass_header(hwnd);
3876
3877 /* LVS_REPORT, single item, no columns added */
3878 insert_item(hwnd, 0);
3879
3880 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3881
3882 pt.x = pt.y = -1;
3883 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3884 expect(TRUE, r);
3885 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3886
3887 /* LVS_REPORT, single item, single column */
3888 insert_column(hwnd, 0);
3889
3890 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3891
3892 pt.x = pt.y = -1;
3893 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3894 expect(TRUE, r);
3895 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3896
3897 SetRectEmpty(&rect);
3898 r = SendMessageA(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3899 ok(r, "got %d\n", r);
3900 /* some padding? */
3901 expect(2, pt.x);
3902 /* offset by header height */
3903 expect(rect.bottom - rect.top, pt.y);
3904
3905 DestroyWindow(hwnd);
3906 }
3907
3908 static void test_columnscreation(void)
3909 {
3910 HWND hwnd, header;
3911 DWORD r;
3912
3913 hwnd = create_listview_control(LVS_REPORT);
3914 ok(hwnd != NULL, "failed to create a listview window\n");
3915
3916 insert_item(hwnd, 0);
3917
3918 /* headers columns aren't created automatically */
3919 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3920 ok(IsWindow(header), "Expected header handle\n");
3921 r = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
3922 expect(0, r);
3923
3924 DestroyWindow(hwnd);
3925 }
3926
3927 static void test_getitemrect(void)
3928 {
3929 HWND hwnd;
3930 HIMAGELIST himl, himl_ret;
3931 HBITMAP hbm;
3932 RECT rect;
3933 DWORD r;
3934 LVITEMA item;
3935 LVCOLUMNA col;
3936 INT order[2];
3937 POINT pt;
3938
3939 /* rectangle isn't empty for empty text items */
3940 hwnd = create_listview_control(LVS_LIST);
3941 memset(&item, 0, sizeof(item));
3942 item.mask = 0;
3943 item.iItem = 0;
3944 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3945 expect(0, r);
3946 rect.left = LVIR_LABEL;
3947 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3948 expect(TRUE, r);
3949 expect(0, rect.left);
3950 expect(0, rect.top);
3951 /* estimate it as width / height ratio */
3952 todo_wine
3953 ok((rect.right / rect.bottom) >= 5, "got right %d, bottom %d\n", rect.right, rect.bottom);
3954 DestroyWindow(hwnd);
3955
3956 hwnd = create_listview_control(LVS_REPORT);
3957 ok(hwnd != NULL, "failed to create a listview window\n");
3958
3959 /* empty item */
3960 memset(&item, 0, sizeof(item));
3961 item.iItem = 0;
3962 item.iSubItem = 0;
3963 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3964 expect(0, r);
3965
3966 SetRect(&rect, LVIR_BOUNDS, -1, -1, -1);
3967 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3968 expect(TRUE, r);
3969
3970 /* zero width rectangle with no padding */
3971 expect(0, rect.left);
3972 expect(0, rect.right);
3973
3974 insert_column(hwnd, 0);
3975 insert_column(hwnd, 1);
3976
3977 col.mask = LVCF_WIDTH;
3978 col.cx = 50;
3979 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 0, (LPARAM)&col);
3980 expect(TRUE, r);
3981
3982 col.mask = LVCF_WIDTH;
3983 col.cx = 100;
3984 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 1, (LPARAM)&col);
3985 expect(TRUE, r);
3986
3987 SetRect(&rect, LVIR_BOUNDS, -1, -1, -1);
3988 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3989 expect(TRUE, r);
3990
3991 /* still no left padding */
3992 expect(0, rect.left);
3993 expect(150, rect.right);
3994
3995 SetRect(&rect, LVIR_SELECTBOUNDS, -1, -1, -1);
3996 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3997 expect(TRUE, r);
3998 /* padding */
3999 expect(2, rect.left);
4000
4001 SetRect(&rect, LVIR_LABEL, -1, -1, -1);
4002 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4003 expect(TRUE, r);
4004 /* padding, column width */
4005 expect(2, rect.left);
4006 expect(50, rect.right);
4007
4008 /* no icons attached */
4009 SetRect(&rect, LVIR_ICON, -1, -1, -1);
4010 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4011 expect(TRUE, r);
4012 /* padding */
4013 expect(2, rect.left);
4014 expect(2, rect.right);
4015
4016 /* change order */
4017 order[0] = 1; order[1] = 0;
4018 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
4019 expect(TRUE, r);
4020 pt.x = -1;
4021 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
4022 expect(TRUE, r);
4023 /* 1 indexed column width + padding */
4024 expect(102, pt.x);
4025 /* rect is at zero too */
4026 SetRect(&rect, LVIR_BOUNDS, -1, -1, -1);
4027 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4028 expect(TRUE, r);
4029 expect(0, rect.left);
4030 /* just width sum */
4031 expect(150, rect.right);
4032
4033 SetRect(&rect, LVIR_SELECTBOUNDS, -1, -1, -1);
4034 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4035 expect(TRUE, r);
4036 /* column width + padding */
4037 expect(102, rect.left);
4038
4039 /* back to initial order */
4040 order[0] = 0; order[1] = 1;
4041 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
4042 expect(TRUE, r);
4043
4044 /* state icons */
4045 himl = ImageList_Create(16, 16, 0, 2, 2);
4046 ok(himl != NULL, "failed to create imagelist\n");
4047 hbm = CreateBitmap(16, 16, 1, 1, NULL);
4048 ok(hbm != NULL, "failed to create bitmap\n");
4049 r = ImageList_Add(himl, hbm, 0);
4050 expect(0, r);
4051 hbm = CreateBitmap(16, 16, 1, 1, NULL);
4052 ok(hbm != NULL, "failed to create bitmap\n");
4053 r = ImageList_Add(himl, hbm, 0);
4054 expect(1, r);
4055
4056 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
4057 expect(0, r);
4058
4059 item.mask = LVIF_STATE;
4060 item.state = INDEXTOSTATEIMAGEMASK(1);
4061 item.stateMask = LVIS_STATEIMAGEMASK;
4062 item.iItem = 0;
4063 item.iSubItem = 0;
4064 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4065 expect(TRUE, r);
4066
4067 /* icon bounds */
4068 SetRect(&rect, LVIR_ICON, -1, -1, -1);
4069 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4070 expect(TRUE, r);
4071 /* padding + stateicon width */
4072 expect(18, rect.left);
4073 expect(18, rect.right);
4074 /* label bounds */
4075 SetRect(&rect, LVIR_LABEL, -1, -1, -1);
4076 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4077 expect(TRUE, r);
4078 /* padding + stateicon width -> column width */
4079 expect(18, rect.left);
4080 expect(50, rect.right);
4081
4082 himl_ret = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
4083 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
4084
4085 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
4086 expect(0, r);
4087
4088 item.mask = LVIF_STATE | LVIF_IMAGE;
4089 item.iImage = 1;
4090 item.state = 0;
4091 item.stateMask = ~0;
4092 item.iItem = 0;
4093 item.iSubItem = 0;
4094 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4095 expect(TRUE, r);
4096
4097 /* icon bounds */
4098 SetRect(&rect, LVIR_ICON, -1, -1, -1);
4099 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4100 expect(TRUE, r);
4101 /* padding, icon width */
4102 expect(2, rect.left);
4103 expect(18, rect.right);
4104 /* label bounds */
4105 SetRect(&rect, LVIR_LABEL, -1, -1, -1);
4106 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4107 expect(TRUE, r);
4108 /* padding + icon width -> column width */
4109 expect(18, rect.left);
4110 expect(50, rect.right);
4111
4112 /* select bounds */
4113 SetRect(&rect, LVIR_SELECTBOUNDS, -1, -1, -1);
4114 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4115 expect(TRUE, r);
4116 /* padding, column width */
4117 expect(2, rect.left);
4118 expect(50, rect.right);
4119
4120 /* try with indentation */
4121 item.mask = LVIF_INDENT;
4122 item.iIndent = 1;
4123 item.iItem = 0;
4124 item.iSubItem = 0;
4125 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4126 expect(TRUE, r);
4127
4128 /* bounds */
4129 SetRect(&rect, LVIR_BOUNDS, -1, -1, -1);
4130 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4131 expect(TRUE, r);
4132 /* padding + 1 icon width, column width */
4133 expect(0, rect.left);
4134 expect(150, rect.right);
4135
4136 /* select bounds */
4137 SetRect(&rect, LVIR_SELECTBOUNDS, -1, -1, -1);
4138 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4139 expect(TRUE, r);
4140 /* padding + 1 icon width, column width */
4141 expect(2 + 16, rect.left);
4142 expect(50, rect.right);
4143
4144 /* label bounds */
4145 SetRect(&rect, LVIR_LABEL, -1, -1, -1);
4146 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4147 expect(TRUE, r);
4148 /* padding + 2 icon widths, column width */
4149 expect(2 + 16*2, rect.left);
4150 expect(50, rect.right);
4151
4152 /* icon bounds */
4153 SetRect(&rect, LVIR_ICON, -1, -1, -1);
4154 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4155 expect(TRUE, r);
4156 /* padding + 1 icon width indentation, icon width */
4157 expect(2 + 16, rect.left);
4158 expect(34, rect.right);
4159
4160 DestroyWindow(hwnd);
4161 }
4162
4163 static void test_editbox(void)
4164 {
4165 static CHAR testitemA[] = "testitem";
4166 static CHAR testitem1A[] = "testitem_quitelongname";
4167 static CHAR testitem2A[] = "testITEM_quitelongname";
4168 static CHAR buffer[25];
4169 HWND hwnd, hwndedit, hwndedit2, header;
4170 LVITEMA item;
4171 INT r;
4172
4173 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4174 ok(hwnd != NULL, "failed to create a listview window\n");
4175
4176 insert_column(hwnd, 0);
4177
4178 memset(&item, 0, sizeof(item));
4179 item.mask = LVIF_TEXT;
4180 item.pszText = testitemA;
4181 item.iItem = 0;
4182 item.iSubItem = 0;
4183 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4184 expect(0, r);
4185
4186 /* test notifications without edit created */
4187 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4188 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
4189 expect(0, r);
4190 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4191 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
4192 /* same thing but with valid window */
4193 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
4194 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
4195 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4196 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
4197 expect(0, r);
4198 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4199 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
4200 DestroyWindow(hwndedit);
4201
4202 /* setting focus is necessary */
4203 SetFocus(hwnd);
4204 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4205 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4206
4207 /* test children Z-order after Edit box created */
4208 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4209 ok(IsWindow(header), "Expected header to be created\n");
4210 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4211 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4212
4213 /* modify initial string */
4214 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4215 expect(TRUE, r);
4216
4217 /* edit window is resized and repositioned,
4218 check again for Z-order - it should be preserved */
4219 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4220 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4221
4222 /* return focus to listview */
4223 SetFocus(hwnd);
4224
4225 memset(&item, 0, sizeof(item));
4226 item.mask = LVIF_TEXT;
4227 item.pszText = buffer;
4228 item.cchTextMax = sizeof(buffer);
4229 item.iItem = 0;
4230 item.iSubItem = 0;
4231 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4232 expect(TRUE, r);
4233
4234 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4235
4236 /* send LVM_EDITLABEL on already created edit */
4237 SetFocus(hwnd);
4238 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4239 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4240 /* focus will be set to edit */
4241 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
4242 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4243 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
4244
4245 /* creating label disabled when control isn't focused */
4246 SetFocus(0);
4247 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4248 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4249
4250 /* check EN_KILLFOCUS handling */
4251 memset(&item, 0, sizeof(item));
4252 item.pszText = testitemA;
4253 item.iItem = 0;
4254 item.iSubItem = 0;
4255 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4256 expect(TRUE, r);
4257
4258 SetFocus(hwnd);
4259 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4260 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4261 /* modify edit and notify control that it lost focus */
4262 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4263 expect(TRUE, r);
4264 g_editbox_disp_info.item.pszText = NULL;
4265 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4266 expect(0, r);
4267 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
4268
4269 memset(&item, 0, sizeof(item));
4270 item.pszText = buffer;
4271 item.cchTextMax = sizeof(buffer);
4272 item.iItem = 0;
4273 item.iSubItem = 0;
4274 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4275 expect(lstrlenA(item.pszText), r);
4276 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4277 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4278
4279 /* change item name to differ in casing only */
4280 SetFocus(hwnd);
4281 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4282 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4283 /* modify edit and notify control that it lost focus */
4284 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
4285 expect(TRUE, r);
4286 g_editbox_disp_info.item.pszText = NULL;
4287 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4288 expect(0, r);
4289 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
4290
4291 memset(&item, 0, sizeof(item));
4292 item.pszText = buffer;
4293 item.cchTextMax = sizeof(buffer);
4294 item.iItem = 0;
4295 item.iSubItem = 0;
4296 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4297 expect(lstrlenA(item.pszText), r);
4298 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
4299 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4300
4301 /* end edit without saving */
4302 SetFocus(hwnd);
4303 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4304 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4305 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
4306 expect(0, r);
4307 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4308 "edit box - end edit, no change, escape", TRUE);
4309 /* end edit with saving */
4310 SetFocus(hwnd);
4311 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4312 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4313 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
4314 expect(0, r);
4315 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4316 "edit box - end edit, no change, return", TRUE);
4317
4318 memset(&item, 0, sizeof(item));
4319 item.pszText = buffer;
4320 item.cchTextMax = sizeof(buffer);
4321 item.iItem = 0;
4322 item.iSubItem = 0;
4323 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4324 expect(lstrlenA(item.pszText), r);
4325 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
4326
4327 /* LVM_EDITLABEL with -1 destroys current edit */
4328 hwndedit = (HWND)SendMessageA(hwnd, LVM_GETEDITCONTROL, 0, 0);
4329 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4330 /* no edit present */
4331 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4332 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4333 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4334 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4335 /* edit present */
4336 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4337 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4338 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4339 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4340 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4341 /* check another negative value */
4342 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4343 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4344 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4345 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -2, 0);
4346 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4347 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4348 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4349 /* and value greater than max item index */
4350 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4351 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4352 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4353 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
4354 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, r, 0);
4355 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4356 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4357 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4358
4359 /* messaging tests */
4360 SetFocus(hwnd);
4361 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4362 blockEdit = FALSE;
4363 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4364 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4365 /* testing only sizing messages */
4366 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
4367 "edit box create - sizing", FALSE);
4368
4369 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4370 SetFocus(hwnd);
4371 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4372 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4373 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4374 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4375 expect(0, r);
4376 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4377 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
4378
4379 DestroyWindow(hwnd);
4380 }
4381
4382 static void test_notifyformat(void)
4383 {
4384 HWND hwnd, header;
4385 DWORD r;
4386
4387 hwnd = create_listview_control(LVS_REPORT);
4388 ok(hwnd != NULL, "failed to create a listview window\n");
4389
4390 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4391 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4392 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4393 expect(0, r);
4394 SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4395 /* set */
4396 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
4397 expect(0, r);
4398 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4399 if (r == 1)
4400 {
4401 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
4402 expect(1, r);
4403 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4404 expect(0, r);
4405 }
4406 else
4407 {
4408 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4409 DestroyWindow(hwnd);
4410 return;
4411 }
4412
4413 DestroyWindow(hwnd);
4414
4415 /* test failure in parent WM_NOTIFYFORMAT */
4416 notifyFormat = 0;
4417 hwnd = create_listview_control(LVS_REPORT);
4418 ok(hwnd != NULL, "failed to create a listview window\n");
4419 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4420 ok(IsWindow(header), "expected header to be created\n");
4421 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4422 expect(0, r);
4423 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4424 ok( r == 1, "Expected 1, got %d\n", r );
4425 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4426 ok(r != 0, "Expected valid format\n");
4427
4428 notifyFormat = NFR_UNICODE;
4429 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4430 expect(NFR_UNICODE, r);
4431 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4432 expect(1, r);
4433 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4434 ok( r == 1, "Expected 1, got %d\n", r );
4435
4436 notifyFormat = NFR_ANSI;
4437 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4438 expect(NFR_ANSI, r);
4439 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4440 expect(0, r);
4441 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4442 ok( r == 1, "Expected 1, got %d\n", r );
4443
4444 DestroyWindow(hwnd);
4445
4446 hwndparentW = create_parent_window(TRUE);
4447 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
4448 if (!IsWindow(hwndparentW)) return;
4449
4450 notifyFormat = -1;
4451 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4452 ok(hwnd != NULL, "failed to create a listview window\n");
4453 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4454 ok(IsWindow(header), "expected header to be created\n");
4455 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4456 expect(1, r);
4457 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4458 expect(1, r);
4459 DestroyWindow(hwnd);
4460 /* receiving error code defaulting to ansi */
4461 notifyFormat = 0;
4462 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4463 ok(hwnd != NULL, "failed to create a listview window\n");
4464 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4465 ok(IsWindow(header), "expected header to be created\n");
4466 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4467 expect(0, r);
4468 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4469 expect(1, r);
4470 DestroyWindow(hwnd);
4471 /* receiving ansi code from unicode window, use it */
4472 notifyFormat = NFR_ANSI;
4473 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4474 ok(hwnd != NULL, "failed to create a listview window\n");
4475 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4476 ok(IsWindow(header), "expected header to be created\n");
4477 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4478 expect(0, r);
4479 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4480 expect(1, r);
4481 DestroyWindow(hwnd);
4482 /* unicode listview with ansi parent window */
4483 notifyFormat = -1;
4484 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4485 ok(hwnd != NULL, "failed to create a listview window\n");
4486 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4487 ok(IsWindow(header), "expected header to be created\n");
4488 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4489 expect(0, r);
4490 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4491 expect(1, r);
4492 DestroyWindow(hwnd);
4493 /* unicode listview with ansi parent window, return error code */
4494 notifyFormat = 0;
4495 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4496 ok(hwnd != NULL, "failed to create a listview window\n");
4497 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4498 ok(IsWindow(header), "expected header to be created\n");
4499 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4500 expect(0, r);
4501 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4502 expect(1, r);
4503 DestroyWindow(hwnd);
4504
4505 DestroyWindow(hwndparentW);
4506 }
4507
4508 static void test_indentation(void)
4509 {
4510 HWND hwnd;
4511 LVITEMA item;
4512 DWORD r;
4513
4514 hwnd = create_listview_control(LVS_REPORT);
4515 ok(hwnd != NULL, "failed to create a listview window\n");
4516
4517 memset(&item, 0, sizeof(item));
4518 item.mask = LVIF_INDENT;
4519 item.iItem = 0;
4520 item.iIndent = I_INDENTCALLBACK;
4521 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4522 expect(0, r);
4523
4524 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4525
4526 item.iItem = 0;
4527 item.mask = LVIF_INDENT;
4528 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4529 expect(TRUE, r);
4530
4531 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
4532 "get indent dispinfo", FALSE);
4533
4534 DestroyWindow(hwnd);
4535 }
4536
4537 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
4538 {
4539 return 0;
4540 }
4541
4542 static BOOL is_below_comctl_5(void)
4543 {
4544 HWND hwnd;
4545 BOOL ret;
4546
4547 hwnd = create_listview_control(LVS_REPORT);
4548 ok(hwnd != NULL, "failed to create a listview window\n");
4549 insert_item(hwnd, 0);
4550
4551 ret = SendMessageA(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
4552
4553 DestroyWindow(hwnd);
4554
4555 return !ret;
4556 }
4557
4558 static void test_get_set_view(void)
4559 {
4560 HWND hwnd;
4561 DWORD ret;
4562 DWORD_PTR style;
4563
4564 /* test style->view mapping */
4565 hwnd = create_listview_control(LVS_REPORT);
4566 ok(hwnd != NULL, "failed to create a listview window\n");
4567
4568 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4569 expect(LV_VIEW_DETAILS, ret);
4570
4571 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4572 /* LVS_ICON == 0 */
4573 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4574 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4575 expect(LV_VIEW_ICON, ret);
4576
4577 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4578 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4579 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4580 expect(LV_VIEW_SMALLICON, ret);
4581
4582 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4583 SetWindowLongPtrA(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4584 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4585 expect(LV_VIEW_LIST, ret);
4586
4587 /* switching view doesn't touch window style */
4588 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4589 expect(1, ret);
4590 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4591 ok(style & LVS_LIST, "Expected style to be preserved\n");
4592 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4593 expect(1, ret);
4594 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4595 ok(style & LVS_LIST, "Expected style to be preserved\n");
4596 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4597 expect(1, ret);
4598 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4599 ok(style & LVS_LIST, "Expected style to be preserved\n");
4600
4601 /* now change window style to see if view is remapped */
4602 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4603 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SHOWSELALWAYS);
4604 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4605 expect(LV_VIEW_SMALLICON, ret);
4606
4607 DestroyWindow(hwnd);
4608 }
4609
4610 static void test_canceleditlabel(void)
4611 {
4612 HWND hwnd, hwndedit;
4613 DWORD ret;
4614 CHAR buff[10];
4615 LVITEMA itema;
4616 static CHAR test[] = "test";
4617 static const CHAR test1[] = "test1";
4618
4619 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4620 ok(hwnd != NULL, "failed to create a listview window\n");
4621
4622 insert_item(hwnd, 0);
4623
4624 /* try without edit created */
4625 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4626 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4627 expect(TRUE, ret);
4628 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4629 "cancel edit label without edit", FALSE);
4630
4631 /* cancel without data change */
4632 SetFocus(hwnd);
4633 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4634 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4635 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4636 expect(TRUE, ret);
4637 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4638
4639 /* cancel after data change */
4640 memset(&itema, 0, sizeof(itema));
4641 itema.pszText = test;
4642 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
4643 expect(TRUE, ret);
4644 SetFocus(hwnd);
4645 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4646 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4647 ret = SetWindowTextA(hwndedit, test1);
4648 expect(1, ret);
4649 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4650 expect(TRUE, ret);
4651 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4652 memset(&itema, 0, sizeof(itema));
4653 itema.pszText = buff;
4654 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4655 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&itema);
4656 expect(5, ret);
4657 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4658
4659 DestroyWindow(hwnd);
4660 }
4661
4662 static void test_mapidindex(void)
4663 {
4664 HWND hwnd;
4665 INT ret;
4666
4667 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4668 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4669 ok(hwnd != NULL, "failed to create a listview window\n");
4670 insert_item(hwnd, 0);
4671 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4672 expect(-1, ret);
4673 DestroyWindow(hwnd);
4674
4675 hwnd = create_listview_control(LVS_REPORT);
4676 ok(hwnd != NULL, "failed to create a listview window\n");
4677
4678 /* LVM_MAPINDEXTOID with invalid index */
4679 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4680 expect(-1, ret);
4681
4682 insert_item(hwnd, 0);
4683 insert_item(hwnd, 1);
4684
4685 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, -1, 0);
4686 expect(-1, ret);
4687 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 2, 0);
4688 expect(-1, ret);
4689
4690 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4691 expect(0, ret);
4692 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4693 expect(1, ret);
4694 /* remove 0 indexed item, id retained */
4695 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
4696 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4697 expect(1, ret);
4698 /* new id starts from previous value */
4699 insert_item(hwnd, 1);
4700 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4701 expect(2, ret);
4702
4703 /* get index by id */
4704 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4705 expect(-1, ret);
4706 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4707 expect(-1, ret);
4708 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4709 expect(0, ret);
4710 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4711 expect(1, ret);
4712
4713 DestroyWindow(hwnd);
4714 }
4715
4716 static void test_getitemspacing(void)
4717 {
4718 HWND hwnd;
4719 DWORD ret;
4720 INT cx, cy;
4721 HIMAGELIST himl40, himl80;
4722
4723 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4724 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4725
4726 /* LVS_ICON */
4727 hwnd = create_listview_control(LVS_ICON);
4728 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4729 expect(cx, LOWORD(ret));
4730 expect(cy, HIWORD(ret));
4731
4732 /* now try with icons */
4733 himl40 = ImageList_Create(40, 40, 0, 4, 4);
4734 ok(himl40 != NULL, "failed to create imagelist\n");
4735 himl80 = ImageList_Create(80, 80, 0, 4, 4);
4736 ok(himl80 != NULL, "failed to create imagelist\n");
4737 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4738 expect(0, ret);
4739
4740 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4741 /* spacing + icon size returned */
4742 expect(cx + 40, LOWORD(ret));
4743 expect(cy + 40, HIWORD(ret));
4744 /* try changing icon size */
4745 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl80);
4746
4747 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4748 /* spacing + icon size returned */
4749 expect(cx + 80, LOWORD(ret));
4750 expect(cy + 80, HIWORD(ret));
4751
4752 /* set own icon spacing */
4753 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(100, 100));
4754 expect(cx + 80, LOWORD(ret));
4755 expect(cy + 80, HIWORD(ret));
4756
4757 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4758 /* set size returned */
4759 expect(100, LOWORD(ret));
4760 expect(100, HIWORD(ret));
4761
4762 /* now change image list - icon spacing should be unaffected */
4763 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4764
4765 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4766 /* set size returned */
4767 expect(100, LOWORD(ret));
4768 expect(100, HIWORD(ret));
4769
4770 /* spacing = 0 - keep previous value */
4771 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(0, -1));
4772 expect(100, LOWORD(ret));
4773 expect(100, HIWORD(ret));
4774
4775 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4776 expect(100, LOWORD(ret));
4777
4778 expect(0xFFFF, HIWORD(ret));
4779
4780 if (sizeof(void*) == 8)
4781 {
4782 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4783 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, (DWORD)-1);
4784 expect(100, LOWORD(ret));
4785 expect(0xFFFF, HIWORD(ret));
4786
4787 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4788 expect(0xFFFF, LOWORD(ret));
4789 expect(0xFFFF, HIWORD(ret));
4790 }
4791 else
4792 {
4793 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4794 expect(100, LOWORD(ret));
4795 expect(0xFFFF, HIWORD(ret));
4796 }
4797 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4798 /* spacing + icon size returned */
4799 expect(cx + 40, LOWORD(ret));
4800 expect(cy + 40, HIWORD(ret));
4801
4802 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4803 ImageList_Destroy(himl80);
4804 DestroyWindow(hwnd);
4805 /* LVS_SMALLICON */
4806 hwnd = create_listview_control(LVS_SMALLICON);
4807 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4808 expect(cx, LOWORD(ret));
4809 expect(cy, HIWORD(ret));
4810
4811 /* spacing does not depend on selected view type */
4812 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4813 expect(0, ret);
4814
4815 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4816 /* spacing + icon size returned */
4817 expect(cx + 40, LOWORD(ret));
4818 expect(cy + 40, HIWORD(ret));
4819
4820 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4821 ImageList_Destroy(himl40);
4822 DestroyWindow(hwnd);
4823 /* LVS_REPORT */
4824 hwnd = create_listview_control(LVS_REPORT);
4825 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4826 expect(cx, LOWORD(ret));
4827 expect(cy, HIWORD(ret));
4828
4829 DestroyWindow(hwnd);
4830 /* LVS_LIST */
4831 hwnd = create_listview_control(LVS_LIST);
4832 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4833 expect(cx, LOWORD(ret));
4834 expect(cy, HIWORD(ret));
4835
4836 DestroyWindow(hwnd);
4837 }
4838
4839 static INT get_current_font_height(HWND listview)
4840 {
4841 TEXTMETRICA tm;
4842 HFONT hfont;
4843 HWND hwnd;
4844 HDC hdc;
4845
4846 hwnd = (HWND)SendMessageA(listview, LVM_GETHEADER, 0, 0);
4847 if (!hwnd)
4848 hwnd = listview;
4849
4850 hfont = (HFONT)SendMessageA(hwnd, WM_GETFONT, 0, 0);
4851 if (!hfont) {
4852 hdc = GetDC(hwnd);
4853 GetTextMetricsA(hdc, &tm);
4854 ReleaseDC(hwnd, hdc);
4855 }
4856 else {
4857 HFONT oldfont;
4858
4859 hdc = GetDC(0);
4860 oldfont = SelectObject(hdc, hfont);
4861 GetTextMetricsA(hdc, &tm);
4862 SelectObject(hdc, oldfont);
4863 ReleaseDC(0, hdc);
4864 }
4865
4866 return tm.tmHeight;
4867 }
4868
4869 static void test_getcolumnwidth(void)
4870 {
4871 HWND hwnd;
4872 INT ret;
4873 DWORD_PTR style;
4874 LVCOLUMNA col;
4875 LVITEMA itema;
4876 INT height;
4877
4878 /* default column width */
4879 hwnd = create_listview_control(LVS_ICON);
4880 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4881 expect(0, ret);
4882 style = GetWindowLongA(hwnd, GWL_STYLE);
4883 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_LIST);
4884 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4885 todo_wine expect(8, ret);
4886 style = GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_LIST;
4887 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_REPORT);
4888 col.mask = 0;
4889 ret = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4890 expect(0, ret);
4891 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4892 expect(10, ret);
4893 DestroyWindow(hwnd);
4894
4895 /* default column width with item added */
4896 hwnd = create_listview_control(LVS_LIST);
4897 memset(&itema, 0, sizeof(itema));
4898 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4899 ok(!ret, "got %d\n", ret);
4900 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4901 height = get_current_font_height(hwnd);
4902 ok((ret / height) >= 6, "got width %d, height %d\n", ret, height);
4903 DestroyWindow(hwnd);
4904 }
4905
4906 static void test_scrollnotify(void)
4907 {
4908 HWND hwnd;
4909 DWORD ret;
4910
4911 hwnd = create_listview_control(LVS_REPORT);
4912
4913 insert_column(hwnd, 0);
4914 insert_column(hwnd, 1);
4915 insert_item(hwnd, 0);
4916
4917 /* make it scrollable - resize */
4918 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4919 expect(TRUE, ret);
4920 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4921 expect(TRUE, ret);
4922
4923 /* try with dummy call */
4924 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4925 ret = SendMessageA(hwnd, LVM_SCROLL, 0, 0);
4926 expect(TRUE, ret);
4927 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4928 "scroll notify 1", TRUE);
4929
4930 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4931 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 0);
4932 expect(TRUE, ret);
4933 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4934 "scroll notify 2", TRUE);
4935
4936 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4937 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 1);
4938 expect(TRUE, ret);
4939 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4940 "scroll notify 3", TRUE);
4941
4942 DestroyWindow(hwnd);
4943 }
4944
4945 static void test_LVS_EX_TRANSPARENTBKGND(void)
4946 {
4947 HWND hwnd;
4948 DWORD ret;
4949 HDC hdc;
4950
4951 hwnd = create_listview_control(LVS_REPORT);
4952
4953 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4954 expect(TRUE, ret);
4955
4956 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4957 LVS_EX_TRANSPARENTBKGND);
4958
4959 ret = SendMessageA(hwnd, LVM_GETBKCOLOR, 0, 0);
4960 if (ret != CLR_NONE)
4961 {
4962 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4963 DestroyWindow(hwnd);
4964 return;
4965 }
4966
4967 /* try to set some back color and check this style bit */
4968 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4969 expect(TRUE, ret);
4970 ret = SendMessageA(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4971 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4972
4973 /* now test what this style actually does */
4974 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4975 LVS_EX_TRANSPARENTBKGND);
4976
4977 hdc = GetWindowDC(hwndparent);
4978
4979 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4980 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4981 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4982 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4983
4984 ReleaseDC(hwndparent, hdc);
4985
4986 DestroyWindow(hwnd);
4987 }
4988
4989 static void test_approximate_viewrect(void)
4990 {
4991 HWND hwnd;
4992 DWORD ret;
4993 HIMAGELIST himl;
4994 HBITMAP hbmp;
4995 LVITEMA itema;
4996 static CHAR test[] = "abracadabra, a very long item label";
4997
4998 hwnd = create_listview_control(LVS_ICON);
4999 himl = ImageList_Create(40, 40, 0, 4, 4);
5000 ok(himl != NULL, "failed to create imagelist\n");
5001 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
5002 ok(hbmp != NULL, "failed to create bitmap\n");
5003 ret = ImageList_Add(himl, hbmp, 0);
5004 expect(0, ret);
5005 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
5006 expect(0, ret);
5007
5008 itema.mask = LVIF_IMAGE;
5009 itema.iImage = 0;
5010 itema.iItem = 0;
5011 itema.iSubItem = 0;
5012 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
5013 expect(0, ret);
5014
5015 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
5016 if (ret == 0)
5017 {
5018 /* version 4.0 */
5019 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
5020 return;
5021 }
5022
5023 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
5024 expect(MAKELONG(77,827), ret);
5025
5026 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
5027 ok(ret != 0, "got 0\n");
5028
5029 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
5030 expect(MAKELONG(102,302), ret);
5031
5032 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
5033 expect(MAKELONG(52,52), ret);
5034
5035 itema.pszText = test;
5036 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
5037 expect(TRUE, ret);
5038 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
5039 expect(MAKELONG(52,52), ret);
5040
5041 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
5042 expect(MAKELONG(52,2), ret);
5043 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
5044 expect(MAKELONG(52,52), ret);
5045 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
5046 expect(MAKELONG(102,52), ret);
5047 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
5048 expect(MAKELONG(102,102), ret);
5049 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
5050 expect(MAKELONG(102,102), ret);
5051 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
5052 expect(MAKELONG(102,152), ret);
5053 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
5054 expect(MAKELONG(102,152), ret);
5055 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
5056 expect(MAKELONG(152,152), ret);
5057
5058 DestroyWindow(hwnd);
5059 }
5060
5061 static void test_finditem(void)
5062 {
5063 LVFINDINFOA fi;
5064 static char f[5];
5065 HWND hwnd;
5066 INT r;
5067
5068 hwnd = create_listview_control(LVS_REPORT);
5069 insert_item(hwnd, 0);
5070
5071 memset(&fi, 0, sizeof(fi));
5072
5073 /* full string search, inserted text was "foo" */
5074 strcpy(f, "foo");
5075 fi.flags = LVFI_STRING;
5076 fi.psz = f;
5077 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5078 expect(0, r);
5079 /* partial string search, inserted text was "foo" */
5080 strcpy(f, "fo");
5081 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5082 fi.psz = f;
5083 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5084 expect(0, r);
5085 /* partial string search, part after start char */
5086 strcpy(f, "oo");
5087 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5088 fi.psz = f;
5089 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5090 expect(-1, r);
5091
5092 /* try with LVFI_SUBSTRING */
5093 strcpy(f, "fo");
5094 fi.flags = LVFI_SUBSTRING;
5095 fi.psz = f;
5096 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5097 if (r == -1)
5098 {
5099 win_skip("LVFI_SUBSTRING not supported\n");
5100 DestroyWindow(hwnd);
5101 return;
5102 }
5103 expect(0, r);
5104 strcpy(f, "f");
5105 fi.flags = LVFI_SUBSTRING;
5106 fi.psz = f;
5107 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5108 expect(0, r);
5109 strcpy(f, "o");
5110 fi.flags = LVFI_SUBSTRING;
5111 fi.psz = f;
5112 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5113 expect(-1, r);
5114
5115 strcpy(f, "f");
5116 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
5117 fi.psz = f;
5118 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5119 expect(0, r);
5120
5121 DestroyWindow(hwnd);
5122 }
5123
5124 static void test_LVS_EX_HEADERINALLVIEWS(void)
5125 {
5126 HWND hwnd, header;
5127 DWORD style;
5128
5129 hwnd = create_listview_control(LVS_ICON);
5130
5131 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5132 LVS_EX_HEADERINALLVIEWS);
5133
5134 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5135 if (!IsWindow(header))
5136 {
5137 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
5138 DestroyWindow(hwnd);
5139 return;
5140 }
5141
5142 /* LVS_NOCOLUMNHEADER works as before */
5143 style = GetWindowLongA(hwnd, GWL_STYLE);
5144 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
5145 style = GetWindowLongA(header, GWL_STYLE);
5146 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
5147 style = GetWindowLongA(hwnd, GWL_STYLE);
5148 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
5149 style = GetWindowLongA(header, GWL_STYLE);
5150 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
5151
5152 /* try to remove style */
5153 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
5154 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5155 ok(IsWindow(header), "Expected header to be created\n");
5156 style = GetWindowLongA(header, GWL_STYLE);
5157 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
5158
5159 DestroyWindow(hwnd);
5160
5161 /* check other styles */
5162 hwnd = create_listview_control(LVS_LIST);
5163 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5164 LVS_EX_HEADERINALLVIEWS);
5165 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5166 ok(IsWindow(header), "Expected header to be created\n");
5167 DestroyWindow(hwnd);
5168
5169 hwnd = create_listview_control(LVS_SMALLICON);
5170 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5171 LVS_EX_HEADERINALLVIEWS);
5172 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5173 ok(IsWindow(header), "Expected header to be created\n");
5174 DestroyWindow(hwnd);
5175
5176 hwnd = create_listview_control(LVS_REPORT);
5177 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5178 LVS_EX_HEADERINALLVIEWS);
5179 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5180 ok(IsWindow(header), "Expected header to be created\n");
5181 DestroyWindow(hwnd);
5182 }
5183
5184 static void test_hover(void)
5185 {
5186 HWND hwnd, fg;
5187 DWORD r;
5188
5189 hwnd = create_listview_control(LVS_ICON);
5190 SetForegroundWindow(hwndparent);
5191 fg = GetForegroundWindow();
5192 if (fg != hwndparent)
5193 {
5194 skip("Window is not in the foreground. Skipping hover tests.\n");
5195 DestroyWindow(hwnd);
5196 return;
5197 }
5198
5199 /* test WM_MOUSEHOVER forwarding */
5200 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5201 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5202 expect(0, r);
5203 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
5204 g_block_hover = TRUE;
5205 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5206 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5207 expect(0, r);
5208 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
5209 g_block_hover = FALSE;
5210
5211 r = SendMessageA(hwnd, LVM_SETHOVERTIME, 0, 500);
5212 expect(HOVER_DEFAULT, r);
5213 r = SendMessageA(hwnd, LVM_GETHOVERTIME, 0, 0);
5214 expect(500, r);
5215
5216 DestroyWindow(hwnd);
5217 }
5218
5219 static void test_destroynotify(void)
5220 {
5221 HWND hwnd;
5222 BOOL ret;
5223
5224 hwnd = create_listview_control(LVS_REPORT);
5225 ok(hwnd != NULL, "failed to create listview window\n");
5226
5227 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5228 DestroyWindow(hwnd);
5229 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
5230
5231 /* same for ownerdata list */
5232 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5233 ok(hwnd != NULL, "failed to create listview window\n");
5234
5235 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5236 DestroyWindow(hwnd);
5237 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_destroy, "check destroy order, ownerdata", FALSE);
5238
5239 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5240 ok(hwnd != NULL, "failed to create listview window\n");
5241
5242 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5243 ret = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
5244 ok(ret == TRUE, "got %d\n", ret);
5245 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_deleteall, "deleteall ownerdata", FALSE);
5246 DestroyWindow(hwnd);
5247 }
5248
5249 static void test_header_notification(void)
5250 {
5251 static char textA[] = "newtext";
5252 HWND list, header;
5253 HDITEMA item;
5254 NMHEADERA nmh;
5255 LVCOLUMNA col;
5256 DWORD ret;
5257 BOOL r;
5258
5259 list = create_listview_control(LVS_REPORT);
5260 ok(list != NULL, "failed to create listview window\n");
5261
5262 memset(&col, 0, sizeof(col));
5263 col.mask = LVCF_WIDTH;
5264 col.cx = 100;
5265 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5266 expect(0, ret);
5267
5268 /* check list parent notification after header item changed,
5269 this test should be placed before header subclassing to avoid
5270 Listview -> Header messages to be logged */
5271 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5272
5273 col.mask = LVCF_TEXT;
5274 col.pszText = textA;
5275 r = SendMessageA(list, LVM_SETCOLUMNA, 0, (LPARAM)&col);
5276 expect(TRUE, r);
5277
5278 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_changed_seq,
5279 "header notify, listview", FALSE);
5280 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5281 "header notify, parent", FALSE);
5282
5283 header = subclass_header(list);
5284
5285 ret = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
5286 expect(1, ret);
5287
5288 memset(&item, 0, sizeof(item));
5289 item.mask = HDI_WIDTH;
5290 ret = SendMessageA(header, HDM_GETITEMA, 0, (LPARAM)&item);
5291 expect(1, ret);
5292 expect(100, item.cxy);
5293
5294 nmh.hdr.hwndFrom = header;
5295 nmh.hdr.idFrom = GetWindowLongPtrA(header, GWLP_ID);
5296 nmh.hdr.code = HDN_ITEMCHANGEDA;
5297 nmh.iItem = 0;
5298 nmh.iButton = 0;
5299 item.mask = HDI_WIDTH;
5300 item.cxy = 50;
5301 nmh.pitem = &item;
5302 ret = SendMessageA(list, WM_NOTIFY, 0, (LPARAM)&nmh);
5303 expect(0, ret);
5304
5305 DestroyWindow(list);
5306 }
5307
5308 static void test_header_notification2(void)
5309 {
5310 static char textA[] = "newtext";
5311 HWND list, header;
5312 HDITEMW itemW;
5313 NMHEADERW nmhdr;
5314 LVCOLUMNA col;
5315 DWORD ret;
5316 WCHAR buffer[100];
5317 struct message parent_header_notify_seq[] = {
5318 { WM_NOTIFY, sent|id, 0, 0, 0 },
5319 { 0 }
5320 };
5321
5322 list = create_listview_control(LVS_REPORT);
5323 ok(list != NULL, "failed to create listview window\n");
5324
5325 memset(&col, 0, sizeof(col));
5326 col.mask = LVCF_WIDTH | LVCF_TEXT;
5327 col.cx = 100;
5328 col.pszText = textA;
5329 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5330 expect(0, ret);
5331
5332 header = (HWND)SendMessageA(list, LVM_GETHEADER, 0, 0);
5333 ok(header != 0, "No header\n");
5334 memset(&itemW, 0, sizeof(itemW));
5335 itemW.mask = HDI_WIDTH | HDI_ORDER | HDI_TEXT;
5336 itemW.pszText = buffer;
5337 itemW.cchTextMax = sizeof(buffer);
5338 ret = SendMessageW(header, HDM_GETITEMW, 0, (LPARAM)&itemW);
5339 expect(1, ret);
5340
5341 nmhdr.hdr.hwndFrom = header;
5342 nmhdr.hdr.idFrom = GetWindowLongPtrW(header, GWLP_ID);
5343 nmhdr.iItem = 0;
5344 nmhdr.iButton = 0;
5345 nmhdr.pitem = &itemW;
5346
5347 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5348 nmhdr.hdr.code = HDN_ITEMCHANGINGW;
5349 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5350 ok(ret == 0, "got %d\n", ret);
5351 parent_header_notify_seq[0].id = HDN_ITEMCHANGINGA;
5352 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5353 "header notify, parent", TRUE);
5354 todo_wine
5355 ok(nmhdr.hdr.code == HDN_ITEMCHANGINGA, "Expected ANSI notification code\n");
5356 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5357 nmhdr.hdr.code = HDN_ITEMCHANGEDW;
5358 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5359 ok(ret == 0, "got %d\n", ret);
5360 parent_header_notify_seq[0].id = HDN_ITEMCHANGEDA;
5361 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5362 "header notify, parent", TRUE);
5363 todo_wine
5364 ok(nmhdr.hdr.code == HDN_ITEMCHANGEDA, "Expected ANSI notification code\n");
5365 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5366 SetFocus(list);
5367 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5368 nmhdr.hdr.code = HDN_ITEMCLICKW;
5369 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5370 ok(ret == 0, "got %d\n", ret);
5371 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_click_seq,
5372 "header notify, parent", FALSE);
5373 ok(nmhdr.hdr.code == HDN_ITEMCLICKA, "Expected ANSI notification code\n");
5374 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5375 nmhdr.hdr.code = HDN_ITEMDBLCLICKW;
5376 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5377 ok(ret == 0, "got %d\n", ret);
5378 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5379 "header notify, parent", FALSE);
5380 ok(nmhdr.hdr.code == HDN_ITEMDBLCLICKW, "Expected Unicode notification code\n");
5381 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5382 nmhdr.hdr.code = HDN_DIVIDERDBLCLICKW;
5383 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5384 ok(ret == 0, "got %d\n", ret);
5385 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_divider_dclick_seq,
5386 "header notify, parent", TRUE);
5387 ok(nmhdr.hdr.code == HDN_DIVIDERDBLCLICKA, "Expected ANSI notification code\n");
5388 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5389 nmhdr.hdr.code = HDN_BEGINTRACKW;
5390 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5391 ok(ret == 0, "got %d\n", ret);
5392 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5393 "header notify, parent", FALSE);
5394 ok(nmhdr.hdr.code == HDN_BEGINTRACKW, "Expected Unicode notification code\n");
5395 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5396 nmhdr.hdr.code = HDN_ENDTRACKW;
5397 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5398 ok(ret == 0, "got %d\n", ret);
5399 parent_header_notify_seq[0].id = HDN_ENDTRACKA;
5400 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5401 "header notify, parent", FALSE);
5402 ok(nmhdr.hdr.code == HDN_ENDTRACKA, "Expected ANSI notification code\n");
5403 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5404 nmhdr.hdr.code = HDN_TRACKW;
5405 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5406 ok(ret == 0, "got %d\n", ret);
5407 parent_header_notify_seq[0].id = HDN_TRACKA;
5408 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5409 "header notify, parent", FALSE);
5410 ok(nmhdr.hdr.code == HDN_TRACKA, "Expected ANSI notification code\n");
5411 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5412 nmhdr.hdr.code = HDN_BEGINDRAG;
5413 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5414 ok(ret == 1, "got %d\n", ret);
5415 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5416 "header notify, parent", FALSE);
5417 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5418 nmhdr.hdr.code = HDN_ENDDRAG;
5419 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5420 ok(ret == 0, "got %d\n", ret);
5421 parent_header_notify_seq[0].id = HDN_ENDDRAG;
5422 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5423 "header notify, parent", FALSE);
5424 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5425 nmhdr.hdr.code = HDN_FILTERCHANGE;
5426 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5427 ok(ret == 0, "got %d\n", ret);
5428 parent_header_notify_seq[0].id = HDN_FILTERCHANGE;
5429 parent_header_notify_seq[0].flags |= optional; /* NT4 does not send this message */
5430 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5431 "header notify, parent", FALSE);
5432 parent_header_notify_seq[0].flags &= ~optional;
5433 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5434 nmhdr.hdr.code = HDN_BEGINFILTEREDIT;
5435 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5436 ok(ret == 0, "got %d\n", ret);
5437 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5438 "header notify, parent", FALSE);
5439 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5440 nmhdr.hdr.code = HDN_ENDFILTEREDIT;
5441 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5442 ok(ret == 0, "got %d\n", ret);
5443 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5444 "header notify, parent", FALSE);
5445 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5446 nmhdr.hdr.code = HDN_ITEMSTATEICONCLICK;
5447 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5448 ok(ret == 0, "got %d\n", ret);
5449 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5450 "header notify, parent", FALSE);
5451 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5452 nmhdr.hdr.code = HDN_ITEMKEYDOWN;
5453 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5454 ok(ret == 0, "got %d\n", ret);
5455 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5456 "header notify, parent", FALSE);
5457
5458 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5459
5460 DestroyWindow(list);
5461 }
5462
5463 static void test_createdragimage(void)
5464 {
5465 HIMAGELIST himl;
5466 POINT pt;
5467 HWND list;
5468
5469 list = create_listview_control(LVS_ICON);
5470 ok(list != NULL, "failed to create listview window\n");
5471
5472 insert_item(list, 0);
5473
5474 /* NULL point */
5475 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
5476 ok(himl == NULL, "got %p\n", himl);
5477
5478 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
5479 ok(himl != NULL, "got %p\n", himl);
5480 ImageList_Destroy(himl);
5481
5482 DestroyWindow(list);
5483 }
5484
5485 static void test_dispinfo(void)
5486 {
5487 static const char testA[] = "TEST";
5488 WCHAR buff[10];
5489 LVITEMA item;
5490 HWND hwnd;
5491 DWORD ret;
5492
5493 hwnd = create_listview_control(LVS_ICON);
5494 ok(hwnd != NULL, "failed to create listview window\n");
5495
5496 insert_item(hwnd, 0);
5497
5498 memset(&item, 0, sizeof(item));
5499 item.pszText = LPSTR_TEXTCALLBACKA;
5500 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5501 expect(1, ret);
5502
5503 g_disp_A_to_W = TRUE;
5504 item.pszText = (char*)buff;
5505 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
5506 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
5507 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
5508 g_disp_A_to_W = FALSE;
5509
5510 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
5511 "got %s, expected %s\n", item.pszText, testA);
5512
5513 DestroyWindow(hwnd);
5514 }
5515
5516 static void test_LVM_SETITEMTEXT(void)
5517 {
5518 static char testA[] = "TEST";
5519 LVITEMA item;
5520 HWND hwnd;
5521 DWORD ret;
5522
5523 hwnd = create_listview_control(LVS_ICON);
5524 ok(hwnd != NULL, "failed to create listview window\n");
5525
5526 insert_item(hwnd, 0);
5527
5528 /* null item pointer */
5529 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, 0);
5530 expect(FALSE, ret);
5531
5532 ret = SendMessageA(hwnd, LVM_SETITEMTEXTW, 0, 0);
5533 expect(FALSE, ret);
5534
5535 /* index out of bounds */
5536 item.pszText = testA;
5537 item.cchTextMax = 0; /* ignored */
5538 item.iSubItem = 0;
5539
5540 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 1, (LPARAM)&item);
5541 expect(FALSE, ret);
5542
5543 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, -1, (LPARAM)&item);
5544 expect(FALSE, ret);
5545
5546 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5547 expect(TRUE, ret);
5548
5549 DestroyWindow(hwnd);
5550 }
5551
5552 static void test_imagelists(void)
5553 {
5554 HWND hwnd, header;
5555 HIMAGELIST himl1, himl2, himl3;
5556 LRESULT ret;
5557
5558 himl1 = ImageList_Create(40, 40, 0, 4, 4);
5559 himl2 = ImageList_Create(40, 40, 0, 4, 4);
5560 himl3 = ImageList_Create(40, 40, 0, 4, 4);
5561 ok(himl1 != NULL, "Failed to create imagelist\n");
5562 ok(himl2 != NULL, "Failed to create imagelist\n");
5563 ok(himl3 != NULL, "Failed to create imagelist\n");
5564
5565 hwnd = create_listview_control(LVS_REPORT | LVS_SHAREIMAGELISTS);
5566 header = subclass_header(hwnd);
5567
5568 ok(header != NULL, "Expected header\n");
5569 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5570 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5571
5572 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5573
5574 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5575 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5576 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5577 "set normal image list", FALSE);
5578
5579 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5580
5581 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5582 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5583 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5584 "set state image list", TRUE);
5585
5586 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5587 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5588
5589 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5590
5591 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5592 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5593 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_set_imagelist,
5594 "set small image list", FALSE);
5595
5596 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5597 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5598 DestroyWindow(hwnd);
5599
5600 hwnd = create_listview_control(WS_VISIBLE | LVS_ICON);
5601
5602 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5603
5604 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5605 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5606 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5607 "set normal image list", FALSE);
5608
5609 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5610
5611 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5612 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5613 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5614 "set state image list", FALSE);
5615
5616 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5617
5618 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5619 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5620 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5621 "set small image list", FALSE);
5622
5623 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5624 ok(header == NULL, "Expected no header, got %p\n", header);
5625
5626 SetWindowLongPtrA(hwnd, GWL_STYLE, GetWindowLongPtrA(hwnd, GWL_STYLE) | LVS_REPORT);
5627
5628 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5629 ok(header != NULL, "Expected header, got NULL\n");
5630
5631 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5632 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5633
5634 DestroyWindow(hwnd);
5635 }
5636
5637 static void test_deleteitem(void)
5638 {
5639 LVITEMA item;
5640 UINT state;
5641 HWND hwnd;
5642 BOOL ret;
5643
5644 hwnd = create_listview_control(LVS_REPORT);
5645
5646 insert_item(hwnd, 0);
5647 insert_item(hwnd, 0);
5648 insert_item(hwnd, 0);
5649 insert_item(hwnd, 0);
5650 insert_item(hwnd, 0);
5651
5652 g_focus_test_LVN_DELETEITEM = TRUE;
5653
5654 /* delete focused item (not the last index) */
5655 item.stateMask = LVIS_FOCUSED;
5656 item.state = LVIS_FOCUSED;
5657 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
5658 ok(ret == TRUE, "got %d\n", ret);
5659 ret = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
5660 ok(ret == TRUE, "got %d\n", ret);
5661 /* next item gets focus */
5662 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5663 ok(state == LVIS_FOCUSED, "got %x\n", state);
5664
5665 /* focus last item and delete it */
5666 item.stateMask = LVIS_FOCUSED;
5667 item.state = LVIS_FOCUSED;
5668 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
5669 ok(ret == TRUE, "got %d\n", ret);
5670 ret = SendMessageA(hwnd, LVM_DELETEITEM, 3, 0);
5671 ok(ret == TRUE, "got %d\n", ret);
5672 /* new last item gets focus */
5673 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5674 ok(state == LVIS_FOCUSED, "got %x\n", state);
5675
5676 /* focus first item and delete it */
5677 item.stateMask = LVIS_FOCUSED;
5678 item.state = LVIS_FOCUSED;
5679 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
5680 ok(ret == TRUE, "got %d\n", ret);
5681 ret = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
5682 ok(ret == TRUE, "got %d\n", ret);
5683 /* new first item gets focus */
5684 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5685 ok(state == LVIS_FOCUSED, "got %x\n", state);
5686
5687 g_focus_test_LVN_DELETEITEM = FALSE;
5688
5689 DestroyWindow(hwnd);
5690 }
5691
5692 static void test_insertitem(void)
5693 {
5694 LVITEMA item;
5695 UINT state;
5696 HWND hwnd;
5697 INT ret;
5698
5699 hwnd = create_listview_control(LVS_REPORT);
5700
5701 /* insert item 0 focused */
5702 item.mask = LVIF_STATE;
5703 item.state = LVIS_FOCUSED;
5704 item.stateMask = LVIS_FOCUSED;
5705 item.iItem = 0;
5706 item.iSubItem = 0;
5707 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5708 ok(ret == 0, "got %d\n", ret);
5709
5710 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5711 ok(state == LVIS_FOCUSED, "got %x\n", state);
5712
5713 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5714
5715 /* insert item 1, focus shift */
5716 item.mask = LVIF_STATE;
5717 item.state = LVIS_FOCUSED;
5718 item.stateMask = LVIS_FOCUSED;
5719 item.iItem = 1;
5720 item.iSubItem = 0;
5721 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5722 ok(ret == 1, "got %d\n", ret);
5723
5724 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused_seq, "insert focused", TRUE);
5725
5726 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5727 ok(state == LVIS_FOCUSED, "got %x\n", state);
5728
5729 /* insert item 2, no focus shift */
5730 item.mask = LVIF_STATE;
5731 item.state = 0;
5732 item.stateMask = LVIS_FOCUSED;
5733 item.iItem = 2;
5734 item.iSubItem = 0;
5735 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5736 ok(ret == 2, "got %d\n", ret);
5737
5738 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5739 ok(state == LVIS_FOCUSED, "got %x\n", state);
5740
5741 DestroyWindow(hwnd);
5742 }
5743
5744 static void test_header_proc(void)
5745 {
5746 HWND hwnd, header, hdr;
5747 WNDPROC proc1, proc2;
5748
5749 hwnd = create_listview_control(LVS_REPORT);
5750
5751 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5752 ok(header != NULL, "got %p\n", header);
5753
5754 hdr = CreateWindowExA(0, WC_HEADERA, NULL,
5755 WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
5756 0, 0, 0, 0,
5757 NULL, NULL, NULL, NULL);
5758 ok(hdr != NULL, "got %p\n", hdr);
5759
5760 proc1 = (WNDPROC)GetWindowLongPtrW(header, GWLP_WNDPROC);
5761 proc2 = (WNDPROC)GetWindowLongPtrW(hdr, GWLP_WNDPROC);
5762 ok(proc1 == proc2, "got %p, expected %p\n", proc1, proc2);
5763
5764 DestroyWindow(hdr);
5765 DestroyWindow(hwnd);
5766 }
5767
5768 static void flush_events(void)
5769 {
5770 MSG msg;
5771 int diff = 200;
5772 int min_timeout = 100;
5773 DWORD time = GetTickCount() + diff;
5774
5775 while (diff > 0)
5776 {
5777 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
5778 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
5779 diff = time - GetTickCount();
5780 }
5781 }
5782
5783 static void test_oneclickactivate(void)
5784 {
5785 TRACKMOUSEEVENT track;
5786 char item1[] = "item1";
5787 LVITEMA item;
5788 HWND hwnd, fg;
5789 RECT rect;
5790 INT r;
5791 POINT orig_pos;
5792
5793 hwnd = CreateWindowExA(0, "SysListView32", "foo", WS_VISIBLE|WS_CHILD|LVS_LIST,
5794 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
5795 ok(hwnd != NULL, "failed to create listview window\n");
5796 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_ONECLICKACTIVATE);
5797 ok(r == 0, "should return zero\n");
5798
5799 SetForegroundWindow(hwndparent);
5800 flush_events();
5801 fg = GetForegroundWindow();
5802 if (fg != hwndparent)
5803 {
5804 skip("Window is not in the foreground. Skipping oneclickactivate tests.\n");
5805 DestroyWindow(hwnd);
5806 return;
5807 }
5808
5809 item.mask = LVIF_TEXT;
5810 item.iItem = 0;
5811 item.iSubItem = 0;
5812 item.iImage = 0;
5813 item.pszText = item1;
5814 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
5815 ok(r == 0, "should not fail\n");
5816
5817 GetWindowRect(hwnd, &rect);
5818 GetCursorPos(&orig_pos);
5819 SetCursorPos(rect.left+5, rect.top+5);
5820 flush_events();
5821 r = SendMessageA(hwnd, WM_MOUSEMOVE, MAKELONG(1, 1), 0);
5822 expect(0, r);
5823
5824 track.cbSize = sizeof(track);
5825 track.dwFlags = TME_QUERY;
5826 _TrackMouseEvent(&track);
5827 ok(track.hwndTrack == hwnd, "hwndTrack != hwnd\n");
5828 ok(track.dwFlags == TME_LEAVE, "dwFlags = %x\n", track.dwFlags);
5829
5830 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
5831 expect(0, r);
5832 r = SendMessageA(hwnd, WM_MOUSEHOVER, MAKELONG(1, 1), 0);
5833 expect(0, r);
5834 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
5835 expect(1, r);
5836
5837 DestroyWindow(hwnd);
5838 SetCursorPos(orig_pos.x, orig_pos.y);
5839 }
5840
5841 static void test_callback_mask(void)
5842 {
5843 DWORD mask;
5844 HWND hwnd;
5845 BOOL ret;
5846
5847 hwnd = create_listview_control(LVS_REPORT);
5848
5849 ret = SendMessageA(hwnd, LVM_SETCALLBACKMASK, ~0u, 0);
5850 ok(ret, "got %d\n", ret);
5851
5852 ret = SendMessageA(hwnd, LVM_SETCALLBACKMASK, ~0u, 1);
5853 ok(ret, "got %d\n", ret);
5854
5855 mask = SendMessageA(hwnd, LVM_GETCALLBACKMASK, 0, 0);
5856 ok(mask == ~0u, "got 0x%08x\n", mask);
5857
5858 DestroyWindow(hwnd);
5859 }
5860
5861 START_TEST(listview)
5862 {
5863 HMODULE hComctl32;
5864 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
5865
5866 ULONG_PTR ctx_cookie;
5867 HANDLE hCtx;
5868
5869 hComctl32 = GetModuleHandleA("comctl32.dll");
5870 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
5871 if (pInitCommonControlsEx)
5872 {
5873 INITCOMMONCONTROLSEX iccex;
5874 iccex.dwSize = sizeof(iccex);
5875 iccex.dwICC = ICC_LISTVIEW_CLASSES;
5876 pInitCommonControlsEx(&iccex);
5877 }
5878 else
5879 InitCommonControls();
5880
5881 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
5882
5883 hwndparent = create_parent_window(FALSE);
5884 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5885
5886 g_is_below_5 = is_below_comctl_5();
5887
5888 test_header_notification();
5889 test_header_notification2();
5890 test_images();
5891 test_checkboxes();
5892 test_items();
5893 test_create();
5894 test_redraw();
5895 test_customdraw();
5896 test_icon_spacing();
5897 test_color();
5898 test_item_count();
5899 test_item_position();
5900 test_columns();
5901 test_getorigin();
5902 test_multiselect();
5903 test_getitemrect();
5904 test_subitem_rect();
5905 test_sorting();
5906 test_ownerdata();
5907 test_norecompute();
5908 test_nosortheader();
5909 test_setredraw();
5910 test_hittest();
5911 test_getviewrect();
5912 test_getitemposition();
5913 test_columnscreation();
5914 test_editbox();
5915 test_notifyformat();
5916 test_indentation();
5917 test_getitemspacing();
5918 test_getcolumnwidth();
5919 test_approximate_viewrect();
5920 test_finditem();
5921 test_hover();
5922 test_destroynotify();
5923 test_createdragimage();
5924 test_dispinfo();
5925 test_LVM_SETITEMTEXT();
5926 test_imagelists();
5927 test_deleteitem();
5928 test_insertitem();
5929 test_header_proc();
5930 test_oneclickactivate();
5931 test_callback_mask();
5932
5933 if (!load_v6_module(&ctx_cookie, &hCtx))
5934 {
5935 DestroyWindow(hwndparent);
5936 return;
5937 }
5938
5939 /* comctl32 version 6 tests start here */
5940 test_get_set_view();
5941 test_canceleditlabel();
5942 test_mapidindex();
5943 test_scrollnotify();
5944 test_LVS_EX_TRANSPARENTBKGND();
5945 test_LVS_EX_HEADERINALLVIEWS();
5946 test_deleteitem();
5947 test_multiselect();
5948 test_insertitem();
5949 test_header_proc();
5950
5951 unload_v6_module(ctx_cookie, hCtx);
5952
5953 DestroyWindow(hwndparent);
5954 }