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 <wine/test.h>
26 //#include <windows.h>
36 PARENT_FULL_SEQ_INDEX
,
47 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
48 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
49 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
51 static const WCHAR testparentclassW
[] =
52 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
54 static HWND hwndparent
, hwndparentW
;
55 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
56 static BOOL blockEdit
;
57 /* return nonzero on NM_HOVER */
58 static BOOL g_block_hover
;
59 /* notification data for LVN_ITEMCHANGED */
60 static NMLISTVIEW g_nmlistview
;
61 /* notification data for LVN_ITEMCHANGING */
62 static NMLISTVIEW g_nmlistview_changing
;
63 /* format reported to control:
64 -1 falls to defproc, anything else returned */
65 static INT notifyFormat
;
66 /* indicates we're running < 5.80 version */
67 static BOOL g_is_below_5
;
68 /* item data passed to LVN_GETDISPINFOA */
69 static LVITEMA g_itema
;
70 /* alter notification code A->W */
71 static BOOL g_disp_A_to_W
;
72 /* dispinfo data sent with LVN_LVN_ENDLABELEDIT */
73 static NMLVDISPINFOA g_editbox_disp_info
;
74 /* when this is set focus will be tested on LVN_DELETEITEM */
75 static BOOL g_focus_test_LVN_DELETEITEM
;
77 static HWND
subclass_editbox(HWND hwndListview
);
79 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
81 static const struct message create_ownerdrawfixed_parent_seq
[] = {
82 { WM_NOTIFYFORMAT
, sent
},
83 { WM_QUERYUISTATE
, sent
|optional
}, /* Win2K and higher */
84 { WM_MEASUREITEM
, sent
},
85 { WM_PARENTNOTIFY
, sent
},
89 static const struct message redraw_listview_seq
[] = {
90 { WM_PAINT
, sent
|id
, 0, 0, LISTVIEW_ID
},
91 { WM_PAINT
, sent
|id
, 0, 0, HEADER_ID
},
92 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
93 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, HEADER_ID
},
94 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
95 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
96 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, LISTVIEW_ID
},
100 static const struct message listview_icon_spacing_seq
[] = {
101 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(20, 30) },
102 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(25, 35) },
103 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(-1, -1) },
107 static const struct message listview_color_seq
[] = {
108 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
109 { LVM_GETBKCOLOR
, sent
},
110 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
111 { LVM_GETTEXTCOLOR
, sent
},
112 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
113 { LVM_GETTEXTBKCOLOR
, sent
},
115 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
116 { LVM_GETBKCOLOR
, sent
},
117 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
118 { LVM_GETTEXTCOLOR
, sent
},
119 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
120 { LVM_GETTEXTBKCOLOR
, sent
},
122 { LVM_SETBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
123 { LVM_GETBKCOLOR
, sent
},
124 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, CLR_NONE
},
125 { LVM_GETTEXTCOLOR
, sent
},
126 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
127 { LVM_GETTEXTBKCOLOR
, sent
},
129 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
130 { LVM_GETBKCOLOR
, sent
},
131 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
132 { LVM_GETTEXTCOLOR
, sent
},
133 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
134 { LVM_GETTEXTBKCOLOR
, sent
},
138 static const struct message listview_item_count_seq
[] = {
139 { LVM_GETITEMCOUNT
, sent
},
140 { LVM_INSERTITEMA
, sent
},
141 { LVM_INSERTITEMA
, sent
},
142 { LVM_INSERTITEMA
, sent
},
143 { LVM_GETITEMCOUNT
, sent
},
144 { LVM_DELETEITEM
, sent
|wparam
, 2 },
145 { WM_NCPAINT
, sent
|optional
},
146 { WM_ERASEBKGND
, sent
|optional
},
147 { LVM_GETITEMCOUNT
, sent
},
148 { LVM_DELETEALLITEMS
, sent
},
149 { LVM_GETITEMCOUNT
, sent
},
150 { LVM_INSERTITEMA
, sent
},
151 { LVM_INSERTITEMA
, sent
},
152 { LVM_GETITEMCOUNT
, sent
},
153 { LVM_INSERTITEMA
, sent
},
154 { LVM_GETITEMCOUNT
, sent
},
158 static const struct message listview_itempos_seq
[] = {
159 { LVM_INSERTITEMA
, sent
},
160 { LVM_INSERTITEMA
, sent
},
161 { LVM_INSERTITEMA
, sent
},
162 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 1, MAKELPARAM(10,5) },
163 { WM_NCPAINT
, sent
|optional
},
164 { WM_ERASEBKGND
, sent
|optional
},
165 { LVM_GETITEMPOSITION
, sent
|wparam
, 1 },
166 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 2, MAKELPARAM(0,0) },
167 { LVM_GETITEMPOSITION
, sent
|wparam
, 2 },
168 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 0, MAKELPARAM(20,20) },
169 { LVM_GETITEMPOSITION
, sent
|wparam
, 0 },
173 static const struct message listview_ownerdata_switchto_seq
[] = {
174 { WM_STYLECHANGING
, sent
},
175 { WM_STYLECHANGED
, sent
},
179 static const struct message listview_getorderarray_seq
[] = {
180 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
181 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
182 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 0, 0, LISTVIEW_ID
},
183 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 0, 0, HEADER_ID
},
187 static const struct message listview_setorderarray_seq
[] = {
188 { LVM_SETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
189 { HDM_SETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
190 { LVM_SETCOLUMNORDERARRAY
, sent
|id
|wparam
, 0, 0, LISTVIEW_ID
},
191 { HDM_SETORDERARRAY
, sent
|id
|wparam
, 0, 0, HEADER_ID
},
195 static const struct message empty_seq
[] = {
199 static const struct message forward_erasebkgnd_parent_seq
[] = {
200 { WM_ERASEBKGND
, sent
},
204 static const struct message ownerdata_select_focus_parent_seq
[] = {
205 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
206 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
207 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
}, /* version 4.7x */
211 static const struct message ownerdata_setstate_all_parent_seq
[] = {
212 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
216 static const struct message ownerdata_defocus_all_parent_seq
[] = {
217 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
218 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
219 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
},
220 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
224 static const struct message ownerdata_deselect_all_parent_seq
[] = {
225 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ODCACHEHINT
},
226 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
230 static const struct message change_all_parent_seq
[] = {
231 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
232 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
234 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
235 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
237 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
238 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
240 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
241 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
243 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
244 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
248 static const struct message changing_all_parent_seq
[] = {
249 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
250 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
251 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
252 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
253 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
257 static const struct message textcallback_set_again_parent_seq
[] = {
258 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
259 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
263 static const struct message single_getdispinfo_parent_seq
[] = {
264 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
268 static const struct message getitemposition_seq1
[] = {
269 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
273 static const struct message getitemposition_seq2
[] = {
274 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
275 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
279 static const struct message getsubitemrect_seq
[] = {
280 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, -1, 0, LISTVIEW_ID
},
281 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
282 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, 0, 0, LISTVIEW_ID
},
283 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
284 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, -10, 0, LISTVIEW_ID
},
285 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
286 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, 20, 0, LISTVIEW_ID
},
287 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
291 static const struct message editbox_create_pos
[] = {
292 /* sequence sent after LVN_BEGINLABELEDIT */
293 /* next two are 4.7x specific */
294 { WM_WINDOWPOSCHANGING
, sent
},
295 { WM_WINDOWPOSCHANGED
, sent
|optional
},
297 { WM_WINDOWPOSCHANGING
, sent
|optional
},
298 { WM_NCCALCSIZE
, sent
},
299 { WM_WINDOWPOSCHANGED
, sent
},
300 { WM_MOVE
, sent
|defwinproc
},
301 { WM_SIZE
, sent
|defwinproc
},
302 /* the rest is todo, skipped in 4.7x */
303 { WM_WINDOWPOSCHANGING
, sent
|optional
},
304 { WM_WINDOWPOSCHANGED
, sent
|optional
},
308 static const struct message scroll_parent_seq
[] = {
309 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_BEGINSCROLL
},
310 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDSCROLL
},
314 static const struct message setredraw_seq
[] = {
315 { WM_SETREDRAW
, sent
|id
|wparam
, FALSE
, 0, LISTVIEW_ID
},
319 static const struct message lvs_ex_transparentbkgnd_seq
[] = {
320 { WM_PRINTCLIENT
, sent
|lparam
, 0, PRF_ERASEBKGND
},
324 static const struct message edit_end_nochange
[] = {
325 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDLABELEDITA
},
326 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
}, /* todo */
327 { WM_NOTIFY
, sent
|id
, 0, 0, NM_SETFOCUS
},
331 static const struct message hover_parent
[] = {
332 { WM_GETDLGCODE
, sent
}, /* todo_wine */
333 { WM_NOTIFY
, sent
|id
, 0, 0, NM_HOVER
},
337 static const struct message listview_destroy
[] = {
338 { 0x0090, sent
|optional
}, /* Vista */
339 { WM_PARENTNOTIFY
, sent
},
340 { WM_SHOWWINDOW
, sent
},
341 { WM_WINDOWPOSCHANGING
, sent
},
342 { WM_WINDOWPOSCHANGED
, sent
|optional
},
343 { WM_DESTROY
, sent
},
344 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_DELETEALLITEMS
},
345 { WM_NCDESTROY
, sent
},
349 static const struct message listview_ownerdata_destroy
[] = {
350 { 0x0090, sent
|optional
}, /* Vista */
351 { WM_PARENTNOTIFY
, sent
},
352 { WM_SHOWWINDOW
, sent
},
353 { WM_WINDOWPOSCHANGING
, sent
},
354 { WM_WINDOWPOSCHANGED
, sent
|optional
},
355 { WM_DESTROY
, sent
},
356 { WM_NCDESTROY
, sent
},
360 static const struct message listview_ownerdata_deleteall
[] = {
361 { LVM_DELETEALLITEMS
, sent
},
362 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_DELETEALLITEMS
},
366 static const struct message listview_header_changed_seq
[] = {
367 { LVM_SETCOLUMNA
, sent
},
368 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
369 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
373 static const struct message parent_header_click_seq
[] = {
374 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_COLUMNCLICK
},
375 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCLICKA
},
379 static const struct message parent_header_divider_dclick_seq
[] = {
380 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCHANGINGA
},
381 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
},
382 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
},
383 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCHANGEDA
},
384 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_DIVIDERDBLCLICKA
},
388 static const struct message listview_set_imagelist
[] = {
389 { LVM_SETIMAGELIST
, sent
|id
, 0, 0, LISTVIEW_ID
},
393 static const struct message listview_header_set_imagelist
[] = {
394 { LVM_SETIMAGELIST
, sent
|id
, 0, 0, LISTVIEW_ID
},
395 { HDM_SETIMAGELIST
, sent
|id
, 0, 0, HEADER_ID
},
399 static const struct message parent_insert_focused_seq
[] = {
400 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
401 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
402 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
403 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
404 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_INSERTITEM
},
408 static const struct message parent_report_cd_seq
[] = {
409 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_PREPAINT
},
410 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
},
411 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
|CDDS_SUBITEM
},
412 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
|CDDS_SUBITEM
},
413 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
|CDDS_SUBITEM
},
414 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
|CDDS_SUBITEM
},
415 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
},
416 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_POSTPAINT
},
420 static const struct message parent_list_cd_seq
[] = {
421 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_PREPAINT
},
422 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
},
423 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
},
424 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_POSTPAINT
},
428 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
430 static LONG defwndproc_counter
= 0;
434 msg
.message
= message
;
435 msg
.flags
= sent
|wparam
|lparam
;
436 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
439 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
441 /* log system messages, except for painting */
442 if (message
< WM_USER
&&
443 message
!= WM_PAINT
&&
444 message
!= WM_ERASEBKGND
&&
445 message
!= WM_NCPAINT
&&
446 message
!= WM_NCHITTEST
&&
447 message
!= WM_GETTEXT
&&
448 message
!= WM_GETICON
&&
449 message
!= WM_DEVICECHANGE
)
451 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
452 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
454 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
460 switch (((NMHDR
*)lParam
)->code
)
462 case LVN_BEGINLABELEDITA
:
466 /* subclass edit box */
468 edit
= subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
472 INT len
= SendMessageA(edit
, EM_GETLIMITTEXT
, 0, 0);
473 ok(len
== 259 || broken(len
== 260) /* includes NULL in NT4 */,
474 "text limit %d, expected 259\n", len
);
479 case LVN_ENDLABELEDITA
:
483 /* always accept new item text */
484 NMLVDISPINFOA
*di
= (NMLVDISPINFOA
*)lParam
;
485 g_editbox_disp_info
= *di
;
486 trace("LVN_ENDLABELEDIT: text=%s\n", di
->item
.pszText
? di
->item
.pszText
: "(null)");
488 /* edit control still available from this notification */
489 edit
= (HWND
)SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETEDITCONTROL
, 0, 0);
490 ok(IsWindow(edit
), "expected valid edit control handle\n");
491 ok((GetWindowLongA(edit
, GWL_STYLE
) & ES_MULTILINE
) == 0, "edit is multiline\n");
495 case LVN_BEGINSCROLL
:
498 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
500 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
501 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
504 case LVN_ITEMCHANGING
:
506 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
507 g_nmlistview_changing
= *nmlv
;
510 case LVN_ITEMCHANGED
:
512 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
513 g_nmlistview
= *nmlv
;
516 case LVN_GETDISPINFOA
:
518 NMLVDISPINFOA
*dispinfo
= (NMLVDISPINFOA
*)lParam
;
519 g_itema
= dispinfo
->item
;
521 if (g_disp_A_to_W
&& (dispinfo
->item
.mask
& LVIF_TEXT
))
523 static const WCHAR testW
[] = {'T','E','S','T',0};
524 dispinfo
->hdr
.code
= LVN_GETDISPINFOW
;
525 memcpy(dispinfo
->item
.pszText
, testW
, sizeof(testW
));
528 /* test control buffer size for text, 10 used to mask cases when control
529 is using caller buffer to process LVM_GETITEM for example */
530 if (dispinfo
->item
.mask
& LVIF_TEXT
&& dispinfo
->item
.cchTextMax
> 10)
531 ok(dispinfo
->item
.cchTextMax
== 260 ||
532 broken(dispinfo
->item
.cchTextMax
== 264) /* NT4 reports aligned size */,
533 "buffer size %d\n", dispinfo
->item
.cchTextMax
);
537 if (g_focus_test_LVN_DELETEITEM
)
539 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
542 state
= SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETITEMSTATE
, nmlv
->iItem
, LVIS_FOCUSED
);
543 ok(state
== 0, "got state %x\n", state
);
547 if (g_block_hover
) return 1;
552 case WM_NOTIFYFORMAT
:
554 /* force to return format */
555 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
560 defwndproc_counter
++;
561 if (IsWindowUnicode(hwnd
))
562 ret
= DefWindowProcW(hwnd
, message
, wParam
, lParam
);
564 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
565 defwndproc_counter
--;
570 static BOOL
register_parent_wnd_class(BOOL Unicode
)
578 clsW
.lpfnWndProc
= parent_wnd_proc
;
581 clsW
.hInstance
= GetModuleHandleW(NULL
);
583 clsW
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
584 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
585 clsW
.lpszMenuName
= NULL
;
586 clsW
.lpszClassName
= testparentclassW
;
591 clsA
.lpfnWndProc
= parent_wnd_proc
;
594 clsA
.hInstance
= GetModuleHandleA(NULL
);
596 clsA
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
597 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
598 clsA
.lpszMenuName
= NULL
;
599 clsA
.lpszClassName
= "Listview test parent class";
602 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
605 static HWND
create_parent_window(BOOL Unicode
)
607 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
610 if (!register_parent_wnd_class(Unicode
))
617 hwnd
= CreateWindowExW(0, testparentclassW
, nameW
,
618 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
619 WS_MAXIMIZEBOX
| WS_VISIBLE
,
621 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
623 hwnd
= CreateWindowExA(0, "Listview test parent class",
624 "Listview test parent window",
625 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
626 WS_MAXIMIZEBOX
| WS_VISIBLE
,
628 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
629 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
633 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
635 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
636 static LONG defwndproc_counter
= 0;
640 /* some debug output for style changing */
641 if ((message
== WM_STYLECHANGING
||
642 message
== WM_STYLECHANGED
) && lParam
)
644 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
645 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
648 msg
.message
= message
;
649 msg
.flags
= sent
|wparam
|lparam
;
650 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
653 msg
.id
= LISTVIEW_ID
;
654 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
655 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
657 defwndproc_counter
++;
658 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
659 defwndproc_counter
--;
663 static HWND
create_listview_control(DWORD style
)
669 GetClientRect(hwndparent
, &rect
);
670 hwnd
= CreateWindowExA(0, WC_LISTVIEWA
, "foo",
671 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
672 0, 0, rect
.right
, rect
.bottom
,
673 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
674 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
676 if (!hwnd
) return NULL
;
678 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
679 (LONG_PTR
)listview_subclass_proc
);
680 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
685 /* unicode listview window with specified parent */
686 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
691 static const WCHAR nameW
[] = {'f','o','o',0};
693 GetClientRect(parent
, &rect
);
694 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
695 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
696 0, 0, rect
.right
, rect
.bottom
,
697 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
698 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
700 if (!hwnd
) return NULL
;
702 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
703 (LONG_PTR
)listview_subclass_proc
);
704 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
709 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
711 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
712 static LONG defwndproc_counter
= 0;
716 msg
.message
= message
;
717 msg
.flags
= sent
|wparam
|lparam
;
718 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
722 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
724 defwndproc_counter
++;
725 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
726 defwndproc_counter
--;
730 static HWND
subclass_header(HWND hwndListview
)
735 hwnd
= (HWND
)SendMessageA(hwndListview
, LVM_GETHEADER
, 0, 0);
736 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
737 (LONG_PTR
)header_subclass_proc
);
738 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
743 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
745 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
746 static LONG defwndproc_counter
= 0;
750 msg
.message
= message
;
751 msg
.flags
= sent
|wparam
|lparam
;
752 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
757 /* all we need is sizing */
758 if (message
== WM_WINDOWPOSCHANGING
||
759 message
== WM_NCCALCSIZE
||
760 message
== WM_WINDOWPOSCHANGED
||
761 message
== WM_MOVE
||
764 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
767 defwndproc_counter
++;
768 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
769 defwndproc_counter
--;
773 static HWND
subclass_editbox(HWND hwndListview
)
778 hwnd
= (HWND
)SendMessageA(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
779 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
780 (LONG_PTR
)editbox_subclass_proc
);
781 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
786 /* Performs a single LVM_HITTEST test */
787 static void test_lvm_hittest_(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
, UINT broken_flags
,
788 BOOL todo_item
, BOOL todo_flags
, int line
)
797 ret
= SendMessageA(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
799 todo_wine_if(todo_item
)
801 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
802 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
803 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
809 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
811 else if (broken_flags
)
812 ok_(__FILE__
, line
)(lpht
.flags
== flags
|| broken(lpht
.flags
== broken_flags
),
813 "Expected flags %x, got %x\n", flags
, lpht
.flags
);
815 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
818 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
820 /* Performs a single LVM_SUBITEMHITTEST test */
821 static void test_lvm_subitemhittest_(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
822 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
830 ret
= SendMessageA(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
832 todo_wine_if(todo_item
)
834 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
835 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
838 todo_wine_if(todo_subitem
)
839 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
841 todo_wine_if(todo_flags
)
842 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
845 #define test_lvm_subitemhittest(a,b,c,d,e,f,g,h,i) test_lvm_subitemhittest_(a,b,c,d,e,f,g,h,i,__LINE__)
847 static void test_images(void)
855 static CHAR hello
[] = "hello";
857 himl
= ImageList_Create(40, 40, 0, 4, 4);
858 ok(himl
!= NULL
, "failed to create imagelist\n");
860 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
861 ok(hbmp
!= NULL
, "failed to create bitmap\n");
863 r
= ImageList_Add(himl
, hbmp
, 0);
864 ok(r
== 0, "should be zero\n");
866 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
867 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
868 ok(hwnd
!= NULL
, "failed to create listview window\n");
870 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
871 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
873 ok(r
== 0, "should return zero\n");
875 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
876 ok(r
== 0, "should return zero\n");
878 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
879 ok(r
!= 0, "got 0\n");
881 /* returns dimensions */
883 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
884 ok(r
== 0, "should be zero items\n");
886 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
891 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
892 ok(r
== -1, "should fail\n");
895 item
.pszText
= hello
;
896 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
897 ok(r
== 0, "should not fail\n");
899 SetRect(&r1
, LVIR_ICON
, 0, 0, 0);
900 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
903 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
904 ok(r
== TRUE
, "should not fail\n");
907 item
.pszText
= hello
;
908 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
909 ok(r
== 0, "should not fail\n");
911 SetRect(&r2
, LVIR_ICON
, 0, 0, 0);
912 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
915 ok(EqualRect(&r1
, &r2
), "rectangle should be the same\n");
920 static void test_checkboxes(void)
925 static CHAR text
[] = "Text",
929 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
930 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
931 ok(hwnd
!= NULL
, "failed to create listview window\n");
933 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
934 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
935 item
.stateMask
= 0xffff;
940 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
944 item
.mask
= LVIF_STATE
;
945 item
.stateMask
= 0xffff;
946 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
948 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
950 /* Don't set LVIF_STATE */
951 item
.mask
= LVIF_TEXT
;
952 item
.stateMask
= 0xffff;
957 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
961 item
.mask
= LVIF_STATE
;
962 item
.stateMask
= 0xffff;
963 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
965 ok(item
.state
== 0, "state %x\n", item
.state
);
967 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
970 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
972 item
.mask
= LVIF_STATE
;
973 item
.stateMask
= 0xffff;
974 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
976 if (item
.state
!= 0x1ccc)
978 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
983 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
985 item
.mask
= LVIF_TEXT
;
987 item
.pszText
= text2
;
988 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
992 item
.mask
= LVIF_STATE
;
993 item
.stateMask
= 0xffff;
994 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
996 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
998 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
1000 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
1001 item
.stateMask
= 0xffff;
1002 item
.state
= 0x2aaa;
1003 item
.pszText
= text3
;
1004 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1008 item
.mask
= LVIF_STATE
;
1009 item
.stateMask
= 0xffff;
1010 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1012 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
1014 /* Set an item's state to checked */
1016 item
.mask
= LVIF_STATE
;
1017 item
.stateMask
= 0xf000;
1018 item
.state
= 0x2000;
1019 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1023 item
.mask
= LVIF_STATE
;
1024 item
.stateMask
= 0xffff;
1025 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1027 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1029 /* Check that only the bits we asked for are returned,
1030 * and that all the others are set to zero
1033 item
.mask
= LVIF_STATE
;
1034 item
.stateMask
= 0xf000;
1035 item
.state
= 0xffff;
1036 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1038 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
1040 /* Set the style again and check that doesn't change an item's state */
1041 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1042 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1045 item
.mask
= LVIF_STATE
;
1046 item
.stateMask
= 0xffff;
1047 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1049 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1051 /* Unsetting the checkbox extended style doesn't change an item's state */
1052 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
1053 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1056 item
.mask
= LVIF_STATE
;
1057 item
.stateMask
= 0xffff;
1058 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1060 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1062 /* Now setting the style again will change an item's state */
1063 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1067 item
.mask
= LVIF_STATE
;
1068 item
.stateMask
= 0xffff;
1069 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1071 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
1073 /* Toggle checkbox tests (bug 9934) */
1074 memset (&item
, 0xcc, sizeof(item
));
1075 item
.mask
= LVIF_STATE
;
1078 item
.state
= LVIS_FOCUSED
;
1079 item
.stateMask
= LVIS_FOCUSED
;
1080 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1084 item
.mask
= LVIF_STATE
;
1085 item
.stateMask
= 0xffff;
1086 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1088 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1090 r
= SendMessageA(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1092 r
= SendMessageA(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1096 item
.mask
= LVIF_STATE
;
1097 item
.stateMask
= 0xffff;
1098 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1100 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
1102 r
= SendMessageA(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1104 r
= SendMessageA(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1108 item
.mask
= LVIF_STATE
;
1109 item
.stateMask
= 0xffff;
1110 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1112 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1114 DestroyWindow(hwnd
);
1117 static void insert_column(HWND hwnd
, int idx
)
1122 memset(&column
, 0xcc, sizeof(column
));
1123 column
.mask
= LVCF_SUBITEM
;
1124 column
.iSubItem
= idx
;
1126 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, idx
, (LPARAM
)&column
);
1130 static void insert_item(HWND hwnd
, int idx
)
1132 static CHAR text
[] = "foo";
1137 memset(&item
, 0xcc, sizeof (item
));
1138 item
.mask
= LVIF_TEXT
;
1141 item
.pszText
= text
;
1143 rc
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
1147 static void test_items(void)
1149 const LPARAM lparamTest
= 0x42;
1150 static CHAR text
[] = "Text";
1156 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1157 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1158 ok(hwnd
!= NULL
, "failed to create listview window\n");
1161 * Test setting/getting item params
1164 /* Set up two columns */
1165 insert_column(hwnd
, 0);
1166 insert_column(hwnd
, 1);
1168 /* LVIS_SELECTED with zero stateMask */
1170 memset (&item
, 0, sizeof (item
));
1171 item
.mask
= LVIF_STATE
;
1172 item
.state
= LVIS_SELECTED
;
1176 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1179 memset (&item
, 0xcc, sizeof (item
));
1180 item
.mask
= LVIF_STATE
;
1181 item
.stateMask
= LVIS_SELECTED
;
1185 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1187 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1188 r
= SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1189 ok(r
, "got %d\n", r
);
1191 /* LVIS_SELECTED with zero stateMask */
1193 memset (&item
, 0, sizeof (item
));
1194 item
.mask
= LVIF_STATE
;
1195 item
.state
= LVIS_FOCUSED
;
1199 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1202 memset (&item
, 0xcc, sizeof (item
));
1203 item
.mask
= LVIF_STATE
;
1204 item
.stateMask
= LVIS_FOCUSED
;
1208 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1210 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1211 r
= SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1212 ok(r
, "got %d\n", r
);
1214 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1216 memset (&item
, 0, sizeof (item
));
1217 item
.mask
= LVIF_STATE
;
1218 item
.state
= LVIS_CUT
;
1219 item
.stateMask
= LVIS_FOCUSED
;
1222 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1225 memset (&item
, 0xcc, sizeof (item
));
1226 item
.mask
= LVIF_STATE
;
1227 item
.stateMask
= LVIS_CUT
;
1231 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1233 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1234 r
= SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1235 ok(r
, "got %d\n", r
);
1237 /* Insert an item with just a param */
1238 memset (&item
, 0xcc, sizeof (item
));
1239 item
.mask
= LVIF_PARAM
;
1242 item
.lParam
= lparamTest
;
1243 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1246 /* Test getting of the param */
1247 memset (&item
, 0xcc, sizeof (item
));
1248 item
.mask
= LVIF_PARAM
;
1251 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1253 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1255 /* Set up a subitem */
1256 memset (&item
, 0xcc, sizeof (item
));
1257 item
.mask
= LVIF_TEXT
;
1260 item
.pszText
= text
;
1261 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1264 item
.mask
= LVIF_TEXT
;
1267 item
.pszText
= buffA
;
1268 item
.cchTextMax
= sizeof(buffA
);
1269 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1271 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got text %s, expected %s\n", item
.pszText
, text
);
1273 /* set up with extra flag */
1274 /* 1. reset subitem text */
1275 item
.mask
= LVIF_TEXT
;
1278 item
.pszText
= NULL
;
1279 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1282 item
.mask
= LVIF_TEXT
;
1285 item
.pszText
= buffA
;
1287 item
.cchTextMax
= sizeof(buffA
);
1288 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1290 ok(item
.pszText
[0] == 0, "got %p\n", item
.pszText
);
1292 /* 2. set new text with extra flag specified */
1293 item
.mask
= LVIF_TEXT
| LVIF_DI_SETITEM
;
1296 item
.pszText
= text
;
1297 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1298 ok(r
== 1 || broken(r
== 0) /* NT4 */, "ret %d\n", r
);
1302 item
.mask
= LVIF_TEXT
;
1305 item
.pszText
= buffA
;
1307 item
.cchTextMax
= sizeof(buffA
);
1308 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1310 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got %s, expected %s\n", item
.pszText
, text
);
1313 /* Query param from subitem: returns main item param */
1314 memset (&item
, 0xcc, sizeof (item
));
1315 item
.mask
= LVIF_PARAM
;
1318 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1320 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1322 /* Set up param on first subitem: no effect */
1323 memset (&item
, 0xcc, sizeof (item
));
1324 item
.mask
= LVIF_PARAM
;
1327 item
.lParam
= lparamTest
+1;
1328 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1331 /* Query param from subitem again: should still return main item param */
1332 memset (&item
, 0xcc, sizeof (item
));
1333 item
.mask
= LVIF_PARAM
;
1336 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1338 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1340 /**** Some tests of state highlighting ****/
1341 memset (&item
, 0xcc, sizeof (item
));
1342 item
.mask
= LVIF_STATE
;
1345 item
.state
= LVIS_SELECTED
;
1346 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1347 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1350 item
.state
= LVIS_DROPHILITED
;
1351 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1354 memset (&item
, 0xcc, sizeof (item
));
1355 item
.mask
= LVIF_STATE
;
1358 item
.stateMask
= -1;
1359 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1361 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1363 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1365 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1367 /* some notnull but meaningless masks */
1368 memset (&item
, 0, sizeof(item
));
1369 item
.mask
= LVIF_NORECOMPUTE
;
1372 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1374 memset (&item
, 0, sizeof(item
));
1375 item
.mask
= LVIF_DI_SETITEM
;
1378 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1381 /* set text to callback value already having it */
1382 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1384 memset (&item
, 0, sizeof (item
));
1385 item
.mask
= LVIF_TEXT
;
1386 item
.pszText
= LPSTR_TEXTCALLBACKA
;
1388 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1390 memset (&item
, 0, sizeof (item
));
1392 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1394 item
.pszText
= LPSTR_TEXTCALLBACKA
;
1395 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0 , (LPARAM
) &item
);
1398 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1399 "check callback text comparison rule", FALSE
);
1401 DestroyWindow(hwnd
);
1404 static void test_columns(void)
1413 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_LIST
,
1414 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1415 ok(hwnd
!= NULL
, "failed to create listview window\n");
1417 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
1418 ok(header
== NULL
, "got %p\n", header
);
1420 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1421 ok(rc
== 0, "got %d\n", rc
);
1423 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
1424 ok(header
== NULL
, "got %p\n", header
);
1426 DestroyWindow(hwnd
);
1428 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1429 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1430 ok(hwnd
!= NULL
, "failed to create listview window\n");
1432 rc
= SendMessageA(hwnd
, LVM_DELETECOLUMN
, -1, 0);
1433 ok(!rc
, "got %d\n", rc
);
1435 rc
= SendMessageA(hwnd
, LVM_DELETECOLUMN
, 0, 0);
1436 ok(!rc
, "got %d\n", rc
);
1438 /* Add a column with no mask */
1439 memset(&column
, 0xcc, sizeof(column
));
1441 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1442 ok(rc
== 0, "Inserting column with no mask failed with %d\n", rc
);
1444 /* Check its width */
1445 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
1446 ok(rc
== 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1448 DestroyWindow(hwnd
);
1450 /* LVM_GETCOLUMNORDERARRAY */
1451 hwnd
= create_listview_control(LVS_REPORT
);
1452 subclass_header(hwnd
);
1454 memset(&column
, 0, sizeof(column
));
1455 column
.mask
= LVCF_WIDTH
;
1457 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1461 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&column
);
1464 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1466 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1468 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1469 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1471 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 0, 0);
1474 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1476 /* LVM_SETCOLUMNORDERARRAY */
1477 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1481 rc
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1484 rc
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 0, 0);
1487 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_setorderarray_seq
, "set order array", FALSE
);
1489 /* after column added subitem is considered as present */
1490 insert_item(hwnd
, 0);
1492 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1494 item
.pszText
= buff
;
1495 item
.cchTextMax
= sizeof(buff
);
1498 item
.mask
= LVIF_TEXT
;
1499 memset(&g_itema
, 0, sizeof(g_itema
));
1500 rc
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
1502 ok(g_itema
.iSubItem
== 1, "got %d\n", g_itema
.iSubItem
);
1504 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
1505 "get subitem text after column added", FALSE
);
1507 DestroyWindow(hwnd
);
1510 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1511 static WNDPROC listviewWndProc
;
1512 static HIMAGELIST test_create_imagelist
;
1514 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1518 if (uMsg
== WM_CREATE
)
1520 CREATESTRUCTA
*lpcs
= (CREATESTRUCTA
*)lParam
;
1521 lpcs
->style
|= LVS_REPORT
;
1523 ret
= CallWindowProcA(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1524 if (uMsg
== WM_CREATE
) SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1528 static void test_create(void)
1539 cls
.cbSize
= sizeof(WNDCLASSEXA
);
1540 ok(GetClassInfoExA(GetModuleHandleA(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1541 listviewWndProc
= cls
.lpfnWndProc
;
1542 cls
.lpfnWndProc
= create_test_wndproc
;
1543 cls
.lpszClassName
= "MyListView32";
1544 ok(RegisterClassExA(&cls
), "RegisterClassEx failed\n");
1546 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1547 hList
= CreateWindowA("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1548 ok((HIMAGELIST
)SendMessageA(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1549 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1551 if (!IsWindow(hHeader
))
1554 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1555 DestroyWindow(hList
);
1559 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1560 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1561 DestroyWindow(hList
);
1563 /* header isn't created on LVS_ICON and LVS_LIST styles */
1564 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1565 GetModuleHandleA(NULL
), 0);
1566 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1567 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1568 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1570 memset(&col
, 0, sizeof(LVCOLUMNA
));
1571 col
.mask
= LVCF_WIDTH
;
1573 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1575 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1576 ok(IsWindow(hHeader
), "Header should be created\n");
1577 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1578 style
= GetWindowLongA(hHeader
, GWL_STYLE
);
1579 ok(!(style
& HDS_HIDDEN
), "Not expected HDS_HIDDEN\n");
1580 DestroyWindow(hList
);
1582 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1583 GetModuleHandleA(NULL
), 0);
1584 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1585 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1586 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1588 memset(&col
, 0, sizeof(LVCOLUMNA
));
1589 col
.mask
= LVCF_WIDTH
;
1591 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1593 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1594 ok(IsWindow(hHeader
), "Header should be created\n");
1595 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1596 DestroyWindow(hList
);
1598 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1599 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1600 GetModuleHandleA(NULL
), 0);
1601 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
, GetWindowLongPtrA(hList
, GWL_STYLE
) | LVS_REPORT
);
1602 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1603 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1604 ok(IsWindow(hHeader
), "Header should be created\n");
1605 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
, GetWindowLongA(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1606 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1607 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1608 ok(IsWindow(hHeader
), "Header should be created\n");
1609 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1610 DestroyWindow(hList
);
1612 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1613 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1614 GetModuleHandleA(NULL
), 0);
1615 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
,
1616 (GetWindowLongPtrA(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1617 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1618 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1619 ok(IsWindow(hHeader
), "Header should be created\n");
1620 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1621 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
,
1622 (GetWindowLongPtrA(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1623 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1624 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1625 ok(IsWindow(hHeader
), "Header should be created\n");
1626 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1627 DestroyWindow(hList
);
1629 /* LVS_REPORT without WS_VISIBLE */
1630 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1631 GetModuleHandleA(NULL
), 0);
1632 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1633 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1634 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1636 memset(&col
, 0, sizeof(LVCOLUMNA
));
1637 col
.mask
= LVCF_WIDTH
;
1639 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1641 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1642 ok(IsWindow(hHeader
), "Header should be created\n");
1643 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1644 DestroyWindow(hList
);
1646 /* LVS_REPORT without WS_VISIBLE, try to show it */
1647 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1648 GetModuleHandleA(NULL
), 0);
1649 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1650 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1651 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1652 ShowWindow(hList
, SW_SHOW
);
1653 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1654 ok(IsWindow(hHeader
), "Header should be created\n");
1655 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1656 DestroyWindow(hList
);
1658 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1659 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1660 0, 0, 100, 100, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1661 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1662 ok(IsWindow(hHeader
), "Header should be created\n");
1663 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1664 /* HDS_DRAGDROP set by default */
1665 ok(GetWindowLongPtrA(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1666 DestroyWindow(hList
);
1668 /* setting LVS_EX_HEADERDRAGDROP creates header */
1669 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1670 GetModuleHandleA(NULL
), 0);
1671 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1672 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1673 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1674 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1675 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1676 ok(IsWindow(hHeader
) ||
1677 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1678 "Header should be created\n");
1679 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1680 DestroyWindow(hList
);
1682 /* setting LVS_EX_GRIDLINES creates header */
1683 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1684 GetModuleHandleA(NULL
), 0);
1685 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1686 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1687 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1688 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_GRIDLINES
);
1689 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1690 ok(IsWindow(hHeader
) ||
1691 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1692 "Header should be created\n");
1693 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1694 DestroyWindow(hList
);
1696 /* setting LVS_EX_FULLROWSELECT creates header */
1697 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1698 GetModuleHandleA(NULL
), 0);
1699 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1700 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1701 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1702 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
1703 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1704 ok(IsWindow(hHeader
) ||
1705 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1706 "Header should be created\n");
1707 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1708 DestroyWindow(hList
);
1710 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1711 hList
= create_listview_control(LVS_ICON
);
1712 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1713 r
= SendMessageA(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1714 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1715 DestroyWindow(hList
);
1717 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1718 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1719 GetModuleHandleA(NULL
), 0);
1720 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1721 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1723 SetRect(&rect
, LVIR_BOUNDS
, 1, -10, -10);
1724 r
= SendMessageA(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1725 /* right value contains garbage, probably because header columns are not set up */
1726 expect(0, rect
.bottom
);
1729 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1730 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1731 ok(GetDlgItem(hList
, 0) == NULL
, "NULL dialog item expected\n");
1733 DestroyWindow(hList
);
1735 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1736 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1737 hList
= create_listview_control(LVS_OWNERDRAWFIXED
| LVS_REPORT
);
1738 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1739 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1740 DestroyWindow(hList
);
1743 static void test_redraw(void)
1750 hwnd
= create_listview_control(LVS_REPORT
);
1751 subclass_header(hwnd
);
1753 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1755 InvalidateRect(hwnd
, NULL
, TRUE
);
1757 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1759 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1761 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1762 /* 1. Without backbuffer */
1763 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
1766 hdc
= GetWindowDC(hwndparent
);
1768 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1769 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1770 ok(r
== 1, "Expected not zero result\n");
1771 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1772 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1774 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_DEFAULT
);
1777 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1778 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1780 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1781 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1783 /* 2. With backbuffer */
1784 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1785 LVS_EX_DOUBLEBUFFER
);
1786 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
1789 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1790 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1792 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1793 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1795 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_DEFAULT
);
1798 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1799 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1800 todo_wine
expect(1, r
);
1801 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1802 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1804 ReleaseDC(hwndparent
, hdc
);
1806 DestroyWindow(hwnd
);
1809 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1811 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1813 if(message
== WM_NOTIFY
) {
1814 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1815 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1816 NMLVCUSTOMDRAW
*nmlvcd
= (NMLVCUSTOMDRAW
*)nmhdr
;
1819 msg
.message
= message
;
1820 msg
.flags
= sent
|wparam
|lparam
|custdraw
;
1821 msg
.wParam
= wParam
;
1822 msg
.lParam
= lParam
;
1823 msg
.id
= nmhdr
->code
;
1824 msg
.stage
= nmlvcd
->nmcd
.dwDrawStage
;
1825 add_message(sequences
, PARENT_CD_SEQ_INDEX
, &msg
);
1827 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1829 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1830 return CDRF_NOTIFYITEMDRAW
|CDRF_NOTIFYPOSTPAINT
;
1831 case CDDS_ITEMPREPAINT
:
1832 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1833 nmlvcd
->clrText
= RGB(0, 255, 0);
1834 return CDRF_NOTIFYSUBITEMDRAW
|CDRF_NOTIFYPOSTPAINT
;
1835 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1836 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1837 ok(nmlvcd
->clrTextBk
== CLR_DEFAULT
, "got 0x%x\n", nmlvcd
->clrTextBk
);
1838 ok(nmlvcd
->clrText
== RGB(0, 255, 0), "got 0x%x\n", nmlvcd
->clrText
);
1839 if (!(GetWindowLongW(nmhdr
->hwndFrom
, GWL_STYLE
) & LVS_SHOWSELALWAYS
))
1841 todo_wine_if(nmlvcd
->iSubItem
)
1842 ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1844 return CDRF_NOTIFYPOSTPAINT
;
1845 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1846 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1847 if (!(GetWindowLongW(nmhdr
->hwndFrom
, GWL_STYLE
) & LVS_SHOWSELALWAYS
))
1848 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1849 ok(nmlvcd
->clrTextBk
== CLR_DEFAULT
, "got 0x%x\n", nmlvcd
->clrTextBk
);
1850 ok(nmlvcd
->clrText
== RGB(0, 255, 0), "got 0x%x\n", nmlvcd
->clrText
);
1851 return CDRF_DODEFAULT
;
1853 return CDRF_DODEFAULT
;
1857 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1860 static void test_customdraw(void)
1866 hwnd
= create_listview_control(LVS_REPORT
);
1868 insert_column(hwnd
, 0);
1869 insert_column(hwnd
, 1);
1870 insert_item(hwnd
, 0);
1872 oldwndproc
= (WNDPROC
)SetWindowLongPtrA(hwndparent
, GWLP_WNDPROC
,
1873 (LONG_PTR
)cd_wndproc
);
1875 InvalidateRect(hwnd
, NULL
, TRUE
);
1879 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1880 InvalidateRect(hwnd
, NULL
, TRUE
);
1882 ok_sequence(sequences
, PARENT_CD_SEQ_INDEX
, parent_report_cd_seq
, "parent customdraw, LVS_REPORT", FALSE
);
1884 /* check colors when item is selected */
1885 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) | LVS_SHOWSELALWAYS
);
1886 item
.mask
= LVIF_STATE
;
1887 item
.stateMask
= LVIS_SELECTED
;
1888 item
.state
= LVIS_SELECTED
;
1889 SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
1891 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1892 InvalidateRect(hwnd
, NULL
, TRUE
);
1894 ok_sequence(sequences
, PARENT_CD_SEQ_INDEX
, parent_report_cd_seq
, "parent customdraw, LVS_REPORT, selection", FALSE
);
1896 DestroyWindow(hwnd
);
1898 hwnd
= create_listview_control(LVS_LIST
);
1900 insert_column(hwnd
, 0);
1901 insert_column(hwnd
, 1);
1902 insert_item(hwnd
, 0);
1904 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1905 InvalidateRect(hwnd
, NULL
, TRUE
);
1907 ok_sequence(sequences
, PARENT_CD_SEQ_INDEX
, parent_list_cd_seq
, "parent customdraw, LVS_LIST", FALSE
);
1909 SetWindowLongPtrA(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1910 DestroyWindow(hwnd
);
1913 static void test_icon_spacing(void)
1915 /* LVM_SETICONSPACING */
1916 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1922 hwnd
= create_listview_control(LVS_ICON
);
1923 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1925 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, NF_REQUERY
);
1926 expect(NFR_ANSI
, r
);
1928 /* reset the icon spacing to defaults */
1929 SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1931 /* now we can request what the defaults are */
1932 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1936 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1938 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1939 ok(r
== MAKELONG(w
, h
) ||
1940 broken(r
== MAKELONG(w
, w
)), /* win98 */
1941 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1943 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1947 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1948 DestroyWindow(hwnd
);
1951 expect(MAKELONG(20,30), r
);
1953 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1954 expect(MAKELONG(25,35), r
);
1956 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1958 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1959 DestroyWindow(hwnd
);
1962 static void test_color(void)
1970 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1972 hwnd
= create_listview_control(LVS_REPORT
);
1973 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1975 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1977 for (i
= 0; i
< 4; i
++)
1981 r
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1983 r
= SendMessageA(hwnd
, LVM_GETBKCOLOR
, 0, 0);
1986 r
= SendMessageA(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1988 r
= SendMessageA(hwnd
, LVM_GETTEXTCOLOR
, 0, 0);
1991 r
= SendMessageA(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1993 r
= SendMessageA(hwnd
, LVM_GETTEXTBKCOLOR
, 0, 0);
1997 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1998 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2000 /* invalidation test done separately to avoid a message chain mess */
2001 r
= ValidateRect(hwnd
, NULL
);
2003 r
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, colors
[0]);
2006 rect
.right
= rect
.bottom
= 1;
2007 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
2008 todo_wine
expect(FALSE
, r
);
2009 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
2011 r
= ValidateRect(hwnd
, NULL
);
2013 r
= SendMessageA(hwnd
, LVM_SETTEXTCOLOR
, 0, colors
[0]);
2016 rect
.right
= rect
.bottom
= 1;
2017 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
2018 todo_wine
expect(FALSE
, r
);
2019 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
2021 r
= ValidateRect(hwnd
, NULL
);
2023 r
= SendMessageA(hwnd
, LVM_SETTEXTBKCOLOR
, 0, colors
[0]);
2026 rect
.right
= rect
.bottom
= 1;
2027 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
2028 todo_wine
expect(FALSE
, r
);
2029 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
2031 DestroyWindow(hwnd
);
2034 static void test_item_count(void)
2036 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
2049 static CHAR item0text
[] = "item0";
2050 static CHAR item1text
[] = "item1";
2051 static CHAR item2text
[] = "item2";
2053 hwnd
= create_listview_control(LVS_REPORT
);
2054 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2056 /* resize in dpiaware manner to fit all 3 items added */
2058 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
2059 GetTextMetricsA(hdc
, &tm
);
2060 /* 2 extra pixels for bounds and header border */
2061 height
= tm
.tmHeight
+ 2;
2062 SelectObject(hdc
, hOldFont
);
2065 GetWindowRect(hwnd
, &rect
);
2066 /* 3 items + 1 header + 1 to be sure */
2067 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
2069 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2071 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2075 item0
.mask
= LVIF_TEXT
;
2078 item0
.pszText
= item0text
;
2079 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item0
);
2082 /* [item0, item1] */
2083 item1
.mask
= LVIF_TEXT
;
2086 item1
.pszText
= item1text
;
2087 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2090 /* [item0, item1, item2] */
2091 item2
.mask
= LVIF_TEXT
;
2094 item2
.pszText
= item2text
;
2095 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2098 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2101 /* [item0, item1] */
2102 r
= SendMessageA(hwnd
, LVM_DELETEITEM
, 2, 0);
2105 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2109 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
2112 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2116 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2119 /* [item0, item1] */
2120 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2123 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2126 /* [item0, item1, item2] */
2127 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2130 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2133 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
2135 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2136 DestroyWindow(hwnd
);
2139 static void test_item_position(void)
2141 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2150 static CHAR item0text
[] = "item0";
2151 static CHAR item1text
[] = "item1";
2152 static CHAR item2text
[] = "item2";
2154 hwnd
= create_listview_control(LVS_ICON
);
2155 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2157 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2160 item0
.mask
= LVIF_TEXT
;
2163 item0
.pszText
= item0text
;
2164 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item0
);
2167 /* [item0, item1] */
2168 item1
.mask
= LVIF_TEXT
;
2171 item1
.pszText
= item1text
;
2172 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2175 /* [item0, item1, item2] */
2176 item2
.mask
= LVIF_TEXT
;
2179 item2
.pszText
= item2text
;
2180 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2183 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
2185 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
2187 expect2(10, 5, position
.x
, position
.y
);
2189 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
2191 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
2193 expect2(0, 0, position
.x
, position
.y
);
2195 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
2197 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
2199 expect2(20, 20, position
.x
, position
.y
);
2201 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
2203 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2204 DestroyWindow(hwnd
);
2207 static void test_getorigin(void)
2215 position
.x
= position
.y
= 0;
2217 hwnd
= create_listview_control(LVS_ICON
);
2218 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2219 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2221 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2223 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2224 DestroyWindow(hwnd
);
2226 hwnd
= create_listview_control(LVS_SMALLICON
);
2227 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2228 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2230 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2232 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2233 DestroyWindow(hwnd
);
2235 hwnd
= create_listview_control(LVS_LIST
);
2236 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2237 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2239 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2241 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2242 DestroyWindow(hwnd
);
2244 hwnd
= create_listview_control(LVS_REPORT
);
2245 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2246 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2248 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2250 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2251 DestroyWindow(hwnd
);
2254 static void test_multiselect(void)
2256 typedef struct t_select_task
2268 static const int items
=5;
2275 static struct t_select_task task_list
[] = {
2276 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
2277 { "using VK_UP", -1, VK_UP
, -1, -1 },
2278 { "using VK_END", 0, VK_END
, 1, -1 },
2279 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
2282 hwnd
= create_listview_control(LVS_REPORT
);
2284 for (i
= 0; i
< items
; i
++)
2285 insert_item(hwnd
, 0);
2287 item_count
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2288 expect(items
, item_count
);
2290 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2291 ok(r
== -1, "got %d\n", r
);
2293 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, 0);
2294 ok(r
== -1, "got %d\n", r
);
2296 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, 0);
2297 ok(r
== 0, "got %d\n", r
);
2299 /* out of range index */
2300 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, items
);
2301 ok(r
== 0, "got %d\n", r
);
2303 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2304 ok(r
== 0, "got %d\n", r
);
2306 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -2);
2307 ok(r
== 0, "got %d\n", r
);
2309 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2310 ok(r
== 0, "got %d\n", r
);
2312 for (i
= 0; i
< sizeof(task_list
)/sizeof(task_list
[0]); i
++) {
2313 DWORD selected_count
;
2316 task
= task_list
[i
];
2318 /* deselect all items */
2320 item
.stateMask
= LVIS_SELECTED
;
2321 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2322 ok(r
, "got %d\n", r
);
2323 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2325 /* set initial position */
2326 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
2327 ok(r
, "got %d\n", r
);
2329 item
.state
= LVIS_SELECTED
;
2330 item
.stateMask
= LVIS_SELECTED
;
2331 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, task
.initPos
== -1 ? item_count
-1 : task
.initPos
, (LPARAM
)&item
);
2332 ok(r
, "got %d\n", r
);
2334 selected_count
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2335 ok(selected_count
== 1, "expected 1, got %d\n", selected_count
);
2337 /* Set SHIFT key pressed */
2338 GetKeyboardState(kstate
);
2339 kstate
[VK_SHIFT
]=0x80;
2340 SetKeyboardState(kstate
);
2342 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
2343 r
= SendMessageA(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
2345 r
= SendMessageA(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
2349 selected_count
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2351 ok((task
.result
== -1 ? item_count
: task
.result
) == selected_count
,
2352 "Failed multiple selection %s. There should be %d selected items (is %d)\n",
2353 task
.descr
, item_count
, selected_count
);
2355 /* Set SHIFT key released */
2356 GetKeyboardState(kstate
);
2357 kstate
[VK_SHIFT
]=0x00;
2358 SetKeyboardState(kstate
);
2360 DestroyWindow(hwnd
);
2362 /* make multiple selection, then switch to LVS_SINGLESEL */
2363 hwnd
= create_listview_control(LVS_REPORT
);
2364 for (i
=0;i
<items
;i
++) {
2365 insert_item(hwnd
, 0);
2367 item_count
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2368 expect(items
,item_count
);
2370 /* try with NULL pointer */
2371 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, 0);
2374 /* select all, check notifications */
2376 item
.stateMask
= LVIS_SELECTED
;
2377 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2378 ok(r
, "got %d\n", r
);
2380 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2382 item
.stateMask
= LVIS_SELECTED
;
2383 item
.state
= LVIS_SELECTED
;
2384 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2387 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2388 "select all notification", FALSE
);
2390 /* select all again (all selected already) */
2391 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2393 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2395 item
.stateMask
= LVIS_SELECTED
;
2396 item
.state
= LVIS_SELECTED
;
2397 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2400 ok(g_nmlistview_changing
.uNewState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2401 ok(g_nmlistview_changing
.uOldState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2402 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2404 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2405 "select all notification 2", FALSE
);
2407 /* deselect all items */
2408 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2411 item
.stateMask
= LVIS_SELECTED
;
2412 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2413 ok(r
, "got %d\n", r
);
2415 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2416 "deselect all notification", FALSE
);
2418 /* deselect all items again */
2419 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2421 item
.stateMask
= LVIS_SELECTED
;
2422 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2423 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "deselect all notification 2", FALSE
);
2425 /* any non-zero state value does the same */
2426 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2428 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2430 item
.stateMask
= LVIS_SELECTED
;
2431 item
.state
= LVIS_CUT
;
2432 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2435 ok(g_nmlistview_changing
.uNewState
== 0, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2436 ok(g_nmlistview_changing
.uOldState
== 0, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2437 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2439 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2440 "set state all notification 3", FALSE
);
2442 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2443 ok(r
, "got %d\n", r
);
2444 for (i
= 0; i
< 3; i
++) {
2445 item
.state
= LVIS_SELECTED
;
2446 item
.stateMask
= LVIS_SELECTED
;
2447 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, i
, (LPARAM
)&item
);
2448 ok(r
, "got %d\n", r
);
2451 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2453 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2456 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2457 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2458 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2459 /* check that style is accepted */
2460 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2461 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2464 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, i
, LVIS_SELECTED
);
2465 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2467 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2469 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2470 ok(r
== -1, "got %d\n", r
);
2472 /* select one more */
2473 item
.state
= LVIS_SELECTED
;
2474 item
.stateMask
= LVIS_SELECTED
;
2475 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
2476 ok(r
, "got %d\n", r
);
2479 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, i
, LVIS_SELECTED
);
2480 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2483 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 3, LVIS_SELECTED
);
2484 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2486 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2488 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2491 /* try to select all on LVS_SINGLESEL */
2492 memset(&item
, 0, sizeof(item
));
2493 item
.stateMask
= LVIS_SELECTED
;
2494 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2496 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2497 ok(r
== -1, "got %d\n", r
);
2499 item
.stateMask
= LVIS_SELECTED
;
2500 item
.state
= LVIS_SELECTED
;
2501 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2504 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2506 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2509 /* try to deselect all on LVS_SINGLESEL */
2510 item
.stateMask
= LVIS_SELECTED
;
2511 item
.state
= LVIS_SELECTED
;
2512 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2515 item
.stateMask
= LVIS_SELECTED
;
2517 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2519 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2522 /* 1. selection mark is update when new focused item is set */
2523 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2524 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2526 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2529 item
.stateMask
= LVIS_FOCUSED
;
2530 item
.state
= LVIS_FOCUSED
;
2531 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2534 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2537 /* it's not updated if already set */
2538 item
.stateMask
= LVIS_FOCUSED
;
2539 item
.state
= LVIS_FOCUSED
;
2540 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2543 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2546 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2549 item
.stateMask
= LVIS_FOCUSED
;
2550 item
.state
= LVIS_FOCUSED
;
2551 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2554 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2557 /* need to reset focused item first */
2558 item
.stateMask
= LVIS_FOCUSED
;
2560 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2563 item
.stateMask
= LVIS_FOCUSED
;
2564 item
.state
= LVIS_FOCUSED
;
2565 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
2568 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2571 item
.stateMask
= LVIS_FOCUSED
;
2573 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2576 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2579 /* 2. same tests, with LVM_SETITEM */
2580 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2581 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2583 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2586 item
.stateMask
= LVIS_FOCUSED
;
2587 item
.state
= LVIS_FOCUSED
;
2588 item
.mask
= LVIF_STATE
;
2589 item
.iItem
= item
.iSubItem
= 0;
2590 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2593 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2596 /* it's not updated if already set */
2597 item
.stateMask
= LVIS_FOCUSED
;
2598 item
.state
= LVIS_FOCUSED
;
2599 item
.mask
= LVIF_STATE
;
2602 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2605 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2608 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2611 item
.stateMask
= LVIS_FOCUSED
;
2612 item
.state
= LVIS_FOCUSED
;
2613 item
.mask
= LVIF_STATE
;
2616 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2619 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2622 /* need to reset focused item first */
2623 item
.stateMask
= LVIS_FOCUSED
;
2625 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2628 item
.stateMask
= LVIS_FOCUSED
;
2629 item
.state
= LVIS_FOCUSED
;
2630 item
.mask
= LVIF_STATE
;
2633 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2636 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2639 item
.stateMask
= LVIS_FOCUSED
;
2641 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2644 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2647 DestroyWindow(hwnd
);
2650 static void test_subitem_rect(void)
2658 /* test LVM_GETSUBITEMRECT for header */
2659 hwnd
= create_listview_control(LVS_REPORT
);
2660 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2661 /* add some columns */
2662 memset(&col
, 0, sizeof(LVCOLUMNA
));
2663 col
.mask
= LVCF_WIDTH
;
2665 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
2668 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&col
);
2671 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 2, (LPARAM
)&col
);
2673 /* item = -1 means header, subitem index is 1 based */
2674 SetRect(&rect
, LVIR_BOUNDS
, 0, 0, 0);
2675 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2678 SetRect(&rect
, LVIR_BOUNDS
, 1, 0, 0);
2679 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2682 expect(100, rect
.left
);
2683 expect(250, rect
.right
);
2684 expect(3, rect
.top
);
2686 SetRect(&rect
, LVIR_BOUNDS
, 2, 0, 0);
2687 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2690 expect(250, rect
.left
);
2691 expect(450, rect
.right
);
2692 expect(3, rect
.top
);
2694 /* item LVS_REPORT padding isn't applied to subitems */
2695 insert_item(hwnd
, 0);
2697 SetRect(&rect
, LVIR_BOUNDS
, 1, 0, 0);
2698 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2700 expect(100, rect
.left
);
2701 expect(250, rect
.right
);
2703 SetRect(&rect
, LVIR_ICON
, 1, 0, 0);
2704 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2706 /* no icon attached - zero width rectangle, with no left padding */
2707 expect(100, rect
.left
);
2708 expect(100, rect
.right
);
2710 SetRect(&rect
, LVIR_LABEL
, 1, 0, 0);
2711 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2713 /* same as full LVIR_BOUNDS */
2714 expect(100, rect
.left
);
2715 expect(250, rect
.right
);
2717 r
= SendMessageA(hwnd
, LVM_SCROLL
, 10, 0);
2718 ok(r
, "got %d\n", r
);
2720 SetRect(&rect
, LVIR_BOUNDS
, 1, 0, 0);
2721 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2723 expect(90, rect
.left
);
2724 expect(240, rect
.right
);
2726 SendMessageA(hwnd
, LVM_SCROLL
, -10, 0);
2728 /* test header interaction */
2729 subclass_header(hwnd
);
2730 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2732 SetRect(&rect
, LVIR_BOUNDS
, 1, 0, 0);
2733 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2736 SetRect(&rect
, LVIR_BOUNDS
, 1, 0, 0);
2737 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2740 SetRect(&rect
, LVIR_BOUNDS
, 1, 0, 0);
2741 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -10, (LPARAM
)&rect
);
2744 SetRect(&rect
, LVIR_BOUNDS
, 1, 0, 0);
2745 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 20, (LPARAM
)&rect
);
2748 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getsubitemrect_seq
, "LVM_GETSUBITEMRECT negative index", FALSE
);
2750 DestroyWindow(hwnd
);
2752 /* test subitem rects after re-arranging columns */
2753 hwnd
= create_listview_control(LVS_REPORT
);
2754 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2755 memset(&col
, 0, sizeof(LVCOLUMNA
));
2756 col
.mask
= LVCF_WIDTH
;
2759 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
2763 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&col
);
2767 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 2, (LPARAM
)&col
);
2770 insert_item(hwnd
, 0);
2771 insert_item(hwnd
, 1);
2773 /* wrong item is refused for main item */
2774 SetRect(&rect
, LVIR_BOUNDS
, 0, -1, -1);
2775 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect
);
2778 /* for subitems rectangle is calculated even if there's no item added */
2779 SetRect(&rect
, LVIR_BOUNDS
, 1, -1, -1);
2780 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect
);
2783 SetRect(&rect2
, LVIR_BOUNDS
, 1, -1, -1);
2784 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect2
);
2786 expect(rect
.right
, rect2
.right
);
2787 expect(rect
.left
, rect2
.left
);
2788 expect(rect
.bottom
, rect2
.top
);
2789 ok(rect2
.bottom
> rect2
.top
, "expected not zero height\n");
2791 arr
[0] = 1; arr
[1] = 0; arr
[2] = 2;
2792 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 3, (LPARAM
)arr
);
2795 SetRect(&rect
, LVIR_BOUNDS
, 0, -1, -1);
2796 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2798 expect(0, rect
.left
);
2799 expect(600, rect
.right
);
2801 SetRect(&rect
, LVIR_BOUNDS
, 1, -1, -1);
2802 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2804 expect(0, rect
.left
);
2805 expect(200, rect
.right
);
2807 SetRect(&rect2
, LVIR_BOUNDS
, 1, -1, -1);
2808 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect2
);
2810 expect(0, rect2
.left
);
2811 expect(200, rect2
.right
);
2812 /* items are of the same height */
2813 ok(rect2
.top
> 0, "expected positive item height\n");
2814 expect(rect
.bottom
, rect2
.top
);
2815 expect(rect
.bottom
* 2 - rect
.top
, rect2
.bottom
);
2817 SetRect(&rect
, LVIR_BOUNDS
, 2, -1, -1);
2818 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2820 expect(300, rect
.left
);
2821 expect(600, rect
.right
);
2823 DestroyWindow(hwnd
);
2825 /* try it for non LVS_REPORT style */
2826 hwnd
= CreateWindowA("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2827 GetModuleHandleA(NULL
), 0);
2828 SetRect(&rect
, LVIR_BOUNDS
, 1, -10, -10);
2829 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2831 /* rect is unchanged */
2832 expect(0, rect
.left
);
2833 expect(-10, rect
.right
);
2834 expect(1, rect
.top
);
2835 expect(-10, rect
.bottom
);
2836 DestroyWindow(hwnd
);
2839 /* comparison callback for test_sorting */
2840 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2842 if (first
== second
) return 0;
2843 return (first
> second
? 1 : -1);
2846 static void test_sorting(void)
2852 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2855 hwnd
= create_listview_control(LVS_REPORT
);
2856 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2858 /* insert some items */
2859 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2860 item
.state
= LVIS_SELECTED
;
2864 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2867 item
.mask
= LVIF_PARAM
;
2871 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2874 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2875 item
.state
= LVIS_SELECTED
;
2879 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2882 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2885 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2888 r
= SendMessageA(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2891 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2893 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2895 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2897 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2898 expect(LVIS_SELECTED
, r
);
2899 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2900 expect(LVIS_SELECTED
, r
);
2902 DestroyWindow(hwnd
);
2904 /* switch to LVS_SORTASCENDING when some items added */
2905 hwnd
= create_listview_control(LVS_REPORT
);
2906 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2908 item
.mask
= LVIF_TEXT
;
2911 item
.pszText
= names
[1];
2912 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2915 item
.mask
= LVIF_TEXT
;
2918 item
.pszText
= names
[2];
2919 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2922 item
.mask
= LVIF_TEXT
;
2925 item
.pszText
= names
[0];
2926 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2929 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2930 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2931 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2932 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2934 /* no sorting performed when switched to LVS_SORTASCENDING */
2935 item
.mask
= LVIF_TEXT
;
2937 item
.pszText
= buff
;
2938 item
.cchTextMax
= sizeof(buff
);
2939 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2941 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2944 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2946 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2949 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2951 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2953 /* adding new item doesn't resort list */
2954 item
.mask
= LVIF_TEXT
;
2957 item
.pszText
= names
[3];
2958 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2961 item
.mask
= LVIF_TEXT
;
2963 item
.pszText
= buff
;
2964 item
.cchTextMax
= sizeof(buff
);
2965 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2967 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2970 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2972 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2975 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2977 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2980 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2982 ok(lstrcmpA(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2984 /* corner case - item should be placed at first position */
2985 item
.mask
= LVIF_TEXT
;
2988 item
.pszText
= names
[4];
2989 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2993 item
.pszText
= buff
;
2994 item
.cchTextMax
= sizeof(buff
);
2995 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2997 ok(lstrcmpA(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
3000 item
.pszText
= buff
;
3001 item
.cchTextMax
= sizeof(buff
);
3002 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
3004 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
3007 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
3009 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
3012 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
3014 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
3017 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
3019 ok(lstrcmpA(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
3021 DestroyWindow(hwnd
);
3024 static void test_ownerdata(void)
3026 static char test_str
[] = "test";
3029 LONG_PTR style
, ret
;
3033 /* it isn't possible to set LVS_OWNERDATA after creation */
3036 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
3040 hwnd
= create_listview_control(LVS_REPORT
);
3041 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3042 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3043 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
3045 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3047 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
3048 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
3049 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
3050 "try to switch to LVS_OWNERDATA seq", FALSE
);
3052 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3053 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
3054 DestroyWindow(hwnd
);
3057 /* try to set LVS_OWNERDATA after creation just having it */
3058 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3059 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3060 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3061 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
3063 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3065 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
3066 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
3067 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
3068 "try to switch to LVS_OWNERDATA seq", FALSE
);
3069 DestroyWindow(hwnd
);
3071 /* try to remove LVS_OWNERDATA after creation just having it */
3074 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
3078 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3079 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3080 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3081 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
3083 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3085 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
3086 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
3087 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
3088 "try to switch to LVS_OWNERDATA seq", FALSE
);
3089 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3090 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
3091 DestroyWindow(hwnd
);
3094 /* try select an item */
3095 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3096 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3097 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3099 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
3101 memset(&item
, 0, sizeof(item
));
3102 item
.stateMask
= LVIS_SELECTED
;
3103 item
.state
= LVIS_SELECTED
;
3104 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3106 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
3108 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3110 DestroyWindow(hwnd
);
3112 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
3113 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3114 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3115 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3117 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3119 memset(&item
, 0, sizeof(item
));
3120 item
.mask
= LVIF_STATE
;
3122 item
.stateMask
= LVIS_SELECTED
;
3123 item
.state
= LVIS_SELECTED
;
3124 res
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3126 memset(&item
, 0, sizeof(item
));
3127 item
.pszText
= test_str
;
3128 res
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3130 DestroyWindow(hwnd
);
3132 /* check notifications after focused/selected changed */
3133 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3134 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3135 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
3138 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3140 memset(&item
, 0, sizeof(item
));
3141 item
.stateMask
= LVIS_SELECTED
;
3142 item
.state
= LVIS_SELECTED
;
3143 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3146 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_select_focus_parent_seq
,
3147 "ownerdata select notification", TRUE
);
3149 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3151 memset(&item
, 0, sizeof(item
));
3152 item
.stateMask
= LVIS_FOCUSED
;
3153 item
.state
= LVIS_FOCUSED
;
3154 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3157 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_select_focus_parent_seq
,
3158 "ownerdata focus notification", TRUE
);
3160 /* select all, check notifications */
3161 item
.stateMask
= LVIS_SELECTED
;
3163 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3166 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3168 item
.stateMask
= LVIS_SELECTED
;
3169 item
.state
= LVIS_SELECTED
;
3171 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3172 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3174 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3175 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3176 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3177 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3178 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3179 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3180 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3182 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3183 "ownerdata select all notification", FALSE
);
3185 /* select all again, note that all items are selected already */
3186 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3187 item
.stateMask
= LVIS_SELECTED
;
3188 item
.state
= LVIS_SELECTED
;
3190 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3191 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3193 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3194 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3195 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3196 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3197 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3198 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3199 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3201 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3202 "ownerdata select all notification", FALSE
);
3205 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3206 item
.stateMask
= LVIS_SELECTED
;
3209 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3210 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3212 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3213 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3214 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3215 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3216 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3217 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3218 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3220 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3221 "ownerdata deselect all notification", TRUE
);
3223 /* nothing selected, deselect all again */
3224 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3225 item
.stateMask
= LVIS_SELECTED
;
3228 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3231 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "ownerdata deselect all notification", FALSE
);
3233 /* select one, then deselect all */
3234 item
.stateMask
= LVIS_SELECTED
;
3235 item
.state
= LVIS_SELECTED
;
3236 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3238 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3239 item
.stateMask
= LVIS_SELECTED
;
3242 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3243 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3245 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3246 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3247 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3248 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3249 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3250 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3251 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3253 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3254 "ownerdata select all notification", TRUE
);
3256 /* remove focused, try to focus all */
3257 item
.stateMask
= LVIS_FOCUSED
;
3258 item
.state
= LVIS_FOCUSED
;
3259 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3261 item
.stateMask
= LVIS_FOCUSED
;
3263 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3265 item
.stateMask
= LVIS_FOCUSED
;
3266 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
3269 /* setting all to focused returns failure value */
3270 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3271 item
.stateMask
= LVIS_FOCUSED
;
3272 item
.state
= LVIS_FOCUSED
;
3274 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3277 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3278 "ownerdata focus all notification", FALSE
);
3280 /* focus single item, remove all */
3281 item
.stateMask
= LVIS_FOCUSED
;
3282 item
.state
= LVIS_FOCUSED
;
3283 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3285 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3286 item
.stateMask
= LVIS_FOCUSED
;
3289 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3290 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3292 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3293 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3294 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3295 ok(g_nmlistview
.uOldState
== LVIS_FOCUSED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3296 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3297 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3298 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3300 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
3301 "ownerdata remove focus all notification", TRUE
);
3304 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3305 item
.stateMask
= LVIS_CUT
;
3306 item
.state
= LVIS_CUT
;
3308 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3309 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3311 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3312 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3313 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3314 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3315 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3316 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3317 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3319 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3320 "ownerdata cut all notification", FALSE
);
3322 /* all marked cut, try again */
3323 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3324 item
.stateMask
= LVIS_CUT
;
3325 item
.state
= LVIS_CUT
;
3327 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3328 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3330 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3331 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3332 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3333 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3334 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3335 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3336 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3338 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3339 "ownerdata cut all notification #2", FALSE
);
3341 DestroyWindow(hwnd
);
3343 /* check notifications on LVM_GETITEM */
3344 /* zero callback mask */
3345 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3346 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3347 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3350 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3352 memset(&item
, 0, sizeof(item
));
3353 item
.stateMask
= LVIS_SELECTED
;
3354 item
.mask
= LVIF_STATE
;
3355 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3358 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3359 "ownerdata getitem selected state 1", FALSE
);
3361 /* non zero callback mask but not we asking for */
3362 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
3365 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3367 memset(&item
, 0, sizeof(item
));
3368 item
.stateMask
= LVIS_SELECTED
;
3369 item
.mask
= LVIF_STATE
;
3370 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3373 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3374 "ownerdata getitem selected state 2", FALSE
);
3376 /* LVIS_OVERLAYMASK callback mask, asking for index */
3377 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3379 memset(&item
, 0, sizeof(item
));
3380 item
.stateMask
= LVIS_OVERLAYMASK
;
3381 item
.mask
= LVIF_STATE
;
3382 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3385 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3386 "ownerdata getitem selected state 2", FALSE
);
3388 DestroyWindow(hwnd
);
3390 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3391 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
| LVS_REPORT
);
3392 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3393 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3394 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3395 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3396 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
3397 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3398 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
3399 DestroyWindow(hwnd
);
3400 /* apparently it's allowed to switch these style on after creation */
3401 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3402 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3403 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3404 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3405 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
3406 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3407 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3408 DestroyWindow(hwnd
);
3410 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3411 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3412 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3413 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3414 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
3415 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3416 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
3417 DestroyWindow(hwnd
);
3419 /* The focused item is updated after the invalidation */
3420 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3421 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3422 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 3, 0);
3425 memset(&item
, 0, sizeof(item
));
3426 item
.stateMask
= LVIS_FOCUSED
;
3427 item
.state
= LVIS_FOCUSED
;
3428 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3431 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3432 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 0, 0);
3434 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3435 "ownerdata setitemcount", FALSE
);
3437 res
= SendMessageA(hwnd
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
);
3439 DestroyWindow(hwnd
);
3442 static void test_norecompute(void)
3444 static CHAR testA
[] = "test";
3450 /* self containing control */
3451 hwnd
= create_listview_control(LVS_REPORT
);
3452 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3453 memset(&item
, 0, sizeof(item
));
3454 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
3456 item
.stateMask
= LVIS_SELECTED
;
3457 item
.state
= LVIS_SELECTED
;
3458 item
.pszText
= testA
;
3459 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3461 /* retrieve with LVIF_NORECOMPUTE */
3462 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3464 item
.pszText
= buff
;
3465 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3466 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3468 ok(lstrcmpA(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
3470 item
.mask
= LVIF_TEXT
;
3472 item
.pszText
= LPSTR_TEXTCALLBACKA
;
3473 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3476 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3478 item
.pszText
= buff
;
3479 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3481 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3482 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3484 ok(item
.pszText
== LPSTR_TEXTCALLBACKA
, "Expected (%p), got (%p)\n",
3485 LPSTR_TEXTCALLBACKA
, (VOID
*)item
.pszText
);
3486 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
3488 DestroyWindow(hwnd
);
3491 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3492 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3494 item
.mask
= LVIF_STATE
;
3495 item
.stateMask
= LVIS_SELECTED
;
3496 item
.state
= LVIS_SELECTED
;
3498 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3501 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3503 item
.pszText
= buff
;
3504 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3505 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3506 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3508 ok(item
.pszText
== LPSTR_TEXTCALLBACKA
, "Expected (%p), got (%p)\n",
3509 LPSTR_TEXTCALLBACKA
, (VOID
*)item
.pszText
);
3510 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
3512 DestroyWindow(hwnd
);
3515 static void test_nosortheader(void)
3520 hwnd
= create_listview_control(LVS_REPORT
);
3521 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3523 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3524 ok(IsWindow(header
), "header expected\n");
3526 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3527 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
3529 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3530 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
3531 /* HDS_BUTTONS retained */
3532 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3533 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
3535 DestroyWindow(hwnd
);
3537 /* create with LVS_NOSORTHEADER */
3538 hwnd
= create_listview_control(LVS_NOSORTHEADER
| LVS_REPORT
);
3539 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3541 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3542 ok(IsWindow(header
), "header expected\n");
3544 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3545 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3547 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3548 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
3549 /* not changed here */
3550 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3551 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3553 DestroyWindow(hwnd
);
3556 static void test_setredraw(void)
3564 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3565 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3567 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3568 ListView seems to handle it internally without DefWinProc */
3570 /* default value first */
3571 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3574 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3575 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3576 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3578 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3579 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3580 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3583 /* check update rect after redrawing */
3584 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3586 InvalidateRect(hwnd
, NULL
, FALSE
);
3587 RedrawWindow(hwnd
, NULL
, NULL
, RDW_UPDATENOW
);
3588 rect
.right
= rect
.bottom
= 1;
3589 GetUpdateRect(hwnd
, &rect
, FALSE
);
3590 expect(0, rect
.right
);
3591 expect(0, rect
.bottom
);
3594 hdc
= GetWindowDC(hwndparent
);
3595 ret
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3597 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3599 ret
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3601 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3603 ReleaseDC(hwndparent
, hdc
);
3605 /* check notification messages to show that repainting is disabled */
3606 ret
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3608 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3610 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3612 InvalidateRect(hwnd
, NULL
, TRUE
);
3614 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3615 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
3617 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
3619 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3620 InvalidateRect(hwnd
, NULL
, TRUE
);
3622 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3623 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
3625 /* message isn't forwarded to header */
3626 subclass_header(hwnd
);
3627 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3628 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3630 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
3631 "WM_SETREDRAW: not forwarded to header", FALSE
);
3633 DestroyWindow(hwnd
);
3636 static void test_hittest(void)
3642 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3646 HIMAGELIST himl
, himl2
;
3649 hwnd
= create_listview_control(LVS_REPORT
);
3650 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3652 /* LVS_REPORT with a single subitem (2 columns) */
3653 insert_column(hwnd
, 0);
3654 insert_column(hwnd
, 1);
3655 insert_item(hwnd
, 0);
3658 /* the only purpose of that line is to be as long as a half item rect */
3659 item
.pszText
= text
;
3660 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3663 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3665 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3668 SetRect(&bounds
, LVIR_BOUNDS
, 0, 0, 0);
3669 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
3671 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
3672 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
3673 r
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, TRUE
, 0);
3675 ok(bounds
.bottom
- bounds
.top
== vert
,
3676 "Vertical spacing inconsistent (%d != %d)\n", bounds
.bottom
- bounds
.top
, vert
);
3677 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
3680 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3682 /* outside columns by x position - valid is [0, 199] */
3684 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3685 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TOLEFT
, 0, FALSE
, FALSE
);
3686 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3688 x
= pos
.x
+ 50; /* column half width */
3689 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3690 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, 0, FALSE
, FALSE
);
3691 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3692 x
= pos
.x
+ 150; /* outside column */
3693 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3694 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3695 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3696 y
= (bounds
.bottom
- bounds
.top
) / 2;
3697 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3698 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3699 /* outside possible client rectangle (to right) */
3701 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3702 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3703 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3704 y
= (bounds
.bottom
- bounds
.top
) / 2;
3705 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3706 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3707 /* subitem returned with -1 item too */
3709 y
= bounds
.top
- vert
;
3710 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3711 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3712 /* return values appear to underflow with negative indices */
3716 test_lvm_subitemhittest(hwnd
, x
, y
, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3717 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3721 /* parent client area is 100x100 by default */
3722 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
3723 x
= pos
.x
+ 150; /* outside column */
3724 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3725 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, FALSE
);
3726 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3727 y
= (bounds
.bottom
- bounds
.top
) / 2;
3728 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, TRUE
);
3729 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3730 /* the same with LVS_EX_FULLROWSELECT */
3731 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3732 x
= pos
.x
+ 150; /* outside column */
3733 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3734 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, LVHT_ONITEMLABEL
, FALSE
, FALSE
);
3735 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3736 y
= (bounds
.bottom
- bounds
.top
) / 2;
3737 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3738 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
3739 x
= pos
.x
+ 150; /* outside column */
3740 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3741 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3742 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3743 y
= (bounds
.bottom
- bounds
.top
) / 2;
3744 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3745 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3746 /* outside possible client rectangle (to right) */
3748 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3749 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3750 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3751 y
= (bounds
.bottom
- bounds
.top
) / 2;
3752 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3753 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3754 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3755 himl
= ImageList_Create(16, 16, 0, 4, 4);
3756 ok(himl
!= NULL
, "failed to create imagelist\n");
3757 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3758 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3759 r
= ImageList_Add(himl
, hbmp
, 0);
3760 ok(r
== 0, "should be zero\n");
3761 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3762 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3763 r
= ImageList_Add(himl
, hbmp
, 0);
3764 ok(r
== 1, "should be one\n");
3766 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3769 item
.mask
= LVIF_IMAGE
;
3773 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3777 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3778 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3779 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3780 y
= (bounds
.bottom
- bounds
.top
) / 2;
3781 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3783 /* state icons indices are 1 based, check with valid index */
3784 item
.mask
= LVIF_STATE
;
3785 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3786 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3789 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3793 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3794 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3795 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3796 y
= (bounds
.bottom
- bounds
.top
) / 2;
3797 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3799 himl2
= (HIMAGELIST
)SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3800 ok(himl2
== himl
, "should return handle\n");
3802 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3806 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3807 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, 0, FALSE
, FALSE
);
3808 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3809 y
= (bounds
.bottom
- bounds
.top
) / 2;
3810 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3812 DestroyWindow(hwnd
);
3815 static void test_getviewrect(void)
3822 hwnd
= create_listview_control(LVS_REPORT
);
3823 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3826 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3829 insert_column(hwnd
, 0);
3830 insert_column(hwnd
, 1);
3832 memset(&item
, 0, sizeof(item
));
3835 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3836 ok(!r
, "got %d\n", r
);
3838 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3840 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3843 SetRect(&rect
, -1, -1, -1, -1);
3844 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3846 /* left is set to (2e31-1) - XP SP2 */
3847 expect(0, rect
.right
);
3848 expect(0, rect
.top
);
3849 expect(0, rect
.bottom
);
3851 /* switch to LVS_ICON */
3852 SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3854 SetRect(&rect
, -1, -1, -1, -1);
3855 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3857 expect(0, rect
.left
);
3858 expect(0, rect
.top
);
3859 /* precise value differs for 2k, XP and Vista */
3860 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3861 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3863 DestroyWindow(hwnd
);
3866 static void test_getitemposition(void)
3873 hwnd
= create_listview_control(LVS_REPORT
);
3874 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3875 header
= subclass_header(hwnd
);
3877 /* LVS_REPORT, single item, no columns added */
3878 insert_item(hwnd
, 0);
3880 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3883 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3885 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3887 /* LVS_REPORT, single item, single column */
3888 insert_column(hwnd
, 0);
3890 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3893 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3895 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3897 SetRectEmpty(&rect
);
3898 r
= SendMessageA(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3899 ok(r
, "got %d\n", r
);
3902 /* offset by header height */
3903 expect(rect
.bottom
- rect
.top
, pt
.y
);
3905 DestroyWindow(hwnd
);
3908 static void test_columnscreation(void)
3913 hwnd
= create_listview_control(LVS_REPORT
);
3914 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3916 insert_item(hwnd
, 0);
3918 /* headers columns aren't created automatically */
3919 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3920 ok(IsWindow(header
), "Expected header handle\n");
3921 r
= SendMessageA(header
, HDM_GETITEMCOUNT
, 0, 0);
3924 DestroyWindow(hwnd
);
3927 static void test_getitemrect(void)
3930 HIMAGELIST himl
, himl_ret
;
3939 /* rectangle isn't empty for empty text items */
3940 hwnd
= create_listview_control(LVS_LIST
);
3941 memset(&item
, 0, sizeof(item
));
3944 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3946 rect
.left
= LVIR_LABEL
;
3947 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3949 expect(0, rect
.left
);
3950 expect(0, rect
.top
);
3951 /* estimate it as width / height ratio */
3953 ok((rect
.right
/ rect
.bottom
) >= 5, "got right %d, bottom %d\n", rect
.right
, rect
.bottom
);
3954 DestroyWindow(hwnd
);
3956 hwnd
= create_listview_control(LVS_REPORT
);
3957 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3960 memset(&item
, 0, sizeof(item
));
3963 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3966 SetRect(&rect
, LVIR_BOUNDS
, -1, -1, -1);
3967 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3970 /* zero width rectangle with no padding */
3971 expect(0, rect
.left
);
3972 expect(0, rect
.right
);
3974 insert_column(hwnd
, 0);
3975 insert_column(hwnd
, 1);
3977 col
.mask
= LVCF_WIDTH
;
3979 r
= SendMessageA(hwnd
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
3982 col
.mask
= LVCF_WIDTH
;
3984 r
= SendMessageA(hwnd
, LVM_SETCOLUMNA
, 1, (LPARAM
)&col
);
3987 SetRect(&rect
, LVIR_BOUNDS
, -1, -1, -1);
3988 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3991 /* still no left padding */
3992 expect(0, rect
.left
);
3993 expect(150, rect
.right
);
3995 SetRect(&rect
, LVIR_SELECTBOUNDS
, -1, -1, -1);
3996 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3999 expect(2, rect
.left
);
4001 SetRect(&rect
, LVIR_LABEL
, -1, -1, -1);
4002 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4004 /* padding, column width */
4005 expect(2, rect
.left
);
4006 expect(50, rect
.right
);
4008 /* no icons attached */
4009 SetRect(&rect
, LVIR_ICON
, -1, -1, -1);
4010 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4013 expect(2, rect
.left
);
4014 expect(2, rect
.right
);
4017 order
[0] = 1; order
[1] = 0;
4018 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
4021 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
4023 /* 1 indexed column width + padding */
4025 /* rect is at zero too */
4026 SetRect(&rect
, LVIR_BOUNDS
, -1, -1, -1);
4027 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4029 expect(0, rect
.left
);
4030 /* just width sum */
4031 expect(150, rect
.right
);
4033 SetRect(&rect
, LVIR_SELECTBOUNDS
, -1, -1, -1);
4034 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4036 /* column width + padding */
4037 expect(102, rect
.left
);
4039 /* back to initial order */
4040 order
[0] = 0; order
[1] = 1;
4041 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
4045 himl
= ImageList_Create(16, 16, 0, 2, 2);
4046 ok(himl
!= NULL
, "failed to create imagelist\n");
4047 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
4048 ok(hbm
!= NULL
, "failed to create bitmap\n");
4049 r
= ImageList_Add(himl
, hbm
, 0);
4051 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
4052 ok(hbm
!= NULL
, "failed to create bitmap\n");
4053 r
= ImageList_Add(himl
, hbm
, 0);
4056 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
4059 item
.mask
= LVIF_STATE
;
4060 item
.state
= INDEXTOSTATEIMAGEMASK(1);
4061 item
.stateMask
= LVIS_STATEIMAGEMASK
;
4064 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
4068 SetRect(&rect
, LVIR_ICON
, -1, -1, -1);
4069 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4071 /* padding + stateicon width */
4072 expect(18, rect
.left
);
4073 expect(18, rect
.right
);
4075 SetRect(&rect
, LVIR_LABEL
, -1, -1, -1);
4076 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4078 /* padding + stateicon width -> column width */
4079 expect(18, rect
.left
);
4080 expect(50, rect
.right
);
4082 himl_ret
= (HIMAGELIST
)SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
4083 ok(himl_ret
== himl
, "got %p, expected %p\n", himl_ret
, himl
);
4085 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
4088 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
4091 item
.stateMask
= ~0;
4094 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
4098 SetRect(&rect
, LVIR_ICON
, -1, -1, -1);
4099 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4101 /* padding, icon width */
4102 expect(2, rect
.left
);
4103 expect(18, rect
.right
);
4105 SetRect(&rect
, LVIR_LABEL
, -1, -1, -1);
4106 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4108 /* padding + icon width -> column width */
4109 expect(18, rect
.left
);
4110 expect(50, rect
.right
);
4113 SetRect(&rect
, LVIR_SELECTBOUNDS
, -1, -1, -1);
4114 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4116 /* padding, column width */
4117 expect(2, rect
.left
);
4118 expect(50, rect
.right
);
4120 /* try with indentation */
4121 item
.mask
= LVIF_INDENT
;
4125 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
4129 SetRect(&rect
, LVIR_BOUNDS
, -1, -1, -1);
4130 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4132 /* padding + 1 icon width, column width */
4133 expect(0, rect
.left
);
4134 expect(150, rect
.right
);
4137 SetRect(&rect
, LVIR_SELECTBOUNDS
, -1, -1, -1);
4138 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4140 /* padding + 1 icon width, column width */
4141 expect(2 + 16, rect
.left
);
4142 expect(50, rect
.right
);
4145 SetRect(&rect
, LVIR_LABEL
, -1, -1, -1);
4146 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4148 /* padding + 2 icon widths, column width */
4149 expect(2 + 16*2, rect
.left
);
4150 expect(50, rect
.right
);
4153 SetRect(&rect
, LVIR_ICON
, -1, -1, -1);
4154 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4156 /* padding + 1 icon width indentation, icon width */
4157 expect(2 + 16, rect
.left
);
4158 expect(34, rect
.right
);
4160 DestroyWindow(hwnd
);
4163 static void test_editbox(void)
4165 static CHAR testitemA
[] = "testitem";
4166 static CHAR testitem1A
[] = "testitem_quitelongname";
4167 static CHAR testitem2A
[] = "testITEM_quitelongname";
4168 static CHAR buffer
[25];
4169 HWND hwnd
, hwndedit
, hwndedit2
, header
;
4173 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4174 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4176 insert_column(hwnd
, 0);
4178 memset(&item
, 0, sizeof(item
));
4179 item
.mask
= LVIF_TEXT
;
4180 item
.pszText
= testitemA
;
4183 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4186 /* test notifications without edit created */
4187 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4188 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)0xdeadbeef);
4190 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4191 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE
);
4192 /* same thing but with valid window */
4193 hwndedit
= CreateWindowA("Edit", "Test edit", WS_VISIBLE
| WS_CHILD
, 0, 0, 20,
4194 10, hwnd
, (HMENU
)1, (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
), 0);
4195 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4196 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)hwndedit
);
4198 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4199 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE
);
4200 DestroyWindow(hwndedit
);
4202 /* setting focus is necessary */
4204 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4205 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4207 /* test children Z-order after Edit box created */
4208 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4209 ok(IsWindow(header
), "Expected header to be created\n");
4210 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4211 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4213 /* modify initial string */
4214 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4217 /* edit window is resized and repositioned,
4218 check again for Z-order - it should be preserved */
4219 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4220 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4222 /* return focus to listview */
4225 memset(&item
, 0, sizeof(item
));
4226 item
.mask
= LVIF_TEXT
;
4227 item
.pszText
= buffer
;
4228 item
.cchTextMax
= sizeof(buffer
);
4231 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
4234 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4236 /* send LVM_EDITLABEL on already created edit */
4238 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4239 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4240 /* focus will be set to edit */
4241 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
4242 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4243 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
4245 /* creating label disabled when control isn't focused */
4247 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4248 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4250 /* check EN_KILLFOCUS handling */
4251 memset(&item
, 0, sizeof(item
));
4252 item
.pszText
= testitemA
;
4255 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
4259 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4260 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4261 /* modify edit and notify control that it lost focus */
4262 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4264 g_editbox_disp_info
.item
.pszText
= NULL
;
4265 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4267 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "expected notification with not null text\n");
4269 memset(&item
, 0, sizeof(item
));
4270 item
.pszText
= buffer
;
4271 item
.cchTextMax
= sizeof(buffer
);
4274 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4275 expect(lstrlenA(item
.pszText
), r
);
4276 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4277 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4279 /* change item name to differ in casing only */
4281 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4282 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4283 /* modify edit and notify control that it lost focus */
4284 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem2A
);
4286 g_editbox_disp_info
.item
.pszText
= NULL
;
4287 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4289 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "got %p\n", g_editbox_disp_info
.item
.pszText
);
4291 memset(&item
, 0, sizeof(item
));
4292 item
.pszText
= buffer
;
4293 item
.cchTextMax
= sizeof(buffer
);
4296 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4297 expect(lstrlenA(item
.pszText
), r
);
4298 ok(strcmp(buffer
, testitem2A
) == 0, "got %s, expected %s\n", buffer
, testitem2A
);
4299 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4301 /* end edit without saving */
4303 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4304 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4305 r
= SendMessageA(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
4307 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4308 "edit box - end edit, no change, escape", TRUE
);
4309 /* end edit with saving */
4311 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4312 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4313 r
= SendMessageA(hwndedit
, WM_KEYDOWN
, VK_RETURN
, 0);
4315 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4316 "edit box - end edit, no change, return", TRUE
);
4318 memset(&item
, 0, sizeof(item
));
4319 item
.pszText
= buffer
;
4320 item
.cchTextMax
= sizeof(buffer
);
4323 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4324 expect(lstrlenA(item
.pszText
), r
);
4325 ok(strcmp(buffer
, testitem2A
) == 0, "Expected item text to change\n");
4327 /* LVM_EDITLABEL with -1 destroys current edit */
4328 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
4329 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4330 /* no edit present */
4331 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -1, 0);
4332 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4333 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4334 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4336 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4337 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -1, 0);
4338 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4339 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4340 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4341 /* check another negative value */
4342 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4343 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4344 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4345 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -2, 0);
4346 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4347 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4348 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4349 /* and value greater than max item index */
4350 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4351 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4352 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4353 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
4354 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, r
, 0);
4355 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4356 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4357 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4359 /* messaging tests */
4361 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4363 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4364 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4365 /* testing only sizing messages */
4366 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
4367 "edit box create - sizing", FALSE
);
4369 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4371 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4372 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4373 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4374 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4376 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4377 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE
);
4379 DestroyWindow(hwnd
);
4382 static void test_notifyformat(void)
4387 hwnd
= create_listview_control(LVS_REPORT
);
4388 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4390 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4391 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4392 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4394 SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4396 r
= SendMessageA(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
4398 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4401 r
= SendMessageA(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
4403 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4408 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4409 DestroyWindow(hwnd
);
4413 DestroyWindow(hwnd
);
4415 /* test failure in parent WM_NOTIFYFORMAT */
4417 hwnd
= create_listview_control(LVS_REPORT
);
4418 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4419 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4420 ok(IsWindow(header
), "expected header to be created\n");
4421 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4423 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4424 ok( r
== 1, "Expected 1, got %d\n", r
);
4425 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4426 ok(r
!= 0, "Expected valid format\n");
4428 notifyFormat
= NFR_UNICODE
;
4429 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4430 expect(NFR_UNICODE
, r
);
4431 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4433 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4434 ok( r
== 1, "Expected 1, got %d\n", r
);
4436 notifyFormat
= NFR_ANSI
;
4437 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4438 expect(NFR_ANSI
, r
);
4439 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4441 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4442 ok( r
== 1, "Expected 1, got %d\n", r
);
4444 DestroyWindow(hwnd
);
4446 hwndparentW
= create_parent_window(TRUE
);
4447 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
4448 if (!IsWindow(hwndparentW
)) return;
4451 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4452 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4453 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4454 ok(IsWindow(header
), "expected header to be created\n");
4455 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4457 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4459 DestroyWindow(hwnd
);
4460 /* receiving error code defaulting to ansi */
4462 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4463 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4464 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4465 ok(IsWindow(header
), "expected header to be created\n");
4466 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4468 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4470 DestroyWindow(hwnd
);
4471 /* receiving ansi code from unicode window, use it */
4472 notifyFormat
= NFR_ANSI
;
4473 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4474 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4475 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4476 ok(IsWindow(header
), "expected header to be created\n");
4477 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4479 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4481 DestroyWindow(hwnd
);
4482 /* unicode listview with ansi parent window */
4484 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4485 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4486 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4487 ok(IsWindow(header
), "expected header to be created\n");
4488 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4490 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4492 DestroyWindow(hwnd
);
4493 /* unicode listview with ansi parent window, return error code */
4495 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4496 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4497 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4498 ok(IsWindow(header
), "expected header to be created\n");
4499 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4501 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4503 DestroyWindow(hwnd
);
4505 DestroyWindow(hwndparentW
);
4508 static void test_indentation(void)
4514 hwnd
= create_listview_control(LVS_REPORT
);
4515 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4517 memset(&item
, 0, sizeof(item
));
4518 item
.mask
= LVIF_INDENT
;
4520 item
.iIndent
= I_INDENTCALLBACK
;
4521 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4524 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4527 item
.mask
= LVIF_INDENT
;
4528 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
4531 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
4532 "get indent dispinfo", FALSE
);
4534 DestroyWindow(hwnd
);
4537 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
4542 static BOOL
is_below_comctl_5(void)
4547 hwnd
= create_listview_control(LVS_REPORT
);
4548 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4549 insert_item(hwnd
, 0);
4551 ret
= SendMessageA(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
4553 DestroyWindow(hwnd
);
4558 static void test_get_set_view(void)
4564 /* test style->view mapping */
4565 hwnd
= create_listview_control(LVS_REPORT
);
4566 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4568 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4569 expect(LV_VIEW_DETAILS
, ret
);
4571 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4573 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
4574 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4575 expect(LV_VIEW_ICON
, ret
);
4577 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4578 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
4579 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4580 expect(LV_VIEW_SMALLICON
, ret
);
4582 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4583 SetWindowLongPtrA(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
4584 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4585 expect(LV_VIEW_LIST
, ret
);
4587 /* switching view doesn't touch window style */
4588 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
4590 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4591 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4592 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
4594 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4595 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4596 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
4598 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4599 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4601 /* now change window style to see if view is remapped */
4602 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4603 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SHOWSELALWAYS
);
4604 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4605 expect(LV_VIEW_SMALLICON
, ret
);
4607 DestroyWindow(hwnd
);
4610 static void test_canceleditlabel(void)
4612 HWND hwnd
, hwndedit
;
4616 static CHAR test
[] = "test";
4617 static const CHAR test1
[] = "test1";
4619 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4620 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4622 insert_item(hwnd
, 0);
4624 /* try without edit created */
4625 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4626 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4628 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4629 "cancel edit label without edit", FALSE
);
4631 /* cancel without data change */
4633 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4634 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4635 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4637 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4639 /* cancel after data change */
4640 memset(&itema
, 0, sizeof(itema
));
4641 itema
.pszText
= test
;
4642 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&itema
);
4645 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4646 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4647 ret
= SetWindowTextA(hwndedit
, test1
);
4649 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4651 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4652 memset(&itema
, 0, sizeof(itema
));
4653 itema
.pszText
= buff
;
4654 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
4655 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&itema
);
4657 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
4659 DestroyWindow(hwnd
);
4662 static void test_mapidindex(void)
4667 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4668 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
4669 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4670 insert_item(hwnd
, 0);
4671 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4673 DestroyWindow(hwnd
);
4675 hwnd
= create_listview_control(LVS_REPORT
);
4676 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4678 /* LVM_MAPINDEXTOID with invalid index */
4679 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4682 insert_item(hwnd
, 0);
4683 insert_item(hwnd
, 1);
4685 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
4687 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
4690 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4692 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4694 /* remove 0 indexed item, id retained */
4695 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
4696 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4698 /* new id starts from previous value */
4699 insert_item(hwnd
, 1);
4700 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4703 /* get index by id */
4704 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
4706 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
4708 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
4710 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
4713 DestroyWindow(hwnd
);
4716 static void test_getitemspacing(void)
4721 HIMAGELIST himl40
, himl80
;
4723 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
4724 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
4727 hwnd
= create_listview_control(LVS_ICON
);
4728 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4729 expect(cx
, LOWORD(ret
));
4730 expect(cy
, HIWORD(ret
));
4732 /* now try with icons */
4733 himl40
= ImageList_Create(40, 40, 0, 4, 4);
4734 ok(himl40
!= NULL
, "failed to create imagelist\n");
4735 himl80
= ImageList_Create(80, 80, 0, 4, 4);
4736 ok(himl80
!= NULL
, "failed to create imagelist\n");
4737 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4740 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4741 /* spacing + icon size returned */
4742 expect(cx
+ 40, LOWORD(ret
));
4743 expect(cy
+ 40, HIWORD(ret
));
4744 /* try changing icon size */
4745 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl80
);
4747 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4748 /* spacing + icon size returned */
4749 expect(cx
+ 80, LOWORD(ret
));
4750 expect(cy
+ 80, HIWORD(ret
));
4752 /* set own icon spacing */
4753 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(100, 100));
4754 expect(cx
+ 80, LOWORD(ret
));
4755 expect(cy
+ 80, HIWORD(ret
));
4757 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4758 /* set size returned */
4759 expect(100, LOWORD(ret
));
4760 expect(100, HIWORD(ret
));
4762 /* now change image list - icon spacing should be unaffected */
4763 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4765 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4766 /* set size returned */
4767 expect(100, LOWORD(ret
));
4768 expect(100, HIWORD(ret
));
4770 /* spacing = 0 - keep previous value */
4771 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(0, -1));
4772 expect(100, LOWORD(ret
));
4773 expect(100, HIWORD(ret
));
4775 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4776 expect(100, LOWORD(ret
));
4778 expect(0xFFFF, HIWORD(ret
));
4780 if (sizeof(void*) == 8)
4782 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4783 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, (DWORD
)-1);
4784 expect(100, LOWORD(ret
));
4785 expect(0xFFFF, HIWORD(ret
));
4787 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, -1);
4788 expect(0xFFFF, LOWORD(ret
));
4789 expect(0xFFFF, HIWORD(ret
));
4793 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, -1);
4794 expect(100, LOWORD(ret
));
4795 expect(0xFFFF, HIWORD(ret
));
4797 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4798 /* spacing + icon size returned */
4799 expect(cx
+ 40, LOWORD(ret
));
4800 expect(cy
+ 40, HIWORD(ret
));
4802 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, 0);
4803 ImageList_Destroy(himl80
);
4804 DestroyWindow(hwnd
);
4806 hwnd
= create_listview_control(LVS_SMALLICON
);
4807 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4808 expect(cx
, LOWORD(ret
));
4809 expect(cy
, HIWORD(ret
));
4811 /* spacing does not depend on selected view type */
4812 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4815 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4816 /* spacing + icon size returned */
4817 expect(cx
+ 40, LOWORD(ret
));
4818 expect(cy
+ 40, HIWORD(ret
));
4820 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, 0);
4821 ImageList_Destroy(himl40
);
4822 DestroyWindow(hwnd
);
4824 hwnd
= create_listview_control(LVS_REPORT
);
4825 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4826 expect(cx
, LOWORD(ret
));
4827 expect(cy
, HIWORD(ret
));
4829 DestroyWindow(hwnd
);
4831 hwnd
= create_listview_control(LVS_LIST
);
4832 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4833 expect(cx
, LOWORD(ret
));
4834 expect(cy
, HIWORD(ret
));
4836 DestroyWindow(hwnd
);
4839 static INT
get_current_font_height(HWND listview
)
4846 hwnd
= (HWND
)SendMessageA(listview
, LVM_GETHEADER
, 0, 0);
4850 hfont
= (HFONT
)SendMessageA(hwnd
, WM_GETFONT
, 0, 0);
4853 GetTextMetricsA(hdc
, &tm
);
4854 ReleaseDC(hwnd
, hdc
);
4860 oldfont
= SelectObject(hdc
, hfont
);
4861 GetTextMetricsA(hdc
, &tm
);
4862 SelectObject(hdc
, oldfont
);
4869 static void test_getcolumnwidth(void)
4878 /* default column width */
4879 hwnd
= create_listview_control(LVS_ICON
);
4880 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4882 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4883 SetWindowLongA(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
4884 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4885 todo_wine
expect(8, ret
);
4886 style
= GetWindowLongA(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
4887 SetWindowLongA(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
4889 ret
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4891 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4893 DestroyWindow(hwnd
);
4895 /* default column width with item added */
4896 hwnd
= create_listview_control(LVS_LIST
);
4897 memset(&itema
, 0, sizeof(itema
));
4898 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4899 ok(!ret
, "got %d\n", ret
);
4900 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4901 height
= get_current_font_height(hwnd
);
4902 ok((ret
/ height
) >= 6, "got width %d, height %d\n", ret
, height
);
4903 DestroyWindow(hwnd
);
4906 static void test_scrollnotify(void)
4911 hwnd
= create_listview_control(LVS_REPORT
);
4913 insert_column(hwnd
, 0);
4914 insert_column(hwnd
, 1);
4915 insert_item(hwnd
, 0);
4917 /* make it scrollable - resize */
4918 ret
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
4920 ret
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
4923 /* try with dummy call */
4924 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4925 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 0, 0);
4927 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4928 "scroll notify 1", TRUE
);
4930 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4931 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 1, 0);
4933 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4934 "scroll notify 2", TRUE
);
4936 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4937 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 1, 1);
4939 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4940 "scroll notify 3", TRUE
);
4942 DestroyWindow(hwnd
);
4945 static void test_LVS_EX_TRANSPARENTBKGND(void)
4951 hwnd
= create_listview_control(LVS_REPORT
);
4953 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4956 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4957 LVS_EX_TRANSPARENTBKGND
);
4959 ret
= SendMessageA(hwnd
, LVM_GETBKCOLOR
, 0, 0);
4960 if (ret
!= CLR_NONE
)
4962 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4963 DestroyWindow(hwnd
);
4967 /* try to set some back color and check this style bit */
4968 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4970 ret
= SendMessageA(hwnd
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
4971 ok(!(ret
& LVS_EX_TRANSPARENTBKGND
), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4973 /* now test what this style actually does */
4974 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4975 LVS_EX_TRANSPARENTBKGND
);
4977 hdc
= GetWindowDC(hwndparent
);
4979 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4980 SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
4981 ok_sequence(sequences
, PARENT_SEQ_INDEX
, lvs_ex_transparentbkgnd_seq
,
4982 "LVS_EX_TRANSPARENTBKGND parent", FALSE
);
4984 ReleaseDC(hwndparent
, hdc
);
4986 DestroyWindow(hwnd
);
4989 static void test_approximate_viewrect(void)
4996 static CHAR test
[] = "abracadabra, a very long item label";
4998 hwnd
= create_listview_control(LVS_ICON
);
4999 himl
= ImageList_Create(40, 40, 0, 4, 4);
5000 ok(himl
!= NULL
, "failed to create imagelist\n");
5001 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
5002 ok(hbmp
!= NULL
, "failed to create bitmap\n");
5003 ret
= ImageList_Add(himl
, hbmp
, 0);
5005 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
5008 itema
.mask
= LVIF_IMAGE
;
5012 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
5015 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(75, 75));
5019 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
5023 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
5024 expect(MAKELONG(77,827), ret
);
5026 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(50, 50));
5027 ok(ret
!= 0, "got 0\n");
5029 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
5030 expect(MAKELONG(102,302), ret
);
5032 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
5033 expect(MAKELONG(52,52), ret
);
5035 itema
.pszText
= test
;
5036 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&itema
);
5038 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
5039 expect(MAKELONG(52,52), ret
);
5041 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 0, MAKELPARAM(100,100));
5042 expect(MAKELONG(52,2), ret
);
5043 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 1, MAKELPARAM(100,100));
5044 expect(MAKELONG(52,52), ret
);
5045 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 2, MAKELPARAM(100,100));
5046 expect(MAKELONG(102,52), ret
);
5047 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 3, MAKELPARAM(100,100));
5048 expect(MAKELONG(102,102), ret
);
5049 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 4, MAKELPARAM(100,100));
5050 expect(MAKELONG(102,102), ret
);
5051 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 5, MAKELPARAM(100,100));
5052 expect(MAKELONG(102,152), ret
);
5053 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 6, MAKELPARAM(100,100));
5054 expect(MAKELONG(102,152), ret
);
5055 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 7, MAKELPARAM(160,100));
5056 expect(MAKELONG(152,152), ret
);
5058 DestroyWindow(hwnd
);
5061 static void test_finditem(void)
5068 hwnd
= create_listview_control(LVS_REPORT
);
5069 insert_item(hwnd
, 0);
5071 memset(&fi
, 0, sizeof(fi
));
5073 /* full string search, inserted text was "foo" */
5075 fi
.flags
= LVFI_STRING
;
5077 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5079 /* partial string search, inserted text was "foo" */
5081 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
5083 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5085 /* partial string search, part after start char */
5087 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
5089 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5092 /* try with LVFI_SUBSTRING */
5094 fi
.flags
= LVFI_SUBSTRING
;
5096 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5099 win_skip("LVFI_SUBSTRING not supported\n");
5100 DestroyWindow(hwnd
);
5105 fi
.flags
= LVFI_SUBSTRING
;
5107 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5110 fi
.flags
= LVFI_SUBSTRING
;
5112 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5116 fi
.flags
= LVFI_SUBSTRING
| LVFI_STRING
;
5118 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5121 DestroyWindow(hwnd
);
5124 static void test_LVS_EX_HEADERINALLVIEWS(void)
5129 hwnd
= create_listview_control(LVS_ICON
);
5131 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5132 LVS_EX_HEADERINALLVIEWS
);
5134 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5135 if (!IsWindow(header
))
5137 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
5138 DestroyWindow(hwnd
);
5142 /* LVS_NOCOLUMNHEADER works as before */
5143 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5144 SetWindowLongW(hwnd
, GWL_STYLE
, style
| LVS_NOCOLUMNHEADER
);
5145 style
= GetWindowLongA(header
, GWL_STYLE
);
5146 ok(style
& HDS_HIDDEN
, "Expected HDS_HIDDEN\n");
5147 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5148 SetWindowLongW(hwnd
, GWL_STYLE
, style
& ~LVS_NOCOLUMNHEADER
);
5149 style
= GetWindowLongA(header
, GWL_STYLE
);
5150 ok(!(style
& HDS_HIDDEN
), "Expected HDS_HIDDEN to be unset\n");
5152 /* try to remove style */
5153 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
, 0);
5154 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5155 ok(IsWindow(header
), "Expected header to be created\n");
5156 style
= GetWindowLongA(header
, GWL_STYLE
);
5157 ok(!(style
& HDS_HIDDEN
), "HDS_HIDDEN not expected\n");
5159 DestroyWindow(hwnd
);
5161 /* check other styles */
5162 hwnd
= create_listview_control(LVS_LIST
);
5163 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5164 LVS_EX_HEADERINALLVIEWS
);
5165 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5166 ok(IsWindow(header
), "Expected header to be created\n");
5167 DestroyWindow(hwnd
);
5169 hwnd
= create_listview_control(LVS_SMALLICON
);
5170 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5171 LVS_EX_HEADERINALLVIEWS
);
5172 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5173 ok(IsWindow(header
), "Expected header to be created\n");
5174 DestroyWindow(hwnd
);
5176 hwnd
= create_listview_control(LVS_REPORT
);
5177 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5178 LVS_EX_HEADERINALLVIEWS
);
5179 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5180 ok(IsWindow(header
), "Expected header to be created\n");
5181 DestroyWindow(hwnd
);
5184 static void test_hover(void)
5189 hwnd
= create_listview_control(LVS_ICON
);
5190 SetForegroundWindow(hwndparent
);
5191 fg
= GetForegroundWindow();
5192 if (fg
!= hwndparent
)
5194 skip("Window is not in the foreground. Skipping hover tests.\n");
5195 DestroyWindow(hwnd
);
5199 /* test WM_MOUSEHOVER forwarding */
5200 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5201 r
= SendMessageA(hwnd
, WM_MOUSEHOVER
, 0, 0);
5203 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER allow test", TRUE
);
5204 g_block_hover
= TRUE
;
5205 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5206 r
= SendMessageA(hwnd
, WM_MOUSEHOVER
, 0, 0);
5208 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER block test", TRUE
);
5209 g_block_hover
= FALSE
;
5211 r
= SendMessageA(hwnd
, LVM_SETHOVERTIME
, 0, 500);
5212 expect(HOVER_DEFAULT
, r
);
5213 r
= SendMessageA(hwnd
, LVM_GETHOVERTIME
, 0, 0);
5216 DestroyWindow(hwnd
);
5219 static void test_destroynotify(void)
5224 hwnd
= create_listview_control(LVS_REPORT
);
5225 ok(hwnd
!= NULL
, "failed to create listview window\n");
5227 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5228 DestroyWindow(hwnd
);
5229 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_destroy
, "check destroy order", FALSE
);
5231 /* same for ownerdata list */
5232 hwnd
= create_listview_control(LVS_REPORT
|LVS_OWNERDATA
);
5233 ok(hwnd
!= NULL
, "failed to create listview window\n");
5235 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5236 DestroyWindow(hwnd
);
5237 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_ownerdata_destroy
, "check destroy order, ownerdata", FALSE
);
5239 hwnd
= create_listview_control(LVS_REPORT
|LVS_OWNERDATA
);
5240 ok(hwnd
!= NULL
, "failed to create listview window\n");
5242 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5243 ret
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
5244 ok(ret
== TRUE
, "got %d\n", ret
);
5245 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_ownerdata_deleteall
, "deleteall ownerdata", FALSE
);
5246 DestroyWindow(hwnd
);
5249 static void test_header_notification(void)
5251 static char textA
[] = "newtext";
5259 list
= create_listview_control(LVS_REPORT
);
5260 ok(list
!= NULL
, "failed to create listview window\n");
5262 memset(&col
, 0, sizeof(col
));
5263 col
.mask
= LVCF_WIDTH
;
5265 ret
= SendMessageA(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5268 /* check list parent notification after header item changed,
5269 this test should be placed before header subclassing to avoid
5270 Listview -> Header messages to be logged */
5271 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5273 col
.mask
= LVCF_TEXT
;
5274 col
.pszText
= textA
;
5275 r
= SendMessageA(list
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
5278 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_changed_seq
,
5279 "header notify, listview", FALSE
);
5280 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5281 "header notify, parent", FALSE
);
5283 header
= subclass_header(list
);
5285 ret
= SendMessageA(header
, HDM_GETITEMCOUNT
, 0, 0);
5288 memset(&item
, 0, sizeof(item
));
5289 item
.mask
= HDI_WIDTH
;
5290 ret
= SendMessageA(header
, HDM_GETITEMA
, 0, (LPARAM
)&item
);
5292 expect(100, item
.cxy
);
5294 nmh
.hdr
.hwndFrom
= header
;
5295 nmh
.hdr
.idFrom
= GetWindowLongPtrA(header
, GWLP_ID
);
5296 nmh
.hdr
.code
= HDN_ITEMCHANGEDA
;
5299 item
.mask
= HDI_WIDTH
;
5302 ret
= SendMessageA(list
, WM_NOTIFY
, 0, (LPARAM
)&nmh
);
5305 DestroyWindow(list
);
5308 static void test_header_notification2(void)
5310 static char textA
[] = "newtext";
5317 struct message parent_header_notify_seq
[] = {
5318 { WM_NOTIFY
, sent
|id
, 0, 0, 0 },
5322 list
= create_listview_control(LVS_REPORT
);
5323 ok(list
!= NULL
, "failed to create listview window\n");
5325 memset(&col
, 0, sizeof(col
));
5326 col
.mask
= LVCF_WIDTH
| LVCF_TEXT
;
5328 col
.pszText
= textA
;
5329 ret
= SendMessageA(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5332 header
= (HWND
)SendMessageA(list
, LVM_GETHEADER
, 0, 0);
5333 ok(header
!= 0, "No header\n");
5334 memset(&itemW
, 0, sizeof(itemW
));
5335 itemW
.mask
= HDI_WIDTH
| HDI_ORDER
| HDI_TEXT
;
5336 itemW
.pszText
= buffer
;
5337 itemW
.cchTextMax
= sizeof(buffer
);
5338 ret
= SendMessageW(header
, HDM_GETITEMW
, 0, (LPARAM
)&itemW
);
5341 nmhdr
.hdr
.hwndFrom
= header
;
5342 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(header
, GWLP_ID
);
5345 nmhdr
.pitem
= &itemW
;
5347 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5348 nmhdr
.hdr
.code
= HDN_ITEMCHANGINGW
;
5349 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5350 ok(ret
== 0, "got %d\n", ret
);
5351 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGINGA
;
5352 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5353 "header notify, parent", TRUE
);
5355 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGINGA
, "Expected ANSI notification code\n");
5356 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5357 nmhdr
.hdr
.code
= HDN_ITEMCHANGEDW
;
5358 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5359 ok(ret
== 0, "got %d\n", ret
);
5360 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGEDA
;
5361 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5362 "header notify, parent", TRUE
);
5364 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGEDA
, "Expected ANSI notification code\n");
5365 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5367 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5368 nmhdr
.hdr
.code
= HDN_ITEMCLICKW
;
5369 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5370 ok(ret
== 0, "got %d\n", ret
);
5371 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_click_seq
,
5372 "header notify, parent", FALSE
);
5373 ok(nmhdr
.hdr
.code
== HDN_ITEMCLICKA
, "Expected ANSI notification code\n");
5374 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5375 nmhdr
.hdr
.code
= HDN_ITEMDBLCLICKW
;
5376 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5377 ok(ret
== 0, "got %d\n", ret
);
5378 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5379 "header notify, parent", FALSE
);
5380 ok(nmhdr
.hdr
.code
== HDN_ITEMDBLCLICKW
, "Expected Unicode notification code\n");
5381 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5382 nmhdr
.hdr
.code
= HDN_DIVIDERDBLCLICKW
;
5383 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5384 ok(ret
== 0, "got %d\n", ret
);
5385 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_divider_dclick_seq
,
5386 "header notify, parent", TRUE
);
5387 ok(nmhdr
.hdr
.code
== HDN_DIVIDERDBLCLICKA
, "Expected ANSI notification code\n");
5388 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5389 nmhdr
.hdr
.code
= HDN_BEGINTRACKW
;
5390 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5391 ok(ret
== 0, "got %d\n", ret
);
5392 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5393 "header notify, parent", FALSE
);
5394 ok(nmhdr
.hdr
.code
== HDN_BEGINTRACKW
, "Expected Unicode notification code\n");
5395 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5396 nmhdr
.hdr
.code
= HDN_ENDTRACKW
;
5397 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5398 ok(ret
== 0, "got %d\n", ret
);
5399 parent_header_notify_seq
[0].id
= HDN_ENDTRACKA
;
5400 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5401 "header notify, parent", FALSE
);
5402 ok(nmhdr
.hdr
.code
== HDN_ENDTRACKA
, "Expected ANSI notification code\n");
5403 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5404 nmhdr
.hdr
.code
= HDN_TRACKW
;
5405 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5406 ok(ret
== 0, "got %d\n", ret
);
5407 parent_header_notify_seq
[0].id
= HDN_TRACKA
;
5408 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5409 "header notify, parent", FALSE
);
5410 ok(nmhdr
.hdr
.code
== HDN_TRACKA
, "Expected ANSI notification code\n");
5411 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5412 nmhdr
.hdr
.code
= HDN_BEGINDRAG
;
5413 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5414 ok(ret
== 1, "got %d\n", ret
);
5415 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5416 "header notify, parent", FALSE
);
5417 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5418 nmhdr
.hdr
.code
= HDN_ENDDRAG
;
5419 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5420 ok(ret
== 0, "got %d\n", ret
);
5421 parent_header_notify_seq
[0].id
= HDN_ENDDRAG
;
5422 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5423 "header notify, parent", FALSE
);
5424 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5425 nmhdr
.hdr
.code
= HDN_FILTERCHANGE
;
5426 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5427 ok(ret
== 0, "got %d\n", ret
);
5428 parent_header_notify_seq
[0].id
= HDN_FILTERCHANGE
;
5429 parent_header_notify_seq
[0].flags
|= optional
; /* NT4 does not send this message */
5430 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5431 "header notify, parent", FALSE
);
5432 parent_header_notify_seq
[0].flags
&= ~optional
;
5433 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5434 nmhdr
.hdr
.code
= HDN_BEGINFILTEREDIT
;
5435 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5436 ok(ret
== 0, "got %d\n", ret
);
5437 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5438 "header notify, parent", FALSE
);
5439 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5440 nmhdr
.hdr
.code
= HDN_ENDFILTEREDIT
;
5441 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5442 ok(ret
== 0, "got %d\n", ret
);
5443 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5444 "header notify, parent", FALSE
);
5445 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5446 nmhdr
.hdr
.code
= HDN_ITEMSTATEICONCLICK
;
5447 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5448 ok(ret
== 0, "got %d\n", ret
);
5449 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5450 "header notify, parent", FALSE
);
5451 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5452 nmhdr
.hdr
.code
= HDN_ITEMKEYDOWN
;
5453 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5454 ok(ret
== 0, "got %d\n", ret
);
5455 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5456 "header notify, parent", FALSE
);
5458 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5460 DestroyWindow(list
);
5463 static void test_createdragimage(void)
5469 list
= create_listview_control(LVS_ICON
);
5470 ok(list
!= NULL
, "failed to create listview window\n");
5472 insert_item(list
, 0);
5475 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, 0);
5476 ok(himl
== NULL
, "got %p\n", himl
);
5478 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, (LPARAM
)&pt
);
5479 ok(himl
!= NULL
, "got %p\n", himl
);
5480 ImageList_Destroy(himl
);
5482 DestroyWindow(list
);
5485 static void test_dispinfo(void)
5487 static const char testA
[] = "TEST";
5493 hwnd
= create_listview_control(LVS_ICON
);
5494 ok(hwnd
!= NULL
, "failed to create listview window\n");
5496 insert_item(hwnd
, 0);
5498 memset(&item
, 0, sizeof(item
));
5499 item
.pszText
= LPSTR_TEXTCALLBACKA
;
5500 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5503 g_disp_A_to_W
= TRUE
;
5504 item
.pszText
= (char*)buff
;
5505 item
.cchTextMax
= sizeof(buff
)/sizeof(WCHAR
);
5506 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
5507 ok(ret
== sizeof(testA
)-1, "got %d, expected 4\n", ret
);
5508 g_disp_A_to_W
= FALSE
;
5510 ok(memcmp(item
.pszText
, testA
, sizeof(testA
)) == 0,
5511 "got %s, expected %s\n", item
.pszText
, testA
);
5513 DestroyWindow(hwnd
);
5516 static void test_LVM_SETITEMTEXT(void)
5518 static char testA
[] = "TEST";
5523 hwnd
= create_listview_control(LVS_ICON
);
5524 ok(hwnd
!= NULL
, "failed to create listview window\n");
5526 insert_item(hwnd
, 0);
5528 /* null item pointer */
5529 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, 0);
5532 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTW
, 0, 0);
5535 /* index out of bounds */
5536 item
.pszText
= testA
;
5537 item
.cchTextMax
= 0; /* ignored */
5540 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 1, (LPARAM
)&item
);
5543 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, -1, (LPARAM
)&item
);
5546 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5549 DestroyWindow(hwnd
);
5552 static void test_imagelists(void)
5555 HIMAGELIST himl1
, himl2
, himl3
;
5558 himl1
= ImageList_Create(40, 40, 0, 4, 4);
5559 himl2
= ImageList_Create(40, 40, 0, 4, 4);
5560 himl3
= ImageList_Create(40, 40, 0, 4, 4);
5561 ok(himl1
!= NULL
, "Failed to create imagelist\n");
5562 ok(himl2
!= NULL
, "Failed to create imagelist\n");
5563 ok(himl3
!= NULL
, "Failed to create imagelist\n");
5565 hwnd
= create_listview_control(LVS_REPORT
| LVS_SHAREIMAGELISTS
);
5566 header
= subclass_header(hwnd
);
5568 ok(header
!= NULL
, "Expected header\n");
5569 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5570 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5572 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5574 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5575 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5576 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5577 "set normal image list", FALSE
);
5579 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5581 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5582 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5583 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5584 "set state image list", TRUE
);
5586 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5587 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5589 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5591 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5592 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5593 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_set_imagelist
,
5594 "set small image list", FALSE
);
5596 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5597 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5598 DestroyWindow(hwnd
);
5600 hwnd
= create_listview_control(WS_VISIBLE
| LVS_ICON
);
5602 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5604 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5605 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5606 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5607 "set normal image list", FALSE
);
5609 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5611 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5612 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5613 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5614 "set state image list", FALSE
);
5616 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5618 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5619 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5620 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5621 "set small image list", FALSE
);
5623 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5624 ok(header
== NULL
, "Expected no header, got %p\n", header
);
5626 SetWindowLongPtrA(hwnd
, GWL_STYLE
, GetWindowLongPtrA(hwnd
, GWL_STYLE
) | LVS_REPORT
);
5628 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5629 ok(header
!= NULL
, "Expected header, got NULL\n");
5631 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5632 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5634 DestroyWindow(hwnd
);
5637 static void test_deleteitem(void)
5644 hwnd
= create_listview_control(LVS_REPORT
);
5646 insert_item(hwnd
, 0);
5647 insert_item(hwnd
, 0);
5648 insert_item(hwnd
, 0);
5649 insert_item(hwnd
, 0);
5650 insert_item(hwnd
, 0);
5652 g_focus_test_LVN_DELETEITEM
= TRUE
;
5654 /* delete focused item (not the last index) */
5655 item
.stateMask
= LVIS_FOCUSED
;
5656 item
.state
= LVIS_FOCUSED
;
5657 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
5658 ok(ret
== TRUE
, "got %d\n", ret
);
5659 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 2, 0);
5660 ok(ret
== TRUE
, "got %d\n", ret
);
5661 /* next item gets focus */
5662 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5663 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5665 /* focus last item and delete it */
5666 item
.stateMask
= LVIS_FOCUSED
;
5667 item
.state
= LVIS_FOCUSED
;
5668 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
5669 ok(ret
== TRUE
, "got %d\n", ret
);
5670 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 3, 0);
5671 ok(ret
== TRUE
, "got %d\n", ret
);
5672 /* new last item gets focus */
5673 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5674 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5676 /* focus first item and delete it */
5677 item
.stateMask
= LVIS_FOCUSED
;
5678 item
.state
= LVIS_FOCUSED
;
5679 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
5680 ok(ret
== TRUE
, "got %d\n", ret
);
5681 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
5682 ok(ret
== TRUE
, "got %d\n", ret
);
5683 /* new first item gets focus */
5684 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5685 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5687 g_focus_test_LVN_DELETEITEM
= FALSE
;
5689 DestroyWindow(hwnd
);
5692 static void test_insertitem(void)
5699 hwnd
= create_listview_control(LVS_REPORT
);
5701 /* insert item 0 focused */
5702 item
.mask
= LVIF_STATE
;
5703 item
.state
= LVIS_FOCUSED
;
5704 item
.stateMask
= LVIS_FOCUSED
;
5707 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5708 ok(ret
== 0, "got %d\n", ret
);
5710 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5711 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5713 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5715 /* insert item 1, focus shift */
5716 item
.mask
= LVIF_STATE
;
5717 item
.state
= LVIS_FOCUSED
;
5718 item
.stateMask
= LVIS_FOCUSED
;
5721 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5722 ok(ret
== 1, "got %d\n", ret
);
5724 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_insert_focused_seq
, "insert focused", TRUE
);
5726 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5727 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5729 /* insert item 2, no focus shift */
5730 item
.mask
= LVIF_STATE
;
5732 item
.stateMask
= LVIS_FOCUSED
;
5735 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5736 ok(ret
== 2, "got %d\n", ret
);
5738 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5739 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5741 DestroyWindow(hwnd
);
5744 static void test_header_proc(void)
5746 HWND hwnd
, header
, hdr
;
5747 WNDPROC proc1
, proc2
;
5749 hwnd
= create_listview_control(LVS_REPORT
);
5751 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5752 ok(header
!= NULL
, "got %p\n", header
);
5754 hdr
= CreateWindowExA(0, WC_HEADERA
, NULL
,
5755 WS_BORDER
|WS_VISIBLE
|HDS_BUTTONS
|HDS_HORZ
,
5757 NULL
, NULL
, NULL
, NULL
);
5758 ok(hdr
!= NULL
, "got %p\n", hdr
);
5760 proc1
= (WNDPROC
)GetWindowLongPtrW(header
, GWLP_WNDPROC
);
5761 proc2
= (WNDPROC
)GetWindowLongPtrW(hdr
, GWLP_WNDPROC
);
5762 ok(proc1
== proc2
, "got %p, expected %p\n", proc1
, proc2
);
5765 DestroyWindow(hwnd
);
5768 static void flush_events(void)
5772 int min_timeout
= 100;
5773 DWORD time
= GetTickCount() + diff
;
5777 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
5778 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
5779 diff
= time
- GetTickCount();
5783 static void test_oneclickactivate(void)
5785 TRACKMOUSEEVENT track
;
5786 char item1
[] = "item1";
5793 hwnd
= CreateWindowExA(0, "SysListView32", "foo", WS_VISIBLE
|WS_CHILD
|LVS_LIST
,
5794 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
5795 ok(hwnd
!= NULL
, "failed to create listview window\n");
5796 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_ONECLICKACTIVATE
);
5797 ok(r
== 0, "should return zero\n");
5799 SetForegroundWindow(hwndparent
);
5801 fg
= GetForegroundWindow();
5802 if (fg
!= hwndparent
)
5804 skip("Window is not in the foreground. Skipping oneclickactivate tests.\n");
5805 DestroyWindow(hwnd
);
5809 item
.mask
= LVIF_TEXT
;
5813 item
.pszText
= item1
;
5814 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
5815 ok(r
== 0, "should not fail\n");
5817 GetWindowRect(hwnd
, &rect
);
5818 GetCursorPos(&orig_pos
);
5819 SetCursorPos(rect
.left
+5, rect
.top
+5);
5821 r
= SendMessageA(hwnd
, WM_MOUSEMOVE
, MAKELONG(1, 1), 0);
5824 track
.cbSize
= sizeof(track
);
5825 track
.dwFlags
= TME_QUERY
;
5826 _TrackMouseEvent(&track
);
5827 ok(track
.hwndTrack
== hwnd
, "hwndTrack != hwnd\n");
5828 ok(track
.dwFlags
== TME_LEAVE
, "dwFlags = %x\n", track
.dwFlags
);
5830 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
5832 r
= SendMessageA(hwnd
, WM_MOUSEHOVER
, MAKELONG(1, 1), 0);
5834 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
5837 DestroyWindow(hwnd
);
5838 SetCursorPos(orig_pos
.x
, orig_pos
.y
);
5841 static void test_callback_mask(void)
5847 hwnd
= create_listview_control(LVS_REPORT
);
5849 ret
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, ~0u, 0);
5850 ok(ret
, "got %d\n", ret
);
5852 ret
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, ~0u, 1);
5853 ok(ret
, "got %d\n", ret
);
5855 mask
= SendMessageA(hwnd
, LVM_GETCALLBACKMASK
, 0, 0);
5856 ok(mask
== ~0u, "got 0x%08x\n", mask
);
5858 DestroyWindow(hwnd
);
5861 START_TEST(listview
)
5864 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
5866 ULONG_PTR ctx_cookie
;
5869 hComctl32
= GetModuleHandleA("comctl32.dll");
5870 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
5871 if (pInitCommonControlsEx
)
5873 INITCOMMONCONTROLSEX iccex
;
5874 iccex
.dwSize
= sizeof(iccex
);
5875 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
5876 pInitCommonControlsEx(&iccex
);
5879 InitCommonControls();
5881 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
5883 hwndparent
= create_parent_window(FALSE
);
5884 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5886 g_is_below_5
= is_below_comctl_5();
5888 test_header_notification();
5889 test_header_notification2();
5896 test_icon_spacing();
5899 test_item_position();
5904 test_subitem_rect();
5908 test_nosortheader();
5912 test_getitemposition();
5913 test_columnscreation();
5915 test_notifyformat();
5917 test_getitemspacing();
5918 test_getcolumnwidth();
5919 test_approximate_viewrect();
5922 test_destroynotify();
5923 test_createdragimage();
5925 test_LVM_SETITEMTEXT();
5930 test_oneclickactivate();
5931 test_callback_mask();
5933 if (!load_v6_module(&ctx_cookie
, &hCtx
))
5935 DestroyWindow(hwndparent
);
5939 /* comctl32 version 6 tests start here */
5940 test_get_set_view();
5941 test_canceleditlabel();
5943 test_scrollnotify();
5944 test_LVS_EX_TRANSPARENTBKGND();
5945 test_LVS_EX_HEADERINALLVIEWS();
5951 unload_v6_module(ctx_cookie
, hCtx
);
5953 DestroyWindow(hwndparent
);