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
},
185 static const struct message empty_seq
[] = {
189 static const struct message forward_erasebkgnd_parent_seq
[] = {
190 { WM_ERASEBKGND
, sent
},
194 static const struct message ownderdata_select_focus_parent_seq
[] = {
195 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
196 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
197 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
}, /* version 4.7x */
201 static const struct message ownerdata_setstate_all_parent_seq
[] = {
202 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
206 static const struct message ownerdata_defocus_all_parent_seq
[] = {
207 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
208 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
209 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
},
210 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
214 static const struct message ownerdata_deselect_all_parent_seq
[] = {
215 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ODCACHEHINT
},
216 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
220 static const struct message change_all_parent_seq
[] = {
221 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
222 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
224 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
225 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
227 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
228 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
230 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
231 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
233 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
234 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
238 static const struct message changing_all_parent_seq
[] = {
239 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
240 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
241 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
242 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
243 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
247 static const struct message textcallback_set_again_parent_seq
[] = {
248 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
249 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
253 static const struct message single_getdispinfo_parent_seq
[] = {
254 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
258 static const struct message getitemposition_seq1
[] = {
259 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
263 static const struct message getitemposition_seq2
[] = {
264 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
265 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
269 static const struct message getsubitemrect_seq
[] = {
270 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, -1, 0, LISTVIEW_ID
},
271 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
272 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, 0, 0, LISTVIEW_ID
},
273 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
274 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, -10, 0, LISTVIEW_ID
},
275 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
276 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, 20, 0, LISTVIEW_ID
},
277 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
281 static const struct message editbox_create_pos
[] = {
282 /* sequence sent after LVN_BEGINLABELEDIT */
283 /* next two are 4.7x specific */
284 { WM_WINDOWPOSCHANGING
, sent
},
285 { WM_WINDOWPOSCHANGED
, sent
|optional
},
287 { WM_WINDOWPOSCHANGING
, sent
|optional
},
288 { WM_NCCALCSIZE
, sent
},
289 { WM_WINDOWPOSCHANGED
, sent
},
290 { WM_MOVE
, sent
|defwinproc
},
291 { WM_SIZE
, sent
|defwinproc
},
292 /* the rest is todo, skipped in 4.7x */
293 { WM_WINDOWPOSCHANGING
, sent
|optional
},
294 { WM_WINDOWPOSCHANGED
, sent
|optional
},
298 static const struct message scroll_parent_seq
[] = {
299 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_BEGINSCROLL
},
300 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDSCROLL
},
304 static const struct message setredraw_seq
[] = {
305 { WM_SETREDRAW
, sent
|id
|wparam
, FALSE
, 0, LISTVIEW_ID
},
309 static const struct message lvs_ex_transparentbkgnd_seq
[] = {
310 { WM_PRINTCLIENT
, sent
|lparam
, 0, PRF_ERASEBKGND
},
314 static const struct message edit_end_nochange
[] = {
315 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDLABELEDITA
},
316 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
}, /* todo */
317 { WM_NOTIFY
, sent
|id
, 0, 0, NM_SETFOCUS
},
321 static const struct message hover_parent
[] = {
322 { WM_GETDLGCODE
, sent
}, /* todo_wine */
323 { WM_NOTIFY
, sent
|id
, 0, 0, NM_HOVER
},
327 static const struct message listview_destroy
[] = {
328 { 0x0090, sent
|optional
}, /* Vista */
329 { WM_PARENTNOTIFY
, sent
},
330 { WM_SHOWWINDOW
, sent
},
331 { WM_WINDOWPOSCHANGING
, sent
},
332 { WM_WINDOWPOSCHANGED
, sent
|optional
},
333 { WM_DESTROY
, sent
},
334 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_DELETEALLITEMS
},
335 { WM_NCDESTROY
, sent
},
339 static const struct message listview_ownerdata_destroy
[] = {
340 { 0x0090, sent
|optional
}, /* Vista */
341 { WM_PARENTNOTIFY
, sent
},
342 { WM_SHOWWINDOW
, sent
},
343 { WM_WINDOWPOSCHANGING
, sent
},
344 { WM_WINDOWPOSCHANGED
, sent
|optional
},
345 { WM_DESTROY
, sent
},
346 { WM_NCDESTROY
, sent
},
350 static const struct message listview_ownerdata_deleteall
[] = {
351 { LVM_DELETEALLITEMS
, sent
},
352 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_DELETEALLITEMS
},
356 static const struct message listview_header_changed_seq
[] = {
357 { LVM_SETCOLUMNA
, sent
},
358 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
359 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
363 static const struct message parent_header_click_seq
[] = {
364 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_COLUMNCLICK
},
365 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCLICKA
},
369 static const struct message parent_header_divider_dclick_seq
[] = {
370 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCHANGINGA
},
371 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
},
372 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
},
373 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCHANGEDA
},
374 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_DIVIDERDBLCLICKA
},
378 static const struct message listview_set_imagelist
[] = {
379 { LVM_SETIMAGELIST
, sent
|id
, 0, 0, LISTVIEW_ID
},
383 static const struct message listview_header_set_imagelist
[] = {
384 { LVM_SETIMAGELIST
, sent
|id
, 0, 0, LISTVIEW_ID
},
385 { HDM_SETIMAGELIST
, sent
|id
, 0, 0, HEADER_ID
},
389 static const struct message parent_insert_focused_seq
[] = {
390 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
391 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
392 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
393 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
394 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_INSERTITEM
},
398 static const struct message parent_report_cd_seq
[] = {
399 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_PREPAINT
},
400 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
},
401 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
|CDDS_SUBITEM
},
402 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
|CDDS_SUBITEM
},
403 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
|CDDS_SUBITEM
},
404 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
|CDDS_SUBITEM
},
405 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
},
406 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_POSTPAINT
},
410 static const struct message parent_list_cd_seq
[] = {
411 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_PREPAINT
},
412 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
},
413 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
},
414 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_POSTPAINT
},
418 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
420 static LONG defwndproc_counter
= 0;
424 msg
.message
= message
;
425 msg
.flags
= sent
|wparam
|lparam
;
426 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
429 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
431 /* log system messages, except for painting */
432 if (message
< WM_USER
&&
433 message
!= WM_PAINT
&&
434 message
!= WM_ERASEBKGND
&&
435 message
!= WM_NCPAINT
&&
436 message
!= WM_NCHITTEST
&&
437 message
!= WM_GETTEXT
&&
438 message
!= WM_GETICON
&&
439 message
!= WM_DEVICECHANGE
)
441 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
442 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
444 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
450 switch (((NMHDR
*)lParam
)->code
)
452 case LVN_BEGINLABELEDITA
:
456 /* subclass edit box */
458 edit
= subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
462 INT len
= SendMessageA(edit
, EM_GETLIMITTEXT
, 0, 0);
463 ok(len
== 259 || broken(len
== 260) /* includes NULL in NT4 */,
464 "text limit %d, expected 259\n", len
);
469 case LVN_ENDLABELEDITA
:
473 /* always accept new item text */
474 NMLVDISPINFOA
*di
= (NMLVDISPINFOA
*)lParam
;
475 g_editbox_disp_info
= *di
;
476 trace("LVN_ENDLABELEDIT: text=%s\n", di
->item
.pszText
? di
->item
.pszText
: "(null)");
478 /* edit control still available from this notification */
479 edit
= (HWND
)SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETEDITCONTROL
, 0, 0);
480 ok(IsWindow(edit
), "expected valid edit control handle\n");
481 ok((GetWindowLongA(edit
, GWL_STYLE
) & ES_MULTILINE
) == 0, "edit is multiline\n");
485 case LVN_BEGINSCROLL
:
488 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
490 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
491 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
494 case LVN_ITEMCHANGING
:
496 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
497 g_nmlistview_changing
= *nmlv
;
500 case LVN_ITEMCHANGED
:
502 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
503 g_nmlistview
= *nmlv
;
506 case LVN_GETDISPINFOA
:
508 NMLVDISPINFOA
*dispinfo
= (NMLVDISPINFOA
*)lParam
;
509 g_itema
= dispinfo
->item
;
511 if (g_disp_A_to_W
&& (dispinfo
->item
.mask
& LVIF_TEXT
))
513 static const WCHAR testW
[] = {'T','E','S','T',0};
514 dispinfo
->hdr
.code
= LVN_GETDISPINFOW
;
515 memcpy(dispinfo
->item
.pszText
, testW
, sizeof(testW
));
518 /* test control buffer size for text, 10 used to mask cases when control
519 is using caller buffer to process LVM_GETITEM for example */
520 if (dispinfo
->item
.mask
& LVIF_TEXT
&& dispinfo
->item
.cchTextMax
> 10)
521 ok(dispinfo
->item
.cchTextMax
== 260 ||
522 broken(dispinfo
->item
.cchTextMax
== 264) /* NT4 reports aligned size */,
523 "buffer size %d\n", dispinfo
->item
.cchTextMax
);
527 if (g_focus_test_LVN_DELETEITEM
)
529 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
532 state
= SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETITEMSTATE
, nmlv
->iItem
, LVIS_FOCUSED
);
533 ok(state
== 0, "got state %x\n", state
);
537 if (g_block_hover
) return 1;
542 case WM_NOTIFYFORMAT
:
544 /* force to return format */
545 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
550 defwndproc_counter
++;
551 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
552 defwndproc_counter
--;
557 static BOOL
register_parent_wnd_class(BOOL Unicode
)
565 clsW
.lpfnWndProc
= parent_wnd_proc
;
568 clsW
.hInstance
= GetModuleHandleW(NULL
);
570 clsW
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
571 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
572 clsW
.lpszMenuName
= NULL
;
573 clsW
.lpszClassName
= testparentclassW
;
578 clsA
.lpfnWndProc
= parent_wnd_proc
;
581 clsA
.hInstance
= GetModuleHandleA(NULL
);
583 clsA
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
584 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
585 clsA
.lpszMenuName
= NULL
;
586 clsA
.lpszClassName
= "Listview test parent class";
589 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
592 static HWND
create_parent_window(BOOL Unicode
)
594 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
597 if (!register_parent_wnd_class(Unicode
))
604 hwnd
= CreateWindowExW(0, testparentclassW
, nameW
,
605 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
606 WS_MAXIMIZEBOX
| WS_VISIBLE
,
608 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
610 hwnd
= CreateWindowExA(0, "Listview test parent class",
611 "Listview test parent window",
612 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
613 WS_MAXIMIZEBOX
| WS_VISIBLE
,
615 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
616 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
620 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
622 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
623 static LONG defwndproc_counter
= 0;
627 /* some debug output for style changing */
628 if ((message
== WM_STYLECHANGING
||
629 message
== WM_STYLECHANGED
) && lParam
)
631 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
632 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
635 msg
.message
= message
;
636 msg
.flags
= sent
|wparam
|lparam
;
637 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
640 msg
.id
= LISTVIEW_ID
;
641 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
642 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
644 defwndproc_counter
++;
645 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
646 defwndproc_counter
--;
650 static HWND
create_listview_control(DWORD style
)
656 GetClientRect(hwndparent
, &rect
);
657 hwnd
= CreateWindowExA(0, WC_LISTVIEWA
, "foo",
658 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
659 0, 0, rect
.right
, rect
.bottom
,
660 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
661 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
663 if (!hwnd
) return NULL
;
665 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
666 (LONG_PTR
)listview_subclass_proc
);
667 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
672 /* unicode listview window with specified parent */
673 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
678 static const WCHAR nameW
[] = {'f','o','o',0};
680 GetClientRect(parent
, &rect
);
681 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
682 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
683 0, 0, rect
.right
, rect
.bottom
,
684 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
685 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
687 if (!hwnd
) return NULL
;
689 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
690 (LONG_PTR
)listview_subclass_proc
);
691 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
696 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
698 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
699 static LONG defwndproc_counter
= 0;
703 msg
.message
= message
;
704 msg
.flags
= sent
|wparam
|lparam
;
705 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
709 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
711 defwndproc_counter
++;
712 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
713 defwndproc_counter
--;
717 static HWND
subclass_header(HWND hwndListview
)
722 hwnd
= (HWND
)SendMessageA(hwndListview
, LVM_GETHEADER
, 0, 0);
723 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
724 (LONG_PTR
)header_subclass_proc
);
725 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
730 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
732 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
733 static LONG defwndproc_counter
= 0;
737 msg
.message
= message
;
738 msg
.flags
= sent
|wparam
|lparam
;
739 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
744 /* all we need is sizing */
745 if (message
== WM_WINDOWPOSCHANGING
||
746 message
== WM_NCCALCSIZE
||
747 message
== WM_WINDOWPOSCHANGED
||
748 message
== WM_MOVE
||
751 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
754 defwndproc_counter
++;
755 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
756 defwndproc_counter
--;
760 static HWND
subclass_editbox(HWND hwndListview
)
765 hwnd
= (HWND
)SendMessageA(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
766 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
767 (LONG_PTR
)editbox_subclass_proc
);
768 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
773 /* Performs a single LVM_HITTEST test */
774 static void test_lvm_hittest_(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
, UINT broken_flags
,
775 BOOL todo_item
, BOOL todo_flags
, int line
)
784 ret
= SendMessageA(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
790 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
791 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
792 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
797 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
798 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
799 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
805 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
807 else if (broken_flags
)
808 ok_(__FILE__
, line
)(lpht
.flags
== flags
|| broken(lpht
.flags
== broken_flags
),
809 "Expected flags %x, got %x\n", flags
, lpht
.flags
);
811 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
814 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
816 /* Performs a single LVM_SUBITEMHITTEST test */
817 static void test_lvm_subitemhittest_(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
818 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
826 ret
= SendMessageA(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
832 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
833 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
838 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
839 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
845 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
848 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
853 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
856 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
859 #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__)
861 static void test_images(void)
869 static CHAR hello
[] = "hello";
871 himl
= ImageList_Create(40, 40, 0, 4, 4);
872 ok(himl
!= NULL
, "failed to create imagelist\n");
874 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
875 ok(hbmp
!= NULL
, "failed to create bitmap\n");
877 r
= ImageList_Add(himl
, hbmp
, 0);
878 ok(r
== 0, "should be zero\n");
880 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
881 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
882 ok(hwnd
!= NULL
, "failed to create listview window\n");
884 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
885 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
887 ok(r
== 0, "should return zero\n");
889 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
890 ok(r
== 0, "should return zero\n");
892 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
893 ok(r
!= 0, "got 0\n");
895 /* returns dimensions */
897 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
898 ok(r
== 0, "should be zero items\n");
900 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
905 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
906 ok(r
== -1, "should fail\n");
909 item
.pszText
= hello
;
910 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
911 ok(r
== 0, "should not fail\n");
913 memset(&r1
, 0, sizeof r1
);
915 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
918 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
919 ok(r
== TRUE
, "should not fail\n");
922 item
.pszText
= hello
;
923 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
924 ok(r
== 0, "should not fail\n");
926 memset(&r2
, 0, sizeof r2
);
928 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
931 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
936 static void test_checkboxes(void)
941 static CHAR text
[] = "Text",
945 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
946 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
947 ok(hwnd
!= NULL
, "failed to create listview window\n");
949 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
950 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
951 item
.stateMask
= 0xffff;
956 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
960 item
.mask
= LVIF_STATE
;
961 item
.stateMask
= 0xffff;
962 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
964 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
966 /* Don't set LVIF_STATE */
967 item
.mask
= LVIF_TEXT
;
968 item
.stateMask
= 0xffff;
973 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
977 item
.mask
= LVIF_STATE
;
978 item
.stateMask
= 0xffff;
979 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
981 ok(item
.state
== 0, "state %x\n", item
.state
);
983 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
986 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
988 item
.mask
= LVIF_STATE
;
989 item
.stateMask
= 0xffff;
990 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
992 if (item
.state
!= 0x1ccc)
994 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
999 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
1001 item
.mask
= LVIF_TEXT
;
1003 item
.pszText
= text2
;
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
== 0x1000, "state %x\n", item
.state
);
1014 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
1016 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
1017 item
.stateMask
= 0xffff;
1018 item
.state
= 0x2aaa;
1019 item
.pszText
= text3
;
1020 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1024 item
.mask
= LVIF_STATE
;
1025 item
.stateMask
= 0xffff;
1026 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1028 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
1030 /* Set an item's state to checked */
1032 item
.mask
= LVIF_STATE
;
1033 item
.stateMask
= 0xf000;
1034 item
.state
= 0x2000;
1035 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1039 item
.mask
= LVIF_STATE
;
1040 item
.stateMask
= 0xffff;
1041 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1043 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1045 /* Check that only the bits we asked for are returned,
1046 * and that all the others are set to zero
1049 item
.mask
= LVIF_STATE
;
1050 item
.stateMask
= 0xf000;
1051 item
.state
= 0xffff;
1052 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1054 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
1056 /* Set the style again and check that doesn't change an item's state */
1057 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1058 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1061 item
.mask
= LVIF_STATE
;
1062 item
.stateMask
= 0xffff;
1063 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1065 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1067 /* Unsetting the checkbox extended style doesn't change an item's state */
1068 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
1069 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1072 item
.mask
= LVIF_STATE
;
1073 item
.stateMask
= 0xffff;
1074 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1076 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1078 /* Now setting the style again will change an item's state */
1079 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1083 item
.mask
= LVIF_STATE
;
1084 item
.stateMask
= 0xffff;
1085 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1087 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
1089 /* Toggle checkbox tests (bug 9934) */
1090 memset (&item
, 0xcc, sizeof(item
));
1091 item
.mask
= LVIF_STATE
;
1094 item
.state
= LVIS_FOCUSED
;
1095 item
.stateMask
= LVIS_FOCUSED
;
1096 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1100 item
.mask
= LVIF_STATE
;
1101 item
.stateMask
= 0xffff;
1102 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1104 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1106 r
= SendMessageA(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1108 r
= SendMessageA(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1112 item
.mask
= LVIF_STATE
;
1113 item
.stateMask
= 0xffff;
1114 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1116 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
1118 r
= SendMessageA(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1120 r
= SendMessageA(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1124 item
.mask
= LVIF_STATE
;
1125 item
.stateMask
= 0xffff;
1126 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1128 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1130 DestroyWindow(hwnd
);
1133 static void insert_column(HWND hwnd
, int idx
)
1138 memset(&column
, 0xcc, sizeof(column
));
1139 column
.mask
= LVCF_SUBITEM
;
1140 column
.iSubItem
= idx
;
1142 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, idx
, (LPARAM
)&column
);
1146 static void insert_item(HWND hwnd
, int idx
)
1148 static CHAR text
[] = "foo";
1153 memset(&item
, 0xcc, sizeof (item
));
1154 item
.mask
= LVIF_TEXT
;
1157 item
.pszText
= text
;
1159 rc
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
1163 static void test_items(void)
1165 const LPARAM lparamTest
= 0x42;
1166 static CHAR text
[] = "Text";
1172 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1173 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1174 ok(hwnd
!= NULL
, "failed to create listview window\n");
1177 * Test setting/getting item params
1180 /* Set up two columns */
1181 insert_column(hwnd
, 0);
1182 insert_column(hwnd
, 1);
1184 /* LVIS_SELECTED with zero stateMask */
1186 memset (&item
, 0, sizeof (item
));
1187 item
.mask
= LVIF_STATE
;
1188 item
.state
= LVIS_SELECTED
;
1192 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1195 memset (&item
, 0xcc, sizeof (item
));
1196 item
.mask
= LVIF_STATE
;
1197 item
.stateMask
= LVIS_SELECTED
;
1201 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1203 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1204 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1206 /* LVIS_SELECTED with zero stateMask */
1208 memset (&item
, 0, sizeof (item
));
1209 item
.mask
= LVIF_STATE
;
1210 item
.state
= LVIS_FOCUSED
;
1214 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1217 memset (&item
, 0xcc, sizeof (item
));
1218 item
.mask
= LVIF_STATE
;
1219 item
.stateMask
= LVIS_FOCUSED
;
1223 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1225 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1226 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1228 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1230 memset (&item
, 0, sizeof (item
));
1231 item
.mask
= LVIF_STATE
;
1232 item
.state
= LVIS_CUT
;
1233 item
.stateMask
= LVIS_FOCUSED
;
1236 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1239 memset (&item
, 0xcc, sizeof (item
));
1240 item
.mask
= LVIF_STATE
;
1241 item
.stateMask
= LVIS_CUT
;
1245 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1247 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1248 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1250 /* Insert an item with just a param */
1251 memset (&item
, 0xcc, sizeof (item
));
1252 item
.mask
= LVIF_PARAM
;
1255 item
.lParam
= lparamTest
;
1256 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1259 /* Test getting of the param */
1260 memset (&item
, 0xcc, sizeof (item
));
1261 item
.mask
= LVIF_PARAM
;
1264 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1266 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1268 /* Set up a subitem */
1269 memset (&item
, 0xcc, sizeof (item
));
1270 item
.mask
= LVIF_TEXT
;
1273 item
.pszText
= text
;
1274 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1277 item
.mask
= LVIF_TEXT
;
1280 item
.pszText
= buffA
;
1281 item
.cchTextMax
= sizeof(buffA
);
1282 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1284 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got text %s, expected %s\n", item
.pszText
, text
);
1286 /* set up with extra flag */
1287 /* 1. reset subitem text */
1288 item
.mask
= LVIF_TEXT
;
1291 item
.pszText
= NULL
;
1292 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1295 item
.mask
= LVIF_TEXT
;
1298 item
.pszText
= buffA
;
1300 item
.cchTextMax
= sizeof(buffA
);
1301 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1303 ok(item
.pszText
[0] == 0, "got %p\n", item
.pszText
);
1305 /* 2. set new text with extra flag specified */
1306 item
.mask
= LVIF_TEXT
| LVIF_DI_SETITEM
;
1309 item
.pszText
= text
;
1310 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1311 ok(r
== 1 || broken(r
== 0) /* NT4 */, "ret %d\n", r
);
1315 item
.mask
= LVIF_TEXT
;
1318 item
.pszText
= buffA
;
1320 item
.cchTextMax
= sizeof(buffA
);
1321 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1323 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got %s, expected %s\n", item
.pszText
, text
);
1326 /* Query param from subitem: returns main item param */
1327 memset (&item
, 0xcc, sizeof (item
));
1328 item
.mask
= LVIF_PARAM
;
1331 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1333 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1335 /* Set up param on first subitem: no effect */
1336 memset (&item
, 0xcc, sizeof (item
));
1337 item
.mask
= LVIF_PARAM
;
1340 item
.lParam
= lparamTest
+1;
1341 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1344 /* Query param from subitem again: should still return main item param */
1345 memset (&item
, 0xcc, sizeof (item
));
1346 item
.mask
= LVIF_PARAM
;
1349 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1351 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1353 /**** Some tests of state highlighting ****/
1354 memset (&item
, 0xcc, sizeof (item
));
1355 item
.mask
= LVIF_STATE
;
1358 item
.state
= LVIS_SELECTED
;
1359 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1360 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1363 item
.state
= LVIS_DROPHILITED
;
1364 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1367 memset (&item
, 0xcc, sizeof (item
));
1368 item
.mask
= LVIF_STATE
;
1371 item
.stateMask
= -1;
1372 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1374 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1376 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1378 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1380 /* some notnull but meaningless masks */
1381 memset (&item
, 0, sizeof(item
));
1382 item
.mask
= LVIF_NORECOMPUTE
;
1385 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1387 memset (&item
, 0, sizeof(item
));
1388 item
.mask
= LVIF_DI_SETITEM
;
1391 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1394 /* set text to callback value already having it */
1395 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1397 memset (&item
, 0, sizeof (item
));
1398 item
.mask
= LVIF_TEXT
;
1399 item
.pszText
= LPSTR_TEXTCALLBACKA
;
1401 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1403 memset (&item
, 0, sizeof (item
));
1405 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1407 item
.pszText
= LPSTR_TEXTCALLBACKA
;
1408 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0 , (LPARAM
) &item
);
1411 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1412 "check callback text comparison rule", FALSE
);
1414 DestroyWindow(hwnd
);
1417 static void test_columns(void)
1426 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1427 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1428 ok(hwnd
!= NULL
, "failed to create listview window\n");
1430 /* Add a column with no mask */
1431 memset(&column
, 0xcc, sizeof(column
));
1433 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1434 ok(rc
== 0, "Inserting column with no mask failed with %d\n", rc
);
1436 /* Check its width */
1437 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
1438 ok(rc
== 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1440 DestroyWindow(hwnd
);
1442 /* LVM_GETCOLUMNORDERARRAY */
1443 hwnd
= create_listview_control(LVS_REPORT
);
1444 subclass_header(hwnd
);
1446 memset(&column
, 0, sizeof(column
));
1447 column
.mask
= LVCF_WIDTH
;
1449 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1453 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&column
);
1456 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1458 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1460 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1461 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1463 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1465 /* after column added subitem is considered as present */
1466 insert_item(hwnd
, 0);
1468 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1470 item
.pszText
= buff
;
1471 item
.cchTextMax
= sizeof(buff
);
1474 item
.mask
= LVIF_TEXT
;
1475 memset(&g_itema
, 0, sizeof(g_itema
));
1476 rc
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
1478 ok(g_itema
.iSubItem
== 1, "got %d\n", g_itema
.iSubItem
);
1480 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
1481 "get subitem text after column added", FALSE
);
1483 DestroyWindow(hwnd
);
1486 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1487 static WNDPROC listviewWndProc
;
1488 static HIMAGELIST test_create_imagelist
;
1490 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1494 if (uMsg
== WM_CREATE
)
1496 CREATESTRUCTA
*lpcs
= (CREATESTRUCTA
*)lParam
;
1497 lpcs
->style
|= LVS_REPORT
;
1499 ret
= CallWindowProcA(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1500 if (uMsg
== WM_CREATE
) SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1504 static void test_create(void)
1515 cls
.cbSize
= sizeof(WNDCLASSEXA
);
1516 ok(GetClassInfoExA(GetModuleHandleA(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1517 listviewWndProc
= cls
.lpfnWndProc
;
1518 cls
.lpfnWndProc
= create_test_wndproc
;
1519 cls
.lpszClassName
= "MyListView32";
1520 ok(RegisterClassExA(&cls
), "RegisterClassEx failed\n");
1522 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1523 hList
= CreateWindowA("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1524 ok((HIMAGELIST
)SendMessageA(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1525 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1527 if (!IsWindow(hHeader
))
1530 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1531 DestroyWindow(hList
);
1535 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1536 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1537 DestroyWindow(hList
);
1539 /* header isn't created on LVS_ICON and LVS_LIST styles */
1540 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1541 GetModuleHandleA(NULL
), 0);
1542 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1543 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1544 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1546 memset(&col
, 0, sizeof(LVCOLUMNA
));
1547 col
.mask
= LVCF_WIDTH
;
1549 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1551 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1552 ok(IsWindow(hHeader
), "Header should be created\n");
1553 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1554 style
= GetWindowLongA(hHeader
, GWL_STYLE
);
1555 ok(!(style
& HDS_HIDDEN
), "Not expected HDS_HIDDEN\n");
1556 DestroyWindow(hList
);
1558 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1559 GetModuleHandleA(NULL
), 0);
1560 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1561 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1562 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1564 memset(&col
, 0, sizeof(LVCOLUMNA
));
1565 col
.mask
= LVCF_WIDTH
;
1567 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1569 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1570 ok(IsWindow(hHeader
), "Header should be created\n");
1571 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1572 DestroyWindow(hList
);
1574 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1575 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1576 GetModuleHandleA(NULL
), 0);
1577 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
, GetWindowLongPtrA(hList
, GWL_STYLE
) | LVS_REPORT
);
1578 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1579 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1580 ok(IsWindow(hHeader
), "Header should be created\n");
1581 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
, GetWindowLongA(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1582 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1583 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1584 ok(IsWindow(hHeader
), "Header should be created\n");
1585 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1586 DestroyWindow(hList
);
1588 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1589 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1590 GetModuleHandleA(NULL
), 0);
1591 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
,
1592 (GetWindowLongPtrA(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1593 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1594 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1595 ok(IsWindow(hHeader
), "Header should be created\n");
1596 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1597 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
,
1598 (GetWindowLongPtrA(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1599 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1600 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1601 ok(IsWindow(hHeader
), "Header should be created\n");
1602 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1603 DestroyWindow(hList
);
1605 /* LVS_REPORT without WS_VISIBLE */
1606 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1607 GetModuleHandleA(NULL
), 0);
1608 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1609 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1610 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1612 memset(&col
, 0, sizeof(LVCOLUMNA
));
1613 col
.mask
= LVCF_WIDTH
;
1615 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1617 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1618 ok(IsWindow(hHeader
), "Header should be created\n");
1619 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1620 DestroyWindow(hList
);
1622 /* LVS_REPORT without WS_VISIBLE, try to show it */
1623 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1624 GetModuleHandleA(NULL
), 0);
1625 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1626 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1627 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1628 ShowWindow(hList
, SW_SHOW
);
1629 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1630 ok(IsWindow(hHeader
), "Header should be created\n");
1631 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1632 DestroyWindow(hList
);
1634 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1635 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1636 0, 0, 100, 100, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1637 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1638 ok(IsWindow(hHeader
), "Header should be created\n");
1639 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1640 /* HDS_DRAGDROP set by default */
1641 ok(GetWindowLongPtrA(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1642 DestroyWindow(hList
);
1644 /* setting LVS_EX_HEADERDRAGDROP creates header */
1645 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1646 GetModuleHandleA(NULL
), 0);
1647 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1648 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1649 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1650 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1651 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1652 ok(IsWindow(hHeader
) ||
1653 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1654 "Header should be created\n");
1655 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1656 DestroyWindow(hList
);
1658 /* setting LVS_EX_GRIDLINES creates header */
1659 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1660 GetModuleHandleA(NULL
), 0);
1661 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1662 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1663 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1664 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_GRIDLINES
);
1665 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1666 ok(IsWindow(hHeader
) ||
1667 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1668 "Header should be created\n");
1669 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1670 DestroyWindow(hList
);
1672 /* setting LVS_EX_FULLROWSELECT creates header */
1673 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1674 GetModuleHandleA(NULL
), 0);
1675 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1676 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1677 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1678 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
1679 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1680 ok(IsWindow(hHeader
) ||
1681 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1682 "Header should be created\n");
1683 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1684 DestroyWindow(hList
);
1686 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1687 hList
= create_listview_control(LVS_ICON
);
1688 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1689 r
= SendMessageA(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1690 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1691 DestroyWindow(hList
);
1693 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1694 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1695 GetModuleHandleA(NULL
), 0);
1696 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1697 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1699 rect
.left
= LVIR_BOUNDS
;
1701 rect
.right
= rect
.bottom
= -10;
1702 r
= SendMessageA(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1703 /* right value contains garbage, probably because header columns are not set up */
1704 expect(0, rect
.bottom
);
1707 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1708 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1709 ok(GetDlgItem(hList
, 0) == NULL
, "NULL dialog item expected\n");
1711 DestroyWindow(hList
);
1713 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1714 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1715 hList
= create_listview_control(LVS_OWNERDRAWFIXED
| LVS_REPORT
);
1716 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1717 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1718 DestroyWindow(hList
);
1721 static void test_redraw(void)
1728 hwnd
= create_listview_control(LVS_REPORT
);
1729 subclass_header(hwnd
);
1731 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1733 InvalidateRect(hwnd
, NULL
, TRUE
);
1735 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1737 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1739 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1740 /* 1. Without backbuffer */
1741 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
1744 hdc
= GetWindowDC(hwndparent
);
1746 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1747 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1748 ok(r
== 1, "Expected not zero result\n");
1749 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1750 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1752 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_DEFAULT
);
1755 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1756 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1758 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1759 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1761 /* 2. With backbuffer */
1762 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1763 LVS_EX_DOUBLEBUFFER
);
1764 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
1767 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1768 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1770 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1771 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1773 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_DEFAULT
);
1776 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1777 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1778 todo_wine
expect(1, r
);
1779 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1780 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1782 ReleaseDC(hwndparent
, hdc
);
1784 DestroyWindow(hwnd
);
1787 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1789 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1791 if(message
== WM_NOTIFY
) {
1792 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1793 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1794 NMLVCUSTOMDRAW
*nmlvcd
= (NMLVCUSTOMDRAW
*)nmhdr
;
1797 msg
.message
= message
;
1798 msg
.flags
= sent
|wparam
|lparam
|custdraw
;
1799 msg
.wParam
= wParam
;
1800 msg
.lParam
= lParam
;
1801 msg
.id
= nmhdr
->code
;
1802 msg
.stage
= nmlvcd
->nmcd
.dwDrawStage
;
1803 add_message(sequences
, PARENT_CD_SEQ_INDEX
, &msg
);
1805 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1807 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1808 return CDRF_NOTIFYITEMDRAW
|CDRF_NOTIFYPOSTPAINT
;
1809 case CDDS_ITEMPREPAINT
:
1810 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1811 nmlvcd
->clrText
= RGB(0, 255, 0);
1812 return CDRF_NOTIFYSUBITEMDRAW
|CDRF_NOTIFYPOSTPAINT
;
1813 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1814 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1815 ok(nmlvcd
->clrTextBk
== CLR_DEFAULT
, "got 0x%x\n", nmlvcd
->clrTextBk
);
1816 ok(nmlvcd
->clrText
== RGB(0, 255, 0), "got 0x%x\n", nmlvcd
->clrText
);
1817 if (nmlvcd
->iSubItem
)
1818 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1820 ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1821 return CDRF_NOTIFYPOSTPAINT
;
1822 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1823 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1824 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1825 ok(nmlvcd
->clrTextBk
== CLR_DEFAULT
, "got 0x%x\n", nmlvcd
->clrTextBk
);
1826 ok(nmlvcd
->clrText
== RGB(0, 255, 0), "got 0x%x\n", nmlvcd
->clrText
);
1827 return CDRF_DODEFAULT
;
1829 return CDRF_DODEFAULT
;
1833 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1836 static void test_customdraw(void)
1841 hwnd
= create_listview_control(LVS_REPORT
);
1843 insert_column(hwnd
, 0);
1844 insert_column(hwnd
, 1);
1845 insert_item(hwnd
, 0);
1847 oldwndproc
= (WNDPROC
)SetWindowLongPtrA(hwndparent
, GWLP_WNDPROC
,
1848 (LONG_PTR
)cd_wndproc
);
1850 InvalidateRect(hwnd
, NULL
, TRUE
);
1854 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1855 InvalidateRect(hwnd
, NULL
, TRUE
);
1857 ok_sequence(sequences
, PARENT_CD_SEQ_INDEX
, parent_report_cd_seq
, "parent customdraw, LVS_REPORT", FALSE
);
1859 DestroyWindow(hwnd
);
1861 hwnd
= create_listview_control(LVS_LIST
);
1863 insert_column(hwnd
, 0);
1864 insert_column(hwnd
, 1);
1865 insert_item(hwnd
, 0);
1867 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1868 InvalidateRect(hwnd
, NULL
, TRUE
);
1870 ok_sequence(sequences
, PARENT_CD_SEQ_INDEX
, parent_list_cd_seq
, "parent customdraw, LVS_LIST", FALSE
);
1872 SetWindowLongPtrA(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1873 DestroyWindow(hwnd
);
1876 static void test_icon_spacing(void)
1878 /* LVM_SETICONSPACING */
1879 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1885 hwnd
= create_listview_control(LVS_ICON
);
1886 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1888 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, NF_REQUERY
);
1889 expect(NFR_ANSI
, r
);
1891 /* reset the icon spacing to defaults */
1892 SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1894 /* now we can request what the defaults are */
1895 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1899 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1901 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1902 ok(r
== MAKELONG(w
, h
) ||
1903 broken(r
== MAKELONG(w
, w
)), /* win98 */
1904 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1906 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1910 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1911 DestroyWindow(hwnd
);
1914 expect(MAKELONG(20,30), r
);
1916 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1917 expect(MAKELONG(25,35), r
);
1919 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1921 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1922 DestroyWindow(hwnd
);
1925 static void test_color(void)
1933 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1935 hwnd
= create_listview_control(LVS_REPORT
);
1936 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1938 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1940 for (i
= 0; i
< 4; i
++)
1944 r
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1946 r
= SendMessageA(hwnd
, LVM_GETBKCOLOR
, 0, 0);
1949 r
= SendMessageA(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1951 r
= SendMessageA(hwnd
, LVM_GETTEXTCOLOR
, 0, 0);
1954 r
= SendMessageA(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1956 r
= SendMessageA(hwnd
, LVM_GETTEXTBKCOLOR
, 0, 0);
1960 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1961 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1963 /* invalidation test done separately to avoid a message chain mess */
1964 r
= ValidateRect(hwnd
, NULL
);
1966 r
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, colors
[0]);
1969 rect
.right
= rect
.bottom
= 1;
1970 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1971 todo_wine
expect(FALSE
, r
);
1972 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1974 r
= ValidateRect(hwnd
, NULL
);
1976 r
= SendMessageA(hwnd
, LVM_SETTEXTCOLOR
, 0, colors
[0]);
1979 rect
.right
= rect
.bottom
= 1;
1980 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1981 todo_wine
expect(FALSE
, r
);
1982 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1984 r
= ValidateRect(hwnd
, NULL
);
1986 r
= SendMessageA(hwnd
, LVM_SETTEXTBKCOLOR
, 0, colors
[0]);
1989 rect
.right
= rect
.bottom
= 1;
1990 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1991 todo_wine
expect(FALSE
, r
);
1992 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1994 DestroyWindow(hwnd
);
1997 static void test_item_count(void)
1999 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
2012 static CHAR item0text
[] = "item0";
2013 static CHAR item1text
[] = "item1";
2014 static CHAR item2text
[] = "item2";
2016 hwnd
= create_listview_control(LVS_REPORT
);
2017 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2019 /* resize in dpiaware manner to fit all 3 items added */
2021 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
2022 GetTextMetricsA(hdc
, &tm
);
2023 /* 2 extra pixels for bounds and header border */
2024 height
= tm
.tmHeight
+ 2;
2025 SelectObject(hdc
, hOldFont
);
2028 GetWindowRect(hwnd
, &rect
);
2029 /* 3 items + 1 header + 1 to be sure */
2030 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
2032 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2034 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2038 item0
.mask
= LVIF_TEXT
;
2041 item0
.pszText
= item0text
;
2042 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item0
);
2045 /* [item0, item1] */
2046 item1
.mask
= LVIF_TEXT
;
2049 item1
.pszText
= item1text
;
2050 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2053 /* [item0, item1, item2] */
2054 item2
.mask
= LVIF_TEXT
;
2057 item2
.pszText
= item2text
;
2058 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2061 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2064 /* [item0, item1] */
2065 r
= SendMessageA(hwnd
, LVM_DELETEITEM
, 2, 0);
2068 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2072 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
2075 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2079 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2082 /* [item0, item1] */
2083 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2086 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2089 /* [item0, item1, item2] */
2090 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2093 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2096 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
2098 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2099 DestroyWindow(hwnd
);
2102 static void test_item_position(void)
2104 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2113 static CHAR item0text
[] = "item0";
2114 static CHAR item1text
[] = "item1";
2115 static CHAR item2text
[] = "item2";
2117 hwnd
= create_listview_control(LVS_ICON
);
2118 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2120 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2123 item0
.mask
= LVIF_TEXT
;
2126 item0
.pszText
= item0text
;
2127 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item0
);
2130 /* [item0, item1] */
2131 item1
.mask
= LVIF_TEXT
;
2134 item1
.pszText
= item1text
;
2135 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2138 /* [item0, item1, item2] */
2139 item2
.mask
= LVIF_TEXT
;
2142 item2
.pszText
= item2text
;
2143 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2146 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
2148 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
2150 expect2(10, 5, position
.x
, position
.y
);
2152 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
2154 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
2156 expect2(0, 0, position
.x
, position
.y
);
2158 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
2160 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
2162 expect2(20, 20, position
.x
, position
.y
);
2164 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
2166 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2167 DestroyWindow(hwnd
);
2170 static void test_getorigin(void)
2178 position
.x
= position
.y
= 0;
2180 hwnd
= create_listview_control(LVS_ICON
);
2181 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2182 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2184 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2186 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2187 DestroyWindow(hwnd
);
2189 hwnd
= create_listview_control(LVS_SMALLICON
);
2190 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2191 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2193 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2195 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2196 DestroyWindow(hwnd
);
2198 hwnd
= create_listview_control(LVS_LIST
);
2199 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2200 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2202 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2204 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2205 DestroyWindow(hwnd
);
2207 hwnd
= create_listview_control(LVS_REPORT
);
2208 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2209 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2211 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2213 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2214 DestroyWindow(hwnd
);
2217 static void test_multiselect(void)
2219 typedef struct t_select_task
2230 int i
,j
,item_count
,selected_count
;
2231 static const int items
=5;
2237 static struct t_select_task task_list
[] = {
2238 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
2239 { "using VK_UP", -1, VK_UP
, -1, -1 },
2240 { "using VK_END", 0, VK_END
, 1, -1 },
2241 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
2244 hwnd
= create_listview_control(LVS_REPORT
);
2246 for (i
= 0; i
< items
; i
++)
2247 insert_item(hwnd
, 0);
2249 item_count
= (int)SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2250 expect(items
, item_count
);
2252 for (i
= 0; i
< 4; i
++) {
2255 task
= task_list
[i
];
2257 /* deselect all items */
2259 item
.stateMask
= LVIS_SELECTED
;
2260 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2261 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2263 /* set initial position */
2264 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
2266 item
.state
= LVIS_SELECTED
;
2267 item
.stateMask
= LVIS_SELECTED
;
2268 SendMessageA(hwnd
, LVM_SETITEMSTATE
, task
.initPos
== -1 ? item_count
-1 : task
.initPos
, (LPARAM
)&item
);
2270 selected_count
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2271 ok(selected_count
== 1, "expected 1, got %d\n", selected_count
);
2273 /* Set SHIFT key pressed */
2274 GetKeyboardState(kstate
);
2275 kstate
[VK_SHIFT
]=0x80;
2276 SetKeyboardState(kstate
);
2278 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
2279 r
= SendMessageA(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
2281 r
= SendMessageA(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
2285 selected_count
= (int)SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2287 ok((task
.result
== -1 ? item_count
: task
.result
) == selected_count
, "Failed multiple selection %s. There should be %d selected items (is %d)\n", task
.descr
, item_count
, selected_count
);
2289 /* Set SHIFT key released */
2290 GetKeyboardState(kstate
);
2291 kstate
[VK_SHIFT
]=0x00;
2292 SetKeyboardState(kstate
);
2294 DestroyWindow(hwnd
);
2296 /* make multiple selection, then switch to LVS_SINGLESEL */
2297 hwnd
= create_listview_control(LVS_REPORT
);
2298 for (i
=0;i
<items
;i
++) {
2299 insert_item(hwnd
, 0);
2301 item_count
= (int)SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2302 expect(items
,item_count
);
2304 /* try with NULL pointer */
2305 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, 0);
2308 /* select all, check notifications */
2310 item
.stateMask
= LVIS_SELECTED
;
2311 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2313 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2315 item
.stateMask
= LVIS_SELECTED
;
2316 item
.state
= LVIS_SELECTED
;
2317 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2320 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2321 "select all notification", FALSE
);
2323 /* select all again (all selected already) */
2324 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2326 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2328 item
.stateMask
= LVIS_SELECTED
;
2329 item
.state
= LVIS_SELECTED
;
2330 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2333 ok(g_nmlistview_changing
.uNewState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2334 ok(g_nmlistview_changing
.uOldState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2335 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2337 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2338 "select all notification 2", FALSE
);
2340 /* deselect all items */
2341 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2344 item
.stateMask
= LVIS_SELECTED
;
2345 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2347 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2348 "deselect all notification", FALSE
);
2350 /* deselect all items again */
2351 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2353 item
.stateMask
= LVIS_SELECTED
;
2354 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2355 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "deselect all notification 2", FALSE
);
2357 /* any non-zero state value does the same */
2358 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2360 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2362 item
.stateMask
= LVIS_SELECTED
;
2363 item
.state
= LVIS_CUT
;
2364 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2367 ok(g_nmlistview_changing
.uNewState
== 0, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2368 ok(g_nmlistview_changing
.uOldState
== 0, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2369 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2371 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2372 "set state all notification 3", FALSE
);
2374 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2375 for (i
= 0; i
< 3; i
++) {
2376 item
.state
= LVIS_SELECTED
;
2377 item
.stateMask
= LVIS_SELECTED
;
2378 SendMessageA(hwnd
, LVM_SETITEMSTATE
, i
, (LPARAM
)&item
);
2381 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2383 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2386 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2387 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2388 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2389 /* check that style is accepted */
2390 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2391 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2394 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, i
, LVIS_SELECTED
);
2395 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2397 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2399 SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2402 /* select one more */
2403 item
.state
= LVIS_SELECTED
;
2404 item
.stateMask
= LVIS_SELECTED
;
2405 SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
2408 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, i
, LVIS_SELECTED
);
2409 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2412 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 3, LVIS_SELECTED
);
2413 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2415 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2417 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2420 /* try to select all on LVS_SINGLESEL */
2421 memset(&item
, 0, sizeof(item
));
2422 item
.stateMask
= LVIS_SELECTED
;
2423 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2425 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2427 item
.stateMask
= LVIS_SELECTED
;
2428 item
.state
= LVIS_SELECTED
;
2429 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2432 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2434 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2437 /* try to deselect all on LVS_SINGLESEL */
2438 item
.stateMask
= LVIS_SELECTED
;
2439 item
.state
= LVIS_SELECTED
;
2440 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2443 item
.stateMask
= LVIS_SELECTED
;
2445 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2447 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2450 /* 1. selection mark is update when new focused item is set */
2451 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2452 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2454 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2457 item
.stateMask
= LVIS_FOCUSED
;
2458 item
.state
= LVIS_FOCUSED
;
2459 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2462 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2465 /* it's not updated if already set */
2466 item
.stateMask
= LVIS_FOCUSED
;
2467 item
.state
= LVIS_FOCUSED
;
2468 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2471 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2474 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2477 item
.stateMask
= LVIS_FOCUSED
;
2478 item
.state
= LVIS_FOCUSED
;
2479 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2482 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2485 /* need to reset focused item first */
2486 item
.stateMask
= LVIS_FOCUSED
;
2488 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2491 item
.stateMask
= LVIS_FOCUSED
;
2492 item
.state
= LVIS_FOCUSED
;
2493 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
2496 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2499 item
.stateMask
= LVIS_FOCUSED
;
2501 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2504 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2507 /* 2. same tests, with LVM_SETITEM */
2508 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2509 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2511 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2514 item
.stateMask
= LVIS_FOCUSED
;
2515 item
.state
= LVIS_FOCUSED
;
2516 item
.mask
= LVIF_STATE
;
2517 item
.iItem
= item
.iSubItem
= 0;
2518 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2521 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2524 /* it's not updated if already set */
2525 item
.stateMask
= LVIS_FOCUSED
;
2526 item
.state
= LVIS_FOCUSED
;
2527 item
.mask
= LVIF_STATE
;
2530 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2533 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2536 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2539 item
.stateMask
= LVIS_FOCUSED
;
2540 item
.state
= LVIS_FOCUSED
;
2541 item
.mask
= LVIF_STATE
;
2544 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2547 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2550 /* need to reset focused item first */
2551 item
.stateMask
= LVIS_FOCUSED
;
2553 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2556 item
.stateMask
= LVIS_FOCUSED
;
2557 item
.state
= LVIS_FOCUSED
;
2558 item
.mask
= LVIF_STATE
;
2561 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2564 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2567 item
.stateMask
= LVIS_FOCUSED
;
2569 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2572 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2575 DestroyWindow(hwnd
);
2578 static void test_subitem_rect(void)
2586 /* test LVM_GETSUBITEMRECT for header */
2587 hwnd
= create_listview_control(LVS_REPORT
);
2588 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2589 /* add some columns */
2590 memset(&col
, 0, sizeof(LVCOLUMNA
));
2591 col
.mask
= LVCF_WIDTH
;
2593 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
2596 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&col
);
2599 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 2, (LPARAM
)&col
);
2601 /* item = -1 means header, subitem index is 1 based */
2602 rect
.left
= LVIR_BOUNDS
;
2604 rect
.right
= rect
.bottom
= 0;
2605 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2608 rect
.left
= LVIR_BOUNDS
;
2610 rect
.right
= rect
.bottom
= 0;
2611 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2614 expect(100, rect
.left
);
2615 expect(250, rect
.right
);
2616 expect(3, rect
.top
);
2618 rect
.left
= LVIR_BOUNDS
;
2620 rect
.right
= rect
.bottom
= 0;
2621 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2624 expect(250, rect
.left
);
2625 expect(450, rect
.right
);
2626 expect(3, rect
.top
);
2628 /* item LVS_REPORT padding isn't applied to subitems */
2629 insert_item(hwnd
, 0);
2631 rect
.left
= LVIR_BOUNDS
;
2633 rect
.right
= rect
.bottom
= 0;
2634 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2636 expect(100, rect
.left
);
2637 expect(250, rect
.right
);
2639 rect
.left
= LVIR_ICON
;
2641 rect
.right
= rect
.bottom
= 0;
2642 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2644 /* no icon attached - zero width rectangle, with no left padding */
2645 expect(100, rect
.left
);
2646 expect(100, rect
.right
);
2648 rect
.left
= LVIR_LABEL
;
2650 rect
.right
= rect
.bottom
= 0;
2651 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2653 /* same as full LVIR_BOUNDS */
2654 expect(100, rect
.left
);
2655 expect(250, rect
.right
);
2657 SendMessageA(hwnd
, LVM_SCROLL
, 10, 0);
2659 rect
.left
= LVIR_BOUNDS
;
2661 rect
.right
= rect
.bottom
= 0;
2662 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2664 expect(90, rect
.left
);
2665 expect(240, rect
.right
);
2667 SendMessageA(hwnd
, LVM_SCROLL
, -10, 0);
2669 /* test header interaction */
2670 subclass_header(hwnd
);
2671 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2673 rect
.left
= LVIR_BOUNDS
;
2675 rect
.right
= rect
.bottom
= 0;
2676 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2679 rect
.left
= LVIR_BOUNDS
;
2681 rect
.right
= rect
.bottom
= 0;
2682 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2685 rect
.left
= LVIR_BOUNDS
;
2687 rect
.right
= rect
.bottom
= 0;
2688 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -10, (LPARAM
)&rect
);
2691 rect
.left
= LVIR_BOUNDS
;
2693 rect
.right
= rect
.bottom
= 0;
2694 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 20, (LPARAM
)&rect
);
2697 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getsubitemrect_seq
, "LVM_GETSUBITEMRECT negative index", FALSE
);
2699 DestroyWindow(hwnd
);
2701 /* test subitem rects after re-arranging columns */
2702 hwnd
= create_listview_control(LVS_REPORT
);
2703 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2704 memset(&col
, 0, sizeof(LVCOLUMNA
));
2705 col
.mask
= LVCF_WIDTH
;
2708 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
2712 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&col
);
2716 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 2, (LPARAM
)&col
);
2719 insert_item(hwnd
, 0);
2720 insert_item(hwnd
, 1);
2722 /* wrong item is refused for main item */
2723 rect
.left
= LVIR_BOUNDS
;
2725 rect
.right
= rect
.bottom
= -1;
2726 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect
);
2729 /* for subitems rectangle is calculated even if there's no item added */
2730 rect
.left
= LVIR_BOUNDS
;
2732 rect
.right
= rect
.bottom
= -1;
2733 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect
);
2736 rect2
.left
= LVIR_BOUNDS
;
2738 rect2
.right
= rect2
.bottom
= -1;
2739 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect2
);
2741 expect(rect
.right
, rect2
.right
);
2742 expect(rect
.left
, rect2
.left
);
2743 expect(rect
.bottom
, rect2
.top
);
2744 ok(rect2
.bottom
> rect2
.top
, "expected not zero height\n");
2746 arr
[0] = 1; arr
[1] = 0; arr
[2] = 2;
2747 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 3, (LPARAM
)arr
);
2750 rect
.left
= LVIR_BOUNDS
;
2752 rect
.right
= rect
.bottom
= -1;
2753 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2755 expect(0, rect
.left
);
2756 expect(600, rect
.right
);
2758 rect
.left
= LVIR_BOUNDS
;
2760 rect
.right
= rect
.bottom
= -1;
2761 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2763 expect(0, rect
.left
);
2764 expect(200, rect
.right
);
2766 rect2
.left
= LVIR_BOUNDS
;
2768 rect2
.right
= rect2
.bottom
= -1;
2769 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect2
);
2771 expect(0, rect2
.left
);
2772 expect(200, rect2
.right
);
2773 /* items are of the same height */
2774 ok(rect2
.top
> 0, "expected positive item height\n");
2775 expect(rect
.bottom
, rect2
.top
);
2776 expect(rect
.bottom
* 2 - rect
.top
, rect2
.bottom
);
2778 rect
.left
= LVIR_BOUNDS
;
2780 rect
.right
= rect
.bottom
= -1;
2781 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2783 expect(300, rect
.left
);
2784 expect(600, rect
.right
);
2786 DestroyWindow(hwnd
);
2788 /* try it for non LVS_REPORT style */
2789 hwnd
= CreateWindowA("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2790 GetModuleHandleA(NULL
), 0);
2791 rect
.left
= LVIR_BOUNDS
;
2793 rect
.right
= rect
.bottom
= -10;
2794 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2796 /* rect is unchanged */
2797 expect(0, rect
.left
);
2798 expect(-10, rect
.right
);
2799 expect(1, rect
.top
);
2800 expect(-10, rect
.bottom
);
2801 DestroyWindow(hwnd
);
2804 /* comparison callback for test_sorting */
2805 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2807 if (first
== second
) return 0;
2808 return (first
> second
? 1 : -1);
2811 static void test_sorting(void)
2817 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2820 hwnd
= create_listview_control(LVS_REPORT
);
2821 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2823 /* insert some items */
2824 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2825 item
.state
= LVIS_SELECTED
;
2829 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2832 item
.mask
= LVIF_PARAM
;
2836 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2839 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2840 item
.state
= LVIS_SELECTED
;
2844 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2847 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2850 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2853 r
= SendMessageA(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2856 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2858 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2860 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2862 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2863 expect(LVIS_SELECTED
, r
);
2864 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2865 expect(LVIS_SELECTED
, r
);
2867 DestroyWindow(hwnd
);
2869 /* switch to LVS_SORTASCENDING when some items added */
2870 hwnd
= create_listview_control(LVS_REPORT
);
2871 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2873 item
.mask
= LVIF_TEXT
;
2876 item
.pszText
= names
[1];
2877 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2880 item
.mask
= LVIF_TEXT
;
2883 item
.pszText
= names
[2];
2884 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2887 item
.mask
= LVIF_TEXT
;
2890 item
.pszText
= names
[0];
2891 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2894 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2895 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2896 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2897 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2899 /* no sorting performed when switched to LVS_SORTASCENDING */
2900 item
.mask
= LVIF_TEXT
;
2902 item
.pszText
= buff
;
2903 item
.cchTextMax
= sizeof(buff
);
2904 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2906 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2909 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2911 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2914 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2916 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2918 /* adding new item doesn't resort list */
2919 item
.mask
= LVIF_TEXT
;
2922 item
.pszText
= names
[3];
2923 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2926 item
.mask
= LVIF_TEXT
;
2928 item
.pszText
= buff
;
2929 item
.cchTextMax
= sizeof(buff
);
2930 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2932 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2935 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2937 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2940 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2942 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2945 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2947 ok(lstrcmpA(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2949 /* corner case - item should be placed at first position */
2950 item
.mask
= LVIF_TEXT
;
2953 item
.pszText
= names
[4];
2954 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2958 item
.pszText
= buff
;
2959 item
.cchTextMax
= sizeof(buff
);
2960 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2962 ok(lstrcmpA(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2965 item
.pszText
= buff
;
2966 item
.cchTextMax
= sizeof(buff
);
2967 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2969 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2972 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2974 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2977 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2979 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2982 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2984 ok(lstrcmpA(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2986 DestroyWindow(hwnd
);
2989 static void test_ownerdata(void)
2991 static char test_str
[] = "test";
2994 LONG_PTR style
, ret
;
2998 /* it isn't possible to set LVS_OWNERDATA after creation */
3001 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
3005 hwnd
= create_listview_control(LVS_REPORT
);
3006 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3007 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3008 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
3010 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3012 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
3013 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
3014 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
3015 "try to switch to LVS_OWNERDATA seq", FALSE
);
3017 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3018 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
3019 DestroyWindow(hwnd
);
3022 /* try to set LVS_OWNERDATA after creation just having it */
3023 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3024 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3025 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3026 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
3028 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3030 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
3031 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
3032 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
3033 "try to switch to LVS_OWNERDATA seq", FALSE
);
3034 DestroyWindow(hwnd
);
3036 /* try to remove LVS_OWNERDATA after creation just having it */
3039 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
3043 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3044 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3045 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3046 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
3048 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3050 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
3051 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
3052 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
3053 "try to switch to LVS_OWNERDATA seq", FALSE
);
3054 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3055 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
3056 DestroyWindow(hwnd
);
3059 /* try select an item */
3060 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3061 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3062 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3064 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
3066 memset(&item
, 0, sizeof(item
));
3067 item
.stateMask
= LVIS_SELECTED
;
3068 item
.state
= LVIS_SELECTED
;
3069 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3071 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
3073 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3075 DestroyWindow(hwnd
);
3077 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
3078 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3079 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3080 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3082 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3084 memset(&item
, 0, sizeof(item
));
3085 item
.mask
= LVIF_STATE
;
3087 item
.stateMask
= LVIS_SELECTED
;
3088 item
.state
= LVIS_SELECTED
;
3089 res
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3091 memset(&item
, 0, sizeof(item
));
3092 item
.pszText
= test_str
;
3093 res
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3095 DestroyWindow(hwnd
);
3097 /* check notifications after focused/selected changed */
3098 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3099 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3100 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
3103 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3105 memset(&item
, 0, sizeof(item
));
3106 item
.stateMask
= LVIS_SELECTED
;
3107 item
.state
= LVIS_SELECTED
;
3108 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3111 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
3112 "ownerdata select notification", TRUE
);
3114 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3116 memset(&item
, 0, sizeof(item
));
3117 item
.stateMask
= LVIS_FOCUSED
;
3118 item
.state
= LVIS_FOCUSED
;
3119 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3122 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
3123 "ownerdata focus notification", TRUE
);
3125 /* select all, check notifications */
3126 item
.stateMask
= LVIS_SELECTED
;
3128 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3131 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3133 item
.stateMask
= LVIS_SELECTED
;
3134 item
.state
= LVIS_SELECTED
;
3136 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3137 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3139 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3140 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3141 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3142 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3143 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3144 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3145 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3147 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3148 "ownerdata select all notification", FALSE
);
3150 /* select all again, note that all items are selected already */
3151 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3152 item
.stateMask
= LVIS_SELECTED
;
3153 item
.state
= LVIS_SELECTED
;
3155 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3156 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3158 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3159 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3160 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3161 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3162 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3163 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3164 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3166 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3167 "ownerdata select all notification", FALSE
);
3170 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3171 item
.stateMask
= LVIS_SELECTED
;
3174 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3175 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3177 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3178 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3179 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3180 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3181 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3182 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3183 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3185 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3186 "ownerdata deselect all notification", TRUE
);
3188 /* nothing selected, deselect all again */
3189 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3190 item
.stateMask
= LVIS_SELECTED
;
3193 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3196 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "ownerdata deselect all notification", FALSE
);
3198 /* select one, then deselect all */
3199 item
.stateMask
= LVIS_SELECTED
;
3200 item
.state
= LVIS_SELECTED
;
3201 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3203 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3204 item
.stateMask
= LVIS_SELECTED
;
3207 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3208 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3210 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3211 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3212 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3213 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3214 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3215 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3216 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3218 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3219 "ownerdata select all notification", TRUE
);
3221 /* remove focused, try to focus all */
3222 item
.stateMask
= LVIS_FOCUSED
;
3223 item
.state
= LVIS_FOCUSED
;
3224 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3226 item
.stateMask
= LVIS_FOCUSED
;
3228 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3230 item
.stateMask
= LVIS_FOCUSED
;
3231 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
3234 /* setting all to focused returns failure value */
3235 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3236 item
.stateMask
= LVIS_FOCUSED
;
3237 item
.state
= LVIS_FOCUSED
;
3239 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3242 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3243 "ownerdata focus all notification", FALSE
);
3245 /* focus single item, remove all */
3246 item
.stateMask
= LVIS_FOCUSED
;
3247 item
.state
= LVIS_FOCUSED
;
3248 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3250 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3251 item
.stateMask
= LVIS_FOCUSED
;
3254 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3255 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3257 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3258 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3259 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3260 ok(g_nmlistview
.uOldState
== LVIS_FOCUSED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3261 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3262 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3263 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3265 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
3266 "ownerdata remove focus all notification", TRUE
);
3269 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3270 item
.stateMask
= LVIS_CUT
;
3271 item
.state
= LVIS_CUT
;
3273 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3274 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3276 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3277 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3278 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3279 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3280 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3281 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3282 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3284 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3285 "ownerdata cut all notification", FALSE
);
3287 /* all marked cut, try again */
3288 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3289 item
.stateMask
= LVIS_CUT
;
3290 item
.state
= LVIS_CUT
;
3292 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3293 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3295 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3296 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3297 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3298 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3299 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3300 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3301 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3303 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3304 "ownerdata cut all notification #2", FALSE
);
3306 DestroyWindow(hwnd
);
3308 /* check notifications on LVM_GETITEM */
3309 /* zero callback mask */
3310 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3311 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3312 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3315 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3317 memset(&item
, 0, sizeof(item
));
3318 item
.stateMask
= LVIS_SELECTED
;
3319 item
.mask
= LVIF_STATE
;
3320 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3323 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3324 "ownerdata getitem selected state 1", FALSE
);
3326 /* non zero callback mask but not we asking for */
3327 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
3330 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3332 memset(&item
, 0, sizeof(item
));
3333 item
.stateMask
= LVIS_SELECTED
;
3334 item
.mask
= LVIF_STATE
;
3335 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3338 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3339 "ownerdata getitem selected state 2", FALSE
);
3341 /* LVIS_OVERLAYMASK callback mask, asking for index */
3342 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3344 memset(&item
, 0, sizeof(item
));
3345 item
.stateMask
= LVIS_OVERLAYMASK
;
3346 item
.mask
= LVIF_STATE
;
3347 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3350 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3351 "ownerdata getitem selected state 2", FALSE
);
3353 DestroyWindow(hwnd
);
3355 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3356 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
| LVS_REPORT
);
3357 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3358 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3359 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3360 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3361 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
3362 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3363 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
3364 DestroyWindow(hwnd
);
3365 /* apparently it's allowed to switch these style on after creation */
3366 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3367 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3368 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3369 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3370 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
3371 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3372 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3373 DestroyWindow(hwnd
);
3375 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3376 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3377 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3378 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3379 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
3380 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3381 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
3382 DestroyWindow(hwnd
);
3385 static void test_norecompute(void)
3387 static CHAR testA
[] = "test";
3393 /* self containing control */
3394 hwnd
= create_listview_control(LVS_REPORT
);
3395 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3396 memset(&item
, 0, sizeof(item
));
3397 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
3399 item
.stateMask
= LVIS_SELECTED
;
3400 item
.state
= LVIS_SELECTED
;
3401 item
.pszText
= testA
;
3402 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3404 /* retrieve with LVIF_NORECOMPUTE */
3405 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3407 item
.pszText
= buff
;
3408 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3409 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3411 ok(lstrcmpA(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
3413 item
.mask
= LVIF_TEXT
;
3415 item
.pszText
= LPSTR_TEXTCALLBACKA
;
3416 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3419 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3421 item
.pszText
= buff
;
3422 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3424 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3425 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3427 ok(item
.pszText
== LPSTR_TEXTCALLBACKA
, "Expected (%p), got (%p)\n",
3428 LPSTR_TEXTCALLBACKA
, (VOID
*)item
.pszText
);
3429 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
3431 DestroyWindow(hwnd
);
3434 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3435 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3437 item
.mask
= LVIF_STATE
;
3438 item
.stateMask
= LVIS_SELECTED
;
3439 item
.state
= LVIS_SELECTED
;
3441 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3444 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3446 item
.pszText
= buff
;
3447 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3448 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3449 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3451 ok(item
.pszText
== LPSTR_TEXTCALLBACKA
, "Expected (%p), got (%p)\n",
3452 LPSTR_TEXTCALLBACKA
, (VOID
*)item
.pszText
);
3453 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
3455 DestroyWindow(hwnd
);
3458 static void test_nosortheader(void)
3463 hwnd
= create_listview_control(LVS_REPORT
);
3464 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3466 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3467 ok(IsWindow(header
), "header expected\n");
3469 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3470 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
3472 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3473 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
3474 /* HDS_BUTTONS retained */
3475 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3476 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
3478 DestroyWindow(hwnd
);
3480 /* create with LVS_NOSORTHEADER */
3481 hwnd
= create_listview_control(LVS_NOSORTHEADER
| LVS_REPORT
);
3482 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3484 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3485 ok(IsWindow(header
), "header expected\n");
3487 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3488 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3490 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3491 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
3492 /* not changed here */
3493 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3494 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3496 DestroyWindow(hwnd
);
3499 static void test_setredraw(void)
3507 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3508 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3510 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3511 ListView seems to handle it internally without DefWinProc */
3513 /* default value first */
3514 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3517 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3518 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3519 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3521 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3522 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3523 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3526 /* check update rect after redrawing */
3527 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3529 InvalidateRect(hwnd
, NULL
, FALSE
);
3530 RedrawWindow(hwnd
, NULL
, NULL
, RDW_UPDATENOW
);
3531 rect
.right
= rect
.bottom
= 1;
3532 GetUpdateRect(hwnd
, &rect
, FALSE
);
3533 expect(0, rect
.right
);
3534 expect(0, rect
.bottom
);
3537 hdc
= GetWindowDC(hwndparent
);
3538 ret
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3540 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3542 ret
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3544 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3546 ReleaseDC(hwndparent
, hdc
);
3548 /* check notification messages to show that repainting is disabled */
3549 ret
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3551 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3553 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3555 InvalidateRect(hwnd
, NULL
, TRUE
);
3557 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3558 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
3560 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
3562 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3563 InvalidateRect(hwnd
, NULL
, TRUE
);
3565 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3566 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
3568 /* message isn't forwarded to header */
3569 subclass_header(hwnd
);
3570 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3571 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3573 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
3574 "WM_SETREDRAW: not forwarded to header", FALSE
);
3576 DestroyWindow(hwnd
);
3579 static void test_hittest(void)
3585 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3589 HIMAGELIST himl
, himl2
;
3592 hwnd
= create_listview_control(LVS_REPORT
);
3593 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3595 /* LVS_REPORT with a single subitem (2 columns) */
3596 insert_column(hwnd
, 0);
3597 insert_column(hwnd
, 1);
3598 insert_item(hwnd
, 0);
3601 /* the only purpose of that line is to be as long as a half item rect */
3602 item
.pszText
= text
;
3603 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3606 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3608 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3611 memset(&bounds
, 0, sizeof(bounds
));
3612 bounds
.left
= LVIR_BOUNDS
;
3613 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
3615 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
3616 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
3617 r
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, TRUE
, 0);
3619 ok(bounds
.bottom
- bounds
.top
== vert
,
3620 "Vertical spacing inconsistent (%d != %d)\n", bounds
.bottom
- bounds
.top
, vert
);
3621 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
3624 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3626 /* outside columns by x position - valid is [0, 199] */
3628 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3629 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TOLEFT
, 0, FALSE
, FALSE
);
3630 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3632 x
= pos
.x
+ 50; /* column half width */
3633 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3634 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, 0, FALSE
, FALSE
);
3635 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3636 x
= pos
.x
+ 150; /* outside column */
3637 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3638 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3639 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3640 y
= (bounds
.bottom
- bounds
.top
) / 2;
3641 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3642 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3643 /* outside possible client rectangle (to right) */
3645 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3646 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3647 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3648 y
= (bounds
.bottom
- bounds
.top
) / 2;
3649 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3650 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3651 /* subitem returned with -1 item too */
3653 y
= bounds
.top
- vert
;
3654 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3655 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3656 /* return values appear to underflow with negative indices */
3660 test_lvm_subitemhittest(hwnd
, x
, y
, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3661 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3665 /* parent client area is 100x100 by default */
3666 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
3667 x
= pos
.x
+ 150; /* outside column */
3668 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3669 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, FALSE
);
3670 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3671 y
= (bounds
.bottom
- bounds
.top
) / 2;
3672 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, TRUE
);
3673 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3674 /* the same with LVS_EX_FULLROWSELECT */
3675 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3676 x
= pos
.x
+ 150; /* outside column */
3677 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3678 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, LVHT_ONITEMLABEL
, FALSE
, FALSE
);
3679 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3680 y
= (bounds
.bottom
- bounds
.top
) / 2;
3681 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3682 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
3683 x
= pos
.x
+ 150; /* outside column */
3684 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3685 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3686 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3687 y
= (bounds
.bottom
- bounds
.top
) / 2;
3688 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3689 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3690 /* outside possible client rectangle (to right) */
3692 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3693 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3694 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3695 y
= (bounds
.bottom
- bounds
.top
) / 2;
3696 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3697 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3698 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3699 himl
= ImageList_Create(16, 16, 0, 4, 4);
3700 ok(himl
!= NULL
, "failed to create imagelist\n");
3701 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3702 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3703 r
= ImageList_Add(himl
, hbmp
, 0);
3704 ok(r
== 0, "should be zero\n");
3705 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3706 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3707 r
= ImageList_Add(himl
, hbmp
, 0);
3708 ok(r
== 1, "should be one\n");
3710 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3713 item
.mask
= LVIF_IMAGE
;
3717 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3721 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3722 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3723 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3724 y
= (bounds
.bottom
- bounds
.top
) / 2;
3725 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3727 /* state icons indices are 1 based, check with valid index */
3728 item
.mask
= LVIF_STATE
;
3729 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3730 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3733 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3737 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3738 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3739 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3740 y
= (bounds
.bottom
- bounds
.top
) / 2;
3741 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3743 himl2
= (HIMAGELIST
)SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3744 ok(himl2
== himl
, "should return handle\n");
3746 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3750 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3751 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, 0, FALSE
, FALSE
);
3752 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3753 y
= (bounds
.bottom
- bounds
.top
) / 2;
3754 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3756 DestroyWindow(hwnd
);
3759 static void test_getviewrect(void)
3766 hwnd
= create_listview_control(LVS_REPORT
);
3767 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3770 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3773 insert_column(hwnd
, 0);
3774 insert_column(hwnd
, 1);
3776 memset(&item
, 0, sizeof(item
));
3779 SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3781 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3783 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3786 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3787 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3789 /* left is set to (2e31-1) - XP SP2 */
3790 expect(0, rect
.right
);
3791 expect(0, rect
.top
);
3792 expect(0, rect
.bottom
);
3794 /* switch to LVS_ICON */
3795 SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3797 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3798 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3800 expect(0, rect
.left
);
3801 expect(0, rect
.top
);
3802 /* precise value differs for 2k, XP and Vista */
3803 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3804 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3806 DestroyWindow(hwnd
);
3809 static void test_getitemposition(void)
3816 hwnd
= create_listview_control(LVS_REPORT
);
3817 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3818 header
= subclass_header(hwnd
);
3820 /* LVS_REPORT, single item, no columns added */
3821 insert_item(hwnd
, 0);
3823 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3826 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3828 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3830 /* LVS_REPORT, single item, single column */
3831 insert_column(hwnd
, 0);
3833 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3836 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3838 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3840 memset(&rect
, 0, sizeof(rect
));
3841 SendMessageA(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3844 /* offset by header height */
3845 expect(rect
.bottom
- rect
.top
, pt
.y
);
3847 DestroyWindow(hwnd
);
3850 static void test_columnscreation(void)
3855 hwnd
= create_listview_control(LVS_REPORT
);
3856 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3858 insert_item(hwnd
, 0);
3860 /* headers columns aren't created automatically */
3861 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3862 ok(IsWindow(header
), "Expected header handle\n");
3863 r
= SendMessageA(header
, HDM_GETITEMCOUNT
, 0, 0);
3866 DestroyWindow(hwnd
);
3869 static void test_getitemrect(void)
3872 HIMAGELIST himl
, himl_ret
;
3882 /* rectangle isn't empty for empty text items */
3883 hwnd
= create_listview_control(LVS_LIST
);
3884 memset(&item
, 0, sizeof(item
));
3887 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3889 rect
.left
= LVIR_LABEL
;
3890 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3892 expect(0, rect
.left
);
3893 expect(0, rect
.top
);
3895 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, rect
.right
);
3896 ReleaseDC(hwnd
, hdc
);
3897 DestroyWindow(hwnd
);
3899 hwnd
= create_listview_control(LVS_REPORT
);
3900 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3903 memset(&item
, 0, sizeof(item
));
3906 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3909 rect
.left
= LVIR_BOUNDS
;
3910 rect
.right
= rect
.top
= rect
.bottom
= -1;
3911 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3914 /* zero width rectangle with no padding */
3915 expect(0, rect
.left
);
3916 expect(0, rect
.right
);
3918 insert_column(hwnd
, 0);
3919 insert_column(hwnd
, 1);
3921 col
.mask
= LVCF_WIDTH
;
3923 r
= SendMessageA(hwnd
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
3926 col
.mask
= LVCF_WIDTH
;
3928 r
= SendMessageA(hwnd
, LVM_SETCOLUMNA
, 1, (LPARAM
)&col
);
3931 rect
.left
= LVIR_BOUNDS
;
3932 rect
.right
= rect
.top
= rect
.bottom
= -1;
3933 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3936 /* still no left padding */
3937 expect(0, rect
.left
);
3938 expect(150, rect
.right
);
3940 rect
.left
= LVIR_SELECTBOUNDS
;
3941 rect
.right
= rect
.top
= rect
.bottom
= -1;
3942 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3945 expect(2, rect
.left
);
3947 rect
.left
= LVIR_LABEL
;
3948 rect
.right
= rect
.top
= rect
.bottom
= -1;
3949 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3951 /* padding, column width */
3952 expect(2, rect
.left
);
3953 expect(50, rect
.right
);
3955 /* no icons attached */
3956 rect
.left
= LVIR_ICON
;
3957 rect
.right
= rect
.top
= rect
.bottom
= -1;
3958 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3961 expect(2, rect
.left
);
3962 expect(2, rect
.right
);
3965 order
[0] = 1; order
[1] = 0;
3966 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3969 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3971 /* 1 indexed column width + padding */
3973 /* rect is at zero too */
3974 rect
.left
= LVIR_BOUNDS
;
3975 rect
.right
= rect
.top
= rect
.bottom
= -1;
3976 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3978 expect(0, rect
.left
);
3979 /* just width sum */
3980 expect(150, rect
.right
);
3982 rect
.left
= LVIR_SELECTBOUNDS
;
3983 rect
.right
= rect
.top
= rect
.bottom
= -1;
3984 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3986 /* column width + padding */
3987 expect(102, rect
.left
);
3989 /* back to initial order */
3990 order
[0] = 0; order
[1] = 1;
3991 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3995 himl
= ImageList_Create(16, 16, 0, 2, 2);
3996 ok(himl
!= NULL
, "failed to create imagelist\n");
3997 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3998 ok(hbm
!= NULL
, "failed to create bitmap\n");
3999 r
= ImageList_Add(himl
, hbm
, 0);
4001 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
4002 ok(hbm
!= NULL
, "failed to create bitmap\n");
4003 r
= ImageList_Add(himl
, hbm
, 0);
4006 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
4009 item
.mask
= LVIF_STATE
;
4010 item
.state
= INDEXTOSTATEIMAGEMASK(1);
4011 item
.stateMask
= LVIS_STATEIMAGEMASK
;
4014 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
4018 rect
.left
= LVIR_ICON
;
4019 rect
.right
= rect
.top
= rect
.bottom
= -1;
4020 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4022 /* padding + stateicon width */
4023 expect(18, rect
.left
);
4024 expect(18, rect
.right
);
4026 rect
.left
= LVIR_LABEL
;
4027 rect
.right
= rect
.top
= rect
.bottom
= -1;
4028 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4030 /* padding + stateicon width -> column width */
4031 expect(18, rect
.left
);
4032 expect(50, rect
.right
);
4034 himl_ret
= (HIMAGELIST
)SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
4035 ok(himl_ret
== himl
, "got %p, expected %p\n", himl_ret
, himl
);
4037 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
4040 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
4043 item
.stateMask
= ~0;
4046 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
4050 rect
.left
= LVIR_ICON
;
4051 rect
.right
= rect
.top
= rect
.bottom
= -1;
4052 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4054 /* padding, icon width */
4055 expect(2, rect
.left
);
4056 expect(18, rect
.right
);
4058 rect
.left
= LVIR_LABEL
;
4059 rect
.right
= rect
.top
= rect
.bottom
= -1;
4060 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4062 /* padding + icon width -> column width */
4063 expect(18, rect
.left
);
4064 expect(50, rect
.right
);
4067 rect
.left
= LVIR_SELECTBOUNDS
;
4068 rect
.right
= rect
.top
= rect
.bottom
= -1;
4069 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4071 /* padding, column width */
4072 expect(2, rect
.left
);
4073 expect(50, rect
.right
);
4075 /* try with indentation */
4076 item
.mask
= LVIF_INDENT
;
4080 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
4084 rect
.left
= LVIR_BOUNDS
;
4085 rect
.right
= rect
.top
= rect
.bottom
= -1;
4086 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4088 /* padding + 1 icon width, column width */
4089 expect(0, rect
.left
);
4090 expect(150, rect
.right
);
4093 rect
.left
= LVIR_SELECTBOUNDS
;
4094 rect
.right
= rect
.top
= rect
.bottom
= -1;
4095 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4097 /* padding + 1 icon width, column width */
4098 expect(2 + 16, rect
.left
);
4099 expect(50, rect
.right
);
4102 rect
.left
= LVIR_LABEL
;
4103 rect
.right
= rect
.top
= rect
.bottom
= -1;
4104 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4106 /* padding + 2 icon widths, column width */
4107 expect(2 + 16*2, rect
.left
);
4108 expect(50, rect
.right
);
4111 rect
.left
= LVIR_ICON
;
4112 rect
.right
= rect
.top
= rect
.bottom
= -1;
4113 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4115 /* padding + 1 icon width indentation, icon width */
4116 expect(2 + 16, rect
.left
);
4117 expect(34, rect
.right
);
4119 DestroyWindow(hwnd
);
4122 static void test_editbox(void)
4124 static CHAR testitemA
[] = "testitem";
4125 static CHAR testitem1A
[] = "testitem_quitelongname";
4126 static CHAR testitem2A
[] = "testITEM_quitelongname";
4127 static CHAR buffer
[25];
4128 HWND hwnd
, hwndedit
, hwndedit2
, header
;
4132 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4133 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4135 insert_column(hwnd
, 0);
4137 memset(&item
, 0, sizeof(item
));
4138 item
.mask
= LVIF_TEXT
;
4139 item
.pszText
= testitemA
;
4142 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4145 /* test notifications without edit created */
4146 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4147 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)0xdeadbeef);
4149 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4150 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE
);
4151 /* same thing but with valid window */
4152 hwndedit
= CreateWindowA("Edit", "Test edit", WS_VISIBLE
| WS_CHILD
, 0, 0, 20,
4153 10, hwnd
, (HMENU
)1, (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
), 0);
4154 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4155 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)hwndedit
);
4157 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4158 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE
);
4159 DestroyWindow(hwndedit
);
4161 /* setting focus is necessary */
4163 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4164 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4166 /* test children Z-order after Edit box created */
4167 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4168 ok(IsWindow(header
), "Expected header to be created\n");
4169 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4170 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4172 /* modify initial string */
4173 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4176 /* edit window is resized and repositioned,
4177 check again for Z-order - it should be preserved */
4178 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4179 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4181 /* return focus to listview */
4184 memset(&item
, 0, sizeof(item
));
4185 item
.mask
= LVIF_TEXT
;
4186 item
.pszText
= buffer
;
4187 item
.cchTextMax
= sizeof(buffer
);
4190 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
4193 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4195 /* send LVM_EDITLABEL on already created edit */
4197 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4198 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4199 /* focus will be set to edit */
4200 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
4201 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4202 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
4204 /* creating label disabled when control isn't focused */
4206 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4207 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4209 /* check EN_KILLFOCUS handling */
4210 memset(&item
, 0, sizeof(item
));
4211 item
.pszText
= testitemA
;
4214 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
4218 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4219 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4220 /* modify edit and notify control that it lost focus */
4221 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4223 g_editbox_disp_info
.item
.pszText
= NULL
;
4224 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4226 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "expected notification with not null text\n");
4228 memset(&item
, 0, sizeof(item
));
4229 item
.pszText
= buffer
;
4230 item
.cchTextMax
= sizeof(buffer
);
4233 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4234 expect(lstrlenA(item
.pszText
), r
);
4235 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4236 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4238 /* change item name to differ in casing only */
4240 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4241 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4242 /* modify edit and notify control that it lost focus */
4243 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem2A
);
4245 g_editbox_disp_info
.item
.pszText
= NULL
;
4246 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4248 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "got %p\n", g_editbox_disp_info
.item
.pszText
);
4250 memset(&item
, 0, sizeof(item
));
4251 item
.pszText
= buffer
;
4252 item
.cchTextMax
= sizeof(buffer
);
4255 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4256 expect(lstrlenA(item
.pszText
), r
);
4257 ok(strcmp(buffer
, testitem2A
) == 0, "got %s, expected %s\n", buffer
, testitem2A
);
4258 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4260 /* end edit without saving */
4262 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4263 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4264 r
= SendMessageA(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
4266 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4267 "edit box - end edit, no change, escape", TRUE
);
4268 /* end edit with saving */
4270 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4271 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4272 r
= SendMessageA(hwndedit
, WM_KEYDOWN
, VK_RETURN
, 0);
4274 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4275 "edit box - end edit, no change, return", TRUE
);
4277 memset(&item
, 0, sizeof(item
));
4278 item
.pszText
= buffer
;
4279 item
.cchTextMax
= sizeof(buffer
);
4282 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4283 expect(lstrlenA(item
.pszText
), r
);
4284 ok(strcmp(buffer
, testitem2A
) == 0, "Expected item text to change\n");
4286 /* LVM_EDITLABEL with -1 destroys current edit */
4287 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
4288 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4289 /* no edit present */
4290 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -1, 0);
4291 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4292 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4293 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4295 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4296 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -1, 0);
4297 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4298 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4299 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4300 /* check another negative value */
4301 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4302 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4303 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4304 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -2, 0);
4305 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4306 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4307 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4308 /* and value greater than max item index */
4309 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4310 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4311 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4312 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
4313 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, r
, 0);
4314 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4315 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4316 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4318 /* messaging tests */
4320 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4322 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4323 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4324 /* testing only sizing messages */
4325 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
4326 "edit box create - sizing", FALSE
);
4328 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4330 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4331 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4332 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4333 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4335 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4336 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE
);
4338 DestroyWindow(hwnd
);
4341 static void test_notifyformat(void)
4346 hwnd
= create_listview_control(LVS_REPORT
);
4347 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4349 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4350 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4351 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4353 SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4355 r
= SendMessageA(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
4357 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4360 r
= SendMessageA(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
4362 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4367 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4368 DestroyWindow(hwnd
);
4372 DestroyWindow(hwnd
);
4374 /* test failure in parent WM_NOTIFYFORMAT */
4376 hwnd
= create_listview_control(LVS_REPORT
);
4377 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4378 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4379 ok(IsWindow(header
), "expected header to be created\n");
4380 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4382 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4383 ok( r
== 1, "Expected 1, got %d\n", r
);
4384 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4385 ok(r
!= 0, "Expected valid format\n");
4387 notifyFormat
= NFR_UNICODE
;
4388 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4389 expect(NFR_UNICODE
, r
);
4390 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4392 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4393 ok( r
== 1, "Expected 1, got %d\n", r
);
4395 notifyFormat
= NFR_ANSI
;
4396 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4397 expect(NFR_ANSI
, r
);
4398 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4400 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4401 ok( r
== 1, "Expected 1, got %d\n", r
);
4403 DestroyWindow(hwnd
);
4405 hwndparentW
= create_parent_window(TRUE
);
4406 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
4407 if (!IsWindow(hwndparentW
)) return;
4410 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4411 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4412 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4413 ok(IsWindow(header
), "expected header to be created\n");
4414 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4416 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4418 DestroyWindow(hwnd
);
4419 /* receiving error code defaulting to ansi */
4421 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4422 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4423 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4424 ok(IsWindow(header
), "expected header to be created\n");
4425 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4427 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4429 DestroyWindow(hwnd
);
4430 /* receiving ansi code from unicode window, use it */
4431 notifyFormat
= NFR_ANSI
;
4432 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4433 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4434 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4435 ok(IsWindow(header
), "expected header to be created\n");
4436 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4438 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4440 DestroyWindow(hwnd
);
4441 /* unicode listview with ansi parent window */
4443 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4444 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4445 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4446 ok(IsWindow(header
), "expected header to be created\n");
4447 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4449 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4451 DestroyWindow(hwnd
);
4452 /* unicode listview with ansi parent window, return error code */
4454 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4455 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4456 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4457 ok(IsWindow(header
), "expected header to be created\n");
4458 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4460 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4462 DestroyWindow(hwnd
);
4464 DestroyWindow(hwndparentW
);
4467 static void test_indentation(void)
4473 hwnd
= create_listview_control(LVS_REPORT
);
4474 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4476 memset(&item
, 0, sizeof(item
));
4477 item
.mask
= LVIF_INDENT
;
4479 item
.iIndent
= I_INDENTCALLBACK
;
4480 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4483 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4486 item
.mask
= LVIF_INDENT
;
4487 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
4490 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
4491 "get indent dispinfo", FALSE
);
4493 DestroyWindow(hwnd
);
4496 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
4501 static BOOL
is_below_comctl_5(void)
4506 hwnd
= create_listview_control(LVS_REPORT
);
4507 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4508 insert_item(hwnd
, 0);
4510 ret
= SendMessageA(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
4512 DestroyWindow(hwnd
);
4517 static void test_get_set_view(void)
4523 /* test style->view mapping */
4524 hwnd
= create_listview_control(LVS_REPORT
);
4525 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4527 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4528 expect(LV_VIEW_DETAILS
, ret
);
4530 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4532 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
4533 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4534 expect(LV_VIEW_ICON
, ret
);
4536 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4537 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
4538 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4539 expect(LV_VIEW_SMALLICON
, ret
);
4541 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4542 SetWindowLongPtrA(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
4543 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4544 expect(LV_VIEW_LIST
, ret
);
4546 /* switching view doesn't touch window style */
4547 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
4549 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4550 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4551 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
4553 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4554 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4555 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
4557 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4558 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4560 DestroyWindow(hwnd
);
4563 static void test_canceleditlabel(void)
4565 HWND hwnd
, hwndedit
;
4569 static CHAR test
[] = "test";
4570 static const CHAR test1
[] = "test1";
4572 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4573 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4575 insert_item(hwnd
, 0);
4577 /* try without edit created */
4578 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4579 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4581 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4582 "cancel edit label without edit", FALSE
);
4584 /* cancel without data change */
4586 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4587 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4588 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4590 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4592 /* cancel after data change */
4593 memset(&itema
, 0, sizeof(itema
));
4594 itema
.pszText
= test
;
4595 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&itema
);
4598 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4599 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4600 ret
= SetWindowTextA(hwndedit
, test1
);
4602 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4604 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4605 memset(&itema
, 0, sizeof(itema
));
4606 itema
.pszText
= buff
;
4607 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
4608 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&itema
);
4610 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
4612 DestroyWindow(hwnd
);
4615 static void test_mapidindex(void)
4620 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4621 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
4622 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4623 insert_item(hwnd
, 0);
4624 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4626 DestroyWindow(hwnd
);
4628 hwnd
= create_listview_control(LVS_REPORT
);
4629 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4631 /* LVM_MAPINDEXTOID with invalid index */
4632 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4635 insert_item(hwnd
, 0);
4636 insert_item(hwnd
, 1);
4638 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
4640 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
4643 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4645 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4647 /* remove 0 indexed item, id retained */
4648 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
4649 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4651 /* new id starts from previous value */
4652 insert_item(hwnd
, 1);
4653 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4656 /* get index by id */
4657 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
4659 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
4661 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
4663 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
4666 DestroyWindow(hwnd
);
4669 static void test_getitemspacing(void)
4674 HIMAGELIST himl40
, himl80
;
4676 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
4677 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
4680 hwnd
= create_listview_control(LVS_ICON
);
4681 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4682 expect(cx
, LOWORD(ret
));
4683 expect(cy
, HIWORD(ret
));
4685 /* now try with icons */
4686 himl40
= ImageList_Create(40, 40, 0, 4, 4);
4687 ok(himl40
!= NULL
, "failed to create imagelist\n");
4688 himl80
= ImageList_Create(80, 80, 0, 4, 4);
4689 ok(himl80
!= NULL
, "failed to create imagelist\n");
4690 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4693 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4694 /* spacing + icon size returned */
4695 expect(cx
+ 40, LOWORD(ret
));
4696 expect(cy
+ 40, HIWORD(ret
));
4697 /* try changing icon size */
4698 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl80
);
4700 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4701 /* spacing + icon size returned */
4702 expect(cx
+ 80, LOWORD(ret
));
4703 expect(cy
+ 80, HIWORD(ret
));
4705 /* set own icon spacing */
4706 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(100, 100));
4707 expect(cx
+ 80, LOWORD(ret
));
4708 expect(cy
+ 80, HIWORD(ret
));
4710 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4711 /* set size returned */
4712 expect(100, LOWORD(ret
));
4713 expect(100, HIWORD(ret
));
4715 /* now change image list - icon spacing should be unaffected */
4716 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4718 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4719 /* set size returned */
4720 expect(100, LOWORD(ret
));
4721 expect(100, HIWORD(ret
));
4723 /* spacing = 0 - keep previous value */
4724 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(0, -1));
4725 expect(100, LOWORD(ret
));
4726 expect(100, HIWORD(ret
));
4728 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4729 expect(100, LOWORD(ret
));
4731 expect(0xFFFF, HIWORD(ret
));
4733 if (sizeof(void*) == 8)
4735 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4736 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, (DWORD
)-1);
4737 expect(100, LOWORD(ret
));
4738 expect(0xFFFF, HIWORD(ret
));
4740 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, -1);
4741 expect(0xFFFF, LOWORD(ret
));
4742 expect(0xFFFF, HIWORD(ret
));
4746 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, -1);
4747 expect(100, LOWORD(ret
));
4748 expect(0xFFFF, HIWORD(ret
));
4750 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4751 /* spacing + icon size returned */
4752 expect(cx
+ 40, LOWORD(ret
));
4753 expect(cy
+ 40, HIWORD(ret
));
4755 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, 0);
4756 ImageList_Destroy(himl80
);
4757 DestroyWindow(hwnd
);
4759 hwnd
= create_listview_control(LVS_SMALLICON
);
4760 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4761 expect(cx
, LOWORD(ret
));
4762 expect(cy
, HIWORD(ret
));
4764 /* spacing does not depend on selected view type */
4765 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4768 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4769 /* spacing + icon size returned */
4770 expect(cx
+ 40, LOWORD(ret
));
4771 expect(cy
+ 40, HIWORD(ret
));
4773 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, 0);
4774 ImageList_Destroy(himl40
);
4775 DestroyWindow(hwnd
);
4777 hwnd
= create_listview_control(LVS_REPORT
);
4778 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4779 expect(cx
, LOWORD(ret
));
4780 expect(cy
, HIWORD(ret
));
4782 DestroyWindow(hwnd
);
4784 hwnd
= create_listview_control(LVS_LIST
);
4785 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4786 expect(cx
, LOWORD(ret
));
4787 expect(cy
, HIWORD(ret
));
4789 DestroyWindow(hwnd
);
4792 static void test_getcolumnwidth(void)
4801 /* default column width */
4802 hwnd
= create_listview_control(LVS_ICON
);
4803 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4805 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4806 SetWindowLongA(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
4807 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4808 todo_wine
expect(8, ret
);
4809 style
= GetWindowLongA(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
4810 SetWindowLongA(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
4812 ret
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4814 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4816 DestroyWindow(hwnd
);
4818 /* default column width with item added */
4819 hwnd
= create_listview_control(LVS_LIST
);
4820 memset(&itema
, 0, sizeof(itema
));
4821 SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4822 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4824 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, ret
);
4825 ReleaseDC(hwnd
, hdc
);
4826 DestroyWindow(hwnd
);
4829 static void test_scrollnotify(void)
4834 hwnd
= create_listview_control(LVS_REPORT
);
4836 insert_column(hwnd
, 0);
4837 insert_column(hwnd
, 1);
4838 insert_item(hwnd
, 0);
4840 /* make it scrollable - resize */
4841 ret
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
4843 ret
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
4846 /* try with dummy call */
4847 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4848 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 0, 0);
4850 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4851 "scroll notify 1", TRUE
);
4853 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4854 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 1, 0);
4856 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4857 "scroll notify 2", TRUE
);
4859 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4860 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 1, 1);
4862 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4863 "scroll notify 3", TRUE
);
4865 DestroyWindow(hwnd
);
4868 static void test_LVS_EX_TRANSPARENTBKGND(void)
4874 hwnd
= create_listview_control(LVS_REPORT
);
4876 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4879 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4880 LVS_EX_TRANSPARENTBKGND
);
4882 ret
= SendMessageA(hwnd
, LVM_GETBKCOLOR
, 0, 0);
4883 if (ret
!= CLR_NONE
)
4885 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4886 DestroyWindow(hwnd
);
4890 /* try to set some back color and check this style bit */
4891 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4893 ret
= SendMessageA(hwnd
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
4894 ok(!(ret
& LVS_EX_TRANSPARENTBKGND
), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4896 /* now test what this style actually does */
4897 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4898 LVS_EX_TRANSPARENTBKGND
);
4900 hdc
= GetWindowDC(hwndparent
);
4902 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4903 SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
4904 ok_sequence(sequences
, PARENT_SEQ_INDEX
, lvs_ex_transparentbkgnd_seq
,
4905 "LVS_EX_TRANSPARENTBKGND parent", FALSE
);
4907 ReleaseDC(hwndparent
, hdc
);
4909 DestroyWindow(hwnd
);
4912 static void test_approximate_viewrect(void)
4919 static CHAR test
[] = "abracadabra, a very long item label";
4921 hwnd
= create_listview_control(LVS_ICON
);
4922 himl
= ImageList_Create(40, 40, 0, 4, 4);
4923 ok(himl
!= NULL
, "failed to create imagelist\n");
4924 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4925 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4926 ret
= ImageList_Add(himl
, hbmp
, 0);
4928 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4931 itema
.mask
= LVIF_IMAGE
;
4935 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4938 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(75, 75));
4942 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4946 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4947 expect(MAKELONG(77,827), ret
);
4949 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(50, 50));
4950 ok(ret
!= 0, "got 0\n");
4952 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4953 expect(MAKELONG(102,302), ret
);
4955 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4956 expect(MAKELONG(52,52), ret
);
4958 itema
.pszText
= test
;
4959 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&itema
);
4961 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4962 expect(MAKELONG(52,52), ret
);
4964 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 0, MAKELPARAM(100,100));
4965 expect(MAKELONG(52,2), ret
);
4966 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 1, MAKELPARAM(100,100));
4967 expect(MAKELONG(52,52), ret
);
4968 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 2, MAKELPARAM(100,100));
4969 expect(MAKELONG(102,52), ret
);
4970 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 3, MAKELPARAM(100,100));
4971 expect(MAKELONG(102,102), ret
);
4972 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 4, MAKELPARAM(100,100));
4973 expect(MAKELONG(102,102), ret
);
4974 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 5, MAKELPARAM(100,100));
4975 expect(MAKELONG(102,152), ret
);
4976 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 6, MAKELPARAM(100,100));
4977 expect(MAKELONG(102,152), ret
);
4978 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 7, MAKELPARAM(160,100));
4979 expect(MAKELONG(152,152), ret
);
4981 DestroyWindow(hwnd
);
4984 static void test_finditem(void)
4991 hwnd
= create_listview_control(LVS_REPORT
);
4992 insert_item(hwnd
, 0);
4994 memset(&fi
, 0, sizeof(fi
));
4996 /* full string search, inserted text was "foo" */
4998 fi
.flags
= LVFI_STRING
;
5000 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5002 /* partial string search, inserted text was "foo" */
5004 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
5006 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5008 /* partial string search, part after start char */
5010 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
5012 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5015 /* try with LVFI_SUBSTRING */
5017 fi
.flags
= LVFI_SUBSTRING
;
5019 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5022 win_skip("LVFI_SUBSTRING not supported\n");
5023 DestroyWindow(hwnd
);
5028 fi
.flags
= LVFI_SUBSTRING
;
5030 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5033 fi
.flags
= LVFI_SUBSTRING
;
5035 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5039 fi
.flags
= LVFI_SUBSTRING
| LVFI_STRING
;
5041 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5044 DestroyWindow(hwnd
);
5047 static void test_LVS_EX_HEADERINALLVIEWS(void)
5052 hwnd
= create_listview_control(LVS_ICON
);
5054 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5055 LVS_EX_HEADERINALLVIEWS
);
5057 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5058 if (!IsWindow(header
))
5060 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
5061 DestroyWindow(hwnd
);
5065 /* LVS_NOCOLUMNHEADER works as before */
5066 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5067 SetWindowLongW(hwnd
, GWL_STYLE
, style
| LVS_NOCOLUMNHEADER
);
5068 style
= GetWindowLongA(header
, GWL_STYLE
);
5069 ok(style
& HDS_HIDDEN
, "Expected HDS_HIDDEN\n");
5070 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5071 SetWindowLongW(hwnd
, GWL_STYLE
, style
& ~LVS_NOCOLUMNHEADER
);
5072 style
= GetWindowLongA(header
, GWL_STYLE
);
5073 ok(!(style
& HDS_HIDDEN
), "Expected HDS_HIDDEN to be unset\n");
5075 /* try to remove style */
5076 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
, 0);
5077 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5078 ok(IsWindow(header
), "Expected header to be created\n");
5079 style
= GetWindowLongA(header
, GWL_STYLE
);
5080 ok(!(style
& HDS_HIDDEN
), "HDS_HIDDEN not expected\n");
5082 DestroyWindow(hwnd
);
5084 /* check other styles */
5085 hwnd
= create_listview_control(LVS_LIST
);
5086 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5087 LVS_EX_HEADERINALLVIEWS
);
5088 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5089 ok(IsWindow(header
), "Expected header to be created\n");
5090 DestroyWindow(hwnd
);
5092 hwnd
= create_listview_control(LVS_SMALLICON
);
5093 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5094 LVS_EX_HEADERINALLVIEWS
);
5095 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5096 ok(IsWindow(header
), "Expected header to be created\n");
5097 DestroyWindow(hwnd
);
5099 hwnd
= create_listview_control(LVS_REPORT
);
5100 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5101 LVS_EX_HEADERINALLVIEWS
);
5102 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5103 ok(IsWindow(header
), "Expected header to be created\n");
5104 DestroyWindow(hwnd
);
5107 static void test_hover(void)
5112 hwnd
= create_listview_control(LVS_ICON
);
5114 /* test WM_MOUSEHOVER forwarding */
5115 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5116 r
= SendMessageA(hwnd
, WM_MOUSEHOVER
, 0, 0);
5118 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER allow test", TRUE
);
5119 g_block_hover
= TRUE
;
5120 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5121 r
= SendMessageA(hwnd
, WM_MOUSEHOVER
, 0, 0);
5123 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER block test", TRUE
);
5124 g_block_hover
= FALSE
;
5126 r
= SendMessageA(hwnd
, LVM_SETHOVERTIME
, 0, 500);
5127 expect(HOVER_DEFAULT
, r
);
5128 r
= SendMessageA(hwnd
, LVM_GETHOVERTIME
, 0, 0);
5131 DestroyWindow(hwnd
);
5134 static void test_destroynotify(void)
5139 hwnd
= create_listview_control(LVS_REPORT
);
5140 ok(hwnd
!= NULL
, "failed to create listview window\n");
5142 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5143 DestroyWindow(hwnd
);
5144 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_destroy
, "check destroy order", FALSE
);
5146 /* same for ownerdata list */
5147 hwnd
= create_listview_control(LVS_REPORT
|LVS_OWNERDATA
);
5148 ok(hwnd
!= NULL
, "failed to create listview window\n");
5150 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5151 DestroyWindow(hwnd
);
5152 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_ownerdata_destroy
, "check destroy order, ownerdata", FALSE
);
5154 hwnd
= create_listview_control(LVS_REPORT
|LVS_OWNERDATA
);
5155 ok(hwnd
!= NULL
, "failed to create listview window\n");
5157 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5158 ret
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
5159 ok(ret
== TRUE
, "got %d\n", ret
);
5160 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_ownerdata_deleteall
, "deleteall ownerdata", FALSE
);
5161 DestroyWindow(hwnd
);
5164 static void test_header_notification(void)
5166 static char textA
[] = "newtext";
5174 list
= create_listview_control(LVS_REPORT
);
5175 ok(list
!= NULL
, "failed to create listview window\n");
5177 memset(&col
, 0, sizeof(col
));
5178 col
.mask
= LVCF_WIDTH
;
5180 ret
= SendMessageA(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5183 /* check list parent notification after header item changed,
5184 this test should be placed before header subclassing to avoid
5185 Listview -> Header messages to be logged */
5186 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5188 col
.mask
= LVCF_TEXT
;
5189 col
.pszText
= textA
;
5190 r
= SendMessageA(list
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
5193 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_changed_seq
,
5194 "header notify, listview", FALSE
);
5195 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5196 "header notify, parent", FALSE
);
5198 header
= subclass_header(list
);
5200 ret
= SendMessageA(header
, HDM_GETITEMCOUNT
, 0, 0);
5203 memset(&item
, 0, sizeof(item
));
5204 item
.mask
= HDI_WIDTH
;
5205 ret
= SendMessageA(header
, HDM_GETITEMA
, 0, (LPARAM
)&item
);
5207 expect(100, item
.cxy
);
5209 nmh
.hdr
.hwndFrom
= header
;
5210 nmh
.hdr
.idFrom
= GetWindowLongPtrA(header
, GWLP_ID
);
5211 nmh
.hdr
.code
= HDN_ITEMCHANGEDA
;
5214 item
.mask
= HDI_WIDTH
;
5217 ret
= SendMessageA(list
, WM_NOTIFY
, 0, (LPARAM
)&nmh
);
5220 DestroyWindow(list
);
5223 static void test_header_notification2(void)
5225 static char textA
[] = "newtext";
5232 struct message parent_header_notify_seq
[] = {
5233 { WM_NOTIFY
, sent
|id
, 0, 0, 0 },
5237 list
= create_listview_control(LVS_REPORT
);
5238 ok(list
!= NULL
, "failed to create listview window\n");
5240 memset(&col
, 0, sizeof(col
));
5241 col
.mask
= LVCF_WIDTH
| LVCF_TEXT
;
5243 col
.pszText
= textA
;
5244 ret
= SendMessageA(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5247 header
= (HWND
)SendMessageA(list
, LVM_GETHEADER
, 0, 0);
5248 ok(header
!= 0, "No header\n");
5249 memset(&itemW
, 0, sizeof(itemW
));
5250 itemW
.mask
= HDI_WIDTH
| HDI_ORDER
| HDI_TEXT
;
5251 itemW
.pszText
= buffer
;
5252 itemW
.cchTextMax
= sizeof(buffer
);
5253 ret
= SendMessageW(header
, HDM_GETITEMW
, 0, (LPARAM
)&itemW
);
5256 nmhdr
.hdr
.hwndFrom
= header
;
5257 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(header
, GWLP_ID
);
5260 nmhdr
.pitem
= &itemW
;
5262 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5263 nmhdr
.hdr
.code
= HDN_ITEMCHANGINGW
;
5264 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5265 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGINGA
;
5266 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5267 "header notify, parent", TRUE
);
5269 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGINGA
, "Expected ANSI notification code\n");
5270 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5271 nmhdr
.hdr
.code
= HDN_ITEMCHANGEDW
;
5272 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5273 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGEDA
;
5274 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5275 "header notify, parent", TRUE
);
5277 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGEDA
, "Expected ANSI notification code\n");
5278 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5280 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5281 nmhdr
.hdr
.code
= HDN_ITEMCLICKW
;
5282 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5283 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_click_seq
,
5284 "header notify, parent", FALSE
);
5285 ok(nmhdr
.hdr
.code
== HDN_ITEMCLICKA
, "Expected ANSI notification code\n");
5286 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5287 nmhdr
.hdr
.code
= HDN_ITEMDBLCLICKW
;
5288 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5289 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5290 "header notify, parent", FALSE
);
5291 ok(nmhdr
.hdr
.code
== HDN_ITEMDBLCLICKW
, "Expected Unicode notification code\n");
5292 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5293 nmhdr
.hdr
.code
= HDN_DIVIDERDBLCLICKW
;
5294 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5295 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_divider_dclick_seq
,
5296 "header notify, parent", TRUE
);
5297 ok(nmhdr
.hdr
.code
== HDN_DIVIDERDBLCLICKA
, "Expected ANSI notification code\n");
5298 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5299 nmhdr
.hdr
.code
= HDN_BEGINTRACKW
;
5300 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5301 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5302 "header notify, parent", FALSE
);
5303 ok(nmhdr
.hdr
.code
== HDN_BEGINTRACKW
, "Expected Unicode notification code\n");
5304 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5305 nmhdr
.hdr
.code
= HDN_ENDTRACKW
;
5306 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5307 parent_header_notify_seq
[0].id
= HDN_ENDTRACKA
;
5308 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5309 "header notify, parent", FALSE
);
5310 ok(nmhdr
.hdr
.code
== HDN_ENDTRACKA
, "Expected ANSI notification code\n");
5311 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5312 nmhdr
.hdr
.code
= HDN_TRACKW
;
5313 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5314 parent_header_notify_seq
[0].id
= HDN_TRACKA
;
5315 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5316 "header notify, parent", FALSE
);
5317 ok(nmhdr
.hdr
.code
== HDN_TRACKA
, "Expected ANSI notification code\n");
5318 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5319 nmhdr
.hdr
.code
= HDN_BEGINDRAG
;
5320 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5321 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5322 "header notify, parent", FALSE
);
5323 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5324 nmhdr
.hdr
.code
= HDN_ENDDRAG
;
5325 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5326 parent_header_notify_seq
[0].id
= HDN_ENDDRAG
;
5327 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5328 "header notify, parent", FALSE
);
5329 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5330 nmhdr
.hdr
.code
= HDN_FILTERCHANGE
;
5331 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5332 parent_header_notify_seq
[0].id
= HDN_FILTERCHANGE
;
5333 parent_header_notify_seq
[0].flags
|= optional
; /* NT4 does not send this message */
5334 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5335 "header notify, parent", FALSE
);
5336 parent_header_notify_seq
[0].flags
&= ~optional
;
5337 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5338 nmhdr
.hdr
.code
= HDN_BEGINFILTEREDIT
;
5339 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5340 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5341 "header notify, parent", FALSE
);
5342 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5343 nmhdr
.hdr
.code
= HDN_ENDFILTEREDIT
;
5344 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5345 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5346 "header notify, parent", FALSE
);
5347 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5348 nmhdr
.hdr
.code
= HDN_ITEMSTATEICONCLICK
;
5349 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5350 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5351 "header notify, parent", FALSE
);
5352 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5353 nmhdr
.hdr
.code
= HDN_ITEMKEYDOWN
;
5354 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5355 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5356 "header notify, parent", FALSE
);
5358 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5360 DestroyWindow(list
);
5363 static void test_createdragimage(void)
5369 list
= create_listview_control(LVS_ICON
);
5370 ok(list
!= NULL
, "failed to create listview window\n");
5372 insert_item(list
, 0);
5375 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, 0);
5376 ok(himl
== NULL
, "got %p\n", himl
);
5378 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, (LPARAM
)&pt
);
5379 ok(himl
!= NULL
, "got %p\n", himl
);
5380 ImageList_Destroy(himl
);
5382 DestroyWindow(list
);
5385 static void test_dispinfo(void)
5387 static const char testA
[] = "TEST";
5393 hwnd
= create_listview_control(LVS_ICON
);
5394 ok(hwnd
!= NULL
, "failed to create listview window\n");
5396 insert_item(hwnd
, 0);
5398 memset(&item
, 0, sizeof(item
));
5399 item
.pszText
= LPSTR_TEXTCALLBACKA
;
5400 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5403 g_disp_A_to_W
= TRUE
;
5404 item
.pszText
= (char*)buff
;
5405 item
.cchTextMax
= sizeof(buff
)/sizeof(WCHAR
);
5406 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
5407 ok(ret
== sizeof(testA
)-1, "got %d, expected 4\n", ret
);
5408 g_disp_A_to_W
= FALSE
;
5410 ok(memcmp(item
.pszText
, testA
, sizeof(testA
)) == 0,
5411 "got %s, expected %s\n", item
.pszText
, testA
);
5413 DestroyWindow(hwnd
);
5416 static void test_LVM_SETITEMTEXT(void)
5418 static char testA
[] = "TEST";
5423 hwnd
= create_listview_control(LVS_ICON
);
5424 ok(hwnd
!= NULL
, "failed to create listview window\n");
5426 insert_item(hwnd
, 0);
5428 /* null item pointer */
5429 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, 0);
5432 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTW
, 0, 0);
5435 /* index out of bounds */
5436 item
.pszText
= testA
;
5437 item
.cchTextMax
= 0; /* ignored */
5440 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 1, (LPARAM
)&item
);
5443 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, -1, (LPARAM
)&item
);
5446 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5449 DestroyWindow(hwnd
);
5452 static void test_imagelists(void)
5455 HIMAGELIST himl1
, himl2
, himl3
;
5458 himl1
= ImageList_Create(40, 40, 0, 4, 4);
5459 himl2
= ImageList_Create(40, 40, 0, 4, 4);
5460 himl3
= ImageList_Create(40, 40, 0, 4, 4);
5461 ok(himl1
!= NULL
, "Failed to create imagelist\n");
5462 ok(himl2
!= NULL
, "Failed to create imagelist\n");
5463 ok(himl3
!= NULL
, "Failed to create imagelist\n");
5465 hwnd
= create_listview_control(LVS_REPORT
| LVS_SHAREIMAGELISTS
);
5466 header
= subclass_header(hwnd
);
5468 ok(header
!= NULL
, "Expected header\n");
5469 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5470 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5472 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5474 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5475 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5476 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5477 "set normal image list", FALSE
);
5479 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5481 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5482 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5483 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5484 "set state image list", TRUE
);
5486 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5487 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5489 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5491 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5492 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5493 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_set_imagelist
,
5494 "set small image list", FALSE
);
5496 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5497 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5498 DestroyWindow(hwnd
);
5500 hwnd
= create_listview_control(WS_VISIBLE
| LVS_ICON
);
5502 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5504 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5505 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5506 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5507 "set normal image list", FALSE
);
5509 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5511 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5512 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5513 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5514 "set state image list", FALSE
);
5516 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5518 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5519 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5520 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5521 "set small image list", FALSE
);
5523 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5524 ok(header
== NULL
, "Expected no header, got %p\n", header
);
5526 SetWindowLongPtrA(hwnd
, GWL_STYLE
, GetWindowLongPtrA(hwnd
, GWL_STYLE
) | LVS_REPORT
);
5528 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5529 ok(header
!= NULL
, "Expected header, got NULL\n");
5531 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5532 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5534 DestroyWindow(hwnd
);
5537 static void test_deleteitem(void)
5544 hwnd
= create_listview_control(LVS_REPORT
);
5546 insert_item(hwnd
, 0);
5547 insert_item(hwnd
, 0);
5548 insert_item(hwnd
, 0);
5549 insert_item(hwnd
, 0);
5550 insert_item(hwnd
, 0);
5552 g_focus_test_LVN_DELETEITEM
= TRUE
;
5554 /* delete focused item (not the last index) */
5555 item
.stateMask
= LVIS_FOCUSED
;
5556 item
.state
= LVIS_FOCUSED
;
5557 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
5558 ok(ret
== TRUE
, "got %d\n", ret
);
5559 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 2, 0);
5560 ok(ret
== TRUE
, "got %d\n", ret
);
5561 /* next item gets focus */
5562 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5563 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5565 /* focus last item and delete it */
5566 item
.stateMask
= LVIS_FOCUSED
;
5567 item
.state
= LVIS_FOCUSED
;
5568 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
5569 ok(ret
== TRUE
, "got %d\n", ret
);
5570 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 3, 0);
5571 ok(ret
== TRUE
, "got %d\n", ret
);
5572 /* new last item gets focus */
5573 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5574 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5576 /* focus first item and delete it */
5577 item
.stateMask
= LVIS_FOCUSED
;
5578 item
.state
= LVIS_FOCUSED
;
5579 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
5580 ok(ret
== TRUE
, "got %d\n", ret
);
5581 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
5582 ok(ret
== TRUE
, "got %d\n", ret
);
5583 /* new first item gets focus */
5584 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5585 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5587 g_focus_test_LVN_DELETEITEM
= FALSE
;
5589 DestroyWindow(hwnd
);
5592 static void test_insertitem(void)
5599 hwnd
= create_listview_control(LVS_REPORT
);
5601 /* insert item 0 focused */
5602 item
.mask
= LVIF_STATE
;
5603 item
.state
= LVIS_FOCUSED
;
5604 item
.stateMask
= LVIS_FOCUSED
;
5607 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5608 ok(ret
== 0, "got %d\n", ret
);
5610 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5611 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5613 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5615 /* insert item 1, focus shift */
5616 item
.mask
= LVIF_STATE
;
5617 item
.state
= LVIS_FOCUSED
;
5618 item
.stateMask
= LVIS_FOCUSED
;
5621 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5622 ok(ret
== 1, "got %d\n", ret
);
5624 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_insert_focused_seq
, "insert focused", TRUE
);
5626 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5627 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5629 /* insert item 2, no focus shift */
5630 item
.mask
= LVIF_STATE
;
5632 item
.stateMask
= LVIS_FOCUSED
;
5635 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5636 ok(ret
== 2, "got %d\n", ret
);
5638 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5639 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5641 DestroyWindow(hwnd
);
5644 START_TEST(listview
)
5647 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
5649 ULONG_PTR ctx_cookie
;
5652 hComctl32
= GetModuleHandleA("comctl32.dll");
5653 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
5654 if (pInitCommonControlsEx
)
5656 INITCOMMONCONTROLSEX iccex
;
5657 iccex
.dwSize
= sizeof(iccex
);
5658 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
5659 pInitCommonControlsEx(&iccex
);
5662 InitCommonControls();
5664 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
5666 hwndparent
= create_parent_window(FALSE
);
5667 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5669 g_is_below_5
= is_below_comctl_5();
5671 test_header_notification();
5672 test_header_notification2();
5679 test_icon_spacing();
5682 test_item_position();
5687 test_subitem_rect();
5691 test_nosortheader();
5695 test_getitemposition();
5696 test_columnscreation();
5698 test_notifyformat();
5700 test_getitemspacing();
5701 test_getcolumnwidth();
5702 test_approximate_viewrect();
5705 test_destroynotify();
5706 test_createdragimage();
5708 test_LVM_SETITEMTEXT();
5713 if (!load_v6_module(&ctx_cookie
, &hCtx
))
5715 DestroyWindow(hwndparent
);
5719 /* comctl32 version 6 tests start here */
5720 test_get_set_view();
5721 test_canceleditlabel();
5723 test_scrollnotify();
5724 test_LVS_EX_TRANSPARENTBKGND();
5725 test_LVS_EX_HEADERINALLVIEWS();
5730 unload_v6_module(ctx_cookie
, hCtx
);
5732 DestroyWindow(hwndparent
);