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 /* format reported to control:
83 -1 falls to defproc, anything else returned */
85 /* indicates we're running < 5.80 version */
88 static HWND
subclass_editbox(HWND hwndListview
);
90 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
92 static const struct message create_parent_wnd_seq
[] = {
93 { WM_GETMINMAXINFO
, sent
},
94 { WM_NCCREATE
, sent
},
95 { WM_NCCALCSIZE
, sent
|wparam
, 0 },
97 { WM_SHOWWINDOW
, sent
|wparam
, 1 },
98 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0 },
99 { WM_QUERYNEWPALETTE
, sent
|optional
},
100 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0 },
101 { WM_WINDOWPOSCHANGED
, sent
|optional
},
102 { WM_NCCALCSIZE
, sent
|wparam
|optional
, 1 },
103 { WM_ACTIVATEAPP
, sent
|wparam
, 1 },
104 { WM_NCACTIVATE
, sent
|wparam
, 1 },
105 { WM_ACTIVATE
, sent
|wparam
, 1 },
106 { WM_IME_SETCONTEXT
, sent
|wparam
|defwinproc
|optional
, 1 },
107 { WM_IME_NOTIFY
, sent
|defwinproc
|optional
},
108 { WM_SETFOCUS
, sent
|wparam
|defwinproc
, 0 },
109 /* Win9x adds SWP_NOZORDER below */
110 { WM_WINDOWPOSCHANGED
, sent
, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
111 { WM_NCCALCSIZE
, sent
|wparam
|optional
, 1 },
117 static const struct message redraw_listview_seq
[] = {
118 { WM_PAINT
, sent
|id
, 0, 0, LISTVIEW_ID
},
119 { WM_PAINT
, sent
|id
, 0, 0, HEADER_ID
},
120 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
121 { WM_ERASEBKGND
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
122 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
123 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
124 { WM_ERASEBKGND
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
128 static const struct message listview_icon_spacing_seq
[] = {
129 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(20, 30) },
130 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(25, 35) },
131 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(-1, -1) },
135 static const struct message listview_color_seq
[] = {
136 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
137 { LVM_GETBKCOLOR
, sent
},
138 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
139 { LVM_GETTEXTCOLOR
, sent
},
140 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
141 { LVM_GETTEXTBKCOLOR
, sent
},
143 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
144 { LVM_GETBKCOLOR
, sent
},
145 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
146 { LVM_GETTEXTCOLOR
, sent
},
147 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
148 { LVM_GETTEXTBKCOLOR
, sent
},
150 { LVM_SETBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
151 { LVM_GETBKCOLOR
, sent
},
152 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, CLR_NONE
},
153 { LVM_GETTEXTCOLOR
, sent
},
154 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
155 { LVM_GETTEXTBKCOLOR
, sent
},
157 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
158 { LVM_GETBKCOLOR
, sent
},
159 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
160 { LVM_GETTEXTCOLOR
, sent
},
161 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
162 { LVM_GETTEXTBKCOLOR
, sent
},
166 static const struct message listview_item_count_seq
[] = {
167 { LVM_GETITEMCOUNT
, sent
},
168 { LVM_INSERTITEM
, sent
},
169 { LVM_INSERTITEM
, sent
},
170 { LVM_INSERTITEM
, sent
},
171 { LVM_GETITEMCOUNT
, sent
},
172 { LVM_DELETEITEM
, sent
|wparam
, 2 },
173 { LVM_GETITEMCOUNT
, sent
},
174 { LVM_DELETEALLITEMS
, sent
},
175 { LVM_GETITEMCOUNT
, sent
},
176 { LVM_INSERTITEM
, sent
},
177 { LVM_INSERTITEM
, sent
},
178 { LVM_GETITEMCOUNT
, sent
},
179 { LVM_INSERTITEM
, sent
},
180 { LVM_GETITEMCOUNT
, sent
},
184 static const struct message listview_itempos_seq
[] = {
185 { LVM_INSERTITEM
, sent
},
186 { LVM_INSERTITEM
, sent
},
187 { LVM_INSERTITEM
, sent
},
188 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 1, MAKELPARAM(10,5) },
189 { LVM_GETITEMPOSITION
, sent
|wparam
, 1 },
190 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 2, MAKELPARAM(0,0) },
191 { LVM_GETITEMPOSITION
, sent
|wparam
, 2 },
192 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 0, MAKELPARAM(20,20) },
193 { LVM_GETITEMPOSITION
, sent
|wparam
, 0 },
197 static const struct message listview_ownerdata_switchto_seq
[] = {
198 { WM_STYLECHANGING
, sent
},
199 { WM_STYLECHANGED
, sent
},
203 static const struct message listview_getorderarray_seq
[] = {
204 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
205 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
209 static const struct message empty_seq
[] = {
213 static const struct message forward_erasebkgnd_parent_seq
[] = {
214 { WM_ERASEBKGND
, sent
},
218 static const struct message ownderdata_select_focus_parent_seq
[] = {
219 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
220 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
224 static const struct message textcallback_set_again_parent_seq
[] = {
225 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
226 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
230 static const struct message single_getdispinfo_parent_seq
[] = {
231 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
235 static const struct message getitemposition_seq1
[] = {
236 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
240 static const struct message getitemposition_seq2
[] = {
241 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
242 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
246 static const struct message editbox_create_pos
[] = {
247 /* sequence sent after LVN_BEGINLABELEDIT */
248 { WM_WINDOWPOSCHANGING
, sent
},
249 { WM_NCCALCSIZE
, sent
},
250 { WM_WINDOWPOSCHANGED
, sent
},
251 { WM_MOVE
, sent
|defwinproc
},
252 { WM_SIZE
, sent
|defwinproc
},
253 /* the rest is todo */
254 { WM_WINDOWPOSCHANGING
, sent
},
255 { WM_WINDOWPOSCHANGED
, sent
},
264 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
266 static LONG defwndproc_counter
= 0;
270 msg
.message
= message
;
271 msg
.flags
= sent
|wparam
|lparam
;
272 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
275 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
277 /* log system messages, except for painting */
278 if (message
< WM_USER
&&
279 message
!= WM_PAINT
&&
280 message
!= WM_ERASEBKGND
&&
281 message
!= WM_NCPAINT
&&
282 message
!= WM_NCHITTEST
&&
283 message
!= WM_GETTEXT
&&
284 message
!= WM_GETICON
&&
285 message
!= WM_DEVICECHANGE
)
287 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
289 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
291 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
297 switch (((NMHDR
*)lParam
)->code
)
299 case LVN_BEGINLABELEDIT
:
300 /* subclass edit box */
302 subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
306 case LVN_ENDLABELEDIT
:
307 /* always accept new item text */
312 case WM_NOTIFYFORMAT
:
314 /* force to return format */
315 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
320 defwndproc_counter
++;
321 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
322 defwndproc_counter
--;
327 static BOOL
register_parent_wnd_class(BOOL Unicode
)
335 clsW
.lpfnWndProc
= parent_wnd_proc
;
338 clsW
.hInstance
= GetModuleHandleW(NULL
);
340 clsW
.hCursor
= LoadCursorA(0, IDC_ARROW
);
341 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
342 clsW
.lpszMenuName
= NULL
;
343 clsW
.lpszClassName
= testparentclassW
;
348 clsA
.lpfnWndProc
= parent_wnd_proc
;
351 clsA
.hInstance
= GetModuleHandleA(NULL
);
353 clsA
.hCursor
= LoadCursorA(0, IDC_ARROW
);
354 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
355 clsA
.lpszMenuName
= NULL
;
356 clsA
.lpszClassName
= "Listview test parent class";
359 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
362 static HWND
create_parent_window(BOOL Unicode
)
364 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W'};
366 if (!register_parent_wnd_class(Unicode
))
373 return CreateWindowExW(0, testparentclassW
, nameW
,
374 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
375 WS_MAXIMIZEBOX
| WS_VISIBLE
,
377 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
379 return CreateWindowExA(0, "Listview test parent class",
380 "Listview test parent window",
381 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
382 WS_MAXIMIZEBOX
| WS_VISIBLE
,
384 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
387 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
389 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
390 static LONG defwndproc_counter
= 0;
394 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
396 /* some debug output for style changing */
397 if ((message
== WM_STYLECHANGING
||
398 message
== WM_STYLECHANGED
) && lParam
)
400 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
401 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
404 msg
.message
= message
;
405 msg
.flags
= sent
|wparam
|lparam
;
406 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
409 msg
.id
= LISTVIEW_ID
;
410 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
412 defwndproc_counter
++;
413 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
414 defwndproc_counter
--;
418 static HWND
create_listview_control(DWORD style
)
420 struct subclass_info
*info
;
424 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
428 GetClientRect(hwndparent
, &rect
);
429 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
430 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
| style
,
431 0, 0, rect
.right
, rect
.bottom
,
432 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
433 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
437 HeapFree(GetProcessHeap(), 0, info
);
441 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
442 (LONG_PTR
)listview_subclass_proc
);
443 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
448 /* unicode listview window with specified parent */
449 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
451 struct subclass_info
*info
;
454 static const WCHAR nameW
[] = {'f','o','o',0};
456 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
460 GetClientRect(parent
, &rect
);
461 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
462 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
| style
,
463 0, 0, rect
.right
, rect
.bottom
,
464 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
465 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
469 HeapFree(GetProcessHeap(), 0, info
);
473 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
474 (LONG_PTR
)listview_subclass_proc
);
475 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
480 static HWND
create_custom_listview_control(DWORD style
)
482 struct subclass_info
*info
;
486 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
490 GetClientRect(hwndparent
, &rect
);
491 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
492 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
493 0, 0, rect
.right
, rect
.bottom
,
494 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
495 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
499 HeapFree(GetProcessHeap(), 0, info
);
503 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
504 (LONG_PTR
)listview_subclass_proc
);
505 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
510 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
512 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
513 static LONG defwndproc_counter
= 0;
517 trace("header: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
519 msg
.message
= message
;
520 msg
.flags
= sent
|wparam
|lparam
;
521 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
525 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
527 defwndproc_counter
++;
528 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
529 defwndproc_counter
--;
533 static HWND
subclass_header(HWND hwndListview
)
535 struct subclass_info
*info
;
538 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
542 hwnd
= ListView_GetHeader(hwndListview
);
543 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
544 (LONG_PTR
)header_subclass_proc
);
545 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
550 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
552 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
553 static LONG defwndproc_counter
= 0;
557 msg
.message
= message
;
558 msg
.flags
= sent
|wparam
|lparam
;
559 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
563 /* all we need is sizing */
564 if (message
== WM_WINDOWPOSCHANGING
||
565 message
== WM_NCCALCSIZE
||
566 message
== WM_WINDOWPOSCHANGED
||
567 message
== WM_MOVE
||
570 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
573 defwndproc_counter
++;
574 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
575 defwndproc_counter
--;
579 static HWND
subclass_editbox(HWND hwndListview
)
581 struct subclass_info
*info
;
584 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
588 hwnd
= (HWND
)SendMessage(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
589 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
590 (LONG_PTR
)editbox_subclass_proc
);
591 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
596 /* Performs a single LVM_HITTEST test */
597 static void test_lvm_hittest(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
,
598 BOOL todo_item
, BOOL todo_flags
, int line
)
607 trace("hittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
608 ret
= SendMessage(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
614 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
615 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
616 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
621 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
622 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
623 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
629 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
632 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
635 /* Performs a single LVM_SUBITEMHITTEST test */
636 static void test_lvm_subitemhittest(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
637 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
645 trace("subhittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
646 ret
= SendMessage(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
652 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
653 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
658 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
659 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
665 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
668 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
673 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
676 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
679 static void test_images(void)
687 static CHAR hello
[] = "hello";
689 himl
= ImageList_Create(40, 40, 0, 4, 4);
690 ok(himl
!= NULL
, "failed to create imagelist\n");
692 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
693 ok(hbmp
!= NULL
, "failed to create bitmap\n");
695 r
= ImageList_Add(himl
, hbmp
, 0);
696 ok(r
== 0, "should be zero\n");
698 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
699 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
700 ok(hwnd
!= NULL
, "failed to create listview window\n");
702 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
703 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
705 ok(r
== 0, "should return zero\n");
707 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
708 ok(r
== 0, "should return zero\n");
710 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
711 /* returns dimensions */
713 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
714 ok(r
== 0, "should be zero items\n");
716 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
721 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
722 ok(r
== -1, "should fail\n");
725 item
.pszText
= hello
;
726 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
727 ok(r
== 0, "should not fail\n");
729 memset(&r1
, 0, sizeof r1
);
731 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
733 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
734 ok(r
== TRUE
, "should not fail\n");
737 item
.pszText
= hello
;
738 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
739 ok(r
== 0, "should not fail\n");
741 memset(&r2
, 0, sizeof r2
);
743 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
745 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
750 static void test_checkboxes(void)
755 static CHAR text
[] = "Text",
759 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
760 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
761 ok(hwnd
!= NULL
, "failed to create listview window\n");
763 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
764 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
765 item
.stateMask
= 0xffff;
770 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
771 ok(r
== 0, "ret %d\n", r
);
774 item
.mask
= LVIF_STATE
;
775 item
.stateMask
= 0xffff;
776 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
777 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
779 /* Don't set LVIF_STATE */
780 item
.mask
= LVIF_TEXT
;
781 item
.stateMask
= 0xffff;
786 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
787 ok(r
== 1, "ret %d\n", r
);
790 item
.mask
= LVIF_STATE
;
791 item
.stateMask
= 0xffff;
792 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
793 ok(item
.state
== 0, "state %x\n", item
.state
);
795 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
796 ok(r
== 0, "should return zero\n");
798 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
800 item
.mask
= LVIF_STATE
;
801 item
.stateMask
= 0xffff;
802 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
803 ok(item
.state
== 0x1ccc, "state %x\n", item
.state
);
805 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
807 item
.mask
= LVIF_TEXT
;
809 item
.pszText
= text2
;
810 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
811 ok(r
== 2, "ret %d\n", r
);
814 item
.mask
= LVIF_STATE
;
815 item
.stateMask
= 0xffff;
816 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
817 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
819 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
821 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
822 item
.stateMask
= 0xffff;
824 item
.pszText
= text3
;
825 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
826 ok(r
== 3, "ret %d\n", r
);
829 item
.mask
= LVIF_STATE
;
830 item
.stateMask
= 0xffff;
831 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
832 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
834 /* Set an item's state to checked */
836 item
.mask
= LVIF_STATE
;
837 item
.stateMask
= 0xf000;
839 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
842 item
.mask
= LVIF_STATE
;
843 item
.stateMask
= 0xffff;
844 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
845 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
847 /* Check that only the bits we asked for are returned,
848 * and that all the others are set to zero
851 item
.mask
= LVIF_STATE
;
852 item
.stateMask
= 0xf000;
854 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
855 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
857 /* Set the style again and check that doesn't change an item's state */
858 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
859 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
862 item
.mask
= LVIF_STATE
;
863 item
.stateMask
= 0xffff;
864 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
865 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
867 /* Unsetting the checkbox extended style doesn't change an item's state */
868 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
869 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
872 item
.mask
= LVIF_STATE
;
873 item
.stateMask
= 0xffff;
874 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
875 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
877 /* Now setting the style again will change an item's state */
878 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
879 ok(r
== 0, "ret %x\n", r
);
882 item
.mask
= LVIF_STATE
;
883 item
.stateMask
= 0xffff;
884 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
885 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
887 /* Toggle checkbox tests (bug 9934) */
888 memset (&item
, 0xcc, sizeof(item
));
889 item
.mask
= LVIF_STATE
;
892 item
.state
= LVIS_FOCUSED
;
893 item
.stateMask
= LVIS_FOCUSED
;
894 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
898 item
.mask
= LVIF_STATE
;
899 item
.stateMask
= 0xffff;
900 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
901 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
903 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
905 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
909 item
.mask
= LVIF_STATE
;
910 item
.stateMask
= 0xffff;
911 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
912 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
914 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
916 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
920 item
.mask
= LVIF_STATE
;
921 item
.stateMask
= 0xffff;
922 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
923 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
928 static void insert_column(HWND hwnd
, int idx
)
933 memset(&column
, 0xcc, sizeof(column
));
934 column
.mask
= LVCF_SUBITEM
;
935 column
.iSubItem
= idx
;
937 rc
= ListView_InsertColumn(hwnd
, idx
, &column
);
941 static void insert_item(HWND hwnd
, int idx
)
943 static CHAR text
[] = "foo";
948 memset(&item
, 0xcc, sizeof (item
));
949 item
.mask
= LVIF_TEXT
;
954 rc
= ListView_InsertItem(hwnd
, &item
);
958 static void test_items(void)
960 const LPARAM lparamTest
= 0x42;
964 static CHAR text
[] = "Text";
966 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
967 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
968 ok(hwnd
!= NULL
, "failed to create listview window\n");
971 * Test setting/getting item params
974 /* Set up two columns */
975 insert_column(hwnd
, 0);
976 insert_column(hwnd
, 1);
978 /* LVIS_SELECTED with zero stateMask */
980 memset (&item
, 0, sizeof (item
));
981 item
.mask
= LVIF_STATE
;
982 item
.state
= LVIS_SELECTED
;
986 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
987 ok(r
== 0, "ret %d\n", r
);
989 memset (&item
, 0xcc, sizeof (item
));
990 item
.mask
= LVIF_STATE
;
991 item
.stateMask
= LVIS_SELECTED
;
995 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
996 ok(r
!= 0, "ret %d\n", r
);
997 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
998 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1000 /* LVIS_SELECTED with zero stateMask */
1002 memset (&item
, 0, sizeof (item
));
1003 item
.mask
= LVIF_STATE
;
1004 item
.state
= LVIS_FOCUSED
;
1008 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1009 ok(r
== 0, "ret %d\n", r
);
1011 memset (&item
, 0xcc, sizeof (item
));
1012 item
.mask
= LVIF_STATE
;
1013 item
.stateMask
= LVIS_FOCUSED
;
1017 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1018 ok(r
!= 0, "ret %d\n", r
);
1019 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1020 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1022 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1024 memset (&item
, 0, sizeof (item
));
1025 item
.mask
= LVIF_STATE
;
1026 item
.state
= LVIS_CUT
;
1027 item
.stateMask
= LVIS_FOCUSED
;
1030 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1031 ok(r
== 0, "ret %d\n", r
);
1033 memset (&item
, 0xcc, sizeof (item
));
1034 item
.mask
= LVIF_STATE
;
1035 item
.stateMask
= LVIS_CUT
;
1039 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1040 ok(r
!= 0, "ret %d\n", r
);
1041 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1042 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1044 /* Insert an item with just a param */
1045 memset (&item
, 0xcc, sizeof (item
));
1046 item
.mask
= LVIF_PARAM
;
1049 item
.lParam
= lparamTest
;
1050 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1051 ok(r
== 0, "ret %d\n", r
);
1053 /* Test getting of the param */
1054 memset (&item
, 0xcc, sizeof (item
));
1055 item
.mask
= LVIF_PARAM
;
1058 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1059 ok(r
!= 0, "ret %d\n", r
);
1060 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1062 /* Set up a subitem */
1063 memset (&item
, 0xcc, sizeof (item
));
1064 item
.mask
= LVIF_TEXT
;
1067 item
.pszText
= text
;
1068 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1069 ok(r
!= 0, "ret %d\n", r
);
1071 /* Query param from subitem: returns main item param */
1072 memset (&item
, 0xcc, sizeof (item
));
1073 item
.mask
= LVIF_PARAM
;
1076 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1077 ok(r
!= 0, "ret %d\n", r
);
1078 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1080 /* Set up param on first subitem: no effect */
1081 memset (&item
, 0xcc, sizeof (item
));
1082 item
.mask
= LVIF_PARAM
;
1085 item
.lParam
= lparamTest
+1;
1086 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1087 ok(r
== 0, "ret %d\n", r
);
1089 /* Query param from subitem again: should still return main item param */
1090 memset (&item
, 0xcc, sizeof (item
));
1091 item
.mask
= LVIF_PARAM
;
1094 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1095 ok(r
!= 0, "ret %d\n", r
);
1096 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1098 /**** Some tests of state highlighting ****/
1099 memset (&item
, 0xcc, sizeof (item
));
1100 item
.mask
= LVIF_STATE
;
1103 item
.state
= LVIS_SELECTED
;
1104 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1105 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1106 ok(r
!= 0, "ret %d\n", r
);
1108 item
.state
= LVIS_DROPHILITED
;
1109 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1110 ok(r
!= 0, "ret %d\n", r
);
1112 memset (&item
, 0xcc, sizeof (item
));
1113 item
.mask
= LVIF_STATE
;
1116 item
.stateMask
= -1;
1117 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1118 ok(r
!= 0, "ret %d\n", r
);
1119 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1121 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1122 ok(r
!= 0, "ret %d\n", r
);
1123 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1125 /* some notnull but meaningless masks */
1126 memset (&item
, 0, sizeof(item
));
1127 item
.mask
= LVIF_NORECOMPUTE
;
1130 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1131 ok(r
!= 0, "ret %d\n", r
);
1132 memset (&item
, 0, sizeof(item
));
1133 item
.mask
= LVIF_DI_SETITEM
;
1136 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1137 ok(r
!= 0, "ret %d\n", r
);
1139 /* set text to callback value already having it */
1140 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1142 memset (&item
, 0, sizeof (item
));
1143 item
.mask
= LVIF_TEXT
;
1144 item
.pszText
= LPSTR_TEXTCALLBACK
;
1146 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1147 ok(r
== 0, "ret %d\n", r
);
1148 memset (&item
, 0, sizeof (item
));
1150 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1152 item
.pszText
= LPSTR_TEXTCALLBACK
;
1153 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0 , (LPARAM
) &item
);
1156 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1157 "check callback text comparison rule", FALSE
);
1159 DestroyWindow(hwnd
);
1162 static void test_columns(void)
1164 HWND hwnd
, hwndheader
;
1169 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1170 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1171 ok(hwnd
!= NULL
, "failed to create listview window\n");
1173 /* Add a column with no mask */
1174 memset(&column
, 0xcc, sizeof(column
));
1176 rc
= ListView_InsertColumn(hwnd
, 0, &column
);
1177 ok(rc
==0, "Inserting column with no mask failed with %d\n", rc
);
1179 /* Check its width */
1180 rc
= ListView_GetColumnWidth(hwnd
, 0);
1182 broken(rc
==0), /* win9x */
1183 "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1185 DestroyWindow(hwnd
);
1187 /* LVM_GETCOLUMNORDERARRAY */
1188 hwnd
= create_listview_control(0);
1189 hwndheader
= subclass_header(hwnd
);
1191 memset(&column
, 0, sizeof(column
));
1192 column
.mask
= LVCF_WIDTH
;
1194 rc
= ListView_InsertColumn(hwnd
, 0, &column
);
1195 ok(rc
== 0, "Inserting column failed with %d\n", rc
);
1198 rc
= ListView_InsertColumn(hwnd
, 1, &column
);
1199 ok(rc
== 1, "Inserting column failed with %d\n", rc
);
1201 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1203 rc
= SendMessage(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1204 ok(rc
!= 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1205 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1206 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1208 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1210 DestroyWindow(hwnd
);
1212 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1213 static WNDPROC listviewWndProc
;
1214 static HIMAGELIST test_create_imagelist
;
1216 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1220 if (uMsg
== WM_CREATE
)
1222 LPCREATESTRUCT lpcs
= (LPCREATESTRUCT
)lParam
;
1223 lpcs
->style
|= LVS_REPORT
;
1225 ret
= CallWindowProc(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1226 if (uMsg
== WM_CREATE
) SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1230 static void test_create(void)
1239 cls
.cbSize
= sizeof(WNDCLASSEX
);
1240 ok(GetClassInfoEx(GetModuleHandle(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1241 listviewWndProc
= cls
.lpfnWndProc
;
1242 cls
.lpfnWndProc
= create_test_wndproc
;
1243 cls
.lpszClassName
= "MyListView32";
1244 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
1246 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1247 hList
= CreateWindow("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1248 ok((HIMAGELIST
)SendMessage(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1249 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1250 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1251 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1252 DestroyWindow(hList
);
1254 /* header isn't created on LVS_ICON and LVS_LIST styles */
1255 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1256 GetModuleHandle(NULL
), 0);
1257 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1258 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1259 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1261 memset(&col
, 0, sizeof(LVCOLUMNA
));
1262 col
.mask
= LVCF_WIDTH
;
1264 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1265 ok(r
== 0, "Expected 0 column's inserted\n");
1266 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1267 ok(IsWindow(hHeader
), "Header should be created\n");
1268 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1269 DestroyWindow(hList
);
1271 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1272 GetModuleHandle(NULL
), 0);
1273 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1274 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1275 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1277 memset(&col
, 0, sizeof(LVCOLUMNA
));
1278 col
.mask
= LVCF_WIDTH
;
1280 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1281 ok(r
== 0, "Expected 0 column's inserted\n");
1282 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1283 ok(IsWindow(hHeader
), "Header should be created\n");
1284 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1285 DestroyWindow(hList
);
1287 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1288 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1289 GetModuleHandle(NULL
), 0);
1290 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLongPtr(hList
, GWL_STYLE
) | LVS_REPORT
);
1291 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1292 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1293 ok(IsWindow(hHeader
), "Header should be created\n");
1294 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLong(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1295 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1296 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1297 ok(IsWindow(hHeader
), "Header should be created\n");
1298 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1299 DestroyWindow(hList
);
1301 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1302 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1303 GetModuleHandle(NULL
), 0);
1304 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1305 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1306 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1307 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1308 ok(IsWindow(hHeader
), "Header should be created\n");
1309 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1310 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1311 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1312 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1313 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1314 ok(IsWindow(hHeader
), "Header should be created\n");
1315 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1316 DestroyWindow(hList
);
1318 /* LVS_REPORT without WS_VISIBLE */
1319 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1320 GetModuleHandle(NULL
), 0);
1321 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1322 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1323 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1325 memset(&col
, 0, sizeof(LVCOLUMNA
));
1326 col
.mask
= LVCF_WIDTH
;
1328 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1329 ok(r
== 0, "Expected 0 column's inserted\n");
1330 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1331 ok(IsWindow(hHeader
), "Header should be created\n");
1332 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1333 DestroyWindow(hList
);
1335 /* LVS_REPORT without WS_VISIBLE, try to show it */
1336 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1337 GetModuleHandle(NULL
), 0);
1338 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1339 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1340 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1341 ShowWindow(hList
, SW_SHOW
);
1342 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1343 ok(IsWindow(hHeader
), "Header should be created\n");
1344 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1345 DestroyWindow(hList
);
1347 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1348 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1349 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1350 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1351 ok(IsWindow(hHeader
), "Header should be created\n");
1352 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1353 /* HDS_DRAGDROP set by default */
1354 ok(GetWindowLongPtr(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1355 DestroyWindow(hList
);
1357 /* setting LVS_EX_HEADERDRAGDROP creates header */
1358 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1359 GetModuleHandle(NULL
), 0);
1360 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1361 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1362 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1363 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1364 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1365 ok(IsWindow(hHeader
) ||
1366 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1367 "Header should be created\n");
1368 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1369 DestroyWindow(hList
);
1371 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1372 hList
= create_custom_listview_control(0);
1373 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1374 r
= SendMessage(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1375 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1376 DestroyWindow(hList
);
1378 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1379 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1380 GetModuleHandle(NULL
), 0);
1381 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1382 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1384 rect
.left
= LVIR_BOUNDS
;
1386 rect
.right
= rect
.bottom
= -10;
1387 r
= SendMessage(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1388 ok(r
!= 0, "Expected not-null LRESULT\n");
1390 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1391 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1392 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1394 DestroyWindow(hList
);
1397 static void test_redraw(void)
1399 HWND hwnd
, hwndheader
;
1404 hwnd
= create_listview_control(0);
1405 hwndheader
= subclass_header(hwnd
);
1407 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1409 trace("invalidate & update\n");
1410 InvalidateRect(hwnd
, NULL
, TRUE
);
1412 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1414 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1416 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1417 /* 1. Without backbuffer */
1418 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1421 hdc
= GetWindowDC(hwndparent
);
1423 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1424 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1425 ok(r
!= 0, "Expected not zero result\n");
1426 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1427 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1429 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1432 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1433 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1434 ok(r
!= 0, "Expected not zero result\n");
1435 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1436 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1438 /* 2. With backbuffer */
1439 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1440 LVS_EX_DOUBLEBUFFER
);
1441 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1444 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1445 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1446 ok(r
!= 0, "Expected not zero result\n");
1447 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1448 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1450 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1453 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1454 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1455 todo_wine
ok(r
!= 0, "Expected not zero result\n");
1456 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1457 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1459 ReleaseDC(hwndparent
, hdc
);
1461 DestroyWindow(hwnd
);
1464 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1466 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1468 if(msg
== WM_NOTIFY
) {
1469 NMHDR
*nmhdr
= (PVOID
)lp
;
1470 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1471 NMLVCUSTOMDRAW
*nmlvcd
= (PVOID
)nmhdr
;
1472 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd
->nmcd
.dwDrawStage
);
1473 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1475 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1476 return CDRF_NOTIFYITEMDRAW
;
1477 case CDDS_ITEMPREPAINT
:
1478 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1479 return CDRF_NOTIFYSUBITEMDRAW
;
1480 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1481 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1482 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1483 return CDRF_NOTIFYPOSTPAINT
;
1484 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1485 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1486 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1487 return CDRF_DODEFAULT
;
1489 return CDRF_DODEFAULT
;
1493 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1496 static void test_customdraw(void)
1501 hwnd
= create_listview_control(0);
1503 insert_column(hwnd
, 0);
1504 insert_column(hwnd
, 1);
1505 insert_item(hwnd
, 0);
1507 oldwndproc
= (WNDPROC
)SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
,
1508 (LONG_PTR
)cd_wndproc
);
1510 InvalidateRect(hwnd
, NULL
, TRUE
);
1513 SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1515 DestroyWindow(hwnd
);
1518 static void test_icon_spacing(void)
1520 /* LVM_SETICONSPACING */
1521 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1527 hwnd
= create_custom_listview_control(LVS_ICON
);
1528 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1530 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, (LPARAM
)NF_REQUERY
);
1531 expect(NFR_ANSI
, r
);
1533 /* reset the icon spacing to defaults */
1534 SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1536 /* now we can request what the defaults are */
1537 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1541 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1543 trace("test icon spacing\n");
1545 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1546 ok(r
== MAKELONG(w
, h
) ||
1547 broken(r
== MAKELONG(w
, w
)), /* win98 */
1548 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1550 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1551 expect(MAKELONG(20,30), r
);
1553 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1554 expect(MAKELONG(25,35), r
);
1556 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1558 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1559 DestroyWindow(hwnd
);
1562 static void test_color(void)
1564 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1571 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1573 hwnd
= create_listview_control(0);
1574 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1576 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1578 trace("test color seq\n");
1579 for (i
= 0; i
< 4; i
++)
1583 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1585 r
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, color
);
1588 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1590 r
= SendMessage(hwnd
, LVM_GETTEXTCOLOR
, 0, color
);
1593 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1595 r
= SendMessage(hwnd
, LVM_GETTEXTBKCOLOR
, 0, color
);
1599 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1601 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1602 DestroyWindow(hwnd
);
1605 static void test_item_count(void)
1607 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1620 static CHAR item0text
[] = "item0";
1621 static CHAR item1text
[] = "item1";
1622 static CHAR item2text
[] = "item2";
1624 hwnd
= create_listview_control(0);
1625 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1627 /* resize in dpiaware manner to fit all 3 items added */
1629 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1630 GetTextMetricsA(hdc
, &tm
);
1631 /* 2 extra pixels for bounds and header border */
1632 height
= tm
.tmHeight
+ 2;
1633 SelectObject(hdc
, hOldFont
);
1636 GetWindowRect(hwnd
, &rect
);
1637 /* 3 items + 1 header + 1 to be sure */
1638 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1640 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1642 trace("test item count\n");
1644 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1648 item0
.mask
= LVIF_TEXT
;
1651 item0
.pszText
= item0text
;
1652 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1655 /* [item0, item1] */
1656 item1
.mask
= LVIF_TEXT
;
1659 item1
.pszText
= item1text
;
1660 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1663 /* [item0, item1, item2] */
1664 item2
.mask
= LVIF_TEXT
;
1667 item2
.pszText
= item2text
;
1668 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1671 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1674 /* [item0, item1] */
1675 r
= SendMessage(hwnd
, LVM_DELETEITEM
, 2, 0);
1678 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1682 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1685 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1689 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1692 /* [item0, item1] */
1693 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1696 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1699 /* [item0, item1, item2] */
1700 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1703 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1706 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
1708 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1709 DestroyWindow(hwnd
);
1712 static void test_item_position(void)
1714 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1723 static CHAR item0text
[] = "item0";
1724 static CHAR item1text
[] = "item1";
1725 static CHAR item2text
[] = "item2";
1727 hwnd
= create_custom_listview_control(LVS_ICON
);
1728 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1730 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1732 trace("test item position\n");
1735 item0
.mask
= LVIF_TEXT
;
1738 item0
.pszText
= item0text
;
1739 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1742 /* [item0, item1] */
1743 item1
.mask
= LVIF_TEXT
;
1746 item1
.pszText
= item1text
;
1747 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1750 /* [item0, item1, item2] */
1751 item2
.mask
= LVIF_TEXT
;
1754 item2
.pszText
= item2text
;
1755 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1758 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
1760 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
1762 expect2(10, 5, position
.x
, position
.y
);
1764 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
1766 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
1768 expect2(0, 0, position
.x
, position
.y
);
1770 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
1772 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
1774 expect2(20, 20, position
.x
, position
.y
);
1776 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
1778 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1779 DestroyWindow(hwnd
);
1782 static void test_getorigin(void)
1790 position
.x
= position
.y
= 0;
1792 hwnd
= create_custom_listview_control(LVS_ICON
);
1793 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1794 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1795 trace("test get origin results\n");
1796 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1798 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1799 DestroyWindow(hwnd
);
1801 hwnd
= create_custom_listview_control(LVS_SMALLICON
);
1802 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1803 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1804 trace("test get origin results\n");
1805 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1807 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1808 DestroyWindow(hwnd
);
1810 hwnd
= create_custom_listview_control(LVS_LIST
);
1811 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1812 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1813 trace("test get origin results\n");
1814 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1816 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1817 DestroyWindow(hwnd
);
1819 hwnd
= create_custom_listview_control(LVS_REPORT
);
1820 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1821 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1822 trace("test get origin results\n");
1823 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1825 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1826 DestroyWindow(hwnd
);
1830 static void test_multiselect(void)
1832 typedef struct t_select_task
1843 int i
,j
,item_count
,selected_count
;
1844 static const int items
=5;
1850 static struct t_select_task task_list
[] = {
1851 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
1852 { "using VK_UP", -1, VK_UP
, -1, -1 },
1853 { "using VK_END", 0, VK_END
, 1, -1 },
1854 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
1858 hwnd
= create_listview_control(0);
1860 for (i
=0;i
<items
;i
++) {
1861 insert_item(hwnd
, 0);
1864 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1866 expect(items
,item_count
);
1869 task
= task_list
[i
];
1871 /* deselect all items */
1872 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1873 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1875 /* set initial position */
1876 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
1877 ListView_SetItemState(hwnd
,(task
.initPos
== -1 ? item_count
-1 : task
.initPos
),LVIS_SELECTED
,LVIS_SELECTED
);
1879 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1881 ok(selected_count
== 1, "There should be only one selected item at the beginning (is %d)\n",selected_count
);
1883 /* Set SHIFT key pressed */
1884 GetKeyboardState(kstate
);
1885 kstate
[VK_SHIFT
]=0x80;
1886 SetKeyboardState(kstate
);
1888 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
1889 r
= SendMessage(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
1891 r
= SendMessage(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
1895 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1897 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
);
1899 /* Set SHIFT key released */
1900 GetKeyboardState(kstate
);
1901 kstate
[VK_SHIFT
]=0x00;
1902 SetKeyboardState(kstate
);
1904 DestroyWindow(hwnd
);
1906 /* make multiple selection, then switch to LVS_SINGLESEL */
1907 hwnd
= create_listview_control(0);
1908 for (i
=0;i
<items
;i
++) {
1909 insert_item(hwnd
, 0);
1911 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1912 expect(items
,item_count
);
1913 /* deselect all items */
1914 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1915 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1917 ListView_SetItemState(hwnd
, i
, LVIS_SELECTED
, LVIS_SELECTED
);
1920 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1922 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
1926 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
1927 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
1928 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
1929 /* check that style is accepted */
1930 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
1931 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
1934 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
1935 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
1937 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1939 SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
1942 /* select one more */
1943 ListView_SetItemState(hwnd
, 3, LVIS_SELECTED
, LVIS_SELECTED
);
1946 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
1947 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
1949 r
= ListView_GetItemState(hwnd
, 3, LVIS_SELECTED
);
1950 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
1952 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1954 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
1958 /* try to select all on LVS_SINGLESEL */
1959 memset(&item
, 0, sizeof(item
));
1960 item
.stateMask
= LVIS_SELECTED
;
1961 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
1963 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1965 item
.stateMask
= LVIS_SELECTED
;
1966 item
.state
= LVIS_SELECTED
;
1967 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
1970 r
= ListView_GetSelectedCount(hwnd
);
1972 r
= ListView_GetSelectionMark(hwnd
);
1975 /* try to deselect all on LVS_SINGLESEL */
1976 item
.stateMask
= LVIS_SELECTED
;
1977 item
.state
= LVIS_SELECTED
;
1978 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
1981 item
.stateMask
= LVIS_SELECTED
;
1983 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
1985 r
= ListView_GetSelectedCount(hwnd
);
1988 DestroyWindow(hwnd
);
1991 static void test_subitem_rect(void)
1998 /* test LVM_GETSUBITEMRECT for header */
1999 hwnd
= create_listview_control(0);
2000 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2001 /* add some columns */
2002 memset(&col
, 0, sizeof(LVCOLUMN
));
2003 col
.mask
= LVCF_WIDTH
;
2006 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2010 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2014 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2016 /* item = -1 means header, subitem index is 1 based */
2017 rect
.left
= LVIR_BOUNDS
;
2019 rect
.right
= rect
.bottom
= 0;
2020 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2023 rect
.left
= LVIR_BOUNDS
;
2025 rect
.right
= rect
.bottom
= 0;
2026 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2028 ok(r
!= 0, "Expected not-null LRESULT\n");
2029 expect(100, rect
.left
);
2030 expect(250, rect
.right
);
2032 expect(3, rect
.top
);
2034 rect
.left
= LVIR_BOUNDS
;
2036 rect
.right
= rect
.bottom
= 0;
2037 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2039 ok(r
!= 0, "Expected not-null LRESULT\n");
2040 expect(250, rect
.left
);
2041 expect(450, rect
.right
);
2043 expect(3, rect
.top
);
2045 /* item LVS_REPORT padding isn't applied to subitems */
2046 insert_item(hwnd
, 0);
2048 rect
.left
= LVIR_BOUNDS
;
2050 rect
.right
= rect
.bottom
= 0;
2051 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2052 ok(r
!= 0, "Expected not-null LRESULT\n");
2053 expect(100, rect
.left
);
2054 expect(250, rect
.right
);
2056 rect
.left
= LVIR_ICON
;
2058 rect
.right
= rect
.bottom
= 0;
2059 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2060 ok(r
!= 0, "Expected not-null LRESULT\n");
2061 /* no icon attached - zero width rectangle, with no left padding */
2062 expect(100, rect
.left
);
2063 expect(100, rect
.right
);
2065 rect
.left
= LVIR_LABEL
;
2067 rect
.right
= rect
.bottom
= 0;
2068 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2069 ok(r
!= 0, "Expected not-null LRESULT\n");
2070 /* same as full LVIR_BOUNDS */
2071 expect(100, rect
.left
);
2072 expect(250, rect
.right
);
2074 DestroyWindow(hwnd
);
2076 /* try it for non LVS_REPORT style */
2077 hwnd
= CreateWindow("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2078 GetModuleHandle(NULL
), 0);
2079 rect
.left
= LVIR_BOUNDS
;
2081 rect
.right
= rect
.bottom
= -10;
2082 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2083 ok(r
== 0, "Expected not-null LRESULT\n");
2084 /* rect is unchanged */
2085 expect(0, rect
.left
);
2086 expect(-10, rect
.right
);
2087 expect(1, rect
.top
);
2088 expect(-10, rect
.bottom
);
2089 DestroyWindow(hwnd
);
2092 /* comparison callback for test_sorting */
2093 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2095 if (first
== second
) return 0;
2096 return (first
> second
? 1 : -1);
2099 static void test_sorting(void)
2105 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2108 hwnd
= create_listview_control(0);
2109 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2111 /* insert some items */
2112 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2113 item
.state
= LVIS_SELECTED
;
2117 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2120 item
.mask
= LVIF_PARAM
;
2124 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2127 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2128 item
.state
= LVIS_SELECTED
;
2132 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2135 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2138 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2141 r
= SendMessage(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2144 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2146 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2148 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2150 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2151 expect(LVIS_SELECTED
, r
);
2152 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2153 expect(LVIS_SELECTED
, r
);
2155 DestroyWindow(hwnd
);
2157 /* switch to LVS_SORTASCENDING when some items added */
2158 hwnd
= create_listview_control(0);
2159 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2161 item
.mask
= LVIF_TEXT
;
2164 item
.pszText
= names
[1];
2165 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2168 item
.mask
= LVIF_TEXT
;
2171 item
.pszText
= names
[2];
2172 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2175 item
.mask
= LVIF_TEXT
;
2178 item
.pszText
= names
[0];
2179 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2182 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2183 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2184 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2185 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2187 /* no sorting performed when switched to LVS_SORTASCENDING */
2188 item
.mask
= LVIF_TEXT
;
2190 item
.pszText
= buff
;
2191 item
.cchTextMax
= sizeof(buff
);
2192 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2194 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2197 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2199 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2202 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2204 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2206 /* adding new item doesn't resort list */
2207 item
.mask
= LVIF_TEXT
;
2210 item
.pszText
= names
[3];
2211 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2214 item
.mask
= LVIF_TEXT
;
2216 item
.pszText
= buff
;
2217 item
.cchTextMax
= sizeof(buff
);
2218 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2220 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2223 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2225 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2228 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2230 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2233 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2235 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2237 /* corner case - item should be placed at first position */
2238 item
.mask
= LVIF_TEXT
;
2241 item
.pszText
= names
[4];
2242 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2246 item
.pszText
= buff
;
2247 item
.cchTextMax
= sizeof(buff
);
2248 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2250 ok(lstrcmp(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2253 item
.pszText
= buff
;
2254 item
.cchTextMax
= sizeof(buff
);
2255 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2257 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2260 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2262 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2265 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2267 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2270 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2272 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2274 DestroyWindow(hwnd
);
2277 static void test_ownerdata(void)
2280 LONG_PTR style
, ret
;
2284 /* it isn't possible to set LVS_OWNERDATA after creation */
2287 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2291 hwnd
= create_listview_control(0);
2292 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2293 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2294 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2296 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2298 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2299 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2300 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2301 "try to switch to LVS_OWNERDATA seq", FALSE
);
2303 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2304 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2305 DestroyWindow(hwnd
);
2308 /* try to set LVS_OWNERDATA after creation just having it */
2309 hwnd
= create_listview_control(LVS_OWNERDATA
);
2310 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2311 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2312 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2314 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2316 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2317 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2318 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2319 "try to switch to LVS_OWNERDATA seq", FALSE
);
2320 DestroyWindow(hwnd
);
2322 /* try to remove LVS_OWNERDATA after creation just having it */
2325 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2329 hwnd
= create_listview_control(LVS_OWNERDATA
);
2330 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2331 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2332 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2334 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2336 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2337 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2338 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2339 "try to switch to LVS_OWNERDATA seq", FALSE
);
2340 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2341 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2342 DestroyWindow(hwnd
);
2345 /* try select an item */
2346 hwnd
= create_listview_control(LVS_OWNERDATA
);
2347 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2348 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2349 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2350 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2352 memset(&item
, 0, sizeof(item
));
2353 item
.stateMask
= LVIS_SELECTED
;
2354 item
.state
= LVIS_SELECTED
;
2355 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2357 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2359 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2361 DestroyWindow(hwnd
);
2363 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2364 hwnd
= create_listview_control(LVS_OWNERDATA
);
2365 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2366 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2367 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2368 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2370 memset(&item
, 0, sizeof(item
));
2371 item
.mask
= LVIF_STATE
;
2373 item
.stateMask
= LVIS_SELECTED
;
2374 item
.state
= LVIS_SELECTED
;
2375 res
= SendMessageA(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2377 DestroyWindow(hwnd
);
2379 /* check notifications after focused/selected changed */
2380 hwnd
= create_listview_control(LVS_OWNERDATA
);
2381 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2382 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2383 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2385 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2387 memset(&item
, 0, sizeof(item
));
2388 item
.stateMask
= LVIS_SELECTED
;
2389 item
.state
= LVIS_SELECTED
;
2390 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2393 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2394 "ownerdata select notification", TRUE
);
2396 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2398 memset(&item
, 0, sizeof(item
));
2399 item
.stateMask
= LVIS_FOCUSED
;
2400 item
.state
= LVIS_FOCUSED
;
2401 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2404 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2405 "ownerdata focus notification", TRUE
);
2406 DestroyWindow(hwnd
);
2408 /* check notifications on LVM_GETITEM */
2409 /* zero callback mask */
2410 hwnd
= create_listview_control(LVS_OWNERDATA
);
2411 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2412 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2413 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2415 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2417 memset(&item
, 0, sizeof(item
));
2418 item
.stateMask
= LVIS_SELECTED
;
2419 item
.mask
= LVIF_STATE
;
2420 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2423 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2424 "ownerdata getitem selected state 1", FALSE
);
2426 /* non zero callback mask but not we asking for */
2427 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
2430 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2432 memset(&item
, 0, sizeof(item
));
2433 item
.stateMask
= LVIS_SELECTED
;
2434 item
.mask
= LVIF_STATE
;
2435 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2438 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2439 "ownerdata getitem selected state 2", FALSE
);
2441 /* LVIS_OVERLAYMASK callback mask, asking for index */
2442 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2444 memset(&item
, 0, sizeof(item
));
2445 item
.stateMask
= LVIS_OVERLAYMASK
;
2446 item
.mask
= LVIF_STATE
;
2447 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2450 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
2451 "ownerdata getitem selected state 2", FALSE
);
2453 DestroyWindow(hwnd
);
2455 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2456 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
);
2457 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2458 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2459 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2460 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2461 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
2462 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2463 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
2464 DestroyWindow(hwnd
);
2465 /* apparently it's allowed to switch these style on after creation */
2466 hwnd
= create_listview_control(LVS_OWNERDATA
);
2467 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2468 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2469 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2470 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2471 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2472 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2473 DestroyWindow(hwnd
);
2475 hwnd
= create_listview_control(LVS_OWNERDATA
);
2476 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2477 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2478 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2479 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
2480 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2481 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
2482 DestroyWindow(hwnd
);
2485 static void test_norecompute(void)
2487 static CHAR testA
[] = "test";
2493 /* self containing control */
2494 hwnd
= create_listview_control(0);
2495 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2496 memset(&item
, 0, sizeof(item
));
2497 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
2499 item
.stateMask
= LVIS_SELECTED
;
2500 item
.state
= LVIS_SELECTED
;
2501 item
.pszText
= testA
;
2502 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2504 /* retrieve with LVIF_NORECOMPUTE */
2505 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2507 item
.pszText
= buff
;
2508 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2509 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2511 ok(lstrcmp(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
2513 item
.mask
= LVIF_TEXT
;
2515 item
.pszText
= LPSTR_TEXTCALLBACK
;
2516 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2519 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2521 item
.pszText
= buff
;
2522 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2524 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2525 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2527 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2528 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2529 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
2531 DestroyWindow(hwnd
);
2534 hwnd
= create_listview_control(LVS_OWNERDATA
);
2535 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2537 item
.mask
= LVIF_STATE
;
2538 item
.stateMask
= LVIS_SELECTED
;
2539 item
.state
= LVIS_SELECTED
;
2541 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2544 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2546 item
.pszText
= buff
;
2547 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2548 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2549 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2551 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2552 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2553 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
2555 DestroyWindow(hwnd
);
2558 static void test_nosortheader(void)
2563 hwnd
= create_listview_control(0);
2564 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2566 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2567 ok(IsWindow(header
), "header expected\n");
2569 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2570 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
2572 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2573 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
2574 /* HDS_BUTTONS retained */
2575 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2576 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
2578 DestroyWindow(hwnd
);
2580 /* create with LVS_NOSORTHEADER */
2581 hwnd
= create_listview_control(LVS_NOSORTHEADER
);
2582 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2584 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2585 ok(IsWindow(header
), "header expected\n");
2587 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2588 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2590 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2591 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
2592 /* not changed here */
2593 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2594 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2596 DestroyWindow(hwnd
);
2599 static void test_setredraw(void)
2605 hwnd
= create_listview_control(0);
2606 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2608 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2609 ListView seems to handle it internally without DefWinProc */
2611 /* default value first */
2612 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2615 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2616 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2617 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2619 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2620 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2622 DestroyWindow(hwnd
);
2625 static void test_hittest(void)
2631 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2634 HIMAGELIST himl
, himl2
;
2637 hwnd
= create_listview_control(0);
2638 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2640 /* LVS_REPORT with a single subitem (2 columns) */
2641 insert_column(hwnd
, 0);
2642 insert_column(hwnd
, 1);
2643 insert_item(hwnd
, 0);
2646 /* the only purpose of that line is to be as long as a half item rect */
2647 item
.pszText
= text
;
2648 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
2651 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
2653 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
2656 memset(&bounds
, 0, sizeof(bounds
));
2657 bounds
.left
= LVIR_BOUNDS
;
2658 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
2659 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
2660 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
2661 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
2664 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2665 x
= pos
.x
+ 50; /* column half width */
2666 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2667 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, __LINE__
);
2668 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2669 x
= pos
.x
+ 150; /* outside column */
2670 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2671 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2672 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, TRUE
, TRUE
, TRUE
, __LINE__
);
2673 /* parent client area is 100x100 by default */
2674 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
2675 x
= pos
.x
+ 150; /* outside column */
2676 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2677 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, FALSE
, FALSE
, __LINE__
);
2678 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2679 /* the same with LVS_EX_FULLROWSELECT */
2680 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
2681 x
= pos
.x
+ 150; /* outside column */
2682 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2683 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, FALSE
, FALSE
, __LINE__
);
2684 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2685 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
2686 x
= pos
.x
+ 150; /* outside column */
2687 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2688 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2689 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, TRUE
, TRUE
, TRUE
, __LINE__
);
2690 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2691 himl
= ImageList_Create(16, 16, 0, 4, 4);
2692 ok(himl
!= NULL
, "failed to create imagelist\n");
2693 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
2694 ok(hbmp
!= NULL
, "failed to create bitmap\n");
2695 r
= ImageList_Add(himl
, hbmp
, 0);
2696 ok(r
== 0, "should be zero\n");
2697 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
2698 ok(hbmp
!= NULL
, "failed to create bitmap\n");
2699 r
= ImageList_Add(himl
, hbmp
, 0);
2700 ok(r
== 1, "should be one\n");
2702 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
2703 ok(r
== 0, "should return zero\n");
2705 item
.mask
= LVIF_IMAGE
;
2709 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2713 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2714 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, __LINE__
);
2715 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2717 /* state icons indices are 1 based, check with valid index */
2718 item
.mask
= LVIF_STATE
;
2719 item
.state
= INDEXTOSTATEIMAGEMASK(1);
2720 item
.stateMask
= LVIS_STATEIMAGEMASK
;
2723 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2727 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2728 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, __LINE__
);
2729 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2731 himl2
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)NULL
);
2732 ok(himl2
== himl
, "should return handle\n");
2734 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
2735 ok(r
== 0, "should return zero\n");
2738 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2739 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, __LINE__
);
2740 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2742 DestroyWindow(hwnd
);
2745 static void test_getviewrect(void)
2752 hwnd
= create_listview_control(0);
2753 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2756 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
2759 insert_column(hwnd
, 0);
2760 insert_column(hwnd
, 1);
2762 memset(&item
, 0, sizeof(item
));
2765 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
2767 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
2769 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
2772 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
2773 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
2775 /* left is set to (2e31-1) - XP SP2 */
2776 expect(0, rect
.right
);
2777 expect(0, rect
.top
);
2778 expect(0, rect
.bottom
);
2780 /* switch to LVS_ICON */
2781 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
2783 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
2784 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
2786 expect(0, rect
.left
);
2787 expect(0, rect
.top
);
2788 /* precise value differs for 2k, XP and Vista */
2789 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
2790 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
2792 DestroyWindow(hwnd
);
2795 static void test_getitemposition(void)
2802 hwnd
= create_listview_control(0);
2803 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2804 header
= subclass_header(hwnd
);
2806 /* LVS_REPORT, single item, no columns added */
2807 insert_item(hwnd
, 0);
2809 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2812 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
2814 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
2816 /* LVS_REPORT, single item, single column */
2817 insert_column(hwnd
, 0);
2819 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2822 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
2824 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
2826 memset(&rect
, 0, sizeof(rect
));
2827 SendMessage(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
2830 /* offset by header height */
2831 expect(rect
.bottom
- rect
.top
, pt
.y
);
2833 DestroyWindow(hwnd
);
2836 static void test_columnscreation(void)
2841 hwnd
= create_listview_control(0);
2842 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2844 insert_item(hwnd
, 0);
2846 /* headers columns aren't created automatically */
2847 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
2848 ok(IsWindow(header
), "Expected header handle\n");
2849 r
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
2852 DestroyWindow(hwnd
);
2855 static void test_getitemrect(void)
2867 hwnd
= create_listview_control(0);
2868 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2871 memset(&item
, 0, sizeof(item
));
2874 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
2877 rect
.left
= LVIR_BOUNDS
;
2878 rect
.right
= rect
.top
= rect
.bottom
= -1;
2879 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
2882 /* zero width rectangle with no padding */
2883 expect(0, rect
.left
);
2884 expect(0, rect
.right
);
2886 insert_column(hwnd
, 0);
2887 insert_column(hwnd
, 1);
2889 col
.mask
= LVCF_WIDTH
;
2891 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 0, (LPARAM
)&col
);
2894 col
.mask
= LVCF_WIDTH
;
2896 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 1, (LPARAM
)&col
);
2899 rect
.left
= LVIR_BOUNDS
;
2900 rect
.right
= rect
.top
= rect
.bottom
= -1;
2901 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
2904 /* still no left padding */
2905 expect(0, rect
.left
);
2906 expect(150, rect
.right
);
2908 rect
.left
= LVIR_SELECTBOUNDS
;
2909 rect
.right
= rect
.top
= rect
.bottom
= -1;
2910 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
2913 expect(2, rect
.left
);
2915 rect
.left
= LVIR_LABEL
;
2916 rect
.right
= rect
.top
= rect
.bottom
= -1;
2917 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
2919 /* padding, column width */
2920 expect(2, rect
.left
);
2921 expect(50, rect
.right
);
2923 /* no icons attached */
2924 rect
.left
= LVIR_ICON
;
2925 rect
.right
= rect
.top
= rect
.bottom
= -1;
2926 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
2929 expect(2, rect
.left
);
2930 expect(2, rect
.right
);
2933 order
[0] = 1; order
[1] = 0;
2934 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
2937 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
2939 /* 1 indexed column width + padding */
2940 todo_wine
expect(102, pt
.x
);
2941 /* rect is at zero too */
2942 rect
.left
= LVIR_BOUNDS
;
2943 rect
.right
= rect
.top
= rect
.bottom
= -1;
2944 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
2946 expect(0, rect
.left
);
2947 /* just width sum */
2948 expect(150, rect
.right
);
2950 rect
.left
= LVIR_SELECTBOUNDS
;
2951 rect
.right
= rect
.top
= rect
.bottom
= -1;
2952 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
2954 /* column width + padding */
2955 todo_wine
expect(102, rect
.left
);
2957 /* back to initial order */
2958 order
[0] = 0; order
[1] = 1;
2959 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
2963 himl
= ImageList_Create(16, 16, 0, 2, 2);
2964 ok(himl
!= NULL
, "failed to create imagelist\n");
2965 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
2966 ok(hbm
!= NULL
, "failed to create bitmap\n");
2967 r
= ImageList_Add(himl
, hbm
, 0);
2968 ok(r
== 0, "should be zero\n");
2969 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
2970 ok(hbm
!= NULL
, "failed to create bitmap\n");
2971 r
= ImageList_Add(himl
, hbm
, 0);
2972 ok(r
== 1, "should be one\n");
2974 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
2975 ok(r
== 0, "should return zero\n");
2977 item
.mask
= LVIF_STATE
;
2978 item
.state
= INDEXTOSTATEIMAGEMASK(1);
2979 item
.stateMask
= LVIS_STATEIMAGEMASK
;
2982 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2986 rect
.left
= LVIR_ICON
;
2987 rect
.right
= rect
.top
= rect
.bottom
= -1;
2988 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
2990 /* padding + stateicon width */
2991 expect(18, rect
.left
);
2992 expect(18, rect
.right
);
2994 rect
.left
= LVIR_LABEL
;
2995 rect
.right
= rect
.top
= rect
.bottom
= -1;
2996 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
2998 /* padding + stateicon width -> column width */
2999 expect(18, rect
.left
);
3000 expect(50, rect
.right
);
3002 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)NULL
);
3003 ok(r
!= 0, "should return current list handle\n");
3005 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3006 ok(r
== 0, "should return zero\n");
3008 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3011 item
.stateMask
= ~0;
3014 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3018 rect
.left
= LVIR_ICON
;
3019 rect
.right
= rect
.top
= rect
.bottom
= -1;
3020 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3022 /* padding, icon width */
3023 expect(2, rect
.left
);
3024 expect(18, rect
.right
);
3026 rect
.left
= LVIR_LABEL
;
3027 rect
.right
= rect
.top
= rect
.bottom
= -1;
3028 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3030 /* padding + icon width -> column width */
3031 expect(18, rect
.left
);
3032 expect(50, rect
.right
);
3035 rect
.left
= LVIR_SELECTBOUNDS
;
3036 rect
.right
= rect
.top
= rect
.bottom
= -1;
3037 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3039 /* padding, column width */
3040 expect(2, rect
.left
);
3041 todo_wine
expect(50, rect
.right
);
3043 /* try with indentation */
3044 item
.mask
= LVIF_INDENT
;
3048 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3052 rect
.left
= LVIR_BOUNDS
;
3053 rect
.right
= rect
.top
= rect
.bottom
= -1;
3054 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3056 /* padding + 1 icon width, column width */
3057 expect(0, rect
.left
);
3058 expect(150, rect
.right
);
3061 rect
.left
= LVIR_SELECTBOUNDS
;
3062 rect
.right
= rect
.top
= rect
.bottom
= -1;
3063 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3065 /* padding + 1 icon width, column width */
3066 expect(2 + 16, rect
.left
);
3067 todo_wine
expect(50, rect
.right
);
3070 rect
.left
= LVIR_LABEL
;
3071 rect
.right
= rect
.top
= rect
.bottom
= -1;
3072 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3074 /* padding + 2 icon widths, column width */
3075 expect(2 + 16*2, rect
.left
);
3076 expect(50, rect
.right
);
3079 rect
.left
= LVIR_ICON
;
3080 rect
.right
= rect
.top
= rect
.bottom
= -1;
3081 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3083 /* padding + 1 icon width indentation, icon width */
3084 expect(2 + 16, rect
.left
);
3085 expect(34, rect
.right
);
3088 DestroyWindow(hwnd
);
3091 static void test_editbox(void)
3093 HWND hwnd
, hwndedit
, hwndedit2
;
3096 static CHAR testitemA
[] = "testitem";
3097 static CHAR testitem1A
[] = "testitem1";
3098 static CHAR buffer
[10];
3100 hwnd
= create_listview_control(LVS_EDITLABELS
);
3101 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3103 insert_column(hwnd
, 0);
3105 memset(&item
, 0, sizeof(item
));
3106 item
.mask
= LVIF_TEXT
;
3107 item
.pszText
= testitemA
;
3110 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3113 /* setting focus is necessary */
3115 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3116 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3118 /* modify initial string */
3119 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3121 /* return focus to listview */
3124 memset(&item
, 0, sizeof(item
));
3125 item
.mask
= LVIF_TEXT
;
3126 item
.pszText
= buffer
;
3127 item
.cchTextMax
= 10;
3130 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3133 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3135 /* send LVM_EDITLABEL on already created edit */
3137 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3138 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3139 /* focus will be set to edit */
3140 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
3141 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3142 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
3144 /* creating label disabled when control isn't focused */
3146 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3147 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3149 /* check EN_KILLFOCUS handling */
3150 memset(&item
, 0, sizeof(item
));
3151 item
.pszText
= testitemA
;
3154 r
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3158 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3159 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3160 /* modify edit and notify control that it lost focus */
3161 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3163 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3165 memset(&item
, 0, sizeof(item
));
3166 item
.pszText
= buffer
;
3167 item
.cchTextMax
= 10;
3170 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3171 expect(lstrlen(item
.pszText
), r
);
3172 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3173 /* end edit without saving */
3174 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
3176 memset(&item
, 0, sizeof(item
));
3177 item
.pszText
= buffer
;
3178 item
.cchTextMax
= 10;
3181 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3182 expect(lstrlen(item
.pszText
), r
);
3183 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3185 /* LVM_EDITLABEL with -1 destroys current edit */
3186 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
3187 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3188 /* no edit present */
3189 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3190 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3191 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3192 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3194 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3195 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3196 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3197 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3198 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3199 /* check another negative value */
3200 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3201 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3202 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3203 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -2, 0);
3204 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3205 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3206 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3207 /* and value greater then max item index */
3208 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3209 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3210 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3211 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3212 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, r
, 0);
3213 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3214 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3215 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3217 /* messaging tests */
3219 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3221 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3222 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3223 /* testing only sizing messages */
3224 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
3225 "edit box create - sizing", TRUE
);
3227 DestroyWindow(hwnd
);
3230 static void test_notifyformat(void)
3235 hwnd
= create_listview_control(0);
3236 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3238 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3239 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3240 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3242 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3244 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
3246 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3249 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
3251 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3256 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3257 DestroyWindow(hwnd
);
3261 DestroyWindow(hwnd
);
3263 /* test failure in parent WM_NOTIFYFORMAT */
3265 hwnd
= create_listview_control(0);
3266 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3267 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3268 ok(IsWindow(header
), "expected header to be created\n");
3269 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3271 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3273 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3274 ok(r
!= 0, "Expected valid format\n");
3276 notifyFormat
= NFR_UNICODE
;
3277 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3278 expect(NFR_UNICODE
, r
);
3279 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3281 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3284 notifyFormat
= NFR_ANSI
;
3285 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3286 expect(NFR_ANSI
, r
);
3287 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3289 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3292 DestroyWindow(hwnd
);
3294 /* try different unicode window combination and defaults */
3295 if (!GetModuleHandleW(NULL
))
3297 win_skip("Additional notify format tests are incompatible with Win9x\n");
3301 hwndparentW
= create_parent_window(TRUE
);
3302 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
3303 if (!IsWindow(hwndparentW
)) return;
3306 hwnd
= create_listview_controlW(0, hwndparentW
);
3307 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3308 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3309 ok(IsWindow(header
), "expected header to be created\n");
3310 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3312 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3314 DestroyWindow(hwnd
);
3315 /* recieving error code defaulting to ansi */
3317 hwnd
= create_listview_controlW(0, hwndparentW
);
3318 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3319 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3320 ok(IsWindow(header
), "expected header to be created\n");
3321 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3323 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3325 DestroyWindow(hwnd
);
3326 /* recieving ansi code from unicode window, use it */
3327 notifyFormat
= NFR_ANSI
;
3328 hwnd
= create_listview_controlW(0, hwndparentW
);
3329 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3330 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3331 ok(IsWindow(header
), "expected header to be created\n");
3332 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3334 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3336 DestroyWindow(hwnd
);
3337 /* unicode listview with ansi parent window */
3339 hwnd
= create_listview_controlW(0, hwndparent
);
3340 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3341 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3342 ok(IsWindow(header
), "expected header to be created\n");
3343 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3345 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3347 DestroyWindow(hwnd
);
3348 /* unicode listview with ansi parent window, return error code */
3350 hwnd
= create_listview_controlW(0, hwndparent
);
3351 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3352 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3353 ok(IsWindow(header
), "expected header to be created\n");
3354 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3356 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3358 DestroyWindow(hwnd
);
3360 DestroyWindow(hwndparentW
);
3363 static void test_indentation(void)
3369 hwnd
= create_listview_control(0);
3370 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3372 memset(&item
, 0, sizeof(item
));
3373 item
.mask
= LVIF_INDENT
;
3375 item
.iIndent
= I_INDENTCALLBACK
;
3376 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3379 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3382 item
.mask
= LVIF_INDENT
;
3383 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3386 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3387 "get indent dispinfo", FALSE
);
3389 DestroyWindow(hwnd
);
3392 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
3397 static BOOL
is_below_comctl_5(void)
3402 hwnd
= create_listview_control(0);
3403 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3404 insert_item(hwnd
, 0);
3406 ret
= SendMessage(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
3408 DestroyWindow(hwnd
);
3413 static void unload_v6_module(ULONG_PTR cookie
)
3416 BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
, ULONG_PTR
);
3418 hKernel32
= GetModuleHandleA("kernel32.dll");
3419 pDeactivateActCtx
= (void*)GetProcAddress(hKernel32
, "DeactivateActCtx");
3420 if (!pDeactivateActCtx
)
3422 win_skip("Activation contexts unsupported\n");
3426 pDeactivateActCtx(0, cookie
);
3428 DeleteFileA(manifest_name
);
3431 static BOOL
load_v6_module(ULONG_PTR
*pcookie
)
3434 HANDLE (WINAPI
*pCreateActCtxA
)(ACTCTXA
*);
3435 BOOL (WINAPI
*pActivateActCtx
)(HANDLE
, ULONG_PTR
*);
3444 hKernel32
= GetModuleHandleA("kernel32.dll");
3445 pCreateActCtxA
= (void*)GetProcAddress(hKernel32
, "CreateActCtxA");
3446 pActivateActCtx
= (void*)GetProcAddress(hKernel32
, "ActivateActCtx");
3447 if (!(pCreateActCtxA
&& pActivateActCtx
))
3449 win_skip("Activation contexts unsupported. No version 6 tests possible.\n");
3453 /* create manifest */
3454 file
= CreateFileA( manifest_name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
3455 if (file
!= INVALID_HANDLE_VALUE
)
3457 ret
= (WriteFile( file
, manifest
, sizeof(manifest
)-1, &written
, NULL
) &&
3458 written
== sizeof(manifest
)-1);
3459 CloseHandle( file
);
3462 DeleteFileA( manifest_name
);
3463 skip("Failed to fill manifest file. Skipping comctl32 V6 tests.\n");
3467 trace("created %s\n", manifest_name
);
3471 skip("Failed to create manifest file. Skipping comctl32 V6 tests.\n");
3475 memset(&ctx
, 0, sizeof(ctx
));
3476 ctx
.cbSize
= sizeof(ctx
);
3477 ctx
.lpSource
= manifest_name
;
3479 hCtx
= pCreateActCtxA(&ctx
);
3480 ok(hCtx
!= 0, "Expected context handle\n");
3482 ret
= pActivateActCtx(hCtx
, pcookie
);
3487 win_skip("A problem during context activation occured.\n");
3488 DeleteFileA(manifest_name
);
3492 /* this is a XP SP3 failure workaround */
3493 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
3494 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
,
3496 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
3497 if (!IsWindow(hwnd
))
3499 win_skip("FIXME: failed to create ListView window.\n");
3500 unload_v6_module(*pcookie
);
3504 DestroyWindow(hwnd
);
3510 static void test_get_set_view(void)
3516 /* test style->view mapping */
3517 hwnd
= create_listview_control(0);
3518 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3520 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3521 expect(LV_VIEW_DETAILS
, ret
);
3523 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3525 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
3526 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3527 expect(LV_VIEW_ICON
, ret
);
3529 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3530 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
3531 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3532 expect(LV_VIEW_SMALLICON
, ret
);
3534 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3535 SetWindowLongPtr(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
3536 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3537 expect(LV_VIEW_LIST
, ret
);
3539 /* switching view doesn't touch window style */
3540 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
3542 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3543 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3544 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
3546 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3547 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3548 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
3550 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3551 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3553 DestroyWindow(hwnd
);
3556 static void test_canceleditlabel(void)
3558 HWND hwnd
, hwndedit
;
3562 static CHAR test
[] = "test";
3563 static const CHAR test1
[] = "test1";
3565 hwnd
= create_listview_control(LVS_EDITLABELS
);
3566 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3568 insert_item(hwnd
, 0);
3570 /* try without edit created */
3571 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3574 /* cancel without data change */
3576 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3577 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3578 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3580 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3582 /* cancel after data change */
3583 memset(&itema
, 0, sizeof(itema
));
3584 itema
.pszText
= test
;
3585 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
3588 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3589 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3590 ret
= SetWindowText(hwndedit
, test1
);
3591 ok(ret
!= 0, "Expected edit text to change\n");
3592 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3594 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3595 memset(&itema
, 0, sizeof(itema
));
3596 itema
.pszText
= buff
;
3597 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3598 ret
= SendMessage(hwnd
, LVM_GETITEMTEXT
, 0, (LPARAM
)&itema
);
3600 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
3602 DestroyWindow(hwnd
);
3605 static void test_mapidindex(void)
3610 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3611 hwnd
= create_listview_control(LVS_OWNERDATA
);
3612 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3613 insert_item(hwnd
, 0);
3614 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3616 DestroyWindow(hwnd
);
3618 hwnd
= create_listview_control(0);
3619 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3621 /* LVM_MAPINDEXTOID with invalid index */
3622 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3625 insert_item(hwnd
, 0);
3626 insert_item(hwnd
, 1);
3628 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
3630 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
3633 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3635 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
3637 /* remove 0 indexed item, id retained */
3638 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
3639 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3641 /* new id starts from previous value */
3642 insert_item(hwnd
, 1);
3643 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
3646 /* get index by id */
3647 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
3649 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
3651 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
3653 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
3656 DestroyWindow(hwnd
);
3659 START_TEST(listview
)
3662 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
3664 ULONG_PTR ctx_cookie
;
3666 hComctl32
= GetModuleHandleA("comctl32.dll");
3667 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
3668 if (pInitCommonControlsEx
)
3670 INITCOMMONCONTROLSEX iccex
;
3671 iccex
.dwSize
= sizeof(iccex
);
3672 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
3673 pInitCommonControlsEx(&iccex
);
3676 InitCommonControls();
3678 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
3680 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3681 hwndparent
= create_parent_window(FALSE
);
3682 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_parent_wnd_seq
, "create parent window", TRUE
);
3683 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3685 g_is_below_5
= is_below_comctl_5();
3693 test_icon_spacing();
3696 test_item_position();
3701 test_subitem_rect();
3705 test_nosortheader();
3709 test_getitemposition();
3710 test_columnscreation();
3712 test_notifyformat();
3715 if (!load_v6_module(&ctx_cookie
))
3717 DestroyWindow(hwndparent
);
3721 /* comctl32 version 6 tests start here */
3722 test_get_set_view();
3723 test_canceleditlabel();
3726 unload_v6_module(ctx_cookie
);
3728 DestroyWindow(hwndparent
);