comctl32: Prevent invalid focus change notifications from LVS_OWNERDATA lists.
[wine.git] / dlls / comctl32 / tests / listview.c
bloba6910d2b9858ca2368d9134aca92048ec025232f
1 /*
2 * ListView tests
4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009-2014 Nikolay Sivov
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.
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.
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
23 #include <stdio.h>
24 #include <windows.h>
25 #include <commctrl.h>
27 #include "wine/test.h"
28 #include "v6util.h"
29 #include "msg.h"
31 enum seq_index {
32 PARENT_SEQ_INDEX,
33 PARENT_FULL_SEQ_INDEX,
34 PARENT_CD_SEQ_INDEX,
35 LISTVIEW_SEQ_INDEX,
36 EDITBOX_SEQ_INDEX,
37 COMBINED_SEQ_INDEX,
38 NUM_MSG_SEQUENCES
41 #define LISTVIEW_ID 0
42 #define HEADER_ID 1
44 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
45 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
46 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
48 static const WCHAR testparentclassW[] =
49 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
51 static HWND hwndparent, hwndparentW;
52 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
53 static BOOL blockEdit;
54 /* return nonzero on NM_HOVER */
55 static BOOL g_block_hover;
56 /* notification data for LVN_ITEMCHANGED */
57 static NMLISTVIEW g_nmlistview;
58 /* notification data for LVN_ITEMCHANGING */
59 static NMLISTVIEW g_nmlistview_changing;
60 /* format reported to control:
61 -1 falls to defproc, anything else returned */
62 static INT notifyFormat;
63 /* indicates we're running < 5.80 version */
64 static BOOL g_is_below_5;
65 /* item data passed to LVN_GETDISPINFOA */
66 static LVITEMA g_itema;
67 /* alter notification code A->W */
68 static BOOL g_disp_A_to_W;
69 /* dispinfo data sent with LVN_LVN_ENDLABELEDIT */
70 static NMLVDISPINFOA g_editbox_disp_info;
71 /* when this is set focus will be tested on LVN_DELETEITEM */
72 static BOOL g_focus_test_LVN_DELETEITEM;
74 static HWND subclass_editbox(HWND hwndListview);
76 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
78 static const struct message create_ownerdrawfixed_parent_seq[] = {
79 { WM_NOTIFYFORMAT, sent },
80 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
81 { WM_MEASUREITEM, sent },
82 { WM_PARENTNOTIFY, sent },
83 { 0 }
86 static const struct message redraw_listview_seq[] = {
87 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
88 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
89 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
90 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
91 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
92 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
93 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
94 { 0 }
97 static const struct message listview_icon_spacing_seq[] = {
98 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
99 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
100 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
101 { 0 }
104 static const struct message listview_color_seq[] = {
105 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
106 { LVM_GETBKCOLOR, sent },
107 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
108 { LVM_GETTEXTCOLOR, sent },
109 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
110 { LVM_GETTEXTBKCOLOR, sent },
112 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
113 { LVM_GETBKCOLOR, sent },
114 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
115 { LVM_GETTEXTCOLOR, sent },
116 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
117 { LVM_GETTEXTBKCOLOR, sent },
119 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
120 { LVM_GETBKCOLOR, sent },
121 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
122 { LVM_GETTEXTCOLOR, sent },
123 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
124 { LVM_GETTEXTBKCOLOR, sent },
126 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
127 { LVM_GETBKCOLOR, sent },
128 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
129 { LVM_GETTEXTCOLOR, sent },
130 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
131 { LVM_GETTEXTBKCOLOR, sent },
132 { 0 }
135 static const struct message listview_item_count_seq[] = {
136 { LVM_GETITEMCOUNT, sent },
137 { LVM_INSERTITEMA, sent },
138 { LVM_INSERTITEMA, sent },
139 { LVM_INSERTITEMA, sent },
140 { LVM_GETITEMCOUNT, sent },
141 { LVM_DELETEITEM, sent|wparam, 2 },
142 { WM_NCPAINT, sent|optional },
143 { WM_ERASEBKGND, sent|optional },
144 { LVM_GETITEMCOUNT, sent },
145 { LVM_DELETEALLITEMS, sent },
146 { LVM_GETITEMCOUNT, sent },
147 { LVM_INSERTITEMA, sent },
148 { LVM_INSERTITEMA, sent },
149 { LVM_GETITEMCOUNT, sent },
150 { LVM_INSERTITEMA, sent },
151 { LVM_GETITEMCOUNT, sent },
152 { 0 }
155 static const struct message listview_itempos_seq[] = {
156 { LVM_INSERTITEMA, sent },
157 { LVM_INSERTITEMA, sent },
158 { LVM_INSERTITEMA, sent },
159 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
160 { WM_NCPAINT, sent|optional },
161 { WM_ERASEBKGND, sent|optional },
162 { LVM_GETITEMPOSITION, sent|wparam, 1 },
163 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
164 { LVM_GETITEMPOSITION, sent|wparam, 2 },
165 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
166 { LVM_GETITEMPOSITION, sent|wparam, 0 },
167 { 0 }
170 static const struct message listview_ownerdata_switchto_seq[] = {
171 { WM_STYLECHANGING, sent },
172 { WM_STYLECHANGED, sent },
173 { 0 }
176 static const struct message listview_getorderarray_seq[] = {
177 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
178 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
179 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 0, 0, LISTVIEW_ID },
180 { HDM_GETORDERARRAY, sent|id|wparam, 0, 0, HEADER_ID },
181 { 0 }
184 static const struct message listview_setorderarray_seq[] = {
185 { LVM_SETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
186 { HDM_SETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
187 { LVM_SETCOLUMNORDERARRAY, sent|id|wparam, 0, 0, LISTVIEW_ID },
188 { HDM_SETORDERARRAY, sent|id|wparam, 0, 0, HEADER_ID },
189 { 0 }
192 static const struct message empty_seq[] = {
193 { 0 }
196 static const struct message forward_erasebkgnd_parent_seq[] = {
197 { WM_ERASEBKGND, sent },
198 { 0 }
201 static const struct message ownerdata_select_focus_parent_seq[] = {
202 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
203 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
204 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
205 { 0 }
208 static const struct message ownerdata_setstate_all_parent_seq[] = {
209 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
210 { 0 }
213 static const struct message ownerdata_defocus_all_parent_seq[] = {
214 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
215 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
216 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
217 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
218 { 0 }
221 static const struct message ownerdata_deselect_all_parent_seq[] = {
222 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
223 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
224 { 0 }
227 static const struct message change_all_parent_seq[] = {
228 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
229 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
231 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
232 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
234 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
235 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
237 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
238 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
240 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
241 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
242 { 0 }
245 static const struct message changing_all_parent_seq[] = {
246 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
247 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
248 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
249 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
250 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
251 { 0 }
254 static const struct message textcallback_set_again_parent_seq[] = {
255 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
256 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
257 { 0 }
260 static const struct message single_getdispinfo_parent_seq[] = {
261 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
262 { 0 }
265 static const struct message getitemposition_seq1[] = {
266 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
267 { 0 }
270 static const struct message getitemposition_seq2[] = {
271 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
272 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
273 { 0 }
276 static const struct message getsubitemrect_seq[] = {
277 { LVM_GETSUBITEMRECT, sent|id|wparam, -1, 0, LISTVIEW_ID },
278 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
279 { LVM_GETSUBITEMRECT, sent|id|wparam, 0, 0, LISTVIEW_ID },
280 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
281 { LVM_GETSUBITEMRECT, sent|id|wparam, -10, 0, LISTVIEW_ID },
282 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
283 { LVM_GETSUBITEMRECT, sent|id|wparam, 20, 0, LISTVIEW_ID },
284 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
285 { 0 }
288 static const struct message editbox_create_pos[] = {
289 /* sequence sent after LVN_BEGINLABELEDIT */
290 /* next two are 4.7x specific */
291 { WM_WINDOWPOSCHANGING, sent },
292 { WM_WINDOWPOSCHANGED, sent|optional },
294 { WM_WINDOWPOSCHANGING, sent|optional },
295 { WM_NCCALCSIZE, sent },
296 { WM_WINDOWPOSCHANGED, sent },
297 { WM_MOVE, sent|defwinproc },
298 { WM_SIZE, sent|defwinproc },
299 /* the rest is todo, skipped in 4.7x */
300 { WM_WINDOWPOSCHANGING, sent|optional },
301 { WM_WINDOWPOSCHANGED, sent|optional },
302 { 0 }
305 static const struct message scroll_parent_seq[] = {
306 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
307 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
308 { 0 }
311 static const struct message setredraw_seq[] = {
312 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
313 { 0 }
316 static const struct message lvs_ex_transparentbkgnd_seq[] = {
317 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
318 { 0 }
321 static const struct message edit_end_nochange[] = {
322 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
323 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW }, /* todo */
324 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
325 { 0 }
328 static const struct message hover_parent[] = {
329 { WM_GETDLGCODE, sent }, /* todo_wine */
330 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
331 { 0 }
334 static const struct message listview_destroy[] = {
335 { 0x0090, sent|optional }, /* Vista */
336 { WM_PARENTNOTIFY, sent },
337 { WM_SHOWWINDOW, sent },
338 { WM_WINDOWPOSCHANGING, sent },
339 { WM_WINDOWPOSCHANGED, sent|optional },
340 { WM_DESTROY, sent },
341 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
342 { WM_NCDESTROY, sent },
343 { 0 }
346 static const struct message listview_ownerdata_destroy[] = {
347 { 0x0090, sent|optional }, /* Vista */
348 { WM_PARENTNOTIFY, sent },
349 { WM_SHOWWINDOW, sent },
350 { WM_WINDOWPOSCHANGING, sent },
351 { WM_WINDOWPOSCHANGED, sent|optional },
352 { WM_DESTROY, sent },
353 { WM_NCDESTROY, sent },
354 { 0 }
357 static const struct message listview_ownerdata_deleteall[] = {
358 { LVM_DELETEALLITEMS, sent },
359 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
360 { 0 }
363 static const struct message listview_header_changed_seq[] = {
364 { LVM_SETCOLUMNA, sent },
365 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
366 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
367 { 0 }
370 static const struct message parent_header_click_seq[] = {
371 { WM_NOTIFY, sent|id, 0, 0, LVN_COLUMNCLICK },
372 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCLICKA },
373 { 0 }
376 static const struct message parent_header_divider_dclick_seq[] = {
377 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGINGA },
378 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
379 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
380 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGEDA },
381 { WM_NOTIFY, sent|id, 0, 0, HDN_DIVIDERDBLCLICKA },
382 { 0 }
385 static const struct message listview_set_imagelist[] = {
386 { LVM_SETIMAGELIST, sent|id, 0, 0, LISTVIEW_ID },
387 { 0 }
390 static const struct message listview_header_set_imagelist[] = {
391 { LVM_SETIMAGELIST, sent|id, 0, 0, LISTVIEW_ID },
392 { HDM_SETIMAGELIST, sent|id, 0, 0, HEADER_ID },
393 { 0 }
396 static const struct message parent_insert_focused_seq[] = {
397 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
398 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
399 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
400 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
401 { WM_NOTIFY, sent|id, 0, 0, LVN_INSERTITEM },
402 { 0 }
405 static const struct message parent_report_cd_seq[] = {
406 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_PREPAINT },
407 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT },
408 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT|CDDS_SUBITEM },
409 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT|CDDS_SUBITEM },
410 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT|CDDS_SUBITEM },
411 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT|CDDS_SUBITEM },
412 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT },
413 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_POSTPAINT },
414 { 0 }
417 static const struct message parent_list_cd_seq[] = {
418 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_PREPAINT },
419 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT },
420 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT },
421 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_POSTPAINT },
422 { 0 }
425 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
427 static LONG defwndproc_counter = 0;
428 LRESULT ret;
429 struct message msg;
431 msg.message = message;
432 msg.flags = sent|wparam|lparam;
433 if (defwndproc_counter) msg.flags |= defwinproc;
434 msg.wParam = wParam;
435 msg.lParam = lParam;
436 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
438 /* log system messages, except for painting */
439 if (message < WM_USER &&
440 message != WM_PAINT &&
441 message != WM_ERASEBKGND &&
442 message != WM_NCPAINT &&
443 message != WM_NCHITTEST &&
444 message != WM_GETTEXT &&
445 message != WM_GETICON &&
446 message != WM_DEVICECHANGE)
448 add_message(sequences, PARENT_SEQ_INDEX, &msg);
449 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
451 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
453 switch (message)
455 case WM_NOTIFY:
457 switch (((NMHDR*)lParam)->code)
459 case LVN_BEGINLABELEDITA:
461 HWND edit = NULL;
463 /* subclass edit box */
464 if (!blockEdit)
465 edit = subclass_editbox(((NMHDR*)lParam)->hwndFrom);
467 if (edit)
469 INT len = SendMessageA(edit, EM_GETLIMITTEXT, 0, 0);
470 ok(len == 259 || broken(len == 260) /* includes NULL in NT4 */,
471 "text limit %d, expected 259\n", len);
474 return blockEdit;
476 case LVN_ENDLABELEDITA:
478 HWND edit;
480 /* always accept new item text */
481 NMLVDISPINFOA *di = (NMLVDISPINFOA*)lParam;
482 g_editbox_disp_info = *di;
483 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText ? di->item.pszText : "(null)");
485 /* edit control still available from this notification */
486 edit = (HWND)SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETEDITCONTROL, 0, 0);
487 ok(IsWindow(edit), "expected valid edit control handle\n");
488 ok((GetWindowLongA(edit, GWL_STYLE) & ES_MULTILINE) == 0, "edit is multiline\n");
490 return TRUE;
492 case LVN_BEGINSCROLL:
493 case LVN_ENDSCROLL:
495 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
497 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
498 "BEGIN" : "END", pScroll->dx, pScroll->dy);
500 break;
501 case LVN_ITEMCHANGING:
503 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
504 g_nmlistview_changing = *nmlv;
506 break;
507 case LVN_ITEMCHANGED:
509 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
510 g_nmlistview = *nmlv;
512 break;
513 case LVN_GETDISPINFOA:
515 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
516 g_itema = dispinfo->item;
518 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
520 static const WCHAR testW[] = {'T','E','S','T',0};
521 dispinfo->hdr.code = LVN_GETDISPINFOW;
522 memcpy(dispinfo->item.pszText, testW, sizeof(testW));
525 /* test control buffer size for text, 10 used to mask cases when control
526 is using caller buffer to process LVM_GETITEM for example */
527 if (dispinfo->item.mask & LVIF_TEXT && dispinfo->item.cchTextMax > 10)
528 ok(dispinfo->item.cchTextMax == 260 ||
529 broken(dispinfo->item.cchTextMax == 264) /* NT4 reports aligned size */,
530 "buffer size %d\n", dispinfo->item.cchTextMax);
532 break;
533 case LVN_DELETEITEM:
534 if (g_focus_test_LVN_DELETEITEM)
536 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
537 UINT state;
539 state = SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETITEMSTATE, nmlv->iItem, LVIS_FOCUSED);
540 ok(state == 0, "got state %x\n", state);
542 break;
543 case NM_HOVER:
544 if (g_block_hover) return 1;
545 break;
547 break;
549 case WM_NOTIFYFORMAT:
551 /* force to return format */
552 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
553 break;
557 defwndproc_counter++;
558 ret = DefWindowProcA(hwnd, message, wParam, lParam);
559 defwndproc_counter--;
561 return ret;
564 static BOOL register_parent_wnd_class(BOOL Unicode)
566 WNDCLASSA clsA;
567 WNDCLASSW clsW;
569 if (Unicode)
571 clsW.style = 0;
572 clsW.lpfnWndProc = parent_wnd_proc;
573 clsW.cbClsExtra = 0;
574 clsW.cbWndExtra = 0;
575 clsW.hInstance = GetModuleHandleW(NULL);
576 clsW.hIcon = 0;
577 clsW.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
578 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
579 clsW.lpszMenuName = NULL;
580 clsW.lpszClassName = testparentclassW;
582 else
584 clsA.style = 0;
585 clsA.lpfnWndProc = parent_wnd_proc;
586 clsA.cbClsExtra = 0;
587 clsA.cbWndExtra = 0;
588 clsA.hInstance = GetModuleHandleA(NULL);
589 clsA.hIcon = 0;
590 clsA.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
591 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
592 clsA.lpszMenuName = NULL;
593 clsA.lpszClassName = "Listview test parent class";
596 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
599 static HWND create_parent_window(BOOL Unicode)
601 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
602 HWND hwnd;
604 if (!register_parent_wnd_class(Unicode))
605 return NULL;
607 blockEdit = FALSE;
608 notifyFormat = -1;
610 if (Unicode)
611 hwnd = CreateWindowExW(0, testparentclassW, nameW,
612 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
613 WS_MAXIMIZEBOX | WS_VISIBLE,
614 0, 0, 100, 100,
615 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
616 else
617 hwnd = CreateWindowExA(0, "Listview test parent class",
618 "Listview test parent window",
619 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
620 WS_MAXIMIZEBOX | WS_VISIBLE,
621 0, 0, 100, 100,
622 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
623 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
624 return hwnd;
627 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
629 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
630 static LONG defwndproc_counter = 0;
631 LRESULT ret;
632 struct message msg;
634 /* some debug output for style changing */
635 if ((message == WM_STYLECHANGING ||
636 message == WM_STYLECHANGED) && lParam)
638 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
639 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
642 msg.message = message;
643 msg.flags = sent|wparam|lparam;
644 if (defwndproc_counter) msg.flags |= defwinproc;
645 msg.wParam = wParam;
646 msg.lParam = lParam;
647 msg.id = LISTVIEW_ID;
648 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
649 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
651 defwndproc_counter++;
652 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
653 defwndproc_counter--;
654 return ret;
657 static HWND create_listview_control(DWORD style)
659 WNDPROC oldproc;
660 HWND hwnd;
661 RECT rect;
663 GetClientRect(hwndparent, &rect);
664 hwnd = CreateWindowExA(0, WC_LISTVIEWA, "foo",
665 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
666 0, 0, rect.right, rect.bottom,
667 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
668 ok(hwnd != NULL, "gle=%d\n", GetLastError());
670 if (!hwnd) return NULL;
672 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
673 (LONG_PTR)listview_subclass_proc);
674 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
676 return hwnd;
679 /* unicode listview window with specified parent */
680 static HWND create_listview_controlW(DWORD style, HWND parent)
682 WNDPROC oldproc;
683 HWND hwnd;
684 RECT rect;
685 static const WCHAR nameW[] = {'f','o','o',0};
687 GetClientRect(parent, &rect);
688 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
689 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
690 0, 0, rect.right, rect.bottom,
691 parent, NULL, GetModuleHandleW(NULL), NULL);
692 ok(hwnd != NULL, "gle=%d\n", GetLastError());
694 if (!hwnd) return NULL;
696 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
697 (LONG_PTR)listview_subclass_proc);
698 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
700 return hwnd;
703 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
705 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
706 static LONG defwndproc_counter = 0;
707 LRESULT ret;
708 struct message msg;
710 msg.message = message;
711 msg.flags = sent|wparam|lparam;
712 if (defwndproc_counter) msg.flags |= defwinproc;
713 msg.wParam = wParam;
714 msg.lParam = lParam;
715 msg.id = HEADER_ID;
716 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
718 defwndproc_counter++;
719 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
720 defwndproc_counter--;
721 return ret;
724 static HWND subclass_header(HWND hwndListview)
726 WNDPROC oldproc;
727 HWND hwnd;
729 hwnd = (HWND)SendMessageA(hwndListview, LVM_GETHEADER, 0, 0);
730 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
731 (LONG_PTR)header_subclass_proc);
732 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
734 return hwnd;
737 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
739 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
740 static LONG defwndproc_counter = 0;
741 LRESULT ret;
742 struct message msg;
744 msg.message = message;
745 msg.flags = sent|wparam|lparam;
746 if (defwndproc_counter) msg.flags |= defwinproc;
747 msg.wParam = wParam;
748 msg.lParam = lParam;
749 msg.id = 0;
751 /* all we need is sizing */
752 if (message == WM_WINDOWPOSCHANGING ||
753 message == WM_NCCALCSIZE ||
754 message == WM_WINDOWPOSCHANGED ||
755 message == WM_MOVE ||
756 message == WM_SIZE)
758 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
761 defwndproc_counter++;
762 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
763 defwndproc_counter--;
764 return ret;
767 static HWND subclass_editbox(HWND hwndListview)
769 WNDPROC oldproc;
770 HWND hwnd;
772 hwnd = (HWND)SendMessageA(hwndListview, LVM_GETEDITCONTROL, 0, 0);
773 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
774 (LONG_PTR)editbox_subclass_proc);
775 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
777 return hwnd;
780 /* Performs a single LVM_HITTEST test */
781 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
782 BOOL todo_item, BOOL todo_flags, int line)
784 LVHITTESTINFO lpht;
785 INT ret;
787 lpht.pt.x = x;
788 lpht.pt.y = y;
789 lpht.iSubItem = 10;
791 ret = SendMessageA(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
793 if (todo_item)
795 todo_wine
797 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
798 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
799 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
802 else
804 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
805 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
806 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
809 if (todo_flags)
811 todo_wine
812 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
814 else if (broken_flags)
815 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
816 "Expected flags %x, got %x\n", flags, lpht.flags);
817 else
818 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
821 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
823 /* Performs a single LVM_SUBITEMHITTEST test */
824 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
825 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
827 LVHITTESTINFO lpht;
828 INT ret;
830 lpht.pt.x = x;
831 lpht.pt.y = y;
833 ret = SendMessageA(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
835 if (todo_item)
837 todo_wine
839 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
840 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
843 else
845 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
846 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
849 if (todo_subitem)
851 todo_wine
852 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
854 else
855 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
857 if (todo_flags)
859 todo_wine
860 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
862 else
863 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
866 #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__)
868 static void test_images(void)
870 HWND hwnd;
871 INT r;
872 LVITEMA item;
873 HIMAGELIST himl;
874 HBITMAP hbmp;
875 RECT r1, r2;
876 static CHAR hello[] = "hello";
878 himl = ImageList_Create(40, 40, 0, 4, 4);
879 ok(himl != NULL, "failed to create imagelist\n");
881 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
882 ok(hbmp != NULL, "failed to create bitmap\n");
884 r = ImageList_Add(himl, hbmp, 0);
885 ok(r == 0, "should be zero\n");
887 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
888 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
889 ok(hwnd != NULL, "failed to create listview window\n");
891 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
892 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
894 ok(r == 0, "should return zero\n");
896 r = SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
897 ok(r == 0, "should return zero\n");
899 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
900 ok(r != 0, "got 0\n");
902 /* returns dimensions */
904 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
905 ok(r == 0, "should be zero items\n");
907 item.mask = LVIF_IMAGE | LVIF_TEXT;
908 item.iItem = 0;
909 item.iSubItem = 1;
910 item.iImage = 0;
911 item.pszText = 0;
912 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
913 ok(r == -1, "should fail\n");
915 item.iSubItem = 0;
916 item.pszText = hello;
917 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
918 ok(r == 0, "should not fail\n");
920 memset(&r1, 0, sizeof r1);
921 r1.left = LVIR_ICON;
922 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
923 expect(1, r);
925 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
926 ok(r == TRUE, "should not fail\n");
928 item.iSubItem = 0;
929 item.pszText = hello;
930 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
931 ok(r == 0, "should not fail\n");
933 memset(&r2, 0, sizeof r2);
934 r2.left = LVIR_ICON;
935 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
936 expect(1, r);
938 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
940 DestroyWindow(hwnd);
943 static void test_checkboxes(void)
945 HWND hwnd;
946 LVITEMA item;
947 DWORD r;
948 static CHAR text[] = "Text",
949 text2[] = "Text2",
950 text3[] = "Text3";
952 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
953 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
954 ok(hwnd != NULL, "failed to create listview window\n");
956 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
957 item.mask = LVIF_TEXT | LVIF_STATE;
958 item.stateMask = 0xffff;
959 item.state = 0xfccc;
960 item.iItem = 0;
961 item.iSubItem = 0;
962 item.pszText = text;
963 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
964 expect(0, r);
966 item.iItem = 0;
967 item.mask = LVIF_STATE;
968 item.stateMask = 0xffff;
969 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
970 expect(1, r);
971 ok(item.state == 0xfccc, "state %x\n", item.state);
973 /* Don't set LVIF_STATE */
974 item.mask = LVIF_TEXT;
975 item.stateMask = 0xffff;
976 item.state = 0xfccc;
977 item.iItem = 1;
978 item.iSubItem = 0;
979 item.pszText = text;
980 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
981 expect(1, r);
983 item.iItem = 1;
984 item.mask = LVIF_STATE;
985 item.stateMask = 0xffff;
986 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
987 expect(1, r);
988 ok(item.state == 0, "state %x\n", item.state);
990 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
991 expect(0, r);
993 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
994 item.iItem = 0;
995 item.mask = LVIF_STATE;
996 item.stateMask = 0xffff;
997 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
998 expect(1, r);
999 if (item.state != 0x1ccc)
1001 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
1002 DestroyWindow(hwnd);
1003 return;
1006 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
1007 item.iItem = 2;
1008 item.mask = LVIF_TEXT;
1009 item.state = 0;
1010 item.pszText = text2;
1011 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1012 expect(2, r);
1014 item.iItem = 2;
1015 item.mask = LVIF_STATE;
1016 item.stateMask = 0xffff;
1017 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1018 expect(1, r);
1019 ok(item.state == 0x1000, "state %x\n", item.state);
1021 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
1022 item.iItem = 3;
1023 item.mask = LVIF_TEXT | LVIF_STATE;
1024 item.stateMask = 0xffff;
1025 item.state = 0x2aaa;
1026 item.pszText = text3;
1027 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1028 expect(3, r);
1030 item.iItem = 3;
1031 item.mask = LVIF_STATE;
1032 item.stateMask = 0xffff;
1033 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1034 expect(1, r);
1035 ok(item.state == 0x1aaa, "state %x\n", item.state);
1037 /* Set an item's state to checked */
1038 item.iItem = 3;
1039 item.mask = LVIF_STATE;
1040 item.stateMask = 0xf000;
1041 item.state = 0x2000;
1042 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1043 expect(1, r);
1045 item.iItem = 3;
1046 item.mask = LVIF_STATE;
1047 item.stateMask = 0xffff;
1048 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1049 expect(1, r);
1050 ok(item.state == 0x2aaa, "state %x\n", item.state);
1052 /* Check that only the bits we asked for are returned,
1053 * and that all the others are set to zero
1055 item.iItem = 3;
1056 item.mask = LVIF_STATE;
1057 item.stateMask = 0xf000;
1058 item.state = 0xffff;
1059 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1060 expect(1, r);
1061 ok(item.state == 0x2000, "state %x\n", item.state);
1063 /* Set the style again and check that doesn't change an item's state */
1064 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1065 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1067 item.iItem = 3;
1068 item.mask = LVIF_STATE;
1069 item.stateMask = 0xffff;
1070 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1071 expect(1, r);
1072 ok(item.state == 0x2aaa, "state %x\n", item.state);
1074 /* Unsetting the checkbox extended style doesn't change an item's state */
1075 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
1076 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1078 item.iItem = 3;
1079 item.mask = LVIF_STATE;
1080 item.stateMask = 0xffff;
1081 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1082 expect(1, r);
1083 ok(item.state == 0x2aaa, "state %x\n", item.state);
1085 /* Now setting the style again will change an item's state */
1086 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1087 expect(0, r);
1089 item.iItem = 3;
1090 item.mask = LVIF_STATE;
1091 item.stateMask = 0xffff;
1092 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1093 expect(1, r);
1094 ok(item.state == 0x1aaa, "state %x\n", item.state);
1096 /* Toggle checkbox tests (bug 9934) */
1097 memset (&item, 0xcc, sizeof(item));
1098 item.mask = LVIF_STATE;
1099 item.iItem = 3;
1100 item.iSubItem = 0;
1101 item.state = LVIS_FOCUSED;
1102 item.stateMask = LVIS_FOCUSED;
1103 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1104 expect(1, r);
1106 item.iItem = 3;
1107 item.mask = LVIF_STATE;
1108 item.stateMask = 0xffff;
1109 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1110 expect(1, r);
1111 ok(item.state == 0x1aab, "state %x\n", item.state);
1113 r = SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1114 expect(0, r);
1115 r = SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
1116 expect(0, r);
1118 item.iItem = 3;
1119 item.mask = LVIF_STATE;
1120 item.stateMask = 0xffff;
1121 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1122 expect(1, r);
1123 ok(item.state == 0x2aab, "state %x\n", item.state);
1125 r = SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1126 expect(0, r);
1127 r = SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
1128 expect(0, r);
1130 item.iItem = 3;
1131 item.mask = LVIF_STATE;
1132 item.stateMask = 0xffff;
1133 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1134 expect(1, r);
1135 ok(item.state == 0x1aab, "state %x\n", item.state);
1137 DestroyWindow(hwnd);
1140 static void insert_column(HWND hwnd, int idx)
1142 LVCOLUMNA column;
1143 INT rc;
1145 memset(&column, 0xcc, sizeof(column));
1146 column.mask = LVCF_SUBITEM;
1147 column.iSubItem = idx;
1149 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, idx, (LPARAM)&column);
1150 expect(idx, rc);
1153 static void insert_item(HWND hwnd, int idx)
1155 static CHAR text[] = "foo";
1157 LVITEMA item;
1158 INT rc;
1160 memset(&item, 0xcc, sizeof (item));
1161 item.mask = LVIF_TEXT;
1162 item.iItem = idx;
1163 item.iSubItem = 0;
1164 item.pszText = text;
1166 rc = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
1167 expect(idx, rc);
1170 static void test_items(void)
1172 const LPARAM lparamTest = 0x42;
1173 static CHAR text[] = "Text";
1174 char buffA[5];
1175 HWND hwnd;
1176 LVITEMA item;
1177 DWORD r;
1179 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1180 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1181 ok(hwnd != NULL, "failed to create listview window\n");
1184 * Test setting/getting item params
1187 /* Set up two columns */
1188 insert_column(hwnd, 0);
1189 insert_column(hwnd, 1);
1191 /* LVIS_SELECTED with zero stateMask */
1192 /* set */
1193 memset (&item, 0, sizeof (item));
1194 item.mask = LVIF_STATE;
1195 item.state = LVIS_SELECTED;
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_SELECTED;
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_SELECTED, "Expected LVIS_SELECTED\n");
1211 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1213 /* LVIS_SELECTED with zero stateMask */
1214 /* set */
1215 memset (&item, 0, sizeof (item));
1216 item.mask = LVIF_STATE;
1217 item.state = LVIS_FOCUSED;
1218 item.stateMask = 0;
1219 item.iItem = 0;
1220 item.iSubItem = 0;
1221 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1222 expect(0, r);
1223 /* get */
1224 memset (&item, 0xcc, sizeof (item));
1225 item.mask = LVIF_STATE;
1226 item.stateMask = LVIS_FOCUSED;
1227 item.state = 0;
1228 item.iItem = 0;
1229 item.iSubItem = 0;
1230 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1231 expect(1, r);
1232 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1233 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1235 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1236 /* set */
1237 memset (&item, 0, sizeof (item));
1238 item.mask = LVIF_STATE;
1239 item.state = LVIS_CUT;
1240 item.stateMask = LVIS_FOCUSED;
1241 item.iItem = 0;
1242 item.iSubItem = 0;
1243 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1244 expect(0, r);
1245 /* get */
1246 memset (&item, 0xcc, sizeof (item));
1247 item.mask = LVIF_STATE;
1248 item.stateMask = LVIS_CUT;
1249 item.state = 0;
1250 item.iItem = 0;
1251 item.iSubItem = 0;
1252 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1253 expect(1, r);
1254 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1255 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1257 /* Insert an item with just a param */
1258 memset (&item, 0xcc, sizeof (item));
1259 item.mask = LVIF_PARAM;
1260 item.iItem = 0;
1261 item.iSubItem = 0;
1262 item.lParam = lparamTest;
1263 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1264 expect(0, r);
1266 /* Test getting of the param */
1267 memset (&item, 0xcc, sizeof (item));
1268 item.mask = LVIF_PARAM;
1269 item.iItem = 0;
1270 item.iSubItem = 0;
1271 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1272 expect(1, r);
1273 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1275 /* Set up a subitem */
1276 memset (&item, 0xcc, sizeof (item));
1277 item.mask = LVIF_TEXT;
1278 item.iItem = 0;
1279 item.iSubItem = 1;
1280 item.pszText = text;
1281 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1282 expect(1, r);
1284 item.mask = LVIF_TEXT;
1285 item.iItem = 0;
1286 item.iSubItem = 1;
1287 item.pszText = buffA;
1288 item.cchTextMax = sizeof(buffA);
1289 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1290 expect(1, r);
1291 ok(!memcmp(item.pszText, text, sizeof(text)), "got text %s, expected %s\n", item.pszText, text);
1293 /* set up with extra flag */
1294 /* 1. reset subitem text */
1295 item.mask = LVIF_TEXT;
1296 item.iItem = 0;
1297 item.iSubItem = 1;
1298 item.pszText = NULL;
1299 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1300 expect(1, r);
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(item.pszText[0] == 0, "got %p\n", item.pszText);
1312 /* 2. set new text with extra flag specified */
1313 item.mask = LVIF_TEXT | LVIF_DI_SETITEM;
1314 item.iItem = 0;
1315 item.iSubItem = 1;
1316 item.pszText = text;
1317 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1318 ok(r == 1 || broken(r == 0) /* NT4 */, "ret %d\n", r);
1320 if (r == 1)
1322 item.mask = LVIF_TEXT;
1323 item.iItem = 0;
1324 item.iSubItem = 1;
1325 item.pszText = buffA;
1326 buffA[0] = 'a';
1327 item.cchTextMax = sizeof(buffA);
1328 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1329 expect(1, r);
1330 ok(!memcmp(item.pszText, text, sizeof(text)), "got %s, expected %s\n", item.pszText, text);
1333 /* Query param from subitem: returns main item param */
1334 memset (&item, 0xcc, sizeof (item));
1335 item.mask = LVIF_PARAM;
1336 item.iItem = 0;
1337 item.iSubItem = 1;
1338 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1339 expect(1, r);
1340 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1342 /* Set up param on first subitem: no effect */
1343 memset (&item, 0xcc, sizeof (item));
1344 item.mask = LVIF_PARAM;
1345 item.iItem = 0;
1346 item.iSubItem = 1;
1347 item.lParam = lparamTest+1;
1348 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1349 expect(0, r);
1351 /* Query param from subitem again: should still return main item param */
1352 memset (&item, 0xcc, sizeof (item));
1353 item.mask = LVIF_PARAM;
1354 item.iItem = 0;
1355 item.iSubItem = 1;
1356 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1357 expect(1, r);
1358 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1360 /**** Some tests of state highlighting ****/
1361 memset (&item, 0xcc, sizeof (item));
1362 item.mask = LVIF_STATE;
1363 item.iItem = 0;
1364 item.iSubItem = 0;
1365 item.state = LVIS_SELECTED;
1366 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1367 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1368 expect(1, r);
1369 item.iSubItem = 1;
1370 item.state = LVIS_DROPHILITED;
1371 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1372 expect(1, r);
1374 memset (&item, 0xcc, sizeof (item));
1375 item.mask = LVIF_STATE;
1376 item.iItem = 0;
1377 item.iSubItem = 0;
1378 item.stateMask = -1;
1379 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1380 expect(1, r);
1381 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1382 item.iSubItem = 1;
1383 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1384 expect(1, r);
1385 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1387 /* some notnull but meaningless masks */
1388 memset (&item, 0, sizeof(item));
1389 item.mask = LVIF_NORECOMPUTE;
1390 item.iItem = 0;
1391 item.iSubItem = 0;
1392 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1393 expect(1, r);
1394 memset (&item, 0, sizeof(item));
1395 item.mask = LVIF_DI_SETITEM;
1396 item.iItem = 0;
1397 item.iSubItem = 0;
1398 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1399 expect(1, r);
1401 /* set text to callback value already having it */
1402 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
1403 expect(TRUE, r);
1404 memset (&item, 0, sizeof (item));
1405 item.mask = LVIF_TEXT;
1406 item.pszText = LPSTR_TEXTCALLBACKA;
1407 item.iItem = 0;
1408 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1409 expect(0, r);
1410 memset (&item, 0, sizeof (item));
1412 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1414 item.pszText = LPSTR_TEXTCALLBACKA;
1415 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0 , (LPARAM) &item);
1416 expect(TRUE, r);
1418 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1419 "check callback text comparison rule", FALSE);
1421 DestroyWindow(hwnd);
1424 static void test_columns(void)
1426 HWND hwnd, header;
1427 LVCOLUMNA column;
1428 LVITEMA item;
1429 INT order[2];
1430 CHAR buff[5];
1431 DWORD rc;
1433 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_LIST,
1434 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1435 ok(hwnd != NULL, "failed to create listview window\n");
1437 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
1438 ok(header == NULL, "got %p\n", header);
1440 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1441 ok(rc == 0, "got %d\n", rc);
1443 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
1444 ok(header == NULL, "got %p\n", header);
1446 DestroyWindow(hwnd);
1448 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1449 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1450 ok(hwnd != NULL, "failed to create listview window\n");
1452 /* Add a column with no mask */
1453 memset(&column, 0xcc, sizeof(column));
1454 column.mask = 0;
1455 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1456 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1458 /* Check its width */
1459 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1460 ok(rc == 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1462 DestroyWindow(hwnd);
1464 /* LVM_GETCOLUMNORDERARRAY */
1465 hwnd = create_listview_control(LVS_REPORT);
1466 subclass_header(hwnd);
1468 memset(&column, 0, sizeof(column));
1469 column.mask = LVCF_WIDTH;
1470 column.cx = 100;
1471 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1472 expect(0, rc);
1474 column.cx = 200;
1475 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1476 expect(1, rc);
1478 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1480 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1481 expect(1, rc);
1482 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1483 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1485 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 0, 0);
1486 expect(0, rc);
1488 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1490 /* LVM_SETCOLUMNORDERARRAY */
1491 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1493 order[0] = 0;
1494 order[1] = 1;
1495 rc = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1496 expect(1, rc);
1498 rc = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 0, 0);
1499 expect(0, rc);
1501 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_setorderarray_seq, "set order array", FALSE);
1503 /* after column added subitem is considered as present */
1504 insert_item(hwnd, 0);
1506 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1508 item.pszText = buff;
1509 item.cchTextMax = sizeof(buff);
1510 item.iItem = 0;
1511 item.iSubItem = 1;
1512 item.mask = LVIF_TEXT;
1513 memset(&g_itema, 0, sizeof(g_itema));
1514 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1515 expect(1, rc);
1516 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1518 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1519 "get subitem text after column added", FALSE);
1521 DestroyWindow(hwnd);
1524 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1525 static WNDPROC listviewWndProc;
1526 static HIMAGELIST test_create_imagelist;
1528 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1530 LRESULT ret;
1532 if (uMsg == WM_CREATE)
1534 CREATESTRUCTA *lpcs = (CREATESTRUCTA*)lParam;
1535 lpcs->style |= LVS_REPORT;
1537 ret = CallWindowProcA(listviewWndProc, hwnd, uMsg, wParam, lParam);
1538 if (uMsg == WM_CREATE) SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1539 return ret;
1542 static void test_create(void)
1544 HWND hList;
1545 HWND hHeader;
1546 LONG_PTR ret;
1547 LONG r;
1548 LVCOLUMNA col;
1549 RECT rect;
1550 WNDCLASSEXA cls;
1551 DWORD style;
1553 cls.cbSize = sizeof(WNDCLASSEXA);
1554 ok(GetClassInfoExA(GetModuleHandleA(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1555 listviewWndProc = cls.lpfnWndProc;
1556 cls.lpfnWndProc = create_test_wndproc;
1557 cls.lpszClassName = "MyListView32";
1558 ok(RegisterClassExA(&cls), "RegisterClassEx failed\n");
1560 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1561 hList = CreateWindowA("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1562 ok((HIMAGELIST)SendMessageA(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1563 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1565 if (!IsWindow(hHeader))
1567 /* version 4.0 */
1568 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1569 DestroyWindow(hList);
1570 return;
1573 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1574 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1575 DestroyWindow(hList);
1577 /* header isn't created on LVS_ICON and LVS_LIST styles */
1578 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1579 GetModuleHandleA(NULL), 0);
1580 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1581 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1582 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1583 /* insert column */
1584 memset(&col, 0, sizeof(LVCOLUMNA));
1585 col.mask = LVCF_WIDTH;
1586 col.cx = 100;
1587 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1588 expect(0, r);
1589 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1590 ok(IsWindow(hHeader), "Header should be created\n");
1591 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1592 style = GetWindowLongA(hHeader, GWL_STYLE);
1593 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1594 DestroyWindow(hList);
1596 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1597 GetModuleHandleA(NULL), 0);
1598 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1599 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1600 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1601 /* insert column */
1602 memset(&col, 0, sizeof(LVCOLUMNA));
1603 col.mask = LVCF_WIDTH;
1604 col.cx = 100;
1605 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1606 expect(0, r);
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);
1612 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1613 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1614 GetModuleHandleA(NULL), 0);
1615 ret = SetWindowLongPtrA(hList, GWL_STYLE, GetWindowLongPtrA(hList, GWL_STYLE) | LVS_REPORT);
1616 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1617 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1618 ok(IsWindow(hHeader), "Header should be created\n");
1619 ret = SetWindowLongPtrA(hList, GWL_STYLE, GetWindowLongA(hList, GWL_STYLE) & ~LVS_REPORT);
1620 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1621 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1622 ok(IsWindow(hHeader), "Header should be created\n");
1623 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1624 DestroyWindow(hList);
1626 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1627 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1628 GetModuleHandleA(NULL), 0);
1629 ret = SetWindowLongPtrA(hList, GWL_STYLE,
1630 (GetWindowLongPtrA(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1631 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1632 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1633 ok(IsWindow(hHeader), "Header should be created\n");
1634 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1635 ret = SetWindowLongPtrA(hList, GWL_STYLE,
1636 (GetWindowLongPtrA(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1637 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1638 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1639 ok(IsWindow(hHeader), "Header should be created\n");
1640 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1641 DestroyWindow(hList);
1643 /* LVS_REPORT without WS_VISIBLE */
1644 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1645 GetModuleHandleA(NULL), 0);
1646 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1647 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1648 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1649 /* insert column */
1650 memset(&col, 0, sizeof(LVCOLUMNA));
1651 col.mask = LVCF_WIDTH;
1652 col.cx = 100;
1653 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1654 expect(0, r);
1655 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1656 ok(IsWindow(hHeader), "Header should be created\n");
1657 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1658 DestroyWindow(hList);
1660 /* LVS_REPORT without WS_VISIBLE, try to show it */
1661 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1662 GetModuleHandleA(NULL), 0);
1663 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1664 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1665 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1666 ShowWindow(hList, SW_SHOW);
1667 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1668 ok(IsWindow(hHeader), "Header should be created\n");
1669 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1670 DestroyWindow(hList);
1672 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1673 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1674 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1675 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1676 ok(IsWindow(hHeader), "Header should be created\n");
1677 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1678 /* HDS_DRAGDROP set by default */
1679 ok(GetWindowLongPtrA(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1680 DestroyWindow(hList);
1682 /* setting LVS_EX_HEADERDRAGDROP 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_HEADERDRAGDROP);
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);
1696 /* setting LVS_EX_GRIDLINES 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_GRIDLINES);
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);
1710 /* setting LVS_EX_FULLROWSELECT creates header */
1711 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1712 GetModuleHandleA(NULL), 0);
1713 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1714 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1715 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1716 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
1717 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1718 ok(IsWindow(hHeader) ||
1719 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1720 "Header should be created\n");
1721 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1722 DestroyWindow(hList);
1724 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1725 hList = create_listview_control(LVS_ICON);
1726 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1727 r = SendMessageA(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1728 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1729 DestroyWindow(hList);
1731 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1732 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1733 GetModuleHandleA(NULL), 0);
1734 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1735 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1737 rect.left = LVIR_BOUNDS;
1738 rect.top = 1;
1739 rect.right = rect.bottom = -10;
1740 r = SendMessageA(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1741 /* right value contains garbage, probably because header columns are not set up */
1742 expect(0, rect.bottom);
1743 expect(1, r);
1745 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1746 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1747 ok(GetDlgItem(hList, 0) == NULL, "NULL dialog item expected\n");
1749 DestroyWindow(hList);
1751 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1752 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1753 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1754 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1755 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1756 DestroyWindow(hList);
1759 static void test_redraw(void)
1761 HWND hwnd;
1762 HDC hdc;
1763 BOOL res;
1764 DWORD r;
1766 hwnd = create_listview_control(LVS_REPORT);
1767 subclass_header(hwnd);
1769 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1771 InvalidateRect(hwnd, NULL, TRUE);
1772 UpdateWindow(hwnd);
1773 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1775 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1777 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1778 /* 1. Without backbuffer */
1779 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
1780 expect(TRUE, res);
1782 hdc = GetWindowDC(hwndparent);
1784 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1785 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1786 ok(r == 1, "Expected not zero result\n");
1787 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1788 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1790 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_DEFAULT);
1791 expect(TRUE, res);
1793 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1794 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1795 expect(1, r);
1796 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1797 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1799 /* 2. With backbuffer */
1800 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1801 LVS_EX_DOUBLEBUFFER);
1802 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
1803 expect(TRUE, res);
1805 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1806 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1807 expect(1, r);
1808 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1809 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1811 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_DEFAULT);
1812 expect(TRUE, res);
1814 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1815 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1816 todo_wine expect(1, r);
1817 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1818 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1820 ReleaseDC(hwndparent, hdc);
1822 DestroyWindow(hwnd);
1825 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1827 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1829 if(message == WM_NOTIFY) {
1830 NMHDR *nmhdr = (NMHDR*)lParam;
1831 if(nmhdr->code == NM_CUSTOMDRAW) {
1832 NMLVCUSTOMDRAW *nmlvcd = (NMLVCUSTOMDRAW*)nmhdr;
1833 struct message msg;
1835 msg.message = message;
1836 msg.flags = sent|wparam|lparam|custdraw;
1837 msg.wParam = wParam;
1838 msg.lParam = lParam;
1839 msg.id = nmhdr->code;
1840 msg.stage = nmlvcd->nmcd.dwDrawStage;
1841 add_message(sequences, PARENT_CD_SEQ_INDEX, &msg);
1843 switch(nmlvcd->nmcd.dwDrawStage) {
1844 case CDDS_PREPAINT:
1845 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1846 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1847 case CDDS_ITEMPREPAINT:
1848 nmlvcd->clrTextBk = CLR_DEFAULT;
1849 nmlvcd->clrText = RGB(0, 255, 0);
1850 return CDRF_NOTIFYSUBITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1851 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1852 clr = GetBkColor(nmlvcd->nmcd.hdc);
1853 ok(nmlvcd->clrTextBk == CLR_DEFAULT, "got 0x%x\n", nmlvcd->clrTextBk);
1854 ok(nmlvcd->clrText == RGB(0, 255, 0), "got 0x%x\n", nmlvcd->clrText);
1855 if (nmlvcd->iSubItem)
1856 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1857 else
1858 ok(clr == c0ffee, "clr=%.8x\n", clr);
1859 return CDRF_NOTIFYPOSTPAINT;
1860 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1861 clr = GetBkColor(nmlvcd->nmcd.hdc);
1862 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1863 ok(nmlvcd->clrTextBk == CLR_DEFAULT, "got 0x%x\n", nmlvcd->clrTextBk);
1864 ok(nmlvcd->clrText == RGB(0, 255, 0), "got 0x%x\n", nmlvcd->clrText);
1865 return CDRF_DODEFAULT;
1867 return CDRF_DODEFAULT;
1871 return DefWindowProcA(hwnd, message, wParam, lParam);
1874 static void test_customdraw(void)
1876 HWND hwnd;
1877 WNDPROC oldwndproc;
1879 hwnd = create_listview_control(LVS_REPORT);
1881 insert_column(hwnd, 0);
1882 insert_column(hwnd, 1);
1883 insert_item(hwnd, 0);
1885 oldwndproc = (WNDPROC)SetWindowLongPtrA(hwndparent, GWLP_WNDPROC,
1886 (LONG_PTR)cd_wndproc);
1888 InvalidateRect(hwnd, NULL, TRUE);
1889 UpdateWindow(hwnd);
1891 /* message tests */
1892 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1893 InvalidateRect(hwnd, NULL, TRUE);
1894 UpdateWindow(hwnd);
1895 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_report_cd_seq, "parent customdraw, LVS_REPORT", FALSE);
1897 DestroyWindow(hwnd);
1899 hwnd = create_listview_control(LVS_LIST);
1901 insert_column(hwnd, 0);
1902 insert_column(hwnd, 1);
1903 insert_item(hwnd, 0);
1905 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1906 InvalidateRect(hwnd, NULL, TRUE);
1907 UpdateWindow(hwnd);
1908 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_list_cd_seq, "parent customdraw, LVS_LIST", FALSE);
1910 SetWindowLongPtrA(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1911 DestroyWindow(hwnd);
1914 static void test_icon_spacing(void)
1916 /* LVM_SETICONSPACING */
1917 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1919 HWND hwnd;
1920 WORD w, h;
1921 INT r;
1923 hwnd = create_listview_control(LVS_ICON);
1924 ok(hwnd != NULL, "failed to create a listview window\n");
1926 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1927 expect(NFR_ANSI, r);
1929 /* reset the icon spacing to defaults */
1930 SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1932 /* now we can request what the defaults are */
1933 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1934 w = LOWORD(r);
1935 h = HIWORD(r);
1937 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1939 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1940 ok(r == MAKELONG(w, h) ||
1941 broken(r == MAKELONG(w, w)), /* win98 */
1942 "Expected %d, got %d\n", MAKELONG(w, h), r);
1944 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1945 if (r == 0)
1947 /* version 4.0 */
1948 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1949 DestroyWindow(hwnd);
1950 return;
1952 expect(MAKELONG(20,30), r);
1954 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1955 expect(MAKELONG(25,35), r);
1957 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1959 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1960 DestroyWindow(hwnd);
1963 static void test_color(void)
1965 RECT rect;
1966 HWND hwnd;
1967 DWORD r;
1968 int i;
1970 COLORREF color;
1971 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1973 hwnd = create_listview_control(LVS_REPORT);
1974 ok(hwnd != NULL, "failed to create a listview window\n");
1976 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1978 for (i = 0; i < 4; i++)
1980 color = colors[i];
1982 r = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, color);
1983 expect(TRUE, r);
1984 r = SendMessageA(hwnd, LVM_GETBKCOLOR, 0, 0);
1985 expect(color, r);
1987 r = SendMessageA(hwnd, LVM_SETTEXTCOLOR, 0, color);
1988 expect (TRUE, r);
1989 r = SendMessageA(hwnd, LVM_GETTEXTCOLOR, 0, 0);
1990 expect(color, r);
1992 r = SendMessageA(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1993 expect(TRUE, r);
1994 r = SendMessageA(hwnd, LVM_GETTEXTBKCOLOR, 0, 0);
1995 expect(color, r);
1998 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1999 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2001 /* invalidation test done separately to avoid a message chain mess */
2002 r = ValidateRect(hwnd, NULL);
2003 expect(TRUE, r);
2004 r = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, colors[0]);
2005 expect(TRUE, r);
2007 rect.right = rect.bottom = 1;
2008 r = GetUpdateRect(hwnd, &rect, TRUE);
2009 todo_wine expect(FALSE, r);
2010 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2012 r = ValidateRect(hwnd, NULL);
2013 expect(TRUE, r);
2014 r = SendMessageA(hwnd, LVM_SETTEXTCOLOR, 0, colors[0]);
2015 expect(TRUE, r);
2017 rect.right = rect.bottom = 1;
2018 r = GetUpdateRect(hwnd, &rect, TRUE);
2019 todo_wine expect(FALSE, r);
2020 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2022 r = ValidateRect(hwnd, NULL);
2023 expect(TRUE, r);
2024 r = SendMessageA(hwnd, LVM_SETTEXTBKCOLOR, 0, colors[0]);
2025 expect(TRUE, r);
2027 rect.right = rect.bottom = 1;
2028 r = GetUpdateRect(hwnd, &rect, TRUE);
2029 todo_wine expect(FALSE, r);
2030 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2032 DestroyWindow(hwnd);
2035 static void test_item_count(void)
2037 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
2039 HWND hwnd;
2040 DWORD r;
2041 HDC hdc;
2042 HFONT hOldFont;
2043 TEXTMETRICA tm;
2044 RECT rect;
2045 INT height;
2047 LVITEMA item0;
2048 LVITEMA item1;
2049 LVITEMA item2;
2050 static CHAR item0text[] = "item0";
2051 static CHAR item1text[] = "item1";
2052 static CHAR item2text[] = "item2";
2054 hwnd = create_listview_control(LVS_REPORT);
2055 ok(hwnd != NULL, "failed to create a listview window\n");
2057 /* resize in dpiaware manner to fit all 3 items added */
2058 hdc = GetDC(0);
2059 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
2060 GetTextMetricsA(hdc, &tm);
2061 /* 2 extra pixels for bounds and header border */
2062 height = tm.tmHeight + 2;
2063 SelectObject(hdc, hOldFont);
2064 ReleaseDC(0, hdc);
2066 GetWindowRect(hwnd, &rect);
2067 /* 3 items + 1 header + 1 to be sure */
2068 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
2070 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2072 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2073 expect(0, r);
2075 /* [item0] */
2076 item0.mask = LVIF_TEXT;
2077 item0.iItem = 0;
2078 item0.iSubItem = 0;
2079 item0.pszText = item0text;
2080 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item0);
2081 expect(0, r);
2083 /* [item0, item1] */
2084 item1.mask = LVIF_TEXT;
2085 item1.iItem = 1;
2086 item1.iSubItem = 0;
2087 item1.pszText = item1text;
2088 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2089 expect(1, r);
2091 /* [item0, item1, item2] */
2092 item2.mask = LVIF_TEXT;
2093 item2.iItem = 2;
2094 item2.iSubItem = 0;
2095 item2.pszText = item2text;
2096 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2097 expect(2, r);
2099 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2100 expect(3, r);
2102 /* [item0, item1] */
2103 r = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
2104 expect(TRUE, r);
2106 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2107 expect(2, r);
2109 /* [] */
2110 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
2111 expect(TRUE, r);
2113 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2114 expect(0, r);
2116 /* [item0] */
2117 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2118 expect(0, r);
2120 /* [item0, item1] */
2121 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2122 expect(1, r);
2124 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2125 expect(2, r);
2127 /* [item0, item1, item2] */
2128 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2129 expect(2, r);
2131 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2132 expect(3, r);
2134 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
2136 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2137 DestroyWindow(hwnd);
2140 static void test_item_position(void)
2142 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2144 HWND hwnd;
2145 DWORD r;
2146 POINT position;
2148 LVITEMA item0;
2149 LVITEMA item1;
2150 LVITEMA item2;
2151 static CHAR item0text[] = "item0";
2152 static CHAR item1text[] = "item1";
2153 static CHAR item2text[] = "item2";
2155 hwnd = create_listview_control(LVS_ICON);
2156 ok(hwnd != NULL, "failed to create a listview window\n");
2158 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2160 /* [item0] */
2161 item0.mask = LVIF_TEXT;
2162 item0.iItem = 0;
2163 item0.iSubItem = 0;
2164 item0.pszText = item0text;
2165 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item0);
2166 expect(0, r);
2168 /* [item0, item1] */
2169 item1.mask = LVIF_TEXT;
2170 item1.iItem = 1;
2171 item1.iSubItem = 0;
2172 item1.pszText = item1text;
2173 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2174 expect(1, r);
2176 /* [item0, item1, item2] */
2177 item2.mask = LVIF_TEXT;
2178 item2.iItem = 2;
2179 item2.iSubItem = 0;
2180 item2.pszText = item2text;
2181 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2182 expect(2, r);
2184 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
2185 expect(TRUE, r);
2186 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
2187 expect(TRUE, r);
2188 expect2(10, 5, position.x, position.y);
2190 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
2191 expect(TRUE, r);
2192 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
2193 expect(TRUE, r);
2194 expect2(0, 0, position.x, position.y);
2196 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
2197 expect(TRUE, r);
2198 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
2199 expect(TRUE, r);
2200 expect2(20, 20, position.x, position.y);
2202 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
2204 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2205 DestroyWindow(hwnd);
2208 static void test_getorigin(void)
2210 /* LVM_GETORIGIN */
2212 HWND hwnd;
2213 DWORD r;
2214 POINT position;
2216 position.x = position.y = 0;
2218 hwnd = create_listview_control(LVS_ICON);
2219 ok(hwnd != NULL, "failed to create a listview window\n");
2220 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2222 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2223 expect(TRUE, r);
2224 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2225 DestroyWindow(hwnd);
2227 hwnd = create_listview_control(LVS_SMALLICON);
2228 ok(hwnd != NULL, "failed to create a listview window\n");
2229 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2231 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2232 expect(TRUE, r);
2233 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2234 DestroyWindow(hwnd);
2236 hwnd = create_listview_control(LVS_LIST);
2237 ok(hwnd != NULL, "failed to create a listview window\n");
2238 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2240 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2241 expect(FALSE, r);
2242 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2243 DestroyWindow(hwnd);
2245 hwnd = create_listview_control(LVS_REPORT);
2246 ok(hwnd != NULL, "failed to create a listview window\n");
2247 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2249 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2250 expect(FALSE, r);
2251 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2252 DestroyWindow(hwnd);
2255 static void test_multiselect(void)
2257 typedef struct t_select_task
2259 const char *descr;
2260 int initPos;
2261 int loopVK;
2262 int count;
2263 int result;
2264 } select_task;
2266 HWND hwnd;
2267 INT r;
2268 int i,j,item_count,selected_count;
2269 static const int items=5;
2270 BYTE kstate[256];
2271 select_task task;
2272 LONG_PTR style;
2273 LVITEMA item;
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 }
2282 hwnd = create_listview_control(LVS_REPORT);
2284 for (i = 0; i < items; i++)
2285 insert_item(hwnd, 0);
2287 item_count = (int)SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2288 expect(items, item_count);
2290 for (i = 0; i < 4; i++) {
2291 LVITEMA item;
2293 task = task_list[i];
2295 /* deselect all items */
2296 item.state = 0;
2297 item.stateMask = LVIS_SELECTED;
2298 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2299 SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2301 /* set initial position */
2302 SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
2304 item.state = LVIS_SELECTED;
2305 item.stateMask = LVIS_SELECTED;
2306 SendMessageA(hwnd, LVM_SETITEMSTATE, task.initPos == -1 ? item_count-1 : task.initPos, (LPARAM)&item);
2308 selected_count = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2309 ok(selected_count == 1, "expected 1, got %d\n", selected_count);
2311 /* Set SHIFT key pressed */
2312 GetKeyboardState(kstate);
2313 kstate[VK_SHIFT]=0x80;
2314 SetKeyboardState(kstate);
2316 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
2317 r = SendMessageA(hwnd, WM_KEYDOWN, task.loopVK, 0);
2318 expect(0,r);
2319 r = SendMessageA(hwnd, WM_KEYUP, task.loopVK, 0);
2320 expect(0,r);
2323 selected_count = (int)SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2325 ok((task.result == -1 ? item_count : task.result) == selected_count, "Failed multiple selection %s. There should be %d selected items (is %d)\n", task.descr, item_count, selected_count);
2327 /* Set SHIFT key released */
2328 GetKeyboardState(kstate);
2329 kstate[VK_SHIFT]=0x00;
2330 SetKeyboardState(kstate);
2332 DestroyWindow(hwnd);
2334 /* make multiple selection, then switch to LVS_SINGLESEL */
2335 hwnd = create_listview_control(LVS_REPORT);
2336 for (i=0;i<items;i++) {
2337 insert_item(hwnd, 0);
2339 item_count = (int)SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2340 expect(items,item_count);
2342 /* try with NULL pointer */
2343 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
2344 expect(FALSE, r);
2346 /* select all, check notifications */
2347 item.state = 0;
2348 item.stateMask = LVIS_SELECTED;
2349 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2351 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2353 item.stateMask = LVIS_SELECTED;
2354 item.state = LVIS_SELECTED;
2355 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2356 expect(TRUE, r);
2358 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2359 "select all notification", FALSE);
2361 /* select all again (all selected already) */
2362 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2364 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2366 item.stateMask = LVIS_SELECTED;
2367 item.state = LVIS_SELECTED;
2368 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2369 expect(TRUE, r);
2371 ok(g_nmlistview_changing.uNewState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uNewState);
2372 ok(g_nmlistview_changing.uOldState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uOldState);
2373 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2375 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2376 "select all notification 2", FALSE);
2378 /* deselect all items */
2379 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2381 item.state = 0;
2382 item.stateMask = LVIS_SELECTED;
2383 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2385 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2386 "deselect all notification", FALSE);
2388 /* deselect all items again */
2389 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2390 item.state = 0;
2391 item.stateMask = LVIS_SELECTED;
2392 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2393 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "deselect all notification 2", FALSE);
2395 /* any non-zero state value does the same */
2396 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2398 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2400 item.stateMask = LVIS_SELECTED;
2401 item.state = LVIS_CUT;
2402 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2403 expect(TRUE, r);
2405 ok(g_nmlistview_changing.uNewState == 0, "got 0x%x\n", g_nmlistview_changing.uNewState);
2406 ok(g_nmlistview_changing.uOldState == 0, "got 0x%x\n", g_nmlistview_changing.uOldState);
2407 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2409 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2410 "set state all notification 3", FALSE);
2412 SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2413 for (i = 0; i < 3; i++) {
2414 item.state = LVIS_SELECTED;
2415 item.stateMask = LVIS_SELECTED;
2416 SendMessageA(hwnd, LVM_SETITEMSTATE, i, (LPARAM)&item);
2419 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2420 expect(3, r);
2421 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2422 expect(-1, r);
2424 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2425 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2426 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2427 /* check that style is accepted */
2428 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2429 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2431 for (i=0;i<3;i++) {
2432 r = SendMessageA(hwnd, LVM_GETITEMSTATE, i, LVIS_SELECTED);
2433 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2435 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2436 expect(3, r);
2437 SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2438 expect(3, r);
2440 /* select one more */
2441 item.state = LVIS_SELECTED;
2442 item.stateMask = LVIS_SELECTED;
2443 SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
2445 for (i=0;i<3;i++) {
2446 r = SendMessageA(hwnd, LVM_GETITEMSTATE, i, LVIS_SELECTED);
2447 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2450 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 3, LVIS_SELECTED);
2451 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2453 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2454 expect(1, r);
2455 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2456 expect(-1, r);
2458 /* try to select all on LVS_SINGLESEL */
2459 memset(&item, 0, sizeof(item));
2460 item.stateMask = LVIS_SELECTED;
2461 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2462 expect(TRUE, r);
2463 SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2465 item.stateMask = LVIS_SELECTED;
2466 item.state = LVIS_SELECTED;
2467 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2468 expect(FALSE, r);
2470 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2471 expect(0, r);
2472 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2473 expect(-1, r);
2475 /* try to deselect all on LVS_SINGLESEL */
2476 item.stateMask = LVIS_SELECTED;
2477 item.state = LVIS_SELECTED;
2478 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2479 expect(TRUE, r);
2481 item.stateMask = LVIS_SELECTED;
2482 item.state = 0;
2483 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2484 expect(TRUE, r);
2485 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2486 expect(0, r);
2488 /* 1. selection mark is update when new focused item is set */
2489 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2490 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2492 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2493 expect(-1, r);
2495 item.stateMask = LVIS_FOCUSED;
2496 item.state = LVIS_FOCUSED;
2497 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2498 expect(TRUE, r);
2500 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2501 expect(0, r);
2503 /* it's not updated if already set */
2504 item.stateMask = LVIS_FOCUSED;
2505 item.state = LVIS_FOCUSED;
2506 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2507 expect(TRUE, r);
2509 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2510 expect(0, r);
2512 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2513 expect(0, r);
2515 item.stateMask = LVIS_FOCUSED;
2516 item.state = LVIS_FOCUSED;
2517 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2518 expect(TRUE, r);
2520 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2521 expect(-1, r);
2523 /* need to reset focused item first */
2524 item.stateMask = LVIS_FOCUSED;
2525 item.state = 0;
2526 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2527 expect(TRUE, r);
2529 item.stateMask = LVIS_FOCUSED;
2530 item.state = LVIS_FOCUSED;
2531 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
2532 expect(TRUE, r);
2534 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2535 expect(2, r);
2537 item.stateMask = LVIS_FOCUSED;
2538 item.state = 0;
2539 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2540 expect(TRUE, r);
2542 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2543 expect(2, r);
2545 /* 2. same tests, with LVM_SETITEM */
2546 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2547 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2549 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2550 expect(2, r);
2552 item.stateMask = LVIS_FOCUSED;
2553 item.state = LVIS_FOCUSED;
2554 item.mask = LVIF_STATE;
2555 item.iItem = item.iSubItem = 0;
2556 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2557 expect(TRUE, r);
2559 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2560 expect(0, r);
2562 /* it's not updated if already set */
2563 item.stateMask = LVIS_FOCUSED;
2564 item.state = LVIS_FOCUSED;
2565 item.mask = LVIF_STATE;
2566 item.iItem = 1;
2567 item.iSubItem = 0;
2568 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2569 expect(TRUE, r);
2571 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2572 expect(0, r);
2574 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2575 expect(0, r);
2577 item.stateMask = LVIS_FOCUSED;
2578 item.state = LVIS_FOCUSED;
2579 item.mask = LVIF_STATE;
2580 item.iItem = 1;
2581 item.iSubItem = 0;
2582 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2583 expect(TRUE, r);
2585 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2586 expect(-1, r);
2588 /* need to reset focused item first */
2589 item.stateMask = LVIS_FOCUSED;
2590 item.state = 0;
2591 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2592 expect(TRUE, r);
2594 item.stateMask = LVIS_FOCUSED;
2595 item.state = LVIS_FOCUSED;
2596 item.mask = LVIF_STATE;
2597 item.iItem = 2;
2598 item.iSubItem = 0;
2599 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2600 expect(TRUE, r);
2602 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2603 expect(2, r);
2605 item.stateMask = LVIS_FOCUSED;
2606 item.state = 0;
2607 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2608 expect(TRUE, r);
2610 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2611 expect(2, r);
2613 DestroyWindow(hwnd);
2616 static void test_subitem_rect(void)
2618 HWND hwnd;
2619 DWORD r;
2620 LVCOLUMNA col;
2621 RECT rect, rect2;
2622 INT arr[3];
2624 /* test LVM_GETSUBITEMRECT for header */
2625 hwnd = create_listview_control(LVS_REPORT);
2626 ok(hwnd != NULL, "failed to create a listview window\n");
2627 /* add some columns */
2628 memset(&col, 0, sizeof(LVCOLUMNA));
2629 col.mask = LVCF_WIDTH;
2630 col.cx = 100;
2631 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
2632 expect(0, r);
2633 col.cx = 150;
2634 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&col);
2635 expect(1, r);
2636 col.cx = 200;
2637 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 2, (LPARAM)&col);
2638 expect(2, r);
2639 /* item = -1 means header, subitem index is 1 based */
2640 rect.left = LVIR_BOUNDS;
2641 rect.top = 0;
2642 rect.right = rect.bottom = 0;
2643 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2644 expect(0, r);
2646 rect.left = LVIR_BOUNDS;
2647 rect.top = 1;
2648 rect.right = rect.bottom = 0;
2649 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2650 expect(1, r);
2652 expect(100, rect.left);
2653 expect(250, rect.right);
2654 expect(3, rect.top);
2656 rect.left = LVIR_BOUNDS;
2657 rect.top = 2;
2658 rect.right = rect.bottom = 0;
2659 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2660 expect(1, r);
2662 expect(250, rect.left);
2663 expect(450, rect.right);
2664 expect(3, rect.top);
2666 /* item LVS_REPORT padding isn't applied to subitems */
2667 insert_item(hwnd, 0);
2669 rect.left = LVIR_BOUNDS;
2670 rect.top = 1;
2671 rect.right = rect.bottom = 0;
2672 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2673 expect(1, r);
2674 expect(100, rect.left);
2675 expect(250, rect.right);
2677 rect.left = LVIR_ICON;
2678 rect.top = 1;
2679 rect.right = rect.bottom = 0;
2680 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2681 expect(1, r);
2682 /* no icon attached - zero width rectangle, with no left padding */
2683 expect(100, rect.left);
2684 expect(100, rect.right);
2686 rect.left = LVIR_LABEL;
2687 rect.top = 1;
2688 rect.right = rect.bottom = 0;
2689 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2690 expect(1, r);
2691 /* same as full LVIR_BOUNDS */
2692 expect(100, rect.left);
2693 expect(250, rect.right);
2695 SendMessageA(hwnd, LVM_SCROLL, 10, 0);
2697 rect.left = LVIR_BOUNDS;
2698 rect.top = 1;
2699 rect.right = rect.bottom = 0;
2700 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2701 expect(1, r);
2702 expect(90, rect.left);
2703 expect(240, rect.right);
2705 SendMessageA(hwnd, LVM_SCROLL, -10, 0);
2707 /* test header interaction */
2708 subclass_header(hwnd);
2709 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2711 rect.left = LVIR_BOUNDS;
2712 rect.top = 1;
2713 rect.right = rect.bottom = 0;
2714 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2715 expect(1, r);
2717 rect.left = LVIR_BOUNDS;
2718 rect.top = 1;
2719 rect.right = rect.bottom = 0;
2720 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2721 expect(1, r);
2723 rect.left = LVIR_BOUNDS;
2724 rect.top = 1;
2725 rect.right = rect.bottom = 0;
2726 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -10, (LPARAM)&rect);
2727 expect(1, r);
2729 rect.left = LVIR_BOUNDS;
2730 rect.top = 1;
2731 rect.right = rect.bottom = 0;
2732 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 20, (LPARAM)&rect);
2733 expect(1, r);
2735 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getsubitemrect_seq, "LVM_GETSUBITEMRECT negative index", FALSE);
2737 DestroyWindow(hwnd);
2739 /* test subitem rects after re-arranging columns */
2740 hwnd = create_listview_control(LVS_REPORT);
2741 ok(hwnd != NULL, "failed to create a listview window\n");
2742 memset(&col, 0, sizeof(LVCOLUMNA));
2743 col.mask = LVCF_WIDTH;
2745 col.cx = 100;
2746 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
2747 expect(0, r);
2749 col.cx = 200;
2750 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&col);
2751 expect(1, r);
2753 col.cx = 300;
2754 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 2, (LPARAM)&col);
2755 expect(2, r);
2757 insert_item(hwnd, 0);
2758 insert_item(hwnd, 1);
2760 /* wrong item is refused for main item */
2761 rect.left = LVIR_BOUNDS;
2762 rect.top = 0;
2763 rect.right = rect.bottom = -1;
2764 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect);
2765 expect(FALSE, r);
2767 /* for subitems rectangle is calculated even if there's no item added */
2768 rect.left = LVIR_BOUNDS;
2769 rect.top = 1;
2770 rect.right = rect.bottom = -1;
2771 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect);
2772 expect(TRUE, r);
2774 rect2.left = LVIR_BOUNDS;
2775 rect2.top = 1;
2776 rect2.right = rect2.bottom = -1;
2777 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect2);
2778 expect(TRUE, r);
2779 expect(rect.right, rect2.right);
2780 expect(rect.left, rect2.left);
2781 expect(rect.bottom, rect2.top);
2782 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2784 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2785 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2786 expect(TRUE, r);
2788 rect.left = LVIR_BOUNDS;
2789 rect.top = 0;
2790 rect.right = rect.bottom = -1;
2791 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2792 expect(TRUE, r);
2793 expect(0, rect.left);
2794 expect(600, rect.right);
2796 rect.left = LVIR_BOUNDS;
2797 rect.top = 1;
2798 rect.right = rect.bottom = -1;
2799 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2800 expect(TRUE, r);
2801 expect(0, rect.left);
2802 expect(200, rect.right);
2804 rect2.left = LVIR_BOUNDS;
2805 rect2.top = 1;
2806 rect2.right = rect2.bottom = -1;
2807 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect2);
2808 expect(TRUE, r);
2809 expect(0, rect2.left);
2810 expect(200, rect2.right);
2811 /* items are of the same height */
2812 ok(rect2.top > 0, "expected positive item height\n");
2813 expect(rect.bottom, rect2.top);
2814 expect(rect.bottom * 2 - rect.top, rect2.bottom);
2816 rect.left = LVIR_BOUNDS;
2817 rect.top = 2;
2818 rect.right = rect.bottom = -1;
2819 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2820 expect(TRUE, r);
2821 expect(300, rect.left);
2822 expect(600, rect.right);
2824 DestroyWindow(hwnd);
2826 /* try it for non LVS_REPORT style */
2827 hwnd = CreateWindowA("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2828 GetModuleHandleA(NULL), 0);
2829 rect.left = LVIR_BOUNDS;
2830 rect.top = 1;
2831 rect.right = rect.bottom = -10;
2832 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2833 expect(0, r);
2834 /* rect is unchanged */
2835 expect(0, rect.left);
2836 expect(-10, rect.right);
2837 expect(1, rect.top);
2838 expect(-10, rect.bottom);
2839 DestroyWindow(hwnd);
2842 /* comparison callback for test_sorting */
2843 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2845 if (first == second) return 0;
2846 return (first > second ? 1 : -1);
2849 static void test_sorting(void)
2851 HWND hwnd;
2852 LVITEMA item = {0};
2853 INT r;
2854 LONG_PTR style;
2855 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2856 CHAR buff[10];
2858 hwnd = create_listview_control(LVS_REPORT);
2859 ok(hwnd != NULL, "failed to create a listview window\n");
2861 /* insert some items */
2862 item.mask = LVIF_PARAM | LVIF_STATE;
2863 item.state = LVIS_SELECTED;
2864 item.iItem = 0;
2865 item.iSubItem = 0;
2866 item.lParam = 3;
2867 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2868 expect(0, r);
2870 item.mask = LVIF_PARAM;
2871 item.iItem = 1;
2872 item.iSubItem = 0;
2873 item.lParam = 2;
2874 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2875 expect(1, r);
2877 item.mask = LVIF_STATE | LVIF_PARAM;
2878 item.state = LVIS_SELECTED;
2879 item.iItem = 2;
2880 item.iSubItem = 0;
2881 item.lParam = 4;
2882 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2883 expect(2, r);
2885 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2886 expect(-1, r);
2888 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2889 expect(2, r);
2891 r = SendMessageA(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2892 expect(TRUE, r);
2894 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2895 expect(2, r);
2896 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2897 expect(-1, r);
2898 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2899 expect(0, r);
2900 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2901 expect(LVIS_SELECTED, r);
2902 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2903 expect(LVIS_SELECTED, r);
2905 DestroyWindow(hwnd);
2907 /* switch to LVS_SORTASCENDING when some items added */
2908 hwnd = create_listview_control(LVS_REPORT);
2909 ok(hwnd != NULL, "failed to create a listview window\n");
2911 item.mask = LVIF_TEXT;
2912 item.iItem = 0;
2913 item.iSubItem = 0;
2914 item.pszText = names[1];
2915 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2916 expect(0, r);
2918 item.mask = LVIF_TEXT;
2919 item.iItem = 1;
2920 item.iSubItem = 0;
2921 item.pszText = names[2];
2922 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2923 expect(1, r);
2925 item.mask = LVIF_TEXT;
2926 item.iItem = 2;
2927 item.iSubItem = 0;
2928 item.pszText = names[0];
2929 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2930 expect(2, r);
2932 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2933 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2934 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2935 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2937 /* no sorting performed when switched to LVS_SORTASCENDING */
2938 item.mask = LVIF_TEXT;
2939 item.iItem = 0;
2940 item.pszText = buff;
2941 item.cchTextMax = sizeof(buff);
2942 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2943 expect(TRUE, r);
2944 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2946 item.iItem = 1;
2947 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2948 expect(TRUE, r);
2949 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2951 item.iItem = 2;
2952 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2953 expect(TRUE, r);
2954 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2956 /* adding new item doesn't resort list */
2957 item.mask = LVIF_TEXT;
2958 item.iItem = 3;
2959 item.iSubItem = 0;
2960 item.pszText = names[3];
2961 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2962 expect(3, r);
2964 item.mask = LVIF_TEXT;
2965 item.iItem = 0;
2966 item.pszText = buff;
2967 item.cchTextMax = sizeof(buff);
2968 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2969 expect(TRUE, r);
2970 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2972 item.iItem = 1;
2973 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2974 expect(TRUE, r);
2975 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2977 item.iItem = 2;
2978 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2979 expect(TRUE, r);
2980 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2982 item.iItem = 3;
2983 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2984 expect(TRUE, r);
2985 ok(lstrcmpA(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2987 /* corner case - item should be placed at first position */
2988 item.mask = LVIF_TEXT;
2989 item.iItem = 4;
2990 item.iSubItem = 0;
2991 item.pszText = names[4];
2992 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2993 expect(0, r);
2995 item.iItem = 0;
2996 item.pszText = buff;
2997 item.cchTextMax = sizeof(buff);
2998 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2999 expect(TRUE, r);
3000 ok(lstrcmpA(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
3002 item.iItem = 1;
3003 item.pszText = buff;
3004 item.cchTextMax = sizeof(buff);
3005 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3006 expect(TRUE, r);
3007 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
3009 item.iItem = 2;
3010 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3011 expect(TRUE, r);
3012 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
3014 item.iItem = 3;
3015 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3016 expect(TRUE, r);
3017 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
3019 item.iItem = 4;
3020 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3021 expect(TRUE, r);
3022 ok(lstrcmpA(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
3024 DestroyWindow(hwnd);
3027 static void test_ownerdata(void)
3029 static char test_str[] = "test";
3031 HWND hwnd;
3032 LONG_PTR style, ret;
3033 DWORD res;
3034 LVITEMA item;
3036 /* it isn't possible to set LVS_OWNERDATA after creation */
3037 if (g_is_below_5)
3039 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
3041 else
3043 hwnd = create_listview_control(LVS_REPORT);
3044 ok(hwnd != NULL, "failed to create a listview window\n");
3045 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3046 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
3048 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3050 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
3051 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
3052 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
3053 "try to switch to LVS_OWNERDATA seq", FALSE);
3055 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3056 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
3057 DestroyWindow(hwnd);
3060 /* try to set LVS_OWNERDATA after creation just having it */
3061 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3062 ok(hwnd != NULL, "failed to create a listview window\n");
3063 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3064 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
3066 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3068 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
3069 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
3070 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
3071 "try to switch to LVS_OWNERDATA seq", FALSE);
3072 DestroyWindow(hwnd);
3074 /* try to remove LVS_OWNERDATA after creation just having it */
3075 if (g_is_below_5)
3077 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
3079 else
3081 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3082 ok(hwnd != NULL, "failed to create a listview window\n");
3083 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3084 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
3086 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3088 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
3089 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
3090 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
3091 "try to switch to LVS_OWNERDATA seq", FALSE);
3092 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3093 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
3094 DestroyWindow(hwnd);
3097 /* try select an item */
3098 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3099 ok(hwnd != NULL, "failed to create a listview window\n");
3100 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3101 expect(1, res);
3102 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
3103 expect(0, res);
3104 memset(&item, 0, sizeof(item));
3105 item.stateMask = LVIS_SELECTED;
3106 item.state = LVIS_SELECTED;
3107 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3108 expect(TRUE, res);
3109 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
3110 expect(1, res);
3111 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
3112 expect(1, res);
3113 DestroyWindow(hwnd);
3115 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
3116 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3117 ok(hwnd != NULL, "failed to create a listview window\n");
3118 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3119 expect(1, res);
3120 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
3121 expect(1, res);
3122 memset(&item, 0, sizeof(item));
3123 item.mask = LVIF_STATE;
3124 item.iItem = 0;
3125 item.stateMask = LVIS_SELECTED;
3126 item.state = LVIS_SELECTED;
3127 res = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3128 expect(FALSE, res);
3129 memset(&item, 0, sizeof(item));
3130 item.pszText = test_str;
3131 res = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3132 expect(FALSE, res);
3133 DestroyWindow(hwnd);
3135 /* check notifications after focused/selected changed */
3136 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3137 ok(hwnd != NULL, "failed to create a listview window\n");
3138 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
3139 expect(1, res);
3141 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3143 memset(&item, 0, sizeof(item));
3144 item.stateMask = LVIS_SELECTED;
3145 item.state = LVIS_SELECTED;
3146 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3147 expect(TRUE, res);
3149 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_select_focus_parent_seq,
3150 "ownerdata select notification", TRUE);
3152 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3154 memset(&item, 0, sizeof(item));
3155 item.stateMask = LVIS_FOCUSED;
3156 item.state = LVIS_FOCUSED;
3157 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3158 expect(TRUE, res);
3160 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_select_focus_parent_seq,
3161 "ownerdata focus notification", TRUE);
3163 /* select all, check notifications */
3164 item.stateMask = LVIS_SELECTED;
3165 item.state = 0;
3166 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3167 expect(TRUE, res);
3169 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3171 item.stateMask = LVIS_SELECTED;
3172 item.state = LVIS_SELECTED;
3174 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3175 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3176 expect(TRUE, res);
3177 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3178 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3179 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3180 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3181 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3182 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3183 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3185 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3186 "ownerdata select all notification", FALSE);
3188 /* select all again, note that all items are selected already */
3189 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3190 item.stateMask = LVIS_SELECTED;
3191 item.state = LVIS_SELECTED;
3193 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3194 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3195 expect(TRUE, res);
3196 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3197 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3198 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3199 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3200 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3201 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3202 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3204 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3205 "ownerdata select all notification", FALSE);
3207 /* deselect all */
3208 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3209 item.stateMask = LVIS_SELECTED;
3210 item.state = 0;
3212 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3213 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3214 expect(TRUE, res);
3215 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3216 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3217 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3218 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3219 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3220 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3221 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3223 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3224 "ownerdata deselect all notification", TRUE);
3226 /* nothing selected, deselect all again */
3227 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3228 item.stateMask = LVIS_SELECTED;
3229 item.state = 0;
3231 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3232 expect(TRUE, res);
3234 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "ownerdata deselect all notification", FALSE);
3236 /* select one, then deselect all */
3237 item.stateMask = LVIS_SELECTED;
3238 item.state = LVIS_SELECTED;
3239 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3240 expect(TRUE, res);
3241 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3242 item.stateMask = LVIS_SELECTED;
3243 item.state = 0;
3245 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3246 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3247 expect(TRUE, res);
3248 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3249 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3250 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3251 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3252 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3253 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3254 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3256 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3257 "ownerdata select all notification", TRUE);
3259 /* remove focused, try to focus all */
3260 item.stateMask = LVIS_FOCUSED;
3261 item.state = LVIS_FOCUSED;
3262 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3263 expect(TRUE, res);
3264 item.stateMask = LVIS_FOCUSED;
3265 item.state = 0;
3266 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3267 expect(TRUE, res);
3268 item.stateMask = LVIS_FOCUSED;
3269 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
3270 expect(0, res);
3272 /* setting all to focused returns failure value */
3273 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3274 item.stateMask = LVIS_FOCUSED;
3275 item.state = LVIS_FOCUSED;
3277 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3278 expect(FALSE, res);
3280 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3281 "ownerdata focus all notification", FALSE);
3283 /* focus single item, remove all */
3284 item.stateMask = LVIS_FOCUSED;
3285 item.state = LVIS_FOCUSED;
3286 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3287 expect(TRUE, res);
3288 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3289 item.stateMask = LVIS_FOCUSED;
3290 item.state = 0;
3292 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3293 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3294 expect(TRUE, res);
3295 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3296 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3297 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3298 ok(g_nmlistview.uOldState == LVIS_FOCUSED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3299 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3300 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3301 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3303 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
3304 "ownerdata remove focus all notification", TRUE);
3306 /* set all cut */
3307 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3308 item.stateMask = LVIS_CUT;
3309 item.state = LVIS_CUT;
3311 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3312 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3313 expect(TRUE, res);
3314 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3315 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3316 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3317 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3318 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3319 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3320 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3322 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3323 "ownerdata cut all notification", FALSE);
3325 /* all marked cut, try again */
3326 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3327 item.stateMask = LVIS_CUT;
3328 item.state = LVIS_CUT;
3330 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3331 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3332 expect(TRUE, res);
3333 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3334 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3335 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3336 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3337 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3338 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3339 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3341 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3342 "ownerdata cut all notification #2", FALSE);
3344 DestroyWindow(hwnd);
3346 /* check notifications on LVM_GETITEM */
3347 /* zero callback mask */
3348 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3349 ok(hwnd != NULL, "failed to create a listview window\n");
3350 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3351 expect(1, res);
3353 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3355 memset(&item, 0, sizeof(item));
3356 item.stateMask = LVIS_SELECTED;
3357 item.mask = LVIF_STATE;
3358 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3359 expect(TRUE, res);
3361 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3362 "ownerdata getitem selected state 1", FALSE);
3364 /* non zero callback mask but not we asking for */
3365 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
3366 expect(TRUE, res);
3368 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3370 memset(&item, 0, sizeof(item));
3371 item.stateMask = LVIS_SELECTED;
3372 item.mask = LVIF_STATE;
3373 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3374 expect(TRUE, res);
3376 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3377 "ownerdata getitem selected state 2", FALSE);
3379 /* LVIS_OVERLAYMASK callback mask, asking for index */
3380 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3382 memset(&item, 0, sizeof(item));
3383 item.stateMask = LVIS_OVERLAYMASK;
3384 item.mask = LVIF_STATE;
3385 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3386 expect(TRUE, res);
3388 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3389 "ownerdata getitem selected state 2", FALSE);
3391 DestroyWindow(hwnd);
3393 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3394 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
3395 ok(hwnd != NULL, "failed to create a listview window\n");
3396 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3397 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3398 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3399 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
3400 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3401 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
3402 DestroyWindow(hwnd);
3403 /* apparently it's allowed to switch these style on after creation */
3404 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3405 ok(hwnd != NULL, "failed to create a listview window\n");
3406 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3407 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3408 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
3409 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3410 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3411 DestroyWindow(hwnd);
3413 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3414 ok(hwnd != NULL, "failed to create a listview window\n");
3415 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3416 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3417 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
3418 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3419 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
3420 DestroyWindow(hwnd);
3422 /* The focused item is updated after the invalidation */
3423 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3424 ok(hwnd != NULL, "failed to create a listview window\n");
3425 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 3, 0);
3426 expect(TRUE, res);
3428 memset(&item, 0, sizeof(item));
3429 item.stateMask = LVIS_FOCUSED;
3430 item.state = LVIS_FOCUSED;
3431 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3432 expect(TRUE, res);
3434 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3435 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 0, 0);
3436 expect(TRUE, res);
3437 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3438 "ownerdata setitemcount", FALSE);
3440 res = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
3441 expect(-1, res);
3442 DestroyWindow(hwnd);
3445 static void test_norecompute(void)
3447 static CHAR testA[] = "test";
3448 CHAR buff[10];
3449 LVITEMA item;
3450 HWND hwnd;
3451 DWORD res;
3453 /* self containing control */
3454 hwnd = create_listview_control(LVS_REPORT);
3455 ok(hwnd != NULL, "failed to create a listview window\n");
3456 memset(&item, 0, sizeof(item));
3457 item.mask = LVIF_TEXT | LVIF_STATE;
3458 item.iItem = 0;
3459 item.stateMask = LVIS_SELECTED;
3460 item.state = LVIS_SELECTED;
3461 item.pszText = testA;
3462 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3463 expect(0, res);
3464 /* retrieve with LVIF_NORECOMPUTE */
3465 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3466 item.iItem = 0;
3467 item.pszText = buff;
3468 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3469 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3470 expect(TRUE, res);
3471 ok(lstrcmpA(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
3473 item.mask = LVIF_TEXT;
3474 item.iItem = 1;
3475 item.pszText = LPSTR_TEXTCALLBACKA;
3476 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3477 expect(1, res);
3479 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3480 item.iItem = 1;
3481 item.pszText = buff;
3482 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3484 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3485 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3486 expect(TRUE, res);
3487 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3488 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3489 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
3491 DestroyWindow(hwnd);
3493 /* LVS_OWNERDATA */
3494 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3495 ok(hwnd != NULL, "failed to create a listview window\n");
3497 item.mask = LVIF_STATE;
3498 item.stateMask = LVIS_SELECTED;
3499 item.state = LVIS_SELECTED;
3500 item.iItem = 0;
3501 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3502 expect(0, res);
3504 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3505 item.iItem = 0;
3506 item.pszText = buff;
3507 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3508 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3509 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3510 expect(TRUE, res);
3511 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3512 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3513 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
3515 DestroyWindow(hwnd);
3518 static void test_nosortheader(void)
3520 HWND hwnd, header;
3521 LONG_PTR style;
3523 hwnd = create_listview_control(LVS_REPORT);
3524 ok(hwnd != NULL, "failed to create a listview window\n");
3526 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3527 ok(IsWindow(header), "header expected\n");
3529 style = GetWindowLongPtrA(header, GWL_STYLE);
3530 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
3532 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3533 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
3534 /* HDS_BUTTONS retained */
3535 style = GetWindowLongPtrA(header, GWL_STYLE);
3536 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
3538 DestroyWindow(hwnd);
3540 /* create with LVS_NOSORTHEADER */
3541 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
3542 ok(hwnd != NULL, "failed to create a listview window\n");
3544 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3545 ok(IsWindow(header), "header expected\n");
3547 style = GetWindowLongPtrA(header, GWL_STYLE);
3548 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3550 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3551 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
3552 /* not changed here */
3553 style = GetWindowLongPtrA(header, GWL_STYLE);
3554 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3556 DestroyWindow(hwnd);
3559 static void test_setredraw(void)
3561 HWND hwnd;
3562 DWORD_PTR style;
3563 DWORD ret;
3564 HDC hdc;
3565 RECT rect;
3567 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3568 ok(hwnd != NULL, "failed to create a listview window\n");
3570 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3571 ListView seems to handle it internally without DefWinProc */
3573 /* default value first */
3574 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3575 expect(0, ret);
3576 /* disable */
3577 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3578 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3579 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3580 expect(0, ret);
3581 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3582 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3583 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3584 expect(0, ret);
3586 /* check update rect after redrawing */
3587 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3588 expect(0, ret);
3589 InvalidateRect(hwnd, NULL, FALSE);
3590 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
3591 rect.right = rect.bottom = 1;
3592 GetUpdateRect(hwnd, &rect, FALSE);
3593 expect(0, rect.right);
3594 expect(0, rect.bottom);
3596 /* WM_ERASEBKGND */
3597 hdc = GetWindowDC(hwndparent);
3598 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3599 expect(TRUE, ret);
3600 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3601 expect(0, ret);
3602 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3603 expect(TRUE, ret);
3604 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3605 expect(0, ret);
3606 ReleaseDC(hwndparent, hdc);
3608 /* check notification messages to show that repainting is disabled */
3609 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3610 expect(TRUE, ret);
3611 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3612 expect(0, ret);
3613 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3615 InvalidateRect(hwnd, NULL, TRUE);
3616 UpdateWindow(hwnd);
3617 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3618 "redraw after WM_SETREDRAW (FALSE)", FALSE);
3620 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3621 expect(TRUE, ret);
3622 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3623 InvalidateRect(hwnd, NULL, TRUE);
3624 UpdateWindow(hwnd);
3625 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3626 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3628 /* message isn't forwarded to header */
3629 subclass_header(hwnd);
3630 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3631 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3632 expect(0, ret);
3633 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3634 "WM_SETREDRAW: not forwarded to header", FALSE);
3636 DestroyWindow(hwnd);
3639 static void test_hittest(void)
3641 HWND hwnd;
3642 DWORD r;
3643 RECT bounds;
3644 LVITEMA item;
3645 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3646 POINT pos;
3647 INT x, y, i;
3648 WORD vert;
3649 HIMAGELIST himl, himl2;
3650 HBITMAP hbmp;
3652 hwnd = create_listview_control(LVS_REPORT);
3653 ok(hwnd != NULL, "failed to create a listview window\n");
3655 /* LVS_REPORT with a single subitem (2 columns) */
3656 insert_column(hwnd, 0);
3657 insert_column(hwnd, 1);
3658 insert_item(hwnd, 0);
3660 item.iSubItem = 0;
3661 /* the only purpose of that line is to be as long as a half item rect */
3662 item.pszText = text;
3663 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3664 expect(TRUE, r);
3666 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3667 expect(TRUE, r);
3668 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3669 expect(TRUE, r);
3671 memset(&bounds, 0, sizeof(bounds));
3672 bounds.left = LVIR_BOUNDS;
3673 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3674 expect(1, r);
3675 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3676 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3677 r = SendMessageA(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3678 vert = HIWORD(r);
3679 ok(bounds.bottom - bounds.top == vert,
3680 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3681 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3682 expect(TRUE, r);
3684 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3686 /* outside columns by x position - valid is [0, 199] */
3687 x = -1;
3688 y = pos.y + (bounds.bottom - bounds.top) / 2;
3689 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3690 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3692 x = pos.x + 50; /* column half width */
3693 y = pos.y + (bounds.bottom - bounds.top) / 2;
3694 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3695 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3696 x = pos.x + 150; /* outside column */
3697 y = pos.y + (bounds.bottom - bounds.top) / 2;
3698 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3699 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3700 y = (bounds.bottom - bounds.top) / 2;
3701 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3702 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3703 /* outside possible client rectangle (to right) */
3704 x = pos.x + 500;
3705 y = pos.y + (bounds.bottom - bounds.top) / 2;
3706 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3707 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3708 y = (bounds.bottom - bounds.top) / 2;
3709 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3710 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3711 /* subitem returned with -1 item too */
3712 x = pos.x + 150;
3713 y = bounds.top - vert;
3714 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3715 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3716 /* return values appear to underflow with negative indices */
3717 i = -2;
3718 y = y - vert;
3719 while (i > -10) {
3720 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3721 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3722 y = y - vert;
3723 i--;
3725 /* parent client area is 100x100 by default */
3726 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3727 x = pos.x + 150; /* outside column */
3728 y = pos.y + (bounds.bottom - bounds.top) / 2;
3729 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3730 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3731 y = (bounds.bottom - bounds.top) / 2;
3732 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3733 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3734 /* the same with LVS_EX_FULLROWSELECT */
3735 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3736 x = pos.x + 150; /* outside column */
3737 y = pos.y + (bounds.bottom - bounds.top) / 2;
3738 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3739 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3740 y = (bounds.bottom - bounds.top) / 2;
3741 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3742 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3743 x = pos.x + 150; /* outside column */
3744 y = pos.y + (bounds.bottom - bounds.top) / 2;
3745 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3746 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3747 y = (bounds.bottom - bounds.top) / 2;
3748 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3749 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3750 /* outside possible client rectangle (to right) */
3751 x = pos.x + 500;
3752 y = pos.y + (bounds.bottom - bounds.top) / 2;
3753 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3754 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3755 y = (bounds.bottom - bounds.top) / 2;
3756 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3757 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3758 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3759 himl = ImageList_Create(16, 16, 0, 4, 4);
3760 ok(himl != NULL, "failed to create imagelist\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 == 0, "should be zero\n");
3765 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3766 ok(hbmp != NULL, "failed to create bitmap\n");
3767 r = ImageList_Add(himl, hbmp, 0);
3768 ok(r == 1, "should be one\n");
3770 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3771 expect(0, r);
3773 item.mask = LVIF_IMAGE;
3774 item.iImage = 0;
3775 item.iItem = 0;
3776 item.iSubItem = 0;
3777 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3778 expect(TRUE, r);
3779 /* on state icon */
3780 x = pos.x + 8;
3781 y = pos.y + (bounds.bottom - bounds.top) / 2;
3782 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3783 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3784 y = (bounds.bottom - bounds.top) / 2;
3785 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3787 /* state icons indices are 1 based, check with valid index */
3788 item.mask = LVIF_STATE;
3789 item.state = INDEXTOSTATEIMAGEMASK(1);
3790 item.stateMask = LVIS_STATEIMAGEMASK;
3791 item.iItem = 0;
3792 item.iSubItem = 0;
3793 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3794 expect(TRUE, r);
3795 /* on state icon */
3796 x = pos.x + 8;
3797 y = pos.y + (bounds.bottom - bounds.top) / 2;
3798 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3799 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3800 y = (bounds.bottom - bounds.top) / 2;
3801 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3803 himl2 = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3804 ok(himl2 == himl, "should return handle\n");
3806 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3807 expect(0, r);
3808 /* on item icon */
3809 x = pos.x + 8;
3810 y = pos.y + (bounds.bottom - bounds.top) / 2;
3811 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3812 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3813 y = (bounds.bottom - bounds.top) / 2;
3814 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3816 DestroyWindow(hwnd);
3819 static void test_getviewrect(void)
3821 HWND hwnd;
3822 DWORD r;
3823 RECT rect;
3824 LVITEMA item;
3826 hwnd = create_listview_control(LVS_REPORT);
3827 ok(hwnd != NULL, "failed to create a listview window\n");
3829 /* empty */
3830 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3831 expect(TRUE, r);
3833 insert_column(hwnd, 0);
3834 insert_column(hwnd, 1);
3836 memset(&item, 0, sizeof(item));
3837 item.iItem = 0;
3838 item.iSubItem = 0;
3839 SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3841 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3842 expect(TRUE, r);
3843 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3844 expect(TRUE, r);
3846 rect.left = rect.right = rect.top = rect.bottom = -1;
3847 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3848 expect(TRUE, r);
3849 /* left is set to (2e31-1) - XP SP2 */
3850 expect(0, rect.right);
3851 expect(0, rect.top);
3852 expect(0, rect.bottom);
3854 /* switch to LVS_ICON */
3855 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_REPORT);
3857 rect.left = rect.right = rect.top = rect.bottom = -1;
3858 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3859 expect(TRUE, r);
3860 expect(0, rect.left);
3861 expect(0, rect.top);
3862 /* precise value differs for 2k, XP and Vista */
3863 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3864 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3866 DestroyWindow(hwnd);
3869 static void test_getitemposition(void)
3871 HWND hwnd, header;
3872 DWORD r;
3873 POINT pt;
3874 RECT rect;
3876 hwnd = create_listview_control(LVS_REPORT);
3877 ok(hwnd != NULL, "failed to create a listview window\n");
3878 header = subclass_header(hwnd);
3880 /* LVS_REPORT, single item, no columns added */
3881 insert_item(hwnd, 0);
3883 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3885 pt.x = pt.y = -1;
3886 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3887 expect(TRUE, r);
3888 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3890 /* LVS_REPORT, single item, single column */
3891 insert_column(hwnd, 0);
3893 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3895 pt.x = pt.y = -1;
3896 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3897 expect(TRUE, r);
3898 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3900 memset(&rect, 0, sizeof(rect));
3901 SendMessageA(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3902 /* some padding? */
3903 expect(2, pt.x);
3904 /* offset by header height */
3905 expect(rect.bottom - rect.top, pt.y);
3907 DestroyWindow(hwnd);
3910 static void test_columnscreation(void)
3912 HWND hwnd, header;
3913 DWORD r;
3915 hwnd = create_listview_control(LVS_REPORT);
3916 ok(hwnd != NULL, "failed to create a listview window\n");
3918 insert_item(hwnd, 0);
3920 /* headers columns aren't created automatically */
3921 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3922 ok(IsWindow(header), "Expected header handle\n");
3923 r = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
3924 expect(0, r);
3926 DestroyWindow(hwnd);
3929 static void test_getitemrect(void)
3931 HWND hwnd;
3932 HIMAGELIST himl, himl_ret;
3933 HBITMAP hbm;
3934 RECT rect;
3935 DWORD r;
3936 LVITEMA item;
3937 LVCOLUMNA col;
3938 INT order[2];
3939 POINT pt;
3941 /* rectangle isn't empty for empty text items */
3942 hwnd = create_listview_control(LVS_LIST);
3943 memset(&item, 0, sizeof(item));
3944 item.mask = 0;
3945 item.iItem = 0;
3946 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3947 expect(0, r);
3948 rect.left = LVIR_LABEL;
3949 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3950 expect(TRUE, r);
3951 expect(0, rect.left);
3952 expect(0, rect.top);
3953 /* estimate it as width / height ratio */
3954 todo_wine
3955 ok((rect.right / rect.bottom) >= 5, "got right %d, bottom %d\n", rect.right, rect.bottom);
3956 DestroyWindow(hwnd);
3958 hwnd = create_listview_control(LVS_REPORT);
3959 ok(hwnd != NULL, "failed to create a listview window\n");
3961 /* empty item */
3962 memset(&item, 0, sizeof(item));
3963 item.iItem = 0;
3964 item.iSubItem = 0;
3965 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3966 expect(0, r);
3968 rect.left = LVIR_BOUNDS;
3969 rect.right = rect.top = rect.bottom = -1;
3970 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3971 expect(TRUE, r);
3973 /* zero width rectangle with no padding */
3974 expect(0, rect.left);
3975 expect(0, rect.right);
3977 insert_column(hwnd, 0);
3978 insert_column(hwnd, 1);
3980 col.mask = LVCF_WIDTH;
3981 col.cx = 50;
3982 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 0, (LPARAM)&col);
3983 expect(TRUE, r);
3985 col.mask = LVCF_WIDTH;
3986 col.cx = 100;
3987 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 1, (LPARAM)&col);
3988 expect(TRUE, r);
3990 rect.left = LVIR_BOUNDS;
3991 rect.right = rect.top = rect.bottom = -1;
3992 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3993 expect(TRUE, r);
3995 /* still no left padding */
3996 expect(0, rect.left);
3997 expect(150, rect.right);
3999 rect.left = LVIR_SELECTBOUNDS;
4000 rect.right = rect.top = rect.bottom = -1;
4001 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4002 expect(TRUE, r);
4003 /* padding */
4004 expect(2, rect.left);
4006 rect.left = LVIR_LABEL;
4007 rect.right = rect.top = rect.bottom = -1;
4008 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4009 expect(TRUE, r);
4010 /* padding, column width */
4011 expect(2, rect.left);
4012 expect(50, rect.right);
4014 /* no icons attached */
4015 rect.left = LVIR_ICON;
4016 rect.right = rect.top = rect.bottom = -1;
4017 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4018 expect(TRUE, r);
4019 /* padding */
4020 expect(2, rect.left);
4021 expect(2, rect.right);
4023 /* change order */
4024 order[0] = 1; order[1] = 0;
4025 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
4026 expect(TRUE, r);
4027 pt.x = -1;
4028 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
4029 expect(TRUE, r);
4030 /* 1 indexed column width + padding */
4031 expect(102, pt.x);
4032 /* rect is at zero too */
4033 rect.left = LVIR_BOUNDS;
4034 rect.right = rect.top = rect.bottom = -1;
4035 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4036 expect(TRUE, r);
4037 expect(0, rect.left);
4038 /* just width sum */
4039 expect(150, rect.right);
4041 rect.left = LVIR_SELECTBOUNDS;
4042 rect.right = rect.top = rect.bottom = -1;
4043 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4044 expect(TRUE, r);
4045 /* column width + padding */
4046 expect(102, rect.left);
4048 /* back to initial order */
4049 order[0] = 0; order[1] = 1;
4050 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
4051 expect(TRUE, r);
4053 /* state icons */
4054 himl = ImageList_Create(16, 16, 0, 2, 2);
4055 ok(himl != NULL, "failed to create imagelist\n");
4056 hbm = CreateBitmap(16, 16, 1, 1, NULL);
4057 ok(hbm != NULL, "failed to create bitmap\n");
4058 r = ImageList_Add(himl, hbm, 0);
4059 expect(0, r);
4060 hbm = CreateBitmap(16, 16, 1, 1, NULL);
4061 ok(hbm != NULL, "failed to create bitmap\n");
4062 r = ImageList_Add(himl, hbm, 0);
4063 expect(1, r);
4065 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
4066 expect(0, r);
4068 item.mask = LVIF_STATE;
4069 item.state = INDEXTOSTATEIMAGEMASK(1);
4070 item.stateMask = LVIS_STATEIMAGEMASK;
4071 item.iItem = 0;
4072 item.iSubItem = 0;
4073 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4074 expect(TRUE, r);
4076 /* icon bounds */
4077 rect.left = LVIR_ICON;
4078 rect.right = rect.top = rect.bottom = -1;
4079 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4080 expect(TRUE, r);
4081 /* padding + stateicon width */
4082 expect(18, rect.left);
4083 expect(18, rect.right);
4084 /* label bounds */
4085 rect.left = LVIR_LABEL;
4086 rect.right = rect.top = rect.bottom = -1;
4087 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4088 expect(TRUE, r);
4089 /* padding + stateicon width -> column width */
4090 expect(18, rect.left);
4091 expect(50, rect.right);
4093 himl_ret = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
4094 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
4096 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
4097 expect(0, r);
4099 item.mask = LVIF_STATE | LVIF_IMAGE;
4100 item.iImage = 1;
4101 item.state = 0;
4102 item.stateMask = ~0;
4103 item.iItem = 0;
4104 item.iSubItem = 0;
4105 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4106 expect(TRUE, r);
4108 /* icon bounds */
4109 rect.left = LVIR_ICON;
4110 rect.right = rect.top = rect.bottom = -1;
4111 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4112 expect(TRUE, r);
4113 /* padding, icon width */
4114 expect(2, rect.left);
4115 expect(18, rect.right);
4116 /* label bounds */
4117 rect.left = LVIR_LABEL;
4118 rect.right = rect.top = rect.bottom = -1;
4119 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4120 expect(TRUE, r);
4121 /* padding + icon width -> column width */
4122 expect(18, rect.left);
4123 expect(50, rect.right);
4125 /* select bounds */
4126 rect.left = LVIR_SELECTBOUNDS;
4127 rect.right = rect.top = rect.bottom = -1;
4128 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4129 expect(TRUE, r);
4130 /* padding, column width */
4131 expect(2, rect.left);
4132 expect(50, rect.right);
4134 /* try with indentation */
4135 item.mask = LVIF_INDENT;
4136 item.iIndent = 1;
4137 item.iItem = 0;
4138 item.iSubItem = 0;
4139 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4140 expect(TRUE, r);
4142 /* bounds */
4143 rect.left = LVIR_BOUNDS;
4144 rect.right = rect.top = rect.bottom = -1;
4145 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4146 expect(TRUE, r);
4147 /* padding + 1 icon width, column width */
4148 expect(0, rect.left);
4149 expect(150, rect.right);
4151 /* select bounds */
4152 rect.left = LVIR_SELECTBOUNDS;
4153 rect.right = rect.top = rect.bottom = -1;
4154 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4155 expect(TRUE, r);
4156 /* padding + 1 icon width, column width */
4157 expect(2 + 16, rect.left);
4158 expect(50, rect.right);
4160 /* label bounds */
4161 rect.left = LVIR_LABEL;
4162 rect.right = rect.top = rect.bottom = -1;
4163 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4164 expect(TRUE, r);
4165 /* padding + 2 icon widths, column width */
4166 expect(2 + 16*2, rect.left);
4167 expect(50, rect.right);
4169 /* icon bounds */
4170 rect.left = LVIR_ICON;
4171 rect.right = rect.top = rect.bottom = -1;
4172 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4173 expect(TRUE, r);
4174 /* padding + 1 icon width indentation, icon width */
4175 expect(2 + 16, rect.left);
4176 expect(34, rect.right);
4178 DestroyWindow(hwnd);
4181 static void test_editbox(void)
4183 static CHAR testitemA[] = "testitem";
4184 static CHAR testitem1A[] = "testitem_quitelongname";
4185 static CHAR testitem2A[] = "testITEM_quitelongname";
4186 static CHAR buffer[25];
4187 HWND hwnd, hwndedit, hwndedit2, header;
4188 LVITEMA item;
4189 INT r;
4191 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4192 ok(hwnd != NULL, "failed to create a listview window\n");
4194 insert_column(hwnd, 0);
4196 memset(&item, 0, sizeof(item));
4197 item.mask = LVIF_TEXT;
4198 item.pszText = testitemA;
4199 item.iItem = 0;
4200 item.iSubItem = 0;
4201 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4202 expect(0, r);
4204 /* test notifications without edit created */
4205 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4206 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
4207 expect(0, r);
4208 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4209 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
4210 /* same thing but with valid window */
4211 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
4212 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
4213 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4214 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
4215 expect(0, r);
4216 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4217 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
4218 DestroyWindow(hwndedit);
4220 /* setting focus is necessary */
4221 SetFocus(hwnd);
4222 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4223 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4225 /* test children Z-order after Edit box created */
4226 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4227 ok(IsWindow(header), "Expected header to be created\n");
4228 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4229 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4231 /* modify initial string */
4232 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4233 expect(TRUE, r);
4235 /* edit window is resized and repositioned,
4236 check again for Z-order - it should be preserved */
4237 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4238 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4240 /* return focus to listview */
4241 SetFocus(hwnd);
4243 memset(&item, 0, sizeof(item));
4244 item.mask = LVIF_TEXT;
4245 item.pszText = buffer;
4246 item.cchTextMax = sizeof(buffer);
4247 item.iItem = 0;
4248 item.iSubItem = 0;
4249 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4250 expect(TRUE, r);
4252 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4254 /* send LVM_EDITLABEL on already created edit */
4255 SetFocus(hwnd);
4256 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4257 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4258 /* focus will be set to edit */
4259 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
4260 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4261 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
4263 /* creating label disabled when control isn't focused */
4264 SetFocus(0);
4265 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4266 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4268 /* check EN_KILLFOCUS handling */
4269 memset(&item, 0, sizeof(item));
4270 item.pszText = testitemA;
4271 item.iItem = 0;
4272 item.iSubItem = 0;
4273 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4274 expect(TRUE, r);
4276 SetFocus(hwnd);
4277 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4278 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4279 /* modify edit and notify control that it lost focus */
4280 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4281 expect(TRUE, r);
4282 g_editbox_disp_info.item.pszText = NULL;
4283 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4284 expect(0, r);
4285 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
4287 memset(&item, 0, sizeof(item));
4288 item.pszText = buffer;
4289 item.cchTextMax = sizeof(buffer);
4290 item.iItem = 0;
4291 item.iSubItem = 0;
4292 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4293 expect(lstrlenA(item.pszText), r);
4294 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4295 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4297 /* change item name to differ in casing only */
4298 SetFocus(hwnd);
4299 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4300 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4301 /* modify edit and notify control that it lost focus */
4302 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
4303 expect(TRUE, r);
4304 g_editbox_disp_info.item.pszText = NULL;
4305 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4306 expect(0, r);
4307 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
4309 memset(&item, 0, sizeof(item));
4310 item.pszText = buffer;
4311 item.cchTextMax = sizeof(buffer);
4312 item.iItem = 0;
4313 item.iSubItem = 0;
4314 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4315 expect(lstrlenA(item.pszText), r);
4316 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
4317 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4319 /* end edit without saving */
4320 SetFocus(hwnd);
4321 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4322 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4323 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
4324 expect(0, r);
4325 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4326 "edit box - end edit, no change, escape", TRUE);
4327 /* end edit with saving */
4328 SetFocus(hwnd);
4329 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4330 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4331 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
4332 expect(0, r);
4333 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4334 "edit box - end edit, no change, return", TRUE);
4336 memset(&item, 0, sizeof(item));
4337 item.pszText = buffer;
4338 item.cchTextMax = sizeof(buffer);
4339 item.iItem = 0;
4340 item.iSubItem = 0;
4341 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4342 expect(lstrlenA(item.pszText), r);
4343 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
4345 /* LVM_EDITLABEL with -1 destroys current edit */
4346 hwndedit = (HWND)SendMessageA(hwnd, LVM_GETEDITCONTROL, 0, 0);
4347 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4348 /* no edit present */
4349 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4350 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4351 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4352 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4353 /* edit present */
4354 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4355 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4356 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4357 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4358 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4359 /* check another negative value */
4360 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4361 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4362 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4363 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -2, 0);
4364 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4365 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4366 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4367 /* and value greater than max item index */
4368 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4369 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4370 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4371 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
4372 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, r, 0);
4373 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4374 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4375 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4377 /* messaging tests */
4378 SetFocus(hwnd);
4379 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4380 blockEdit = FALSE;
4381 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4382 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4383 /* testing only sizing messages */
4384 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
4385 "edit box create - sizing", FALSE);
4387 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4388 SetFocus(hwnd);
4389 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4390 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4391 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4392 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4393 expect(0, r);
4394 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4395 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
4397 DestroyWindow(hwnd);
4400 static void test_notifyformat(void)
4402 HWND hwnd, header;
4403 DWORD r;
4405 hwnd = create_listview_control(LVS_REPORT);
4406 ok(hwnd != NULL, "failed to create a listview window\n");
4408 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4409 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4410 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4411 expect(0, r);
4412 SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4413 /* set */
4414 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
4415 expect(0, r);
4416 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4417 if (r == 1)
4419 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
4420 expect(1, r);
4421 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4422 expect(0, r);
4424 else
4426 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4427 DestroyWindow(hwnd);
4428 return;
4431 DestroyWindow(hwnd);
4433 /* test failure in parent WM_NOTIFYFORMAT */
4434 notifyFormat = 0;
4435 hwnd = create_listview_control(LVS_REPORT);
4436 ok(hwnd != NULL, "failed to create a listview window\n");
4437 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4438 ok(IsWindow(header), "expected header to be created\n");
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 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4444 ok(r != 0, "Expected valid format\n");
4446 notifyFormat = NFR_UNICODE;
4447 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4448 expect(NFR_UNICODE, r);
4449 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4450 expect(1, r);
4451 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4452 ok( r == 1, "Expected 1, got %d\n", r );
4454 notifyFormat = NFR_ANSI;
4455 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4456 expect(NFR_ANSI, r);
4457 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4458 expect(0, r);
4459 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4460 ok( r == 1, "Expected 1, got %d\n", r );
4462 DestroyWindow(hwnd);
4464 hwndparentW = create_parent_window(TRUE);
4465 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
4466 if (!IsWindow(hwndparentW)) return;
4468 notifyFormat = -1;
4469 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4470 ok(hwnd != NULL, "failed to create a listview window\n");
4471 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4472 ok(IsWindow(header), "expected header to be created\n");
4473 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4474 expect(1, r);
4475 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4476 expect(1, r);
4477 DestroyWindow(hwnd);
4478 /* receiving error code defaulting to ansi */
4479 notifyFormat = 0;
4480 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4481 ok(hwnd != NULL, "failed to create a listview window\n");
4482 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4483 ok(IsWindow(header), "expected header to be created\n");
4484 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4485 expect(0, r);
4486 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4487 expect(1, r);
4488 DestroyWindow(hwnd);
4489 /* receiving ansi code from unicode window, use it */
4490 notifyFormat = NFR_ANSI;
4491 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4492 ok(hwnd != NULL, "failed to create a listview window\n");
4493 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4494 ok(IsWindow(header), "expected header to be created\n");
4495 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4496 expect(0, r);
4497 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4498 expect(1, r);
4499 DestroyWindow(hwnd);
4500 /* unicode listview with ansi parent window */
4501 notifyFormat = -1;
4502 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4503 ok(hwnd != NULL, "failed to create a listview window\n");
4504 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4505 ok(IsWindow(header), "expected header to be created\n");
4506 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4507 expect(0, r);
4508 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4509 expect(1, r);
4510 DestroyWindow(hwnd);
4511 /* unicode listview with ansi parent window, return error code */
4512 notifyFormat = 0;
4513 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4514 ok(hwnd != NULL, "failed to create a listview window\n");
4515 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4516 ok(IsWindow(header), "expected header to be created\n");
4517 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4518 expect(0, r);
4519 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4520 expect(1, r);
4521 DestroyWindow(hwnd);
4523 DestroyWindow(hwndparentW);
4526 static void test_indentation(void)
4528 HWND hwnd;
4529 LVITEMA item;
4530 DWORD r;
4532 hwnd = create_listview_control(LVS_REPORT);
4533 ok(hwnd != NULL, "failed to create a listview window\n");
4535 memset(&item, 0, sizeof(item));
4536 item.mask = LVIF_INDENT;
4537 item.iItem = 0;
4538 item.iIndent = I_INDENTCALLBACK;
4539 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4540 expect(0, r);
4542 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4544 item.iItem = 0;
4545 item.mask = LVIF_INDENT;
4546 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4547 expect(TRUE, r);
4549 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
4550 "get indent dispinfo", FALSE);
4552 DestroyWindow(hwnd);
4555 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
4557 return 0;
4560 static BOOL is_below_comctl_5(void)
4562 HWND hwnd;
4563 BOOL ret;
4565 hwnd = create_listview_control(LVS_REPORT);
4566 ok(hwnd != NULL, "failed to create a listview window\n");
4567 insert_item(hwnd, 0);
4569 ret = SendMessageA(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
4571 DestroyWindow(hwnd);
4573 return !ret;
4576 static void test_get_set_view(void)
4578 HWND hwnd;
4579 DWORD ret;
4580 DWORD_PTR style;
4582 /* test style->view mapping */
4583 hwnd = create_listview_control(LVS_REPORT);
4584 ok(hwnd != NULL, "failed to create a listview window\n");
4586 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4587 expect(LV_VIEW_DETAILS, ret);
4589 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4590 /* LVS_ICON == 0 */
4591 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4592 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4593 expect(LV_VIEW_ICON, ret);
4595 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4596 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4597 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4598 expect(LV_VIEW_SMALLICON, ret);
4600 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4601 SetWindowLongPtrA(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4602 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4603 expect(LV_VIEW_LIST, ret);
4605 /* switching view doesn't touch window style */
4606 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4607 expect(1, ret);
4608 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4609 ok(style & LVS_LIST, "Expected style to be preserved\n");
4610 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4611 expect(1, ret);
4612 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4613 ok(style & LVS_LIST, "Expected style to be preserved\n");
4614 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4615 expect(1, ret);
4616 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4617 ok(style & LVS_LIST, "Expected style to be preserved\n");
4619 /* now change window style to see if view is remapped */
4620 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4621 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SHOWSELALWAYS);
4622 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4623 expect(LV_VIEW_SMALLICON, ret);
4625 DestroyWindow(hwnd);
4628 static void test_canceleditlabel(void)
4630 HWND hwnd, hwndedit;
4631 DWORD ret;
4632 CHAR buff[10];
4633 LVITEMA itema;
4634 static CHAR test[] = "test";
4635 static const CHAR test1[] = "test1";
4637 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4638 ok(hwnd != NULL, "failed to create a listview window\n");
4640 insert_item(hwnd, 0);
4642 /* try without edit created */
4643 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4644 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4645 expect(TRUE, ret);
4646 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4647 "cancel edit label without edit", FALSE);
4649 /* cancel without data change */
4650 SetFocus(hwnd);
4651 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4652 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4653 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4654 expect(TRUE, ret);
4655 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4657 /* cancel after data change */
4658 memset(&itema, 0, sizeof(itema));
4659 itema.pszText = test;
4660 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
4661 expect(TRUE, ret);
4662 SetFocus(hwnd);
4663 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4664 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4665 ret = SetWindowTextA(hwndedit, test1);
4666 expect(1, ret);
4667 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4668 expect(TRUE, ret);
4669 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4670 memset(&itema, 0, sizeof(itema));
4671 itema.pszText = buff;
4672 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4673 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&itema);
4674 expect(5, ret);
4675 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4677 DestroyWindow(hwnd);
4680 static void test_mapidindex(void)
4682 HWND hwnd;
4683 INT ret;
4685 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4686 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4687 ok(hwnd != NULL, "failed to create a listview window\n");
4688 insert_item(hwnd, 0);
4689 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4690 expect(-1, ret);
4691 DestroyWindow(hwnd);
4693 hwnd = create_listview_control(LVS_REPORT);
4694 ok(hwnd != NULL, "failed to create a listview window\n");
4696 /* LVM_MAPINDEXTOID with invalid index */
4697 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4698 expect(-1, ret);
4700 insert_item(hwnd, 0);
4701 insert_item(hwnd, 1);
4703 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, -1, 0);
4704 expect(-1, ret);
4705 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 2, 0);
4706 expect(-1, ret);
4708 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4709 expect(0, ret);
4710 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4711 expect(1, ret);
4712 /* remove 0 indexed item, id retained */
4713 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
4714 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4715 expect(1, ret);
4716 /* new id starts from previous value */
4717 insert_item(hwnd, 1);
4718 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4719 expect(2, ret);
4721 /* get index by id */
4722 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4723 expect(-1, ret);
4724 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4725 expect(-1, ret);
4726 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4727 expect(0, ret);
4728 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4729 expect(1, ret);
4731 DestroyWindow(hwnd);
4734 static void test_getitemspacing(void)
4736 HWND hwnd;
4737 DWORD ret;
4738 INT cx, cy;
4739 HIMAGELIST himl40, himl80;
4741 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4742 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4744 /* LVS_ICON */
4745 hwnd = create_listview_control(LVS_ICON);
4746 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4747 expect(cx, LOWORD(ret));
4748 expect(cy, HIWORD(ret));
4750 /* now try with icons */
4751 himl40 = ImageList_Create(40, 40, 0, 4, 4);
4752 ok(himl40 != NULL, "failed to create imagelist\n");
4753 himl80 = ImageList_Create(80, 80, 0, 4, 4);
4754 ok(himl80 != NULL, "failed to create imagelist\n");
4755 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4756 expect(0, ret);
4758 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4759 /* spacing + icon size returned */
4760 expect(cx + 40, LOWORD(ret));
4761 expect(cy + 40, HIWORD(ret));
4762 /* try changing icon size */
4763 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl80);
4765 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4766 /* spacing + icon size returned */
4767 expect(cx + 80, LOWORD(ret));
4768 expect(cy + 80, HIWORD(ret));
4770 /* set own icon spacing */
4771 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(100, 100));
4772 expect(cx + 80, LOWORD(ret));
4773 expect(cy + 80, HIWORD(ret));
4775 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4776 /* set size returned */
4777 expect(100, LOWORD(ret));
4778 expect(100, HIWORD(ret));
4780 /* now change image list - icon spacing should be unaffected */
4781 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4783 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4784 /* set size returned */
4785 expect(100, LOWORD(ret));
4786 expect(100, HIWORD(ret));
4788 /* spacing = 0 - keep previous value */
4789 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(0, -1));
4790 expect(100, LOWORD(ret));
4791 expect(100, HIWORD(ret));
4793 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4794 expect(100, LOWORD(ret));
4796 expect(0xFFFF, HIWORD(ret));
4798 if (sizeof(void*) == 8)
4800 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4801 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, (DWORD)-1);
4802 expect(100, LOWORD(ret));
4803 expect(0xFFFF, HIWORD(ret));
4805 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4806 expect(0xFFFF, LOWORD(ret));
4807 expect(0xFFFF, HIWORD(ret));
4809 else
4811 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4812 expect(100, LOWORD(ret));
4813 expect(0xFFFF, HIWORD(ret));
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));
4820 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4821 ImageList_Destroy(himl80);
4822 DestroyWindow(hwnd);
4823 /* LVS_SMALLICON */
4824 hwnd = create_listview_control(LVS_SMALLICON);
4825 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4826 expect(cx, LOWORD(ret));
4827 expect(cy, HIWORD(ret));
4829 /* spacing does not depend on selected view type */
4830 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4831 expect(0, ret);
4833 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4834 /* spacing + icon size returned */
4835 expect(cx + 40, LOWORD(ret));
4836 expect(cy + 40, HIWORD(ret));
4838 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4839 ImageList_Destroy(himl40);
4840 DestroyWindow(hwnd);
4841 /* LVS_REPORT */
4842 hwnd = create_listview_control(LVS_REPORT);
4843 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4844 expect(cx, LOWORD(ret));
4845 expect(cy, HIWORD(ret));
4847 DestroyWindow(hwnd);
4848 /* LVS_LIST */
4849 hwnd = create_listview_control(LVS_LIST);
4850 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4851 expect(cx, LOWORD(ret));
4852 expect(cy, HIWORD(ret));
4854 DestroyWindow(hwnd);
4857 static INT get_current_font_height(HWND listview)
4859 TEXTMETRICA tm;
4860 HFONT hfont;
4861 HWND hwnd;
4862 HDC hdc;
4864 hwnd = (HWND)SendMessageA(listview, LVM_GETHEADER, 0, 0);
4865 if (!hwnd)
4866 hwnd = listview;
4868 hfont = (HFONT)SendMessageA(hwnd, WM_GETFONT, 0, 0);
4869 if (!hfont) {
4870 hdc = GetDC(hwnd);
4871 GetTextMetricsA(hdc, &tm);
4872 ReleaseDC(hwnd, hdc);
4874 else {
4875 HFONT oldfont;
4877 hdc = GetDC(0);
4878 oldfont = SelectObject(hdc, hfont);
4879 GetTextMetricsA(hdc, &tm);
4880 SelectObject(hdc, oldfont);
4881 ReleaseDC(0, hdc);
4884 return tm.tmHeight;
4887 static void test_getcolumnwidth(void)
4889 HWND hwnd;
4890 INT ret;
4891 DWORD_PTR style;
4892 LVCOLUMNA col;
4893 LVITEMA itema;
4894 INT height;
4896 /* default column width */
4897 hwnd = create_listview_control(LVS_ICON);
4898 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4899 expect(0, ret);
4900 style = GetWindowLongA(hwnd, GWL_STYLE);
4901 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_LIST);
4902 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4903 todo_wine expect(8, ret);
4904 style = GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_LIST;
4905 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_REPORT);
4906 col.mask = 0;
4907 ret = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4908 expect(0, ret);
4909 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4910 expect(10, ret);
4911 DestroyWindow(hwnd);
4913 /* default column width with item added */
4914 hwnd = create_listview_control(LVS_LIST);
4915 memset(&itema, 0, sizeof(itema));
4916 SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4917 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4918 height = get_current_font_height(hwnd);
4919 ok((ret / height) >= 6, "got width %d, height %d\n", ret, height);
4920 DestroyWindow(hwnd);
4923 static void test_scrollnotify(void)
4925 HWND hwnd;
4926 DWORD ret;
4928 hwnd = create_listview_control(LVS_REPORT);
4930 insert_column(hwnd, 0);
4931 insert_column(hwnd, 1);
4932 insert_item(hwnd, 0);
4934 /* make it scrollable - resize */
4935 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4936 expect(TRUE, ret);
4937 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4938 expect(TRUE, ret);
4940 /* try with dummy call */
4941 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4942 ret = SendMessageA(hwnd, LVM_SCROLL, 0, 0);
4943 expect(TRUE, ret);
4944 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4945 "scroll notify 1", TRUE);
4947 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4948 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 0);
4949 expect(TRUE, ret);
4950 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4951 "scroll notify 2", TRUE);
4953 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4954 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 1);
4955 expect(TRUE, ret);
4956 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4957 "scroll notify 3", TRUE);
4959 DestroyWindow(hwnd);
4962 static void test_LVS_EX_TRANSPARENTBKGND(void)
4964 HWND hwnd;
4965 DWORD ret;
4966 HDC hdc;
4968 hwnd = create_listview_control(LVS_REPORT);
4970 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4971 expect(TRUE, ret);
4973 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4974 LVS_EX_TRANSPARENTBKGND);
4976 ret = SendMessageA(hwnd, LVM_GETBKCOLOR, 0, 0);
4977 if (ret != CLR_NONE)
4979 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4980 DestroyWindow(hwnd);
4981 return;
4984 /* try to set some back color and check this style bit */
4985 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4986 expect(TRUE, ret);
4987 ret = SendMessageA(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4988 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4990 /* now test what this style actually does */
4991 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4992 LVS_EX_TRANSPARENTBKGND);
4994 hdc = GetWindowDC(hwndparent);
4996 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4997 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4998 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4999 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
5001 ReleaseDC(hwndparent, hdc);
5003 DestroyWindow(hwnd);
5006 static void test_approximate_viewrect(void)
5008 HWND hwnd;
5009 DWORD ret;
5010 HIMAGELIST himl;
5011 HBITMAP hbmp;
5012 LVITEMA itema;
5013 static CHAR test[] = "abracadabra, a very long item label";
5015 hwnd = create_listview_control(LVS_ICON);
5016 himl = ImageList_Create(40, 40, 0, 4, 4);
5017 ok(himl != NULL, "failed to create imagelist\n");
5018 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
5019 ok(hbmp != NULL, "failed to create bitmap\n");
5020 ret = ImageList_Add(himl, hbmp, 0);
5021 expect(0, ret);
5022 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
5023 expect(0, ret);
5025 itema.mask = LVIF_IMAGE;
5026 itema.iImage = 0;
5027 itema.iItem = 0;
5028 itema.iSubItem = 0;
5029 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
5030 expect(0, ret);
5032 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
5033 if (ret == 0)
5035 /* version 4.0 */
5036 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
5037 return;
5040 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
5041 expect(MAKELONG(77,827), ret);
5043 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
5044 ok(ret != 0, "got 0\n");
5046 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
5047 expect(MAKELONG(102,302), ret);
5049 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
5050 expect(MAKELONG(52,52), ret);
5052 itema.pszText = test;
5053 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
5054 expect(TRUE, ret);
5055 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
5056 expect(MAKELONG(52,52), ret);
5058 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
5059 expect(MAKELONG(52,2), ret);
5060 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
5061 expect(MAKELONG(52,52), ret);
5062 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
5063 expect(MAKELONG(102,52), ret);
5064 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
5065 expect(MAKELONG(102,102), ret);
5066 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
5067 expect(MAKELONG(102,102), ret);
5068 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
5069 expect(MAKELONG(102,152), ret);
5070 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
5071 expect(MAKELONG(102,152), ret);
5072 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
5073 expect(MAKELONG(152,152), ret);
5075 DestroyWindow(hwnd);
5078 static void test_finditem(void)
5080 LVFINDINFOA fi;
5081 static char f[5];
5082 HWND hwnd;
5083 INT r;
5085 hwnd = create_listview_control(LVS_REPORT);
5086 insert_item(hwnd, 0);
5088 memset(&fi, 0, sizeof(fi));
5090 /* full string search, inserted text was "foo" */
5091 strcpy(f, "foo");
5092 fi.flags = LVFI_STRING;
5093 fi.psz = f;
5094 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5095 expect(0, r);
5096 /* partial string search, inserted text was "foo" */
5097 strcpy(f, "fo");
5098 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5099 fi.psz = f;
5100 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5101 expect(0, r);
5102 /* partial string search, part after start char */
5103 strcpy(f, "oo");
5104 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5105 fi.psz = f;
5106 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5107 expect(-1, r);
5109 /* try with LVFI_SUBSTRING */
5110 strcpy(f, "fo");
5111 fi.flags = LVFI_SUBSTRING;
5112 fi.psz = f;
5113 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5114 if (r == -1)
5116 win_skip("LVFI_SUBSTRING not supported\n");
5117 DestroyWindow(hwnd);
5118 return;
5120 expect(0, r);
5121 strcpy(f, "f");
5122 fi.flags = LVFI_SUBSTRING;
5123 fi.psz = f;
5124 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5125 expect(0, r);
5126 strcpy(f, "o");
5127 fi.flags = LVFI_SUBSTRING;
5128 fi.psz = f;
5129 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5130 expect(-1, r);
5132 strcpy(f, "f");
5133 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
5134 fi.psz = f;
5135 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5136 expect(0, r);
5138 DestroyWindow(hwnd);
5141 static void test_LVS_EX_HEADERINALLVIEWS(void)
5143 HWND hwnd, header;
5144 DWORD style;
5146 hwnd = create_listview_control(LVS_ICON);
5148 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5149 LVS_EX_HEADERINALLVIEWS);
5151 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5152 if (!IsWindow(header))
5154 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
5155 DestroyWindow(hwnd);
5156 return;
5159 /* LVS_NOCOLUMNHEADER works as before */
5160 style = GetWindowLongA(hwnd, GWL_STYLE);
5161 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
5162 style = GetWindowLongA(header, GWL_STYLE);
5163 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
5164 style = GetWindowLongA(hwnd, GWL_STYLE);
5165 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
5166 style = GetWindowLongA(header, GWL_STYLE);
5167 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
5169 /* try to remove style */
5170 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
5171 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5172 ok(IsWindow(header), "Expected header to be created\n");
5173 style = GetWindowLongA(header, GWL_STYLE);
5174 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
5176 DestroyWindow(hwnd);
5178 /* check other styles */
5179 hwnd = create_listview_control(LVS_LIST);
5180 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5181 LVS_EX_HEADERINALLVIEWS);
5182 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5183 ok(IsWindow(header), "Expected header to be created\n");
5184 DestroyWindow(hwnd);
5186 hwnd = create_listview_control(LVS_SMALLICON);
5187 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5188 LVS_EX_HEADERINALLVIEWS);
5189 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5190 ok(IsWindow(header), "Expected header to be created\n");
5191 DestroyWindow(hwnd);
5193 hwnd = create_listview_control(LVS_REPORT);
5194 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5195 LVS_EX_HEADERINALLVIEWS);
5196 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5197 ok(IsWindow(header), "Expected header to be created\n");
5198 DestroyWindow(hwnd);
5201 static void test_hover(void)
5203 HWND hwnd, fg;
5204 DWORD r;
5206 hwnd = create_listview_control(LVS_ICON);
5207 SetForegroundWindow(hwndparent);
5208 fg = GetForegroundWindow();
5209 if (fg != hwndparent)
5211 skip("Window is not in the foreground. Skipping hover tests.\n");
5212 DestroyWindow(hwnd);
5213 return;
5216 /* test WM_MOUSEHOVER forwarding */
5217 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5218 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5219 expect(0, r);
5220 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
5221 g_block_hover = TRUE;
5222 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5223 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5224 expect(0, r);
5225 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
5226 g_block_hover = FALSE;
5228 r = SendMessageA(hwnd, LVM_SETHOVERTIME, 0, 500);
5229 expect(HOVER_DEFAULT, r);
5230 r = SendMessageA(hwnd, LVM_GETHOVERTIME, 0, 0);
5231 expect(500, r);
5233 DestroyWindow(hwnd);
5236 static void test_destroynotify(void)
5238 HWND hwnd;
5239 BOOL ret;
5241 hwnd = create_listview_control(LVS_REPORT);
5242 ok(hwnd != NULL, "failed to create listview window\n");
5244 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5245 DestroyWindow(hwnd);
5246 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
5248 /* same for ownerdata list */
5249 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5250 ok(hwnd != NULL, "failed to create listview window\n");
5252 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5253 DestroyWindow(hwnd);
5254 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_destroy, "check destroy order, ownerdata", FALSE);
5256 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5257 ok(hwnd != NULL, "failed to create listview window\n");
5259 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5260 ret = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
5261 ok(ret == TRUE, "got %d\n", ret);
5262 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_deleteall, "deleteall ownerdata", FALSE);
5263 DestroyWindow(hwnd);
5266 static void test_header_notification(void)
5268 static char textA[] = "newtext";
5269 HWND list, header;
5270 HDITEMA item;
5271 NMHEADERA nmh;
5272 LVCOLUMNA col;
5273 DWORD ret;
5274 BOOL r;
5276 list = create_listview_control(LVS_REPORT);
5277 ok(list != NULL, "failed to create listview window\n");
5279 memset(&col, 0, sizeof(col));
5280 col.mask = LVCF_WIDTH;
5281 col.cx = 100;
5282 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5283 expect(0, ret);
5285 /* check list parent notification after header item changed,
5286 this test should be placed before header subclassing to avoid
5287 Listview -> Header messages to be logged */
5288 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5290 col.mask = LVCF_TEXT;
5291 col.pszText = textA;
5292 r = SendMessageA(list, LVM_SETCOLUMNA, 0, (LPARAM)&col);
5293 expect(TRUE, r);
5295 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_changed_seq,
5296 "header notify, listview", FALSE);
5297 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5298 "header notify, parent", FALSE);
5300 header = subclass_header(list);
5302 ret = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
5303 expect(1, ret);
5305 memset(&item, 0, sizeof(item));
5306 item.mask = HDI_WIDTH;
5307 ret = SendMessageA(header, HDM_GETITEMA, 0, (LPARAM)&item);
5308 expect(1, ret);
5309 expect(100, item.cxy);
5311 nmh.hdr.hwndFrom = header;
5312 nmh.hdr.idFrom = GetWindowLongPtrA(header, GWLP_ID);
5313 nmh.hdr.code = HDN_ITEMCHANGEDA;
5314 nmh.iItem = 0;
5315 nmh.iButton = 0;
5316 item.mask = HDI_WIDTH;
5317 item.cxy = 50;
5318 nmh.pitem = &item;
5319 ret = SendMessageA(list, WM_NOTIFY, 0, (LPARAM)&nmh);
5320 expect(0, ret);
5322 DestroyWindow(list);
5325 static void test_header_notification2(void)
5327 static char textA[] = "newtext";
5328 HWND list, header;
5329 HDITEMW itemW;
5330 NMHEADERW nmhdr;
5331 LVCOLUMNA col;
5332 DWORD ret;
5333 WCHAR buffer[100];
5334 struct message parent_header_notify_seq[] = {
5335 { WM_NOTIFY, sent|id, 0, 0, 0 },
5336 { 0 }
5339 list = create_listview_control(LVS_REPORT);
5340 ok(list != NULL, "failed to create listview window\n");
5342 memset(&col, 0, sizeof(col));
5343 col.mask = LVCF_WIDTH | LVCF_TEXT;
5344 col.cx = 100;
5345 col.pszText = textA;
5346 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5347 expect(0, ret);
5349 header = (HWND)SendMessageA(list, LVM_GETHEADER, 0, 0);
5350 ok(header != 0, "No header\n");
5351 memset(&itemW, 0, sizeof(itemW));
5352 itemW.mask = HDI_WIDTH | HDI_ORDER | HDI_TEXT;
5353 itemW.pszText = buffer;
5354 itemW.cchTextMax = sizeof(buffer);
5355 ret = SendMessageW(header, HDM_GETITEMW, 0, (LPARAM)&itemW);
5356 expect(1, ret);
5358 nmhdr.hdr.hwndFrom = header;
5359 nmhdr.hdr.idFrom = GetWindowLongPtrW(header, GWLP_ID);
5360 nmhdr.iItem = 0;
5361 nmhdr.iButton = 0;
5362 nmhdr.pitem = &itemW;
5364 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5365 nmhdr.hdr.code = HDN_ITEMCHANGINGW;
5366 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5367 ok(ret == 0, "got %d\n", ret);
5368 parent_header_notify_seq[0].id = HDN_ITEMCHANGINGA;
5369 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5370 "header notify, parent", TRUE);
5371 todo_wine
5372 ok(nmhdr.hdr.code == HDN_ITEMCHANGINGA, "Expected ANSI notification code\n");
5373 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5374 nmhdr.hdr.code = HDN_ITEMCHANGEDW;
5375 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5376 ok(ret == 0, "got %d\n", ret);
5377 parent_header_notify_seq[0].id = HDN_ITEMCHANGEDA;
5378 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5379 "header notify, parent", TRUE);
5380 todo_wine
5381 ok(nmhdr.hdr.code == HDN_ITEMCHANGEDA, "Expected ANSI notification code\n");
5382 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5383 SetFocus(list);
5384 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5385 nmhdr.hdr.code = HDN_ITEMCLICKW;
5386 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5387 ok(ret == 0, "got %d\n", ret);
5388 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_click_seq,
5389 "header notify, parent", FALSE);
5390 ok(nmhdr.hdr.code == HDN_ITEMCLICKA, "Expected ANSI notification code\n");
5391 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5392 nmhdr.hdr.code = HDN_ITEMDBLCLICKW;
5393 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5394 ok(ret == 0, "got %d\n", ret);
5395 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5396 "header notify, parent", FALSE);
5397 ok(nmhdr.hdr.code == HDN_ITEMDBLCLICKW, "Expected Unicode notification code\n");
5398 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5399 nmhdr.hdr.code = HDN_DIVIDERDBLCLICKW;
5400 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5401 ok(ret == 0, "got %d\n", ret);
5402 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_divider_dclick_seq,
5403 "header notify, parent", TRUE);
5404 ok(nmhdr.hdr.code == HDN_DIVIDERDBLCLICKA, "Expected ANSI notification code\n");
5405 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5406 nmhdr.hdr.code = HDN_BEGINTRACKW;
5407 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5408 ok(ret == 0, "got %d\n", ret);
5409 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5410 "header notify, parent", FALSE);
5411 ok(nmhdr.hdr.code == HDN_BEGINTRACKW, "Expected Unicode notification code\n");
5412 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5413 nmhdr.hdr.code = HDN_ENDTRACKW;
5414 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5415 ok(ret == 0, "got %d\n", ret);
5416 parent_header_notify_seq[0].id = HDN_ENDTRACKA;
5417 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5418 "header notify, parent", FALSE);
5419 ok(nmhdr.hdr.code == HDN_ENDTRACKA, "Expected ANSI notification code\n");
5420 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5421 nmhdr.hdr.code = HDN_TRACKW;
5422 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5423 ok(ret == 0, "got %d\n", ret);
5424 parent_header_notify_seq[0].id = HDN_TRACKA;
5425 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5426 "header notify, parent", FALSE);
5427 ok(nmhdr.hdr.code == HDN_TRACKA, "Expected ANSI notification code\n");
5428 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5429 nmhdr.hdr.code = HDN_BEGINDRAG;
5430 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5431 ok(ret == 1, "got %d\n", ret);
5432 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5433 "header notify, parent", FALSE);
5434 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5435 nmhdr.hdr.code = HDN_ENDDRAG;
5436 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5437 ok(ret == 0, "got %d\n", ret);
5438 parent_header_notify_seq[0].id = HDN_ENDDRAG;
5439 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5440 "header notify, parent", FALSE);
5441 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5442 nmhdr.hdr.code = HDN_FILTERCHANGE;
5443 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5444 ok(ret == 0, "got %d\n", ret);
5445 parent_header_notify_seq[0].id = HDN_FILTERCHANGE;
5446 parent_header_notify_seq[0].flags |= optional; /* NT4 does not send this message */
5447 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5448 "header notify, parent", FALSE);
5449 parent_header_notify_seq[0].flags &= ~optional;
5450 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5451 nmhdr.hdr.code = HDN_BEGINFILTEREDIT;
5452 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5453 ok(ret == 0, "got %d\n", ret);
5454 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5455 "header notify, parent", FALSE);
5456 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5457 nmhdr.hdr.code = HDN_ENDFILTEREDIT;
5458 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5459 ok(ret == 0, "got %d\n", ret);
5460 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5461 "header notify, parent", FALSE);
5462 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5463 nmhdr.hdr.code = HDN_ITEMSTATEICONCLICK;
5464 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5465 ok(ret == 0, "got %d\n", ret);
5466 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5467 "header notify, parent", FALSE);
5468 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5469 nmhdr.hdr.code = HDN_ITEMKEYDOWN;
5470 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5471 ok(ret == 0, "got %d\n", ret);
5472 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5473 "header notify, parent", FALSE);
5475 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5477 DestroyWindow(list);
5480 static void test_createdragimage(void)
5482 HIMAGELIST himl;
5483 POINT pt;
5484 HWND list;
5486 list = create_listview_control(LVS_ICON);
5487 ok(list != NULL, "failed to create listview window\n");
5489 insert_item(list, 0);
5491 /* NULL point */
5492 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
5493 ok(himl == NULL, "got %p\n", himl);
5495 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
5496 ok(himl != NULL, "got %p\n", himl);
5497 ImageList_Destroy(himl);
5499 DestroyWindow(list);
5502 static void test_dispinfo(void)
5504 static const char testA[] = "TEST";
5505 WCHAR buff[10];
5506 LVITEMA item;
5507 HWND hwnd;
5508 DWORD ret;
5510 hwnd = create_listview_control(LVS_ICON);
5511 ok(hwnd != NULL, "failed to create listview window\n");
5513 insert_item(hwnd, 0);
5515 memset(&item, 0, sizeof(item));
5516 item.pszText = LPSTR_TEXTCALLBACKA;
5517 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5518 expect(1, ret);
5520 g_disp_A_to_W = TRUE;
5521 item.pszText = (char*)buff;
5522 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
5523 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
5524 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
5525 g_disp_A_to_W = FALSE;
5527 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
5528 "got %s, expected %s\n", item.pszText, testA);
5530 DestroyWindow(hwnd);
5533 static void test_LVM_SETITEMTEXT(void)
5535 static char testA[] = "TEST";
5536 LVITEMA item;
5537 HWND hwnd;
5538 DWORD ret;
5540 hwnd = create_listview_control(LVS_ICON);
5541 ok(hwnd != NULL, "failed to create listview window\n");
5543 insert_item(hwnd, 0);
5545 /* null item pointer */
5546 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, 0);
5547 expect(FALSE, ret);
5549 ret = SendMessageA(hwnd, LVM_SETITEMTEXTW, 0, 0);
5550 expect(FALSE, ret);
5552 /* index out of bounds */
5553 item.pszText = testA;
5554 item.cchTextMax = 0; /* ignored */
5555 item.iSubItem = 0;
5557 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 1, (LPARAM)&item);
5558 expect(FALSE, ret);
5560 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, -1, (LPARAM)&item);
5561 expect(FALSE, ret);
5563 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5564 expect(TRUE, ret);
5566 DestroyWindow(hwnd);
5569 static void test_imagelists(void)
5571 HWND hwnd, header;
5572 HIMAGELIST himl1, himl2, himl3;
5573 LRESULT ret;
5575 himl1 = ImageList_Create(40, 40, 0, 4, 4);
5576 himl2 = ImageList_Create(40, 40, 0, 4, 4);
5577 himl3 = ImageList_Create(40, 40, 0, 4, 4);
5578 ok(himl1 != NULL, "Failed to create imagelist\n");
5579 ok(himl2 != NULL, "Failed to create imagelist\n");
5580 ok(himl3 != NULL, "Failed to create imagelist\n");
5582 hwnd = create_listview_control(LVS_REPORT | LVS_SHAREIMAGELISTS);
5583 header = subclass_header(hwnd);
5585 ok(header != NULL, "Expected header\n");
5586 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5587 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5589 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5591 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5592 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5593 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5594 "set normal image list", FALSE);
5596 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5598 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5599 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5600 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5601 "set state image list", TRUE);
5603 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5604 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5606 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5608 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5609 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5610 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_set_imagelist,
5611 "set small image list", FALSE);
5613 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5614 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5615 DestroyWindow(hwnd);
5617 hwnd = create_listview_control(WS_VISIBLE | LVS_ICON);
5619 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5621 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5622 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5623 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5624 "set normal image list", FALSE);
5626 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5628 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5629 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5630 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5631 "set state image list", FALSE);
5633 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5635 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5636 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5637 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5638 "set small image list", FALSE);
5640 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5641 ok(header == NULL, "Expected no header, got %p\n", header);
5643 SetWindowLongPtrA(hwnd, GWL_STYLE, GetWindowLongPtrA(hwnd, GWL_STYLE) | LVS_REPORT);
5645 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5646 ok(header != NULL, "Expected header, got NULL\n");
5648 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5649 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5651 DestroyWindow(hwnd);
5654 static void test_deleteitem(void)
5656 LVITEMA item;
5657 UINT state;
5658 HWND hwnd;
5659 BOOL ret;
5661 hwnd = create_listview_control(LVS_REPORT);
5663 insert_item(hwnd, 0);
5664 insert_item(hwnd, 0);
5665 insert_item(hwnd, 0);
5666 insert_item(hwnd, 0);
5667 insert_item(hwnd, 0);
5669 g_focus_test_LVN_DELETEITEM = TRUE;
5671 /* delete focused item (not the last index) */
5672 item.stateMask = LVIS_FOCUSED;
5673 item.state = LVIS_FOCUSED;
5674 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
5675 ok(ret == TRUE, "got %d\n", ret);
5676 ret = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
5677 ok(ret == TRUE, "got %d\n", ret);
5678 /* next item gets focus */
5679 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5680 ok(state == LVIS_FOCUSED, "got %x\n", state);
5682 /* focus last item and delete it */
5683 item.stateMask = LVIS_FOCUSED;
5684 item.state = LVIS_FOCUSED;
5685 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
5686 ok(ret == TRUE, "got %d\n", ret);
5687 ret = SendMessageA(hwnd, LVM_DELETEITEM, 3, 0);
5688 ok(ret == TRUE, "got %d\n", ret);
5689 /* new last item gets focus */
5690 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5691 ok(state == LVIS_FOCUSED, "got %x\n", state);
5693 /* focus first item and delete it */
5694 item.stateMask = LVIS_FOCUSED;
5695 item.state = LVIS_FOCUSED;
5696 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
5697 ok(ret == TRUE, "got %d\n", ret);
5698 ret = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
5699 ok(ret == TRUE, "got %d\n", ret);
5700 /* new first item gets focus */
5701 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5702 ok(state == LVIS_FOCUSED, "got %x\n", state);
5704 g_focus_test_LVN_DELETEITEM = FALSE;
5706 DestroyWindow(hwnd);
5709 static void test_insertitem(void)
5711 LVITEMA item;
5712 UINT state;
5713 HWND hwnd;
5714 INT ret;
5716 hwnd = create_listview_control(LVS_REPORT);
5718 /* insert item 0 focused */
5719 item.mask = LVIF_STATE;
5720 item.state = LVIS_FOCUSED;
5721 item.stateMask = LVIS_FOCUSED;
5722 item.iItem = 0;
5723 item.iSubItem = 0;
5724 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5725 ok(ret == 0, "got %d\n", ret);
5727 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5728 ok(state == LVIS_FOCUSED, "got %x\n", state);
5730 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5732 /* insert item 1, focus shift */
5733 item.mask = LVIF_STATE;
5734 item.state = LVIS_FOCUSED;
5735 item.stateMask = LVIS_FOCUSED;
5736 item.iItem = 1;
5737 item.iSubItem = 0;
5738 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5739 ok(ret == 1, "got %d\n", ret);
5741 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused_seq, "insert focused", TRUE);
5743 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5744 ok(state == LVIS_FOCUSED, "got %x\n", state);
5746 /* insert item 2, no focus shift */
5747 item.mask = LVIF_STATE;
5748 item.state = 0;
5749 item.stateMask = LVIS_FOCUSED;
5750 item.iItem = 2;
5751 item.iSubItem = 0;
5752 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5753 ok(ret == 2, "got %d\n", ret);
5755 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5756 ok(state == LVIS_FOCUSED, "got %x\n", state);
5758 DestroyWindow(hwnd);
5761 static void test_header_proc(void)
5763 HWND hwnd, header, hdr;
5764 WNDPROC proc1, proc2;
5766 hwnd = create_listview_control(LVS_REPORT);
5768 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5769 ok(header != NULL, "got %p\n", header);
5771 hdr = CreateWindowExA(0, WC_HEADERA, NULL,
5772 WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
5773 0, 0, 0, 0,
5774 NULL, NULL, NULL, NULL);
5775 ok(hdr != NULL, "got %p\n", hdr);
5777 proc1 = (WNDPROC)GetWindowLongPtrW(header, GWLP_WNDPROC);
5778 proc2 = (WNDPROC)GetWindowLongPtrW(hdr, GWLP_WNDPROC);
5779 ok(proc1 == proc2, "got %p, expected %p\n", proc1, proc2);
5781 DestroyWindow(hdr);
5782 DestroyWindow(hwnd);
5785 static void flush_events(void)
5787 MSG msg;
5788 int diff = 200;
5789 int min_timeout = 100;
5790 DWORD time = GetTickCount() + diff;
5792 while (diff > 0)
5794 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
5795 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
5796 diff = time - GetTickCount();
5800 static void test_oneclickactivate(void)
5802 TRACKMOUSEEVENT track;
5803 char item1[] = "item1";
5804 LVITEMA item;
5805 HWND hwnd, fg;
5806 RECT rect;
5807 INT r;
5809 hwnd = CreateWindowExA(0, "SysListView32", "foo", WS_VISIBLE|WS_CHILD|LVS_LIST,
5810 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
5811 ok(hwnd != NULL, "failed to create listview window\n");
5812 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_ONECLICKACTIVATE);
5813 ok(r == 0, "should return zero\n");
5815 SetForegroundWindow(hwndparent);
5816 flush_events();
5817 fg = GetForegroundWindow();
5818 if (fg != hwndparent)
5820 skip("Window is not in the foreground. Skipping oneclickactivate tests.\n");
5821 DestroyWindow(hwnd);
5822 return;
5825 item.mask = LVIF_TEXT;
5826 item.iItem = 0;
5827 item.iSubItem = 0;
5828 item.iImage = 0;
5829 item.pszText = item1;
5830 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
5831 ok(r == 0, "should not fail\n");
5833 GetWindowRect(hwnd, &rect);
5834 SetCursorPos(rect.left+5, rect.top+5);
5835 flush_events();
5836 r = SendMessageA(hwnd, WM_MOUSEMOVE, MAKELONG(1, 1), 0);
5837 expect(0, r);
5839 track.cbSize = sizeof(track);
5840 track.dwFlags = TME_QUERY;
5841 _TrackMouseEvent(&track);
5842 ok(track.hwndTrack == hwnd, "hwndTrack != hwnd\n");
5843 ok(track.dwFlags == TME_LEAVE, "dwFlags = %x\n", track.dwFlags);
5845 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
5846 expect(0, r);
5847 r = SendMessageA(hwnd, WM_MOUSEHOVER, MAKELONG(1, 1), 0);
5848 expect(0, r);
5849 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
5850 expect(1, r);
5852 DestroyWindow(hwnd);
5855 START_TEST(listview)
5857 HMODULE hComctl32;
5858 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
5860 ULONG_PTR ctx_cookie;
5861 HANDLE hCtx;
5863 hComctl32 = GetModuleHandleA("comctl32.dll");
5864 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
5865 if (pInitCommonControlsEx)
5867 INITCOMMONCONTROLSEX iccex;
5868 iccex.dwSize = sizeof(iccex);
5869 iccex.dwICC = ICC_LISTVIEW_CLASSES;
5870 pInitCommonControlsEx(&iccex);
5872 else
5873 InitCommonControls();
5875 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
5877 hwndparent = create_parent_window(FALSE);
5878 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5880 g_is_below_5 = is_below_comctl_5();
5882 test_header_notification();
5883 test_header_notification2();
5884 test_images();
5885 test_checkboxes();
5886 test_items();
5887 test_create();
5888 test_redraw();
5889 test_customdraw();
5890 test_icon_spacing();
5891 test_color();
5892 test_item_count();
5893 test_item_position();
5894 test_columns();
5895 test_getorigin();
5896 test_multiselect();
5897 test_getitemrect();
5898 test_subitem_rect();
5899 test_sorting();
5900 test_ownerdata();
5901 test_norecompute();
5902 test_nosortheader();
5903 test_setredraw();
5904 test_hittest();
5905 test_getviewrect();
5906 test_getitemposition();
5907 test_columnscreation();
5908 test_editbox();
5909 test_notifyformat();
5910 test_indentation();
5911 test_getitemspacing();
5912 test_getcolumnwidth();
5913 test_approximate_viewrect();
5914 test_finditem();
5915 test_hover();
5916 test_destroynotify();
5917 test_createdragimage();
5918 test_dispinfo();
5919 test_LVM_SETITEMTEXT();
5920 test_imagelists();
5921 test_deleteitem();
5922 test_insertitem();
5923 test_header_proc();
5924 test_oneclickactivate();
5926 if (!load_v6_module(&ctx_cookie, &hCtx))
5928 DestroyWindow(hwndparent);
5929 return;
5932 /* comctl32 version 6 tests start here */
5933 test_get_set_view();
5934 test_canceleditlabel();
5935 test_mapidindex();
5936 test_scrollnotify();
5937 test_LVS_EX_TRANSPARENTBKGND();
5938 test_LVS_EX_HEADERINALLVIEWS();
5939 test_deleteitem();
5940 test_multiselect();
5941 test_insertitem();
5942 test_header_proc();
5944 unload_v6_module(ctx_cookie, hCtx);
5946 DestroyWindow(hwndparent);