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 { WM_WINDOWPOSCHANGING
, sent
},
271 { WM_NCCALCSIZE
, sent
},
272 { WM_WINDOWPOSCHANGED
, sent
},
273 { WM_MOVE
, sent
|defwinproc
},
274 { WM_SIZE
, sent
|defwinproc
},
275 /* the rest is todo */
276 { WM_WINDOWPOSCHANGING
, sent
},
277 { WM_WINDOWPOSCHANGED
, sent
},
281 static const struct message scroll_parent_seq
[] = {
282 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_BEGINSCROLL
},
283 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDSCROLL
},
292 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
294 static LONG defwndproc_counter
= 0;
298 msg
.message
= message
;
299 msg
.flags
= sent
|wparam
|lparam
;
300 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
303 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
305 /* log system messages, except for painting */
306 if (message
< WM_USER
&&
307 message
!= WM_PAINT
&&
308 message
!= WM_ERASEBKGND
&&
309 message
!= WM_NCPAINT
&&
310 message
!= WM_NCHITTEST
&&
311 message
!= WM_GETTEXT
&&
312 message
!= WM_GETICON
&&
313 message
!= WM_DEVICECHANGE
)
315 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
317 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
319 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
325 switch (((NMHDR
*)lParam
)->code
)
327 case LVN_BEGINLABELEDIT
:
328 /* subclass edit box */
330 subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
334 case LVN_ENDLABELEDIT
:
335 /* always accept new item text */
337 case LVN_BEGINSCROLL
:
340 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
342 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
343 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
346 case LVN_ITEMCHANGED
:
347 if (g_dump_itemchanged
)
349 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
350 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
351 nmlv
->iItem
, nmlv
->uNewState
, nmlv
->uOldState
, nmlv
->uChanged
);
357 case WM_NOTIFYFORMAT
:
359 /* force to return format */
360 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
365 defwndproc_counter
++;
366 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
367 defwndproc_counter
--;
372 static BOOL
register_parent_wnd_class(BOOL Unicode
)
380 clsW
.lpfnWndProc
= parent_wnd_proc
;
383 clsW
.hInstance
= GetModuleHandleW(NULL
);
385 clsW
.hCursor
= LoadCursorA(0, IDC_ARROW
);
386 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
387 clsW
.lpszMenuName
= NULL
;
388 clsW
.lpszClassName
= testparentclassW
;
393 clsA
.lpfnWndProc
= parent_wnd_proc
;
396 clsA
.hInstance
= GetModuleHandleA(NULL
);
398 clsA
.hCursor
= LoadCursorA(0, IDC_ARROW
);
399 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
400 clsA
.lpszMenuName
= NULL
;
401 clsA
.lpszClassName
= "Listview test parent class";
404 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
407 static HWND
create_parent_window(BOOL Unicode
)
409 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W'};
411 if (!register_parent_wnd_class(Unicode
))
418 return CreateWindowExW(0, testparentclassW
, nameW
,
419 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
420 WS_MAXIMIZEBOX
| WS_VISIBLE
,
422 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
424 return CreateWindowExA(0, "Listview test parent class",
425 "Listview test parent window",
426 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
427 WS_MAXIMIZEBOX
| WS_VISIBLE
,
429 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
432 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
434 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
435 static LONG defwndproc_counter
= 0;
439 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
441 /* some debug output for style changing */
442 if ((message
== WM_STYLECHANGING
||
443 message
== WM_STYLECHANGED
) && lParam
)
445 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
446 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
449 msg
.message
= message
;
450 msg
.flags
= sent
|wparam
|lparam
;
451 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
454 msg
.id
= LISTVIEW_ID
;
455 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
457 defwndproc_counter
++;
458 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
459 defwndproc_counter
--;
463 static HWND
create_listview_control(DWORD style
)
465 struct subclass_info
*info
;
469 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
473 GetClientRect(hwndparent
, &rect
);
474 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
475 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
| style
,
476 0, 0, rect
.right
, rect
.bottom
,
477 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
478 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
482 HeapFree(GetProcessHeap(), 0, info
);
486 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
487 (LONG_PTR
)listview_subclass_proc
);
488 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
493 /* unicode listview window with specified parent */
494 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
496 struct subclass_info
*info
;
499 static const WCHAR nameW
[] = {'f','o','o',0};
501 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
505 GetClientRect(parent
, &rect
);
506 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
507 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
| style
,
508 0, 0, rect
.right
, rect
.bottom
,
509 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
510 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
514 HeapFree(GetProcessHeap(), 0, info
);
518 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
519 (LONG_PTR
)listview_subclass_proc
);
520 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
525 static HWND
create_custom_listview_control(DWORD style
)
527 struct subclass_info
*info
;
531 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
535 GetClientRect(hwndparent
, &rect
);
536 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
537 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
538 0, 0, rect
.right
, rect
.bottom
,
539 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
540 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
544 HeapFree(GetProcessHeap(), 0, info
);
548 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
549 (LONG_PTR
)listview_subclass_proc
);
550 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
555 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
557 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
558 static LONG defwndproc_counter
= 0;
562 trace("header: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
564 msg
.message
= message
;
565 msg
.flags
= sent
|wparam
|lparam
;
566 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
570 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
572 defwndproc_counter
++;
573 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
574 defwndproc_counter
--;
578 static HWND
subclass_header(HWND hwndListview
)
580 struct subclass_info
*info
;
583 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
587 hwnd
= ListView_GetHeader(hwndListview
);
588 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
589 (LONG_PTR
)header_subclass_proc
);
590 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
595 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
597 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
598 static LONG defwndproc_counter
= 0;
602 msg
.message
= message
;
603 msg
.flags
= sent
|wparam
|lparam
;
604 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
608 /* all we need is sizing */
609 if (message
== WM_WINDOWPOSCHANGING
||
610 message
== WM_NCCALCSIZE
||
611 message
== WM_WINDOWPOSCHANGED
||
612 message
== WM_MOVE
||
615 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
618 defwndproc_counter
++;
619 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
620 defwndproc_counter
--;
624 static HWND
subclass_editbox(HWND hwndListview
)
626 struct subclass_info
*info
;
629 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
633 hwnd
= (HWND
)SendMessage(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
634 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
635 (LONG_PTR
)editbox_subclass_proc
);
636 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
641 /* Performs a single LVM_HITTEST test */
642 static void test_lvm_hittest(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
,
643 BOOL todo_item
, BOOL todo_flags
, int line
)
652 trace("hittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
653 ret
= SendMessage(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
659 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
660 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
661 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
666 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
667 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
668 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
674 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
677 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
680 /* Performs a single LVM_SUBITEMHITTEST test */
681 static void test_lvm_subitemhittest(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
682 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
690 trace("subhittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
691 ret
= SendMessage(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
697 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
698 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
703 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
704 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
710 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
713 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
718 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
721 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
724 static void test_images(void)
732 static CHAR hello
[] = "hello";
734 himl
= ImageList_Create(40, 40, 0, 4, 4);
735 ok(himl
!= NULL
, "failed to create imagelist\n");
737 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
738 ok(hbmp
!= NULL
, "failed to create bitmap\n");
740 r
= ImageList_Add(himl
, hbmp
, 0);
741 ok(r
== 0, "should be zero\n");
743 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
744 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
745 ok(hwnd
!= NULL
, "failed to create listview window\n");
747 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
748 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
750 ok(r
== 0, "should return zero\n");
752 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
753 ok(r
== 0, "should return zero\n");
755 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
756 /* returns dimensions */
758 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
759 ok(r
== 0, "should be zero items\n");
761 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
766 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
767 ok(r
== -1, "should fail\n");
770 item
.pszText
= hello
;
771 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
772 ok(r
== 0, "should not fail\n");
774 memset(&r1
, 0, sizeof r1
);
776 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
778 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
779 ok(r
== TRUE
, "should not fail\n");
782 item
.pszText
= hello
;
783 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
784 ok(r
== 0, "should not fail\n");
786 memset(&r2
, 0, sizeof r2
);
788 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
790 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
795 static void test_checkboxes(void)
800 static CHAR text
[] = "Text",
804 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
805 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
806 ok(hwnd
!= NULL
, "failed to create listview window\n");
808 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
809 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
810 item
.stateMask
= 0xffff;
815 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
816 ok(r
== 0, "ret %d\n", r
);
819 item
.mask
= LVIF_STATE
;
820 item
.stateMask
= 0xffff;
821 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
822 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
824 /* Don't set LVIF_STATE */
825 item
.mask
= LVIF_TEXT
;
826 item
.stateMask
= 0xffff;
831 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
832 ok(r
== 1, "ret %d\n", r
);
835 item
.mask
= LVIF_STATE
;
836 item
.stateMask
= 0xffff;
837 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
838 ok(item
.state
== 0, "state %x\n", item
.state
);
840 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
841 ok(r
== 0, "should return zero\n");
843 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
845 item
.mask
= LVIF_STATE
;
846 item
.stateMask
= 0xffff;
847 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
848 ok(item
.state
== 0x1ccc, "state %x\n", item
.state
);
850 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
852 item
.mask
= LVIF_TEXT
;
854 item
.pszText
= text2
;
855 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
856 ok(r
== 2, "ret %d\n", r
);
859 item
.mask
= LVIF_STATE
;
860 item
.stateMask
= 0xffff;
861 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
862 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
864 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
866 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
867 item
.stateMask
= 0xffff;
869 item
.pszText
= text3
;
870 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
871 ok(r
== 3, "ret %d\n", r
);
874 item
.mask
= LVIF_STATE
;
875 item
.stateMask
= 0xffff;
876 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
877 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
879 /* Set an item's state to checked */
881 item
.mask
= LVIF_STATE
;
882 item
.stateMask
= 0xf000;
884 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
887 item
.mask
= LVIF_STATE
;
888 item
.stateMask
= 0xffff;
889 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
890 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
892 /* Check that only the bits we asked for are returned,
893 * and that all the others are set to zero
896 item
.mask
= LVIF_STATE
;
897 item
.stateMask
= 0xf000;
899 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
900 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
902 /* Set the style again and check that doesn't change an item's state */
903 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
904 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
907 item
.mask
= LVIF_STATE
;
908 item
.stateMask
= 0xffff;
909 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
910 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
912 /* Unsetting the checkbox extended style doesn't change an item's state */
913 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
914 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
917 item
.mask
= LVIF_STATE
;
918 item
.stateMask
= 0xffff;
919 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
920 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
922 /* Now setting the style again will change an item's state */
923 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
924 ok(r
== 0, "ret %x\n", r
);
927 item
.mask
= LVIF_STATE
;
928 item
.stateMask
= 0xffff;
929 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
930 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
932 /* Toggle checkbox tests (bug 9934) */
933 memset (&item
, 0xcc, sizeof(item
));
934 item
.mask
= LVIF_STATE
;
937 item
.state
= LVIS_FOCUSED
;
938 item
.stateMask
= LVIS_FOCUSED
;
939 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
943 item
.mask
= LVIF_STATE
;
944 item
.stateMask
= 0xffff;
945 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
946 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
948 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
950 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
954 item
.mask
= LVIF_STATE
;
955 item
.stateMask
= 0xffff;
956 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
957 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
959 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
961 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
965 item
.mask
= LVIF_STATE
;
966 item
.stateMask
= 0xffff;
967 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
968 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
973 static void insert_column(HWND hwnd
, int idx
)
978 memset(&column
, 0xcc, sizeof(column
));
979 column
.mask
= LVCF_SUBITEM
;
980 column
.iSubItem
= idx
;
982 rc
= ListView_InsertColumn(hwnd
, idx
, &column
);
986 static void insert_item(HWND hwnd
, int idx
)
988 static CHAR text
[] = "foo";
993 memset(&item
, 0xcc, sizeof (item
));
994 item
.mask
= LVIF_TEXT
;
999 rc
= ListView_InsertItem(hwnd
, &item
);
1003 static void test_items(void)
1005 const LPARAM lparamTest
= 0x42;
1009 static CHAR text
[] = "Text";
1011 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1012 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1013 ok(hwnd
!= NULL
, "failed to create listview window\n");
1016 * Test setting/getting item params
1019 /* Set up two columns */
1020 insert_column(hwnd
, 0);
1021 insert_column(hwnd
, 1);
1023 /* LVIS_SELECTED with zero stateMask */
1025 memset (&item
, 0, sizeof (item
));
1026 item
.mask
= LVIF_STATE
;
1027 item
.state
= LVIS_SELECTED
;
1031 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1032 ok(r
== 0, "ret %d\n", r
);
1034 memset (&item
, 0xcc, sizeof (item
));
1035 item
.mask
= LVIF_STATE
;
1036 item
.stateMask
= LVIS_SELECTED
;
1040 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1041 ok(r
!= 0, "ret %d\n", r
);
1042 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1043 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1045 /* LVIS_SELECTED with zero stateMask */
1047 memset (&item
, 0, sizeof (item
));
1048 item
.mask
= LVIF_STATE
;
1049 item
.state
= LVIS_FOCUSED
;
1053 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1054 ok(r
== 0, "ret %d\n", r
);
1056 memset (&item
, 0xcc, sizeof (item
));
1057 item
.mask
= LVIF_STATE
;
1058 item
.stateMask
= LVIS_FOCUSED
;
1062 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1063 ok(r
!= 0, "ret %d\n", r
);
1064 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1065 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1067 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1069 memset (&item
, 0, sizeof (item
));
1070 item
.mask
= LVIF_STATE
;
1071 item
.state
= LVIS_CUT
;
1072 item
.stateMask
= LVIS_FOCUSED
;
1075 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1076 ok(r
== 0, "ret %d\n", r
);
1078 memset (&item
, 0xcc, sizeof (item
));
1079 item
.mask
= LVIF_STATE
;
1080 item
.stateMask
= LVIS_CUT
;
1084 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1085 ok(r
!= 0, "ret %d\n", r
);
1086 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1087 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1089 /* Insert an item with just a param */
1090 memset (&item
, 0xcc, sizeof (item
));
1091 item
.mask
= LVIF_PARAM
;
1094 item
.lParam
= lparamTest
;
1095 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1096 ok(r
== 0, "ret %d\n", r
);
1098 /* Test getting of the param */
1099 memset (&item
, 0xcc, sizeof (item
));
1100 item
.mask
= LVIF_PARAM
;
1103 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1104 ok(r
!= 0, "ret %d\n", r
);
1105 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1107 /* Set up a subitem */
1108 memset (&item
, 0xcc, sizeof (item
));
1109 item
.mask
= LVIF_TEXT
;
1112 item
.pszText
= text
;
1113 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1114 ok(r
!= 0, "ret %d\n", r
);
1116 /* Query param from subitem: returns main item param */
1117 memset (&item
, 0xcc, sizeof (item
));
1118 item
.mask
= LVIF_PARAM
;
1121 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1122 ok(r
!= 0, "ret %d\n", r
);
1123 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1125 /* Set up param on first subitem: no effect */
1126 memset (&item
, 0xcc, sizeof (item
));
1127 item
.mask
= LVIF_PARAM
;
1130 item
.lParam
= lparamTest
+1;
1131 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1132 ok(r
== 0, "ret %d\n", r
);
1134 /* Query param from subitem again: should still return main item param */
1135 memset (&item
, 0xcc, sizeof (item
));
1136 item
.mask
= LVIF_PARAM
;
1139 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1140 ok(r
!= 0, "ret %d\n", r
);
1141 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1143 /**** Some tests of state highlighting ****/
1144 memset (&item
, 0xcc, sizeof (item
));
1145 item
.mask
= LVIF_STATE
;
1148 item
.state
= LVIS_SELECTED
;
1149 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1150 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1151 ok(r
!= 0, "ret %d\n", r
);
1153 item
.state
= LVIS_DROPHILITED
;
1154 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1155 ok(r
!= 0, "ret %d\n", r
);
1157 memset (&item
, 0xcc, sizeof (item
));
1158 item
.mask
= LVIF_STATE
;
1161 item
.stateMask
= -1;
1162 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1163 ok(r
!= 0, "ret %d\n", r
);
1164 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1166 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1167 ok(r
!= 0, "ret %d\n", r
);
1168 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1170 /* some notnull but meaningless masks */
1171 memset (&item
, 0, sizeof(item
));
1172 item
.mask
= LVIF_NORECOMPUTE
;
1175 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1176 ok(r
!= 0, "ret %d\n", r
);
1177 memset (&item
, 0, sizeof(item
));
1178 item
.mask
= LVIF_DI_SETITEM
;
1181 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1182 ok(r
!= 0, "ret %d\n", r
);
1184 /* set text to callback value already having it */
1185 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1187 memset (&item
, 0, sizeof (item
));
1188 item
.mask
= LVIF_TEXT
;
1189 item
.pszText
= LPSTR_TEXTCALLBACK
;
1191 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1192 ok(r
== 0, "ret %d\n", r
);
1193 memset (&item
, 0, sizeof (item
));
1195 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1197 item
.pszText
= LPSTR_TEXTCALLBACK
;
1198 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0 , (LPARAM
) &item
);
1201 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1202 "check callback text comparison rule", FALSE
);
1204 DestroyWindow(hwnd
);
1207 static void test_columns(void)
1209 HWND hwnd
, hwndheader
;
1214 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1215 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1216 ok(hwnd
!= NULL
, "failed to create listview window\n");
1218 /* Add a column with no mask */
1219 memset(&column
, 0xcc, sizeof(column
));
1221 rc
= ListView_InsertColumn(hwnd
, 0, &column
);
1222 ok(rc
==0, "Inserting column with no mask failed with %d\n", rc
);
1224 /* Check its width */
1225 rc
= ListView_GetColumnWidth(hwnd
, 0);
1227 broken(rc
==0), /* win9x */
1228 "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1230 DestroyWindow(hwnd
);
1232 /* LVM_GETCOLUMNORDERARRAY */
1233 hwnd
= create_listview_control(0);
1234 hwndheader
= subclass_header(hwnd
);
1236 memset(&column
, 0, sizeof(column
));
1237 column
.mask
= LVCF_WIDTH
;
1239 rc
= ListView_InsertColumn(hwnd
, 0, &column
);
1240 ok(rc
== 0, "Inserting column failed with %d\n", rc
);
1243 rc
= ListView_InsertColumn(hwnd
, 1, &column
);
1244 ok(rc
== 1, "Inserting column failed with %d\n", rc
);
1246 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1248 rc
= SendMessage(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1249 ok(rc
!= 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1250 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1251 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1253 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1255 DestroyWindow(hwnd
);
1257 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1258 static WNDPROC listviewWndProc
;
1259 static HIMAGELIST test_create_imagelist
;
1261 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1265 if (uMsg
== WM_CREATE
)
1267 LPCREATESTRUCT lpcs
= (LPCREATESTRUCT
)lParam
;
1268 lpcs
->style
|= LVS_REPORT
;
1270 ret
= CallWindowProc(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1271 if (uMsg
== WM_CREATE
) SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1275 static void test_create(void)
1284 cls
.cbSize
= sizeof(WNDCLASSEX
);
1285 ok(GetClassInfoEx(GetModuleHandle(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1286 listviewWndProc
= cls
.lpfnWndProc
;
1287 cls
.lpfnWndProc
= create_test_wndproc
;
1288 cls
.lpszClassName
= "MyListView32";
1289 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
1291 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1292 hList
= CreateWindow("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1293 ok((HIMAGELIST
)SendMessage(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1294 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1295 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1296 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1297 DestroyWindow(hList
);
1299 /* header isn't created on LVS_ICON and LVS_LIST styles */
1300 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1301 GetModuleHandle(NULL
), 0);
1302 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1303 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1304 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1306 memset(&col
, 0, sizeof(LVCOLUMNA
));
1307 col
.mask
= LVCF_WIDTH
;
1309 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1310 ok(r
== 0, "Expected 0 column's inserted\n");
1311 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1312 ok(IsWindow(hHeader
), "Header should be created\n");
1313 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1314 DestroyWindow(hList
);
1316 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1317 GetModuleHandle(NULL
), 0);
1318 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1319 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1320 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1322 memset(&col
, 0, sizeof(LVCOLUMNA
));
1323 col
.mask
= LVCF_WIDTH
;
1325 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1326 ok(r
== 0, "Expected 0 column's inserted\n");
1327 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1328 ok(IsWindow(hHeader
), "Header should be created\n");
1329 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1330 DestroyWindow(hList
);
1332 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1333 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1334 GetModuleHandle(NULL
), 0);
1335 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLongPtr(hList
, GWL_STYLE
) | LVS_REPORT
);
1336 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1337 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1338 ok(IsWindow(hHeader
), "Header should be created\n");
1339 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLong(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1340 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1341 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1342 ok(IsWindow(hHeader
), "Header should be created\n");
1343 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1344 DestroyWindow(hList
);
1346 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1347 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1348 GetModuleHandle(NULL
), 0);
1349 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1350 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1351 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1352 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1353 ok(IsWindow(hHeader
), "Header should be created\n");
1354 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1355 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1356 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1357 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1358 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1359 ok(IsWindow(hHeader
), "Header should be created\n");
1360 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1361 DestroyWindow(hList
);
1363 /* LVS_REPORT without WS_VISIBLE */
1364 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1365 GetModuleHandle(NULL
), 0);
1366 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1367 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1368 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1370 memset(&col
, 0, sizeof(LVCOLUMNA
));
1371 col
.mask
= LVCF_WIDTH
;
1373 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1374 ok(r
== 0, "Expected 0 column's inserted\n");
1375 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1376 ok(IsWindow(hHeader
), "Header should be created\n");
1377 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1378 DestroyWindow(hList
);
1380 /* LVS_REPORT without WS_VISIBLE, try to show it */
1381 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1382 GetModuleHandle(NULL
), 0);
1383 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1384 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1385 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1386 ShowWindow(hList
, SW_SHOW
);
1387 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1388 ok(IsWindow(hHeader
), "Header should be created\n");
1389 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1390 DestroyWindow(hList
);
1392 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1393 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1394 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1395 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1396 ok(IsWindow(hHeader
), "Header should be created\n");
1397 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1398 /* HDS_DRAGDROP set by default */
1399 ok(GetWindowLongPtr(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1400 DestroyWindow(hList
);
1402 /* setting LVS_EX_HEADERDRAGDROP creates header */
1403 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1404 GetModuleHandle(NULL
), 0);
1405 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1406 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1407 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1408 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1409 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1410 ok(IsWindow(hHeader
) ||
1411 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1412 "Header should be created\n");
1413 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1414 DestroyWindow(hList
);
1416 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1417 hList
= create_custom_listview_control(0);
1418 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1419 r
= SendMessage(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1420 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1421 DestroyWindow(hList
);
1423 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1424 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1425 GetModuleHandle(NULL
), 0);
1426 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1427 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1429 rect
.left
= LVIR_BOUNDS
;
1431 rect
.right
= rect
.bottom
= -10;
1432 r
= SendMessage(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1433 ok(r
!= 0, "Expected not-null LRESULT\n");
1435 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1436 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1437 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1439 DestroyWindow(hList
);
1441 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1442 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1443 hList
= create_listview_control(LVS_OWNERDRAWFIXED
);
1444 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1445 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1446 DestroyWindow(hList
);
1449 static void test_redraw(void)
1451 HWND hwnd
, hwndheader
;
1456 hwnd
= create_listview_control(0);
1457 hwndheader
= subclass_header(hwnd
);
1459 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1461 trace("invalidate & update\n");
1462 InvalidateRect(hwnd
, NULL
, TRUE
);
1464 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1466 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1468 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1469 /* 1. Without backbuffer */
1470 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1473 hdc
= GetWindowDC(hwndparent
);
1475 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1476 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1477 ok(r
!= 0, "Expected not zero result\n");
1478 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1479 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1481 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1484 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1485 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1486 ok(r
!= 0, "Expected not zero result\n");
1487 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1488 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1490 /* 2. With backbuffer */
1491 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1492 LVS_EX_DOUBLEBUFFER
);
1493 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1496 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1497 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1498 ok(r
!= 0, "Expected not zero result\n");
1499 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1500 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1502 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1505 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1506 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1507 todo_wine
ok(r
!= 0, "Expected not zero result\n");
1508 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1509 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1511 ReleaseDC(hwndparent
, hdc
);
1513 DestroyWindow(hwnd
);
1516 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1518 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1520 if(msg
== WM_NOTIFY
) {
1521 NMHDR
*nmhdr
= (PVOID
)lp
;
1522 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1523 NMLVCUSTOMDRAW
*nmlvcd
= (PVOID
)nmhdr
;
1524 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd
->nmcd
.dwDrawStage
);
1525 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1527 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1528 return CDRF_NOTIFYITEMDRAW
;
1529 case CDDS_ITEMPREPAINT
:
1530 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1531 return CDRF_NOTIFYSUBITEMDRAW
;
1532 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1533 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1534 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1535 return CDRF_NOTIFYPOSTPAINT
;
1536 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1537 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1538 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1539 return CDRF_DODEFAULT
;
1541 return CDRF_DODEFAULT
;
1545 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1548 static void test_customdraw(void)
1553 hwnd
= create_listview_control(0);
1555 insert_column(hwnd
, 0);
1556 insert_column(hwnd
, 1);
1557 insert_item(hwnd
, 0);
1559 oldwndproc
= (WNDPROC
)SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
,
1560 (LONG_PTR
)cd_wndproc
);
1562 InvalidateRect(hwnd
, NULL
, TRUE
);
1565 SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1567 DestroyWindow(hwnd
);
1570 static void test_icon_spacing(void)
1572 /* LVM_SETICONSPACING */
1573 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1579 hwnd
= create_custom_listview_control(LVS_ICON
);
1580 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1582 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, (LPARAM
)NF_REQUERY
);
1583 expect(NFR_ANSI
, r
);
1585 /* reset the icon spacing to defaults */
1586 SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1588 /* now we can request what the defaults are */
1589 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1593 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1595 trace("test icon spacing\n");
1597 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1598 ok(r
== MAKELONG(w
, h
) ||
1599 broken(r
== MAKELONG(w
, w
)), /* win98 */
1600 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1602 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1603 expect(MAKELONG(20,30), r
);
1605 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1606 expect(MAKELONG(25,35), r
);
1608 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1610 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1611 DestroyWindow(hwnd
);
1614 static void test_color(void)
1616 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1623 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1625 hwnd
= create_listview_control(0);
1626 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1628 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1630 trace("test color seq\n");
1631 for (i
= 0; i
< 4; i
++)
1635 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1637 r
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, color
);
1640 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1642 r
= SendMessage(hwnd
, LVM_GETTEXTCOLOR
, 0, color
);
1645 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1647 r
= SendMessage(hwnd
, LVM_GETTEXTBKCOLOR
, 0, color
);
1651 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1653 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1654 DestroyWindow(hwnd
);
1657 static void test_item_count(void)
1659 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1672 static CHAR item0text
[] = "item0";
1673 static CHAR item1text
[] = "item1";
1674 static CHAR item2text
[] = "item2";
1676 hwnd
= create_listview_control(0);
1677 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1679 /* resize in dpiaware manner to fit all 3 items added */
1681 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1682 GetTextMetricsA(hdc
, &tm
);
1683 /* 2 extra pixels for bounds and header border */
1684 height
= tm
.tmHeight
+ 2;
1685 SelectObject(hdc
, hOldFont
);
1688 GetWindowRect(hwnd
, &rect
);
1689 /* 3 items + 1 header + 1 to be sure */
1690 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1692 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1694 trace("test item count\n");
1696 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1700 item0
.mask
= LVIF_TEXT
;
1703 item0
.pszText
= item0text
;
1704 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1707 /* [item0, item1] */
1708 item1
.mask
= LVIF_TEXT
;
1711 item1
.pszText
= item1text
;
1712 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1715 /* [item0, item1, item2] */
1716 item2
.mask
= LVIF_TEXT
;
1719 item2
.pszText
= item2text
;
1720 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1723 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1726 /* [item0, item1] */
1727 r
= SendMessage(hwnd
, LVM_DELETEITEM
, 2, 0);
1730 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1734 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1737 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1741 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1744 /* [item0, item1] */
1745 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1748 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1751 /* [item0, item1, item2] */
1752 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1755 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1758 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
1760 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1761 DestroyWindow(hwnd
);
1764 static void test_item_position(void)
1766 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1775 static CHAR item0text
[] = "item0";
1776 static CHAR item1text
[] = "item1";
1777 static CHAR item2text
[] = "item2";
1779 hwnd
= create_custom_listview_control(LVS_ICON
);
1780 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1782 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1784 trace("test item position\n");
1787 item0
.mask
= LVIF_TEXT
;
1790 item0
.pszText
= item0text
;
1791 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1794 /* [item0, item1] */
1795 item1
.mask
= LVIF_TEXT
;
1798 item1
.pszText
= item1text
;
1799 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1802 /* [item0, item1, item2] */
1803 item2
.mask
= LVIF_TEXT
;
1806 item2
.pszText
= item2text
;
1807 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1810 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
1812 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
1814 expect2(10, 5, position
.x
, position
.y
);
1816 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
1818 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
1820 expect2(0, 0, position
.x
, position
.y
);
1822 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
1824 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
1826 expect2(20, 20, position
.x
, position
.y
);
1828 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
1830 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1831 DestroyWindow(hwnd
);
1834 static void test_getorigin(void)
1842 position
.x
= position
.y
= 0;
1844 hwnd
= create_custom_listview_control(LVS_ICON
);
1845 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1846 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1847 trace("test get origin results\n");
1848 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1850 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1851 DestroyWindow(hwnd
);
1853 hwnd
= create_custom_listview_control(LVS_SMALLICON
);
1854 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1855 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1856 trace("test get origin results\n");
1857 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1859 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1860 DestroyWindow(hwnd
);
1862 hwnd
= create_custom_listview_control(LVS_LIST
);
1863 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1864 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1865 trace("test get origin results\n");
1866 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1868 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1869 DestroyWindow(hwnd
);
1871 hwnd
= create_custom_listview_control(LVS_REPORT
);
1872 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1873 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1874 trace("test get origin results\n");
1875 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1877 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1878 DestroyWindow(hwnd
);
1882 static void test_multiselect(void)
1884 typedef struct t_select_task
1895 int i
,j
,item_count
,selected_count
;
1896 static const int items
=5;
1902 static struct t_select_task task_list
[] = {
1903 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
1904 { "using VK_UP", -1, VK_UP
, -1, -1 },
1905 { "using VK_END", 0, VK_END
, 1, -1 },
1906 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
1910 hwnd
= create_listview_control(0);
1912 for (i
=0;i
<items
;i
++) {
1913 insert_item(hwnd
, 0);
1916 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1918 expect(items
,item_count
);
1921 task
= task_list
[i
];
1923 /* deselect all items */
1924 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1925 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1927 /* set initial position */
1928 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
1929 ListView_SetItemState(hwnd
,(task
.initPos
== -1 ? item_count
-1 : task
.initPos
),LVIS_SELECTED
,LVIS_SELECTED
);
1931 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1933 ok(selected_count
== 1, "There should be only one selected item at the beginning (is %d)\n",selected_count
);
1935 /* Set SHIFT key pressed */
1936 GetKeyboardState(kstate
);
1937 kstate
[VK_SHIFT
]=0x80;
1938 SetKeyboardState(kstate
);
1940 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
1941 r
= SendMessage(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
1943 r
= SendMessage(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
1947 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1949 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
);
1951 /* Set SHIFT key released */
1952 GetKeyboardState(kstate
);
1953 kstate
[VK_SHIFT
]=0x00;
1954 SetKeyboardState(kstate
);
1956 DestroyWindow(hwnd
);
1958 /* make multiple selection, then switch to LVS_SINGLESEL */
1959 hwnd
= create_listview_control(0);
1960 for (i
=0;i
<items
;i
++) {
1961 insert_item(hwnd
, 0);
1963 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1964 expect(items
,item_count
);
1966 /* try with NULL pointer */
1967 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)NULL
);
1970 /* select all, check notifications */
1971 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1973 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1975 item
.stateMask
= LVIS_SELECTED
;
1976 item
.state
= LVIS_SELECTED
;
1977 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
1980 ok_sequence(sequences
, PARENT_SEQ_INDEX
, select_all_parent_seq
,
1981 "select all notification", FALSE
);
1983 /* deselect all items */
1984 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1985 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1987 ListView_SetItemState(hwnd
, i
, LVIS_SELECTED
, LVIS_SELECTED
);
1990 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1992 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
1995 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
1996 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
1997 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
1998 /* check that style is accepted */
1999 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2000 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2003 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2004 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2006 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2008 SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2011 /* select one more */
2012 ListView_SetItemState(hwnd
, 3, LVIS_SELECTED
, LVIS_SELECTED
);
2015 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2016 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2018 r
= ListView_GetItemState(hwnd
, 3, LVIS_SELECTED
);
2019 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2021 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2023 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2026 /* try to select all on LVS_SINGLESEL */
2027 memset(&item
, 0, sizeof(item
));
2028 item
.stateMask
= LVIS_SELECTED
;
2029 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2031 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2033 item
.stateMask
= LVIS_SELECTED
;
2034 item
.state
= LVIS_SELECTED
;
2035 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2038 r
= ListView_GetSelectedCount(hwnd
);
2040 r
= ListView_GetSelectionMark(hwnd
);
2043 /* try to deselect all on LVS_SINGLESEL */
2044 item
.stateMask
= LVIS_SELECTED
;
2045 item
.state
= LVIS_SELECTED
;
2046 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2049 item
.stateMask
= LVIS_SELECTED
;
2051 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2053 r
= ListView_GetSelectedCount(hwnd
);
2056 DestroyWindow(hwnd
);
2059 static void test_subitem_rect(void)
2066 /* test LVM_GETSUBITEMRECT for header */
2067 hwnd
= create_listview_control(0);
2068 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2069 /* add some columns */
2070 memset(&col
, 0, sizeof(LVCOLUMN
));
2071 col
.mask
= LVCF_WIDTH
;
2074 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2078 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2082 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2084 /* item = -1 means header, subitem index is 1 based */
2085 rect
.left
= LVIR_BOUNDS
;
2087 rect
.right
= rect
.bottom
= 0;
2088 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2091 rect
.left
= LVIR_BOUNDS
;
2093 rect
.right
= rect
.bottom
= 0;
2094 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2096 ok(r
!= 0, "Expected not-null LRESULT\n");
2097 expect(100, rect
.left
);
2098 expect(250, rect
.right
);
2100 expect(3, rect
.top
);
2102 rect
.left
= LVIR_BOUNDS
;
2104 rect
.right
= rect
.bottom
= 0;
2105 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2107 ok(r
!= 0, "Expected not-null LRESULT\n");
2108 expect(250, rect
.left
);
2109 expect(450, rect
.right
);
2111 expect(3, rect
.top
);
2113 /* item LVS_REPORT padding isn't applied to subitems */
2114 insert_item(hwnd
, 0);
2116 rect
.left
= LVIR_BOUNDS
;
2118 rect
.right
= rect
.bottom
= 0;
2119 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2120 ok(r
!= 0, "Expected not-null LRESULT\n");
2121 expect(100, rect
.left
);
2122 expect(250, rect
.right
);
2124 rect
.left
= LVIR_ICON
;
2126 rect
.right
= rect
.bottom
= 0;
2127 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2128 ok(r
!= 0, "Expected not-null LRESULT\n");
2129 /* no icon attached - zero width rectangle, with no left padding */
2130 expect(100, rect
.left
);
2131 expect(100, rect
.right
);
2133 rect
.left
= LVIR_LABEL
;
2135 rect
.right
= rect
.bottom
= 0;
2136 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2137 ok(r
!= 0, "Expected not-null LRESULT\n");
2138 /* same as full LVIR_BOUNDS */
2139 expect(100, rect
.left
);
2140 expect(250, rect
.right
);
2142 DestroyWindow(hwnd
);
2144 /* try it for non LVS_REPORT style */
2145 hwnd
= CreateWindow("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2146 GetModuleHandle(NULL
), 0);
2147 rect
.left
= LVIR_BOUNDS
;
2149 rect
.right
= rect
.bottom
= -10;
2150 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2151 ok(r
== 0, "Expected not-null LRESULT\n");
2152 /* rect is unchanged */
2153 expect(0, rect
.left
);
2154 expect(-10, rect
.right
);
2155 expect(1, rect
.top
);
2156 expect(-10, rect
.bottom
);
2157 DestroyWindow(hwnd
);
2160 /* comparison callback for test_sorting */
2161 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2163 if (first
== second
) return 0;
2164 return (first
> second
? 1 : -1);
2167 static void test_sorting(void)
2173 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2176 hwnd
= create_listview_control(0);
2177 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2179 /* insert some items */
2180 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2181 item
.state
= LVIS_SELECTED
;
2185 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2188 item
.mask
= LVIF_PARAM
;
2192 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2195 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2196 item
.state
= LVIS_SELECTED
;
2200 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2203 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2206 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2209 r
= SendMessage(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2212 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2214 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2216 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2218 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2219 expect(LVIS_SELECTED
, r
);
2220 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2221 expect(LVIS_SELECTED
, r
);
2223 DestroyWindow(hwnd
);
2225 /* switch to LVS_SORTASCENDING when some items added */
2226 hwnd
= create_listview_control(0);
2227 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2229 item
.mask
= LVIF_TEXT
;
2232 item
.pszText
= names
[1];
2233 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2236 item
.mask
= LVIF_TEXT
;
2239 item
.pszText
= names
[2];
2240 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2243 item
.mask
= LVIF_TEXT
;
2246 item
.pszText
= names
[0];
2247 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2250 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2251 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2252 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2253 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2255 /* no sorting performed when switched to LVS_SORTASCENDING */
2256 item
.mask
= LVIF_TEXT
;
2258 item
.pszText
= buff
;
2259 item
.cchTextMax
= sizeof(buff
);
2260 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2262 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2265 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2267 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2270 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2272 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2274 /* adding new item doesn't resort list */
2275 item
.mask
= LVIF_TEXT
;
2278 item
.pszText
= names
[3];
2279 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2282 item
.mask
= LVIF_TEXT
;
2284 item
.pszText
= buff
;
2285 item
.cchTextMax
= sizeof(buff
);
2286 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2288 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2291 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2293 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2296 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2298 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2301 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2303 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2305 /* corner case - item should be placed at first position */
2306 item
.mask
= LVIF_TEXT
;
2309 item
.pszText
= names
[4];
2310 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2314 item
.pszText
= buff
;
2315 item
.cchTextMax
= sizeof(buff
);
2316 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2318 ok(lstrcmp(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2321 item
.pszText
= buff
;
2322 item
.cchTextMax
= sizeof(buff
);
2323 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2325 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2328 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2330 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2333 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2335 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2338 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2340 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2342 DestroyWindow(hwnd
);
2345 static void test_ownerdata(void)
2348 LONG_PTR style
, ret
;
2352 /* it isn't possible to set LVS_OWNERDATA after creation */
2355 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2359 hwnd
= create_listview_control(0);
2360 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2361 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2362 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2364 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2366 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2367 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2368 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2369 "try to switch to LVS_OWNERDATA seq", FALSE
);
2371 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2372 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2373 DestroyWindow(hwnd
);
2376 /* try to set LVS_OWNERDATA after creation just having it */
2377 hwnd
= create_listview_control(LVS_OWNERDATA
);
2378 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2379 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2380 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2382 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2384 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2385 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2386 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2387 "try to switch to LVS_OWNERDATA seq", FALSE
);
2388 DestroyWindow(hwnd
);
2390 /* try to remove LVS_OWNERDATA after creation just having it */
2393 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2397 hwnd
= create_listview_control(LVS_OWNERDATA
);
2398 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2399 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2400 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2402 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2404 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2405 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2406 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2407 "try to switch to LVS_OWNERDATA seq", FALSE
);
2408 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2409 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2410 DestroyWindow(hwnd
);
2413 /* try select an item */
2414 hwnd
= create_listview_control(LVS_OWNERDATA
);
2415 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2416 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2417 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2418 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2420 memset(&item
, 0, sizeof(item
));
2421 item
.stateMask
= LVIS_SELECTED
;
2422 item
.state
= LVIS_SELECTED
;
2423 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2425 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2427 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2429 DestroyWindow(hwnd
);
2431 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2432 hwnd
= create_listview_control(LVS_OWNERDATA
);
2433 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2434 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2435 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2436 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2438 memset(&item
, 0, sizeof(item
));
2439 item
.mask
= LVIF_STATE
;
2441 item
.stateMask
= LVIS_SELECTED
;
2442 item
.state
= LVIS_SELECTED
;
2443 res
= SendMessageA(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2445 DestroyWindow(hwnd
);
2447 /* check notifications after focused/selected changed */
2448 hwnd
= create_listview_control(LVS_OWNERDATA
);
2449 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2450 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
2451 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2453 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2455 memset(&item
, 0, sizeof(item
));
2456 item
.stateMask
= LVIS_SELECTED
;
2457 item
.state
= LVIS_SELECTED
;
2458 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2461 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2462 "ownerdata select notification", TRUE
);
2464 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2466 memset(&item
, 0, sizeof(item
));
2467 item
.stateMask
= LVIS_FOCUSED
;
2468 item
.state
= LVIS_FOCUSED
;
2469 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2472 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2473 "ownerdata focus notification", TRUE
);
2475 /* select all, check notifications */
2476 item
.stateMask
= LVIS_SELECTED
;
2478 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2481 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2483 item
.stateMask
= LVIS_SELECTED
;
2484 item
.state
= LVIS_SELECTED
;
2486 g_dump_itemchanged
= TRUE
;
2487 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2489 g_dump_itemchanged
= FALSE
;
2491 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2492 "ownerdata select all notification", TRUE
);
2494 /* select all again, note that all items are selected already */
2495 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2496 item
.stateMask
= LVIS_SELECTED
;
2497 item
.state
= LVIS_SELECTED
;
2498 g_dump_itemchanged
= TRUE
;
2499 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2501 g_dump_itemchanged
= FALSE
;
2502 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2503 "ownerdata select all notification", TRUE
);
2505 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2506 item
.stateMask
= LVIS_SELECTED
;
2508 g_dump_itemchanged
= TRUE
;
2509 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2511 g_dump_itemchanged
= FALSE
;
2512 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2513 "ownerdata deselect all notification", TRUE
);
2515 /* select one, then deselect all */
2516 item
.stateMask
= LVIS_SELECTED
;
2517 item
.state
= LVIS_SELECTED
;
2518 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2520 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2521 item
.stateMask
= LVIS_SELECTED
;
2523 g_dump_itemchanged
= TRUE
;
2524 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2526 g_dump_itemchanged
= FALSE
;
2527 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2528 "ownerdata select all notification", TRUE
);
2530 /* remove focused, try to focus all */
2531 item
.stateMask
= LVIS_FOCUSED
;
2532 item
.state
= LVIS_FOCUSED
;
2533 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2535 item
.stateMask
= LVIS_FOCUSED
;
2537 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2539 item
.stateMask
= LVIS_FOCUSED
;
2540 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
2542 /* setting all to focused returns failure value */
2543 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2544 item
.stateMask
= LVIS_FOCUSED
;
2545 item
.state
= LVIS_FOCUSED
;
2546 g_dump_itemchanged
= TRUE
;
2547 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2549 g_dump_itemchanged
= FALSE
;
2550 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2551 "ownerdata focus all notification", FALSE
);
2552 /* focus single item, remove all */
2553 item
.stateMask
= LVIS_FOCUSED
;
2554 item
.state
= LVIS_FOCUSED
;
2555 res
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2557 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2558 item
.stateMask
= LVIS_FOCUSED
;
2560 g_dump_itemchanged
= TRUE
;
2561 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2563 g_dump_itemchanged
= FALSE
;
2564 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
2565 "ownerdata remove focus all notification", TRUE
);
2567 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2568 item
.stateMask
= LVIS_CUT
;
2569 item
.state
= LVIS_CUT
;
2570 g_dump_itemchanged
= TRUE
;
2571 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2573 g_dump_itemchanged
= FALSE
;
2574 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2575 "ownerdata cut all notification", TRUE
);
2576 /* all marked cut, try again */
2577 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2578 item
.stateMask
= LVIS_CUT
;
2579 item
.state
= LVIS_CUT
;
2580 g_dump_itemchanged
= TRUE
;
2581 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2583 g_dump_itemchanged
= FALSE
;
2584 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2585 "ownerdata cut all notification #2", TRUE
);
2587 DestroyWindow(hwnd
);
2589 /* check notifications on LVM_GETITEM */
2590 /* zero callback mask */
2591 hwnd
= create_listview_control(LVS_OWNERDATA
);
2592 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2593 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2594 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2596 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2598 memset(&item
, 0, sizeof(item
));
2599 item
.stateMask
= LVIS_SELECTED
;
2600 item
.mask
= LVIF_STATE
;
2601 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2604 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2605 "ownerdata getitem selected state 1", FALSE
);
2607 /* non zero callback mask but not we asking for */
2608 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
2611 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2613 memset(&item
, 0, sizeof(item
));
2614 item
.stateMask
= LVIS_SELECTED
;
2615 item
.mask
= LVIF_STATE
;
2616 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2619 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2620 "ownerdata getitem selected state 2", FALSE
);
2622 /* LVIS_OVERLAYMASK callback mask, asking for index */
2623 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2625 memset(&item
, 0, sizeof(item
));
2626 item
.stateMask
= LVIS_OVERLAYMASK
;
2627 item
.mask
= LVIF_STATE
;
2628 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2631 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
2632 "ownerdata getitem selected state 2", FALSE
);
2634 DestroyWindow(hwnd
);
2636 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2637 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
);
2638 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2639 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2640 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2641 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2642 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
2643 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2644 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
2645 DestroyWindow(hwnd
);
2646 /* apparently it's allowed to switch these style on after creation */
2647 hwnd
= create_listview_control(LVS_OWNERDATA
);
2648 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2649 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2650 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2651 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2652 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2653 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2654 DestroyWindow(hwnd
);
2656 hwnd
= create_listview_control(LVS_OWNERDATA
);
2657 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2658 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2659 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2660 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
2661 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2662 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
2663 DestroyWindow(hwnd
);
2666 static void test_norecompute(void)
2668 static CHAR testA
[] = "test";
2674 /* self containing control */
2675 hwnd
= create_listview_control(0);
2676 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2677 memset(&item
, 0, sizeof(item
));
2678 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
2680 item
.stateMask
= LVIS_SELECTED
;
2681 item
.state
= LVIS_SELECTED
;
2682 item
.pszText
= testA
;
2683 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2685 /* retrieve with LVIF_NORECOMPUTE */
2686 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2688 item
.pszText
= buff
;
2689 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2690 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2692 ok(lstrcmp(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
2694 item
.mask
= LVIF_TEXT
;
2696 item
.pszText
= LPSTR_TEXTCALLBACK
;
2697 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2700 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2702 item
.pszText
= buff
;
2703 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2705 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2706 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2708 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2709 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2710 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
2712 DestroyWindow(hwnd
);
2715 hwnd
= create_listview_control(LVS_OWNERDATA
);
2716 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2718 item
.mask
= LVIF_STATE
;
2719 item
.stateMask
= LVIS_SELECTED
;
2720 item
.state
= LVIS_SELECTED
;
2722 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2725 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2727 item
.pszText
= buff
;
2728 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2729 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2730 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2732 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2733 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2734 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
2736 DestroyWindow(hwnd
);
2739 static void test_nosortheader(void)
2744 hwnd
= create_listview_control(0);
2745 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2747 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2748 ok(IsWindow(header
), "header expected\n");
2750 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2751 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
2753 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2754 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
2755 /* HDS_BUTTONS retained */
2756 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2757 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
2759 DestroyWindow(hwnd
);
2761 /* create with LVS_NOSORTHEADER */
2762 hwnd
= create_listview_control(LVS_NOSORTHEADER
);
2763 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2765 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2766 ok(IsWindow(header
), "header expected\n");
2768 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2769 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2771 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2772 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
2773 /* not changed here */
2774 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2775 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2777 DestroyWindow(hwnd
);
2780 static void test_setredraw(void)
2786 hwnd
= create_listview_control(0);
2787 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2789 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2790 ListView seems to handle it internally without DefWinProc */
2792 /* default value first */
2793 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2796 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2797 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2798 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2800 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2801 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2803 DestroyWindow(hwnd
);
2806 static void test_hittest(void)
2812 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2815 HIMAGELIST himl
, himl2
;
2818 hwnd
= create_listview_control(0);
2819 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2821 /* LVS_REPORT with a single subitem (2 columns) */
2822 insert_column(hwnd
, 0);
2823 insert_column(hwnd
, 1);
2824 insert_item(hwnd
, 0);
2827 /* the only purpose of that line is to be as long as a half item rect */
2828 item
.pszText
= text
;
2829 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
2832 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
2834 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
2837 memset(&bounds
, 0, sizeof(bounds
));
2838 bounds
.left
= LVIR_BOUNDS
;
2839 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
2840 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
2841 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
2842 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
2845 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2846 x
= pos
.x
+ 50; /* column half width */
2847 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2848 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, __LINE__
);
2849 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2850 x
= pos
.x
+ 150; /* outside column */
2851 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2852 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2853 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2854 y
= (bounds
.bottom
- bounds
.top
) / 2;
2855 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, TRUE
, __LINE__
);
2856 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2857 /* outside possible client rectangle (to right) */
2859 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2860 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2861 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2862 y
= (bounds
.bottom
- bounds
.top
) / 2;
2863 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, TRUE
, __LINE__
);
2864 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2865 /* subitem returned with -1 item too */
2868 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2869 /* parent client area is 100x100 by default */
2870 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
2871 x
= pos
.x
+ 150; /* outside column */
2872 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2873 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, FALSE
, FALSE
, __LINE__
);
2874 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2875 y
= (bounds
.bottom
- bounds
.top
) / 2;
2876 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, FALSE
, TRUE
, __LINE__
);
2877 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2878 /* the same with LVS_EX_FULLROWSELECT */
2879 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
2880 x
= pos
.x
+ 150; /* outside column */
2881 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2882 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, FALSE
, FALSE
, __LINE__
);
2883 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2884 y
= (bounds
.bottom
- bounds
.top
) / 2;
2885 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2886 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
2887 x
= pos
.x
+ 150; /* outside column */
2888 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2889 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2890 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2891 y
= (bounds
.bottom
- bounds
.top
) / 2;
2892 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, TRUE
, __LINE__
);
2893 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2894 /* outside possible client rectangle (to right) */
2896 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2897 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2898 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2899 y
= (bounds
.bottom
- bounds
.top
) / 2;
2900 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, TRUE
, __LINE__
);
2901 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2902 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2903 himl
= ImageList_Create(16, 16, 0, 4, 4);
2904 ok(himl
!= NULL
, "failed to create imagelist\n");
2905 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
2906 ok(hbmp
!= NULL
, "failed to create bitmap\n");
2907 r
= ImageList_Add(himl
, hbmp
, 0);
2908 ok(r
== 0, "should be zero\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
== 1, "should be one\n");
2914 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
2915 ok(r
== 0, "should return zero\n");
2917 item
.mask
= LVIF_IMAGE
;
2921 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2925 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2926 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, __LINE__
);
2927 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2928 y
= (bounds
.bottom
- bounds
.top
) / 2;
2929 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2931 /* state icons indices are 1 based, check with valid index */
2932 item
.mask
= LVIF_STATE
;
2933 item
.state
= INDEXTOSTATEIMAGEMASK(1);
2934 item
.stateMask
= LVIS_STATEIMAGEMASK
;
2937 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2941 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2942 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, __LINE__
);
2943 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2944 y
= (bounds
.bottom
- bounds
.top
) / 2;
2945 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2947 himl2
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)NULL
);
2948 ok(himl2
== himl
, "should return handle\n");
2950 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
2951 ok(r
== 0, "should return zero\n");
2954 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2955 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, __LINE__
);
2956 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2957 y
= (bounds
.bottom
- bounds
.top
) / 2;
2958 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2960 DestroyWindow(hwnd
);
2963 static void test_getviewrect(void)
2970 hwnd
= create_listview_control(0);
2971 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2974 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
2977 insert_column(hwnd
, 0);
2978 insert_column(hwnd
, 1);
2980 memset(&item
, 0, sizeof(item
));
2983 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
2985 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
2987 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
2990 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
2991 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
2993 /* left is set to (2e31-1) - XP SP2 */
2994 expect(0, rect
.right
);
2995 expect(0, rect
.top
);
2996 expect(0, rect
.bottom
);
2998 /* switch to LVS_ICON */
2999 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3001 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3002 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3004 expect(0, rect
.left
);
3005 expect(0, rect
.top
);
3006 /* precise value differs for 2k, XP and Vista */
3007 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3008 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3010 DestroyWindow(hwnd
);
3013 static void test_getitemposition(void)
3020 hwnd
= create_listview_control(0);
3021 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3022 header
= subclass_header(hwnd
);
3024 /* LVS_REPORT, single item, no columns added */
3025 insert_item(hwnd
, 0);
3027 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3030 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3032 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3034 /* LVS_REPORT, single item, single column */
3035 insert_column(hwnd
, 0);
3037 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3040 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3042 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3044 memset(&rect
, 0, sizeof(rect
));
3045 SendMessage(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3048 /* offset by header height */
3049 expect(rect
.bottom
- rect
.top
, pt
.y
);
3051 DestroyWindow(hwnd
);
3054 static void test_columnscreation(void)
3059 hwnd
= create_listview_control(0);
3060 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3062 insert_item(hwnd
, 0);
3064 /* headers columns aren't created automatically */
3065 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3066 ok(IsWindow(header
), "Expected header handle\n");
3067 r
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
3070 DestroyWindow(hwnd
);
3073 static void test_getitemrect(void)
3085 hwnd
= create_listview_control(0);
3086 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3089 memset(&item
, 0, sizeof(item
));
3092 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3095 rect
.left
= LVIR_BOUNDS
;
3096 rect
.right
= rect
.top
= rect
.bottom
= -1;
3097 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3100 /* zero width rectangle with no padding */
3101 expect(0, rect
.left
);
3102 expect(0, rect
.right
);
3104 insert_column(hwnd
, 0);
3105 insert_column(hwnd
, 1);
3107 col
.mask
= LVCF_WIDTH
;
3109 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 0, (LPARAM
)&col
);
3112 col
.mask
= LVCF_WIDTH
;
3114 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 1, (LPARAM
)&col
);
3117 rect
.left
= LVIR_BOUNDS
;
3118 rect
.right
= rect
.top
= rect
.bottom
= -1;
3119 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3122 /* still no left padding */
3123 expect(0, rect
.left
);
3124 expect(150, rect
.right
);
3126 rect
.left
= LVIR_SELECTBOUNDS
;
3127 rect
.right
= rect
.top
= rect
.bottom
= -1;
3128 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3131 expect(2, rect
.left
);
3133 rect
.left
= LVIR_LABEL
;
3134 rect
.right
= rect
.top
= rect
.bottom
= -1;
3135 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3137 /* padding, column width */
3138 expect(2, rect
.left
);
3139 expect(50, rect
.right
);
3141 /* no icons attached */
3142 rect
.left
= LVIR_ICON
;
3143 rect
.right
= rect
.top
= rect
.bottom
= -1;
3144 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3147 expect(2, rect
.left
);
3148 expect(2, rect
.right
);
3151 order
[0] = 1; order
[1] = 0;
3152 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3155 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3157 /* 1 indexed column width + padding */
3158 todo_wine
expect(102, pt
.x
);
3159 /* rect is at zero too */
3160 rect
.left
= LVIR_BOUNDS
;
3161 rect
.right
= rect
.top
= rect
.bottom
= -1;
3162 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3164 expect(0, rect
.left
);
3165 /* just width sum */
3166 expect(150, rect
.right
);
3168 rect
.left
= LVIR_SELECTBOUNDS
;
3169 rect
.right
= rect
.top
= rect
.bottom
= -1;
3170 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3172 /* column width + padding */
3173 todo_wine
expect(102, rect
.left
);
3175 /* back to initial order */
3176 order
[0] = 0; order
[1] = 1;
3177 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3181 himl
= ImageList_Create(16, 16, 0, 2, 2);
3182 ok(himl
!= NULL
, "failed to create imagelist\n");
3183 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3184 ok(hbm
!= NULL
, "failed to create bitmap\n");
3185 r
= ImageList_Add(himl
, hbm
, 0);
3186 ok(r
== 0, "should be zero\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
== 1, "should be one\n");
3192 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3193 ok(r
== 0, "should return zero\n");
3195 item
.mask
= LVIF_STATE
;
3196 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3197 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3200 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3204 rect
.left
= LVIR_ICON
;
3205 rect
.right
= rect
.top
= rect
.bottom
= -1;
3206 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3208 /* padding + stateicon width */
3209 expect(18, rect
.left
);
3210 expect(18, rect
.right
);
3212 rect
.left
= LVIR_LABEL
;
3213 rect
.right
= rect
.top
= rect
.bottom
= -1;
3214 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3216 /* padding + stateicon width -> column width */
3217 expect(18, rect
.left
);
3218 expect(50, rect
.right
);
3220 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)NULL
);
3221 ok(r
!= 0, "should return current list handle\n");
3223 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3224 ok(r
== 0, "should return zero\n");
3226 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3229 item
.stateMask
= ~0;
3232 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3236 rect
.left
= LVIR_ICON
;
3237 rect
.right
= rect
.top
= rect
.bottom
= -1;
3238 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3240 /* padding, icon width */
3241 expect(2, rect
.left
);
3242 expect(18, rect
.right
);
3244 rect
.left
= LVIR_LABEL
;
3245 rect
.right
= rect
.top
= rect
.bottom
= -1;
3246 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3248 /* padding + icon width -> column width */
3249 expect(18, rect
.left
);
3250 expect(50, rect
.right
);
3253 rect
.left
= LVIR_SELECTBOUNDS
;
3254 rect
.right
= rect
.top
= rect
.bottom
= -1;
3255 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3257 /* padding, column width */
3258 expect(2, rect
.left
);
3259 expect(50, rect
.right
);
3261 /* try with indentation */
3262 item
.mask
= LVIF_INDENT
;
3266 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3270 rect
.left
= LVIR_BOUNDS
;
3271 rect
.right
= rect
.top
= rect
.bottom
= -1;
3272 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3274 /* padding + 1 icon width, column width */
3275 expect(0, rect
.left
);
3276 expect(150, rect
.right
);
3279 rect
.left
= LVIR_SELECTBOUNDS
;
3280 rect
.right
= rect
.top
= rect
.bottom
= -1;
3281 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3283 /* padding + 1 icon width, column width */
3284 expect(2 + 16, rect
.left
);
3285 expect(50, rect
.right
);
3288 rect
.left
= LVIR_LABEL
;
3289 rect
.right
= rect
.top
= rect
.bottom
= -1;
3290 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3292 /* padding + 2 icon widths, column width */
3293 expect(2 + 16*2, rect
.left
);
3294 expect(50, rect
.right
);
3297 rect
.left
= LVIR_ICON
;
3298 rect
.right
= rect
.top
= rect
.bottom
= -1;
3299 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3301 /* padding + 1 icon width indentation, icon width */
3302 expect(2 + 16, rect
.left
);
3303 expect(34, rect
.right
);
3306 DestroyWindow(hwnd
);
3309 static void test_editbox(void)
3311 HWND hwnd
, hwndedit
, hwndedit2
;
3314 static CHAR testitemA
[] = "testitem";
3315 static CHAR testitem1A
[] = "testitem1";
3316 static CHAR buffer
[10];
3318 hwnd
= create_listview_control(LVS_EDITLABELS
);
3319 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3321 insert_column(hwnd
, 0);
3323 memset(&item
, 0, sizeof(item
));
3324 item
.mask
= LVIF_TEXT
;
3325 item
.pszText
= testitemA
;
3328 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3331 /* setting focus is necessary */
3333 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3334 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3336 /* modify initial string */
3337 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3339 /* return focus to listview */
3342 memset(&item
, 0, sizeof(item
));
3343 item
.mask
= LVIF_TEXT
;
3344 item
.pszText
= buffer
;
3345 item
.cchTextMax
= 10;
3348 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3351 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3353 /* send LVM_EDITLABEL on already created edit */
3355 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3356 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3357 /* focus will be set to edit */
3358 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
3359 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3360 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
3362 /* creating label disabled when control isn't focused */
3364 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3365 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3367 /* check EN_KILLFOCUS handling */
3368 memset(&item
, 0, sizeof(item
));
3369 item
.pszText
= testitemA
;
3372 r
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3376 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3377 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3378 /* modify edit and notify control that it lost focus */
3379 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3381 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3383 memset(&item
, 0, sizeof(item
));
3384 item
.pszText
= buffer
;
3385 item
.cchTextMax
= 10;
3388 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3389 expect(lstrlen(item
.pszText
), r
);
3390 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3391 /* end edit without saving */
3392 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
3394 memset(&item
, 0, sizeof(item
));
3395 item
.pszText
= buffer
;
3396 item
.cchTextMax
= 10;
3399 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3400 expect(lstrlen(item
.pszText
), r
);
3401 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3403 /* LVM_EDITLABEL with -1 destroys current edit */
3404 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
3405 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3406 /* no edit present */
3407 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3408 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3409 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3410 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3412 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3413 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3414 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3415 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3416 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3417 /* check another negative value */
3418 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3419 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3420 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3421 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -2, 0);
3422 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3423 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3424 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3425 /* and value greater than max item index */
3426 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3427 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3428 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3429 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3430 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, r
, 0);
3431 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3432 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3433 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3435 /* messaging tests */
3437 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3439 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3440 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3441 /* testing only sizing messages */
3442 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
3443 "edit box create - sizing", TRUE
);
3445 DestroyWindow(hwnd
);
3448 static void test_notifyformat(void)
3453 hwnd
= create_listview_control(0);
3454 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3456 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3457 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3458 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3460 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3462 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
3464 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3467 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
3469 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3474 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3475 DestroyWindow(hwnd
);
3479 DestroyWindow(hwnd
);
3481 /* test failure in parent WM_NOTIFYFORMAT */
3483 hwnd
= create_listview_control(0);
3484 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3485 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3486 ok(IsWindow(header
), "expected header to be created\n");
3487 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3489 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3491 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3492 ok(r
!= 0, "Expected valid format\n");
3494 notifyFormat
= NFR_UNICODE
;
3495 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3496 expect(NFR_UNICODE
, r
);
3497 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3499 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3502 notifyFormat
= NFR_ANSI
;
3503 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3504 expect(NFR_ANSI
, r
);
3505 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3507 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3510 DestroyWindow(hwnd
);
3512 /* try different unicode window combination and defaults */
3513 if (!GetModuleHandleW(NULL
))
3515 win_skip("Additional notify format tests are incompatible with Win9x\n");
3519 hwndparentW
= create_parent_window(TRUE
);
3520 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
3521 if (!IsWindow(hwndparentW
)) return;
3524 hwnd
= create_listview_controlW(0, hwndparentW
);
3525 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3526 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3527 ok(IsWindow(header
), "expected header to be created\n");
3528 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3530 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3532 DestroyWindow(hwnd
);
3533 /* receiving error code defaulting to ansi */
3535 hwnd
= create_listview_controlW(0, hwndparentW
);
3536 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3537 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3538 ok(IsWindow(header
), "expected header to be created\n");
3539 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3541 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3543 DestroyWindow(hwnd
);
3544 /* receiving ansi code from unicode window, use it */
3545 notifyFormat
= NFR_ANSI
;
3546 hwnd
= create_listview_controlW(0, hwndparentW
);
3547 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3548 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3549 ok(IsWindow(header
), "expected header to be created\n");
3550 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3552 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3554 DestroyWindow(hwnd
);
3555 /* unicode listview with ansi parent window */
3557 hwnd
= create_listview_controlW(0, hwndparent
);
3558 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3559 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3560 ok(IsWindow(header
), "expected header to be created\n");
3561 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3563 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3565 DestroyWindow(hwnd
);
3566 /* unicode listview with ansi parent window, return error code */
3568 hwnd
= create_listview_controlW(0, hwndparent
);
3569 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3570 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3571 ok(IsWindow(header
), "expected header to be created\n");
3572 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3574 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3576 DestroyWindow(hwnd
);
3578 DestroyWindow(hwndparentW
);
3581 static void test_indentation(void)
3587 hwnd
= create_listview_control(0);
3588 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3590 memset(&item
, 0, sizeof(item
));
3591 item
.mask
= LVIF_INDENT
;
3593 item
.iIndent
= I_INDENTCALLBACK
;
3594 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3597 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3600 item
.mask
= LVIF_INDENT
;
3601 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3604 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3605 "get indent dispinfo", FALSE
);
3607 DestroyWindow(hwnd
);
3610 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
3615 static BOOL
is_below_comctl_5(void)
3620 hwnd
= create_listview_control(0);
3621 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3622 insert_item(hwnd
, 0);
3624 ret
= SendMessage(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
3626 DestroyWindow(hwnd
);
3631 static void unload_v6_module(ULONG_PTR cookie
)
3634 BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
, ULONG_PTR
);
3636 hKernel32
= GetModuleHandleA("kernel32.dll");
3637 pDeactivateActCtx
= (void*)GetProcAddress(hKernel32
, "DeactivateActCtx");
3638 if (!pDeactivateActCtx
)
3640 win_skip("Activation contexts unsupported\n");
3644 pDeactivateActCtx(0, cookie
);
3646 DeleteFileA(manifest_name
);
3649 static BOOL
load_v6_module(ULONG_PTR
*pcookie
)
3652 HANDLE (WINAPI
*pCreateActCtxA
)(ACTCTXA
*);
3653 BOOL (WINAPI
*pActivateActCtx
)(HANDLE
, ULONG_PTR
*);
3662 hKernel32
= GetModuleHandleA("kernel32.dll");
3663 pCreateActCtxA
= (void*)GetProcAddress(hKernel32
, "CreateActCtxA");
3664 pActivateActCtx
= (void*)GetProcAddress(hKernel32
, "ActivateActCtx");
3665 if (!(pCreateActCtxA
&& pActivateActCtx
))
3667 win_skip("Activation contexts unsupported. No version 6 tests possible.\n");
3671 /* create manifest */
3672 file
= CreateFileA( manifest_name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
3673 if (file
!= INVALID_HANDLE_VALUE
)
3675 ret
= (WriteFile( file
, manifest
, sizeof(manifest
)-1, &written
, NULL
) &&
3676 written
== sizeof(manifest
)-1);
3677 CloseHandle( file
);
3680 DeleteFileA( manifest_name
);
3681 skip("Failed to fill manifest file. Skipping comctl32 V6 tests.\n");
3685 trace("created %s\n", manifest_name
);
3689 skip("Failed to create manifest file. Skipping comctl32 V6 tests.\n");
3693 memset(&ctx
, 0, sizeof(ctx
));
3694 ctx
.cbSize
= sizeof(ctx
);
3695 ctx
.lpSource
= manifest_name
;
3697 hCtx
= pCreateActCtxA(&ctx
);
3698 ok(hCtx
!= 0, "Expected context handle\n");
3700 ret
= pActivateActCtx(hCtx
, pcookie
);
3705 win_skip("A problem during context activation occurred.\n");
3706 DeleteFileA(manifest_name
);
3711 /* this is a XP SP3 failure workaround */
3712 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
3713 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
,
3715 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
3716 if (!IsWindow(hwnd
))
3718 win_skip("FIXME: failed to create ListView window.\n");
3719 unload_v6_module(*pcookie
);
3723 DestroyWindow(hwnd
);
3729 static void test_get_set_view(void)
3735 /* test style->view mapping */
3736 hwnd
= create_listview_control(0);
3737 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3739 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3740 expect(LV_VIEW_DETAILS
, ret
);
3742 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3744 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
3745 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3746 expect(LV_VIEW_ICON
, ret
);
3748 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3749 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
3750 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3751 expect(LV_VIEW_SMALLICON
, ret
);
3753 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3754 SetWindowLongPtr(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
3755 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3756 expect(LV_VIEW_LIST
, ret
);
3758 /* switching view doesn't touch window style */
3759 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
3761 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3762 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3763 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 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_SMALLICON
, 0);
3769 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3770 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3772 DestroyWindow(hwnd
);
3775 static void test_canceleditlabel(void)
3777 HWND hwnd
, hwndedit
;
3781 static CHAR test
[] = "test";
3782 static const CHAR test1
[] = "test1";
3784 hwnd
= create_listview_control(LVS_EDITLABELS
);
3785 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3787 insert_item(hwnd
, 0);
3789 /* try without edit created */
3790 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3793 /* cancel without data change */
3795 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3796 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3797 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3799 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3801 /* cancel after data change */
3802 memset(&itema
, 0, sizeof(itema
));
3803 itema
.pszText
= test
;
3804 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
3807 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3808 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3809 ret
= SetWindowText(hwndedit
, test1
);
3810 ok(ret
!= 0, "Expected edit text to change\n");
3811 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3813 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3814 memset(&itema
, 0, sizeof(itema
));
3815 itema
.pszText
= buff
;
3816 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3817 ret
= SendMessage(hwnd
, LVM_GETITEMTEXT
, 0, (LPARAM
)&itema
);
3819 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
3821 DestroyWindow(hwnd
);
3824 static void test_mapidindex(void)
3829 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3830 hwnd
= create_listview_control(LVS_OWNERDATA
);
3831 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3832 insert_item(hwnd
, 0);
3833 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3835 DestroyWindow(hwnd
);
3837 hwnd
= create_listview_control(0);
3838 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3840 /* LVM_MAPINDEXTOID with invalid index */
3841 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3844 insert_item(hwnd
, 0);
3845 insert_item(hwnd
, 1);
3847 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
3849 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
3852 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3854 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
3856 /* remove 0 indexed item, id retained */
3857 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
3858 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3860 /* new id starts from previous value */
3861 insert_item(hwnd
, 1);
3862 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
3865 /* get index by id */
3866 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
3868 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
3870 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
3872 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
3875 DestroyWindow(hwnd
);
3878 static void test_getitemspacing(void)
3887 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
3888 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
3891 hwnd
= create_custom_listview_control(0);
3892 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3894 expect(cx
, LOWORD(ret
));
3895 expect(cy
, HIWORD(ret
));
3897 /* now try with icons */
3898 himl
= ImageList_Create(40, 40, 0, 4, 4);
3899 ok(himl
!= NULL
, "failed to create imagelist\n");
3900 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
3901 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3902 ret
= ImageList_Add(himl
, hbmp
, 0);
3904 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
3907 itema
.mask
= LVIF_IMAGE
;
3911 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
3913 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3915 /* spacing + icon size returned */
3916 expect(cx
+ 40, LOWORD(ret
));
3917 expect(cy
+ 40, HIWORD(ret
));
3919 DestroyWindow(hwnd
);
3921 hwnd
= create_custom_listview_control(LVS_SMALLICON
);
3922 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3924 expect(cx
, LOWORD(ret
));
3925 expect(cy
, HIWORD(ret
));
3927 DestroyWindow(hwnd
);
3929 hwnd
= create_custom_listview_control(LVS_REPORT
);
3930 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3932 expect(cx
, LOWORD(ret
));
3933 expect(cy
, HIWORD(ret
));
3935 DestroyWindow(hwnd
);
3937 hwnd
= create_custom_listview_control(LVS_LIST
);
3938 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3940 expect(cx
, LOWORD(ret
));
3941 expect(cy
, HIWORD(ret
));
3943 DestroyWindow(hwnd
);
3946 static void test_getcolumnwidth(void)
3953 /* default column width */
3954 hwnd
= create_custom_listview_control(0);
3955 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
3957 style
= GetWindowLong(hwnd
, GWL_STYLE
);
3958 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
3959 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
3960 todo_wine
expect(8, ret
);
3961 style
= GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
3962 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
3964 ret
= SendMessage(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
3966 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
3968 DestroyWindow(hwnd
);
3971 static void test_scrollnotify(void)
3976 hwnd
= create_listview_control(0);
3978 insert_column(hwnd
, 0);
3979 insert_column(hwnd
, 1);
3980 insert_item(hwnd
, 0);
3982 /* make it scrollable - resize */
3983 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3985 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3988 /* try with dummy call */
3989 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3990 ret
= SendMessage(hwnd
, LVM_SCROLL
, 0, 0);
3992 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
3993 "scroll notify 1", TRUE
);
3995 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3996 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 0);
3998 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
3999 "scroll notify 2", TRUE
);
4001 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4002 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 1);
4004 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4005 "scroll notify 3", TRUE
);
4007 DestroyWindow(hwnd
);
4010 START_TEST(listview
)
4013 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
4015 ULONG_PTR ctx_cookie
;
4017 hComctl32
= GetModuleHandleA("comctl32.dll");
4018 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
4019 if (pInitCommonControlsEx
)
4021 INITCOMMONCONTROLSEX iccex
;
4022 iccex
.dwSize
= sizeof(iccex
);
4023 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
4024 pInitCommonControlsEx(&iccex
);
4027 InitCommonControls();
4029 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
4031 hwndparent
= create_parent_window(FALSE
);
4032 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4034 g_is_below_5
= is_below_comctl_5();
4042 test_icon_spacing();
4045 test_item_position();
4050 test_subitem_rect();
4054 test_nosortheader();
4058 test_getitemposition();
4059 test_columnscreation();
4061 test_notifyformat();
4063 test_getitemspacing();
4064 test_getcolumnwidth();
4066 if (!load_v6_module(&ctx_cookie
))
4068 DestroyWindow(hwndparent
);
4072 /* comctl32 version 6 tests start here */
4073 test_get_set_view();
4074 test_canceleditlabel();
4076 test_scrollnotify();
4078 unload_v6_module(ctx_cookie
);
4080 DestroyWindow(hwndparent
);