4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009 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 /* dumps LVN_ITEMCHANGED message data */
54 static BOOL g_dump_itemchanged
;
55 /* format reported to control:
56 -1 falls to defproc, anything else returned */
57 static INT notifyFormat
;
58 /* indicates we're running < 5.80 version */
59 static BOOL g_is_below_5
;
60 /* item data passed to LVN_GETDISPINFOA */
61 static LVITEMA g_itema
;
63 static HWND
subclass_editbox(HWND hwndListview
);
65 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
67 static const struct message create_ownerdrawfixed_parent_seq
[] = {
68 { WM_NOTIFYFORMAT
, sent
},
69 { WM_QUERYUISTATE
, sent
|optional
}, /* Win2K and higher */
70 { WM_MEASUREITEM
, sent
},
71 { WM_PARENTNOTIFY
, sent
},
75 static const struct message redraw_listview_seq
[] = {
76 { WM_PAINT
, sent
|id
, 0, 0, LISTVIEW_ID
},
77 { WM_PAINT
, sent
|id
, 0, 0, HEADER_ID
},
78 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
79 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, HEADER_ID
},
80 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
81 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
82 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, LISTVIEW_ID
},
86 static const struct message listview_icon_spacing_seq
[] = {
87 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(20, 30) },
88 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(25, 35) },
89 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(-1, -1) },
93 static const struct message listview_color_seq
[] = {
94 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
95 { LVM_GETBKCOLOR
, sent
},
96 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
97 { LVM_GETTEXTCOLOR
, sent
},
98 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
99 { LVM_GETTEXTBKCOLOR
, sent
},
101 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
102 { LVM_GETBKCOLOR
, sent
},
103 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
104 { LVM_GETTEXTCOLOR
, sent
},
105 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
106 { LVM_GETTEXTBKCOLOR
, sent
},
108 { LVM_SETBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
109 { LVM_GETBKCOLOR
, sent
},
110 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, CLR_NONE
},
111 { LVM_GETTEXTCOLOR
, sent
},
112 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
113 { LVM_GETTEXTBKCOLOR
, sent
},
115 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
116 { LVM_GETBKCOLOR
, sent
},
117 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
118 { LVM_GETTEXTCOLOR
, sent
},
119 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
120 { LVM_GETTEXTBKCOLOR
, sent
},
124 static const struct message listview_item_count_seq
[] = {
125 { LVM_GETITEMCOUNT
, sent
},
126 { LVM_INSERTITEM
, sent
},
127 { LVM_INSERTITEM
, sent
},
128 { LVM_INSERTITEM
, sent
},
129 { LVM_GETITEMCOUNT
, sent
},
130 { LVM_DELETEITEM
, sent
|wparam
, 2 },
131 { WM_NCPAINT
, sent
|optional
},
132 { WM_ERASEBKGND
, sent
|optional
},
133 { LVM_GETITEMCOUNT
, sent
},
134 { LVM_DELETEALLITEMS
, sent
},
135 { LVM_GETITEMCOUNT
, sent
},
136 { LVM_INSERTITEM
, sent
},
137 { LVM_INSERTITEM
, sent
},
138 { LVM_GETITEMCOUNT
, sent
},
139 { LVM_INSERTITEM
, sent
},
140 { LVM_GETITEMCOUNT
, sent
},
144 static const struct message listview_itempos_seq
[] = {
145 { LVM_INSERTITEM
, sent
},
146 { LVM_INSERTITEM
, sent
},
147 { LVM_INSERTITEM
, sent
},
148 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 1, MAKELPARAM(10,5) },
149 { WM_NCPAINT
, sent
|optional
},
150 { WM_ERASEBKGND
, sent
|optional
},
151 { LVM_GETITEMPOSITION
, sent
|wparam
, 1 },
152 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 2, MAKELPARAM(0,0) },
153 { LVM_GETITEMPOSITION
, sent
|wparam
, 2 },
154 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 0, MAKELPARAM(20,20) },
155 { LVM_GETITEMPOSITION
, sent
|wparam
, 0 },
159 static const struct message listview_ownerdata_switchto_seq
[] = {
160 { WM_STYLECHANGING
, sent
},
161 { WM_STYLECHANGED
, sent
},
165 static const struct message listview_getorderarray_seq
[] = {
166 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
167 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
171 static const struct message empty_seq
[] = {
175 static const struct message forward_erasebkgnd_parent_seq
[] = {
176 { WM_ERASEBKGND
, sent
},
180 static const struct message ownderdata_select_focus_parent_seq
[] = {
181 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
182 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
183 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
}, /* version 4.7x */
187 static const struct message ownerdata_setstate_all_parent_seq
[] = {
188 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
192 static const struct message ownerdata_defocus_all_parent_seq
[] = {
193 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
194 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
195 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
},
196 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
200 static const struct message ownerdata_deselect_all_parent_seq
[] = {
201 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ODCACHEHINT
},
202 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
206 static const struct message select_all_parent_seq
[] = {
207 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
208 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
210 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
211 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
213 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
214 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
216 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
217 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
219 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
220 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
224 static const struct message textcallback_set_again_parent_seq
[] = {
225 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
226 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
230 static const struct message single_getdispinfo_parent_seq
[] = {
231 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
235 static const struct message getitemposition_seq1
[] = {
236 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
240 static const struct message getitemposition_seq2
[] = {
241 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
242 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
246 static const struct message editbox_create_pos
[] = {
247 /* sequence sent after LVN_BEGINLABELEDIT */
248 /* next two are 4.7x specific */
249 { WM_WINDOWPOSCHANGING
, sent
},
250 { WM_WINDOWPOSCHANGED
, sent
|optional
},
252 { WM_WINDOWPOSCHANGING
, sent
|optional
},
253 { WM_NCCALCSIZE
, sent
},
254 { WM_WINDOWPOSCHANGED
, sent
},
255 { WM_MOVE
, sent
|defwinproc
},
256 { WM_SIZE
, sent
|defwinproc
},
257 /* the rest is todo, skipped in 4.7x */
258 { WM_WINDOWPOSCHANGING
, sent
|optional
},
259 { WM_WINDOWPOSCHANGED
, sent
|optional
},
263 static const struct message scroll_parent_seq
[] = {
264 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_BEGINSCROLL
},
265 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDSCROLL
},
269 static const struct message setredraw_seq
[] = {
270 { WM_SETREDRAW
, sent
|id
|wparam
, FALSE
, 0, LISTVIEW_ID
},
274 static const struct message lvs_ex_transparentbkgnd_seq
[] = {
275 { WM_PRINTCLIENT
, sent
|lparam
, 0, PRF_ERASEBKGND
},
279 static const struct message edit_end_nochange
[] = {
280 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDLABELEDITA
},
281 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
}, /* todo */
282 { WM_NOTIFY
, sent
|id
, 0, 0, NM_SETFOCUS
},
286 static const struct message hover_parent
[] = {
287 { WM_GETDLGCODE
, sent
}, /* todo_wine */
288 { WM_NOTIFY
, sent
|id
, 0, 0, NM_HOVER
},
292 static const struct message listview_destroy
[] = {
293 { 0x0090, sent
|optional
}, /* Vista */
294 { WM_PARENTNOTIFY
, sent
},
295 { WM_SHOWWINDOW
, sent
},
296 { WM_WINDOWPOSCHANGING
, sent
},
297 { WM_WINDOWPOSCHANGED
, sent
|optional
},
298 { WM_DESTROY
, sent
},
299 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_DELETEALLITEMS
},
300 { WM_NCDESTROY
, sent
},
304 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
306 static LONG defwndproc_counter
= 0;
310 msg
.message
= message
;
311 msg
.flags
= sent
|wparam
|lparam
;
312 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
315 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
317 /* log system messages, except for painting */
318 if (message
< WM_USER
&&
319 message
!= WM_PAINT
&&
320 message
!= WM_ERASEBKGND
&&
321 message
!= WM_NCPAINT
&&
322 message
!= WM_NCHITTEST
&&
323 message
!= WM_GETTEXT
&&
324 message
!= WM_GETICON
&&
325 message
!= WM_DEVICECHANGE
)
327 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
329 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
330 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
332 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
338 switch (((NMHDR
*)lParam
)->code
)
340 case LVN_BEGINLABELEDIT
:
341 /* subclass edit box */
343 subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
347 case LVN_ENDLABELEDIT
:
349 /* always accept new item text */
350 NMLVDISPINFO
*di
= (NMLVDISPINFO
*)lParam
;
351 trace("LVN_ENDLABELEDIT: text=%s\n", di
->item
.pszText
);
354 case LVN_BEGINSCROLL
:
357 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
359 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
360 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
363 case LVN_ITEMCHANGED
:
364 if (g_dump_itemchanged
)
366 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
367 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
368 nmlv
->iItem
, nmlv
->uNewState
, nmlv
->uOldState
, nmlv
->uChanged
);
371 case LVN_GETDISPINFOA
:
373 NMLVDISPINFOA
*dispinfo
= (NMLVDISPINFOA
*)lParam
;
374 g_itema
= dispinfo
->item
;
378 if (g_block_hover
) return 1;
383 case WM_NOTIFYFORMAT
:
385 /* force to return format */
386 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
391 defwndproc_counter
++;
392 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
393 defwndproc_counter
--;
398 static BOOL
register_parent_wnd_class(BOOL Unicode
)
406 clsW
.lpfnWndProc
= parent_wnd_proc
;
409 clsW
.hInstance
= GetModuleHandleW(NULL
);
411 clsW
.hCursor
= LoadCursorA(0, IDC_ARROW
);
412 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
413 clsW
.lpszMenuName
= NULL
;
414 clsW
.lpszClassName
= testparentclassW
;
419 clsA
.lpfnWndProc
= parent_wnd_proc
;
422 clsA
.hInstance
= GetModuleHandleA(NULL
);
424 clsA
.hCursor
= LoadCursorA(0, IDC_ARROW
);
425 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
426 clsA
.lpszMenuName
= NULL
;
427 clsA
.lpszClassName
= "Listview test parent class";
430 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
433 static HWND
create_parent_window(BOOL Unicode
)
435 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
438 if (!register_parent_wnd_class(Unicode
))
445 hwnd
= CreateWindowExW(0, testparentclassW
, nameW
,
446 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
447 WS_MAXIMIZEBOX
| WS_VISIBLE
,
449 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
451 hwnd
= CreateWindowExA(0, "Listview test parent class",
452 "Listview test parent window",
453 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
454 WS_MAXIMIZEBOX
| WS_VISIBLE
,
456 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
457 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
461 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
463 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
464 static LONG defwndproc_counter
= 0;
468 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
470 /* some debug output for style changing */
471 if ((message
== WM_STYLECHANGING
||
472 message
== WM_STYLECHANGED
) && lParam
)
474 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
475 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
478 msg
.message
= message
;
479 msg
.flags
= sent
|wparam
|lparam
;
480 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
483 msg
.id
= LISTVIEW_ID
;
484 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
485 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
487 defwndproc_counter
++;
488 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
489 defwndproc_counter
--;
493 static HWND
create_listview_control(DWORD style
)
499 GetClientRect(hwndparent
, &rect
);
500 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
501 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
502 0, 0, rect
.right
, rect
.bottom
,
503 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
504 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
506 if (!hwnd
) return NULL
;
508 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
509 (LONG_PTR
)listview_subclass_proc
);
510 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
515 /* unicode listview window with specified parent */
516 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
521 static const WCHAR nameW
[] = {'f','o','o',0};
523 GetClientRect(parent
, &rect
);
524 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
525 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
526 0, 0, rect
.right
, rect
.bottom
,
527 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
528 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
530 if (!hwnd
) return NULL
;
532 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
533 (LONG_PTR
)listview_subclass_proc
);
534 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
539 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
541 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
542 static LONG defwndproc_counter
= 0;
546 trace("header: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
548 msg
.message
= message
;
549 msg
.flags
= sent
|wparam
|lparam
;
550 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
554 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
556 defwndproc_counter
++;
557 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
558 defwndproc_counter
--;
562 static HWND
subclass_header(HWND hwndListview
)
567 hwnd
= ListView_GetHeader(hwndListview
);
568 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
569 (LONG_PTR
)header_subclass_proc
);
570 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
575 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
577 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
578 static LONG defwndproc_counter
= 0;
582 msg
.message
= message
;
583 msg
.flags
= sent
|wparam
|lparam
;
584 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
588 /* all we need is sizing */
589 if (message
== WM_WINDOWPOSCHANGING
||
590 message
== WM_NCCALCSIZE
||
591 message
== WM_WINDOWPOSCHANGED
||
592 message
== WM_MOVE
||
595 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
598 defwndproc_counter
++;
599 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
600 defwndproc_counter
--;
604 static HWND
subclass_editbox(HWND hwndListview
)
609 hwnd
= (HWND
)SendMessage(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
610 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
611 (LONG_PTR
)editbox_subclass_proc
);
612 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
617 /* Performs a single LVM_HITTEST test */
618 static void test_lvm_hittest_(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
, UINT broken_flags
,
619 BOOL todo_item
, BOOL todo_flags
, int line
)
628 trace("hittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
629 ret
= SendMessage(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
635 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
636 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
637 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
642 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
643 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
644 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
650 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
652 else if (broken_flags
)
653 ok_(__FILE__
, line
)(lpht
.flags
== flags
|| broken(lpht
.flags
== broken_flags
),
654 "Expected flags %x, got %x\n", flags
, lpht
.flags
);
656 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
659 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
661 /* Performs a single LVM_SUBITEMHITTEST test */
662 static void test_lvm_subitemhittest_(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
663 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
671 trace("subhittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
672 ret
= SendMessage(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
678 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
679 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
684 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
685 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
691 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
694 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
699 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
702 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
705 #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__)
707 static void test_images(void)
715 static CHAR hello
[] = "hello";
717 himl
= ImageList_Create(40, 40, 0, 4, 4);
718 ok(himl
!= NULL
, "failed to create imagelist\n");
720 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
721 ok(hbmp
!= NULL
, "failed to create bitmap\n");
723 r
= ImageList_Add(himl
, hbmp
, 0);
724 ok(r
== 0, "should be zero\n");
726 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
727 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
728 ok(hwnd
!= NULL
, "failed to create listview window\n");
730 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
731 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
733 ok(r
== 0, "should return zero\n");
735 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
736 ok(r
== 0, "should return zero\n");
738 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
739 /* returns dimensions */
741 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
742 ok(r
== 0, "should be zero items\n");
744 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
749 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
750 ok(r
== -1, "should fail\n");
753 item
.pszText
= hello
;
754 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
755 ok(r
== 0, "should not fail\n");
757 memset(&r1
, 0, sizeof r1
);
759 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
761 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
762 ok(r
== TRUE
, "should not fail\n");
765 item
.pszText
= hello
;
766 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
767 ok(r
== 0, "should not fail\n");
769 memset(&r2
, 0, sizeof r2
);
771 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
773 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
778 static void test_checkboxes(void)
783 static CHAR text
[] = "Text",
787 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
788 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
789 ok(hwnd
!= NULL
, "failed to create listview window\n");
791 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
792 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
793 item
.stateMask
= 0xffff;
798 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
799 ok(r
== 0, "ret %d\n", r
);
802 item
.mask
= LVIF_STATE
;
803 item
.stateMask
= 0xffff;
804 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
805 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
807 /* Don't set LVIF_STATE */
808 item
.mask
= LVIF_TEXT
;
809 item
.stateMask
= 0xffff;
814 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
815 ok(r
== 1, "ret %d\n", r
);
818 item
.mask
= LVIF_STATE
;
819 item
.stateMask
= 0xffff;
820 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
821 ok(item
.state
== 0, "state %x\n", item
.state
);
823 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
824 ok(r
== 0, "should return zero\n");
826 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
828 item
.mask
= LVIF_STATE
;
829 item
.stateMask
= 0xffff;
830 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
831 if (item
.state
!= 0x1ccc)
833 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
838 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
840 item
.mask
= LVIF_TEXT
;
842 item
.pszText
= text2
;
843 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
844 ok(r
== 2, "ret %d\n", r
);
847 item
.mask
= LVIF_STATE
;
848 item
.stateMask
= 0xffff;
849 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
850 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
852 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
854 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
855 item
.stateMask
= 0xffff;
857 item
.pszText
= text3
;
858 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
859 ok(r
== 3, "ret %d\n", r
);
862 item
.mask
= LVIF_STATE
;
863 item
.stateMask
= 0xffff;
864 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
865 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
867 /* Set an item's state to checked */
869 item
.mask
= LVIF_STATE
;
870 item
.stateMask
= 0xf000;
872 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
875 item
.mask
= LVIF_STATE
;
876 item
.stateMask
= 0xffff;
877 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
878 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
880 /* Check that only the bits we asked for are returned,
881 * and that all the others are set to zero
884 item
.mask
= LVIF_STATE
;
885 item
.stateMask
= 0xf000;
887 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
888 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
890 /* Set the style again and check that doesn't change an item's state */
891 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
892 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
895 item
.mask
= LVIF_STATE
;
896 item
.stateMask
= 0xffff;
897 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
898 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
900 /* Unsetting the checkbox extended style doesn't change an item's state */
901 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
902 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
905 item
.mask
= LVIF_STATE
;
906 item
.stateMask
= 0xffff;
907 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
908 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
910 /* Now setting the style again will change an item's state */
911 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
912 ok(r
== 0, "ret %x\n", r
);
915 item
.mask
= LVIF_STATE
;
916 item
.stateMask
= 0xffff;
917 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
918 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
920 /* Toggle checkbox tests (bug 9934) */
921 memset (&item
, 0xcc, sizeof(item
));
922 item
.mask
= LVIF_STATE
;
925 item
.state
= LVIS_FOCUSED
;
926 item
.stateMask
= LVIS_FOCUSED
;
927 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
931 item
.mask
= LVIF_STATE
;
932 item
.stateMask
= 0xffff;
933 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
934 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
936 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
938 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
942 item
.mask
= LVIF_STATE
;
943 item
.stateMask
= 0xffff;
944 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
945 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
947 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
949 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
953 item
.mask
= LVIF_STATE
;
954 item
.stateMask
= 0xffff;
955 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
956 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
961 static void insert_column(HWND hwnd
, int idx
)
966 memset(&column
, 0xcc, sizeof(column
));
967 column
.mask
= LVCF_SUBITEM
;
968 column
.iSubItem
= idx
;
970 rc
= ListView_InsertColumn(hwnd
, idx
, &column
);
974 static void insert_item(HWND hwnd
, int idx
)
976 static CHAR text
[] = "foo";
981 memset(&item
, 0xcc, sizeof (item
));
982 item
.mask
= LVIF_TEXT
;
987 rc
= ListView_InsertItem(hwnd
, &item
);
991 static void test_items(void)
993 const LPARAM lparamTest
= 0x42;
997 static CHAR text
[] = "Text";
999 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1000 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1001 ok(hwnd
!= NULL
, "failed to create listview window\n");
1004 * Test setting/getting item params
1007 /* Set up two columns */
1008 insert_column(hwnd
, 0);
1009 insert_column(hwnd
, 1);
1011 /* LVIS_SELECTED with zero stateMask */
1013 memset (&item
, 0, sizeof (item
));
1014 item
.mask
= LVIF_STATE
;
1015 item
.state
= LVIS_SELECTED
;
1019 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1020 ok(r
== 0, "ret %d\n", r
);
1022 memset (&item
, 0xcc, sizeof (item
));
1023 item
.mask
= LVIF_STATE
;
1024 item
.stateMask
= LVIS_SELECTED
;
1028 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1029 ok(r
!= 0, "ret %d\n", r
);
1030 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1031 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1033 /* LVIS_SELECTED with zero stateMask */
1035 memset (&item
, 0, sizeof (item
));
1036 item
.mask
= LVIF_STATE
;
1037 item
.state
= LVIS_FOCUSED
;
1041 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1042 ok(r
== 0, "ret %d\n", r
);
1044 memset (&item
, 0xcc, sizeof (item
));
1045 item
.mask
= LVIF_STATE
;
1046 item
.stateMask
= LVIS_FOCUSED
;
1050 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1051 ok(r
!= 0, "ret %d\n", r
);
1052 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1053 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1055 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1057 memset (&item
, 0, sizeof (item
));
1058 item
.mask
= LVIF_STATE
;
1059 item
.state
= LVIS_CUT
;
1060 item
.stateMask
= LVIS_FOCUSED
;
1063 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1064 ok(r
== 0, "ret %d\n", r
);
1066 memset (&item
, 0xcc, sizeof (item
));
1067 item
.mask
= LVIF_STATE
;
1068 item
.stateMask
= LVIS_CUT
;
1072 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1073 ok(r
!= 0, "ret %d\n", r
);
1074 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1075 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1077 /* Insert an item with just a param */
1078 memset (&item
, 0xcc, sizeof (item
));
1079 item
.mask
= LVIF_PARAM
;
1082 item
.lParam
= lparamTest
;
1083 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1084 ok(r
== 0, "ret %d\n", r
);
1086 /* Test getting of the param */
1087 memset (&item
, 0xcc, sizeof (item
));
1088 item
.mask
= LVIF_PARAM
;
1091 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1092 ok(r
!= 0, "ret %d\n", r
);
1093 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1095 /* Set up a subitem */
1096 memset (&item
, 0xcc, sizeof (item
));
1097 item
.mask
= LVIF_TEXT
;
1100 item
.pszText
= text
;
1101 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1102 ok(r
!= 0, "ret %d\n", r
);
1104 /* Query param from subitem: returns main item param */
1105 memset (&item
, 0xcc, sizeof (item
));
1106 item
.mask
= LVIF_PARAM
;
1109 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1110 ok(r
!= 0, "ret %d\n", r
);
1111 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1113 /* Set up param on first subitem: no effect */
1114 memset (&item
, 0xcc, sizeof (item
));
1115 item
.mask
= LVIF_PARAM
;
1118 item
.lParam
= lparamTest
+1;
1119 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1120 ok(r
== 0, "ret %d\n", r
);
1122 /* Query param from subitem again: should still return main item param */
1123 memset (&item
, 0xcc, sizeof (item
));
1124 item
.mask
= LVIF_PARAM
;
1127 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1128 ok(r
!= 0, "ret %d\n", r
);
1129 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1131 /**** Some tests of state highlighting ****/
1132 memset (&item
, 0xcc, sizeof (item
));
1133 item
.mask
= LVIF_STATE
;
1136 item
.state
= LVIS_SELECTED
;
1137 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1138 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1139 ok(r
!= 0, "ret %d\n", r
);
1141 item
.state
= LVIS_DROPHILITED
;
1142 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1143 ok(r
!= 0, "ret %d\n", r
);
1145 memset (&item
, 0xcc, sizeof (item
));
1146 item
.mask
= LVIF_STATE
;
1149 item
.stateMask
= -1;
1150 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1151 ok(r
!= 0, "ret %d\n", r
);
1152 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1154 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1155 ok(r
!= 0, "ret %d\n", r
);
1156 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1158 /* some notnull but meaningless masks */
1159 memset (&item
, 0, sizeof(item
));
1160 item
.mask
= LVIF_NORECOMPUTE
;
1163 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1164 ok(r
!= 0, "ret %d\n", r
);
1165 memset (&item
, 0, sizeof(item
));
1166 item
.mask
= LVIF_DI_SETITEM
;
1169 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1170 ok(r
!= 0, "ret %d\n", r
);
1172 /* set text to callback value already having it */
1173 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1175 memset (&item
, 0, sizeof (item
));
1176 item
.mask
= LVIF_TEXT
;
1177 item
.pszText
= LPSTR_TEXTCALLBACK
;
1179 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1180 ok(r
== 0, "ret %d\n", r
);
1181 memset (&item
, 0, sizeof (item
));
1183 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1185 item
.pszText
= LPSTR_TEXTCALLBACK
;
1186 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0 , (LPARAM
) &item
);
1189 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1190 "check callback text comparison rule", FALSE
);
1192 DestroyWindow(hwnd
);
1195 static void test_columns(void)
1204 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1205 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1206 ok(hwnd
!= NULL
, "failed to create listview window\n");
1208 /* Add a column with no mask */
1209 memset(&column
, 0xcc, sizeof(column
));
1211 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1212 ok(rc
== 0, "Inserting column with no mask failed with %d\n", rc
);
1214 /* Check its width */
1215 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
1216 ok(rc
== 10 || broken(rc
== 0) /* win9x */,
1217 "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1219 DestroyWindow(hwnd
);
1221 /* LVM_GETCOLUMNORDERARRAY */
1222 hwnd
= create_listview_control(LVS_REPORT
);
1223 subclass_header(hwnd
);
1225 memset(&column
, 0, sizeof(column
));
1226 column
.mask
= LVCF_WIDTH
;
1228 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1229 ok(rc
== 0, "Inserting column failed with %d\n", rc
);
1232 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&column
);
1233 ok(rc
== 1, "Inserting column failed with %d\n", rc
);
1235 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1237 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1238 ok(rc
== 1, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1239 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1240 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1242 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1244 /* after column added subitem is considered as present */
1245 insert_item(hwnd
, 0);
1247 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1249 item
.pszText
= buff
;
1250 item
.cchTextMax
= sizeof(buff
);
1253 item
.mask
= LVIF_TEXT
;
1254 memset(&g_itema
, 0, sizeof(g_itema
));
1255 rc
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
1256 ok(rc
== 1, "got %d\n", rc
);
1257 ok(g_itema
.iSubItem
== 1, "got %d\n", g_itema
.iSubItem
);
1259 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
1260 "get subitem text after column added", FALSE
);
1262 DestroyWindow(hwnd
);
1265 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1266 static WNDPROC listviewWndProc
;
1267 static HIMAGELIST test_create_imagelist
;
1269 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1273 if (uMsg
== WM_CREATE
)
1275 LPCREATESTRUCT lpcs
= (LPCREATESTRUCT
)lParam
;
1276 lpcs
->style
|= LVS_REPORT
;
1278 ret
= CallWindowProc(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1279 if (uMsg
== WM_CREATE
) SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1283 static void test_create(void)
1294 cls
.cbSize
= sizeof(WNDCLASSEX
);
1295 ok(GetClassInfoEx(GetModuleHandle(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1296 listviewWndProc
= cls
.lpfnWndProc
;
1297 cls
.lpfnWndProc
= create_test_wndproc
;
1298 cls
.lpszClassName
= "MyListView32";
1299 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
1301 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1302 hList
= CreateWindow("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1303 ok((HIMAGELIST
)SendMessage(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1304 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1306 if (!IsWindow(hHeader
))
1309 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1310 DestroyWindow(hList
);
1314 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1315 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1316 DestroyWindow(hList
);
1318 /* header isn't created on LVS_ICON and LVS_LIST styles */
1319 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1320 GetModuleHandle(NULL
), 0);
1321 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1322 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1323 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1325 memset(&col
, 0, sizeof(LVCOLUMNA
));
1326 col
.mask
= LVCF_WIDTH
;
1328 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1329 ok(r
== 0, "Expected 0 column's inserted\n");
1330 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1331 ok(IsWindow(hHeader
), "Header should be created\n");
1332 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1333 style
= GetWindowLong(hHeader
, GWL_STYLE
);
1334 ok(!(style
& HDS_HIDDEN
), "Not expected HDS_HIDDEN\n");
1335 DestroyWindow(hList
);
1337 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1338 GetModuleHandle(NULL
), 0);
1339 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1340 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1341 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1343 memset(&col
, 0, sizeof(LVCOLUMNA
));
1344 col
.mask
= LVCF_WIDTH
;
1346 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1347 ok(r
== 0, "Expected 0 column's inserted\n");
1348 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1349 ok(IsWindow(hHeader
), "Header should be created\n");
1350 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1351 DestroyWindow(hList
);
1353 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1354 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1355 GetModuleHandle(NULL
), 0);
1356 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLongPtr(hList
, GWL_STYLE
) | LVS_REPORT
);
1357 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1358 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1359 ok(IsWindow(hHeader
), "Header should be created\n");
1360 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLong(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1361 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1362 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1363 ok(IsWindow(hHeader
), "Header should be created\n");
1364 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1365 DestroyWindow(hList
);
1367 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1368 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1369 GetModuleHandle(NULL
), 0);
1370 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1371 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1372 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1373 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1374 ok(IsWindow(hHeader
), "Header should be created\n");
1375 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1376 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1377 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1378 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1379 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1380 ok(IsWindow(hHeader
), "Header should be created\n");
1381 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1382 DestroyWindow(hList
);
1384 /* LVS_REPORT without WS_VISIBLE */
1385 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1386 GetModuleHandle(NULL
), 0);
1387 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1388 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1389 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1391 memset(&col
, 0, sizeof(LVCOLUMNA
));
1392 col
.mask
= LVCF_WIDTH
;
1394 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1395 ok(r
== 0, "Expected 0 column's inserted\n");
1396 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1397 ok(IsWindow(hHeader
), "Header should be created\n");
1398 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1399 DestroyWindow(hList
);
1401 /* LVS_REPORT without WS_VISIBLE, try to show it */
1402 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1403 GetModuleHandle(NULL
), 0);
1404 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1405 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1406 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1407 ShowWindow(hList
, SW_SHOW
);
1408 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1409 ok(IsWindow(hHeader
), "Header should be created\n");
1410 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1411 DestroyWindow(hList
);
1413 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1414 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1415 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1416 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1417 ok(IsWindow(hHeader
), "Header should be created\n");
1418 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1419 /* HDS_DRAGDROP set by default */
1420 ok(GetWindowLongPtr(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1421 DestroyWindow(hList
);
1423 /* setting LVS_EX_HEADERDRAGDROP creates header */
1424 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1425 GetModuleHandle(NULL
), 0);
1426 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1427 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1428 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1429 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1430 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1431 ok(IsWindow(hHeader
) ||
1432 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1433 "Header should be created\n");
1434 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1435 DestroyWindow(hList
);
1437 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1438 hList
= create_listview_control(LVS_ICON
);
1439 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1440 r
= SendMessage(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1441 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1442 DestroyWindow(hList
);
1444 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1445 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1446 GetModuleHandle(NULL
), 0);
1447 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1448 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1450 rect
.left
= LVIR_BOUNDS
;
1452 rect
.right
= rect
.bottom
= -10;
1453 r
= SendMessage(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1454 ok(r
!= 0, "Expected not-null LRESULT\n");
1456 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1457 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1458 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1460 DestroyWindow(hList
);
1462 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1463 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1464 hList
= create_listview_control(LVS_OWNERDRAWFIXED
| LVS_REPORT
);
1465 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1466 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1467 DestroyWindow(hList
);
1470 static void test_redraw(void)
1477 hwnd
= create_listview_control(LVS_REPORT
);
1478 subclass_header(hwnd
);
1480 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1482 trace("invalidate & update\n");
1483 InvalidateRect(hwnd
, NULL
, TRUE
);
1485 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1487 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1489 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1490 /* 1. Without backbuffer */
1491 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1494 hdc
= GetWindowDC(hwndparent
);
1496 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1497 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1498 ok(r
!= 0, "Expected not zero result\n");
1499 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1500 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1502 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1505 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1506 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1507 ok(r
!= 0, "Expected not zero result\n");
1508 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1509 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1511 /* 2. With backbuffer */
1512 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1513 LVS_EX_DOUBLEBUFFER
);
1514 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1517 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1518 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1519 ok(r
!= 0, "Expected not zero result\n");
1520 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1521 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1523 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1526 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1527 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1528 todo_wine
ok(r
!= 0, "Expected not zero result\n");
1529 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1530 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1532 ReleaseDC(hwndparent
, hdc
);
1534 DestroyWindow(hwnd
);
1537 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1539 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1541 if(msg
== WM_NOTIFY
) {
1542 NMHDR
*nmhdr
= (PVOID
)lp
;
1543 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1544 NMLVCUSTOMDRAW
*nmlvcd
= (PVOID
)nmhdr
;
1545 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd
->nmcd
.dwDrawStage
);
1546 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1548 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1549 return CDRF_NOTIFYITEMDRAW
;
1550 case CDDS_ITEMPREPAINT
:
1551 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1552 return CDRF_NOTIFYSUBITEMDRAW
;
1553 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1554 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1555 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1556 return CDRF_NOTIFYPOSTPAINT
;
1557 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1558 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1559 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1560 return CDRF_DODEFAULT
;
1562 return CDRF_DODEFAULT
;
1566 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1569 static void test_customdraw(void)
1574 hwnd
= create_listview_control(LVS_REPORT
);
1576 insert_column(hwnd
, 0);
1577 insert_column(hwnd
, 1);
1578 insert_item(hwnd
, 0);
1580 oldwndproc
= (WNDPROC
)SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
,
1581 (LONG_PTR
)cd_wndproc
);
1583 InvalidateRect(hwnd
, NULL
, TRUE
);
1586 SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1588 DestroyWindow(hwnd
);
1591 static void test_icon_spacing(void)
1593 /* LVM_SETICONSPACING */
1594 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1600 hwnd
= create_listview_control(LVS_ICON
);
1601 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1603 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, NF_REQUERY
);
1604 expect(NFR_ANSI
, r
);
1606 /* reset the icon spacing to defaults */
1607 SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1609 /* now we can request what the defaults are */
1610 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1614 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1616 trace("test icon spacing\n");
1618 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1619 ok(r
== MAKELONG(w
, h
) ||
1620 broken(r
== MAKELONG(w
, w
)), /* win98 */
1621 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1623 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1627 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1628 DestroyWindow(hwnd
);
1631 expect(MAKELONG(20,30), r
);
1633 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1634 expect(MAKELONG(25,35), r
);
1636 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1638 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1639 DestroyWindow(hwnd
);
1642 static void test_color(void)
1644 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1651 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1653 hwnd
= create_listview_control(LVS_REPORT
);
1654 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1656 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1658 trace("test color seq\n");
1659 for (i
= 0; i
< 4; i
++)
1663 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1665 r
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, color
);
1668 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1670 r
= SendMessage(hwnd
, LVM_GETTEXTCOLOR
, 0, color
);
1673 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1675 r
= SendMessage(hwnd
, LVM_GETTEXTBKCOLOR
, 0, color
);
1679 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1681 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1682 DestroyWindow(hwnd
);
1685 static void test_item_count(void)
1687 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1700 static CHAR item0text
[] = "item0";
1701 static CHAR item1text
[] = "item1";
1702 static CHAR item2text
[] = "item2";
1704 hwnd
= create_listview_control(LVS_REPORT
);
1705 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1707 /* resize in dpiaware manner to fit all 3 items added */
1709 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1710 GetTextMetricsA(hdc
, &tm
);
1711 /* 2 extra pixels for bounds and header border */
1712 height
= tm
.tmHeight
+ 2;
1713 SelectObject(hdc
, hOldFont
);
1716 GetWindowRect(hwnd
, &rect
);
1717 /* 3 items + 1 header + 1 to be sure */
1718 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1720 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1722 trace("test item count\n");
1724 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1728 item0
.mask
= LVIF_TEXT
;
1731 item0
.pszText
= item0text
;
1732 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1735 /* [item0, item1] */
1736 item1
.mask
= LVIF_TEXT
;
1739 item1
.pszText
= item1text
;
1740 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1743 /* [item0, item1, item2] */
1744 item2
.mask
= LVIF_TEXT
;
1747 item2
.pszText
= item2text
;
1748 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1751 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1754 /* [item0, item1] */
1755 r
= SendMessage(hwnd
, LVM_DELETEITEM
, 2, 0);
1758 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1762 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1765 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1769 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1772 /* [item0, item1] */
1773 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1776 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1779 /* [item0, item1, item2] */
1780 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1783 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1786 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
1788 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1789 DestroyWindow(hwnd
);
1792 static void test_item_position(void)
1794 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1803 static CHAR item0text
[] = "item0";
1804 static CHAR item1text
[] = "item1";
1805 static CHAR item2text
[] = "item2";
1807 hwnd
= create_listview_control(LVS_ICON
);
1808 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1810 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1812 trace("test item position\n");
1815 item0
.mask
= LVIF_TEXT
;
1818 item0
.pszText
= item0text
;
1819 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1822 /* [item0, item1] */
1823 item1
.mask
= LVIF_TEXT
;
1826 item1
.pszText
= item1text
;
1827 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1830 /* [item0, item1, item2] */
1831 item2
.mask
= LVIF_TEXT
;
1834 item2
.pszText
= item2text
;
1835 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1838 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
1840 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
1842 expect2(10, 5, position
.x
, position
.y
);
1844 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
1846 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
1848 expect2(0, 0, position
.x
, position
.y
);
1850 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
1852 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
1854 expect2(20, 20, position
.x
, position
.y
);
1856 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
1858 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1859 DestroyWindow(hwnd
);
1862 static void test_getorigin(void)
1870 position
.x
= position
.y
= 0;
1872 hwnd
= create_listview_control(LVS_ICON
);
1873 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1874 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1875 trace("test get origin results\n");
1876 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1878 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1879 DestroyWindow(hwnd
);
1881 hwnd
= create_listview_control(LVS_SMALLICON
);
1882 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1883 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1884 trace("test get origin results\n");
1885 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1887 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1888 DestroyWindow(hwnd
);
1890 hwnd
= create_listview_control(LVS_LIST
);
1891 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1892 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1893 trace("test get origin results\n");
1894 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1896 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1897 DestroyWindow(hwnd
);
1899 hwnd
= create_listview_control(LVS_REPORT
);
1900 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1901 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1902 trace("test get origin results\n");
1903 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1905 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1906 DestroyWindow(hwnd
);
1910 static void test_multiselect(void)
1912 typedef struct t_select_task
1923 int i
,j
,item_count
,selected_count
;
1924 static const int items
=5;
1930 static struct t_select_task task_list
[] = {
1931 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
1932 { "using VK_UP", -1, VK_UP
, -1, -1 },
1933 { "using VK_END", 0, VK_END
, 1, -1 },
1934 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
1938 hwnd
= create_listview_control(LVS_REPORT
);
1940 for (i
=0;i
<items
;i
++) {
1941 insert_item(hwnd
, 0);
1944 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1946 expect(items
,item_count
);
1949 task
= task_list
[i
];
1951 /* deselect all items */
1952 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1953 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1955 /* set initial position */
1956 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
1957 ListView_SetItemState(hwnd
,(task
.initPos
== -1 ? item_count
-1 : task
.initPos
),LVIS_SELECTED
,LVIS_SELECTED
);
1959 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1961 ok(selected_count
== 1, "There should be only one selected item at the beginning (is %d)\n",selected_count
);
1963 /* Set SHIFT key pressed */
1964 GetKeyboardState(kstate
);
1965 kstate
[VK_SHIFT
]=0x80;
1966 SetKeyboardState(kstate
);
1968 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
1969 r
= SendMessage(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
1971 r
= SendMessage(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
1975 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1977 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
);
1979 /* Set SHIFT key released */
1980 GetKeyboardState(kstate
);
1981 kstate
[VK_SHIFT
]=0x00;
1982 SetKeyboardState(kstate
);
1984 DestroyWindow(hwnd
);
1986 /* make multiple selection, then switch to LVS_SINGLESEL */
1987 hwnd
= create_listview_control(LVS_REPORT
);
1988 for (i
=0;i
<items
;i
++) {
1989 insert_item(hwnd
, 0);
1991 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1992 expect(items
,item_count
);
1994 /* try with NULL pointer */
1995 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, 0);
1998 /* select all, check notifications */
1999 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
2001 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2003 item
.stateMask
= LVIS_SELECTED
;
2004 item
.state
= LVIS_SELECTED
;
2005 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2008 ok_sequence(sequences
, PARENT_SEQ_INDEX
, select_all_parent_seq
,
2009 "select all notification", FALSE
);
2011 /* deselect all items */
2012 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
2013 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2015 ListView_SetItemState(hwnd
, i
, LVIS_SELECTED
, LVIS_SELECTED
);
2018 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2020 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2023 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2024 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2025 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2026 /* check that style is accepted */
2027 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2028 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2031 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2032 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2034 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2036 SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2039 /* select one more */
2040 ListView_SetItemState(hwnd
, 3, LVIS_SELECTED
, LVIS_SELECTED
);
2043 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2044 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2046 r
= ListView_GetItemState(hwnd
, 3, LVIS_SELECTED
);
2047 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2049 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2051 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2054 /* try to select all on LVS_SINGLESEL */
2055 memset(&item
, 0, sizeof(item
));
2056 item
.stateMask
= LVIS_SELECTED
;
2057 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2059 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2061 item
.stateMask
= LVIS_SELECTED
;
2062 item
.state
= LVIS_SELECTED
;
2063 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2066 r
= ListView_GetSelectedCount(hwnd
);
2068 r
= ListView_GetSelectionMark(hwnd
);
2071 /* try to deselect all on LVS_SINGLESEL */
2072 item
.stateMask
= LVIS_SELECTED
;
2073 item
.state
= LVIS_SELECTED
;
2074 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2077 item
.stateMask
= LVIS_SELECTED
;
2079 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2081 r
= ListView_GetSelectedCount(hwnd
);
2084 DestroyWindow(hwnd
);
2087 static void test_subitem_rect(void)
2095 /* test LVM_GETSUBITEMRECT for header */
2096 hwnd
= create_listview_control(LVS_REPORT
);
2097 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2098 /* add some columns */
2099 memset(&col
, 0, sizeof(LVCOLUMN
));
2100 col
.mask
= LVCF_WIDTH
;
2102 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2105 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2108 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2110 /* item = -1 means header, subitem index is 1 based */
2111 rect
.left
= LVIR_BOUNDS
;
2113 rect
.right
= rect
.bottom
= 0;
2114 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2117 rect
.left
= LVIR_BOUNDS
;
2119 rect
.right
= rect
.bottom
= 0;
2120 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2122 ok(r
!= 0, "Expected not-null LRESULT\n");
2123 expect(100, rect
.left
);
2124 expect(250, rect
.right
);
2126 expect(3, rect
.top
);
2128 rect
.left
= LVIR_BOUNDS
;
2130 rect
.right
= rect
.bottom
= 0;
2131 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2133 ok(r
!= 0, "Expected not-null LRESULT\n");
2134 expect(250, rect
.left
);
2135 expect(450, rect
.right
);
2137 expect(3, rect
.top
);
2139 /* item LVS_REPORT padding isn't applied to subitems */
2140 insert_item(hwnd
, 0);
2142 rect
.left
= LVIR_BOUNDS
;
2144 rect
.right
= rect
.bottom
= 0;
2145 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2146 ok(r
!= 0, "Expected not-null LRESULT\n");
2147 expect(100, rect
.left
);
2148 expect(250, rect
.right
);
2150 rect
.left
= LVIR_ICON
;
2152 rect
.right
= rect
.bottom
= 0;
2153 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2154 ok(r
!= 0, "Expected not-null LRESULT\n");
2155 /* no icon attached - zero width rectangle, with no left padding */
2156 expect(100, rect
.left
);
2157 expect(100, rect
.right
);
2159 rect
.left
= LVIR_LABEL
;
2161 rect
.right
= rect
.bottom
= 0;
2162 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2163 ok(r
!= 0, "Expected not-null LRESULT\n");
2164 /* same as full LVIR_BOUNDS */
2165 expect(100, rect
.left
);
2166 expect(250, rect
.right
);
2168 SendMessage(hwnd
, LVM_SCROLL
, 10, 0);
2170 rect
.left
= LVIR_BOUNDS
;
2172 rect
.right
= rect
.bottom
= 0;
2173 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2174 ok(r
!= 0, "Expected not-null LRESULT\n");
2175 expect(90, rect
.left
);
2176 expect(240, rect
.right
);
2178 SendMessage(hwnd
, LVM_SCROLL
, -10, 0);
2180 DestroyWindow(hwnd
);
2182 /* test subitem rects after re-arranging columns */
2183 hwnd
= create_listview_control(LVS_REPORT
);
2184 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2185 memset(&col
, 0, sizeof(LVCOLUMN
));
2186 col
.mask
= LVCF_WIDTH
;
2189 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2193 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2197 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2200 insert_item(hwnd
, 0);
2201 insert_item(hwnd
, 1);
2203 /* wrong item is refused for main item */
2204 rect
.left
= LVIR_BOUNDS
;
2206 rect
.right
= rect
.bottom
= -1;
2207 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect
);
2208 ok(r
== FALSE
, "got %d\n", r
);
2210 /* for subitems rectangle is calculated even if there's no item added */
2211 rect
.left
= LVIR_BOUNDS
;
2213 rect
.right
= rect
.bottom
= -1;
2214 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect
);
2215 ok(r
== TRUE
, "got %d\n", r
);
2217 rect2
.left
= LVIR_BOUNDS
;
2219 rect2
.right
= rect2
.bottom
= -1;
2220 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect2
);
2222 ok(r
== TRUE
, "got %d\n", r
);
2223 expect(rect
.right
, rect2
.right
);
2224 expect(rect
.left
, rect2
.left
);
2225 expect(rect
.bottom
, rect2
.top
);
2226 ok(rect2
.bottom
> rect2
.top
, "expected not zero height\n");
2229 arr
[0] = 1; arr
[1] = 0; arr
[2] = 2;
2230 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 3, (LPARAM
)arr
);
2233 rect
.left
= LVIR_BOUNDS
;
2235 rect
.right
= rect
.bottom
= -1;
2236 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2237 ok(r
== TRUE
, "got %d\n", r
);
2238 expect(0, rect
.left
);
2239 expect(600, rect
.right
);
2241 rect
.left
= LVIR_BOUNDS
;
2243 rect
.right
= rect
.bottom
= -1;
2244 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2245 ok(r
== TRUE
, "got %d\n", r
);
2246 expect(0, rect
.left
);
2247 expect(200, rect
.right
);
2249 rect2
.left
= LVIR_BOUNDS
;
2251 rect2
.right
= rect2
.bottom
= -1;
2252 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect2
);
2253 ok(r
== TRUE
, "got %d\n", r
);
2254 expect(0, rect2
.left
);
2255 expect(200, rect2
.right
);
2256 /* items are of the same height */
2257 ok(rect2
.top
> 0, "expected positive item height\n");
2258 expect(rect
.bottom
, rect2
.top
);
2259 expect(rect
.bottom
* 2 - rect
.top
, rect2
.bottom
);
2261 rect
.left
= LVIR_BOUNDS
;
2263 rect
.right
= rect
.bottom
= -1;
2264 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2265 ok(r
== TRUE
, "got %d\n", r
);
2266 expect(300, rect
.left
);
2267 expect(600, rect
.right
);
2269 DestroyWindow(hwnd
);
2271 /* try it for non LVS_REPORT style */
2272 hwnd
= CreateWindow("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2273 GetModuleHandle(NULL
), 0);
2274 rect
.left
= LVIR_BOUNDS
;
2276 rect
.right
= rect
.bottom
= -10;
2277 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2278 ok(r
== 0, "Expected not-null LRESULT\n");
2279 /* rect is unchanged */
2280 expect(0, rect
.left
);
2281 expect(-10, rect
.right
);
2282 expect(1, rect
.top
);
2283 expect(-10, rect
.bottom
);
2284 DestroyWindow(hwnd
);
2287 /* comparison callback for test_sorting */
2288 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2290 if (first
== second
) return 0;
2291 return (first
> second
? 1 : -1);
2294 static void test_sorting(void)
2300 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2303 hwnd
= create_listview_control(LVS_REPORT
);
2304 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2306 /* insert some items */
2307 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2308 item
.state
= LVIS_SELECTED
;
2312 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2315 item
.mask
= LVIF_PARAM
;
2319 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2322 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2323 item
.state
= LVIS_SELECTED
;
2327 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2330 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2333 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2336 r
= SendMessage(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2339 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2341 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2343 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2345 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2346 expect(LVIS_SELECTED
, r
);
2347 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2348 expect(LVIS_SELECTED
, r
);
2350 DestroyWindow(hwnd
);
2352 /* switch to LVS_SORTASCENDING when some items added */
2353 hwnd
= create_listview_control(LVS_REPORT
);
2354 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2356 item
.mask
= LVIF_TEXT
;
2359 item
.pszText
= names
[1];
2360 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2363 item
.mask
= LVIF_TEXT
;
2366 item
.pszText
= names
[2];
2367 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2370 item
.mask
= LVIF_TEXT
;
2373 item
.pszText
= names
[0];
2374 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2377 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2378 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2379 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2380 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2382 /* no sorting performed when switched to LVS_SORTASCENDING */
2383 item
.mask
= LVIF_TEXT
;
2385 item
.pszText
= buff
;
2386 item
.cchTextMax
= sizeof(buff
);
2387 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2389 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2392 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2394 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2397 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2399 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2401 /* adding new item doesn't resort list */
2402 item
.mask
= LVIF_TEXT
;
2405 item
.pszText
= names
[3];
2406 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2409 item
.mask
= LVIF_TEXT
;
2411 item
.pszText
= buff
;
2412 item
.cchTextMax
= sizeof(buff
);
2413 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2415 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2418 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2420 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2423 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2425 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2428 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2430 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2432 /* corner case - item should be placed at first position */
2433 item
.mask
= LVIF_TEXT
;
2436 item
.pszText
= names
[4];
2437 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2441 item
.pszText
= buff
;
2442 item
.cchTextMax
= sizeof(buff
);
2443 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2445 ok(lstrcmp(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2448 item
.pszText
= buff
;
2449 item
.cchTextMax
= sizeof(buff
);
2450 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2452 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2455 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2457 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2460 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2462 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2465 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2467 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2469 DestroyWindow(hwnd
);
2472 static void test_ownerdata(void)
2475 LONG_PTR style
, ret
;
2479 /* it isn't possible to set LVS_OWNERDATA after creation */
2482 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2486 hwnd
= create_listview_control(LVS_REPORT
);
2487 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2488 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2489 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2491 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2493 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2494 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2495 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2496 "try to switch to LVS_OWNERDATA seq", FALSE
);
2498 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2499 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2500 DestroyWindow(hwnd
);
2503 /* try to set LVS_OWNERDATA after creation just having it */
2504 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2505 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2506 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2507 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2509 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2511 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2512 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2513 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2514 "try to switch to LVS_OWNERDATA seq", FALSE
);
2515 DestroyWindow(hwnd
);
2517 /* try to remove LVS_OWNERDATA after creation just having it */
2520 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2524 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2525 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2526 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2527 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2529 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2531 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2532 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2533 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2534 "try to switch to LVS_OWNERDATA seq", FALSE
);
2535 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2536 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2537 DestroyWindow(hwnd
);
2540 /* try select an item */
2541 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2542 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2543 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2544 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2545 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2547 memset(&item
, 0, sizeof(item
));
2548 item
.stateMask
= LVIS_SELECTED
;
2549 item
.state
= LVIS_SELECTED
;
2550 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2552 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2554 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2556 DestroyWindow(hwnd
);
2558 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2559 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2560 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2561 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2562 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2563 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2565 memset(&item
, 0, sizeof(item
));
2566 item
.mask
= LVIF_STATE
;
2568 item
.stateMask
= LVIS_SELECTED
;
2569 item
.state
= LVIS_SELECTED
;
2570 res
= SendMessageA(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2572 DestroyWindow(hwnd
);
2574 /* check notifications after focused/selected changed */
2575 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2576 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2577 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
2578 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2580 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2582 memset(&item
, 0, sizeof(item
));
2583 item
.stateMask
= LVIS_SELECTED
;
2584 item
.state
= LVIS_SELECTED
;
2585 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2588 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2589 "ownerdata select notification", TRUE
);
2591 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2593 memset(&item
, 0, sizeof(item
));
2594 item
.stateMask
= LVIS_FOCUSED
;
2595 item
.state
= LVIS_FOCUSED
;
2596 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2599 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2600 "ownerdata focus notification", TRUE
);
2602 /* select all, check notifications */
2603 item
.stateMask
= LVIS_SELECTED
;
2605 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2608 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2610 item
.stateMask
= LVIS_SELECTED
;
2611 item
.state
= LVIS_SELECTED
;
2613 g_dump_itemchanged
= TRUE
;
2614 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2616 g_dump_itemchanged
= FALSE
;
2618 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2619 "ownerdata select all notification", TRUE
);
2621 /* select all again, note that all items are selected already */
2622 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2623 item
.stateMask
= LVIS_SELECTED
;
2624 item
.state
= LVIS_SELECTED
;
2625 g_dump_itemchanged
= TRUE
;
2626 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2628 g_dump_itemchanged
= FALSE
;
2629 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2630 "ownerdata select all notification", TRUE
);
2632 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2633 item
.stateMask
= LVIS_SELECTED
;
2635 g_dump_itemchanged
= TRUE
;
2636 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2638 g_dump_itemchanged
= FALSE
;
2639 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2640 "ownerdata deselect all notification", TRUE
);
2642 /* select one, then deselect all */
2643 item
.stateMask
= LVIS_SELECTED
;
2644 item
.state
= LVIS_SELECTED
;
2645 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2647 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2648 item
.stateMask
= LVIS_SELECTED
;
2650 g_dump_itemchanged
= TRUE
;
2651 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2653 g_dump_itemchanged
= FALSE
;
2654 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2655 "ownerdata select all notification", TRUE
);
2657 /* remove focused, try to focus all */
2658 item
.stateMask
= LVIS_FOCUSED
;
2659 item
.state
= LVIS_FOCUSED
;
2660 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2662 item
.stateMask
= LVIS_FOCUSED
;
2664 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2666 item
.stateMask
= LVIS_FOCUSED
;
2667 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
2669 /* setting all to focused returns failure value */
2670 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2671 item
.stateMask
= LVIS_FOCUSED
;
2672 item
.state
= LVIS_FOCUSED
;
2673 g_dump_itemchanged
= TRUE
;
2674 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2676 g_dump_itemchanged
= FALSE
;
2677 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2678 "ownerdata focus all notification", FALSE
);
2679 /* focus single item, remove all */
2680 item
.stateMask
= LVIS_FOCUSED
;
2681 item
.state
= LVIS_FOCUSED
;
2682 res
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2684 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2685 item
.stateMask
= LVIS_FOCUSED
;
2687 g_dump_itemchanged
= TRUE
;
2688 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2690 g_dump_itemchanged
= FALSE
;
2691 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
2692 "ownerdata remove focus all notification", TRUE
);
2694 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2695 item
.stateMask
= LVIS_CUT
;
2696 item
.state
= LVIS_CUT
;
2697 g_dump_itemchanged
= TRUE
;
2698 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2700 g_dump_itemchanged
= FALSE
;
2701 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2702 "ownerdata cut all notification", TRUE
);
2703 /* all marked cut, try again */
2704 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2705 item
.stateMask
= LVIS_CUT
;
2706 item
.state
= LVIS_CUT
;
2707 g_dump_itemchanged
= TRUE
;
2708 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2710 g_dump_itemchanged
= FALSE
;
2711 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2712 "ownerdata cut all notification #2", TRUE
);
2714 DestroyWindow(hwnd
);
2716 /* check notifications on LVM_GETITEM */
2717 /* zero callback mask */
2718 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2719 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2720 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2721 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2723 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2725 memset(&item
, 0, sizeof(item
));
2726 item
.stateMask
= LVIS_SELECTED
;
2727 item
.mask
= LVIF_STATE
;
2728 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2731 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2732 "ownerdata getitem selected state 1", FALSE
);
2734 /* non zero callback mask but not we asking for */
2735 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
2738 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2740 memset(&item
, 0, sizeof(item
));
2741 item
.stateMask
= LVIS_SELECTED
;
2742 item
.mask
= LVIF_STATE
;
2743 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2746 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2747 "ownerdata getitem selected state 2", FALSE
);
2749 /* LVIS_OVERLAYMASK callback mask, asking for index */
2750 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2752 memset(&item
, 0, sizeof(item
));
2753 item
.stateMask
= LVIS_OVERLAYMASK
;
2754 item
.mask
= LVIF_STATE
;
2755 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2758 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
2759 "ownerdata getitem selected state 2", FALSE
);
2761 DestroyWindow(hwnd
);
2763 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2764 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
| LVS_REPORT
);
2765 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2766 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2767 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2768 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2769 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
2770 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2771 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
2772 DestroyWindow(hwnd
);
2773 /* apparently it's allowed to switch these style on after creation */
2774 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2775 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2776 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2777 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2778 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2779 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2780 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2781 DestroyWindow(hwnd
);
2783 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2784 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2785 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2786 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2787 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
2788 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2789 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
2790 DestroyWindow(hwnd
);
2793 static void test_norecompute(void)
2795 static CHAR testA
[] = "test";
2801 /* self containing control */
2802 hwnd
= create_listview_control(LVS_REPORT
);
2803 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2804 memset(&item
, 0, sizeof(item
));
2805 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
2807 item
.stateMask
= LVIS_SELECTED
;
2808 item
.state
= LVIS_SELECTED
;
2809 item
.pszText
= testA
;
2810 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2812 /* retrieve with LVIF_NORECOMPUTE */
2813 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2815 item
.pszText
= buff
;
2816 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2817 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2819 ok(lstrcmp(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
2821 item
.mask
= LVIF_TEXT
;
2823 item
.pszText
= LPSTR_TEXTCALLBACK
;
2824 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2827 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2829 item
.pszText
= buff
;
2830 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2832 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2833 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2835 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2836 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2837 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
2839 DestroyWindow(hwnd
);
2842 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2843 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2845 item
.mask
= LVIF_STATE
;
2846 item
.stateMask
= LVIS_SELECTED
;
2847 item
.state
= LVIS_SELECTED
;
2849 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2852 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2854 item
.pszText
= buff
;
2855 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2856 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2857 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2859 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2860 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2861 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
2863 DestroyWindow(hwnd
);
2866 static void test_nosortheader(void)
2871 hwnd
= create_listview_control(LVS_REPORT
);
2872 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2874 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2875 ok(IsWindow(header
), "header expected\n");
2877 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2878 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
2880 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2881 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
2882 /* HDS_BUTTONS retained */
2883 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2884 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
2886 DestroyWindow(hwnd
);
2888 /* create with LVS_NOSORTHEADER */
2889 hwnd
= create_listview_control(LVS_NOSORTHEADER
| LVS_REPORT
);
2890 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2892 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2893 ok(IsWindow(header
), "header expected\n");
2895 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2896 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2898 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2899 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
2900 /* not changed here */
2901 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2902 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2904 DestroyWindow(hwnd
);
2907 static void test_setredraw(void)
2915 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2916 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2918 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2919 ListView seems to handle it internally without DefWinProc */
2921 /* default value first */
2922 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2925 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2926 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2927 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2929 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2930 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2931 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2934 /* check update rect after redrawing */
2935 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2937 InvalidateRect(hwnd
, NULL
, FALSE
);
2938 RedrawWindow(hwnd
, NULL
, NULL
, RDW_UPDATENOW
);
2939 rect
.right
= rect
.bottom
= 1;
2940 GetUpdateRect(hwnd
, &rect
, FALSE
);
2941 expect(0, rect
.right
);
2942 expect(0, rect
.bottom
);
2945 hdc
= GetWindowDC(hwndparent
);
2946 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
2948 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2950 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
2952 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2954 ReleaseDC(hwndparent
, hdc
);
2956 /* check notification messages to show that repainting is disabled */
2957 ret
= SendMessage(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2959 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2961 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2963 InvalidateRect(hwnd
, NULL
, TRUE
);
2965 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2966 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
2968 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
2970 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2971 InvalidateRect(hwnd
, NULL
, TRUE
);
2973 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2974 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
2976 /* message isn't forwarded to header */
2977 subclass_header(hwnd
);
2978 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2979 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2981 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
2982 "WM_SETREDRAW: not forwarded to header", FALSE
);
2984 DestroyWindow(hwnd
);
2987 static void test_hittest(void)
2993 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2996 HIMAGELIST himl
, himl2
;
2999 hwnd
= create_listview_control(LVS_REPORT
);
3000 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3002 /* LVS_REPORT with a single subitem (2 columns) */
3003 insert_column(hwnd
, 0);
3004 insert_column(hwnd
, 1);
3005 insert_item(hwnd
, 0);
3008 /* the only purpose of that line is to be as long as a half item rect */
3009 item
.pszText
= text
;
3010 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
3013 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3015 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3018 memset(&bounds
, 0, sizeof(bounds
));
3019 bounds
.left
= LVIR_BOUNDS
;
3020 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
3021 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
3022 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
3023 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
3026 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3028 /* outside columns by x position - valid is [0, 199] */
3030 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3031 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TOLEFT
, 0, FALSE
, FALSE
);
3032 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3034 x
= pos
.x
+ 50; /* column half width */
3035 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3036 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, 0, FALSE
, FALSE
);
3037 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3038 x
= pos
.x
+ 150; /* outside column */
3039 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3040 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3041 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3042 y
= (bounds
.bottom
- bounds
.top
) / 2;
3043 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3044 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3045 /* outside possible client rectangle (to right) */
3047 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3048 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3049 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3050 y
= (bounds
.bottom
- bounds
.top
) / 2;
3051 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3052 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3053 /* subitem returned with -1 item too */
3056 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3057 /* parent client area is 100x100 by default */
3058 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
3059 x
= pos
.x
+ 150; /* outside column */
3060 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3061 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, FALSE
);
3062 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3063 y
= (bounds
.bottom
- bounds
.top
) / 2;
3064 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, TRUE
);
3065 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3066 /* the same with LVS_EX_FULLROWSELECT */
3067 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3068 x
= pos
.x
+ 150; /* outside column */
3069 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3070 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, LVHT_ONITEMLABEL
, FALSE
, FALSE
);
3071 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3072 y
= (bounds
.bottom
- bounds
.top
) / 2;
3073 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3074 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
3075 x
= pos
.x
+ 150; /* outside column */
3076 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3077 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3078 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3079 y
= (bounds
.bottom
- bounds
.top
) / 2;
3080 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3081 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3082 /* outside possible client rectangle (to right) */
3084 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3085 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3086 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3087 y
= (bounds
.bottom
- bounds
.top
) / 2;
3088 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3089 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3090 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3091 himl
= ImageList_Create(16, 16, 0, 4, 4);
3092 ok(himl
!= NULL
, "failed to create imagelist\n");
3093 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3094 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3095 r
= ImageList_Add(himl
, hbmp
, 0);
3096 ok(r
== 0, "should be zero\n");
3097 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3098 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3099 r
= ImageList_Add(himl
, hbmp
, 0);
3100 ok(r
== 1, "should be one\n");
3102 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3103 ok(r
== 0, "should return zero\n");
3105 item
.mask
= LVIF_IMAGE
;
3109 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3113 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3114 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3115 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3116 y
= (bounds
.bottom
- bounds
.top
) / 2;
3117 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3119 /* state icons indices are 1 based, check with valid index */
3120 item
.mask
= LVIF_STATE
;
3121 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3122 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3125 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3129 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3130 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3131 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3132 y
= (bounds
.bottom
- bounds
.top
) / 2;
3133 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3135 himl2
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3136 ok(himl2
== himl
, "should return handle\n");
3138 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3139 ok(r
== 0, "should return zero\n");
3142 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3143 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, 0, FALSE
, FALSE
);
3144 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3145 y
= (bounds
.bottom
- bounds
.top
) / 2;
3146 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3148 DestroyWindow(hwnd
);
3151 static void test_getviewrect(void)
3158 hwnd
= create_listview_control(LVS_REPORT
);
3159 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3162 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3165 insert_column(hwnd
, 0);
3166 insert_column(hwnd
, 1);
3168 memset(&item
, 0, sizeof(item
));
3171 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3173 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3175 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3178 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3179 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3181 /* left is set to (2e31-1) - XP SP2 */
3182 expect(0, rect
.right
);
3183 expect(0, rect
.top
);
3184 expect(0, rect
.bottom
);
3186 /* switch to LVS_ICON */
3187 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3189 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3190 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3192 expect(0, rect
.left
);
3193 expect(0, rect
.top
);
3194 /* precise value differs for 2k, XP and Vista */
3195 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3196 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3198 DestroyWindow(hwnd
);
3201 static void test_getitemposition(void)
3208 hwnd
= create_listview_control(LVS_REPORT
);
3209 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3210 header
= subclass_header(hwnd
);
3212 /* LVS_REPORT, single item, no columns added */
3213 insert_item(hwnd
, 0);
3215 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3218 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3220 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3222 /* LVS_REPORT, single item, single column */
3223 insert_column(hwnd
, 0);
3225 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3228 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3230 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3232 memset(&rect
, 0, sizeof(rect
));
3233 SendMessage(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3236 /* offset by header height */
3237 expect(rect
.bottom
- rect
.top
, pt
.y
);
3239 DestroyWindow(hwnd
);
3242 static void test_columnscreation(void)
3247 hwnd
= create_listview_control(LVS_REPORT
);
3248 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3250 insert_item(hwnd
, 0);
3252 /* headers columns aren't created automatically */
3253 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3254 ok(IsWindow(header
), "Expected header handle\n");
3255 r
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
3258 DestroyWindow(hwnd
);
3261 static void test_getitemrect(void)
3273 /* rectangle isn't empty for empty text items */
3274 hwnd
= create_listview_control(LVS_LIST
);
3275 memset(&item
, 0, sizeof(item
));
3278 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3280 rect
.left
= LVIR_LABEL
;
3281 SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3282 expect(0, rect
.left
);
3283 expect(0, rect
.top
);
3284 todo_wine
expect(96, rect
.right
);
3285 DestroyWindow(hwnd
);
3287 hwnd
= create_listview_control(LVS_REPORT
);
3288 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3291 memset(&item
, 0, sizeof(item
));
3294 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3297 rect
.left
= LVIR_BOUNDS
;
3298 rect
.right
= rect
.top
= rect
.bottom
= -1;
3299 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3302 /* zero width rectangle with no padding */
3303 expect(0, rect
.left
);
3304 expect(0, rect
.right
);
3306 insert_column(hwnd
, 0);
3307 insert_column(hwnd
, 1);
3309 col
.mask
= LVCF_WIDTH
;
3311 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 0, (LPARAM
)&col
);
3314 col
.mask
= LVCF_WIDTH
;
3316 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 1, (LPARAM
)&col
);
3319 rect
.left
= LVIR_BOUNDS
;
3320 rect
.right
= rect
.top
= rect
.bottom
= -1;
3321 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3324 /* still no left padding */
3325 expect(0, rect
.left
);
3326 expect(150, rect
.right
);
3328 rect
.left
= LVIR_SELECTBOUNDS
;
3329 rect
.right
= rect
.top
= rect
.bottom
= -1;
3330 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3333 expect(2, rect
.left
);
3335 rect
.left
= LVIR_LABEL
;
3336 rect
.right
= rect
.top
= rect
.bottom
= -1;
3337 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3339 /* padding, column width */
3340 expect(2, rect
.left
);
3341 expect(50, rect
.right
);
3343 /* no icons attached */
3344 rect
.left
= LVIR_ICON
;
3345 rect
.right
= rect
.top
= rect
.bottom
= -1;
3346 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3349 expect(2, rect
.left
);
3350 expect(2, rect
.right
);
3353 order
[0] = 1; order
[1] = 0;
3354 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3357 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3359 /* 1 indexed column width + padding */
3361 /* rect is at zero too */
3362 rect
.left
= LVIR_BOUNDS
;
3363 rect
.right
= rect
.top
= rect
.bottom
= -1;
3364 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3366 expect(0, rect
.left
);
3367 /* just width sum */
3368 expect(150, rect
.right
);
3370 rect
.left
= LVIR_SELECTBOUNDS
;
3371 rect
.right
= rect
.top
= rect
.bottom
= -1;
3372 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3374 /* column width + padding */
3375 expect(102, rect
.left
);
3377 /* back to initial order */
3378 order
[0] = 0; order
[1] = 1;
3379 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3383 himl
= ImageList_Create(16, 16, 0, 2, 2);
3384 ok(himl
!= NULL
, "failed to create imagelist\n");
3385 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3386 ok(hbm
!= NULL
, "failed to create bitmap\n");
3387 r
= ImageList_Add(himl
, hbm
, 0);
3388 ok(r
== 0, "should be zero\n");
3389 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3390 ok(hbm
!= NULL
, "failed to create bitmap\n");
3391 r
= ImageList_Add(himl
, hbm
, 0);
3392 ok(r
== 1, "should be one\n");
3394 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3395 ok(r
== 0, "should return zero\n");
3397 item
.mask
= LVIF_STATE
;
3398 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3399 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3402 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3406 rect
.left
= LVIR_ICON
;
3407 rect
.right
= rect
.top
= rect
.bottom
= -1;
3408 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3410 /* padding + stateicon width */
3411 expect(18, rect
.left
);
3412 expect(18, rect
.right
);
3414 rect
.left
= LVIR_LABEL
;
3415 rect
.right
= rect
.top
= rect
.bottom
= -1;
3416 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3418 /* padding + stateicon width -> column width */
3419 expect(18, rect
.left
);
3420 expect(50, rect
.right
);
3422 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3423 ok(r
!= 0, "should return current list handle\n");
3425 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3426 ok(r
== 0, "should return zero\n");
3428 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3431 item
.stateMask
= ~0;
3434 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3438 rect
.left
= LVIR_ICON
;
3439 rect
.right
= rect
.top
= rect
.bottom
= -1;
3440 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3442 /* padding, icon width */
3443 expect(2, rect
.left
);
3444 expect(18, rect
.right
);
3446 rect
.left
= LVIR_LABEL
;
3447 rect
.right
= rect
.top
= rect
.bottom
= -1;
3448 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3450 /* padding + icon width -> column width */
3451 expect(18, rect
.left
);
3452 expect(50, rect
.right
);
3455 rect
.left
= LVIR_SELECTBOUNDS
;
3456 rect
.right
= rect
.top
= rect
.bottom
= -1;
3457 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3459 /* padding, column width */
3460 expect(2, rect
.left
);
3461 expect(50, rect
.right
);
3463 /* try with indentation */
3464 item
.mask
= LVIF_INDENT
;
3468 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3472 rect
.left
= LVIR_BOUNDS
;
3473 rect
.right
= rect
.top
= rect
.bottom
= -1;
3474 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3476 /* padding + 1 icon width, column width */
3477 expect(0, rect
.left
);
3478 expect(150, rect
.right
);
3481 rect
.left
= LVIR_SELECTBOUNDS
;
3482 rect
.right
= rect
.top
= rect
.bottom
= -1;
3483 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3485 /* padding + 1 icon width, column width */
3486 expect(2 + 16, rect
.left
);
3487 expect(50, rect
.right
);
3490 rect
.left
= LVIR_LABEL
;
3491 rect
.right
= rect
.top
= rect
.bottom
= -1;
3492 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3494 /* padding + 2 icon widths, column width */
3495 expect(2 + 16*2, rect
.left
);
3496 expect(50, rect
.right
);
3499 rect
.left
= LVIR_ICON
;
3500 rect
.right
= rect
.top
= rect
.bottom
= -1;
3501 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3503 /* padding + 1 icon width indentation, icon width */
3504 expect(2 + 16, rect
.left
);
3505 expect(34, rect
.right
);
3507 DestroyWindow(hwnd
);
3510 static void test_editbox(void)
3512 static CHAR testitemA
[] = "testitem";
3513 static CHAR testitem1A
[] = "testitem_quitelongname";
3514 static CHAR buffer
[25];
3515 HWND hwnd
, hwndedit
, hwndedit2
, header
;
3519 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
3520 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3522 insert_column(hwnd
, 0);
3524 memset(&item
, 0, sizeof(item
));
3525 item
.mask
= LVIF_TEXT
;
3526 item
.pszText
= testitemA
;
3529 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3532 /* test notifications without edit created */
3533 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3534 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)0xdeadbeef);
3536 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3537 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE
);
3538 /* same thing but with valid window */
3539 hwndedit
= CreateWindowA("Edit", "Test edit", WS_VISIBLE
| WS_CHILD
, 0, 0, 20,
3540 10, hwnd
, (HMENU
)1, (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
), 0);
3541 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3542 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)hwndedit
);
3544 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3545 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE
);
3546 DestroyWindow(hwndedit
);
3548 /* setting focus is necessary */
3550 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3551 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3553 /* test children Z-order after Edit box created */
3554 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3555 ok(IsWindow(header
), "Expected header to be created\n");
3556 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
3557 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
3559 /* modify initial string */
3560 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3563 /* edit window is resized and repositioned,
3564 check again for Z-order - it should be preserved */
3565 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
3566 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
3568 /* return focus to listview */
3571 memset(&item
, 0, sizeof(item
));
3572 item
.mask
= LVIF_TEXT
;
3573 item
.pszText
= buffer
;
3574 item
.cchTextMax
= sizeof(buffer
);
3577 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3580 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3582 /* send LVM_EDITLABEL on already created edit */
3584 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3585 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3586 /* focus will be set to edit */
3587 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
3588 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3589 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
3591 /* creating label disabled when control isn't focused */
3593 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3594 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3596 /* check EN_KILLFOCUS handling */
3597 memset(&item
, 0, sizeof(item
));
3598 item
.pszText
= testitemA
;
3601 r
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3605 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3606 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3607 /* modify edit and notify control that it lost focus */
3608 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3610 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3612 memset(&item
, 0, sizeof(item
));
3613 item
.pszText
= buffer
;
3614 item
.cchTextMax
= sizeof(buffer
);
3617 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3618 expect(lstrlen(item
.pszText
), r
);
3619 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3620 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
3621 /* end edit without saving */
3623 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3624 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3625 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
3627 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3628 "edit box - end edit, no change, escape", TRUE
);
3629 /* end edit with saving */
3631 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3632 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3633 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_RETURN
, 0);
3635 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3636 "edit box - end edit, no change, return", TRUE
);
3638 memset(&item
, 0, sizeof(item
));
3639 item
.pszText
= buffer
;
3640 item
.cchTextMax
= sizeof(buffer
);
3643 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3644 expect(lstrlen(item
.pszText
), r
);
3645 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3647 /* LVM_EDITLABEL with -1 destroys current edit */
3648 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
3649 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3650 /* no edit present */
3651 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3652 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3653 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3654 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3656 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3657 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3658 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3659 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3660 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3661 /* check another negative value */
3662 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3663 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3664 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3665 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -2, 0);
3666 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3667 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3668 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3669 /* and value greater than max item index */
3670 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3671 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3672 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3673 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3674 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, r
, 0);
3675 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3676 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3677 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3679 /* messaging tests */
3681 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3683 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3684 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3685 /* testing only sizing messages */
3686 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
3687 "edit box create - sizing", FALSE
);
3689 /* WM_COMMAND with EN_KILLFOCUS isn't forwared to parent */
3691 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3692 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3693 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3694 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3696 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3697 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE
);
3699 DestroyWindow(hwnd
);
3702 static void test_notifyformat(void)
3707 hwnd
= create_listview_control(LVS_REPORT
);
3708 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3710 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3711 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3712 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3714 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3716 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
3718 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3721 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
3723 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3728 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3729 DestroyWindow(hwnd
);
3733 DestroyWindow(hwnd
);
3735 /* test failure in parent WM_NOTIFYFORMAT */
3737 hwnd
= create_listview_control(LVS_REPORT
);
3738 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3739 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3740 ok(IsWindow(header
), "expected header to be created\n");
3741 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3743 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3744 ok( r
== 1 || broken(r
== 0), /* win9x */ "Expected 1, got %d\n", r
);
3745 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3746 ok(r
!= 0, "Expected valid format\n");
3748 notifyFormat
= NFR_UNICODE
;
3749 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3750 expect(NFR_UNICODE
, r
);
3751 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3753 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3754 ok( r
== 1 || broken(r
== 0), /* win9x */ "Expected 1, got %d\n", r
);
3756 notifyFormat
= NFR_ANSI
;
3757 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3758 expect(NFR_ANSI
, r
);
3759 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3761 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3762 ok( r
== 1 || broken(r
== 0), /* win9x */ "Expected 1, got %d\n", r
);
3764 DestroyWindow(hwnd
);
3766 /* try different unicode window combination and defaults */
3767 if (!GetModuleHandleW(NULL
))
3769 win_skip("Additional notify format tests are incompatible with Win9x\n");
3773 hwndparentW
= create_parent_window(TRUE
);
3774 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
3775 if (!IsWindow(hwndparentW
)) return;
3778 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3779 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3780 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3781 ok(IsWindow(header
), "expected header to be created\n");
3782 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3784 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3786 DestroyWindow(hwnd
);
3787 /* receiving error code defaulting to ansi */
3789 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3790 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3791 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3792 ok(IsWindow(header
), "expected header to be created\n");
3793 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3795 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3797 DestroyWindow(hwnd
);
3798 /* receiving ansi code from unicode window, use it */
3799 notifyFormat
= NFR_ANSI
;
3800 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3801 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3802 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3803 ok(IsWindow(header
), "expected header to be created\n");
3804 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3806 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3808 DestroyWindow(hwnd
);
3809 /* unicode listview with ansi parent window */
3811 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
3812 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3813 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3814 ok(IsWindow(header
), "expected header to be created\n");
3815 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3817 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3819 DestroyWindow(hwnd
);
3820 /* unicode listview with ansi parent window, return error code */
3822 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
3823 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3824 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3825 ok(IsWindow(header
), "expected header to be created\n");
3826 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3828 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3830 DestroyWindow(hwnd
);
3832 DestroyWindow(hwndparentW
);
3835 static void test_indentation(void)
3841 hwnd
= create_listview_control(LVS_REPORT
);
3842 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3844 memset(&item
, 0, sizeof(item
));
3845 item
.mask
= LVIF_INDENT
;
3847 item
.iIndent
= I_INDENTCALLBACK
;
3848 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3851 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3854 item
.mask
= LVIF_INDENT
;
3855 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3858 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3859 "get indent dispinfo", FALSE
);
3861 DestroyWindow(hwnd
);
3864 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
3869 static BOOL
is_below_comctl_5(void)
3874 hwnd
= create_listview_control(LVS_REPORT
);
3875 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3876 insert_item(hwnd
, 0);
3878 ret
= SendMessage(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
3880 DestroyWindow(hwnd
);
3885 static void test_get_set_view(void)
3891 /* test style->view mapping */
3892 hwnd
= create_listview_control(LVS_REPORT
);
3893 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3895 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3896 expect(LV_VIEW_DETAILS
, ret
);
3898 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3900 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
3901 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3902 expect(LV_VIEW_ICON
, ret
);
3904 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3905 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
3906 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3907 expect(LV_VIEW_SMALLICON
, ret
);
3909 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3910 SetWindowLongPtr(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
3911 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3912 expect(LV_VIEW_LIST
, ret
);
3914 /* switching view doesn't touch window style */
3915 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
3917 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3918 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3919 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
3921 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3922 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3923 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
3925 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3926 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3928 DestroyWindow(hwnd
);
3931 static void test_canceleditlabel(void)
3933 HWND hwnd
, hwndedit
;
3937 static CHAR test
[] = "test";
3938 static const CHAR test1
[] = "test1";
3940 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
3941 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3943 insert_item(hwnd
, 0);
3945 /* try without edit created */
3946 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3947 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3949 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3950 "cancel edit label without edit", FALSE
);
3952 /* cancel without data change */
3954 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3955 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3956 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3958 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3960 /* cancel after data change */
3961 memset(&itema
, 0, sizeof(itema
));
3962 itema
.pszText
= test
;
3963 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
3966 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3967 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3968 ret
= SetWindowText(hwndedit
, test1
);
3969 ok(ret
!= 0, "Expected edit text to change\n");
3970 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3972 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3973 memset(&itema
, 0, sizeof(itema
));
3974 itema
.pszText
= buff
;
3975 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3976 ret
= SendMessage(hwnd
, LVM_GETITEMTEXT
, 0, (LPARAM
)&itema
);
3978 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
3980 DestroyWindow(hwnd
);
3983 static void test_mapidindex(void)
3988 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3989 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3990 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3991 insert_item(hwnd
, 0);
3992 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3994 DestroyWindow(hwnd
);
3996 hwnd
= create_listview_control(LVS_REPORT
);
3997 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3999 /* LVM_MAPINDEXTOID with invalid index */
4000 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4003 insert_item(hwnd
, 0);
4004 insert_item(hwnd
, 1);
4006 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
4008 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
4011 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4013 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4015 /* remove 0 indexed item, id retained */
4016 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
4017 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4019 /* new id starts from previous value */
4020 insert_item(hwnd
, 1);
4021 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4024 /* get index by id */
4025 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
4027 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
4029 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
4031 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
4034 DestroyWindow(hwnd
);
4037 static void test_getitemspacing(void)
4046 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
4047 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
4050 hwnd
= create_listview_control(LVS_ICON
);
4051 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4053 expect(cx
, LOWORD(ret
));
4054 expect(cy
, HIWORD(ret
));
4056 /* now try with icons */
4057 himl
= ImageList_Create(40, 40, 0, 4, 4);
4058 ok(himl
!= NULL
, "failed to create imagelist\n");
4059 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4060 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4061 ret
= ImageList_Add(himl
, hbmp
, 0);
4063 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4066 itema
.mask
= LVIF_IMAGE
;
4070 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
4072 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4074 /* spacing + icon size returned */
4075 expect(cx
+ 40, LOWORD(ret
));
4076 expect(cy
+ 40, HIWORD(ret
));
4078 DestroyWindow(hwnd
);
4080 hwnd
= create_listview_control(LVS_SMALLICON
);
4081 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4083 expect(cx
, LOWORD(ret
));
4084 expect(cy
, HIWORD(ret
));
4086 DestroyWindow(hwnd
);
4088 hwnd
= create_listview_control(LVS_REPORT
);
4089 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4091 expect(cx
, LOWORD(ret
));
4092 expect(cy
, HIWORD(ret
));
4094 DestroyWindow(hwnd
);
4096 hwnd
= create_listview_control(LVS_LIST
);
4097 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4099 expect(cx
, LOWORD(ret
));
4100 expect(cy
, HIWORD(ret
));
4102 DestroyWindow(hwnd
);
4105 static void test_getcolumnwidth(void)
4113 /* default column width */
4114 hwnd
= create_listview_control(LVS_ICON
);
4115 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4117 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4118 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
4119 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4120 todo_wine
expect(8, ret
);
4121 style
= GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
4122 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
4124 ret
= SendMessage(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4126 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4128 DestroyWindow(hwnd
);
4130 /* default column width with item added */
4131 hwnd
= create_listview_control(LVS_LIST
);
4132 memset(&itema
, 0, sizeof(itema
));
4133 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4134 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4135 todo_wine
expect(96, ret
);
4136 DestroyWindow(hwnd
);
4139 static void test_scrollnotify(void)
4144 hwnd
= create_listview_control(LVS_REPORT
);
4146 insert_column(hwnd
, 0);
4147 insert_column(hwnd
, 1);
4148 insert_item(hwnd
, 0);
4150 /* make it scrollable - resize */
4151 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
4153 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
4156 /* try with dummy call */
4157 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4158 ret
= SendMessage(hwnd
, LVM_SCROLL
, 0, 0);
4160 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4161 "scroll notify 1", TRUE
);
4163 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4164 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 0);
4166 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4167 "scroll notify 2", TRUE
);
4169 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4170 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 1);
4172 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4173 "scroll notify 3", TRUE
);
4175 DestroyWindow(hwnd
);
4178 static void test_LVS_EX_TRANSPARENTBKGND(void)
4184 hwnd
= create_listview_control(LVS_REPORT
);
4186 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4189 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4190 LVS_EX_TRANSPARENTBKGND
);
4192 ret
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, 0);
4193 if (ret
!= CLR_NONE
)
4195 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4196 DestroyWindow(hwnd
);
4200 /* try to set some back color and check this style bit */
4201 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4203 ret
= SendMessage(hwnd
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
4204 ok(!(ret
& LVS_EX_TRANSPARENTBKGND
), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4206 /* now test what this style actually does */
4207 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4208 LVS_EX_TRANSPARENTBKGND
);
4210 hdc
= GetWindowDC(hwndparent
);
4212 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4213 SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
4214 ok_sequence(sequences
, PARENT_SEQ_INDEX
, lvs_ex_transparentbkgnd_seq
,
4215 "LVS_EX_TRANSPARENTBKGND parent", FALSE
);
4217 ReleaseDC(hwndparent
, hdc
);
4219 DestroyWindow(hwnd
);
4222 static void test_approximate_viewrect(void)
4229 static CHAR test
[] = "abracadabra, a very long item label";
4231 hwnd
= create_listview_control(LVS_ICON
);
4232 himl
= ImageList_Create(40, 40, 0, 4, 4);
4233 ok(himl
!= NULL
, "failed to create imagelist\n");
4234 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4235 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4236 ret
= ImageList_Add(himl
, hbmp
, 0);
4238 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4241 itema
.mask
= LVIF_IMAGE
;
4245 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
4248 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(75, 75));
4252 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4256 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4257 ok(MAKELONG(77,827)==ret
,"Incorrect Approximate rect\n");
4259 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(50, 50));
4260 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4261 ok(MAKELONG(102,302)==ret
,"Incorrect Approximate rect\n");
4263 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4264 ok(MAKELONG(52,52)==ret
,"Incorrect Approximate rect\n");
4266 itema
.pszText
= test
;
4267 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
4269 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4270 ok(MAKELONG(52,52)==ret
,"Incorrect Approximate rect\n");
4272 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 0, MAKELPARAM(100,100));
4273 ok(MAKELONG(52,2)==ret
,"Incorrect Approximate rect\n");
4274 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 1, MAKELPARAM(100,100));
4275 ok(MAKELONG(52,52)==ret
,"Incorrect Approximate rect\n");
4276 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 2, MAKELPARAM(100,100));
4277 ok(MAKELONG(102,52)==ret
,"Incorrect Approximate rect\n");
4278 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 3, MAKELPARAM(100,100));
4279 ok(MAKELONG(102,102)==ret
,"Incorrect Approximate rect\n");
4280 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 4, MAKELPARAM(100,100));
4281 ok(MAKELONG(102,102)==ret
,"Incorrect Approximate rect\n");
4282 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 5, MAKELPARAM(100,100));
4283 ok(MAKELONG(102,152)==ret
,"Incorrect Approximate rect\n");
4284 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 6, MAKELPARAM(100,100));
4285 ok(MAKELONG(102,152)==ret
,"Incorrect Approximate rect\n");
4286 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 7, MAKELPARAM(160,100));
4287 ok(MAKELONG(152,152)==ret
,"Incorrect Approximate rect\n");
4289 DestroyWindow(hwnd
);
4292 static void test_finditem(void)
4299 hwnd
= create_listview_control(LVS_REPORT
);
4300 insert_item(hwnd
, 0);
4302 memset(&fi
, 0, sizeof(fi
));
4304 /* full string search, inserted text was "foo" */
4306 fi
.flags
= LVFI_STRING
;
4308 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4310 /* partial string search, inserted text was "foo" */
4312 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4314 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4316 /* partial string search, part after start char */
4318 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4320 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4323 /* try with LVFI_SUBSTRING */
4325 fi
.flags
= LVFI_SUBSTRING
;
4327 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4330 win_skip("LVFI_SUBSTRING not supported\n");
4331 DestroyWindow(hwnd
);
4336 fi
.flags
= LVFI_SUBSTRING
;
4338 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4341 fi
.flags
= LVFI_SUBSTRING
;
4343 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4347 fi
.flags
= LVFI_SUBSTRING
| LVFI_STRING
;
4349 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4352 DestroyWindow(hwnd
);
4355 static void test_LVS_EX_HEADERINALLVIEWS(void)
4360 hwnd
= create_listview_control(LVS_ICON
);
4362 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4363 LVS_EX_HEADERINALLVIEWS
);
4365 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4366 if (!IsWindow(header
))
4368 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4369 DestroyWindow(hwnd
);
4373 /* LVS_NOCOLUMNHEADER works as before */
4374 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4375 SetWindowLongW(hwnd
, GWL_STYLE
, style
| LVS_NOCOLUMNHEADER
);
4376 style
= GetWindowLongA(header
, GWL_STYLE
);
4377 ok(style
& HDS_HIDDEN
, "Expected HDS_HIDDEN\n");
4378 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4379 SetWindowLongW(hwnd
, GWL_STYLE
, style
& ~LVS_NOCOLUMNHEADER
);
4380 style
= GetWindowLongA(header
, GWL_STYLE
);
4381 ok(!(style
& HDS_HIDDEN
), "Expected HDS_HIDDEN to be unset\n");
4383 /* try to remove style */
4384 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
, 0);
4385 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4386 ok(IsWindow(header
), "Expected header to be created\n");
4387 style
= GetWindowLongA(header
, GWL_STYLE
);
4388 ok(!(style
& HDS_HIDDEN
), "HDS_HIDDEN not expected\n");
4390 DestroyWindow(hwnd
);
4392 /* check other styles */
4393 hwnd
= create_listview_control(LVS_LIST
);
4394 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4395 LVS_EX_HEADERINALLVIEWS
);
4396 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4397 ok(IsWindow(header
), "Expected header to be created\n");
4398 DestroyWindow(hwnd
);
4400 hwnd
= create_listview_control(LVS_SMALLICON
);
4401 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4402 LVS_EX_HEADERINALLVIEWS
);
4403 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4404 ok(IsWindow(header
), "Expected header to be created\n");
4405 DestroyWindow(hwnd
);
4407 hwnd
= create_listview_control(LVS_REPORT
);
4408 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4409 LVS_EX_HEADERINALLVIEWS
);
4410 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4411 ok(IsWindow(header
), "Expected header to be created\n");
4412 DestroyWindow(hwnd
);
4415 static void test_hover(void)
4420 hwnd
= create_listview_control(LVS_ICON
);
4422 /* test WM_MOUSEHOVER forwarding */
4423 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4424 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
4426 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER allow test", TRUE
);
4427 g_block_hover
= TRUE
;
4428 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4429 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
4431 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER block test", TRUE
);
4432 g_block_hover
= FALSE
;
4434 r
= SendMessage(hwnd
, LVM_SETHOVERTIME
, 0, 500);
4435 expect(HOVER_DEFAULT
, r
);
4436 r
= SendMessage(hwnd
, LVM_GETHOVERTIME
, 0, 0);
4439 DestroyWindow(hwnd
);
4442 static void test_destroynotify(void)
4446 hwnd
= create_listview_control(LVS_REPORT
);
4447 ok(hwnd
!= NULL
, "failed to create listview window\n");
4449 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4450 DestroyWindow(hwnd
);
4451 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_destroy
, "check destroy order", FALSE
);
4454 static void test_header_notification(void)
4462 list
= create_listview_control(LVS_REPORT
);
4463 ok(list
!= 0, "failed to create listview window\n");
4465 memset(&col
, 0, sizeof(col
));
4466 col
.mask
= LVCF_WIDTH
;
4468 ret
= SendMessage(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4469 ok(!ret
, "expected 0, got %ld\n", ret
);
4471 header
= subclass_header(list
);
4473 ret
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
4474 ok(ret
== 1, "expected header item count 1, got %ld\n", ret
);
4476 memset(&item
, 0, sizeof(item
));
4477 item
.mask
= HDI_WIDTH
;
4478 ret
= SendMessage(header
, HDM_GETITEMA
, 0, (LPARAM
)&item
);
4479 ok(ret
, "HDM_GETITEM failed\n");
4480 ok(item
.cxy
== 100, "expected 100, got %d\n", item
.cxy
);
4482 nmh
.hdr
.hwndFrom
= header
;
4483 nmh
.hdr
.idFrom
= GetWindowLongPtr(header
, GWLP_ID
);
4484 nmh
.hdr
.code
= HDN_ITEMCHANGEDA
;
4487 item
.mask
= HDI_WIDTH
;
4490 ret
= SendMessage(list
, WM_NOTIFY
, 0, (LPARAM
)&nmh
);
4491 ok(!ret
, "WM_NOTIFY/HDN_ITEMCHANGED failed\n");
4493 DestroyWindow(list
);
4496 static void test_createdragimage(void)
4502 list
= create_listview_control(LVS_ICON
);
4503 ok(list
!= 0, "failed to create listview window\n");
4505 insert_item(list
, 0);
4508 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, 0);
4509 ok(himl
== NULL
, "got %p\n", himl
);
4511 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, (LPARAM
)&pt
);
4512 ok(himl
!= NULL
, "got %p\n", himl
);
4513 ImageList_Destroy(himl
);
4515 DestroyWindow(list
);
4518 START_TEST(listview
)
4521 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
4523 ULONG_PTR ctx_cookie
;
4527 hComctl32
= GetModuleHandleA("comctl32.dll");
4528 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
4529 if (pInitCommonControlsEx
)
4531 INITCOMMONCONTROLSEX iccex
;
4532 iccex
.dwSize
= sizeof(iccex
);
4533 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
4534 pInitCommonControlsEx(&iccex
);
4537 InitCommonControls();
4539 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
4541 hwndparent
= create_parent_window(FALSE
);
4542 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4544 g_is_below_5
= is_below_comctl_5();
4546 test_header_notification();
4553 test_icon_spacing();
4556 test_item_position();
4561 test_subitem_rect();
4565 test_nosortheader();
4569 test_getitemposition();
4570 test_columnscreation();
4572 test_notifyformat();
4574 test_getitemspacing();
4575 test_getcolumnwidth();
4576 test_approximate_viewrect();
4579 test_destroynotify();
4580 test_createdragimage();
4582 if (!load_v6_module(&ctx_cookie
, &hCtx
))
4584 DestroyWindow(hwndparent
);
4588 /* this is a XP SP3 failure workaround */
4589 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
4590 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
,
4592 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
4593 if (!IsWindow(hwnd
))
4595 win_skip("FIXME: failed to create ListView window.\n");
4596 unload_v6_module(ctx_cookie
, hCtx
);
4597 DestroyWindow(hwndparent
);
4601 DestroyWindow(hwnd
);
4603 /* comctl32 version 6 tests start here */
4604 test_get_set_view();
4605 test_canceleditlabel();
4607 test_scrollnotify();
4608 test_LVS_EX_TRANSPARENTBKGND();
4609 test_LVS_EX_HEADERINALLVIEWS();
4611 unload_v6_module(ctx_cookie
, hCtx
);
4613 DestroyWindow(hwndparent
);