4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
30 #define PARENT_SEQ_INDEX 0
31 #define PARENT_FULL_SEQ_INDEX 1
32 #define LISTVIEW_SEQ_INDEX 2
33 #define EDITBOX_SEQ_INDEX 3
34 #define NUM_MSG_SEQUENCES 4
39 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
40 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
41 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
43 static const WCHAR testparentclassW
[] =
44 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
46 HWND hwndparent
, hwndparentW
;
47 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
49 /* dumps LVN_ITEMCHANGED message data */
50 static BOOL g_dump_itemchanged
;
51 /* format reported to control:
52 -1 falls to defproc, anything else returned */
54 /* indicates we're running < 5.80 version */
57 static HWND
subclass_editbox(HWND hwndListview
);
59 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
61 static const struct message create_ownerdrawfixed_parent_seq
[] = {
62 { WM_NOTIFYFORMAT
, sent
},
63 { WM_QUERYUISTATE
, sent
|optional
}, /* Win2K and higher */
64 { WM_MEASUREITEM
, sent
},
65 { WM_PARENTNOTIFY
, sent
},
69 static const struct message redraw_listview_seq
[] = {
70 { WM_PAINT
, sent
|id
, 0, 0, LISTVIEW_ID
},
71 { WM_PAINT
, sent
|id
, 0, 0, HEADER_ID
},
72 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
73 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, HEADER_ID
},
74 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
75 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
76 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, LISTVIEW_ID
},
80 static const struct message listview_icon_spacing_seq
[] = {
81 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(20, 30) },
82 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(25, 35) },
83 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(-1, -1) },
87 static const struct message listview_color_seq
[] = {
88 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
89 { LVM_GETBKCOLOR
, sent
},
90 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
91 { LVM_GETTEXTCOLOR
, sent
},
92 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
93 { LVM_GETTEXTBKCOLOR
, sent
},
95 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
96 { LVM_GETBKCOLOR
, sent
},
97 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
98 { LVM_GETTEXTCOLOR
, sent
},
99 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
100 { LVM_GETTEXTBKCOLOR
, sent
},
102 { LVM_SETBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
103 { LVM_GETBKCOLOR
, sent
},
104 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, CLR_NONE
},
105 { LVM_GETTEXTCOLOR
, sent
},
106 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
107 { LVM_GETTEXTBKCOLOR
, sent
},
109 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
110 { LVM_GETBKCOLOR
, sent
},
111 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
112 { LVM_GETTEXTCOLOR
, sent
},
113 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
114 { LVM_GETTEXTBKCOLOR
, sent
},
118 static const struct message listview_item_count_seq
[] = {
119 { LVM_GETITEMCOUNT
, sent
},
120 { LVM_INSERTITEM
, sent
},
121 { LVM_INSERTITEM
, sent
},
122 { LVM_INSERTITEM
, sent
},
123 { LVM_GETITEMCOUNT
, sent
},
124 { LVM_DELETEITEM
, sent
|wparam
, 2 },
125 { WM_NCPAINT
, sent
|optional
},
126 { WM_ERASEBKGND
, sent
|optional
},
127 { LVM_GETITEMCOUNT
, sent
},
128 { LVM_DELETEALLITEMS
, sent
},
129 { LVM_GETITEMCOUNT
, sent
},
130 { LVM_INSERTITEM
, sent
},
131 { LVM_INSERTITEM
, sent
},
132 { LVM_GETITEMCOUNT
, sent
},
133 { LVM_INSERTITEM
, sent
},
134 { LVM_GETITEMCOUNT
, sent
},
138 static const struct message listview_itempos_seq
[] = {
139 { LVM_INSERTITEM
, sent
},
140 { LVM_INSERTITEM
, sent
},
141 { LVM_INSERTITEM
, sent
},
142 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 1, MAKELPARAM(10,5) },
143 { WM_NCPAINT
, sent
|optional
},
144 { WM_ERASEBKGND
, sent
|optional
},
145 { LVM_GETITEMPOSITION
, sent
|wparam
, 1 },
146 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 2, MAKELPARAM(0,0) },
147 { LVM_GETITEMPOSITION
, sent
|wparam
, 2 },
148 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 0, MAKELPARAM(20,20) },
149 { LVM_GETITEMPOSITION
, sent
|wparam
, 0 },
153 static const struct message listview_ownerdata_switchto_seq
[] = {
154 { WM_STYLECHANGING
, sent
},
155 { WM_STYLECHANGED
, sent
},
159 static const struct message listview_getorderarray_seq
[] = {
160 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
161 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
165 static const struct message empty_seq
[] = {
169 static const struct message forward_erasebkgnd_parent_seq
[] = {
170 { WM_ERASEBKGND
, sent
},
174 static const struct message ownderdata_select_focus_parent_seq
[] = {
175 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
176 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
177 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
}, /* version 4.7x */
181 static const struct message ownerdata_setstate_all_parent_seq
[] = {
182 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
186 static const struct message ownerdata_defocus_all_parent_seq
[] = {
187 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
188 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
189 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
},
190 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
194 static const struct message ownerdata_deselect_all_parent_seq
[] = {
195 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ODCACHEHINT
},
196 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
200 static const struct message select_all_parent_seq
[] = {
201 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
202 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
204 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
205 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
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
},
218 static const struct message textcallback_set_again_parent_seq
[] = {
219 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
220 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
224 static const struct message single_getdispinfo_parent_seq
[] = {
225 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
229 static const struct message getitemposition_seq1
[] = {
230 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
234 static const struct message getitemposition_seq2
[] = {
235 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
236 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
240 static const struct message editbox_create_pos
[] = {
241 /* sequence sent after LVN_BEGINLABELEDIT */
242 /* next two are 4.7x specific */
243 { WM_WINDOWPOSCHANGING
, sent
},
244 { WM_WINDOWPOSCHANGED
, sent
|optional
},
246 { WM_WINDOWPOSCHANGING
, sent
|optional
},
247 { WM_NCCALCSIZE
, sent
},
248 { WM_WINDOWPOSCHANGED
, sent
},
249 { WM_MOVE
, sent
|defwinproc
},
250 { WM_SIZE
, sent
|defwinproc
},
251 /* the rest is todo, skipped in 4.7x */
252 { WM_WINDOWPOSCHANGING
, sent
|optional
},
253 { WM_WINDOWPOSCHANGED
, sent
|optional
},
257 static const struct message scroll_parent_seq
[] = {
258 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_BEGINSCROLL
},
259 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDSCROLL
},
263 static const struct message setredraw_seq
[] = {
264 { WM_SETREDRAW
, sent
|id
|wparam
, FALSE
, 0, LISTVIEW_ID
},
273 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
275 static LONG defwndproc_counter
= 0;
279 msg
.message
= message
;
280 msg
.flags
= sent
|wparam
|lparam
;
281 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
284 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
286 /* log system messages, except for painting */
287 if (message
< WM_USER
&&
288 message
!= WM_PAINT
&&
289 message
!= WM_ERASEBKGND
&&
290 message
!= WM_NCPAINT
&&
291 message
!= WM_NCHITTEST
&&
292 message
!= WM_GETTEXT
&&
293 message
!= WM_GETICON
&&
294 message
!= WM_DEVICECHANGE
)
296 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
298 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
300 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
306 switch (((NMHDR
*)lParam
)->code
)
308 case LVN_BEGINLABELEDIT
:
309 /* subclass edit box */
311 subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
315 case LVN_ENDLABELEDIT
:
316 /* always accept new item text */
318 case LVN_BEGINSCROLL
:
321 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
323 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
324 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
327 case LVN_ITEMCHANGED
:
328 if (g_dump_itemchanged
)
330 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
331 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
332 nmlv
->iItem
, nmlv
->uNewState
, nmlv
->uOldState
, nmlv
->uChanged
);
338 case WM_NOTIFYFORMAT
:
340 /* force to return format */
341 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
346 defwndproc_counter
++;
347 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
348 defwndproc_counter
--;
353 static BOOL
register_parent_wnd_class(BOOL Unicode
)
361 clsW
.lpfnWndProc
= parent_wnd_proc
;
364 clsW
.hInstance
= GetModuleHandleW(NULL
);
366 clsW
.hCursor
= LoadCursorA(0, IDC_ARROW
);
367 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
368 clsW
.lpszMenuName
= NULL
;
369 clsW
.lpszClassName
= testparentclassW
;
374 clsA
.lpfnWndProc
= parent_wnd_proc
;
377 clsA
.hInstance
= GetModuleHandleA(NULL
);
379 clsA
.hCursor
= LoadCursorA(0, IDC_ARROW
);
380 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
381 clsA
.lpszMenuName
= NULL
;
382 clsA
.lpszClassName
= "Listview test parent class";
385 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
388 static HWND
create_parent_window(BOOL Unicode
)
390 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W'};
393 if (!register_parent_wnd_class(Unicode
))
400 hwnd
= CreateWindowExW(0, testparentclassW
, nameW
,
401 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
402 WS_MAXIMIZEBOX
| WS_VISIBLE
,
404 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
406 hwnd
= CreateWindowExA(0, "Listview test parent class",
407 "Listview test parent window",
408 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
409 WS_MAXIMIZEBOX
| WS_VISIBLE
,
411 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
412 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
416 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
418 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
419 static LONG defwndproc_counter
= 0;
423 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
425 /* some debug output for style changing */
426 if ((message
== WM_STYLECHANGING
||
427 message
== WM_STYLECHANGED
) && lParam
)
429 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
430 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
433 msg
.message
= message
;
434 msg
.flags
= sent
|wparam
|lparam
;
435 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
438 msg
.id
= LISTVIEW_ID
;
439 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
441 defwndproc_counter
++;
442 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
443 defwndproc_counter
--;
447 static HWND
create_listview_control(DWORD style
)
449 struct subclass_info
*info
;
453 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
457 GetClientRect(hwndparent
, &rect
);
458 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
459 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
| style
,
460 0, 0, rect
.right
, rect
.bottom
,
461 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
462 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
466 HeapFree(GetProcessHeap(), 0, info
);
470 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
471 (LONG_PTR
)listview_subclass_proc
);
472 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
477 /* unicode listview window with specified parent */
478 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
480 struct subclass_info
*info
;
483 static const WCHAR nameW
[] = {'f','o','o',0};
485 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
489 GetClientRect(parent
, &rect
);
490 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
491 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
| style
,
492 0, 0, rect
.right
, rect
.bottom
,
493 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
494 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
498 HeapFree(GetProcessHeap(), 0, info
);
502 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
503 (LONG_PTR
)listview_subclass_proc
);
504 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
509 static HWND
create_custom_listview_control(DWORD style
)
511 struct subclass_info
*info
;
515 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
519 GetClientRect(hwndparent
, &rect
);
520 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
521 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
522 0, 0, rect
.right
, rect
.bottom
,
523 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
524 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
528 HeapFree(GetProcessHeap(), 0, info
);
532 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
533 (LONG_PTR
)listview_subclass_proc
);
534 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
539 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
541 struct subclass_info
*info
= (struct subclass_info
*)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(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
558 defwndproc_counter
--;
562 static HWND
subclass_header(HWND hwndListview
)
564 struct subclass_info
*info
;
567 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
571 hwnd
= ListView_GetHeader(hwndListview
);
572 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
573 (LONG_PTR
)header_subclass_proc
);
574 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
579 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
581 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
582 static LONG defwndproc_counter
= 0;
586 msg
.message
= message
;
587 msg
.flags
= sent
|wparam
|lparam
;
588 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
592 /* all we need is sizing */
593 if (message
== WM_WINDOWPOSCHANGING
||
594 message
== WM_NCCALCSIZE
||
595 message
== WM_WINDOWPOSCHANGED
||
596 message
== WM_MOVE
||
599 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
602 defwndproc_counter
++;
603 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
604 defwndproc_counter
--;
608 static HWND
subclass_editbox(HWND hwndListview
)
610 struct subclass_info
*info
;
613 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
617 hwnd
= (HWND
)SendMessage(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
618 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
619 (LONG_PTR
)editbox_subclass_proc
);
620 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
625 /* Performs a single LVM_HITTEST test */
626 static void test_lvm_hittest(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
, UINT broken_flags
,
627 BOOL todo_item
, BOOL todo_flags
, int line
)
636 trace("hittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
637 ret
= SendMessage(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
643 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
644 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
645 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
650 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
651 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
652 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
658 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
660 else if (broken_flags
)
661 ok_(__FILE__
, line
)(lpht
.flags
== flags
|| broken(lpht
.flags
== broken_flags
),
662 "Expected flags %x, got %x\n", flags
, lpht
.flags
);
664 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
667 /* Performs a single LVM_SUBITEMHITTEST test */
668 static void test_lvm_subitemhittest(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
669 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
677 trace("subhittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
678 ret
= SendMessage(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
684 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
685 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
690 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
691 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
697 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
700 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
705 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
708 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
711 static void test_images(void)
719 static CHAR hello
[] = "hello";
721 himl
= ImageList_Create(40, 40, 0, 4, 4);
722 ok(himl
!= NULL
, "failed to create imagelist\n");
724 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
725 ok(hbmp
!= NULL
, "failed to create bitmap\n");
727 r
= ImageList_Add(himl
, hbmp
, 0);
728 ok(r
== 0, "should be zero\n");
730 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
731 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
732 ok(hwnd
!= NULL
, "failed to create listview window\n");
734 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
735 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
737 ok(r
== 0, "should return zero\n");
739 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
740 ok(r
== 0, "should return zero\n");
742 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
743 /* returns dimensions */
745 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
746 ok(r
== 0, "should be zero items\n");
748 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
753 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
754 ok(r
== -1, "should fail\n");
757 item
.pszText
= hello
;
758 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
759 ok(r
== 0, "should not fail\n");
761 memset(&r1
, 0, sizeof r1
);
763 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
765 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
766 ok(r
== TRUE
, "should not fail\n");
769 item
.pszText
= hello
;
770 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
771 ok(r
== 0, "should not fail\n");
773 memset(&r2
, 0, sizeof r2
);
775 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
777 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
782 static void test_checkboxes(void)
787 static CHAR text
[] = "Text",
791 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
792 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
793 ok(hwnd
!= NULL
, "failed to create listview window\n");
795 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
796 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
797 item
.stateMask
= 0xffff;
802 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
803 ok(r
== 0, "ret %d\n", r
);
806 item
.mask
= LVIF_STATE
;
807 item
.stateMask
= 0xffff;
808 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
809 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
811 /* Don't set LVIF_STATE */
812 item
.mask
= LVIF_TEXT
;
813 item
.stateMask
= 0xffff;
818 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
819 ok(r
== 1, "ret %d\n", r
);
822 item
.mask
= LVIF_STATE
;
823 item
.stateMask
= 0xffff;
824 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
825 ok(item
.state
== 0, "state %x\n", item
.state
);
827 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
828 ok(r
== 0, "should return zero\n");
830 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
832 item
.mask
= LVIF_STATE
;
833 item
.stateMask
= 0xffff;
834 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
835 ok(item
.state
== 0x1ccc, "state %x\n", item
.state
);
837 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
839 item
.mask
= LVIF_TEXT
;
841 item
.pszText
= text2
;
842 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
843 ok(r
== 2, "ret %d\n", r
);
846 item
.mask
= LVIF_STATE
;
847 item
.stateMask
= 0xffff;
848 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
849 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
851 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
853 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
854 item
.stateMask
= 0xffff;
856 item
.pszText
= text3
;
857 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
858 ok(r
== 3, "ret %d\n", r
);
861 item
.mask
= LVIF_STATE
;
862 item
.stateMask
= 0xffff;
863 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
864 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
866 /* Set an item's state to checked */
868 item
.mask
= LVIF_STATE
;
869 item
.stateMask
= 0xf000;
871 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
874 item
.mask
= LVIF_STATE
;
875 item
.stateMask
= 0xffff;
876 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
877 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
879 /* Check that only the bits we asked for are returned,
880 * and that all the others are set to zero
883 item
.mask
= LVIF_STATE
;
884 item
.stateMask
= 0xf000;
886 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
887 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
889 /* Set the style again and check that doesn't change an item's state */
890 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
891 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
894 item
.mask
= LVIF_STATE
;
895 item
.stateMask
= 0xffff;
896 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
897 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
899 /* Unsetting the checkbox extended style doesn't change an item's state */
900 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
901 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
904 item
.mask
= LVIF_STATE
;
905 item
.stateMask
= 0xffff;
906 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
907 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
909 /* Now setting the style again will change an item's state */
910 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
911 ok(r
== 0, "ret %x\n", r
);
914 item
.mask
= LVIF_STATE
;
915 item
.stateMask
= 0xffff;
916 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
917 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
919 /* Toggle checkbox tests (bug 9934) */
920 memset (&item
, 0xcc, sizeof(item
));
921 item
.mask
= LVIF_STATE
;
924 item
.state
= LVIS_FOCUSED
;
925 item
.stateMask
= LVIS_FOCUSED
;
926 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
930 item
.mask
= LVIF_STATE
;
931 item
.stateMask
= 0xffff;
932 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
933 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
935 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
937 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
941 item
.mask
= LVIF_STATE
;
942 item
.stateMask
= 0xffff;
943 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
944 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
946 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
948 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
952 item
.mask
= LVIF_STATE
;
953 item
.stateMask
= 0xffff;
954 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
955 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
960 static void insert_column(HWND hwnd
, int idx
)
965 memset(&column
, 0xcc, sizeof(column
));
966 column
.mask
= LVCF_SUBITEM
;
967 column
.iSubItem
= idx
;
969 rc
= ListView_InsertColumn(hwnd
, idx
, &column
);
973 static void insert_item(HWND hwnd
, int idx
)
975 static CHAR text
[] = "foo";
980 memset(&item
, 0xcc, sizeof (item
));
981 item
.mask
= LVIF_TEXT
;
986 rc
= ListView_InsertItem(hwnd
, &item
);
990 static void test_items(void)
992 const LPARAM lparamTest
= 0x42;
996 static CHAR text
[] = "Text";
998 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
999 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1000 ok(hwnd
!= NULL
, "failed to create listview window\n");
1003 * Test setting/getting item params
1006 /* Set up two columns */
1007 insert_column(hwnd
, 0);
1008 insert_column(hwnd
, 1);
1010 /* LVIS_SELECTED with zero stateMask */
1012 memset (&item
, 0, sizeof (item
));
1013 item
.mask
= LVIF_STATE
;
1014 item
.state
= LVIS_SELECTED
;
1018 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1019 ok(r
== 0, "ret %d\n", r
);
1021 memset (&item
, 0xcc, sizeof (item
));
1022 item
.mask
= LVIF_STATE
;
1023 item
.stateMask
= LVIS_SELECTED
;
1027 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1028 ok(r
!= 0, "ret %d\n", r
);
1029 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1030 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1032 /* LVIS_SELECTED with zero stateMask */
1034 memset (&item
, 0, sizeof (item
));
1035 item
.mask
= LVIF_STATE
;
1036 item
.state
= LVIS_FOCUSED
;
1040 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1041 ok(r
== 0, "ret %d\n", r
);
1043 memset (&item
, 0xcc, sizeof (item
));
1044 item
.mask
= LVIF_STATE
;
1045 item
.stateMask
= LVIS_FOCUSED
;
1049 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1050 ok(r
!= 0, "ret %d\n", r
);
1051 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1052 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1054 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1056 memset (&item
, 0, sizeof (item
));
1057 item
.mask
= LVIF_STATE
;
1058 item
.state
= LVIS_CUT
;
1059 item
.stateMask
= LVIS_FOCUSED
;
1062 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1063 ok(r
== 0, "ret %d\n", r
);
1065 memset (&item
, 0xcc, sizeof (item
));
1066 item
.mask
= LVIF_STATE
;
1067 item
.stateMask
= LVIS_CUT
;
1071 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1072 ok(r
!= 0, "ret %d\n", r
);
1073 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1074 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1076 /* Insert an item with just a param */
1077 memset (&item
, 0xcc, sizeof (item
));
1078 item
.mask
= LVIF_PARAM
;
1081 item
.lParam
= lparamTest
;
1082 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1083 ok(r
== 0, "ret %d\n", r
);
1085 /* Test getting of the param */
1086 memset (&item
, 0xcc, sizeof (item
));
1087 item
.mask
= LVIF_PARAM
;
1090 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1091 ok(r
!= 0, "ret %d\n", r
);
1092 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1094 /* Set up a subitem */
1095 memset (&item
, 0xcc, sizeof (item
));
1096 item
.mask
= LVIF_TEXT
;
1099 item
.pszText
= text
;
1100 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1101 ok(r
!= 0, "ret %d\n", r
);
1103 /* Query param from subitem: returns main item param */
1104 memset (&item
, 0xcc, sizeof (item
));
1105 item
.mask
= LVIF_PARAM
;
1108 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1109 ok(r
!= 0, "ret %d\n", r
);
1110 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1112 /* Set up param on first subitem: no effect */
1113 memset (&item
, 0xcc, sizeof (item
));
1114 item
.mask
= LVIF_PARAM
;
1117 item
.lParam
= lparamTest
+1;
1118 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1119 ok(r
== 0, "ret %d\n", r
);
1121 /* Query param from subitem again: should still return main item param */
1122 memset (&item
, 0xcc, sizeof (item
));
1123 item
.mask
= LVIF_PARAM
;
1126 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1127 ok(r
!= 0, "ret %d\n", r
);
1128 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1130 /**** Some tests of state highlighting ****/
1131 memset (&item
, 0xcc, sizeof (item
));
1132 item
.mask
= LVIF_STATE
;
1135 item
.state
= LVIS_SELECTED
;
1136 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1137 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1138 ok(r
!= 0, "ret %d\n", r
);
1140 item
.state
= LVIS_DROPHILITED
;
1141 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1142 ok(r
!= 0, "ret %d\n", r
);
1144 memset (&item
, 0xcc, sizeof (item
));
1145 item
.mask
= LVIF_STATE
;
1148 item
.stateMask
= -1;
1149 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1150 ok(r
!= 0, "ret %d\n", r
);
1151 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1153 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1154 ok(r
!= 0, "ret %d\n", r
);
1155 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1157 /* some notnull but meaningless masks */
1158 memset (&item
, 0, sizeof(item
));
1159 item
.mask
= LVIF_NORECOMPUTE
;
1162 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1163 ok(r
!= 0, "ret %d\n", r
);
1164 memset (&item
, 0, sizeof(item
));
1165 item
.mask
= LVIF_DI_SETITEM
;
1168 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1169 ok(r
!= 0, "ret %d\n", r
);
1171 /* set text to callback value already having it */
1172 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1174 memset (&item
, 0, sizeof (item
));
1175 item
.mask
= LVIF_TEXT
;
1176 item
.pszText
= LPSTR_TEXTCALLBACK
;
1178 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1179 ok(r
== 0, "ret %d\n", r
);
1180 memset (&item
, 0, sizeof (item
));
1182 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1184 item
.pszText
= LPSTR_TEXTCALLBACK
;
1185 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0 , (LPARAM
) &item
);
1188 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1189 "check callback text comparison rule", FALSE
);
1191 DestroyWindow(hwnd
);
1194 static void test_columns(void)
1196 HWND hwnd
, hwndheader
;
1201 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1202 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1203 ok(hwnd
!= NULL
, "failed to create listview window\n");
1205 /* Add a column with no mask */
1206 memset(&column
, 0xcc, sizeof(column
));
1208 rc
= ListView_InsertColumn(hwnd
, 0, &column
);
1209 ok(rc
==0, "Inserting column with no mask failed with %d\n", rc
);
1211 /* Check its width */
1212 rc
= ListView_GetColumnWidth(hwnd
, 0);
1214 broken(rc
==0), /* win9x */
1215 "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1217 DestroyWindow(hwnd
);
1219 /* LVM_GETCOLUMNORDERARRAY */
1220 hwnd
= create_listview_control(0);
1221 hwndheader
= subclass_header(hwnd
);
1223 memset(&column
, 0, sizeof(column
));
1224 column
.mask
= LVCF_WIDTH
;
1226 rc
= ListView_InsertColumn(hwnd
, 0, &column
);
1227 ok(rc
== 0, "Inserting column failed with %d\n", rc
);
1230 rc
= ListView_InsertColumn(hwnd
, 1, &column
);
1231 ok(rc
== 1, "Inserting column failed with %d\n", rc
);
1233 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1235 rc
= SendMessage(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1236 ok(rc
!= 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1237 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1238 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1240 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1242 DestroyWindow(hwnd
);
1244 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1245 static WNDPROC listviewWndProc
;
1246 static HIMAGELIST test_create_imagelist
;
1248 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1252 if (uMsg
== WM_CREATE
)
1254 LPCREATESTRUCT lpcs
= (LPCREATESTRUCT
)lParam
;
1255 lpcs
->style
|= LVS_REPORT
;
1257 ret
= CallWindowProc(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1258 if (uMsg
== WM_CREATE
) SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1262 static void test_create(void)
1271 cls
.cbSize
= sizeof(WNDCLASSEX
);
1272 ok(GetClassInfoEx(GetModuleHandle(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1273 listviewWndProc
= cls
.lpfnWndProc
;
1274 cls
.lpfnWndProc
= create_test_wndproc
;
1275 cls
.lpszClassName
= "MyListView32";
1276 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
1278 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1279 hList
= CreateWindow("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1280 ok((HIMAGELIST
)SendMessage(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1281 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1282 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1283 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1284 DestroyWindow(hList
);
1286 /* header isn't created on LVS_ICON and LVS_LIST styles */
1287 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1288 GetModuleHandle(NULL
), 0);
1289 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1290 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1291 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1293 memset(&col
, 0, sizeof(LVCOLUMNA
));
1294 col
.mask
= LVCF_WIDTH
;
1296 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1297 ok(r
== 0, "Expected 0 column's inserted\n");
1298 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1299 ok(IsWindow(hHeader
), "Header should be created\n");
1300 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1301 DestroyWindow(hList
);
1303 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1304 GetModuleHandle(NULL
), 0);
1305 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1306 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1307 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1309 memset(&col
, 0, sizeof(LVCOLUMNA
));
1310 col
.mask
= LVCF_WIDTH
;
1312 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1313 ok(r
== 0, "Expected 0 column's inserted\n");
1314 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1315 ok(IsWindow(hHeader
), "Header should be created\n");
1316 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1317 DestroyWindow(hList
);
1319 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1320 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1321 GetModuleHandle(NULL
), 0);
1322 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLongPtr(hList
, GWL_STYLE
) | LVS_REPORT
);
1323 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1324 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1325 ok(IsWindow(hHeader
), "Header should be created\n");
1326 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLong(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1327 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1328 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1329 ok(IsWindow(hHeader
), "Header should be created\n");
1330 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1331 DestroyWindow(hList
);
1333 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1334 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1335 GetModuleHandle(NULL
), 0);
1336 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1337 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1338 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1339 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1340 ok(IsWindow(hHeader
), "Header should be created\n");
1341 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1342 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1343 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1344 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1345 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1346 ok(IsWindow(hHeader
), "Header should be created\n");
1347 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1348 DestroyWindow(hList
);
1350 /* LVS_REPORT without WS_VISIBLE */
1351 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1352 GetModuleHandle(NULL
), 0);
1353 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1354 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1355 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1357 memset(&col
, 0, sizeof(LVCOLUMNA
));
1358 col
.mask
= LVCF_WIDTH
;
1360 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1361 ok(r
== 0, "Expected 0 column's inserted\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 /* LVS_REPORT without WS_VISIBLE, try to show it */
1368 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1369 GetModuleHandle(NULL
), 0);
1370 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1371 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1372 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1373 ShowWindow(hList
, SW_SHOW
);
1374 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1375 ok(IsWindow(hHeader
), "Header should be created\n");
1376 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1377 DestroyWindow(hList
);
1379 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1380 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1381 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1382 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1383 ok(IsWindow(hHeader
), "Header should be created\n");
1384 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1385 /* HDS_DRAGDROP set by default */
1386 ok(GetWindowLongPtr(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1387 DestroyWindow(hList
);
1389 /* setting LVS_EX_HEADERDRAGDROP creates header */
1390 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1391 GetModuleHandle(NULL
), 0);
1392 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1393 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1394 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1395 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1396 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1397 ok(IsWindow(hHeader
) ||
1398 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1399 "Header should be created\n");
1400 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1401 DestroyWindow(hList
);
1403 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1404 hList
= create_custom_listview_control(0);
1405 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1406 r
= SendMessage(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1407 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1408 DestroyWindow(hList
);
1410 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1411 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1412 GetModuleHandle(NULL
), 0);
1413 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1414 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1416 rect
.left
= LVIR_BOUNDS
;
1418 rect
.right
= rect
.bottom
= -10;
1419 r
= SendMessage(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1420 ok(r
!= 0, "Expected not-null LRESULT\n");
1422 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1423 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1424 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1426 DestroyWindow(hList
);
1428 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1429 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1430 hList
= create_listview_control(LVS_OWNERDRAWFIXED
);
1431 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1432 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1433 DestroyWindow(hList
);
1436 static void test_redraw(void)
1438 HWND hwnd
, hwndheader
;
1443 hwnd
= create_listview_control(0);
1444 hwndheader
= subclass_header(hwnd
);
1446 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1448 trace("invalidate & update\n");
1449 InvalidateRect(hwnd
, NULL
, TRUE
);
1451 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1453 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1455 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1456 /* 1. Without backbuffer */
1457 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1460 hdc
= GetWindowDC(hwndparent
);
1462 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1463 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1464 ok(r
!= 0, "Expected not zero result\n");
1465 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1466 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1468 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1471 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1472 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1473 ok(r
!= 0, "Expected not zero result\n");
1474 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1475 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1477 /* 2. With backbuffer */
1478 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1479 LVS_EX_DOUBLEBUFFER
);
1480 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1483 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1484 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1485 ok(r
!= 0, "Expected not zero result\n");
1486 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1487 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1489 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1492 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1493 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1494 todo_wine
ok(r
!= 0, "Expected not zero result\n");
1495 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1496 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1498 ReleaseDC(hwndparent
, hdc
);
1500 DestroyWindow(hwnd
);
1503 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1505 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1507 if(msg
== WM_NOTIFY
) {
1508 NMHDR
*nmhdr
= (PVOID
)lp
;
1509 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1510 NMLVCUSTOMDRAW
*nmlvcd
= (PVOID
)nmhdr
;
1511 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd
->nmcd
.dwDrawStage
);
1512 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1514 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1515 return CDRF_NOTIFYITEMDRAW
;
1516 case CDDS_ITEMPREPAINT
:
1517 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1518 return CDRF_NOTIFYSUBITEMDRAW
;
1519 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1520 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1521 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1522 return CDRF_NOTIFYPOSTPAINT
;
1523 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1524 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1525 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1526 return CDRF_DODEFAULT
;
1528 return CDRF_DODEFAULT
;
1532 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1535 static void test_customdraw(void)
1540 hwnd
= create_listview_control(0);
1542 insert_column(hwnd
, 0);
1543 insert_column(hwnd
, 1);
1544 insert_item(hwnd
, 0);
1546 oldwndproc
= (WNDPROC
)SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
,
1547 (LONG_PTR
)cd_wndproc
);
1549 InvalidateRect(hwnd
, NULL
, TRUE
);
1552 SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1554 DestroyWindow(hwnd
);
1557 static void test_icon_spacing(void)
1559 /* LVM_SETICONSPACING */
1560 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1566 hwnd
= create_custom_listview_control(LVS_ICON
);
1567 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1569 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, (LPARAM
)NF_REQUERY
);
1570 expect(NFR_ANSI
, r
);
1572 /* reset the icon spacing to defaults */
1573 SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1575 /* now we can request what the defaults are */
1576 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1580 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1582 trace("test icon spacing\n");
1584 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1585 ok(r
== MAKELONG(w
, h
) ||
1586 broken(r
== MAKELONG(w
, w
)), /* win98 */
1587 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1589 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1590 expect(MAKELONG(20,30), r
);
1592 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1593 expect(MAKELONG(25,35), r
);
1595 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1597 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1598 DestroyWindow(hwnd
);
1601 static void test_color(void)
1603 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1610 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1612 hwnd
= create_listview_control(0);
1613 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1615 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1617 trace("test color seq\n");
1618 for (i
= 0; i
< 4; i
++)
1622 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1624 r
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, color
);
1627 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1629 r
= SendMessage(hwnd
, LVM_GETTEXTCOLOR
, 0, color
);
1632 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1634 r
= SendMessage(hwnd
, LVM_GETTEXTBKCOLOR
, 0, color
);
1638 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1640 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1641 DestroyWindow(hwnd
);
1644 static void test_item_count(void)
1646 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1659 static CHAR item0text
[] = "item0";
1660 static CHAR item1text
[] = "item1";
1661 static CHAR item2text
[] = "item2";
1663 hwnd
= create_listview_control(0);
1664 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1666 /* resize in dpiaware manner to fit all 3 items added */
1668 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1669 GetTextMetricsA(hdc
, &tm
);
1670 /* 2 extra pixels for bounds and header border */
1671 height
= tm
.tmHeight
+ 2;
1672 SelectObject(hdc
, hOldFont
);
1675 GetWindowRect(hwnd
, &rect
);
1676 /* 3 items + 1 header + 1 to be sure */
1677 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1679 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1681 trace("test item count\n");
1683 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1687 item0
.mask
= LVIF_TEXT
;
1690 item0
.pszText
= item0text
;
1691 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1694 /* [item0, item1] */
1695 item1
.mask
= LVIF_TEXT
;
1698 item1
.pszText
= item1text
;
1699 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1702 /* [item0, item1, item2] */
1703 item2
.mask
= LVIF_TEXT
;
1706 item2
.pszText
= item2text
;
1707 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1710 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1713 /* [item0, item1] */
1714 r
= SendMessage(hwnd
, LVM_DELETEITEM
, 2, 0);
1717 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1721 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1724 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1728 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1731 /* [item0, item1] */
1732 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1735 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1738 /* [item0, item1, item2] */
1739 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1742 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1745 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
1747 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1748 DestroyWindow(hwnd
);
1751 static void test_item_position(void)
1753 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1762 static CHAR item0text
[] = "item0";
1763 static CHAR item1text
[] = "item1";
1764 static CHAR item2text
[] = "item2";
1766 hwnd
= create_custom_listview_control(LVS_ICON
);
1767 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1769 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1771 trace("test item position\n");
1774 item0
.mask
= LVIF_TEXT
;
1777 item0
.pszText
= item0text
;
1778 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1781 /* [item0, item1] */
1782 item1
.mask
= LVIF_TEXT
;
1785 item1
.pszText
= item1text
;
1786 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1789 /* [item0, item1, item2] */
1790 item2
.mask
= LVIF_TEXT
;
1793 item2
.pszText
= item2text
;
1794 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1797 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
1799 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
1801 expect2(10, 5, position
.x
, position
.y
);
1803 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
1805 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
1807 expect2(0, 0, position
.x
, position
.y
);
1809 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
1811 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
1813 expect2(20, 20, position
.x
, position
.y
);
1815 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
1817 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1818 DestroyWindow(hwnd
);
1821 static void test_getorigin(void)
1829 position
.x
= position
.y
= 0;
1831 hwnd
= create_custom_listview_control(LVS_ICON
);
1832 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1833 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1834 trace("test get origin results\n");
1835 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1837 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1838 DestroyWindow(hwnd
);
1840 hwnd
= create_custom_listview_control(LVS_SMALLICON
);
1841 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1842 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1843 trace("test get origin results\n");
1844 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1846 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1847 DestroyWindow(hwnd
);
1849 hwnd
= create_custom_listview_control(LVS_LIST
);
1850 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1851 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1852 trace("test get origin results\n");
1853 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1855 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1856 DestroyWindow(hwnd
);
1858 hwnd
= create_custom_listview_control(LVS_REPORT
);
1859 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1860 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1861 trace("test get origin results\n");
1862 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1864 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1865 DestroyWindow(hwnd
);
1869 static void test_multiselect(void)
1871 typedef struct t_select_task
1882 int i
,j
,item_count
,selected_count
;
1883 static const int items
=5;
1889 static struct t_select_task task_list
[] = {
1890 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
1891 { "using VK_UP", -1, VK_UP
, -1, -1 },
1892 { "using VK_END", 0, VK_END
, 1, -1 },
1893 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
1897 hwnd
= create_listview_control(0);
1899 for (i
=0;i
<items
;i
++) {
1900 insert_item(hwnd
, 0);
1903 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1905 expect(items
,item_count
);
1908 task
= task_list
[i
];
1910 /* deselect all items */
1911 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1912 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1914 /* set initial position */
1915 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
1916 ListView_SetItemState(hwnd
,(task
.initPos
== -1 ? item_count
-1 : task
.initPos
),LVIS_SELECTED
,LVIS_SELECTED
);
1918 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1920 ok(selected_count
== 1, "There should be only one selected item at the beginning (is %d)\n",selected_count
);
1922 /* Set SHIFT key pressed */
1923 GetKeyboardState(kstate
);
1924 kstate
[VK_SHIFT
]=0x80;
1925 SetKeyboardState(kstate
);
1927 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
1928 r
= SendMessage(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
1930 r
= SendMessage(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
1934 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1936 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
);
1938 /* Set SHIFT key released */
1939 GetKeyboardState(kstate
);
1940 kstate
[VK_SHIFT
]=0x00;
1941 SetKeyboardState(kstate
);
1943 DestroyWindow(hwnd
);
1945 /* make multiple selection, then switch to LVS_SINGLESEL */
1946 hwnd
= create_listview_control(0);
1947 for (i
=0;i
<items
;i
++) {
1948 insert_item(hwnd
, 0);
1950 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1951 expect(items
,item_count
);
1953 /* try with NULL pointer */
1954 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)NULL
);
1957 /* select all, check notifications */
1958 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1960 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1962 item
.stateMask
= LVIS_SELECTED
;
1963 item
.state
= LVIS_SELECTED
;
1964 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
1967 ok_sequence(sequences
, PARENT_SEQ_INDEX
, select_all_parent_seq
,
1968 "select all notification", FALSE
);
1970 /* deselect all items */
1971 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1972 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1974 ListView_SetItemState(hwnd
, i
, LVIS_SELECTED
, LVIS_SELECTED
);
1977 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1979 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
1982 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
1983 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
1984 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
1985 /* check that style is accepted */
1986 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
1987 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
1990 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
1991 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
1993 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1995 SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
1998 /* select one more */
1999 ListView_SetItemState(hwnd
, 3, LVIS_SELECTED
, LVIS_SELECTED
);
2002 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2003 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2005 r
= ListView_GetItemState(hwnd
, 3, LVIS_SELECTED
);
2006 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2008 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2010 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2013 /* try to select all on LVS_SINGLESEL */
2014 memset(&item
, 0, sizeof(item
));
2015 item
.stateMask
= LVIS_SELECTED
;
2016 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2018 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2020 item
.stateMask
= LVIS_SELECTED
;
2021 item
.state
= LVIS_SELECTED
;
2022 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2025 r
= ListView_GetSelectedCount(hwnd
);
2027 r
= ListView_GetSelectionMark(hwnd
);
2030 /* try to deselect all on LVS_SINGLESEL */
2031 item
.stateMask
= LVIS_SELECTED
;
2032 item
.state
= LVIS_SELECTED
;
2033 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2036 item
.stateMask
= LVIS_SELECTED
;
2038 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2040 r
= ListView_GetSelectedCount(hwnd
);
2043 DestroyWindow(hwnd
);
2046 static void test_subitem_rect(void)
2053 /* test LVM_GETSUBITEMRECT for header */
2054 hwnd
= create_listview_control(0);
2055 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2056 /* add some columns */
2057 memset(&col
, 0, sizeof(LVCOLUMN
));
2058 col
.mask
= LVCF_WIDTH
;
2061 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2065 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2069 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2071 /* item = -1 means header, subitem index is 1 based */
2072 rect
.left
= LVIR_BOUNDS
;
2074 rect
.right
= rect
.bottom
= 0;
2075 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2078 rect
.left
= LVIR_BOUNDS
;
2080 rect
.right
= rect
.bottom
= 0;
2081 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2083 ok(r
!= 0, "Expected not-null LRESULT\n");
2084 expect(100, rect
.left
);
2085 expect(250, rect
.right
);
2087 expect(3, rect
.top
);
2089 rect
.left
= LVIR_BOUNDS
;
2091 rect
.right
= rect
.bottom
= 0;
2092 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2094 ok(r
!= 0, "Expected not-null LRESULT\n");
2095 expect(250, rect
.left
);
2096 expect(450, rect
.right
);
2098 expect(3, rect
.top
);
2100 /* item LVS_REPORT padding isn't applied to subitems */
2101 insert_item(hwnd
, 0);
2103 rect
.left
= LVIR_BOUNDS
;
2105 rect
.right
= rect
.bottom
= 0;
2106 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2107 ok(r
!= 0, "Expected not-null LRESULT\n");
2108 expect(100, rect
.left
);
2109 expect(250, rect
.right
);
2111 rect
.left
= LVIR_ICON
;
2113 rect
.right
= rect
.bottom
= 0;
2114 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2115 ok(r
!= 0, "Expected not-null LRESULT\n");
2116 /* no icon attached - zero width rectangle, with no left padding */
2117 expect(100, rect
.left
);
2118 expect(100, rect
.right
);
2120 rect
.left
= LVIR_LABEL
;
2122 rect
.right
= rect
.bottom
= 0;
2123 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2124 ok(r
!= 0, "Expected not-null LRESULT\n");
2125 /* same as full LVIR_BOUNDS */
2126 expect(100, rect
.left
);
2127 expect(250, rect
.right
);
2129 DestroyWindow(hwnd
);
2131 /* try it for non LVS_REPORT style */
2132 hwnd
= CreateWindow("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2133 GetModuleHandle(NULL
), 0);
2134 rect
.left
= LVIR_BOUNDS
;
2136 rect
.right
= rect
.bottom
= -10;
2137 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2138 ok(r
== 0, "Expected not-null LRESULT\n");
2139 /* rect is unchanged */
2140 expect(0, rect
.left
);
2141 expect(-10, rect
.right
);
2142 expect(1, rect
.top
);
2143 expect(-10, rect
.bottom
);
2144 DestroyWindow(hwnd
);
2147 /* comparison callback for test_sorting */
2148 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2150 if (first
== second
) return 0;
2151 return (first
> second
? 1 : -1);
2154 static void test_sorting(void)
2160 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2163 hwnd
= create_listview_control(0);
2164 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2166 /* insert some items */
2167 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2168 item
.state
= LVIS_SELECTED
;
2172 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2175 item
.mask
= LVIF_PARAM
;
2179 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2182 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2183 item
.state
= LVIS_SELECTED
;
2187 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2190 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2193 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2196 r
= SendMessage(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2199 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2201 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2203 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2205 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2206 expect(LVIS_SELECTED
, r
);
2207 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2208 expect(LVIS_SELECTED
, r
);
2210 DestroyWindow(hwnd
);
2212 /* switch to LVS_SORTASCENDING when some items added */
2213 hwnd
= create_listview_control(0);
2214 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2216 item
.mask
= LVIF_TEXT
;
2219 item
.pszText
= names
[1];
2220 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2223 item
.mask
= LVIF_TEXT
;
2226 item
.pszText
= names
[2];
2227 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2230 item
.mask
= LVIF_TEXT
;
2233 item
.pszText
= names
[0];
2234 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2237 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2238 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2239 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2240 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2242 /* no sorting performed when switched to LVS_SORTASCENDING */
2243 item
.mask
= LVIF_TEXT
;
2245 item
.pszText
= buff
;
2246 item
.cchTextMax
= sizeof(buff
);
2247 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2249 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2252 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2254 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2257 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2259 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2261 /* adding new item doesn't resort list */
2262 item
.mask
= LVIF_TEXT
;
2265 item
.pszText
= names
[3];
2266 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2269 item
.mask
= LVIF_TEXT
;
2271 item
.pszText
= buff
;
2272 item
.cchTextMax
= sizeof(buff
);
2273 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2275 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2278 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2280 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2283 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2285 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2288 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2290 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2292 /* corner case - item should be placed at first position */
2293 item
.mask
= LVIF_TEXT
;
2296 item
.pszText
= names
[4];
2297 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2301 item
.pszText
= buff
;
2302 item
.cchTextMax
= sizeof(buff
);
2303 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2305 ok(lstrcmp(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2308 item
.pszText
= buff
;
2309 item
.cchTextMax
= sizeof(buff
);
2310 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2312 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2315 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2317 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2320 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2322 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2325 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2327 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2329 DestroyWindow(hwnd
);
2332 static void test_ownerdata(void)
2335 LONG_PTR style
, ret
;
2339 /* it isn't possible to set LVS_OWNERDATA after creation */
2342 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2346 hwnd
= create_listview_control(0);
2347 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2348 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2349 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2351 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2353 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2354 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2355 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2356 "try to switch to LVS_OWNERDATA seq", FALSE
);
2358 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2359 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2360 DestroyWindow(hwnd
);
2363 /* try to set LVS_OWNERDATA after creation just having it */
2364 hwnd
= create_listview_control(LVS_OWNERDATA
);
2365 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2366 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2367 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2369 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2371 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2372 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2373 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2374 "try to switch to LVS_OWNERDATA seq", FALSE
);
2375 DestroyWindow(hwnd
);
2377 /* try to remove LVS_OWNERDATA after creation just having it */
2380 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2384 hwnd
= create_listview_control(LVS_OWNERDATA
);
2385 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2386 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2387 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2389 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2391 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2392 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2393 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2394 "try to switch to LVS_OWNERDATA seq", FALSE
);
2395 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2396 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2397 DestroyWindow(hwnd
);
2400 /* try select an item */
2401 hwnd
= create_listview_control(LVS_OWNERDATA
);
2402 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2403 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2404 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2405 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2407 memset(&item
, 0, sizeof(item
));
2408 item
.stateMask
= LVIS_SELECTED
;
2409 item
.state
= LVIS_SELECTED
;
2410 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2412 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2414 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2416 DestroyWindow(hwnd
);
2418 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2419 hwnd
= create_listview_control(LVS_OWNERDATA
);
2420 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2421 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2422 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2423 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2425 memset(&item
, 0, sizeof(item
));
2426 item
.mask
= LVIF_STATE
;
2428 item
.stateMask
= LVIS_SELECTED
;
2429 item
.state
= LVIS_SELECTED
;
2430 res
= SendMessageA(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2432 DestroyWindow(hwnd
);
2434 /* check notifications after focused/selected changed */
2435 hwnd
= create_listview_control(LVS_OWNERDATA
);
2436 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2437 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
2438 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2440 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2442 memset(&item
, 0, sizeof(item
));
2443 item
.stateMask
= LVIS_SELECTED
;
2444 item
.state
= LVIS_SELECTED
;
2445 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2448 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2449 "ownerdata select notification", TRUE
);
2451 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2453 memset(&item
, 0, sizeof(item
));
2454 item
.stateMask
= LVIS_FOCUSED
;
2455 item
.state
= LVIS_FOCUSED
;
2456 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2459 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2460 "ownerdata focus notification", TRUE
);
2462 /* select all, check notifications */
2463 item
.stateMask
= LVIS_SELECTED
;
2465 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2468 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2470 item
.stateMask
= LVIS_SELECTED
;
2471 item
.state
= LVIS_SELECTED
;
2473 g_dump_itemchanged
= TRUE
;
2474 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2476 g_dump_itemchanged
= FALSE
;
2478 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2479 "ownerdata select all notification", TRUE
);
2481 /* select all again, note that all items are selected already */
2482 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2483 item
.stateMask
= LVIS_SELECTED
;
2484 item
.state
= LVIS_SELECTED
;
2485 g_dump_itemchanged
= TRUE
;
2486 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2488 g_dump_itemchanged
= FALSE
;
2489 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2490 "ownerdata select all notification", TRUE
);
2492 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2493 item
.stateMask
= LVIS_SELECTED
;
2495 g_dump_itemchanged
= TRUE
;
2496 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2498 g_dump_itemchanged
= FALSE
;
2499 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2500 "ownerdata deselect all notification", TRUE
);
2502 /* select one, then deselect all */
2503 item
.stateMask
= LVIS_SELECTED
;
2504 item
.state
= LVIS_SELECTED
;
2505 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2507 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2508 item
.stateMask
= LVIS_SELECTED
;
2510 g_dump_itemchanged
= TRUE
;
2511 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2513 g_dump_itemchanged
= FALSE
;
2514 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2515 "ownerdata select all notification", TRUE
);
2517 /* remove focused, try to focus all */
2518 item
.stateMask
= LVIS_FOCUSED
;
2519 item
.state
= LVIS_FOCUSED
;
2520 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2522 item
.stateMask
= LVIS_FOCUSED
;
2524 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2526 item
.stateMask
= LVIS_FOCUSED
;
2527 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
2529 /* setting all to focused returns failure value */
2530 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2531 item
.stateMask
= LVIS_FOCUSED
;
2532 item
.state
= LVIS_FOCUSED
;
2533 g_dump_itemchanged
= TRUE
;
2534 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2536 g_dump_itemchanged
= FALSE
;
2537 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2538 "ownerdata focus all notification", FALSE
);
2539 /* focus single item, remove all */
2540 item
.stateMask
= LVIS_FOCUSED
;
2541 item
.state
= LVIS_FOCUSED
;
2542 res
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2544 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2545 item
.stateMask
= LVIS_FOCUSED
;
2547 g_dump_itemchanged
= TRUE
;
2548 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2550 g_dump_itemchanged
= FALSE
;
2551 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
2552 "ownerdata remove focus all notification", TRUE
);
2554 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2555 item
.stateMask
= LVIS_CUT
;
2556 item
.state
= LVIS_CUT
;
2557 g_dump_itemchanged
= TRUE
;
2558 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2560 g_dump_itemchanged
= FALSE
;
2561 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2562 "ownerdata cut all notification", TRUE
);
2563 /* all marked cut, try again */
2564 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2565 item
.stateMask
= LVIS_CUT
;
2566 item
.state
= LVIS_CUT
;
2567 g_dump_itemchanged
= TRUE
;
2568 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2570 g_dump_itemchanged
= FALSE
;
2571 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2572 "ownerdata cut all notification #2", TRUE
);
2574 DestroyWindow(hwnd
);
2576 /* check notifications on LVM_GETITEM */
2577 /* zero callback mask */
2578 hwnd
= create_listview_control(LVS_OWNERDATA
);
2579 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2580 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2581 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2583 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2585 memset(&item
, 0, sizeof(item
));
2586 item
.stateMask
= LVIS_SELECTED
;
2587 item
.mask
= LVIF_STATE
;
2588 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2591 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2592 "ownerdata getitem selected state 1", FALSE
);
2594 /* non zero callback mask but not we asking for */
2595 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
2598 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2600 memset(&item
, 0, sizeof(item
));
2601 item
.stateMask
= LVIS_SELECTED
;
2602 item
.mask
= LVIF_STATE
;
2603 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2606 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2607 "ownerdata getitem selected state 2", FALSE
);
2609 /* LVIS_OVERLAYMASK callback mask, asking for index */
2610 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2612 memset(&item
, 0, sizeof(item
));
2613 item
.stateMask
= LVIS_OVERLAYMASK
;
2614 item
.mask
= LVIF_STATE
;
2615 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2618 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
2619 "ownerdata getitem selected state 2", FALSE
);
2621 DestroyWindow(hwnd
);
2623 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2624 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
);
2625 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2626 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2627 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2628 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2629 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
2630 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2631 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
2632 DestroyWindow(hwnd
);
2633 /* apparently it's allowed to switch these style on after creation */
2634 hwnd
= create_listview_control(LVS_OWNERDATA
);
2635 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2636 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2637 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2638 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2639 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2640 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2641 DestroyWindow(hwnd
);
2643 hwnd
= create_listview_control(LVS_OWNERDATA
);
2644 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2645 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2646 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2647 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
2648 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2649 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
2650 DestroyWindow(hwnd
);
2653 static void test_norecompute(void)
2655 static CHAR testA
[] = "test";
2661 /* self containing control */
2662 hwnd
= create_listview_control(0);
2663 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2664 memset(&item
, 0, sizeof(item
));
2665 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
2667 item
.stateMask
= LVIS_SELECTED
;
2668 item
.state
= LVIS_SELECTED
;
2669 item
.pszText
= testA
;
2670 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2672 /* retrieve with LVIF_NORECOMPUTE */
2673 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2675 item
.pszText
= buff
;
2676 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2677 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2679 ok(lstrcmp(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
2681 item
.mask
= LVIF_TEXT
;
2683 item
.pszText
= LPSTR_TEXTCALLBACK
;
2684 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2687 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2689 item
.pszText
= buff
;
2690 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2692 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2693 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2695 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2696 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2697 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
2699 DestroyWindow(hwnd
);
2702 hwnd
= create_listview_control(LVS_OWNERDATA
);
2703 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2705 item
.mask
= LVIF_STATE
;
2706 item
.stateMask
= LVIS_SELECTED
;
2707 item
.state
= LVIS_SELECTED
;
2709 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2712 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2714 item
.pszText
= buff
;
2715 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2716 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2717 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2719 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2720 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2721 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
2723 DestroyWindow(hwnd
);
2726 static void test_nosortheader(void)
2731 hwnd
= create_listview_control(0);
2732 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2734 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2735 ok(IsWindow(header
), "header expected\n");
2737 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2738 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
2740 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2741 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
2742 /* HDS_BUTTONS retained */
2743 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2744 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
2746 DestroyWindow(hwnd
);
2748 /* create with LVS_NOSORTHEADER */
2749 hwnd
= create_listview_control(LVS_NOSORTHEADER
);
2750 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2752 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2753 ok(IsWindow(header
), "header expected\n");
2755 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2756 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2758 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2759 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
2760 /* not changed here */
2761 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2762 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2764 DestroyWindow(hwnd
);
2767 static void test_setredraw(void)
2775 hwnd
= create_listview_control(LVS_OWNERDATA
);
2776 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2778 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2779 ListView seems to handle it internally without DefWinProc */
2781 /* default value first */
2782 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2785 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2786 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2787 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2789 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2790 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2791 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2794 /* check update rect after redrawing */
2795 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2797 InvalidateRect(hwnd
, NULL
, FALSE
);
2798 RedrawWindow(hwnd
, NULL
, NULL
, RDW_UPDATENOW
);
2799 rect
.right
= rect
.bottom
= 1;
2800 GetUpdateRect(hwnd
, &rect
, FALSE
);
2801 expect(0, rect
.right
);
2802 expect(0, rect
.bottom
);
2805 hdc
= GetWindowDC(hwndparent
);
2806 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
2808 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2810 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
2812 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2814 ReleaseDC(hwndparent
, hdc
);
2816 /* check notification messages to show that repainting is disabled */
2817 ret
= SendMessage(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2819 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2821 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2823 InvalidateRect(hwnd
, NULL
, TRUE
);
2825 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2826 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
2828 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
2830 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2831 InvalidateRect(hwnd
, NULL
, TRUE
);
2833 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2834 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
2836 /* message isn't forwarded to header */
2837 subclass_header(hwnd
);
2838 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2839 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2841 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
2842 "WM_SETREDRAW: not forwarded to header", FALSE
);
2844 DestroyWindow(hwnd
);
2847 static void test_hittest(void)
2853 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2856 HIMAGELIST himl
, himl2
;
2859 hwnd
= create_listview_control(0);
2860 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2862 /* LVS_REPORT with a single subitem (2 columns) */
2863 insert_column(hwnd
, 0);
2864 insert_column(hwnd
, 1);
2865 insert_item(hwnd
, 0);
2868 /* the only purpose of that line is to be as long as a half item rect */
2869 item
.pszText
= text
;
2870 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
2873 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
2875 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
2878 memset(&bounds
, 0, sizeof(bounds
));
2879 bounds
.left
= LVIR_BOUNDS
;
2880 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
2881 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
2882 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
2883 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
2886 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2887 x
= pos
.x
+ 50; /* column half width */
2888 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2889 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, 0, FALSE
, FALSE
, __LINE__
);
2890 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2891 x
= pos
.x
+ 150; /* outside column */
2892 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2893 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
, __LINE__
);
2894 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2895 y
= (bounds
.bottom
- bounds
.top
) / 2;
2896 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
, __LINE__
);
2897 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2898 /* outside possible client rectangle (to right) */
2900 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2901 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
, __LINE__
);
2902 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2903 y
= (bounds
.bottom
- bounds
.top
) / 2;
2904 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
, __LINE__
);
2905 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2906 /* subitem returned with -1 item too */
2909 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2910 /* parent client area is 100x100 by default */
2911 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
2912 x
= pos
.x
+ 150; /* outside column */
2913 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2914 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, FALSE
, __LINE__
);
2915 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2916 y
= (bounds
.bottom
- bounds
.top
) / 2;
2917 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, TRUE
, __LINE__
);
2918 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2919 /* the same with LVS_EX_FULLROWSELECT */
2920 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
2921 x
= pos
.x
+ 150; /* outside column */
2922 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2923 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, LVHT_ONITEMLABEL
, FALSE
, FALSE
, __LINE__
);
2924 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2925 y
= (bounds
.bottom
- bounds
.top
) / 2;
2926 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2927 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
2928 x
= pos
.x
+ 150; /* outside column */
2929 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2930 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
, __LINE__
);
2931 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2932 y
= (bounds
.bottom
- bounds
.top
) / 2;
2933 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
, __LINE__
);
2934 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2935 /* outside possible client rectangle (to right) */
2937 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2938 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
, __LINE__
);
2939 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2940 y
= (bounds
.bottom
- bounds
.top
) / 2;
2941 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
, __LINE__
);
2942 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2943 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2944 himl
= ImageList_Create(16, 16, 0, 4, 4);
2945 ok(himl
!= NULL
, "failed to create imagelist\n");
2946 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
2947 ok(hbmp
!= NULL
, "failed to create bitmap\n");
2948 r
= ImageList_Add(himl
, hbmp
, 0);
2949 ok(r
== 0, "should be zero\n");
2950 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
2951 ok(hbmp
!= NULL
, "failed to create bitmap\n");
2952 r
= ImageList_Add(himl
, hbmp
, 0);
2953 ok(r
== 1, "should be one\n");
2955 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
2956 ok(r
== 0, "should return zero\n");
2958 item
.mask
= LVIF_IMAGE
;
2962 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2966 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2967 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
, __LINE__
);
2968 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2969 y
= (bounds
.bottom
- bounds
.top
) / 2;
2970 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2972 /* state icons indices are 1 based, check with valid index */
2973 item
.mask
= LVIF_STATE
;
2974 item
.state
= INDEXTOSTATEIMAGEMASK(1);
2975 item
.stateMask
= LVIS_STATEIMAGEMASK
;
2978 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2982 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2983 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
, __LINE__
);
2984 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2985 y
= (bounds
.bottom
- bounds
.top
) / 2;
2986 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2988 himl2
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)NULL
);
2989 ok(himl2
== himl
, "should return handle\n");
2991 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
2992 ok(r
== 0, "should return zero\n");
2995 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2996 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, 0, FALSE
, FALSE
, __LINE__
);
2997 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2998 y
= (bounds
.bottom
- bounds
.top
) / 2;
2999 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
3001 DestroyWindow(hwnd
);
3004 static void test_getviewrect(void)
3011 hwnd
= create_listview_control(0);
3012 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3015 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3018 insert_column(hwnd
, 0);
3019 insert_column(hwnd
, 1);
3021 memset(&item
, 0, sizeof(item
));
3024 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3026 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3028 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3031 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3032 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3034 /* left is set to (2e31-1) - XP SP2 */
3035 expect(0, rect
.right
);
3036 expect(0, rect
.top
);
3037 expect(0, rect
.bottom
);
3039 /* switch to LVS_ICON */
3040 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3042 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3043 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3045 expect(0, rect
.left
);
3046 expect(0, rect
.top
);
3047 /* precise value differs for 2k, XP and Vista */
3048 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3049 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3051 DestroyWindow(hwnd
);
3054 static void test_getitemposition(void)
3061 hwnd
= create_listview_control(0);
3062 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3063 header
= subclass_header(hwnd
);
3065 /* LVS_REPORT, single item, no columns added */
3066 insert_item(hwnd
, 0);
3068 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3071 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3073 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3075 /* LVS_REPORT, single item, single column */
3076 insert_column(hwnd
, 0);
3078 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3081 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3083 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3085 memset(&rect
, 0, sizeof(rect
));
3086 SendMessage(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3089 /* offset by header height */
3090 expect(rect
.bottom
- rect
.top
, pt
.y
);
3092 DestroyWindow(hwnd
);
3095 static void test_columnscreation(void)
3100 hwnd
= create_listview_control(0);
3101 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3103 insert_item(hwnd
, 0);
3105 /* headers columns aren't created automatically */
3106 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3107 ok(IsWindow(header
), "Expected header handle\n");
3108 r
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
3111 DestroyWindow(hwnd
);
3114 static void test_getitemrect(void)
3126 hwnd
= create_listview_control(0);
3127 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3130 memset(&item
, 0, sizeof(item
));
3133 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3136 rect
.left
= LVIR_BOUNDS
;
3137 rect
.right
= rect
.top
= rect
.bottom
= -1;
3138 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3141 /* zero width rectangle with no padding */
3142 expect(0, rect
.left
);
3143 expect(0, rect
.right
);
3145 insert_column(hwnd
, 0);
3146 insert_column(hwnd
, 1);
3148 col
.mask
= LVCF_WIDTH
;
3150 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 0, (LPARAM
)&col
);
3153 col
.mask
= LVCF_WIDTH
;
3155 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 1, (LPARAM
)&col
);
3158 rect
.left
= LVIR_BOUNDS
;
3159 rect
.right
= rect
.top
= rect
.bottom
= -1;
3160 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3163 /* still no left padding */
3164 expect(0, rect
.left
);
3165 expect(150, rect
.right
);
3167 rect
.left
= LVIR_SELECTBOUNDS
;
3168 rect
.right
= rect
.top
= rect
.bottom
= -1;
3169 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3172 expect(2, rect
.left
);
3174 rect
.left
= LVIR_LABEL
;
3175 rect
.right
= rect
.top
= rect
.bottom
= -1;
3176 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3178 /* padding, column width */
3179 expect(2, rect
.left
);
3180 expect(50, rect
.right
);
3182 /* no icons attached */
3183 rect
.left
= LVIR_ICON
;
3184 rect
.right
= rect
.top
= rect
.bottom
= -1;
3185 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3188 expect(2, rect
.left
);
3189 expect(2, rect
.right
);
3192 order
[0] = 1; order
[1] = 0;
3193 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3196 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3198 /* 1 indexed column width + padding */
3200 /* rect is at zero too */
3201 rect
.left
= LVIR_BOUNDS
;
3202 rect
.right
= rect
.top
= rect
.bottom
= -1;
3203 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3205 expect(0, rect
.left
);
3206 /* just width sum */
3207 expect(150, rect
.right
);
3209 rect
.left
= LVIR_SELECTBOUNDS
;
3210 rect
.right
= rect
.top
= rect
.bottom
= -1;
3211 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3213 /* column width + padding */
3214 expect(102, rect
.left
);
3216 /* back to initial order */
3217 order
[0] = 0; order
[1] = 1;
3218 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3222 himl
= ImageList_Create(16, 16, 0, 2, 2);
3223 ok(himl
!= NULL
, "failed to create imagelist\n");
3224 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3225 ok(hbm
!= NULL
, "failed to create bitmap\n");
3226 r
= ImageList_Add(himl
, hbm
, 0);
3227 ok(r
== 0, "should be zero\n");
3228 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3229 ok(hbm
!= NULL
, "failed to create bitmap\n");
3230 r
= ImageList_Add(himl
, hbm
, 0);
3231 ok(r
== 1, "should be one\n");
3233 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3234 ok(r
== 0, "should return zero\n");
3236 item
.mask
= LVIF_STATE
;
3237 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3238 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3241 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3245 rect
.left
= LVIR_ICON
;
3246 rect
.right
= rect
.top
= rect
.bottom
= -1;
3247 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3249 /* padding + stateicon width */
3250 expect(18, rect
.left
);
3251 expect(18, rect
.right
);
3253 rect
.left
= LVIR_LABEL
;
3254 rect
.right
= rect
.top
= rect
.bottom
= -1;
3255 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3257 /* padding + stateicon width -> column width */
3258 expect(18, rect
.left
);
3259 expect(50, rect
.right
);
3261 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)NULL
);
3262 ok(r
!= 0, "should return current list handle\n");
3264 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3265 ok(r
== 0, "should return zero\n");
3267 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3270 item
.stateMask
= ~0;
3273 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3277 rect
.left
= LVIR_ICON
;
3278 rect
.right
= rect
.top
= rect
.bottom
= -1;
3279 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3281 /* padding, icon width */
3282 expect(2, rect
.left
);
3283 expect(18, rect
.right
);
3285 rect
.left
= LVIR_LABEL
;
3286 rect
.right
= rect
.top
= rect
.bottom
= -1;
3287 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3289 /* padding + icon width -> column width */
3290 expect(18, rect
.left
);
3291 expect(50, rect
.right
);
3294 rect
.left
= LVIR_SELECTBOUNDS
;
3295 rect
.right
= rect
.top
= rect
.bottom
= -1;
3296 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3298 /* padding, column width */
3299 expect(2, rect
.left
);
3300 expect(50, rect
.right
);
3302 /* try with indentation */
3303 item
.mask
= LVIF_INDENT
;
3307 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3311 rect
.left
= LVIR_BOUNDS
;
3312 rect
.right
= rect
.top
= rect
.bottom
= -1;
3313 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3315 /* padding + 1 icon width, column width */
3316 expect(0, rect
.left
);
3317 expect(150, rect
.right
);
3320 rect
.left
= LVIR_SELECTBOUNDS
;
3321 rect
.right
= rect
.top
= rect
.bottom
= -1;
3322 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3324 /* padding + 1 icon width, column width */
3325 expect(2 + 16, rect
.left
);
3326 expect(50, rect
.right
);
3329 rect
.left
= LVIR_LABEL
;
3330 rect
.right
= rect
.top
= rect
.bottom
= -1;
3331 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3333 /* padding + 2 icon widths, column width */
3334 expect(2 + 16*2, rect
.left
);
3335 expect(50, rect
.right
);
3338 rect
.left
= LVIR_ICON
;
3339 rect
.right
= rect
.top
= rect
.bottom
= -1;
3340 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3342 /* padding + 1 icon width indentation, icon width */
3343 expect(2 + 16, rect
.left
);
3344 expect(34, rect
.right
);
3347 DestroyWindow(hwnd
);
3350 static void test_editbox(void)
3352 HWND hwnd
, hwndedit
, hwndedit2
;
3355 static CHAR testitemA
[] = "testitem";
3356 static CHAR testitem1A
[] = "testitem1";
3357 static CHAR buffer
[10];
3359 hwnd
= create_listview_control(LVS_EDITLABELS
);
3360 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3362 insert_column(hwnd
, 0);
3364 memset(&item
, 0, sizeof(item
));
3365 item
.mask
= LVIF_TEXT
;
3366 item
.pszText
= testitemA
;
3369 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3372 /* setting focus is necessary */
3374 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3375 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3377 /* modify initial string */
3378 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3380 /* return focus to listview */
3383 memset(&item
, 0, sizeof(item
));
3384 item
.mask
= LVIF_TEXT
;
3385 item
.pszText
= buffer
;
3386 item
.cchTextMax
= 10;
3389 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3392 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3394 /* send LVM_EDITLABEL on already created edit */
3396 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3397 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3398 /* focus will be set to edit */
3399 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
3400 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3401 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
3403 /* creating label disabled when control isn't focused */
3405 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3406 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3408 /* check EN_KILLFOCUS handling */
3409 memset(&item
, 0, sizeof(item
));
3410 item
.pszText
= testitemA
;
3413 r
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3417 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3418 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3419 /* modify edit and notify control that it lost focus */
3420 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3422 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3424 memset(&item
, 0, sizeof(item
));
3425 item
.pszText
= buffer
;
3426 item
.cchTextMax
= 10;
3429 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3430 expect(lstrlen(item
.pszText
), r
);
3431 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3432 /* end edit without saving */
3433 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
3435 memset(&item
, 0, sizeof(item
));
3436 item
.pszText
= buffer
;
3437 item
.cchTextMax
= 10;
3440 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3441 expect(lstrlen(item
.pszText
), r
);
3442 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3444 /* LVM_EDITLABEL with -1 destroys current edit */
3445 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
3446 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3447 /* no edit present */
3448 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3449 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3450 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3451 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3453 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3454 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3455 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3456 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3457 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3458 /* check another negative value */
3459 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3460 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3461 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3462 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -2, 0);
3463 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3464 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3465 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3466 /* and value greater than max item index */
3467 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3468 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3469 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3470 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3471 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, r
, 0);
3472 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3473 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3474 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3476 /* messaging tests */
3478 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3480 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3481 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3482 /* testing only sizing messages */
3483 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
3484 "edit box create - sizing", FALSE
);
3486 DestroyWindow(hwnd
);
3489 static void test_notifyformat(void)
3494 hwnd
= create_listview_control(0);
3495 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3497 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3498 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3499 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3501 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3503 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
3505 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3508 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
3510 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3515 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3516 DestroyWindow(hwnd
);
3520 DestroyWindow(hwnd
);
3522 /* test failure in parent WM_NOTIFYFORMAT */
3524 hwnd
= create_listview_control(0);
3525 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3526 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3527 ok(IsWindow(header
), "expected header to be created\n");
3528 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3530 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3531 ok( r
== 1 || broken(r
== 0), /* win9x */ "Expected 1, got %d\n", r
);
3532 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3533 ok(r
!= 0, "Expected valid format\n");
3535 notifyFormat
= NFR_UNICODE
;
3536 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3537 expect(NFR_UNICODE
, r
);
3538 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3540 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3541 ok( r
== 1 || broken(r
== 0), /* win9x */ "Expected 1, got %d\n", r
);
3543 notifyFormat
= NFR_ANSI
;
3544 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3545 expect(NFR_ANSI
, r
);
3546 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3548 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3549 ok( r
== 1 || broken(r
== 0), /* win9x */ "Expected 1, got %d\n", r
);
3551 DestroyWindow(hwnd
);
3553 /* try different unicode window combination and defaults */
3554 if (!GetModuleHandleW(NULL
))
3556 win_skip("Additional notify format tests are incompatible with Win9x\n");
3560 hwndparentW
= create_parent_window(TRUE
);
3561 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
3562 if (!IsWindow(hwndparentW
)) return;
3565 hwnd
= create_listview_controlW(0, hwndparentW
);
3566 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3567 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3568 ok(IsWindow(header
), "expected header to be created\n");
3569 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3571 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3573 DestroyWindow(hwnd
);
3574 /* receiving error code defaulting to ansi */
3576 hwnd
= create_listview_controlW(0, hwndparentW
);
3577 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3578 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3579 ok(IsWindow(header
), "expected header to be created\n");
3580 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3582 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3584 DestroyWindow(hwnd
);
3585 /* receiving ansi code from unicode window, use it */
3586 notifyFormat
= NFR_ANSI
;
3587 hwnd
= create_listview_controlW(0, hwndparentW
);
3588 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3589 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3590 ok(IsWindow(header
), "expected header to be created\n");
3591 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3593 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3595 DestroyWindow(hwnd
);
3596 /* unicode listview with ansi parent window */
3598 hwnd
= create_listview_controlW(0, hwndparent
);
3599 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3600 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3601 ok(IsWindow(header
), "expected header to be created\n");
3602 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3604 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3606 DestroyWindow(hwnd
);
3607 /* unicode listview with ansi parent window, return error code */
3609 hwnd
= create_listview_controlW(0, hwndparent
);
3610 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3611 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3612 ok(IsWindow(header
), "expected header to be created\n");
3613 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3615 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3617 DestroyWindow(hwnd
);
3619 DestroyWindow(hwndparentW
);
3622 static void test_indentation(void)
3628 hwnd
= create_listview_control(0);
3629 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3631 memset(&item
, 0, sizeof(item
));
3632 item
.mask
= LVIF_INDENT
;
3634 item
.iIndent
= I_INDENTCALLBACK
;
3635 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3638 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3641 item
.mask
= LVIF_INDENT
;
3642 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3645 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3646 "get indent dispinfo", FALSE
);
3648 DestroyWindow(hwnd
);
3651 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
3656 static BOOL
is_below_comctl_5(void)
3661 hwnd
= create_listview_control(0);
3662 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3663 insert_item(hwnd
, 0);
3665 ret
= SendMessage(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
3667 DestroyWindow(hwnd
);
3672 static void test_get_set_view(void)
3678 /* test style->view mapping */
3679 hwnd
= create_listview_control(0);
3680 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3682 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3683 expect(LV_VIEW_DETAILS
, ret
);
3685 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3687 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
3688 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3689 expect(LV_VIEW_ICON
, ret
);
3691 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3692 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
3693 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3694 expect(LV_VIEW_SMALLICON
, ret
);
3696 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3697 SetWindowLongPtr(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
3698 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3699 expect(LV_VIEW_LIST
, ret
);
3701 /* switching view doesn't touch window style */
3702 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
3704 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3705 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3706 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
3708 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3709 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3710 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
3712 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3713 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3715 DestroyWindow(hwnd
);
3718 static void test_canceleditlabel(void)
3720 HWND hwnd
, hwndedit
;
3724 static CHAR test
[] = "test";
3725 static const CHAR test1
[] = "test1";
3727 hwnd
= create_listview_control(LVS_EDITLABELS
);
3728 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3730 insert_item(hwnd
, 0);
3732 /* try without edit created */
3733 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3736 /* cancel without data change */
3738 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3739 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3740 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3742 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3744 /* cancel after data change */
3745 memset(&itema
, 0, sizeof(itema
));
3746 itema
.pszText
= test
;
3747 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
3750 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3751 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3752 ret
= SetWindowText(hwndedit
, test1
);
3753 ok(ret
!= 0, "Expected edit text to change\n");
3754 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3756 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3757 memset(&itema
, 0, sizeof(itema
));
3758 itema
.pszText
= buff
;
3759 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3760 ret
= SendMessage(hwnd
, LVM_GETITEMTEXT
, 0, (LPARAM
)&itema
);
3762 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
3764 DestroyWindow(hwnd
);
3767 static void test_mapidindex(void)
3772 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3773 hwnd
= create_listview_control(LVS_OWNERDATA
);
3774 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3775 insert_item(hwnd
, 0);
3776 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3778 DestroyWindow(hwnd
);
3780 hwnd
= create_listview_control(0);
3781 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3783 /* LVM_MAPINDEXTOID with invalid index */
3784 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3787 insert_item(hwnd
, 0);
3788 insert_item(hwnd
, 1);
3790 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
3792 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
3795 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3797 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
3799 /* remove 0 indexed item, id retained */
3800 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
3801 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3803 /* new id starts from previous value */
3804 insert_item(hwnd
, 1);
3805 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
3808 /* get index by id */
3809 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
3811 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
3813 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
3815 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
3818 DestroyWindow(hwnd
);
3821 static void test_getitemspacing(void)
3830 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
3831 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
3834 hwnd
= create_custom_listview_control(0);
3835 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3837 expect(cx
, LOWORD(ret
));
3838 expect(cy
, HIWORD(ret
));
3840 /* now try with icons */
3841 himl
= ImageList_Create(40, 40, 0, 4, 4);
3842 ok(himl
!= NULL
, "failed to create imagelist\n");
3843 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
3844 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3845 ret
= ImageList_Add(himl
, hbmp
, 0);
3847 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
3850 itema
.mask
= LVIF_IMAGE
;
3854 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
3856 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3858 /* spacing + icon size returned */
3859 expect(cx
+ 40, LOWORD(ret
));
3860 expect(cy
+ 40, HIWORD(ret
));
3862 DestroyWindow(hwnd
);
3864 hwnd
= create_custom_listview_control(LVS_SMALLICON
);
3865 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3867 expect(cx
, LOWORD(ret
));
3868 expect(cy
, HIWORD(ret
));
3870 DestroyWindow(hwnd
);
3872 hwnd
= create_custom_listview_control(LVS_REPORT
);
3873 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3875 expect(cx
, LOWORD(ret
));
3876 expect(cy
, HIWORD(ret
));
3878 DestroyWindow(hwnd
);
3880 hwnd
= create_custom_listview_control(LVS_LIST
);
3881 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3883 expect(cx
, LOWORD(ret
));
3884 expect(cy
, HIWORD(ret
));
3886 DestroyWindow(hwnd
);
3889 static void test_getcolumnwidth(void)
3896 /* default column width */
3897 hwnd
= create_custom_listview_control(0);
3898 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
3900 style
= GetWindowLong(hwnd
, GWL_STYLE
);
3901 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
3902 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
3903 todo_wine
expect(8, ret
);
3904 style
= GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
3905 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
3907 ret
= SendMessage(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
3909 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
3911 DestroyWindow(hwnd
);
3914 static void test_scrollnotify(void)
3919 hwnd
= create_listview_control(0);
3921 insert_column(hwnd
, 0);
3922 insert_column(hwnd
, 1);
3923 insert_item(hwnd
, 0);
3925 /* make it scrollable - resize */
3926 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3928 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3931 /* try with dummy call */
3932 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3933 ret
= SendMessage(hwnd
, LVM_SCROLL
, 0, 0);
3935 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
3936 "scroll notify 1", TRUE
);
3938 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3939 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 0);
3941 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
3942 "scroll notify 2", TRUE
);
3944 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3945 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 1);
3947 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
3948 "scroll notify 3", TRUE
);
3950 DestroyWindow(hwnd
);
3953 START_TEST(listview
)
3956 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
3958 ULONG_PTR ctx_cookie
;
3961 hComctl32
= GetModuleHandleA("comctl32.dll");
3962 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
3963 if (pInitCommonControlsEx
)
3965 INITCOMMONCONTROLSEX iccex
;
3966 iccex
.dwSize
= sizeof(iccex
);
3967 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
3968 pInitCommonControlsEx(&iccex
);
3971 InitCommonControls();
3973 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
3975 hwndparent
= create_parent_window(FALSE
);
3976 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3978 g_is_below_5
= is_below_comctl_5();
3986 test_icon_spacing();
3989 test_item_position();
3994 test_subitem_rect();
3998 test_nosortheader();
4002 test_getitemposition();
4003 test_columnscreation();
4005 test_notifyformat();
4007 test_getitemspacing();
4008 test_getcolumnwidth();
4010 if (!load_v6_module(&ctx_cookie
))
4012 DestroyWindow(hwndparent
);
4016 /* this is a XP SP3 failure workaround */
4017 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
4018 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
,
4020 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
4021 if (!IsWindow(hwnd
))
4023 win_skip("FIXME: failed to create ListView window.\n");
4024 unload_v6_module(ctx_cookie
);
4028 DestroyWindow(hwnd
);
4030 /* comctl32 version 6 tests start here */
4031 test_get_set_view();
4032 test_canceleditlabel();
4034 test_scrollnotify();
4036 unload_v6_module(ctx_cookie
);
4038 DestroyWindow(hwndparent
);