mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / comctl32 / tests / listview.c
blobe95b81f5bb173551fc4260b024d9bd15eff48be8
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 static HIMAGELIST (WINAPI *pImageList_Create)(int, int, UINT, int, int);
32 static BOOL (WINAPI *pImageList_Destroy)(HIMAGELIST);
33 static int (WINAPI *pImageList_Add)(HIMAGELIST, HBITMAP, HBITMAP);
34 static BOOL (WINAPI *p_TrackMouseEvent)(TRACKMOUSEEVENT *);
36 enum seq_index {
37 PARENT_SEQ_INDEX,
38 PARENT_FULL_SEQ_INDEX,
39 PARENT_CD_SEQ_INDEX,
40 LISTVIEW_SEQ_INDEX,
41 EDITBOX_SEQ_INDEX,
42 COMBINED_SEQ_INDEX,
43 NUM_MSG_SEQUENCES
46 #define LISTVIEW_ID 0
47 #define HEADER_ID 1
49 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
50 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
51 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
53 static HWND hwndparent, hwndparentW;
54 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
55 static BOOL blockEdit;
56 /* return nonzero on NM_HOVER */
57 static BOOL g_block_hover;
58 /* notification data for LVN_ITEMCHANGED */
59 static NMLISTVIEW g_nmlistview;
60 /* notification data for LVN_ITEMCHANGING */
61 static NMLISTVIEW g_nmlistview_changing;
62 /* format reported to control:
63 -1 falls to defproc, anything else returned */
64 static INT notifyFormat;
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;
73 /* Whether to send WM_KILLFOCUS to the edit control during LVN_ENDLABELEDIT */
74 static BOOL g_WM_KILLFOCUS_on_LVN_ENDLABELEDIT;
76 static HWND subclass_editbox(HWND hwndListview);
78 static void init_functions(void)
80 HMODULE hComCtl32 = LoadLibraryA("comctl32.dll");
82 #define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
83 X(ImageList_Create);
84 X(ImageList_Destroy);
85 X(ImageList_Add);
86 X(_TrackMouseEvent);
87 #undef X
90 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
92 static const struct message create_ownerdrawfixed_parent_seq[] = {
93 { WM_NOTIFYFORMAT, sent },
94 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
95 { WM_MEASUREITEM, sent },
96 { WM_PARENTNOTIFY, sent },
97 { 0 }
100 static const struct message redraw_listview_seq[] = {
101 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
102 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
103 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
104 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
105 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
106 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
107 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
108 { 0 }
111 static const struct message listview_icon_spacing_seq[] = {
112 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
113 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
114 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
115 { 0 }
118 static const struct message listview_color_seq[] = {
119 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
120 { LVM_GETBKCOLOR, sent },
121 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
122 { LVM_GETTEXTCOLOR, sent },
123 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
124 { LVM_GETTEXTBKCOLOR, sent },
126 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
127 { LVM_GETBKCOLOR, sent },
128 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
129 { LVM_GETTEXTCOLOR, sent },
130 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
131 { LVM_GETTEXTBKCOLOR, sent },
133 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
134 { LVM_GETBKCOLOR, sent },
135 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
136 { LVM_GETTEXTCOLOR, sent },
137 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
138 { LVM_GETTEXTBKCOLOR, sent },
140 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
141 { LVM_GETBKCOLOR, sent },
142 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
143 { LVM_GETTEXTCOLOR, sent },
144 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
145 { LVM_GETTEXTBKCOLOR, sent },
146 { 0 }
149 static const struct message listview_item_count_seq[] = {
150 { LVM_GETITEMCOUNT, sent },
151 { LVM_INSERTITEMA, sent },
152 { LVM_INSERTITEMA, sent },
153 { LVM_INSERTITEMA, sent },
154 { LVM_GETITEMCOUNT, sent },
155 { LVM_DELETEITEM, sent|wparam, 2 },
156 { WM_NCPAINT, sent|optional },
157 { WM_ERASEBKGND, sent|optional },
158 { LVM_GETITEMCOUNT, sent },
159 { LVM_DELETEALLITEMS, sent },
160 { LVM_GETITEMCOUNT, sent },
161 { LVM_INSERTITEMA, sent },
162 { LVM_INSERTITEMA, sent },
163 { LVM_GETITEMCOUNT, sent },
164 { LVM_INSERTITEMA, sent },
165 { LVM_GETITEMCOUNT, sent },
166 { 0 }
169 static const struct message listview_itempos_seq[] = {
170 { LVM_INSERTITEMA, sent },
171 { LVM_INSERTITEMA, sent },
172 { LVM_INSERTITEMA, sent },
173 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
174 { WM_NCPAINT, sent|optional },
175 { WM_ERASEBKGND, sent|optional },
176 { LVM_GETITEMPOSITION, sent|wparam, 1 },
177 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
178 { LVM_GETITEMPOSITION, sent|wparam, 2 },
179 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
180 { LVM_GETITEMPOSITION, sent|wparam, 0 },
181 { 0 }
184 static const struct message listview_ownerdata_switchto_seq[] = {
185 { WM_STYLECHANGING, sent },
186 { WM_STYLECHANGED, sent },
187 { 0 }
190 static const struct message listview_getorderarray_seq[] = {
191 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
192 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
193 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 0, 0, LISTVIEW_ID },
194 { HDM_GETORDERARRAY, sent|id|wparam, 0, 0, HEADER_ID },
195 { 0 }
198 static const struct message listview_setorderarray_seq[] = {
199 { LVM_SETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
200 { HDM_SETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
201 { LVM_SETCOLUMNORDERARRAY, sent|id|wparam, 0, 0, LISTVIEW_ID },
202 { HDM_SETORDERARRAY, sent|id|wparam, 0, 0, HEADER_ID },
203 { 0 }
206 static const struct message empty_seq[] = {
207 { 0 }
210 static const struct message parent_focus_change_ownerdata_seq[] = {
211 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
212 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
213 { 0 }
216 static const struct message forward_erasebkgnd_parent_seq[] = {
217 { WM_ERASEBKGND, sent },
218 { 0 }
221 static const struct message ownerdata_select_focus_parent_seq[] = {
222 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
223 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
224 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
225 { 0 }
228 static const struct message ownerdata_setstate_all_parent_seq[] = {
229 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
230 { 0 }
233 static const struct message ownerdata_defocus_all_parent_seq[] = {
234 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
235 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
236 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
237 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
238 { 0 }
241 static const struct message ownerdata_deselect_all_parent_seq[] = {
242 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
243 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
244 { 0 }
247 static const struct message change_all_parent_seq[] = {
248 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
249 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
251 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
252 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
254 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
255 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
257 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
258 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
260 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
261 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
262 { 0 }
265 static const struct message changing_all_parent_seq[] = {
266 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
267 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
268 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
269 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
270 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
271 { 0 }
274 static const struct message textcallback_set_again_parent_seq[] = {
275 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
276 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
277 { 0 }
280 static const struct message single_getdispinfo_parent_seq[] = {
281 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
282 { 0 }
285 static const struct message getitemposition_seq1[] = {
286 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
287 { 0 }
290 static const struct message getitemposition_seq2[] = {
291 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
292 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
293 { 0 }
296 static const struct message getsubitemrect_seq[] = {
297 { LVM_GETSUBITEMRECT, sent|id|wparam, -1, 0, LISTVIEW_ID },
298 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
299 { LVM_GETSUBITEMRECT, sent|id|wparam, 0, 0, LISTVIEW_ID },
300 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
301 { LVM_GETSUBITEMRECT, sent|id|wparam, -10, 0, LISTVIEW_ID },
302 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
303 { LVM_GETSUBITEMRECT, sent|id|wparam, 20, 0, LISTVIEW_ID },
304 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
305 { 0 }
308 static const struct message editbox_create_pos[] = {
309 /* sequence sent after LVN_BEGINLABELEDIT */
310 /* next two are 4.7x specific */
311 { WM_WINDOWPOSCHANGING, sent },
312 { WM_WINDOWPOSCHANGED, sent|optional },
314 { WM_WINDOWPOSCHANGING, sent|optional },
315 { WM_NCCALCSIZE, sent },
316 { WM_WINDOWPOSCHANGED, sent },
317 { WM_MOVE, sent|defwinproc },
318 { WM_SIZE, sent|defwinproc },
319 /* the rest is todo, skipped in 4.7x */
320 { WM_WINDOWPOSCHANGING, sent|optional },
321 { WM_WINDOWPOSCHANGED, sent|optional },
322 { 0 }
325 static const struct message scroll_parent_seq[] = {
326 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
327 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
328 { 0 }
331 static const struct message setredraw_seq[] = {
332 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
333 { 0 }
336 static const struct message lvs_ex_transparentbkgnd_seq[] = {
337 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
338 { 0 }
341 static const struct message edit_end_nochange[] = {
342 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
343 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW }, /* todo */
344 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
345 { 0 }
348 static const struct message hover_parent[] = {
349 { WM_GETDLGCODE, sent }, /* todo_wine */
350 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
351 { 0 }
354 static const struct message listview_destroy[] = {
355 { 0x0090, sent|optional }, /* Vista */
356 { WM_PARENTNOTIFY, sent },
357 { WM_SHOWWINDOW, sent },
358 { WM_WINDOWPOSCHANGING, sent },
359 { WM_WINDOWPOSCHANGED, sent|optional },
360 { WM_DESTROY, sent },
361 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
362 { WM_NCDESTROY, sent },
363 { 0 }
366 static const struct message listview_ownerdata_destroy[] = {
367 { 0x0090, sent|optional }, /* Vista */
368 { WM_PARENTNOTIFY, sent },
369 { WM_SHOWWINDOW, sent },
370 { WM_WINDOWPOSCHANGING, sent },
371 { WM_WINDOWPOSCHANGED, sent|optional },
372 { WM_DESTROY, sent },
373 { WM_NCDESTROY, sent },
374 { 0 }
377 static const struct message listview_ownerdata_deleteall[] = {
378 { LVM_DELETEALLITEMS, sent },
379 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
380 { 0 }
383 static const struct message listview_header_changed_seq[] = {
384 { LVM_SETCOLUMNA, sent },
385 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
386 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
387 { 0 }
390 static const struct message parent_header_click_seq[] = {
391 { WM_NOTIFY, sent|id, 0, 0, LVN_COLUMNCLICK },
392 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCLICKA },
393 { 0 }
396 static const struct message parent_header_divider_dclick_seq[] = {
397 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGINGA },
398 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
399 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
400 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGEDA },
401 { WM_NOTIFY, sent|id, 0, 0, HDN_DIVIDERDBLCLICKA },
402 { 0 }
405 static const struct message listview_set_imagelist[] = {
406 { LVM_SETIMAGELIST, sent|id, 0, 0, LISTVIEW_ID },
407 { 0 }
410 static const struct message listview_header_set_imagelist[] = {
411 { LVM_SETIMAGELIST, sent|id, 0, 0, LISTVIEW_ID },
412 { HDM_SETIMAGELIST, sent|id, 0, 0, HEADER_ID },
413 { 0 }
416 static const struct message parent_insert_focused_seq[] = {
417 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
418 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
419 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
420 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
421 { WM_NOTIFY, sent|id, 0, 0, LVN_INSERTITEM },
422 { 0 }
425 static const struct message parent_report_cd_seq[] = {
426 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_PREPAINT },
427 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT },
428 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT|CDDS_SUBITEM },
429 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT|CDDS_SUBITEM },
430 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT|CDDS_SUBITEM },
431 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT|CDDS_SUBITEM },
432 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT },
433 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_POSTPAINT },
434 { 0 }
437 static const struct message parent_list_cd_seq[] = {
438 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_PREPAINT },
439 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT },
440 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT },
441 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_POSTPAINT },
442 { 0 }
445 static const struct message listview_end_label_edit[] = {
446 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
447 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING},
448 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
449 { WM_NOTIFY, sent|id|optional, 0, 0, NM_CUSTOMDRAW }, /* XP */
450 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
451 { 0 }
454 static const struct message listview_end_label_edit_kill_focus[] = {
455 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
456 { WM_COMMAND, sent|id|optional, 0, 0, EN_KILLFOCUS }, /* todo: not sent by wine yet */
457 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
458 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
459 { WM_NOTIFY, sent|id|optional, 0, 0, NM_CUSTOMDRAW }, /* XP */
460 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
461 { 0 }
464 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
466 static LONG defwndproc_counter = 0;
467 LRESULT ret;
468 struct message msg;
470 msg.message = message;
471 msg.flags = sent|wparam|lparam;
472 if (defwndproc_counter) msg.flags |= defwinproc;
473 msg.wParam = wParam;
474 msg.lParam = lParam;
475 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
476 if (message == WM_COMMAND) msg.id = HIWORD(wParam);
478 /* log system messages, except for painting */
479 if (message < WM_USER &&
480 message != WM_PAINT &&
481 message != WM_ERASEBKGND &&
482 message != WM_NCPAINT &&
483 message != WM_NCHITTEST &&
484 message != WM_GETTEXT &&
485 message != WM_GETICON &&
486 message != WM_DEVICECHANGE)
488 add_message(sequences, PARENT_SEQ_INDEX, &msg);
489 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
491 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
493 switch (message)
495 case WM_NOTIFY:
497 switch (((NMHDR*)lParam)->code)
499 case LVN_BEGINLABELEDITA:
501 HWND edit = NULL;
503 /* subclass edit box */
504 if (!blockEdit)
505 edit = subclass_editbox(((NMHDR*)lParam)->hwndFrom);
507 if (edit)
509 INT len = SendMessageA(edit, EM_GETLIMITTEXT, 0, 0);
510 ok(len == 259 || broken(len == 260) /* includes NULL in NT4 */,
511 "text limit %d, expected 259\n", len);
514 return blockEdit;
516 case LVN_ENDLABELEDITA:
518 HWND edit;
520 /* always accept new item text */
521 NMLVDISPINFOA *di = (NMLVDISPINFOA*)lParam;
522 g_editbox_disp_info = *di;
524 /* edit control still available from this notification */
525 edit = (HWND)SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETEDITCONTROL, 0, 0);
526 ok(IsWindow(edit), "expected valid edit control handle\n");
527 ok((GetWindowLongA(edit, GWL_STYLE) & ES_MULTILINE) == 0, "edit is multiline\n");
529 if (g_WM_KILLFOCUS_on_LVN_ENDLABELEDIT)
530 SendMessageA(edit, WM_KILLFOCUS, 0, 0);
532 return TRUE;
534 case LVN_ITEMCHANGING:
536 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
537 g_nmlistview_changing = *nmlv;
539 break;
540 case LVN_ITEMCHANGED:
542 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
543 g_nmlistview = *nmlv;
545 break;
546 case LVN_GETDISPINFOA:
548 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
549 g_itema = dispinfo->item;
551 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
553 dispinfo->hdr.code = LVN_GETDISPINFOW;
554 lstrcpyW((WCHAR *)dispinfo->item.pszText, L"TEST");
557 /* test control buffer size for text, 10 used to mask cases when control
558 is using caller buffer to process LVM_GETITEM for example */
559 if (dispinfo->item.mask & LVIF_TEXT && dispinfo->item.cchTextMax > 10)
560 ok(dispinfo->item.cchTextMax == 260 ||
561 broken(dispinfo->item.cchTextMax == 264) /* NT4 reports aligned size */,
562 "buffer size %d\n", dispinfo->item.cchTextMax);
564 break;
565 case LVN_DELETEITEM:
566 if (g_focus_test_LVN_DELETEITEM)
568 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
569 UINT state;
571 state = SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETITEMSTATE, nmlv->iItem, LVIS_FOCUSED);
572 ok(state == 0, "got state %x\n", state);
574 break;
575 case NM_HOVER:
576 if (g_block_hover) return 1;
577 break;
579 break;
581 case WM_NOTIFYFORMAT:
583 /* force to return format */
584 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
585 break;
589 defwndproc_counter++;
590 if (IsWindowUnicode(hwnd))
591 ret = DefWindowProcW(hwnd, message, wParam, lParam);
592 else
593 ret = DefWindowProcA(hwnd, message, wParam, lParam);
594 defwndproc_counter--;
596 return ret;
599 static BOOL register_parent_wnd_class(BOOL Unicode)
601 WNDCLASSA clsA;
602 WNDCLASSW clsW;
604 if (Unicode)
606 clsW.style = 0;
607 clsW.lpfnWndProc = parent_wnd_proc;
608 clsW.cbClsExtra = 0;
609 clsW.cbWndExtra = 0;
610 clsW.hInstance = GetModuleHandleW(NULL);
611 clsW.hIcon = 0;
612 clsW.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
613 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
614 clsW.lpszMenuName = NULL;
615 clsW.lpszClassName = L"Listview test parentW";
617 else
619 clsA.style = 0;
620 clsA.lpfnWndProc = parent_wnd_proc;
621 clsA.cbClsExtra = 0;
622 clsA.cbWndExtra = 0;
623 clsA.hInstance = GetModuleHandleA(NULL);
624 clsA.hIcon = 0;
625 clsA.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
626 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
627 clsA.lpszMenuName = NULL;
628 clsA.lpszClassName = "Listview test parent class";
631 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
634 static HWND create_parent_window(BOOL Unicode)
636 HWND hwnd;
638 if (!register_parent_wnd_class(Unicode))
639 return NULL;
641 blockEdit = FALSE;
642 notifyFormat = -1;
644 if (Unicode)
645 hwnd = CreateWindowExW(0, L"Listview test parentW", L"testparentnameW",
646 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
647 WS_MAXIMIZEBOX | WS_VISIBLE,
648 0, 0, 100, 100,
649 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
650 else
651 hwnd = CreateWindowExA(0, "Listview test parent class",
652 "Listview test parent window",
653 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
654 WS_MAXIMIZEBOX | WS_VISIBLE,
655 0, 0, 100, 100,
656 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
657 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
658 return hwnd;
661 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
663 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
664 static LONG defwndproc_counter = 0;
665 LRESULT ret;
666 struct message msg;
668 msg.message = message;
669 msg.flags = sent|wparam|lparam;
670 if (defwndproc_counter) msg.flags |= defwinproc;
671 msg.wParam = wParam;
672 msg.lParam = lParam;
673 msg.id = LISTVIEW_ID;
674 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
675 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
677 defwndproc_counter++;
678 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
679 defwndproc_counter--;
680 return ret;
683 static HWND create_listview_control(DWORD style)
685 WNDPROC oldproc;
686 HWND hwnd;
687 RECT rect;
689 GetClientRect(hwndparent, &rect);
690 hwnd = CreateWindowExA(0, WC_LISTVIEWA, "foo",
691 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
692 0, 0, rect.right, rect.bottom,
693 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
694 ok(hwnd != NULL, "gle=%d\n", GetLastError());
696 if (!hwnd) return NULL;
698 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
699 (LONG_PTR)listview_subclass_proc);
700 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
702 return hwnd;
705 /* unicode listview window with specified parent */
706 static HWND create_listview_controlW(DWORD style, HWND parent)
708 WNDPROC oldproc;
709 HWND hwnd;
710 RECT rect;
712 GetClientRect(parent, &rect);
713 hwnd = CreateWindowExW(0, WC_LISTVIEWW, L"foo",
714 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
715 0, 0, rect.right, rect.bottom,
716 parent, NULL, GetModuleHandleW(NULL), NULL);
717 ok(hwnd != NULL, "gle=%d\n", GetLastError());
719 if (!hwnd) return NULL;
721 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
722 (LONG_PTR)listview_subclass_proc);
723 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
725 return hwnd;
729 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
731 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
732 static LONG defwndproc_counter = 0;
733 struct message msg = { 0 };
734 LRESULT ret;
736 msg.message = message;
737 msg.flags = sent|wparam|lparam;
738 if (defwndproc_counter) msg.flags |= defwinproc;
739 msg.wParam = wParam;
740 msg.lParam = lParam;
741 msg.id = HEADER_ID;
742 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
744 defwndproc_counter++;
745 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
746 defwndproc_counter--;
747 return ret;
750 static HWND subclass_header(HWND hwndListview)
752 WNDPROC oldproc;
753 HWND hwnd;
755 hwnd = (HWND)SendMessageA(hwndListview, LVM_GETHEADER, 0, 0);
756 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
757 (LONG_PTR)header_subclass_proc);
758 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
760 return hwnd;
763 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
765 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
766 static LONG defwndproc_counter = 0;
767 struct message msg = { 0 };
768 LRESULT ret;
770 msg.message = message;
771 msg.flags = sent|wparam|lparam;
772 if (defwndproc_counter) msg.flags |= defwinproc;
773 msg.wParam = wParam;
774 msg.lParam = lParam;
776 /* all we need is sizing */
777 if (message == WM_WINDOWPOSCHANGING ||
778 message == WM_NCCALCSIZE ||
779 message == WM_WINDOWPOSCHANGED ||
780 message == WM_MOVE ||
781 message == WM_SIZE)
783 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
786 defwndproc_counter++;
787 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
788 defwndproc_counter--;
789 return ret;
792 static HWND subclass_editbox(HWND hwndListview)
794 WNDPROC oldproc;
795 HWND hwnd;
797 hwnd = (HWND)SendMessageA(hwndListview, LVM_GETEDITCONTROL, 0, 0);
798 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
799 (LONG_PTR)editbox_subclass_proc);
800 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
802 return hwnd;
805 /* Performs a single LVM_HITTEST test */
806 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
807 BOOL todo_item, BOOL todo_flags, int line)
809 LVHITTESTINFO lpht;
810 INT ret;
812 lpht.pt.x = x;
813 lpht.pt.y = y;
814 lpht.iSubItem = 10;
816 ret = SendMessageA(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
818 todo_wine_if(todo_item)
820 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
821 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
822 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
825 if (todo_flags)
827 todo_wine
828 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
830 else if (broken_flags)
831 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
832 "Expected flags %x, got %x\n", flags, lpht.flags);
833 else
834 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
837 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
839 /* Performs a single LVM_SUBITEMHITTEST test */
840 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
841 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
843 LVHITTESTINFO lpht;
844 INT ret;
846 lpht.pt.x = x;
847 lpht.pt.y = y;
849 ret = SendMessageA(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
851 todo_wine_if(todo_item)
853 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
854 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
857 todo_wine_if(todo_subitem)
858 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
860 todo_wine_if(todo_flags)
861 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
864 #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__)
866 static void test_images(void)
868 HWND hwnd;
869 INT r;
870 LVITEMA item;
871 HIMAGELIST himl;
872 HBITMAP hbmp;
873 RECT r1, r2;
874 static CHAR hello[] = "hello";
876 himl = pImageList_Create(40, 40, 0, 4, 4);
877 ok(himl != NULL, "failed to create imagelist\n");
879 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
880 ok(hbmp != NULL, "failed to create bitmap\n");
882 r = pImageList_Add(himl, hbmp, 0);
883 ok(r == 0, "should be zero\n");
885 hwnd = CreateWindowExA(0, WC_LISTVIEWA, "foo", LVS_OWNERDRAWFIXED,
886 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
887 ok(hwnd != NULL, "failed to create listview window\n");
889 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
890 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
892 ok(r == 0, "should return zero\n");
894 r = SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
895 ok(r == 0, "should return zero\n");
897 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
898 ok(r != 0, "got 0\n");
900 /* returns dimensions */
902 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
903 ok(r == 0, "should be zero items\n");
905 item.mask = LVIF_IMAGE | LVIF_TEXT;
906 item.iItem = 0;
907 item.iSubItem = 1;
908 item.iImage = 0;
909 item.pszText = 0;
910 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
911 ok(r == -1, "should fail\n");
913 item.iSubItem = 0;
914 item.pszText = hello;
915 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
916 ok(r == 0, "should not fail\n");
918 SetRect(&r1, LVIR_ICON, 0, 0, 0);
919 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
920 expect(1, r);
922 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
923 ok(r == TRUE, "should not fail\n");
925 item.iSubItem = 0;
926 item.pszText = hello;
927 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
928 ok(r == 0, "should not fail\n");
930 SetRect(&r2, LVIR_ICON, 0, 0, 0);
931 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
932 expect(1, r);
934 ok(EqualRect(&r1, &r2), "rectangle should be the same\n");
936 DestroyWindow(hwnd);
938 /* I_IMAGECALLBACK set for item, try to get image with invalid subitem. */
939 hwnd = create_listview_control(LVS_REPORT);
940 ok(hwnd != NULL, "Failed to create listview.\n");
942 memset(&item, 0, sizeof(item));
943 item.mask = LVIF_IMAGE;
944 item.iImage = I_IMAGECALLBACK;
945 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
946 ok(!r, "Failed to insert item.\n");
948 flush_sequences(sequences, NUM_MSG_SEQUENCES);
950 memset(&item, 0, sizeof(item));
951 item.mask = LVIF_IMAGE;
952 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
953 ok(r, "Failed to get item.\n");
955 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq, "get image dispinfo 1", FALSE);
957 flush_sequences(sequences, NUM_MSG_SEQUENCES);
959 memset(&item, 0, sizeof(item));
960 item.mask = LVIF_IMAGE;
961 item.iSubItem = 1;
962 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
963 ok(r, "Failed to get item.\n");
965 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "get image dispinfo 2", FALSE);
967 DestroyWindow(hwnd);
970 static void test_checkboxes(void)
972 HWND hwnd;
973 LVITEMA item;
974 DWORD r;
975 static CHAR text[] = "Text",
976 text2[] = "Text2",
977 text3[] = "Text3";
979 hwnd = CreateWindowExA(0, WC_LISTVIEWA, "foo", LVS_REPORT,
980 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
981 ok(hwnd != NULL, "failed to create listview window\n");
983 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
984 item.mask = LVIF_TEXT | LVIF_STATE;
985 item.stateMask = 0xffff;
986 item.state = 0xfccc;
987 item.iItem = 0;
988 item.iSubItem = 0;
989 item.pszText = text;
990 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
991 expect(0, r);
993 item.iItem = 0;
994 item.mask = LVIF_STATE;
995 item.stateMask = 0xffff;
996 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
997 expect(1, r);
998 ok(item.state == 0xfccc, "state %x\n", item.state);
1000 /* Don't set LVIF_STATE */
1001 item.mask = LVIF_TEXT;
1002 item.stateMask = 0xffff;
1003 item.state = 0xfccc;
1004 item.iItem = 1;
1005 item.iSubItem = 0;
1006 item.pszText = text;
1007 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1008 expect(1, r);
1010 item.iItem = 1;
1011 item.mask = LVIF_STATE;
1012 item.stateMask = 0xffff;
1013 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1014 expect(1, r);
1015 ok(item.state == 0, "state %x\n", item.state);
1017 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1018 expect(0, r);
1020 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
1021 item.iItem = 0;
1022 item.mask = LVIF_STATE;
1023 item.stateMask = 0xffff;
1024 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1025 expect(1, r);
1027 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
1028 item.iItem = 2;
1029 item.mask = LVIF_TEXT;
1030 item.state = 0;
1031 item.pszText = text2;
1032 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1033 expect(2, r);
1035 item.iItem = 2;
1036 item.mask = LVIF_STATE;
1037 item.stateMask = 0xffff;
1038 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1039 expect(1, r);
1040 ok(item.state == 0x1000, "state %x\n", item.state);
1042 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
1043 item.iItem = 3;
1044 item.mask = LVIF_TEXT | LVIF_STATE;
1045 item.stateMask = 0xffff;
1046 item.state = 0x2aaa;
1047 item.pszText = text3;
1048 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1049 expect(3, r);
1051 item.iItem = 3;
1052 item.mask = LVIF_STATE;
1053 item.stateMask = 0xffff;
1054 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1055 expect(1, r);
1056 ok(item.state == 0x1aaa, "state %x\n", item.state);
1058 /* Set an item's state to checked */
1059 item.iItem = 3;
1060 item.mask = LVIF_STATE;
1061 item.stateMask = 0xf000;
1062 item.state = 0x2000;
1063 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1064 expect(1, r);
1066 item.iItem = 3;
1067 item.mask = LVIF_STATE;
1068 item.stateMask = 0xffff;
1069 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1070 expect(1, r);
1071 ok(item.state == 0x2aaa, "state %x\n", item.state);
1073 /* Check that only the bits we asked for are returned,
1074 * and that all the others are set to zero
1076 item.iItem = 3;
1077 item.mask = LVIF_STATE;
1078 item.stateMask = 0xf000;
1079 item.state = 0xffff;
1080 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1081 expect(1, r);
1082 ok(item.state == 0x2000, "state %x\n", item.state);
1084 /* Set the style again and check that doesn't change an item's state */
1085 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1086 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1088 item.iItem = 3;
1089 item.mask = LVIF_STATE;
1090 item.stateMask = 0xffff;
1091 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1092 expect(1, r);
1093 ok(item.state == 0x2aaa, "state %x\n", item.state);
1095 /* Unsetting the checkbox extended style doesn't change an item's state */
1096 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
1097 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1099 item.iItem = 3;
1100 item.mask = LVIF_STATE;
1101 item.stateMask = 0xffff;
1102 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1103 expect(1, r);
1104 ok(item.state == 0x2aaa, "state %x\n", item.state);
1106 /* Now setting the style again will change an item's state */
1107 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1108 expect(0, r);
1110 item.iItem = 3;
1111 item.mask = LVIF_STATE;
1112 item.stateMask = 0xffff;
1113 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1114 expect(1, r);
1115 ok(item.state == 0x1aaa, "state %x\n", item.state);
1117 /* Toggle checkbox tests (bug 9934) */
1118 memset (&item, 0xcc, sizeof(item));
1119 item.mask = LVIF_STATE;
1120 item.iItem = 3;
1121 item.iSubItem = 0;
1122 item.state = LVIS_FOCUSED;
1123 item.stateMask = LVIS_FOCUSED;
1124 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1125 expect(1, r);
1127 item.iItem = 3;
1128 item.mask = LVIF_STATE;
1129 item.stateMask = 0xffff;
1130 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1131 expect(1, r);
1132 ok(item.state == 0x1aab, "state %x\n", item.state);
1134 r = SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1135 expect(0, r);
1136 r = SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
1137 expect(0, r);
1139 item.iItem = 3;
1140 item.mask = LVIF_STATE;
1141 item.stateMask = 0xffff;
1142 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1143 expect(1, r);
1144 ok(item.state == 0x2aab, "state %x\n", item.state);
1146 r = SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1147 expect(0, r);
1148 r = SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
1149 expect(0, r);
1151 item.iItem = 3;
1152 item.mask = LVIF_STATE;
1153 item.stateMask = 0xffff;
1154 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1155 expect(1, r);
1156 ok(item.state == 0x1aab, "state %x\n", item.state);
1158 DestroyWindow(hwnd);
1161 static void insert_column(HWND hwnd, int idx)
1163 LVCOLUMNA column;
1164 INT rc;
1166 memset(&column, 0xcc, sizeof(column));
1167 column.mask = LVCF_SUBITEM;
1168 column.iSubItem = idx;
1170 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, idx, (LPARAM)&column);
1171 expect(idx, rc);
1174 static void insert_item(HWND hwnd, int idx)
1176 static CHAR text[] = "foo";
1178 LVITEMA item;
1179 INT rc;
1181 memset(&item, 0xcc, sizeof (item));
1182 item.mask = LVIF_TEXT;
1183 item.iItem = idx;
1184 item.iSubItem = 0;
1185 item.pszText = text;
1187 rc = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
1188 expect(idx, rc);
1191 static void test_items(void)
1193 const LPARAM lparamTest = 0x42;
1194 static CHAR text[] = "Text";
1195 char buffA[5];
1196 HWND hwnd;
1197 LVITEMA item;
1198 DWORD r;
1200 hwnd = CreateWindowExA(0, WC_LISTVIEWA, "foo", LVS_REPORT,
1201 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1202 ok(hwnd != NULL, "failed to create listview window\n");
1205 * Test setting/getting item params
1208 /* Set up two columns */
1209 insert_column(hwnd, 0);
1210 insert_column(hwnd, 1);
1212 /* LVIS_SELECTED with zero stateMask */
1213 /* set */
1214 memset (&item, 0, sizeof (item));
1215 item.mask = LVIF_STATE;
1216 item.state = LVIS_SELECTED;
1217 item.stateMask = 0;
1218 item.iItem = 0;
1219 item.iSubItem = 0;
1220 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1221 expect(0, r);
1222 /* get */
1223 memset (&item, 0xcc, sizeof (item));
1224 item.mask = LVIF_STATE;
1225 item.stateMask = LVIS_SELECTED;
1226 item.state = 0;
1227 item.iItem = 0;
1228 item.iSubItem = 0;
1229 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1230 expect(1, r);
1231 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1232 r = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1233 ok(r, "got %d\n", r);
1235 /* LVIS_SELECTED with zero stateMask */
1236 /* set */
1237 memset (&item, 0, sizeof (item));
1238 item.mask = LVIF_STATE;
1239 item.state = LVIS_FOCUSED;
1240 item.stateMask = 0;
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_FOCUSED;
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_FOCUSED, "Expected LVIS_FOCUSED\n");
1255 r = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1256 ok(r, "got %d\n", r);
1258 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1259 /* set */
1260 memset (&item, 0, sizeof (item));
1261 item.mask = LVIF_STATE;
1262 item.state = LVIS_CUT;
1263 item.stateMask = LVIS_FOCUSED;
1264 item.iItem = 0;
1265 item.iSubItem = 0;
1266 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1267 expect(0, r);
1268 /* get */
1269 memset (&item, 0xcc, sizeof (item));
1270 item.mask = LVIF_STATE;
1271 item.stateMask = LVIS_CUT;
1272 item.state = 0;
1273 item.iItem = 0;
1274 item.iSubItem = 0;
1275 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1276 expect(1, r);
1277 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1278 r = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1279 ok(r, "got %d\n", r);
1281 /* Insert an item with just a param */
1282 memset (&item, 0xcc, sizeof (item));
1283 item.mask = LVIF_PARAM;
1284 item.iItem = 0;
1285 item.iSubItem = 0;
1286 item.lParam = lparamTest;
1287 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1288 expect(0, r);
1290 /* Test getting of the param */
1291 memset (&item, 0xcc, sizeof (item));
1292 item.mask = LVIF_PARAM;
1293 item.iItem = 0;
1294 item.iSubItem = 0;
1295 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1296 expect(1, r);
1297 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1299 /* Set up a subitem */
1300 memset (&item, 0xcc, sizeof (item));
1301 item.mask = LVIF_TEXT;
1302 item.iItem = 0;
1303 item.iSubItem = 1;
1304 item.pszText = text;
1305 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1306 expect(1, r);
1308 item.mask = LVIF_TEXT;
1309 item.iItem = 0;
1310 item.iSubItem = 1;
1311 item.pszText = buffA;
1312 item.cchTextMax = sizeof(buffA);
1313 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1314 expect(1, r);
1315 ok(!memcmp(item.pszText, text, sizeof(text)), "got text %s, expected %s\n", item.pszText, text);
1317 /* set up with extra flag */
1318 /* 1. reset subitem text */
1319 item.mask = LVIF_TEXT;
1320 item.iItem = 0;
1321 item.iSubItem = 1;
1322 item.pszText = NULL;
1323 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1324 expect(1, r);
1326 item.mask = LVIF_TEXT;
1327 item.iItem = 0;
1328 item.iSubItem = 1;
1329 item.pszText = buffA;
1330 buffA[0] = 'a';
1331 item.cchTextMax = sizeof(buffA);
1332 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1333 expect(1, r);
1334 ok(item.pszText[0] == 0, "got %p\n", item.pszText);
1336 /* 2. set new text with extra flag specified */
1337 item.mask = LVIF_TEXT | LVIF_DI_SETITEM;
1338 item.iItem = 0;
1339 item.iSubItem = 1;
1340 item.pszText = text;
1341 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1342 ok(r == 1 || broken(r == 0) /* NT4 */, "ret %d\n", r);
1344 if (r == 1)
1346 item.mask = LVIF_TEXT;
1347 item.iItem = 0;
1348 item.iSubItem = 1;
1349 item.pszText = buffA;
1350 buffA[0] = 'a';
1351 item.cchTextMax = sizeof(buffA);
1352 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1353 expect(1, r);
1354 ok(!memcmp(item.pszText, text, sizeof(text)), "got %s, expected %s\n", item.pszText, text);
1357 /* Query param from subitem: returns main item param */
1358 memset (&item, 0xcc, sizeof (item));
1359 item.mask = LVIF_PARAM;
1360 item.iItem = 0;
1361 item.iSubItem = 1;
1362 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1363 expect(1, r);
1364 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1366 /* Set up param on first subitem: no effect */
1367 memset (&item, 0xcc, sizeof (item));
1368 item.mask = LVIF_PARAM;
1369 item.iItem = 0;
1370 item.iSubItem = 1;
1371 item.lParam = lparamTest+1;
1372 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1373 expect(0, r);
1375 /* Query param from subitem again: should still return main item param */
1376 memset (&item, 0xcc, sizeof (item));
1377 item.mask = LVIF_PARAM;
1378 item.iItem = 0;
1379 item.iSubItem = 1;
1380 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1381 expect(1, r);
1382 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1384 /**** Some tests of state highlighting ****/
1385 memset (&item, 0xcc, sizeof (item));
1386 item.mask = LVIF_STATE;
1387 item.iItem = 0;
1388 item.iSubItem = 0;
1389 item.state = LVIS_SELECTED;
1390 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1391 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1392 expect(1, r);
1393 item.iSubItem = 1;
1394 item.state = LVIS_DROPHILITED;
1395 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1396 expect(1, r);
1398 memset (&item, 0xcc, sizeof (item));
1399 item.mask = LVIF_STATE;
1400 item.iItem = 0;
1401 item.iSubItem = 0;
1402 item.stateMask = -1;
1403 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1404 expect(1, r);
1405 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1406 item.iSubItem = 1;
1407 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1408 expect(1, r);
1409 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1411 /* some notnull but meaningless masks */
1412 memset (&item, 0, sizeof(item));
1413 item.mask = LVIF_NORECOMPUTE;
1414 item.iItem = 0;
1415 item.iSubItem = 0;
1416 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1417 expect(1, r);
1418 memset (&item, 0, sizeof(item));
1419 item.mask = LVIF_DI_SETITEM;
1420 item.iItem = 0;
1421 item.iSubItem = 0;
1422 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1423 expect(1, r);
1425 /* set text to callback value already having it */
1426 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
1427 expect(TRUE, r);
1428 memset (&item, 0, sizeof (item));
1429 item.mask = LVIF_TEXT;
1430 item.pszText = LPSTR_TEXTCALLBACKA;
1431 item.iItem = 0;
1432 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1433 expect(0, r);
1434 memset (&item, 0, sizeof (item));
1436 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1438 item.pszText = LPSTR_TEXTCALLBACKA;
1439 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0 , (LPARAM) &item);
1440 expect(TRUE, r);
1442 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1443 "check callback text comparison rule", FALSE);
1445 DestroyWindow(hwnd);
1448 static void test_columns(void)
1450 HWND hwnd, header;
1451 LVCOLUMNA column;
1452 LVITEMA item;
1453 INT order[2];
1454 CHAR buff[5];
1455 DWORD rc;
1457 hwnd = CreateWindowExA(0, WC_LISTVIEWA, "foo", LVS_LIST,
1458 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1459 ok(hwnd != NULL, "failed to create listview window\n");
1461 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
1462 ok(header == NULL, "got %p\n", header);
1464 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1465 ok(rc == 0, "got %d\n", rc);
1467 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
1468 ok(header == NULL, "got %p\n", header);
1470 DestroyWindow(hwnd);
1472 hwnd = CreateWindowExA(0, WC_LISTVIEWA, "foo", LVS_REPORT,
1473 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1474 ok(hwnd != NULL, "failed to create listview window\n");
1476 rc = SendMessageA(hwnd, LVM_DELETECOLUMN, -1, 0);
1477 ok(!rc, "got %d\n", rc);
1479 rc = SendMessageA(hwnd, LVM_DELETECOLUMN, 0, 0);
1480 ok(!rc, "got %d\n", rc);
1482 /* Add a column with no mask */
1483 memset(&column, 0xcc, sizeof(column));
1484 column.mask = 0;
1485 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1486 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1488 /* Check its width */
1489 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1490 ok(rc == 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1492 DestroyWindow(hwnd);
1494 /* LVM_GETCOLUMNORDERARRAY */
1495 hwnd = create_listview_control(LVS_REPORT);
1496 subclass_header(hwnd);
1498 memset(&column, 0, sizeof(column));
1499 column.mask = LVCF_WIDTH;
1500 column.cx = 100;
1501 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1502 expect(0, rc);
1504 column.cx = 200;
1505 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1506 expect(1, rc);
1508 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1510 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1511 expect(1, rc);
1512 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1513 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1515 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 0, 0);
1516 expect(0, rc);
1518 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1520 /* LVM_SETCOLUMNORDERARRAY */
1521 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1523 order[0] = 0;
1524 order[1] = 1;
1525 rc = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1526 expect(1, rc);
1528 rc = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 0, 0);
1529 expect(0, rc);
1531 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_setorderarray_seq, "set order array", FALSE);
1533 /* after column added subitem is considered as present */
1534 insert_item(hwnd, 0);
1536 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1538 item.pszText = buff;
1539 item.cchTextMax = sizeof(buff);
1540 item.iItem = 0;
1541 item.iSubItem = 1;
1542 item.mask = LVIF_TEXT;
1543 memset(&g_itema, 0, sizeof(g_itema));
1544 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1545 expect(1, rc);
1546 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1548 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1549 "get subitem text after column added", FALSE);
1551 DestroyWindow(hwnd);
1553 /* Columns are not created right away. */
1554 hwnd = create_listview_control(LVS_REPORT);
1555 ok(hwnd != NULL, "Failed to create a listview window.\n");
1557 insert_item(hwnd, 0);
1559 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
1560 ok(IsWindow(header), "Expected header handle.\n");
1561 rc = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
1562 ok(!rc, "Unexpected column count.\n");
1564 DestroyWindow(hwnd);
1567 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1568 static WNDPROC listviewWndProc;
1569 static HIMAGELIST test_create_imagelist;
1571 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1573 LRESULT ret;
1575 if (uMsg == WM_CREATE)
1577 CREATESTRUCTA *lpcs = (CREATESTRUCTA*)lParam;
1578 lpcs->style |= LVS_REPORT;
1580 ret = CallWindowProcA(listviewWndProc, hwnd, uMsg, wParam, lParam);
1581 if (uMsg == WM_CREATE) SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1582 return ret;
1585 /* Header creation is delayed in classic implementation. */
1586 #define TEST_NO_HEADER(a) test_header_presence_(a, FALSE, __LINE__)
1587 #define TEST_HEADER_EXPECTED(a) test_header_presence_(a, TRUE, __LINE__)
1588 #define TEST_NO_HEADER2(a, b) test_header_presence_(a, b, __LINE__)
1589 static void test_header_presence_(HWND hwnd, BOOL present, int line)
1591 HWND header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
1593 if (present)
1595 ok_(__FILE__, line)(IsWindow(header), "Header should have been created.\n");
1596 if (header) /* FIXME: remove when todo's are fixed */
1597 ok_(__FILE__, line)(header == GetDlgItem(hwnd, 0), "Dialog item expected.\n");
1599 else
1601 ok_(__FILE__, line)(!IsWindow(header), "Header shouldn't be created.\n");
1602 ok_(__FILE__, line)(NULL == GetDlgItem(hwnd, 0), "NULL dialog item expected.\n");
1606 static void test_create(BOOL is_version_6)
1608 char buff[16];
1609 HWND hList;
1610 HWND hHeader;
1611 LONG_PTR ret;
1612 LONG r;
1613 LVCOLUMNA col;
1614 RECT rect;
1615 WNDCLASSEXA cls;
1616 DWORD style;
1617 ATOM class;
1619 cls.cbSize = sizeof(WNDCLASSEXA);
1620 r = GetClassInfoExA(GetModuleHandleA(NULL), WC_LISTVIEWA, &cls);
1621 ok(r, "Failed to get class info.\n");
1622 listviewWndProc = cls.lpfnWndProc;
1623 cls.lpfnWndProc = create_test_wndproc;
1624 cls.lpszClassName = "MyListView32";
1625 class = RegisterClassExA(&cls);
1626 ok(class, "Failed to register class.\n");
1628 test_create_imagelist = pImageList_Create(16, 16, 0, 5, 10);
1629 hList = CreateWindowA("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1630 ok((HIMAGELIST)SendMessageA(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1631 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1632 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1633 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1634 DestroyWindow(hList);
1636 /* header isn't created on LVS_ICON and LVS_LIST styles */
1637 hList = CreateWindowA(WC_LISTVIEWA, "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1638 TEST_NO_HEADER(hList);
1640 /* insert column */
1641 memset(&col, 0, sizeof(LVCOLUMNA));
1642 col.mask = LVCF_WIDTH;
1643 col.cx = 100;
1644 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1645 expect(0, r);
1646 TEST_HEADER_EXPECTED(hList);
1647 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1648 style = GetWindowLongA(hHeader, GWL_STYLE);
1649 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1650 DestroyWindow(hList);
1652 hList = CreateWindowA(WC_LISTVIEWA, "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1653 GetModuleHandleA(NULL), 0);
1654 TEST_NO_HEADER(hList);
1655 /* insert column */
1656 memset(&col, 0, sizeof(LVCOLUMNA));
1657 col.mask = LVCF_WIDTH;
1658 col.cx = 100;
1659 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1660 expect(0, r);
1661 TEST_HEADER_EXPECTED(hList);
1662 DestroyWindow(hList);
1664 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1665 hList = CreateWindowA(WC_LISTVIEWA, "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1666 GetModuleHandleA(NULL), 0);
1667 ret = SetWindowLongPtrA(hList, GWL_STYLE, GetWindowLongPtrA(hList, GWL_STYLE) | LVS_REPORT);
1668 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1669 TEST_HEADER_EXPECTED(hList);
1670 ret = SetWindowLongPtrA(hList, GWL_STYLE, GetWindowLongA(hList, GWL_STYLE) & ~LVS_REPORT);
1671 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1672 TEST_HEADER_EXPECTED(hList);
1673 DestroyWindow(hList);
1675 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1676 hList = CreateWindowA(WC_LISTVIEWA, "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1677 GetModuleHandleA(NULL), 0);
1678 ret = SetWindowLongPtrA(hList, GWL_STYLE,
1679 (GetWindowLongPtrA(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1680 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1681 TEST_HEADER_EXPECTED(hList);
1682 ret = SetWindowLongPtrA(hList, GWL_STYLE, (GetWindowLongPtrA(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1683 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1684 TEST_HEADER_EXPECTED(hList);
1685 DestroyWindow(hList);
1687 /* LVS_REPORT without WS_VISIBLE */
1688 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1689 GetModuleHandleA(NULL), 0);
1690 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1691 todo_wine_if(is_version_6)
1692 TEST_NO_HEADER2(hList, is_version_6);
1694 /* insert column */
1695 memset(&col, 0, sizeof(LVCOLUMNA));
1696 col.mask = LVCF_WIDTH;
1697 col.cx = 100;
1698 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1699 expect(0, r);
1700 TEST_HEADER_EXPECTED(hList);
1701 DestroyWindow(hList);
1703 /* LVS_REPORT without WS_VISIBLE, try to show it */
1704 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1705 GetModuleHandleA(NULL), 0);
1706 todo_wine_if(is_version_6)
1707 TEST_NO_HEADER2(hList, is_version_6);
1709 ShowWindow(hList, SW_SHOW);
1710 TEST_HEADER_EXPECTED(hList);
1711 DestroyWindow(hList);
1713 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1714 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1715 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1716 TEST_HEADER_EXPECTED(hList);
1717 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1718 /* HDS_DRAGDROP set by default */
1719 ok(GetWindowLongPtrA(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1720 DestroyWindow(hList);
1722 /* setting LVS_EX_HEADERDRAGDROP creates header */
1723 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1724 GetModuleHandleA(NULL), 0);
1725 todo_wine_if(is_version_6)
1726 TEST_NO_HEADER2(hList, is_version_6);
1728 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1729 TEST_HEADER_EXPECTED(hList);
1730 DestroyWindow(hList);
1732 /* setting LVS_EX_GRIDLINES creates header */
1733 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1734 GetModuleHandleA(NULL), 0);
1735 todo_wine_if(is_version_6)
1736 TEST_NO_HEADER2(hList, is_version_6);
1738 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_GRIDLINES);
1739 TEST_HEADER_EXPECTED(hList);
1740 DestroyWindow(hList);
1742 /* setting LVS_EX_FULLROWSELECT creates header */
1743 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1744 GetModuleHandleA(NULL), 0);
1745 todo_wine_if(is_version_6)
1746 TEST_NO_HEADER2(hList, is_version_6);
1747 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
1748 TEST_HEADER_EXPECTED(hList);
1749 DestroyWindow(hList);
1751 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1752 hList = create_listview_control(LVS_ICON);
1753 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1754 r = SendMessageA(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1755 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1756 DestroyWindow(hList);
1758 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1759 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1760 GetModuleHandleA(NULL), 0);
1761 todo_wine_if(is_version_6)
1762 TEST_NO_HEADER2(hList, is_version_6);
1764 SetRect(&rect, LVIR_BOUNDS, 1, -10, -10);
1765 r = SendMessageA(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1766 ok(r == 1, "Unexpected ret value %d.\n", r);
1767 /* right value contains garbage, probably because header columns are not set up */
1768 ok(rect.bottom >= 0, "Unexpected rectangle.\n");
1770 todo_wine_if(is_version_6)
1771 TEST_NO_HEADER2(hList, is_version_6);
1772 DestroyWindow(hList);
1774 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1775 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1776 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1777 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1778 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1779 DestroyWindow(hList);
1781 /* Test that window text is preserved. */
1782 hList = CreateWindowExA(0, WC_LISTVIEWA, "test text", WS_CHILD | WS_BORDER | WS_VISIBLE,
1783 0, 0, 100, 100, hwndparent, NULL, GetModuleHandleA(NULL), NULL);
1784 ok(hList != NULL, "Failed to create ListView window.\n");
1785 *buff = 0;
1786 GetWindowTextA(hList, buff, sizeof(buff));
1787 ok(!strcmp(buff, "test text"), "Unexpected window text %s.\n", buff);
1788 DestroyWindow(hList);
1790 hList = CreateWindowExW(0, WC_LISTVIEWW, L"test text", WS_CHILD | WS_BORDER | WS_VISIBLE,
1791 0, 0, 100, 100, hwndparent, NULL, GetModuleHandleA(NULL), NULL);
1792 ok(hList != NULL, "Failed to create ListView window.\n");
1793 *buff = 0;
1794 GetWindowTextA(hList, buff, sizeof(buff));
1795 ok(!strcmp(buff, "test text"), "Unexpected window text %s.\n", buff);
1796 DestroyWindow(hList);
1798 r = UnregisterClassA("MyListView32", NULL);
1799 ok(r, "Failed to unregister test class.\n");
1802 static void test_redraw(void)
1804 HWND hwnd;
1805 HDC hdc;
1806 BOOL res;
1807 DWORD r;
1808 RECT rect;
1810 hwnd = create_listview_control(LVS_REPORT);
1811 subclass_header(hwnd);
1813 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1815 InvalidateRect(hwnd, NULL, TRUE);
1816 UpdateWindow(hwnd);
1817 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1819 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1821 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1822 /* 1. Without backbuffer */
1823 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
1824 expect(TRUE, res);
1826 hdc = GetWindowDC(hwndparent);
1828 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1829 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1830 ok(r == 1, "Expected not zero result\n");
1831 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1832 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1834 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_DEFAULT);
1835 expect(TRUE, res);
1837 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1838 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1839 expect(1, r);
1840 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1841 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1843 /* 2. With backbuffer */
1844 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1845 LVS_EX_DOUBLEBUFFER);
1846 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
1847 expect(TRUE, res);
1849 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1850 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1851 expect(1, r);
1852 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1853 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1855 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_DEFAULT);
1856 expect(TRUE, res);
1858 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1859 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1860 todo_wine expect(1, r);
1861 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1862 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1864 ReleaseDC(hwndparent, hdc);
1866 /* test setting the window style to what it already was */
1867 UpdateWindow(hwnd);
1868 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE));
1869 GetUpdateRect(hwnd, &rect, FALSE);
1870 ok(rect.left == 0 && rect.top == 0 && rect.right == 0 && rect.bottom == 0,
1871 "Expected empty update rect, got %s\n", wine_dbgstr_rect(&rect));
1873 DestroyWindow(hwnd);
1876 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1878 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1880 if(message == WM_NOTIFY) {
1881 NMHDR *nmhdr = (NMHDR*)lParam;
1882 if(nmhdr->code == NM_CUSTOMDRAW) {
1883 NMLVCUSTOMDRAW *nmlvcd = (NMLVCUSTOMDRAW*)nmhdr;
1884 BOOL showsel_always = !!(GetWindowLongA(nmlvcd->nmcd.hdr.hwndFrom, GWL_STYLE) & LVS_SHOWSELALWAYS);
1885 BOOL is_selected = !!(nmlvcd->nmcd.uItemState & CDIS_SELECTED);
1886 struct message msg;
1888 msg.message = message;
1889 msg.flags = sent|wparam|lparam|custdraw;
1890 msg.wParam = wParam;
1891 msg.lParam = lParam;
1892 msg.id = nmhdr->code;
1893 msg.stage = nmlvcd->nmcd.dwDrawStage;
1894 add_message(sequences, PARENT_CD_SEQ_INDEX, &msg);
1896 switch(nmlvcd->nmcd.dwDrawStage) {
1897 case CDDS_PREPAINT:
1898 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1899 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1900 case CDDS_ITEMPREPAINT:
1901 clr = GetBkColor(nmlvcd->nmcd.hdc);
1902 todo_wine_if(nmlvcd->iSubItem)
1903 ok(clr == c0ffee, "Unexpected background color %#x.\n", clr);
1904 nmlvcd->clrTextBk = CLR_DEFAULT;
1905 nmlvcd->clrText = RGB(0, 255, 0);
1906 return CDRF_NOTIFYSUBITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1907 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1908 clr = GetBkColor(nmlvcd->nmcd.hdc);
1909 ok(nmlvcd->clrTextBk == CLR_DEFAULT, "Unexpected text background %#x.\n", nmlvcd->clrTextBk);
1910 ok(nmlvcd->clrText == RGB(0, 255, 0), "Unexpected text color %#x.\n", nmlvcd->clrText);
1911 if (showsel_always && is_selected && nmlvcd->iSubItem)
1912 ok(clr == GetSysColor(COLOR_3DFACE), "Unexpected background color %#x.\n", clr);
1913 else
1914 todo_wine_if(nmlvcd->iSubItem)
1915 ok(clr == c0ffee, "clr=%.8x\n", clr);
1916 return CDRF_NOTIFYPOSTPAINT;
1917 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1918 clr = GetBkColor(nmlvcd->nmcd.hdc);
1919 if (showsel_always && is_selected)
1920 ok(clr == GetSysColor(COLOR_3DFACE), "Unexpected background color %#x.\n", clr);
1921 else
1923 todo_wine
1924 ok(clr == c0ffee, "Unexpected background color %#x.\n", clr);
1927 ok(nmlvcd->clrTextBk == CLR_DEFAULT, "Unexpected text background color %#x.\n", nmlvcd->clrTextBk);
1928 ok(nmlvcd->clrText == RGB(0, 255, 0), "got 0x%x\n", nmlvcd->clrText);
1929 return CDRF_DODEFAULT;
1931 return CDRF_DODEFAULT;
1935 return DefWindowProcA(hwnd, message, wParam, lParam);
1938 static void test_customdraw(void)
1940 HWND hwnd;
1941 WNDPROC oldwndproc;
1942 LVITEMA item;
1944 hwnd = create_listview_control(LVS_REPORT);
1946 insert_column(hwnd, 0);
1947 insert_column(hwnd, 1);
1948 insert_item(hwnd, 0);
1950 oldwndproc = (WNDPROC)SetWindowLongPtrA(hwndparent, GWLP_WNDPROC,
1951 (LONG_PTR)cd_wndproc);
1953 InvalidateRect(hwnd, NULL, TRUE);
1954 UpdateWindow(hwnd);
1956 /* message tests */
1957 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1958 InvalidateRect(hwnd, NULL, TRUE);
1959 UpdateWindow(hwnd);
1960 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_report_cd_seq, "parent customdraw, LVS_REPORT", FALSE);
1962 /* Check colors when item is selected. */
1963 item.mask = LVIF_STATE;
1964 item.stateMask = LVIS_SELECTED;
1965 item.state = LVIS_SELECTED;
1966 SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
1968 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1969 InvalidateRect(hwnd, NULL, TRUE);
1970 UpdateWindow(hwnd);
1971 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_report_cd_seq,
1972 "parent customdraw, item selected, LVS_REPORT, selection", FALSE);
1974 SetWindowLongW(hwnd, GWL_STYLE, GetWindowLongW(hwnd, GWL_STYLE) | LVS_SHOWSELALWAYS);
1975 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1976 InvalidateRect(hwnd, NULL, TRUE);
1977 UpdateWindow(hwnd);
1978 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_report_cd_seq,
1979 "parent customdraw, item selected, LVS_SHOWSELALWAYS, LVS_REPORT", FALSE);
1981 DestroyWindow(hwnd);
1983 hwnd = create_listview_control(LVS_LIST);
1985 insert_column(hwnd, 0);
1986 insert_column(hwnd, 1);
1987 insert_item(hwnd, 0);
1989 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1990 InvalidateRect(hwnd, NULL, TRUE);
1991 UpdateWindow(hwnd);
1992 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_list_cd_seq, "parent customdraw, LVS_LIST", FALSE);
1994 SetWindowLongPtrA(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1995 DestroyWindow(hwnd);
1998 static void test_icon_spacing(void)
2000 /* LVM_SETICONSPACING */
2001 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
2003 HWND hwnd;
2004 WORD w, h;
2005 INT r;
2007 hwnd = create_listview_control(LVS_ICON);
2008 ok(hwnd != NULL, "failed to create a listview window\n");
2010 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
2011 expect(NFR_ANSI, r);
2013 /* reset the icon spacing to defaults */
2014 SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
2016 /* now we can request what the defaults are */
2017 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
2018 w = LOWORD(r);
2019 h = HIWORD(r);
2021 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2023 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
2024 ok(r == MAKELONG(w, h) ||
2025 broken(r == MAKELONG(w, w)), /* win98 */
2026 "Expected %d, got %d\n", MAKELONG(w, h), r);
2028 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
2029 expect(MAKELONG(20,30), r);
2031 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
2032 expect(MAKELONG(25,35), r);
2034 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
2036 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2037 DestroyWindow(hwnd);
2040 static void test_color(void)
2042 RECT rect;
2043 HWND hwnd;
2044 DWORD r;
2045 int i;
2047 COLORREF color;
2048 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
2050 hwnd = create_listview_control(LVS_REPORT);
2051 ok(hwnd != NULL, "failed to create a listview window\n");
2053 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2055 for (i = 0; i < 4; i++)
2057 color = colors[i];
2059 r = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, color);
2060 expect(TRUE, r);
2061 r = SendMessageA(hwnd, LVM_GETBKCOLOR, 0, 0);
2062 expect(color, r);
2064 r = SendMessageA(hwnd, LVM_SETTEXTCOLOR, 0, color);
2065 expect (TRUE, r);
2066 r = SendMessageA(hwnd, LVM_GETTEXTCOLOR, 0, 0);
2067 expect(color, r);
2069 r = SendMessageA(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
2070 expect(TRUE, r);
2071 r = SendMessageA(hwnd, LVM_GETTEXTBKCOLOR, 0, 0);
2072 expect(color, r);
2075 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
2076 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2078 /* invalidation test done separately to avoid a message chain mess */
2079 r = ValidateRect(hwnd, NULL);
2080 expect(TRUE, r);
2081 r = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, colors[0]);
2082 expect(TRUE, r);
2084 rect.right = rect.bottom = 1;
2085 r = GetUpdateRect(hwnd, &rect, TRUE);
2086 todo_wine expect(FALSE, r);
2087 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2089 r = ValidateRect(hwnd, NULL);
2090 expect(TRUE, r);
2091 r = SendMessageA(hwnd, LVM_SETTEXTCOLOR, 0, colors[0]);
2092 expect(TRUE, r);
2094 rect.right = rect.bottom = 1;
2095 r = GetUpdateRect(hwnd, &rect, TRUE);
2096 todo_wine expect(FALSE, r);
2097 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2099 r = ValidateRect(hwnd, NULL);
2100 expect(TRUE, r);
2101 r = SendMessageA(hwnd, LVM_SETTEXTBKCOLOR, 0, colors[0]);
2102 expect(TRUE, r);
2104 rect.right = rect.bottom = 1;
2105 r = GetUpdateRect(hwnd, &rect, TRUE);
2106 todo_wine expect(FALSE, r);
2107 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2109 DestroyWindow(hwnd);
2112 static void test_item_count(void)
2114 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
2116 HWND hwnd;
2117 DWORD r;
2118 HDC hdc;
2119 HFONT hOldFont;
2120 TEXTMETRICA tm;
2121 RECT rect;
2122 INT height;
2124 LVITEMA item0;
2125 LVITEMA item1;
2126 LVITEMA item2;
2127 static CHAR item0text[] = "item0";
2128 static CHAR item1text[] = "item1";
2129 static CHAR item2text[] = "item2";
2131 hwnd = create_listview_control(LVS_REPORT);
2132 ok(hwnd != NULL, "failed to create a listview window\n");
2134 /* resize in dpiaware manner to fit all 3 items added */
2135 hdc = GetDC(0);
2136 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
2137 GetTextMetricsA(hdc, &tm);
2138 /* 2 extra pixels for bounds and header border */
2139 height = tm.tmHeight + 2;
2140 SelectObject(hdc, hOldFont);
2141 ReleaseDC(0, hdc);
2143 GetWindowRect(hwnd, &rect);
2144 /* 3 items + 1 header + 1 to be sure */
2145 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
2147 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2149 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2150 expect(0, r);
2152 /* [item0] */
2153 item0.mask = LVIF_TEXT;
2154 item0.iItem = 0;
2155 item0.iSubItem = 0;
2156 item0.pszText = item0text;
2157 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item0);
2158 expect(0, r);
2160 /* [item0, item1] */
2161 item1.mask = LVIF_TEXT;
2162 item1.iItem = 1;
2163 item1.iSubItem = 0;
2164 item1.pszText = item1text;
2165 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2166 expect(1, r);
2168 /* [item0, item1, item2] */
2169 item2.mask = LVIF_TEXT;
2170 item2.iItem = 2;
2171 item2.iSubItem = 0;
2172 item2.pszText = item2text;
2173 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2174 expect(2, r);
2176 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2177 expect(3, r);
2179 /* [item0, item1] */
2180 r = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
2181 expect(TRUE, r);
2183 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2184 expect(2, r);
2186 /* [] */
2187 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
2188 expect(TRUE, r);
2190 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2191 expect(0, r);
2193 /* [item0] */
2194 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2195 expect(0, r);
2197 /* [item0, item1] */
2198 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2199 expect(1, r);
2201 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2202 expect(2, r);
2204 /* [item0, item1, item2] */
2205 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2206 expect(2, r);
2208 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2209 expect(3, r);
2211 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
2213 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2214 DestroyWindow(hwnd);
2217 static void test_item_position(void)
2219 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2221 HWND hwnd;
2222 DWORD r;
2223 POINT position;
2225 LVITEMA item0;
2226 LVITEMA item1;
2227 LVITEMA item2;
2228 static CHAR item0text[] = "item0";
2229 static CHAR item1text[] = "item1";
2230 static CHAR item2text[] = "item2";
2232 hwnd = create_listview_control(LVS_ICON);
2233 ok(hwnd != NULL, "failed to create a listview window\n");
2235 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2237 /* [item0] */
2238 item0.mask = LVIF_TEXT;
2239 item0.iItem = 0;
2240 item0.iSubItem = 0;
2241 item0.pszText = item0text;
2242 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item0);
2243 expect(0, r);
2245 /* [item0, item1] */
2246 item1.mask = LVIF_TEXT;
2247 item1.iItem = 1;
2248 item1.iSubItem = 0;
2249 item1.pszText = item1text;
2250 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2251 expect(1, r);
2253 /* [item0, item1, item2] */
2254 item2.mask = LVIF_TEXT;
2255 item2.iItem = 2;
2256 item2.iSubItem = 0;
2257 item2.pszText = item2text;
2258 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2259 expect(2, r);
2261 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
2262 expect(TRUE, r);
2263 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
2264 expect(TRUE, r);
2265 expect2(10, 5, position.x, position.y);
2267 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
2268 expect(TRUE, r);
2269 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
2270 expect(TRUE, r);
2271 expect2(0, 0, position.x, position.y);
2273 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
2274 expect(TRUE, r);
2275 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
2276 expect(TRUE, r);
2277 expect2(20, 20, position.x, position.y);
2279 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
2281 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2282 DestroyWindow(hwnd);
2285 static void test_getorigin(void)
2287 /* LVM_GETORIGIN */
2289 HWND hwnd;
2290 DWORD r;
2291 POINT position;
2293 position.x = position.y = 0;
2295 hwnd = create_listview_control(LVS_ICON);
2296 ok(hwnd != NULL, "failed to create a listview window\n");
2297 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2299 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2300 expect(TRUE, r);
2301 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2302 DestroyWindow(hwnd);
2304 hwnd = create_listview_control(LVS_SMALLICON);
2305 ok(hwnd != NULL, "failed to create a listview window\n");
2306 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2308 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2309 expect(TRUE, r);
2310 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2311 DestroyWindow(hwnd);
2313 hwnd = create_listview_control(LVS_LIST);
2314 ok(hwnd != NULL, "failed to create a listview window\n");
2315 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2317 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2318 expect(FALSE, r);
2319 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2320 DestroyWindow(hwnd);
2322 hwnd = create_listview_control(LVS_REPORT);
2323 ok(hwnd != NULL, "failed to create a listview window\n");
2324 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2326 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2327 expect(FALSE, r);
2328 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2329 DestroyWindow(hwnd);
2332 static void test_multiselect(void)
2334 typedef struct t_select_task
2336 const char *descr;
2337 int initPos;
2338 int loopVK;
2339 int count;
2340 int result;
2341 } select_task;
2343 HWND hwnd;
2344 INT r;
2345 int i, j;
2346 static const int items=5;
2347 DWORD item_count;
2348 BYTE kstate[256];
2349 select_task task;
2350 LONG_PTR style;
2351 LVITEMA item;
2353 static struct t_select_task task_list[] = {
2354 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
2355 { "using VK_UP", -1, VK_UP, -1, -1 },
2356 { "using VK_END", 0, VK_END, 1, -1 },
2357 { "using VK_HOME", -1, VK_HOME, 1, -1 }
2360 hwnd = create_listview_control(LVS_REPORT);
2362 for (i = 0; i < items; i++)
2363 insert_item(hwnd, 0);
2365 item_count = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2366 expect(items, item_count);
2368 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2369 ok(r == -1, "got %d\n", r);
2371 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, 0);
2372 ok(r == -1, "got %d\n", r);
2374 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, 0);
2375 ok(r == 0, "got %d\n", r);
2377 /* out of range index */
2378 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, items);
2379 ok(r == 0, "got %d\n", r);
2381 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2382 ok(r == 0, "got %d\n", r);
2384 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -2);
2385 ok(r == 0, "got %d\n", r);
2387 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2388 ok(r == 0, "got %d\n", r);
2390 for (i = 0; i < ARRAY_SIZE(task_list); i++) {
2391 DWORD selected_count;
2392 LVITEMA item;
2394 task = task_list[i];
2396 /* deselect all items */
2397 item.state = 0;
2398 item.stateMask = LVIS_SELECTED;
2399 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2400 ok(r, "got %d\n", r);
2401 SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2403 /* set initial position */
2404 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
2405 ok(r, "got %d\n", r);
2407 item.state = LVIS_SELECTED;
2408 item.stateMask = LVIS_SELECTED;
2409 r = SendMessageA(hwnd, LVM_SETITEMSTATE, task.initPos == -1 ? item_count-1 : task.initPos, (LPARAM)&item);
2410 ok(r, "got %d\n", r);
2412 selected_count = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2413 ok(selected_count == 1, "expected 1, got %d\n", selected_count);
2415 /* Set SHIFT key pressed */
2416 GetKeyboardState(kstate);
2417 kstate[VK_SHIFT]=0x80;
2418 SetKeyboardState(kstate);
2420 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
2421 r = SendMessageA(hwnd, WM_KEYDOWN, task.loopVK, 0);
2422 expect(0,r);
2423 r = SendMessageA(hwnd, WM_KEYUP, task.loopVK, 0);
2424 expect(0,r);
2427 selected_count = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2429 ok((task.result == -1 ? item_count : task.result) == selected_count,
2430 "Failed multiple selection %s. There should be %d selected items (is %d)\n",
2431 task.descr, item_count, selected_count);
2433 /* Set SHIFT key released */
2434 GetKeyboardState(kstate);
2435 kstate[VK_SHIFT]=0x00;
2436 SetKeyboardState(kstate);
2438 DestroyWindow(hwnd);
2440 /* make multiple selection, then switch to LVS_SINGLESEL */
2441 hwnd = create_listview_control(LVS_REPORT);
2442 for (i=0;i<items;i++) {
2443 insert_item(hwnd, 0);
2445 item_count = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2446 expect(items,item_count);
2448 /* try with NULL pointer */
2449 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
2450 expect(FALSE, r);
2452 /* select all, check notifications */
2453 item.state = 0;
2454 item.stateMask = LVIS_SELECTED;
2455 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2456 ok(r, "got %d\n", r);
2458 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2460 item.stateMask = LVIS_SELECTED;
2461 item.state = LVIS_SELECTED;
2462 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2463 expect(TRUE, r);
2465 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2466 "select all notification", FALSE);
2468 /* select all again (all selected already) */
2469 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2471 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2473 item.stateMask = LVIS_SELECTED;
2474 item.state = LVIS_SELECTED;
2475 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2476 expect(TRUE, r);
2478 ok(g_nmlistview_changing.uNewState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uNewState);
2479 ok(g_nmlistview_changing.uOldState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uOldState);
2480 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2482 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2483 "select all notification 2", FALSE);
2485 /* deselect all items */
2486 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2488 item.state = 0;
2489 item.stateMask = LVIS_SELECTED;
2490 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2491 ok(r, "got %d\n", r);
2493 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2494 "deselect all notification", FALSE);
2496 /* deselect all items again */
2497 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2498 item.state = 0;
2499 item.stateMask = LVIS_SELECTED;
2500 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2501 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "deselect all notification 2", FALSE);
2503 /* any non-zero state value does the same */
2504 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2506 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2508 item.stateMask = LVIS_SELECTED;
2509 item.state = LVIS_CUT;
2510 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2511 expect(TRUE, r);
2513 ok(g_nmlistview_changing.uNewState == 0, "got 0x%x\n", g_nmlistview_changing.uNewState);
2514 ok(g_nmlistview_changing.uOldState == 0, "got 0x%x\n", g_nmlistview_changing.uOldState);
2515 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2517 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2518 "set state all notification 3", FALSE);
2520 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2521 ok(r, "got %d\n", r);
2522 for (i = 0; i < 3; i++) {
2523 item.state = LVIS_SELECTED;
2524 item.stateMask = LVIS_SELECTED;
2525 r = SendMessageA(hwnd, LVM_SETITEMSTATE, i, (LPARAM)&item);
2526 ok(r, "got %d\n", r);
2529 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2530 expect(3, r);
2531 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2532 expect(-1, r);
2534 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2535 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2536 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2537 /* check that style is accepted */
2538 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2539 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2541 for (i=0;i<3;i++) {
2542 r = SendMessageA(hwnd, LVM_GETITEMSTATE, i, LVIS_SELECTED);
2543 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2545 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2546 expect(3, r);
2547 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2548 ok(r == -1, "got %d\n", r);
2550 /* select one more */
2551 item.state = LVIS_SELECTED;
2552 item.stateMask = LVIS_SELECTED;
2553 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
2554 ok(r, "got %d\n", r);
2556 for (i=0;i<3;i++) {
2557 r = SendMessageA(hwnd, LVM_GETITEMSTATE, i, LVIS_SELECTED);
2558 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2561 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 3, LVIS_SELECTED);
2562 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2564 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2565 expect(1, r);
2566 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2567 expect(-1, r);
2569 /* try to select all on LVS_SINGLESEL */
2570 memset(&item, 0, sizeof(item));
2571 item.stateMask = LVIS_SELECTED;
2572 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2573 expect(TRUE, r);
2574 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2575 ok(r == -1, "got %d\n", r);
2577 item.stateMask = LVIS_SELECTED;
2578 item.state = LVIS_SELECTED;
2579 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2580 expect(FALSE, r);
2582 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2583 expect(0, r);
2584 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2585 expect(-1, r);
2587 /* try to deselect all on LVS_SINGLESEL */
2588 item.stateMask = LVIS_SELECTED;
2589 item.state = LVIS_SELECTED;
2590 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2591 expect(TRUE, r);
2593 item.stateMask = LVIS_SELECTED;
2594 item.state = 0;
2595 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2596 expect(TRUE, r);
2597 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2598 expect(0, r);
2600 /* 1. selection mark is update when new focused item is set */
2601 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2602 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2604 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2605 expect(-1, r);
2607 item.stateMask = LVIS_FOCUSED;
2608 item.state = LVIS_FOCUSED;
2609 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2610 expect(TRUE, r);
2612 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2613 expect(0, r);
2615 /* it's not updated if already set */
2616 item.stateMask = LVIS_FOCUSED;
2617 item.state = LVIS_FOCUSED;
2618 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2619 expect(TRUE, r);
2621 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2622 expect(0, r);
2624 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2625 expect(0, r);
2627 item.stateMask = LVIS_FOCUSED;
2628 item.state = LVIS_FOCUSED;
2629 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2630 expect(TRUE, r);
2632 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2633 expect(-1, r);
2635 /* need to reset focused item first */
2636 item.stateMask = LVIS_FOCUSED;
2637 item.state = 0;
2638 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2639 expect(TRUE, r);
2641 item.stateMask = LVIS_FOCUSED;
2642 item.state = LVIS_FOCUSED;
2643 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
2644 expect(TRUE, r);
2646 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2647 expect(2, r);
2649 item.stateMask = LVIS_FOCUSED;
2650 item.state = 0;
2651 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2652 expect(TRUE, r);
2654 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2655 expect(2, r);
2657 /* 2. same tests, with LVM_SETITEM */
2658 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2659 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2661 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2662 expect(2, r);
2664 item.stateMask = LVIS_FOCUSED;
2665 item.state = LVIS_FOCUSED;
2666 item.mask = LVIF_STATE;
2667 item.iItem = item.iSubItem = 0;
2668 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2669 expect(TRUE, r);
2671 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2672 expect(0, r);
2674 /* it's not updated if already set */
2675 item.stateMask = LVIS_FOCUSED;
2676 item.state = LVIS_FOCUSED;
2677 item.mask = LVIF_STATE;
2678 item.iItem = 1;
2679 item.iSubItem = 0;
2680 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2681 expect(TRUE, r);
2683 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2684 expect(0, r);
2686 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2687 expect(0, r);
2689 item.stateMask = LVIS_FOCUSED;
2690 item.state = LVIS_FOCUSED;
2691 item.mask = LVIF_STATE;
2692 item.iItem = 1;
2693 item.iSubItem = 0;
2694 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2695 expect(TRUE, r);
2697 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2698 expect(-1, r);
2700 /* need to reset focused item first */
2701 item.stateMask = LVIS_FOCUSED;
2702 item.state = 0;
2703 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2704 expect(TRUE, r);
2706 item.stateMask = LVIS_FOCUSED;
2707 item.state = LVIS_FOCUSED;
2708 item.mask = LVIF_STATE;
2709 item.iItem = 2;
2710 item.iSubItem = 0;
2711 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2712 expect(TRUE, r);
2714 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2715 expect(2, r);
2717 item.stateMask = LVIS_FOCUSED;
2718 item.state = 0;
2719 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2720 expect(TRUE, r);
2722 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2723 expect(2, r);
2725 DestroyWindow(hwnd);
2728 static void test_subitem_rect(void)
2730 HWND hwnd;
2731 DWORD r;
2732 LVCOLUMNA col;
2733 RECT rect, rect2;
2734 INT arr[3];
2736 /* test LVM_GETSUBITEMRECT for header */
2737 hwnd = create_listview_control(LVS_REPORT);
2738 ok(hwnd != NULL, "failed to create a listview window\n");
2739 /* add some columns */
2740 memset(&col, 0, sizeof(LVCOLUMNA));
2741 col.mask = LVCF_WIDTH;
2742 col.cx = 100;
2743 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
2744 expect(0, r);
2745 col.cx = 150;
2746 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&col);
2747 expect(1, r);
2748 col.cx = 200;
2749 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 2, (LPARAM)&col);
2750 expect(2, r);
2751 /* item = -1 means header, subitem index is 1 based */
2752 SetRect(&rect, LVIR_BOUNDS, 0, 0, 0);
2753 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2754 expect(0, r);
2756 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2757 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2758 expect(1, r);
2760 expect(100, rect.left);
2761 expect(250, rect.right);
2762 expect(3, rect.top);
2764 SetRect(&rect, LVIR_BOUNDS, 2, 0, 0);
2765 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2766 expect(1, r);
2768 expect(250, rect.left);
2769 expect(450, rect.right);
2770 expect(3, rect.top);
2772 /* item LVS_REPORT padding isn't applied to subitems */
2773 insert_item(hwnd, 0);
2775 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2776 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2777 expect(1, r);
2778 expect(100, rect.left);
2779 expect(250, rect.right);
2781 SetRect(&rect, LVIR_ICON, 1, 0, 0);
2782 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2783 expect(1, r);
2784 /* no icon attached - zero width rectangle, with no left padding */
2785 expect(100, rect.left);
2786 expect(100, rect.right);
2788 SetRect(&rect, LVIR_LABEL, 1, 0, 0);
2789 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2790 expect(1, r);
2791 /* same as full LVIR_BOUNDS */
2792 expect(100, rect.left);
2793 expect(250, rect.right);
2795 r = SendMessageA(hwnd, LVM_SCROLL, 10, 0);
2796 ok(r, "got %d\n", r);
2798 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2799 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2800 expect(1, r);
2801 expect(90, rect.left);
2802 expect(240, rect.right);
2804 SendMessageA(hwnd, LVM_SCROLL, -10, 0);
2806 /* test header interaction */
2807 subclass_header(hwnd);
2808 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2810 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2811 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2812 expect(1, r);
2814 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2815 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2816 expect(1, r);
2818 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2819 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -10, (LPARAM)&rect);
2820 expect(1, r);
2822 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2823 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 20, (LPARAM)&rect);
2824 expect(1, r);
2826 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getsubitemrect_seq, "LVM_GETSUBITEMRECT negative index", FALSE);
2828 DestroyWindow(hwnd);
2830 /* test subitem rects after re-arranging columns */
2831 hwnd = create_listview_control(LVS_REPORT);
2832 ok(hwnd != NULL, "failed to create a listview window\n");
2833 memset(&col, 0, sizeof(LVCOLUMNA));
2834 col.mask = LVCF_WIDTH;
2836 col.cx = 100;
2837 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
2838 expect(0, r);
2840 col.cx = 200;
2841 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&col);
2842 expect(1, r);
2844 col.cx = 300;
2845 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 2, (LPARAM)&col);
2846 expect(2, r);
2848 insert_item(hwnd, 0);
2849 insert_item(hwnd, 1);
2851 /* wrong item is refused for main item */
2852 SetRect(&rect, LVIR_BOUNDS, 0, -1, -1);
2853 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect);
2854 expect(FALSE, r);
2856 /* for subitems rectangle is calculated even if there's no item added */
2857 SetRect(&rect, LVIR_BOUNDS, 1, -1, -1);
2858 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect);
2859 expect(TRUE, r);
2861 SetRect(&rect2, LVIR_BOUNDS, 1, -1, -1);
2862 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect2);
2863 expect(TRUE, r);
2864 expect(rect.right, rect2.right);
2865 expect(rect.left, rect2.left);
2866 expect(rect.bottom, rect2.top);
2867 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2869 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2870 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2871 expect(TRUE, r);
2873 SetRect(&rect, LVIR_BOUNDS, 0, -1, -1);
2874 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2875 expect(TRUE, r);
2876 expect(0, rect.left);
2877 expect(600, rect.right);
2879 SetRect(&rect, LVIR_BOUNDS, 1, -1, -1);
2880 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2881 expect(TRUE, r);
2882 expect(0, rect.left);
2883 expect(200, rect.right);
2885 SetRect(&rect2, LVIR_BOUNDS, 1, -1, -1);
2886 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect2);
2887 expect(TRUE, r);
2888 expect(0, rect2.left);
2889 expect(200, rect2.right);
2890 /* items are of the same height */
2891 ok(rect2.top > 0, "expected positive item height\n");
2892 expect(rect.bottom, rect2.top);
2893 expect(rect.bottom * 2 - rect.top, rect2.bottom);
2895 SetRect(&rect, LVIR_BOUNDS, 2, -1, -1);
2896 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2897 expect(TRUE, r);
2898 expect(300, rect.left);
2899 expect(600, rect.right);
2901 DestroyWindow(hwnd);
2903 /* try it for non LVS_REPORT style */
2904 hwnd = CreateWindowA(WC_LISTVIEWA, "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2905 GetModuleHandleA(NULL), 0);
2906 SetRect(&rect, LVIR_BOUNDS, 1, -10, -10);
2907 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2908 expect(0, r);
2909 /* rect is unchanged */
2910 expect(0, rect.left);
2911 expect(-10, rect.right);
2912 expect(1, rect.top);
2913 expect(-10, rect.bottom);
2914 DestroyWindow(hwnd);
2917 /* comparison callback for test_sorting */
2918 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2920 if (first == second) return 0;
2921 return (first > second ? 1 : -1);
2924 static void test_sorting(void)
2926 HWND hwnd;
2927 LVITEMA item = {0};
2928 INT r;
2929 LONG_PTR style;
2930 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2931 CHAR buff[10];
2933 hwnd = create_listview_control(LVS_REPORT);
2934 ok(hwnd != NULL, "failed to create a listview window\n");
2936 /* insert some items */
2937 item.mask = LVIF_PARAM | LVIF_STATE;
2938 item.state = LVIS_SELECTED;
2939 item.iItem = 0;
2940 item.iSubItem = 0;
2941 item.lParam = 3;
2942 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2943 expect(0, r);
2945 item.mask = LVIF_PARAM;
2946 item.iItem = 1;
2947 item.iSubItem = 0;
2948 item.lParam = 2;
2949 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2950 expect(1, r);
2952 item.mask = LVIF_STATE | LVIF_PARAM;
2953 item.state = LVIS_SELECTED;
2954 item.iItem = 2;
2955 item.iSubItem = 0;
2956 item.lParam = 4;
2957 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2958 expect(2, r);
2960 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2961 expect(-1, r);
2963 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2964 expect(2, r);
2966 r = SendMessageA(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2967 expect(TRUE, r);
2969 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2970 expect(2, r);
2971 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2972 expect(-1, r);
2973 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2974 expect(0, r);
2975 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2976 expect(LVIS_SELECTED, r);
2977 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2978 expect(LVIS_SELECTED, r);
2980 DestroyWindow(hwnd);
2982 /* switch to LVS_SORTASCENDING when some items added */
2983 hwnd = create_listview_control(LVS_REPORT);
2984 ok(hwnd != NULL, "failed to create a listview window\n");
2986 item.mask = LVIF_TEXT;
2987 item.iItem = 0;
2988 item.iSubItem = 0;
2989 item.pszText = names[1];
2990 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2991 expect(0, r);
2993 item.mask = LVIF_TEXT;
2994 item.iItem = 1;
2995 item.iSubItem = 0;
2996 item.pszText = names[2];
2997 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2998 expect(1, r);
3000 item.mask = LVIF_TEXT;
3001 item.iItem = 2;
3002 item.iSubItem = 0;
3003 item.pszText = names[0];
3004 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
3005 expect(2, r);
3007 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3008 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
3009 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3010 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3012 /* no sorting performed when switched to LVS_SORTASCENDING */
3013 item.mask = LVIF_TEXT;
3014 item.iItem = 0;
3015 item.pszText = buff;
3016 item.cchTextMax = sizeof(buff);
3017 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3018 expect(TRUE, r);
3019 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
3021 item.iItem = 1;
3022 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3023 expect(TRUE, r);
3024 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
3026 item.iItem = 2;
3027 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3028 expect(TRUE, r);
3029 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
3031 /* adding new item doesn't resort list */
3032 item.mask = LVIF_TEXT;
3033 item.iItem = 3;
3034 item.iSubItem = 0;
3035 item.pszText = names[3];
3036 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
3037 expect(3, r);
3039 item.mask = LVIF_TEXT;
3040 item.iItem = 0;
3041 item.pszText = buff;
3042 item.cchTextMax = sizeof(buff);
3043 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3044 expect(TRUE, r);
3045 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
3047 item.iItem = 1;
3048 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3049 expect(TRUE, r);
3050 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
3052 item.iItem = 2;
3053 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3054 expect(TRUE, r);
3055 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
3057 item.iItem = 3;
3058 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3059 expect(TRUE, r);
3060 ok(lstrcmpA(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
3062 /* corner case - item should be placed at first position */
3063 item.mask = LVIF_TEXT;
3064 item.iItem = 4;
3065 item.iSubItem = 0;
3066 item.pszText = names[4];
3067 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
3068 expect(0, r);
3070 item.iItem = 0;
3071 item.pszText = buff;
3072 item.cchTextMax = sizeof(buff);
3073 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3074 expect(TRUE, r);
3075 ok(lstrcmpA(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
3077 item.iItem = 1;
3078 item.pszText = buff;
3079 item.cchTextMax = sizeof(buff);
3080 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3081 expect(TRUE, r);
3082 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
3084 item.iItem = 2;
3085 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3086 expect(TRUE, r);
3087 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
3089 item.iItem = 3;
3090 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3091 expect(TRUE, r);
3092 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
3094 item.iItem = 4;
3095 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
3096 expect(TRUE, r);
3097 ok(lstrcmpA(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
3099 DestroyWindow(hwnd);
3102 static void test_ownerdata(void)
3104 static char test_str[] = "test";
3106 HWND hwnd;
3107 LONG_PTR style, ret;
3108 DWORD res;
3109 LVITEMA item;
3111 /* Setting LVS_OWNERDATA after creation leads to crash on older versions < 5.80 */
3112 hwnd = create_listview_control(LVS_REPORT);
3113 ok(hwnd != NULL, "failed to create a listview window\n");
3114 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3115 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
3117 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3119 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
3120 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
3121 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
3122 "try to switch to LVS_OWNERDATA seq", FALSE);
3124 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3125 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
3126 DestroyWindow(hwnd);
3128 /* try to set LVS_OWNERDATA after creation just having it */
3129 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3130 ok(hwnd != NULL, "failed to create a listview window\n");
3131 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3132 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
3134 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3136 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
3137 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
3138 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
3139 "try to switch to LVS_OWNERDATA seq", FALSE);
3140 DestroyWindow(hwnd);
3142 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3143 ok(hwnd != NULL, "failed to create a listview window\n");
3144 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3145 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
3147 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3149 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
3150 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
3151 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
3152 "try to switch to LVS_OWNERDATA seq", FALSE);
3153 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3154 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
3155 DestroyWindow(hwnd);
3157 /* try select an item */
3158 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3159 ok(hwnd != NULL, "failed to create a listview window\n");
3160 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3161 expect(1, res);
3162 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
3163 expect(0, res);
3164 memset(&item, 0, sizeof(item));
3165 item.stateMask = LVIS_SELECTED;
3166 item.state = LVIS_SELECTED;
3167 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3168 expect(TRUE, res);
3169 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
3170 expect(1, res);
3171 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
3172 expect(1, res);
3173 DestroyWindow(hwnd);
3175 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
3176 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3177 ok(hwnd != NULL, "failed to create a listview window\n");
3178 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3179 expect(1, res);
3180 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
3181 expect(1, res);
3182 memset(&item, 0, sizeof(item));
3183 item.mask = LVIF_STATE;
3184 item.iItem = 0;
3185 item.stateMask = LVIS_SELECTED;
3186 item.state = LVIS_SELECTED;
3187 res = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3188 expect(FALSE, res);
3189 memset(&item, 0, sizeof(item));
3190 item.pszText = test_str;
3191 res = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3192 expect(FALSE, res);
3193 DestroyWindow(hwnd);
3195 /* check notifications after focused/selected changed */
3196 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3197 ok(hwnd != NULL, "failed to create a listview window\n");
3198 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
3199 expect(1, res);
3201 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3203 memset(&item, 0, sizeof(item));
3204 item.stateMask = LVIS_SELECTED;
3205 item.state = LVIS_SELECTED;
3206 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3207 expect(TRUE, res);
3209 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_select_focus_parent_seq,
3210 "ownerdata select notification", TRUE);
3212 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3214 memset(&item, 0, sizeof(item));
3215 item.stateMask = LVIS_FOCUSED;
3216 item.state = LVIS_FOCUSED;
3217 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3218 expect(TRUE, res);
3220 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_select_focus_parent_seq,
3221 "ownerdata focus notification", TRUE);
3223 /* select all, check notifications */
3224 item.stateMask = LVIS_SELECTED;
3225 item.state = 0;
3226 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3227 expect(TRUE, res);
3229 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3231 item.stateMask = LVIS_SELECTED;
3232 item.state = LVIS_SELECTED;
3234 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3235 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3236 expect(TRUE, res);
3237 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3238 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3239 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3240 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3241 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3242 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3243 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3245 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3246 "ownerdata select all notification", FALSE);
3248 /* select all again, note that all items are selected already */
3249 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3250 item.stateMask = LVIS_SELECTED;
3251 item.state = LVIS_SELECTED;
3253 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3254 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3255 expect(TRUE, res);
3256 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3257 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3258 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3259 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3260 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3261 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3262 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3264 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3265 "ownerdata select all notification", FALSE);
3267 /* deselect all */
3268 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3269 item.stateMask = LVIS_SELECTED;
3270 item.state = 0;
3272 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3273 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3274 expect(TRUE, res);
3275 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3276 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3277 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3278 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3279 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3280 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3281 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3283 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3284 "ownerdata deselect all notification", TRUE);
3286 /* nothing selected, deselect all again */
3287 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3288 item.stateMask = LVIS_SELECTED;
3289 item.state = 0;
3291 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3292 expect(TRUE, res);
3294 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "ownerdata deselect all notification", FALSE);
3296 /* select one, then deselect all */
3297 item.stateMask = LVIS_SELECTED;
3298 item.state = LVIS_SELECTED;
3299 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3300 expect(TRUE, res);
3301 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3302 item.stateMask = LVIS_SELECTED;
3303 item.state = 0;
3305 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3306 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3307 expect(TRUE, res);
3308 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3309 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3310 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3311 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3312 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3313 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3314 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3316 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3317 "ownerdata select all notification", TRUE);
3319 /* remove focused, try to focus all */
3320 item.stateMask = LVIS_FOCUSED;
3321 item.state = LVIS_FOCUSED;
3322 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3323 expect(TRUE, res);
3324 item.stateMask = LVIS_FOCUSED;
3325 item.state = 0;
3326 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3327 expect(TRUE, res);
3328 item.stateMask = LVIS_FOCUSED;
3329 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
3330 expect(0, res);
3332 /* setting all to focused returns failure value */
3333 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3334 item.stateMask = LVIS_FOCUSED;
3335 item.state = LVIS_FOCUSED;
3337 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3338 expect(FALSE, res);
3340 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3341 "ownerdata focus all notification", FALSE);
3343 /* focus single item, remove all */
3344 item.stateMask = LVIS_FOCUSED;
3345 item.state = LVIS_FOCUSED;
3346 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3347 expect(TRUE, res);
3348 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3349 item.stateMask = LVIS_FOCUSED;
3350 item.state = 0;
3352 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3353 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3354 expect(TRUE, res);
3355 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3356 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3357 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3358 ok(g_nmlistview.uOldState == LVIS_FOCUSED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3359 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3360 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3361 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3363 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
3364 "ownerdata remove focus all notification", TRUE);
3366 /* set all cut */
3367 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3368 item.stateMask = LVIS_CUT;
3369 item.state = LVIS_CUT;
3371 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3372 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3373 expect(TRUE, res);
3374 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3375 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3376 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3377 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3378 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3379 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3380 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3382 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3383 "ownerdata cut all notification", FALSE);
3385 /* all marked cut, try again */
3386 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3387 item.stateMask = LVIS_CUT;
3388 item.state = LVIS_CUT;
3390 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3391 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3392 expect(TRUE, res);
3393 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3394 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3395 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3396 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3397 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3398 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3399 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3401 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3402 "ownerdata cut all notification #2", FALSE);
3404 DestroyWindow(hwnd);
3406 /* check notifications on LVM_GETITEM */
3407 /* zero callback mask */
3408 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3409 ok(hwnd != NULL, "failed to create a listview window\n");
3410 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3411 expect(1, res);
3413 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3415 memset(&item, 0, sizeof(item));
3416 item.stateMask = LVIS_SELECTED;
3417 item.mask = LVIF_STATE;
3418 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3419 expect(TRUE, res);
3421 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3422 "ownerdata getitem selected state 1", FALSE);
3424 /* non zero callback mask but not we asking for */
3425 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
3426 expect(TRUE, res);
3428 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3430 memset(&item, 0, sizeof(item));
3431 item.stateMask = LVIS_SELECTED;
3432 item.mask = LVIF_STATE;
3433 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3434 expect(TRUE, res);
3436 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3437 "ownerdata getitem selected state 2", FALSE);
3439 /* LVIS_OVERLAYMASK callback mask, asking for index */
3440 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3442 memset(&item, 0, sizeof(item));
3443 item.stateMask = LVIS_OVERLAYMASK;
3444 item.mask = LVIF_STATE;
3445 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3446 expect(TRUE, res);
3448 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3449 "ownerdata getitem selected state 2", FALSE);
3451 DestroyWindow(hwnd);
3453 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3454 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
3455 ok(hwnd != NULL, "failed to create a listview window\n");
3456 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3457 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3458 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3459 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
3460 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3461 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
3462 DestroyWindow(hwnd);
3463 /* apparently it's allowed to switch these style on after creation */
3464 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3465 ok(hwnd != NULL, "failed to create a listview window\n");
3466 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3467 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3468 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
3469 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3470 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3471 DestroyWindow(hwnd);
3473 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3474 ok(hwnd != NULL, "failed to create a listview window\n");
3475 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3476 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3477 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
3478 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3479 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
3480 DestroyWindow(hwnd);
3482 /* The focused item is updated after the invalidation */
3483 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3484 ok(hwnd != NULL, "failed to create a listview window\n");
3485 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 3, 0);
3486 expect(TRUE, res);
3488 memset(&item, 0, sizeof(item));
3489 item.stateMask = LVIS_FOCUSED;
3490 item.state = LVIS_FOCUSED;
3491 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3492 expect(TRUE, res);
3494 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3495 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 0, 0);
3496 expect(TRUE, res);
3497 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3498 "ownerdata setitemcount", FALSE);
3500 res = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
3501 expect(-1, res);
3502 DestroyWindow(hwnd);
3505 static void test_norecompute(void)
3507 static CHAR testA[] = "test";
3508 CHAR buff[10];
3509 LVITEMA item;
3510 HWND hwnd;
3511 DWORD res;
3513 /* self containing control */
3514 hwnd = create_listview_control(LVS_REPORT);
3515 ok(hwnd != NULL, "failed to create a listview window\n");
3516 memset(&item, 0, sizeof(item));
3517 item.mask = LVIF_TEXT | LVIF_STATE;
3518 item.iItem = 0;
3519 item.stateMask = LVIS_SELECTED;
3520 item.state = LVIS_SELECTED;
3521 item.pszText = testA;
3522 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3523 expect(0, res);
3524 /* retrieve with LVIF_NORECOMPUTE */
3525 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3526 item.iItem = 0;
3527 item.pszText = buff;
3528 item.cchTextMax = ARRAY_SIZE(buff);
3529 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3530 expect(TRUE, res);
3531 ok(lstrcmpA(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
3533 item.mask = LVIF_TEXT;
3534 item.iItem = 1;
3535 item.pszText = LPSTR_TEXTCALLBACKA;
3536 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3537 expect(1, res);
3539 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3540 item.iItem = 1;
3541 item.pszText = buff;
3542 item.cchTextMax = ARRAY_SIZE(buff);
3544 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3545 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3546 expect(TRUE, res);
3547 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3548 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3549 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
3551 DestroyWindow(hwnd);
3553 /* LVS_OWNERDATA */
3554 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3555 ok(hwnd != NULL, "failed to create a listview window\n");
3557 item.mask = LVIF_STATE;
3558 item.stateMask = LVIS_SELECTED;
3559 item.state = LVIS_SELECTED;
3560 item.iItem = 0;
3561 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3562 expect(0, res);
3564 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3565 item.iItem = 0;
3566 item.pszText = buff;
3567 item.cchTextMax = ARRAY_SIZE(buff);
3568 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3569 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3570 expect(TRUE, res);
3571 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3572 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3573 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
3575 DestroyWindow(hwnd);
3578 static void test_nosortheader(void)
3580 HWND hwnd, header;
3581 LONG_PTR style;
3583 hwnd = create_listview_control(LVS_REPORT);
3584 ok(hwnd != NULL, "failed to create a listview window\n");
3586 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3587 ok(IsWindow(header), "header expected\n");
3589 style = GetWindowLongPtrA(header, GWL_STYLE);
3590 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
3592 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3593 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
3594 /* HDS_BUTTONS retained */
3595 style = GetWindowLongPtrA(header, GWL_STYLE);
3596 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
3598 DestroyWindow(hwnd);
3600 /* create with LVS_NOSORTHEADER */
3601 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
3602 ok(hwnd != NULL, "failed to create a listview window\n");
3604 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3605 ok(IsWindow(header), "header expected\n");
3607 style = GetWindowLongPtrA(header, GWL_STYLE);
3608 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3610 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3611 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
3612 /* not changed here */
3613 style = GetWindowLongPtrA(header, GWL_STYLE);
3614 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3616 DestroyWindow(hwnd);
3619 static void test_setredraw(void)
3621 HWND hwnd;
3622 DWORD_PTR style;
3623 DWORD ret;
3624 HDC hdc;
3625 RECT rect;
3627 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3628 ok(hwnd != NULL, "failed to create a listview window\n");
3630 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3631 ListView seems to handle it internally without DefWinProc */
3633 /* default value first */
3634 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3635 expect(0, ret);
3636 /* disable */
3637 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3638 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3639 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3640 expect(0, ret);
3641 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3642 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3643 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3644 expect(0, ret);
3646 /* check update rect after redrawing */
3647 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3648 expect(0, ret);
3649 InvalidateRect(hwnd, NULL, FALSE);
3650 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
3651 rect.right = rect.bottom = 1;
3652 GetUpdateRect(hwnd, &rect, FALSE);
3653 expect(0, rect.right);
3654 expect(0, rect.bottom);
3656 /* WM_ERASEBKGND */
3657 hdc = GetWindowDC(hwndparent);
3658 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3659 expect(TRUE, ret);
3660 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3661 expect(0, ret);
3662 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3663 expect(TRUE, ret);
3664 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3665 expect(0, ret);
3666 ReleaseDC(hwndparent, hdc);
3668 /* check notification messages to show that repainting is disabled */
3669 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3670 expect(TRUE, ret);
3671 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3672 expect(0, ret);
3673 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3675 InvalidateRect(hwnd, NULL, TRUE);
3676 UpdateWindow(hwnd);
3677 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3678 "redraw after WM_SETREDRAW (FALSE)", FALSE);
3680 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3681 expect(TRUE, ret);
3682 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3683 InvalidateRect(hwnd, NULL, TRUE);
3684 UpdateWindow(hwnd);
3685 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3686 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3688 /* message isn't forwarded to header */
3689 subclass_header(hwnd);
3690 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3691 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3692 expect(0, ret);
3693 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3694 "WM_SETREDRAW: not forwarded to header", FALSE);
3696 DestroyWindow(hwnd);
3699 static void test_hittest(void)
3701 HWND hwnd;
3702 DWORD r;
3703 RECT bounds;
3704 LVITEMA item;
3705 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3706 POINT pos;
3707 INT x, y, i;
3708 WORD vert;
3709 HIMAGELIST himl, himl2;
3710 HBITMAP hbmp;
3712 hwnd = create_listview_control(LVS_REPORT);
3713 ok(hwnd != NULL, "failed to create a listview window\n");
3715 /* LVS_REPORT with a single subitem (2 columns) */
3716 insert_column(hwnd, 0);
3717 insert_column(hwnd, 1);
3718 insert_item(hwnd, 0);
3720 item.iSubItem = 0;
3721 /* the only purpose of that line is to be as long as a half item rect */
3722 item.pszText = text;
3723 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3724 expect(TRUE, r);
3726 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3727 expect(TRUE, r);
3728 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3729 expect(TRUE, r);
3731 SetRect(&bounds, LVIR_BOUNDS, 0, 0, 0);
3732 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3733 expect(1, r);
3734 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3735 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3736 r = SendMessageA(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3737 vert = HIWORD(r);
3738 ok(bounds.bottom - bounds.top == vert,
3739 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3740 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3741 expect(TRUE, r);
3743 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3745 /* outside columns by x position - valid is [0, 199] */
3746 x = -1;
3747 y = pos.y + (bounds.bottom - bounds.top) / 2;
3748 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3749 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3751 x = pos.x + 50; /* column half width */
3752 y = pos.y + (bounds.bottom - bounds.top) / 2;
3753 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3754 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3755 x = pos.x + 150; /* outside column */
3756 y = pos.y + (bounds.bottom - bounds.top) / 2;
3757 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3758 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3759 y = (bounds.bottom - bounds.top) / 2;
3760 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3761 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3762 /* outside possible client rectangle (to right) */
3763 x = pos.x + 500;
3764 y = pos.y + (bounds.bottom - bounds.top) / 2;
3765 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3766 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3767 y = (bounds.bottom - bounds.top) / 2;
3768 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3769 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3770 /* subitem returned with -1 item too */
3771 x = pos.x + 150;
3772 y = bounds.top - vert;
3773 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3774 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3775 /* return values appear to underflow with negative indices */
3776 i = -2;
3777 y = y - vert;
3778 while (i > -10) {
3779 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3780 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3781 y = y - vert;
3782 i--;
3784 /* parent client area is 100x100 by default */
3785 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3786 x = pos.x + 150; /* outside column */
3787 y = pos.y + (bounds.bottom - bounds.top) / 2;
3788 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3789 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3790 y = (bounds.bottom - bounds.top) / 2;
3791 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3792 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3793 /* the same with LVS_EX_FULLROWSELECT */
3794 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3795 x = pos.x + 150; /* outside column */
3796 y = pos.y + (bounds.bottom - bounds.top) / 2;
3797 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3798 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3799 y = (bounds.bottom - bounds.top) / 2;
3800 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3801 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3802 x = pos.x + 150; /* outside column */
3803 y = pos.y + (bounds.bottom - bounds.top) / 2;
3804 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3805 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3806 y = (bounds.bottom - bounds.top) / 2;
3807 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3808 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3809 /* outside possible client rectangle (to right) */
3810 x = pos.x + 500;
3811 y = pos.y + (bounds.bottom - bounds.top) / 2;
3812 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3813 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3814 y = (bounds.bottom - bounds.top) / 2;
3815 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3816 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3817 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3818 himl = pImageList_Create(16, 16, 0, 4, 4);
3819 ok(himl != NULL, "failed to create imagelist\n");
3820 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3821 ok(hbmp != NULL, "failed to create bitmap\n");
3822 r = pImageList_Add(himl, hbmp, 0);
3823 ok(r == 0, "should be zero\n");
3824 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3825 ok(hbmp != NULL, "failed to create bitmap\n");
3826 r = pImageList_Add(himl, hbmp, 0);
3827 ok(r == 1, "should be one\n");
3829 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3830 expect(0, r);
3832 item.mask = LVIF_IMAGE;
3833 item.iImage = 0;
3834 item.iItem = 0;
3835 item.iSubItem = 0;
3836 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3837 expect(TRUE, r);
3838 /* on state icon */
3839 x = pos.x + 8;
3840 y = pos.y + (bounds.bottom - bounds.top) / 2;
3841 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3842 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3843 y = (bounds.bottom - bounds.top) / 2;
3844 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3846 /* state icons indices are 1 based, check with valid index */
3847 item.mask = LVIF_STATE;
3848 item.state = INDEXTOSTATEIMAGEMASK(1);
3849 item.stateMask = LVIS_STATEIMAGEMASK;
3850 item.iItem = 0;
3851 item.iSubItem = 0;
3852 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3853 expect(TRUE, r);
3854 /* on state icon */
3855 x = pos.x + 8;
3856 y = pos.y + (bounds.bottom - bounds.top) / 2;
3857 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3858 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3859 y = (bounds.bottom - bounds.top) / 2;
3860 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3862 himl2 = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3863 ok(himl2 == himl, "should return handle\n");
3865 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3866 expect(0, r);
3867 /* on item icon */
3868 x = pos.x + 8;
3869 y = pos.y + (bounds.bottom - bounds.top) / 2;
3870 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3871 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3872 y = (bounds.bottom - bounds.top) / 2;
3873 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3875 DestroyWindow(hwnd);
3878 static void test_getviewrect(void)
3880 HWND hwnd;
3881 DWORD r;
3882 RECT rect;
3883 LVITEMA item;
3885 hwnd = create_listview_control(LVS_REPORT);
3886 ok(hwnd != NULL, "failed to create a listview window\n");
3888 /* empty */
3889 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3890 expect(TRUE, r);
3892 insert_column(hwnd, 0);
3893 insert_column(hwnd, 1);
3895 memset(&item, 0, sizeof(item));
3896 item.iItem = 0;
3897 item.iSubItem = 0;
3898 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3899 ok(!r, "got %d\n", r);
3901 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3902 expect(TRUE, r);
3903 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3904 expect(TRUE, r);
3906 SetRect(&rect, -1, -1, -1, -1);
3907 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3908 expect(TRUE, r);
3909 /* left is set to (2e31-1) - XP SP2 */
3910 expect(0, rect.right);
3911 expect(0, rect.top);
3912 expect(0, rect.bottom);
3914 /* switch to LVS_ICON */
3915 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_REPORT);
3917 SetRect(&rect, -1, -1, -1, -1);
3918 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3919 expect(TRUE, r);
3920 expect(0, rect.left);
3921 expect(0, rect.top);
3922 /* precise value differs for 2k, XP and Vista */
3923 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3924 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3926 DestroyWindow(hwnd);
3929 static void test_getitemposition(void)
3931 HWND hwnd, header;
3932 DWORD r;
3933 POINT pt;
3934 RECT rect;
3936 hwnd = create_listview_control(LVS_REPORT);
3937 ok(hwnd != NULL, "failed to create a listview window\n");
3938 header = subclass_header(hwnd);
3940 /* LVS_REPORT, single item, no columns added */
3941 insert_item(hwnd, 0);
3943 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3945 pt.x = pt.y = -1;
3946 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3947 expect(TRUE, r);
3948 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3950 /* LVS_REPORT, single item, single column */
3951 insert_column(hwnd, 0);
3953 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3955 pt.x = pt.y = -1;
3956 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3957 expect(TRUE, r);
3958 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3960 SetRectEmpty(&rect);
3961 r = SendMessageA(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3962 ok(r, "got %d\n", r);
3963 /* some padding? */
3964 expect(2, pt.x);
3965 /* offset by header height */
3966 expect(rect.bottom - rect.top, pt.y);
3968 DestroyWindow(hwnd);
3971 static void test_getitemrect(void)
3973 HWND hwnd;
3974 HIMAGELIST himl, himl_ret;
3975 HBITMAP hbm;
3976 RECT rect;
3977 DWORD r;
3978 LVITEMA item;
3979 LVCOLUMNA col;
3980 INT order[2];
3981 POINT pt;
3983 /* rectangle isn't empty for empty text items */
3984 hwnd = create_listview_control(LVS_LIST);
3985 memset(&item, 0, sizeof(item));
3986 item.mask = 0;
3987 item.iItem = 0;
3988 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3989 expect(0, r);
3990 rect.left = LVIR_LABEL;
3991 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3992 expect(TRUE, r);
3993 expect(0, rect.left);
3994 expect(0, rect.top);
3995 /* estimate it as width / height ratio */
3996 todo_wine
3997 ok((rect.right / rect.bottom) >= 5, "got right %d, bottom %d\n", rect.right, rect.bottom);
3998 DestroyWindow(hwnd);
4000 hwnd = create_listview_control(LVS_REPORT);
4001 ok(hwnd != NULL, "failed to create a listview window\n");
4003 /* empty item */
4004 memset(&item, 0, sizeof(item));
4005 item.iItem = 0;
4006 item.iSubItem = 0;
4007 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4008 expect(0, r);
4010 SetRect(&rect, LVIR_BOUNDS, -1, -1, -1);
4011 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4012 expect(TRUE, r);
4014 /* zero width rectangle with no padding */
4015 expect(0, rect.left);
4016 expect(0, rect.right);
4018 insert_column(hwnd, 0);
4019 insert_column(hwnd, 1);
4021 col.mask = LVCF_WIDTH;
4022 col.cx = 50;
4023 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 0, (LPARAM)&col);
4024 expect(TRUE, r);
4026 col.mask = LVCF_WIDTH;
4027 col.cx = 100;
4028 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 1, (LPARAM)&col);
4029 expect(TRUE, r);
4031 SetRect(&rect, LVIR_BOUNDS, -1, -1, -1);
4032 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4033 expect(TRUE, r);
4035 /* still no left padding */
4036 expect(0, rect.left);
4037 expect(150, rect.right);
4039 SetRect(&rect, LVIR_SELECTBOUNDS, -1, -1, -1);
4040 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4041 expect(TRUE, r);
4042 /* padding */
4043 expect(2, rect.left);
4045 SetRect(&rect, LVIR_LABEL, -1, -1, -1);
4046 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4047 expect(TRUE, r);
4048 /* padding, column width */
4049 expect(2, rect.left);
4050 expect(50, rect.right);
4052 /* no icons attached */
4053 SetRect(&rect, LVIR_ICON, -1, -1, -1);
4054 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4055 expect(TRUE, r);
4056 /* padding */
4057 expect(2, rect.left);
4058 expect(2, rect.right);
4060 /* change order */
4061 order[0] = 1; order[1] = 0;
4062 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
4063 expect(TRUE, r);
4064 pt.x = -1;
4065 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
4066 expect(TRUE, r);
4067 /* 1 indexed column width + padding */
4068 expect(102, pt.x);
4069 /* rect is at zero too */
4070 SetRect(&rect, LVIR_BOUNDS, -1, -1, -1);
4071 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4072 expect(TRUE, r);
4073 expect(0, rect.left);
4074 /* just width sum */
4075 expect(150, rect.right);
4077 SetRect(&rect, LVIR_SELECTBOUNDS, -1, -1, -1);
4078 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4079 expect(TRUE, r);
4080 /* column width + padding */
4081 expect(102, rect.left);
4083 /* back to initial order */
4084 order[0] = 0; order[1] = 1;
4085 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
4086 expect(TRUE, r);
4088 /* state icons */
4089 himl = pImageList_Create(16, 16, 0, 2, 2);
4090 ok(himl != NULL, "failed to create imagelist\n");
4091 hbm = CreateBitmap(16, 16, 1, 1, NULL);
4092 ok(hbm != NULL, "failed to create bitmap\n");
4093 r = pImageList_Add(himl, hbm, 0);
4094 expect(0, r);
4095 hbm = CreateBitmap(16, 16, 1, 1, NULL);
4096 ok(hbm != NULL, "failed to create bitmap\n");
4097 r = pImageList_Add(himl, hbm, 0);
4098 expect(1, r);
4100 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
4101 expect(0, r);
4103 item.mask = LVIF_STATE;
4104 item.state = INDEXTOSTATEIMAGEMASK(1);
4105 item.stateMask = LVIS_STATEIMAGEMASK;
4106 item.iItem = 0;
4107 item.iSubItem = 0;
4108 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4109 expect(TRUE, r);
4111 /* icon bounds */
4112 SetRect(&rect, LVIR_ICON, -1, -1, -1);
4113 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4114 expect(TRUE, r);
4115 /* padding + stateicon width */
4116 expect(18, rect.left);
4117 expect(18, rect.right);
4118 /* label bounds */
4119 SetRect(&rect, LVIR_LABEL, -1, -1, -1);
4120 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4121 expect(TRUE, r);
4122 /* padding + stateicon width -> column width */
4123 expect(18, rect.left);
4124 expect(50, rect.right);
4126 himl_ret = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
4127 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
4129 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
4130 expect(0, r);
4132 item.mask = LVIF_STATE | LVIF_IMAGE;
4133 item.iImage = 1;
4134 item.state = 0;
4135 item.stateMask = ~0;
4136 item.iItem = 0;
4137 item.iSubItem = 0;
4138 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4139 expect(TRUE, r);
4141 /* icon bounds */
4142 SetRect(&rect, LVIR_ICON, -1, -1, -1);
4143 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4144 expect(TRUE, r);
4145 /* padding, icon width */
4146 expect(2, rect.left);
4147 expect(18, rect.right);
4148 /* label bounds */
4149 SetRect(&rect, LVIR_LABEL, -1, -1, -1);
4150 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4151 expect(TRUE, r);
4152 /* padding + icon width -> column width */
4153 expect(18, rect.left);
4154 expect(50, rect.right);
4156 /* select bounds */
4157 SetRect(&rect, LVIR_SELECTBOUNDS, -1, -1, -1);
4158 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4159 expect(TRUE, r);
4160 /* padding, column width */
4161 expect(2, rect.left);
4162 expect(50, rect.right);
4164 /* try with indentation */
4165 item.mask = LVIF_INDENT;
4166 item.iIndent = 1;
4167 item.iItem = 0;
4168 item.iSubItem = 0;
4169 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4170 expect(TRUE, r);
4172 /* bounds */
4173 SetRect(&rect, LVIR_BOUNDS, -1, -1, -1);
4174 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4175 expect(TRUE, r);
4176 /* padding + 1 icon width, column width */
4177 expect(0, rect.left);
4178 expect(150, rect.right);
4180 /* select bounds */
4181 SetRect(&rect, LVIR_SELECTBOUNDS, -1, -1, -1);
4182 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4183 expect(TRUE, r);
4184 /* padding + 1 icon width, column width */
4185 expect(2 + 16, rect.left);
4186 expect(50, rect.right);
4188 /* label bounds */
4189 SetRect(&rect, LVIR_LABEL, -1, -1, -1);
4190 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4191 expect(TRUE, r);
4192 /* padding + 2 icon widths, column width */
4193 expect(2 + 16*2, rect.left);
4194 expect(50, rect.right);
4196 /* icon bounds */
4197 SetRect(&rect, LVIR_ICON, -1, -1, -1);
4198 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4199 expect(TRUE, r);
4200 /* padding + 1 icon width indentation, icon width */
4201 expect(2 + 16, rect.left);
4202 expect(34, rect.right);
4204 DestroyWindow(hwnd);
4207 static void test_editbox(void)
4209 static CHAR testitemA[] = "testitem";
4210 static CHAR testitem1A[] = "testitem_quitelongname";
4211 static CHAR testitem2A[] = "testITEM_quitelongname";
4212 static CHAR buffer[25];
4213 HWND hwnd, hwndedit, hwndedit2, header;
4214 LVITEMA item;
4215 INT r;
4217 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4218 ok(hwnd != NULL, "failed to create a listview window\n");
4220 insert_column(hwnd, 0);
4222 memset(&item, 0, sizeof(item));
4223 item.mask = LVIF_TEXT;
4224 item.pszText = testitemA;
4225 item.iItem = 0;
4226 item.iSubItem = 0;
4227 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4228 expect(0, r);
4230 /* test notifications without edit created */
4231 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4232 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
4233 expect(0, r);
4234 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4235 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
4236 /* same thing but with valid window */
4237 hwndedit = CreateWindowA(WC_EDITA, "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
4238 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
4239 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4240 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
4241 expect(0, r);
4242 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4243 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
4244 DestroyWindow(hwndedit);
4246 /* setting focus is necessary */
4247 SetFocus(hwnd);
4248 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4249 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4251 /* test children Z-order after Edit box created */
4252 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4253 ok(IsWindow(header), "Expected header to be created\n");
4254 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4255 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4257 /* modify initial string */
4258 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4259 expect(TRUE, r);
4261 /* edit window is resized and repositioned,
4262 check again for Z-order - it should be preserved */
4263 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4264 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4266 /* return focus to listview */
4267 SetFocus(hwnd);
4269 memset(&item, 0, sizeof(item));
4270 item.mask = LVIF_TEXT;
4271 item.pszText = buffer;
4272 item.cchTextMax = sizeof(buffer);
4273 item.iItem = 0;
4274 item.iSubItem = 0;
4275 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4276 expect(TRUE, r);
4278 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4280 /* send LVM_EDITLABEL on already created edit */
4281 SetFocus(hwnd);
4282 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4283 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4284 /* focus will be set to edit */
4285 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
4286 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4287 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
4289 /* creating label disabled when control isn't focused */
4290 SetFocus(0);
4291 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4292 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4294 /* check EN_KILLFOCUS handling */
4295 memset(&item, 0, sizeof(item));
4296 item.pszText = testitemA;
4297 item.iItem = 0;
4298 item.iSubItem = 0;
4299 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4300 expect(TRUE, r);
4302 SetFocus(hwnd);
4303 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4304 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4305 /* modify edit and notify control that it lost focus */
4306 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4307 expect(TRUE, r);
4308 g_editbox_disp_info.item.pszText = NULL;
4309 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4310 expect(0, r);
4311 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
4313 memset(&item, 0, sizeof(item));
4314 item.pszText = buffer;
4315 item.cchTextMax = sizeof(buffer);
4316 item.iItem = 0;
4317 item.iSubItem = 0;
4318 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4319 expect(lstrlenA(item.pszText), r);
4320 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4321 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4323 /* change item name to differ in casing only */
4324 SetFocus(hwnd);
4325 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4326 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4327 /* modify edit and notify control that it lost focus */
4328 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
4329 expect(TRUE, r);
4330 g_editbox_disp_info.item.pszText = NULL;
4331 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4332 expect(0, r);
4333 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
4335 memset(&item, 0, sizeof(item));
4336 item.pszText = buffer;
4337 item.cchTextMax = sizeof(buffer);
4338 item.iItem = 0;
4339 item.iSubItem = 0;
4340 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4341 expect(lstrlenA(item.pszText), r);
4342 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
4343 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4345 /* end edit without saving */
4346 SetFocus(hwnd);
4347 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4348 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4349 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
4350 expect(0, r);
4351 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4352 "edit box - end edit, no change, escape", TRUE);
4353 /* end edit with saving */
4354 SetFocus(hwnd);
4355 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4356 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4357 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
4358 expect(0, r);
4359 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4360 "edit box - end edit, no change, return", TRUE);
4362 memset(&item, 0, sizeof(item));
4363 item.pszText = buffer;
4364 item.cchTextMax = sizeof(buffer);
4365 item.iItem = 0;
4366 item.iSubItem = 0;
4367 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4368 expect(lstrlenA(item.pszText), r);
4369 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
4371 /* LVM_EDITLABEL with -1 destroys current edit */
4372 hwndedit = (HWND)SendMessageA(hwnd, LVM_GETEDITCONTROL, 0, 0);
4373 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4374 /* no edit present */
4375 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4376 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4377 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4378 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4379 /* edit present */
4380 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4381 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4382 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4383 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4384 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4385 /* check another negative value */
4386 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4387 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4388 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4389 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -2, 0);
4390 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4391 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4392 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4393 /* and value greater than max item index */
4394 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4395 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4396 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4397 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
4398 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, r, 0);
4399 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4400 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4401 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4403 /* messaging tests */
4404 SetFocus(hwnd);
4405 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4406 blockEdit = FALSE;
4407 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4408 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4409 /* testing only sizing messages */
4410 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
4411 "edit box create - sizing", FALSE);
4413 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4414 SetFocus(hwnd);
4415 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4416 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4417 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4418 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4419 expect(0, r);
4420 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4421 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
4423 DestroyWindow(hwnd);
4426 static void test_notifyformat(void)
4428 HWND hwnd, header;
4429 DWORD r;
4431 hwnd = create_listview_control(LVS_REPORT);
4432 ok(hwnd != NULL, "failed to create a listview window\n");
4434 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4435 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4436 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4437 expect(0, r);
4438 SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4439 /* set */
4440 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
4441 expect(0, r);
4442 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4443 ok(r == 1, "Unexpected return value %d.\n", r);
4444 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
4445 expect(1, r);
4446 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4447 expect(0, r);
4449 DestroyWindow(hwnd);
4451 /* test failure in parent WM_NOTIFYFORMAT */
4452 notifyFormat = 0;
4453 hwnd = create_listview_control(LVS_REPORT);
4454 ok(hwnd != NULL, "failed to create a listview window\n");
4455 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4456 ok(IsWindow(header), "expected header to be created\n");
4457 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4458 expect(0, r);
4459 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4460 ok( r == 1, "Expected 1, got %d\n", r );
4461 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4462 ok(r != 0, "Expected valid format\n");
4464 notifyFormat = NFR_UNICODE;
4465 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4466 expect(NFR_UNICODE, r);
4467 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4468 expect(1, r);
4469 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4470 ok( r == 1, "Expected 1, got %d\n", r );
4472 notifyFormat = NFR_ANSI;
4473 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4474 expect(NFR_ANSI, r);
4475 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4476 expect(0, r);
4477 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4478 ok( r == 1, "Expected 1, got %d\n", r );
4480 DestroyWindow(hwnd);
4482 hwndparentW = create_parent_window(TRUE);
4483 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
4484 if (!IsWindow(hwndparentW)) return;
4486 notifyFormat = -1;
4487 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4488 ok(hwnd != NULL, "failed to create a listview window\n");
4489 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4490 ok(IsWindow(header), "expected header to be created\n");
4491 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4492 expect(1, r);
4493 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4494 expect(1, r);
4495 DestroyWindow(hwnd);
4496 /* receiving error code defaulting to ansi */
4497 notifyFormat = 0;
4498 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4499 ok(hwnd != NULL, "failed to create a listview window\n");
4500 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4501 ok(IsWindow(header), "expected header to be created\n");
4502 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4503 expect(0, r);
4504 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4505 expect(1, r);
4506 DestroyWindow(hwnd);
4507 /* receiving ansi code from unicode window, use it */
4508 notifyFormat = NFR_ANSI;
4509 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4510 ok(hwnd != NULL, "failed to create a listview window\n");
4511 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4512 ok(IsWindow(header), "expected header to be created\n");
4513 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4514 expect(0, r);
4515 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4516 expect(1, r);
4517 DestroyWindow(hwnd);
4518 /* unicode listview with ansi parent window */
4519 notifyFormat = -1;
4520 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4521 ok(hwnd != NULL, "failed to create a listview window\n");
4522 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4523 ok(IsWindow(header), "expected header to be created\n");
4524 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4525 expect(0, r);
4526 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4527 expect(1, r);
4528 DestroyWindow(hwnd);
4529 /* unicode listview with ansi parent window, return error code */
4530 notifyFormat = 0;
4531 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4532 ok(hwnd != NULL, "failed to create a listview window\n");
4533 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4534 ok(IsWindow(header), "expected header to be created\n");
4535 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4536 expect(0, r);
4537 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4538 expect(1, r);
4539 DestroyWindow(hwnd);
4541 DestroyWindow(hwndparentW);
4544 static void test_indentation(void)
4546 HWND hwnd;
4547 LVITEMA item;
4548 DWORD r;
4550 hwnd = create_listview_control(LVS_REPORT);
4551 ok(hwnd != NULL, "failed to create a listview window\n");
4553 memset(&item, 0, sizeof(item));
4554 item.mask = LVIF_INDENT;
4555 item.iItem = 0;
4556 item.iIndent = I_INDENTCALLBACK;
4557 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4558 expect(0, r);
4560 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4562 item.iItem = 0;
4563 item.mask = LVIF_INDENT;
4564 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4565 expect(TRUE, r);
4567 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
4568 "get indent dispinfo", FALSE);
4570 /* Ask for iIndent with invalid subitem. */
4571 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4573 memset(&item, 0, sizeof(item));
4574 item.mask = LVIF_INDENT;
4575 item.iSubItem = 1;
4576 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4577 ok(r, "Failed to get item.\n");
4579 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "get indent dispinfo 2", FALSE);
4581 DestroyWindow(hwnd);
4584 static void test_get_set_view(void)
4586 HWND hwnd;
4587 DWORD ret;
4588 DWORD_PTR style;
4590 /* test style->view mapping */
4591 hwnd = create_listview_control(LVS_REPORT);
4592 ok(hwnd != NULL, "failed to create a listview window\n");
4594 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4595 expect(LV_VIEW_DETAILS, ret);
4597 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4598 /* LVS_ICON == 0 */
4599 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4600 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4601 expect(LV_VIEW_ICON, ret);
4603 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4604 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4605 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4606 expect(LV_VIEW_SMALLICON, ret);
4608 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4609 SetWindowLongPtrA(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4610 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4611 expect(LV_VIEW_LIST, ret);
4613 /* switching view doesn't touch window style */
4614 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4615 expect(1, ret);
4616 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4617 ok(style & LVS_LIST, "Expected style to be preserved\n");
4618 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4619 expect(1, ret);
4620 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4621 ok(style & LVS_LIST, "Expected style to be preserved\n");
4622 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4623 expect(1, ret);
4624 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4625 ok(style & LVS_LIST, "Expected style to be preserved\n");
4627 /* now change window style to see if view is remapped */
4628 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4629 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SHOWSELALWAYS);
4630 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4631 expect(LV_VIEW_SMALLICON, ret);
4633 DestroyWindow(hwnd);
4636 static void test_canceleditlabel(void)
4638 HWND hwnd, hwndedit;
4639 DWORD ret;
4640 CHAR buff[10];
4641 LVITEMA itema;
4642 static CHAR test[] = "test";
4643 static const CHAR test1[] = "test1";
4645 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4646 ok(hwnd != NULL, "failed to create a listview window\n");
4648 insert_item(hwnd, 0);
4650 /* try without edit created */
4651 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4652 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4653 expect(TRUE, ret);
4654 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4655 "cancel edit label without edit", FALSE);
4657 /* cancel without data change */
4658 SetFocus(hwnd);
4659 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4660 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4661 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4662 expect(TRUE, ret);
4663 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4665 /* cancel after data change */
4666 memset(&itema, 0, sizeof(itema));
4667 itema.pszText = test;
4668 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
4669 expect(TRUE, ret);
4670 SetFocus(hwnd);
4671 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4672 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4673 ret = SetWindowTextA(hwndedit, test1);
4674 expect(1, ret);
4675 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4676 expect(TRUE, ret);
4677 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4678 memset(&itema, 0, sizeof(itema));
4679 itema.pszText = buff;
4680 itema.cchTextMax = ARRAY_SIZE(buff);
4681 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&itema);
4682 expect(5, ret);
4683 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4685 DestroyWindow(hwnd);
4688 static void test_mapidindex(void)
4690 HWND hwnd;
4691 INT ret;
4693 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4694 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4695 ok(hwnd != NULL, "failed to create a listview window\n");
4696 insert_item(hwnd, 0);
4697 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4698 expect(-1, ret);
4699 DestroyWindow(hwnd);
4701 hwnd = create_listview_control(LVS_REPORT);
4702 ok(hwnd != NULL, "failed to create a listview window\n");
4704 /* LVM_MAPINDEXTOID with invalid index */
4705 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4706 expect(-1, ret);
4708 insert_item(hwnd, 0);
4709 insert_item(hwnd, 1);
4711 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, -1, 0);
4712 expect(-1, ret);
4713 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 2, 0);
4714 expect(-1, ret);
4716 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4717 expect(0, ret);
4718 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4719 expect(1, ret);
4720 /* remove 0 indexed item, id retained */
4721 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
4722 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4723 expect(1, ret);
4724 /* new id starts from previous value */
4725 insert_item(hwnd, 1);
4726 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4727 expect(2, ret);
4729 /* get index by id */
4730 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4731 expect(-1, ret);
4732 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4733 expect(-1, ret);
4734 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4735 expect(0, ret);
4736 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4737 expect(1, ret);
4739 DestroyWindow(hwnd);
4742 static void test_getitemspacing(void)
4744 HWND hwnd;
4745 DWORD ret;
4746 INT cx, cy;
4747 HIMAGELIST himl40, himl80;
4749 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4750 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4752 /* LVS_ICON */
4753 hwnd = create_listview_control(LVS_ICON);
4754 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4755 expect(cx, LOWORD(ret));
4756 expect(cy, HIWORD(ret));
4758 /* now try with icons */
4759 himl40 = pImageList_Create(40, 40, 0, 4, 4);
4760 ok(himl40 != NULL, "failed to create imagelist\n");
4761 himl80 = pImageList_Create(80, 80, 0, 4, 4);
4762 ok(himl80 != NULL, "failed to create imagelist\n");
4763 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4764 expect(0, ret);
4766 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4767 /* spacing + icon size returned */
4768 expect(cx + 40, LOWORD(ret));
4769 expect(cy + 40, HIWORD(ret));
4770 /* try changing icon size */
4771 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl80);
4773 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4774 /* spacing + icon size returned */
4775 expect(cx + 80, LOWORD(ret));
4776 expect(cy + 80, HIWORD(ret));
4778 /* set own icon spacing */
4779 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(100, 100));
4780 expect(cx + 80, LOWORD(ret));
4781 expect(cy + 80, HIWORD(ret));
4783 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4784 /* set size returned */
4785 expect(100, LOWORD(ret));
4786 expect(100, HIWORD(ret));
4788 /* now change image list - icon spacing should be unaffected */
4789 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4791 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4792 /* set size returned */
4793 expect(100, LOWORD(ret));
4794 expect(100, HIWORD(ret));
4796 /* spacing = 0 - keep previous value */
4797 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(0, -1));
4798 expect(100, LOWORD(ret));
4799 expect(100, HIWORD(ret));
4801 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4802 expect(100, LOWORD(ret));
4804 expect(0xFFFF, HIWORD(ret));
4806 if (sizeof(void*) == 8)
4808 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4809 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, (DWORD)-1);
4810 expect(100, LOWORD(ret));
4811 expect(0xFFFF, HIWORD(ret));
4813 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4814 expect(0xFFFF, LOWORD(ret));
4815 expect(0xFFFF, HIWORD(ret));
4817 else
4819 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4820 expect(100, LOWORD(ret));
4821 expect(0xFFFF, HIWORD(ret));
4823 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4824 /* spacing + icon size returned */
4825 expect(cx + 40, LOWORD(ret));
4826 expect(cy + 40, HIWORD(ret));
4828 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4829 pImageList_Destroy(himl80);
4830 DestroyWindow(hwnd);
4831 /* LVS_SMALLICON */
4832 hwnd = create_listview_control(LVS_SMALLICON);
4833 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4834 expect(cx, LOWORD(ret));
4835 expect(cy, HIWORD(ret));
4837 /* spacing does not depend on selected view type */
4838 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4839 expect(0, ret);
4841 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4842 /* spacing + icon size returned */
4843 expect(cx + 40, LOWORD(ret));
4844 expect(cy + 40, HIWORD(ret));
4846 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4847 pImageList_Destroy(himl40);
4848 DestroyWindow(hwnd);
4849 /* LVS_REPORT */
4850 hwnd = create_listview_control(LVS_REPORT);
4851 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4852 expect(cx, LOWORD(ret));
4853 expect(cy, HIWORD(ret));
4855 DestroyWindow(hwnd);
4856 /* LVS_LIST */
4857 hwnd = create_listview_control(LVS_LIST);
4858 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4859 expect(cx, LOWORD(ret));
4860 expect(cy, HIWORD(ret));
4862 DestroyWindow(hwnd);
4865 static INT get_current_font_height(HWND listview)
4867 TEXTMETRICA tm;
4868 HFONT hfont;
4869 HWND hwnd;
4870 HDC hdc;
4872 hwnd = (HWND)SendMessageA(listview, LVM_GETHEADER, 0, 0);
4873 if (!hwnd)
4874 hwnd = listview;
4876 hfont = (HFONT)SendMessageA(hwnd, WM_GETFONT, 0, 0);
4877 if (!hfont) {
4878 hdc = GetDC(hwnd);
4879 GetTextMetricsA(hdc, &tm);
4880 ReleaseDC(hwnd, hdc);
4882 else {
4883 HFONT oldfont;
4885 hdc = GetDC(0);
4886 oldfont = SelectObject(hdc, hfont);
4887 GetTextMetricsA(hdc, &tm);
4888 SelectObject(hdc, oldfont);
4889 ReleaseDC(0, hdc);
4892 return tm.tmHeight;
4895 static void test_getcolumnwidth(void)
4897 HWND hwnd;
4898 INT ret;
4899 DWORD_PTR style;
4900 LVCOLUMNA col;
4901 LVITEMA itema;
4902 INT height;
4904 /* default column width */
4905 hwnd = create_listview_control(LVS_ICON);
4906 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4907 expect(0, ret);
4908 style = GetWindowLongA(hwnd, GWL_STYLE);
4909 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_LIST);
4910 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4911 todo_wine expect(8, ret);
4912 style = GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_LIST;
4913 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_REPORT);
4914 col.mask = 0;
4915 ret = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4916 expect(0, ret);
4917 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4918 expect(10, ret);
4919 DestroyWindow(hwnd);
4921 /* default column width with item added */
4922 hwnd = create_listview_control(LVS_LIST);
4923 memset(&itema, 0, sizeof(itema));
4924 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4925 ok(!ret, "got %d\n", ret);
4926 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4927 height = get_current_font_height(hwnd);
4928 ok((ret / height) >= 6, "got width %d, height %d\n", ret, height);
4929 DestroyWindow(hwnd);
4932 static void test_scrollnotify(void)
4934 HWND hwnd;
4935 DWORD ret;
4937 hwnd = create_listview_control(LVS_REPORT);
4939 insert_column(hwnd, 0);
4940 insert_column(hwnd, 1);
4941 insert_item(hwnd, 0);
4943 /* make it scrollable - resize */
4944 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4945 expect(TRUE, ret);
4946 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4947 expect(TRUE, ret);
4949 /* try with dummy call */
4950 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4951 ret = SendMessageA(hwnd, LVM_SCROLL, 0, 0);
4952 expect(TRUE, ret);
4953 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4954 "scroll notify 1", TRUE);
4956 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4957 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 0);
4958 expect(TRUE, ret);
4959 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4960 "scroll notify 2", TRUE);
4962 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4963 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 1);
4964 expect(TRUE, ret);
4965 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4966 "scroll notify 3", TRUE);
4968 DestroyWindow(hwnd);
4971 static void test_LVS_EX_TRANSPARENTBKGND(void)
4973 HWND hwnd;
4974 DWORD ret;
4975 HDC hdc;
4977 hwnd = create_listview_control(LVS_REPORT);
4979 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4980 expect(TRUE, ret);
4982 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4983 LVS_EX_TRANSPARENTBKGND);
4985 ret = SendMessageA(hwnd, LVM_GETBKCOLOR, 0, 0);
4986 if (ret != CLR_NONE)
4988 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4989 DestroyWindow(hwnd);
4990 return;
4993 /* try to set some back color and check this style bit */
4994 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4995 expect(TRUE, ret);
4996 ret = SendMessageA(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4997 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4999 /* now test what this style actually does */
5000 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
5001 LVS_EX_TRANSPARENTBKGND);
5003 hdc = GetWindowDC(hwndparent);
5005 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5006 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
5007 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
5008 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
5010 ReleaseDC(hwndparent, hdc);
5012 DestroyWindow(hwnd);
5015 static void test_approximate_viewrect(void)
5017 static CHAR test[] = "abracadabra, a very long item label";
5018 DWORD item_width, item_height, header_height;
5019 static CHAR column_header[] = "Header";
5020 unsigned const column_width = 100;
5021 DWORD ret, item_count;
5022 HIMAGELIST himl;
5023 LVITEMA itema;
5024 LVCOLUMNA col;
5025 HBITMAP hbmp;
5026 HWND hwnd;
5028 /* LVS_ICON */
5029 hwnd = create_listview_control(LVS_ICON);
5030 himl = pImageList_Create(40, 40, 0, 4, 4);
5031 ok(himl != NULL, "failed to create imagelist\n");
5032 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
5033 ok(hbmp != NULL, "failed to create bitmap\n");
5034 ret = pImageList_Add(himl, hbmp, 0);
5035 expect(0, ret);
5036 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
5037 expect(0, ret);
5039 itema.mask = LVIF_IMAGE;
5040 itema.iImage = 0;
5041 itema.iItem = 0;
5042 itema.iSubItem = 0;
5043 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
5044 expect(0, ret);
5046 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
5047 ok(ret != 0, "Unexpected return value %#x.\n", ret);
5049 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
5050 expect(MAKELONG(77,827), ret);
5052 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
5053 ok(ret != 0, "got 0\n");
5055 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
5056 expect(MAKELONG(102,302), ret);
5058 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
5059 expect(MAKELONG(52,52), ret);
5061 itema.pszText = test;
5062 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
5063 expect(TRUE, ret);
5064 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
5065 expect(MAKELONG(52,52), ret);
5067 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
5068 expect(MAKELONG(52,2), ret);
5069 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
5070 expect(MAKELONG(52,52), ret);
5071 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
5072 expect(MAKELONG(102,52), ret);
5073 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
5074 expect(MAKELONG(102,102), ret);
5075 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
5076 expect(MAKELONG(102,102), ret);
5077 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
5078 expect(MAKELONG(102,152), ret);
5079 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
5080 expect(MAKELONG(102,152), ret);
5081 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
5082 expect(MAKELONG(152,152), ret);
5084 DestroyWindow(hwnd);
5086 /* LVS_REPORT */
5087 hwnd = create_listview_control(LVS_REPORT);
5089 /* Empty control without columns */
5090 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100, 100));
5091 todo_wine
5092 ok(LOWORD(ret) == 0, "Unexpected width %d.\n", LOWORD(ret));
5093 ok(HIWORD(ret) != 0, "Unexpected height %d.\n", HIWORD(ret));
5095 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 0, 0);
5096 ok(LOWORD(ret) == 0, "Unexpected width %d.\n", LOWORD(ret));
5097 todo_wine
5098 ok(HIWORD(ret) != 0, "Unexpected height %d.\n", HIWORD(ret));
5100 header_height = HIWORD(ret);
5102 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 1, 0);
5103 ok(LOWORD(ret) == 0, "Unexpected width %d.\n", LOWORD(ret));
5104 todo_wine
5105 ok(HIWORD(ret) > header_height, "Unexpected height %d.\n", HIWORD(ret));
5107 item_height = HIWORD(ret) - header_height;
5109 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -2, 0);
5110 ok(LOWORD(ret) == 0, "Unexpected width %d.\n", LOWORD(ret));
5111 ok(HIWORD(ret) == (header_height - 2 * item_height), "Unexpected height %d.\n", HIWORD(ret)) ;
5113 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, 0);
5114 ok(LOWORD(ret) == 0, "Unexpected width %d.\n", LOWORD(ret));
5115 ok(HIWORD(ret) == header_height, "Unexpected height.\n");
5116 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 2, 0);
5117 ok(LOWORD(ret) == 0, "Unexpected width %d.\n", LOWORD(ret));
5118 ok(HIWORD(ret) == header_height + 2 * item_height, "Unexpected height %d.\n", HIWORD(ret));
5120 /* Insert column */
5121 col.mask = LVCF_TEXT | LVCF_WIDTH;
5122 col.pszText = column_header;
5123 col.cx = column_width;
5124 ret = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5125 ok(ret == 0, "Unexpected return value %d.\n", ret);
5127 /* Empty control with column */
5128 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 0, 0);
5129 todo_wine {
5130 ok(LOWORD(ret) >= column_width, "Unexpected width %d.\n", LOWORD(ret));
5131 ok(HIWORD(ret) != 0, "Unexpected height %d.\n", HIWORD(ret));
5133 header_height = HIWORD(ret);
5134 item_width = LOWORD(ret);
5136 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 1, 0);
5137 ok(LOWORD(ret) == item_width, "Unexpected width %d.\n", LOWORD(ret));
5138 todo_wine
5139 ok(HIWORD(ret) > header_height, "Unexpected height %d.\n", HIWORD(ret));
5141 item_height = HIWORD(ret) - header_height;
5143 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -2, 0);
5144 ok(LOWORD(ret) == item_width, "Unexpected width %d.\n", LOWORD(ret));
5145 ok(HIWORD(ret) == header_height - 2 * item_height, "Unexpected height %d.\n", HIWORD(ret));
5147 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, 0);
5148 ok(LOWORD(ret) == item_width, "Unexpected width %d.\n", LOWORD(ret));
5149 ok(HIWORD(ret) == header_height, "Unexpected height %d.\n", HIWORD(ret));
5151 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 2, 0);
5152 ok(LOWORD(ret) == item_width, "Unexpected width %d.\n", LOWORD(ret));
5153 ok(HIWORD(ret) == header_height + 2 * item_height, "Unexpected height %d.\n", HIWORD(ret));
5155 for (item_count = 1; item_count <= 2; ++item_count)
5157 itema.mask = LVIF_TEXT;
5158 itema.iItem = 0;
5159 itema.iSubItem = 0;
5160 itema.pszText = test;
5161 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
5162 ok(ret == 0, "Unexpected return value %d.\n", ret);
5164 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 0, 0);
5165 ok(LOWORD(ret) >= column_width, "Unexpected width %d.\n", LOWORD(ret));
5166 todo_wine
5167 ok(HIWORD(ret) != 0, "Unexpected height %d.\n", HIWORD(ret));
5169 header_height = HIWORD(ret);
5170 item_width = LOWORD(ret);
5172 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 1, 0);
5173 ok(LOWORD(ret) == item_width, "Unexpected width %d, item %d\n", LOWORD(ret), item_count - 1);
5174 ok(HIWORD(ret) > header_height, "Unexpected height %d. item %d.\n", HIWORD(ret), item_count - 1);
5176 item_height = HIWORD(ret) - header_height;
5178 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -2, 0);
5179 ok(LOWORD(ret) == item_width, "Unexpected width %d.\n", LOWORD(ret));
5180 todo_wine
5181 ok(HIWORD(ret) == header_height - 2 * item_height, "Unexpected height %d.\n", HIWORD(ret));
5183 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, 0);
5184 ok(LOWORD(ret) == item_width, "Unexpected width %d.\n", LOWORD(ret));
5185 ok(HIWORD(ret) == header_height + item_count * item_height, "Unexpected height %d.\n", HIWORD(ret));
5187 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 2, 0);
5188 ok(LOWORD(ret) == item_width, "Unexpected width %d.\n", LOWORD(ret));
5189 ok(HIWORD(ret) == header_height + 2 * item_height, "Unexpected height %d.\n", HIWORD(ret));
5191 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELONG(item_width * 2, header_height + 3 * item_height));
5192 ok(LOWORD(ret) == item_width, "Unexpected width %d.\n", LOWORD(ret));
5193 ok(HIWORD(ret) == header_height + 2 * item_height, "Unexpected height %d.\n", HIWORD(ret));
5195 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -2, MAKELONG(item_width * 2, 0));
5196 ok(LOWORD(ret) == item_width, "Unexpected width %d.\n", LOWORD(ret));
5197 todo_wine
5198 ok(HIWORD(ret) == header_height - 2 * item_height, "Unexpected height %d.\n", HIWORD(ret));
5200 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -2, MAKELONG(-1, -1));
5201 ok(LOWORD(ret) == item_width, "Unexpected width %d.\n", LOWORD(ret));
5202 todo_wine
5203 ok(HIWORD(ret) == header_height - 2 * item_height, "Unexpected height %d.\n", HIWORD(ret));
5206 DestroyWindow(hwnd);
5210 static void test_finditem(void)
5212 LVFINDINFOA fi;
5213 static char f[5];
5214 HWND hwnd;
5215 INT r;
5217 hwnd = create_listview_control(LVS_REPORT);
5218 insert_item(hwnd, 0);
5220 memset(&fi, 0, sizeof(fi));
5222 /* full string search, inserted text was "foo" */
5223 strcpy(f, "foo");
5224 fi.flags = LVFI_STRING;
5225 fi.psz = f;
5226 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5227 expect(0, r);
5229 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5230 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5231 expect(0, r);
5233 fi.flags = LVFI_PARTIAL;
5234 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5235 expect(0, r);
5237 /* partial string search, inserted text was "foo" */
5238 strcpy(f, "fo");
5239 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5240 fi.psz = f;
5241 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5242 expect(0, r);
5244 fi.flags = LVFI_STRING;
5245 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5246 expect(-1, r);
5248 fi.flags = LVFI_PARTIAL;
5249 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5250 expect(0, r);
5252 /* partial string search, part after start char */
5253 strcpy(f, "oo");
5254 fi.flags = LVFI_STRING | LVFI_PARTIAL;
5255 fi.psz = f;
5256 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5257 expect(-1, r);
5259 /* try with LVFI_SUBSTRING */
5260 strcpy(f, "fo");
5261 fi.flags = LVFI_SUBSTRING;
5262 fi.psz = f;
5263 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5264 expect(0, r);
5265 strcpy(f, "f");
5266 fi.flags = LVFI_SUBSTRING;
5267 fi.psz = f;
5268 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5269 expect(0, r);
5270 strcpy(f, "o");
5271 fi.flags = LVFI_SUBSTRING;
5272 fi.psz = f;
5273 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5274 expect(-1, r);
5276 strcpy(f, "o");
5277 fi.flags = LVFI_SUBSTRING | LVFI_PARTIAL;
5278 fi.psz = f;
5279 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5280 expect(-1, r);
5282 strcpy(f, "f");
5283 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
5284 fi.psz = f;
5285 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5286 expect(0, r);
5288 fi.flags = LVFI_SUBSTRING | LVFI_PARTIAL;
5289 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5290 expect(0, r);
5292 /* Case sensitivity. */
5293 strcpy(f, "Foo");
5294 fi.flags = LVFI_STRING;
5295 fi.psz = f;
5296 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5297 ok(!r, "Unexpected item index %d.\n", r);
5299 strcpy(f, "F");
5300 fi.flags = LVFI_SUBSTRING;
5301 fi.psz = f;
5302 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
5303 ok(!r, "Unexpected item index %d.\n", r);
5305 DestroyWindow(hwnd);
5308 static void test_LVS_EX_HEADERINALLVIEWS(void)
5310 HWND hwnd, header;
5311 DWORD style;
5313 hwnd = create_listview_control(LVS_ICON);
5315 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5316 LVS_EX_HEADERINALLVIEWS);
5318 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5319 if (!IsWindow(header))
5321 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
5322 DestroyWindow(hwnd);
5323 return;
5326 /* LVS_NOCOLUMNHEADER works as before */
5327 style = GetWindowLongA(hwnd, GWL_STYLE);
5328 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
5329 style = GetWindowLongA(header, GWL_STYLE);
5330 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
5331 style = GetWindowLongA(hwnd, GWL_STYLE);
5332 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
5333 style = GetWindowLongA(header, GWL_STYLE);
5334 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
5336 /* try to remove style */
5337 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
5338 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5339 ok(IsWindow(header), "Expected header to be created\n");
5340 style = GetWindowLongA(header, GWL_STYLE);
5341 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
5343 DestroyWindow(hwnd);
5345 /* check other styles */
5346 hwnd = create_listview_control(LVS_LIST);
5347 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5348 LVS_EX_HEADERINALLVIEWS);
5349 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5350 ok(IsWindow(header), "Expected header to be created\n");
5351 DestroyWindow(hwnd);
5353 hwnd = create_listview_control(LVS_SMALLICON);
5354 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5355 LVS_EX_HEADERINALLVIEWS);
5356 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5357 ok(IsWindow(header), "Expected header to be created\n");
5358 DestroyWindow(hwnd);
5360 hwnd = create_listview_control(LVS_REPORT);
5361 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5362 LVS_EX_HEADERINALLVIEWS);
5363 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5364 ok(IsWindow(header), "Expected header to be created\n");
5365 DestroyWindow(hwnd);
5368 static void test_hover(void)
5370 HWND hwnd, fg;
5371 DWORD r;
5373 hwnd = create_listview_control(LVS_ICON);
5374 SetForegroundWindow(hwndparent);
5375 fg = GetForegroundWindow();
5376 if (fg != hwndparent)
5378 skip("Window is not in the foreground. Skipping hover tests.\n");
5379 DestroyWindow(hwnd);
5380 return;
5383 /* test WM_MOUSEHOVER forwarding */
5384 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5385 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5386 expect(0, r);
5387 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
5388 g_block_hover = TRUE;
5389 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5390 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5391 expect(0, r);
5392 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
5393 g_block_hover = FALSE;
5395 r = SendMessageA(hwnd, LVM_SETHOVERTIME, 0, 500);
5396 expect(HOVER_DEFAULT, r);
5397 r = SendMessageA(hwnd, LVM_GETHOVERTIME, 0, 0);
5398 expect(500, r);
5400 DestroyWindow(hwnd);
5403 static void test_destroynotify(void)
5405 HWND hwnd;
5406 BOOL ret;
5408 hwnd = create_listview_control(LVS_REPORT);
5409 ok(hwnd != NULL, "failed to create listview window\n");
5411 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5412 DestroyWindow(hwnd);
5413 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
5415 /* same for ownerdata list */
5416 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5417 ok(hwnd != NULL, "failed to create listview window\n");
5419 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5420 DestroyWindow(hwnd);
5421 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_destroy, "check destroy order, ownerdata", FALSE);
5423 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5424 ok(hwnd != NULL, "failed to create listview window\n");
5426 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5427 ret = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
5428 ok(ret == TRUE, "got %d\n", ret);
5429 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_deleteall, "deleteall ownerdata", FALSE);
5430 DestroyWindow(hwnd);
5433 static void test_header_notification(void)
5435 static char textA[] = "newtext";
5436 HWND list, header;
5437 HDITEMA item;
5438 NMHEADERA nmh;
5439 LVCOLUMNA col;
5440 DWORD ret;
5441 BOOL r;
5443 list = create_listview_control(LVS_REPORT);
5444 ok(list != NULL, "failed to create listview window\n");
5446 memset(&col, 0, sizeof(col));
5447 col.mask = LVCF_WIDTH;
5448 col.cx = 100;
5449 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5450 expect(0, ret);
5452 /* check list parent notification after header item changed,
5453 this test should be placed before header subclassing to avoid
5454 Listview -> Header messages to be logged */
5455 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5457 col.mask = LVCF_TEXT;
5458 col.pszText = textA;
5459 r = SendMessageA(list, LVM_SETCOLUMNA, 0, (LPARAM)&col);
5460 expect(TRUE, r);
5462 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_changed_seq,
5463 "header notify, listview", FALSE);
5464 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5465 "header notify, parent", FALSE);
5467 header = subclass_header(list);
5469 ret = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
5470 expect(1, ret);
5472 memset(&item, 0, sizeof(item));
5473 item.mask = HDI_WIDTH;
5474 ret = SendMessageA(header, HDM_GETITEMA, 0, (LPARAM)&item);
5475 expect(1, ret);
5476 expect(100, item.cxy);
5478 nmh.hdr.hwndFrom = header;
5479 nmh.hdr.idFrom = GetWindowLongPtrA(header, GWLP_ID);
5480 nmh.hdr.code = HDN_ITEMCHANGEDA;
5481 nmh.iItem = 0;
5482 nmh.iButton = 0;
5483 item.mask = HDI_WIDTH;
5484 item.cxy = 50;
5485 nmh.pitem = &item;
5486 ret = SendMessageA(list, WM_NOTIFY, 0, (LPARAM)&nmh);
5487 expect(0, ret);
5489 DestroyWindow(list);
5492 static void test_header_notification2(void)
5494 static char textA[] = "newtext";
5495 HWND list, header;
5496 HDITEMW itemW;
5497 NMHEADERW nmhdr;
5498 LVCOLUMNA col;
5499 DWORD ret;
5500 WCHAR buffer[100];
5501 struct message parent_header_notify_seq[] = {
5502 { WM_NOTIFY, sent|id, 0, 0, 0 },
5503 { 0 }
5506 list = create_listview_control(LVS_REPORT);
5507 ok(list != NULL, "failed to create listview window\n");
5509 memset(&col, 0, sizeof(col));
5510 col.mask = LVCF_WIDTH | LVCF_TEXT;
5511 col.cx = 100;
5512 col.pszText = textA;
5513 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5514 expect(0, ret);
5516 header = (HWND)SendMessageA(list, LVM_GETHEADER, 0, 0);
5517 ok(header != 0, "No header\n");
5518 memset(&itemW, 0, sizeof(itemW));
5519 itemW.mask = HDI_WIDTH | HDI_ORDER | HDI_TEXT;
5520 itemW.pszText = buffer;
5521 itemW.cchTextMax = ARRAY_SIZE(buffer);
5522 ret = SendMessageW(header, HDM_GETITEMW, 0, (LPARAM)&itemW);
5523 expect(1, ret);
5525 nmhdr.hdr.hwndFrom = header;
5526 nmhdr.hdr.idFrom = GetWindowLongPtrW(header, GWLP_ID);
5527 nmhdr.iItem = 0;
5528 nmhdr.iButton = 0;
5529 nmhdr.pitem = &itemW;
5531 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5532 nmhdr.hdr.code = HDN_ITEMCHANGINGW;
5533 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5534 ok(ret == 0, "got %d\n", ret);
5535 parent_header_notify_seq[0].id = HDN_ITEMCHANGINGA;
5536 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5537 "header notify, parent", TRUE);
5538 todo_wine
5539 ok(nmhdr.hdr.code == HDN_ITEMCHANGINGA, "Expected ANSI notification code\n");
5540 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5541 nmhdr.hdr.code = HDN_ITEMCHANGEDW;
5542 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5543 ok(ret == 0, "got %d\n", ret);
5544 parent_header_notify_seq[0].id = HDN_ITEMCHANGEDA;
5545 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5546 "header notify, parent", TRUE);
5547 todo_wine
5548 ok(nmhdr.hdr.code == HDN_ITEMCHANGEDA, "Expected ANSI notification code\n");
5549 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5550 SetFocus(list);
5551 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5552 nmhdr.hdr.code = HDN_ITEMCLICKW;
5553 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5554 ok(ret == 0, "got %d\n", ret);
5555 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_click_seq,
5556 "header notify, parent", FALSE);
5557 ok(nmhdr.hdr.code == HDN_ITEMCLICKA, "Expected ANSI notification code\n");
5558 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5559 nmhdr.hdr.code = HDN_ITEMDBLCLICKW;
5560 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5561 ok(ret == 0, "got %d\n", ret);
5562 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5563 "header notify, parent", FALSE);
5564 ok(nmhdr.hdr.code == HDN_ITEMDBLCLICKW, "Expected Unicode notification code\n");
5565 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5566 nmhdr.hdr.code = HDN_DIVIDERDBLCLICKW;
5567 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5568 ok(ret == 0, "got %d\n", ret);
5569 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_divider_dclick_seq,
5570 "header notify, parent", TRUE);
5571 ok(nmhdr.hdr.code == HDN_DIVIDERDBLCLICKA, "Expected ANSI notification code\n");
5572 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5573 nmhdr.hdr.code = HDN_BEGINTRACKW;
5574 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5575 ok(ret == 0, "got %d\n", ret);
5576 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5577 "header notify, parent", FALSE);
5578 ok(nmhdr.hdr.code == HDN_BEGINTRACKW, "Expected Unicode notification code\n");
5579 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5580 nmhdr.hdr.code = HDN_ENDTRACKW;
5581 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5582 ok(ret == 0, "got %d\n", ret);
5583 parent_header_notify_seq[0].id = HDN_ENDTRACKA;
5584 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5585 "header notify, parent", FALSE);
5586 ok(nmhdr.hdr.code == HDN_ENDTRACKA, "Expected ANSI notification code\n");
5587 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5588 nmhdr.hdr.code = HDN_TRACKW;
5589 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5590 ok(ret == 0, "got %d\n", ret);
5591 parent_header_notify_seq[0].id = HDN_TRACKA;
5592 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5593 "header notify, parent", FALSE);
5594 ok(nmhdr.hdr.code == HDN_TRACKA, "Expected ANSI notification code\n");
5595 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5596 nmhdr.hdr.code = HDN_BEGINDRAG;
5597 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5598 ok(ret == 1, "got %d\n", ret);
5599 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5600 "header notify, parent", FALSE);
5601 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5602 nmhdr.hdr.code = HDN_ENDDRAG;
5603 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5604 ok(ret == 0, "got %d\n", ret);
5605 parent_header_notify_seq[0].id = HDN_ENDDRAG;
5606 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5607 "header notify, parent", FALSE);
5608 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5609 nmhdr.hdr.code = HDN_FILTERCHANGE;
5610 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5611 ok(ret == 0, "got %d\n", ret);
5612 parent_header_notify_seq[0].id = HDN_FILTERCHANGE;
5613 parent_header_notify_seq[0].flags |= optional; /* NT4 does not send this message */
5614 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5615 "header notify, parent", FALSE);
5616 parent_header_notify_seq[0].flags &= ~optional;
5617 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5618 nmhdr.hdr.code = HDN_BEGINFILTEREDIT;
5619 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5620 ok(ret == 0, "got %d\n", ret);
5621 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5622 "header notify, parent", FALSE);
5623 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5624 nmhdr.hdr.code = HDN_ENDFILTEREDIT;
5625 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5626 ok(ret == 0, "got %d\n", ret);
5627 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5628 "header notify, parent", FALSE);
5629 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5630 nmhdr.hdr.code = HDN_ITEMSTATEICONCLICK;
5631 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5632 ok(ret == 0, "got %d\n", ret);
5633 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5634 "header notify, parent", FALSE);
5635 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5636 nmhdr.hdr.code = HDN_ITEMKEYDOWN;
5637 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5638 ok(ret == 0, "got %d\n", ret);
5639 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5640 "header notify, parent", FALSE);
5642 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5644 DestroyWindow(list);
5647 static void test_createdragimage(void)
5649 HIMAGELIST himl;
5650 POINT pt;
5651 HWND list;
5653 list = create_listview_control(LVS_ICON);
5654 ok(list != NULL, "failed to create listview window\n");
5656 insert_item(list, 0);
5658 /* NULL point */
5659 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
5660 ok(himl == NULL, "got %p\n", himl);
5662 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
5663 ok(himl != NULL, "got %p\n", himl);
5664 pImageList_Destroy(himl);
5666 DestroyWindow(list);
5669 static void test_dispinfo(void)
5671 static const char testA[] = "TEST";
5672 WCHAR buff[10];
5673 LVITEMA item;
5674 HWND hwnd;
5675 DWORD ret;
5677 hwnd = create_listview_control(LVS_ICON);
5678 ok(hwnd != NULL, "failed to create listview window\n");
5680 insert_item(hwnd, 0);
5682 memset(&item, 0, sizeof(item));
5683 item.pszText = LPSTR_TEXTCALLBACKA;
5684 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5685 expect(1, ret);
5687 g_disp_A_to_W = TRUE;
5688 item.pszText = (char*)buff;
5689 item.cchTextMax = ARRAY_SIZE(buff);
5690 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
5691 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
5692 g_disp_A_to_W = FALSE;
5694 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
5695 "got %s, expected %s\n", item.pszText, testA);
5697 DestroyWindow(hwnd);
5700 static void test_LVM_SETITEMTEXT(void)
5702 static char testA[] = "TEST";
5703 LVITEMA item;
5704 HWND hwnd;
5705 DWORD ret;
5707 hwnd = create_listview_control(LVS_ICON);
5708 ok(hwnd != NULL, "failed to create listview window\n");
5710 insert_item(hwnd, 0);
5712 /* null item pointer */
5713 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, 0);
5714 expect(FALSE, ret);
5716 ret = SendMessageA(hwnd, LVM_SETITEMTEXTW, 0, 0);
5717 expect(FALSE, ret);
5719 /* index out of bounds */
5720 item.pszText = testA;
5721 item.cchTextMax = 0; /* ignored */
5722 item.iSubItem = 0;
5724 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 1, (LPARAM)&item);
5725 expect(FALSE, ret);
5727 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, -1, (LPARAM)&item);
5728 expect(FALSE, ret);
5730 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5731 expect(TRUE, ret);
5733 DestroyWindow(hwnd);
5736 static void test_LVM_REDRAWITEMS(void)
5738 HWND list;
5739 DWORD ret;
5741 list = create_listview_control(LVS_ICON);
5742 ok(list != NULL, "failed to create listview window\n");
5744 ret = SendMessageA(list, LVM_REDRAWITEMS, 0, 0);
5745 expect(TRUE, ret);
5747 insert_item(list, 0);
5749 ret = SendMessageA(list, LVM_REDRAWITEMS, -1, 0);
5750 expect(TRUE, ret);
5752 ret = SendMessageA(list, LVM_REDRAWITEMS, 0, -1);
5753 expect(TRUE, ret);
5755 ret = SendMessageA(list, LVM_REDRAWITEMS, 0, 0);
5756 expect(TRUE, ret);
5758 ret = SendMessageA(list, LVM_REDRAWITEMS, 0, 1);
5759 expect(TRUE, ret);
5761 ret = SendMessageA(list, LVM_REDRAWITEMS, 0, 2);
5762 expect(TRUE, ret);
5764 ret = SendMessageA(list, LVM_REDRAWITEMS, 1, 0);
5765 expect(TRUE, ret);
5767 ret = SendMessageA(list, LVM_REDRAWITEMS, 2, 3);
5768 expect(TRUE, ret);
5770 DestroyWindow(list);
5773 static void test_imagelists(void)
5775 HWND hwnd, header;
5776 HIMAGELIST himl1, himl2, himl3;
5777 LRESULT ret;
5779 himl1 = pImageList_Create(40, 40, 0, 4, 4);
5780 himl2 = pImageList_Create(40, 40, 0, 4, 4);
5781 himl3 = pImageList_Create(40, 40, 0, 4, 4);
5782 ok(himl1 != NULL, "Failed to create imagelist\n");
5783 ok(himl2 != NULL, "Failed to create imagelist\n");
5784 ok(himl3 != NULL, "Failed to create imagelist\n");
5786 hwnd = create_listview_control(LVS_REPORT | LVS_SHAREIMAGELISTS);
5787 header = subclass_header(hwnd);
5789 ok(header != NULL, "Expected header\n");
5790 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5791 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5793 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5795 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5796 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5797 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5798 "set normal image list", FALSE);
5800 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5802 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5803 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5804 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5805 "set state image list", TRUE);
5807 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5808 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5810 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5812 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5813 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5814 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_set_imagelist,
5815 "set small image list", FALSE);
5817 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5818 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5819 DestroyWindow(hwnd);
5821 hwnd = create_listview_control(WS_VISIBLE | LVS_ICON);
5823 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5825 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5826 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5827 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5828 "set normal image list", FALSE);
5830 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5832 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5833 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5834 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5835 "set state image list", FALSE);
5837 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5839 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5840 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5841 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5842 "set small image list", FALSE);
5844 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5845 ok(header == NULL, "Expected no header, got %p\n", header);
5847 SetWindowLongPtrA(hwnd, GWL_STYLE, GetWindowLongPtrA(hwnd, GWL_STYLE) | LVS_REPORT);
5849 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5850 ok(header != NULL, "Expected header, got NULL\n");
5852 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5853 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5855 DestroyWindow(hwnd);
5858 static void test_deleteitem(void)
5860 LVITEMA item;
5861 UINT state;
5862 HWND hwnd;
5863 BOOL ret;
5865 hwnd = create_listview_control(LVS_REPORT);
5867 insert_item(hwnd, 0);
5868 insert_item(hwnd, 0);
5869 insert_item(hwnd, 0);
5870 insert_item(hwnd, 0);
5871 insert_item(hwnd, 0);
5873 g_focus_test_LVN_DELETEITEM = TRUE;
5875 /* delete focused item (not the last index) */
5876 item.stateMask = LVIS_FOCUSED;
5877 item.state = LVIS_FOCUSED;
5878 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
5879 ok(ret == TRUE, "got %d\n", ret);
5880 ret = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
5881 ok(ret == TRUE, "got %d\n", ret);
5882 /* next item gets focus */
5883 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5884 ok(state == LVIS_FOCUSED, "got %x\n", state);
5886 /* focus last item and delete it */
5887 item.stateMask = LVIS_FOCUSED;
5888 item.state = LVIS_FOCUSED;
5889 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
5890 ok(ret == TRUE, "got %d\n", ret);
5891 ret = SendMessageA(hwnd, LVM_DELETEITEM, 3, 0);
5892 ok(ret == TRUE, "got %d\n", ret);
5893 /* new last item gets focus */
5894 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5895 ok(state == LVIS_FOCUSED, "got %x\n", state);
5897 /* focus first item and delete it */
5898 item.stateMask = LVIS_FOCUSED;
5899 item.state = LVIS_FOCUSED;
5900 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
5901 ok(ret == TRUE, "got %d\n", ret);
5902 ret = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
5903 ok(ret == TRUE, "got %d\n", ret);
5904 /* new first item gets focus */
5905 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5906 ok(state == LVIS_FOCUSED, "got %x\n", state);
5908 g_focus_test_LVN_DELETEITEM = FALSE;
5910 DestroyWindow(hwnd);
5913 static void test_insertitem(void)
5915 LVITEMA item;
5916 UINT state;
5917 HWND hwnd;
5918 INT ret;
5920 hwnd = create_listview_control(LVS_REPORT);
5922 /* insert item 0 focused */
5923 item.mask = LVIF_STATE;
5924 item.state = LVIS_FOCUSED;
5925 item.stateMask = LVIS_FOCUSED;
5926 item.iItem = 0;
5927 item.iSubItem = 0;
5928 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5929 ok(ret == 0, "got %d\n", ret);
5931 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5932 ok(state == LVIS_FOCUSED, "got %x\n", state);
5934 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5936 /* insert item 1, focus shift */
5937 item.mask = LVIF_STATE;
5938 item.state = LVIS_FOCUSED;
5939 item.stateMask = LVIS_FOCUSED;
5940 item.iItem = 1;
5941 item.iSubItem = 0;
5942 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5943 ok(ret == 1, "got %d\n", ret);
5945 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused_seq, "insert focused", TRUE);
5947 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5948 ok(state == LVIS_FOCUSED, "got %x\n", state);
5950 /* insert item 2, no focus shift */
5951 item.mask = LVIF_STATE;
5952 item.state = 0;
5953 item.stateMask = LVIS_FOCUSED;
5954 item.iItem = 2;
5955 item.iSubItem = 0;
5956 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5957 ok(ret == 2, "got %d\n", ret);
5959 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5960 ok(state == LVIS_FOCUSED, "got %x\n", state);
5962 DestroyWindow(hwnd);
5965 static void test_header_proc(void)
5967 HWND hwnd, header, hdr;
5968 WNDPROC proc1, proc2;
5970 hwnd = create_listview_control(LVS_REPORT);
5972 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5973 ok(header != NULL, "got %p\n", header);
5975 hdr = CreateWindowExA(0, WC_HEADERA, NULL,
5976 WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
5977 0, 0, 0, 0,
5978 NULL, NULL, NULL, NULL);
5979 ok(hdr != NULL, "got %p\n", hdr);
5981 proc1 = (WNDPROC)GetWindowLongPtrW(header, GWLP_WNDPROC);
5982 proc2 = (WNDPROC)GetWindowLongPtrW(hdr, GWLP_WNDPROC);
5983 ok(proc1 == proc2, "got %p, expected %p\n", proc1, proc2);
5985 DestroyWindow(hdr);
5986 DestroyWindow(hwnd);
5989 static void flush_events(void)
5991 MSG msg;
5992 int diff = 200;
5993 int min_timeout = 100;
5994 DWORD time = GetTickCount() + diff;
5996 while (diff > 0)
5998 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
5999 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
6000 diff = time - GetTickCount();
6004 static void test_oneclickactivate(void)
6006 TRACKMOUSEEVENT track;
6007 char item1[] = "item1";
6008 LVITEMA item;
6009 HWND hwnd, fg;
6010 RECT rect;
6011 INT r;
6012 POINT orig_pos;
6014 hwnd = CreateWindowExA(0, WC_LISTVIEWA, "foo", WS_VISIBLE|WS_CHILD|LVS_LIST,
6015 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
6016 ok(hwnd != NULL, "failed to create listview window\n");
6017 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_ONECLICKACTIVATE);
6018 ok(r == 0, "should return zero\n");
6020 SetForegroundWindow(hwndparent);
6021 flush_events();
6022 fg = GetForegroundWindow();
6023 if (fg != hwndparent)
6025 skip("Window is not in the foreground. Skipping oneclickactivate tests.\n");
6026 DestroyWindow(hwnd);
6027 return;
6030 item.mask = LVIF_TEXT;
6031 item.iItem = 0;
6032 item.iSubItem = 0;
6033 item.iImage = 0;
6034 item.pszText = item1;
6035 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
6036 ok(r == 0, "should not fail\n");
6038 GetWindowRect(hwnd, &rect);
6039 GetCursorPos(&orig_pos);
6040 SetCursorPos(rect.left+5, rect.top+5);
6041 flush_events();
6042 r = SendMessageA(hwnd, WM_MOUSEMOVE, MAKELONG(1, 1), 0);
6043 expect(0, r);
6045 track.cbSize = sizeof(track);
6046 track.dwFlags = TME_QUERY;
6047 p_TrackMouseEvent(&track);
6048 ok(track.hwndTrack == hwnd, "hwndTrack != hwnd\n");
6049 ok(track.dwFlags == TME_LEAVE, "dwFlags = %x\n", track.dwFlags);
6051 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
6052 expect(0, r);
6053 r = SendMessageA(hwnd, WM_MOUSEHOVER, MAKELONG(1, 1), 0);
6054 expect(0, r);
6055 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
6056 expect(1, r);
6058 DestroyWindow(hwnd);
6059 SetCursorPos(orig_pos.x, orig_pos.y);
6062 static void test_callback_mask(void)
6064 LVITEMA item;
6065 DWORD mask;
6066 HWND hwnd;
6067 BOOL ret;
6069 hwnd = create_listview_control(LVS_REPORT);
6071 ret = SendMessageA(hwnd, LVM_SETCALLBACKMASK, ~0u, 0);
6072 ok(ret, "got %d\n", ret);
6074 ret = SendMessageA(hwnd, LVM_SETCALLBACKMASK, ~0u, 1);
6075 ok(ret, "got %d\n", ret);
6077 mask = SendMessageA(hwnd, LVM_GETCALLBACKMASK, 0, 0);
6078 ok(mask == ~0u, "got 0x%08x\n", mask);
6080 /* Ask for state, invalid subitem. */
6081 insert_item(hwnd, 0);
6083 ret = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_FOCUSED, 0);
6084 ok(ret, "Failed to set callback mask.\n");
6086 flush_sequences(sequences, NUM_MSG_SEQUENCES);
6088 memset(&item, 0, sizeof(item));
6089 item.iSubItem = 1;
6090 item.mask = LVIF_STATE;
6091 item.stateMask = LVIS_SELECTED;
6092 ret = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
6093 ok(ret, "Failed to get item data.\n");
6095 memset(&item, 0, sizeof(item));
6096 item.mask = LVIF_STATE;
6097 item.stateMask = LVIS_SELECTED;
6098 ret = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
6099 ok(ret, "Failed to get item data.\n");
6101 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "parent seq, callback mask/invalid subitem 1", TRUE);
6103 flush_sequences(sequences, NUM_MSG_SEQUENCES);
6105 memset(&item, 0, sizeof(item));
6106 memset(&g_itema, 0, sizeof(g_itema));
6107 item.iSubItem = 1;
6108 item.mask = LVIF_STATE;
6109 item.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
6110 ret = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
6111 ok(ret, "Failed to get item data.\n");
6112 ok(g_itema.iSubItem == 1, "Unexpected LVN_DISPINFO subitem %d.\n", g_itema.iSubItem);
6113 ok(g_itema.stateMask == LVIS_FOCUSED, "Unexpected state mask %#x.\n", g_itema.stateMask);
6115 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
6116 "parent seq, callback mask/invalid subitem 2", FALSE);
6118 DestroyWindow(hwnd);
6120 /* LVS_OWNERDATA, mask LVIS_FOCUSED */
6121 hwnd = create_listview_control(LVS_REPORT | LVS_OWNERDATA);
6123 mask = SendMessageA(hwnd, LVM_GETCALLBACKMASK, 0, 0);
6124 ok(mask == 0, "Unexpected callback mask %#x.\n", mask);
6126 ret = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_FOCUSED, 0);
6127 ok(ret, "Failed to set callback mask, %d\n", ret);
6129 mask = SendMessageA(hwnd, LVM_GETCALLBACKMASK, 0, 0);
6130 ok(mask == LVIS_FOCUSED, "Unexpected callback mask %#x.\n", mask);
6132 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
6133 ok(ret, "Failed to set item count.\n");
6135 ret = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
6136 ok(ret == -1, "Unexpected selection mark, %d\n", ret);
6138 item.stateMask = LVIS_FOCUSED;
6139 item.state = LVIS_FOCUSED;
6140 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
6141 ok(ret, "Failed to set item state.\n");
6143 flush_sequences(sequences, NUM_MSG_SEQUENCES);
6145 ret = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
6146 todo_wine
6147 ok(ret == 0, "Unexpected focused item, ret %d\n", ret);
6149 ret = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
6150 todo_wine
6151 ok(ret == 0, "Unexpected selection mark, %d\n", ret);
6153 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 0, 0);
6154 ok(ret, "Failed to set item count.\n");
6156 ret = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
6157 ok(ret == -1, "Unexpected focused item, ret %d\n", ret);
6159 ret = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
6160 ok(ret == -1, "Unexpected selection mark, %d\n", ret);
6162 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
6163 ok(ret, "Failed to set item count.\n");
6165 ret = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
6166 ok(ret == -1, "Unexpected focused item, ret %d\n", ret);
6168 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "parent seq, owner data/focus 1", FALSE);
6170 /* LVS_OWNDERDATA, empty mask */
6171 ret = SendMessageA(hwnd, LVM_SETCALLBACKMASK, 0, 0);
6172 ok(ret, "Failed to set callback mask, %d\n", ret);
6174 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
6175 ok(ret, "Failed to set item count.\n");
6177 ret = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
6178 ok(ret == -1, "Unexpected selection mark, %d\n", ret);
6180 item.stateMask = LVIS_FOCUSED;
6181 item.state = LVIS_FOCUSED;
6182 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
6183 ok(ret, "Failed to set item state.\n");
6185 ret = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
6186 ok(ret == 0, "Unexpected selection mark, %d\n", ret);
6188 flush_sequences(sequences, NUM_MSG_SEQUENCES);
6190 ret = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
6191 ok(ret == 0, "Unexpected focused item, ret %d\n", ret);
6193 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 0, 0);
6194 ok(ret, "Failed to set item count.\n");
6196 ret = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
6197 ok(ret == -1, "Unexpected focused item, ret %d\n", ret);
6199 ret = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
6200 todo_wine
6201 ok(ret == -1, "Unexpected selection mark, %d\n", ret);
6203 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
6204 ok(ret, "Failed to set item count.\n");
6206 ret = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
6207 ok(ret == -1, "Unexpected focused item, ret %d\n", ret);
6209 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "parent seq, owner data/focus 2", FALSE);
6211 /* 2 items, focus on index 0, reduce to 1 item. */
6212 flush_sequences(sequences, NUM_MSG_SEQUENCES);
6214 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 2, 0);
6215 ok(ret, "Failed to set item count.\n");
6217 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
6218 ok(ret, "Failed to set item state.\n");
6220 ret = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
6221 ok(ret == 0, "Unexpected focused item, ret %d\n", ret);
6223 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
6224 ok(ret, "Failed to set item count.\n");
6226 ret = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
6227 ok(ret == 0, "Unexpected focused item, ret %d\n", ret);
6229 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_focus_change_ownerdata_seq,
6230 "parent seq, owner data/focus 3", TRUE);
6232 DestroyWindow(hwnd);
6235 static void test_state_image(void)
6237 static const DWORD styles[] =
6239 LVS_ICON,
6240 LVS_REPORT,
6241 LVS_SMALLICON,
6242 LVS_LIST,
6244 int i;
6246 for (i = 0; i < ARRAY_SIZE(styles); i++)
6248 static char text[] = "Item";
6249 static char subtext[] = "Subitem";
6250 char buff[16];
6251 LVITEMA item;
6252 HWND hwnd;
6253 int r;
6255 hwnd = create_listview_control(styles[i]);
6257 insert_column(hwnd, 0);
6258 insert_column(hwnd, 1);
6260 item.mask = LVIF_TEXT | LVIF_PARAM;
6261 item.iItem = 0;
6262 item.iSubItem = 0;
6263 item.pszText = text;
6264 item.lParam = 123456;
6265 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
6266 ok(r == 0, "Failed to insert an item.\n");
6268 item.mask = LVIF_STATE;
6269 item.state = INDEXTOSTATEIMAGEMASK(1) | LVIS_SELECTED | LVIS_FOCUSED;
6270 item.stateMask = LVIS_STATEIMAGEMASK | LVIS_SELECTED | LVIS_FOCUSED;
6271 item.iItem = 0;
6272 item.iSubItem = 0;
6273 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
6274 ok(r, "Failed to set item state.\n");
6276 item.mask = LVIF_TEXT;
6277 item.iItem = 0;
6278 item.iSubItem = 1;
6279 item.pszText = subtext;
6280 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
6281 ok(r, "Failed to set subitem text.\n");
6283 item.mask = LVIF_STATE | LVIF_PARAM;
6284 item.stateMask = ~0u;
6285 item.state = 0;
6286 item.iItem = 0;
6287 item.iSubItem = 0;
6288 item.lParam = 0;
6289 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
6290 ok(r, "Failed to get item state.\n");
6291 ok(item.state == (INDEXTOSTATEIMAGEMASK(1) | LVIS_SELECTED | LVIS_FOCUSED),
6292 "Unexpected item state %#x.\n", item.state);
6293 ok(item.lParam == 123456, "Unexpected lParam %ld.\n", item.lParam);
6295 item.mask = 0;
6296 item.stateMask = ~0u;
6297 item.state = INDEXTOSTATEIMAGEMASK(2);
6298 item.iItem = 0;
6299 item.iSubItem = 1;
6300 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
6301 ok(r, "Failed to get subitem state.\n");
6302 ok(item.state == INDEXTOSTATEIMAGEMASK(2), "Unexpected state %#x.\n", item.state);
6304 item.mask = LVIF_STATE | LVIF_PARAM;
6305 item.stateMask = ~0u;
6306 item.state = INDEXTOSTATEIMAGEMASK(2);
6307 item.iItem = 0;
6308 item.iSubItem = 1;
6309 item.lParam = 0;
6310 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
6311 ok(r, "Failed to get subitem state.\n");
6312 ok(item.state == 0, "Unexpected state %#x.\n", item.state);
6313 ok(item.lParam == 123456, "Unexpected lParam %ld.\n", item.lParam);
6315 item.mask = LVIF_STATE;
6316 item.stateMask = LVIS_FOCUSED;
6317 item.state = 0;
6318 item.iItem = 0;
6319 item.iSubItem = 1;
6320 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
6321 ok(r, "Failed to get subitem state.\n");
6322 ok(item.state == 0, "Unexpected state %#x.\n", item.state);
6324 item.mask = LVIF_STATE;
6325 item.stateMask = ~0u;
6326 item.state = INDEXTOSTATEIMAGEMASK(2);
6327 item.iItem = 0;
6328 item.iSubItem = 2;
6329 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
6330 ok(r, "Failed to get subitem state.\n");
6331 ok(item.state == 0, "Unexpected state %#x.\n", item.state);
6333 item.mask = LVIF_TEXT;
6334 item.iItem = 0;
6335 item.iSubItem = 1;
6336 item.pszText = buff;
6337 item.cchTextMax = sizeof(buff);
6338 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
6339 ok(r, "Failed to get subitem text %d.\n", r);
6340 ok(!strcmp(buff, subtext), "Unexpected subitem text %s.\n", buff);
6342 DestroyWindow(hwnd);
6346 static void test_LVSCW_AUTOSIZE(void)
6348 int width, width2;
6349 HWND hwnd;
6350 BOOL ret;
6352 hwnd = create_listview_control(LVS_REPORT);
6353 ok(hwnd != NULL, "failed to create a listview window\n");
6355 insert_column(hwnd, 0);
6356 insert_column(hwnd, 1);
6357 insert_item(hwnd, 0);
6359 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, LVSCW_AUTOSIZE);
6360 ok(ret, "Failed to set column width.\n");
6362 width = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
6363 ok(width > 0, "Unexpected column width %d.\n", width);
6365 /* Turn on checkboxes. */
6366 ret = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
6367 ok(ret == 0, "Unexpected previous extended style.\n");
6369 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, LVSCW_AUTOSIZE);
6370 ok(ret, "Failed to set column width.\n");
6372 width2 = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
6373 ok(width2 > 0, "Unexpected column width %d.\n", width2);
6374 ok(width2 > width, "Expected increased column width.\n");
6376 /* Turn off checkboxes. */
6377 ret = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
6378 ok(ret == LVS_EX_CHECKBOXES, "Unexpected previous extended style.\n");
6380 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, LVSCW_AUTOSIZE);
6381 ok(ret, "Failed to set column width.\n");
6383 width = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
6384 ok(width > 0, "Unexpected column width %d.\n", width2);
6385 ok(width2 > width, "Expected reduced column width.\n");
6387 DestroyWindow(hwnd);
6390 static void test_LVN_ENDLABELEDIT(void)
6392 WCHAR text[] = {'l','a','l','a',0};
6393 HWND hwnd, hwndedit;
6394 LVITEMW item = {0};
6395 DWORD ret;
6397 hwnd = create_listview_control(LVS_REPORT | LVS_EDITLABELS);
6399 insert_column(hwnd, 0);
6401 item.mask = LVIF_TEXT;
6402 item.pszText = text;
6403 SendMessageW(hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item);
6405 /* Test normal editing */
6406 SetFocus(hwnd);
6407 hwndedit = (HWND)SendMessageW(hwnd, LVM_EDITLABELW, 0, 0);
6408 ok(hwndedit != NULL, "Failed to get edit control.\n");
6410 ret = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)"test");
6411 ok(ret, "Failed to set edit text.\n");
6413 flush_sequences(sequences, NUM_MSG_SEQUENCES);
6415 ret = SendMessageA(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
6416 ok_sequence(sequences, PARENT_SEQ_INDEX, listview_end_label_edit, "Label edit", FALSE);
6418 /* Test editing with kill focus */
6419 SetFocus(hwnd);
6420 hwndedit = (HWND)SendMessageW(hwnd, LVM_EDITLABELW, 0, 0);
6421 ok(hwndedit != NULL, "Failed to get edit control.\n");
6423 ret = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)"test2");
6424 ok(ret, "Failed to set edit text.\n");
6426 flush_sequences(sequences, NUM_MSG_SEQUENCES);
6428 g_WM_KILLFOCUS_on_LVN_ENDLABELEDIT = TRUE;
6429 ret = SendMessageA(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
6430 g_WM_KILLFOCUS_on_LVN_ENDLABELEDIT = FALSE;
6432 ok_sequence(sequences, PARENT_SEQ_INDEX, listview_end_label_edit_kill_focus,
6433 "Label edit, kill focus", FALSE);
6434 ok(GetFocus() == hwnd, "Unexpected focused window.\n");
6436 flush_sequences(sequences, NUM_MSG_SEQUENCES);
6438 DestroyWindow(hwnd);
6441 static LRESULT CALLBACK create_item_height_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
6443 if (msg == WM_CREATE)
6444 return 0;
6446 return CallWindowProcA(listviewWndProc, hwnd, msg, wParam, lParam);
6449 static void test_LVM_GETCOUNTPERPAGE(void)
6451 static const DWORD styles[] = { LVS_ICON, LVS_LIST, LVS_REPORT, LVS_SMALLICON };
6452 unsigned int i, j;
6453 WNDCLASSEXA cls;
6454 ATOM class;
6455 HWND hwnd;
6456 BOOL ret;
6458 cls.cbSize = sizeof(WNDCLASSEXA);
6459 ret = GetClassInfoExA(GetModuleHandleA(NULL), WC_LISTVIEWA, &cls);
6460 ok(ret, "Failed to get class info.\n");
6461 listviewWndProc = cls.lpfnWndProc;
6462 cls.lpfnWndProc = create_item_height_wndproc;
6463 cls.lpszClassName = "CountPerPageClass";
6464 class = RegisterClassExA(&cls);
6465 ok(class, "Failed to register class.\n");
6467 for (i = 0; i < ARRAY_SIZE(styles); i++)
6469 static char text[] = "item text";
6470 LVITEMA item = { 0 };
6471 UINT count, count2;
6473 hwnd = create_listview_control(styles[i]);
6474 ok(hwnd != NULL, "Failed to create listview window.\n");
6476 count = SendMessageA(hwnd, LVM_GETCOUNTPERPAGE, 0, 0);
6477 if (styles[i] == LVS_LIST || styles[i] == LVS_REPORT)
6478 ok(count > 0 || broken(styles[i] == LVS_LIST && count == 0), "%u: unexpected count %u.\n", i, count);
6479 else
6480 ok(count == 0, "%u: unexpected count %u.\n", i, count);
6482 for (j = 0; j < 10; j++)
6484 item.mask = LVIF_TEXT;
6485 item.pszText = text;
6486 SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
6489 count2 = SendMessageA(hwnd, LVM_GETCOUNTPERPAGE, 0, 0);
6490 if (styles[i] == LVS_LIST || styles[i] == LVS_REPORT)
6491 ok(count == count2, "%u: unexpected count %u.\n", i, count2);
6492 else
6493 ok(count2 == 10, "%u: unexpected count %u.\n", i, count2);
6495 DestroyWindow(hwnd);
6497 hwnd = CreateWindowA("CountPerPageClass", "Test", WS_VISIBLE | styles[i], 0, 0, 100, 100, NULL, NULL,
6498 GetModuleHandleA(NULL), 0);
6499 ok(hwnd != NULL, "Failed to create a window.\n");
6501 count = SendMessageA(hwnd, LVM_GETCOUNTPERPAGE, 0, 0);
6502 ok(count == 0, "%u: unexpected count %u.\n", i, count);
6504 DestroyWindow(hwnd);
6507 ret = UnregisterClassA("CountPerPageClass", NULL);
6508 ok(ret, "Failed to unregister test class.\n");
6511 static void test_item_state_change(void)
6513 static const DWORD styles[] = { LVS_ICON, LVS_LIST, LVS_REPORT, LVS_SMALLICON };
6514 LVITEMA item;
6515 HWND hwnd;
6516 DWORD res;
6517 int i;
6519 for (i = 0; i < ARRAY_SIZE(styles); i++)
6521 hwnd = create_listview_control(styles[i]);
6523 insert_item(hwnd, 0);
6525 /* LVM_SETITEMSTATE with mask */
6526 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
6527 memset(&item, 0, sizeof(item));
6528 item.mask = LVIF_STATE;
6529 item.stateMask = LVIS_SELECTED;
6530 item.state = LVIS_SELECTED;
6531 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
6532 ok(res, "Failed to set item state.\n");
6534 ok(g_nmlistview.iItem == item.iItem, "Unexpected item %d.\n", g_nmlistview.iItem);
6535 ok(g_nmlistview.iSubItem == item.iSubItem, "Unexpected subitem %d.\n", g_nmlistview.iSubItem);
6536 ok(g_nmlistview.lParam == item.lParam, "Unexpected lParam.\n");
6537 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
6538 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
6539 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
6541 /* LVM_SETITEMSTATE 0 mask */
6542 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
6543 memset(&item, 0, sizeof(item));
6544 item.stateMask = LVIS_SELECTED;
6545 item.state = 0;
6546 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
6547 ok(res, "Failed to set item state.\n");
6549 ok(g_nmlistview.iItem == item.iItem, "Unexpected item %d.\n", g_nmlistview.iItem);
6550 ok(g_nmlistview.iSubItem == item.iSubItem, "Unexpected subitem %d.\n", g_nmlistview.iSubItem);
6551 ok(g_nmlistview.lParam == item.lParam, "Unexpected lParam.\n");
6552 ok(g_nmlistview.uNewState == 0, "Unexpected new state %#x.\n", g_nmlistview.uNewState);
6553 ok(g_nmlistview.uOldState == LVIS_SELECTED, "Unexpected old state %#x.\n", g_nmlistview.uOldState);
6554 ok(g_nmlistview.uChanged == LVIF_STATE, "Unexpected change mask %#x.\n", g_nmlistview.uChanged);
6556 /* LVM_SETITEM changes state */
6557 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
6558 memset(&item, 0, sizeof(item));
6559 item.stateMask = LVIS_SELECTED;
6560 item.state = LVIS_SELECTED;
6561 item.mask = LVIF_STATE;
6562 res = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
6563 ok(res, "Failed to set item.\n");
6565 ok(g_nmlistview.iItem == item.iItem, "Unexpected item %d.\n", g_nmlistview.iItem);
6566 ok(g_nmlistview.iSubItem == item.iSubItem, "Unexpected subitem %d.\n", g_nmlistview.iSubItem);
6567 ok(g_nmlistview.lParam == item.lParam, "Unexpected lParam.\n");
6568 ok(g_nmlistview.uNewState == LVIS_SELECTED, "Unexpected new state %#x.\n", g_nmlistview.uNewState);
6569 ok(g_nmlistview.uOldState == 0, "Unexpected old state %#x.\n", g_nmlistview.uOldState);
6570 ok(g_nmlistview.uChanged == LVIF_STATE, "Unexpected change mask %#x.\n", g_nmlistview.uChanged);
6572 /* LVM_SETITEM no state changes */
6573 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
6574 memset(&item, 0, sizeof(item));
6575 item.lParam = 11;
6576 item.mask = LVIF_PARAM;
6577 res = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
6578 ok(res, "Failed to set item.\n");
6580 ok(g_nmlistview.iItem == item.iItem, "Unexpected item %d.\n", g_nmlistview.iItem);
6581 ok(g_nmlistview.iSubItem == item.iSubItem, "Unexpected subitem %d.\n", g_nmlistview.iSubItem);
6582 ok(g_nmlistview.lParam == item.lParam, "Unexpected lParam.\n");
6583 ok(g_nmlistview.uNewState == 0, "Unexpected new state %#x.\n", g_nmlistview.uNewState);
6584 ok(g_nmlistview.uOldState == 0, "Unexpected old state %#x.\n", g_nmlistview.uOldState);
6585 ok(g_nmlistview.uChanged == LVIF_PARAM, "Unexpected change mask %#x.\n", g_nmlistview.uChanged);
6587 DestroyWindow(hwnd);
6591 static void test_selected_column(void)
6593 static const DWORD styles[] = { LVS_ICON, LVS_LIST, LVS_REPORT, LVS_SMALLICON };
6594 int ret, i;
6595 HWND hwnd;
6597 for (i = 0; i < ARRAY_SIZE(styles); ++i)
6599 hwnd = create_listview_control(styles[i]);
6601 /* Initial value */
6602 ret = SendMessageA(hwnd, LVM_GETSELECTEDCOLUMN, 0, 0);
6603 ok(ret == -1, "Unexpected column %d.\n", ret);
6605 ret = SendMessageA(hwnd, LVM_SETSELECTEDCOLUMN, -100, 0);
6606 ok(ret == 1, "Unexpected return value %d.\n", ret);
6608 ret = SendMessageA(hwnd, LVM_GETSELECTEDCOLUMN, 0, 0);
6609 ok(ret == -100, "Unexpected column %d.\n", ret);
6611 ret = SendMessageA(hwnd, LVM_SETSELECTEDCOLUMN, 100, 0);
6612 ok(ret == 1, "Unexpected return value %d.\n", ret);
6614 ret = SendMessageA(hwnd, LVM_GETSELECTEDCOLUMN, 0, 0);
6615 ok(ret == 100, "Unexpected column %d.\n", ret);
6617 ret = SendMessageA(hwnd, LVM_SETSELECTEDCOLUMN, -1, 0);
6618 ok(ret == 1, "Unexpected return value %d.\n", ret);
6620 ret = SendMessageA(hwnd, LVM_GETSELECTEDCOLUMN, 0, 0);
6621 ok(ret == -1, "Unexpected column %d.\n", ret);
6623 DestroyWindow(hwnd);
6627 START_TEST(listview)
6629 ULONG_PTR ctx_cookie;
6630 HANDLE hCtx;
6632 init_functions();
6634 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
6636 hwndparent = create_parent_window(FALSE);
6637 flush_sequences(sequences, NUM_MSG_SEQUENCES);
6639 test_header_notification();
6640 test_header_notification2();
6641 test_images();
6642 test_checkboxes();
6643 test_items();
6644 test_create(FALSE);
6645 test_redraw();
6646 test_customdraw();
6647 test_icon_spacing();
6648 test_color();
6649 test_item_count();
6650 test_item_position();
6651 test_columns();
6652 test_getorigin();
6653 test_multiselect();
6654 test_getitemrect();
6655 test_subitem_rect();
6656 test_sorting();
6657 test_ownerdata();
6658 test_norecompute();
6659 test_nosortheader();
6660 test_setredraw();
6661 test_hittest();
6662 test_getviewrect();
6663 test_getitemposition();
6664 test_editbox();
6665 test_notifyformat();
6666 test_indentation();
6667 test_getitemspacing();
6668 test_getcolumnwidth();
6669 test_approximate_viewrect();
6670 test_finditem();
6671 test_hover();
6672 test_destroynotify();
6673 test_createdragimage();
6674 test_dispinfo();
6675 test_LVM_SETITEMTEXT();
6676 test_LVM_REDRAWITEMS();
6677 test_imagelists();
6678 test_deleteitem();
6679 test_insertitem();
6680 test_header_proc();
6681 test_oneclickactivate();
6682 test_callback_mask();
6683 test_state_image();
6684 test_LVSCW_AUTOSIZE();
6685 test_LVN_ENDLABELEDIT();
6686 test_LVM_GETCOUNTPERPAGE();
6687 test_item_state_change();
6689 if (!load_v6_module(&ctx_cookie, &hCtx))
6691 DestroyWindow(hwndparent);
6692 return;
6695 init_functions();
6697 /* comctl32 version 6 tests start here */
6698 test_get_set_view();
6699 test_canceleditlabel();
6700 test_mapidindex();
6701 test_scrollnotify();
6702 test_LVS_EX_TRANSPARENTBKGND();
6703 test_LVS_EX_HEADERINALLVIEWS();
6704 test_deleteitem();
6705 test_multiselect();
6706 test_insertitem();
6707 test_header_proc();
6708 test_images();
6709 test_checkboxes();
6710 test_items();
6711 test_create(TRUE);
6712 test_color();
6713 test_columns();
6714 test_sorting();
6715 test_ownerdata();
6716 test_norecompute();
6717 test_nosortheader();
6718 test_indentation();
6719 test_finditem();
6720 test_hover();
6721 test_destroynotify();
6722 test_createdragimage();
6723 test_dispinfo();
6724 test_LVM_SETITEMTEXT();
6725 test_LVM_REDRAWITEMS();
6726 test_oneclickactivate();
6727 test_state_image();
6728 test_LVSCW_AUTOSIZE();
6729 test_LVN_ENDLABELEDIT();
6730 test_LVM_GETCOUNTPERPAGE();
6731 test_item_state_change();
6732 test_selected_column();
6734 unload_v6_module(ctx_cookie, hCtx);
6736 DestroyWindow(hwndparent);