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
27 #include "wine/test.h"
33 PARENT_FULL_SEQ_INDEX
,
44 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
45 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
46 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
48 static const WCHAR testparentclassW
[] =
49 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
51 static HWND hwndparent
, hwndparentW
;
52 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
53 static BOOL blockEdit
;
54 /* return nonzero on NM_HOVER */
55 static BOOL g_block_hover
;
56 /* notification data for LVN_ITEMCHANGED */
57 static NMLISTVIEW g_nmlistview
;
58 /* notification data for LVN_ITEMCHANGING */
59 static NMLISTVIEW g_nmlistview_changing
;
60 /* format reported to control:
61 -1 falls to defproc, anything else returned */
62 static INT notifyFormat
;
63 /* indicates we're running < 5.80 version */
64 static BOOL g_is_below_5
;
65 /* item data passed to LVN_GETDISPINFOA */
66 static LVITEMA g_itema
;
67 /* alter notification code A->W */
68 static BOOL g_disp_A_to_W
;
69 /* dispinfo data sent with LVN_LVN_ENDLABELEDIT */
70 static NMLVDISPINFOA g_editbox_disp_info
;
71 /* when this is set focus will be tested on LVN_DELETEITEM */
72 static BOOL g_focus_test_LVN_DELETEITEM
;
74 static HWND
subclass_editbox(HWND hwndListview
);
76 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
78 static const struct message create_ownerdrawfixed_parent_seq
[] = {
79 { WM_NOTIFYFORMAT
, sent
},
80 { WM_QUERYUISTATE
, sent
|optional
}, /* Win2K and higher */
81 { WM_MEASUREITEM
, sent
},
82 { WM_PARENTNOTIFY
, sent
},
86 static const struct message redraw_listview_seq
[] = {
87 { WM_PAINT
, sent
|id
, 0, 0, LISTVIEW_ID
},
88 { WM_PAINT
, sent
|id
, 0, 0, HEADER_ID
},
89 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
90 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, HEADER_ID
},
91 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
92 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
93 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, LISTVIEW_ID
},
97 static const struct message listview_icon_spacing_seq
[] = {
98 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(20, 30) },
99 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(25, 35) },
100 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(-1, -1) },
104 static const struct message listview_color_seq
[] = {
105 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
106 { LVM_GETBKCOLOR
, sent
},
107 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
108 { LVM_GETTEXTCOLOR
, sent
},
109 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
110 { LVM_GETTEXTBKCOLOR
, sent
},
112 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
113 { LVM_GETBKCOLOR
, sent
},
114 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
115 { LVM_GETTEXTCOLOR
, sent
},
116 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
117 { LVM_GETTEXTBKCOLOR
, sent
},
119 { LVM_SETBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
120 { LVM_GETBKCOLOR
, sent
},
121 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, CLR_NONE
},
122 { LVM_GETTEXTCOLOR
, sent
},
123 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
124 { LVM_GETTEXTBKCOLOR
, sent
},
126 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
127 { LVM_GETBKCOLOR
, sent
},
128 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
129 { LVM_GETTEXTCOLOR
, sent
},
130 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
131 { LVM_GETTEXTBKCOLOR
, sent
},
135 static const struct message listview_item_count_seq
[] = {
136 { LVM_GETITEMCOUNT
, sent
},
137 { LVM_INSERTITEMA
, sent
},
138 { LVM_INSERTITEMA
, sent
},
139 { LVM_INSERTITEMA
, sent
},
140 { LVM_GETITEMCOUNT
, sent
},
141 { LVM_DELETEITEM
, sent
|wparam
, 2 },
142 { WM_NCPAINT
, sent
|optional
},
143 { WM_ERASEBKGND
, sent
|optional
},
144 { LVM_GETITEMCOUNT
, sent
},
145 { LVM_DELETEALLITEMS
, sent
},
146 { LVM_GETITEMCOUNT
, sent
},
147 { LVM_INSERTITEMA
, sent
},
148 { LVM_INSERTITEMA
, sent
},
149 { LVM_GETITEMCOUNT
, sent
},
150 { LVM_INSERTITEMA
, sent
},
151 { LVM_GETITEMCOUNT
, sent
},
155 static const struct message listview_itempos_seq
[] = {
156 { LVM_INSERTITEMA
, sent
},
157 { LVM_INSERTITEMA
, sent
},
158 { LVM_INSERTITEMA
, sent
},
159 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 1, MAKELPARAM(10,5) },
160 { WM_NCPAINT
, sent
|optional
},
161 { WM_ERASEBKGND
, sent
|optional
},
162 { LVM_GETITEMPOSITION
, sent
|wparam
, 1 },
163 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 2, MAKELPARAM(0,0) },
164 { LVM_GETITEMPOSITION
, sent
|wparam
, 2 },
165 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 0, MAKELPARAM(20,20) },
166 { LVM_GETITEMPOSITION
, sent
|wparam
, 0 },
170 static const struct message listview_ownerdata_switchto_seq
[] = {
171 { WM_STYLECHANGING
, sent
},
172 { WM_STYLECHANGED
, sent
},
176 static const struct message listview_getorderarray_seq
[] = {
177 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
178 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
179 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 0, 0, LISTVIEW_ID
},
180 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 0, 0, HEADER_ID
},
184 static const struct message listview_setorderarray_seq
[] = {
185 { LVM_SETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
186 { HDM_SETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
187 { LVM_SETCOLUMNORDERARRAY
, sent
|id
|wparam
, 0, 0, LISTVIEW_ID
},
188 { HDM_SETORDERARRAY
, sent
|id
|wparam
, 0, 0, HEADER_ID
},
192 static const struct message empty_seq
[] = {
196 static const struct message forward_erasebkgnd_parent_seq
[] = {
197 { WM_ERASEBKGND
, sent
},
201 static const struct message ownderdata_select_focus_parent_seq
[] = {
202 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
203 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
204 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
}, /* version 4.7x */
208 static const struct message ownerdata_setstate_all_parent_seq
[] = {
209 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
213 static const struct message ownerdata_defocus_all_parent_seq
[] = {
214 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
215 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
216 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
},
217 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
221 static const struct message ownerdata_deselect_all_parent_seq
[] = {
222 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ODCACHEHINT
},
223 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
227 static const struct message change_all_parent_seq
[] = {
228 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
229 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
231 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
232 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
234 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
235 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
237 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
238 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
240 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
241 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
245 static const struct message changing_all_parent_seq
[] = {
246 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
247 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
248 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
249 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
250 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
254 static const struct message textcallback_set_again_parent_seq
[] = {
255 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
256 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
260 static const struct message single_getdispinfo_parent_seq
[] = {
261 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
265 static const struct message getitemposition_seq1
[] = {
266 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
270 static const struct message getitemposition_seq2
[] = {
271 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
272 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
276 static const struct message getsubitemrect_seq
[] = {
277 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, -1, 0, LISTVIEW_ID
},
278 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
279 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, 0, 0, LISTVIEW_ID
},
280 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
281 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, -10, 0, LISTVIEW_ID
},
282 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
283 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, 20, 0, LISTVIEW_ID
},
284 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
288 static const struct message editbox_create_pos
[] = {
289 /* sequence sent after LVN_BEGINLABELEDIT */
290 /* next two are 4.7x specific */
291 { WM_WINDOWPOSCHANGING
, sent
},
292 { WM_WINDOWPOSCHANGED
, sent
|optional
},
294 { WM_WINDOWPOSCHANGING
, sent
|optional
},
295 { WM_NCCALCSIZE
, sent
},
296 { WM_WINDOWPOSCHANGED
, sent
},
297 { WM_MOVE
, sent
|defwinproc
},
298 { WM_SIZE
, sent
|defwinproc
},
299 /* the rest is todo, skipped in 4.7x */
300 { WM_WINDOWPOSCHANGING
, sent
|optional
},
301 { WM_WINDOWPOSCHANGED
, sent
|optional
},
305 static const struct message scroll_parent_seq
[] = {
306 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_BEGINSCROLL
},
307 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDSCROLL
},
311 static const struct message setredraw_seq
[] = {
312 { WM_SETREDRAW
, sent
|id
|wparam
, FALSE
, 0, LISTVIEW_ID
},
316 static const struct message lvs_ex_transparentbkgnd_seq
[] = {
317 { WM_PRINTCLIENT
, sent
|lparam
, 0, PRF_ERASEBKGND
},
321 static const struct message edit_end_nochange
[] = {
322 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDLABELEDITA
},
323 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
}, /* todo */
324 { WM_NOTIFY
, sent
|id
, 0, 0, NM_SETFOCUS
},
328 static const struct message hover_parent
[] = {
329 { WM_GETDLGCODE
, sent
}, /* todo_wine */
330 { WM_NOTIFY
, sent
|id
, 0, 0, NM_HOVER
},
334 static const struct message listview_destroy
[] = {
335 { 0x0090, sent
|optional
}, /* Vista */
336 { WM_PARENTNOTIFY
, sent
},
337 { WM_SHOWWINDOW
, sent
},
338 { WM_WINDOWPOSCHANGING
, sent
},
339 { WM_WINDOWPOSCHANGED
, sent
|optional
},
340 { WM_DESTROY
, sent
},
341 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_DELETEALLITEMS
},
342 { WM_NCDESTROY
, sent
},
346 static const struct message listview_ownerdata_destroy
[] = {
347 { 0x0090, sent
|optional
}, /* Vista */
348 { WM_PARENTNOTIFY
, sent
},
349 { WM_SHOWWINDOW
, sent
},
350 { WM_WINDOWPOSCHANGING
, sent
},
351 { WM_WINDOWPOSCHANGED
, sent
|optional
},
352 { WM_DESTROY
, sent
},
353 { WM_NCDESTROY
, sent
},
357 static const struct message listview_ownerdata_deleteall
[] = {
358 { LVM_DELETEALLITEMS
, sent
},
359 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_DELETEALLITEMS
},
363 static const struct message listview_header_changed_seq
[] = {
364 { LVM_SETCOLUMNA
, sent
},
365 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
366 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
370 static const struct message parent_header_click_seq
[] = {
371 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_COLUMNCLICK
},
372 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCLICKA
},
376 static const struct message parent_header_divider_dclick_seq
[] = {
377 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCHANGINGA
},
378 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
},
379 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
},
380 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCHANGEDA
},
381 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_DIVIDERDBLCLICKA
},
385 static const struct message listview_set_imagelist
[] = {
386 { LVM_SETIMAGELIST
, sent
|id
, 0, 0, LISTVIEW_ID
},
390 static const struct message listview_header_set_imagelist
[] = {
391 { LVM_SETIMAGELIST
, sent
|id
, 0, 0, LISTVIEW_ID
},
392 { HDM_SETIMAGELIST
, sent
|id
, 0, 0, HEADER_ID
},
396 static const struct message parent_insert_focused_seq
[] = {
397 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
398 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
399 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
400 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
401 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_INSERTITEM
},
405 static const struct message parent_report_cd_seq
[] = {
406 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_PREPAINT
},
407 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
},
408 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
|CDDS_SUBITEM
},
409 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
|CDDS_SUBITEM
},
410 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
|CDDS_SUBITEM
},
411 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
|CDDS_SUBITEM
},
412 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
},
413 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_POSTPAINT
},
417 static const struct message parent_list_cd_seq
[] = {
418 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_PREPAINT
},
419 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPREPAINT
},
420 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_ITEMPOSTPAINT
},
421 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, NM_CUSTOMDRAW
, CDDS_POSTPAINT
},
425 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
427 static LONG defwndproc_counter
= 0;
431 msg
.message
= message
;
432 msg
.flags
= sent
|wparam
|lparam
;
433 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
436 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
438 /* log system messages, except for painting */
439 if (message
< WM_USER
&&
440 message
!= WM_PAINT
&&
441 message
!= WM_ERASEBKGND
&&
442 message
!= WM_NCPAINT
&&
443 message
!= WM_NCHITTEST
&&
444 message
!= WM_GETTEXT
&&
445 message
!= WM_GETICON
&&
446 message
!= WM_DEVICECHANGE
)
448 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
449 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
451 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
457 switch (((NMHDR
*)lParam
)->code
)
459 case LVN_BEGINLABELEDITA
:
463 /* subclass edit box */
465 edit
= subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
469 INT len
= SendMessageA(edit
, EM_GETLIMITTEXT
, 0, 0);
470 ok(len
== 259 || broken(len
== 260) /* includes NULL in NT4 */,
471 "text limit %d, expected 259\n", len
);
476 case LVN_ENDLABELEDITA
:
480 /* always accept new item text */
481 NMLVDISPINFOA
*di
= (NMLVDISPINFOA
*)lParam
;
482 g_editbox_disp_info
= *di
;
483 trace("LVN_ENDLABELEDIT: text=%s\n", di
->item
.pszText
? di
->item
.pszText
: "(null)");
485 /* edit control still available from this notification */
486 edit
= (HWND
)SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETEDITCONTROL
, 0, 0);
487 ok(IsWindow(edit
), "expected valid edit control handle\n");
488 ok((GetWindowLongA(edit
, GWL_STYLE
) & ES_MULTILINE
) == 0, "edit is multiline\n");
492 case LVN_BEGINSCROLL
:
495 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
497 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
498 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
501 case LVN_ITEMCHANGING
:
503 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
504 g_nmlistview_changing
= *nmlv
;
507 case LVN_ITEMCHANGED
:
509 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
510 g_nmlistview
= *nmlv
;
513 case LVN_GETDISPINFOA
:
515 NMLVDISPINFOA
*dispinfo
= (NMLVDISPINFOA
*)lParam
;
516 g_itema
= dispinfo
->item
;
518 if (g_disp_A_to_W
&& (dispinfo
->item
.mask
& LVIF_TEXT
))
520 static const WCHAR testW
[] = {'T','E','S','T',0};
521 dispinfo
->hdr
.code
= LVN_GETDISPINFOW
;
522 memcpy(dispinfo
->item
.pszText
, testW
, sizeof(testW
));
525 /* test control buffer size for text, 10 used to mask cases when control
526 is using caller buffer to process LVM_GETITEM for example */
527 if (dispinfo
->item
.mask
& LVIF_TEXT
&& dispinfo
->item
.cchTextMax
> 10)
528 ok(dispinfo
->item
.cchTextMax
== 260 ||
529 broken(dispinfo
->item
.cchTextMax
== 264) /* NT4 reports aligned size */,
530 "buffer size %d\n", dispinfo
->item
.cchTextMax
);
534 if (g_focus_test_LVN_DELETEITEM
)
536 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
539 state
= SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETITEMSTATE
, nmlv
->iItem
, LVIS_FOCUSED
);
540 ok(state
== 0, "got state %x\n", state
);
544 if (g_block_hover
) return 1;
549 case WM_NOTIFYFORMAT
:
551 /* force to return format */
552 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
557 defwndproc_counter
++;
558 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
559 defwndproc_counter
--;
564 static BOOL
register_parent_wnd_class(BOOL Unicode
)
572 clsW
.lpfnWndProc
= parent_wnd_proc
;
575 clsW
.hInstance
= GetModuleHandleW(NULL
);
577 clsW
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
578 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
579 clsW
.lpszMenuName
= NULL
;
580 clsW
.lpszClassName
= testparentclassW
;
585 clsA
.lpfnWndProc
= parent_wnd_proc
;
588 clsA
.hInstance
= GetModuleHandleA(NULL
);
590 clsA
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
591 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
592 clsA
.lpszMenuName
= NULL
;
593 clsA
.lpszClassName
= "Listview test parent class";
596 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
599 static HWND
create_parent_window(BOOL Unicode
)
601 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
604 if (!register_parent_wnd_class(Unicode
))
611 hwnd
= CreateWindowExW(0, testparentclassW
, nameW
,
612 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
613 WS_MAXIMIZEBOX
| WS_VISIBLE
,
615 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
617 hwnd
= CreateWindowExA(0, "Listview test parent class",
618 "Listview test parent window",
619 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
620 WS_MAXIMIZEBOX
| WS_VISIBLE
,
622 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
623 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
627 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
629 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
630 static LONG defwndproc_counter
= 0;
634 /* some debug output for style changing */
635 if ((message
== WM_STYLECHANGING
||
636 message
== WM_STYLECHANGED
) && lParam
)
638 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
639 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
642 msg
.message
= message
;
643 msg
.flags
= sent
|wparam
|lparam
;
644 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
647 msg
.id
= LISTVIEW_ID
;
648 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
649 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
651 defwndproc_counter
++;
652 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
653 defwndproc_counter
--;
657 static HWND
create_listview_control(DWORD style
)
663 GetClientRect(hwndparent
, &rect
);
664 hwnd
= CreateWindowExA(0, WC_LISTVIEWA
, "foo",
665 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
666 0, 0, rect
.right
, rect
.bottom
,
667 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
668 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
670 if (!hwnd
) return NULL
;
672 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
673 (LONG_PTR
)listview_subclass_proc
);
674 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
679 /* unicode listview window with specified parent */
680 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
685 static const WCHAR nameW
[] = {'f','o','o',0};
687 GetClientRect(parent
, &rect
);
688 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
689 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
690 0, 0, rect
.right
, rect
.bottom
,
691 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
692 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
694 if (!hwnd
) return NULL
;
696 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
697 (LONG_PTR
)listview_subclass_proc
);
698 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
703 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
705 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
706 static LONG defwndproc_counter
= 0;
710 msg
.message
= message
;
711 msg
.flags
= sent
|wparam
|lparam
;
712 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
716 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
718 defwndproc_counter
++;
719 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
720 defwndproc_counter
--;
724 static HWND
subclass_header(HWND hwndListview
)
729 hwnd
= (HWND
)SendMessageA(hwndListview
, LVM_GETHEADER
, 0, 0);
730 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
731 (LONG_PTR
)header_subclass_proc
);
732 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
737 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
739 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
740 static LONG defwndproc_counter
= 0;
744 msg
.message
= message
;
745 msg
.flags
= sent
|wparam
|lparam
;
746 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
751 /* all we need is sizing */
752 if (message
== WM_WINDOWPOSCHANGING
||
753 message
== WM_NCCALCSIZE
||
754 message
== WM_WINDOWPOSCHANGED
||
755 message
== WM_MOVE
||
758 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
761 defwndproc_counter
++;
762 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
763 defwndproc_counter
--;
767 static HWND
subclass_editbox(HWND hwndListview
)
772 hwnd
= (HWND
)SendMessageA(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
773 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
774 (LONG_PTR
)editbox_subclass_proc
);
775 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
780 /* Performs a single LVM_HITTEST test */
781 static void test_lvm_hittest_(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
, UINT broken_flags
,
782 BOOL todo_item
, BOOL todo_flags
, int line
)
791 ret
= SendMessageA(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
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");
804 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
805 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
806 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
812 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
814 else if (broken_flags
)
815 ok_(__FILE__
, line
)(lpht
.flags
== flags
|| broken(lpht
.flags
== broken_flags
),
816 "Expected flags %x, got %x\n", flags
, lpht
.flags
);
818 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
821 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
823 /* Performs a single LVM_SUBITEMHITTEST test */
824 static void test_lvm_subitemhittest_(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
825 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
833 ret
= SendMessageA(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
839 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
840 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
845 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
846 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
852 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
855 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
860 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
863 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
866 #define test_lvm_subitemhittest(a,b,c,d,e,f,g,h,i) test_lvm_subitemhittest_(a,b,c,d,e,f,g,h,i,__LINE__)
868 static void test_images(void)
876 static CHAR hello
[] = "hello";
878 himl
= ImageList_Create(40, 40, 0, 4, 4);
879 ok(himl
!= NULL
, "failed to create imagelist\n");
881 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
882 ok(hbmp
!= NULL
, "failed to create bitmap\n");
884 r
= ImageList_Add(himl
, hbmp
, 0);
885 ok(r
== 0, "should be zero\n");
887 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
888 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
889 ok(hwnd
!= NULL
, "failed to create listview window\n");
891 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
892 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
894 ok(r
== 0, "should return zero\n");
896 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
897 ok(r
== 0, "should return zero\n");
899 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
900 ok(r
!= 0, "got 0\n");
902 /* returns dimensions */
904 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
905 ok(r
== 0, "should be zero items\n");
907 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
912 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
913 ok(r
== -1, "should fail\n");
916 item
.pszText
= hello
;
917 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
918 ok(r
== 0, "should not fail\n");
920 memset(&r1
, 0, sizeof r1
);
922 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
925 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
926 ok(r
== TRUE
, "should not fail\n");
929 item
.pszText
= hello
;
930 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
931 ok(r
== 0, "should not fail\n");
933 memset(&r2
, 0, sizeof r2
);
935 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
938 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
943 static void test_checkboxes(void)
948 static CHAR text
[] = "Text",
952 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
953 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
954 ok(hwnd
!= NULL
, "failed to create listview window\n");
956 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
957 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
958 item
.stateMask
= 0xffff;
963 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
967 item
.mask
= LVIF_STATE
;
968 item
.stateMask
= 0xffff;
969 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
971 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
973 /* Don't set LVIF_STATE */
974 item
.mask
= LVIF_TEXT
;
975 item
.stateMask
= 0xffff;
980 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
984 item
.mask
= LVIF_STATE
;
985 item
.stateMask
= 0xffff;
986 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
988 ok(item
.state
== 0, "state %x\n", item
.state
);
990 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
993 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
995 item
.mask
= LVIF_STATE
;
996 item
.stateMask
= 0xffff;
997 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
999 if (item
.state
!= 0x1ccc)
1001 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
1002 DestroyWindow(hwnd
);
1006 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
1008 item
.mask
= LVIF_TEXT
;
1010 item
.pszText
= text2
;
1011 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1015 item
.mask
= LVIF_STATE
;
1016 item
.stateMask
= 0xffff;
1017 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1019 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
1021 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
1023 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
1024 item
.stateMask
= 0xffff;
1025 item
.state
= 0x2aaa;
1026 item
.pszText
= text3
;
1027 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1031 item
.mask
= LVIF_STATE
;
1032 item
.stateMask
= 0xffff;
1033 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1035 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
1037 /* Set an item's state to checked */
1039 item
.mask
= LVIF_STATE
;
1040 item
.stateMask
= 0xf000;
1041 item
.state
= 0x2000;
1042 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1046 item
.mask
= LVIF_STATE
;
1047 item
.stateMask
= 0xffff;
1048 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1050 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1052 /* Check that only the bits we asked for are returned,
1053 * and that all the others are set to zero
1056 item
.mask
= LVIF_STATE
;
1057 item
.stateMask
= 0xf000;
1058 item
.state
= 0xffff;
1059 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1061 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
1063 /* Set the style again and check that doesn't change an item's state */
1064 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1065 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1068 item
.mask
= LVIF_STATE
;
1069 item
.stateMask
= 0xffff;
1070 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1072 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1074 /* Unsetting the checkbox extended style doesn't change an item's state */
1075 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
1076 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1079 item
.mask
= LVIF_STATE
;
1080 item
.stateMask
= 0xffff;
1081 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1083 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1085 /* Now setting the style again will change an item's state */
1086 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1090 item
.mask
= LVIF_STATE
;
1091 item
.stateMask
= 0xffff;
1092 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1094 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
1096 /* Toggle checkbox tests (bug 9934) */
1097 memset (&item
, 0xcc, sizeof(item
));
1098 item
.mask
= LVIF_STATE
;
1101 item
.state
= LVIS_FOCUSED
;
1102 item
.stateMask
= LVIS_FOCUSED
;
1103 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1107 item
.mask
= LVIF_STATE
;
1108 item
.stateMask
= 0xffff;
1109 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1111 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1113 r
= SendMessageA(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1115 r
= SendMessageA(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1119 item
.mask
= LVIF_STATE
;
1120 item
.stateMask
= 0xffff;
1121 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1123 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
1125 r
= SendMessageA(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1127 r
= SendMessageA(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1131 item
.mask
= LVIF_STATE
;
1132 item
.stateMask
= 0xffff;
1133 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1135 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1137 DestroyWindow(hwnd
);
1140 static void insert_column(HWND hwnd
, int idx
)
1145 memset(&column
, 0xcc, sizeof(column
));
1146 column
.mask
= LVCF_SUBITEM
;
1147 column
.iSubItem
= idx
;
1149 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, idx
, (LPARAM
)&column
);
1153 static void insert_item(HWND hwnd
, int idx
)
1155 static CHAR text
[] = "foo";
1160 memset(&item
, 0xcc, sizeof (item
));
1161 item
.mask
= LVIF_TEXT
;
1164 item
.pszText
= text
;
1166 rc
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
1170 static void test_items(void)
1172 const LPARAM lparamTest
= 0x42;
1173 static CHAR text
[] = "Text";
1179 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1180 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1181 ok(hwnd
!= NULL
, "failed to create listview window\n");
1184 * Test setting/getting item params
1187 /* Set up two columns */
1188 insert_column(hwnd
, 0);
1189 insert_column(hwnd
, 1);
1191 /* LVIS_SELECTED with zero stateMask */
1193 memset (&item
, 0, sizeof (item
));
1194 item
.mask
= LVIF_STATE
;
1195 item
.state
= LVIS_SELECTED
;
1199 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1202 memset (&item
, 0xcc, sizeof (item
));
1203 item
.mask
= LVIF_STATE
;
1204 item
.stateMask
= LVIS_SELECTED
;
1208 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1210 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1211 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1213 /* LVIS_SELECTED with zero stateMask */
1215 memset (&item
, 0, sizeof (item
));
1216 item
.mask
= LVIF_STATE
;
1217 item
.state
= LVIS_FOCUSED
;
1221 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1224 memset (&item
, 0xcc, sizeof (item
));
1225 item
.mask
= LVIF_STATE
;
1226 item
.stateMask
= LVIS_FOCUSED
;
1230 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1232 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1233 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1235 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1237 memset (&item
, 0, sizeof (item
));
1238 item
.mask
= LVIF_STATE
;
1239 item
.state
= LVIS_CUT
;
1240 item
.stateMask
= LVIS_FOCUSED
;
1243 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1246 memset (&item
, 0xcc, sizeof (item
));
1247 item
.mask
= LVIF_STATE
;
1248 item
.stateMask
= LVIS_CUT
;
1252 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1254 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1255 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1257 /* Insert an item with just a param */
1258 memset (&item
, 0xcc, sizeof (item
));
1259 item
.mask
= LVIF_PARAM
;
1262 item
.lParam
= lparamTest
;
1263 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1266 /* Test getting of the param */
1267 memset (&item
, 0xcc, sizeof (item
));
1268 item
.mask
= LVIF_PARAM
;
1271 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1273 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1275 /* Set up a subitem */
1276 memset (&item
, 0xcc, sizeof (item
));
1277 item
.mask
= LVIF_TEXT
;
1280 item
.pszText
= text
;
1281 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1284 item
.mask
= LVIF_TEXT
;
1287 item
.pszText
= buffA
;
1288 item
.cchTextMax
= sizeof(buffA
);
1289 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1291 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got text %s, expected %s\n", item
.pszText
, text
);
1293 /* set up with extra flag */
1294 /* 1. reset subitem text */
1295 item
.mask
= LVIF_TEXT
;
1298 item
.pszText
= NULL
;
1299 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1302 item
.mask
= LVIF_TEXT
;
1305 item
.pszText
= buffA
;
1307 item
.cchTextMax
= sizeof(buffA
);
1308 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1310 ok(item
.pszText
[0] == 0, "got %p\n", item
.pszText
);
1312 /* 2. set new text with extra flag specified */
1313 item
.mask
= LVIF_TEXT
| LVIF_DI_SETITEM
;
1316 item
.pszText
= text
;
1317 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1318 ok(r
== 1 || broken(r
== 0) /* NT4 */, "ret %d\n", r
);
1322 item
.mask
= LVIF_TEXT
;
1325 item
.pszText
= buffA
;
1327 item
.cchTextMax
= sizeof(buffA
);
1328 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1330 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got %s, expected %s\n", item
.pszText
, text
);
1333 /* Query param from subitem: returns main item param */
1334 memset (&item
, 0xcc, sizeof (item
));
1335 item
.mask
= LVIF_PARAM
;
1338 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1340 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1342 /* Set up param on first subitem: no effect */
1343 memset (&item
, 0xcc, sizeof (item
));
1344 item
.mask
= LVIF_PARAM
;
1347 item
.lParam
= lparamTest
+1;
1348 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1351 /* Query param from subitem again: should still return main item param */
1352 memset (&item
, 0xcc, sizeof (item
));
1353 item
.mask
= LVIF_PARAM
;
1356 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1358 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1360 /**** Some tests of state highlighting ****/
1361 memset (&item
, 0xcc, sizeof (item
));
1362 item
.mask
= LVIF_STATE
;
1365 item
.state
= LVIS_SELECTED
;
1366 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1367 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1370 item
.state
= LVIS_DROPHILITED
;
1371 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1374 memset (&item
, 0xcc, sizeof (item
));
1375 item
.mask
= LVIF_STATE
;
1378 item
.stateMask
= -1;
1379 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1381 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1383 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1385 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1387 /* some notnull but meaningless masks */
1388 memset (&item
, 0, sizeof(item
));
1389 item
.mask
= LVIF_NORECOMPUTE
;
1392 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1394 memset (&item
, 0, sizeof(item
));
1395 item
.mask
= LVIF_DI_SETITEM
;
1398 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1401 /* set text to callback value already having it */
1402 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1404 memset (&item
, 0, sizeof (item
));
1405 item
.mask
= LVIF_TEXT
;
1406 item
.pszText
= LPSTR_TEXTCALLBACKA
;
1408 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1410 memset (&item
, 0, sizeof (item
));
1412 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1414 item
.pszText
= LPSTR_TEXTCALLBACKA
;
1415 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0 , (LPARAM
) &item
);
1418 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1419 "check callback text comparison rule", FALSE
);
1421 DestroyWindow(hwnd
);
1424 static void test_columns(void)
1433 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_LIST
,
1434 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1435 ok(hwnd
!= NULL
, "failed to create listview window\n");
1437 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
1438 ok(header
== NULL
, "got %p\n", header
);
1440 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1441 ok(rc
== 0, "got %d\n", rc
);
1443 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
1444 ok(header
== NULL
, "got %p\n", header
);
1446 DestroyWindow(hwnd
);
1448 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1449 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1450 ok(hwnd
!= NULL
, "failed to create listview window\n");
1452 /* Add a column with no mask */
1453 memset(&column
, 0xcc, sizeof(column
));
1455 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1456 ok(rc
== 0, "Inserting column with no mask failed with %d\n", rc
);
1458 /* Check its width */
1459 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
1460 ok(rc
== 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1462 DestroyWindow(hwnd
);
1464 /* LVM_GETCOLUMNORDERARRAY */
1465 hwnd
= create_listview_control(LVS_REPORT
);
1466 subclass_header(hwnd
);
1468 memset(&column
, 0, sizeof(column
));
1469 column
.mask
= LVCF_WIDTH
;
1471 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1475 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&column
);
1478 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1480 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1482 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1483 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1485 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 0, 0);
1488 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1490 /* LVM_SETCOLUMNORDERARRAY */
1491 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1495 rc
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1498 rc
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 0, 0);
1501 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_setorderarray_seq
, "set order array", FALSE
);
1503 /* after column added subitem is considered as present */
1504 insert_item(hwnd
, 0);
1506 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1508 item
.pszText
= buff
;
1509 item
.cchTextMax
= sizeof(buff
);
1512 item
.mask
= LVIF_TEXT
;
1513 memset(&g_itema
, 0, sizeof(g_itema
));
1514 rc
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
1516 ok(g_itema
.iSubItem
== 1, "got %d\n", g_itema
.iSubItem
);
1518 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
1519 "get subitem text after column added", FALSE
);
1521 DestroyWindow(hwnd
);
1524 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1525 static WNDPROC listviewWndProc
;
1526 static HIMAGELIST test_create_imagelist
;
1528 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1532 if (uMsg
== WM_CREATE
)
1534 CREATESTRUCTA
*lpcs
= (CREATESTRUCTA
*)lParam
;
1535 lpcs
->style
|= LVS_REPORT
;
1537 ret
= CallWindowProcA(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1538 if (uMsg
== WM_CREATE
) SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1542 static void test_create(void)
1553 cls
.cbSize
= sizeof(WNDCLASSEXA
);
1554 ok(GetClassInfoExA(GetModuleHandleA(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1555 listviewWndProc
= cls
.lpfnWndProc
;
1556 cls
.lpfnWndProc
= create_test_wndproc
;
1557 cls
.lpszClassName
= "MyListView32";
1558 ok(RegisterClassExA(&cls
), "RegisterClassEx failed\n");
1560 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1561 hList
= CreateWindowA("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1562 ok((HIMAGELIST
)SendMessageA(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1563 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1565 if (!IsWindow(hHeader
))
1568 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1569 DestroyWindow(hList
);
1573 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1574 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1575 DestroyWindow(hList
);
1577 /* header isn't created on LVS_ICON and LVS_LIST styles */
1578 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1579 GetModuleHandleA(NULL
), 0);
1580 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1581 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1582 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1584 memset(&col
, 0, sizeof(LVCOLUMNA
));
1585 col
.mask
= LVCF_WIDTH
;
1587 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1589 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1590 ok(IsWindow(hHeader
), "Header should be created\n");
1591 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1592 style
= GetWindowLongA(hHeader
, GWL_STYLE
);
1593 ok(!(style
& HDS_HIDDEN
), "Not expected HDS_HIDDEN\n");
1594 DestroyWindow(hList
);
1596 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1597 GetModuleHandleA(NULL
), 0);
1598 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1599 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1600 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1602 memset(&col
, 0, sizeof(LVCOLUMNA
));
1603 col
.mask
= LVCF_WIDTH
;
1605 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1607 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1608 ok(IsWindow(hHeader
), "Header should be created\n");
1609 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1610 DestroyWindow(hList
);
1612 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1613 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1614 GetModuleHandleA(NULL
), 0);
1615 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
, GetWindowLongPtrA(hList
, GWL_STYLE
) | LVS_REPORT
);
1616 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1617 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1618 ok(IsWindow(hHeader
), "Header should be created\n");
1619 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
, GetWindowLongA(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1620 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1621 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1622 ok(IsWindow(hHeader
), "Header should be created\n");
1623 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1624 DestroyWindow(hList
);
1626 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1627 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1628 GetModuleHandleA(NULL
), 0);
1629 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
,
1630 (GetWindowLongPtrA(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1631 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1632 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1633 ok(IsWindow(hHeader
), "Header should be created\n");
1634 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1635 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
,
1636 (GetWindowLongPtrA(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1637 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1638 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1639 ok(IsWindow(hHeader
), "Header should be created\n");
1640 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1641 DestroyWindow(hList
);
1643 /* LVS_REPORT without WS_VISIBLE */
1644 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1645 GetModuleHandleA(NULL
), 0);
1646 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1647 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1648 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1650 memset(&col
, 0, sizeof(LVCOLUMNA
));
1651 col
.mask
= LVCF_WIDTH
;
1653 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1655 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1656 ok(IsWindow(hHeader
), "Header should be created\n");
1657 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1658 DestroyWindow(hList
);
1660 /* LVS_REPORT without WS_VISIBLE, try to show it */
1661 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1662 GetModuleHandleA(NULL
), 0);
1663 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1664 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1665 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1666 ShowWindow(hList
, SW_SHOW
);
1667 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1668 ok(IsWindow(hHeader
), "Header should be created\n");
1669 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1670 DestroyWindow(hList
);
1672 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1673 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1674 0, 0, 100, 100, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1675 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1676 ok(IsWindow(hHeader
), "Header should be created\n");
1677 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1678 /* HDS_DRAGDROP set by default */
1679 ok(GetWindowLongPtrA(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1680 DestroyWindow(hList
);
1682 /* setting LVS_EX_HEADERDRAGDROP creates header */
1683 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1684 GetModuleHandleA(NULL
), 0);
1685 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1686 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1687 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1688 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1689 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1690 ok(IsWindow(hHeader
) ||
1691 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1692 "Header should be created\n");
1693 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1694 DestroyWindow(hList
);
1696 /* setting LVS_EX_GRIDLINES creates header */
1697 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1698 GetModuleHandleA(NULL
), 0);
1699 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1700 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1701 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1702 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_GRIDLINES
);
1703 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1704 ok(IsWindow(hHeader
) ||
1705 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1706 "Header should be created\n");
1707 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1708 DestroyWindow(hList
);
1710 /* setting LVS_EX_FULLROWSELECT creates header */
1711 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1712 GetModuleHandleA(NULL
), 0);
1713 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1714 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1715 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1716 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
1717 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1718 ok(IsWindow(hHeader
) ||
1719 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1720 "Header should be created\n");
1721 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1722 DestroyWindow(hList
);
1724 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1725 hList
= create_listview_control(LVS_ICON
);
1726 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1727 r
= SendMessageA(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1728 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1729 DestroyWindow(hList
);
1731 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1732 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1733 GetModuleHandleA(NULL
), 0);
1734 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1735 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1737 rect
.left
= LVIR_BOUNDS
;
1739 rect
.right
= rect
.bottom
= -10;
1740 r
= SendMessageA(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1741 /* right value contains garbage, probably because header columns are not set up */
1742 expect(0, rect
.bottom
);
1745 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1746 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1747 ok(GetDlgItem(hList
, 0) == NULL
, "NULL dialog item expected\n");
1749 DestroyWindow(hList
);
1751 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1752 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1753 hList
= create_listview_control(LVS_OWNERDRAWFIXED
| LVS_REPORT
);
1754 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1755 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1756 DestroyWindow(hList
);
1759 static void test_redraw(void)
1766 hwnd
= create_listview_control(LVS_REPORT
);
1767 subclass_header(hwnd
);
1769 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1771 InvalidateRect(hwnd
, NULL
, TRUE
);
1773 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1775 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1777 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1778 /* 1. Without backbuffer */
1779 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
1782 hdc
= GetWindowDC(hwndparent
);
1784 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1785 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1786 ok(r
== 1, "Expected not zero result\n");
1787 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1788 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1790 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_DEFAULT
);
1793 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1794 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1796 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1797 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1799 /* 2. With backbuffer */
1800 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1801 LVS_EX_DOUBLEBUFFER
);
1802 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
1805 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1806 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1808 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1809 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1811 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_DEFAULT
);
1814 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1815 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1816 todo_wine
expect(1, r
);
1817 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1818 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1820 ReleaseDC(hwndparent
, hdc
);
1822 DestroyWindow(hwnd
);
1825 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1827 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1829 if(message
== WM_NOTIFY
) {
1830 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1831 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1832 NMLVCUSTOMDRAW
*nmlvcd
= (NMLVCUSTOMDRAW
*)nmhdr
;
1835 msg
.message
= message
;
1836 msg
.flags
= sent
|wparam
|lparam
|custdraw
;
1837 msg
.wParam
= wParam
;
1838 msg
.lParam
= lParam
;
1839 msg
.id
= nmhdr
->code
;
1840 msg
.stage
= nmlvcd
->nmcd
.dwDrawStage
;
1841 add_message(sequences
, PARENT_CD_SEQ_INDEX
, &msg
);
1843 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1845 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1846 return CDRF_NOTIFYITEMDRAW
|CDRF_NOTIFYPOSTPAINT
;
1847 case CDDS_ITEMPREPAINT
:
1848 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1849 nmlvcd
->clrText
= RGB(0, 255, 0);
1850 return CDRF_NOTIFYSUBITEMDRAW
|CDRF_NOTIFYPOSTPAINT
;
1851 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1852 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1853 ok(nmlvcd
->clrTextBk
== CLR_DEFAULT
, "got 0x%x\n", nmlvcd
->clrTextBk
);
1854 ok(nmlvcd
->clrText
== RGB(0, 255, 0), "got 0x%x\n", nmlvcd
->clrText
);
1855 if (nmlvcd
->iSubItem
)
1856 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1858 ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1859 return CDRF_NOTIFYPOSTPAINT
;
1860 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1861 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1862 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1863 ok(nmlvcd
->clrTextBk
== CLR_DEFAULT
, "got 0x%x\n", nmlvcd
->clrTextBk
);
1864 ok(nmlvcd
->clrText
== RGB(0, 255, 0), "got 0x%x\n", nmlvcd
->clrText
);
1865 return CDRF_DODEFAULT
;
1867 return CDRF_DODEFAULT
;
1871 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1874 static void test_customdraw(void)
1879 hwnd
= create_listview_control(LVS_REPORT
);
1881 insert_column(hwnd
, 0);
1882 insert_column(hwnd
, 1);
1883 insert_item(hwnd
, 0);
1885 oldwndproc
= (WNDPROC
)SetWindowLongPtrA(hwndparent
, GWLP_WNDPROC
,
1886 (LONG_PTR
)cd_wndproc
);
1888 InvalidateRect(hwnd
, NULL
, TRUE
);
1892 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1893 InvalidateRect(hwnd
, NULL
, TRUE
);
1895 ok_sequence(sequences
, PARENT_CD_SEQ_INDEX
, parent_report_cd_seq
, "parent customdraw, LVS_REPORT", FALSE
);
1897 DestroyWindow(hwnd
);
1899 hwnd
= create_listview_control(LVS_LIST
);
1901 insert_column(hwnd
, 0);
1902 insert_column(hwnd
, 1);
1903 insert_item(hwnd
, 0);
1905 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1906 InvalidateRect(hwnd
, NULL
, TRUE
);
1908 ok_sequence(sequences
, PARENT_CD_SEQ_INDEX
, parent_list_cd_seq
, "parent customdraw, LVS_LIST", FALSE
);
1910 SetWindowLongPtrA(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1911 DestroyWindow(hwnd
);
1914 static void test_icon_spacing(void)
1916 /* LVM_SETICONSPACING */
1917 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1923 hwnd
= create_listview_control(LVS_ICON
);
1924 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1926 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, NF_REQUERY
);
1927 expect(NFR_ANSI
, r
);
1929 /* reset the icon spacing to defaults */
1930 SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1932 /* now we can request what the defaults are */
1933 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1937 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1939 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1940 ok(r
== MAKELONG(w
, h
) ||
1941 broken(r
== MAKELONG(w
, w
)), /* win98 */
1942 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1944 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1948 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1949 DestroyWindow(hwnd
);
1952 expect(MAKELONG(20,30), r
);
1954 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1955 expect(MAKELONG(25,35), r
);
1957 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1959 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1960 DestroyWindow(hwnd
);
1963 static void test_color(void)
1971 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1973 hwnd
= create_listview_control(LVS_REPORT
);
1974 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1976 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1978 for (i
= 0; i
< 4; i
++)
1982 r
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1984 r
= SendMessageA(hwnd
, LVM_GETBKCOLOR
, 0, 0);
1987 r
= SendMessageA(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1989 r
= SendMessageA(hwnd
, LVM_GETTEXTCOLOR
, 0, 0);
1992 r
= SendMessageA(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1994 r
= SendMessageA(hwnd
, LVM_GETTEXTBKCOLOR
, 0, 0);
1998 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1999 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2001 /* invalidation test done separately to avoid a message chain mess */
2002 r
= ValidateRect(hwnd
, NULL
);
2004 r
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, colors
[0]);
2007 rect
.right
= rect
.bottom
= 1;
2008 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
2009 todo_wine
expect(FALSE
, r
);
2010 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
2012 r
= ValidateRect(hwnd
, NULL
);
2014 r
= SendMessageA(hwnd
, LVM_SETTEXTCOLOR
, 0, colors
[0]);
2017 rect
.right
= rect
.bottom
= 1;
2018 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
2019 todo_wine
expect(FALSE
, r
);
2020 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
2022 r
= ValidateRect(hwnd
, NULL
);
2024 r
= SendMessageA(hwnd
, LVM_SETTEXTBKCOLOR
, 0, colors
[0]);
2027 rect
.right
= rect
.bottom
= 1;
2028 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
2029 todo_wine
expect(FALSE
, r
);
2030 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
2032 DestroyWindow(hwnd
);
2035 static void test_item_count(void)
2037 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
2050 static CHAR item0text
[] = "item0";
2051 static CHAR item1text
[] = "item1";
2052 static CHAR item2text
[] = "item2";
2054 hwnd
= create_listview_control(LVS_REPORT
);
2055 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2057 /* resize in dpiaware manner to fit all 3 items added */
2059 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
2060 GetTextMetricsA(hdc
, &tm
);
2061 /* 2 extra pixels for bounds and header border */
2062 height
= tm
.tmHeight
+ 2;
2063 SelectObject(hdc
, hOldFont
);
2066 GetWindowRect(hwnd
, &rect
);
2067 /* 3 items + 1 header + 1 to be sure */
2068 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
2070 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2072 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2076 item0
.mask
= LVIF_TEXT
;
2079 item0
.pszText
= item0text
;
2080 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item0
);
2083 /* [item0, item1] */
2084 item1
.mask
= LVIF_TEXT
;
2087 item1
.pszText
= item1text
;
2088 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2091 /* [item0, item1, item2] */
2092 item2
.mask
= LVIF_TEXT
;
2095 item2
.pszText
= item2text
;
2096 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2099 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2102 /* [item0, item1] */
2103 r
= SendMessageA(hwnd
, LVM_DELETEITEM
, 2, 0);
2106 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2110 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
2113 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2117 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2120 /* [item0, item1] */
2121 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2124 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2127 /* [item0, item1, item2] */
2128 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2131 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2134 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
2136 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2137 DestroyWindow(hwnd
);
2140 static void test_item_position(void)
2142 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2151 static CHAR item0text
[] = "item0";
2152 static CHAR item1text
[] = "item1";
2153 static CHAR item2text
[] = "item2";
2155 hwnd
= create_listview_control(LVS_ICON
);
2156 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2158 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2161 item0
.mask
= LVIF_TEXT
;
2164 item0
.pszText
= item0text
;
2165 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item0
);
2168 /* [item0, item1] */
2169 item1
.mask
= LVIF_TEXT
;
2172 item1
.pszText
= item1text
;
2173 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2176 /* [item0, item1, item2] */
2177 item2
.mask
= LVIF_TEXT
;
2180 item2
.pszText
= item2text
;
2181 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2184 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
2186 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
2188 expect2(10, 5, position
.x
, position
.y
);
2190 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
2192 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
2194 expect2(0, 0, position
.x
, position
.y
);
2196 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
2198 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
2200 expect2(20, 20, position
.x
, position
.y
);
2202 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
2204 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2205 DestroyWindow(hwnd
);
2208 static void test_getorigin(void)
2216 position
.x
= position
.y
= 0;
2218 hwnd
= create_listview_control(LVS_ICON
);
2219 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2220 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2222 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2224 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2225 DestroyWindow(hwnd
);
2227 hwnd
= create_listview_control(LVS_SMALLICON
);
2228 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2229 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2231 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2233 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2234 DestroyWindow(hwnd
);
2236 hwnd
= create_listview_control(LVS_LIST
);
2237 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2238 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2240 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2242 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2243 DestroyWindow(hwnd
);
2245 hwnd
= create_listview_control(LVS_REPORT
);
2246 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2247 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2249 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2251 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2252 DestroyWindow(hwnd
);
2255 static void test_multiselect(void)
2257 typedef struct t_select_task
2268 int i
,j
,item_count
,selected_count
;
2269 static const int items
=5;
2275 static struct t_select_task task_list
[] = {
2276 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
2277 { "using VK_UP", -1, VK_UP
, -1, -1 },
2278 { "using VK_END", 0, VK_END
, 1, -1 },
2279 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
2282 hwnd
= create_listview_control(LVS_REPORT
);
2284 for (i
= 0; i
< items
; i
++)
2285 insert_item(hwnd
, 0);
2287 item_count
= (int)SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2288 expect(items
, item_count
);
2290 for (i
= 0; i
< 4; i
++) {
2293 task
= task_list
[i
];
2295 /* deselect all items */
2297 item
.stateMask
= LVIS_SELECTED
;
2298 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2299 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2301 /* set initial position */
2302 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
2304 item
.state
= LVIS_SELECTED
;
2305 item
.stateMask
= LVIS_SELECTED
;
2306 SendMessageA(hwnd
, LVM_SETITEMSTATE
, task
.initPos
== -1 ? item_count
-1 : task
.initPos
, (LPARAM
)&item
);
2308 selected_count
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2309 ok(selected_count
== 1, "expected 1, got %d\n", selected_count
);
2311 /* Set SHIFT key pressed */
2312 GetKeyboardState(kstate
);
2313 kstate
[VK_SHIFT
]=0x80;
2314 SetKeyboardState(kstate
);
2316 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
2317 r
= SendMessageA(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
2319 r
= SendMessageA(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
2323 selected_count
= (int)SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2325 ok((task
.result
== -1 ? item_count
: task
.result
) == selected_count
, "Failed multiple selection %s. There should be %d selected items (is %d)\n", task
.descr
, item_count
, selected_count
);
2327 /* Set SHIFT key released */
2328 GetKeyboardState(kstate
);
2329 kstate
[VK_SHIFT
]=0x00;
2330 SetKeyboardState(kstate
);
2332 DestroyWindow(hwnd
);
2334 /* make multiple selection, then switch to LVS_SINGLESEL */
2335 hwnd
= create_listview_control(LVS_REPORT
);
2336 for (i
=0;i
<items
;i
++) {
2337 insert_item(hwnd
, 0);
2339 item_count
= (int)SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2340 expect(items
,item_count
);
2342 /* try with NULL pointer */
2343 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, 0);
2346 /* select all, check notifications */
2348 item
.stateMask
= LVIS_SELECTED
;
2349 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2351 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2353 item
.stateMask
= LVIS_SELECTED
;
2354 item
.state
= LVIS_SELECTED
;
2355 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2358 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2359 "select all notification", FALSE
);
2361 /* select all again (all selected already) */
2362 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2364 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2366 item
.stateMask
= LVIS_SELECTED
;
2367 item
.state
= LVIS_SELECTED
;
2368 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2371 ok(g_nmlistview_changing
.uNewState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2372 ok(g_nmlistview_changing
.uOldState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2373 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2375 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2376 "select all notification 2", FALSE
);
2378 /* deselect all items */
2379 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2382 item
.stateMask
= LVIS_SELECTED
;
2383 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2385 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2386 "deselect all notification", FALSE
);
2388 /* deselect all items again */
2389 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2391 item
.stateMask
= LVIS_SELECTED
;
2392 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2393 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "deselect all notification 2", FALSE
);
2395 /* any non-zero state value does the same */
2396 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2398 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2400 item
.stateMask
= LVIS_SELECTED
;
2401 item
.state
= LVIS_CUT
;
2402 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2405 ok(g_nmlistview_changing
.uNewState
== 0, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2406 ok(g_nmlistview_changing
.uOldState
== 0, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2407 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2409 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2410 "set state all notification 3", FALSE
);
2412 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2413 for (i
= 0; i
< 3; i
++) {
2414 item
.state
= LVIS_SELECTED
;
2415 item
.stateMask
= LVIS_SELECTED
;
2416 SendMessageA(hwnd
, LVM_SETITEMSTATE
, i
, (LPARAM
)&item
);
2419 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2421 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2424 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2425 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2426 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2427 /* check that style is accepted */
2428 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2429 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2432 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, i
, LVIS_SELECTED
);
2433 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2435 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2437 SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2440 /* select one more */
2441 item
.state
= LVIS_SELECTED
;
2442 item
.stateMask
= LVIS_SELECTED
;
2443 SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
2446 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, i
, LVIS_SELECTED
);
2447 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2450 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 3, LVIS_SELECTED
);
2451 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2453 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2455 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2458 /* try to select all on LVS_SINGLESEL */
2459 memset(&item
, 0, sizeof(item
));
2460 item
.stateMask
= LVIS_SELECTED
;
2461 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2463 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2465 item
.stateMask
= LVIS_SELECTED
;
2466 item
.state
= LVIS_SELECTED
;
2467 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2470 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2472 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2475 /* try to deselect all on LVS_SINGLESEL */
2476 item
.stateMask
= LVIS_SELECTED
;
2477 item
.state
= LVIS_SELECTED
;
2478 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2481 item
.stateMask
= LVIS_SELECTED
;
2483 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2485 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2488 /* 1. selection mark is update when new focused item is set */
2489 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2490 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2492 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2495 item
.stateMask
= LVIS_FOCUSED
;
2496 item
.state
= LVIS_FOCUSED
;
2497 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2500 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2503 /* it's not updated if already set */
2504 item
.stateMask
= LVIS_FOCUSED
;
2505 item
.state
= LVIS_FOCUSED
;
2506 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2509 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2512 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2515 item
.stateMask
= LVIS_FOCUSED
;
2516 item
.state
= LVIS_FOCUSED
;
2517 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2520 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2523 /* need to reset focused item first */
2524 item
.stateMask
= LVIS_FOCUSED
;
2526 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2529 item
.stateMask
= LVIS_FOCUSED
;
2530 item
.state
= LVIS_FOCUSED
;
2531 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
2534 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2537 item
.stateMask
= LVIS_FOCUSED
;
2539 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2542 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2545 /* 2. same tests, with LVM_SETITEM */
2546 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2547 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2549 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2552 item
.stateMask
= LVIS_FOCUSED
;
2553 item
.state
= LVIS_FOCUSED
;
2554 item
.mask
= LVIF_STATE
;
2555 item
.iItem
= item
.iSubItem
= 0;
2556 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2559 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2562 /* it's not updated if already set */
2563 item
.stateMask
= LVIS_FOCUSED
;
2564 item
.state
= LVIS_FOCUSED
;
2565 item
.mask
= LVIF_STATE
;
2568 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2571 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2574 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2577 item
.stateMask
= LVIS_FOCUSED
;
2578 item
.state
= LVIS_FOCUSED
;
2579 item
.mask
= LVIF_STATE
;
2582 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2585 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2588 /* need to reset focused item first */
2589 item
.stateMask
= LVIS_FOCUSED
;
2591 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2594 item
.stateMask
= LVIS_FOCUSED
;
2595 item
.state
= LVIS_FOCUSED
;
2596 item
.mask
= LVIF_STATE
;
2599 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2602 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2605 item
.stateMask
= LVIS_FOCUSED
;
2607 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2610 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2613 DestroyWindow(hwnd
);
2616 static void test_subitem_rect(void)
2624 /* test LVM_GETSUBITEMRECT for header */
2625 hwnd
= create_listview_control(LVS_REPORT
);
2626 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2627 /* add some columns */
2628 memset(&col
, 0, sizeof(LVCOLUMNA
));
2629 col
.mask
= LVCF_WIDTH
;
2631 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
2634 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&col
);
2637 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 2, (LPARAM
)&col
);
2639 /* item = -1 means header, subitem index is 1 based */
2640 rect
.left
= LVIR_BOUNDS
;
2642 rect
.right
= rect
.bottom
= 0;
2643 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2646 rect
.left
= LVIR_BOUNDS
;
2648 rect
.right
= rect
.bottom
= 0;
2649 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2652 expect(100, rect
.left
);
2653 expect(250, rect
.right
);
2654 expect(3, rect
.top
);
2656 rect
.left
= LVIR_BOUNDS
;
2658 rect
.right
= rect
.bottom
= 0;
2659 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2662 expect(250, rect
.left
);
2663 expect(450, rect
.right
);
2664 expect(3, rect
.top
);
2666 /* item LVS_REPORT padding isn't applied to subitems */
2667 insert_item(hwnd
, 0);
2669 rect
.left
= LVIR_BOUNDS
;
2671 rect
.right
= rect
.bottom
= 0;
2672 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2674 expect(100, rect
.left
);
2675 expect(250, rect
.right
);
2677 rect
.left
= LVIR_ICON
;
2679 rect
.right
= rect
.bottom
= 0;
2680 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2682 /* no icon attached - zero width rectangle, with no left padding */
2683 expect(100, rect
.left
);
2684 expect(100, rect
.right
);
2686 rect
.left
= LVIR_LABEL
;
2688 rect
.right
= rect
.bottom
= 0;
2689 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2691 /* same as full LVIR_BOUNDS */
2692 expect(100, rect
.left
);
2693 expect(250, rect
.right
);
2695 SendMessageA(hwnd
, LVM_SCROLL
, 10, 0);
2697 rect
.left
= LVIR_BOUNDS
;
2699 rect
.right
= rect
.bottom
= 0;
2700 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2702 expect(90, rect
.left
);
2703 expect(240, rect
.right
);
2705 SendMessageA(hwnd
, LVM_SCROLL
, -10, 0);
2707 /* test header interaction */
2708 subclass_header(hwnd
);
2709 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2711 rect
.left
= LVIR_BOUNDS
;
2713 rect
.right
= rect
.bottom
= 0;
2714 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2717 rect
.left
= LVIR_BOUNDS
;
2719 rect
.right
= rect
.bottom
= 0;
2720 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2723 rect
.left
= LVIR_BOUNDS
;
2725 rect
.right
= rect
.bottom
= 0;
2726 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -10, (LPARAM
)&rect
);
2729 rect
.left
= LVIR_BOUNDS
;
2731 rect
.right
= rect
.bottom
= 0;
2732 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 20, (LPARAM
)&rect
);
2735 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getsubitemrect_seq
, "LVM_GETSUBITEMRECT negative index", FALSE
);
2737 DestroyWindow(hwnd
);
2739 /* test subitem rects after re-arranging columns */
2740 hwnd
= create_listview_control(LVS_REPORT
);
2741 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2742 memset(&col
, 0, sizeof(LVCOLUMNA
));
2743 col
.mask
= LVCF_WIDTH
;
2746 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
2750 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&col
);
2754 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 2, (LPARAM
)&col
);
2757 insert_item(hwnd
, 0);
2758 insert_item(hwnd
, 1);
2760 /* wrong item is refused for main item */
2761 rect
.left
= LVIR_BOUNDS
;
2763 rect
.right
= rect
.bottom
= -1;
2764 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect
);
2767 /* for subitems rectangle is calculated even if there's no item added */
2768 rect
.left
= LVIR_BOUNDS
;
2770 rect
.right
= rect
.bottom
= -1;
2771 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect
);
2774 rect2
.left
= LVIR_BOUNDS
;
2776 rect2
.right
= rect2
.bottom
= -1;
2777 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect2
);
2779 expect(rect
.right
, rect2
.right
);
2780 expect(rect
.left
, rect2
.left
);
2781 expect(rect
.bottom
, rect2
.top
);
2782 ok(rect2
.bottom
> rect2
.top
, "expected not zero height\n");
2784 arr
[0] = 1; arr
[1] = 0; arr
[2] = 2;
2785 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 3, (LPARAM
)arr
);
2788 rect
.left
= LVIR_BOUNDS
;
2790 rect
.right
= rect
.bottom
= -1;
2791 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2793 expect(0, rect
.left
);
2794 expect(600, rect
.right
);
2796 rect
.left
= LVIR_BOUNDS
;
2798 rect
.right
= rect
.bottom
= -1;
2799 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2801 expect(0, rect
.left
);
2802 expect(200, rect
.right
);
2804 rect2
.left
= LVIR_BOUNDS
;
2806 rect2
.right
= rect2
.bottom
= -1;
2807 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect2
);
2809 expect(0, rect2
.left
);
2810 expect(200, rect2
.right
);
2811 /* items are of the same height */
2812 ok(rect2
.top
> 0, "expected positive item height\n");
2813 expect(rect
.bottom
, rect2
.top
);
2814 expect(rect
.bottom
* 2 - rect
.top
, rect2
.bottom
);
2816 rect
.left
= LVIR_BOUNDS
;
2818 rect
.right
= rect
.bottom
= -1;
2819 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2821 expect(300, rect
.left
);
2822 expect(600, rect
.right
);
2824 DestroyWindow(hwnd
);
2826 /* try it for non LVS_REPORT style */
2827 hwnd
= CreateWindowA("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2828 GetModuleHandleA(NULL
), 0);
2829 rect
.left
= LVIR_BOUNDS
;
2831 rect
.right
= rect
.bottom
= -10;
2832 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2834 /* rect is unchanged */
2835 expect(0, rect
.left
);
2836 expect(-10, rect
.right
);
2837 expect(1, rect
.top
);
2838 expect(-10, rect
.bottom
);
2839 DestroyWindow(hwnd
);
2842 /* comparison callback for test_sorting */
2843 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2845 if (first
== second
) return 0;
2846 return (first
> second
? 1 : -1);
2849 static void test_sorting(void)
2855 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2858 hwnd
= create_listview_control(LVS_REPORT
);
2859 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2861 /* insert some items */
2862 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2863 item
.state
= LVIS_SELECTED
;
2867 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2870 item
.mask
= LVIF_PARAM
;
2874 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2877 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2878 item
.state
= LVIS_SELECTED
;
2882 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2885 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2888 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2891 r
= SendMessageA(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2894 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2896 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2898 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2900 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2901 expect(LVIS_SELECTED
, r
);
2902 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2903 expect(LVIS_SELECTED
, r
);
2905 DestroyWindow(hwnd
);
2907 /* switch to LVS_SORTASCENDING when some items added */
2908 hwnd
= create_listview_control(LVS_REPORT
);
2909 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2911 item
.mask
= LVIF_TEXT
;
2914 item
.pszText
= names
[1];
2915 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2918 item
.mask
= LVIF_TEXT
;
2921 item
.pszText
= names
[2];
2922 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2925 item
.mask
= LVIF_TEXT
;
2928 item
.pszText
= names
[0];
2929 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2932 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2933 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2934 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2935 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2937 /* no sorting performed when switched to LVS_SORTASCENDING */
2938 item
.mask
= LVIF_TEXT
;
2940 item
.pszText
= buff
;
2941 item
.cchTextMax
= sizeof(buff
);
2942 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2944 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2947 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2949 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2952 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2954 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2956 /* adding new item doesn't resort list */
2957 item
.mask
= LVIF_TEXT
;
2960 item
.pszText
= names
[3];
2961 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2964 item
.mask
= LVIF_TEXT
;
2966 item
.pszText
= buff
;
2967 item
.cchTextMax
= sizeof(buff
);
2968 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2970 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2973 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2975 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2978 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2980 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2983 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2985 ok(lstrcmpA(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2987 /* corner case - item should be placed at first position */
2988 item
.mask
= LVIF_TEXT
;
2991 item
.pszText
= names
[4];
2992 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2996 item
.pszText
= buff
;
2997 item
.cchTextMax
= sizeof(buff
);
2998 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
3000 ok(lstrcmpA(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
3003 item
.pszText
= buff
;
3004 item
.cchTextMax
= sizeof(buff
);
3005 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
3007 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
3010 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
3012 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
3015 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
3017 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
3020 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
3022 ok(lstrcmpA(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
3024 DestroyWindow(hwnd
);
3027 static void test_ownerdata(void)
3029 static char test_str
[] = "test";
3032 LONG_PTR style
, ret
;
3036 /* it isn't possible to set LVS_OWNERDATA after creation */
3039 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
3043 hwnd
= create_listview_control(LVS_REPORT
);
3044 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3045 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3046 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
3048 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3050 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
3051 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
3052 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
3053 "try to switch to LVS_OWNERDATA seq", FALSE
);
3055 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3056 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
3057 DestroyWindow(hwnd
);
3060 /* try to set LVS_OWNERDATA after creation just having it */
3061 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3062 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3063 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3064 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
3066 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3068 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
3069 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
3070 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
3071 "try to switch to LVS_OWNERDATA seq", FALSE
);
3072 DestroyWindow(hwnd
);
3074 /* try to remove LVS_OWNERDATA after creation just having it */
3077 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
3081 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3082 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3083 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3084 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
3086 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3088 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
3089 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
3090 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
3091 "try to switch to LVS_OWNERDATA seq", FALSE
);
3092 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3093 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
3094 DestroyWindow(hwnd
);
3097 /* try select an item */
3098 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3099 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3100 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3102 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
3104 memset(&item
, 0, sizeof(item
));
3105 item
.stateMask
= LVIS_SELECTED
;
3106 item
.state
= LVIS_SELECTED
;
3107 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3109 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
3111 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3113 DestroyWindow(hwnd
);
3115 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
3116 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3117 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3118 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3120 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3122 memset(&item
, 0, sizeof(item
));
3123 item
.mask
= LVIF_STATE
;
3125 item
.stateMask
= LVIS_SELECTED
;
3126 item
.state
= LVIS_SELECTED
;
3127 res
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3129 memset(&item
, 0, sizeof(item
));
3130 item
.pszText
= test_str
;
3131 res
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3133 DestroyWindow(hwnd
);
3135 /* check notifications after focused/selected changed */
3136 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3137 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3138 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
3141 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3143 memset(&item
, 0, sizeof(item
));
3144 item
.stateMask
= LVIS_SELECTED
;
3145 item
.state
= LVIS_SELECTED
;
3146 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3149 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
3150 "ownerdata select notification", TRUE
);
3152 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3154 memset(&item
, 0, sizeof(item
));
3155 item
.stateMask
= LVIS_FOCUSED
;
3156 item
.state
= LVIS_FOCUSED
;
3157 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3160 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
3161 "ownerdata focus notification", TRUE
);
3163 /* select all, check notifications */
3164 item
.stateMask
= LVIS_SELECTED
;
3166 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3169 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3171 item
.stateMask
= LVIS_SELECTED
;
3172 item
.state
= LVIS_SELECTED
;
3174 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3175 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3177 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3178 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3179 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3180 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3181 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3182 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3183 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3185 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3186 "ownerdata select all notification", FALSE
);
3188 /* select all again, note that all items are selected already */
3189 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3190 item
.stateMask
= LVIS_SELECTED
;
3191 item
.state
= LVIS_SELECTED
;
3193 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3194 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3196 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3197 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3198 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3199 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3200 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3201 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3202 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3204 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3205 "ownerdata select all notification", FALSE
);
3208 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3209 item
.stateMask
= LVIS_SELECTED
;
3212 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3213 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3215 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3216 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3217 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3218 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3219 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3220 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3221 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3223 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3224 "ownerdata deselect all notification", TRUE
);
3226 /* nothing selected, deselect all again */
3227 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3228 item
.stateMask
= LVIS_SELECTED
;
3231 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3234 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "ownerdata deselect all notification", FALSE
);
3236 /* select one, then deselect all */
3237 item
.stateMask
= LVIS_SELECTED
;
3238 item
.state
= LVIS_SELECTED
;
3239 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3241 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3242 item
.stateMask
= LVIS_SELECTED
;
3245 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3246 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3248 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3249 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3250 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3251 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3252 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3253 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3254 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3256 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3257 "ownerdata select all notification", TRUE
);
3259 /* remove focused, try to focus all */
3260 item
.stateMask
= LVIS_FOCUSED
;
3261 item
.state
= LVIS_FOCUSED
;
3262 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3264 item
.stateMask
= LVIS_FOCUSED
;
3266 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3268 item
.stateMask
= LVIS_FOCUSED
;
3269 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
3272 /* setting all to focused returns failure value */
3273 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3274 item
.stateMask
= LVIS_FOCUSED
;
3275 item
.state
= LVIS_FOCUSED
;
3277 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3280 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3281 "ownerdata focus all notification", FALSE
);
3283 /* focus single item, remove all */
3284 item
.stateMask
= LVIS_FOCUSED
;
3285 item
.state
= LVIS_FOCUSED
;
3286 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3288 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3289 item
.stateMask
= LVIS_FOCUSED
;
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
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3298 ok(g_nmlistview
.uOldState
== LVIS_FOCUSED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3299 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3300 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3301 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3303 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
3304 "ownerdata remove focus all notification", TRUE
);
3307 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3308 item
.stateMask
= LVIS_CUT
;
3309 item
.state
= LVIS_CUT
;
3311 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3312 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3314 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3315 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3316 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3317 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3318 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3319 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3320 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3322 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3323 "ownerdata cut all notification", FALSE
);
3325 /* all marked cut, try again */
3326 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3327 item
.stateMask
= LVIS_CUT
;
3328 item
.state
= LVIS_CUT
;
3330 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3331 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3333 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3334 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3335 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3336 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3337 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3338 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3339 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3341 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3342 "ownerdata cut all notification #2", FALSE
);
3344 DestroyWindow(hwnd
);
3346 /* check notifications on LVM_GETITEM */
3347 /* zero callback mask */
3348 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3349 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3350 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3353 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3355 memset(&item
, 0, sizeof(item
));
3356 item
.stateMask
= LVIS_SELECTED
;
3357 item
.mask
= LVIF_STATE
;
3358 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3361 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3362 "ownerdata getitem selected state 1", FALSE
);
3364 /* non zero callback mask but not we asking for */
3365 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
3368 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3370 memset(&item
, 0, sizeof(item
));
3371 item
.stateMask
= LVIS_SELECTED
;
3372 item
.mask
= LVIF_STATE
;
3373 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3376 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3377 "ownerdata getitem selected state 2", FALSE
);
3379 /* LVIS_OVERLAYMASK callback mask, asking for index */
3380 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3382 memset(&item
, 0, sizeof(item
));
3383 item
.stateMask
= LVIS_OVERLAYMASK
;
3384 item
.mask
= LVIF_STATE
;
3385 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3388 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3389 "ownerdata getitem selected state 2", FALSE
);
3391 DestroyWindow(hwnd
);
3393 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3394 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
| LVS_REPORT
);
3395 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3396 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3397 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3398 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3399 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
3400 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3401 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
3402 DestroyWindow(hwnd
);
3403 /* apparently it's allowed to switch these style on after creation */
3404 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3405 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3406 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3407 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3408 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
3409 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3410 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3411 DestroyWindow(hwnd
);
3413 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3414 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3415 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3416 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3417 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
3418 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3419 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
3420 DestroyWindow(hwnd
);
3423 static void test_norecompute(void)
3425 static CHAR testA
[] = "test";
3431 /* self containing control */
3432 hwnd
= create_listview_control(LVS_REPORT
);
3433 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3434 memset(&item
, 0, sizeof(item
));
3435 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
3437 item
.stateMask
= LVIS_SELECTED
;
3438 item
.state
= LVIS_SELECTED
;
3439 item
.pszText
= testA
;
3440 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3442 /* retrieve with LVIF_NORECOMPUTE */
3443 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3445 item
.pszText
= buff
;
3446 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3447 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3449 ok(lstrcmpA(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
3451 item
.mask
= LVIF_TEXT
;
3453 item
.pszText
= LPSTR_TEXTCALLBACKA
;
3454 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3457 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3459 item
.pszText
= buff
;
3460 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3462 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3463 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3465 ok(item
.pszText
== LPSTR_TEXTCALLBACKA
, "Expected (%p), got (%p)\n",
3466 LPSTR_TEXTCALLBACKA
, (VOID
*)item
.pszText
);
3467 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
3469 DestroyWindow(hwnd
);
3472 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3473 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3475 item
.mask
= LVIF_STATE
;
3476 item
.stateMask
= LVIS_SELECTED
;
3477 item
.state
= LVIS_SELECTED
;
3479 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3482 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3484 item
.pszText
= buff
;
3485 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3486 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3487 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3489 ok(item
.pszText
== LPSTR_TEXTCALLBACKA
, "Expected (%p), got (%p)\n",
3490 LPSTR_TEXTCALLBACKA
, (VOID
*)item
.pszText
);
3491 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
3493 DestroyWindow(hwnd
);
3496 static void test_nosortheader(void)
3501 hwnd
= create_listview_control(LVS_REPORT
);
3502 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3504 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3505 ok(IsWindow(header
), "header expected\n");
3507 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3508 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
3510 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3511 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
3512 /* HDS_BUTTONS retained */
3513 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3514 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
3516 DestroyWindow(hwnd
);
3518 /* create with LVS_NOSORTHEADER */
3519 hwnd
= create_listview_control(LVS_NOSORTHEADER
| LVS_REPORT
);
3520 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3522 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3523 ok(IsWindow(header
), "header expected\n");
3525 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3526 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3528 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3529 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
3530 /* not changed here */
3531 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3532 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3534 DestroyWindow(hwnd
);
3537 static void test_setredraw(void)
3545 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3546 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3548 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3549 ListView seems to handle it internally without DefWinProc */
3551 /* default value first */
3552 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3555 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3556 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3557 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3559 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3560 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3561 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3564 /* check update rect after redrawing */
3565 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3567 InvalidateRect(hwnd
, NULL
, FALSE
);
3568 RedrawWindow(hwnd
, NULL
, NULL
, RDW_UPDATENOW
);
3569 rect
.right
= rect
.bottom
= 1;
3570 GetUpdateRect(hwnd
, &rect
, FALSE
);
3571 expect(0, rect
.right
);
3572 expect(0, rect
.bottom
);
3575 hdc
= GetWindowDC(hwndparent
);
3576 ret
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3578 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3580 ret
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3582 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3584 ReleaseDC(hwndparent
, hdc
);
3586 /* check notification messages to show that repainting is disabled */
3587 ret
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3589 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3591 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3593 InvalidateRect(hwnd
, NULL
, TRUE
);
3595 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3596 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
3598 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
3600 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3601 InvalidateRect(hwnd
, NULL
, TRUE
);
3603 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3604 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
3606 /* message isn't forwarded to header */
3607 subclass_header(hwnd
);
3608 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3609 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3611 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
3612 "WM_SETREDRAW: not forwarded to header", FALSE
);
3614 DestroyWindow(hwnd
);
3617 static void test_hittest(void)
3623 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3627 HIMAGELIST himl
, himl2
;
3630 hwnd
= create_listview_control(LVS_REPORT
);
3631 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3633 /* LVS_REPORT with a single subitem (2 columns) */
3634 insert_column(hwnd
, 0);
3635 insert_column(hwnd
, 1);
3636 insert_item(hwnd
, 0);
3639 /* the only purpose of that line is to be as long as a half item rect */
3640 item
.pszText
= text
;
3641 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3644 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3646 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3649 memset(&bounds
, 0, sizeof(bounds
));
3650 bounds
.left
= LVIR_BOUNDS
;
3651 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
3653 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
3654 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
3655 r
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, TRUE
, 0);
3657 ok(bounds
.bottom
- bounds
.top
== vert
,
3658 "Vertical spacing inconsistent (%d != %d)\n", bounds
.bottom
- bounds
.top
, vert
);
3659 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
3662 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3664 /* outside columns by x position - valid is [0, 199] */
3666 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3667 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TOLEFT
, 0, FALSE
, FALSE
);
3668 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3670 x
= pos
.x
+ 50; /* column half width */
3671 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3672 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, 0, FALSE
, FALSE
);
3673 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3674 x
= pos
.x
+ 150; /* outside column */
3675 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3676 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3677 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3678 y
= (bounds
.bottom
- bounds
.top
) / 2;
3679 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3680 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3681 /* outside possible client rectangle (to right) */
3683 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3684 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3685 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3686 y
= (bounds
.bottom
- bounds
.top
) / 2;
3687 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3688 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3689 /* subitem returned with -1 item too */
3691 y
= bounds
.top
- vert
;
3692 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3693 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3694 /* return values appear to underflow with negative indices */
3698 test_lvm_subitemhittest(hwnd
, x
, y
, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3699 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3703 /* parent client area is 100x100 by default */
3704 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
3705 x
= pos
.x
+ 150; /* outside column */
3706 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3707 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, FALSE
);
3708 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3709 y
= (bounds
.bottom
- bounds
.top
) / 2;
3710 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, TRUE
);
3711 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3712 /* the same with LVS_EX_FULLROWSELECT */
3713 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3714 x
= pos
.x
+ 150; /* outside column */
3715 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3716 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, LVHT_ONITEMLABEL
, FALSE
, FALSE
);
3717 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3718 y
= (bounds
.bottom
- bounds
.top
) / 2;
3719 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3720 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
3721 x
= pos
.x
+ 150; /* outside column */
3722 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3723 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3724 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3725 y
= (bounds
.bottom
- bounds
.top
) / 2;
3726 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3727 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3728 /* outside possible client rectangle (to right) */
3730 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3731 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3732 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3733 y
= (bounds
.bottom
- bounds
.top
) / 2;
3734 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3735 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3736 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3737 himl
= ImageList_Create(16, 16, 0, 4, 4);
3738 ok(himl
!= NULL
, "failed to create imagelist\n");
3739 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3740 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3741 r
= ImageList_Add(himl
, hbmp
, 0);
3742 ok(r
== 0, "should be zero\n");
3743 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3744 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3745 r
= ImageList_Add(himl
, hbmp
, 0);
3746 ok(r
== 1, "should be one\n");
3748 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3751 item
.mask
= LVIF_IMAGE
;
3755 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3759 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3760 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3761 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3762 y
= (bounds
.bottom
- bounds
.top
) / 2;
3763 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3765 /* state icons indices are 1 based, check with valid index */
3766 item
.mask
= LVIF_STATE
;
3767 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3768 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3771 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3775 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3776 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3777 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3778 y
= (bounds
.bottom
- bounds
.top
) / 2;
3779 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3781 himl2
= (HIMAGELIST
)SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3782 ok(himl2
== himl
, "should return handle\n");
3784 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3788 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3789 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, 0, FALSE
, FALSE
);
3790 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3791 y
= (bounds
.bottom
- bounds
.top
) / 2;
3792 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3794 DestroyWindow(hwnd
);
3797 static void test_getviewrect(void)
3804 hwnd
= create_listview_control(LVS_REPORT
);
3805 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3808 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3811 insert_column(hwnd
, 0);
3812 insert_column(hwnd
, 1);
3814 memset(&item
, 0, sizeof(item
));
3817 SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3819 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3821 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3824 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3825 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3827 /* left is set to (2e31-1) - XP SP2 */
3828 expect(0, rect
.right
);
3829 expect(0, rect
.top
);
3830 expect(0, rect
.bottom
);
3832 /* switch to LVS_ICON */
3833 SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3835 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3836 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3838 expect(0, rect
.left
);
3839 expect(0, rect
.top
);
3840 /* precise value differs for 2k, XP and Vista */
3841 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3842 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3844 DestroyWindow(hwnd
);
3847 static void test_getitemposition(void)
3854 hwnd
= create_listview_control(LVS_REPORT
);
3855 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3856 header
= subclass_header(hwnd
);
3858 /* LVS_REPORT, single item, no columns added */
3859 insert_item(hwnd
, 0);
3861 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3864 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3866 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3868 /* LVS_REPORT, single item, single column */
3869 insert_column(hwnd
, 0);
3871 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3874 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3876 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3878 memset(&rect
, 0, sizeof(rect
));
3879 SendMessageA(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3882 /* offset by header height */
3883 expect(rect
.bottom
- rect
.top
, pt
.y
);
3885 DestroyWindow(hwnd
);
3888 static void test_columnscreation(void)
3893 hwnd
= create_listview_control(LVS_REPORT
);
3894 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3896 insert_item(hwnd
, 0);
3898 /* headers columns aren't created automatically */
3899 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3900 ok(IsWindow(header
), "Expected header handle\n");
3901 r
= SendMessageA(header
, HDM_GETITEMCOUNT
, 0, 0);
3904 DestroyWindow(hwnd
);
3907 static void test_getitemrect(void)
3910 HIMAGELIST himl
, himl_ret
;
3920 /* rectangle isn't empty for empty text items */
3921 hwnd
= create_listview_control(LVS_LIST
);
3922 memset(&item
, 0, sizeof(item
));
3925 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3927 rect
.left
= LVIR_LABEL
;
3928 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3930 expect(0, rect
.left
);
3931 expect(0, rect
.top
);
3933 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, rect
.right
);
3934 ReleaseDC(hwnd
, hdc
);
3935 DestroyWindow(hwnd
);
3937 hwnd
= create_listview_control(LVS_REPORT
);
3938 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3941 memset(&item
, 0, sizeof(item
));
3944 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3947 rect
.left
= LVIR_BOUNDS
;
3948 rect
.right
= rect
.top
= rect
.bottom
= -1;
3949 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3952 /* zero width rectangle with no padding */
3953 expect(0, rect
.left
);
3954 expect(0, rect
.right
);
3956 insert_column(hwnd
, 0);
3957 insert_column(hwnd
, 1);
3959 col
.mask
= LVCF_WIDTH
;
3961 r
= SendMessageA(hwnd
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
3964 col
.mask
= LVCF_WIDTH
;
3966 r
= SendMessageA(hwnd
, LVM_SETCOLUMNA
, 1, (LPARAM
)&col
);
3969 rect
.left
= LVIR_BOUNDS
;
3970 rect
.right
= rect
.top
= rect
.bottom
= -1;
3971 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3974 /* still no left padding */
3975 expect(0, rect
.left
);
3976 expect(150, rect
.right
);
3978 rect
.left
= LVIR_SELECTBOUNDS
;
3979 rect
.right
= rect
.top
= rect
.bottom
= -1;
3980 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3983 expect(2, rect
.left
);
3985 rect
.left
= LVIR_LABEL
;
3986 rect
.right
= rect
.top
= rect
.bottom
= -1;
3987 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3989 /* padding, column width */
3990 expect(2, rect
.left
);
3991 expect(50, rect
.right
);
3993 /* no icons attached */
3994 rect
.left
= LVIR_ICON
;
3995 rect
.right
= rect
.top
= rect
.bottom
= -1;
3996 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3999 expect(2, rect
.left
);
4000 expect(2, rect
.right
);
4003 order
[0] = 1; order
[1] = 0;
4004 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
4007 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
4009 /* 1 indexed column width + padding */
4011 /* rect is at zero too */
4012 rect
.left
= LVIR_BOUNDS
;
4013 rect
.right
= rect
.top
= rect
.bottom
= -1;
4014 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4016 expect(0, rect
.left
);
4017 /* just width sum */
4018 expect(150, rect
.right
);
4020 rect
.left
= LVIR_SELECTBOUNDS
;
4021 rect
.right
= rect
.top
= rect
.bottom
= -1;
4022 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4024 /* column width + padding */
4025 expect(102, rect
.left
);
4027 /* back to initial order */
4028 order
[0] = 0; order
[1] = 1;
4029 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
4033 himl
= ImageList_Create(16, 16, 0, 2, 2);
4034 ok(himl
!= NULL
, "failed to create imagelist\n");
4035 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
4036 ok(hbm
!= NULL
, "failed to create bitmap\n");
4037 r
= ImageList_Add(himl
, hbm
, 0);
4039 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
4040 ok(hbm
!= NULL
, "failed to create bitmap\n");
4041 r
= ImageList_Add(himl
, hbm
, 0);
4044 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
4047 item
.mask
= LVIF_STATE
;
4048 item
.state
= INDEXTOSTATEIMAGEMASK(1);
4049 item
.stateMask
= LVIS_STATEIMAGEMASK
;
4052 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
4056 rect
.left
= LVIR_ICON
;
4057 rect
.right
= rect
.top
= rect
.bottom
= -1;
4058 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4060 /* padding + stateicon width */
4061 expect(18, rect
.left
);
4062 expect(18, rect
.right
);
4064 rect
.left
= LVIR_LABEL
;
4065 rect
.right
= rect
.top
= rect
.bottom
= -1;
4066 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4068 /* padding + stateicon width -> column width */
4069 expect(18, rect
.left
);
4070 expect(50, rect
.right
);
4072 himl_ret
= (HIMAGELIST
)SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
4073 ok(himl_ret
== himl
, "got %p, expected %p\n", himl_ret
, himl
);
4075 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
4078 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
4081 item
.stateMask
= ~0;
4084 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
4088 rect
.left
= LVIR_ICON
;
4089 rect
.right
= rect
.top
= rect
.bottom
= -1;
4090 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4092 /* padding, icon width */
4093 expect(2, rect
.left
);
4094 expect(18, rect
.right
);
4096 rect
.left
= LVIR_LABEL
;
4097 rect
.right
= rect
.top
= rect
.bottom
= -1;
4098 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4100 /* padding + icon width -> column width */
4101 expect(18, rect
.left
);
4102 expect(50, rect
.right
);
4105 rect
.left
= LVIR_SELECTBOUNDS
;
4106 rect
.right
= rect
.top
= rect
.bottom
= -1;
4107 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4109 /* padding, column width */
4110 expect(2, rect
.left
);
4111 expect(50, rect
.right
);
4113 /* try with indentation */
4114 item
.mask
= LVIF_INDENT
;
4118 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
4122 rect
.left
= LVIR_BOUNDS
;
4123 rect
.right
= rect
.top
= rect
.bottom
= -1;
4124 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4126 /* padding + 1 icon width, column width */
4127 expect(0, rect
.left
);
4128 expect(150, rect
.right
);
4131 rect
.left
= LVIR_SELECTBOUNDS
;
4132 rect
.right
= rect
.top
= rect
.bottom
= -1;
4133 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4135 /* padding + 1 icon width, column width */
4136 expect(2 + 16, rect
.left
);
4137 expect(50, rect
.right
);
4140 rect
.left
= LVIR_LABEL
;
4141 rect
.right
= rect
.top
= rect
.bottom
= -1;
4142 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4144 /* padding + 2 icon widths, column width */
4145 expect(2 + 16*2, rect
.left
);
4146 expect(50, rect
.right
);
4149 rect
.left
= LVIR_ICON
;
4150 rect
.right
= rect
.top
= rect
.bottom
= -1;
4151 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4153 /* padding + 1 icon width indentation, icon width */
4154 expect(2 + 16, rect
.left
);
4155 expect(34, rect
.right
);
4157 DestroyWindow(hwnd
);
4160 static void test_editbox(void)
4162 static CHAR testitemA
[] = "testitem";
4163 static CHAR testitem1A
[] = "testitem_quitelongname";
4164 static CHAR testitem2A
[] = "testITEM_quitelongname";
4165 static CHAR buffer
[25];
4166 HWND hwnd
, hwndedit
, hwndedit2
, header
;
4170 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4171 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4173 insert_column(hwnd
, 0);
4175 memset(&item
, 0, sizeof(item
));
4176 item
.mask
= LVIF_TEXT
;
4177 item
.pszText
= testitemA
;
4180 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4183 /* test notifications without edit created */
4184 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4185 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)0xdeadbeef);
4187 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4188 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE
);
4189 /* same thing but with valid window */
4190 hwndedit
= CreateWindowA("Edit", "Test edit", WS_VISIBLE
| WS_CHILD
, 0, 0, 20,
4191 10, hwnd
, (HMENU
)1, (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
), 0);
4192 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4193 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)hwndedit
);
4195 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4196 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE
);
4197 DestroyWindow(hwndedit
);
4199 /* setting focus is necessary */
4201 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4202 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4204 /* test children Z-order after Edit box created */
4205 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4206 ok(IsWindow(header
), "Expected header to be created\n");
4207 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4208 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4210 /* modify initial string */
4211 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4214 /* edit window is resized and repositioned,
4215 check again for Z-order - it should be preserved */
4216 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4217 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4219 /* return focus to listview */
4222 memset(&item
, 0, sizeof(item
));
4223 item
.mask
= LVIF_TEXT
;
4224 item
.pszText
= buffer
;
4225 item
.cchTextMax
= sizeof(buffer
);
4228 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
4231 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4233 /* send LVM_EDITLABEL on already created edit */
4235 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4236 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4237 /* focus will be set to edit */
4238 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
4239 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4240 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
4242 /* creating label disabled when control isn't focused */
4244 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4245 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4247 /* check EN_KILLFOCUS handling */
4248 memset(&item
, 0, sizeof(item
));
4249 item
.pszText
= testitemA
;
4252 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
4256 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4257 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4258 /* modify edit and notify control that it lost focus */
4259 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4261 g_editbox_disp_info
.item
.pszText
= NULL
;
4262 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4264 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "expected notification with not null text\n");
4266 memset(&item
, 0, sizeof(item
));
4267 item
.pszText
= buffer
;
4268 item
.cchTextMax
= sizeof(buffer
);
4271 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4272 expect(lstrlenA(item
.pszText
), r
);
4273 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4274 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4276 /* change item name to differ in casing only */
4278 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4279 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4280 /* modify edit and notify control that it lost focus */
4281 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem2A
);
4283 g_editbox_disp_info
.item
.pszText
= NULL
;
4284 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4286 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "got %p\n", g_editbox_disp_info
.item
.pszText
);
4288 memset(&item
, 0, sizeof(item
));
4289 item
.pszText
= buffer
;
4290 item
.cchTextMax
= sizeof(buffer
);
4293 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4294 expect(lstrlenA(item
.pszText
), r
);
4295 ok(strcmp(buffer
, testitem2A
) == 0, "got %s, expected %s\n", buffer
, testitem2A
);
4296 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4298 /* end edit without saving */
4300 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4301 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4302 r
= SendMessageA(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
4304 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4305 "edit box - end edit, no change, escape", TRUE
);
4306 /* end edit with saving */
4308 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4309 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4310 r
= SendMessageA(hwndedit
, WM_KEYDOWN
, VK_RETURN
, 0);
4312 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4313 "edit box - end edit, no change, return", TRUE
);
4315 memset(&item
, 0, sizeof(item
));
4316 item
.pszText
= buffer
;
4317 item
.cchTextMax
= sizeof(buffer
);
4320 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4321 expect(lstrlenA(item
.pszText
), r
);
4322 ok(strcmp(buffer
, testitem2A
) == 0, "Expected item text to change\n");
4324 /* LVM_EDITLABEL with -1 destroys current edit */
4325 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
4326 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4327 /* no edit present */
4328 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -1, 0);
4329 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4330 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4331 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4333 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4334 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -1, 0);
4335 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4336 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4337 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4338 /* check another negative value */
4339 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4340 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4341 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4342 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -2, 0);
4343 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4344 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4345 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4346 /* and value greater than max item index */
4347 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4348 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4349 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4350 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
4351 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, r
, 0);
4352 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4353 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4354 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4356 /* messaging tests */
4358 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4360 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4361 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4362 /* testing only sizing messages */
4363 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
4364 "edit box create - sizing", FALSE
);
4366 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4368 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4369 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4370 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4371 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4373 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4374 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE
);
4376 DestroyWindow(hwnd
);
4379 static void test_notifyformat(void)
4384 hwnd
= create_listview_control(LVS_REPORT
);
4385 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4387 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4388 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4389 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4391 SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4393 r
= SendMessageA(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
4395 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4398 r
= SendMessageA(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
4400 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4405 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4406 DestroyWindow(hwnd
);
4410 DestroyWindow(hwnd
);
4412 /* test failure in parent WM_NOTIFYFORMAT */
4414 hwnd
= create_listview_control(LVS_REPORT
);
4415 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4416 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4417 ok(IsWindow(header
), "expected header to be created\n");
4418 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4420 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4421 ok( r
== 1, "Expected 1, got %d\n", r
);
4422 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4423 ok(r
!= 0, "Expected valid format\n");
4425 notifyFormat
= NFR_UNICODE
;
4426 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4427 expect(NFR_UNICODE
, r
);
4428 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4430 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4431 ok( r
== 1, "Expected 1, got %d\n", r
);
4433 notifyFormat
= NFR_ANSI
;
4434 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4435 expect(NFR_ANSI
, r
);
4436 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4438 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4439 ok( r
== 1, "Expected 1, got %d\n", r
);
4441 DestroyWindow(hwnd
);
4443 hwndparentW
= create_parent_window(TRUE
);
4444 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
4445 if (!IsWindow(hwndparentW
)) return;
4448 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4449 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4450 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4451 ok(IsWindow(header
), "expected header to be created\n");
4452 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4454 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4456 DestroyWindow(hwnd
);
4457 /* receiving error code defaulting to ansi */
4459 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4460 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4461 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4462 ok(IsWindow(header
), "expected header to be created\n");
4463 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4465 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4467 DestroyWindow(hwnd
);
4468 /* receiving ansi code from unicode window, use it */
4469 notifyFormat
= NFR_ANSI
;
4470 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4471 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4472 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4473 ok(IsWindow(header
), "expected header to be created\n");
4474 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4476 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4478 DestroyWindow(hwnd
);
4479 /* unicode listview with ansi parent window */
4481 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4482 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4483 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4484 ok(IsWindow(header
), "expected header to be created\n");
4485 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4487 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4489 DestroyWindow(hwnd
);
4490 /* unicode listview with ansi parent window, return error code */
4492 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4493 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4494 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4495 ok(IsWindow(header
), "expected header to be created\n");
4496 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4498 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4500 DestroyWindow(hwnd
);
4502 DestroyWindow(hwndparentW
);
4505 static void test_indentation(void)
4511 hwnd
= create_listview_control(LVS_REPORT
);
4512 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4514 memset(&item
, 0, sizeof(item
));
4515 item
.mask
= LVIF_INDENT
;
4517 item
.iIndent
= I_INDENTCALLBACK
;
4518 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4521 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4524 item
.mask
= LVIF_INDENT
;
4525 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
4528 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
4529 "get indent dispinfo", FALSE
);
4531 DestroyWindow(hwnd
);
4534 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
4539 static BOOL
is_below_comctl_5(void)
4544 hwnd
= create_listview_control(LVS_REPORT
);
4545 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4546 insert_item(hwnd
, 0);
4548 ret
= SendMessageA(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
4550 DestroyWindow(hwnd
);
4555 static void test_get_set_view(void)
4561 /* test style->view mapping */
4562 hwnd
= create_listview_control(LVS_REPORT
);
4563 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4565 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4566 expect(LV_VIEW_DETAILS
, ret
);
4568 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4570 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
4571 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4572 expect(LV_VIEW_ICON
, ret
);
4574 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4575 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
4576 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4577 expect(LV_VIEW_SMALLICON
, ret
);
4579 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4580 SetWindowLongPtrA(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
4581 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4582 expect(LV_VIEW_LIST
, ret
);
4584 /* switching view doesn't touch window style */
4585 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
4587 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4588 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4589 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
4591 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4592 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4593 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
4595 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4596 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4598 /* now change window style to see if view is remapped */
4599 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4600 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SHOWSELALWAYS
);
4601 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4602 expect(LV_VIEW_SMALLICON
, ret
);
4604 DestroyWindow(hwnd
);
4607 static void test_canceleditlabel(void)
4609 HWND hwnd
, hwndedit
;
4613 static CHAR test
[] = "test";
4614 static const CHAR test1
[] = "test1";
4616 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4617 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4619 insert_item(hwnd
, 0);
4621 /* try without edit created */
4622 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4623 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4625 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4626 "cancel edit label without edit", FALSE
);
4628 /* cancel without data change */
4630 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4631 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4632 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4634 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4636 /* cancel after data change */
4637 memset(&itema
, 0, sizeof(itema
));
4638 itema
.pszText
= test
;
4639 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&itema
);
4642 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4643 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4644 ret
= SetWindowTextA(hwndedit
, test1
);
4646 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4648 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4649 memset(&itema
, 0, sizeof(itema
));
4650 itema
.pszText
= buff
;
4651 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
4652 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&itema
);
4654 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
4656 DestroyWindow(hwnd
);
4659 static void test_mapidindex(void)
4664 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4665 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
4666 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4667 insert_item(hwnd
, 0);
4668 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4670 DestroyWindow(hwnd
);
4672 hwnd
= create_listview_control(LVS_REPORT
);
4673 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4675 /* LVM_MAPINDEXTOID with invalid index */
4676 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4679 insert_item(hwnd
, 0);
4680 insert_item(hwnd
, 1);
4682 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
4684 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
4687 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4689 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4691 /* remove 0 indexed item, id retained */
4692 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
4693 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4695 /* new id starts from previous value */
4696 insert_item(hwnd
, 1);
4697 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4700 /* get index by id */
4701 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
4703 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
4705 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
4707 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
4710 DestroyWindow(hwnd
);
4713 static void test_getitemspacing(void)
4718 HIMAGELIST himl40
, himl80
;
4720 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
4721 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
4724 hwnd
= create_listview_control(LVS_ICON
);
4725 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4726 expect(cx
, LOWORD(ret
));
4727 expect(cy
, HIWORD(ret
));
4729 /* now try with icons */
4730 himl40
= ImageList_Create(40, 40, 0, 4, 4);
4731 ok(himl40
!= NULL
, "failed to create imagelist\n");
4732 himl80
= ImageList_Create(80, 80, 0, 4, 4);
4733 ok(himl80
!= NULL
, "failed to create imagelist\n");
4734 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4737 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4738 /* spacing + icon size returned */
4739 expect(cx
+ 40, LOWORD(ret
));
4740 expect(cy
+ 40, HIWORD(ret
));
4741 /* try changing icon size */
4742 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl80
);
4744 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4745 /* spacing + icon size returned */
4746 expect(cx
+ 80, LOWORD(ret
));
4747 expect(cy
+ 80, HIWORD(ret
));
4749 /* set own icon spacing */
4750 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(100, 100));
4751 expect(cx
+ 80, LOWORD(ret
));
4752 expect(cy
+ 80, HIWORD(ret
));
4754 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4755 /* set size returned */
4756 expect(100, LOWORD(ret
));
4757 expect(100, HIWORD(ret
));
4759 /* now change image list - icon spacing should be unaffected */
4760 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4762 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4763 /* set size returned */
4764 expect(100, LOWORD(ret
));
4765 expect(100, HIWORD(ret
));
4767 /* spacing = 0 - keep previous value */
4768 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(0, -1));
4769 expect(100, LOWORD(ret
));
4770 expect(100, HIWORD(ret
));
4772 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4773 expect(100, LOWORD(ret
));
4775 expect(0xFFFF, HIWORD(ret
));
4777 if (sizeof(void*) == 8)
4779 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4780 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, (DWORD
)-1);
4781 expect(100, LOWORD(ret
));
4782 expect(0xFFFF, HIWORD(ret
));
4784 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, -1);
4785 expect(0xFFFF, LOWORD(ret
));
4786 expect(0xFFFF, HIWORD(ret
));
4790 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, -1);
4791 expect(100, LOWORD(ret
));
4792 expect(0xFFFF, HIWORD(ret
));
4794 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4795 /* spacing + icon size returned */
4796 expect(cx
+ 40, LOWORD(ret
));
4797 expect(cy
+ 40, HIWORD(ret
));
4799 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, 0);
4800 ImageList_Destroy(himl80
);
4801 DestroyWindow(hwnd
);
4803 hwnd
= create_listview_control(LVS_SMALLICON
);
4804 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4805 expect(cx
, LOWORD(ret
));
4806 expect(cy
, HIWORD(ret
));
4808 /* spacing does not depend on selected view type */
4809 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4812 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4813 /* spacing + icon size returned */
4814 expect(cx
+ 40, LOWORD(ret
));
4815 expect(cy
+ 40, HIWORD(ret
));
4817 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, 0);
4818 ImageList_Destroy(himl40
);
4819 DestroyWindow(hwnd
);
4821 hwnd
= create_listview_control(LVS_REPORT
);
4822 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4823 expect(cx
, LOWORD(ret
));
4824 expect(cy
, HIWORD(ret
));
4826 DestroyWindow(hwnd
);
4828 hwnd
= create_listview_control(LVS_LIST
);
4829 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4830 expect(cx
, LOWORD(ret
));
4831 expect(cy
, HIWORD(ret
));
4833 DestroyWindow(hwnd
);
4836 static void test_getcolumnwidth(void)
4845 /* default column width */
4846 hwnd
= create_listview_control(LVS_ICON
);
4847 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4849 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4850 SetWindowLongA(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
4851 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4852 todo_wine
expect(8, ret
);
4853 style
= GetWindowLongA(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
4854 SetWindowLongA(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
4856 ret
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4858 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4860 DestroyWindow(hwnd
);
4862 /* default column width with item added */
4863 hwnd
= create_listview_control(LVS_LIST
);
4864 memset(&itema
, 0, sizeof(itema
));
4865 SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4866 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4868 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, ret
);
4869 ReleaseDC(hwnd
, hdc
);
4870 DestroyWindow(hwnd
);
4873 static void test_scrollnotify(void)
4878 hwnd
= create_listview_control(LVS_REPORT
);
4880 insert_column(hwnd
, 0);
4881 insert_column(hwnd
, 1);
4882 insert_item(hwnd
, 0);
4884 /* make it scrollable - resize */
4885 ret
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
4887 ret
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
4890 /* try with dummy call */
4891 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4892 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 0, 0);
4894 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4895 "scroll notify 1", TRUE
);
4897 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4898 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 1, 0);
4900 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4901 "scroll notify 2", TRUE
);
4903 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4904 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 1, 1);
4906 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4907 "scroll notify 3", TRUE
);
4909 DestroyWindow(hwnd
);
4912 static void test_LVS_EX_TRANSPARENTBKGND(void)
4918 hwnd
= create_listview_control(LVS_REPORT
);
4920 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4923 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4924 LVS_EX_TRANSPARENTBKGND
);
4926 ret
= SendMessageA(hwnd
, LVM_GETBKCOLOR
, 0, 0);
4927 if (ret
!= CLR_NONE
)
4929 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4930 DestroyWindow(hwnd
);
4934 /* try to set some back color and check this style bit */
4935 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4937 ret
= SendMessageA(hwnd
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
4938 ok(!(ret
& LVS_EX_TRANSPARENTBKGND
), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4940 /* now test what this style actually does */
4941 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4942 LVS_EX_TRANSPARENTBKGND
);
4944 hdc
= GetWindowDC(hwndparent
);
4946 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4947 SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
4948 ok_sequence(sequences
, PARENT_SEQ_INDEX
, lvs_ex_transparentbkgnd_seq
,
4949 "LVS_EX_TRANSPARENTBKGND parent", FALSE
);
4951 ReleaseDC(hwndparent
, hdc
);
4953 DestroyWindow(hwnd
);
4956 static void test_approximate_viewrect(void)
4963 static CHAR test
[] = "abracadabra, a very long item label";
4965 hwnd
= create_listview_control(LVS_ICON
);
4966 himl
= ImageList_Create(40, 40, 0, 4, 4);
4967 ok(himl
!= NULL
, "failed to create imagelist\n");
4968 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4969 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4970 ret
= ImageList_Add(himl
, hbmp
, 0);
4972 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4975 itema
.mask
= LVIF_IMAGE
;
4979 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4982 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(75, 75));
4986 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4990 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4991 expect(MAKELONG(77,827), ret
);
4993 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(50, 50));
4994 ok(ret
!= 0, "got 0\n");
4996 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4997 expect(MAKELONG(102,302), ret
);
4999 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
5000 expect(MAKELONG(52,52), ret
);
5002 itema
.pszText
= test
;
5003 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&itema
);
5005 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
5006 expect(MAKELONG(52,52), ret
);
5008 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 0, MAKELPARAM(100,100));
5009 expect(MAKELONG(52,2), ret
);
5010 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 1, MAKELPARAM(100,100));
5011 expect(MAKELONG(52,52), ret
);
5012 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 2, MAKELPARAM(100,100));
5013 expect(MAKELONG(102,52), ret
);
5014 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 3, MAKELPARAM(100,100));
5015 expect(MAKELONG(102,102), ret
);
5016 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 4, MAKELPARAM(100,100));
5017 expect(MAKELONG(102,102), ret
);
5018 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 5, MAKELPARAM(100,100));
5019 expect(MAKELONG(102,152), ret
);
5020 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 6, MAKELPARAM(100,100));
5021 expect(MAKELONG(102,152), ret
);
5022 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 7, MAKELPARAM(160,100));
5023 expect(MAKELONG(152,152), ret
);
5025 DestroyWindow(hwnd
);
5028 static void test_finditem(void)
5035 hwnd
= create_listview_control(LVS_REPORT
);
5036 insert_item(hwnd
, 0);
5038 memset(&fi
, 0, sizeof(fi
));
5040 /* full string search, inserted text was "foo" */
5042 fi
.flags
= LVFI_STRING
;
5044 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5046 /* partial string search, inserted text was "foo" */
5048 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
5050 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5052 /* partial string search, part after start char */
5054 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
5056 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5059 /* try with LVFI_SUBSTRING */
5061 fi
.flags
= LVFI_SUBSTRING
;
5063 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5066 win_skip("LVFI_SUBSTRING not supported\n");
5067 DestroyWindow(hwnd
);
5072 fi
.flags
= LVFI_SUBSTRING
;
5074 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5077 fi
.flags
= LVFI_SUBSTRING
;
5079 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5083 fi
.flags
= LVFI_SUBSTRING
| LVFI_STRING
;
5085 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
5088 DestroyWindow(hwnd
);
5091 static void test_LVS_EX_HEADERINALLVIEWS(void)
5096 hwnd
= create_listview_control(LVS_ICON
);
5098 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5099 LVS_EX_HEADERINALLVIEWS
);
5101 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5102 if (!IsWindow(header
))
5104 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
5105 DestroyWindow(hwnd
);
5109 /* LVS_NOCOLUMNHEADER works as before */
5110 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5111 SetWindowLongW(hwnd
, GWL_STYLE
, style
| LVS_NOCOLUMNHEADER
);
5112 style
= GetWindowLongA(header
, GWL_STYLE
);
5113 ok(style
& HDS_HIDDEN
, "Expected HDS_HIDDEN\n");
5114 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5115 SetWindowLongW(hwnd
, GWL_STYLE
, style
& ~LVS_NOCOLUMNHEADER
);
5116 style
= GetWindowLongA(header
, GWL_STYLE
);
5117 ok(!(style
& HDS_HIDDEN
), "Expected HDS_HIDDEN to be unset\n");
5119 /* try to remove style */
5120 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
, 0);
5121 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5122 ok(IsWindow(header
), "Expected header to be created\n");
5123 style
= GetWindowLongA(header
, GWL_STYLE
);
5124 ok(!(style
& HDS_HIDDEN
), "HDS_HIDDEN not expected\n");
5126 DestroyWindow(hwnd
);
5128 /* check other styles */
5129 hwnd
= create_listview_control(LVS_LIST
);
5130 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5131 LVS_EX_HEADERINALLVIEWS
);
5132 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5133 ok(IsWindow(header
), "Expected header to be created\n");
5134 DestroyWindow(hwnd
);
5136 hwnd
= create_listview_control(LVS_SMALLICON
);
5137 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5138 LVS_EX_HEADERINALLVIEWS
);
5139 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5140 ok(IsWindow(header
), "Expected header to be created\n");
5141 DestroyWindow(hwnd
);
5143 hwnd
= create_listview_control(LVS_REPORT
);
5144 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5145 LVS_EX_HEADERINALLVIEWS
);
5146 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5147 ok(IsWindow(header
), "Expected header to be created\n");
5148 DestroyWindow(hwnd
);
5151 static void test_hover(void)
5156 hwnd
= create_listview_control(LVS_ICON
);
5158 /* test WM_MOUSEHOVER forwarding */
5159 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5160 r
= SendMessageA(hwnd
, WM_MOUSEHOVER
, 0, 0);
5162 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER allow test", TRUE
);
5163 g_block_hover
= TRUE
;
5164 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5165 r
= SendMessageA(hwnd
, WM_MOUSEHOVER
, 0, 0);
5167 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER block test", TRUE
);
5168 g_block_hover
= FALSE
;
5170 r
= SendMessageA(hwnd
, LVM_SETHOVERTIME
, 0, 500);
5171 expect(HOVER_DEFAULT
, r
);
5172 r
= SendMessageA(hwnd
, LVM_GETHOVERTIME
, 0, 0);
5175 DestroyWindow(hwnd
);
5178 static void test_destroynotify(void)
5183 hwnd
= create_listview_control(LVS_REPORT
);
5184 ok(hwnd
!= NULL
, "failed to create listview window\n");
5186 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5187 DestroyWindow(hwnd
);
5188 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_destroy
, "check destroy order", FALSE
);
5190 /* same for ownerdata list */
5191 hwnd
= create_listview_control(LVS_REPORT
|LVS_OWNERDATA
);
5192 ok(hwnd
!= NULL
, "failed to create listview window\n");
5194 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5195 DestroyWindow(hwnd
);
5196 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_ownerdata_destroy
, "check destroy order, ownerdata", FALSE
);
5198 hwnd
= create_listview_control(LVS_REPORT
|LVS_OWNERDATA
);
5199 ok(hwnd
!= NULL
, "failed to create listview window\n");
5201 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5202 ret
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
5203 ok(ret
== TRUE
, "got %d\n", ret
);
5204 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_ownerdata_deleteall
, "deleteall ownerdata", FALSE
);
5205 DestroyWindow(hwnd
);
5208 static void test_header_notification(void)
5210 static char textA
[] = "newtext";
5218 list
= create_listview_control(LVS_REPORT
);
5219 ok(list
!= NULL
, "failed to create listview window\n");
5221 memset(&col
, 0, sizeof(col
));
5222 col
.mask
= LVCF_WIDTH
;
5224 ret
= SendMessageA(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5227 /* check list parent notification after header item changed,
5228 this test should be placed before header subclassing to avoid
5229 Listview -> Header messages to be logged */
5230 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5232 col
.mask
= LVCF_TEXT
;
5233 col
.pszText
= textA
;
5234 r
= SendMessageA(list
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
5237 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_changed_seq
,
5238 "header notify, listview", FALSE
);
5239 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5240 "header notify, parent", FALSE
);
5242 header
= subclass_header(list
);
5244 ret
= SendMessageA(header
, HDM_GETITEMCOUNT
, 0, 0);
5247 memset(&item
, 0, sizeof(item
));
5248 item
.mask
= HDI_WIDTH
;
5249 ret
= SendMessageA(header
, HDM_GETITEMA
, 0, (LPARAM
)&item
);
5251 expect(100, item
.cxy
);
5253 nmh
.hdr
.hwndFrom
= header
;
5254 nmh
.hdr
.idFrom
= GetWindowLongPtrA(header
, GWLP_ID
);
5255 nmh
.hdr
.code
= HDN_ITEMCHANGEDA
;
5258 item
.mask
= HDI_WIDTH
;
5261 ret
= SendMessageA(list
, WM_NOTIFY
, 0, (LPARAM
)&nmh
);
5264 DestroyWindow(list
);
5267 static void test_header_notification2(void)
5269 static char textA
[] = "newtext";
5276 struct message parent_header_notify_seq
[] = {
5277 { WM_NOTIFY
, sent
|id
, 0, 0, 0 },
5281 list
= create_listview_control(LVS_REPORT
);
5282 ok(list
!= NULL
, "failed to create listview window\n");
5284 memset(&col
, 0, sizeof(col
));
5285 col
.mask
= LVCF_WIDTH
| LVCF_TEXT
;
5287 col
.pszText
= textA
;
5288 ret
= SendMessageA(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5291 header
= (HWND
)SendMessageA(list
, LVM_GETHEADER
, 0, 0);
5292 ok(header
!= 0, "No header\n");
5293 memset(&itemW
, 0, sizeof(itemW
));
5294 itemW
.mask
= HDI_WIDTH
| HDI_ORDER
| HDI_TEXT
;
5295 itemW
.pszText
= buffer
;
5296 itemW
.cchTextMax
= sizeof(buffer
);
5297 ret
= SendMessageW(header
, HDM_GETITEMW
, 0, (LPARAM
)&itemW
);
5300 nmhdr
.hdr
.hwndFrom
= header
;
5301 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(header
, GWLP_ID
);
5304 nmhdr
.pitem
= &itemW
;
5306 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5307 nmhdr
.hdr
.code
= HDN_ITEMCHANGINGW
;
5308 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5309 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGINGA
;
5310 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5311 "header notify, parent", TRUE
);
5313 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGINGA
, "Expected ANSI notification code\n");
5314 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5315 nmhdr
.hdr
.code
= HDN_ITEMCHANGEDW
;
5316 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5317 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGEDA
;
5318 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5319 "header notify, parent", TRUE
);
5321 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGEDA
, "Expected ANSI notification code\n");
5322 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5324 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5325 nmhdr
.hdr
.code
= HDN_ITEMCLICKW
;
5326 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5327 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_click_seq
,
5328 "header notify, parent", FALSE
);
5329 ok(nmhdr
.hdr
.code
== HDN_ITEMCLICKA
, "Expected ANSI notification code\n");
5330 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5331 nmhdr
.hdr
.code
= HDN_ITEMDBLCLICKW
;
5332 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5333 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5334 "header notify, parent", FALSE
);
5335 ok(nmhdr
.hdr
.code
== HDN_ITEMDBLCLICKW
, "Expected Unicode notification code\n");
5336 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5337 nmhdr
.hdr
.code
= HDN_DIVIDERDBLCLICKW
;
5338 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5339 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_divider_dclick_seq
,
5340 "header notify, parent", TRUE
);
5341 ok(nmhdr
.hdr
.code
== HDN_DIVIDERDBLCLICKA
, "Expected ANSI notification code\n");
5342 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5343 nmhdr
.hdr
.code
= HDN_BEGINTRACKW
;
5344 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5345 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5346 "header notify, parent", FALSE
);
5347 ok(nmhdr
.hdr
.code
== HDN_BEGINTRACKW
, "Expected Unicode notification code\n");
5348 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5349 nmhdr
.hdr
.code
= HDN_ENDTRACKW
;
5350 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5351 parent_header_notify_seq
[0].id
= HDN_ENDTRACKA
;
5352 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5353 "header notify, parent", FALSE
);
5354 ok(nmhdr
.hdr
.code
== HDN_ENDTRACKA
, "Expected ANSI notification code\n");
5355 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5356 nmhdr
.hdr
.code
= HDN_TRACKW
;
5357 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5358 parent_header_notify_seq
[0].id
= HDN_TRACKA
;
5359 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5360 "header notify, parent", FALSE
);
5361 ok(nmhdr
.hdr
.code
== HDN_TRACKA
, "Expected ANSI notification code\n");
5362 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5363 nmhdr
.hdr
.code
= HDN_BEGINDRAG
;
5364 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5365 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5366 "header notify, parent", FALSE
);
5367 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5368 nmhdr
.hdr
.code
= HDN_ENDDRAG
;
5369 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5370 parent_header_notify_seq
[0].id
= HDN_ENDDRAG
;
5371 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5372 "header notify, parent", FALSE
);
5373 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5374 nmhdr
.hdr
.code
= HDN_FILTERCHANGE
;
5375 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5376 parent_header_notify_seq
[0].id
= HDN_FILTERCHANGE
;
5377 parent_header_notify_seq
[0].flags
|= optional
; /* NT4 does not send this message */
5378 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5379 "header notify, parent", FALSE
);
5380 parent_header_notify_seq
[0].flags
&= ~optional
;
5381 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5382 nmhdr
.hdr
.code
= HDN_BEGINFILTEREDIT
;
5383 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5384 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5385 "header notify, parent", FALSE
);
5386 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5387 nmhdr
.hdr
.code
= HDN_ENDFILTEREDIT
;
5388 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5389 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5390 "header notify, parent", FALSE
);
5391 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5392 nmhdr
.hdr
.code
= HDN_ITEMSTATEICONCLICK
;
5393 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5394 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5395 "header notify, parent", FALSE
);
5396 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5397 nmhdr
.hdr
.code
= HDN_ITEMKEYDOWN
;
5398 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5399 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5400 "header notify, parent", FALSE
);
5402 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5404 DestroyWindow(list
);
5407 static void test_createdragimage(void)
5413 list
= create_listview_control(LVS_ICON
);
5414 ok(list
!= NULL
, "failed to create listview window\n");
5416 insert_item(list
, 0);
5419 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, 0);
5420 ok(himl
== NULL
, "got %p\n", himl
);
5422 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, (LPARAM
)&pt
);
5423 ok(himl
!= NULL
, "got %p\n", himl
);
5424 ImageList_Destroy(himl
);
5426 DestroyWindow(list
);
5429 static void test_dispinfo(void)
5431 static const char testA
[] = "TEST";
5437 hwnd
= create_listview_control(LVS_ICON
);
5438 ok(hwnd
!= NULL
, "failed to create listview window\n");
5440 insert_item(hwnd
, 0);
5442 memset(&item
, 0, sizeof(item
));
5443 item
.pszText
= LPSTR_TEXTCALLBACKA
;
5444 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5447 g_disp_A_to_W
= TRUE
;
5448 item
.pszText
= (char*)buff
;
5449 item
.cchTextMax
= sizeof(buff
)/sizeof(WCHAR
);
5450 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
5451 ok(ret
== sizeof(testA
)-1, "got %d, expected 4\n", ret
);
5452 g_disp_A_to_W
= FALSE
;
5454 ok(memcmp(item
.pszText
, testA
, sizeof(testA
)) == 0,
5455 "got %s, expected %s\n", item
.pszText
, testA
);
5457 DestroyWindow(hwnd
);
5460 static void test_LVM_SETITEMTEXT(void)
5462 static char testA
[] = "TEST";
5467 hwnd
= create_listview_control(LVS_ICON
);
5468 ok(hwnd
!= NULL
, "failed to create listview window\n");
5470 insert_item(hwnd
, 0);
5472 /* null item pointer */
5473 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, 0);
5476 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTW
, 0, 0);
5479 /* index out of bounds */
5480 item
.pszText
= testA
;
5481 item
.cchTextMax
= 0; /* ignored */
5484 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 1, (LPARAM
)&item
);
5487 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, -1, (LPARAM
)&item
);
5490 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5493 DestroyWindow(hwnd
);
5496 static void test_imagelists(void)
5499 HIMAGELIST himl1
, himl2
, himl3
;
5502 himl1
= ImageList_Create(40, 40, 0, 4, 4);
5503 himl2
= ImageList_Create(40, 40, 0, 4, 4);
5504 himl3
= ImageList_Create(40, 40, 0, 4, 4);
5505 ok(himl1
!= NULL
, "Failed to create imagelist\n");
5506 ok(himl2
!= NULL
, "Failed to create imagelist\n");
5507 ok(himl3
!= NULL
, "Failed to create imagelist\n");
5509 hwnd
= create_listview_control(LVS_REPORT
| LVS_SHAREIMAGELISTS
);
5510 header
= subclass_header(hwnd
);
5512 ok(header
!= NULL
, "Expected header\n");
5513 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5514 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5516 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5518 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5519 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5520 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5521 "set normal image list", FALSE
);
5523 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5525 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5526 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5527 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5528 "set state image list", TRUE
);
5530 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5531 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5533 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5535 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5536 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5537 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_set_imagelist
,
5538 "set small image list", FALSE
);
5540 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5541 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5542 DestroyWindow(hwnd
);
5544 hwnd
= create_listview_control(WS_VISIBLE
| LVS_ICON
);
5546 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5548 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5549 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5550 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5551 "set normal image list", FALSE
);
5553 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5555 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5556 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5557 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5558 "set state image list", FALSE
);
5560 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5562 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5563 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5564 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5565 "set small image list", FALSE
);
5567 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5568 ok(header
== NULL
, "Expected no header, got %p\n", header
);
5570 SetWindowLongPtrA(hwnd
, GWL_STYLE
, GetWindowLongPtrA(hwnd
, GWL_STYLE
) | LVS_REPORT
);
5572 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5573 ok(header
!= NULL
, "Expected header, got NULL\n");
5575 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5576 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5578 DestroyWindow(hwnd
);
5581 static void test_deleteitem(void)
5588 hwnd
= create_listview_control(LVS_REPORT
);
5590 insert_item(hwnd
, 0);
5591 insert_item(hwnd
, 0);
5592 insert_item(hwnd
, 0);
5593 insert_item(hwnd
, 0);
5594 insert_item(hwnd
, 0);
5596 g_focus_test_LVN_DELETEITEM
= TRUE
;
5598 /* delete focused item (not the last index) */
5599 item
.stateMask
= LVIS_FOCUSED
;
5600 item
.state
= LVIS_FOCUSED
;
5601 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
5602 ok(ret
== TRUE
, "got %d\n", ret
);
5603 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 2, 0);
5604 ok(ret
== TRUE
, "got %d\n", ret
);
5605 /* next item gets focus */
5606 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5607 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5609 /* focus last item and delete it */
5610 item
.stateMask
= LVIS_FOCUSED
;
5611 item
.state
= LVIS_FOCUSED
;
5612 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
5613 ok(ret
== TRUE
, "got %d\n", ret
);
5614 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 3, 0);
5615 ok(ret
== TRUE
, "got %d\n", ret
);
5616 /* new last item gets focus */
5617 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5618 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5620 /* focus first item and delete it */
5621 item
.stateMask
= LVIS_FOCUSED
;
5622 item
.state
= LVIS_FOCUSED
;
5623 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
5624 ok(ret
== TRUE
, "got %d\n", ret
);
5625 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
5626 ok(ret
== TRUE
, "got %d\n", ret
);
5627 /* new first item gets focus */
5628 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5629 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5631 g_focus_test_LVN_DELETEITEM
= FALSE
;
5633 DestroyWindow(hwnd
);
5636 static void test_insertitem(void)
5643 hwnd
= create_listview_control(LVS_REPORT
);
5645 /* insert item 0 focused */
5646 item
.mask
= LVIF_STATE
;
5647 item
.state
= LVIS_FOCUSED
;
5648 item
.stateMask
= LVIS_FOCUSED
;
5651 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5652 ok(ret
== 0, "got %d\n", ret
);
5654 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5655 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5657 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5659 /* insert item 1, focus shift */
5660 item
.mask
= LVIF_STATE
;
5661 item
.state
= LVIS_FOCUSED
;
5662 item
.stateMask
= LVIS_FOCUSED
;
5665 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5666 ok(ret
== 1, "got %d\n", ret
);
5668 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_insert_focused_seq
, "insert focused", TRUE
);
5670 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5671 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5673 /* insert item 2, no focus shift */
5674 item
.mask
= LVIF_STATE
;
5676 item
.stateMask
= LVIS_FOCUSED
;
5679 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5680 ok(ret
== 2, "got %d\n", ret
);
5682 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5683 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5685 DestroyWindow(hwnd
);
5688 static void test_header_proc(void)
5690 HWND hwnd
, header
, hdr
;
5691 WNDPROC proc1
, proc2
;
5693 hwnd
= create_listview_control(LVS_REPORT
);
5695 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5696 ok(header
!= NULL
, "got %p\n", header
);
5698 hdr
= CreateWindowExA(0, WC_HEADERA
, NULL
,
5699 WS_BORDER
|WS_VISIBLE
|HDS_BUTTONS
|HDS_HORZ
,
5701 NULL
, NULL
, NULL
, NULL
);
5702 ok(hdr
!= NULL
, "got %p\n", hdr
);
5704 proc1
= (WNDPROC
)GetWindowLongPtrW(header
, GWLP_WNDPROC
);
5705 proc2
= (WNDPROC
)GetWindowLongPtrW(hdr
, GWLP_WNDPROC
);
5706 ok(proc1
== proc2
, "got %p, expected %p\n", proc1
, proc2
);
5709 DestroyWindow(hwnd
);
5712 START_TEST(listview
)
5715 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
5717 ULONG_PTR ctx_cookie
;
5720 hComctl32
= GetModuleHandleA("comctl32.dll");
5721 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
5722 if (pInitCommonControlsEx
)
5724 INITCOMMONCONTROLSEX iccex
;
5725 iccex
.dwSize
= sizeof(iccex
);
5726 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
5727 pInitCommonControlsEx(&iccex
);
5730 InitCommonControls();
5732 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
5734 hwndparent
= create_parent_window(FALSE
);
5735 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5737 g_is_below_5
= is_below_comctl_5();
5739 test_header_notification();
5740 test_header_notification2();
5747 test_icon_spacing();
5750 test_item_position();
5755 test_subitem_rect();
5759 test_nosortheader();
5763 test_getitemposition();
5764 test_columnscreation();
5766 test_notifyformat();
5768 test_getitemspacing();
5769 test_getcolumnwidth();
5770 test_approximate_viewrect();
5773 test_destroynotify();
5774 test_createdragimage();
5776 test_LVM_SETITEMTEXT();
5782 if (!load_v6_module(&ctx_cookie
, &hCtx
))
5784 DestroyWindow(hwndparent
);
5788 /* comctl32 version 6 tests start here */
5789 test_get_set_view();
5790 test_canceleditlabel();
5792 test_scrollnotify();
5793 test_LVS_EX_TRANSPARENTBKGND();
5794 test_LVS_EX_HEADERINALLVIEWS();
5800 unload_v6_module(ctx_cookie
, hCtx
);
5802 DestroyWindow(hwndparent
);