comctl32/listview: Always forward HDM_SETORDERARRAY to a header.
[wine.git] / dlls / comctl32 / tests / listview.c
blob94c19f44cfb53adbd3191da4e5aece5ffde38d57
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 ownderdata_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, ownderdata_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, ownderdata_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);
3423 static void test_norecompute(void)
3425 static CHAR testA[] = "test";
3426 CHAR buff[10];
3427 LVITEMA item;
3428 HWND hwnd;
3429 DWORD res;
3431 /* self containing control */
3432 hwnd = create_listview_control(LVS_REPORT);
3433 ok(hwnd != NULL, "failed to create a listview window\n");
3434 memset(&item, 0, sizeof(item));
3435 item.mask = LVIF_TEXT | LVIF_STATE;
3436 item.iItem = 0;
3437 item.stateMask = LVIS_SELECTED;
3438 item.state = LVIS_SELECTED;
3439 item.pszText = testA;
3440 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3441 expect(0, res);
3442 /* retrieve with LVIF_NORECOMPUTE */
3443 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3444 item.iItem = 0;
3445 item.pszText = buff;
3446 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3447 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3448 expect(TRUE, res);
3449 ok(lstrcmpA(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
3451 item.mask = LVIF_TEXT;
3452 item.iItem = 1;
3453 item.pszText = LPSTR_TEXTCALLBACKA;
3454 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3455 expect(1, res);
3457 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3458 item.iItem = 1;
3459 item.pszText = buff;
3460 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3462 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3463 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3464 expect(TRUE, res);
3465 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3466 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3467 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
3469 DestroyWindow(hwnd);
3471 /* LVS_OWNERDATA */
3472 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3473 ok(hwnd != NULL, "failed to create a listview window\n");
3475 item.mask = LVIF_STATE;
3476 item.stateMask = LVIS_SELECTED;
3477 item.state = LVIS_SELECTED;
3478 item.iItem = 0;
3479 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3480 expect(0, res);
3482 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3483 item.iItem = 0;
3484 item.pszText = buff;
3485 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3486 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3487 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3488 expect(TRUE, res);
3489 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3490 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3491 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
3493 DestroyWindow(hwnd);
3496 static void test_nosortheader(void)
3498 HWND hwnd, header;
3499 LONG_PTR style;
3501 hwnd = create_listview_control(LVS_REPORT);
3502 ok(hwnd != NULL, "failed to create a listview window\n");
3504 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3505 ok(IsWindow(header), "header expected\n");
3507 style = GetWindowLongPtrA(header, GWL_STYLE);
3508 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
3510 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3511 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
3512 /* HDS_BUTTONS retained */
3513 style = GetWindowLongPtrA(header, GWL_STYLE);
3514 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
3516 DestroyWindow(hwnd);
3518 /* create with LVS_NOSORTHEADER */
3519 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
3520 ok(hwnd != NULL, "failed to create a listview window\n");
3522 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3523 ok(IsWindow(header), "header expected\n");
3525 style = GetWindowLongPtrA(header, GWL_STYLE);
3526 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3528 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3529 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
3530 /* not changed here */
3531 style = GetWindowLongPtrA(header, GWL_STYLE);
3532 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3534 DestroyWindow(hwnd);
3537 static void test_setredraw(void)
3539 HWND hwnd;
3540 DWORD_PTR style;
3541 DWORD ret;
3542 HDC hdc;
3543 RECT rect;
3545 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3546 ok(hwnd != NULL, "failed to create a listview window\n");
3548 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3549 ListView seems to handle it internally without DefWinProc */
3551 /* default value first */
3552 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3553 expect(0, ret);
3554 /* disable */
3555 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3556 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3557 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3558 expect(0, ret);
3559 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3560 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3561 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3562 expect(0, ret);
3564 /* check update rect after redrawing */
3565 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3566 expect(0, ret);
3567 InvalidateRect(hwnd, NULL, FALSE);
3568 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
3569 rect.right = rect.bottom = 1;
3570 GetUpdateRect(hwnd, &rect, FALSE);
3571 expect(0, rect.right);
3572 expect(0, rect.bottom);
3574 /* WM_ERASEBKGND */
3575 hdc = GetWindowDC(hwndparent);
3576 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3577 expect(TRUE, ret);
3578 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3579 expect(0, ret);
3580 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3581 expect(TRUE, ret);
3582 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3583 expect(0, ret);
3584 ReleaseDC(hwndparent, hdc);
3586 /* check notification messages to show that repainting is disabled */
3587 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3588 expect(TRUE, ret);
3589 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3590 expect(0, ret);
3591 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3593 InvalidateRect(hwnd, NULL, TRUE);
3594 UpdateWindow(hwnd);
3595 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3596 "redraw after WM_SETREDRAW (FALSE)", FALSE);
3598 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3599 expect(TRUE, ret);
3600 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3601 InvalidateRect(hwnd, NULL, TRUE);
3602 UpdateWindow(hwnd);
3603 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3604 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3606 /* message isn't forwarded to header */
3607 subclass_header(hwnd);
3608 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3609 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3610 expect(0, ret);
3611 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3612 "WM_SETREDRAW: not forwarded to header", FALSE);
3614 DestroyWindow(hwnd);
3617 static void test_hittest(void)
3619 HWND hwnd;
3620 DWORD r;
3621 RECT bounds;
3622 LVITEMA item;
3623 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3624 POINT pos;
3625 INT x, y, i;
3626 WORD vert;
3627 HIMAGELIST himl, himl2;
3628 HBITMAP hbmp;
3630 hwnd = create_listview_control(LVS_REPORT);
3631 ok(hwnd != NULL, "failed to create a listview window\n");
3633 /* LVS_REPORT with a single subitem (2 columns) */
3634 insert_column(hwnd, 0);
3635 insert_column(hwnd, 1);
3636 insert_item(hwnd, 0);
3638 item.iSubItem = 0;
3639 /* the only purpose of that line is to be as long as a half item rect */
3640 item.pszText = text;
3641 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3642 expect(TRUE, r);
3644 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3645 expect(TRUE, r);
3646 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3647 expect(TRUE, r);
3649 memset(&bounds, 0, sizeof(bounds));
3650 bounds.left = LVIR_BOUNDS;
3651 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3652 expect(1, r);
3653 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3654 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3655 r = SendMessageA(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3656 vert = HIWORD(r);
3657 ok(bounds.bottom - bounds.top == vert,
3658 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3659 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3660 expect(TRUE, r);
3662 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3664 /* outside columns by x position - valid is [0, 199] */
3665 x = -1;
3666 y = pos.y + (bounds.bottom - bounds.top) / 2;
3667 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3668 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3670 x = pos.x + 50; /* column half width */
3671 y = pos.y + (bounds.bottom - bounds.top) / 2;
3672 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3673 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3674 x = pos.x + 150; /* outside column */
3675 y = pos.y + (bounds.bottom - bounds.top) / 2;
3676 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3677 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3678 y = (bounds.bottom - bounds.top) / 2;
3679 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3680 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3681 /* outside possible client rectangle (to right) */
3682 x = pos.x + 500;
3683 y = pos.y + (bounds.bottom - bounds.top) / 2;
3684 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3685 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3686 y = (bounds.bottom - bounds.top) / 2;
3687 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3688 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3689 /* subitem returned with -1 item too */
3690 x = pos.x + 150;
3691 y = bounds.top - vert;
3692 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3693 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3694 /* return values appear to underflow with negative indices */
3695 i = -2;
3696 y = y - vert;
3697 while (i > -10) {
3698 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3699 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3700 y = y - vert;
3701 i--;
3703 /* parent client area is 100x100 by default */
3704 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3705 x = pos.x + 150; /* outside column */
3706 y = pos.y + (bounds.bottom - bounds.top) / 2;
3707 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3708 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3709 y = (bounds.bottom - bounds.top) / 2;
3710 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3711 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3712 /* the same with LVS_EX_FULLROWSELECT */
3713 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3714 x = pos.x + 150; /* outside column */
3715 y = pos.y + (bounds.bottom - bounds.top) / 2;
3716 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3717 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3718 y = (bounds.bottom - bounds.top) / 2;
3719 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3720 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3721 x = pos.x + 150; /* outside column */
3722 y = pos.y + (bounds.bottom - bounds.top) / 2;
3723 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3724 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3725 y = (bounds.bottom - bounds.top) / 2;
3726 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3727 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3728 /* outside possible client rectangle (to right) */
3729 x = pos.x + 500;
3730 y = pos.y + (bounds.bottom - bounds.top) / 2;
3731 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3732 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3733 y = (bounds.bottom - bounds.top) / 2;
3734 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3735 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3736 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3737 himl = ImageList_Create(16, 16, 0, 4, 4);
3738 ok(himl != NULL, "failed to create imagelist\n");
3739 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3740 ok(hbmp != NULL, "failed to create bitmap\n");
3741 r = ImageList_Add(himl, hbmp, 0);
3742 ok(r == 0, "should be zero\n");
3743 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3744 ok(hbmp != NULL, "failed to create bitmap\n");
3745 r = ImageList_Add(himl, hbmp, 0);
3746 ok(r == 1, "should be one\n");
3748 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3749 expect(0, r);
3751 item.mask = LVIF_IMAGE;
3752 item.iImage = 0;
3753 item.iItem = 0;
3754 item.iSubItem = 0;
3755 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3756 expect(TRUE, r);
3757 /* on state icon */
3758 x = pos.x + 8;
3759 y = pos.y + (bounds.bottom - bounds.top) / 2;
3760 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3761 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3762 y = (bounds.bottom - bounds.top) / 2;
3763 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3765 /* state icons indices are 1 based, check with valid index */
3766 item.mask = LVIF_STATE;
3767 item.state = INDEXTOSTATEIMAGEMASK(1);
3768 item.stateMask = LVIS_STATEIMAGEMASK;
3769 item.iItem = 0;
3770 item.iSubItem = 0;
3771 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3772 expect(TRUE, r);
3773 /* on state icon */
3774 x = pos.x + 8;
3775 y = pos.y + (bounds.bottom - bounds.top) / 2;
3776 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3777 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3778 y = (bounds.bottom - bounds.top) / 2;
3779 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3781 himl2 = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3782 ok(himl2 == himl, "should return handle\n");
3784 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3785 expect(0, r);
3786 /* on item icon */
3787 x = pos.x + 8;
3788 y = pos.y + (bounds.bottom - bounds.top) / 2;
3789 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3790 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3791 y = (bounds.bottom - bounds.top) / 2;
3792 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3794 DestroyWindow(hwnd);
3797 static void test_getviewrect(void)
3799 HWND hwnd;
3800 DWORD r;
3801 RECT rect;
3802 LVITEMA item;
3804 hwnd = create_listview_control(LVS_REPORT);
3805 ok(hwnd != NULL, "failed to create a listview window\n");
3807 /* empty */
3808 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3809 expect(TRUE, r);
3811 insert_column(hwnd, 0);
3812 insert_column(hwnd, 1);
3814 memset(&item, 0, sizeof(item));
3815 item.iItem = 0;
3816 item.iSubItem = 0;
3817 SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3819 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3820 expect(TRUE, r);
3821 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3822 expect(TRUE, r);
3824 rect.left = rect.right = rect.top = rect.bottom = -1;
3825 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3826 expect(TRUE, r);
3827 /* left is set to (2e31-1) - XP SP2 */
3828 expect(0, rect.right);
3829 expect(0, rect.top);
3830 expect(0, rect.bottom);
3832 /* switch to LVS_ICON */
3833 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_REPORT);
3835 rect.left = rect.right = rect.top = rect.bottom = -1;
3836 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3837 expect(TRUE, r);
3838 expect(0, rect.left);
3839 expect(0, rect.top);
3840 /* precise value differs for 2k, XP and Vista */
3841 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3842 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3844 DestroyWindow(hwnd);
3847 static void test_getitemposition(void)
3849 HWND hwnd, header;
3850 DWORD r;
3851 POINT pt;
3852 RECT rect;
3854 hwnd = create_listview_control(LVS_REPORT);
3855 ok(hwnd != NULL, "failed to create a listview window\n");
3856 header = subclass_header(hwnd);
3858 /* LVS_REPORT, single item, no columns added */
3859 insert_item(hwnd, 0);
3861 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3863 pt.x = pt.y = -1;
3864 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3865 expect(TRUE, r);
3866 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3868 /* LVS_REPORT, single item, single column */
3869 insert_column(hwnd, 0);
3871 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3873 pt.x = pt.y = -1;
3874 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3875 expect(TRUE, r);
3876 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3878 memset(&rect, 0, sizeof(rect));
3879 SendMessageA(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3880 /* some padding? */
3881 expect(2, pt.x);
3882 /* offset by header height */
3883 expect(rect.bottom - rect.top, pt.y);
3885 DestroyWindow(hwnd);
3888 static void test_columnscreation(void)
3890 HWND hwnd, header;
3891 DWORD r;
3893 hwnd = create_listview_control(LVS_REPORT);
3894 ok(hwnd != NULL, "failed to create a listview window\n");
3896 insert_item(hwnd, 0);
3898 /* headers columns aren't created automatically */
3899 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3900 ok(IsWindow(header), "Expected header handle\n");
3901 r = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
3902 expect(0, r);
3904 DestroyWindow(hwnd);
3907 static void test_getitemrect(void)
3909 HWND hwnd;
3910 HIMAGELIST himl, himl_ret;
3911 HBITMAP hbm;
3912 RECT rect;
3913 DWORD r;
3914 LVITEMA item;
3915 LVCOLUMNA col;
3916 INT order[2];
3917 POINT pt;
3918 HDC hdc;
3920 /* rectangle isn't empty for empty text items */
3921 hwnd = create_listview_control(LVS_LIST);
3922 memset(&item, 0, sizeof(item));
3923 item.mask = 0;
3924 item.iItem = 0;
3925 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3926 expect(0, r);
3927 rect.left = LVIR_LABEL;
3928 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3929 expect(TRUE, r);
3930 expect(0, rect.left);
3931 expect(0, rect.top);
3932 hdc = GetDC(hwnd);
3933 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, rect.right);
3934 ReleaseDC(hwnd, hdc);
3935 DestroyWindow(hwnd);
3937 hwnd = create_listview_control(LVS_REPORT);
3938 ok(hwnd != NULL, "failed to create a listview window\n");
3940 /* empty item */
3941 memset(&item, 0, sizeof(item));
3942 item.iItem = 0;
3943 item.iSubItem = 0;
3944 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3945 expect(0, r);
3947 rect.left = LVIR_BOUNDS;
3948 rect.right = rect.top = rect.bottom = -1;
3949 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3950 expect(TRUE, r);
3952 /* zero width rectangle with no padding */
3953 expect(0, rect.left);
3954 expect(0, rect.right);
3956 insert_column(hwnd, 0);
3957 insert_column(hwnd, 1);
3959 col.mask = LVCF_WIDTH;
3960 col.cx = 50;
3961 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 0, (LPARAM)&col);
3962 expect(TRUE, r);
3964 col.mask = LVCF_WIDTH;
3965 col.cx = 100;
3966 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 1, (LPARAM)&col);
3967 expect(TRUE, r);
3969 rect.left = LVIR_BOUNDS;
3970 rect.right = rect.top = rect.bottom = -1;
3971 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3972 expect(TRUE, r);
3974 /* still no left padding */
3975 expect(0, rect.left);
3976 expect(150, rect.right);
3978 rect.left = LVIR_SELECTBOUNDS;
3979 rect.right = rect.top = rect.bottom = -1;
3980 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3981 expect(TRUE, r);
3982 /* padding */
3983 expect(2, rect.left);
3985 rect.left = LVIR_LABEL;
3986 rect.right = rect.top = rect.bottom = -1;
3987 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3988 expect(TRUE, r);
3989 /* padding, column width */
3990 expect(2, rect.left);
3991 expect(50, rect.right);
3993 /* no icons attached */
3994 rect.left = LVIR_ICON;
3995 rect.right = rect.top = rect.bottom = -1;
3996 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3997 expect(TRUE, r);
3998 /* padding */
3999 expect(2, rect.left);
4000 expect(2, rect.right);
4002 /* change order */
4003 order[0] = 1; order[1] = 0;
4004 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
4005 expect(TRUE, r);
4006 pt.x = -1;
4007 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
4008 expect(TRUE, r);
4009 /* 1 indexed column width + padding */
4010 expect(102, pt.x);
4011 /* rect is at zero too */
4012 rect.left = LVIR_BOUNDS;
4013 rect.right = rect.top = rect.bottom = -1;
4014 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4015 expect(TRUE, r);
4016 expect(0, rect.left);
4017 /* just width sum */
4018 expect(150, rect.right);
4020 rect.left = LVIR_SELECTBOUNDS;
4021 rect.right = rect.top = rect.bottom = -1;
4022 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4023 expect(TRUE, r);
4024 /* column width + padding */
4025 expect(102, rect.left);
4027 /* back to initial order */
4028 order[0] = 0; order[1] = 1;
4029 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
4030 expect(TRUE, r);
4032 /* state icons */
4033 himl = ImageList_Create(16, 16, 0, 2, 2);
4034 ok(himl != NULL, "failed to create imagelist\n");
4035 hbm = CreateBitmap(16, 16, 1, 1, NULL);
4036 ok(hbm != NULL, "failed to create bitmap\n");
4037 r = ImageList_Add(himl, hbm, 0);
4038 expect(0, r);
4039 hbm = CreateBitmap(16, 16, 1, 1, NULL);
4040 ok(hbm != NULL, "failed to create bitmap\n");
4041 r = ImageList_Add(himl, hbm, 0);
4042 expect(1, r);
4044 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
4045 expect(0, r);
4047 item.mask = LVIF_STATE;
4048 item.state = INDEXTOSTATEIMAGEMASK(1);
4049 item.stateMask = LVIS_STATEIMAGEMASK;
4050 item.iItem = 0;
4051 item.iSubItem = 0;
4052 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4053 expect(TRUE, r);
4055 /* icon bounds */
4056 rect.left = LVIR_ICON;
4057 rect.right = rect.top = rect.bottom = -1;
4058 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4059 expect(TRUE, r);
4060 /* padding + stateicon width */
4061 expect(18, rect.left);
4062 expect(18, rect.right);
4063 /* label bounds */
4064 rect.left = LVIR_LABEL;
4065 rect.right = rect.top = rect.bottom = -1;
4066 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4067 expect(TRUE, r);
4068 /* padding + stateicon width -> column width */
4069 expect(18, rect.left);
4070 expect(50, rect.right);
4072 himl_ret = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
4073 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
4075 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
4076 expect(0, r);
4078 item.mask = LVIF_STATE | LVIF_IMAGE;
4079 item.iImage = 1;
4080 item.state = 0;
4081 item.stateMask = ~0;
4082 item.iItem = 0;
4083 item.iSubItem = 0;
4084 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4085 expect(TRUE, r);
4087 /* icon bounds */
4088 rect.left = LVIR_ICON;
4089 rect.right = rect.top = rect.bottom = -1;
4090 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4091 expect(TRUE, r);
4092 /* padding, icon width */
4093 expect(2, rect.left);
4094 expect(18, rect.right);
4095 /* label bounds */
4096 rect.left = LVIR_LABEL;
4097 rect.right = rect.top = rect.bottom = -1;
4098 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4099 expect(TRUE, r);
4100 /* padding + icon width -> column width */
4101 expect(18, rect.left);
4102 expect(50, rect.right);
4104 /* select bounds */
4105 rect.left = LVIR_SELECTBOUNDS;
4106 rect.right = rect.top = rect.bottom = -1;
4107 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4108 expect(TRUE, r);
4109 /* padding, column width */
4110 expect(2, rect.left);
4111 expect(50, rect.right);
4113 /* try with indentation */
4114 item.mask = LVIF_INDENT;
4115 item.iIndent = 1;
4116 item.iItem = 0;
4117 item.iSubItem = 0;
4118 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4119 expect(TRUE, r);
4121 /* bounds */
4122 rect.left = LVIR_BOUNDS;
4123 rect.right = rect.top = rect.bottom = -1;
4124 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4125 expect(TRUE, r);
4126 /* padding + 1 icon width, column width */
4127 expect(0, rect.left);
4128 expect(150, rect.right);
4130 /* select bounds */
4131 rect.left = LVIR_SELECTBOUNDS;
4132 rect.right = rect.top = rect.bottom = -1;
4133 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4134 expect(TRUE, r);
4135 /* padding + 1 icon width, column width */
4136 expect(2 + 16, rect.left);
4137 expect(50, rect.right);
4139 /* label bounds */
4140 rect.left = LVIR_LABEL;
4141 rect.right = rect.top = rect.bottom = -1;
4142 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4143 expect(TRUE, r);
4144 /* padding + 2 icon widths, column width */
4145 expect(2 + 16*2, rect.left);
4146 expect(50, rect.right);
4148 /* icon bounds */
4149 rect.left = LVIR_ICON;
4150 rect.right = rect.top = rect.bottom = -1;
4151 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4152 expect(TRUE, r);
4153 /* padding + 1 icon width indentation, icon width */
4154 expect(2 + 16, rect.left);
4155 expect(34, rect.right);
4157 DestroyWindow(hwnd);
4160 static void test_editbox(void)
4162 static CHAR testitemA[] = "testitem";
4163 static CHAR testitem1A[] = "testitem_quitelongname";
4164 static CHAR testitem2A[] = "testITEM_quitelongname";
4165 static CHAR buffer[25];
4166 HWND hwnd, hwndedit, hwndedit2, header;
4167 LVITEMA item;
4168 INT r;
4170 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4171 ok(hwnd != NULL, "failed to create a listview window\n");
4173 insert_column(hwnd, 0);
4175 memset(&item, 0, sizeof(item));
4176 item.mask = LVIF_TEXT;
4177 item.pszText = testitemA;
4178 item.iItem = 0;
4179 item.iSubItem = 0;
4180 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4181 expect(0, r);
4183 /* test notifications without edit created */
4184 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4185 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
4186 expect(0, r);
4187 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4188 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
4189 /* same thing but with valid window */
4190 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
4191 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
4192 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4193 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
4194 expect(0, r);
4195 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4196 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
4197 DestroyWindow(hwndedit);
4199 /* setting focus is necessary */
4200 SetFocus(hwnd);
4201 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4202 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4204 /* test children Z-order after Edit box created */
4205 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4206 ok(IsWindow(header), "Expected header to be created\n");
4207 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4208 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4210 /* modify initial string */
4211 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4212 expect(TRUE, r);
4214 /* edit window is resized and repositioned,
4215 check again for Z-order - it should be preserved */
4216 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4217 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4219 /* return focus to listview */
4220 SetFocus(hwnd);
4222 memset(&item, 0, sizeof(item));
4223 item.mask = LVIF_TEXT;
4224 item.pszText = buffer;
4225 item.cchTextMax = sizeof(buffer);
4226 item.iItem = 0;
4227 item.iSubItem = 0;
4228 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4229 expect(TRUE, r);
4231 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4233 /* send LVM_EDITLABEL on already created edit */
4234 SetFocus(hwnd);
4235 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4236 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4237 /* focus will be set to edit */
4238 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
4239 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4240 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
4242 /* creating label disabled when control isn't focused */
4243 SetFocus(0);
4244 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4245 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4247 /* check EN_KILLFOCUS handling */
4248 memset(&item, 0, sizeof(item));
4249 item.pszText = testitemA;
4250 item.iItem = 0;
4251 item.iSubItem = 0;
4252 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4253 expect(TRUE, r);
4255 SetFocus(hwnd);
4256 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4257 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4258 /* modify edit and notify control that it lost focus */
4259 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4260 expect(TRUE, r);
4261 g_editbox_disp_info.item.pszText = NULL;
4262 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4263 expect(0, r);
4264 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
4266 memset(&item, 0, sizeof(item));
4267 item.pszText = buffer;
4268 item.cchTextMax = sizeof(buffer);
4269 item.iItem = 0;
4270 item.iSubItem = 0;
4271 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4272 expect(lstrlenA(item.pszText), r);
4273 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4274 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4276 /* change item name to differ in casing only */
4277 SetFocus(hwnd);
4278 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4279 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4280 /* modify edit and notify control that it lost focus */
4281 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
4282 expect(TRUE, r);
4283 g_editbox_disp_info.item.pszText = NULL;
4284 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4285 expect(0, r);
4286 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
4288 memset(&item, 0, sizeof(item));
4289 item.pszText = buffer;
4290 item.cchTextMax = sizeof(buffer);
4291 item.iItem = 0;
4292 item.iSubItem = 0;
4293 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4294 expect(lstrlenA(item.pszText), r);
4295 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
4296 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4298 /* end edit without saving */
4299 SetFocus(hwnd);
4300 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4301 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4302 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
4303 expect(0, r);
4304 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4305 "edit box - end edit, no change, escape", TRUE);
4306 /* end edit with saving */
4307 SetFocus(hwnd);
4308 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4309 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4310 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
4311 expect(0, r);
4312 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4313 "edit box - end edit, no change, return", TRUE);
4315 memset(&item, 0, sizeof(item));
4316 item.pszText = buffer;
4317 item.cchTextMax = sizeof(buffer);
4318 item.iItem = 0;
4319 item.iSubItem = 0;
4320 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4321 expect(lstrlenA(item.pszText), r);
4322 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
4324 /* LVM_EDITLABEL with -1 destroys current edit */
4325 hwndedit = (HWND)SendMessageA(hwnd, LVM_GETEDITCONTROL, 0, 0);
4326 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4327 /* no edit present */
4328 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4329 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4330 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4331 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4332 /* edit present */
4333 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4334 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4335 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4336 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4337 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4338 /* check another negative value */
4339 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4340 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4341 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4342 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -2, 0);
4343 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4344 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4345 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4346 /* and value greater than max item index */
4347 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4348 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4349 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4350 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
4351 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, r, 0);
4352 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4353 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4354 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4356 /* messaging tests */
4357 SetFocus(hwnd);
4358 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4359 blockEdit = FALSE;
4360 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4361 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4362 /* testing only sizing messages */
4363 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
4364 "edit box create - sizing", FALSE);
4366 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4367 SetFocus(hwnd);
4368 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4369 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4370 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4371 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4372 expect(0, r);
4373 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4374 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
4376 DestroyWindow(hwnd);
4379 static void test_notifyformat(void)
4381 HWND hwnd, header;
4382 DWORD r;
4384 hwnd = create_listview_control(LVS_REPORT);
4385 ok(hwnd != NULL, "failed to create a listview window\n");
4387 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4388 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4389 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4390 expect(0, r);
4391 SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4392 /* set */
4393 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
4394 expect(0, r);
4395 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4396 if (r == 1)
4398 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
4399 expect(1, r);
4400 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4401 expect(0, r);
4403 else
4405 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4406 DestroyWindow(hwnd);
4407 return;
4410 DestroyWindow(hwnd);
4412 /* test failure in parent WM_NOTIFYFORMAT */
4413 notifyFormat = 0;
4414 hwnd = create_listview_control(LVS_REPORT);
4415 ok(hwnd != NULL, "failed to create a listview window\n");
4416 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4417 ok(IsWindow(header), "expected header to be created\n");
4418 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4419 expect(0, r);
4420 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4421 ok( r == 1, "Expected 1, got %d\n", r );
4422 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4423 ok(r != 0, "Expected valid format\n");
4425 notifyFormat = NFR_UNICODE;
4426 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4427 expect(NFR_UNICODE, r);
4428 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4429 expect(1, r);
4430 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4431 ok( r == 1, "Expected 1, got %d\n", r );
4433 notifyFormat = NFR_ANSI;
4434 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4435 expect(NFR_ANSI, r);
4436 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4437 expect(0, r);
4438 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4439 ok( r == 1, "Expected 1, got %d\n", r );
4441 DestroyWindow(hwnd);
4443 hwndparentW = create_parent_window(TRUE);
4444 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
4445 if (!IsWindow(hwndparentW)) return;
4447 notifyFormat = -1;
4448 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4449 ok(hwnd != NULL, "failed to create a listview window\n");
4450 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4451 ok(IsWindow(header), "expected header to be created\n");
4452 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4453 expect(1, r);
4454 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4455 expect(1, r);
4456 DestroyWindow(hwnd);
4457 /* receiving error code defaulting to ansi */
4458 notifyFormat = 0;
4459 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4460 ok(hwnd != NULL, "failed to create a listview window\n");
4461 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4462 ok(IsWindow(header), "expected header to be created\n");
4463 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4464 expect(0, r);
4465 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4466 expect(1, r);
4467 DestroyWindow(hwnd);
4468 /* receiving ansi code from unicode window, use it */
4469 notifyFormat = NFR_ANSI;
4470 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4471 ok(hwnd != NULL, "failed to create a listview window\n");
4472 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4473 ok(IsWindow(header), "expected header to be created\n");
4474 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4475 expect(0, r);
4476 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4477 expect(1, r);
4478 DestroyWindow(hwnd);
4479 /* unicode listview with ansi parent window */
4480 notifyFormat = -1;
4481 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4482 ok(hwnd != NULL, "failed to create a listview window\n");
4483 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4484 ok(IsWindow(header), "expected header to be created\n");
4485 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4486 expect(0, r);
4487 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4488 expect(1, r);
4489 DestroyWindow(hwnd);
4490 /* unicode listview with ansi parent window, return error code */
4491 notifyFormat = 0;
4492 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4493 ok(hwnd != NULL, "failed to create a listview window\n");
4494 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4495 ok(IsWindow(header), "expected header to be created\n");
4496 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4497 expect(0, r);
4498 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4499 expect(1, r);
4500 DestroyWindow(hwnd);
4502 DestroyWindow(hwndparentW);
4505 static void test_indentation(void)
4507 HWND hwnd;
4508 LVITEMA item;
4509 DWORD r;
4511 hwnd = create_listview_control(LVS_REPORT);
4512 ok(hwnd != NULL, "failed to create a listview window\n");
4514 memset(&item, 0, sizeof(item));
4515 item.mask = LVIF_INDENT;
4516 item.iItem = 0;
4517 item.iIndent = I_INDENTCALLBACK;
4518 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4519 expect(0, r);
4521 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4523 item.iItem = 0;
4524 item.mask = LVIF_INDENT;
4525 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4526 expect(TRUE, r);
4528 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
4529 "get indent dispinfo", FALSE);
4531 DestroyWindow(hwnd);
4534 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
4536 return 0;
4539 static BOOL is_below_comctl_5(void)
4541 HWND hwnd;
4542 BOOL ret;
4544 hwnd = create_listview_control(LVS_REPORT);
4545 ok(hwnd != NULL, "failed to create a listview window\n");
4546 insert_item(hwnd, 0);
4548 ret = SendMessageA(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
4550 DestroyWindow(hwnd);
4552 return !ret;
4555 static void test_get_set_view(void)
4557 HWND hwnd;
4558 DWORD ret;
4559 DWORD_PTR style;
4561 /* test style->view mapping */
4562 hwnd = create_listview_control(LVS_REPORT);
4563 ok(hwnd != NULL, "failed to create a listview window\n");
4565 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4566 expect(LV_VIEW_DETAILS, ret);
4568 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4569 /* LVS_ICON == 0 */
4570 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4571 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4572 expect(LV_VIEW_ICON, ret);
4574 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4575 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4576 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4577 expect(LV_VIEW_SMALLICON, ret);
4579 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4580 SetWindowLongPtrA(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4581 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4582 expect(LV_VIEW_LIST, ret);
4584 /* switching view doesn't touch window style */
4585 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4586 expect(1, ret);
4587 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4588 ok(style & LVS_LIST, "Expected style to be preserved\n");
4589 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4590 expect(1, ret);
4591 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4592 ok(style & LVS_LIST, "Expected style to be preserved\n");
4593 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4594 expect(1, ret);
4595 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4596 ok(style & LVS_LIST, "Expected style to be preserved\n");
4598 /* now change window style to see if view is remapped */
4599 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4600 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SHOWSELALWAYS);
4601 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4602 expect(LV_VIEW_SMALLICON, ret);
4604 DestroyWindow(hwnd);
4607 static void test_canceleditlabel(void)
4609 HWND hwnd, hwndedit;
4610 DWORD ret;
4611 CHAR buff[10];
4612 LVITEMA itema;
4613 static CHAR test[] = "test";
4614 static const CHAR test1[] = "test1";
4616 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4617 ok(hwnd != NULL, "failed to create a listview window\n");
4619 insert_item(hwnd, 0);
4621 /* try without edit created */
4622 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4623 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4624 expect(TRUE, ret);
4625 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4626 "cancel edit label without edit", FALSE);
4628 /* cancel without data change */
4629 SetFocus(hwnd);
4630 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4631 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4632 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4633 expect(TRUE, ret);
4634 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4636 /* cancel after data change */
4637 memset(&itema, 0, sizeof(itema));
4638 itema.pszText = test;
4639 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
4640 expect(TRUE, ret);
4641 SetFocus(hwnd);
4642 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4643 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4644 ret = SetWindowTextA(hwndedit, test1);
4645 expect(1, ret);
4646 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4647 expect(TRUE, ret);
4648 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4649 memset(&itema, 0, sizeof(itema));
4650 itema.pszText = buff;
4651 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4652 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&itema);
4653 expect(5, ret);
4654 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4656 DestroyWindow(hwnd);
4659 static void test_mapidindex(void)
4661 HWND hwnd;
4662 INT ret;
4664 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4665 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4666 ok(hwnd != NULL, "failed to create a listview window\n");
4667 insert_item(hwnd, 0);
4668 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4669 expect(-1, ret);
4670 DestroyWindow(hwnd);
4672 hwnd = create_listview_control(LVS_REPORT);
4673 ok(hwnd != NULL, "failed to create a listview window\n");
4675 /* LVM_MAPINDEXTOID with invalid index */
4676 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4677 expect(-1, ret);
4679 insert_item(hwnd, 0);
4680 insert_item(hwnd, 1);
4682 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, -1, 0);
4683 expect(-1, ret);
4684 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 2, 0);
4685 expect(-1, ret);
4687 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4688 expect(0, ret);
4689 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4690 expect(1, ret);
4691 /* remove 0 indexed item, id retained */
4692 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
4693 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4694 expect(1, ret);
4695 /* new id starts from previous value */
4696 insert_item(hwnd, 1);
4697 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4698 expect(2, ret);
4700 /* get index by id */
4701 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4702 expect(-1, ret);
4703 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4704 expect(-1, ret);
4705 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4706 expect(0, ret);
4707 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4708 expect(1, ret);
4710 DestroyWindow(hwnd);
4713 static void test_getitemspacing(void)
4715 HWND hwnd;
4716 DWORD ret;
4717 INT cx, cy;
4718 HIMAGELIST himl40, himl80;
4720 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4721 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4723 /* LVS_ICON */
4724 hwnd = create_listview_control(LVS_ICON);
4725 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4726 expect(cx, LOWORD(ret));
4727 expect(cy, HIWORD(ret));
4729 /* now try with icons */
4730 himl40 = ImageList_Create(40, 40, 0, 4, 4);
4731 ok(himl40 != NULL, "failed to create imagelist\n");
4732 himl80 = ImageList_Create(80, 80, 0, 4, 4);
4733 ok(himl80 != NULL, "failed to create imagelist\n");
4734 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4735 expect(0, ret);
4737 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4738 /* spacing + icon size returned */
4739 expect(cx + 40, LOWORD(ret));
4740 expect(cy + 40, HIWORD(ret));
4741 /* try changing icon size */
4742 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl80);
4744 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4745 /* spacing + icon size returned */
4746 expect(cx + 80, LOWORD(ret));
4747 expect(cy + 80, HIWORD(ret));
4749 /* set own icon spacing */
4750 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(100, 100));
4751 expect(cx + 80, LOWORD(ret));
4752 expect(cy + 80, HIWORD(ret));
4754 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4755 /* set size returned */
4756 expect(100, LOWORD(ret));
4757 expect(100, HIWORD(ret));
4759 /* now change image list - icon spacing should be unaffected */
4760 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4762 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4763 /* set size returned */
4764 expect(100, LOWORD(ret));
4765 expect(100, HIWORD(ret));
4767 /* spacing = 0 - keep previous value */
4768 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(0, -1));
4769 expect(100, LOWORD(ret));
4770 expect(100, HIWORD(ret));
4772 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4773 expect(100, LOWORD(ret));
4775 expect(0xFFFF, HIWORD(ret));
4777 if (sizeof(void*) == 8)
4779 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4780 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, (DWORD)-1);
4781 expect(100, LOWORD(ret));
4782 expect(0xFFFF, HIWORD(ret));
4784 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4785 expect(0xFFFF, LOWORD(ret));
4786 expect(0xFFFF, HIWORD(ret));
4788 else
4790 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4791 expect(100, LOWORD(ret));
4792 expect(0xFFFF, HIWORD(ret));
4794 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4795 /* spacing + icon size returned */
4796 expect(cx + 40, LOWORD(ret));
4797 expect(cy + 40, HIWORD(ret));
4799 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4800 ImageList_Destroy(himl80);
4801 DestroyWindow(hwnd);
4802 /* LVS_SMALLICON */
4803 hwnd = create_listview_control(LVS_SMALLICON);
4804 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4805 expect(cx, LOWORD(ret));
4806 expect(cy, HIWORD(ret));
4808 /* spacing does not depend on selected view type */
4809 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4810 expect(0, ret);
4812 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4813 /* spacing + icon size returned */
4814 expect(cx + 40, LOWORD(ret));
4815 expect(cy + 40, HIWORD(ret));
4817 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4818 ImageList_Destroy(himl40);
4819 DestroyWindow(hwnd);
4820 /* LVS_REPORT */
4821 hwnd = create_listview_control(LVS_REPORT);
4822 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4823 expect(cx, LOWORD(ret));
4824 expect(cy, HIWORD(ret));
4826 DestroyWindow(hwnd);
4827 /* LVS_LIST */
4828 hwnd = create_listview_control(LVS_LIST);
4829 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4830 expect(cx, LOWORD(ret));
4831 expect(cy, HIWORD(ret));
4833 DestroyWindow(hwnd);
4836 static void test_getcolumnwidth(void)
4838 HWND hwnd;
4839 INT ret;
4840 DWORD_PTR style;
4841 LVCOLUMNA col;
4842 LVITEMA itema;
4843 HDC hdc;
4845 /* default column width */
4846 hwnd = create_listview_control(LVS_ICON);
4847 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4848 expect(0, ret);
4849 style = GetWindowLongA(hwnd, GWL_STYLE);
4850 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_LIST);
4851 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4852 todo_wine expect(8, ret);
4853 style = GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_LIST;
4854 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_REPORT);
4855 col.mask = 0;
4856 ret = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4857 expect(0, ret);
4858 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4859 expect(10, ret);
4860 DestroyWindow(hwnd);
4862 /* default column width with item added */
4863 hwnd = create_listview_control(LVS_LIST);
4864 memset(&itema, 0, sizeof(itema));
4865 SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4866 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4867 hdc = GetDC(hwnd);
4868 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, ret);
4869 ReleaseDC(hwnd, hdc);
4870 DestroyWindow(hwnd);
4873 static void test_scrollnotify(void)
4875 HWND hwnd;
4876 DWORD ret;
4878 hwnd = create_listview_control(LVS_REPORT);
4880 insert_column(hwnd, 0);
4881 insert_column(hwnd, 1);
4882 insert_item(hwnd, 0);
4884 /* make it scrollable - resize */
4885 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4886 expect(TRUE, ret);
4887 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4888 expect(TRUE, ret);
4890 /* try with dummy call */
4891 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4892 ret = SendMessageA(hwnd, LVM_SCROLL, 0, 0);
4893 expect(TRUE, ret);
4894 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4895 "scroll notify 1", TRUE);
4897 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4898 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 0);
4899 expect(TRUE, ret);
4900 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4901 "scroll notify 2", TRUE);
4903 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4904 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 1);
4905 expect(TRUE, ret);
4906 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4907 "scroll notify 3", TRUE);
4909 DestroyWindow(hwnd);
4912 static void test_LVS_EX_TRANSPARENTBKGND(void)
4914 HWND hwnd;
4915 DWORD ret;
4916 HDC hdc;
4918 hwnd = create_listview_control(LVS_REPORT);
4920 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4921 expect(TRUE, ret);
4923 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4924 LVS_EX_TRANSPARENTBKGND);
4926 ret = SendMessageA(hwnd, LVM_GETBKCOLOR, 0, 0);
4927 if (ret != CLR_NONE)
4929 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4930 DestroyWindow(hwnd);
4931 return;
4934 /* try to set some back color and check this style bit */
4935 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4936 expect(TRUE, ret);
4937 ret = SendMessageA(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4938 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4940 /* now test what this style actually does */
4941 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4942 LVS_EX_TRANSPARENTBKGND);
4944 hdc = GetWindowDC(hwndparent);
4946 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4947 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4948 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4949 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4951 ReleaseDC(hwndparent, hdc);
4953 DestroyWindow(hwnd);
4956 static void test_approximate_viewrect(void)
4958 HWND hwnd;
4959 DWORD ret;
4960 HIMAGELIST himl;
4961 HBITMAP hbmp;
4962 LVITEMA itema;
4963 static CHAR test[] = "abracadabra, a very long item label";
4965 hwnd = create_listview_control(LVS_ICON);
4966 himl = ImageList_Create(40, 40, 0, 4, 4);
4967 ok(himl != NULL, "failed to create imagelist\n");
4968 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4969 ok(hbmp != NULL, "failed to create bitmap\n");
4970 ret = ImageList_Add(himl, hbmp, 0);
4971 expect(0, ret);
4972 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4973 expect(0, ret);
4975 itema.mask = LVIF_IMAGE;
4976 itema.iImage = 0;
4977 itema.iItem = 0;
4978 itema.iSubItem = 0;
4979 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4980 expect(0, ret);
4982 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4983 if (ret == 0)
4985 /* version 4.0 */
4986 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4987 return;
4990 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4991 expect(MAKELONG(77,827), ret);
4993 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4994 ok(ret != 0, "got 0\n");
4996 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4997 expect(MAKELONG(102,302), ret);
4999 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
5000 expect(MAKELONG(52,52), ret);
5002 itema.pszText = test;
5003 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
5004 expect(TRUE, ret);
5005 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
5006 expect(MAKELONG(52,52), ret);
5008 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
5009 expect(MAKELONG(52,2), ret);
5010 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
5011 expect(MAKELONG(52,52), ret);
5012 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
5013 expect(MAKELONG(102,52), ret);
5014 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
5015 expect(MAKELONG(102,102), ret);
5016 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
5017 expect(MAKELONG(102,102), ret);
5018 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
5019 expect(MAKELONG(102,152), ret);
5020 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
5021 expect(MAKELONG(102,152), ret);
5022 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
5023 expect(MAKELONG(152,152), ret);
5025 DestroyWindow(hwnd);
5028 static void test_finditem(void)
5030 LVFINDINFOA fi;
5031 static char f[5];
5032 HWND hwnd;
5033 INT r;
5035 hwnd = create_listview_control(LVS_REPORT);
5036 insert_item(hwnd, 0);
5038 memset(&fi, 0, sizeof(fi));
5040 /* full string search, inserted text was "foo" */
5041 strcpy(f, "foo");
5042 fi.flags = LVFI_STRING;
5043 fi.psz = f;
5044 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5045 expect(0, r);
5046 /* partial string search, inserted text was "foo" */
5047 strcpy(f, "fo");
5048 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5049 fi.psz = f;
5050 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5051 expect(0, r);
5052 /* partial string search, part after start char */
5053 strcpy(f, "oo");
5054 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5055 fi.psz = f;
5056 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5057 expect(-1, r);
5059 /* try with LVFI_SUBSTRING */
5060 strcpy(f, "fo");
5061 fi.flags = LVFI_SUBSTRING;
5062 fi.psz = f;
5063 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5064 if (r == -1)
5066 win_skip("LVFI_SUBSTRING not supported\n");
5067 DestroyWindow(hwnd);
5068 return;
5070 expect(0, r);
5071 strcpy(f, "f");
5072 fi.flags = LVFI_SUBSTRING;
5073 fi.psz = f;
5074 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5075 expect(0, r);
5076 strcpy(f, "o");
5077 fi.flags = LVFI_SUBSTRING;
5078 fi.psz = f;
5079 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5080 expect(-1, r);
5082 strcpy(f, "f");
5083 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
5084 fi.psz = f;
5085 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5086 expect(0, r);
5088 DestroyWindow(hwnd);
5091 static void test_LVS_EX_HEADERINALLVIEWS(void)
5093 HWND hwnd, header;
5094 DWORD style;
5096 hwnd = create_listview_control(LVS_ICON);
5098 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5099 LVS_EX_HEADERINALLVIEWS);
5101 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5102 if (!IsWindow(header))
5104 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
5105 DestroyWindow(hwnd);
5106 return;
5109 /* LVS_NOCOLUMNHEADER works as before */
5110 style = GetWindowLongA(hwnd, GWL_STYLE);
5111 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
5112 style = GetWindowLongA(header, GWL_STYLE);
5113 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
5114 style = GetWindowLongA(hwnd, GWL_STYLE);
5115 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
5116 style = GetWindowLongA(header, GWL_STYLE);
5117 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
5119 /* try to remove style */
5120 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
5121 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5122 ok(IsWindow(header), "Expected header to be created\n");
5123 style = GetWindowLongA(header, GWL_STYLE);
5124 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
5126 DestroyWindow(hwnd);
5128 /* check other styles */
5129 hwnd = create_listview_control(LVS_LIST);
5130 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5131 LVS_EX_HEADERINALLVIEWS);
5132 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5133 ok(IsWindow(header), "Expected header to be created\n");
5134 DestroyWindow(hwnd);
5136 hwnd = create_listview_control(LVS_SMALLICON);
5137 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5138 LVS_EX_HEADERINALLVIEWS);
5139 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5140 ok(IsWindow(header), "Expected header to be created\n");
5141 DestroyWindow(hwnd);
5143 hwnd = create_listview_control(LVS_REPORT);
5144 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5145 LVS_EX_HEADERINALLVIEWS);
5146 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5147 ok(IsWindow(header), "Expected header to be created\n");
5148 DestroyWindow(hwnd);
5151 static void test_hover(void)
5153 HWND hwnd;
5154 DWORD r;
5156 hwnd = create_listview_control(LVS_ICON);
5158 /* test WM_MOUSEHOVER forwarding */
5159 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5160 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5161 expect(0, r);
5162 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
5163 g_block_hover = TRUE;
5164 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5165 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5166 expect(0, r);
5167 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
5168 g_block_hover = FALSE;
5170 r = SendMessageA(hwnd, LVM_SETHOVERTIME, 0, 500);
5171 expect(HOVER_DEFAULT, r);
5172 r = SendMessageA(hwnd, LVM_GETHOVERTIME, 0, 0);
5173 expect(500, r);
5175 DestroyWindow(hwnd);
5178 static void test_destroynotify(void)
5180 HWND hwnd;
5181 BOOL ret;
5183 hwnd = create_listview_control(LVS_REPORT);
5184 ok(hwnd != NULL, "failed to create listview window\n");
5186 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5187 DestroyWindow(hwnd);
5188 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
5190 /* same for ownerdata list */
5191 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5192 ok(hwnd != NULL, "failed to create listview window\n");
5194 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5195 DestroyWindow(hwnd);
5196 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_destroy, "check destroy order, ownerdata", FALSE);
5198 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5199 ok(hwnd != NULL, "failed to create listview window\n");
5201 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5202 ret = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
5203 ok(ret == TRUE, "got %d\n", ret);
5204 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_deleteall, "deleteall ownerdata", FALSE);
5205 DestroyWindow(hwnd);
5208 static void test_header_notification(void)
5210 static char textA[] = "newtext";
5211 HWND list, header;
5212 HDITEMA item;
5213 NMHEADERA nmh;
5214 LVCOLUMNA col;
5215 DWORD ret;
5216 BOOL r;
5218 list = create_listview_control(LVS_REPORT);
5219 ok(list != NULL, "failed to create listview window\n");
5221 memset(&col, 0, sizeof(col));
5222 col.mask = LVCF_WIDTH;
5223 col.cx = 100;
5224 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5225 expect(0, ret);
5227 /* check list parent notification after header item changed,
5228 this test should be placed before header subclassing to avoid
5229 Listview -> Header messages to be logged */
5230 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5232 col.mask = LVCF_TEXT;
5233 col.pszText = textA;
5234 r = SendMessageA(list, LVM_SETCOLUMNA, 0, (LPARAM)&col);
5235 expect(TRUE, r);
5237 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_changed_seq,
5238 "header notify, listview", FALSE);
5239 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5240 "header notify, parent", FALSE);
5242 header = subclass_header(list);
5244 ret = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
5245 expect(1, ret);
5247 memset(&item, 0, sizeof(item));
5248 item.mask = HDI_WIDTH;
5249 ret = SendMessageA(header, HDM_GETITEMA, 0, (LPARAM)&item);
5250 expect(1, ret);
5251 expect(100, item.cxy);
5253 nmh.hdr.hwndFrom = header;
5254 nmh.hdr.idFrom = GetWindowLongPtrA(header, GWLP_ID);
5255 nmh.hdr.code = HDN_ITEMCHANGEDA;
5256 nmh.iItem = 0;
5257 nmh.iButton = 0;
5258 item.mask = HDI_WIDTH;
5259 item.cxy = 50;
5260 nmh.pitem = &item;
5261 ret = SendMessageA(list, WM_NOTIFY, 0, (LPARAM)&nmh);
5262 expect(0, ret);
5264 DestroyWindow(list);
5267 static void test_header_notification2(void)
5269 static char textA[] = "newtext";
5270 HWND list, header;
5271 HDITEMW itemW;
5272 NMHEADERW nmhdr;
5273 LVCOLUMNA col;
5274 DWORD ret;
5275 WCHAR buffer[100];
5276 struct message parent_header_notify_seq[] = {
5277 { WM_NOTIFY, sent|id, 0, 0, 0 },
5278 { 0 }
5281 list = create_listview_control(LVS_REPORT);
5282 ok(list != NULL, "failed to create listview window\n");
5284 memset(&col, 0, sizeof(col));
5285 col.mask = LVCF_WIDTH | LVCF_TEXT;
5286 col.cx = 100;
5287 col.pszText = textA;
5288 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5289 expect(0, ret);
5291 header = (HWND)SendMessageA(list, LVM_GETHEADER, 0, 0);
5292 ok(header != 0, "No header\n");
5293 memset(&itemW, 0, sizeof(itemW));
5294 itemW.mask = HDI_WIDTH | HDI_ORDER | HDI_TEXT;
5295 itemW.pszText = buffer;
5296 itemW.cchTextMax = sizeof(buffer);
5297 ret = SendMessageW(header, HDM_GETITEMW, 0, (LPARAM)&itemW);
5298 expect(1, ret);
5300 nmhdr.hdr.hwndFrom = header;
5301 nmhdr.hdr.idFrom = GetWindowLongPtrW(header, GWLP_ID);
5302 nmhdr.iItem = 0;
5303 nmhdr.iButton = 0;
5304 nmhdr.pitem = &itemW;
5306 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5307 nmhdr.hdr.code = HDN_ITEMCHANGINGW;
5308 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5309 parent_header_notify_seq[0].id = HDN_ITEMCHANGINGA;
5310 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5311 "header notify, parent", TRUE);
5312 todo_wine
5313 ok(nmhdr.hdr.code == HDN_ITEMCHANGINGA, "Expected ANSI notification code\n");
5314 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5315 nmhdr.hdr.code = HDN_ITEMCHANGEDW;
5316 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5317 parent_header_notify_seq[0].id = HDN_ITEMCHANGEDA;
5318 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5319 "header notify, parent", TRUE);
5320 todo_wine
5321 ok(nmhdr.hdr.code == HDN_ITEMCHANGEDA, "Expected ANSI notification code\n");
5322 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5323 SetFocus(list);
5324 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5325 nmhdr.hdr.code = HDN_ITEMCLICKW;
5326 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5327 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_click_seq,
5328 "header notify, parent", FALSE);
5329 ok(nmhdr.hdr.code == HDN_ITEMCLICKA, "Expected ANSI notification code\n");
5330 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5331 nmhdr.hdr.code = HDN_ITEMDBLCLICKW;
5332 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5333 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5334 "header notify, parent", FALSE);
5335 ok(nmhdr.hdr.code == HDN_ITEMDBLCLICKW, "Expected Unicode notification code\n");
5336 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5337 nmhdr.hdr.code = HDN_DIVIDERDBLCLICKW;
5338 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5339 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_divider_dclick_seq,
5340 "header notify, parent", TRUE);
5341 ok(nmhdr.hdr.code == HDN_DIVIDERDBLCLICKA, "Expected ANSI notification code\n");
5342 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5343 nmhdr.hdr.code = HDN_BEGINTRACKW;
5344 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5345 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5346 "header notify, parent", FALSE);
5347 ok(nmhdr.hdr.code == HDN_BEGINTRACKW, "Expected Unicode notification code\n");
5348 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5349 nmhdr.hdr.code = HDN_ENDTRACKW;
5350 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5351 parent_header_notify_seq[0].id = HDN_ENDTRACKA;
5352 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5353 "header notify, parent", FALSE);
5354 ok(nmhdr.hdr.code == HDN_ENDTRACKA, "Expected ANSI notification code\n");
5355 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5356 nmhdr.hdr.code = HDN_TRACKW;
5357 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5358 parent_header_notify_seq[0].id = HDN_TRACKA;
5359 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5360 "header notify, parent", FALSE);
5361 ok(nmhdr.hdr.code == HDN_TRACKA, "Expected ANSI notification code\n");
5362 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5363 nmhdr.hdr.code = HDN_BEGINDRAG;
5364 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5365 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5366 "header notify, parent", FALSE);
5367 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5368 nmhdr.hdr.code = HDN_ENDDRAG;
5369 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5370 parent_header_notify_seq[0].id = HDN_ENDDRAG;
5371 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5372 "header notify, parent", FALSE);
5373 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5374 nmhdr.hdr.code = HDN_FILTERCHANGE;
5375 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5376 parent_header_notify_seq[0].id = HDN_FILTERCHANGE;
5377 parent_header_notify_seq[0].flags |= optional; /* NT4 does not send this message */
5378 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5379 "header notify, parent", FALSE);
5380 parent_header_notify_seq[0].flags &= ~optional;
5381 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5382 nmhdr.hdr.code = HDN_BEGINFILTEREDIT;
5383 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5384 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5385 "header notify, parent", FALSE);
5386 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5387 nmhdr.hdr.code = HDN_ENDFILTEREDIT;
5388 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5389 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5390 "header notify, parent", FALSE);
5391 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5392 nmhdr.hdr.code = HDN_ITEMSTATEICONCLICK;
5393 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5394 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5395 "header notify, parent", FALSE);
5396 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5397 nmhdr.hdr.code = HDN_ITEMKEYDOWN;
5398 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5399 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5400 "header notify, parent", FALSE);
5402 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5404 DestroyWindow(list);
5407 static void test_createdragimage(void)
5409 HIMAGELIST himl;
5410 POINT pt;
5411 HWND list;
5413 list = create_listview_control(LVS_ICON);
5414 ok(list != NULL, "failed to create listview window\n");
5416 insert_item(list, 0);
5418 /* NULL point */
5419 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
5420 ok(himl == NULL, "got %p\n", himl);
5422 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
5423 ok(himl != NULL, "got %p\n", himl);
5424 ImageList_Destroy(himl);
5426 DestroyWindow(list);
5429 static void test_dispinfo(void)
5431 static const char testA[] = "TEST";
5432 WCHAR buff[10];
5433 LVITEMA item;
5434 HWND hwnd;
5435 DWORD ret;
5437 hwnd = create_listview_control(LVS_ICON);
5438 ok(hwnd != NULL, "failed to create listview window\n");
5440 insert_item(hwnd, 0);
5442 memset(&item, 0, sizeof(item));
5443 item.pszText = LPSTR_TEXTCALLBACKA;
5444 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5445 expect(1, ret);
5447 g_disp_A_to_W = TRUE;
5448 item.pszText = (char*)buff;
5449 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
5450 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
5451 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
5452 g_disp_A_to_W = FALSE;
5454 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
5455 "got %s, expected %s\n", item.pszText, testA);
5457 DestroyWindow(hwnd);
5460 static void test_LVM_SETITEMTEXT(void)
5462 static char testA[] = "TEST";
5463 LVITEMA item;
5464 HWND hwnd;
5465 DWORD ret;
5467 hwnd = create_listview_control(LVS_ICON);
5468 ok(hwnd != NULL, "failed to create listview window\n");
5470 insert_item(hwnd, 0);
5472 /* null item pointer */
5473 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, 0);
5474 expect(FALSE, ret);
5476 ret = SendMessageA(hwnd, LVM_SETITEMTEXTW, 0, 0);
5477 expect(FALSE, ret);
5479 /* index out of bounds */
5480 item.pszText = testA;
5481 item.cchTextMax = 0; /* ignored */
5482 item.iSubItem = 0;
5484 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 1, (LPARAM)&item);
5485 expect(FALSE, ret);
5487 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, -1, (LPARAM)&item);
5488 expect(FALSE, ret);
5490 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5491 expect(TRUE, ret);
5493 DestroyWindow(hwnd);
5496 static void test_imagelists(void)
5498 HWND hwnd, header;
5499 HIMAGELIST himl1, himl2, himl3;
5500 LRESULT ret;
5502 himl1 = ImageList_Create(40, 40, 0, 4, 4);
5503 himl2 = ImageList_Create(40, 40, 0, 4, 4);
5504 himl3 = ImageList_Create(40, 40, 0, 4, 4);
5505 ok(himl1 != NULL, "Failed to create imagelist\n");
5506 ok(himl2 != NULL, "Failed to create imagelist\n");
5507 ok(himl3 != NULL, "Failed to create imagelist\n");
5509 hwnd = create_listview_control(LVS_REPORT | LVS_SHAREIMAGELISTS);
5510 header = subclass_header(hwnd);
5512 ok(header != NULL, "Expected header\n");
5513 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5514 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5516 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5518 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5519 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5520 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5521 "set normal image list", FALSE);
5523 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5525 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5526 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5527 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5528 "set state image list", TRUE);
5530 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5531 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5533 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5535 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5536 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5537 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_set_imagelist,
5538 "set small image list", FALSE);
5540 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5541 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5542 DestroyWindow(hwnd);
5544 hwnd = create_listview_control(WS_VISIBLE | LVS_ICON);
5546 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5548 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5549 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5550 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5551 "set normal image list", FALSE);
5553 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5555 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5556 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5557 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5558 "set state image list", FALSE);
5560 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5562 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5563 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5564 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5565 "set small image list", FALSE);
5567 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5568 ok(header == NULL, "Expected no header, got %p\n", header);
5570 SetWindowLongPtrA(hwnd, GWL_STYLE, GetWindowLongPtrA(hwnd, GWL_STYLE) | LVS_REPORT);
5572 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5573 ok(header != NULL, "Expected header, got NULL\n");
5575 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5576 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5578 DestroyWindow(hwnd);
5581 static void test_deleteitem(void)
5583 LVITEMA item;
5584 UINT state;
5585 HWND hwnd;
5586 BOOL ret;
5588 hwnd = create_listview_control(LVS_REPORT);
5590 insert_item(hwnd, 0);
5591 insert_item(hwnd, 0);
5592 insert_item(hwnd, 0);
5593 insert_item(hwnd, 0);
5594 insert_item(hwnd, 0);
5596 g_focus_test_LVN_DELETEITEM = TRUE;
5598 /* delete focused item (not the last index) */
5599 item.stateMask = LVIS_FOCUSED;
5600 item.state = LVIS_FOCUSED;
5601 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
5602 ok(ret == TRUE, "got %d\n", ret);
5603 ret = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
5604 ok(ret == TRUE, "got %d\n", ret);
5605 /* next item gets focus */
5606 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5607 ok(state == LVIS_FOCUSED, "got %x\n", state);
5609 /* focus last item and delete it */
5610 item.stateMask = LVIS_FOCUSED;
5611 item.state = LVIS_FOCUSED;
5612 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
5613 ok(ret == TRUE, "got %d\n", ret);
5614 ret = SendMessageA(hwnd, LVM_DELETEITEM, 3, 0);
5615 ok(ret == TRUE, "got %d\n", ret);
5616 /* new last item gets focus */
5617 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5618 ok(state == LVIS_FOCUSED, "got %x\n", state);
5620 /* focus first item and delete it */
5621 item.stateMask = LVIS_FOCUSED;
5622 item.state = LVIS_FOCUSED;
5623 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
5624 ok(ret == TRUE, "got %d\n", ret);
5625 ret = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
5626 ok(ret == TRUE, "got %d\n", ret);
5627 /* new first item gets focus */
5628 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5629 ok(state == LVIS_FOCUSED, "got %x\n", state);
5631 g_focus_test_LVN_DELETEITEM = FALSE;
5633 DestroyWindow(hwnd);
5636 static void test_insertitem(void)
5638 LVITEMA item;
5639 UINT state;
5640 HWND hwnd;
5641 INT ret;
5643 hwnd = create_listview_control(LVS_REPORT);
5645 /* insert item 0 focused */
5646 item.mask = LVIF_STATE;
5647 item.state = LVIS_FOCUSED;
5648 item.stateMask = LVIS_FOCUSED;
5649 item.iItem = 0;
5650 item.iSubItem = 0;
5651 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5652 ok(ret == 0, "got %d\n", ret);
5654 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5655 ok(state == LVIS_FOCUSED, "got %x\n", state);
5657 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5659 /* insert item 1, focus shift */
5660 item.mask = LVIF_STATE;
5661 item.state = LVIS_FOCUSED;
5662 item.stateMask = LVIS_FOCUSED;
5663 item.iItem = 1;
5664 item.iSubItem = 0;
5665 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5666 ok(ret == 1, "got %d\n", ret);
5668 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused_seq, "insert focused", TRUE);
5670 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5671 ok(state == LVIS_FOCUSED, "got %x\n", state);
5673 /* insert item 2, no focus shift */
5674 item.mask = LVIF_STATE;
5675 item.state = 0;
5676 item.stateMask = LVIS_FOCUSED;
5677 item.iItem = 2;
5678 item.iSubItem = 0;
5679 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5680 ok(ret == 2, "got %d\n", ret);
5682 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5683 ok(state == LVIS_FOCUSED, "got %x\n", state);
5685 DestroyWindow(hwnd);
5688 static void test_header_proc(void)
5690 HWND hwnd, header, hdr;
5691 WNDPROC proc1, proc2;
5693 hwnd = create_listview_control(LVS_REPORT);
5695 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5696 ok(header != NULL, "got %p\n", header);
5698 hdr = CreateWindowExA(0, WC_HEADERA, NULL,
5699 WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
5700 0, 0, 0, 0,
5701 NULL, NULL, NULL, NULL);
5702 ok(hdr != NULL, "got %p\n", hdr);
5704 proc1 = (WNDPROC)GetWindowLongPtrW(header, GWLP_WNDPROC);
5705 proc2 = (WNDPROC)GetWindowLongPtrW(hdr, GWLP_WNDPROC);
5706 ok(proc1 == proc2, "got %p, expected %p\n", proc1, proc2);
5708 DestroyWindow(hdr);
5709 DestroyWindow(hwnd);
5712 START_TEST(listview)
5714 HMODULE hComctl32;
5715 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
5717 ULONG_PTR ctx_cookie;
5718 HANDLE hCtx;
5720 hComctl32 = GetModuleHandleA("comctl32.dll");
5721 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
5722 if (pInitCommonControlsEx)
5724 INITCOMMONCONTROLSEX iccex;
5725 iccex.dwSize = sizeof(iccex);
5726 iccex.dwICC = ICC_LISTVIEW_CLASSES;
5727 pInitCommonControlsEx(&iccex);
5729 else
5730 InitCommonControls();
5732 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
5734 hwndparent = create_parent_window(FALSE);
5735 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5737 g_is_below_5 = is_below_comctl_5();
5739 test_header_notification();
5740 test_header_notification2();
5741 test_images();
5742 test_checkboxes();
5743 test_items();
5744 test_create();
5745 test_redraw();
5746 test_customdraw();
5747 test_icon_spacing();
5748 test_color();
5749 test_item_count();
5750 test_item_position();
5751 test_columns();
5752 test_getorigin();
5753 test_multiselect();
5754 test_getitemrect();
5755 test_subitem_rect();
5756 test_sorting();
5757 test_ownerdata();
5758 test_norecompute();
5759 test_nosortheader();
5760 test_setredraw();
5761 test_hittest();
5762 test_getviewrect();
5763 test_getitemposition();
5764 test_columnscreation();
5765 test_editbox();
5766 test_notifyformat();
5767 test_indentation();
5768 test_getitemspacing();
5769 test_getcolumnwidth();
5770 test_approximate_viewrect();
5771 test_finditem();
5772 test_hover();
5773 test_destroynotify();
5774 test_createdragimage();
5775 test_dispinfo();
5776 test_LVM_SETITEMTEXT();
5777 test_imagelists();
5778 test_deleteitem();
5779 test_insertitem();
5780 test_header_proc();
5782 if (!load_v6_module(&ctx_cookie, &hCtx))
5784 DestroyWindow(hwndparent);
5785 return;
5788 /* comctl32 version 6 tests start here */
5789 test_get_set_view();
5790 test_canceleditlabel();
5791 test_mapidindex();
5792 test_scrollnotify();
5793 test_LVS_EX_TRANSPARENTBKGND();
5794 test_LVS_EX_HEADERINALLVIEWS();
5795 test_deleteitem();
5796 test_multiselect();
5797 test_insertitem();
5798 test_header_proc();
5800 unload_v6_module(ctx_cookie, hCtx);
5802 DestroyWindow(hwndparent);