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"
29 #define PARENT_SEQ_INDEX 0
30 #define PARENT_FULL_SEQ_INDEX 1
31 #define LISTVIEW_SEQ_INDEX 2
32 #define EDITBOX_SEQ_INDEX 3
33 #define NUM_MSG_SEQUENCES 4
38 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
39 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
40 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
44 #elif defined __x86_64__
50 static const CHAR manifest_name
[] = "cc6.manifest";
52 static const CHAR manifest
[] =
53 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
54 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">\n"
55 " <assemblyIdentity\n"
57 " name=\"Wine.ComCtl32.Tests\"\n"
58 " version=\"1.0.0.0\"\n"
59 " processorArchitecture=\"" ARCH
"\"\n"
61 "<description>Wine comctl32 test suite</description>\n"
63 " <dependentAssembly>\n"
64 " <assemblyIdentity\n"
66 " name=\"microsoft.windows.common-controls\"\n"
67 " version=\"6.0.0.0\"\n"
68 " processorArchitecture=\"" ARCH
"\"\n"
69 " publicKeyToken=\"6595b64144ccf1df\"\n"
72 "</dependentAssembly>\n"
76 static const WCHAR testparentclassW
[] =
77 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
79 HWND hwndparent
, hwndparentW
;
80 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
82 /* dumps LVN_ITEMCHANGED message data */
83 static BOOL g_dump_itemchanged
;
84 /* format reported to control:
85 -1 falls to defproc, anything else returned */
87 /* indicates we're running < 5.80 version */
90 static HWND
subclass_editbox(HWND hwndListview
);
92 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
94 static const struct message create_ownerdrawfixed_parent_seq
[] = {
95 { WM_NOTIFYFORMAT
, sent
},
96 { WM_QUERYUISTATE
, sent
|optional
}, /* Win2K and higher */
97 { WM_MEASUREITEM
, sent
},
98 { WM_PARENTNOTIFY
, sent
},
102 static const struct message redraw_listview_seq
[] = {
103 { WM_PAINT
, sent
|id
, 0, 0, LISTVIEW_ID
},
104 { WM_PAINT
, sent
|id
, 0, 0, HEADER_ID
},
105 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
106 { WM_ERASEBKGND
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
107 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
108 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
109 { WM_ERASEBKGND
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
113 static const struct message listview_icon_spacing_seq
[] = {
114 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(20, 30) },
115 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(25, 35) },
116 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(-1, -1) },
120 static const struct message listview_color_seq
[] = {
121 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
122 { LVM_GETBKCOLOR
, sent
},
123 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
124 { LVM_GETTEXTCOLOR
, sent
},
125 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
126 { LVM_GETTEXTBKCOLOR
, sent
},
128 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
129 { LVM_GETBKCOLOR
, sent
},
130 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
131 { LVM_GETTEXTCOLOR
, sent
},
132 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
133 { LVM_GETTEXTBKCOLOR
, sent
},
135 { LVM_SETBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
136 { LVM_GETBKCOLOR
, sent
},
137 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, CLR_NONE
},
138 { LVM_GETTEXTCOLOR
, sent
},
139 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
140 { LVM_GETTEXTBKCOLOR
, sent
},
142 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
143 { LVM_GETBKCOLOR
, sent
},
144 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
145 { LVM_GETTEXTCOLOR
, sent
},
146 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
147 { LVM_GETTEXTBKCOLOR
, sent
},
151 static const struct message listview_item_count_seq
[] = {
152 { LVM_GETITEMCOUNT
, sent
},
153 { LVM_INSERTITEM
, sent
},
154 { LVM_INSERTITEM
, sent
},
155 { LVM_INSERTITEM
, sent
},
156 { LVM_GETITEMCOUNT
, sent
},
157 { LVM_DELETEITEM
, sent
|wparam
, 2 },
158 { LVM_GETITEMCOUNT
, sent
},
159 { LVM_DELETEALLITEMS
, sent
},
160 { LVM_GETITEMCOUNT
, sent
},
161 { LVM_INSERTITEM
, sent
},
162 { LVM_INSERTITEM
, sent
},
163 { LVM_GETITEMCOUNT
, sent
},
164 { LVM_INSERTITEM
, sent
},
165 { LVM_GETITEMCOUNT
, sent
},
169 static const struct message listview_itempos_seq
[] = {
170 { LVM_INSERTITEM
, sent
},
171 { LVM_INSERTITEM
, sent
},
172 { LVM_INSERTITEM
, sent
},
173 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 1, MAKELPARAM(10,5) },
174 { LVM_GETITEMPOSITION
, sent
|wparam
, 1 },
175 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 2, MAKELPARAM(0,0) },
176 { LVM_GETITEMPOSITION
, sent
|wparam
, 2 },
177 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 0, MAKELPARAM(20,20) },
178 { LVM_GETITEMPOSITION
, sent
|wparam
, 0 },
182 static const struct message listview_ownerdata_switchto_seq
[] = {
183 { WM_STYLECHANGING
, sent
},
184 { WM_STYLECHANGED
, sent
},
188 static const struct message listview_getorderarray_seq
[] = {
189 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
190 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
194 static const struct message empty_seq
[] = {
198 static const struct message forward_erasebkgnd_parent_seq
[] = {
199 { WM_ERASEBKGND
, sent
},
203 static const struct message ownderdata_select_focus_parent_seq
[] = {
204 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
205 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
206 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
}, /* version 4.7x */
210 static const struct message ownerdata_setstate_all_parent_seq
[] = {
211 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
215 static const struct message ownerdata_defocus_all_parent_seq
[] = {
216 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
217 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
218 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
222 static const struct message ownerdata_deselect_all_parent_seq
[] = {
223 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ODCACHEHINT
},
224 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
228 static const struct message select_all_parent_seq
[] = {
229 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
230 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
232 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
233 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
235 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
236 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
238 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
239 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
241 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
242 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
246 static const struct message textcallback_set_again_parent_seq
[] = {
247 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
248 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
252 static const struct message single_getdispinfo_parent_seq
[] = {
253 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
257 static const struct message getitemposition_seq1
[] = {
258 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
262 static const struct message getitemposition_seq2
[] = {
263 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
264 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
268 static const struct message editbox_create_pos
[] = {
269 /* sequence sent after LVN_BEGINLABELEDIT */
270 /* next two are 4.7x specific */
271 { WM_WINDOWPOSCHANGING
, sent
},
272 { WM_WINDOWPOSCHANGED
, sent
|optional
},
274 { WM_WINDOWPOSCHANGING
, sent
|optional
},
275 { WM_NCCALCSIZE
, sent
},
276 { WM_WINDOWPOSCHANGED
, sent
},
277 { WM_MOVE
, sent
|defwinproc
},
278 { WM_SIZE
, sent
|defwinproc
},
279 /* the rest is todo, skipped in 4.7x */
280 { WM_WINDOWPOSCHANGING
, sent
|optional
},
281 { WM_WINDOWPOSCHANGED
, sent
|optional
},
285 static const struct message scroll_parent_seq
[] = {
286 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_BEGINSCROLL
},
287 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDSCROLL
},
296 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
298 static LONG defwndproc_counter
= 0;
302 msg
.message
= message
;
303 msg
.flags
= sent
|wparam
|lparam
;
304 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
307 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
309 /* log system messages, except for painting */
310 if (message
< WM_USER
&&
311 message
!= WM_PAINT
&&
312 message
!= WM_ERASEBKGND
&&
313 message
!= WM_NCPAINT
&&
314 message
!= WM_NCHITTEST
&&
315 message
!= WM_GETTEXT
&&
316 message
!= WM_GETICON
&&
317 message
!= WM_DEVICECHANGE
)
319 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
321 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
323 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
329 switch (((NMHDR
*)lParam
)->code
)
331 case LVN_BEGINLABELEDIT
:
332 /* subclass edit box */
334 subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
338 case LVN_ENDLABELEDIT
:
339 /* always accept new item text */
341 case LVN_BEGINSCROLL
:
344 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
346 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
347 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
350 case LVN_ITEMCHANGED
:
351 if (g_dump_itemchanged
)
353 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
354 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
355 nmlv
->iItem
, nmlv
->uNewState
, nmlv
->uOldState
, nmlv
->uChanged
);
361 case WM_NOTIFYFORMAT
:
363 /* force to return format */
364 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
369 defwndproc_counter
++;
370 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
371 defwndproc_counter
--;
376 static BOOL
register_parent_wnd_class(BOOL Unicode
)
384 clsW
.lpfnWndProc
= parent_wnd_proc
;
387 clsW
.hInstance
= GetModuleHandleW(NULL
);
389 clsW
.hCursor
= LoadCursorA(0, IDC_ARROW
);
390 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
391 clsW
.lpszMenuName
= NULL
;
392 clsW
.lpszClassName
= testparentclassW
;
397 clsA
.lpfnWndProc
= parent_wnd_proc
;
400 clsA
.hInstance
= GetModuleHandleA(NULL
);
402 clsA
.hCursor
= LoadCursorA(0, IDC_ARROW
);
403 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
404 clsA
.lpszMenuName
= NULL
;
405 clsA
.lpszClassName
= "Listview test parent class";
408 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
411 static HWND
create_parent_window(BOOL Unicode
)
413 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W'};
415 if (!register_parent_wnd_class(Unicode
))
422 return CreateWindowExW(0, testparentclassW
, nameW
,
423 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
424 WS_MAXIMIZEBOX
| WS_VISIBLE
,
426 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
428 return CreateWindowExA(0, "Listview test parent class",
429 "Listview test parent window",
430 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
431 WS_MAXIMIZEBOX
| WS_VISIBLE
,
433 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
436 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
438 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
439 static LONG defwndproc_counter
= 0;
443 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
445 /* some debug output for style changing */
446 if ((message
== WM_STYLECHANGING
||
447 message
== WM_STYLECHANGED
) && lParam
)
449 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
450 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
453 msg
.message
= message
;
454 msg
.flags
= sent
|wparam
|lparam
;
455 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
458 msg
.id
= LISTVIEW_ID
;
459 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
461 defwndproc_counter
++;
462 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
463 defwndproc_counter
--;
467 static HWND
create_listview_control(DWORD style
)
469 struct subclass_info
*info
;
473 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
477 GetClientRect(hwndparent
, &rect
);
478 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
479 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
| style
,
480 0, 0, rect
.right
, rect
.bottom
,
481 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
482 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
486 HeapFree(GetProcessHeap(), 0, info
);
490 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
491 (LONG_PTR
)listview_subclass_proc
);
492 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
497 /* unicode listview window with specified parent */
498 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
500 struct subclass_info
*info
;
503 static const WCHAR nameW
[] = {'f','o','o',0};
505 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
509 GetClientRect(parent
, &rect
);
510 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
511 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
| style
,
512 0, 0, rect
.right
, rect
.bottom
,
513 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
514 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
518 HeapFree(GetProcessHeap(), 0, info
);
522 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
523 (LONG_PTR
)listview_subclass_proc
);
524 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
529 static HWND
create_custom_listview_control(DWORD style
)
531 struct subclass_info
*info
;
535 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
539 GetClientRect(hwndparent
, &rect
);
540 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
541 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
542 0, 0, rect
.right
, rect
.bottom
,
543 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
544 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
548 HeapFree(GetProcessHeap(), 0, info
);
552 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
553 (LONG_PTR
)listview_subclass_proc
);
554 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
559 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
561 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
562 static LONG defwndproc_counter
= 0;
566 trace("header: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
568 msg
.message
= message
;
569 msg
.flags
= sent
|wparam
|lparam
;
570 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
574 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
576 defwndproc_counter
++;
577 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
578 defwndproc_counter
--;
582 static HWND
subclass_header(HWND hwndListview
)
584 struct subclass_info
*info
;
587 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
591 hwnd
= ListView_GetHeader(hwndListview
);
592 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
593 (LONG_PTR
)header_subclass_proc
);
594 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
599 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
601 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
602 static LONG defwndproc_counter
= 0;
606 msg
.message
= message
;
607 msg
.flags
= sent
|wparam
|lparam
;
608 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
612 /* all we need is sizing */
613 if (message
== WM_WINDOWPOSCHANGING
||
614 message
== WM_NCCALCSIZE
||
615 message
== WM_WINDOWPOSCHANGED
||
616 message
== WM_MOVE
||
619 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
622 defwndproc_counter
++;
623 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
624 defwndproc_counter
--;
628 static HWND
subclass_editbox(HWND hwndListview
)
630 struct subclass_info
*info
;
633 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
637 hwnd
= (HWND
)SendMessage(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
638 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
639 (LONG_PTR
)editbox_subclass_proc
);
640 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
645 /* Performs a single LVM_HITTEST test */
646 static void test_lvm_hittest(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
,
647 BOOL todo_item
, BOOL todo_flags
, int line
)
656 trace("hittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
657 ret
= SendMessage(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
663 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
664 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
665 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
670 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
671 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
672 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
678 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
681 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
684 /* Performs a single LVM_SUBITEMHITTEST test */
685 static void test_lvm_subitemhittest(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
686 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
694 trace("subhittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
695 ret
= SendMessage(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
701 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
702 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
707 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
708 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
714 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
717 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
722 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
725 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
728 static void test_images(void)
736 static CHAR hello
[] = "hello";
738 himl
= ImageList_Create(40, 40, 0, 4, 4);
739 ok(himl
!= NULL
, "failed to create imagelist\n");
741 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
742 ok(hbmp
!= NULL
, "failed to create bitmap\n");
744 r
= ImageList_Add(himl
, hbmp
, 0);
745 ok(r
== 0, "should be zero\n");
747 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
748 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
749 ok(hwnd
!= NULL
, "failed to create listview window\n");
751 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
752 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
754 ok(r
== 0, "should return zero\n");
756 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
757 ok(r
== 0, "should return zero\n");
759 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
760 /* returns dimensions */
762 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
763 ok(r
== 0, "should be zero items\n");
765 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
770 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
771 ok(r
== -1, "should fail\n");
774 item
.pszText
= hello
;
775 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
776 ok(r
== 0, "should not fail\n");
778 memset(&r1
, 0, sizeof r1
);
780 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
782 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
783 ok(r
== TRUE
, "should not fail\n");
786 item
.pszText
= hello
;
787 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
788 ok(r
== 0, "should not fail\n");
790 memset(&r2
, 0, sizeof r2
);
792 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
794 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
799 static void test_checkboxes(void)
804 static CHAR text
[] = "Text",
808 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
809 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
810 ok(hwnd
!= NULL
, "failed to create listview window\n");
812 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
813 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
814 item
.stateMask
= 0xffff;
819 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
820 ok(r
== 0, "ret %d\n", r
);
823 item
.mask
= LVIF_STATE
;
824 item
.stateMask
= 0xffff;
825 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
826 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
828 /* Don't set LVIF_STATE */
829 item
.mask
= LVIF_TEXT
;
830 item
.stateMask
= 0xffff;
835 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
836 ok(r
== 1, "ret %d\n", r
);
839 item
.mask
= LVIF_STATE
;
840 item
.stateMask
= 0xffff;
841 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
842 ok(item
.state
== 0, "state %x\n", item
.state
);
844 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
845 ok(r
== 0, "should return zero\n");
847 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
849 item
.mask
= LVIF_STATE
;
850 item
.stateMask
= 0xffff;
851 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
852 ok(item
.state
== 0x1ccc, "state %x\n", item
.state
);
854 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
856 item
.mask
= LVIF_TEXT
;
858 item
.pszText
= text2
;
859 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
860 ok(r
== 2, "ret %d\n", r
);
863 item
.mask
= LVIF_STATE
;
864 item
.stateMask
= 0xffff;
865 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
866 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
868 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
870 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
871 item
.stateMask
= 0xffff;
873 item
.pszText
= text3
;
874 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
875 ok(r
== 3, "ret %d\n", r
);
878 item
.mask
= LVIF_STATE
;
879 item
.stateMask
= 0xffff;
880 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
881 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
883 /* Set an item's state to checked */
885 item
.mask
= LVIF_STATE
;
886 item
.stateMask
= 0xf000;
888 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
891 item
.mask
= LVIF_STATE
;
892 item
.stateMask
= 0xffff;
893 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
894 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
896 /* Check that only the bits we asked for are returned,
897 * and that all the others are set to zero
900 item
.mask
= LVIF_STATE
;
901 item
.stateMask
= 0xf000;
903 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
904 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
906 /* Set the style again and check that doesn't change an item's state */
907 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
908 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
911 item
.mask
= LVIF_STATE
;
912 item
.stateMask
= 0xffff;
913 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
914 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
916 /* Unsetting the checkbox extended style doesn't change an item's state */
917 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
918 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
921 item
.mask
= LVIF_STATE
;
922 item
.stateMask
= 0xffff;
923 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
924 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
926 /* Now setting the style again will change an item's state */
927 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
928 ok(r
== 0, "ret %x\n", r
);
931 item
.mask
= LVIF_STATE
;
932 item
.stateMask
= 0xffff;
933 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
934 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
936 /* Toggle checkbox tests (bug 9934) */
937 memset (&item
, 0xcc, sizeof(item
));
938 item
.mask
= LVIF_STATE
;
941 item
.state
= LVIS_FOCUSED
;
942 item
.stateMask
= LVIS_FOCUSED
;
943 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
947 item
.mask
= LVIF_STATE
;
948 item
.stateMask
= 0xffff;
949 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
950 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
952 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
954 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
958 item
.mask
= LVIF_STATE
;
959 item
.stateMask
= 0xffff;
960 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
961 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
963 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
965 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
969 item
.mask
= LVIF_STATE
;
970 item
.stateMask
= 0xffff;
971 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
972 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
977 static void insert_column(HWND hwnd
, int idx
)
982 memset(&column
, 0xcc, sizeof(column
));
983 column
.mask
= LVCF_SUBITEM
;
984 column
.iSubItem
= idx
;
986 rc
= ListView_InsertColumn(hwnd
, idx
, &column
);
990 static void insert_item(HWND hwnd
, int idx
)
992 static CHAR text
[] = "foo";
997 memset(&item
, 0xcc, sizeof (item
));
998 item
.mask
= LVIF_TEXT
;
1001 item
.pszText
= text
;
1003 rc
= ListView_InsertItem(hwnd
, &item
);
1007 static void test_items(void)
1009 const LPARAM lparamTest
= 0x42;
1013 static CHAR text
[] = "Text";
1015 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1016 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1017 ok(hwnd
!= NULL
, "failed to create listview window\n");
1020 * Test setting/getting item params
1023 /* Set up two columns */
1024 insert_column(hwnd
, 0);
1025 insert_column(hwnd
, 1);
1027 /* LVIS_SELECTED with zero stateMask */
1029 memset (&item
, 0, sizeof (item
));
1030 item
.mask
= LVIF_STATE
;
1031 item
.state
= LVIS_SELECTED
;
1035 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1036 ok(r
== 0, "ret %d\n", r
);
1038 memset (&item
, 0xcc, sizeof (item
));
1039 item
.mask
= LVIF_STATE
;
1040 item
.stateMask
= LVIS_SELECTED
;
1044 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1045 ok(r
!= 0, "ret %d\n", r
);
1046 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1047 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1049 /* LVIS_SELECTED with zero stateMask */
1051 memset (&item
, 0, sizeof (item
));
1052 item
.mask
= LVIF_STATE
;
1053 item
.state
= LVIS_FOCUSED
;
1057 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1058 ok(r
== 0, "ret %d\n", r
);
1060 memset (&item
, 0xcc, sizeof (item
));
1061 item
.mask
= LVIF_STATE
;
1062 item
.stateMask
= LVIS_FOCUSED
;
1066 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1067 ok(r
!= 0, "ret %d\n", r
);
1068 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1069 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1071 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1073 memset (&item
, 0, sizeof (item
));
1074 item
.mask
= LVIF_STATE
;
1075 item
.state
= LVIS_CUT
;
1076 item
.stateMask
= LVIS_FOCUSED
;
1079 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1080 ok(r
== 0, "ret %d\n", r
);
1082 memset (&item
, 0xcc, sizeof (item
));
1083 item
.mask
= LVIF_STATE
;
1084 item
.stateMask
= LVIS_CUT
;
1088 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1089 ok(r
!= 0, "ret %d\n", r
);
1090 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1091 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1093 /* Insert an item with just a param */
1094 memset (&item
, 0xcc, sizeof (item
));
1095 item
.mask
= LVIF_PARAM
;
1098 item
.lParam
= lparamTest
;
1099 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1100 ok(r
== 0, "ret %d\n", r
);
1102 /* Test getting of the param */
1103 memset (&item
, 0xcc, sizeof (item
));
1104 item
.mask
= LVIF_PARAM
;
1107 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1108 ok(r
!= 0, "ret %d\n", r
);
1109 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1111 /* Set up a subitem */
1112 memset (&item
, 0xcc, sizeof (item
));
1113 item
.mask
= LVIF_TEXT
;
1116 item
.pszText
= text
;
1117 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1118 ok(r
!= 0, "ret %d\n", r
);
1120 /* Query param from subitem: returns main item param */
1121 memset (&item
, 0xcc, sizeof (item
));
1122 item
.mask
= LVIF_PARAM
;
1125 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1126 ok(r
!= 0, "ret %d\n", r
);
1127 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1129 /* Set up param on first subitem: no effect */
1130 memset (&item
, 0xcc, sizeof (item
));
1131 item
.mask
= LVIF_PARAM
;
1134 item
.lParam
= lparamTest
+1;
1135 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1136 ok(r
== 0, "ret %d\n", r
);
1138 /* Query param from subitem again: should still return main item param */
1139 memset (&item
, 0xcc, sizeof (item
));
1140 item
.mask
= LVIF_PARAM
;
1143 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1144 ok(r
!= 0, "ret %d\n", r
);
1145 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1147 /**** Some tests of state highlighting ****/
1148 memset (&item
, 0xcc, sizeof (item
));
1149 item
.mask
= LVIF_STATE
;
1152 item
.state
= LVIS_SELECTED
;
1153 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1154 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1155 ok(r
!= 0, "ret %d\n", r
);
1157 item
.state
= LVIS_DROPHILITED
;
1158 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1159 ok(r
!= 0, "ret %d\n", r
);
1161 memset (&item
, 0xcc, sizeof (item
));
1162 item
.mask
= LVIF_STATE
;
1165 item
.stateMask
= -1;
1166 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1167 ok(r
!= 0, "ret %d\n", r
);
1168 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1170 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1171 ok(r
!= 0, "ret %d\n", r
);
1172 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1174 /* some notnull but meaningless masks */
1175 memset (&item
, 0, sizeof(item
));
1176 item
.mask
= LVIF_NORECOMPUTE
;
1179 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1180 ok(r
!= 0, "ret %d\n", r
);
1181 memset (&item
, 0, sizeof(item
));
1182 item
.mask
= LVIF_DI_SETITEM
;
1185 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1186 ok(r
!= 0, "ret %d\n", r
);
1188 /* set text to callback value already having it */
1189 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1191 memset (&item
, 0, sizeof (item
));
1192 item
.mask
= LVIF_TEXT
;
1193 item
.pszText
= LPSTR_TEXTCALLBACK
;
1195 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1196 ok(r
== 0, "ret %d\n", r
);
1197 memset (&item
, 0, sizeof (item
));
1199 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1201 item
.pszText
= LPSTR_TEXTCALLBACK
;
1202 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0 , (LPARAM
) &item
);
1205 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1206 "check callback text comparison rule", FALSE
);
1208 DestroyWindow(hwnd
);
1211 static void test_columns(void)
1213 HWND hwnd
, hwndheader
;
1218 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1219 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1220 ok(hwnd
!= NULL
, "failed to create listview window\n");
1222 /* Add a column with no mask */
1223 memset(&column
, 0xcc, sizeof(column
));
1225 rc
= ListView_InsertColumn(hwnd
, 0, &column
);
1226 ok(rc
==0, "Inserting column with no mask failed with %d\n", rc
);
1228 /* Check its width */
1229 rc
= ListView_GetColumnWidth(hwnd
, 0);
1231 broken(rc
==0), /* win9x */
1232 "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1234 DestroyWindow(hwnd
);
1236 /* LVM_GETCOLUMNORDERARRAY */
1237 hwnd
= create_listview_control(0);
1238 hwndheader
= subclass_header(hwnd
);
1240 memset(&column
, 0, sizeof(column
));
1241 column
.mask
= LVCF_WIDTH
;
1243 rc
= ListView_InsertColumn(hwnd
, 0, &column
);
1244 ok(rc
== 0, "Inserting column failed with %d\n", rc
);
1247 rc
= ListView_InsertColumn(hwnd
, 1, &column
);
1248 ok(rc
== 1, "Inserting column failed with %d\n", rc
);
1250 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1252 rc
= SendMessage(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1253 ok(rc
!= 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1254 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1255 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1257 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1259 DestroyWindow(hwnd
);
1261 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1262 static WNDPROC listviewWndProc
;
1263 static HIMAGELIST test_create_imagelist
;
1265 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1269 if (uMsg
== WM_CREATE
)
1271 LPCREATESTRUCT lpcs
= (LPCREATESTRUCT
)lParam
;
1272 lpcs
->style
|= LVS_REPORT
;
1274 ret
= CallWindowProc(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1275 if (uMsg
== WM_CREATE
) SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1279 static void test_create(void)
1288 cls
.cbSize
= sizeof(WNDCLASSEX
);
1289 ok(GetClassInfoEx(GetModuleHandle(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1290 listviewWndProc
= cls
.lpfnWndProc
;
1291 cls
.lpfnWndProc
= create_test_wndproc
;
1292 cls
.lpszClassName
= "MyListView32";
1293 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
1295 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1296 hList
= CreateWindow("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1297 ok((HIMAGELIST
)SendMessage(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1298 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1299 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1300 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1301 DestroyWindow(hList
);
1303 /* header isn't created on LVS_ICON and LVS_LIST styles */
1304 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1305 GetModuleHandle(NULL
), 0);
1306 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1307 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1308 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1310 memset(&col
, 0, sizeof(LVCOLUMNA
));
1311 col
.mask
= LVCF_WIDTH
;
1313 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1314 ok(r
== 0, "Expected 0 column's inserted\n");
1315 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1316 ok(IsWindow(hHeader
), "Header should be created\n");
1317 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1318 DestroyWindow(hList
);
1320 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1321 GetModuleHandle(NULL
), 0);
1322 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1323 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1324 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1326 memset(&col
, 0, sizeof(LVCOLUMNA
));
1327 col
.mask
= LVCF_WIDTH
;
1329 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1330 ok(r
== 0, "Expected 0 column's inserted\n");
1331 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1332 ok(IsWindow(hHeader
), "Header should be created\n");
1333 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1334 DestroyWindow(hList
);
1336 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1337 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1338 GetModuleHandle(NULL
), 0);
1339 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLongPtr(hList
, GWL_STYLE
) | LVS_REPORT
);
1340 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1341 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1342 ok(IsWindow(hHeader
), "Header should be created\n");
1343 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLong(hList
, GWL_STYLE
) & ~LVS_REPORT
);
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 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1351 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1352 GetModuleHandle(NULL
), 0);
1353 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1354 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1355 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1356 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1357 ok(IsWindow(hHeader
), "Header should be created\n");
1358 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1359 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1360 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1361 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1362 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1363 ok(IsWindow(hHeader
), "Header should be created\n");
1364 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1365 DestroyWindow(hList
);
1367 /* LVS_REPORT without WS_VISIBLE */
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");
1374 memset(&col
, 0, sizeof(LVCOLUMNA
));
1375 col
.mask
= LVCF_WIDTH
;
1377 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1378 ok(r
== 0, "Expected 0 column's inserted\n");
1379 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1380 ok(IsWindow(hHeader
), "Header should be created\n");
1381 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1382 DestroyWindow(hList
);
1384 /* LVS_REPORT without WS_VISIBLE, try to show it */
1385 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1386 GetModuleHandle(NULL
), 0);
1387 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1388 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1389 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1390 ShowWindow(hList
, SW_SHOW
);
1391 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1392 ok(IsWindow(hHeader
), "Header should be created\n");
1393 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1394 DestroyWindow(hList
);
1396 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1397 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1398 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1399 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1400 ok(IsWindow(hHeader
), "Header should be created\n");
1401 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1402 /* HDS_DRAGDROP set by default */
1403 ok(GetWindowLongPtr(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1404 DestroyWindow(hList
);
1406 /* setting LVS_EX_HEADERDRAGDROP creates header */
1407 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1408 GetModuleHandle(NULL
), 0);
1409 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1410 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1411 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1412 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1413 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1414 ok(IsWindow(hHeader
) ||
1415 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1416 "Header should be created\n");
1417 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1418 DestroyWindow(hList
);
1420 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1421 hList
= create_custom_listview_control(0);
1422 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1423 r
= SendMessage(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1424 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1425 DestroyWindow(hList
);
1427 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1428 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1429 GetModuleHandle(NULL
), 0);
1430 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1431 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1433 rect
.left
= LVIR_BOUNDS
;
1435 rect
.right
= rect
.bottom
= -10;
1436 r
= SendMessage(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1437 ok(r
!= 0, "Expected not-null LRESULT\n");
1439 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1440 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1441 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1443 DestroyWindow(hList
);
1445 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1446 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1447 hList
= create_listview_control(LVS_OWNERDRAWFIXED
);
1448 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1449 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1450 DestroyWindow(hList
);
1453 static void test_redraw(void)
1455 HWND hwnd
, hwndheader
;
1460 hwnd
= create_listview_control(0);
1461 hwndheader
= subclass_header(hwnd
);
1463 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1465 trace("invalidate & update\n");
1466 InvalidateRect(hwnd
, NULL
, TRUE
);
1468 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1470 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1472 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1473 /* 1. Without backbuffer */
1474 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1477 hdc
= GetWindowDC(hwndparent
);
1479 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1480 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1481 ok(r
!= 0, "Expected not zero result\n");
1482 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1483 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1485 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1488 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1489 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1490 ok(r
!= 0, "Expected not zero result\n");
1491 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1492 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1494 /* 2. With backbuffer */
1495 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1496 LVS_EX_DOUBLEBUFFER
);
1497 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1500 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1501 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1502 ok(r
!= 0, "Expected not zero result\n");
1503 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1504 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1506 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1509 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1510 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1511 todo_wine
ok(r
!= 0, "Expected not zero result\n");
1512 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1513 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1515 ReleaseDC(hwndparent
, hdc
);
1517 DestroyWindow(hwnd
);
1520 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1522 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1524 if(msg
== WM_NOTIFY
) {
1525 NMHDR
*nmhdr
= (PVOID
)lp
;
1526 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1527 NMLVCUSTOMDRAW
*nmlvcd
= (PVOID
)nmhdr
;
1528 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd
->nmcd
.dwDrawStage
);
1529 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1531 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1532 return CDRF_NOTIFYITEMDRAW
;
1533 case CDDS_ITEMPREPAINT
:
1534 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1535 return CDRF_NOTIFYSUBITEMDRAW
;
1536 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1537 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1538 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1539 return CDRF_NOTIFYPOSTPAINT
;
1540 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1541 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1542 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1543 return CDRF_DODEFAULT
;
1545 return CDRF_DODEFAULT
;
1549 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1552 static void test_customdraw(void)
1557 hwnd
= create_listview_control(0);
1559 insert_column(hwnd
, 0);
1560 insert_column(hwnd
, 1);
1561 insert_item(hwnd
, 0);
1563 oldwndproc
= (WNDPROC
)SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
,
1564 (LONG_PTR
)cd_wndproc
);
1566 InvalidateRect(hwnd
, NULL
, TRUE
);
1569 SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1571 DestroyWindow(hwnd
);
1574 static void test_icon_spacing(void)
1576 /* LVM_SETICONSPACING */
1577 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1583 hwnd
= create_custom_listview_control(LVS_ICON
);
1584 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1586 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, (LPARAM
)NF_REQUERY
);
1587 expect(NFR_ANSI
, r
);
1589 /* reset the icon spacing to defaults */
1590 SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1592 /* now we can request what the defaults are */
1593 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1597 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1599 trace("test icon spacing\n");
1601 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1602 ok(r
== MAKELONG(w
, h
) ||
1603 broken(r
== MAKELONG(w
, w
)), /* win98 */
1604 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1606 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1607 expect(MAKELONG(20,30), r
);
1609 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1610 expect(MAKELONG(25,35), r
);
1612 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1614 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1615 DestroyWindow(hwnd
);
1618 static void test_color(void)
1620 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1627 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1629 hwnd
= create_listview_control(0);
1630 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1632 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1634 trace("test color seq\n");
1635 for (i
= 0; i
< 4; i
++)
1639 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1641 r
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, color
);
1644 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1646 r
= SendMessage(hwnd
, LVM_GETTEXTCOLOR
, 0, color
);
1649 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1651 r
= SendMessage(hwnd
, LVM_GETTEXTBKCOLOR
, 0, color
);
1655 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1657 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1658 DestroyWindow(hwnd
);
1661 static void test_item_count(void)
1663 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1676 static CHAR item0text
[] = "item0";
1677 static CHAR item1text
[] = "item1";
1678 static CHAR item2text
[] = "item2";
1680 hwnd
= create_listview_control(0);
1681 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1683 /* resize in dpiaware manner to fit all 3 items added */
1685 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1686 GetTextMetricsA(hdc
, &tm
);
1687 /* 2 extra pixels for bounds and header border */
1688 height
= tm
.tmHeight
+ 2;
1689 SelectObject(hdc
, hOldFont
);
1692 GetWindowRect(hwnd
, &rect
);
1693 /* 3 items + 1 header + 1 to be sure */
1694 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1696 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1698 trace("test item count\n");
1700 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1704 item0
.mask
= LVIF_TEXT
;
1707 item0
.pszText
= item0text
;
1708 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1711 /* [item0, item1] */
1712 item1
.mask
= LVIF_TEXT
;
1715 item1
.pszText
= item1text
;
1716 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1719 /* [item0, item1, item2] */
1720 item2
.mask
= LVIF_TEXT
;
1723 item2
.pszText
= item2text
;
1724 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1727 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1730 /* [item0, item1] */
1731 r
= SendMessage(hwnd
, LVM_DELETEITEM
, 2, 0);
1734 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1738 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1741 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1745 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1748 /* [item0, item1] */
1749 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1752 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1755 /* [item0, item1, item2] */
1756 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1759 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1762 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
1764 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1765 DestroyWindow(hwnd
);
1768 static void test_item_position(void)
1770 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1779 static CHAR item0text
[] = "item0";
1780 static CHAR item1text
[] = "item1";
1781 static CHAR item2text
[] = "item2";
1783 hwnd
= create_custom_listview_control(LVS_ICON
);
1784 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1786 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1788 trace("test item position\n");
1791 item0
.mask
= LVIF_TEXT
;
1794 item0
.pszText
= item0text
;
1795 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1798 /* [item0, item1] */
1799 item1
.mask
= LVIF_TEXT
;
1802 item1
.pszText
= item1text
;
1803 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1806 /* [item0, item1, item2] */
1807 item2
.mask
= LVIF_TEXT
;
1810 item2
.pszText
= item2text
;
1811 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1814 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
1816 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
1818 expect2(10, 5, position
.x
, position
.y
);
1820 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
1822 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
1824 expect2(0, 0, position
.x
, position
.y
);
1826 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
1828 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
1830 expect2(20, 20, position
.x
, position
.y
);
1832 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
1834 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1835 DestroyWindow(hwnd
);
1838 static void test_getorigin(void)
1846 position
.x
= position
.y
= 0;
1848 hwnd
= create_custom_listview_control(LVS_ICON
);
1849 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1850 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1851 trace("test get origin results\n");
1852 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1854 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1855 DestroyWindow(hwnd
);
1857 hwnd
= create_custom_listview_control(LVS_SMALLICON
);
1858 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1859 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1860 trace("test get origin results\n");
1861 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1863 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1864 DestroyWindow(hwnd
);
1866 hwnd
= create_custom_listview_control(LVS_LIST
);
1867 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1868 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1869 trace("test get origin results\n");
1870 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1872 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1873 DestroyWindow(hwnd
);
1875 hwnd
= create_custom_listview_control(LVS_REPORT
);
1876 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1877 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1878 trace("test get origin results\n");
1879 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1881 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1882 DestroyWindow(hwnd
);
1886 static void test_multiselect(void)
1888 typedef struct t_select_task
1899 int i
,j
,item_count
,selected_count
;
1900 static const int items
=5;
1906 static struct t_select_task task_list
[] = {
1907 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
1908 { "using VK_UP", -1, VK_UP
, -1, -1 },
1909 { "using VK_END", 0, VK_END
, 1, -1 },
1910 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
1914 hwnd
= create_listview_control(0);
1916 for (i
=0;i
<items
;i
++) {
1917 insert_item(hwnd
, 0);
1920 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1922 expect(items
,item_count
);
1925 task
= task_list
[i
];
1927 /* deselect all items */
1928 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1929 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1931 /* set initial position */
1932 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
1933 ListView_SetItemState(hwnd
,(task
.initPos
== -1 ? item_count
-1 : task
.initPos
),LVIS_SELECTED
,LVIS_SELECTED
);
1935 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1937 ok(selected_count
== 1, "There should be only one selected item at the beginning (is %d)\n",selected_count
);
1939 /* Set SHIFT key pressed */
1940 GetKeyboardState(kstate
);
1941 kstate
[VK_SHIFT
]=0x80;
1942 SetKeyboardState(kstate
);
1944 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
1945 r
= SendMessage(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
1947 r
= SendMessage(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
1951 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1953 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
);
1955 /* Set SHIFT key released */
1956 GetKeyboardState(kstate
);
1957 kstate
[VK_SHIFT
]=0x00;
1958 SetKeyboardState(kstate
);
1960 DestroyWindow(hwnd
);
1962 /* make multiple selection, then switch to LVS_SINGLESEL */
1963 hwnd
= create_listview_control(0);
1964 for (i
=0;i
<items
;i
++) {
1965 insert_item(hwnd
, 0);
1967 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1968 expect(items
,item_count
);
1970 /* try with NULL pointer */
1971 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)NULL
);
1974 /* select all, check notifications */
1975 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1977 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1979 item
.stateMask
= LVIS_SELECTED
;
1980 item
.state
= LVIS_SELECTED
;
1981 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
1984 ok_sequence(sequences
, PARENT_SEQ_INDEX
, select_all_parent_seq
,
1985 "select all notification", FALSE
);
1987 /* deselect all items */
1988 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1989 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1991 ListView_SetItemState(hwnd
, i
, LVIS_SELECTED
, LVIS_SELECTED
);
1994 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1996 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
1999 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2000 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2001 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2002 /* check that style is accepted */
2003 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2004 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2007 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2008 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2010 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2012 SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2015 /* select one more */
2016 ListView_SetItemState(hwnd
, 3, LVIS_SELECTED
, LVIS_SELECTED
);
2019 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2020 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2022 r
= ListView_GetItemState(hwnd
, 3, LVIS_SELECTED
);
2023 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2025 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2027 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2030 /* try to select all on LVS_SINGLESEL */
2031 memset(&item
, 0, sizeof(item
));
2032 item
.stateMask
= LVIS_SELECTED
;
2033 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2035 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2037 item
.stateMask
= LVIS_SELECTED
;
2038 item
.state
= LVIS_SELECTED
;
2039 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2042 r
= ListView_GetSelectedCount(hwnd
);
2044 r
= ListView_GetSelectionMark(hwnd
);
2047 /* try to deselect all on LVS_SINGLESEL */
2048 item
.stateMask
= LVIS_SELECTED
;
2049 item
.state
= LVIS_SELECTED
;
2050 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2053 item
.stateMask
= LVIS_SELECTED
;
2055 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2057 r
= ListView_GetSelectedCount(hwnd
);
2060 DestroyWindow(hwnd
);
2063 static void test_subitem_rect(void)
2070 /* test LVM_GETSUBITEMRECT for header */
2071 hwnd
= create_listview_control(0);
2072 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2073 /* add some columns */
2074 memset(&col
, 0, sizeof(LVCOLUMN
));
2075 col
.mask
= LVCF_WIDTH
;
2078 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2082 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2086 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2088 /* item = -1 means header, subitem index is 1 based */
2089 rect
.left
= LVIR_BOUNDS
;
2091 rect
.right
= rect
.bottom
= 0;
2092 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2095 rect
.left
= LVIR_BOUNDS
;
2097 rect
.right
= rect
.bottom
= 0;
2098 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2100 ok(r
!= 0, "Expected not-null LRESULT\n");
2101 expect(100, rect
.left
);
2102 expect(250, rect
.right
);
2104 expect(3, rect
.top
);
2106 rect
.left
= LVIR_BOUNDS
;
2108 rect
.right
= rect
.bottom
= 0;
2109 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2111 ok(r
!= 0, "Expected not-null LRESULT\n");
2112 expect(250, rect
.left
);
2113 expect(450, rect
.right
);
2115 expect(3, rect
.top
);
2117 /* item LVS_REPORT padding isn't applied to subitems */
2118 insert_item(hwnd
, 0);
2120 rect
.left
= LVIR_BOUNDS
;
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 expect(100, rect
.left
);
2126 expect(250, rect
.right
);
2128 rect
.left
= LVIR_ICON
;
2130 rect
.right
= rect
.bottom
= 0;
2131 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2132 ok(r
!= 0, "Expected not-null LRESULT\n");
2133 /* no icon attached - zero width rectangle, with no left padding */
2134 expect(100, rect
.left
);
2135 expect(100, rect
.right
);
2137 rect
.left
= LVIR_LABEL
;
2139 rect
.right
= rect
.bottom
= 0;
2140 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2141 ok(r
!= 0, "Expected not-null LRESULT\n");
2142 /* same as full LVIR_BOUNDS */
2143 expect(100, rect
.left
);
2144 expect(250, rect
.right
);
2146 DestroyWindow(hwnd
);
2148 /* try it for non LVS_REPORT style */
2149 hwnd
= CreateWindow("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2150 GetModuleHandle(NULL
), 0);
2151 rect
.left
= LVIR_BOUNDS
;
2153 rect
.right
= rect
.bottom
= -10;
2154 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2155 ok(r
== 0, "Expected not-null LRESULT\n");
2156 /* rect is unchanged */
2157 expect(0, rect
.left
);
2158 expect(-10, rect
.right
);
2159 expect(1, rect
.top
);
2160 expect(-10, rect
.bottom
);
2161 DestroyWindow(hwnd
);
2164 /* comparison callback for test_sorting */
2165 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2167 if (first
== second
) return 0;
2168 return (first
> second
? 1 : -1);
2171 static void test_sorting(void)
2177 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2180 hwnd
= create_listview_control(0);
2181 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2183 /* insert some items */
2184 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2185 item
.state
= LVIS_SELECTED
;
2189 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2192 item
.mask
= LVIF_PARAM
;
2196 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2199 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2200 item
.state
= LVIS_SELECTED
;
2204 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2207 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2210 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2213 r
= SendMessage(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2216 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2218 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2220 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2222 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2223 expect(LVIS_SELECTED
, r
);
2224 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2225 expect(LVIS_SELECTED
, r
);
2227 DestroyWindow(hwnd
);
2229 /* switch to LVS_SORTASCENDING when some items added */
2230 hwnd
= create_listview_control(0);
2231 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2233 item
.mask
= LVIF_TEXT
;
2236 item
.pszText
= names
[1];
2237 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2240 item
.mask
= LVIF_TEXT
;
2243 item
.pszText
= names
[2];
2244 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2247 item
.mask
= LVIF_TEXT
;
2250 item
.pszText
= names
[0];
2251 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2254 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2255 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2256 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2257 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2259 /* no sorting performed when switched to LVS_SORTASCENDING */
2260 item
.mask
= LVIF_TEXT
;
2262 item
.pszText
= buff
;
2263 item
.cchTextMax
= sizeof(buff
);
2264 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2266 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2269 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2271 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2274 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2276 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2278 /* adding new item doesn't resort list */
2279 item
.mask
= LVIF_TEXT
;
2282 item
.pszText
= names
[3];
2283 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2286 item
.mask
= LVIF_TEXT
;
2288 item
.pszText
= buff
;
2289 item
.cchTextMax
= sizeof(buff
);
2290 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2292 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2295 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2297 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2300 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2302 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2305 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2307 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2309 /* corner case - item should be placed at first position */
2310 item
.mask
= LVIF_TEXT
;
2313 item
.pszText
= names
[4];
2314 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2318 item
.pszText
= buff
;
2319 item
.cchTextMax
= sizeof(buff
);
2320 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2322 ok(lstrcmp(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2325 item
.pszText
= buff
;
2326 item
.cchTextMax
= sizeof(buff
);
2327 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2329 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2332 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2334 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2337 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2339 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2342 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2344 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2346 DestroyWindow(hwnd
);
2349 static void test_ownerdata(void)
2352 LONG_PTR style
, ret
;
2356 /* it isn't possible to set LVS_OWNERDATA after creation */
2359 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2363 hwnd
= create_listview_control(0);
2364 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2365 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2366 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2368 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2370 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2371 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2372 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2373 "try to switch to LVS_OWNERDATA seq", FALSE
);
2375 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2376 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2377 DestroyWindow(hwnd
);
2380 /* try to set LVS_OWNERDATA after creation just having it */
2381 hwnd
= create_listview_control(LVS_OWNERDATA
);
2382 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2383 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2384 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2386 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2388 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2389 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2390 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2391 "try to switch to LVS_OWNERDATA seq", FALSE
);
2392 DestroyWindow(hwnd
);
2394 /* try to remove LVS_OWNERDATA after creation just having it */
2397 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2401 hwnd
= create_listview_control(LVS_OWNERDATA
);
2402 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2403 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2404 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2406 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2408 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2409 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2410 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2411 "try to switch to LVS_OWNERDATA seq", FALSE
);
2412 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2413 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2414 DestroyWindow(hwnd
);
2417 /* try select an item */
2418 hwnd
= create_listview_control(LVS_OWNERDATA
);
2419 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2420 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2421 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2422 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2424 memset(&item
, 0, sizeof(item
));
2425 item
.stateMask
= LVIS_SELECTED
;
2426 item
.state
= LVIS_SELECTED
;
2427 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2429 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2431 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2433 DestroyWindow(hwnd
);
2435 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2436 hwnd
= create_listview_control(LVS_OWNERDATA
);
2437 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2438 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2439 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2440 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2442 memset(&item
, 0, sizeof(item
));
2443 item
.mask
= LVIF_STATE
;
2445 item
.stateMask
= LVIS_SELECTED
;
2446 item
.state
= LVIS_SELECTED
;
2447 res
= SendMessageA(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2449 DestroyWindow(hwnd
);
2451 /* check notifications after focused/selected changed */
2452 hwnd
= create_listview_control(LVS_OWNERDATA
);
2453 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2454 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
2455 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2457 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2459 memset(&item
, 0, sizeof(item
));
2460 item
.stateMask
= LVIS_SELECTED
;
2461 item
.state
= LVIS_SELECTED
;
2462 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2465 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2466 "ownerdata select notification", TRUE
);
2468 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2470 memset(&item
, 0, sizeof(item
));
2471 item
.stateMask
= LVIS_FOCUSED
;
2472 item
.state
= LVIS_FOCUSED
;
2473 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2476 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2477 "ownerdata focus notification", TRUE
);
2479 /* select all, check notifications */
2480 item
.stateMask
= LVIS_SELECTED
;
2482 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2485 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2487 item
.stateMask
= LVIS_SELECTED
;
2488 item
.state
= LVIS_SELECTED
;
2490 g_dump_itemchanged
= TRUE
;
2491 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2493 g_dump_itemchanged
= FALSE
;
2495 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2496 "ownerdata select all notification", TRUE
);
2498 /* select all again, note that all items are selected already */
2499 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2500 item
.stateMask
= LVIS_SELECTED
;
2501 item
.state
= LVIS_SELECTED
;
2502 g_dump_itemchanged
= TRUE
;
2503 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2505 g_dump_itemchanged
= FALSE
;
2506 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2507 "ownerdata select all notification", TRUE
);
2509 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2510 item
.stateMask
= LVIS_SELECTED
;
2512 g_dump_itemchanged
= TRUE
;
2513 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2515 g_dump_itemchanged
= FALSE
;
2516 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2517 "ownerdata deselect all notification", TRUE
);
2519 /* select one, then deselect all */
2520 item
.stateMask
= LVIS_SELECTED
;
2521 item
.state
= LVIS_SELECTED
;
2522 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2524 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2525 item
.stateMask
= LVIS_SELECTED
;
2527 g_dump_itemchanged
= TRUE
;
2528 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2530 g_dump_itemchanged
= FALSE
;
2531 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2532 "ownerdata select all notification", TRUE
);
2534 /* remove focused, try to focus all */
2535 item
.stateMask
= LVIS_FOCUSED
;
2536 item
.state
= LVIS_FOCUSED
;
2537 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2539 item
.stateMask
= LVIS_FOCUSED
;
2541 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2543 item
.stateMask
= LVIS_FOCUSED
;
2544 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
2546 /* setting all to focused returns failure value */
2547 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2548 item
.stateMask
= LVIS_FOCUSED
;
2549 item
.state
= LVIS_FOCUSED
;
2550 g_dump_itemchanged
= TRUE
;
2551 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2553 g_dump_itemchanged
= FALSE
;
2554 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2555 "ownerdata focus all notification", FALSE
);
2556 /* focus single item, remove all */
2557 item
.stateMask
= LVIS_FOCUSED
;
2558 item
.state
= LVIS_FOCUSED
;
2559 res
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2561 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2562 item
.stateMask
= LVIS_FOCUSED
;
2564 g_dump_itemchanged
= TRUE
;
2565 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2567 g_dump_itemchanged
= FALSE
;
2568 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
2569 "ownerdata remove focus all notification", TRUE
);
2571 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2572 item
.stateMask
= LVIS_CUT
;
2573 item
.state
= LVIS_CUT
;
2574 g_dump_itemchanged
= TRUE
;
2575 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2577 g_dump_itemchanged
= FALSE
;
2578 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2579 "ownerdata cut all notification", TRUE
);
2580 /* all marked cut, try again */
2581 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2582 item
.stateMask
= LVIS_CUT
;
2583 item
.state
= LVIS_CUT
;
2584 g_dump_itemchanged
= TRUE
;
2585 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2587 g_dump_itemchanged
= FALSE
;
2588 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2589 "ownerdata cut all notification #2", TRUE
);
2591 DestroyWindow(hwnd
);
2593 /* check notifications on LVM_GETITEM */
2594 /* zero callback mask */
2595 hwnd
= create_listview_control(LVS_OWNERDATA
);
2596 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2597 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2598 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2600 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2602 memset(&item
, 0, sizeof(item
));
2603 item
.stateMask
= LVIS_SELECTED
;
2604 item
.mask
= LVIF_STATE
;
2605 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2608 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2609 "ownerdata getitem selected state 1", FALSE
);
2611 /* non zero callback mask but not we asking for */
2612 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
2615 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2617 memset(&item
, 0, sizeof(item
));
2618 item
.stateMask
= LVIS_SELECTED
;
2619 item
.mask
= LVIF_STATE
;
2620 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2623 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2624 "ownerdata getitem selected state 2", FALSE
);
2626 /* LVIS_OVERLAYMASK callback mask, asking for index */
2627 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2629 memset(&item
, 0, sizeof(item
));
2630 item
.stateMask
= LVIS_OVERLAYMASK
;
2631 item
.mask
= LVIF_STATE
;
2632 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2635 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
2636 "ownerdata getitem selected state 2", FALSE
);
2638 DestroyWindow(hwnd
);
2640 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2641 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
);
2642 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2643 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2644 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2645 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2646 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
2647 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2648 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
2649 DestroyWindow(hwnd
);
2650 /* apparently it's allowed to switch these style on after creation */
2651 hwnd
= create_listview_control(LVS_OWNERDATA
);
2652 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2653 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2654 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2655 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2656 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2657 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2658 DestroyWindow(hwnd
);
2660 hwnd
= create_listview_control(LVS_OWNERDATA
);
2661 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2662 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2663 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2664 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
2665 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2666 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
2667 DestroyWindow(hwnd
);
2670 static void test_norecompute(void)
2672 static CHAR testA
[] = "test";
2678 /* self containing control */
2679 hwnd
= create_listview_control(0);
2680 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2681 memset(&item
, 0, sizeof(item
));
2682 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
2684 item
.stateMask
= LVIS_SELECTED
;
2685 item
.state
= LVIS_SELECTED
;
2686 item
.pszText
= testA
;
2687 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2689 /* retrieve with LVIF_NORECOMPUTE */
2690 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2692 item
.pszText
= buff
;
2693 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2694 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2696 ok(lstrcmp(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
2698 item
.mask
= LVIF_TEXT
;
2700 item
.pszText
= LPSTR_TEXTCALLBACK
;
2701 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2704 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2706 item
.pszText
= buff
;
2707 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2709 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2710 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2712 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2713 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2714 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
2716 DestroyWindow(hwnd
);
2719 hwnd
= create_listview_control(LVS_OWNERDATA
);
2720 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2722 item
.mask
= LVIF_STATE
;
2723 item
.stateMask
= LVIS_SELECTED
;
2724 item
.state
= LVIS_SELECTED
;
2726 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2729 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2731 item
.pszText
= buff
;
2732 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2733 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2734 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2736 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2737 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2738 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
2740 DestroyWindow(hwnd
);
2743 static void test_nosortheader(void)
2748 hwnd
= create_listview_control(0);
2749 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2751 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2752 ok(IsWindow(header
), "header expected\n");
2754 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2755 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
2757 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2758 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
2759 /* HDS_BUTTONS retained */
2760 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2761 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
2763 DestroyWindow(hwnd
);
2765 /* create with LVS_NOSORTHEADER */
2766 hwnd
= create_listview_control(LVS_NOSORTHEADER
);
2767 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2769 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2770 ok(IsWindow(header
), "header expected\n");
2772 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2773 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2775 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2776 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
2777 /* not changed here */
2778 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2779 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2781 DestroyWindow(hwnd
);
2784 static void test_setredraw(void)
2790 hwnd
= create_listview_control(0);
2791 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2793 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2794 ListView seems to handle it internally without DefWinProc */
2796 /* default value first */
2797 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2800 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2801 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2802 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2804 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2805 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2807 DestroyWindow(hwnd
);
2810 static void test_hittest(void)
2816 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2819 HIMAGELIST himl
, himl2
;
2822 hwnd
= create_listview_control(0);
2823 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2825 /* LVS_REPORT with a single subitem (2 columns) */
2826 insert_column(hwnd
, 0);
2827 insert_column(hwnd
, 1);
2828 insert_item(hwnd
, 0);
2831 /* the only purpose of that line is to be as long as a half item rect */
2832 item
.pszText
= text
;
2833 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
2836 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
2838 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
2841 memset(&bounds
, 0, sizeof(bounds
));
2842 bounds
.left
= LVIR_BOUNDS
;
2843 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
2844 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
2845 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
2846 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
2849 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2850 x
= pos
.x
+ 50; /* column half width */
2851 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2852 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, __LINE__
);
2853 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2854 x
= pos
.x
+ 150; /* outside column */
2855 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2856 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2857 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2858 y
= (bounds
.bottom
- bounds
.top
) / 2;
2859 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, TRUE
, __LINE__
);
2860 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2861 /* outside possible client rectangle (to right) */
2863 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2864 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2865 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2866 y
= (bounds
.bottom
- bounds
.top
) / 2;
2867 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, TRUE
, __LINE__
);
2868 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2869 /* subitem returned with -1 item too */
2872 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2873 /* parent client area is 100x100 by default */
2874 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
2875 x
= pos
.x
+ 150; /* outside column */
2876 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2877 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, FALSE
, FALSE
, __LINE__
);
2878 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2879 y
= (bounds
.bottom
- bounds
.top
) / 2;
2880 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, FALSE
, TRUE
, __LINE__
);
2881 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2882 /* the same with LVS_EX_FULLROWSELECT */
2883 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
2884 x
= pos
.x
+ 150; /* outside column */
2885 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2886 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, FALSE
, FALSE
, __LINE__
);
2887 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2888 y
= (bounds
.bottom
- bounds
.top
) / 2;
2889 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2890 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
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
, 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
, 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
, 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
, FALSE
, TRUE
, __LINE__
);
2905 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2906 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2907 himl
= ImageList_Create(16, 16, 0, 4, 4);
2908 ok(himl
!= NULL
, "failed to create imagelist\n");
2909 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
2910 ok(hbmp
!= NULL
, "failed to create bitmap\n");
2911 r
= ImageList_Add(himl
, hbmp
, 0);
2912 ok(r
== 0, "should be zero\n");
2913 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
2914 ok(hbmp
!= NULL
, "failed to create bitmap\n");
2915 r
= ImageList_Add(himl
, hbmp
, 0);
2916 ok(r
== 1, "should be one\n");
2918 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
2919 ok(r
== 0, "should return zero\n");
2921 item
.mask
= LVIF_IMAGE
;
2925 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2929 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2930 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, __LINE__
);
2931 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2932 y
= (bounds
.bottom
- bounds
.top
) / 2;
2933 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2935 /* state icons indices are 1 based, check with valid index */
2936 item
.mask
= LVIF_STATE
;
2937 item
.state
= INDEXTOSTATEIMAGEMASK(1);
2938 item
.stateMask
= LVIS_STATEIMAGEMASK
;
2941 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2945 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2946 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, __LINE__
);
2947 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2948 y
= (bounds
.bottom
- bounds
.top
) / 2;
2949 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2951 himl2
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)NULL
);
2952 ok(himl2
== himl
, "should return handle\n");
2954 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
2955 ok(r
== 0, "should return zero\n");
2958 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2959 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, __LINE__
);
2960 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2961 y
= (bounds
.bottom
- bounds
.top
) / 2;
2962 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2964 DestroyWindow(hwnd
);
2967 static void test_getviewrect(void)
2974 hwnd
= create_listview_control(0);
2975 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2978 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
2981 insert_column(hwnd
, 0);
2982 insert_column(hwnd
, 1);
2984 memset(&item
, 0, sizeof(item
));
2987 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
2989 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
2991 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
2994 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
2995 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
2997 /* left is set to (2e31-1) - XP SP2 */
2998 expect(0, rect
.right
);
2999 expect(0, rect
.top
);
3000 expect(0, rect
.bottom
);
3002 /* switch to LVS_ICON */
3003 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3005 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3006 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3008 expect(0, rect
.left
);
3009 expect(0, rect
.top
);
3010 /* precise value differs for 2k, XP and Vista */
3011 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3012 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3014 DestroyWindow(hwnd
);
3017 static void test_getitemposition(void)
3024 hwnd
= create_listview_control(0);
3025 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3026 header
= subclass_header(hwnd
);
3028 /* LVS_REPORT, single item, no columns added */
3029 insert_item(hwnd
, 0);
3031 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3034 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3036 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3038 /* LVS_REPORT, single item, single column */
3039 insert_column(hwnd
, 0);
3041 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3044 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3046 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3048 memset(&rect
, 0, sizeof(rect
));
3049 SendMessage(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3052 /* offset by header height */
3053 expect(rect
.bottom
- rect
.top
, pt
.y
);
3055 DestroyWindow(hwnd
);
3058 static void test_columnscreation(void)
3063 hwnd
= create_listview_control(0);
3064 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3066 insert_item(hwnd
, 0);
3068 /* headers columns aren't created automatically */
3069 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3070 ok(IsWindow(header
), "Expected header handle\n");
3071 r
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
3074 DestroyWindow(hwnd
);
3077 static void test_getitemrect(void)
3089 hwnd
= create_listview_control(0);
3090 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3093 memset(&item
, 0, sizeof(item
));
3096 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3099 rect
.left
= LVIR_BOUNDS
;
3100 rect
.right
= rect
.top
= rect
.bottom
= -1;
3101 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3104 /* zero width rectangle with no padding */
3105 expect(0, rect
.left
);
3106 expect(0, rect
.right
);
3108 insert_column(hwnd
, 0);
3109 insert_column(hwnd
, 1);
3111 col
.mask
= LVCF_WIDTH
;
3113 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 0, (LPARAM
)&col
);
3116 col
.mask
= LVCF_WIDTH
;
3118 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 1, (LPARAM
)&col
);
3121 rect
.left
= LVIR_BOUNDS
;
3122 rect
.right
= rect
.top
= rect
.bottom
= -1;
3123 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3126 /* still no left padding */
3127 expect(0, rect
.left
);
3128 expect(150, rect
.right
);
3130 rect
.left
= LVIR_SELECTBOUNDS
;
3131 rect
.right
= rect
.top
= rect
.bottom
= -1;
3132 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3135 expect(2, rect
.left
);
3137 rect
.left
= LVIR_LABEL
;
3138 rect
.right
= rect
.top
= rect
.bottom
= -1;
3139 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3141 /* padding, column width */
3142 expect(2, rect
.left
);
3143 expect(50, rect
.right
);
3145 /* no icons attached */
3146 rect
.left
= LVIR_ICON
;
3147 rect
.right
= rect
.top
= rect
.bottom
= -1;
3148 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3151 expect(2, rect
.left
);
3152 expect(2, rect
.right
);
3155 order
[0] = 1; order
[1] = 0;
3156 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3159 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3161 /* 1 indexed column width + padding */
3163 /* rect is at zero too */
3164 rect
.left
= LVIR_BOUNDS
;
3165 rect
.right
= rect
.top
= rect
.bottom
= -1;
3166 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3168 expect(0, rect
.left
);
3169 /* just width sum */
3170 expect(150, rect
.right
);
3172 rect
.left
= LVIR_SELECTBOUNDS
;
3173 rect
.right
= rect
.top
= rect
.bottom
= -1;
3174 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3176 /* column width + padding */
3177 expect(102, rect
.left
);
3179 /* back to initial order */
3180 order
[0] = 0; order
[1] = 1;
3181 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3185 himl
= ImageList_Create(16, 16, 0, 2, 2);
3186 ok(himl
!= NULL
, "failed to create imagelist\n");
3187 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3188 ok(hbm
!= NULL
, "failed to create bitmap\n");
3189 r
= ImageList_Add(himl
, hbm
, 0);
3190 ok(r
== 0, "should be zero\n");
3191 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3192 ok(hbm
!= NULL
, "failed to create bitmap\n");
3193 r
= ImageList_Add(himl
, hbm
, 0);
3194 ok(r
== 1, "should be one\n");
3196 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3197 ok(r
== 0, "should return zero\n");
3199 item
.mask
= LVIF_STATE
;
3200 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3201 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3204 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3208 rect
.left
= LVIR_ICON
;
3209 rect
.right
= rect
.top
= rect
.bottom
= -1;
3210 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3212 /* padding + stateicon width */
3213 expect(18, rect
.left
);
3214 expect(18, rect
.right
);
3216 rect
.left
= LVIR_LABEL
;
3217 rect
.right
= rect
.top
= rect
.bottom
= -1;
3218 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3220 /* padding + stateicon width -> column width */
3221 expect(18, rect
.left
);
3222 expect(50, rect
.right
);
3224 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)NULL
);
3225 ok(r
!= 0, "should return current list handle\n");
3227 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3228 ok(r
== 0, "should return zero\n");
3230 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3233 item
.stateMask
= ~0;
3236 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3240 rect
.left
= LVIR_ICON
;
3241 rect
.right
= rect
.top
= rect
.bottom
= -1;
3242 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3244 /* padding, icon width */
3245 expect(2, rect
.left
);
3246 expect(18, rect
.right
);
3248 rect
.left
= LVIR_LABEL
;
3249 rect
.right
= rect
.top
= rect
.bottom
= -1;
3250 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3252 /* padding + icon width -> column width */
3253 expect(18, rect
.left
);
3254 expect(50, rect
.right
);
3257 rect
.left
= LVIR_SELECTBOUNDS
;
3258 rect
.right
= rect
.top
= rect
.bottom
= -1;
3259 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3261 /* padding, column width */
3262 expect(2, rect
.left
);
3263 expect(50, rect
.right
);
3265 /* try with indentation */
3266 item
.mask
= LVIF_INDENT
;
3270 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3274 rect
.left
= LVIR_BOUNDS
;
3275 rect
.right
= rect
.top
= rect
.bottom
= -1;
3276 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3278 /* padding + 1 icon width, column width */
3279 expect(0, rect
.left
);
3280 expect(150, rect
.right
);
3283 rect
.left
= LVIR_SELECTBOUNDS
;
3284 rect
.right
= rect
.top
= rect
.bottom
= -1;
3285 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3287 /* padding + 1 icon width, column width */
3288 expect(2 + 16, rect
.left
);
3289 expect(50, rect
.right
);
3292 rect
.left
= LVIR_LABEL
;
3293 rect
.right
= rect
.top
= rect
.bottom
= -1;
3294 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3296 /* padding + 2 icon widths, column width */
3297 expect(2 + 16*2, rect
.left
);
3298 expect(50, rect
.right
);
3301 rect
.left
= LVIR_ICON
;
3302 rect
.right
= rect
.top
= rect
.bottom
= -1;
3303 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3305 /* padding + 1 icon width indentation, icon width */
3306 expect(2 + 16, rect
.left
);
3307 expect(34, rect
.right
);
3310 DestroyWindow(hwnd
);
3313 static void test_editbox(void)
3315 HWND hwnd
, hwndedit
, hwndedit2
;
3318 static CHAR testitemA
[] = "testitem";
3319 static CHAR testitem1A
[] = "testitem1";
3320 static CHAR buffer
[10];
3322 hwnd
= create_listview_control(LVS_EDITLABELS
);
3323 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3325 insert_column(hwnd
, 0);
3327 memset(&item
, 0, sizeof(item
));
3328 item
.mask
= LVIF_TEXT
;
3329 item
.pszText
= testitemA
;
3332 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3335 /* setting focus is necessary */
3337 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3338 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3340 /* modify initial string */
3341 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3343 /* return focus to listview */
3346 memset(&item
, 0, sizeof(item
));
3347 item
.mask
= LVIF_TEXT
;
3348 item
.pszText
= buffer
;
3349 item
.cchTextMax
= 10;
3352 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3355 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3357 /* send LVM_EDITLABEL on already created edit */
3359 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3360 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3361 /* focus will be set to edit */
3362 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
3363 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3364 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
3366 /* creating label disabled when control isn't focused */
3368 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3369 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3371 /* check EN_KILLFOCUS handling */
3372 memset(&item
, 0, sizeof(item
));
3373 item
.pszText
= testitemA
;
3376 r
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3380 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3381 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3382 /* modify edit and notify control that it lost focus */
3383 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3385 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3387 memset(&item
, 0, sizeof(item
));
3388 item
.pszText
= buffer
;
3389 item
.cchTextMax
= 10;
3392 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3393 expect(lstrlen(item
.pszText
), r
);
3394 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3395 /* end edit without saving */
3396 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
3398 memset(&item
, 0, sizeof(item
));
3399 item
.pszText
= buffer
;
3400 item
.cchTextMax
= 10;
3403 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3404 expect(lstrlen(item
.pszText
), r
);
3405 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3407 /* LVM_EDITLABEL with -1 destroys current edit */
3408 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
3409 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3410 /* no edit present */
3411 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3412 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3413 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3414 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3416 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3417 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3418 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3419 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3420 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3421 /* check another negative value */
3422 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3423 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3424 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3425 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -2, 0);
3426 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3427 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3428 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3429 /* and value greater than max item index */
3430 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3431 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3432 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3433 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3434 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, r
, 0);
3435 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3436 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3437 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3439 /* messaging tests */
3441 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3443 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3444 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3445 /* testing only sizing messages */
3446 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
3447 "edit box create - sizing", FALSE
);
3449 DestroyWindow(hwnd
);
3452 static void test_notifyformat(void)
3457 hwnd
= create_listview_control(0);
3458 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3460 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3461 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3462 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3464 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3466 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
3468 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3471 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
3473 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3478 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3479 DestroyWindow(hwnd
);
3483 DestroyWindow(hwnd
);
3485 /* test failure in parent WM_NOTIFYFORMAT */
3487 hwnd
= create_listview_control(0);
3488 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3489 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3490 ok(IsWindow(header
), "expected header to be created\n");
3491 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3493 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3495 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3496 ok(r
!= 0, "Expected valid format\n");
3498 notifyFormat
= NFR_UNICODE
;
3499 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3500 expect(NFR_UNICODE
, r
);
3501 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3503 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3506 notifyFormat
= NFR_ANSI
;
3507 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3508 expect(NFR_ANSI
, r
);
3509 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3511 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3514 DestroyWindow(hwnd
);
3516 /* try different unicode window combination and defaults */
3517 if (!GetModuleHandleW(NULL
))
3519 win_skip("Additional notify format tests are incompatible with Win9x\n");
3523 hwndparentW
= create_parent_window(TRUE
);
3524 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
3525 if (!IsWindow(hwndparentW
)) return;
3528 hwnd
= create_listview_controlW(0, hwndparentW
);
3529 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3530 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3531 ok(IsWindow(header
), "expected header to be created\n");
3532 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3534 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3536 DestroyWindow(hwnd
);
3537 /* receiving error code defaulting to ansi */
3539 hwnd
= create_listview_controlW(0, hwndparentW
);
3540 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3541 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3542 ok(IsWindow(header
), "expected header to be created\n");
3543 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3545 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3547 DestroyWindow(hwnd
);
3548 /* receiving ansi code from unicode window, use it */
3549 notifyFormat
= NFR_ANSI
;
3550 hwnd
= create_listview_controlW(0, hwndparentW
);
3551 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3552 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3553 ok(IsWindow(header
), "expected header to be created\n");
3554 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3556 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3558 DestroyWindow(hwnd
);
3559 /* unicode listview with ansi parent window */
3561 hwnd
= create_listview_controlW(0, hwndparent
);
3562 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3563 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3564 ok(IsWindow(header
), "expected header to be created\n");
3565 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3567 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3569 DestroyWindow(hwnd
);
3570 /* unicode listview with ansi parent window, return error code */
3572 hwnd
= create_listview_controlW(0, hwndparent
);
3573 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3574 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3575 ok(IsWindow(header
), "expected header to be created\n");
3576 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3578 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3580 DestroyWindow(hwnd
);
3582 DestroyWindow(hwndparentW
);
3585 static void test_indentation(void)
3591 hwnd
= create_listview_control(0);
3592 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3594 memset(&item
, 0, sizeof(item
));
3595 item
.mask
= LVIF_INDENT
;
3597 item
.iIndent
= I_INDENTCALLBACK
;
3598 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3601 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3604 item
.mask
= LVIF_INDENT
;
3605 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3608 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3609 "get indent dispinfo", FALSE
);
3611 DestroyWindow(hwnd
);
3614 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
3619 static BOOL
is_below_comctl_5(void)
3624 hwnd
= create_listview_control(0);
3625 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3626 insert_item(hwnd
, 0);
3628 ret
= SendMessage(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
3630 DestroyWindow(hwnd
);
3635 static void unload_v6_module(ULONG_PTR cookie
)
3638 BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
, ULONG_PTR
);
3640 hKernel32
= GetModuleHandleA("kernel32.dll");
3641 pDeactivateActCtx
= (void*)GetProcAddress(hKernel32
, "DeactivateActCtx");
3642 if (!pDeactivateActCtx
)
3644 win_skip("Activation contexts unsupported\n");
3648 pDeactivateActCtx(0, cookie
);
3650 DeleteFileA(manifest_name
);
3653 static BOOL
load_v6_module(ULONG_PTR
*pcookie
)
3656 HANDLE (WINAPI
*pCreateActCtxA
)(ACTCTXA
*);
3657 BOOL (WINAPI
*pActivateActCtx
)(HANDLE
, ULONG_PTR
*);
3666 hKernel32
= GetModuleHandleA("kernel32.dll");
3667 pCreateActCtxA
= (void*)GetProcAddress(hKernel32
, "CreateActCtxA");
3668 pActivateActCtx
= (void*)GetProcAddress(hKernel32
, "ActivateActCtx");
3669 if (!(pCreateActCtxA
&& pActivateActCtx
))
3671 win_skip("Activation contexts unsupported. No version 6 tests possible.\n");
3675 /* create manifest */
3676 file
= CreateFileA( manifest_name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
3677 if (file
!= INVALID_HANDLE_VALUE
)
3679 ret
= (WriteFile( file
, manifest
, sizeof(manifest
)-1, &written
, NULL
) &&
3680 written
== sizeof(manifest
)-1);
3681 CloseHandle( file
);
3684 DeleteFileA( manifest_name
);
3685 skip("Failed to fill manifest file. Skipping comctl32 V6 tests.\n");
3689 trace("created %s\n", manifest_name
);
3693 skip("Failed to create manifest file. Skipping comctl32 V6 tests.\n");
3697 memset(&ctx
, 0, sizeof(ctx
));
3698 ctx
.cbSize
= sizeof(ctx
);
3699 ctx
.lpSource
= manifest_name
;
3701 hCtx
= pCreateActCtxA(&ctx
);
3702 ok(hCtx
!= 0, "Expected context handle\n");
3704 ret
= pActivateActCtx(hCtx
, pcookie
);
3709 win_skip("A problem during context activation occurred.\n");
3710 DeleteFileA(manifest_name
);
3715 /* this is a XP SP3 failure workaround */
3716 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
3717 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
,
3719 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
3720 if (!IsWindow(hwnd
))
3722 win_skip("FIXME: failed to create ListView window.\n");
3723 unload_v6_module(*pcookie
);
3727 DestroyWindow(hwnd
);
3733 static void test_get_set_view(void)
3739 /* test style->view mapping */
3740 hwnd
= create_listview_control(0);
3741 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3743 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3744 expect(LV_VIEW_DETAILS
, ret
);
3746 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3748 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
3749 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3750 expect(LV_VIEW_ICON
, ret
);
3752 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3753 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
3754 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3755 expect(LV_VIEW_SMALLICON
, ret
);
3757 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3758 SetWindowLongPtr(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
3759 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3760 expect(LV_VIEW_LIST
, ret
);
3762 /* switching view doesn't touch window style */
3763 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
3765 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3766 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3767 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
3769 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3770 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3771 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
3773 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3774 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3776 DestroyWindow(hwnd
);
3779 static void test_canceleditlabel(void)
3781 HWND hwnd
, hwndedit
;
3785 static CHAR test
[] = "test";
3786 static const CHAR test1
[] = "test1";
3788 hwnd
= create_listview_control(LVS_EDITLABELS
);
3789 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3791 insert_item(hwnd
, 0);
3793 /* try without edit created */
3794 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3797 /* cancel without data change */
3799 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3800 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3801 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3803 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3805 /* cancel after data change */
3806 memset(&itema
, 0, sizeof(itema
));
3807 itema
.pszText
= test
;
3808 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
3811 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3812 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3813 ret
= SetWindowText(hwndedit
, test1
);
3814 ok(ret
!= 0, "Expected edit text to change\n");
3815 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3817 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3818 memset(&itema
, 0, sizeof(itema
));
3819 itema
.pszText
= buff
;
3820 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3821 ret
= SendMessage(hwnd
, LVM_GETITEMTEXT
, 0, (LPARAM
)&itema
);
3823 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
3825 DestroyWindow(hwnd
);
3828 static void test_mapidindex(void)
3833 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3834 hwnd
= create_listview_control(LVS_OWNERDATA
);
3835 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3836 insert_item(hwnd
, 0);
3837 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3839 DestroyWindow(hwnd
);
3841 hwnd
= create_listview_control(0);
3842 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3844 /* LVM_MAPINDEXTOID with invalid index */
3845 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3848 insert_item(hwnd
, 0);
3849 insert_item(hwnd
, 1);
3851 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
3853 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
3856 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3858 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
3860 /* remove 0 indexed item, id retained */
3861 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
3862 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3864 /* new id starts from previous value */
3865 insert_item(hwnd
, 1);
3866 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
3869 /* get index by id */
3870 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
3872 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
3874 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
3876 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
3879 DestroyWindow(hwnd
);
3882 static void test_getitemspacing(void)
3891 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
3892 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
3895 hwnd
= create_custom_listview_control(0);
3896 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3898 expect(cx
, LOWORD(ret
));
3899 expect(cy
, HIWORD(ret
));
3901 /* now try with icons */
3902 himl
= ImageList_Create(40, 40, 0, 4, 4);
3903 ok(himl
!= NULL
, "failed to create imagelist\n");
3904 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
3905 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3906 ret
= ImageList_Add(himl
, hbmp
, 0);
3908 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
3911 itema
.mask
= LVIF_IMAGE
;
3915 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
3917 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3919 /* spacing + icon size returned */
3920 expect(cx
+ 40, LOWORD(ret
));
3921 expect(cy
+ 40, HIWORD(ret
));
3923 DestroyWindow(hwnd
);
3925 hwnd
= create_custom_listview_control(LVS_SMALLICON
);
3926 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3928 expect(cx
, LOWORD(ret
));
3929 expect(cy
, HIWORD(ret
));
3931 DestroyWindow(hwnd
);
3933 hwnd
= create_custom_listview_control(LVS_REPORT
);
3934 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3936 expect(cx
, LOWORD(ret
));
3937 expect(cy
, HIWORD(ret
));
3939 DestroyWindow(hwnd
);
3941 hwnd
= create_custom_listview_control(LVS_LIST
);
3942 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3944 expect(cx
, LOWORD(ret
));
3945 expect(cy
, HIWORD(ret
));
3947 DestroyWindow(hwnd
);
3950 static void test_getcolumnwidth(void)
3957 /* default column width */
3958 hwnd
= create_custom_listview_control(0);
3959 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
3961 style
= GetWindowLong(hwnd
, GWL_STYLE
);
3962 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
3963 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
3964 todo_wine
expect(8, ret
);
3965 style
= GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
3966 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
3968 ret
= SendMessage(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
3970 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
3972 DestroyWindow(hwnd
);
3975 static void test_scrollnotify(void)
3980 hwnd
= create_listview_control(0);
3982 insert_column(hwnd
, 0);
3983 insert_column(hwnd
, 1);
3984 insert_item(hwnd
, 0);
3986 /* make it scrollable - resize */
3987 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3989 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3992 /* try with dummy call */
3993 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3994 ret
= SendMessage(hwnd
, LVM_SCROLL
, 0, 0);
3996 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
3997 "scroll notify 1", TRUE
);
3999 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4000 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 0);
4002 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4003 "scroll notify 2", TRUE
);
4005 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4006 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 1);
4008 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4009 "scroll notify 3", TRUE
);
4011 DestroyWindow(hwnd
);
4014 START_TEST(listview
)
4017 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
4019 ULONG_PTR ctx_cookie
;
4021 hComctl32
= GetModuleHandleA("comctl32.dll");
4022 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
4023 if (pInitCommonControlsEx
)
4025 INITCOMMONCONTROLSEX iccex
;
4026 iccex
.dwSize
= sizeof(iccex
);
4027 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
4028 pInitCommonControlsEx(&iccex
);
4031 InitCommonControls();
4033 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
4035 hwndparent
= create_parent_window(FALSE
);
4036 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4038 g_is_below_5
= is_below_comctl_5();
4046 test_icon_spacing();
4049 test_item_position();
4054 test_subitem_rect();
4058 test_nosortheader();
4062 test_getitemposition();
4063 test_columnscreation();
4065 test_notifyformat();
4067 test_getitemspacing();
4068 test_getcolumnwidth();
4070 if (!load_v6_module(&ctx_cookie
))
4072 DestroyWindow(hwndparent
);
4076 /* comctl32 version 6 tests start here */
4077 test_get_set_view();
4078 test_canceleditlabel();
4080 test_scrollnotify();
4082 unload_v6_module(ctx_cookie
);
4084 DestroyWindow(hwndparent
);