TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / comctl32 / tests / listview.c
blobacfcd20462c9fa1c781f25013f6f277367a515fc
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;
3919 /* rectangle isn't empty for empty text items */
3920 hwnd = create_listview_control(LVS_LIST);
3921 memset(&item, 0, sizeof(item));
3922 item.mask = 0;
3923 item.iItem = 0;
3924 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3925 expect(0, r);
3926 rect.left = LVIR_LABEL;
3927 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3928 expect(TRUE, r);
3929 expect(0, rect.left);
3930 expect(0, rect.top);
3931 /* estimate it as width / height ratio */
3932 todo_wine
3933 ok((rect.right / rect.bottom) >= 5, "got right %d, bottom %d\n", rect.right, rect.bottom);
3934 DestroyWindow(hwnd);
3936 hwnd = create_listview_control(LVS_REPORT);
3937 ok(hwnd != NULL, "failed to create a listview window\n");
3939 /* empty item */
3940 memset(&item, 0, sizeof(item));
3941 item.iItem = 0;
3942 item.iSubItem = 0;
3943 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3944 expect(0, r);
3946 rect.left = LVIR_BOUNDS;
3947 rect.right = rect.top = rect.bottom = -1;
3948 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3949 expect(TRUE, r);
3951 /* zero width rectangle with no padding */
3952 expect(0, rect.left);
3953 expect(0, rect.right);
3955 insert_column(hwnd, 0);
3956 insert_column(hwnd, 1);
3958 col.mask = LVCF_WIDTH;
3959 col.cx = 50;
3960 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 0, (LPARAM)&col);
3961 expect(TRUE, r);
3963 col.mask = LVCF_WIDTH;
3964 col.cx = 100;
3965 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 1, (LPARAM)&col);
3966 expect(TRUE, r);
3968 rect.left = LVIR_BOUNDS;
3969 rect.right = rect.top = rect.bottom = -1;
3970 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3971 expect(TRUE, r);
3973 /* still no left padding */
3974 expect(0, rect.left);
3975 expect(150, rect.right);
3977 rect.left = LVIR_SELECTBOUNDS;
3978 rect.right = rect.top = rect.bottom = -1;
3979 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3980 expect(TRUE, r);
3981 /* padding */
3982 expect(2, rect.left);
3984 rect.left = LVIR_LABEL;
3985 rect.right = rect.top = rect.bottom = -1;
3986 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3987 expect(TRUE, r);
3988 /* padding, column width */
3989 expect(2, rect.left);
3990 expect(50, rect.right);
3992 /* no icons attached */
3993 rect.left = LVIR_ICON;
3994 rect.right = rect.top = rect.bottom = -1;
3995 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3996 expect(TRUE, r);
3997 /* padding */
3998 expect(2, rect.left);
3999 expect(2, rect.right);
4001 /* change order */
4002 order[0] = 1; order[1] = 0;
4003 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
4004 expect(TRUE, r);
4005 pt.x = -1;
4006 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
4007 expect(TRUE, r);
4008 /* 1 indexed column width + padding */
4009 expect(102, pt.x);
4010 /* rect is at zero too */
4011 rect.left = LVIR_BOUNDS;
4012 rect.right = rect.top = rect.bottom = -1;
4013 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4014 expect(TRUE, r);
4015 expect(0, rect.left);
4016 /* just width sum */
4017 expect(150, rect.right);
4019 rect.left = LVIR_SELECTBOUNDS;
4020 rect.right = rect.top = rect.bottom = -1;
4021 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4022 expect(TRUE, r);
4023 /* column width + padding */
4024 expect(102, rect.left);
4026 /* back to initial order */
4027 order[0] = 0; order[1] = 1;
4028 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
4029 expect(TRUE, r);
4031 /* state icons */
4032 himl = ImageList_Create(16, 16, 0, 2, 2);
4033 ok(himl != NULL, "failed to create imagelist\n");
4034 hbm = CreateBitmap(16, 16, 1, 1, NULL);
4035 ok(hbm != NULL, "failed to create bitmap\n");
4036 r = ImageList_Add(himl, hbm, 0);
4037 expect(0, r);
4038 hbm = CreateBitmap(16, 16, 1, 1, NULL);
4039 ok(hbm != NULL, "failed to create bitmap\n");
4040 r = ImageList_Add(himl, hbm, 0);
4041 expect(1, r);
4043 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
4044 expect(0, r);
4046 item.mask = LVIF_STATE;
4047 item.state = INDEXTOSTATEIMAGEMASK(1);
4048 item.stateMask = LVIS_STATEIMAGEMASK;
4049 item.iItem = 0;
4050 item.iSubItem = 0;
4051 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4052 expect(TRUE, r);
4054 /* icon bounds */
4055 rect.left = LVIR_ICON;
4056 rect.right = rect.top = rect.bottom = -1;
4057 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4058 expect(TRUE, r);
4059 /* padding + stateicon width */
4060 expect(18, rect.left);
4061 expect(18, rect.right);
4062 /* label bounds */
4063 rect.left = LVIR_LABEL;
4064 rect.right = rect.top = rect.bottom = -1;
4065 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4066 expect(TRUE, r);
4067 /* padding + stateicon width -> column width */
4068 expect(18, rect.left);
4069 expect(50, rect.right);
4071 himl_ret = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
4072 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
4074 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
4075 expect(0, r);
4077 item.mask = LVIF_STATE | LVIF_IMAGE;
4078 item.iImage = 1;
4079 item.state = 0;
4080 item.stateMask = ~0;
4081 item.iItem = 0;
4082 item.iSubItem = 0;
4083 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4084 expect(TRUE, r);
4086 /* icon bounds */
4087 rect.left = LVIR_ICON;
4088 rect.right = rect.top = rect.bottom = -1;
4089 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4090 expect(TRUE, r);
4091 /* padding, icon width */
4092 expect(2, rect.left);
4093 expect(18, rect.right);
4094 /* label bounds */
4095 rect.left = LVIR_LABEL;
4096 rect.right = rect.top = rect.bottom = -1;
4097 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4098 expect(TRUE, r);
4099 /* padding + icon width -> column width */
4100 expect(18, rect.left);
4101 expect(50, rect.right);
4103 /* select bounds */
4104 rect.left = LVIR_SELECTBOUNDS;
4105 rect.right = rect.top = rect.bottom = -1;
4106 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4107 expect(TRUE, r);
4108 /* padding, column width */
4109 expect(2, rect.left);
4110 expect(50, rect.right);
4112 /* try with indentation */
4113 item.mask = LVIF_INDENT;
4114 item.iIndent = 1;
4115 item.iItem = 0;
4116 item.iSubItem = 0;
4117 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4118 expect(TRUE, r);
4120 /* bounds */
4121 rect.left = LVIR_BOUNDS;
4122 rect.right = rect.top = rect.bottom = -1;
4123 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4124 expect(TRUE, r);
4125 /* padding + 1 icon width, column width */
4126 expect(0, rect.left);
4127 expect(150, rect.right);
4129 /* select bounds */
4130 rect.left = LVIR_SELECTBOUNDS;
4131 rect.right = rect.top = rect.bottom = -1;
4132 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4133 expect(TRUE, r);
4134 /* padding + 1 icon width, column width */
4135 expect(2 + 16, rect.left);
4136 expect(50, rect.right);
4138 /* label bounds */
4139 rect.left = LVIR_LABEL;
4140 rect.right = rect.top = rect.bottom = -1;
4141 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4142 expect(TRUE, r);
4143 /* padding + 2 icon widths, column width */
4144 expect(2 + 16*2, rect.left);
4145 expect(50, rect.right);
4147 /* icon bounds */
4148 rect.left = LVIR_ICON;
4149 rect.right = rect.top = rect.bottom = -1;
4150 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4151 expect(TRUE, r);
4152 /* padding + 1 icon width indentation, icon width */
4153 expect(2 + 16, rect.left);
4154 expect(34, rect.right);
4156 DestroyWindow(hwnd);
4159 static void test_editbox(void)
4161 static CHAR testitemA[] = "testitem";
4162 static CHAR testitem1A[] = "testitem_quitelongname";
4163 static CHAR testitem2A[] = "testITEM_quitelongname";
4164 static CHAR buffer[25];
4165 HWND hwnd, hwndedit, hwndedit2, header;
4166 LVITEMA item;
4167 INT r;
4169 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4170 ok(hwnd != NULL, "failed to create a listview window\n");
4172 insert_column(hwnd, 0);
4174 memset(&item, 0, sizeof(item));
4175 item.mask = LVIF_TEXT;
4176 item.pszText = testitemA;
4177 item.iItem = 0;
4178 item.iSubItem = 0;
4179 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4180 expect(0, r);
4182 /* test notifications without edit created */
4183 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4184 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
4185 expect(0, r);
4186 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4187 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
4188 /* same thing but with valid window */
4189 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
4190 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
4191 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4192 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
4193 expect(0, r);
4194 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4195 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
4196 DestroyWindow(hwndedit);
4198 /* setting focus is necessary */
4199 SetFocus(hwnd);
4200 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4201 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4203 /* test children Z-order after Edit box created */
4204 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4205 ok(IsWindow(header), "Expected header to be created\n");
4206 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4207 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4209 /* modify initial string */
4210 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4211 expect(TRUE, r);
4213 /* edit window is resized and repositioned,
4214 check again for Z-order - it should be preserved */
4215 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4216 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4218 /* return focus to listview */
4219 SetFocus(hwnd);
4221 memset(&item, 0, sizeof(item));
4222 item.mask = LVIF_TEXT;
4223 item.pszText = buffer;
4224 item.cchTextMax = sizeof(buffer);
4225 item.iItem = 0;
4226 item.iSubItem = 0;
4227 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4228 expect(TRUE, r);
4230 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4232 /* send LVM_EDITLABEL on already created edit */
4233 SetFocus(hwnd);
4234 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4235 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4236 /* focus will be set to edit */
4237 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
4238 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4239 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
4241 /* creating label disabled when control isn't focused */
4242 SetFocus(0);
4243 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4244 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4246 /* check EN_KILLFOCUS handling */
4247 memset(&item, 0, sizeof(item));
4248 item.pszText = testitemA;
4249 item.iItem = 0;
4250 item.iSubItem = 0;
4251 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4252 expect(TRUE, r);
4254 SetFocus(hwnd);
4255 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4256 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4257 /* modify edit and notify control that it lost focus */
4258 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4259 expect(TRUE, r);
4260 g_editbox_disp_info.item.pszText = NULL;
4261 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4262 expect(0, r);
4263 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
4265 memset(&item, 0, sizeof(item));
4266 item.pszText = buffer;
4267 item.cchTextMax = sizeof(buffer);
4268 item.iItem = 0;
4269 item.iSubItem = 0;
4270 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4271 expect(lstrlenA(item.pszText), r);
4272 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4273 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4275 /* change item name to differ in casing only */
4276 SetFocus(hwnd);
4277 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4278 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4279 /* modify edit and notify control that it lost focus */
4280 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
4281 expect(TRUE, r);
4282 g_editbox_disp_info.item.pszText = NULL;
4283 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4284 expect(0, r);
4285 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
4287 memset(&item, 0, sizeof(item));
4288 item.pszText = buffer;
4289 item.cchTextMax = sizeof(buffer);
4290 item.iItem = 0;
4291 item.iSubItem = 0;
4292 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4293 expect(lstrlenA(item.pszText), r);
4294 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
4295 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4297 /* end edit without saving */
4298 SetFocus(hwnd);
4299 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4300 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4301 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
4302 expect(0, r);
4303 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4304 "edit box - end edit, no change, escape", TRUE);
4305 /* end edit with saving */
4306 SetFocus(hwnd);
4307 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4308 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4309 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
4310 expect(0, r);
4311 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4312 "edit box - end edit, no change, return", TRUE);
4314 memset(&item, 0, sizeof(item));
4315 item.pszText = buffer;
4316 item.cchTextMax = sizeof(buffer);
4317 item.iItem = 0;
4318 item.iSubItem = 0;
4319 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4320 expect(lstrlenA(item.pszText), r);
4321 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
4323 /* LVM_EDITLABEL with -1 destroys current edit */
4324 hwndedit = (HWND)SendMessageA(hwnd, LVM_GETEDITCONTROL, 0, 0);
4325 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4326 /* no edit present */
4327 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4328 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4329 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4330 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4331 /* edit present */
4332 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4333 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4334 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4335 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4336 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4337 /* check another negative value */
4338 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4339 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4340 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4341 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -2, 0);
4342 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4343 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4344 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4345 /* and value greater than max item index */
4346 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4347 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4348 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4349 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
4350 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, r, 0);
4351 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4352 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4353 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4355 /* messaging tests */
4356 SetFocus(hwnd);
4357 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4358 blockEdit = FALSE;
4359 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4360 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4361 /* testing only sizing messages */
4362 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
4363 "edit box create - sizing", FALSE);
4365 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4366 SetFocus(hwnd);
4367 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4368 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4369 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4370 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4371 expect(0, r);
4372 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4373 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
4375 DestroyWindow(hwnd);
4378 static void test_notifyformat(void)
4380 HWND hwnd, header;
4381 DWORD r;
4383 hwnd = create_listview_control(LVS_REPORT);
4384 ok(hwnd != NULL, "failed to create a listview window\n");
4386 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4387 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4388 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4389 expect(0, r);
4390 SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4391 /* set */
4392 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
4393 expect(0, r);
4394 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4395 if (r == 1)
4397 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
4398 expect(1, r);
4399 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4400 expect(0, r);
4402 else
4404 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4405 DestroyWindow(hwnd);
4406 return;
4409 DestroyWindow(hwnd);
4411 /* test failure in parent WM_NOTIFYFORMAT */
4412 notifyFormat = 0;
4413 hwnd = create_listview_control(LVS_REPORT);
4414 ok(hwnd != NULL, "failed to create a listview window\n");
4415 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4416 ok(IsWindow(header), "expected header to be created\n");
4417 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4418 expect(0, r);
4419 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4420 ok( r == 1, "Expected 1, got %d\n", r );
4421 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4422 ok(r != 0, "Expected valid format\n");
4424 notifyFormat = NFR_UNICODE;
4425 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4426 expect(NFR_UNICODE, r);
4427 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4428 expect(1, r);
4429 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4430 ok( r == 1, "Expected 1, got %d\n", r );
4432 notifyFormat = NFR_ANSI;
4433 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4434 expect(NFR_ANSI, r);
4435 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4436 expect(0, r);
4437 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4438 ok( r == 1, "Expected 1, got %d\n", r );
4440 DestroyWindow(hwnd);
4442 hwndparentW = create_parent_window(TRUE);
4443 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
4444 if (!IsWindow(hwndparentW)) return;
4446 notifyFormat = -1;
4447 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4448 ok(hwnd != NULL, "failed to create a listview window\n");
4449 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4450 ok(IsWindow(header), "expected header to be created\n");
4451 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4452 expect(1, r);
4453 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4454 expect(1, r);
4455 DestroyWindow(hwnd);
4456 /* receiving error code defaulting to ansi */
4457 notifyFormat = 0;
4458 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4459 ok(hwnd != NULL, "failed to create a listview window\n");
4460 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4461 ok(IsWindow(header), "expected header to be created\n");
4462 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4463 expect(0, r);
4464 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4465 expect(1, r);
4466 DestroyWindow(hwnd);
4467 /* receiving ansi code from unicode window, use it */
4468 notifyFormat = NFR_ANSI;
4469 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4470 ok(hwnd != NULL, "failed to create a listview window\n");
4471 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4472 ok(IsWindow(header), "expected header to be created\n");
4473 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4474 expect(0, r);
4475 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4476 expect(1, r);
4477 DestroyWindow(hwnd);
4478 /* unicode listview with ansi parent window */
4479 notifyFormat = -1;
4480 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4481 ok(hwnd != NULL, "failed to create a listview window\n");
4482 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4483 ok(IsWindow(header), "expected header to be created\n");
4484 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4485 expect(0, r);
4486 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4487 expect(1, r);
4488 DestroyWindow(hwnd);
4489 /* unicode listview with ansi parent window, return error code */
4490 notifyFormat = 0;
4491 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4492 ok(hwnd != NULL, "failed to create a listview window\n");
4493 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4494 ok(IsWindow(header), "expected header to be created\n");
4495 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4496 expect(0, r);
4497 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4498 expect(1, r);
4499 DestroyWindow(hwnd);
4501 DestroyWindow(hwndparentW);
4504 static void test_indentation(void)
4506 HWND hwnd;
4507 LVITEMA item;
4508 DWORD r;
4510 hwnd = create_listview_control(LVS_REPORT);
4511 ok(hwnd != NULL, "failed to create a listview window\n");
4513 memset(&item, 0, sizeof(item));
4514 item.mask = LVIF_INDENT;
4515 item.iItem = 0;
4516 item.iIndent = I_INDENTCALLBACK;
4517 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4518 expect(0, r);
4520 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4522 item.iItem = 0;
4523 item.mask = LVIF_INDENT;
4524 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4525 expect(TRUE, r);
4527 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
4528 "get indent dispinfo", FALSE);
4530 DestroyWindow(hwnd);
4533 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
4535 return 0;
4538 static BOOL is_below_comctl_5(void)
4540 HWND hwnd;
4541 BOOL ret;
4543 hwnd = create_listview_control(LVS_REPORT);
4544 ok(hwnd != NULL, "failed to create a listview window\n");
4545 insert_item(hwnd, 0);
4547 ret = SendMessageA(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
4549 DestroyWindow(hwnd);
4551 return !ret;
4554 static void test_get_set_view(void)
4556 HWND hwnd;
4557 DWORD ret;
4558 DWORD_PTR style;
4560 /* test style->view mapping */
4561 hwnd = create_listview_control(LVS_REPORT);
4562 ok(hwnd != NULL, "failed to create a listview window\n");
4564 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4565 expect(LV_VIEW_DETAILS, ret);
4567 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4568 /* LVS_ICON == 0 */
4569 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4570 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4571 expect(LV_VIEW_ICON, ret);
4573 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4574 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4575 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4576 expect(LV_VIEW_SMALLICON, ret);
4578 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4579 SetWindowLongPtrA(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4580 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4581 expect(LV_VIEW_LIST, ret);
4583 /* switching view doesn't touch window style */
4584 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4585 expect(1, ret);
4586 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4587 ok(style & LVS_LIST, "Expected style to be preserved\n");
4588 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4589 expect(1, ret);
4590 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4591 ok(style & LVS_LIST, "Expected style to be preserved\n");
4592 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4593 expect(1, ret);
4594 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4595 ok(style & LVS_LIST, "Expected style to be preserved\n");
4597 /* now change window style to see if view is remapped */
4598 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4599 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SHOWSELALWAYS);
4600 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4601 expect(LV_VIEW_SMALLICON, ret);
4603 DestroyWindow(hwnd);
4606 static void test_canceleditlabel(void)
4608 HWND hwnd, hwndedit;
4609 DWORD ret;
4610 CHAR buff[10];
4611 LVITEMA itema;
4612 static CHAR test[] = "test";
4613 static const CHAR test1[] = "test1";
4615 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4616 ok(hwnd != NULL, "failed to create a listview window\n");
4618 insert_item(hwnd, 0);
4620 /* try without edit created */
4621 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4622 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4623 expect(TRUE, ret);
4624 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4625 "cancel edit label without edit", FALSE);
4627 /* cancel without data change */
4628 SetFocus(hwnd);
4629 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4630 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4631 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4632 expect(TRUE, ret);
4633 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4635 /* cancel after data change */
4636 memset(&itema, 0, sizeof(itema));
4637 itema.pszText = test;
4638 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
4639 expect(TRUE, ret);
4640 SetFocus(hwnd);
4641 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4642 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4643 ret = SetWindowTextA(hwndedit, test1);
4644 expect(1, ret);
4645 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4646 expect(TRUE, ret);
4647 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4648 memset(&itema, 0, sizeof(itema));
4649 itema.pszText = buff;
4650 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4651 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&itema);
4652 expect(5, ret);
4653 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4655 DestroyWindow(hwnd);
4658 static void test_mapidindex(void)
4660 HWND hwnd;
4661 INT ret;
4663 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4664 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4665 ok(hwnd != NULL, "failed to create a listview window\n");
4666 insert_item(hwnd, 0);
4667 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4668 expect(-1, ret);
4669 DestroyWindow(hwnd);
4671 hwnd = create_listview_control(LVS_REPORT);
4672 ok(hwnd != NULL, "failed to create a listview window\n");
4674 /* LVM_MAPINDEXTOID with invalid index */
4675 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4676 expect(-1, ret);
4678 insert_item(hwnd, 0);
4679 insert_item(hwnd, 1);
4681 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, -1, 0);
4682 expect(-1, ret);
4683 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 2, 0);
4684 expect(-1, ret);
4686 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4687 expect(0, ret);
4688 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4689 expect(1, ret);
4690 /* remove 0 indexed item, id retained */
4691 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
4692 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4693 expect(1, ret);
4694 /* new id starts from previous value */
4695 insert_item(hwnd, 1);
4696 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4697 expect(2, ret);
4699 /* get index by id */
4700 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4701 expect(-1, ret);
4702 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4703 expect(-1, ret);
4704 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4705 expect(0, ret);
4706 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4707 expect(1, ret);
4709 DestroyWindow(hwnd);
4712 static void test_getitemspacing(void)
4714 HWND hwnd;
4715 DWORD ret;
4716 INT cx, cy;
4717 HIMAGELIST himl40, himl80;
4719 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4720 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4722 /* LVS_ICON */
4723 hwnd = create_listview_control(LVS_ICON);
4724 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4725 expect(cx, LOWORD(ret));
4726 expect(cy, HIWORD(ret));
4728 /* now try with icons */
4729 himl40 = ImageList_Create(40, 40, 0, 4, 4);
4730 ok(himl40 != NULL, "failed to create imagelist\n");
4731 himl80 = ImageList_Create(80, 80, 0, 4, 4);
4732 ok(himl80 != NULL, "failed to create imagelist\n");
4733 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4734 expect(0, ret);
4736 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4737 /* spacing + icon size returned */
4738 expect(cx + 40, LOWORD(ret));
4739 expect(cy + 40, HIWORD(ret));
4740 /* try changing icon size */
4741 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl80);
4743 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4744 /* spacing + icon size returned */
4745 expect(cx + 80, LOWORD(ret));
4746 expect(cy + 80, HIWORD(ret));
4748 /* set own icon spacing */
4749 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(100, 100));
4750 expect(cx + 80, LOWORD(ret));
4751 expect(cy + 80, HIWORD(ret));
4753 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4754 /* set size returned */
4755 expect(100, LOWORD(ret));
4756 expect(100, HIWORD(ret));
4758 /* now change image list - icon spacing should be unaffected */
4759 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4761 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4762 /* set size returned */
4763 expect(100, LOWORD(ret));
4764 expect(100, HIWORD(ret));
4766 /* spacing = 0 - keep previous value */
4767 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(0, -1));
4768 expect(100, LOWORD(ret));
4769 expect(100, HIWORD(ret));
4771 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4772 expect(100, LOWORD(ret));
4774 expect(0xFFFF, HIWORD(ret));
4776 if (sizeof(void*) == 8)
4778 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4779 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, (DWORD)-1);
4780 expect(100, LOWORD(ret));
4781 expect(0xFFFF, HIWORD(ret));
4783 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4784 expect(0xFFFF, LOWORD(ret));
4785 expect(0xFFFF, HIWORD(ret));
4787 else
4789 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4790 expect(100, LOWORD(ret));
4791 expect(0xFFFF, HIWORD(ret));
4793 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4794 /* spacing + icon size returned */
4795 expect(cx + 40, LOWORD(ret));
4796 expect(cy + 40, HIWORD(ret));
4798 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4799 ImageList_Destroy(himl80);
4800 DestroyWindow(hwnd);
4801 /* LVS_SMALLICON */
4802 hwnd = create_listview_control(LVS_SMALLICON);
4803 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4804 expect(cx, LOWORD(ret));
4805 expect(cy, HIWORD(ret));
4807 /* spacing does not depend on selected view type */
4808 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4809 expect(0, ret);
4811 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4812 /* spacing + icon size returned */
4813 expect(cx + 40, LOWORD(ret));
4814 expect(cy + 40, HIWORD(ret));
4816 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4817 ImageList_Destroy(himl40);
4818 DestroyWindow(hwnd);
4819 /* LVS_REPORT */
4820 hwnd = create_listview_control(LVS_REPORT);
4821 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4822 expect(cx, LOWORD(ret));
4823 expect(cy, HIWORD(ret));
4825 DestroyWindow(hwnd);
4826 /* LVS_LIST */
4827 hwnd = create_listview_control(LVS_LIST);
4828 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4829 expect(cx, LOWORD(ret));
4830 expect(cy, HIWORD(ret));
4832 DestroyWindow(hwnd);
4835 static INT get_current_font_height(HWND listview)
4837 TEXTMETRICA tm;
4838 HFONT hfont;
4839 HWND hwnd;
4840 HDC hdc;
4842 hwnd = (HWND)SendMessageA(listview, LVM_GETHEADER, 0, 0);
4843 if (!hwnd)
4844 hwnd = listview;
4846 hfont = (HFONT)SendMessageA(hwnd, WM_GETFONT, 0, 0);
4847 if (!hfont) {
4848 hdc = GetDC(hwnd);
4849 GetTextMetricsA(hdc, &tm);
4850 ReleaseDC(hwnd, hdc);
4852 else {
4853 HFONT oldfont;
4855 hdc = GetDC(0);
4856 oldfont = SelectObject(hdc, hfont);
4857 GetTextMetricsA(hdc, &tm);
4858 SelectObject(hdc, oldfont);
4859 ReleaseDC(0, hdc);
4862 return tm.tmHeight;
4865 static void test_getcolumnwidth(void)
4867 HWND hwnd;
4868 INT ret;
4869 DWORD_PTR style;
4870 LVCOLUMNA col;
4871 LVITEMA itema;
4872 INT height;
4874 /* default column width */
4875 hwnd = create_listview_control(LVS_ICON);
4876 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4877 expect(0, ret);
4878 style = GetWindowLongA(hwnd, GWL_STYLE);
4879 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_LIST);
4880 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4881 todo_wine expect(8, ret);
4882 style = GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_LIST;
4883 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_REPORT);
4884 col.mask = 0;
4885 ret = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4886 expect(0, ret);
4887 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4888 expect(10, ret);
4889 DestroyWindow(hwnd);
4891 /* default column width with item added */
4892 hwnd = create_listview_control(LVS_LIST);
4893 memset(&itema, 0, sizeof(itema));
4894 SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4895 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4896 height = get_current_font_height(hwnd);
4897 ok((ret / height) >= 6, "got width %d, height %d\n", ret, height);
4898 DestroyWindow(hwnd);
4901 static void test_scrollnotify(void)
4903 HWND hwnd;
4904 DWORD ret;
4906 hwnd = create_listview_control(LVS_REPORT);
4908 insert_column(hwnd, 0);
4909 insert_column(hwnd, 1);
4910 insert_item(hwnd, 0);
4912 /* make it scrollable - resize */
4913 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4914 expect(TRUE, ret);
4915 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4916 expect(TRUE, ret);
4918 /* try with dummy call */
4919 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4920 ret = SendMessageA(hwnd, LVM_SCROLL, 0, 0);
4921 expect(TRUE, ret);
4922 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4923 "scroll notify 1", TRUE);
4925 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4926 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 0);
4927 expect(TRUE, ret);
4928 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4929 "scroll notify 2", TRUE);
4931 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4932 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 1);
4933 expect(TRUE, ret);
4934 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4935 "scroll notify 3", TRUE);
4937 DestroyWindow(hwnd);
4940 static void test_LVS_EX_TRANSPARENTBKGND(void)
4942 HWND hwnd;
4943 DWORD ret;
4944 HDC hdc;
4946 hwnd = create_listview_control(LVS_REPORT);
4948 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4949 expect(TRUE, ret);
4951 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4952 LVS_EX_TRANSPARENTBKGND);
4954 ret = SendMessageA(hwnd, LVM_GETBKCOLOR, 0, 0);
4955 if (ret != CLR_NONE)
4957 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4958 DestroyWindow(hwnd);
4959 return;
4962 /* try to set some back color and check this style bit */
4963 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4964 expect(TRUE, ret);
4965 ret = SendMessageA(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4966 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4968 /* now test what this style actually does */
4969 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4970 LVS_EX_TRANSPARENTBKGND);
4972 hdc = GetWindowDC(hwndparent);
4974 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4975 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4976 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4977 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4979 ReleaseDC(hwndparent, hdc);
4981 DestroyWindow(hwnd);
4984 static void test_approximate_viewrect(void)
4986 HWND hwnd;
4987 DWORD ret;
4988 HIMAGELIST himl;
4989 HBITMAP hbmp;
4990 LVITEMA itema;
4991 static CHAR test[] = "abracadabra, a very long item label";
4993 hwnd = create_listview_control(LVS_ICON);
4994 himl = ImageList_Create(40, 40, 0, 4, 4);
4995 ok(himl != NULL, "failed to create imagelist\n");
4996 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4997 ok(hbmp != NULL, "failed to create bitmap\n");
4998 ret = ImageList_Add(himl, hbmp, 0);
4999 expect(0, ret);
5000 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
5001 expect(0, ret);
5003 itema.mask = LVIF_IMAGE;
5004 itema.iImage = 0;
5005 itema.iItem = 0;
5006 itema.iSubItem = 0;
5007 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
5008 expect(0, ret);
5010 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
5011 if (ret == 0)
5013 /* version 4.0 */
5014 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
5015 return;
5018 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
5019 expect(MAKELONG(77,827), ret);
5021 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
5022 ok(ret != 0, "got 0\n");
5024 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
5025 expect(MAKELONG(102,302), ret);
5027 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
5028 expect(MAKELONG(52,52), ret);
5030 itema.pszText = test;
5031 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
5032 expect(TRUE, ret);
5033 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
5034 expect(MAKELONG(52,52), ret);
5036 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
5037 expect(MAKELONG(52,2), ret);
5038 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
5039 expect(MAKELONG(52,52), ret);
5040 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
5041 expect(MAKELONG(102,52), ret);
5042 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
5043 expect(MAKELONG(102,102), ret);
5044 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
5045 expect(MAKELONG(102,102), ret);
5046 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
5047 expect(MAKELONG(102,152), ret);
5048 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
5049 expect(MAKELONG(102,152), ret);
5050 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
5051 expect(MAKELONG(152,152), ret);
5053 DestroyWindow(hwnd);
5056 static void test_finditem(void)
5058 LVFINDINFOA fi;
5059 static char f[5];
5060 HWND hwnd;
5061 INT r;
5063 hwnd = create_listview_control(LVS_REPORT);
5064 insert_item(hwnd, 0);
5066 memset(&fi, 0, sizeof(fi));
5068 /* full string search, inserted text was "foo" */
5069 strcpy(f, "foo");
5070 fi.flags = LVFI_STRING;
5071 fi.psz = f;
5072 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5073 expect(0, r);
5074 /* partial string search, inserted text was "foo" */
5075 strcpy(f, "fo");
5076 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5077 fi.psz = f;
5078 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5079 expect(0, r);
5080 /* partial string search, part after start char */
5081 strcpy(f, "oo");
5082 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5083 fi.psz = f;
5084 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5085 expect(-1, r);
5087 /* try with LVFI_SUBSTRING */
5088 strcpy(f, "fo");
5089 fi.flags = LVFI_SUBSTRING;
5090 fi.psz = f;
5091 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5092 if (r == -1)
5094 win_skip("LVFI_SUBSTRING not supported\n");
5095 DestroyWindow(hwnd);
5096 return;
5098 expect(0, r);
5099 strcpy(f, "f");
5100 fi.flags = LVFI_SUBSTRING;
5101 fi.psz = f;
5102 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5103 expect(0, r);
5104 strcpy(f, "o");
5105 fi.flags = LVFI_SUBSTRING;
5106 fi.psz = f;
5107 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5108 expect(-1, r);
5110 strcpy(f, "f");
5111 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
5112 fi.psz = f;
5113 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5114 expect(0, r);
5116 DestroyWindow(hwnd);
5119 static void test_LVS_EX_HEADERINALLVIEWS(void)
5121 HWND hwnd, header;
5122 DWORD style;
5124 hwnd = create_listview_control(LVS_ICON);
5126 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5127 LVS_EX_HEADERINALLVIEWS);
5129 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5130 if (!IsWindow(header))
5132 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
5133 DestroyWindow(hwnd);
5134 return;
5137 /* LVS_NOCOLUMNHEADER works as before */
5138 style = GetWindowLongA(hwnd, GWL_STYLE);
5139 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
5140 style = GetWindowLongA(header, GWL_STYLE);
5141 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
5142 style = GetWindowLongA(hwnd, GWL_STYLE);
5143 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
5144 style = GetWindowLongA(header, GWL_STYLE);
5145 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
5147 /* try to remove style */
5148 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
5149 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5150 ok(IsWindow(header), "Expected header to be created\n");
5151 style = GetWindowLongA(header, GWL_STYLE);
5152 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
5154 DestroyWindow(hwnd);
5156 /* check other styles */
5157 hwnd = create_listview_control(LVS_LIST);
5158 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5159 LVS_EX_HEADERINALLVIEWS);
5160 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5161 ok(IsWindow(header), "Expected header to be created\n");
5162 DestroyWindow(hwnd);
5164 hwnd = create_listview_control(LVS_SMALLICON);
5165 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5166 LVS_EX_HEADERINALLVIEWS);
5167 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5168 ok(IsWindow(header), "Expected header to be created\n");
5169 DestroyWindow(hwnd);
5171 hwnd = create_listview_control(LVS_REPORT);
5172 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5173 LVS_EX_HEADERINALLVIEWS);
5174 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5175 ok(IsWindow(header), "Expected header to be created\n");
5176 DestroyWindow(hwnd);
5179 static void test_hover(void)
5181 HWND hwnd, fg;
5182 DWORD r;
5184 hwnd = create_listview_control(LVS_ICON);
5185 SetForegroundWindow(hwndparent);
5186 fg = GetForegroundWindow();
5187 if (fg != hwndparent)
5189 skip("Window is not in the foreground. Skipping hover tests.\n");
5190 DestroyWindow(hwnd);
5191 return;
5194 /* test WM_MOUSEHOVER forwarding */
5195 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5196 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5197 expect(0, r);
5198 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
5199 g_block_hover = TRUE;
5200 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5201 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5202 expect(0, r);
5203 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
5204 g_block_hover = FALSE;
5206 r = SendMessageA(hwnd, LVM_SETHOVERTIME, 0, 500);
5207 expect(HOVER_DEFAULT, r);
5208 r = SendMessageA(hwnd, LVM_GETHOVERTIME, 0, 0);
5209 expect(500, r);
5211 DestroyWindow(hwnd);
5214 static void test_destroynotify(void)
5216 HWND hwnd;
5217 BOOL ret;
5219 hwnd = create_listview_control(LVS_REPORT);
5220 ok(hwnd != NULL, "failed to create listview window\n");
5222 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5223 DestroyWindow(hwnd);
5224 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
5226 /* same for ownerdata list */
5227 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5228 ok(hwnd != NULL, "failed to create listview window\n");
5230 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5231 DestroyWindow(hwnd);
5232 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_destroy, "check destroy order, ownerdata", FALSE);
5234 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5235 ok(hwnd != NULL, "failed to create listview window\n");
5237 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5238 ret = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
5239 ok(ret == TRUE, "got %d\n", ret);
5240 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_deleteall, "deleteall ownerdata", FALSE);
5241 DestroyWindow(hwnd);
5244 static void test_header_notification(void)
5246 static char textA[] = "newtext";
5247 HWND list, header;
5248 HDITEMA item;
5249 NMHEADERA nmh;
5250 LVCOLUMNA col;
5251 DWORD ret;
5252 BOOL r;
5254 list = create_listview_control(LVS_REPORT);
5255 ok(list != NULL, "failed to create listview window\n");
5257 memset(&col, 0, sizeof(col));
5258 col.mask = LVCF_WIDTH;
5259 col.cx = 100;
5260 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5261 expect(0, ret);
5263 /* check list parent notification after header item changed,
5264 this test should be placed before header subclassing to avoid
5265 Listview -> Header messages to be logged */
5266 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5268 col.mask = LVCF_TEXT;
5269 col.pszText = textA;
5270 r = SendMessageA(list, LVM_SETCOLUMNA, 0, (LPARAM)&col);
5271 expect(TRUE, r);
5273 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_changed_seq,
5274 "header notify, listview", FALSE);
5275 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5276 "header notify, parent", FALSE);
5278 header = subclass_header(list);
5280 ret = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
5281 expect(1, ret);
5283 memset(&item, 0, sizeof(item));
5284 item.mask = HDI_WIDTH;
5285 ret = SendMessageA(header, HDM_GETITEMA, 0, (LPARAM)&item);
5286 expect(1, ret);
5287 expect(100, item.cxy);
5289 nmh.hdr.hwndFrom = header;
5290 nmh.hdr.idFrom = GetWindowLongPtrA(header, GWLP_ID);
5291 nmh.hdr.code = HDN_ITEMCHANGEDA;
5292 nmh.iItem = 0;
5293 nmh.iButton = 0;
5294 item.mask = HDI_WIDTH;
5295 item.cxy = 50;
5296 nmh.pitem = &item;
5297 ret = SendMessageA(list, WM_NOTIFY, 0, (LPARAM)&nmh);
5298 expect(0, ret);
5300 DestroyWindow(list);
5303 static void test_header_notification2(void)
5305 static char textA[] = "newtext";
5306 HWND list, header;
5307 HDITEMW itemW;
5308 NMHEADERW nmhdr;
5309 LVCOLUMNA col;
5310 DWORD ret;
5311 WCHAR buffer[100];
5312 struct message parent_header_notify_seq[] = {
5313 { WM_NOTIFY, sent|id, 0, 0, 0 },
5314 { 0 }
5317 list = create_listview_control(LVS_REPORT);
5318 ok(list != NULL, "failed to create listview window\n");
5320 memset(&col, 0, sizeof(col));
5321 col.mask = LVCF_WIDTH | LVCF_TEXT;
5322 col.cx = 100;
5323 col.pszText = textA;
5324 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5325 expect(0, ret);
5327 header = (HWND)SendMessageA(list, LVM_GETHEADER, 0, 0);
5328 ok(header != 0, "No header\n");
5329 memset(&itemW, 0, sizeof(itemW));
5330 itemW.mask = HDI_WIDTH | HDI_ORDER | HDI_TEXT;
5331 itemW.pszText = buffer;
5332 itemW.cchTextMax = sizeof(buffer);
5333 ret = SendMessageW(header, HDM_GETITEMW, 0, (LPARAM)&itemW);
5334 expect(1, ret);
5336 nmhdr.hdr.hwndFrom = header;
5337 nmhdr.hdr.idFrom = GetWindowLongPtrW(header, GWLP_ID);
5338 nmhdr.iItem = 0;
5339 nmhdr.iButton = 0;
5340 nmhdr.pitem = &itemW;
5342 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5343 nmhdr.hdr.code = HDN_ITEMCHANGINGW;
5344 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5345 ok(ret == 0, "got %d\n", ret);
5346 parent_header_notify_seq[0].id = HDN_ITEMCHANGINGA;
5347 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5348 "header notify, parent", TRUE);
5349 todo_wine
5350 ok(nmhdr.hdr.code == HDN_ITEMCHANGINGA, "Expected ANSI notification code\n");
5351 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5352 nmhdr.hdr.code = HDN_ITEMCHANGEDW;
5353 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5354 ok(ret == 0, "got %d\n", ret);
5355 parent_header_notify_seq[0].id = HDN_ITEMCHANGEDA;
5356 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5357 "header notify, parent", TRUE);
5358 todo_wine
5359 ok(nmhdr.hdr.code == HDN_ITEMCHANGEDA, "Expected ANSI notification code\n");
5360 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5361 SetFocus(list);
5362 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5363 nmhdr.hdr.code = HDN_ITEMCLICKW;
5364 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5365 ok(ret == 0, "got %d\n", ret);
5366 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_click_seq,
5367 "header notify, parent", FALSE);
5368 ok(nmhdr.hdr.code == HDN_ITEMCLICKA, "Expected ANSI notification code\n");
5369 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5370 nmhdr.hdr.code = HDN_ITEMDBLCLICKW;
5371 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5372 ok(ret == 0, "got %d\n", ret);
5373 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5374 "header notify, parent", FALSE);
5375 ok(nmhdr.hdr.code == HDN_ITEMDBLCLICKW, "Expected Unicode notification code\n");
5376 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5377 nmhdr.hdr.code = HDN_DIVIDERDBLCLICKW;
5378 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5379 ok(ret == 0, "got %d\n", ret);
5380 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_divider_dclick_seq,
5381 "header notify, parent", TRUE);
5382 ok(nmhdr.hdr.code == HDN_DIVIDERDBLCLICKA, "Expected ANSI notification code\n");
5383 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5384 nmhdr.hdr.code = HDN_BEGINTRACKW;
5385 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5386 ok(ret == 0, "got %d\n", ret);
5387 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5388 "header notify, parent", FALSE);
5389 ok(nmhdr.hdr.code == HDN_BEGINTRACKW, "Expected Unicode notification code\n");
5390 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5391 nmhdr.hdr.code = HDN_ENDTRACKW;
5392 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5393 ok(ret == 0, "got %d\n", ret);
5394 parent_header_notify_seq[0].id = HDN_ENDTRACKA;
5395 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5396 "header notify, parent", FALSE);
5397 ok(nmhdr.hdr.code == HDN_ENDTRACKA, "Expected ANSI notification code\n");
5398 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5399 nmhdr.hdr.code = HDN_TRACKW;
5400 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5401 ok(ret == 0, "got %d\n", ret);
5402 parent_header_notify_seq[0].id = HDN_TRACKA;
5403 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5404 "header notify, parent", FALSE);
5405 ok(nmhdr.hdr.code == HDN_TRACKA, "Expected ANSI notification code\n");
5406 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5407 nmhdr.hdr.code = HDN_BEGINDRAG;
5408 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5409 ok(ret == 1, "got %d\n", ret);
5410 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5411 "header notify, parent", FALSE);
5412 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5413 nmhdr.hdr.code = HDN_ENDDRAG;
5414 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5415 ok(ret == 0, "got %d\n", ret);
5416 parent_header_notify_seq[0].id = HDN_ENDDRAG;
5417 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5418 "header notify, parent", FALSE);
5419 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5420 nmhdr.hdr.code = HDN_FILTERCHANGE;
5421 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5422 ok(ret == 0, "got %d\n", ret);
5423 parent_header_notify_seq[0].id = HDN_FILTERCHANGE;
5424 parent_header_notify_seq[0].flags |= optional; /* NT4 does not send this message */
5425 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5426 "header notify, parent", FALSE);
5427 parent_header_notify_seq[0].flags &= ~optional;
5428 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5429 nmhdr.hdr.code = HDN_BEGINFILTEREDIT;
5430 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5431 ok(ret == 0, "got %d\n", ret);
5432 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5433 "header notify, parent", FALSE);
5434 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5435 nmhdr.hdr.code = HDN_ENDFILTEREDIT;
5436 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5437 ok(ret == 0, "got %d\n", ret);
5438 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5439 "header notify, parent", FALSE);
5440 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5441 nmhdr.hdr.code = HDN_ITEMSTATEICONCLICK;
5442 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5443 ok(ret == 0, "got %d\n", ret);
5444 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5445 "header notify, parent", FALSE);
5446 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5447 nmhdr.hdr.code = HDN_ITEMKEYDOWN;
5448 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5449 ok(ret == 0, "got %d\n", ret);
5450 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5451 "header notify, parent", FALSE);
5453 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5455 DestroyWindow(list);
5458 static void test_createdragimage(void)
5460 HIMAGELIST himl;
5461 POINT pt;
5462 HWND list;
5464 list = create_listview_control(LVS_ICON);
5465 ok(list != NULL, "failed to create listview window\n");
5467 insert_item(list, 0);
5469 /* NULL point */
5470 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
5471 ok(himl == NULL, "got %p\n", himl);
5473 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
5474 ok(himl != NULL, "got %p\n", himl);
5475 ImageList_Destroy(himl);
5477 DestroyWindow(list);
5480 static void test_dispinfo(void)
5482 static const char testA[] = "TEST";
5483 WCHAR buff[10];
5484 LVITEMA item;
5485 HWND hwnd;
5486 DWORD ret;
5488 hwnd = create_listview_control(LVS_ICON);
5489 ok(hwnd != NULL, "failed to create listview window\n");
5491 insert_item(hwnd, 0);
5493 memset(&item, 0, sizeof(item));
5494 item.pszText = LPSTR_TEXTCALLBACKA;
5495 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5496 expect(1, ret);
5498 g_disp_A_to_W = TRUE;
5499 item.pszText = (char*)buff;
5500 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
5501 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
5502 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
5503 g_disp_A_to_W = FALSE;
5505 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
5506 "got %s, expected %s\n", item.pszText, testA);
5508 DestroyWindow(hwnd);
5511 static void test_LVM_SETITEMTEXT(void)
5513 static char testA[] = "TEST";
5514 LVITEMA item;
5515 HWND hwnd;
5516 DWORD ret;
5518 hwnd = create_listview_control(LVS_ICON);
5519 ok(hwnd != NULL, "failed to create listview window\n");
5521 insert_item(hwnd, 0);
5523 /* null item pointer */
5524 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, 0);
5525 expect(FALSE, ret);
5527 ret = SendMessageA(hwnd, LVM_SETITEMTEXTW, 0, 0);
5528 expect(FALSE, ret);
5530 /* index out of bounds */
5531 item.pszText = testA;
5532 item.cchTextMax = 0; /* ignored */
5533 item.iSubItem = 0;
5535 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 1, (LPARAM)&item);
5536 expect(FALSE, ret);
5538 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, -1, (LPARAM)&item);
5539 expect(FALSE, ret);
5541 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5542 expect(TRUE, ret);
5544 DestroyWindow(hwnd);
5547 static void test_imagelists(void)
5549 HWND hwnd, header;
5550 HIMAGELIST himl1, himl2, himl3;
5551 LRESULT ret;
5553 himl1 = ImageList_Create(40, 40, 0, 4, 4);
5554 himl2 = ImageList_Create(40, 40, 0, 4, 4);
5555 himl3 = ImageList_Create(40, 40, 0, 4, 4);
5556 ok(himl1 != NULL, "Failed to create imagelist\n");
5557 ok(himl2 != NULL, "Failed to create imagelist\n");
5558 ok(himl3 != NULL, "Failed to create imagelist\n");
5560 hwnd = create_listview_control(LVS_REPORT | LVS_SHAREIMAGELISTS);
5561 header = subclass_header(hwnd);
5563 ok(header != NULL, "Expected header\n");
5564 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5565 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5567 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5569 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5570 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5571 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5572 "set normal image list", FALSE);
5574 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5576 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5577 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5578 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5579 "set state image list", TRUE);
5581 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5582 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5584 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5586 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5587 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5588 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_set_imagelist,
5589 "set small image list", FALSE);
5591 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5592 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5593 DestroyWindow(hwnd);
5595 hwnd = create_listview_control(WS_VISIBLE | LVS_ICON);
5597 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5599 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5600 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5601 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5602 "set normal image list", FALSE);
5604 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5606 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5607 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5608 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5609 "set state image list", FALSE);
5611 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5613 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5614 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5615 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5616 "set small image list", FALSE);
5618 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5619 ok(header == NULL, "Expected no header, got %p\n", header);
5621 SetWindowLongPtrA(hwnd, GWL_STYLE, GetWindowLongPtrA(hwnd, GWL_STYLE) | LVS_REPORT);
5623 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5624 ok(header != NULL, "Expected header, got NULL\n");
5626 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5627 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5629 DestroyWindow(hwnd);
5632 static void test_deleteitem(void)
5634 LVITEMA item;
5635 UINT state;
5636 HWND hwnd;
5637 BOOL ret;
5639 hwnd = create_listview_control(LVS_REPORT);
5641 insert_item(hwnd, 0);
5642 insert_item(hwnd, 0);
5643 insert_item(hwnd, 0);
5644 insert_item(hwnd, 0);
5645 insert_item(hwnd, 0);
5647 g_focus_test_LVN_DELETEITEM = TRUE;
5649 /* delete focused item (not the last index) */
5650 item.stateMask = LVIS_FOCUSED;
5651 item.state = LVIS_FOCUSED;
5652 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
5653 ok(ret == TRUE, "got %d\n", ret);
5654 ret = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
5655 ok(ret == TRUE, "got %d\n", ret);
5656 /* next item gets focus */
5657 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5658 ok(state == LVIS_FOCUSED, "got %x\n", state);
5660 /* focus last item and delete it */
5661 item.stateMask = LVIS_FOCUSED;
5662 item.state = LVIS_FOCUSED;
5663 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
5664 ok(ret == TRUE, "got %d\n", ret);
5665 ret = SendMessageA(hwnd, LVM_DELETEITEM, 3, 0);
5666 ok(ret == TRUE, "got %d\n", ret);
5667 /* new last item gets focus */
5668 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5669 ok(state == LVIS_FOCUSED, "got %x\n", state);
5671 /* focus first item and delete it */
5672 item.stateMask = LVIS_FOCUSED;
5673 item.state = LVIS_FOCUSED;
5674 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
5675 ok(ret == TRUE, "got %d\n", ret);
5676 ret = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
5677 ok(ret == TRUE, "got %d\n", ret);
5678 /* new first item gets focus */
5679 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5680 ok(state == LVIS_FOCUSED, "got %x\n", state);
5682 g_focus_test_LVN_DELETEITEM = FALSE;
5684 DestroyWindow(hwnd);
5687 static void test_insertitem(void)
5689 LVITEMA item;
5690 UINT state;
5691 HWND hwnd;
5692 INT ret;
5694 hwnd = create_listview_control(LVS_REPORT);
5696 /* insert item 0 focused */
5697 item.mask = LVIF_STATE;
5698 item.state = LVIS_FOCUSED;
5699 item.stateMask = LVIS_FOCUSED;
5700 item.iItem = 0;
5701 item.iSubItem = 0;
5702 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5703 ok(ret == 0, "got %d\n", ret);
5705 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5706 ok(state == LVIS_FOCUSED, "got %x\n", state);
5708 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5710 /* insert item 1, focus shift */
5711 item.mask = LVIF_STATE;
5712 item.state = LVIS_FOCUSED;
5713 item.stateMask = LVIS_FOCUSED;
5714 item.iItem = 1;
5715 item.iSubItem = 0;
5716 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5717 ok(ret == 1, "got %d\n", ret);
5719 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused_seq, "insert focused", TRUE);
5721 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5722 ok(state == LVIS_FOCUSED, "got %x\n", state);
5724 /* insert item 2, no focus shift */
5725 item.mask = LVIF_STATE;
5726 item.state = 0;
5727 item.stateMask = LVIS_FOCUSED;
5728 item.iItem = 2;
5729 item.iSubItem = 0;
5730 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5731 ok(ret == 2, "got %d\n", ret);
5733 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5734 ok(state == LVIS_FOCUSED, "got %x\n", state);
5736 DestroyWindow(hwnd);
5739 static void test_header_proc(void)
5741 HWND hwnd, header, hdr;
5742 WNDPROC proc1, proc2;
5744 hwnd = create_listview_control(LVS_REPORT);
5746 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5747 ok(header != NULL, "got %p\n", header);
5749 hdr = CreateWindowExA(0, WC_HEADERA, NULL,
5750 WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
5751 0, 0, 0, 0,
5752 NULL, NULL, NULL, NULL);
5753 ok(hdr != NULL, "got %p\n", hdr);
5755 proc1 = (WNDPROC)GetWindowLongPtrW(header, GWLP_WNDPROC);
5756 proc2 = (WNDPROC)GetWindowLongPtrW(hdr, GWLP_WNDPROC);
5757 ok(proc1 == proc2, "got %p, expected %p\n", proc1, proc2);
5759 DestroyWindow(hdr);
5760 DestroyWindow(hwnd);
5763 static void flush_events(void)
5765 MSG msg;
5766 int diff = 200;
5767 int min_timeout = 100;
5768 DWORD time = GetTickCount() + diff;
5770 while (diff > 0)
5772 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
5773 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
5774 diff = time - GetTickCount();
5778 static void test_oneclickactivate(void)
5780 TRACKMOUSEEVENT track;
5781 char item1[] = "item1";
5782 LVITEMA item;
5783 HWND hwnd, fg;
5784 RECT rect;
5785 INT r;
5787 hwnd = CreateWindowExA(0, "SysListView32", "foo", WS_VISIBLE|WS_CHILD|LVS_LIST,
5788 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
5789 ok(hwnd != NULL, "failed to create listview window\n");
5790 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_ONECLICKACTIVATE);
5791 ok(r == 0, "should return zero\n");
5793 SetForegroundWindow(hwndparent);
5794 flush_events();
5795 fg = GetForegroundWindow();
5796 if (fg != hwndparent)
5798 skip("Window is not in the foreground. Skipping oneclickactivate tests.\n");
5799 DestroyWindow(hwnd);
5800 return;
5803 item.mask = LVIF_TEXT;
5804 item.iItem = 0;
5805 item.iSubItem = 0;
5806 item.iImage = 0;
5807 item.pszText = item1;
5808 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
5809 ok(r == 0, "should not fail\n");
5811 GetWindowRect(hwnd, &rect);
5812 SetCursorPos(rect.left+5, rect.top+5);
5813 flush_events();
5814 r = SendMessageA(hwnd, WM_MOUSEMOVE, MAKELONG(1, 1), 0);
5815 expect(0, r);
5817 track.cbSize = sizeof(track);
5818 track.dwFlags = TME_QUERY;
5819 _TrackMouseEvent(&track);
5820 ok(track.hwndTrack == hwnd, "hwndTrack != hwnd\n");
5821 ok(track.dwFlags == TME_LEAVE, "dwFlags = %x\n", track.dwFlags);
5823 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
5824 expect(0, r);
5825 r = SendMessageA(hwnd, WM_MOUSEHOVER, MAKELONG(1, 1), 0);
5826 expect(0, r);
5827 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
5828 expect(1, r);
5830 DestroyWindow(hwnd);
5833 START_TEST(listview)
5835 HMODULE hComctl32;
5836 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
5838 ULONG_PTR ctx_cookie;
5839 HANDLE hCtx;
5841 hComctl32 = GetModuleHandleA("comctl32.dll");
5842 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
5843 if (pInitCommonControlsEx)
5845 INITCOMMONCONTROLSEX iccex;
5846 iccex.dwSize = sizeof(iccex);
5847 iccex.dwICC = ICC_LISTVIEW_CLASSES;
5848 pInitCommonControlsEx(&iccex);
5850 else
5851 InitCommonControls();
5853 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
5855 hwndparent = create_parent_window(FALSE);
5856 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5858 g_is_below_5 = is_below_comctl_5();
5860 test_header_notification();
5861 test_header_notification2();
5862 test_images();
5863 test_checkboxes();
5864 test_items();
5865 test_create();
5866 test_redraw();
5867 test_customdraw();
5868 test_icon_spacing();
5869 test_color();
5870 test_item_count();
5871 test_item_position();
5872 test_columns();
5873 test_getorigin();
5874 test_multiselect();
5875 test_getitemrect();
5876 test_subitem_rect();
5877 test_sorting();
5878 test_ownerdata();
5879 test_norecompute();
5880 test_nosortheader();
5881 test_setredraw();
5882 test_hittest();
5883 test_getviewrect();
5884 test_getitemposition();
5885 test_columnscreation();
5886 test_editbox();
5887 test_notifyformat();
5888 test_indentation();
5889 test_getitemspacing();
5890 test_getcolumnwidth();
5891 test_approximate_viewrect();
5892 test_finditem();
5893 test_hover();
5894 test_destroynotify();
5895 test_createdragimage();
5896 test_dispinfo();
5897 test_LVM_SETITEMTEXT();
5898 test_imagelists();
5899 test_deleteitem();
5900 test_insertitem();
5901 test_header_proc();
5902 test_oneclickactivate();
5904 if (!load_v6_module(&ctx_cookie, &hCtx))
5906 DestroyWindow(hwndparent);
5907 return;
5910 /* comctl32 version 6 tests start here */
5911 test_get_set_view();
5912 test_canceleditlabel();
5913 test_mapidindex();
5914 test_scrollnotify();
5915 test_LVS_EX_TRANSPARENTBKGND();
5916 test_LVS_EX_HEADERINALLVIEWS();
5917 test_deleteitem();
5918 test_multiselect();
5919 test_insertitem();
5920 test_header_proc();
5922 unload_v6_module(ctx_cookie, hCtx);
5924 DestroyWindow(hwndparent);