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 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
399 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
401 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
407 switch (((NMHDR
*)lParam
)->code
)
409 case LVN_BEGINLABELEDIT
:
413 /* subclass edit box */
415 edit
= subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
419 INT len
= SendMessageA(edit
, EM_GETLIMITTEXT
, 0, 0);
420 ok(len
== 259 || broken(len
== 260) /* includes NULL in NT4 */,
421 "text limit %d, expected 259\n", len
);
426 case LVN_ENDLABELEDIT
:
430 /* always accept new item text */
431 NMLVDISPINFO
*di
= (NMLVDISPINFO
*)lParam
;
432 g_editbox_disp_info
= *di
;
433 trace("LVN_ENDLABELEDIT: text=%s\n", di
->item
.pszText
? di
->item
.pszText
: "(null)");
435 /* edit control still available from this notification */
436 edit
= (HWND
)SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETEDITCONTROL
, 0, 0);
437 ok(IsWindow(edit
), "expected valid edit control handle\n");
438 ok((GetWindowLongA(edit
, GWL_STYLE
) & ES_MULTILINE
) == 0, "edit is multiline\n");
442 case LVN_BEGINSCROLL
:
445 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
447 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
448 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
451 case LVN_ITEMCHANGING
:
453 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
454 g_nmlistview_changing
= *nmlv
;
457 case LVN_ITEMCHANGED
:
459 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
460 g_nmlistview
= *nmlv
;
463 case LVN_GETDISPINFOA
:
465 NMLVDISPINFOA
*dispinfo
= (NMLVDISPINFOA
*)lParam
;
466 g_itema
= dispinfo
->item
;
468 if (g_disp_A_to_W
&& (dispinfo
->item
.mask
& LVIF_TEXT
))
470 static const WCHAR testW
[] = {'T','E','S','T',0};
471 dispinfo
->hdr
.code
= LVN_GETDISPINFOW
;
472 memcpy(dispinfo
->item
.pszText
, testW
, sizeof(testW
));
475 /* test control buffer size for text, 10 used to mask cases when control
476 is using caller buffer to process LVM_GETITEM for example */
477 if (dispinfo
->item
.mask
& LVIF_TEXT
&& dispinfo
->item
.cchTextMax
> 10)
478 ok(dispinfo
->item
.cchTextMax
== 260 ||
479 broken(dispinfo
->item
.cchTextMax
== 264) /* NT4 reports aligned size */,
480 "buffer size %d\n", dispinfo
->item
.cchTextMax
);
484 if (g_focus_test_LVN_DELETEITEM
)
486 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
489 state
= SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETITEMSTATE
, nmlv
->iItem
, LVIS_FOCUSED
);
490 ok(state
== 0, "got state %x\n", state
);
494 if (g_block_hover
) return 1;
499 case WM_NOTIFYFORMAT
:
501 /* force to return format */
502 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
507 defwndproc_counter
++;
508 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
509 defwndproc_counter
--;
514 static BOOL
register_parent_wnd_class(BOOL Unicode
)
522 clsW
.lpfnWndProc
= parent_wnd_proc
;
525 clsW
.hInstance
= GetModuleHandleW(NULL
);
527 clsW
.hCursor
= LoadCursorA(0, IDC_ARROW
);
528 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
529 clsW
.lpszMenuName
= NULL
;
530 clsW
.lpszClassName
= testparentclassW
;
535 clsA
.lpfnWndProc
= parent_wnd_proc
;
538 clsA
.hInstance
= GetModuleHandleA(NULL
);
540 clsA
.hCursor
= LoadCursorA(0, IDC_ARROW
);
541 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
542 clsA
.lpszMenuName
= NULL
;
543 clsA
.lpszClassName
= "Listview test parent class";
546 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
549 static HWND
create_parent_window(BOOL Unicode
)
551 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
554 if (!register_parent_wnd_class(Unicode
))
561 hwnd
= CreateWindowExW(0, testparentclassW
, nameW
,
562 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
563 WS_MAXIMIZEBOX
| WS_VISIBLE
,
565 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
567 hwnd
= CreateWindowExA(0, "Listview test parent class",
568 "Listview test parent window",
569 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
570 WS_MAXIMIZEBOX
| WS_VISIBLE
,
572 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
573 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
577 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
579 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
580 static LONG defwndproc_counter
= 0;
584 /* some debug output for style changing */
585 if ((message
== WM_STYLECHANGING
||
586 message
== WM_STYLECHANGED
) && lParam
)
588 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
589 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
592 msg
.message
= message
;
593 msg
.flags
= sent
|wparam
|lparam
;
594 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
597 msg
.id
= LISTVIEW_ID
;
598 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
599 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
601 defwndproc_counter
++;
602 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
603 defwndproc_counter
--;
607 static HWND
create_listview_control(DWORD style
)
613 GetClientRect(hwndparent
, &rect
);
614 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
615 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
616 0, 0, rect
.right
, rect
.bottom
,
617 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
618 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
620 if (!hwnd
) return NULL
;
622 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
623 (LONG_PTR
)listview_subclass_proc
);
624 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
629 /* unicode listview window with specified parent */
630 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
635 static const WCHAR nameW
[] = {'f','o','o',0};
637 GetClientRect(parent
, &rect
);
638 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
639 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
640 0, 0, rect
.right
, rect
.bottom
,
641 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
642 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
644 if (!hwnd
) return NULL
;
646 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
647 (LONG_PTR
)listview_subclass_proc
);
648 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
653 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
655 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
656 static LONG defwndproc_counter
= 0;
660 msg
.message
= message
;
661 msg
.flags
= sent
|wparam
|lparam
;
662 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
666 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
668 defwndproc_counter
++;
669 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
670 defwndproc_counter
--;
674 static HWND
subclass_header(HWND hwndListview
)
679 hwnd
= ListView_GetHeader(hwndListview
);
680 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
681 (LONG_PTR
)header_subclass_proc
);
682 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
687 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
689 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
690 static LONG defwndproc_counter
= 0;
694 msg
.message
= message
;
695 msg
.flags
= sent
|wparam
|lparam
;
696 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
701 /* all we need is sizing */
702 if (message
== WM_WINDOWPOSCHANGING
||
703 message
== WM_NCCALCSIZE
||
704 message
== WM_WINDOWPOSCHANGED
||
705 message
== WM_MOVE
||
708 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
711 defwndproc_counter
++;
712 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
713 defwndproc_counter
--;
717 static HWND
subclass_editbox(HWND hwndListview
)
722 hwnd
= (HWND
)SendMessage(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
723 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
724 (LONG_PTR
)editbox_subclass_proc
);
725 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
730 /* Performs a single LVM_HITTEST test */
731 static void test_lvm_hittest_(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
, UINT broken_flags
,
732 BOOL todo_item
, BOOL todo_flags
, int line
)
741 ret
= SendMessage(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
747 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
748 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
749 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
754 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
755 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
756 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
762 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
764 else if (broken_flags
)
765 ok_(__FILE__
, line
)(lpht
.flags
== flags
|| broken(lpht
.flags
== broken_flags
),
766 "Expected flags %x, got %x\n", flags
, lpht
.flags
);
768 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
771 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
773 /* Performs a single LVM_SUBITEMHITTEST test */
774 static void test_lvm_subitemhittest_(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
775 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
783 ret
= SendMessage(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
789 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
790 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
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
);
802 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
805 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
810 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
813 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
816 #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__)
818 static void test_images(void)
826 static CHAR hello
[] = "hello";
828 himl
= ImageList_Create(40, 40, 0, 4, 4);
829 ok(himl
!= NULL
, "failed to create imagelist\n");
831 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
832 ok(hbmp
!= NULL
, "failed to create bitmap\n");
834 r
= ImageList_Add(himl
, hbmp
, 0);
835 ok(r
== 0, "should be zero\n");
837 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
838 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
839 ok(hwnd
!= NULL
, "failed to create listview window\n");
841 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
842 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
844 ok(r
== 0, "should return zero\n");
846 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
847 ok(r
== 0, "should return zero\n");
849 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
850 ok(r
!= 0, "got 0\n");
852 /* returns dimensions */
854 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
855 ok(r
== 0, "should be zero items\n");
857 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
862 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
863 ok(r
== -1, "should fail\n");
866 item
.pszText
= hello
;
867 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
868 ok(r
== 0, "should not fail\n");
870 memset(&r1
, 0, sizeof r1
);
872 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
875 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
876 ok(r
== TRUE
, "should not fail\n");
879 item
.pszText
= hello
;
880 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
881 ok(r
== 0, "should not fail\n");
883 memset(&r2
, 0, sizeof r2
);
885 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
888 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
893 static void test_checkboxes(void)
898 static CHAR text
[] = "Text",
902 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
903 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
904 ok(hwnd
!= NULL
, "failed to create listview window\n");
906 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
907 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
908 item
.stateMask
= 0xffff;
913 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
917 item
.mask
= LVIF_STATE
;
918 item
.stateMask
= 0xffff;
919 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
921 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
923 /* Don't set LVIF_STATE */
924 item
.mask
= LVIF_TEXT
;
925 item
.stateMask
= 0xffff;
930 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
934 item
.mask
= LVIF_STATE
;
935 item
.stateMask
= 0xffff;
936 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
938 ok(item
.state
== 0, "state %x\n", item
.state
);
940 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
943 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
945 item
.mask
= LVIF_STATE
;
946 item
.stateMask
= 0xffff;
947 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
949 if (item
.state
!= 0x1ccc)
951 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
956 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
958 item
.mask
= LVIF_TEXT
;
960 item
.pszText
= text2
;
961 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
965 item
.mask
= LVIF_STATE
;
966 item
.stateMask
= 0xffff;
967 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
969 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
971 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
973 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
974 item
.stateMask
= 0xffff;
976 item
.pszText
= text3
;
977 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
981 item
.mask
= LVIF_STATE
;
982 item
.stateMask
= 0xffff;
983 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
985 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
987 /* Set an item's state to checked */
989 item
.mask
= LVIF_STATE
;
990 item
.stateMask
= 0xf000;
992 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
996 item
.mask
= LVIF_STATE
;
997 item
.stateMask
= 0xffff;
998 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1000 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1002 /* Check that only the bits we asked for are returned,
1003 * and that all the others are set to zero
1006 item
.mask
= LVIF_STATE
;
1007 item
.stateMask
= 0xf000;
1008 item
.state
= 0xffff;
1009 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1011 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
1013 /* Set the style again and check that doesn't change an item's state */
1014 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1015 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1018 item
.mask
= LVIF_STATE
;
1019 item
.stateMask
= 0xffff;
1020 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1022 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1024 /* Unsetting the checkbox extended style doesn't change an item's state */
1025 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
1026 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1029 item
.mask
= LVIF_STATE
;
1030 item
.stateMask
= 0xffff;
1031 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1033 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1035 /* Now setting the style again will change an item's state */
1036 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1040 item
.mask
= LVIF_STATE
;
1041 item
.stateMask
= 0xffff;
1042 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1044 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
1046 /* Toggle checkbox tests (bug 9934) */
1047 memset (&item
, 0xcc, sizeof(item
));
1048 item
.mask
= LVIF_STATE
;
1051 item
.state
= LVIS_FOCUSED
;
1052 item
.stateMask
= LVIS_FOCUSED
;
1053 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1057 item
.mask
= LVIF_STATE
;
1058 item
.stateMask
= 0xffff;
1059 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1061 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1063 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1065 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1069 item
.mask
= LVIF_STATE
;
1070 item
.stateMask
= 0xffff;
1071 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1073 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
1075 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1077 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1081 item
.mask
= LVIF_STATE
;
1082 item
.stateMask
= 0xffff;
1083 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1085 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1087 DestroyWindow(hwnd
);
1090 static void insert_column(HWND hwnd
, int idx
)
1095 memset(&column
, 0xcc, sizeof(column
));
1096 column
.mask
= LVCF_SUBITEM
;
1097 column
.iSubItem
= idx
;
1099 rc
= ListView_InsertColumn(hwnd
, idx
, &column
);
1103 static void insert_item(HWND hwnd
, int idx
)
1105 static CHAR text
[] = "foo";
1110 memset(&item
, 0xcc, sizeof (item
));
1111 item
.mask
= LVIF_TEXT
;
1114 item
.pszText
= text
;
1116 rc
= ListView_InsertItem(hwnd
, &item
);
1120 static void test_items(void)
1122 const LPARAM lparamTest
= 0x42;
1123 static CHAR text
[] = "Text";
1129 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1130 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1131 ok(hwnd
!= NULL
, "failed to create listview window\n");
1134 * Test setting/getting item params
1137 /* Set up two columns */
1138 insert_column(hwnd
, 0);
1139 insert_column(hwnd
, 1);
1141 /* LVIS_SELECTED with zero stateMask */
1143 memset (&item
, 0, sizeof (item
));
1144 item
.mask
= LVIF_STATE
;
1145 item
.state
= LVIS_SELECTED
;
1149 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1152 memset (&item
, 0xcc, sizeof (item
));
1153 item
.mask
= LVIF_STATE
;
1154 item
.stateMask
= LVIS_SELECTED
;
1158 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1160 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1161 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1163 /* LVIS_SELECTED with zero stateMask */
1165 memset (&item
, 0, sizeof (item
));
1166 item
.mask
= LVIF_STATE
;
1167 item
.state
= LVIS_FOCUSED
;
1171 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1174 memset (&item
, 0xcc, sizeof (item
));
1175 item
.mask
= LVIF_STATE
;
1176 item
.stateMask
= LVIS_FOCUSED
;
1180 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1182 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1183 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1185 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1187 memset (&item
, 0, sizeof (item
));
1188 item
.mask
= LVIF_STATE
;
1189 item
.state
= LVIS_CUT
;
1190 item
.stateMask
= LVIS_FOCUSED
;
1193 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1196 memset (&item
, 0xcc, sizeof (item
));
1197 item
.mask
= LVIF_STATE
;
1198 item
.stateMask
= LVIS_CUT
;
1202 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1204 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1205 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1207 /* Insert an item with just a param */
1208 memset (&item
, 0xcc, sizeof (item
));
1209 item
.mask
= LVIF_PARAM
;
1212 item
.lParam
= lparamTest
;
1213 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1216 /* Test getting of the param */
1217 memset (&item
, 0xcc, sizeof (item
));
1218 item
.mask
= LVIF_PARAM
;
1221 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1223 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1225 /* Set up a subitem */
1226 memset (&item
, 0xcc, sizeof (item
));
1227 item
.mask
= LVIF_TEXT
;
1230 item
.pszText
= text
;
1231 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1234 item
.mask
= LVIF_TEXT
;
1237 item
.pszText
= buffA
;
1238 item
.cchTextMax
= sizeof(buffA
);
1239 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1241 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got text %s, expected %s\n", item
.pszText
, text
);
1243 /* set up with extra flag */
1244 /* 1. reset subitem text */
1245 item
.mask
= LVIF_TEXT
;
1248 item
.pszText
= NULL
;
1249 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1252 item
.mask
= LVIF_TEXT
;
1255 item
.pszText
= buffA
;
1257 item
.cchTextMax
= sizeof(buffA
);
1258 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1260 ok(item
.pszText
[0] == 0, "got %p\n", item
.pszText
);
1262 /* 2. set new text with extra flag specified */
1263 item
.mask
= LVIF_TEXT
| LVIF_DI_SETITEM
;
1266 item
.pszText
= text
;
1267 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1268 ok(r
== 1 || broken(r
== 0) /* NT4 */, "ret %d\n", r
);
1272 item
.mask
= LVIF_TEXT
;
1275 item
.pszText
= buffA
;
1277 item
.cchTextMax
= sizeof(buffA
);
1278 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1280 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got %s, expected %s\n", item
.pszText
, text
);
1283 /* Query param from subitem: returns main item param */
1284 memset (&item
, 0xcc, sizeof (item
));
1285 item
.mask
= LVIF_PARAM
;
1288 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1290 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1292 /* Set up param on first subitem: no effect */
1293 memset (&item
, 0xcc, sizeof (item
));
1294 item
.mask
= LVIF_PARAM
;
1297 item
.lParam
= lparamTest
+1;
1298 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1301 /* Query param from subitem again: should still return main item param */
1302 memset (&item
, 0xcc, sizeof (item
));
1303 item
.mask
= LVIF_PARAM
;
1306 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1308 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1310 /**** Some tests of state highlighting ****/
1311 memset (&item
, 0xcc, sizeof (item
));
1312 item
.mask
= LVIF_STATE
;
1315 item
.state
= LVIS_SELECTED
;
1316 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1317 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1320 item
.state
= LVIS_DROPHILITED
;
1321 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1324 memset (&item
, 0xcc, sizeof (item
));
1325 item
.mask
= LVIF_STATE
;
1328 item
.stateMask
= -1;
1329 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1331 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1333 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1335 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1337 /* some notnull but meaningless masks */
1338 memset (&item
, 0, sizeof(item
));
1339 item
.mask
= LVIF_NORECOMPUTE
;
1342 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1344 memset (&item
, 0, sizeof(item
));
1345 item
.mask
= LVIF_DI_SETITEM
;
1348 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1351 /* set text to callback value already having it */
1352 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1354 memset (&item
, 0, sizeof (item
));
1355 item
.mask
= LVIF_TEXT
;
1356 item
.pszText
= LPSTR_TEXTCALLBACK
;
1358 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1360 memset (&item
, 0, sizeof (item
));
1362 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1364 item
.pszText
= LPSTR_TEXTCALLBACK
;
1365 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0 , (LPARAM
) &item
);
1368 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1369 "check callback text comparison rule", FALSE
);
1371 DestroyWindow(hwnd
);
1374 static void test_columns(void)
1383 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1384 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1385 ok(hwnd
!= NULL
, "failed to create listview window\n");
1387 /* Add a column with no mask */
1388 memset(&column
, 0xcc, sizeof(column
));
1390 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1391 ok(rc
== 0, "Inserting column with no mask failed with %d\n", rc
);
1393 /* Check its width */
1394 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
1395 ok(rc
== 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1397 DestroyWindow(hwnd
);
1399 /* LVM_GETCOLUMNORDERARRAY */
1400 hwnd
= create_listview_control(LVS_REPORT
);
1401 subclass_header(hwnd
);
1403 memset(&column
, 0, sizeof(column
));
1404 column
.mask
= LVCF_WIDTH
;
1406 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1410 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&column
);
1413 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1415 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1417 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1418 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1420 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1422 /* after column added subitem is considered as present */
1423 insert_item(hwnd
, 0);
1425 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1427 item
.pszText
= buff
;
1428 item
.cchTextMax
= sizeof(buff
);
1431 item
.mask
= LVIF_TEXT
;
1432 memset(&g_itema
, 0, sizeof(g_itema
));
1433 rc
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
1435 ok(g_itema
.iSubItem
== 1, "got %d\n", g_itema
.iSubItem
);
1437 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
1438 "get subitem text after column added", FALSE
);
1440 DestroyWindow(hwnd
);
1443 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1444 static WNDPROC listviewWndProc
;
1445 static HIMAGELIST test_create_imagelist
;
1447 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1451 if (uMsg
== WM_CREATE
)
1453 LPCREATESTRUCT lpcs
= (LPCREATESTRUCT
)lParam
;
1454 lpcs
->style
|= LVS_REPORT
;
1456 ret
= CallWindowProc(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1457 if (uMsg
== WM_CREATE
) SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1461 static void test_create(void)
1472 cls
.cbSize
= sizeof(WNDCLASSEX
);
1473 ok(GetClassInfoEx(GetModuleHandle(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1474 listviewWndProc
= cls
.lpfnWndProc
;
1475 cls
.lpfnWndProc
= create_test_wndproc
;
1476 cls
.lpszClassName
= "MyListView32";
1477 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
1479 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1480 hList
= CreateWindow("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1481 ok((HIMAGELIST
)SendMessage(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1482 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1484 if (!IsWindow(hHeader
))
1487 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1488 DestroyWindow(hList
);
1492 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1493 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1494 DestroyWindow(hList
);
1496 /* header isn't created on LVS_ICON and LVS_LIST styles */
1497 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1498 GetModuleHandle(NULL
), 0);
1499 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1500 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1501 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1503 memset(&col
, 0, sizeof(LVCOLUMNA
));
1504 col
.mask
= LVCF_WIDTH
;
1506 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1508 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1509 ok(IsWindow(hHeader
), "Header should be created\n");
1510 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1511 style
= GetWindowLong(hHeader
, GWL_STYLE
);
1512 ok(!(style
& HDS_HIDDEN
), "Not expected HDS_HIDDEN\n");
1513 DestroyWindow(hList
);
1515 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1516 GetModuleHandle(NULL
), 0);
1517 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1518 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1519 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1521 memset(&col
, 0, sizeof(LVCOLUMNA
));
1522 col
.mask
= LVCF_WIDTH
;
1524 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1526 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1527 ok(IsWindow(hHeader
), "Header should be created\n");
1528 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1529 DestroyWindow(hList
);
1531 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1532 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1533 GetModuleHandle(NULL
), 0);
1534 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLongPtr(hList
, GWL_STYLE
) | LVS_REPORT
);
1535 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1536 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1537 ok(IsWindow(hHeader
), "Header should be created\n");
1538 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLong(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1539 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1540 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1541 ok(IsWindow(hHeader
), "Header should be created\n");
1542 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1543 DestroyWindow(hList
);
1545 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1546 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1547 GetModuleHandle(NULL
), 0);
1548 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1549 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1550 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1551 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1552 ok(IsWindow(hHeader
), "Header should be created\n");
1553 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1554 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1555 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1556 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\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 DestroyWindow(hList
);
1562 /* LVS_REPORT without WS_VISIBLE */
1563 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1564 GetModuleHandle(NULL
), 0);
1565 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1566 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1567 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1569 memset(&col
, 0, sizeof(LVCOLUMNA
));
1570 col
.mask
= LVCF_WIDTH
;
1572 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1574 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1575 ok(IsWindow(hHeader
), "Header should be created\n");
1576 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1577 DestroyWindow(hList
);
1579 /* LVS_REPORT without WS_VISIBLE, try to show it */
1580 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1581 GetModuleHandle(NULL
), 0);
1582 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1583 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1584 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1585 ShowWindow(hList
, SW_SHOW
);
1586 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1587 ok(IsWindow(hHeader
), "Header should be created\n");
1588 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1589 DestroyWindow(hList
);
1591 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1592 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1593 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1594 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1595 ok(IsWindow(hHeader
), "Header should be created\n");
1596 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1597 /* HDS_DRAGDROP set by default */
1598 ok(GetWindowLongPtr(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1599 DestroyWindow(hList
);
1601 /* setting LVS_EX_HEADERDRAGDROP creates header */
1602 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1603 GetModuleHandle(NULL
), 0);
1604 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1605 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1606 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1607 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1608 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1609 ok(IsWindow(hHeader
) ||
1610 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1611 "Header should be created\n");
1612 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1613 DestroyWindow(hList
);
1615 /* setting LVS_EX_GRIDLINES creates header */
1616 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1617 GetModuleHandle(NULL
), 0);
1618 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1619 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1620 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1621 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_GRIDLINES
);
1622 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1623 ok(IsWindow(hHeader
) ||
1624 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1625 "Header should be created\n");
1626 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1627 DestroyWindow(hList
);
1629 /* setting LVS_EX_FULLROWSELECT creates header */
1630 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1631 GetModuleHandle(NULL
), 0);
1632 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1633 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1634 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1635 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
1636 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1637 ok(IsWindow(hHeader
) ||
1638 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1639 "Header should be created\n");
1640 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1641 DestroyWindow(hList
);
1643 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1644 hList
= create_listview_control(LVS_ICON
);
1645 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1646 r
= SendMessage(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1647 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1648 DestroyWindow(hList
);
1650 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1651 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1652 GetModuleHandle(NULL
), 0);
1653 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1654 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1656 rect
.left
= LVIR_BOUNDS
;
1658 rect
.right
= rect
.bottom
= -10;
1659 r
= SendMessage(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1660 /* right value contains garbage, probably because header columns are not set up */
1661 expect(0, rect
.bottom
);
1664 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1665 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1666 ok(GetDlgItem(hList
, 0) == NULL
, "NULL dialog item expected\n");
1668 DestroyWindow(hList
);
1670 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1671 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1672 hList
= create_listview_control(LVS_OWNERDRAWFIXED
| LVS_REPORT
);
1673 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1674 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1675 DestroyWindow(hList
);
1678 static void test_redraw(void)
1685 hwnd
= create_listview_control(LVS_REPORT
);
1686 subclass_header(hwnd
);
1688 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1690 InvalidateRect(hwnd
, NULL
, TRUE
);
1692 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1694 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1696 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1697 /* 1. Without backbuffer */
1698 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1701 hdc
= GetWindowDC(hwndparent
);
1703 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1704 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1705 ok(r
== 1, "Expected not zero result\n");
1706 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1707 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1709 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1712 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1713 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1715 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1716 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1718 /* 2. With backbuffer */
1719 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1720 LVS_EX_DOUBLEBUFFER
);
1721 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1724 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1725 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1727 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1728 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1730 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1733 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1734 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1735 todo_wine
expect(1, r
);
1736 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1737 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1739 ReleaseDC(hwndparent
, hdc
);
1741 DestroyWindow(hwnd
);
1744 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1746 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1748 if(msg
== WM_NOTIFY
) {
1749 NMHDR
*nmhdr
= (PVOID
)lp
;
1750 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1751 NMLVCUSTOMDRAW
*nmlvcd
= (NMLVCUSTOMDRAW
*)nmhdr
;
1753 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1755 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1756 return CDRF_NOTIFYITEMDRAW
;
1757 case CDDS_ITEMPREPAINT
:
1758 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1759 return CDRF_NOTIFYSUBITEMDRAW
;
1760 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1761 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1762 if (nmlvcd
->iSubItem
)
1763 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1765 ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1766 return CDRF_NOTIFYPOSTPAINT
;
1767 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1768 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1769 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1770 return CDRF_DODEFAULT
;
1772 return CDRF_DODEFAULT
;
1776 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1779 static void test_customdraw(void)
1784 hwnd
= create_listview_control(LVS_REPORT
);
1786 insert_column(hwnd
, 0);
1787 insert_column(hwnd
, 1);
1788 insert_item(hwnd
, 0);
1790 oldwndproc
= (WNDPROC
)SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
,
1791 (LONG_PTR
)cd_wndproc
);
1793 InvalidateRect(hwnd
, NULL
, TRUE
);
1796 SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1798 DestroyWindow(hwnd
);
1801 static void test_icon_spacing(void)
1803 /* LVM_SETICONSPACING */
1804 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1810 hwnd
= create_listview_control(LVS_ICON
);
1811 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1813 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, NF_REQUERY
);
1814 expect(NFR_ANSI
, r
);
1816 /* reset the icon spacing to defaults */
1817 SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1819 /* now we can request what the defaults are */
1820 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1824 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1826 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1827 ok(r
== MAKELONG(w
, h
) ||
1828 broken(r
== MAKELONG(w
, w
)), /* win98 */
1829 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1831 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1835 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1836 DestroyWindow(hwnd
);
1839 expect(MAKELONG(20,30), r
);
1841 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1842 expect(MAKELONG(25,35), r
);
1844 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1846 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1847 DestroyWindow(hwnd
);
1850 static void test_color(void)
1858 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1860 hwnd
= create_listview_control(LVS_REPORT
);
1861 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1863 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1865 for (i
= 0; i
< 4; i
++)
1869 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1871 r
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, 0);
1874 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1876 r
= SendMessage(hwnd
, LVM_GETTEXTCOLOR
, 0, 0);
1879 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1881 r
= SendMessage(hwnd
, LVM_GETTEXTBKCOLOR
, 0, 0);
1885 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1886 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1888 /* invalidation test done separately to avoid a message chain mess */
1889 r
= ValidateRect(hwnd
, NULL
);
1891 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, colors
[0]);
1894 rect
.right
= rect
.bottom
= 1;
1895 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1896 todo_wine
expect(FALSE
, r
);
1897 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1899 r
= ValidateRect(hwnd
, NULL
);
1901 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, colors
[0]);
1904 rect
.right
= rect
.bottom
= 1;
1905 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1906 todo_wine
expect(FALSE
, r
);
1907 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1909 r
= ValidateRect(hwnd
, NULL
);
1911 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, colors
[0]);
1914 rect
.right
= rect
.bottom
= 1;
1915 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1916 todo_wine
expect(FALSE
, r
);
1917 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1919 DestroyWindow(hwnd
);
1922 static void test_item_count(void)
1924 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1937 static CHAR item0text
[] = "item0";
1938 static CHAR item1text
[] = "item1";
1939 static CHAR item2text
[] = "item2";
1941 hwnd
= create_listview_control(LVS_REPORT
);
1942 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1944 /* resize in dpiaware manner to fit all 3 items added */
1946 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1947 GetTextMetricsA(hdc
, &tm
);
1948 /* 2 extra pixels for bounds and header border */
1949 height
= tm
.tmHeight
+ 2;
1950 SelectObject(hdc
, hOldFont
);
1953 GetWindowRect(hwnd
, &rect
);
1954 /* 3 items + 1 header + 1 to be sure */
1955 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1957 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1959 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1963 item0
.mask
= LVIF_TEXT
;
1966 item0
.pszText
= item0text
;
1967 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1970 /* [item0, item1] */
1971 item1
.mask
= LVIF_TEXT
;
1974 item1
.pszText
= item1text
;
1975 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1978 /* [item0, item1, item2] */
1979 item2
.mask
= LVIF_TEXT
;
1982 item2
.pszText
= item2text
;
1983 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1986 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1989 /* [item0, item1] */
1990 r
= SendMessage(hwnd
, LVM_DELETEITEM
, 2, 0);
1993 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1997 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
2000 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2004 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
2007 /* [item0, item1] */
2008 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
2011 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2014 /* [item0, item1, item2] */
2015 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
2018 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2021 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
2023 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2024 DestroyWindow(hwnd
);
2027 static void test_item_position(void)
2029 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2038 static CHAR item0text
[] = "item0";
2039 static CHAR item1text
[] = "item1";
2040 static CHAR item2text
[] = "item2";
2042 hwnd
= create_listview_control(LVS_ICON
);
2043 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2045 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2048 item0
.mask
= LVIF_TEXT
;
2051 item0
.pszText
= item0text
;
2052 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
2055 /* [item0, item1] */
2056 item1
.mask
= LVIF_TEXT
;
2059 item1
.pszText
= item1text
;
2060 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
2063 /* [item0, item1, item2] */
2064 item2
.mask
= LVIF_TEXT
;
2067 item2
.pszText
= item2text
;
2068 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
2071 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
2073 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
2075 expect2(10, 5, position
.x
, position
.y
);
2077 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
2079 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
2081 expect2(0, 0, position
.x
, position
.y
);
2083 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
2085 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
2087 expect2(20, 20, position
.x
, position
.y
);
2089 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
2091 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2092 DestroyWindow(hwnd
);
2095 static void test_getorigin(void)
2103 position
.x
= position
.y
= 0;
2105 hwnd
= create_listview_control(LVS_ICON
);
2106 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2107 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2109 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2111 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2112 DestroyWindow(hwnd
);
2114 hwnd
= create_listview_control(LVS_SMALLICON
);
2115 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2116 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2118 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2120 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2121 DestroyWindow(hwnd
);
2123 hwnd
= create_listview_control(LVS_LIST
);
2124 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2125 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2127 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2129 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2130 DestroyWindow(hwnd
);
2132 hwnd
= create_listview_control(LVS_REPORT
);
2133 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2134 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2136 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2138 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2139 DestroyWindow(hwnd
);
2142 static void test_multiselect(void)
2144 typedef struct t_select_task
2155 int i
,j
,item_count
,selected_count
;
2156 static const int items
=5;
2162 static struct t_select_task task_list
[] = {
2163 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
2164 { "using VK_UP", -1, VK_UP
, -1, -1 },
2165 { "using VK_END", 0, VK_END
, 1, -1 },
2166 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
2169 hwnd
= create_listview_control(LVS_REPORT
);
2171 for (i
= 0; i
< items
; i
++)
2172 insert_item(hwnd
, 0);
2174 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2175 expect(items
, item_count
);
2177 for (i
= 0; i
< 4; i
++) {
2180 task
= task_list
[i
];
2182 /* deselect all items */
2184 item
.stateMask
= LVIS_SELECTED
;
2185 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2186 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2188 /* set initial position */
2189 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
2191 item
.state
= LVIS_SELECTED
;
2192 item
.stateMask
= LVIS_SELECTED
;
2193 SendMessageA(hwnd
, LVM_SETITEMSTATE
, task
.initPos
== -1 ? item_count
-1 : task
.initPos
, (LPARAM
)&item
);
2195 selected_count
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2196 ok(selected_count
== 1, "expected 1, got %d\n", selected_count
);
2198 /* Set SHIFT key pressed */
2199 GetKeyboardState(kstate
);
2200 kstate
[VK_SHIFT
]=0x80;
2201 SetKeyboardState(kstate
);
2203 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
2204 r
= SendMessage(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
2206 r
= SendMessage(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
2210 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2212 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
);
2214 /* Set SHIFT key released */
2215 GetKeyboardState(kstate
);
2216 kstate
[VK_SHIFT
]=0x00;
2217 SetKeyboardState(kstate
);
2219 DestroyWindow(hwnd
);
2221 /* make multiple selection, then switch to LVS_SINGLESEL */
2222 hwnd
= create_listview_control(LVS_REPORT
);
2223 for (i
=0;i
<items
;i
++) {
2224 insert_item(hwnd
, 0);
2226 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2227 expect(items
,item_count
);
2229 /* try with NULL pointer */
2230 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, 0);
2233 /* select all, check notifications */
2235 item
.stateMask
= LVIS_SELECTED
;
2236 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2238 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2240 item
.stateMask
= LVIS_SELECTED
;
2241 item
.state
= LVIS_SELECTED
;
2242 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2245 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2246 "select all notification", FALSE
);
2248 /* select all again (all selected already) */
2249 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2251 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2253 item
.stateMask
= LVIS_SELECTED
;
2254 item
.state
= LVIS_SELECTED
;
2255 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2258 ok(g_nmlistview_changing
.uNewState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2259 ok(g_nmlistview_changing
.uOldState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2260 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2262 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2263 "select all notification 2", FALSE
);
2265 /* deselect all items */
2266 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2269 item
.stateMask
= LVIS_SELECTED
;
2270 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2272 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2273 "deselect all notification", FALSE
);
2275 /* deselect all items again */
2276 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2278 item
.stateMask
= LVIS_SELECTED
;
2279 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2280 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "deselect all notification 2", FALSE
);
2282 /* any non-zero state value does the same */
2283 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2285 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2287 item
.stateMask
= LVIS_SELECTED
;
2288 item
.state
= LVIS_CUT
;
2289 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2292 ok(g_nmlistview_changing
.uNewState
== 0, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2293 ok(g_nmlistview_changing
.uOldState
== 0, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2294 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2296 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2297 "set state all notification 3", FALSE
);
2299 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2300 for (i
= 0; i
< 3; i
++) {
2301 item
.state
= LVIS_SELECTED
;
2302 item
.stateMask
= LVIS_SELECTED
;
2303 SendMessageA(hwnd
, LVM_SETITEMSTATE
, i
, (LPARAM
)&item
);
2306 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2308 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2311 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2312 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2313 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2314 /* check that style is accepted */
2315 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2316 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2319 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2320 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2322 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2324 SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2327 /* select one more */
2328 item
.state
= LVIS_SELECTED
;
2329 item
.stateMask
= LVIS_SELECTED
;
2330 SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
2333 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2334 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2336 r
= ListView_GetItemState(hwnd
, 3, LVIS_SELECTED
);
2337 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2339 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2341 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2344 /* try to select all on LVS_SINGLESEL */
2345 memset(&item
, 0, sizeof(item
));
2346 item
.stateMask
= LVIS_SELECTED
;
2347 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2349 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2351 item
.stateMask
= LVIS_SELECTED
;
2352 item
.state
= LVIS_SELECTED
;
2353 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2356 r
= ListView_GetSelectedCount(hwnd
);
2358 r
= ListView_GetSelectionMark(hwnd
);
2361 /* try to deselect all on LVS_SINGLESEL */
2362 item
.stateMask
= LVIS_SELECTED
;
2363 item
.state
= LVIS_SELECTED
;
2364 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2367 item
.stateMask
= LVIS_SELECTED
;
2369 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2371 r
= ListView_GetSelectedCount(hwnd
);
2374 /* 1. selection mark is update when new focused item is set */
2375 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2376 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2378 r
= SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2381 item
.stateMask
= LVIS_FOCUSED
;
2382 item
.state
= LVIS_FOCUSED
;
2383 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2386 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2389 /* it's not updated if already set */
2390 item
.stateMask
= LVIS_FOCUSED
;
2391 item
.state
= LVIS_FOCUSED
;
2392 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2395 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2398 r
= SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2401 item
.stateMask
= LVIS_FOCUSED
;
2402 item
.state
= LVIS_FOCUSED
;
2403 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2406 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2409 /* need to reset focused item first */
2410 item
.stateMask
= LVIS_FOCUSED
;
2412 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2415 item
.stateMask
= LVIS_FOCUSED
;
2416 item
.state
= LVIS_FOCUSED
;
2417 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
2420 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2423 item
.stateMask
= LVIS_FOCUSED
;
2425 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2428 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2431 /* 2. same tests, with LVM_SETITEM */
2432 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2433 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2435 r
= SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2438 item
.stateMask
= LVIS_FOCUSED
;
2439 item
.state
= LVIS_FOCUSED
;
2440 item
.mask
= LVIF_STATE
;
2441 item
.iItem
= item
.iSubItem
= 0;
2442 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2445 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2448 /* it's not updated if already set */
2449 item
.stateMask
= LVIS_FOCUSED
;
2450 item
.state
= LVIS_FOCUSED
;
2451 item
.mask
= LVIF_STATE
;
2454 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2457 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2460 r
= SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2463 item
.stateMask
= LVIS_FOCUSED
;
2464 item
.state
= LVIS_FOCUSED
;
2465 item
.mask
= LVIF_STATE
;
2468 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2471 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2474 /* need to reset focused item first */
2475 item
.stateMask
= LVIS_FOCUSED
;
2477 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2480 item
.stateMask
= LVIS_FOCUSED
;
2481 item
.state
= LVIS_FOCUSED
;
2482 item
.mask
= LVIF_STATE
;
2485 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2488 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2491 item
.stateMask
= LVIS_FOCUSED
;
2493 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2496 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2499 DestroyWindow(hwnd
);
2502 static void test_subitem_rect(void)
2510 /* test LVM_GETSUBITEMRECT for header */
2511 hwnd
= create_listview_control(LVS_REPORT
);
2512 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2513 /* add some columns */
2514 memset(&col
, 0, sizeof(LVCOLUMN
));
2515 col
.mask
= LVCF_WIDTH
;
2517 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2520 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2523 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2525 /* item = -1 means header, subitem index is 1 based */
2526 rect
.left
= LVIR_BOUNDS
;
2528 rect
.right
= rect
.bottom
= 0;
2529 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2532 rect
.left
= LVIR_BOUNDS
;
2534 rect
.right
= rect
.bottom
= 0;
2535 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2538 expect(100, rect
.left
);
2539 expect(250, rect
.right
);
2540 expect(3, rect
.top
);
2542 rect
.left
= LVIR_BOUNDS
;
2544 rect
.right
= rect
.bottom
= 0;
2545 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2548 expect(250, rect
.left
);
2549 expect(450, rect
.right
);
2550 expect(3, rect
.top
);
2552 /* item LVS_REPORT padding isn't applied to subitems */
2553 insert_item(hwnd
, 0);
2555 rect
.left
= LVIR_BOUNDS
;
2557 rect
.right
= rect
.bottom
= 0;
2558 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2560 expect(100, rect
.left
);
2561 expect(250, rect
.right
);
2563 rect
.left
= LVIR_ICON
;
2565 rect
.right
= rect
.bottom
= 0;
2566 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2568 /* no icon attached - zero width rectangle, with no left padding */
2569 expect(100, rect
.left
);
2570 expect(100, rect
.right
);
2572 rect
.left
= LVIR_LABEL
;
2574 rect
.right
= rect
.bottom
= 0;
2575 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2577 /* same as full LVIR_BOUNDS */
2578 expect(100, rect
.left
);
2579 expect(250, rect
.right
);
2581 SendMessage(hwnd
, LVM_SCROLL
, 10, 0);
2583 rect
.left
= LVIR_BOUNDS
;
2585 rect
.right
= rect
.bottom
= 0;
2586 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2588 expect(90, rect
.left
);
2589 expect(240, rect
.right
);
2591 SendMessage(hwnd
, LVM_SCROLL
, -10, 0);
2593 /* test header interaction */
2594 subclass_header(hwnd
);
2595 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2597 rect
.left
= LVIR_BOUNDS
;
2599 rect
.right
= rect
.bottom
= 0;
2600 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2603 rect
.left
= LVIR_BOUNDS
;
2605 rect
.right
= rect
.bottom
= 0;
2606 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2609 rect
.left
= LVIR_BOUNDS
;
2611 rect
.right
= rect
.bottom
= 0;
2612 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -10, (LPARAM
)&rect
);
2615 rect
.left
= LVIR_BOUNDS
;
2617 rect
.right
= rect
.bottom
= 0;
2618 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 20, (LPARAM
)&rect
);
2621 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getsubitemrect_seq
, "LVM_GETSUBITEMRECT negative index", FALSE
);
2623 DestroyWindow(hwnd
);
2625 /* test subitem rects after re-arranging columns */
2626 hwnd
= create_listview_control(LVS_REPORT
);
2627 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2628 memset(&col
, 0, sizeof(LVCOLUMN
));
2629 col
.mask
= LVCF_WIDTH
;
2632 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2636 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2640 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2643 insert_item(hwnd
, 0);
2644 insert_item(hwnd
, 1);
2646 /* wrong item is refused for main item */
2647 rect
.left
= LVIR_BOUNDS
;
2649 rect
.right
= rect
.bottom
= -1;
2650 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect
);
2653 /* for subitems rectangle is calculated even if there's no item added */
2654 rect
.left
= LVIR_BOUNDS
;
2656 rect
.right
= rect
.bottom
= -1;
2657 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect
);
2660 rect2
.left
= LVIR_BOUNDS
;
2662 rect2
.right
= rect2
.bottom
= -1;
2663 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect2
);
2665 expect(rect
.right
, rect2
.right
);
2666 expect(rect
.left
, rect2
.left
);
2667 expect(rect
.bottom
, rect2
.top
);
2668 ok(rect2
.bottom
> rect2
.top
, "expected not zero height\n");
2670 arr
[0] = 1; arr
[1] = 0; arr
[2] = 2;
2671 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 3, (LPARAM
)arr
);
2674 rect
.left
= LVIR_BOUNDS
;
2676 rect
.right
= rect
.bottom
= -1;
2677 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2679 expect(0, rect
.left
);
2680 expect(600, rect
.right
);
2682 rect
.left
= LVIR_BOUNDS
;
2684 rect
.right
= rect
.bottom
= -1;
2685 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2687 expect(0, rect
.left
);
2688 expect(200, rect
.right
);
2690 rect2
.left
= LVIR_BOUNDS
;
2692 rect2
.right
= rect2
.bottom
= -1;
2693 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect2
);
2695 expect(0, rect2
.left
);
2696 expect(200, rect2
.right
);
2697 /* items are of the same height */
2698 ok(rect2
.top
> 0, "expected positive item height\n");
2699 expect(rect
.bottom
, rect2
.top
);
2700 expect(rect
.bottom
* 2 - rect
.top
, rect2
.bottom
);
2702 rect
.left
= LVIR_BOUNDS
;
2704 rect
.right
= rect
.bottom
= -1;
2705 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2707 expect(300, rect
.left
);
2708 expect(600, rect
.right
);
2710 DestroyWindow(hwnd
);
2712 /* try it for non LVS_REPORT style */
2713 hwnd
= CreateWindow("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2714 GetModuleHandle(NULL
), 0);
2715 rect
.left
= LVIR_BOUNDS
;
2717 rect
.right
= rect
.bottom
= -10;
2718 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2720 /* rect is unchanged */
2721 expect(0, rect
.left
);
2722 expect(-10, rect
.right
);
2723 expect(1, rect
.top
);
2724 expect(-10, rect
.bottom
);
2725 DestroyWindow(hwnd
);
2728 /* comparison callback for test_sorting */
2729 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2731 if (first
== second
) return 0;
2732 return (first
> second
? 1 : -1);
2735 static void test_sorting(void)
2741 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2744 hwnd
= create_listview_control(LVS_REPORT
);
2745 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2747 /* insert some items */
2748 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2749 item
.state
= LVIS_SELECTED
;
2753 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2756 item
.mask
= LVIF_PARAM
;
2760 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2763 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2764 item
.state
= LVIS_SELECTED
;
2768 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2771 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2774 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2777 r
= SendMessage(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2780 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2782 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2784 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2786 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2787 expect(LVIS_SELECTED
, r
);
2788 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2789 expect(LVIS_SELECTED
, r
);
2791 DestroyWindow(hwnd
);
2793 /* switch to LVS_SORTASCENDING when some items added */
2794 hwnd
= create_listview_control(LVS_REPORT
);
2795 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2797 item
.mask
= LVIF_TEXT
;
2800 item
.pszText
= names
[1];
2801 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2804 item
.mask
= LVIF_TEXT
;
2807 item
.pszText
= names
[2];
2808 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2811 item
.mask
= LVIF_TEXT
;
2814 item
.pszText
= names
[0];
2815 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2818 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2819 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2820 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2821 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2823 /* no sorting performed when switched to LVS_SORTASCENDING */
2824 item
.mask
= LVIF_TEXT
;
2826 item
.pszText
= buff
;
2827 item
.cchTextMax
= sizeof(buff
);
2828 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2830 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2833 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2835 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2838 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2840 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2842 /* adding new item doesn't resort list */
2843 item
.mask
= LVIF_TEXT
;
2846 item
.pszText
= names
[3];
2847 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2850 item
.mask
= LVIF_TEXT
;
2852 item
.pszText
= buff
;
2853 item
.cchTextMax
= sizeof(buff
);
2854 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2856 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2859 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2861 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2864 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2866 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2869 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2871 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2873 /* corner case - item should be placed at first position */
2874 item
.mask
= LVIF_TEXT
;
2877 item
.pszText
= names
[4];
2878 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2882 item
.pszText
= buff
;
2883 item
.cchTextMax
= sizeof(buff
);
2884 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2886 ok(lstrcmp(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2889 item
.pszText
= buff
;
2890 item
.cchTextMax
= sizeof(buff
);
2891 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2893 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2896 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2898 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2901 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2903 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2906 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2908 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2910 DestroyWindow(hwnd
);
2913 static void test_ownerdata(void)
2915 static char test_str
[] = "test";
2918 LONG_PTR style
, ret
;
2922 /* it isn't possible to set LVS_OWNERDATA after creation */
2925 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2929 hwnd
= create_listview_control(LVS_REPORT
);
2930 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2931 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2932 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2934 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2936 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2937 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2938 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2939 "try to switch to LVS_OWNERDATA seq", FALSE
);
2941 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2942 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2943 DestroyWindow(hwnd
);
2946 /* try to set LVS_OWNERDATA after creation just having it */
2947 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2948 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2949 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2950 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2952 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2954 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2955 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2956 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2957 "try to switch to LVS_OWNERDATA seq", FALSE
);
2958 DestroyWindow(hwnd
);
2960 /* try to remove LVS_OWNERDATA after creation just having it */
2963 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2967 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2968 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2969 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2970 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2972 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2974 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2975 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2976 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2977 "try to switch to LVS_OWNERDATA seq", FALSE
);
2978 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2979 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2980 DestroyWindow(hwnd
);
2983 /* try select an item */
2984 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2985 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2986 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2988 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2990 memset(&item
, 0, sizeof(item
));
2991 item
.stateMask
= LVIS_SELECTED
;
2992 item
.state
= LVIS_SELECTED
;
2993 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2995 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2997 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2999 DestroyWindow(hwnd
);
3001 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
3002 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3003 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3004 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3006 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3008 memset(&item
, 0, sizeof(item
));
3009 item
.mask
= LVIF_STATE
;
3011 item
.stateMask
= LVIS_SELECTED
;
3012 item
.state
= LVIS_SELECTED
;
3013 res
= SendMessageA(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3015 memset(&item
, 0, sizeof(item
));
3016 item
.pszText
= test_str
;
3017 res
= SendMessageA(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
3019 DestroyWindow(hwnd
);
3021 /* check notifications after focused/selected changed */
3022 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3023 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3024 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
3027 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3029 memset(&item
, 0, sizeof(item
));
3030 item
.stateMask
= LVIS_SELECTED
;
3031 item
.state
= LVIS_SELECTED
;
3032 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3035 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
3036 "ownerdata select notification", TRUE
);
3038 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3040 memset(&item
, 0, sizeof(item
));
3041 item
.stateMask
= LVIS_FOCUSED
;
3042 item
.state
= LVIS_FOCUSED
;
3043 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3046 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
3047 "ownerdata focus notification", TRUE
);
3049 /* select all, check notifications */
3050 item
.stateMask
= LVIS_SELECTED
;
3052 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3055 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3057 item
.stateMask
= LVIS_SELECTED
;
3058 item
.state
= LVIS_SELECTED
;
3060 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3061 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3063 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3064 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3065 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3066 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3067 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3068 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3069 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3071 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3072 "ownerdata select all notification", FALSE
);
3074 /* select all again, note that all items are selected already */
3075 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3076 item
.stateMask
= LVIS_SELECTED
;
3077 item
.state
= LVIS_SELECTED
;
3079 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3080 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3082 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3083 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3084 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3085 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3086 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3087 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3088 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3090 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3091 "ownerdata select all notification", FALSE
);
3094 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3095 item
.stateMask
= LVIS_SELECTED
;
3098 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3099 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3101 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3102 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3103 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3104 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3105 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3106 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3107 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3109 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3110 "ownerdata deselect all notification", TRUE
);
3112 /* nothing selected, deselect all again */
3113 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3114 item
.stateMask
= LVIS_SELECTED
;
3117 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3120 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "ownerdata deselect all notification", FALSE
);
3122 /* select one, then deselect all */
3123 item
.stateMask
= LVIS_SELECTED
;
3124 item
.state
= LVIS_SELECTED
;
3125 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3127 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3128 item
.stateMask
= LVIS_SELECTED
;
3131 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3132 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3134 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3135 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3136 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3137 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3138 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3139 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3140 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3142 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3143 "ownerdata select all notification", TRUE
);
3145 /* remove focused, try to focus all */
3146 item
.stateMask
= LVIS_FOCUSED
;
3147 item
.state
= LVIS_FOCUSED
;
3148 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3150 item
.stateMask
= LVIS_FOCUSED
;
3152 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3154 item
.stateMask
= LVIS_FOCUSED
;
3155 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
3158 /* setting all to focused returns failure value */
3159 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3160 item
.stateMask
= LVIS_FOCUSED
;
3161 item
.state
= LVIS_FOCUSED
;
3163 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3166 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3167 "ownerdata focus all notification", FALSE
);
3169 /* focus single item, remove all */
3170 item
.stateMask
= LVIS_FOCUSED
;
3171 item
.state
= LVIS_FOCUSED
;
3172 res
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3174 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3175 item
.stateMask
= LVIS_FOCUSED
;
3178 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3179 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3181 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3182 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3183 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3184 ok(g_nmlistview
.uOldState
== LVIS_FOCUSED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3185 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3186 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3187 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3189 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
3190 "ownerdata remove focus all notification", TRUE
);
3193 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3194 item
.stateMask
= LVIS_CUT
;
3195 item
.state
= LVIS_CUT
;
3197 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3198 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3200 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3201 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3202 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3203 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3204 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3205 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3206 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3208 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3209 "ownerdata cut all notification", FALSE
);
3211 /* all marked cut, try again */
3212 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3213 item
.stateMask
= LVIS_CUT
;
3214 item
.state
= LVIS_CUT
;
3216 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3217 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3219 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3220 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3221 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3222 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3223 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3224 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3225 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3227 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3228 "ownerdata cut all notification #2", FALSE
);
3230 DestroyWindow(hwnd
);
3232 /* check notifications on LVM_GETITEM */
3233 /* zero callback mask */
3234 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3235 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3236 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3239 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3241 memset(&item
, 0, sizeof(item
));
3242 item
.stateMask
= LVIS_SELECTED
;
3243 item
.mask
= LVIF_STATE
;
3244 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3247 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3248 "ownerdata getitem selected state 1", FALSE
);
3250 /* non zero callback mask but not we asking for */
3251 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
3254 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3256 memset(&item
, 0, sizeof(item
));
3257 item
.stateMask
= LVIS_SELECTED
;
3258 item
.mask
= LVIF_STATE
;
3259 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3262 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3263 "ownerdata getitem selected state 2", FALSE
);
3265 /* LVIS_OVERLAYMASK callback mask, asking for index */
3266 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3268 memset(&item
, 0, sizeof(item
));
3269 item
.stateMask
= LVIS_OVERLAYMASK
;
3270 item
.mask
= LVIF_STATE
;
3271 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3274 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3275 "ownerdata getitem selected state 2", FALSE
);
3277 DestroyWindow(hwnd
);
3279 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3280 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
| LVS_REPORT
);
3281 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3282 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3283 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3284 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3285 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
3286 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3287 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
3288 DestroyWindow(hwnd
);
3289 /* apparently it's allowed to switch these style on after creation */
3290 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3291 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3292 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3293 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3294 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
3295 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3296 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3297 DestroyWindow(hwnd
);
3299 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3300 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3301 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3302 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3303 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
3304 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3305 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
3306 DestroyWindow(hwnd
);
3309 static void test_norecompute(void)
3311 static CHAR testA
[] = "test";
3317 /* self containing control */
3318 hwnd
= create_listview_control(LVS_REPORT
);
3319 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3320 memset(&item
, 0, sizeof(item
));
3321 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
3323 item
.stateMask
= LVIS_SELECTED
;
3324 item
.state
= LVIS_SELECTED
;
3325 item
.pszText
= testA
;
3326 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
3328 /* retrieve with LVIF_NORECOMPUTE */
3329 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3331 item
.pszText
= buff
;
3332 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3333 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3335 ok(lstrcmp(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
3337 item
.mask
= LVIF_TEXT
;
3339 item
.pszText
= LPSTR_TEXTCALLBACK
;
3340 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
3343 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3345 item
.pszText
= buff
;
3346 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3348 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3349 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3351 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
3352 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
3353 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
3355 DestroyWindow(hwnd
);
3358 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3359 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3361 item
.mask
= LVIF_STATE
;
3362 item
.stateMask
= LVIS_SELECTED
;
3363 item
.state
= LVIS_SELECTED
;
3365 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
3368 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3370 item
.pszText
= buff
;
3371 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3372 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3373 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3375 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
3376 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
3377 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
3379 DestroyWindow(hwnd
);
3382 static void test_nosortheader(void)
3387 hwnd
= create_listview_control(LVS_REPORT
);
3388 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3390 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3391 ok(IsWindow(header
), "header expected\n");
3393 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3394 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
3396 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3397 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
3398 /* HDS_BUTTONS retained */
3399 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3400 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
3402 DestroyWindow(hwnd
);
3404 /* create with LVS_NOSORTHEADER */
3405 hwnd
= create_listview_control(LVS_NOSORTHEADER
| LVS_REPORT
);
3406 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3408 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3409 ok(IsWindow(header
), "header expected\n");
3411 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3412 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3414 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3415 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
3416 /* not changed here */
3417 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3418 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3420 DestroyWindow(hwnd
);
3423 static void test_setredraw(void)
3431 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3432 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3434 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3435 ListView seems to handle it internally without DefWinProc */
3437 /* default value first */
3438 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3441 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3442 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3443 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3445 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3446 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3447 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3450 /* check update rect after redrawing */
3451 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3453 InvalidateRect(hwnd
, NULL
, FALSE
);
3454 RedrawWindow(hwnd
, NULL
, NULL
, RDW_UPDATENOW
);
3455 rect
.right
= rect
.bottom
= 1;
3456 GetUpdateRect(hwnd
, &rect
, FALSE
);
3457 expect(0, rect
.right
);
3458 expect(0, rect
.bottom
);
3461 hdc
= GetWindowDC(hwndparent
);
3462 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3464 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3466 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3468 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3470 ReleaseDC(hwndparent
, hdc
);
3472 /* check notification messages to show that repainting is disabled */
3473 ret
= SendMessage(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3475 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3477 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3479 InvalidateRect(hwnd
, NULL
, TRUE
);
3481 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3482 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
3484 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
3486 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3487 InvalidateRect(hwnd
, NULL
, TRUE
);
3489 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3490 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
3492 /* message isn't forwarded to header */
3493 subclass_header(hwnd
);
3494 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3495 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3497 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
3498 "WM_SETREDRAW: not forwarded to header", FALSE
);
3500 DestroyWindow(hwnd
);
3503 static void test_hittest(void)
3509 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3513 HIMAGELIST himl
, himl2
;
3516 hwnd
= create_listview_control(LVS_REPORT
);
3517 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3519 /* LVS_REPORT with a single subitem (2 columns) */
3520 insert_column(hwnd
, 0);
3521 insert_column(hwnd
, 1);
3522 insert_item(hwnd
, 0);
3525 /* the only purpose of that line is to be as long as a half item rect */
3526 item
.pszText
= text
;
3527 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
3530 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3532 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3535 memset(&bounds
, 0, sizeof(bounds
));
3536 bounds
.left
= LVIR_BOUNDS
;
3537 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
3539 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
3540 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
3541 r
= SendMessage(hwnd
, LVM_GETITEMSPACING
, TRUE
, 0);
3543 ok(bounds
.bottom
- bounds
.top
== vert
,
3544 "Vertical spacing inconsistent (%d != %d)\n", bounds
.bottom
- bounds
.top
, vert
);
3545 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
3548 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3550 /* outside columns by x position - valid is [0, 199] */
3552 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3553 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TOLEFT
, 0, FALSE
, FALSE
);
3554 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3556 x
= pos
.x
+ 50; /* column half width */
3557 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3558 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, 0, FALSE
, FALSE
);
3559 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3560 x
= pos
.x
+ 150; /* outside column */
3561 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3562 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3563 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3564 y
= (bounds
.bottom
- bounds
.top
) / 2;
3565 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3566 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3567 /* outside possible client rectangle (to right) */
3569 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3570 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3571 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3572 y
= (bounds
.bottom
- bounds
.top
) / 2;
3573 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3574 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3575 /* subitem returned with -1 item too */
3577 y
= bounds
.top
- vert
;
3578 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3579 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3580 /* return values appear to underflow with negative indices */
3584 test_lvm_subitemhittest(hwnd
, x
, y
, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3585 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3589 /* parent client area is 100x100 by default */
3590 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
3591 x
= pos
.x
+ 150; /* outside column */
3592 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3593 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, FALSE
);
3594 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3595 y
= (bounds
.bottom
- bounds
.top
) / 2;
3596 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, TRUE
);
3597 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3598 /* the same with LVS_EX_FULLROWSELECT */
3599 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3600 x
= pos
.x
+ 150; /* outside column */
3601 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3602 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, LVHT_ONITEMLABEL
, FALSE
, FALSE
);
3603 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3604 y
= (bounds
.bottom
- bounds
.top
) / 2;
3605 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3606 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
3607 x
= pos
.x
+ 150; /* outside column */
3608 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3609 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3610 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3611 y
= (bounds
.bottom
- bounds
.top
) / 2;
3612 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3613 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3614 /* outside possible client rectangle (to right) */
3616 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3617 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3618 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3619 y
= (bounds
.bottom
- bounds
.top
) / 2;
3620 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3621 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3622 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3623 himl
= ImageList_Create(16, 16, 0, 4, 4);
3624 ok(himl
!= NULL
, "failed to create imagelist\n");
3625 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3626 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3627 r
= ImageList_Add(himl
, hbmp
, 0);
3628 ok(r
== 0, "should be zero\n");
3629 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3630 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3631 r
= ImageList_Add(himl
, hbmp
, 0);
3632 ok(r
== 1, "should be one\n");
3634 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3637 item
.mask
= LVIF_IMAGE
;
3641 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3645 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3646 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3647 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3648 y
= (bounds
.bottom
- bounds
.top
) / 2;
3649 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3651 /* state icons indices are 1 based, check with valid index */
3652 item
.mask
= LVIF_STATE
;
3653 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3654 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3657 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3661 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3662 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3663 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3664 y
= (bounds
.bottom
- bounds
.top
) / 2;
3665 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3667 himl2
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3668 ok(himl2
== himl
, "should return handle\n");
3670 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3674 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3675 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, 0, FALSE
, FALSE
);
3676 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3677 y
= (bounds
.bottom
- bounds
.top
) / 2;
3678 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3680 DestroyWindow(hwnd
);
3683 static void test_getviewrect(void)
3690 hwnd
= create_listview_control(LVS_REPORT
);
3691 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3694 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3697 insert_column(hwnd
, 0);
3698 insert_column(hwnd
, 1);
3700 memset(&item
, 0, sizeof(item
));
3703 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3705 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3707 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3710 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3711 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3713 /* left is set to (2e31-1) - XP SP2 */
3714 expect(0, rect
.right
);
3715 expect(0, rect
.top
);
3716 expect(0, rect
.bottom
);
3718 /* switch to LVS_ICON */
3719 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3721 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3722 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3724 expect(0, rect
.left
);
3725 expect(0, rect
.top
);
3726 /* precise value differs for 2k, XP and Vista */
3727 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3728 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3730 DestroyWindow(hwnd
);
3733 static void test_getitemposition(void)
3740 hwnd
= create_listview_control(LVS_REPORT
);
3741 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3742 header
= subclass_header(hwnd
);
3744 /* LVS_REPORT, single item, no columns added */
3745 insert_item(hwnd
, 0);
3747 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3750 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3752 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3754 /* LVS_REPORT, single item, single column */
3755 insert_column(hwnd
, 0);
3757 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3760 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3762 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3764 memset(&rect
, 0, sizeof(rect
));
3765 SendMessage(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3768 /* offset by header height */
3769 expect(rect
.bottom
- rect
.top
, pt
.y
);
3771 DestroyWindow(hwnd
);
3774 static void test_columnscreation(void)
3779 hwnd
= create_listview_control(LVS_REPORT
);
3780 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3782 insert_item(hwnd
, 0);
3784 /* headers columns aren't created automatically */
3785 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3786 ok(IsWindow(header
), "Expected header handle\n");
3787 r
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
3790 DestroyWindow(hwnd
);
3793 static void test_getitemrect(void)
3796 HIMAGELIST himl
, himl_ret
;
3806 /* rectangle isn't empty for empty text items */
3807 hwnd
= create_listview_control(LVS_LIST
);
3808 memset(&item
, 0, sizeof(item
));
3811 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3813 rect
.left
= LVIR_LABEL
;
3814 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3816 expect(0, rect
.left
);
3817 expect(0, rect
.top
);
3819 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, rect
.right
);
3820 ReleaseDC(hwnd
, hdc
);
3821 DestroyWindow(hwnd
);
3823 hwnd
= create_listview_control(LVS_REPORT
);
3824 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3827 memset(&item
, 0, sizeof(item
));
3830 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3833 rect
.left
= LVIR_BOUNDS
;
3834 rect
.right
= rect
.top
= rect
.bottom
= -1;
3835 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3838 /* zero width rectangle with no padding */
3839 expect(0, rect
.left
);
3840 expect(0, rect
.right
);
3842 insert_column(hwnd
, 0);
3843 insert_column(hwnd
, 1);
3845 col
.mask
= LVCF_WIDTH
;
3847 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 0, (LPARAM
)&col
);
3850 col
.mask
= LVCF_WIDTH
;
3852 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 1, (LPARAM
)&col
);
3855 rect
.left
= LVIR_BOUNDS
;
3856 rect
.right
= rect
.top
= rect
.bottom
= -1;
3857 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3860 /* still no left padding */
3861 expect(0, rect
.left
);
3862 expect(150, rect
.right
);
3864 rect
.left
= LVIR_SELECTBOUNDS
;
3865 rect
.right
= rect
.top
= rect
.bottom
= -1;
3866 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3869 expect(2, rect
.left
);
3871 rect
.left
= LVIR_LABEL
;
3872 rect
.right
= rect
.top
= rect
.bottom
= -1;
3873 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3875 /* padding, column width */
3876 expect(2, rect
.left
);
3877 expect(50, rect
.right
);
3879 /* no icons attached */
3880 rect
.left
= LVIR_ICON
;
3881 rect
.right
= rect
.top
= rect
.bottom
= -1;
3882 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3885 expect(2, rect
.left
);
3886 expect(2, rect
.right
);
3889 order
[0] = 1; order
[1] = 0;
3890 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3893 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3895 /* 1 indexed column width + padding */
3897 /* rect is at zero too */
3898 rect
.left
= LVIR_BOUNDS
;
3899 rect
.right
= rect
.top
= rect
.bottom
= -1;
3900 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3902 expect(0, rect
.left
);
3903 /* just width sum */
3904 expect(150, rect
.right
);
3906 rect
.left
= LVIR_SELECTBOUNDS
;
3907 rect
.right
= rect
.top
= rect
.bottom
= -1;
3908 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3910 /* column width + padding */
3911 expect(102, rect
.left
);
3913 /* back to initial order */
3914 order
[0] = 0; order
[1] = 1;
3915 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3919 himl
= ImageList_Create(16, 16, 0, 2, 2);
3920 ok(himl
!= NULL
, "failed to create imagelist\n");
3921 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3922 ok(hbm
!= NULL
, "failed to create bitmap\n");
3923 r
= ImageList_Add(himl
, hbm
, 0);
3925 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3926 ok(hbm
!= NULL
, "failed to create bitmap\n");
3927 r
= ImageList_Add(himl
, hbm
, 0);
3930 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3933 item
.mask
= LVIF_STATE
;
3934 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3935 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3938 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3942 rect
.left
= LVIR_ICON
;
3943 rect
.right
= rect
.top
= rect
.bottom
= -1;
3944 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3946 /* padding + stateicon width */
3947 expect(18, rect
.left
);
3948 expect(18, rect
.right
);
3950 rect
.left
= LVIR_LABEL
;
3951 rect
.right
= rect
.top
= rect
.bottom
= -1;
3952 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3954 /* padding + stateicon width -> column width */
3955 expect(18, rect
.left
);
3956 expect(50, rect
.right
);
3958 himl_ret
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3959 ok(himl_ret
== himl
, "got %p, expected %p\n", himl_ret
, himl
);
3961 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3964 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3967 item
.stateMask
= ~0;
3970 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3974 rect
.left
= LVIR_ICON
;
3975 rect
.right
= rect
.top
= rect
.bottom
= -1;
3976 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3978 /* padding, icon width */
3979 expect(2, rect
.left
);
3980 expect(18, rect
.right
);
3982 rect
.left
= LVIR_LABEL
;
3983 rect
.right
= rect
.top
= rect
.bottom
= -1;
3984 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3986 /* padding + icon width -> column width */
3987 expect(18, rect
.left
);
3988 expect(50, rect
.right
);
3991 rect
.left
= LVIR_SELECTBOUNDS
;
3992 rect
.right
= rect
.top
= rect
.bottom
= -1;
3993 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3995 /* padding, column width */
3996 expect(2, rect
.left
);
3997 expect(50, rect
.right
);
3999 /* try with indentation */
4000 item
.mask
= LVIF_INDENT
;
4004 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
4008 rect
.left
= LVIR_BOUNDS
;
4009 rect
.right
= rect
.top
= rect
.bottom
= -1;
4010 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4012 /* padding + 1 icon width, column width */
4013 expect(0, rect
.left
);
4014 expect(150, rect
.right
);
4017 rect
.left
= LVIR_SELECTBOUNDS
;
4018 rect
.right
= rect
.top
= rect
.bottom
= -1;
4019 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4021 /* padding + 1 icon width, column width */
4022 expect(2 + 16, rect
.left
);
4023 expect(50, rect
.right
);
4026 rect
.left
= LVIR_LABEL
;
4027 rect
.right
= rect
.top
= rect
.bottom
= -1;
4028 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4030 /* padding + 2 icon widths, column width */
4031 expect(2 + 16*2, rect
.left
);
4032 expect(50, rect
.right
);
4035 rect
.left
= LVIR_ICON
;
4036 rect
.right
= rect
.top
= rect
.bottom
= -1;
4037 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4039 /* padding + 1 icon width indentation, icon width */
4040 expect(2 + 16, rect
.left
);
4041 expect(34, rect
.right
);
4043 DestroyWindow(hwnd
);
4046 static void test_editbox(void)
4048 static CHAR testitemA
[] = "testitem";
4049 static CHAR testitem1A
[] = "testitem_quitelongname";
4050 static CHAR testitem2A
[] = "testITEM_quitelongname";
4051 static CHAR buffer
[25];
4052 HWND hwnd
, hwndedit
, hwndedit2
, header
;
4056 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4057 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4059 insert_column(hwnd
, 0);
4061 memset(&item
, 0, sizeof(item
));
4062 item
.mask
= LVIF_TEXT
;
4063 item
.pszText
= testitemA
;
4066 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4069 /* test notifications without edit created */
4070 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4071 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)0xdeadbeef);
4073 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4074 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE
);
4075 /* same thing but with valid window */
4076 hwndedit
= CreateWindowA("Edit", "Test edit", WS_VISIBLE
| WS_CHILD
, 0, 0, 20,
4077 10, hwnd
, (HMENU
)1, (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
), 0);
4078 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4079 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)hwndedit
);
4081 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4082 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE
);
4083 DestroyWindow(hwndedit
);
4085 /* setting focus is necessary */
4087 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4088 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4090 /* test children Z-order after Edit box created */
4091 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4092 ok(IsWindow(header
), "Expected header to be created\n");
4093 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4094 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4096 /* modify initial string */
4097 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4100 /* edit window is resized and repositioned,
4101 check again for Z-order - it should be preserved */
4102 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4103 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4105 /* return focus to listview */
4108 memset(&item
, 0, sizeof(item
));
4109 item
.mask
= LVIF_TEXT
;
4110 item
.pszText
= buffer
;
4111 item
.cchTextMax
= sizeof(buffer
);
4114 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
4117 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4119 /* send LVM_EDITLABEL on already created edit */
4121 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4122 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4123 /* focus will be set to edit */
4124 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
4125 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4126 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
4128 /* creating label disabled when control isn't focused */
4130 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4131 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4133 /* check EN_KILLFOCUS handling */
4134 memset(&item
, 0, sizeof(item
));
4135 item
.pszText
= testitemA
;
4138 r
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
4142 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4143 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4144 /* modify edit and notify control that it lost focus */
4145 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4147 g_editbox_disp_info
.item
.pszText
= NULL
;
4148 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4150 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "expected notification with not null text\n");
4152 memset(&item
, 0, sizeof(item
));
4153 item
.pszText
= buffer
;
4154 item
.cchTextMax
= sizeof(buffer
);
4157 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4158 expect(lstrlen(item
.pszText
), r
);
4159 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4160 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4162 /* change item name to differ in casing only */
4164 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4165 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4166 /* modify edit and notify control that it lost focus */
4167 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem2A
);
4169 g_editbox_disp_info
.item
.pszText
= NULL
;
4170 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4172 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "got %p\n", g_editbox_disp_info
.item
.pszText
);
4174 memset(&item
, 0, sizeof(item
));
4175 item
.pszText
= buffer
;
4176 item
.cchTextMax
= sizeof(buffer
);
4179 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4180 expect(lstrlen(item
.pszText
), r
);
4181 ok(strcmp(buffer
, testitem2A
) == 0, "got %s, expected %s\n", buffer
, testitem2A
);
4182 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4184 /* end edit without saving */
4186 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4187 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4188 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
4190 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4191 "edit box - end edit, no change, escape", TRUE
);
4192 /* end edit with saving */
4194 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4195 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4196 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_RETURN
, 0);
4198 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4199 "edit box - end edit, no change, return", TRUE
);
4201 memset(&item
, 0, sizeof(item
));
4202 item
.pszText
= buffer
;
4203 item
.cchTextMax
= sizeof(buffer
);
4206 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4207 expect(lstrlen(item
.pszText
), r
);
4208 ok(strcmp(buffer
, testitem2A
) == 0, "Expected item text to change\n");
4210 /* LVM_EDITLABEL with -1 destroys current edit */
4211 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
4212 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4213 /* no edit present */
4214 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
4215 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4216 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4217 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4219 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4220 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
4221 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4222 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4223 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4224 /* check another negative value */
4225 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4226 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4227 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4228 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -2, 0);
4229 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4230 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4231 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4232 /* and value greater than max item index */
4233 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4234 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4235 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4236 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
4237 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, r
, 0);
4238 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4239 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4240 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4242 /* messaging tests */
4244 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4246 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4247 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4248 /* testing only sizing messages */
4249 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
4250 "edit box create - sizing", FALSE
);
4252 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4254 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4255 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4256 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4257 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4259 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4260 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE
);
4262 DestroyWindow(hwnd
);
4265 static void test_notifyformat(void)
4270 hwnd
= create_listview_control(LVS_REPORT
);
4271 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4273 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4274 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4275 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4277 SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4279 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
4281 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4284 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
4286 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4291 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4292 DestroyWindow(hwnd
);
4296 DestroyWindow(hwnd
);
4298 /* test failure in parent WM_NOTIFYFORMAT */
4300 hwnd
= create_listview_control(LVS_REPORT
);
4301 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4302 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4303 ok(IsWindow(header
), "expected header to be created\n");
4304 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4306 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4307 ok( r
== 1, "Expected 1, got %d\n", r
);
4308 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4309 ok(r
!= 0, "Expected valid format\n");
4311 notifyFormat
= NFR_UNICODE
;
4312 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4313 expect(NFR_UNICODE
, r
);
4314 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4316 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4317 ok( r
== 1, "Expected 1, got %d\n", r
);
4319 notifyFormat
= NFR_ANSI
;
4320 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4321 expect(NFR_ANSI
, r
);
4322 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4324 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4325 ok( r
== 1, "Expected 1, got %d\n", r
);
4327 DestroyWindow(hwnd
);
4329 hwndparentW
= create_parent_window(TRUE
);
4330 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
4331 if (!IsWindow(hwndparentW
)) return;
4334 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4335 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4336 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4337 ok(IsWindow(header
), "expected header to be created\n");
4338 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4340 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4342 DestroyWindow(hwnd
);
4343 /* receiving error code defaulting to ansi */
4345 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4346 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4347 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4348 ok(IsWindow(header
), "expected header to be created\n");
4349 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4351 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4353 DestroyWindow(hwnd
);
4354 /* receiving ansi code from unicode window, use it */
4355 notifyFormat
= NFR_ANSI
;
4356 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4357 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4358 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4359 ok(IsWindow(header
), "expected header to be created\n");
4360 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4362 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4364 DestroyWindow(hwnd
);
4365 /* unicode listview with ansi parent window */
4367 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4368 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4369 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4370 ok(IsWindow(header
), "expected header to be created\n");
4371 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4373 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4375 DestroyWindow(hwnd
);
4376 /* unicode listview with ansi parent window, return error code */
4378 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4379 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4380 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4381 ok(IsWindow(header
), "expected header to be created\n");
4382 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4384 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4386 DestroyWindow(hwnd
);
4388 DestroyWindow(hwndparentW
);
4391 static void test_indentation(void)
4397 hwnd
= create_listview_control(LVS_REPORT
);
4398 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4400 memset(&item
, 0, sizeof(item
));
4401 item
.mask
= LVIF_INDENT
;
4403 item
.iIndent
= I_INDENTCALLBACK
;
4404 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4407 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4410 item
.mask
= LVIF_INDENT
;
4411 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
4414 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
4415 "get indent dispinfo", FALSE
);
4417 DestroyWindow(hwnd
);
4420 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
4425 static BOOL
is_below_comctl_5(void)
4430 hwnd
= create_listview_control(LVS_REPORT
);
4431 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4432 insert_item(hwnd
, 0);
4434 ret
= SendMessage(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
4436 DestroyWindow(hwnd
);
4441 static void test_get_set_view(void)
4447 /* test style->view mapping */
4448 hwnd
= create_listview_control(LVS_REPORT
);
4449 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4451 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4452 expect(LV_VIEW_DETAILS
, ret
);
4454 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4456 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
4457 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4458 expect(LV_VIEW_ICON
, ret
);
4460 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4461 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
4462 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4463 expect(LV_VIEW_SMALLICON
, ret
);
4465 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4466 SetWindowLongPtr(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
4467 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4468 expect(LV_VIEW_LIST
, ret
);
4470 /* switching view doesn't touch window style */
4471 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
4473 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4474 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4475 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
4477 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4478 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4479 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
4481 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4482 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4484 DestroyWindow(hwnd
);
4487 static void test_canceleditlabel(void)
4489 HWND hwnd
, hwndedit
;
4493 static CHAR test
[] = "test";
4494 static const CHAR test1
[] = "test1";
4496 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4497 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4499 insert_item(hwnd
, 0);
4501 /* try without edit created */
4502 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4503 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4505 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4506 "cancel edit label without edit", FALSE
);
4508 /* cancel without data change */
4510 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4511 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4512 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4514 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4516 /* cancel after data change */
4517 memset(&itema
, 0, sizeof(itema
));
4518 itema
.pszText
= test
;
4519 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
4522 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4523 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4524 ret
= SetWindowText(hwndedit
, test1
);
4526 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4528 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4529 memset(&itema
, 0, sizeof(itema
));
4530 itema
.pszText
= buff
;
4531 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
4532 ret
= SendMessage(hwnd
, LVM_GETITEMTEXT
, 0, (LPARAM
)&itema
);
4534 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
4536 DestroyWindow(hwnd
);
4539 static void test_mapidindex(void)
4544 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4545 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
4546 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4547 insert_item(hwnd
, 0);
4548 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4550 DestroyWindow(hwnd
);
4552 hwnd
= create_listview_control(LVS_REPORT
);
4553 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4555 /* LVM_MAPINDEXTOID with invalid index */
4556 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4559 insert_item(hwnd
, 0);
4560 insert_item(hwnd
, 1);
4562 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
4564 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
4567 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4569 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4571 /* remove 0 indexed item, id retained */
4572 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
4573 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4575 /* new id starts from previous value */
4576 insert_item(hwnd
, 1);
4577 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4580 /* get index by id */
4581 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
4583 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
4585 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
4587 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
4590 DestroyWindow(hwnd
);
4593 static void test_getitemspacing(void)
4598 HIMAGELIST himl40
, himl80
;
4600 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
4601 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
4604 hwnd
= create_listview_control(LVS_ICON
);
4605 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4606 expect(cx
, LOWORD(ret
));
4607 expect(cy
, HIWORD(ret
));
4609 /* now try with icons */
4610 himl40
= ImageList_Create(40, 40, 0, 4, 4);
4611 ok(himl40
!= NULL
, "failed to create imagelist\n");
4612 himl80
= ImageList_Create(80, 80, 0, 4, 4);
4613 ok(himl80
!= NULL
, "failed to create imagelist\n");
4614 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4617 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4618 /* spacing + icon size returned */
4619 expect(cx
+ 40, LOWORD(ret
));
4620 expect(cy
+ 40, HIWORD(ret
));
4621 /* try changing icon size */
4622 SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl80
);
4624 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4625 /* spacing + icon size returned */
4626 expect(cx
+ 80, LOWORD(ret
));
4627 expect(cy
+ 80, HIWORD(ret
));
4629 /* set own icon spacing */
4630 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(100, 100));
4631 expect(cx
+ 80, LOWORD(ret
));
4632 expect(cy
+ 80, HIWORD(ret
));
4634 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4635 /* set size returned */
4636 expect(100, LOWORD(ret
));
4637 expect(100, HIWORD(ret
));
4639 /* now change image list - icon spacing should be unaffected */
4640 SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4642 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4643 /* set size returned */
4644 expect(100, LOWORD(ret
));
4645 expect(100, HIWORD(ret
));
4647 /* spacing = 0 - keep previous value */
4648 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(0, -1));
4649 expect(100, LOWORD(ret
));
4650 expect(100, HIWORD(ret
));
4652 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4653 expect(100, LOWORD(ret
));
4655 expect(0xFFFF, HIWORD(ret
));
4657 if (sizeof(void*) == 8)
4659 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4660 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, (DWORD
)-1);
4661 expect(100, LOWORD(ret
));
4662 expect(0xFFFF, HIWORD(ret
));
4664 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, -1);
4665 expect(0xFFFF, LOWORD(ret
));
4666 expect(0xFFFF, HIWORD(ret
));
4670 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, -1);
4671 expect(100, LOWORD(ret
));
4672 expect(0xFFFF, HIWORD(ret
));
4674 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4675 /* spacing + icon size returned */
4676 expect(cx
+ 40, LOWORD(ret
));
4677 expect(cy
+ 40, HIWORD(ret
));
4679 SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, 0);
4680 ImageList_Destroy(himl80
);
4681 DestroyWindow(hwnd
);
4683 hwnd
= create_listview_control(LVS_SMALLICON
);
4684 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4685 expect(cx
, LOWORD(ret
));
4686 expect(cy
, HIWORD(ret
));
4688 /* spacing does not depend on selected view type */
4689 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4692 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4693 /* spacing + icon size returned */
4694 expect(cx
+ 40, LOWORD(ret
));
4695 expect(cy
+ 40, HIWORD(ret
));
4697 SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, 0);
4698 ImageList_Destroy(himl40
);
4699 DestroyWindow(hwnd
);
4701 hwnd
= create_listview_control(LVS_REPORT
);
4702 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4703 expect(cx
, LOWORD(ret
));
4704 expect(cy
, HIWORD(ret
));
4706 DestroyWindow(hwnd
);
4708 hwnd
= create_listview_control(LVS_LIST
);
4709 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4710 expect(cx
, LOWORD(ret
));
4711 expect(cy
, HIWORD(ret
));
4713 DestroyWindow(hwnd
);
4716 static void test_getcolumnwidth(void)
4725 /* default column width */
4726 hwnd
= create_listview_control(LVS_ICON
);
4727 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4729 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4730 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
4731 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4732 todo_wine
expect(8, ret
);
4733 style
= GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
4734 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
4736 ret
= SendMessage(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4738 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4740 DestroyWindow(hwnd
);
4742 /* default column width with item added */
4743 hwnd
= create_listview_control(LVS_LIST
);
4744 memset(&itema
, 0, sizeof(itema
));
4745 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4746 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4748 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, ret
);
4749 ReleaseDC(hwnd
, hdc
);
4750 DestroyWindow(hwnd
);
4753 static void test_scrollnotify(void)
4758 hwnd
= create_listview_control(LVS_REPORT
);
4760 insert_column(hwnd
, 0);
4761 insert_column(hwnd
, 1);
4762 insert_item(hwnd
, 0);
4764 /* make it scrollable - resize */
4765 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
4767 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
4770 /* try with dummy call */
4771 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4772 ret
= SendMessage(hwnd
, LVM_SCROLL
, 0, 0);
4774 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4775 "scroll notify 1", TRUE
);
4777 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4778 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 0);
4780 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4781 "scroll notify 2", TRUE
);
4783 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4784 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 1);
4786 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4787 "scroll notify 3", TRUE
);
4789 DestroyWindow(hwnd
);
4792 static void test_LVS_EX_TRANSPARENTBKGND(void)
4798 hwnd
= create_listview_control(LVS_REPORT
);
4800 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4803 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4804 LVS_EX_TRANSPARENTBKGND
);
4806 ret
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, 0);
4807 if (ret
!= CLR_NONE
)
4809 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4810 DestroyWindow(hwnd
);
4814 /* try to set some back color and check this style bit */
4815 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4817 ret
= SendMessage(hwnd
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
4818 ok(!(ret
& LVS_EX_TRANSPARENTBKGND
), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4820 /* now test what this style actually does */
4821 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4822 LVS_EX_TRANSPARENTBKGND
);
4824 hdc
= GetWindowDC(hwndparent
);
4826 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4827 SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
4828 ok_sequence(sequences
, PARENT_SEQ_INDEX
, lvs_ex_transparentbkgnd_seq
,
4829 "LVS_EX_TRANSPARENTBKGND parent", FALSE
);
4831 ReleaseDC(hwndparent
, hdc
);
4833 DestroyWindow(hwnd
);
4836 static void test_approximate_viewrect(void)
4843 static CHAR test
[] = "abracadabra, a very long item label";
4845 hwnd
= create_listview_control(LVS_ICON
);
4846 himl
= ImageList_Create(40, 40, 0, 4, 4);
4847 ok(himl
!= NULL
, "failed to create imagelist\n");
4848 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4849 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4850 ret
= ImageList_Add(himl
, hbmp
, 0);
4852 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4855 itema
.mask
= LVIF_IMAGE
;
4859 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
4862 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(75, 75));
4866 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4870 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4871 expect(MAKELONG(77,827), ret
);
4873 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(50, 50));
4874 ok(ret
!= 0, "got 0\n");
4876 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4877 expect(MAKELONG(102,302), ret
);
4879 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4880 expect(MAKELONG(52,52), ret
);
4882 itema
.pszText
= test
;
4883 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
4885 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4886 expect(MAKELONG(52,52), ret
);
4888 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 0, MAKELPARAM(100,100));
4889 expect(MAKELONG(52,2), ret
);
4890 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 1, MAKELPARAM(100,100));
4891 expect(MAKELONG(52,52), ret
);
4892 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 2, MAKELPARAM(100,100));
4893 expect(MAKELONG(102,52), ret
);
4894 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 3, MAKELPARAM(100,100));
4895 expect(MAKELONG(102,102), ret
);
4896 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 4, MAKELPARAM(100,100));
4897 expect(MAKELONG(102,102), ret
);
4898 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 5, MAKELPARAM(100,100));
4899 expect(MAKELONG(102,152), ret
);
4900 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 6, MAKELPARAM(100,100));
4901 expect(MAKELONG(102,152), ret
);
4902 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 7, MAKELPARAM(160,100));
4903 expect(MAKELONG(152,152), ret
);
4905 DestroyWindow(hwnd
);
4908 static void test_finditem(void)
4915 hwnd
= create_listview_control(LVS_REPORT
);
4916 insert_item(hwnd
, 0);
4918 memset(&fi
, 0, sizeof(fi
));
4920 /* full string search, inserted text was "foo" */
4922 fi
.flags
= LVFI_STRING
;
4924 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4926 /* partial string search, inserted text was "foo" */
4928 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4930 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4932 /* partial string search, part after start char */
4934 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4936 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4939 /* try with LVFI_SUBSTRING */
4941 fi
.flags
= LVFI_SUBSTRING
;
4943 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4946 win_skip("LVFI_SUBSTRING not supported\n");
4947 DestroyWindow(hwnd
);
4952 fi
.flags
= LVFI_SUBSTRING
;
4954 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4957 fi
.flags
= LVFI_SUBSTRING
;
4959 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4963 fi
.flags
= LVFI_SUBSTRING
| LVFI_STRING
;
4965 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4968 DestroyWindow(hwnd
);
4971 static void test_LVS_EX_HEADERINALLVIEWS(void)
4976 hwnd
= create_listview_control(LVS_ICON
);
4978 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4979 LVS_EX_HEADERINALLVIEWS
);
4981 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4982 if (!IsWindow(header
))
4984 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4985 DestroyWindow(hwnd
);
4989 /* LVS_NOCOLUMNHEADER works as before */
4990 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4991 SetWindowLongW(hwnd
, GWL_STYLE
, style
| LVS_NOCOLUMNHEADER
);
4992 style
= GetWindowLongA(header
, GWL_STYLE
);
4993 ok(style
& HDS_HIDDEN
, "Expected HDS_HIDDEN\n");
4994 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4995 SetWindowLongW(hwnd
, GWL_STYLE
, style
& ~LVS_NOCOLUMNHEADER
);
4996 style
= GetWindowLongA(header
, GWL_STYLE
);
4997 ok(!(style
& HDS_HIDDEN
), "Expected HDS_HIDDEN to be unset\n");
4999 /* try to remove style */
5000 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
, 0);
5001 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
5002 ok(IsWindow(header
), "Expected header to be created\n");
5003 style
= GetWindowLongA(header
, GWL_STYLE
);
5004 ok(!(style
& HDS_HIDDEN
), "HDS_HIDDEN not expected\n");
5006 DestroyWindow(hwnd
);
5008 /* check other styles */
5009 hwnd
= create_listview_control(LVS_LIST
);
5010 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5011 LVS_EX_HEADERINALLVIEWS
);
5012 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
5013 ok(IsWindow(header
), "Expected header to be created\n");
5014 DestroyWindow(hwnd
);
5016 hwnd
= create_listview_control(LVS_SMALLICON
);
5017 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5018 LVS_EX_HEADERINALLVIEWS
);
5019 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
5020 ok(IsWindow(header
), "Expected header to be created\n");
5021 DestroyWindow(hwnd
);
5023 hwnd
= create_listview_control(LVS_REPORT
);
5024 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5025 LVS_EX_HEADERINALLVIEWS
);
5026 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
5027 ok(IsWindow(header
), "Expected header to be created\n");
5028 DestroyWindow(hwnd
);
5031 static void test_hover(void)
5036 hwnd
= create_listview_control(LVS_ICON
);
5038 /* test WM_MOUSEHOVER forwarding */
5039 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5040 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
5042 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER allow test", TRUE
);
5043 g_block_hover
= TRUE
;
5044 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5045 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
5047 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER block test", TRUE
);
5048 g_block_hover
= FALSE
;
5050 r
= SendMessage(hwnd
, LVM_SETHOVERTIME
, 0, 500);
5051 expect(HOVER_DEFAULT
, r
);
5052 r
= SendMessage(hwnd
, LVM_GETHOVERTIME
, 0, 0);
5055 DestroyWindow(hwnd
);
5058 static void test_destroynotify(void)
5062 hwnd
= create_listview_control(LVS_REPORT
);
5063 ok(hwnd
!= NULL
, "failed to create listview window\n");
5065 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5066 DestroyWindow(hwnd
);
5067 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_destroy
, "check destroy order", FALSE
);
5070 static void test_header_notification(void)
5072 static char textA
[] = "newtext";
5080 list
= create_listview_control(LVS_REPORT
);
5081 ok(list
!= NULL
, "failed to create listview window\n");
5083 memset(&col
, 0, sizeof(col
));
5084 col
.mask
= LVCF_WIDTH
;
5086 ret
= SendMessage(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5089 /* check list parent notification after header item changed,
5090 this test should be placed before header subclassing to avoid
5091 Listview -> Header messages to be logged */
5092 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5094 col
.mask
= LVCF_TEXT
;
5095 col
.pszText
= textA
;
5096 r
= SendMessage(list
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
5099 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_changed_seq
,
5100 "header notify, listview", FALSE
);
5101 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5102 "header notify, parent", FALSE
);
5104 header
= subclass_header(list
);
5106 ret
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
5109 memset(&item
, 0, sizeof(item
));
5110 item
.mask
= HDI_WIDTH
;
5111 ret
= SendMessage(header
, HDM_GETITEMA
, 0, (LPARAM
)&item
);
5113 expect(100, item
.cxy
);
5115 nmh
.hdr
.hwndFrom
= header
;
5116 nmh
.hdr
.idFrom
= GetWindowLongPtr(header
, GWLP_ID
);
5117 nmh
.hdr
.code
= HDN_ITEMCHANGEDA
;
5120 item
.mask
= HDI_WIDTH
;
5123 ret
= SendMessage(list
, WM_NOTIFY
, 0, (LPARAM
)&nmh
);
5126 DestroyWindow(list
);
5129 static void test_header_notification2(void)
5131 static char textA
[] = "newtext";
5138 struct message parent_header_notify_seq
[] = {
5139 { WM_NOTIFY
, sent
|id
, 0, 0, 0 },
5143 list
= create_listview_control(LVS_REPORT
);
5144 ok(list
!= NULL
, "failed to create listview window\n");
5146 memset(&col
, 0, sizeof(col
));
5147 col
.mask
= LVCF_WIDTH
| LVCF_TEXT
;
5149 col
.pszText
= textA
;
5150 ret
= SendMessage(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5153 header
= ListView_GetHeader(list
);
5154 ok(header
!= 0, "No header\n");
5155 memset(&itemW
, 0, sizeof(itemW
));
5156 itemW
.mask
= HDI_WIDTH
| HDI_ORDER
| HDI_TEXT
;
5157 itemW
.pszText
= buffer
;
5158 itemW
.cchTextMax
= sizeof(buffer
);
5159 ret
= SendMessageW(header
, HDM_GETITEMW
, 0, (LPARAM
)&itemW
);
5162 nmhdr
.hdr
.hwndFrom
= header
;
5163 nmhdr
.hdr
.idFrom
= GetWindowLongPtr(header
, GWLP_ID
);
5166 nmhdr
.pitem
= &itemW
;
5168 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5169 nmhdr
.hdr
.code
= HDN_ITEMCHANGINGW
;
5170 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5171 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGINGA
;
5172 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5173 "header notify, parent", TRUE
);
5175 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGINGA
, "Expected ANSI notification code\n");
5176 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5177 nmhdr
.hdr
.code
= HDN_ITEMCHANGEDW
;
5178 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5179 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGEDA
;
5180 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5181 "header notify, parent", TRUE
);
5183 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGEDA
, "Expected ANSI notification code\n");
5184 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5186 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5187 nmhdr
.hdr
.code
= HDN_ITEMCLICKW
;
5188 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5189 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_click_seq
,
5190 "header notify, parent", FALSE
);
5191 ok(nmhdr
.hdr
.code
== HDN_ITEMCLICKA
, "Expected ANSI notification code\n");
5192 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5193 nmhdr
.hdr
.code
= HDN_ITEMDBLCLICKW
;
5194 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5195 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5196 "header notify, parent", FALSE
);
5197 ok(nmhdr
.hdr
.code
== HDN_ITEMDBLCLICKW
, "Expected Unicode notification code\n");
5198 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5199 nmhdr
.hdr
.code
= HDN_DIVIDERDBLCLICKW
;
5200 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5201 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_divider_dclick_seq
,
5202 "header notify, parent", TRUE
);
5203 ok(nmhdr
.hdr
.code
== HDN_DIVIDERDBLCLICKA
, "Expected ANSI notification code\n");
5204 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5205 nmhdr
.hdr
.code
= HDN_BEGINTRACKW
;
5206 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5207 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5208 "header notify, parent", FALSE
);
5209 ok(nmhdr
.hdr
.code
== HDN_BEGINTRACKW
, "Expected Unicode notification code\n");
5210 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5211 nmhdr
.hdr
.code
= HDN_ENDTRACKW
;
5212 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5213 parent_header_notify_seq
[0].id
= HDN_ENDTRACKA
;
5214 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5215 "header notify, parent", FALSE
);
5216 ok(nmhdr
.hdr
.code
== HDN_ENDTRACKA
, "Expected ANSI notification code\n");
5217 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5218 nmhdr
.hdr
.code
= HDN_TRACKW
;
5219 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5220 parent_header_notify_seq
[0].id
= HDN_TRACKA
;
5221 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5222 "header notify, parent", FALSE
);
5223 ok(nmhdr
.hdr
.code
== HDN_TRACKA
, "Expected ANSI notification code\n");
5224 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5225 nmhdr
.hdr
.code
= HDN_BEGINDRAG
;
5226 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5227 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5228 "header notify, parent", FALSE
);
5229 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5230 nmhdr
.hdr
.code
= HDN_ENDDRAG
;
5231 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5232 parent_header_notify_seq
[0].id
= HDN_ENDDRAG
;
5233 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5234 "header notify, parent", FALSE
);
5235 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5236 nmhdr
.hdr
.code
= HDN_FILTERCHANGE
;
5237 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5238 parent_header_notify_seq
[0].id
= HDN_FILTERCHANGE
;
5239 parent_header_notify_seq
[0].flags
|= optional
; /* NT4 does not send this message */
5240 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5241 "header notify, parent", FALSE
);
5242 parent_header_notify_seq
[0].flags
&= ~optional
;
5243 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5244 nmhdr
.hdr
.code
= HDN_BEGINFILTEREDIT
;
5245 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5246 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5247 "header notify, parent", FALSE
);
5248 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5249 nmhdr
.hdr
.code
= HDN_ENDFILTEREDIT
;
5250 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5251 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5252 "header notify, parent", FALSE
);
5253 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5254 nmhdr
.hdr
.code
= HDN_ITEMSTATEICONCLICK
;
5255 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5256 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5257 "header notify, parent", FALSE
);
5258 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5259 nmhdr
.hdr
.code
= HDN_ITEMKEYDOWN
;
5260 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5261 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5262 "header notify, parent", FALSE
);
5264 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5266 DestroyWindow(list
);
5269 static void test_createdragimage(void)
5275 list
= create_listview_control(LVS_ICON
);
5276 ok(list
!= NULL
, "failed to create listview window\n");
5278 insert_item(list
, 0);
5281 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, 0);
5282 ok(himl
== NULL
, "got %p\n", himl
);
5284 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, (LPARAM
)&pt
);
5285 ok(himl
!= NULL
, "got %p\n", himl
);
5286 ImageList_Destroy(himl
);
5288 DestroyWindow(list
);
5291 static void test_dispinfo(void)
5293 static const char testA
[] = "TEST";
5299 hwnd
= create_listview_control(LVS_ICON
);
5300 ok(hwnd
!= NULL
, "failed to create listview window\n");
5302 insert_item(hwnd
, 0);
5304 memset(&item
, 0, sizeof(item
));
5305 item
.pszText
= LPSTR_TEXTCALLBACKA
;
5306 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5309 g_disp_A_to_W
= TRUE
;
5310 item
.pszText
= (char*)buff
;
5311 item
.cchTextMax
= sizeof(buff
)/sizeof(WCHAR
);
5312 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
5313 ok(ret
== sizeof(testA
)-1, "got %d, expected 4\n", ret
);
5314 g_disp_A_to_W
= FALSE
;
5316 ok(memcmp(item
.pszText
, testA
, sizeof(testA
)) == 0,
5317 "got %s, expected %s\n", item
.pszText
, testA
);
5319 DestroyWindow(hwnd
);
5322 static void test_LVM_SETITEMTEXT(void)
5324 static char testA
[] = "TEST";
5329 hwnd
= create_listview_control(LVS_ICON
);
5330 ok(hwnd
!= NULL
, "failed to create listview window\n");
5332 insert_item(hwnd
, 0);
5334 /* null item pointer */
5335 ret
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, 0);
5338 ret
= SendMessage(hwnd
, LVM_SETITEMTEXTW
, 0, 0);
5341 /* index out of bounds */
5342 item
.pszText
= testA
;
5343 item
.cchTextMax
= 0; /* ignored */
5346 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 1, (LPARAM
)&item
);
5349 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, -1, (LPARAM
)&item
);
5352 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5355 DestroyWindow(hwnd
);
5358 static void test_imagelists(void)
5361 HIMAGELIST himl1
, himl2
, himl3
;
5364 himl1
= ImageList_Create(40, 40, 0, 4, 4);
5365 himl2
= ImageList_Create(40, 40, 0, 4, 4);
5366 himl3
= ImageList_Create(40, 40, 0, 4, 4);
5367 ok(himl1
!= NULL
, "Failed to create imagelist\n");
5368 ok(himl2
!= NULL
, "Failed to create imagelist\n");
5369 ok(himl3
!= NULL
, "Failed to create imagelist\n");
5371 hwnd
= create_listview_control(LVS_REPORT
| LVS_SHAREIMAGELISTS
);
5372 header
= subclass_header(hwnd
);
5374 ok(header
!= NULL
, "Expected header\n");
5375 ret
= SendMessage(header
, HDM_GETIMAGELIST
, 0, 0);
5376 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5378 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5380 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5381 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5382 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5383 "set normal image list", FALSE
);
5385 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5387 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5388 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5389 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5390 "set state image list", TRUE
);
5392 ret
= SendMessage(header
, HDM_GETIMAGELIST
, 0, 0);
5393 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5395 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5397 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5398 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5399 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_set_imagelist
,
5400 "set small image list", FALSE
);
5402 ret
= SendMessage(header
, HDM_GETIMAGELIST
, 0, 0);
5403 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5404 DestroyWindow(hwnd
);
5406 hwnd
= create_listview_control(WS_VISIBLE
| LVS_ICON
);
5408 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5410 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5411 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5412 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5413 "set normal image list", FALSE
);
5415 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5417 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5418 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5419 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5420 "set state image list", FALSE
);
5422 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5424 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5425 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5426 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5427 "set small image list", FALSE
);
5429 header
= ListView_GetHeader(hwnd
);
5430 ok(header
== NULL
, "Expected no header, got %p\n", header
);
5432 SetWindowLongPtr(hwnd
, GWL_STYLE
, GetWindowLongPtr(hwnd
, GWL_STYLE
) | LVS_REPORT
);
5434 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
5435 ok(header
!= NULL
, "Expected header, got NULL\n");
5437 ret
= SendMessage(header
, HDM_GETIMAGELIST
, 0, 0);
5438 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5440 DestroyWindow(hwnd
);
5443 static void test_deleteitem(void)
5450 hwnd
= create_listview_control(LVS_REPORT
);
5452 insert_item(hwnd
, 0);
5453 insert_item(hwnd
, 0);
5454 insert_item(hwnd
, 0);
5455 insert_item(hwnd
, 0);
5456 insert_item(hwnd
, 0);
5458 g_focus_test_LVN_DELETEITEM
= TRUE
;
5460 /* delete focused item (not the last index) */
5461 item
.stateMask
= LVIS_FOCUSED
;
5462 item
.state
= LVIS_FOCUSED
;
5463 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
5464 ok(ret
== TRUE
, "got %d\n", ret
);
5465 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 2, 0);
5466 ok(ret
== TRUE
, "got %d\n", ret
);
5467 /* next item gets focus */
5468 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5469 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5471 /* focus last item and delete it */
5472 item
.stateMask
= LVIS_FOCUSED
;
5473 item
.state
= LVIS_FOCUSED
;
5474 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
5475 ok(ret
== TRUE
, "got %d\n", ret
);
5476 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 3, 0);
5477 ok(ret
== TRUE
, "got %d\n", ret
);
5478 /* new last item gets focus */
5479 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5480 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5482 /* focus first item and delete it */
5483 item
.stateMask
= LVIS_FOCUSED
;
5484 item
.state
= LVIS_FOCUSED
;
5485 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
5486 ok(ret
== TRUE
, "got %d\n", ret
);
5487 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
5488 ok(ret
== TRUE
, "got %d\n", ret
);
5489 /* new first item gets focus */
5490 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5491 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5493 g_focus_test_LVN_DELETEITEM
= FALSE
;
5495 DestroyWindow(hwnd
);
5498 static void test_insertitem(void)
5505 hwnd
= create_listview_control(LVS_REPORT
);
5507 /* insert item 0 focused */
5508 item
.mask
= LVIF_STATE
;
5509 item
.state
= LVIS_FOCUSED
;
5510 item
.stateMask
= LVIS_FOCUSED
;
5513 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5514 ok(ret
== 0, "got %d\n", ret
);
5516 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5517 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5519 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5521 /* insert item 1, focus shift */
5522 item
.mask
= LVIF_STATE
;
5523 item
.state
= LVIS_FOCUSED
;
5524 item
.stateMask
= LVIS_FOCUSED
;
5527 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5528 ok(ret
== 1, "got %d\n", ret
);
5530 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_insert_focused_seq
, "insert focused", TRUE
);
5532 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5533 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5535 /* insert item 2, no focus shift */
5536 item
.mask
= LVIF_STATE
;
5538 item
.stateMask
= LVIS_FOCUSED
;
5541 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5542 ok(ret
== 2, "got %d\n", ret
);
5544 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5545 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5547 DestroyWindow(hwnd
);
5550 START_TEST(listview
)
5553 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
5555 ULONG_PTR ctx_cookie
;
5559 hComctl32
= GetModuleHandleA("comctl32.dll");
5560 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
5561 if (pInitCommonControlsEx
)
5563 INITCOMMONCONTROLSEX iccex
;
5564 iccex
.dwSize
= sizeof(iccex
);
5565 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
5566 pInitCommonControlsEx(&iccex
);
5569 InitCommonControls();
5571 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
5573 hwndparent
= create_parent_window(FALSE
);
5574 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5576 g_is_below_5
= is_below_comctl_5();
5578 test_header_notification();
5579 test_header_notification2();
5586 test_icon_spacing();
5589 test_item_position();
5594 test_subitem_rect();
5598 test_nosortheader();
5602 test_getitemposition();
5603 test_columnscreation();
5605 test_notifyformat();
5607 test_getitemspacing();
5608 test_getcolumnwidth();
5609 test_approximate_viewrect();
5612 test_destroynotify();
5613 test_createdragimage();
5615 test_LVM_SETITEMTEXT();
5620 if (!load_v6_module(&ctx_cookie
, &hCtx
))
5622 DestroyWindow(hwndparent
);
5626 /* this is a XP SP3 failure workaround */
5627 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
5628 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
,
5630 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
5631 if (!IsWindow(hwnd
))
5633 win_skip("FIXME: failed to create ListView window.\n");
5634 unload_v6_module(ctx_cookie
, hCtx
);
5635 DestroyWindow(hwndparent
);
5639 DestroyWindow(hwnd
);
5641 /* comctl32 version 6 tests start here */
5642 test_get_set_view();
5643 test_canceleditlabel();
5645 test_scrollnotify();
5646 test_LVS_EX_TRANSPARENTBKGND();
5647 test_LVS_EX_HEADERINALLVIEWS();
5652 unload_v6_module(ctx_cookie
, hCtx
);
5654 DestroyWindow(hwndparent
);