4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009-2013 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"
31 #define PARENT_SEQ_INDEX 0
32 #define PARENT_FULL_SEQ_INDEX 1
33 #define LISTVIEW_SEQ_INDEX 2
34 #define EDITBOX_SEQ_INDEX 3
35 #define COMBINED_SEQ_INDEX 4
36 #define NUM_MSG_SEQUENCES 5
41 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
42 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
43 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
45 static const WCHAR testparentclassW
[] =
46 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
48 static HWND hwndparent
, hwndparentW
;
49 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
50 static BOOL blockEdit
;
51 /* return nonzero on NM_HOVER */
52 static BOOL g_block_hover
;
53 /* notification data for LVN_ITEMCHANGED */
54 static NMLISTVIEW g_nmlistview
;
55 /* notification data for LVN_ITEMCHANGING */
56 static NMLISTVIEW g_nmlistview_changing
;
57 /* format reported to control:
58 -1 falls to defproc, anything else returned */
59 static INT notifyFormat
;
60 /* indicates we're running < 5.80 version */
61 static BOOL g_is_below_5
;
62 /* item data passed to LVN_GETDISPINFOA */
63 static LVITEMA g_itema
;
64 /* alter notification code A->W */
65 static BOOL g_disp_A_to_W
;
66 /* dispinfo data sent with LVN_LVN_ENDLABELEDIT */
67 static NMLVDISPINFO g_editbox_disp_info
;
68 /* when this is set focus will be tested on LVN_DELETEITEM */
69 static BOOL g_focus_test_LVN_DELETEITEM
;
71 static HWND
subclass_editbox(HWND hwndListview
);
73 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
75 static const struct message create_ownerdrawfixed_parent_seq
[] = {
76 { WM_NOTIFYFORMAT
, sent
},
77 { WM_QUERYUISTATE
, sent
|optional
}, /* Win2K and higher */
78 { WM_MEASUREITEM
, sent
},
79 { WM_PARENTNOTIFY
, sent
},
83 static const struct message redraw_listview_seq
[] = {
84 { WM_PAINT
, sent
|id
, 0, 0, LISTVIEW_ID
},
85 { WM_PAINT
, sent
|id
, 0, 0, HEADER_ID
},
86 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
87 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, HEADER_ID
},
88 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
89 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
90 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, LISTVIEW_ID
},
94 static const struct message listview_icon_spacing_seq
[] = {
95 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(20, 30) },
96 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(25, 35) },
97 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(-1, -1) },
101 static const struct message listview_color_seq
[] = {
102 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
103 { LVM_GETBKCOLOR
, sent
},
104 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
105 { LVM_GETTEXTCOLOR
, sent
},
106 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
107 { LVM_GETTEXTBKCOLOR
, sent
},
109 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
110 { LVM_GETBKCOLOR
, sent
},
111 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
112 { LVM_GETTEXTCOLOR
, sent
},
113 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
114 { LVM_GETTEXTBKCOLOR
, sent
},
116 { LVM_SETBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
117 { LVM_GETBKCOLOR
, sent
},
118 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, CLR_NONE
},
119 { LVM_GETTEXTCOLOR
, sent
},
120 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
121 { LVM_GETTEXTBKCOLOR
, sent
},
123 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
124 { LVM_GETBKCOLOR
, sent
},
125 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
126 { LVM_GETTEXTCOLOR
, sent
},
127 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
128 { LVM_GETTEXTBKCOLOR
, sent
},
132 static const struct message listview_item_count_seq
[] = {
133 { LVM_GETITEMCOUNT
, sent
},
134 { LVM_INSERTITEM
, sent
},
135 { LVM_INSERTITEM
, sent
},
136 { LVM_INSERTITEM
, sent
},
137 { LVM_GETITEMCOUNT
, sent
},
138 { LVM_DELETEITEM
, sent
|wparam
, 2 },
139 { WM_NCPAINT
, sent
|optional
},
140 { WM_ERASEBKGND
, sent
|optional
},
141 { LVM_GETITEMCOUNT
, sent
},
142 { LVM_DELETEALLITEMS
, sent
},
143 { LVM_GETITEMCOUNT
, sent
},
144 { LVM_INSERTITEM
, sent
},
145 { LVM_INSERTITEM
, sent
},
146 { LVM_GETITEMCOUNT
, sent
},
147 { LVM_INSERTITEM
, sent
},
148 { LVM_GETITEMCOUNT
, sent
},
152 static const struct message listview_itempos_seq
[] = {
153 { LVM_INSERTITEM
, sent
},
154 { LVM_INSERTITEM
, sent
},
155 { LVM_INSERTITEM
, sent
},
156 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 1, MAKELPARAM(10,5) },
157 { WM_NCPAINT
, sent
|optional
},
158 { WM_ERASEBKGND
, sent
|optional
},
159 { LVM_GETITEMPOSITION
, sent
|wparam
, 1 },
160 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 2, MAKELPARAM(0,0) },
161 { LVM_GETITEMPOSITION
, sent
|wparam
, 2 },
162 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 0, MAKELPARAM(20,20) },
163 { LVM_GETITEMPOSITION
, sent
|wparam
, 0 },
167 static const struct message listview_ownerdata_switchto_seq
[] = {
168 { WM_STYLECHANGING
, sent
},
169 { WM_STYLECHANGED
, sent
},
173 static const struct message listview_getorderarray_seq
[] = {
174 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
175 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
179 static const struct message empty_seq
[] = {
183 static const struct message forward_erasebkgnd_parent_seq
[] = {
184 { WM_ERASEBKGND
, sent
},
188 static const struct message ownderdata_select_focus_parent_seq
[] = {
189 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
190 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
191 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
}, /* version 4.7x */
195 static const struct message ownerdata_setstate_all_parent_seq
[] = {
196 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
200 static const struct message ownerdata_defocus_all_parent_seq
[] = {
201 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
202 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
203 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
},
204 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
208 static const struct message ownerdata_deselect_all_parent_seq
[] = {
209 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ODCACHEHINT
},
210 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
214 static const struct message change_all_parent_seq
[] = {
215 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
216 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
218 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
219 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
221 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
222 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
224 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
225 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
227 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
228 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
232 static const struct message changing_all_parent_seq
[] = {
233 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
234 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
235 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
236 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
237 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
241 static const struct message textcallback_set_again_parent_seq
[] = {
242 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
243 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
247 static const struct message single_getdispinfo_parent_seq
[] = {
248 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
252 static const struct message getitemposition_seq1
[] = {
253 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
257 static const struct message getitemposition_seq2
[] = {
258 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
259 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
263 static const struct message getsubitemrect_seq
[] = {
264 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, -1, 0, LISTVIEW_ID
},
265 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
266 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, 0, 0, LISTVIEW_ID
},
267 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
268 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, -10, 0, LISTVIEW_ID
},
269 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
270 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, 20, 0, LISTVIEW_ID
},
271 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
275 static const struct message editbox_create_pos
[] = {
276 /* sequence sent after LVN_BEGINLABELEDIT */
277 /* next two are 4.7x specific */
278 { WM_WINDOWPOSCHANGING
, sent
},
279 { WM_WINDOWPOSCHANGED
, sent
|optional
},
281 { WM_WINDOWPOSCHANGING
, sent
|optional
},
282 { WM_NCCALCSIZE
, sent
},
283 { WM_WINDOWPOSCHANGED
, sent
},
284 { WM_MOVE
, sent
|defwinproc
},
285 { WM_SIZE
, sent
|defwinproc
},
286 /* the rest is todo, skipped in 4.7x */
287 { WM_WINDOWPOSCHANGING
, sent
|optional
},
288 { WM_WINDOWPOSCHANGED
, sent
|optional
},
292 static const struct message scroll_parent_seq
[] = {
293 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_BEGINSCROLL
},
294 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDSCROLL
},
298 static const struct message setredraw_seq
[] = {
299 { WM_SETREDRAW
, sent
|id
|wparam
, FALSE
, 0, LISTVIEW_ID
},
303 static const struct message lvs_ex_transparentbkgnd_seq
[] = {
304 { WM_PRINTCLIENT
, sent
|lparam
, 0, PRF_ERASEBKGND
},
308 static const struct message edit_end_nochange
[] = {
309 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDLABELEDITA
},
310 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
}, /* todo */
311 { WM_NOTIFY
, sent
|id
, 0, 0, NM_SETFOCUS
},
315 static const struct message hover_parent
[] = {
316 { WM_GETDLGCODE
, sent
}, /* todo_wine */
317 { WM_NOTIFY
, sent
|id
, 0, 0, NM_HOVER
},
321 static const struct message listview_destroy
[] = {
322 { 0x0090, sent
|optional
}, /* Vista */
323 { WM_PARENTNOTIFY
, sent
},
324 { WM_SHOWWINDOW
, sent
},
325 { WM_WINDOWPOSCHANGING
, sent
},
326 { WM_WINDOWPOSCHANGED
, sent
|optional
},
327 { WM_DESTROY
, sent
},
328 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_DELETEALLITEMS
},
329 { WM_NCDESTROY
, sent
},
333 static const struct message listview_header_changed_seq
[] = {
334 { LVM_SETCOLUMNA
, sent
},
335 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
336 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
340 static const struct message parent_header_click_seq
[] = {
341 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_COLUMNCLICK
},
342 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCLICKA
},
346 static const struct message parent_header_divider_dclick_seq
[] = {
347 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCHANGINGA
},
348 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
},
349 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
},
350 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCHANGEDA
},
351 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_DIVIDERDBLCLICKA
},
355 static const struct message listview_set_imagelist
[] = {
356 { LVM_SETIMAGELIST
, sent
|id
, 0, 0, LISTVIEW_ID
},
360 static const struct message listview_header_set_imagelist
[] = {
361 { LVM_SETIMAGELIST
, sent
|id
, 0, 0, LISTVIEW_ID
},
362 { HDM_SETIMAGELIST
, sent
|id
, 0, 0, HEADER_ID
},
366 static const struct message parent_insert_focused_seq
[] = {
367 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
368 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
369 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
370 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
371 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_INSERTITEM
},
375 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
377 static LONG defwndproc_counter
= 0;
381 msg
.message
= message
;
382 msg
.flags
= sent
|wparam
|lparam
;
383 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
386 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
388 /* log system messages, except for painting */
389 if (message
< WM_USER
&&
390 message
!= WM_PAINT
&&
391 message
!= WM_ERASEBKGND
&&
392 message
!= WM_NCPAINT
&&
393 message
!= WM_NCHITTEST
&&
394 message
!= WM_GETTEXT
&&
395 message
!= WM_GETICON
&&
396 message
!= WM_DEVICECHANGE
)
398 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
400 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
401 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
403 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
409 switch (((NMHDR
*)lParam
)->code
)
411 case LVN_BEGINLABELEDIT
:
415 /* subclass edit box */
417 edit
= subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
421 INT len
= SendMessageA(edit
, EM_GETLIMITTEXT
, 0, 0);
422 ok(len
== 259 || broken(len
== 260) /* includes NULL in NT4 */,
423 "text limit %d, expected 259\n", len
);
428 case LVN_ENDLABELEDIT
:
432 /* always accept new item text */
433 NMLVDISPINFO
*di
= (NMLVDISPINFO
*)lParam
;
434 g_editbox_disp_info
= *di
;
435 trace("LVN_ENDLABELEDIT: text=%s\n", di
->item
.pszText
? di
->item
.pszText
: "(null)");
437 /* edit control still available from this notification */
438 edit
= (HWND
)SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETEDITCONTROL
, 0, 0);
439 ok(IsWindow(edit
), "expected valid edit control handle\n");
440 ok((GetWindowLongA(edit
, GWL_STYLE
) & ES_MULTILINE
) == 0, "edit is multiline\n");
444 case LVN_BEGINSCROLL
:
447 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
449 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
450 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
453 case LVN_ITEMCHANGING
:
455 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
456 g_nmlistview_changing
= *nmlv
;
459 case LVN_ITEMCHANGED
:
461 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
462 g_nmlistview
= *nmlv
;
465 case LVN_GETDISPINFOA
:
467 NMLVDISPINFOA
*dispinfo
= (NMLVDISPINFOA
*)lParam
;
468 g_itema
= dispinfo
->item
;
470 if (g_disp_A_to_W
&& (dispinfo
->item
.mask
& LVIF_TEXT
))
472 static const WCHAR testW
[] = {'T','E','S','T',0};
473 dispinfo
->hdr
.code
= LVN_GETDISPINFOW
;
474 memcpy(dispinfo
->item
.pszText
, testW
, sizeof(testW
));
477 /* test control buffer size for text, 10 used to mask cases when control
478 is using caller buffer to process LVM_GETITEM for example */
479 if (dispinfo
->item
.mask
& LVIF_TEXT
&& dispinfo
->item
.cchTextMax
> 10)
480 ok(dispinfo
->item
.cchTextMax
== 260 ||
481 broken(dispinfo
->item
.cchTextMax
== 264) /* NT4 reports aligned size */,
482 "buffer size %d\n", dispinfo
->item
.cchTextMax
);
486 if (g_focus_test_LVN_DELETEITEM
)
488 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
491 state
= SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETITEMSTATE
, nmlv
->iItem
, LVIS_FOCUSED
);
492 ok(state
== 0, "got state %x\n", state
);
496 if (g_block_hover
) return 1;
501 case WM_NOTIFYFORMAT
:
503 /* force to return format */
504 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
509 defwndproc_counter
++;
510 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
511 defwndproc_counter
--;
516 static BOOL
register_parent_wnd_class(BOOL Unicode
)
524 clsW
.lpfnWndProc
= parent_wnd_proc
;
527 clsW
.hInstance
= GetModuleHandleW(NULL
);
529 clsW
.hCursor
= LoadCursorA(0, IDC_ARROW
);
530 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
531 clsW
.lpszMenuName
= NULL
;
532 clsW
.lpszClassName
= testparentclassW
;
537 clsA
.lpfnWndProc
= parent_wnd_proc
;
540 clsA
.hInstance
= GetModuleHandleA(NULL
);
542 clsA
.hCursor
= LoadCursorA(0, IDC_ARROW
);
543 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
544 clsA
.lpszMenuName
= NULL
;
545 clsA
.lpszClassName
= "Listview test parent class";
548 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
551 static HWND
create_parent_window(BOOL Unicode
)
553 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
556 if (!register_parent_wnd_class(Unicode
))
563 hwnd
= CreateWindowExW(0, testparentclassW
, nameW
,
564 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
565 WS_MAXIMIZEBOX
| WS_VISIBLE
,
567 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
569 hwnd
= CreateWindowExA(0, "Listview test parent class",
570 "Listview test parent window",
571 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
572 WS_MAXIMIZEBOX
| WS_VISIBLE
,
574 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
575 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
579 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
581 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
582 static LONG defwndproc_counter
= 0;
586 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
588 /* some debug output for style changing */
589 if ((message
== WM_STYLECHANGING
||
590 message
== WM_STYLECHANGED
) && lParam
)
592 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
593 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
596 msg
.message
= message
;
597 msg
.flags
= sent
|wparam
|lparam
;
598 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
601 msg
.id
= LISTVIEW_ID
;
602 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
603 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
605 defwndproc_counter
++;
606 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
607 defwndproc_counter
--;
611 static HWND
create_listview_control(DWORD style
)
617 GetClientRect(hwndparent
, &rect
);
618 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
619 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
620 0, 0, rect
.right
, rect
.bottom
,
621 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
622 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
624 if (!hwnd
) return NULL
;
626 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
627 (LONG_PTR
)listview_subclass_proc
);
628 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
633 /* unicode listview window with specified parent */
634 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
639 static const WCHAR nameW
[] = {'f','o','o',0};
641 GetClientRect(parent
, &rect
);
642 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
643 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
644 0, 0, rect
.right
, rect
.bottom
,
645 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
646 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
648 if (!hwnd
) return NULL
;
650 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
651 (LONG_PTR
)listview_subclass_proc
);
652 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
657 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
659 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
660 static LONG defwndproc_counter
= 0;
664 trace("header: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
666 msg
.message
= message
;
667 msg
.flags
= sent
|wparam
|lparam
;
668 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
672 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
674 defwndproc_counter
++;
675 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
676 defwndproc_counter
--;
680 static HWND
subclass_header(HWND hwndListview
)
685 hwnd
= ListView_GetHeader(hwndListview
);
686 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
687 (LONG_PTR
)header_subclass_proc
);
688 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
693 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
695 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
696 static LONG defwndproc_counter
= 0;
700 msg
.message
= message
;
701 msg
.flags
= sent
|wparam
|lparam
;
702 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
707 /* all we need is sizing */
708 if (message
== WM_WINDOWPOSCHANGING
||
709 message
== WM_NCCALCSIZE
||
710 message
== WM_WINDOWPOSCHANGED
||
711 message
== WM_MOVE
||
714 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
717 defwndproc_counter
++;
718 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
719 defwndproc_counter
--;
723 static HWND
subclass_editbox(HWND hwndListview
)
728 hwnd
= (HWND
)SendMessage(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
729 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
730 (LONG_PTR
)editbox_subclass_proc
);
731 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
736 /* Performs a single LVM_HITTEST test */
737 static void test_lvm_hittest_(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
, UINT broken_flags
,
738 BOOL todo_item
, BOOL todo_flags
, int line
)
747 ret
= SendMessage(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
753 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
754 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
755 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
760 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
761 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
762 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
768 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
770 else if (broken_flags
)
771 ok_(__FILE__
, line
)(lpht
.flags
== flags
|| broken(lpht
.flags
== broken_flags
),
772 "Expected flags %x, got %x\n", flags
, lpht
.flags
);
774 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
777 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
779 /* Performs a single LVM_SUBITEMHITTEST test */
780 static void test_lvm_subitemhittest_(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
781 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
789 ret
= SendMessage(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
795 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
796 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
801 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
802 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
808 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
811 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
816 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
819 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
822 #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__)
824 static void test_images(void)
832 static CHAR hello
[] = "hello";
834 himl
= ImageList_Create(40, 40, 0, 4, 4);
835 ok(himl
!= NULL
, "failed to create imagelist\n");
837 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
838 ok(hbmp
!= NULL
, "failed to create bitmap\n");
840 r
= ImageList_Add(himl
, hbmp
, 0);
841 ok(r
== 0, "should be zero\n");
843 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
844 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
845 ok(hwnd
!= NULL
, "failed to create listview window\n");
847 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
848 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
850 ok(r
== 0, "should return zero\n");
852 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
853 ok(r
== 0, "should return zero\n");
855 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
856 ok(r
!= 0, "got 0\n");
858 /* returns dimensions */
860 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
861 ok(r
== 0, "should be zero items\n");
863 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
868 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
869 ok(r
== -1, "should fail\n");
872 item
.pszText
= hello
;
873 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
874 ok(r
== 0, "should not fail\n");
876 memset(&r1
, 0, sizeof r1
);
878 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
881 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
882 ok(r
== TRUE
, "should not fail\n");
885 item
.pszText
= hello
;
886 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
887 ok(r
== 0, "should not fail\n");
889 memset(&r2
, 0, sizeof r2
);
891 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
894 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
899 static void test_checkboxes(void)
904 static CHAR text
[] = "Text",
908 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
909 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
910 ok(hwnd
!= NULL
, "failed to create listview window\n");
912 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
913 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
914 item
.stateMask
= 0xffff;
919 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
923 item
.mask
= LVIF_STATE
;
924 item
.stateMask
= 0xffff;
925 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
927 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
929 /* Don't set LVIF_STATE */
930 item
.mask
= LVIF_TEXT
;
931 item
.stateMask
= 0xffff;
936 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
940 item
.mask
= LVIF_STATE
;
941 item
.stateMask
= 0xffff;
942 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
944 ok(item
.state
== 0, "state %x\n", item
.state
);
946 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
949 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
951 item
.mask
= LVIF_STATE
;
952 item
.stateMask
= 0xffff;
953 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
955 if (item
.state
!= 0x1ccc)
957 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
962 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
964 item
.mask
= LVIF_TEXT
;
966 item
.pszText
= text2
;
967 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
971 item
.mask
= LVIF_STATE
;
972 item
.stateMask
= 0xffff;
973 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
975 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
977 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
979 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
980 item
.stateMask
= 0xffff;
982 item
.pszText
= text3
;
983 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
987 item
.mask
= LVIF_STATE
;
988 item
.stateMask
= 0xffff;
989 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
991 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
993 /* Set an item's state to checked */
995 item
.mask
= LVIF_STATE
;
996 item
.stateMask
= 0xf000;
998 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1002 item
.mask
= LVIF_STATE
;
1003 item
.stateMask
= 0xffff;
1004 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1006 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1008 /* Check that only the bits we asked for are returned,
1009 * and that all the others are set to zero
1012 item
.mask
= LVIF_STATE
;
1013 item
.stateMask
= 0xf000;
1014 item
.state
= 0xffff;
1015 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1017 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
1019 /* Set the style again and check that doesn't change an item's state */
1020 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1021 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1024 item
.mask
= LVIF_STATE
;
1025 item
.stateMask
= 0xffff;
1026 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1028 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1030 /* Unsetting the checkbox extended style doesn't change an item's state */
1031 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
1032 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1035 item
.mask
= LVIF_STATE
;
1036 item
.stateMask
= 0xffff;
1037 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1039 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1041 /* Now setting the style again will change an item's state */
1042 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1046 item
.mask
= LVIF_STATE
;
1047 item
.stateMask
= 0xffff;
1048 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1050 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
1052 /* Toggle checkbox tests (bug 9934) */
1053 memset (&item
, 0xcc, sizeof(item
));
1054 item
.mask
= LVIF_STATE
;
1057 item
.state
= LVIS_FOCUSED
;
1058 item
.stateMask
= LVIS_FOCUSED
;
1059 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1063 item
.mask
= LVIF_STATE
;
1064 item
.stateMask
= 0xffff;
1065 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1067 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1069 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1071 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1075 item
.mask
= LVIF_STATE
;
1076 item
.stateMask
= 0xffff;
1077 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1079 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
1081 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1083 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1087 item
.mask
= LVIF_STATE
;
1088 item
.stateMask
= 0xffff;
1089 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1091 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1093 DestroyWindow(hwnd
);
1096 static void insert_column(HWND hwnd
, int idx
)
1101 memset(&column
, 0xcc, sizeof(column
));
1102 column
.mask
= LVCF_SUBITEM
;
1103 column
.iSubItem
= idx
;
1105 rc
= ListView_InsertColumn(hwnd
, idx
, &column
);
1109 static void insert_item(HWND hwnd
, int idx
)
1111 static CHAR text
[] = "foo";
1116 memset(&item
, 0xcc, sizeof (item
));
1117 item
.mask
= LVIF_TEXT
;
1120 item
.pszText
= text
;
1122 rc
= ListView_InsertItem(hwnd
, &item
);
1126 static void test_items(void)
1128 const LPARAM lparamTest
= 0x42;
1129 static CHAR text
[] = "Text";
1135 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1136 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1137 ok(hwnd
!= NULL
, "failed to create listview window\n");
1140 * Test setting/getting item params
1143 /* Set up two columns */
1144 insert_column(hwnd
, 0);
1145 insert_column(hwnd
, 1);
1147 /* LVIS_SELECTED with zero stateMask */
1149 memset (&item
, 0, sizeof (item
));
1150 item
.mask
= LVIF_STATE
;
1151 item
.state
= LVIS_SELECTED
;
1155 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1158 memset (&item
, 0xcc, sizeof (item
));
1159 item
.mask
= LVIF_STATE
;
1160 item
.stateMask
= LVIS_SELECTED
;
1164 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1166 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1167 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1169 /* LVIS_SELECTED with zero stateMask */
1171 memset (&item
, 0, sizeof (item
));
1172 item
.mask
= LVIF_STATE
;
1173 item
.state
= LVIS_FOCUSED
;
1177 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1180 memset (&item
, 0xcc, sizeof (item
));
1181 item
.mask
= LVIF_STATE
;
1182 item
.stateMask
= LVIS_FOCUSED
;
1186 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1188 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1189 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1191 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1193 memset (&item
, 0, sizeof (item
));
1194 item
.mask
= LVIF_STATE
;
1195 item
.state
= LVIS_CUT
;
1196 item
.stateMask
= LVIS_FOCUSED
;
1199 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1202 memset (&item
, 0xcc, sizeof (item
));
1203 item
.mask
= LVIF_STATE
;
1204 item
.stateMask
= LVIS_CUT
;
1208 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1210 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1211 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1213 /* Insert an item with just a param */
1214 memset (&item
, 0xcc, sizeof (item
));
1215 item
.mask
= LVIF_PARAM
;
1218 item
.lParam
= lparamTest
;
1219 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1222 /* Test getting of the param */
1223 memset (&item
, 0xcc, sizeof (item
));
1224 item
.mask
= LVIF_PARAM
;
1227 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1229 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1231 /* Set up a subitem */
1232 memset (&item
, 0xcc, sizeof (item
));
1233 item
.mask
= LVIF_TEXT
;
1236 item
.pszText
= text
;
1237 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1240 item
.mask
= LVIF_TEXT
;
1243 item
.pszText
= buffA
;
1244 item
.cchTextMax
= sizeof(buffA
);
1245 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1247 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got text %s, expected %s\n", item
.pszText
, text
);
1249 /* set up with extra flag */
1250 /* 1. reset subitem text */
1251 item
.mask
= LVIF_TEXT
;
1254 item
.pszText
= NULL
;
1255 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1258 item
.mask
= LVIF_TEXT
;
1261 item
.pszText
= buffA
;
1263 item
.cchTextMax
= sizeof(buffA
);
1264 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1266 ok(item
.pszText
[0] == 0, "got %p\n", item
.pszText
);
1268 /* 2. set new text with extra flag specified */
1269 item
.mask
= LVIF_TEXT
| LVIF_DI_SETITEM
;
1272 item
.pszText
= text
;
1273 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1274 ok(r
== 1 || broken(r
== 0) /* NT4 */, "ret %d\n", r
);
1278 item
.mask
= LVIF_TEXT
;
1281 item
.pszText
= buffA
;
1283 item
.cchTextMax
= sizeof(buffA
);
1284 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1286 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got %s, expected %s\n", item
.pszText
, text
);
1289 /* Query param from subitem: returns main item param */
1290 memset (&item
, 0xcc, sizeof (item
));
1291 item
.mask
= LVIF_PARAM
;
1294 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1296 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1298 /* Set up param on first subitem: no effect */
1299 memset (&item
, 0xcc, sizeof (item
));
1300 item
.mask
= LVIF_PARAM
;
1303 item
.lParam
= lparamTest
+1;
1304 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1307 /* Query param from subitem again: should still return main item param */
1308 memset (&item
, 0xcc, sizeof (item
));
1309 item
.mask
= LVIF_PARAM
;
1312 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1314 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1316 /**** Some tests of state highlighting ****/
1317 memset (&item
, 0xcc, sizeof (item
));
1318 item
.mask
= LVIF_STATE
;
1321 item
.state
= LVIS_SELECTED
;
1322 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1323 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1326 item
.state
= LVIS_DROPHILITED
;
1327 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1330 memset (&item
, 0xcc, sizeof (item
));
1331 item
.mask
= LVIF_STATE
;
1334 item
.stateMask
= -1;
1335 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1337 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1339 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1341 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1343 /* some notnull but meaningless masks */
1344 memset (&item
, 0, sizeof(item
));
1345 item
.mask
= LVIF_NORECOMPUTE
;
1348 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1350 memset (&item
, 0, sizeof(item
));
1351 item
.mask
= LVIF_DI_SETITEM
;
1354 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1357 /* set text to callback value already having it */
1358 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1360 memset (&item
, 0, sizeof (item
));
1361 item
.mask
= LVIF_TEXT
;
1362 item
.pszText
= LPSTR_TEXTCALLBACK
;
1364 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1366 memset (&item
, 0, sizeof (item
));
1368 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1370 item
.pszText
= LPSTR_TEXTCALLBACK
;
1371 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0 , (LPARAM
) &item
);
1374 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1375 "check callback text comparison rule", FALSE
);
1377 DestroyWindow(hwnd
);
1380 static void test_columns(void)
1389 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1390 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1391 ok(hwnd
!= NULL
, "failed to create listview window\n");
1393 /* Add a column with no mask */
1394 memset(&column
, 0xcc, sizeof(column
));
1396 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1397 ok(rc
== 0, "Inserting column with no mask failed with %d\n", rc
);
1399 /* Check its width */
1400 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
1401 ok(rc
== 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1403 DestroyWindow(hwnd
);
1405 /* LVM_GETCOLUMNORDERARRAY */
1406 hwnd
= create_listview_control(LVS_REPORT
);
1407 subclass_header(hwnd
);
1409 memset(&column
, 0, sizeof(column
));
1410 column
.mask
= LVCF_WIDTH
;
1412 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1416 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&column
);
1419 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1421 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1423 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1424 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1426 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1428 /* after column added subitem is considered as present */
1429 insert_item(hwnd
, 0);
1431 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1433 item
.pszText
= buff
;
1434 item
.cchTextMax
= sizeof(buff
);
1437 item
.mask
= LVIF_TEXT
;
1438 memset(&g_itema
, 0, sizeof(g_itema
));
1439 rc
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
1441 ok(g_itema
.iSubItem
== 1, "got %d\n", g_itema
.iSubItem
);
1443 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
1444 "get subitem text after column added", FALSE
);
1446 DestroyWindow(hwnd
);
1449 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1450 static WNDPROC listviewWndProc
;
1451 static HIMAGELIST test_create_imagelist
;
1453 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1457 if (uMsg
== WM_CREATE
)
1459 LPCREATESTRUCT lpcs
= (LPCREATESTRUCT
)lParam
;
1460 lpcs
->style
|= LVS_REPORT
;
1462 ret
= CallWindowProc(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1463 if (uMsg
== WM_CREATE
) SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1467 static void test_create(void)
1478 cls
.cbSize
= sizeof(WNDCLASSEX
);
1479 ok(GetClassInfoEx(GetModuleHandle(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1480 listviewWndProc
= cls
.lpfnWndProc
;
1481 cls
.lpfnWndProc
= create_test_wndproc
;
1482 cls
.lpszClassName
= "MyListView32";
1483 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
1485 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1486 hList
= CreateWindow("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1487 ok((HIMAGELIST
)SendMessage(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1488 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1490 if (!IsWindow(hHeader
))
1493 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1494 DestroyWindow(hList
);
1498 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1499 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1500 DestroyWindow(hList
);
1502 /* header isn't created on LVS_ICON and LVS_LIST styles */
1503 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1504 GetModuleHandle(NULL
), 0);
1505 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1506 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1507 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1509 memset(&col
, 0, sizeof(LVCOLUMNA
));
1510 col
.mask
= LVCF_WIDTH
;
1512 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1514 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1515 ok(IsWindow(hHeader
), "Header should be created\n");
1516 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1517 style
= GetWindowLong(hHeader
, GWL_STYLE
);
1518 ok(!(style
& HDS_HIDDEN
), "Not expected HDS_HIDDEN\n");
1519 DestroyWindow(hList
);
1521 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1522 GetModuleHandle(NULL
), 0);
1523 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1524 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1525 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1527 memset(&col
, 0, sizeof(LVCOLUMNA
));
1528 col
.mask
= LVCF_WIDTH
;
1530 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1532 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1533 ok(IsWindow(hHeader
), "Header should be created\n");
1534 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1535 DestroyWindow(hList
);
1537 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1538 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1539 GetModuleHandle(NULL
), 0);
1540 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLongPtr(hList
, GWL_STYLE
) | LVS_REPORT
);
1541 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1542 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1543 ok(IsWindow(hHeader
), "Header should be created\n");
1544 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLong(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1545 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1546 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1547 ok(IsWindow(hHeader
), "Header should be created\n");
1548 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1549 DestroyWindow(hList
);
1551 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1552 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1553 GetModuleHandle(NULL
), 0);
1554 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1555 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1556 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1557 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1558 ok(IsWindow(hHeader
), "Header should be created\n");
1559 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1560 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1561 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1562 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1563 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1564 ok(IsWindow(hHeader
), "Header should be created\n");
1565 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1566 DestroyWindow(hList
);
1568 /* LVS_REPORT without WS_VISIBLE */
1569 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1570 GetModuleHandle(NULL
), 0);
1571 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1572 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1573 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1575 memset(&col
, 0, sizeof(LVCOLUMNA
));
1576 col
.mask
= LVCF_WIDTH
;
1578 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1580 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1581 ok(IsWindow(hHeader
), "Header should be created\n");
1582 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1583 DestroyWindow(hList
);
1585 /* LVS_REPORT without WS_VISIBLE, try to show it */
1586 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1587 GetModuleHandle(NULL
), 0);
1588 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1589 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1590 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1591 ShowWindow(hList
, SW_SHOW
);
1592 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1593 ok(IsWindow(hHeader
), "Header should be created\n");
1594 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1595 DestroyWindow(hList
);
1597 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1598 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1599 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1600 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1601 ok(IsWindow(hHeader
), "Header should be created\n");
1602 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1603 /* HDS_DRAGDROP set by default */
1604 ok(GetWindowLongPtr(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1605 DestroyWindow(hList
);
1607 /* setting LVS_EX_HEADERDRAGDROP creates header */
1608 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1609 GetModuleHandle(NULL
), 0);
1610 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1611 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1612 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1613 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1614 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1615 ok(IsWindow(hHeader
) ||
1616 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1617 "Header should be created\n");
1618 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1619 DestroyWindow(hList
);
1621 /* setting LVS_EX_GRIDLINES creates header */
1622 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1623 GetModuleHandle(NULL
), 0);
1624 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1625 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1626 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1627 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_GRIDLINES
);
1628 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1629 ok(IsWindow(hHeader
) ||
1630 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1631 "Header should be created\n");
1632 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1633 DestroyWindow(hList
);
1635 /* setting LVS_EX_FULLROWSELECT creates header */
1636 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1637 GetModuleHandle(NULL
), 0);
1638 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1639 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1640 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1641 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
1642 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1643 ok(IsWindow(hHeader
) ||
1644 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1645 "Header should be created\n");
1646 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1647 DestroyWindow(hList
);
1649 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1650 hList
= create_listview_control(LVS_ICON
);
1651 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1652 r
= SendMessage(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1653 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1654 DestroyWindow(hList
);
1656 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1657 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1658 GetModuleHandle(NULL
), 0);
1659 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1660 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1662 rect
.left
= LVIR_BOUNDS
;
1664 rect
.right
= rect
.bottom
= -10;
1665 r
= SendMessage(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1666 /* right value contains garbage, probably because header columns are not set up */
1667 expect(0, rect
.bottom
);
1670 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1671 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1672 ok(GetDlgItem(hList
, 0) == NULL
, "NULL dialog item expected\n");
1674 DestroyWindow(hList
);
1676 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1677 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1678 hList
= create_listview_control(LVS_OWNERDRAWFIXED
| LVS_REPORT
);
1679 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1680 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1681 DestroyWindow(hList
);
1684 static void test_redraw(void)
1691 hwnd
= create_listview_control(LVS_REPORT
);
1692 subclass_header(hwnd
);
1694 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1696 InvalidateRect(hwnd
, NULL
, TRUE
);
1698 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1700 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1702 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1703 /* 1. Without backbuffer */
1704 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1707 hdc
= GetWindowDC(hwndparent
);
1709 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1710 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1711 ok(r
== 1, "Expected not zero result\n");
1712 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1713 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1715 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1718 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1719 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1721 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1722 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1724 /* 2. With backbuffer */
1725 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1726 LVS_EX_DOUBLEBUFFER
);
1727 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1730 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1731 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1733 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1734 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1736 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1739 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1740 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1741 todo_wine
expect(1, r
);
1742 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1743 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1745 ReleaseDC(hwndparent
, hdc
);
1747 DestroyWindow(hwnd
);
1750 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1752 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1754 if(msg
== WM_NOTIFY
) {
1755 NMHDR
*nmhdr
= (PVOID
)lp
;
1756 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1757 NMLVCUSTOMDRAW
*nmlvcd
= (PVOID
)nmhdr
;
1758 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd
->nmcd
.dwDrawStage
);
1759 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1761 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1762 return CDRF_NOTIFYITEMDRAW
;
1763 case CDDS_ITEMPREPAINT
:
1764 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1765 return CDRF_NOTIFYSUBITEMDRAW
;
1766 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1767 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1768 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1769 return CDRF_NOTIFYPOSTPAINT
;
1770 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1771 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1772 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1773 return CDRF_DODEFAULT
;
1775 return CDRF_DODEFAULT
;
1779 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1782 static void test_customdraw(void)
1787 hwnd
= create_listview_control(LVS_REPORT
);
1789 insert_column(hwnd
, 0);
1790 insert_column(hwnd
, 1);
1791 insert_item(hwnd
, 0);
1793 oldwndproc
= (WNDPROC
)SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
,
1794 (LONG_PTR
)cd_wndproc
);
1796 InvalidateRect(hwnd
, NULL
, TRUE
);
1799 SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1801 DestroyWindow(hwnd
);
1804 static void test_icon_spacing(void)
1806 /* LVM_SETICONSPACING */
1807 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1813 hwnd
= create_listview_control(LVS_ICON
);
1814 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1816 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, NF_REQUERY
);
1817 expect(NFR_ANSI
, r
);
1819 /* reset the icon spacing to defaults */
1820 SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1822 /* now we can request what the defaults are */
1823 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1827 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1829 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1830 ok(r
== MAKELONG(w
, h
) ||
1831 broken(r
== MAKELONG(w
, w
)), /* win98 */
1832 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1834 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1838 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1839 DestroyWindow(hwnd
);
1842 expect(MAKELONG(20,30), r
);
1844 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1845 expect(MAKELONG(25,35), r
);
1847 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1849 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1850 DestroyWindow(hwnd
);
1853 static void test_color(void)
1861 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1863 hwnd
= create_listview_control(LVS_REPORT
);
1864 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1866 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1868 for (i
= 0; i
< 4; i
++)
1872 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1874 r
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, 0);
1877 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1879 r
= SendMessage(hwnd
, LVM_GETTEXTCOLOR
, 0, 0);
1882 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1884 r
= SendMessage(hwnd
, LVM_GETTEXTBKCOLOR
, 0, 0);
1888 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1889 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1891 /* invalidation test done separately to avoid a message chain mess */
1892 r
= ValidateRect(hwnd
, NULL
);
1894 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, colors
[0]);
1897 rect
.right
= rect
.bottom
= 1;
1898 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1899 todo_wine
expect(FALSE
, r
);
1900 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1902 r
= ValidateRect(hwnd
, NULL
);
1904 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, colors
[0]);
1907 rect
.right
= rect
.bottom
= 1;
1908 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1909 todo_wine
expect(FALSE
, r
);
1910 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1912 r
= ValidateRect(hwnd
, NULL
);
1914 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, colors
[0]);
1917 rect
.right
= rect
.bottom
= 1;
1918 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1919 todo_wine
expect(FALSE
, r
);
1920 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1922 DestroyWindow(hwnd
);
1925 static void test_item_count(void)
1927 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1940 static CHAR item0text
[] = "item0";
1941 static CHAR item1text
[] = "item1";
1942 static CHAR item2text
[] = "item2";
1944 hwnd
= create_listview_control(LVS_REPORT
);
1945 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1947 /* resize in dpiaware manner to fit all 3 items added */
1949 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1950 GetTextMetricsA(hdc
, &tm
);
1951 /* 2 extra pixels for bounds and header border */
1952 height
= tm
.tmHeight
+ 2;
1953 SelectObject(hdc
, hOldFont
);
1956 GetWindowRect(hwnd
, &rect
);
1957 /* 3 items + 1 header + 1 to be sure */
1958 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1960 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1962 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1966 item0
.mask
= LVIF_TEXT
;
1969 item0
.pszText
= item0text
;
1970 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1973 /* [item0, item1] */
1974 item1
.mask
= LVIF_TEXT
;
1977 item1
.pszText
= item1text
;
1978 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1981 /* [item0, item1, item2] */
1982 item2
.mask
= LVIF_TEXT
;
1985 item2
.pszText
= item2text
;
1986 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1989 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1992 /* [item0, item1] */
1993 r
= SendMessage(hwnd
, LVM_DELETEITEM
, 2, 0);
1996 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2000 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
2003 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2007 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
2010 /* [item0, item1] */
2011 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
2014 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2017 /* [item0, item1, item2] */
2018 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
2021 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2024 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
2026 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2027 DestroyWindow(hwnd
);
2030 static void test_item_position(void)
2032 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2041 static CHAR item0text
[] = "item0";
2042 static CHAR item1text
[] = "item1";
2043 static CHAR item2text
[] = "item2";
2045 hwnd
= create_listview_control(LVS_ICON
);
2046 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2048 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2051 item0
.mask
= LVIF_TEXT
;
2054 item0
.pszText
= item0text
;
2055 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
2058 /* [item0, item1] */
2059 item1
.mask
= LVIF_TEXT
;
2062 item1
.pszText
= item1text
;
2063 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
2066 /* [item0, item1, item2] */
2067 item2
.mask
= LVIF_TEXT
;
2070 item2
.pszText
= item2text
;
2071 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
2074 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
2076 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
2078 expect2(10, 5, position
.x
, position
.y
);
2080 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
2082 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
2084 expect2(0, 0, position
.x
, position
.y
);
2086 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
2088 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
2090 expect2(20, 20, position
.x
, position
.y
);
2092 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
2094 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2095 DestroyWindow(hwnd
);
2098 static void test_getorigin(void)
2106 position
.x
= position
.y
= 0;
2108 hwnd
= create_listview_control(LVS_ICON
);
2109 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2110 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2112 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2114 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2115 DestroyWindow(hwnd
);
2117 hwnd
= create_listview_control(LVS_SMALLICON
);
2118 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2119 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2121 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2123 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2124 DestroyWindow(hwnd
);
2126 hwnd
= create_listview_control(LVS_LIST
);
2127 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2128 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2130 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2132 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2133 DestroyWindow(hwnd
);
2135 hwnd
= create_listview_control(LVS_REPORT
);
2136 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2137 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2139 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2141 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2142 DestroyWindow(hwnd
);
2145 static void test_multiselect(void)
2147 typedef struct t_select_task
2158 int i
,j
,item_count
,selected_count
;
2159 static const int items
=5;
2165 static struct t_select_task task_list
[] = {
2166 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
2167 { "using VK_UP", -1, VK_UP
, -1, -1 },
2168 { "using VK_END", 0, VK_END
, 1, -1 },
2169 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
2172 hwnd
= create_listview_control(LVS_REPORT
);
2174 for (i
= 0; i
< items
; i
++)
2175 insert_item(hwnd
, 0);
2177 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2178 expect(items
, item_count
);
2180 for (i
= 0; i
< 4; i
++) {
2183 task
= task_list
[i
];
2185 /* deselect all items */
2187 item
.stateMask
= LVIS_SELECTED
;
2188 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2189 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2191 /* set initial position */
2192 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
2194 item
.state
= LVIS_SELECTED
;
2195 item
.stateMask
= LVIS_SELECTED
;
2196 SendMessageA(hwnd
, LVM_SETITEMSTATE
, task
.initPos
== -1 ? item_count
-1 : task
.initPos
, (LPARAM
)&item
);
2198 selected_count
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2199 ok(selected_count
== 1, "expected 1, got %d\n", selected_count
);
2201 /* Set SHIFT key pressed */
2202 GetKeyboardState(kstate
);
2203 kstate
[VK_SHIFT
]=0x80;
2204 SetKeyboardState(kstate
);
2206 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
2207 r
= SendMessage(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
2209 r
= SendMessage(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
2213 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2215 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
);
2217 /* Set SHIFT key released */
2218 GetKeyboardState(kstate
);
2219 kstate
[VK_SHIFT
]=0x00;
2220 SetKeyboardState(kstate
);
2222 DestroyWindow(hwnd
);
2224 /* make multiple selection, then switch to LVS_SINGLESEL */
2225 hwnd
= create_listview_control(LVS_REPORT
);
2226 for (i
=0;i
<items
;i
++) {
2227 insert_item(hwnd
, 0);
2229 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2230 expect(items
,item_count
);
2232 /* try with NULL pointer */
2233 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, 0);
2236 /* select all, check notifications */
2238 item
.stateMask
= LVIS_SELECTED
;
2239 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2241 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2243 item
.stateMask
= LVIS_SELECTED
;
2244 item
.state
= LVIS_SELECTED
;
2245 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2248 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2249 "select all notification", FALSE
);
2251 /* select all again (all selected already) */
2252 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2254 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2256 item
.stateMask
= LVIS_SELECTED
;
2257 item
.state
= LVIS_SELECTED
;
2258 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2261 ok(g_nmlistview_changing
.uNewState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2262 ok(g_nmlistview_changing
.uOldState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2263 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2265 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2266 "select all notification 2", FALSE
);
2268 /* deselect all items */
2269 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2272 item
.stateMask
= LVIS_SELECTED
;
2273 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2275 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2276 "deselect all notification", FALSE
);
2278 /* deselect all items again */
2279 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2281 item
.stateMask
= LVIS_SELECTED
;
2282 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2283 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "deselect all notification 2", FALSE
);
2285 /* any non-zero state value does the same */
2286 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2288 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2290 item
.stateMask
= LVIS_SELECTED
;
2291 item
.state
= LVIS_CUT
;
2292 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2295 ok(g_nmlistview_changing
.uNewState
== 0, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2296 ok(g_nmlistview_changing
.uOldState
== 0, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2297 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2299 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2300 "set state all notification 3", FALSE
);
2302 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2303 for (i
= 0; i
< 3; i
++) {
2304 item
.state
= LVIS_SELECTED
;
2305 item
.stateMask
= LVIS_SELECTED
;
2306 SendMessageA(hwnd
, LVM_SETITEMSTATE
, i
, (LPARAM
)&item
);
2309 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2311 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2314 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2315 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2316 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2317 /* check that style is accepted */
2318 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2319 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2322 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2323 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2325 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2327 SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2330 /* select one more */
2331 item
.state
= LVIS_SELECTED
;
2332 item
.stateMask
= LVIS_SELECTED
;
2333 SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
2336 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2337 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2339 r
= ListView_GetItemState(hwnd
, 3, LVIS_SELECTED
);
2340 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2342 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2344 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2347 /* try to select all on LVS_SINGLESEL */
2348 memset(&item
, 0, sizeof(item
));
2349 item
.stateMask
= LVIS_SELECTED
;
2350 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2352 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2354 item
.stateMask
= LVIS_SELECTED
;
2355 item
.state
= LVIS_SELECTED
;
2356 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2359 r
= ListView_GetSelectedCount(hwnd
);
2361 r
= ListView_GetSelectionMark(hwnd
);
2364 /* try to deselect all on LVS_SINGLESEL */
2365 item
.stateMask
= LVIS_SELECTED
;
2366 item
.state
= LVIS_SELECTED
;
2367 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2370 item
.stateMask
= LVIS_SELECTED
;
2372 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2374 r
= ListView_GetSelectedCount(hwnd
);
2377 /* 1. selection mark is update when new focused item is set */
2378 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2379 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2381 r
= SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2384 item
.stateMask
= LVIS_FOCUSED
;
2385 item
.state
= LVIS_FOCUSED
;
2386 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2389 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2392 /* it's not updated if already set */
2393 item
.stateMask
= LVIS_FOCUSED
;
2394 item
.state
= LVIS_FOCUSED
;
2395 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2398 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2401 r
= SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2404 item
.stateMask
= LVIS_FOCUSED
;
2405 item
.state
= LVIS_FOCUSED
;
2406 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2409 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2412 /* need to reset focused item first */
2413 item
.stateMask
= LVIS_FOCUSED
;
2415 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2418 item
.stateMask
= LVIS_FOCUSED
;
2419 item
.state
= LVIS_FOCUSED
;
2420 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
2423 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2426 item
.stateMask
= LVIS_FOCUSED
;
2428 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2431 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2434 /* 2. same tests, with LVM_SETITEM */
2435 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2436 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2438 r
= SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2441 item
.stateMask
= LVIS_FOCUSED
;
2442 item
.state
= LVIS_FOCUSED
;
2443 item
.mask
= LVIF_STATE
;
2444 item
.iItem
= item
.iSubItem
= 0;
2445 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2448 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2451 /* it's not updated if already set */
2452 item
.stateMask
= LVIS_FOCUSED
;
2453 item
.state
= LVIS_FOCUSED
;
2454 item
.mask
= LVIF_STATE
;
2457 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2460 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2463 r
= SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2466 item
.stateMask
= LVIS_FOCUSED
;
2467 item
.state
= LVIS_FOCUSED
;
2468 item
.mask
= LVIF_STATE
;
2471 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2474 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2477 /* need to reset focused item first */
2478 item
.stateMask
= LVIS_FOCUSED
;
2480 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2483 item
.stateMask
= LVIS_FOCUSED
;
2484 item
.state
= LVIS_FOCUSED
;
2485 item
.mask
= LVIF_STATE
;
2488 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2491 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2494 item
.stateMask
= LVIS_FOCUSED
;
2496 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2499 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2502 DestroyWindow(hwnd
);
2505 static void test_subitem_rect(void)
2513 /* test LVM_GETSUBITEMRECT for header */
2514 hwnd
= create_listview_control(LVS_REPORT
);
2515 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2516 /* add some columns */
2517 memset(&col
, 0, sizeof(LVCOLUMN
));
2518 col
.mask
= LVCF_WIDTH
;
2520 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2523 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2526 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2528 /* item = -1 means header, subitem index is 1 based */
2529 rect
.left
= LVIR_BOUNDS
;
2531 rect
.right
= rect
.bottom
= 0;
2532 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2535 rect
.left
= LVIR_BOUNDS
;
2537 rect
.right
= rect
.bottom
= 0;
2538 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2541 expect(100, rect
.left
);
2542 expect(250, rect
.right
);
2543 expect(3, rect
.top
);
2545 rect
.left
= LVIR_BOUNDS
;
2547 rect
.right
= rect
.bottom
= 0;
2548 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2551 expect(250, rect
.left
);
2552 expect(450, rect
.right
);
2553 expect(3, rect
.top
);
2555 /* item LVS_REPORT padding isn't applied to subitems */
2556 insert_item(hwnd
, 0);
2558 rect
.left
= LVIR_BOUNDS
;
2560 rect
.right
= rect
.bottom
= 0;
2561 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2563 expect(100, rect
.left
);
2564 expect(250, rect
.right
);
2566 rect
.left
= LVIR_ICON
;
2568 rect
.right
= rect
.bottom
= 0;
2569 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2571 /* no icon attached - zero width rectangle, with no left padding */
2572 expect(100, rect
.left
);
2573 expect(100, rect
.right
);
2575 rect
.left
= LVIR_LABEL
;
2577 rect
.right
= rect
.bottom
= 0;
2578 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2580 /* same as full LVIR_BOUNDS */
2581 expect(100, rect
.left
);
2582 expect(250, rect
.right
);
2584 SendMessage(hwnd
, LVM_SCROLL
, 10, 0);
2586 rect
.left
= LVIR_BOUNDS
;
2588 rect
.right
= rect
.bottom
= 0;
2589 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2591 expect(90, rect
.left
);
2592 expect(240, rect
.right
);
2594 SendMessage(hwnd
, LVM_SCROLL
, -10, 0);
2596 /* test header interaction */
2597 subclass_header(hwnd
);
2598 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2600 rect
.left
= LVIR_BOUNDS
;
2602 rect
.right
= rect
.bottom
= 0;
2603 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2606 rect
.left
= LVIR_BOUNDS
;
2608 rect
.right
= rect
.bottom
= 0;
2609 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2612 rect
.left
= LVIR_BOUNDS
;
2614 rect
.right
= rect
.bottom
= 0;
2615 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -10, (LPARAM
)&rect
);
2618 rect
.left
= LVIR_BOUNDS
;
2620 rect
.right
= rect
.bottom
= 0;
2621 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 20, (LPARAM
)&rect
);
2624 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getsubitemrect_seq
, "LVM_GETSUBITEMRECT negative index", FALSE
);
2626 DestroyWindow(hwnd
);
2628 /* test subitem rects after re-arranging columns */
2629 hwnd
= create_listview_control(LVS_REPORT
);
2630 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2631 memset(&col
, 0, sizeof(LVCOLUMN
));
2632 col
.mask
= LVCF_WIDTH
;
2635 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2639 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2643 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2646 insert_item(hwnd
, 0);
2647 insert_item(hwnd
, 1);
2649 /* wrong item is refused for main item */
2650 rect
.left
= LVIR_BOUNDS
;
2652 rect
.right
= rect
.bottom
= -1;
2653 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect
);
2656 /* for subitems rectangle is calculated even if there's no item added */
2657 rect
.left
= LVIR_BOUNDS
;
2659 rect
.right
= rect
.bottom
= -1;
2660 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect
);
2663 rect2
.left
= LVIR_BOUNDS
;
2665 rect2
.right
= rect2
.bottom
= -1;
2666 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect2
);
2668 expect(rect
.right
, rect2
.right
);
2669 expect(rect
.left
, rect2
.left
);
2670 expect(rect
.bottom
, rect2
.top
);
2671 ok(rect2
.bottom
> rect2
.top
, "expected not zero height\n");
2673 arr
[0] = 1; arr
[1] = 0; arr
[2] = 2;
2674 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 3, (LPARAM
)arr
);
2677 rect
.left
= LVIR_BOUNDS
;
2679 rect
.right
= rect
.bottom
= -1;
2680 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2682 expect(0, rect
.left
);
2683 expect(600, rect
.right
);
2685 rect
.left
= LVIR_BOUNDS
;
2687 rect
.right
= rect
.bottom
= -1;
2688 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2690 expect(0, rect
.left
);
2691 expect(200, rect
.right
);
2693 rect2
.left
= LVIR_BOUNDS
;
2695 rect2
.right
= rect2
.bottom
= -1;
2696 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect2
);
2698 expect(0, rect2
.left
);
2699 expect(200, rect2
.right
);
2700 /* items are of the same height */
2701 ok(rect2
.top
> 0, "expected positive item height\n");
2702 expect(rect
.bottom
, rect2
.top
);
2703 expect(rect
.bottom
* 2 - rect
.top
, rect2
.bottom
);
2705 rect
.left
= LVIR_BOUNDS
;
2707 rect
.right
= rect
.bottom
= -1;
2708 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2710 expect(300, rect
.left
);
2711 expect(600, rect
.right
);
2713 DestroyWindow(hwnd
);
2715 /* try it for non LVS_REPORT style */
2716 hwnd
= CreateWindow("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2717 GetModuleHandle(NULL
), 0);
2718 rect
.left
= LVIR_BOUNDS
;
2720 rect
.right
= rect
.bottom
= -10;
2721 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2723 /* rect is unchanged */
2724 expect(0, rect
.left
);
2725 expect(-10, rect
.right
);
2726 expect(1, rect
.top
);
2727 expect(-10, rect
.bottom
);
2728 DestroyWindow(hwnd
);
2731 /* comparison callback for test_sorting */
2732 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2734 if (first
== second
) return 0;
2735 return (first
> second
? 1 : -1);
2738 static void test_sorting(void)
2744 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2747 hwnd
= create_listview_control(LVS_REPORT
);
2748 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2750 /* insert some items */
2751 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2752 item
.state
= LVIS_SELECTED
;
2756 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2759 item
.mask
= LVIF_PARAM
;
2763 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2766 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2767 item
.state
= LVIS_SELECTED
;
2771 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2774 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2777 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2780 r
= SendMessage(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2783 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2785 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2787 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2789 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2790 expect(LVIS_SELECTED
, r
);
2791 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2792 expect(LVIS_SELECTED
, r
);
2794 DestroyWindow(hwnd
);
2796 /* switch to LVS_SORTASCENDING when some items added */
2797 hwnd
= create_listview_control(LVS_REPORT
);
2798 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2800 item
.mask
= LVIF_TEXT
;
2803 item
.pszText
= names
[1];
2804 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2807 item
.mask
= LVIF_TEXT
;
2810 item
.pszText
= names
[2];
2811 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2814 item
.mask
= LVIF_TEXT
;
2817 item
.pszText
= names
[0];
2818 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2821 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2822 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2823 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2824 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2826 /* no sorting performed when switched to LVS_SORTASCENDING */
2827 item
.mask
= LVIF_TEXT
;
2829 item
.pszText
= buff
;
2830 item
.cchTextMax
= sizeof(buff
);
2831 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2833 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2836 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2838 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2841 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2843 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2845 /* adding new item doesn't resort list */
2846 item
.mask
= LVIF_TEXT
;
2849 item
.pszText
= names
[3];
2850 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2853 item
.mask
= LVIF_TEXT
;
2855 item
.pszText
= buff
;
2856 item
.cchTextMax
= sizeof(buff
);
2857 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2859 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2862 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2864 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2867 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2869 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2872 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2874 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2876 /* corner case - item should be placed at first position */
2877 item
.mask
= LVIF_TEXT
;
2880 item
.pszText
= names
[4];
2881 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2885 item
.pszText
= buff
;
2886 item
.cchTextMax
= sizeof(buff
);
2887 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2889 ok(lstrcmp(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2892 item
.pszText
= buff
;
2893 item
.cchTextMax
= sizeof(buff
);
2894 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2896 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2899 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2901 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2904 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2906 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2909 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2911 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2913 DestroyWindow(hwnd
);
2916 static void test_ownerdata(void)
2918 static char test_str
[] = "test";
2921 LONG_PTR style
, ret
;
2925 /* it isn't possible to set LVS_OWNERDATA after creation */
2928 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2932 hwnd
= create_listview_control(LVS_REPORT
);
2933 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2934 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2935 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2937 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2939 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2940 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2941 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2942 "try to switch to LVS_OWNERDATA seq", FALSE
);
2944 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2945 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2946 DestroyWindow(hwnd
);
2949 /* try to set LVS_OWNERDATA after creation just having it */
2950 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2951 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2952 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2953 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2955 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2957 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2958 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2959 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2960 "try to switch to LVS_OWNERDATA seq", FALSE
);
2961 DestroyWindow(hwnd
);
2963 /* try to remove LVS_OWNERDATA after creation just having it */
2966 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2970 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2971 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2972 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2973 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2975 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2977 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2978 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2979 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2980 "try to switch to LVS_OWNERDATA seq", FALSE
);
2981 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2982 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2983 DestroyWindow(hwnd
);
2986 /* try select an item */
2987 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2988 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2989 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2991 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2993 memset(&item
, 0, sizeof(item
));
2994 item
.stateMask
= LVIS_SELECTED
;
2995 item
.state
= LVIS_SELECTED
;
2996 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2998 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
3000 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3002 DestroyWindow(hwnd
);
3004 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
3005 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3006 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3007 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3009 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3011 memset(&item
, 0, sizeof(item
));
3012 item
.mask
= LVIF_STATE
;
3014 item
.stateMask
= LVIS_SELECTED
;
3015 item
.state
= LVIS_SELECTED
;
3016 res
= SendMessageA(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3018 memset(&item
, 0, sizeof(item
));
3019 item
.pszText
= test_str
;
3020 res
= SendMessageA(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
3022 DestroyWindow(hwnd
);
3024 /* check notifications after focused/selected changed */
3025 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3026 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3027 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
3030 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3032 memset(&item
, 0, sizeof(item
));
3033 item
.stateMask
= LVIS_SELECTED
;
3034 item
.state
= LVIS_SELECTED
;
3035 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3038 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
3039 "ownerdata select notification", TRUE
);
3041 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3043 memset(&item
, 0, sizeof(item
));
3044 item
.stateMask
= LVIS_FOCUSED
;
3045 item
.state
= LVIS_FOCUSED
;
3046 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3049 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
3050 "ownerdata focus notification", TRUE
);
3052 /* select all, check notifications */
3053 item
.stateMask
= LVIS_SELECTED
;
3055 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3058 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3060 item
.stateMask
= LVIS_SELECTED
;
3061 item
.state
= LVIS_SELECTED
;
3063 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3064 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3066 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3067 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3068 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3069 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3070 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3071 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3072 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3074 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3075 "ownerdata select all notification", FALSE
);
3077 /* select all again, note that all items are selected already */
3078 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3079 item
.stateMask
= LVIS_SELECTED
;
3080 item
.state
= LVIS_SELECTED
;
3082 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3083 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3085 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3086 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3087 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3088 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3089 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3090 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3091 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3093 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3094 "ownerdata select all notification", FALSE
);
3097 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3098 item
.stateMask
= LVIS_SELECTED
;
3101 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3102 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3104 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3105 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3106 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3107 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3108 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3109 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3110 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3112 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3113 "ownerdata deselect all notification", TRUE
);
3115 /* nothing selected, deselect all again */
3116 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3117 item
.stateMask
= LVIS_SELECTED
;
3120 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3123 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "ownerdata deselect all notification", FALSE
);
3125 /* select one, then deselect all */
3126 item
.stateMask
= LVIS_SELECTED
;
3127 item
.state
= LVIS_SELECTED
;
3128 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3130 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3131 item
.stateMask
= LVIS_SELECTED
;
3134 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3135 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3137 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3138 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3139 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3140 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3141 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3142 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3143 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3145 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3146 "ownerdata select all notification", TRUE
);
3148 /* remove focused, try to focus all */
3149 item
.stateMask
= LVIS_FOCUSED
;
3150 item
.state
= LVIS_FOCUSED
;
3151 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3153 item
.stateMask
= LVIS_FOCUSED
;
3155 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3157 item
.stateMask
= LVIS_FOCUSED
;
3158 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
3161 /* setting all to focused returns failure value */
3162 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3163 item
.stateMask
= LVIS_FOCUSED
;
3164 item
.state
= LVIS_FOCUSED
;
3166 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3169 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3170 "ownerdata focus all notification", FALSE
);
3172 /* focus single item, remove all */
3173 item
.stateMask
= LVIS_FOCUSED
;
3174 item
.state
= LVIS_FOCUSED
;
3175 res
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3177 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3178 item
.stateMask
= LVIS_FOCUSED
;
3181 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3182 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3184 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3185 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3186 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3187 ok(g_nmlistview
.uOldState
== LVIS_FOCUSED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3188 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3189 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3190 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3192 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
3193 "ownerdata remove focus all notification", TRUE
);
3196 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3197 item
.stateMask
= LVIS_CUT
;
3198 item
.state
= LVIS_CUT
;
3200 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3201 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3203 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3204 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3205 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3206 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3207 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3208 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3209 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3211 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3212 "ownerdata cut all notification", FALSE
);
3214 /* all marked cut, try again */
3215 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3216 item
.stateMask
= LVIS_CUT
;
3217 item
.state
= LVIS_CUT
;
3219 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3220 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3222 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3223 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3224 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3225 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3226 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3227 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3228 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3230 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3231 "ownerdata cut all notification #2", FALSE
);
3233 DestroyWindow(hwnd
);
3235 /* check notifications on LVM_GETITEM */
3236 /* zero callback mask */
3237 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3238 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3239 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3242 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3244 memset(&item
, 0, sizeof(item
));
3245 item
.stateMask
= LVIS_SELECTED
;
3246 item
.mask
= LVIF_STATE
;
3247 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3250 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3251 "ownerdata getitem selected state 1", FALSE
);
3253 /* non zero callback mask but not we asking for */
3254 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
3257 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3259 memset(&item
, 0, sizeof(item
));
3260 item
.stateMask
= LVIS_SELECTED
;
3261 item
.mask
= LVIF_STATE
;
3262 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3265 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3266 "ownerdata getitem selected state 2", FALSE
);
3268 /* LVIS_OVERLAYMASK callback mask, asking for index */
3269 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3271 memset(&item
, 0, sizeof(item
));
3272 item
.stateMask
= LVIS_OVERLAYMASK
;
3273 item
.mask
= LVIF_STATE
;
3274 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3277 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3278 "ownerdata getitem selected state 2", FALSE
);
3280 DestroyWindow(hwnd
);
3282 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3283 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
| LVS_REPORT
);
3284 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3285 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3286 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3287 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3288 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
3289 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3290 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
3291 DestroyWindow(hwnd
);
3292 /* apparently it's allowed to switch these style on after creation */
3293 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3294 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3295 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3296 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3297 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
3298 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3299 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3300 DestroyWindow(hwnd
);
3302 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3303 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3304 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3305 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3306 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
3307 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3308 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
3309 DestroyWindow(hwnd
);
3312 static void test_norecompute(void)
3314 static CHAR testA
[] = "test";
3320 /* self containing control */
3321 hwnd
= create_listview_control(LVS_REPORT
);
3322 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3323 memset(&item
, 0, sizeof(item
));
3324 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
3326 item
.stateMask
= LVIS_SELECTED
;
3327 item
.state
= LVIS_SELECTED
;
3328 item
.pszText
= testA
;
3329 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
3331 /* retrieve with LVIF_NORECOMPUTE */
3332 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3334 item
.pszText
= buff
;
3335 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3336 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3338 ok(lstrcmp(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
3340 item
.mask
= LVIF_TEXT
;
3342 item
.pszText
= LPSTR_TEXTCALLBACK
;
3343 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
3346 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3348 item
.pszText
= buff
;
3349 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3351 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3352 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3354 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
3355 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
3356 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
3358 DestroyWindow(hwnd
);
3361 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3362 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3364 item
.mask
= LVIF_STATE
;
3365 item
.stateMask
= LVIS_SELECTED
;
3366 item
.state
= LVIS_SELECTED
;
3368 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
3371 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3373 item
.pszText
= buff
;
3374 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3375 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3376 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3378 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
3379 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
3380 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
3382 DestroyWindow(hwnd
);
3385 static void test_nosortheader(void)
3390 hwnd
= create_listview_control(LVS_REPORT
);
3391 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3393 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3394 ok(IsWindow(header
), "header expected\n");
3396 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3397 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
3399 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3400 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
3401 /* HDS_BUTTONS retained */
3402 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3403 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
3405 DestroyWindow(hwnd
);
3407 /* create with LVS_NOSORTHEADER */
3408 hwnd
= create_listview_control(LVS_NOSORTHEADER
| LVS_REPORT
);
3409 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3411 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3412 ok(IsWindow(header
), "header expected\n");
3414 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3415 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3417 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3418 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
3419 /* not changed here */
3420 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3421 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3423 DestroyWindow(hwnd
);
3426 static void test_setredraw(void)
3434 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3435 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3437 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3438 ListView seems to handle it internally without DefWinProc */
3440 /* default value first */
3441 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3444 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3445 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3446 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3448 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3449 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3450 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3453 /* check update rect after redrawing */
3454 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3456 InvalidateRect(hwnd
, NULL
, FALSE
);
3457 RedrawWindow(hwnd
, NULL
, NULL
, RDW_UPDATENOW
);
3458 rect
.right
= rect
.bottom
= 1;
3459 GetUpdateRect(hwnd
, &rect
, FALSE
);
3460 expect(0, rect
.right
);
3461 expect(0, rect
.bottom
);
3464 hdc
= GetWindowDC(hwndparent
);
3465 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3467 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3469 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3471 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3473 ReleaseDC(hwndparent
, hdc
);
3475 /* check notification messages to show that repainting is disabled */
3476 ret
= SendMessage(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3478 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3480 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3482 InvalidateRect(hwnd
, NULL
, TRUE
);
3484 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3485 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
3487 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
3489 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3490 InvalidateRect(hwnd
, NULL
, TRUE
);
3492 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3493 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
3495 /* message isn't forwarded to header */
3496 subclass_header(hwnd
);
3497 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3498 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3500 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
3501 "WM_SETREDRAW: not forwarded to header", FALSE
);
3503 DestroyWindow(hwnd
);
3506 static void test_hittest(void)
3512 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3516 HIMAGELIST himl
, himl2
;
3519 hwnd
= create_listview_control(LVS_REPORT
);
3520 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3522 /* LVS_REPORT with a single subitem (2 columns) */
3523 insert_column(hwnd
, 0);
3524 insert_column(hwnd
, 1);
3525 insert_item(hwnd
, 0);
3528 /* the only purpose of that line is to be as long as a half item rect */
3529 item
.pszText
= text
;
3530 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
3533 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3535 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3538 memset(&bounds
, 0, sizeof(bounds
));
3539 bounds
.left
= LVIR_BOUNDS
;
3540 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
3542 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
3543 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
3544 r
= SendMessage(hwnd
, LVM_GETITEMSPACING
, TRUE
, 0);
3546 ok(bounds
.bottom
- bounds
.top
== vert
,
3547 "Vertical spacing inconsistent (%d != %d)\n", bounds
.bottom
- bounds
.top
, vert
);
3548 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
3551 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3553 /* outside columns by x position - valid is [0, 199] */
3555 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3556 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TOLEFT
, 0, FALSE
, FALSE
);
3557 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3559 x
= pos
.x
+ 50; /* column half width */
3560 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3561 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, 0, FALSE
, FALSE
);
3562 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3563 x
= pos
.x
+ 150; /* outside column */
3564 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3565 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3566 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3567 y
= (bounds
.bottom
- bounds
.top
) / 2;
3568 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3569 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3570 /* outside possible client rectangle (to right) */
3572 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3573 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3574 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3575 y
= (bounds
.bottom
- bounds
.top
) / 2;
3576 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3577 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3578 /* subitem returned with -1 item too */
3580 y
= bounds
.top
- vert
;
3581 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3582 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3583 /* return values appear to underflow with negative indices */
3587 test_lvm_subitemhittest(hwnd
, x
, y
, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3588 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3592 /* parent client area is 100x100 by default */
3593 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
3594 x
= pos
.x
+ 150; /* outside column */
3595 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3596 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, FALSE
);
3597 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3598 y
= (bounds
.bottom
- bounds
.top
) / 2;
3599 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, TRUE
);
3600 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3601 /* the same with LVS_EX_FULLROWSELECT */
3602 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3603 x
= pos
.x
+ 150; /* outside column */
3604 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3605 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, LVHT_ONITEMLABEL
, FALSE
, FALSE
);
3606 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3607 y
= (bounds
.bottom
- bounds
.top
) / 2;
3608 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3609 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
3610 x
= pos
.x
+ 150; /* outside column */
3611 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3612 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3613 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3614 y
= (bounds
.bottom
- bounds
.top
) / 2;
3615 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3616 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3617 /* outside possible client rectangle (to right) */
3619 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3620 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3621 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3622 y
= (bounds
.bottom
- bounds
.top
) / 2;
3623 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3624 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3625 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3626 himl
= ImageList_Create(16, 16, 0, 4, 4);
3627 ok(himl
!= NULL
, "failed to create imagelist\n");
3628 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3629 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3630 r
= ImageList_Add(himl
, hbmp
, 0);
3631 ok(r
== 0, "should be zero\n");
3632 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3633 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3634 r
= ImageList_Add(himl
, hbmp
, 0);
3635 ok(r
== 1, "should be one\n");
3637 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3640 item
.mask
= LVIF_IMAGE
;
3644 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3648 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3649 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3650 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3651 y
= (bounds
.bottom
- bounds
.top
) / 2;
3652 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3654 /* state icons indices are 1 based, check with valid index */
3655 item
.mask
= LVIF_STATE
;
3656 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3657 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3660 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3664 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3665 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3666 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3667 y
= (bounds
.bottom
- bounds
.top
) / 2;
3668 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3670 himl2
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3671 ok(himl2
== himl
, "should return handle\n");
3673 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3677 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3678 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, 0, FALSE
, FALSE
);
3679 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3680 y
= (bounds
.bottom
- bounds
.top
) / 2;
3681 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3683 DestroyWindow(hwnd
);
3686 static void test_getviewrect(void)
3693 hwnd
= create_listview_control(LVS_REPORT
);
3694 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3697 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3700 insert_column(hwnd
, 0);
3701 insert_column(hwnd
, 1);
3703 memset(&item
, 0, sizeof(item
));
3706 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3708 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3710 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3713 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3714 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3716 /* left is set to (2e31-1) - XP SP2 */
3717 expect(0, rect
.right
);
3718 expect(0, rect
.top
);
3719 expect(0, rect
.bottom
);
3721 /* switch to LVS_ICON */
3722 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3724 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3725 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3727 expect(0, rect
.left
);
3728 expect(0, rect
.top
);
3729 /* precise value differs for 2k, XP and Vista */
3730 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3731 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3733 DestroyWindow(hwnd
);
3736 static void test_getitemposition(void)
3743 hwnd
= create_listview_control(LVS_REPORT
);
3744 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3745 header
= subclass_header(hwnd
);
3747 /* LVS_REPORT, single item, no columns added */
3748 insert_item(hwnd
, 0);
3750 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3753 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3755 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3757 /* LVS_REPORT, single item, single column */
3758 insert_column(hwnd
, 0);
3760 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3763 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3765 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3767 memset(&rect
, 0, sizeof(rect
));
3768 SendMessage(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3771 /* offset by header height */
3772 expect(rect
.bottom
- rect
.top
, pt
.y
);
3774 DestroyWindow(hwnd
);
3777 static void test_columnscreation(void)
3782 hwnd
= create_listview_control(LVS_REPORT
);
3783 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3785 insert_item(hwnd
, 0);
3787 /* headers columns aren't created automatically */
3788 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3789 ok(IsWindow(header
), "Expected header handle\n");
3790 r
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
3793 DestroyWindow(hwnd
);
3796 static void test_getitemrect(void)
3799 HIMAGELIST himl
, himl_ret
;
3809 /* rectangle isn't empty for empty text items */
3810 hwnd
= create_listview_control(LVS_LIST
);
3811 memset(&item
, 0, sizeof(item
));
3814 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3816 rect
.left
= LVIR_LABEL
;
3817 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3819 expect(0, rect
.left
);
3820 expect(0, rect
.top
);
3822 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, rect
.right
);
3823 ReleaseDC(hwnd
, hdc
);
3824 DestroyWindow(hwnd
);
3826 hwnd
= create_listview_control(LVS_REPORT
);
3827 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3830 memset(&item
, 0, sizeof(item
));
3833 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3836 rect
.left
= LVIR_BOUNDS
;
3837 rect
.right
= rect
.top
= rect
.bottom
= -1;
3838 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3841 /* zero width rectangle with no padding */
3842 expect(0, rect
.left
);
3843 expect(0, rect
.right
);
3845 insert_column(hwnd
, 0);
3846 insert_column(hwnd
, 1);
3848 col
.mask
= LVCF_WIDTH
;
3850 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 0, (LPARAM
)&col
);
3853 col
.mask
= LVCF_WIDTH
;
3855 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 1, (LPARAM
)&col
);
3858 rect
.left
= LVIR_BOUNDS
;
3859 rect
.right
= rect
.top
= rect
.bottom
= -1;
3860 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3863 /* still no left padding */
3864 expect(0, rect
.left
);
3865 expect(150, rect
.right
);
3867 rect
.left
= LVIR_SELECTBOUNDS
;
3868 rect
.right
= rect
.top
= rect
.bottom
= -1;
3869 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3872 expect(2, rect
.left
);
3874 rect
.left
= LVIR_LABEL
;
3875 rect
.right
= rect
.top
= rect
.bottom
= -1;
3876 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3878 /* padding, column width */
3879 expect(2, rect
.left
);
3880 expect(50, rect
.right
);
3882 /* no icons attached */
3883 rect
.left
= LVIR_ICON
;
3884 rect
.right
= rect
.top
= rect
.bottom
= -1;
3885 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3888 expect(2, rect
.left
);
3889 expect(2, rect
.right
);
3892 order
[0] = 1; order
[1] = 0;
3893 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3896 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3898 /* 1 indexed column width + padding */
3900 /* rect is at zero too */
3901 rect
.left
= LVIR_BOUNDS
;
3902 rect
.right
= rect
.top
= rect
.bottom
= -1;
3903 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3905 expect(0, rect
.left
);
3906 /* just width sum */
3907 expect(150, rect
.right
);
3909 rect
.left
= LVIR_SELECTBOUNDS
;
3910 rect
.right
= rect
.top
= rect
.bottom
= -1;
3911 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3913 /* column width + padding */
3914 expect(102, rect
.left
);
3916 /* back to initial order */
3917 order
[0] = 0; order
[1] = 1;
3918 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3922 himl
= ImageList_Create(16, 16, 0, 2, 2);
3923 ok(himl
!= NULL
, "failed to create imagelist\n");
3924 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3925 ok(hbm
!= NULL
, "failed to create bitmap\n");
3926 r
= ImageList_Add(himl
, hbm
, 0);
3928 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3929 ok(hbm
!= NULL
, "failed to create bitmap\n");
3930 r
= ImageList_Add(himl
, hbm
, 0);
3933 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3936 item
.mask
= LVIF_STATE
;
3937 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3938 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3941 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3945 rect
.left
= LVIR_ICON
;
3946 rect
.right
= rect
.top
= rect
.bottom
= -1;
3947 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3949 /* padding + stateicon width */
3950 expect(18, rect
.left
);
3951 expect(18, rect
.right
);
3953 rect
.left
= LVIR_LABEL
;
3954 rect
.right
= rect
.top
= rect
.bottom
= -1;
3955 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3957 /* padding + stateicon width -> column width */
3958 expect(18, rect
.left
);
3959 expect(50, rect
.right
);
3961 himl_ret
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3962 ok(himl_ret
== himl
, "got %p, expected %p\n", himl_ret
, himl
);
3964 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3967 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3970 item
.stateMask
= ~0;
3973 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3977 rect
.left
= LVIR_ICON
;
3978 rect
.right
= rect
.top
= rect
.bottom
= -1;
3979 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3981 /* padding, icon width */
3982 expect(2, rect
.left
);
3983 expect(18, rect
.right
);
3985 rect
.left
= LVIR_LABEL
;
3986 rect
.right
= rect
.top
= rect
.bottom
= -1;
3987 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3989 /* padding + icon width -> column width */
3990 expect(18, rect
.left
);
3991 expect(50, rect
.right
);
3994 rect
.left
= LVIR_SELECTBOUNDS
;
3995 rect
.right
= rect
.top
= rect
.bottom
= -1;
3996 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3998 /* padding, column width */
3999 expect(2, rect
.left
);
4000 expect(50, rect
.right
);
4002 /* try with indentation */
4003 item
.mask
= LVIF_INDENT
;
4007 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
4011 rect
.left
= LVIR_BOUNDS
;
4012 rect
.right
= rect
.top
= rect
.bottom
= -1;
4013 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4015 /* padding + 1 icon width, column width */
4016 expect(0, rect
.left
);
4017 expect(150, rect
.right
);
4020 rect
.left
= LVIR_SELECTBOUNDS
;
4021 rect
.right
= rect
.top
= rect
.bottom
= -1;
4022 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4024 /* padding + 1 icon width, column width */
4025 expect(2 + 16, rect
.left
);
4026 expect(50, rect
.right
);
4029 rect
.left
= LVIR_LABEL
;
4030 rect
.right
= rect
.top
= rect
.bottom
= -1;
4031 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4033 /* padding + 2 icon widths, column width */
4034 expect(2 + 16*2, rect
.left
);
4035 expect(50, rect
.right
);
4038 rect
.left
= LVIR_ICON
;
4039 rect
.right
= rect
.top
= rect
.bottom
= -1;
4040 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4042 /* padding + 1 icon width indentation, icon width */
4043 expect(2 + 16, rect
.left
);
4044 expect(34, rect
.right
);
4046 DestroyWindow(hwnd
);
4049 static void test_editbox(void)
4051 static CHAR testitemA
[] = "testitem";
4052 static CHAR testitem1A
[] = "testitem_quitelongname";
4053 static CHAR testitem2A
[] = "testITEM_quitelongname";
4054 static CHAR buffer
[25];
4055 HWND hwnd
, hwndedit
, hwndedit2
, header
;
4059 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4060 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4062 insert_column(hwnd
, 0);
4064 memset(&item
, 0, sizeof(item
));
4065 item
.mask
= LVIF_TEXT
;
4066 item
.pszText
= testitemA
;
4069 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4072 /* test notifications without edit created */
4073 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4074 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)0xdeadbeef);
4076 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4077 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE
);
4078 /* same thing but with valid window */
4079 hwndedit
= CreateWindowA("Edit", "Test edit", WS_VISIBLE
| WS_CHILD
, 0, 0, 20,
4080 10, hwnd
, (HMENU
)1, (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
), 0);
4081 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4082 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)hwndedit
);
4084 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4085 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE
);
4086 DestroyWindow(hwndedit
);
4088 /* setting focus is necessary */
4090 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4091 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4093 /* test children Z-order after Edit box created */
4094 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4095 ok(IsWindow(header
), "Expected header to be created\n");
4096 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4097 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4099 /* modify initial string */
4100 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4103 /* edit window is resized and repositioned,
4104 check again for Z-order - it should be preserved */
4105 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4106 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4108 /* return focus to listview */
4111 memset(&item
, 0, sizeof(item
));
4112 item
.mask
= LVIF_TEXT
;
4113 item
.pszText
= buffer
;
4114 item
.cchTextMax
= sizeof(buffer
);
4117 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
4120 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4122 /* send LVM_EDITLABEL on already created edit */
4124 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4125 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4126 /* focus will be set to edit */
4127 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
4128 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4129 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
4131 /* creating label disabled when control isn't focused */
4133 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4134 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4136 /* check EN_KILLFOCUS handling */
4137 memset(&item
, 0, sizeof(item
));
4138 item
.pszText
= testitemA
;
4141 r
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
4145 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4146 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4147 /* modify edit and notify control that it lost focus */
4148 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4150 g_editbox_disp_info
.item
.pszText
= NULL
;
4151 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4153 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "expected notification with not null text\n");
4155 memset(&item
, 0, sizeof(item
));
4156 item
.pszText
= buffer
;
4157 item
.cchTextMax
= sizeof(buffer
);
4160 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4161 expect(lstrlen(item
.pszText
), r
);
4162 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4163 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4165 /* change item name to differ in casing only */
4167 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4168 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4169 /* modify edit and notify control that it lost focus */
4170 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem2A
);
4172 g_editbox_disp_info
.item
.pszText
= NULL
;
4173 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4175 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "got %p\n", g_editbox_disp_info
.item
.pszText
);
4177 memset(&item
, 0, sizeof(item
));
4178 item
.pszText
= buffer
;
4179 item
.cchTextMax
= sizeof(buffer
);
4182 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4183 expect(lstrlen(item
.pszText
), r
);
4184 ok(strcmp(buffer
, testitem2A
) == 0, "got %s, expected %s\n", buffer
, testitem2A
);
4185 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4187 /* end edit without saving */
4189 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4190 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4191 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
4193 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4194 "edit box - end edit, no change, escape", TRUE
);
4195 /* end edit with saving */
4197 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4198 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4199 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_RETURN
, 0);
4201 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4202 "edit box - end edit, no change, return", TRUE
);
4204 memset(&item
, 0, sizeof(item
));
4205 item
.pszText
= buffer
;
4206 item
.cchTextMax
= sizeof(buffer
);
4209 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4210 expect(lstrlen(item
.pszText
), r
);
4211 ok(strcmp(buffer
, testitem2A
) == 0, "Expected item text to change\n");
4213 /* LVM_EDITLABEL with -1 destroys current edit */
4214 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
4215 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4216 /* no edit present */
4217 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
4218 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4219 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4220 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4222 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4223 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
4224 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4225 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4226 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4227 /* check another negative value */
4228 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4229 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4230 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4231 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -2, 0);
4232 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4233 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4234 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4235 /* and value greater than max item index */
4236 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4237 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4238 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4239 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
4240 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, r
, 0);
4241 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4242 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4243 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4245 /* messaging tests */
4247 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4249 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4250 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4251 /* testing only sizing messages */
4252 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
4253 "edit box create - sizing", FALSE
);
4255 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4257 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4258 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4259 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4260 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4262 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4263 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE
);
4265 DestroyWindow(hwnd
);
4268 static void test_notifyformat(void)
4273 hwnd
= create_listview_control(LVS_REPORT
);
4274 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4276 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4277 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4278 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4280 SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4282 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
4284 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4287 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
4289 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4294 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4295 DestroyWindow(hwnd
);
4299 DestroyWindow(hwnd
);
4301 /* test failure in parent WM_NOTIFYFORMAT */
4303 hwnd
= create_listview_control(LVS_REPORT
);
4304 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4305 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4306 ok(IsWindow(header
), "expected header to be created\n");
4307 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4309 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4310 ok( r
== 1, "Expected 1, got %d\n", r
);
4311 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4312 ok(r
!= 0, "Expected valid format\n");
4314 notifyFormat
= NFR_UNICODE
;
4315 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4316 expect(NFR_UNICODE
, r
);
4317 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4319 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4320 ok( r
== 1, "Expected 1, got %d\n", r
);
4322 notifyFormat
= NFR_ANSI
;
4323 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4324 expect(NFR_ANSI
, r
);
4325 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4327 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4328 ok( r
== 1, "Expected 1, got %d\n", r
);
4330 DestroyWindow(hwnd
);
4332 hwndparentW
= create_parent_window(TRUE
);
4333 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
4334 if (!IsWindow(hwndparentW
)) return;
4337 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4338 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4339 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4340 ok(IsWindow(header
), "expected header to be created\n");
4341 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4343 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4345 DestroyWindow(hwnd
);
4346 /* receiving error code defaulting to ansi */
4348 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4349 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4350 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4351 ok(IsWindow(header
), "expected header to be created\n");
4352 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4354 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4356 DestroyWindow(hwnd
);
4357 /* receiving ansi code from unicode window, use it */
4358 notifyFormat
= NFR_ANSI
;
4359 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4360 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4361 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4362 ok(IsWindow(header
), "expected header to be created\n");
4363 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4365 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4367 DestroyWindow(hwnd
);
4368 /* unicode listview with ansi parent window */
4370 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4371 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4372 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4373 ok(IsWindow(header
), "expected header to be created\n");
4374 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4376 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4378 DestroyWindow(hwnd
);
4379 /* unicode listview with ansi parent window, return error code */
4381 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4382 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4383 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4384 ok(IsWindow(header
), "expected header to be created\n");
4385 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4387 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4389 DestroyWindow(hwnd
);
4391 DestroyWindow(hwndparentW
);
4394 static void test_indentation(void)
4400 hwnd
= create_listview_control(LVS_REPORT
);
4401 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4403 memset(&item
, 0, sizeof(item
));
4404 item
.mask
= LVIF_INDENT
;
4406 item
.iIndent
= I_INDENTCALLBACK
;
4407 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4410 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4413 item
.mask
= LVIF_INDENT
;
4414 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
4417 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
4418 "get indent dispinfo", FALSE
);
4420 DestroyWindow(hwnd
);
4423 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
4428 static BOOL
is_below_comctl_5(void)
4433 hwnd
= create_listview_control(LVS_REPORT
);
4434 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4435 insert_item(hwnd
, 0);
4437 ret
= SendMessage(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
4439 DestroyWindow(hwnd
);
4444 static void test_get_set_view(void)
4450 /* test style->view mapping */
4451 hwnd
= create_listview_control(LVS_REPORT
);
4452 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4454 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4455 expect(LV_VIEW_DETAILS
, ret
);
4457 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4459 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
4460 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4461 expect(LV_VIEW_ICON
, ret
);
4463 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4464 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
4465 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4466 expect(LV_VIEW_SMALLICON
, ret
);
4468 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4469 SetWindowLongPtr(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
4470 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4471 expect(LV_VIEW_LIST
, ret
);
4473 /* switching view doesn't touch window style */
4474 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
4476 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4477 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4478 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
4480 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4481 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4482 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
4484 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4485 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4487 DestroyWindow(hwnd
);
4490 static void test_canceleditlabel(void)
4492 HWND hwnd
, hwndedit
;
4496 static CHAR test
[] = "test";
4497 static const CHAR test1
[] = "test1";
4499 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4500 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4502 insert_item(hwnd
, 0);
4504 /* try without edit created */
4505 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4506 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4508 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4509 "cancel edit label without edit", FALSE
);
4511 /* cancel without data change */
4513 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4514 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4515 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4517 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4519 /* cancel after data change */
4520 memset(&itema
, 0, sizeof(itema
));
4521 itema
.pszText
= test
;
4522 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
4525 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4526 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4527 ret
= SetWindowText(hwndedit
, test1
);
4529 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4531 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4532 memset(&itema
, 0, sizeof(itema
));
4533 itema
.pszText
= buff
;
4534 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
4535 ret
= SendMessage(hwnd
, LVM_GETITEMTEXT
, 0, (LPARAM
)&itema
);
4537 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
4539 DestroyWindow(hwnd
);
4542 static void test_mapidindex(void)
4547 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4548 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
4549 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4550 insert_item(hwnd
, 0);
4551 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4553 DestroyWindow(hwnd
);
4555 hwnd
= create_listview_control(LVS_REPORT
);
4556 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4558 /* LVM_MAPINDEXTOID with invalid index */
4559 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4562 insert_item(hwnd
, 0);
4563 insert_item(hwnd
, 1);
4565 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
4567 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
4570 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4572 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4574 /* remove 0 indexed item, id retained */
4575 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
4576 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4578 /* new id starts from previous value */
4579 insert_item(hwnd
, 1);
4580 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4583 /* get index by id */
4584 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
4586 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
4588 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
4590 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
4593 DestroyWindow(hwnd
);
4596 static void test_getitemspacing(void)
4605 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
4606 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
4609 hwnd
= create_listview_control(LVS_ICON
);
4610 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4612 expect(cx
, LOWORD(ret
));
4613 expect(cy
, HIWORD(ret
));
4615 /* now try with icons */
4616 himl
= ImageList_Create(40, 40, 0, 4, 4);
4617 ok(himl
!= NULL
, "failed to create imagelist\n");
4618 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4619 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4620 ret
= ImageList_Add(himl
, hbmp
, 0);
4622 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4625 itema
.mask
= LVIF_IMAGE
;
4629 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
4631 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4633 /* spacing + icon size returned */
4634 expect(cx
+ 40, LOWORD(ret
));
4635 expect(cy
+ 40, HIWORD(ret
));
4637 DestroyWindow(hwnd
);
4639 hwnd
= create_listview_control(LVS_SMALLICON
);
4640 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4642 expect(cx
, LOWORD(ret
));
4643 expect(cy
, HIWORD(ret
));
4645 DestroyWindow(hwnd
);
4647 hwnd
= create_listview_control(LVS_REPORT
);
4648 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4650 expect(cx
, LOWORD(ret
));
4651 expect(cy
, HIWORD(ret
));
4653 DestroyWindow(hwnd
);
4655 hwnd
= create_listview_control(LVS_LIST
);
4656 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4658 expect(cx
, LOWORD(ret
));
4659 expect(cy
, HIWORD(ret
));
4661 DestroyWindow(hwnd
);
4664 static void test_getcolumnwidth(void)
4673 /* default column width */
4674 hwnd
= create_listview_control(LVS_ICON
);
4675 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4677 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4678 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
4679 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4680 todo_wine
expect(8, ret
);
4681 style
= GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
4682 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
4684 ret
= SendMessage(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4686 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4688 DestroyWindow(hwnd
);
4690 /* default column width with item added */
4691 hwnd
= create_listview_control(LVS_LIST
);
4692 memset(&itema
, 0, sizeof(itema
));
4693 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4694 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4696 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, ret
);
4697 ReleaseDC(hwnd
, hdc
);
4698 DestroyWindow(hwnd
);
4701 static void test_scrollnotify(void)
4706 hwnd
= create_listview_control(LVS_REPORT
);
4708 insert_column(hwnd
, 0);
4709 insert_column(hwnd
, 1);
4710 insert_item(hwnd
, 0);
4712 /* make it scrollable - resize */
4713 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
4715 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
4718 /* try with dummy call */
4719 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4720 ret
= SendMessage(hwnd
, LVM_SCROLL
, 0, 0);
4722 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4723 "scroll notify 1", TRUE
);
4725 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4726 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 0);
4728 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4729 "scroll notify 2", TRUE
);
4731 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4732 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 1);
4734 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4735 "scroll notify 3", TRUE
);
4737 DestroyWindow(hwnd
);
4740 static void test_LVS_EX_TRANSPARENTBKGND(void)
4746 hwnd
= create_listview_control(LVS_REPORT
);
4748 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4751 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4752 LVS_EX_TRANSPARENTBKGND
);
4754 ret
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, 0);
4755 if (ret
!= CLR_NONE
)
4757 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4758 DestroyWindow(hwnd
);
4762 /* try to set some back color and check this style bit */
4763 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4765 ret
= SendMessage(hwnd
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
4766 ok(!(ret
& LVS_EX_TRANSPARENTBKGND
), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4768 /* now test what this style actually does */
4769 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4770 LVS_EX_TRANSPARENTBKGND
);
4772 hdc
= GetWindowDC(hwndparent
);
4774 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4775 SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
4776 ok_sequence(sequences
, PARENT_SEQ_INDEX
, lvs_ex_transparentbkgnd_seq
,
4777 "LVS_EX_TRANSPARENTBKGND parent", FALSE
);
4779 ReleaseDC(hwndparent
, hdc
);
4781 DestroyWindow(hwnd
);
4784 static void test_approximate_viewrect(void)
4791 static CHAR test
[] = "abracadabra, a very long item label";
4793 hwnd
= create_listview_control(LVS_ICON
);
4794 himl
= ImageList_Create(40, 40, 0, 4, 4);
4795 ok(himl
!= NULL
, "failed to create imagelist\n");
4796 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4797 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4798 ret
= ImageList_Add(himl
, hbmp
, 0);
4800 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4803 itema
.mask
= LVIF_IMAGE
;
4807 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
4810 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(75, 75));
4814 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4818 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4819 expect(MAKELONG(77,827), ret
);
4821 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(50, 50));
4822 ok(ret
!= 0, "got 0\n");
4824 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4825 expect(MAKELONG(102,302), ret
);
4827 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4828 expect(MAKELONG(52,52), ret
);
4830 itema
.pszText
= test
;
4831 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
4833 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4834 expect(MAKELONG(52,52), ret
);
4836 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 0, MAKELPARAM(100,100));
4837 expect(MAKELONG(52,2), ret
);
4838 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 1, MAKELPARAM(100,100));
4839 expect(MAKELONG(52,52), ret
);
4840 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 2, MAKELPARAM(100,100));
4841 expect(MAKELONG(102,52), ret
);
4842 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 3, MAKELPARAM(100,100));
4843 expect(MAKELONG(102,102), ret
);
4844 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 4, MAKELPARAM(100,100));
4845 expect(MAKELONG(102,102), ret
);
4846 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 5, MAKELPARAM(100,100));
4847 expect(MAKELONG(102,152), ret
);
4848 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 6, MAKELPARAM(100,100));
4849 expect(MAKELONG(102,152), ret
);
4850 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 7, MAKELPARAM(160,100));
4851 expect(MAKELONG(152,152), ret
);
4853 DestroyWindow(hwnd
);
4856 static void test_finditem(void)
4863 hwnd
= create_listview_control(LVS_REPORT
);
4864 insert_item(hwnd
, 0);
4866 memset(&fi
, 0, sizeof(fi
));
4868 /* full string search, inserted text was "foo" */
4870 fi
.flags
= LVFI_STRING
;
4872 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4874 /* partial string search, inserted text was "foo" */
4876 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4878 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4880 /* partial string search, part after start char */
4882 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4884 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4887 /* try with LVFI_SUBSTRING */
4889 fi
.flags
= LVFI_SUBSTRING
;
4891 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4894 win_skip("LVFI_SUBSTRING not supported\n");
4895 DestroyWindow(hwnd
);
4900 fi
.flags
= LVFI_SUBSTRING
;
4902 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4905 fi
.flags
= LVFI_SUBSTRING
;
4907 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4911 fi
.flags
= LVFI_SUBSTRING
| LVFI_STRING
;
4913 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4916 DestroyWindow(hwnd
);
4919 static void test_LVS_EX_HEADERINALLVIEWS(void)
4924 hwnd
= create_listview_control(LVS_ICON
);
4926 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4927 LVS_EX_HEADERINALLVIEWS
);
4929 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4930 if (!IsWindow(header
))
4932 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4933 DestroyWindow(hwnd
);
4937 /* LVS_NOCOLUMNHEADER works as before */
4938 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4939 SetWindowLongW(hwnd
, GWL_STYLE
, style
| LVS_NOCOLUMNHEADER
);
4940 style
= GetWindowLongA(header
, GWL_STYLE
);
4941 ok(style
& HDS_HIDDEN
, "Expected HDS_HIDDEN\n");
4942 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4943 SetWindowLongW(hwnd
, GWL_STYLE
, style
& ~LVS_NOCOLUMNHEADER
);
4944 style
= GetWindowLongA(header
, GWL_STYLE
);
4945 ok(!(style
& HDS_HIDDEN
), "Expected HDS_HIDDEN to be unset\n");
4947 /* try to remove style */
4948 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
, 0);
4949 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4950 ok(IsWindow(header
), "Expected header to be created\n");
4951 style
= GetWindowLongA(header
, GWL_STYLE
);
4952 ok(!(style
& HDS_HIDDEN
), "HDS_HIDDEN not expected\n");
4954 DestroyWindow(hwnd
);
4956 /* check other styles */
4957 hwnd
= create_listview_control(LVS_LIST
);
4958 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4959 LVS_EX_HEADERINALLVIEWS
);
4960 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4961 ok(IsWindow(header
), "Expected header to be created\n");
4962 DestroyWindow(hwnd
);
4964 hwnd
= create_listview_control(LVS_SMALLICON
);
4965 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4966 LVS_EX_HEADERINALLVIEWS
);
4967 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4968 ok(IsWindow(header
), "Expected header to be created\n");
4969 DestroyWindow(hwnd
);
4971 hwnd
= create_listview_control(LVS_REPORT
);
4972 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4973 LVS_EX_HEADERINALLVIEWS
);
4974 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4975 ok(IsWindow(header
), "Expected header to be created\n");
4976 DestroyWindow(hwnd
);
4979 static void test_hover(void)
4984 hwnd
= create_listview_control(LVS_ICON
);
4986 /* test WM_MOUSEHOVER forwarding */
4987 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4988 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
4990 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER allow test", TRUE
);
4991 g_block_hover
= TRUE
;
4992 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4993 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
4995 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER block test", TRUE
);
4996 g_block_hover
= FALSE
;
4998 r
= SendMessage(hwnd
, LVM_SETHOVERTIME
, 0, 500);
4999 expect(HOVER_DEFAULT
, r
);
5000 r
= SendMessage(hwnd
, LVM_GETHOVERTIME
, 0, 0);
5003 DestroyWindow(hwnd
);
5006 static void test_destroynotify(void)
5010 hwnd
= create_listview_control(LVS_REPORT
);
5011 ok(hwnd
!= NULL
, "failed to create listview window\n");
5013 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5014 DestroyWindow(hwnd
);
5015 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_destroy
, "check destroy order", FALSE
);
5018 static void test_header_notification(void)
5020 static char textA
[] = "newtext";
5028 list
= create_listview_control(LVS_REPORT
);
5029 ok(list
!= NULL
, "failed to create listview window\n");
5031 memset(&col
, 0, sizeof(col
));
5032 col
.mask
= LVCF_WIDTH
;
5034 ret
= SendMessage(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5037 /* check list parent notification after header item changed,
5038 this test should be placed before header subclassing to avoid
5039 Listview -> Header messages to be logged */
5040 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5042 col
.mask
= LVCF_TEXT
;
5043 col
.pszText
= textA
;
5044 r
= SendMessage(list
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
5047 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_changed_seq
,
5048 "header notify, listview", FALSE
);
5049 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5050 "header notify, parent", FALSE
);
5052 header
= subclass_header(list
);
5054 ret
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
5057 memset(&item
, 0, sizeof(item
));
5058 item
.mask
= HDI_WIDTH
;
5059 ret
= SendMessage(header
, HDM_GETITEMA
, 0, (LPARAM
)&item
);
5061 expect(100, item
.cxy
);
5063 nmh
.hdr
.hwndFrom
= header
;
5064 nmh
.hdr
.idFrom
= GetWindowLongPtr(header
, GWLP_ID
);
5065 nmh
.hdr
.code
= HDN_ITEMCHANGEDA
;
5068 item
.mask
= HDI_WIDTH
;
5071 ret
= SendMessage(list
, WM_NOTIFY
, 0, (LPARAM
)&nmh
);
5074 DestroyWindow(list
);
5077 static void test_header_notification2(void)
5079 static char textA
[] = "newtext";
5086 struct message parent_header_notify_seq
[] = {
5087 { WM_NOTIFY
, sent
|id
, 0, 0, 0 },
5091 list
= create_listview_control(LVS_REPORT
);
5092 ok(list
!= NULL
, "failed to create listview window\n");
5094 memset(&col
, 0, sizeof(col
));
5095 col
.mask
= LVCF_WIDTH
| LVCF_TEXT
;
5097 col
.pszText
= textA
;
5098 ret
= SendMessage(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5101 header
= ListView_GetHeader(list
);
5102 ok(header
!= 0, "No header\n");
5103 memset(&itemW
, 0, sizeof(itemW
));
5104 itemW
.mask
= HDI_WIDTH
| HDI_ORDER
| HDI_TEXT
;
5105 itemW
.pszText
= buffer
;
5106 itemW
.cchTextMax
= sizeof(buffer
);
5107 ret
= SendMessageW(header
, HDM_GETITEMW
, 0, (LPARAM
)&itemW
);
5110 nmhdr
.hdr
.hwndFrom
= header
;
5111 nmhdr
.hdr
.idFrom
= GetWindowLongPtr(header
, GWLP_ID
);
5114 nmhdr
.pitem
= &itemW
;
5116 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5117 nmhdr
.hdr
.code
= HDN_ITEMCHANGINGW
;
5118 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5119 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGINGA
;
5120 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5121 "header notify, parent", TRUE
);
5123 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGINGA
, "Expected ANSI notification code\n");
5124 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5125 nmhdr
.hdr
.code
= HDN_ITEMCHANGEDW
;
5126 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5127 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGEDA
;
5128 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5129 "header notify, parent", TRUE
);
5131 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGEDA
, "Expected ANSI notification code\n");
5132 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5134 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5135 nmhdr
.hdr
.code
= HDN_ITEMCLICKW
;
5136 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5137 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_click_seq
,
5138 "header notify, parent", FALSE
);
5139 ok(nmhdr
.hdr
.code
== HDN_ITEMCLICKA
, "Expected ANSI notification code\n");
5140 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5141 nmhdr
.hdr
.code
= HDN_ITEMDBLCLICKW
;
5142 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5143 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5144 "header notify, parent", FALSE
);
5145 ok(nmhdr
.hdr
.code
== HDN_ITEMDBLCLICKW
, "Expected Unicode notification code\n");
5146 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5147 nmhdr
.hdr
.code
= HDN_DIVIDERDBLCLICKW
;
5148 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5149 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_divider_dclick_seq
,
5150 "header notify, parent", TRUE
);
5151 ok(nmhdr
.hdr
.code
== HDN_DIVIDERDBLCLICKA
, "Expected ANSI notification code\n");
5152 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5153 nmhdr
.hdr
.code
= HDN_BEGINTRACKW
;
5154 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5155 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5156 "header notify, parent", FALSE
);
5157 ok(nmhdr
.hdr
.code
== HDN_BEGINTRACKW
, "Expected Unicode notification code\n");
5158 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5159 nmhdr
.hdr
.code
= HDN_ENDTRACKW
;
5160 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5161 parent_header_notify_seq
[0].id
= HDN_ENDTRACKA
;
5162 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5163 "header notify, parent", FALSE
);
5164 ok(nmhdr
.hdr
.code
== HDN_ENDTRACKA
, "Expected ANSI notification code\n");
5165 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5166 nmhdr
.hdr
.code
= HDN_TRACKW
;
5167 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5168 parent_header_notify_seq
[0].id
= HDN_TRACKA
;
5169 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5170 "header notify, parent", FALSE
);
5171 ok(nmhdr
.hdr
.code
== HDN_TRACKA
, "Expected ANSI notification code\n");
5172 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5173 nmhdr
.hdr
.code
= HDN_BEGINDRAG
;
5174 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5175 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5176 "header notify, parent", FALSE
);
5177 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5178 nmhdr
.hdr
.code
= HDN_ENDDRAG
;
5179 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5180 parent_header_notify_seq
[0].id
= HDN_ENDDRAG
;
5181 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5182 "header notify, parent", FALSE
);
5183 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5184 nmhdr
.hdr
.code
= HDN_FILTERCHANGE
;
5185 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5186 parent_header_notify_seq
[0].id
= HDN_FILTERCHANGE
;
5187 parent_header_notify_seq
[0].flags
|= optional
; /* NT4 does not send this message */
5188 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5189 "header notify, parent", FALSE
);
5190 parent_header_notify_seq
[0].flags
&= ~optional
;
5191 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5192 nmhdr
.hdr
.code
= HDN_BEGINFILTEREDIT
;
5193 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5194 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5195 "header notify, parent", FALSE
);
5196 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5197 nmhdr
.hdr
.code
= HDN_ENDFILTEREDIT
;
5198 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5199 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5200 "header notify, parent", FALSE
);
5201 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5202 nmhdr
.hdr
.code
= HDN_ITEMSTATEICONCLICK
;
5203 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5204 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5205 "header notify, parent", FALSE
);
5206 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5207 nmhdr
.hdr
.code
= HDN_ITEMKEYDOWN
;
5208 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5209 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5210 "header notify, parent", FALSE
);
5212 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5214 DestroyWindow(list
);
5217 static void test_createdragimage(void)
5223 list
= create_listview_control(LVS_ICON
);
5224 ok(list
!= NULL
, "failed to create listview window\n");
5226 insert_item(list
, 0);
5229 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, 0);
5230 ok(himl
== NULL
, "got %p\n", himl
);
5232 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, (LPARAM
)&pt
);
5233 ok(himl
!= NULL
, "got %p\n", himl
);
5234 ImageList_Destroy(himl
);
5236 DestroyWindow(list
);
5239 static void test_dispinfo(void)
5241 static const char testA
[] = "TEST";
5247 hwnd
= create_listview_control(LVS_ICON
);
5248 ok(hwnd
!= NULL
, "failed to create listview window\n");
5250 insert_item(hwnd
, 0);
5252 memset(&item
, 0, sizeof(item
));
5253 item
.pszText
= LPSTR_TEXTCALLBACKA
;
5254 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5257 g_disp_A_to_W
= TRUE
;
5258 item
.pszText
= (char*)buff
;
5259 item
.cchTextMax
= sizeof(buff
)/sizeof(WCHAR
);
5260 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
5261 ok(ret
== sizeof(testA
)-1, "got %d, expected 4\n", ret
);
5262 g_disp_A_to_W
= FALSE
;
5264 ok(memcmp(item
.pszText
, testA
, sizeof(testA
)) == 0,
5265 "got %s, expected %s\n", item
.pszText
, testA
);
5267 DestroyWindow(hwnd
);
5270 static void test_LVM_SETITEMTEXT(void)
5272 static char testA
[] = "TEST";
5277 hwnd
= create_listview_control(LVS_ICON
);
5278 ok(hwnd
!= NULL
, "failed to create listview window\n");
5280 insert_item(hwnd
, 0);
5282 /* null item pointer */
5283 ret
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, 0);
5286 ret
= SendMessage(hwnd
, LVM_SETITEMTEXTW
, 0, 0);
5289 /* index out of bounds */
5290 item
.pszText
= testA
;
5291 item
.cchTextMax
= 0; /* ignored */
5294 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 1, (LPARAM
)&item
);
5297 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, -1, (LPARAM
)&item
);
5300 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5303 DestroyWindow(hwnd
);
5306 static void test_imagelists(void)
5309 HIMAGELIST himl1
, himl2
, himl3
;
5312 himl1
= ImageList_Create(40, 40, 0, 4, 4);
5313 himl2
= ImageList_Create(40, 40, 0, 4, 4);
5314 himl3
= ImageList_Create(40, 40, 0, 4, 4);
5315 ok(himl1
!= NULL
, "Failed to create imagelist\n");
5316 ok(himl2
!= NULL
, "Failed to create imagelist\n");
5317 ok(himl3
!= NULL
, "Failed to create imagelist\n");
5319 hwnd
= create_listview_control(LVS_REPORT
| LVS_SHAREIMAGELISTS
);
5320 header
= subclass_header(hwnd
);
5322 ok(header
!= NULL
, "Expected header\n");
5323 ret
= SendMessage(header
, HDM_GETIMAGELIST
, 0, 0);
5324 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5326 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5328 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5329 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5330 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5331 "set normal image list", FALSE
);
5333 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5335 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5336 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5337 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5338 "set state image list", TRUE
);
5340 ret
= SendMessage(header
, HDM_GETIMAGELIST
, 0, 0);
5341 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5343 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5345 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5346 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5347 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_set_imagelist
,
5348 "set small image list", FALSE
);
5350 ret
= SendMessage(header
, HDM_GETIMAGELIST
, 0, 0);
5351 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5352 DestroyWindow(hwnd
);
5354 hwnd
= create_listview_control(WS_VISIBLE
| LVS_ICON
);
5356 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5358 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5359 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5360 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5361 "set normal image list", FALSE
);
5363 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5365 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5366 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5367 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5368 "set state image list", FALSE
);
5370 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5372 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5373 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5374 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5375 "set small image list", FALSE
);
5377 header
= ListView_GetHeader(hwnd
);
5378 ok(header
== NULL
, "Expected no header, got %p\n", header
);
5380 SetWindowLongPtr(hwnd
, GWL_STYLE
, GetWindowLongPtr(hwnd
, GWL_STYLE
) | LVS_REPORT
);
5382 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
5383 ok(header
!= NULL
, "Expected header, got NULL\n");
5385 ret
= SendMessage(header
, HDM_GETIMAGELIST
, 0, 0);
5386 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5388 DestroyWindow(hwnd
);
5391 static void test_deleteitem(void)
5398 hwnd
= create_listview_control(LVS_REPORT
);
5400 insert_item(hwnd
, 0);
5401 insert_item(hwnd
, 0);
5402 insert_item(hwnd
, 0);
5403 insert_item(hwnd
, 0);
5404 insert_item(hwnd
, 0);
5406 g_focus_test_LVN_DELETEITEM
= TRUE
;
5408 /* delete focused item (not the last index) */
5409 item
.stateMask
= LVIS_FOCUSED
;
5410 item
.state
= LVIS_FOCUSED
;
5411 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
5412 ok(ret
== TRUE
, "got %d\n", ret
);
5413 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 2, 0);
5414 ok(ret
== TRUE
, "got %d\n", ret
);
5415 /* next item gets focus */
5416 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5417 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5419 /* focus last item and delete it */
5420 item
.stateMask
= LVIS_FOCUSED
;
5421 item
.state
= LVIS_FOCUSED
;
5422 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
5423 ok(ret
== TRUE
, "got %d\n", ret
);
5424 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 3, 0);
5425 ok(ret
== TRUE
, "got %d\n", ret
);
5426 /* new last item gets focus */
5427 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5428 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5430 /* focus first item and delete it */
5431 item
.stateMask
= LVIS_FOCUSED
;
5432 item
.state
= LVIS_FOCUSED
;
5433 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
5434 ok(ret
== TRUE
, "got %d\n", ret
);
5435 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
5436 ok(ret
== TRUE
, "got %d\n", ret
);
5437 /* new first item gets focus */
5438 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5439 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5441 g_focus_test_LVN_DELETEITEM
= FALSE
;
5443 DestroyWindow(hwnd
);
5446 static void test_insertitem(void)
5453 hwnd
= create_listview_control(LVS_REPORT
);
5455 /* insert item 0 focused */
5456 item
.mask
= LVIF_STATE
;
5457 item
.state
= LVIS_FOCUSED
;
5458 item
.stateMask
= LVIS_FOCUSED
;
5461 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5462 ok(ret
== 0, "got %d\n", ret
);
5464 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5465 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5467 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5469 /* insert item 1, focus shift */
5470 item
.mask
= LVIF_STATE
;
5471 item
.state
= LVIS_FOCUSED
;
5472 item
.stateMask
= LVIS_FOCUSED
;
5475 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5476 ok(ret
== 1, "got %d\n", ret
);
5478 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_insert_focused_seq
, "insert focused", TRUE
);
5480 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5481 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5483 /* insert item 2, no focus shift */
5484 item
.mask
= LVIF_STATE
;
5486 item
.stateMask
= LVIS_FOCUSED
;
5489 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5490 ok(ret
== 2, "got %d\n", ret
);
5492 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5493 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5495 DestroyWindow(hwnd
);
5498 START_TEST(listview
)
5501 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
5503 ULONG_PTR ctx_cookie
;
5507 hComctl32
= GetModuleHandleA("comctl32.dll");
5508 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
5509 if (pInitCommonControlsEx
)
5511 INITCOMMONCONTROLSEX iccex
;
5512 iccex
.dwSize
= sizeof(iccex
);
5513 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
5514 pInitCommonControlsEx(&iccex
);
5517 InitCommonControls();
5519 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
5521 hwndparent
= create_parent_window(FALSE
);
5522 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5524 g_is_below_5
= is_below_comctl_5();
5526 test_header_notification();
5527 test_header_notification2();
5534 test_icon_spacing();
5537 test_item_position();
5542 test_subitem_rect();
5546 test_nosortheader();
5550 test_getitemposition();
5551 test_columnscreation();
5553 test_notifyformat();
5555 test_getitemspacing();
5556 test_getcolumnwidth();
5557 test_approximate_viewrect();
5560 test_destroynotify();
5561 test_createdragimage();
5563 test_LVM_SETITEMTEXT();
5568 if (!load_v6_module(&ctx_cookie
, &hCtx
))
5570 DestroyWindow(hwndparent
);
5574 /* this is a XP SP3 failure workaround */
5575 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
5576 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
,
5578 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
5579 if (!IsWindow(hwnd
))
5581 win_skip("FIXME: failed to create ListView window.\n");
5582 unload_v6_module(ctx_cookie
, hCtx
);
5583 DestroyWindow(hwndparent
);
5587 DestroyWindow(hwnd
);
5589 /* comctl32 version 6 tests start here */
5590 test_get_set_view();
5591 test_canceleditlabel();
5593 test_scrollnotify();
5594 test_LVS_EX_TRANSPARENTBKGND();
5595 test_LVS_EX_HEADERINALLVIEWS();
5600 unload_v6_module(ctx_cookie
, hCtx
);
5602 DestroyWindow(hwndparent
);