4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
29 #define PARENT_SEQ_INDEX 0
30 #define PARENT_FULL_SEQ_INDEX 1
31 #define LISTVIEW_SEQ_INDEX 2
32 #define EDITBOX_SEQ_INDEX 3
33 #define NUM_MSG_SEQUENCES 4
38 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
39 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
40 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
44 #elif defined __x86_64__
50 static const CHAR manifest_name
[] = "cc6.manifest";
52 static const CHAR manifest
[] =
53 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
54 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">\n"
55 " <assemblyIdentity\n"
57 " name=\"Wine.ComCtl32.Tests\"\n"
58 " version=\"1.0.0.0\"\n"
59 " processorArchitecture=\"" ARCH
"\"\n"
61 "<description>Wine comctl32 test suite</description>\n"
63 " <dependentAssembly>\n"
64 " <assemblyIdentity\n"
66 " name=\"microsoft.windows.common-controls\"\n"
67 " version=\"6.0.0.0\"\n"
68 " processorArchitecture=\"" ARCH
"\"\n"
69 " publicKeyToken=\"6595b64144ccf1df\"\n"
72 "</dependentAssembly>\n"
76 static const WCHAR testparentclassW
[] =
77 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
79 HWND hwndparent
, hwndparentW
;
80 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
82 /* dumps LVN_ITEMCHANGED message data */
83 static BOOL g_dump_itemchanged
;
84 /* format reported to control:
85 -1 falls to defproc, anything else returned */
87 /* indicates we're running < 5.80 version */
90 static HWND
subclass_editbox(HWND hwndListview
);
92 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
94 static const struct message create_ownerdrawfixed_parent_seq
[] = {
95 { WM_NOTIFYFORMAT
, sent
},
96 { WM_QUERYUISTATE
, sent
|optional
}, /* Win2K and higher */
97 { WM_MEASUREITEM
, sent
},
98 { WM_PARENTNOTIFY
, sent
},
102 static const struct message redraw_listview_seq
[] = {
103 { WM_PAINT
, sent
|id
, 0, 0, LISTVIEW_ID
},
104 { WM_PAINT
, sent
|id
, 0, 0, HEADER_ID
},
105 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
106 { WM_ERASEBKGND
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
107 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
108 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
109 { WM_ERASEBKGND
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
113 static const struct message listview_icon_spacing_seq
[] = {
114 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(20, 30) },
115 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(25, 35) },
116 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(-1, -1) },
120 static const struct message listview_color_seq
[] = {
121 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
122 { LVM_GETBKCOLOR
, sent
},
123 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
124 { LVM_GETTEXTCOLOR
, sent
},
125 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
126 { LVM_GETTEXTBKCOLOR
, sent
},
128 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
129 { LVM_GETBKCOLOR
, sent
},
130 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
131 { LVM_GETTEXTCOLOR
, sent
},
132 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
133 { LVM_GETTEXTBKCOLOR
, sent
},
135 { LVM_SETBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
136 { LVM_GETBKCOLOR
, sent
},
137 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, CLR_NONE
},
138 { LVM_GETTEXTCOLOR
, sent
},
139 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
140 { LVM_GETTEXTBKCOLOR
, sent
},
142 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
143 { LVM_GETBKCOLOR
, sent
},
144 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
145 { LVM_GETTEXTCOLOR
, sent
},
146 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
147 { LVM_GETTEXTBKCOLOR
, sent
},
151 static const struct message listview_item_count_seq
[] = {
152 { LVM_GETITEMCOUNT
, sent
},
153 { LVM_INSERTITEM
, sent
},
154 { LVM_INSERTITEM
, sent
},
155 { LVM_INSERTITEM
, sent
},
156 { LVM_GETITEMCOUNT
, sent
},
157 { LVM_DELETEITEM
, sent
|wparam
, 2 },
158 { LVM_GETITEMCOUNT
, sent
},
159 { LVM_DELETEALLITEMS
, sent
},
160 { LVM_GETITEMCOUNT
, sent
},
161 { LVM_INSERTITEM
, sent
},
162 { LVM_INSERTITEM
, sent
},
163 { LVM_GETITEMCOUNT
, sent
},
164 { LVM_INSERTITEM
, sent
},
165 { LVM_GETITEMCOUNT
, sent
},
169 static const struct message listview_itempos_seq
[] = {
170 { LVM_INSERTITEM
, sent
},
171 { LVM_INSERTITEM
, sent
},
172 { LVM_INSERTITEM
, sent
},
173 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 1, MAKELPARAM(10,5) },
174 { LVM_GETITEMPOSITION
, sent
|wparam
, 1 },
175 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 2, MAKELPARAM(0,0) },
176 { LVM_GETITEMPOSITION
, sent
|wparam
, 2 },
177 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 0, MAKELPARAM(20,20) },
178 { LVM_GETITEMPOSITION
, sent
|wparam
, 0 },
182 static const struct message listview_ownerdata_switchto_seq
[] = {
183 { WM_STYLECHANGING
, sent
},
184 { WM_STYLECHANGED
, sent
},
188 static const struct message listview_getorderarray_seq
[] = {
189 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
190 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
194 static const struct message empty_seq
[] = {
198 static const struct message forward_erasebkgnd_parent_seq
[] = {
199 { WM_ERASEBKGND
, sent
},
203 static const struct message ownderdata_select_focus_parent_seq
[] = {
204 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
205 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
206 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
}, /* version 4.7x */
210 static const struct message ownerdata_setstate_all_parent_seq
[] = {
211 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
215 static const struct message ownerdata_defocus_all_parent_seq
[] = {
216 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
217 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
218 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
222 static const struct message ownerdata_deselect_all_parent_seq
[] = {
223 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ODCACHEHINT
},
224 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
228 static const struct message select_all_parent_seq
[] = {
229 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
230 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
232 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
233 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
235 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
236 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
238 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
239 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
241 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
242 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
246 static const struct message textcallback_set_again_parent_seq
[] = {
247 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
248 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
252 static const struct message single_getdispinfo_parent_seq
[] = {
253 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
257 static const struct message getitemposition_seq1
[] = {
258 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
262 static const struct message getitemposition_seq2
[] = {
263 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
264 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
268 static const struct message editbox_create_pos
[] = {
269 /* sequence sent after LVN_BEGINLABELEDIT */
270 /* next two are 4.7x specific */
271 { WM_WINDOWPOSCHANGING
, sent
},
272 { WM_WINDOWPOSCHANGED
, sent
|optional
},
274 { WM_WINDOWPOSCHANGING
, sent
|optional
},
275 { WM_NCCALCSIZE
, sent
},
276 { WM_WINDOWPOSCHANGED
, sent
},
277 { WM_MOVE
, sent
|defwinproc
},
278 { WM_SIZE
, sent
|defwinproc
},
279 /* the rest is todo, skipped in 4.7x */
280 { WM_WINDOWPOSCHANGING
, sent
|optional
},
281 { WM_WINDOWPOSCHANGED
, sent
|optional
},
285 static const struct message scroll_parent_seq
[] = {
286 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_BEGINSCROLL
},
287 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDSCROLL
},
291 static const struct message setredraw_seq
[] = {
292 { WM_SETREDRAW
, sent
|id
|wparam
, FALSE
, 0, LISTVIEW_ID
},
301 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
303 static LONG defwndproc_counter
= 0;
307 msg
.message
= message
;
308 msg
.flags
= sent
|wparam
|lparam
;
309 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
312 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
314 /* log system messages, except for painting */
315 if (message
< WM_USER
&&
316 message
!= WM_PAINT
&&
317 message
!= WM_ERASEBKGND
&&
318 message
!= WM_NCPAINT
&&
319 message
!= WM_NCHITTEST
&&
320 message
!= WM_GETTEXT
&&
321 message
!= WM_GETICON
&&
322 message
!= WM_DEVICECHANGE
)
324 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
326 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
328 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
334 switch (((NMHDR
*)lParam
)->code
)
336 case LVN_BEGINLABELEDIT
:
337 /* subclass edit box */
339 subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
343 case LVN_ENDLABELEDIT
:
344 /* always accept new item text */
346 case LVN_BEGINSCROLL
:
349 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
351 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
352 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
355 case LVN_ITEMCHANGED
:
356 if (g_dump_itemchanged
)
358 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
359 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
360 nmlv
->iItem
, nmlv
->uNewState
, nmlv
->uOldState
, nmlv
->uChanged
);
366 case WM_NOTIFYFORMAT
:
368 /* force to return format */
369 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
374 defwndproc_counter
++;
375 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
376 defwndproc_counter
--;
381 static BOOL
register_parent_wnd_class(BOOL Unicode
)
389 clsW
.lpfnWndProc
= parent_wnd_proc
;
392 clsW
.hInstance
= GetModuleHandleW(NULL
);
394 clsW
.hCursor
= LoadCursorA(0, IDC_ARROW
);
395 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
396 clsW
.lpszMenuName
= NULL
;
397 clsW
.lpszClassName
= testparentclassW
;
402 clsA
.lpfnWndProc
= parent_wnd_proc
;
405 clsA
.hInstance
= GetModuleHandleA(NULL
);
407 clsA
.hCursor
= LoadCursorA(0, IDC_ARROW
);
408 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
409 clsA
.lpszMenuName
= NULL
;
410 clsA
.lpszClassName
= "Listview test parent class";
413 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
416 static HWND
create_parent_window(BOOL Unicode
)
418 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W'};
420 if (!register_parent_wnd_class(Unicode
))
427 return CreateWindowExW(0, testparentclassW
, nameW
,
428 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
429 WS_MAXIMIZEBOX
| WS_VISIBLE
,
431 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
433 return CreateWindowExA(0, "Listview test parent class",
434 "Listview test parent window",
435 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
436 WS_MAXIMIZEBOX
| WS_VISIBLE
,
438 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
441 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
443 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
444 static LONG defwndproc_counter
= 0;
448 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
450 /* some debug output for style changing */
451 if ((message
== WM_STYLECHANGING
||
452 message
== WM_STYLECHANGED
) && lParam
)
454 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
455 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
458 msg
.message
= message
;
459 msg
.flags
= sent
|wparam
|lparam
;
460 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
463 msg
.id
= LISTVIEW_ID
;
464 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
466 defwndproc_counter
++;
467 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
468 defwndproc_counter
--;
472 static HWND
create_listview_control(DWORD style
)
474 struct subclass_info
*info
;
478 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
482 GetClientRect(hwndparent
, &rect
);
483 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
484 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
| style
,
485 0, 0, rect
.right
, rect
.bottom
,
486 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
487 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
491 HeapFree(GetProcessHeap(), 0, info
);
495 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
496 (LONG_PTR
)listview_subclass_proc
);
497 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
502 /* unicode listview window with specified parent */
503 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
505 struct subclass_info
*info
;
508 static const WCHAR nameW
[] = {'f','o','o',0};
510 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
514 GetClientRect(parent
, &rect
);
515 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
516 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
| style
,
517 0, 0, rect
.right
, rect
.bottom
,
518 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
519 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
523 HeapFree(GetProcessHeap(), 0, info
);
527 info
->oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
528 (LONG_PTR
)listview_subclass_proc
);
529 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
534 static HWND
create_custom_listview_control(DWORD style
)
536 struct subclass_info
*info
;
540 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
544 GetClientRect(hwndparent
, &rect
);
545 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
546 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
547 0, 0, rect
.right
, rect
.bottom
,
548 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
549 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
553 HeapFree(GetProcessHeap(), 0, info
);
557 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
558 (LONG_PTR
)listview_subclass_proc
);
559 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
564 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
566 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
567 static LONG defwndproc_counter
= 0;
571 trace("header: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
573 msg
.message
= message
;
574 msg
.flags
= sent
|wparam
|lparam
;
575 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
579 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
581 defwndproc_counter
++;
582 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
583 defwndproc_counter
--;
587 static HWND
subclass_header(HWND hwndListview
)
589 struct subclass_info
*info
;
592 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
596 hwnd
= ListView_GetHeader(hwndListview
);
597 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
598 (LONG_PTR
)header_subclass_proc
);
599 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
604 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
606 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
607 static LONG defwndproc_counter
= 0;
611 msg
.message
= message
;
612 msg
.flags
= sent
|wparam
|lparam
;
613 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
617 /* all we need is sizing */
618 if (message
== WM_WINDOWPOSCHANGING
||
619 message
== WM_NCCALCSIZE
||
620 message
== WM_WINDOWPOSCHANGED
||
621 message
== WM_MOVE
||
624 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
627 defwndproc_counter
++;
628 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
629 defwndproc_counter
--;
633 static HWND
subclass_editbox(HWND hwndListview
)
635 struct subclass_info
*info
;
638 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
642 hwnd
= (HWND
)SendMessage(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
643 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
644 (LONG_PTR
)editbox_subclass_proc
);
645 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)info
);
650 /* Performs a single LVM_HITTEST test */
651 static void test_lvm_hittest(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
,
652 BOOL todo_item
, BOOL todo_flags
, int line
)
661 trace("hittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
662 ret
= SendMessage(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
668 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
669 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
670 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
675 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
676 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
677 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
683 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
686 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
689 /* Performs a single LVM_SUBITEMHITTEST test */
690 static void test_lvm_subitemhittest(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
691 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
699 trace("subhittesting pt=(%d,%d)\n", lpht
.pt
.x
, lpht
.pt
.y
);
700 ret
= SendMessage(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
706 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
707 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
712 ok_(__FILE__
, line
)(ret
== item
, "Expected %d item, got %d\n", item
, ret
);
713 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
719 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
722 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
727 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
730 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags %x, got %x\n", flags
, lpht
.flags
);
733 static void test_images(void)
741 static CHAR hello
[] = "hello";
743 himl
= ImageList_Create(40, 40, 0, 4, 4);
744 ok(himl
!= NULL
, "failed to create imagelist\n");
746 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
747 ok(hbmp
!= NULL
, "failed to create bitmap\n");
749 r
= ImageList_Add(himl
, hbmp
, 0);
750 ok(r
== 0, "should be zero\n");
752 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
753 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
754 ok(hwnd
!= NULL
, "failed to create listview window\n");
756 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
757 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
759 ok(r
== 0, "should return zero\n");
761 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
762 ok(r
== 0, "should return zero\n");
764 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
765 /* returns dimensions */
767 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
768 ok(r
== 0, "should be zero items\n");
770 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
775 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
776 ok(r
== -1, "should fail\n");
779 item
.pszText
= hello
;
780 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
781 ok(r
== 0, "should not fail\n");
783 memset(&r1
, 0, sizeof r1
);
785 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
787 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
788 ok(r
== TRUE
, "should not fail\n");
791 item
.pszText
= hello
;
792 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
793 ok(r
== 0, "should not fail\n");
795 memset(&r2
, 0, sizeof r2
);
797 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
799 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
804 static void test_checkboxes(void)
809 static CHAR text
[] = "Text",
813 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
814 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
815 ok(hwnd
!= NULL
, "failed to create listview window\n");
817 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
818 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
819 item
.stateMask
= 0xffff;
824 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
825 ok(r
== 0, "ret %d\n", r
);
828 item
.mask
= LVIF_STATE
;
829 item
.stateMask
= 0xffff;
830 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
831 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
833 /* Don't set LVIF_STATE */
834 item
.mask
= LVIF_TEXT
;
835 item
.stateMask
= 0xffff;
840 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
841 ok(r
== 1, "ret %d\n", r
);
844 item
.mask
= LVIF_STATE
;
845 item
.stateMask
= 0xffff;
846 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
847 ok(item
.state
== 0, "state %x\n", item
.state
);
849 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
850 ok(r
== 0, "should return zero\n");
852 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
854 item
.mask
= LVIF_STATE
;
855 item
.stateMask
= 0xffff;
856 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
857 ok(item
.state
== 0x1ccc, "state %x\n", item
.state
);
859 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
861 item
.mask
= LVIF_TEXT
;
863 item
.pszText
= text2
;
864 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
865 ok(r
== 2, "ret %d\n", r
);
868 item
.mask
= LVIF_STATE
;
869 item
.stateMask
= 0xffff;
870 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
871 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
873 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
875 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
876 item
.stateMask
= 0xffff;
878 item
.pszText
= text3
;
879 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
880 ok(r
== 3, "ret %d\n", r
);
883 item
.mask
= LVIF_STATE
;
884 item
.stateMask
= 0xffff;
885 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
886 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
888 /* Set an item's state to checked */
890 item
.mask
= LVIF_STATE
;
891 item
.stateMask
= 0xf000;
893 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
896 item
.mask
= LVIF_STATE
;
897 item
.stateMask
= 0xffff;
898 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
899 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
901 /* Check that only the bits we asked for are returned,
902 * and that all the others are set to zero
905 item
.mask
= LVIF_STATE
;
906 item
.stateMask
= 0xf000;
908 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
909 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
911 /* Set the style again and check that doesn't change an item's state */
912 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
913 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
916 item
.mask
= LVIF_STATE
;
917 item
.stateMask
= 0xffff;
918 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
919 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
921 /* Unsetting the checkbox extended style doesn't change an item's state */
922 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
923 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
926 item
.mask
= LVIF_STATE
;
927 item
.stateMask
= 0xffff;
928 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
929 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
931 /* Now setting the style again will change an item's state */
932 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
933 ok(r
== 0, "ret %x\n", r
);
936 item
.mask
= LVIF_STATE
;
937 item
.stateMask
= 0xffff;
938 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
939 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
941 /* Toggle checkbox tests (bug 9934) */
942 memset (&item
, 0xcc, sizeof(item
));
943 item
.mask
= LVIF_STATE
;
946 item
.state
= LVIS_FOCUSED
;
947 item
.stateMask
= LVIS_FOCUSED
;
948 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
952 item
.mask
= LVIF_STATE
;
953 item
.stateMask
= 0xffff;
954 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
955 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
957 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
959 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
963 item
.mask
= LVIF_STATE
;
964 item
.stateMask
= 0xffff;
965 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
966 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
968 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
970 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
974 item
.mask
= LVIF_STATE
;
975 item
.stateMask
= 0xffff;
976 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
977 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
982 static void insert_column(HWND hwnd
, int idx
)
987 memset(&column
, 0xcc, sizeof(column
));
988 column
.mask
= LVCF_SUBITEM
;
989 column
.iSubItem
= idx
;
991 rc
= ListView_InsertColumn(hwnd
, idx
, &column
);
995 static void insert_item(HWND hwnd
, int idx
)
997 static CHAR text
[] = "foo";
1002 memset(&item
, 0xcc, sizeof (item
));
1003 item
.mask
= LVIF_TEXT
;
1006 item
.pszText
= text
;
1008 rc
= ListView_InsertItem(hwnd
, &item
);
1012 static void test_items(void)
1014 const LPARAM lparamTest
= 0x42;
1018 static CHAR text
[] = "Text";
1020 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1021 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1022 ok(hwnd
!= NULL
, "failed to create listview window\n");
1025 * Test setting/getting item params
1028 /* Set up two columns */
1029 insert_column(hwnd
, 0);
1030 insert_column(hwnd
, 1);
1032 /* LVIS_SELECTED with zero stateMask */
1034 memset (&item
, 0, sizeof (item
));
1035 item
.mask
= LVIF_STATE
;
1036 item
.state
= LVIS_SELECTED
;
1040 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1041 ok(r
== 0, "ret %d\n", r
);
1043 memset (&item
, 0xcc, sizeof (item
));
1044 item
.mask
= LVIF_STATE
;
1045 item
.stateMask
= LVIS_SELECTED
;
1049 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1050 ok(r
!= 0, "ret %d\n", r
);
1051 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1052 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1054 /* LVIS_SELECTED with zero stateMask */
1056 memset (&item
, 0, sizeof (item
));
1057 item
.mask
= LVIF_STATE
;
1058 item
.state
= LVIS_FOCUSED
;
1062 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1063 ok(r
== 0, "ret %d\n", r
);
1065 memset (&item
, 0xcc, sizeof (item
));
1066 item
.mask
= LVIF_STATE
;
1067 item
.stateMask
= LVIS_FOCUSED
;
1071 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1072 ok(r
!= 0, "ret %d\n", r
);
1073 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1074 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1076 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1078 memset (&item
, 0, sizeof (item
));
1079 item
.mask
= LVIF_STATE
;
1080 item
.state
= LVIS_CUT
;
1081 item
.stateMask
= LVIS_FOCUSED
;
1084 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1085 ok(r
== 0, "ret %d\n", r
);
1087 memset (&item
, 0xcc, sizeof (item
));
1088 item
.mask
= LVIF_STATE
;
1089 item
.stateMask
= LVIS_CUT
;
1093 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1094 ok(r
!= 0, "ret %d\n", r
);
1095 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1096 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1098 /* Insert an item with just a param */
1099 memset (&item
, 0xcc, sizeof (item
));
1100 item
.mask
= LVIF_PARAM
;
1103 item
.lParam
= lparamTest
;
1104 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1105 ok(r
== 0, "ret %d\n", r
);
1107 /* Test getting of the param */
1108 memset (&item
, 0xcc, sizeof (item
));
1109 item
.mask
= LVIF_PARAM
;
1112 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1113 ok(r
!= 0, "ret %d\n", r
);
1114 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1116 /* Set up a subitem */
1117 memset (&item
, 0xcc, sizeof (item
));
1118 item
.mask
= LVIF_TEXT
;
1121 item
.pszText
= text
;
1122 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1123 ok(r
!= 0, "ret %d\n", r
);
1125 /* Query param from subitem: returns main item param */
1126 memset (&item
, 0xcc, sizeof (item
));
1127 item
.mask
= LVIF_PARAM
;
1130 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1131 ok(r
!= 0, "ret %d\n", r
);
1132 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1134 /* Set up param on first subitem: no effect */
1135 memset (&item
, 0xcc, sizeof (item
));
1136 item
.mask
= LVIF_PARAM
;
1139 item
.lParam
= lparamTest
+1;
1140 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1141 ok(r
== 0, "ret %d\n", r
);
1143 /* Query param from subitem again: should still return main item param */
1144 memset (&item
, 0xcc, sizeof (item
));
1145 item
.mask
= LVIF_PARAM
;
1148 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1149 ok(r
!= 0, "ret %d\n", r
);
1150 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1152 /**** Some tests of state highlighting ****/
1153 memset (&item
, 0xcc, sizeof (item
));
1154 item
.mask
= LVIF_STATE
;
1157 item
.state
= LVIS_SELECTED
;
1158 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1159 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1160 ok(r
!= 0, "ret %d\n", r
);
1162 item
.state
= LVIS_DROPHILITED
;
1163 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1164 ok(r
!= 0, "ret %d\n", r
);
1166 memset (&item
, 0xcc, sizeof (item
));
1167 item
.mask
= LVIF_STATE
;
1170 item
.stateMask
= -1;
1171 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1172 ok(r
!= 0, "ret %d\n", r
);
1173 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1175 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1176 ok(r
!= 0, "ret %d\n", r
);
1177 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1179 /* some notnull but meaningless masks */
1180 memset (&item
, 0, sizeof(item
));
1181 item
.mask
= LVIF_NORECOMPUTE
;
1184 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1185 ok(r
!= 0, "ret %d\n", r
);
1186 memset (&item
, 0, sizeof(item
));
1187 item
.mask
= LVIF_DI_SETITEM
;
1190 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1191 ok(r
!= 0, "ret %d\n", r
);
1193 /* set text to callback value already having it */
1194 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1196 memset (&item
, 0, sizeof (item
));
1197 item
.mask
= LVIF_TEXT
;
1198 item
.pszText
= LPSTR_TEXTCALLBACK
;
1200 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1201 ok(r
== 0, "ret %d\n", r
);
1202 memset (&item
, 0, sizeof (item
));
1204 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1206 item
.pszText
= LPSTR_TEXTCALLBACK
;
1207 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0 , (LPARAM
) &item
);
1210 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1211 "check callback text comparison rule", FALSE
);
1213 DestroyWindow(hwnd
);
1216 static void test_columns(void)
1218 HWND hwnd
, hwndheader
;
1223 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1224 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1225 ok(hwnd
!= NULL
, "failed to create listview window\n");
1227 /* Add a column with no mask */
1228 memset(&column
, 0xcc, sizeof(column
));
1230 rc
= ListView_InsertColumn(hwnd
, 0, &column
);
1231 ok(rc
==0, "Inserting column with no mask failed with %d\n", rc
);
1233 /* Check its width */
1234 rc
= ListView_GetColumnWidth(hwnd
, 0);
1236 broken(rc
==0), /* win9x */
1237 "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1239 DestroyWindow(hwnd
);
1241 /* LVM_GETCOLUMNORDERARRAY */
1242 hwnd
= create_listview_control(0);
1243 hwndheader
= subclass_header(hwnd
);
1245 memset(&column
, 0, sizeof(column
));
1246 column
.mask
= LVCF_WIDTH
;
1248 rc
= ListView_InsertColumn(hwnd
, 0, &column
);
1249 ok(rc
== 0, "Inserting column failed with %d\n", rc
);
1252 rc
= ListView_InsertColumn(hwnd
, 1, &column
);
1253 ok(rc
== 1, "Inserting column failed with %d\n", rc
);
1255 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1257 rc
= SendMessage(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1258 ok(rc
!= 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1259 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1260 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1262 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1264 DestroyWindow(hwnd
);
1266 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1267 static WNDPROC listviewWndProc
;
1268 static HIMAGELIST test_create_imagelist
;
1270 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1274 if (uMsg
== WM_CREATE
)
1276 LPCREATESTRUCT lpcs
= (LPCREATESTRUCT
)lParam
;
1277 lpcs
->style
|= LVS_REPORT
;
1279 ret
= CallWindowProc(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1280 if (uMsg
== WM_CREATE
) SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1284 static void test_create(void)
1293 cls
.cbSize
= sizeof(WNDCLASSEX
);
1294 ok(GetClassInfoEx(GetModuleHandle(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1295 listviewWndProc
= cls
.lpfnWndProc
;
1296 cls
.lpfnWndProc
= create_test_wndproc
;
1297 cls
.lpszClassName
= "MyListView32";
1298 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
1300 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1301 hList
= CreateWindow("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1302 ok((HIMAGELIST
)SendMessage(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1303 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1304 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1305 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1306 DestroyWindow(hList
);
1308 /* header isn't created on LVS_ICON and LVS_LIST styles */
1309 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1310 GetModuleHandle(NULL
), 0);
1311 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1312 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1313 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1315 memset(&col
, 0, sizeof(LVCOLUMNA
));
1316 col
.mask
= LVCF_WIDTH
;
1318 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1319 ok(r
== 0, "Expected 0 column's inserted\n");
1320 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1321 ok(IsWindow(hHeader
), "Header should be created\n");
1322 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1323 DestroyWindow(hList
);
1325 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1326 GetModuleHandle(NULL
), 0);
1327 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1328 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1329 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1331 memset(&col
, 0, sizeof(LVCOLUMNA
));
1332 col
.mask
= LVCF_WIDTH
;
1334 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1335 ok(r
== 0, "Expected 0 column's inserted\n");
1336 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1337 ok(IsWindow(hHeader
), "Header should be created\n");
1338 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1339 DestroyWindow(hList
);
1341 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1342 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1343 GetModuleHandle(NULL
), 0);
1344 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLongPtr(hList
, GWL_STYLE
) | LVS_REPORT
);
1345 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1346 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1347 ok(IsWindow(hHeader
), "Header should be created\n");
1348 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLong(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1349 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
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 DestroyWindow(hList
);
1355 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1356 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1357 GetModuleHandle(NULL
), 0);
1358 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1359 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1360 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1361 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1362 ok(IsWindow(hHeader
), "Header should be created\n");
1363 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1364 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1365 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1366 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1367 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1368 ok(IsWindow(hHeader
), "Header should be created\n");
1369 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1370 DestroyWindow(hList
);
1372 /* LVS_REPORT without WS_VISIBLE */
1373 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1374 GetModuleHandle(NULL
), 0);
1375 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1376 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1377 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1379 memset(&col
, 0, sizeof(LVCOLUMNA
));
1380 col
.mask
= LVCF_WIDTH
;
1382 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1383 ok(r
== 0, "Expected 0 column's inserted\n");
1384 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1385 ok(IsWindow(hHeader
), "Header should be created\n");
1386 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1387 DestroyWindow(hList
);
1389 /* LVS_REPORT without WS_VISIBLE, try to show it */
1390 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1391 GetModuleHandle(NULL
), 0);
1392 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1393 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1394 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1395 ShowWindow(hList
, SW_SHOW
);
1396 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1397 ok(IsWindow(hHeader
), "Header should be created\n");
1398 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1399 DestroyWindow(hList
);
1401 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1402 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1403 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1404 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1405 ok(IsWindow(hHeader
), "Header should be created\n");
1406 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1407 /* HDS_DRAGDROP set by default */
1408 ok(GetWindowLongPtr(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1409 DestroyWindow(hList
);
1411 /* setting LVS_EX_HEADERDRAGDROP creates header */
1412 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1413 GetModuleHandle(NULL
), 0);
1414 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1415 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1416 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1417 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1418 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1419 ok(IsWindow(hHeader
) ||
1420 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1421 "Header should be created\n");
1422 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1423 DestroyWindow(hList
);
1425 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1426 hList
= create_custom_listview_control(0);
1427 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1428 r
= SendMessage(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1429 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1430 DestroyWindow(hList
);
1432 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1433 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1434 GetModuleHandle(NULL
), 0);
1435 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1436 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1438 rect
.left
= LVIR_BOUNDS
;
1440 rect
.right
= rect
.bottom
= -10;
1441 r
= SendMessage(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1442 ok(r
!= 0, "Expected not-null LRESULT\n");
1444 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1445 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1446 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1448 DestroyWindow(hList
);
1450 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1451 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1452 hList
= create_listview_control(LVS_OWNERDRAWFIXED
);
1453 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1454 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1455 DestroyWindow(hList
);
1458 static void test_redraw(void)
1460 HWND hwnd
, hwndheader
;
1465 hwnd
= create_listview_control(0);
1466 hwndheader
= subclass_header(hwnd
);
1468 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1470 trace("invalidate & update\n");
1471 InvalidateRect(hwnd
, NULL
, TRUE
);
1473 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1475 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1477 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1478 /* 1. Without backbuffer */
1479 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1482 hdc
= GetWindowDC(hwndparent
);
1484 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1485 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1486 ok(r
!= 0, "Expected not zero result\n");
1487 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1488 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1490 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1493 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1494 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1495 ok(r
!= 0, "Expected not zero result\n");
1496 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1497 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1499 /* 2. With backbuffer */
1500 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1501 LVS_EX_DOUBLEBUFFER
);
1502 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1505 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1506 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1507 ok(r
!= 0, "Expected not zero result\n");
1508 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1509 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1511 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1514 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1515 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1516 todo_wine
ok(r
!= 0, "Expected not zero result\n");
1517 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1518 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1520 ReleaseDC(hwndparent
, hdc
);
1522 DestroyWindow(hwnd
);
1525 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1527 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1529 if(msg
== WM_NOTIFY
) {
1530 NMHDR
*nmhdr
= (PVOID
)lp
;
1531 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1532 NMLVCUSTOMDRAW
*nmlvcd
= (PVOID
)nmhdr
;
1533 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd
->nmcd
.dwDrawStage
);
1534 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1536 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1537 return CDRF_NOTIFYITEMDRAW
;
1538 case CDDS_ITEMPREPAINT
:
1539 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1540 return CDRF_NOTIFYSUBITEMDRAW
;
1541 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1542 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1543 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1544 return CDRF_NOTIFYPOSTPAINT
;
1545 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1546 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1547 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1548 return CDRF_DODEFAULT
;
1550 return CDRF_DODEFAULT
;
1554 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1557 static void test_customdraw(void)
1562 hwnd
= create_listview_control(0);
1564 insert_column(hwnd
, 0);
1565 insert_column(hwnd
, 1);
1566 insert_item(hwnd
, 0);
1568 oldwndproc
= (WNDPROC
)SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
,
1569 (LONG_PTR
)cd_wndproc
);
1571 InvalidateRect(hwnd
, NULL
, TRUE
);
1574 SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1576 DestroyWindow(hwnd
);
1579 static void test_icon_spacing(void)
1581 /* LVM_SETICONSPACING */
1582 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1588 hwnd
= create_custom_listview_control(LVS_ICON
);
1589 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1591 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, (LPARAM
)NF_REQUERY
);
1592 expect(NFR_ANSI
, r
);
1594 /* reset the icon spacing to defaults */
1595 SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1597 /* now we can request what the defaults are */
1598 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1602 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1604 trace("test icon spacing\n");
1606 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1607 ok(r
== MAKELONG(w
, h
) ||
1608 broken(r
== MAKELONG(w
, w
)), /* win98 */
1609 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1611 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1612 expect(MAKELONG(20,30), r
);
1614 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1615 expect(MAKELONG(25,35), r
);
1617 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1619 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1620 DestroyWindow(hwnd
);
1623 static void test_color(void)
1625 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1632 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1634 hwnd
= create_listview_control(0);
1635 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1637 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1639 trace("test color seq\n");
1640 for (i
= 0; i
< 4; i
++)
1644 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1646 r
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, color
);
1649 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1651 r
= SendMessage(hwnd
, LVM_GETTEXTCOLOR
, 0, color
);
1654 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1656 r
= SendMessage(hwnd
, LVM_GETTEXTBKCOLOR
, 0, color
);
1660 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1662 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1663 DestroyWindow(hwnd
);
1666 static void test_item_count(void)
1668 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1681 static CHAR item0text
[] = "item0";
1682 static CHAR item1text
[] = "item1";
1683 static CHAR item2text
[] = "item2";
1685 hwnd
= create_listview_control(0);
1686 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1688 /* resize in dpiaware manner to fit all 3 items added */
1690 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1691 GetTextMetricsA(hdc
, &tm
);
1692 /* 2 extra pixels for bounds and header border */
1693 height
= tm
.tmHeight
+ 2;
1694 SelectObject(hdc
, hOldFont
);
1697 GetWindowRect(hwnd
, &rect
);
1698 /* 3 items + 1 header + 1 to be sure */
1699 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1701 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1703 trace("test item count\n");
1705 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1709 item0
.mask
= LVIF_TEXT
;
1712 item0
.pszText
= item0text
;
1713 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1716 /* [item0, item1] */
1717 item1
.mask
= LVIF_TEXT
;
1720 item1
.pszText
= item1text
;
1721 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1724 /* [item0, item1, item2] */
1725 item2
.mask
= LVIF_TEXT
;
1728 item2
.pszText
= item2text
;
1729 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1732 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1735 /* [item0, item1] */
1736 r
= SendMessage(hwnd
, LVM_DELETEITEM
, 2, 0);
1739 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1743 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1746 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1750 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1753 /* [item0, item1] */
1754 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1757 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1760 /* [item0, item1, item2] */
1761 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1764 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1767 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
1769 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1770 DestroyWindow(hwnd
);
1773 static void test_item_position(void)
1775 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1784 static CHAR item0text
[] = "item0";
1785 static CHAR item1text
[] = "item1";
1786 static CHAR item2text
[] = "item2";
1788 hwnd
= create_custom_listview_control(LVS_ICON
);
1789 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1791 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1793 trace("test item position\n");
1796 item0
.mask
= LVIF_TEXT
;
1799 item0
.pszText
= item0text
;
1800 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1803 /* [item0, item1] */
1804 item1
.mask
= LVIF_TEXT
;
1807 item1
.pszText
= item1text
;
1808 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1811 /* [item0, item1, item2] */
1812 item2
.mask
= LVIF_TEXT
;
1815 item2
.pszText
= item2text
;
1816 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1819 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
1821 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
1823 expect2(10, 5, position
.x
, position
.y
);
1825 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
1827 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
1829 expect2(0, 0, position
.x
, position
.y
);
1831 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
1833 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
1835 expect2(20, 20, position
.x
, position
.y
);
1837 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
1839 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1840 DestroyWindow(hwnd
);
1843 static void test_getorigin(void)
1851 position
.x
= position
.y
= 0;
1853 hwnd
= create_custom_listview_control(LVS_ICON
);
1854 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1855 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1856 trace("test get origin results\n");
1857 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1859 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1860 DestroyWindow(hwnd
);
1862 hwnd
= create_custom_listview_control(LVS_SMALLICON
);
1863 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1864 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1865 trace("test get origin results\n");
1866 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1868 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1869 DestroyWindow(hwnd
);
1871 hwnd
= create_custom_listview_control(LVS_LIST
);
1872 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1873 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1874 trace("test get origin results\n");
1875 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1877 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1878 DestroyWindow(hwnd
);
1880 hwnd
= create_custom_listview_control(LVS_REPORT
);
1881 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1882 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1883 trace("test get origin results\n");
1884 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1886 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1887 DestroyWindow(hwnd
);
1891 static void test_multiselect(void)
1893 typedef struct t_select_task
1904 int i
,j
,item_count
,selected_count
;
1905 static const int items
=5;
1911 static struct t_select_task task_list
[] = {
1912 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
1913 { "using VK_UP", -1, VK_UP
, -1, -1 },
1914 { "using VK_END", 0, VK_END
, 1, -1 },
1915 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
1919 hwnd
= create_listview_control(0);
1921 for (i
=0;i
<items
;i
++) {
1922 insert_item(hwnd
, 0);
1925 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1927 expect(items
,item_count
);
1930 task
= task_list
[i
];
1932 /* deselect all items */
1933 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1934 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1936 /* set initial position */
1937 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
1938 ListView_SetItemState(hwnd
,(task
.initPos
== -1 ? item_count
-1 : task
.initPos
),LVIS_SELECTED
,LVIS_SELECTED
);
1940 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1942 ok(selected_count
== 1, "There should be only one selected item at the beginning (is %d)\n",selected_count
);
1944 /* Set SHIFT key pressed */
1945 GetKeyboardState(kstate
);
1946 kstate
[VK_SHIFT
]=0x80;
1947 SetKeyboardState(kstate
);
1949 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
1950 r
= SendMessage(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
1952 r
= SendMessage(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
1956 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
1958 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
);
1960 /* Set SHIFT key released */
1961 GetKeyboardState(kstate
);
1962 kstate
[VK_SHIFT
]=0x00;
1963 SetKeyboardState(kstate
);
1965 DestroyWindow(hwnd
);
1967 /* make multiple selection, then switch to LVS_SINGLESEL */
1968 hwnd
= create_listview_control(0);
1969 for (i
=0;i
<items
;i
++) {
1970 insert_item(hwnd
, 0);
1972 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1973 expect(items
,item_count
);
1975 /* try with NULL pointer */
1976 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)NULL
);
1979 /* select all, check notifications */
1980 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1982 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1984 item
.stateMask
= LVIS_SELECTED
;
1985 item
.state
= LVIS_SELECTED
;
1986 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
1989 ok_sequence(sequences
, PARENT_SEQ_INDEX
, select_all_parent_seq
,
1990 "select all notification", FALSE
);
1992 /* deselect all items */
1993 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
1994 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
1996 ListView_SetItemState(hwnd
, i
, LVIS_SELECTED
, LVIS_SELECTED
);
1999 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2001 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2004 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2005 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2006 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2007 /* check that style is accepted */
2008 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2009 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2012 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2013 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2015 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2017 SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2020 /* select one more */
2021 ListView_SetItemState(hwnd
, 3, LVIS_SELECTED
, LVIS_SELECTED
);
2024 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2025 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2027 r
= ListView_GetItemState(hwnd
, 3, LVIS_SELECTED
);
2028 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2030 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2032 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2035 /* try to select all on LVS_SINGLESEL */
2036 memset(&item
, 0, sizeof(item
));
2037 item
.stateMask
= LVIS_SELECTED
;
2038 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2040 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2042 item
.stateMask
= LVIS_SELECTED
;
2043 item
.state
= LVIS_SELECTED
;
2044 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2047 r
= ListView_GetSelectedCount(hwnd
);
2049 r
= ListView_GetSelectionMark(hwnd
);
2052 /* try to deselect all on LVS_SINGLESEL */
2053 item
.stateMask
= LVIS_SELECTED
;
2054 item
.state
= LVIS_SELECTED
;
2055 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2058 item
.stateMask
= LVIS_SELECTED
;
2060 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2062 r
= ListView_GetSelectedCount(hwnd
);
2065 DestroyWindow(hwnd
);
2068 static void test_subitem_rect(void)
2075 /* test LVM_GETSUBITEMRECT for header */
2076 hwnd
= create_listview_control(0);
2077 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2078 /* add some columns */
2079 memset(&col
, 0, sizeof(LVCOLUMN
));
2080 col
.mask
= LVCF_WIDTH
;
2083 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2087 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2091 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2093 /* item = -1 means header, subitem index is 1 based */
2094 rect
.left
= LVIR_BOUNDS
;
2096 rect
.right
= rect
.bottom
= 0;
2097 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2100 rect
.left
= LVIR_BOUNDS
;
2102 rect
.right
= rect
.bottom
= 0;
2103 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2105 ok(r
!= 0, "Expected not-null LRESULT\n");
2106 expect(100, rect
.left
);
2107 expect(250, rect
.right
);
2109 expect(3, rect
.top
);
2111 rect
.left
= LVIR_BOUNDS
;
2113 rect
.right
= rect
.bottom
= 0;
2114 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2116 ok(r
!= 0, "Expected not-null LRESULT\n");
2117 expect(250, rect
.left
);
2118 expect(450, rect
.right
);
2120 expect(3, rect
.top
);
2122 /* item LVS_REPORT padding isn't applied to subitems */
2123 insert_item(hwnd
, 0);
2125 rect
.left
= LVIR_BOUNDS
;
2127 rect
.right
= rect
.bottom
= 0;
2128 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2129 ok(r
!= 0, "Expected not-null LRESULT\n");
2130 expect(100, rect
.left
);
2131 expect(250, rect
.right
);
2133 rect
.left
= LVIR_ICON
;
2135 rect
.right
= rect
.bottom
= 0;
2136 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2137 ok(r
!= 0, "Expected not-null LRESULT\n");
2138 /* no icon attached - zero width rectangle, with no left padding */
2139 expect(100, rect
.left
);
2140 expect(100, rect
.right
);
2142 rect
.left
= LVIR_LABEL
;
2144 rect
.right
= rect
.bottom
= 0;
2145 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2146 ok(r
!= 0, "Expected not-null LRESULT\n");
2147 /* same as full LVIR_BOUNDS */
2148 expect(100, rect
.left
);
2149 expect(250, rect
.right
);
2151 DestroyWindow(hwnd
);
2153 /* try it for non LVS_REPORT style */
2154 hwnd
= CreateWindow("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2155 GetModuleHandle(NULL
), 0);
2156 rect
.left
= LVIR_BOUNDS
;
2158 rect
.right
= rect
.bottom
= -10;
2159 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2160 ok(r
== 0, "Expected not-null LRESULT\n");
2161 /* rect is unchanged */
2162 expect(0, rect
.left
);
2163 expect(-10, rect
.right
);
2164 expect(1, rect
.top
);
2165 expect(-10, rect
.bottom
);
2166 DestroyWindow(hwnd
);
2169 /* comparison callback for test_sorting */
2170 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2172 if (first
== second
) return 0;
2173 return (first
> second
? 1 : -1);
2176 static void test_sorting(void)
2182 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2185 hwnd
= create_listview_control(0);
2186 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2188 /* insert some items */
2189 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2190 item
.state
= LVIS_SELECTED
;
2194 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2197 item
.mask
= LVIF_PARAM
;
2201 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2204 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2205 item
.state
= LVIS_SELECTED
;
2209 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2212 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2215 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2218 r
= SendMessage(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2221 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2223 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2225 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2227 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2228 expect(LVIS_SELECTED
, r
);
2229 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2230 expect(LVIS_SELECTED
, r
);
2232 DestroyWindow(hwnd
);
2234 /* switch to LVS_SORTASCENDING when some items added */
2235 hwnd
= create_listview_control(0);
2236 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2238 item
.mask
= LVIF_TEXT
;
2241 item
.pszText
= names
[1];
2242 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2245 item
.mask
= LVIF_TEXT
;
2248 item
.pszText
= names
[2];
2249 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2252 item
.mask
= LVIF_TEXT
;
2255 item
.pszText
= names
[0];
2256 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2259 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2260 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2261 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2262 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2264 /* no sorting performed when switched to LVS_SORTASCENDING */
2265 item
.mask
= LVIF_TEXT
;
2267 item
.pszText
= buff
;
2268 item
.cchTextMax
= sizeof(buff
);
2269 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2271 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2274 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2276 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2279 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2281 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2283 /* adding new item doesn't resort list */
2284 item
.mask
= LVIF_TEXT
;
2287 item
.pszText
= names
[3];
2288 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2291 item
.mask
= LVIF_TEXT
;
2293 item
.pszText
= buff
;
2294 item
.cchTextMax
= sizeof(buff
);
2295 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2297 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2300 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2302 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2305 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2307 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2310 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2312 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2314 /* corner case - item should be placed at first position */
2315 item
.mask
= LVIF_TEXT
;
2318 item
.pszText
= names
[4];
2319 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2323 item
.pszText
= buff
;
2324 item
.cchTextMax
= sizeof(buff
);
2325 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2327 ok(lstrcmp(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2330 item
.pszText
= buff
;
2331 item
.cchTextMax
= sizeof(buff
);
2332 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2334 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2337 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2339 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2342 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2344 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2347 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2349 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2351 DestroyWindow(hwnd
);
2354 static void test_ownerdata(void)
2357 LONG_PTR style
, ret
;
2361 /* it isn't possible to set LVS_OWNERDATA after creation */
2364 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2368 hwnd
= create_listview_control(0);
2369 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2370 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2371 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2373 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2375 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2376 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2377 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2378 "try to switch to LVS_OWNERDATA seq", FALSE
);
2380 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2381 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2382 DestroyWindow(hwnd
);
2385 /* try to set LVS_OWNERDATA after creation just having it */
2386 hwnd
= create_listview_control(LVS_OWNERDATA
);
2387 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2388 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2389 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2391 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2393 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2394 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2395 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2396 "try to switch to LVS_OWNERDATA seq", FALSE
);
2397 DestroyWindow(hwnd
);
2399 /* try to remove LVS_OWNERDATA after creation just having it */
2402 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2406 hwnd
= create_listview_control(LVS_OWNERDATA
);
2407 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2408 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2409 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2411 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2413 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2414 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2415 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2416 "try to switch to LVS_OWNERDATA seq", FALSE
);
2417 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2418 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2419 DestroyWindow(hwnd
);
2422 /* try select an item */
2423 hwnd
= create_listview_control(LVS_OWNERDATA
);
2424 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2425 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2426 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2427 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2429 memset(&item
, 0, sizeof(item
));
2430 item
.stateMask
= LVIS_SELECTED
;
2431 item
.state
= LVIS_SELECTED
;
2432 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2434 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2436 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2438 DestroyWindow(hwnd
);
2440 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2441 hwnd
= create_listview_control(LVS_OWNERDATA
);
2442 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2443 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2444 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2445 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2447 memset(&item
, 0, sizeof(item
));
2448 item
.mask
= LVIF_STATE
;
2450 item
.stateMask
= LVIS_SELECTED
;
2451 item
.state
= LVIS_SELECTED
;
2452 res
= SendMessageA(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2454 DestroyWindow(hwnd
);
2456 /* check notifications after focused/selected changed */
2457 hwnd
= create_listview_control(LVS_OWNERDATA
);
2458 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2459 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
2460 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2462 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2464 memset(&item
, 0, sizeof(item
));
2465 item
.stateMask
= LVIS_SELECTED
;
2466 item
.state
= LVIS_SELECTED
;
2467 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2470 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2471 "ownerdata select notification", TRUE
);
2473 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2475 memset(&item
, 0, sizeof(item
));
2476 item
.stateMask
= LVIS_FOCUSED
;
2477 item
.state
= LVIS_FOCUSED
;
2478 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2481 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2482 "ownerdata focus notification", TRUE
);
2484 /* select all, check notifications */
2485 item
.stateMask
= LVIS_SELECTED
;
2487 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2490 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2492 item
.stateMask
= LVIS_SELECTED
;
2493 item
.state
= LVIS_SELECTED
;
2495 g_dump_itemchanged
= TRUE
;
2496 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2498 g_dump_itemchanged
= FALSE
;
2500 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2501 "ownerdata select all notification", TRUE
);
2503 /* select all again, note that all items are selected already */
2504 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2505 item
.stateMask
= LVIS_SELECTED
;
2506 item
.state
= LVIS_SELECTED
;
2507 g_dump_itemchanged
= TRUE
;
2508 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2510 g_dump_itemchanged
= FALSE
;
2511 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2512 "ownerdata select all notification", TRUE
);
2514 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2515 item
.stateMask
= LVIS_SELECTED
;
2517 g_dump_itemchanged
= TRUE
;
2518 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2520 g_dump_itemchanged
= FALSE
;
2521 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2522 "ownerdata deselect all notification", TRUE
);
2524 /* select one, then deselect all */
2525 item
.stateMask
= LVIS_SELECTED
;
2526 item
.state
= LVIS_SELECTED
;
2527 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2529 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2530 item
.stateMask
= LVIS_SELECTED
;
2532 g_dump_itemchanged
= TRUE
;
2533 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2535 g_dump_itemchanged
= FALSE
;
2536 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2537 "ownerdata select all notification", TRUE
);
2539 /* remove focused, try to focus all */
2540 item
.stateMask
= LVIS_FOCUSED
;
2541 item
.state
= LVIS_FOCUSED
;
2542 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2544 item
.stateMask
= LVIS_FOCUSED
;
2546 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2548 item
.stateMask
= LVIS_FOCUSED
;
2549 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
2551 /* setting all to focused returns failure value */
2552 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2553 item
.stateMask
= LVIS_FOCUSED
;
2554 item
.state
= LVIS_FOCUSED
;
2555 g_dump_itemchanged
= TRUE
;
2556 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2558 g_dump_itemchanged
= FALSE
;
2559 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2560 "ownerdata focus all notification", FALSE
);
2561 /* focus single item, remove all */
2562 item
.stateMask
= LVIS_FOCUSED
;
2563 item
.state
= LVIS_FOCUSED
;
2564 res
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2566 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2567 item
.stateMask
= LVIS_FOCUSED
;
2569 g_dump_itemchanged
= TRUE
;
2570 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2572 g_dump_itemchanged
= FALSE
;
2573 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
2574 "ownerdata remove focus all notification", TRUE
);
2576 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2577 item
.stateMask
= LVIS_CUT
;
2578 item
.state
= LVIS_CUT
;
2579 g_dump_itemchanged
= TRUE
;
2580 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2582 g_dump_itemchanged
= FALSE
;
2583 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2584 "ownerdata cut all notification", TRUE
);
2585 /* all marked cut, try again */
2586 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2587 item
.stateMask
= LVIS_CUT
;
2588 item
.state
= LVIS_CUT
;
2589 g_dump_itemchanged
= TRUE
;
2590 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2592 g_dump_itemchanged
= FALSE
;
2593 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2594 "ownerdata cut all notification #2", TRUE
);
2596 DestroyWindow(hwnd
);
2598 /* check notifications on LVM_GETITEM */
2599 /* zero callback mask */
2600 hwnd
= create_listview_control(LVS_OWNERDATA
);
2601 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2602 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2603 ok(res
!= 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2605 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2607 memset(&item
, 0, sizeof(item
));
2608 item
.stateMask
= LVIS_SELECTED
;
2609 item
.mask
= LVIF_STATE
;
2610 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2613 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2614 "ownerdata getitem selected state 1", FALSE
);
2616 /* non zero callback mask but not we asking for */
2617 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
2620 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2622 memset(&item
, 0, sizeof(item
));
2623 item
.stateMask
= LVIS_SELECTED
;
2624 item
.mask
= LVIF_STATE
;
2625 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2628 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2629 "ownerdata getitem selected state 2", FALSE
);
2631 /* LVIS_OVERLAYMASK callback mask, asking for index */
2632 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2634 memset(&item
, 0, sizeof(item
));
2635 item
.stateMask
= LVIS_OVERLAYMASK
;
2636 item
.mask
= LVIF_STATE
;
2637 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2640 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
2641 "ownerdata getitem selected state 2", FALSE
);
2643 DestroyWindow(hwnd
);
2645 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2646 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
);
2647 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2648 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2649 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2650 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2651 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
2652 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2653 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
2654 DestroyWindow(hwnd
);
2655 /* apparently it's allowed to switch these style on after creation */
2656 hwnd
= create_listview_control(LVS_OWNERDATA
);
2657 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2658 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2659 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2660 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2661 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2662 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2663 DestroyWindow(hwnd
);
2665 hwnd
= create_listview_control(LVS_OWNERDATA
);
2666 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2667 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2668 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2669 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
2670 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2671 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
2672 DestroyWindow(hwnd
);
2675 static void test_norecompute(void)
2677 static CHAR testA
[] = "test";
2683 /* self containing control */
2684 hwnd
= create_listview_control(0);
2685 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2686 memset(&item
, 0, sizeof(item
));
2687 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
2689 item
.stateMask
= LVIS_SELECTED
;
2690 item
.state
= LVIS_SELECTED
;
2691 item
.pszText
= testA
;
2692 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2694 /* retrieve with LVIF_NORECOMPUTE */
2695 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2697 item
.pszText
= buff
;
2698 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2699 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2701 ok(lstrcmp(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
2703 item
.mask
= LVIF_TEXT
;
2705 item
.pszText
= LPSTR_TEXTCALLBACK
;
2706 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2709 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2711 item
.pszText
= buff
;
2712 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2714 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2715 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2717 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2718 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2719 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
2721 DestroyWindow(hwnd
);
2724 hwnd
= create_listview_control(LVS_OWNERDATA
);
2725 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2727 item
.mask
= LVIF_STATE
;
2728 item
.stateMask
= LVIS_SELECTED
;
2729 item
.state
= LVIS_SELECTED
;
2731 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2734 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2736 item
.pszText
= buff
;
2737 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2738 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2739 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2741 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2742 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2743 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
2745 DestroyWindow(hwnd
);
2748 static void test_nosortheader(void)
2753 hwnd
= create_listview_control(0);
2754 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2756 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2757 ok(IsWindow(header
), "header expected\n");
2759 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2760 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
2762 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2763 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
2764 /* HDS_BUTTONS retained */
2765 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2766 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
2768 DestroyWindow(hwnd
);
2770 /* create with LVS_NOSORTHEADER */
2771 hwnd
= create_listview_control(LVS_NOSORTHEADER
);
2772 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2774 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2775 ok(IsWindow(header
), "header expected\n");
2777 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2778 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2780 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2781 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
2782 /* not changed here */
2783 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2784 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2786 DestroyWindow(hwnd
);
2789 static void test_setredraw(void)
2796 hwnd
= create_listview_control(LVS_OWNERDATA
);
2797 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2799 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2800 ListView seems to handle it internally without DefWinProc */
2802 /* default value first */
2803 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2806 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2807 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2808 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2810 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2811 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
2812 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2816 hdc
= GetWindowDC(hwndparent
);
2817 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
2819 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2821 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
2823 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
2825 ReleaseDC(hwndparent
, hdc
);
2827 /* check notification messages to show that repainting is disabled */
2828 ret
= SendMessage(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2830 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2832 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2834 InvalidateRect(hwnd
, NULL
, TRUE
);
2836 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2837 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
2839 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
2841 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2842 InvalidateRect(hwnd
, NULL
, TRUE
);
2844 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2845 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
2847 /* message isn't forwarded to header */
2848 subclass_header(hwnd
);
2849 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2850 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
2852 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
2853 "WM_SETREDRAW: not forwarded to header", FALSE
);
2855 DestroyWindow(hwnd
);
2858 static void test_hittest(void)
2864 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2867 HIMAGELIST himl
, himl2
;
2870 hwnd
= create_listview_control(0);
2871 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2873 /* LVS_REPORT with a single subitem (2 columns) */
2874 insert_column(hwnd
, 0);
2875 insert_column(hwnd
, 1);
2876 insert_item(hwnd
, 0);
2879 /* the only purpose of that line is to be as long as a half item rect */
2880 item
.pszText
= text
;
2881 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
2884 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
2886 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
2889 memset(&bounds
, 0, sizeof(bounds
));
2890 bounds
.left
= LVIR_BOUNDS
;
2891 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
2892 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
2893 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
2894 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
2897 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2898 x
= pos
.x
+ 50; /* column half width */
2899 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2900 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, __LINE__
);
2901 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2902 x
= pos
.x
+ 150; /* outside column */
2903 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2904 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2905 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2906 y
= (bounds
.bottom
- bounds
.top
) / 2;
2907 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, TRUE
, __LINE__
);
2908 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2909 /* outside possible client rectangle (to right) */
2911 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2912 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2913 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2914 y
= (bounds
.bottom
- bounds
.top
) / 2;
2915 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, TRUE
, __LINE__
);
2916 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2917 /* subitem returned with -1 item too */
2920 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2921 /* parent client area is 100x100 by default */
2922 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
2923 x
= pos
.x
+ 150; /* outside column */
2924 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2925 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, FALSE
, FALSE
, __LINE__
);
2926 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2927 y
= (bounds
.bottom
- bounds
.top
) / 2;
2928 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, FALSE
, TRUE
, __LINE__
);
2929 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2930 /* the same with LVS_EX_FULLROWSELECT */
2931 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
2932 x
= pos
.x
+ 150; /* outside column */
2933 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2934 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, FALSE
, FALSE
, __LINE__
);
2935 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2936 y
= (bounds
.bottom
- bounds
.top
) / 2;
2937 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2938 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
2939 x
= pos
.x
+ 150; /* outside column */
2940 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2941 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2942 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2943 y
= (bounds
.bottom
- bounds
.top
) / 2;
2944 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, TRUE
, __LINE__
);
2945 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
, __LINE__
);
2946 /* outside possible client rectangle (to right) */
2948 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2949 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, FALSE
, __LINE__
);
2950 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2951 y
= (bounds
.bottom
- bounds
.top
) / 2;
2952 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, FALSE
, TRUE
, __LINE__
);
2953 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
, __LINE__
);
2954 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2955 himl
= ImageList_Create(16, 16, 0, 4, 4);
2956 ok(himl
!= NULL
, "failed to create imagelist\n");
2957 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
2958 ok(hbmp
!= NULL
, "failed to create bitmap\n");
2959 r
= ImageList_Add(himl
, hbmp
, 0);
2960 ok(r
== 0, "should be zero\n");
2961 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
2962 ok(hbmp
!= NULL
, "failed to create bitmap\n");
2963 r
= ImageList_Add(himl
, hbmp
, 0);
2964 ok(r
== 1, "should be one\n");
2966 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
2967 ok(r
== 0, "should return zero\n");
2969 item
.mask
= LVIF_IMAGE
;
2973 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2977 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2978 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, __LINE__
);
2979 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2980 y
= (bounds
.bottom
- bounds
.top
) / 2;
2981 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2983 /* state icons indices are 1 based, check with valid index */
2984 item
.mask
= LVIF_STATE
;
2985 item
.state
= INDEXTOSTATEIMAGEMASK(1);
2986 item
.stateMask
= LVIS_STATEIMAGEMASK
;
2989 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2993 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
2994 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, __LINE__
);
2995 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2996 y
= (bounds
.bottom
- bounds
.top
) / 2;
2997 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
2999 himl2
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)NULL
);
3000 ok(himl2
== himl
, "should return handle\n");
3002 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3003 ok(r
== 0, "should return zero\n");
3006 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3007 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, __LINE__
);
3008 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
3009 y
= (bounds
.bottom
- bounds
.top
) / 2;
3010 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
, __LINE__
);
3012 DestroyWindow(hwnd
);
3015 static void test_getviewrect(void)
3022 hwnd
= create_listview_control(0);
3023 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3026 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3029 insert_column(hwnd
, 0);
3030 insert_column(hwnd
, 1);
3032 memset(&item
, 0, sizeof(item
));
3035 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3037 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3039 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3042 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3043 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3045 /* left is set to (2e31-1) - XP SP2 */
3046 expect(0, rect
.right
);
3047 expect(0, rect
.top
);
3048 expect(0, rect
.bottom
);
3050 /* switch to LVS_ICON */
3051 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3053 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3054 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3056 expect(0, rect
.left
);
3057 expect(0, rect
.top
);
3058 /* precise value differs for 2k, XP and Vista */
3059 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3060 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3062 DestroyWindow(hwnd
);
3065 static void test_getitemposition(void)
3072 hwnd
= create_listview_control(0);
3073 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3074 header
= subclass_header(hwnd
);
3076 /* LVS_REPORT, single item, no columns added */
3077 insert_item(hwnd
, 0);
3079 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3082 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3084 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3086 /* LVS_REPORT, single item, single column */
3087 insert_column(hwnd
, 0);
3089 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3092 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3094 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3096 memset(&rect
, 0, sizeof(rect
));
3097 SendMessage(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3100 /* offset by header height */
3101 expect(rect
.bottom
- rect
.top
, pt
.y
);
3103 DestroyWindow(hwnd
);
3106 static void test_columnscreation(void)
3111 hwnd
= create_listview_control(0);
3112 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3114 insert_item(hwnd
, 0);
3116 /* headers columns aren't created automatically */
3117 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3118 ok(IsWindow(header
), "Expected header handle\n");
3119 r
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
3122 DestroyWindow(hwnd
);
3125 static void test_getitemrect(void)
3137 hwnd
= create_listview_control(0);
3138 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3141 memset(&item
, 0, sizeof(item
));
3144 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3147 rect
.left
= LVIR_BOUNDS
;
3148 rect
.right
= rect
.top
= rect
.bottom
= -1;
3149 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3152 /* zero width rectangle with no padding */
3153 expect(0, rect
.left
);
3154 expect(0, rect
.right
);
3156 insert_column(hwnd
, 0);
3157 insert_column(hwnd
, 1);
3159 col
.mask
= LVCF_WIDTH
;
3161 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 0, (LPARAM
)&col
);
3164 col
.mask
= LVCF_WIDTH
;
3166 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 1, (LPARAM
)&col
);
3169 rect
.left
= LVIR_BOUNDS
;
3170 rect
.right
= rect
.top
= rect
.bottom
= -1;
3171 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3174 /* still no left padding */
3175 expect(0, rect
.left
);
3176 expect(150, rect
.right
);
3178 rect
.left
= LVIR_SELECTBOUNDS
;
3179 rect
.right
= rect
.top
= rect
.bottom
= -1;
3180 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3183 expect(2, rect
.left
);
3185 rect
.left
= LVIR_LABEL
;
3186 rect
.right
= rect
.top
= rect
.bottom
= -1;
3187 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3189 /* padding, column width */
3190 expect(2, rect
.left
);
3191 expect(50, rect
.right
);
3193 /* no icons attached */
3194 rect
.left
= LVIR_ICON
;
3195 rect
.right
= rect
.top
= rect
.bottom
= -1;
3196 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3199 expect(2, rect
.left
);
3200 expect(2, rect
.right
);
3203 order
[0] = 1; order
[1] = 0;
3204 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3207 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3209 /* 1 indexed column width + padding */
3211 /* rect is at zero too */
3212 rect
.left
= LVIR_BOUNDS
;
3213 rect
.right
= rect
.top
= rect
.bottom
= -1;
3214 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3216 expect(0, rect
.left
);
3217 /* just width sum */
3218 expect(150, rect
.right
);
3220 rect
.left
= LVIR_SELECTBOUNDS
;
3221 rect
.right
= rect
.top
= rect
.bottom
= -1;
3222 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3224 /* column width + padding */
3225 expect(102, rect
.left
);
3227 /* back to initial order */
3228 order
[0] = 0; order
[1] = 1;
3229 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3233 himl
= ImageList_Create(16, 16, 0, 2, 2);
3234 ok(himl
!= NULL
, "failed to create imagelist\n");
3235 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3236 ok(hbm
!= NULL
, "failed to create bitmap\n");
3237 r
= ImageList_Add(himl
, hbm
, 0);
3238 ok(r
== 0, "should be zero\n");
3239 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3240 ok(hbm
!= NULL
, "failed to create bitmap\n");
3241 r
= ImageList_Add(himl
, hbm
, 0);
3242 ok(r
== 1, "should be one\n");
3244 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3245 ok(r
== 0, "should return zero\n");
3247 item
.mask
= LVIF_STATE
;
3248 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3249 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3252 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3256 rect
.left
= LVIR_ICON
;
3257 rect
.right
= rect
.top
= rect
.bottom
= -1;
3258 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3260 /* padding + stateicon width */
3261 expect(18, rect
.left
);
3262 expect(18, rect
.right
);
3264 rect
.left
= LVIR_LABEL
;
3265 rect
.right
= rect
.top
= rect
.bottom
= -1;
3266 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3268 /* padding + stateicon width -> column width */
3269 expect(18, rect
.left
);
3270 expect(50, rect
.right
);
3272 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)NULL
);
3273 ok(r
!= 0, "should return current list handle\n");
3275 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3276 ok(r
== 0, "should return zero\n");
3278 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3281 item
.stateMask
= ~0;
3284 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3288 rect
.left
= LVIR_ICON
;
3289 rect
.right
= rect
.top
= rect
.bottom
= -1;
3290 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3292 /* padding, icon width */
3293 expect(2, rect
.left
);
3294 expect(18, rect
.right
);
3296 rect
.left
= LVIR_LABEL
;
3297 rect
.right
= rect
.top
= rect
.bottom
= -1;
3298 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3300 /* padding + icon width -> column width */
3301 expect(18, rect
.left
);
3302 expect(50, rect
.right
);
3305 rect
.left
= LVIR_SELECTBOUNDS
;
3306 rect
.right
= rect
.top
= rect
.bottom
= -1;
3307 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3309 /* padding, column width */
3310 expect(2, rect
.left
);
3311 expect(50, rect
.right
);
3313 /* try with indentation */
3314 item
.mask
= LVIF_INDENT
;
3318 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3322 rect
.left
= LVIR_BOUNDS
;
3323 rect
.right
= rect
.top
= rect
.bottom
= -1;
3324 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3326 /* padding + 1 icon width, column width */
3327 expect(0, rect
.left
);
3328 expect(150, rect
.right
);
3331 rect
.left
= LVIR_SELECTBOUNDS
;
3332 rect
.right
= rect
.top
= rect
.bottom
= -1;
3333 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3335 /* padding + 1 icon width, column width */
3336 expect(2 + 16, rect
.left
);
3337 expect(50, rect
.right
);
3340 rect
.left
= LVIR_LABEL
;
3341 rect
.right
= rect
.top
= rect
.bottom
= -1;
3342 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3344 /* padding + 2 icon widths, column width */
3345 expect(2 + 16*2, rect
.left
);
3346 expect(50, rect
.right
);
3349 rect
.left
= LVIR_ICON
;
3350 rect
.right
= rect
.top
= rect
.bottom
= -1;
3351 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3353 /* padding + 1 icon width indentation, icon width */
3354 expect(2 + 16, rect
.left
);
3355 expect(34, rect
.right
);
3358 DestroyWindow(hwnd
);
3361 static void test_editbox(void)
3363 HWND hwnd
, hwndedit
, hwndedit2
;
3366 static CHAR testitemA
[] = "testitem";
3367 static CHAR testitem1A
[] = "testitem1";
3368 static CHAR buffer
[10];
3370 hwnd
= create_listview_control(LVS_EDITLABELS
);
3371 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3373 insert_column(hwnd
, 0);
3375 memset(&item
, 0, sizeof(item
));
3376 item
.mask
= LVIF_TEXT
;
3377 item
.pszText
= testitemA
;
3380 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3383 /* setting focus is necessary */
3385 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3386 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3388 /* modify initial string */
3389 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3391 /* return focus to listview */
3394 memset(&item
, 0, sizeof(item
));
3395 item
.mask
= LVIF_TEXT
;
3396 item
.pszText
= buffer
;
3397 item
.cchTextMax
= 10;
3400 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3403 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3405 /* send LVM_EDITLABEL on already created edit */
3407 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3408 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3409 /* focus will be set to edit */
3410 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
3411 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3412 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
3414 /* creating label disabled when control isn't focused */
3416 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3417 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3419 /* check EN_KILLFOCUS handling */
3420 memset(&item
, 0, sizeof(item
));
3421 item
.pszText
= testitemA
;
3424 r
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3428 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3429 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3430 /* modify edit and notify control that it lost focus */
3431 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3433 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3435 memset(&item
, 0, sizeof(item
));
3436 item
.pszText
= buffer
;
3437 item
.cchTextMax
= 10;
3440 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3441 expect(lstrlen(item
.pszText
), r
);
3442 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3443 /* end edit without saving */
3444 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
3446 memset(&item
, 0, sizeof(item
));
3447 item
.pszText
= buffer
;
3448 item
.cchTextMax
= 10;
3451 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3452 expect(lstrlen(item
.pszText
), r
);
3453 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3455 /* LVM_EDITLABEL with -1 destroys current edit */
3456 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
3457 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3458 /* no edit present */
3459 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3460 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3461 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3462 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3464 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3465 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3466 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3467 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3468 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3469 /* check another negative value */
3470 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3471 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3472 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3473 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -2, 0);
3474 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3475 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3476 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3477 /* and value greater than max item index */
3478 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3479 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3480 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3481 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3482 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, r
, 0);
3483 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3484 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3485 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3487 /* messaging tests */
3489 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3491 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3492 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3493 /* testing only sizing messages */
3494 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
3495 "edit box create - sizing", FALSE
);
3497 DestroyWindow(hwnd
);
3500 static void test_notifyformat(void)
3505 hwnd
= create_listview_control(0);
3506 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3508 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3509 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3510 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3512 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3514 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
3516 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3519 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
3521 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3526 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3527 DestroyWindow(hwnd
);
3531 DestroyWindow(hwnd
);
3533 /* test failure in parent WM_NOTIFYFORMAT */
3535 hwnd
= create_listview_control(0);
3536 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3537 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3538 ok(IsWindow(header
), "expected header to be created\n");
3539 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3541 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3543 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3544 ok(r
!= 0, "Expected valid format\n");
3546 notifyFormat
= NFR_UNICODE
;
3547 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3548 expect(NFR_UNICODE
, r
);
3549 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3551 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3554 notifyFormat
= NFR_ANSI
;
3555 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3556 expect(NFR_ANSI
, r
);
3557 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3559 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3562 DestroyWindow(hwnd
);
3564 /* try different unicode window combination and defaults */
3565 if (!GetModuleHandleW(NULL
))
3567 win_skip("Additional notify format tests are incompatible with Win9x\n");
3571 hwndparentW
= create_parent_window(TRUE
);
3572 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
3573 if (!IsWindow(hwndparentW
)) return;
3576 hwnd
= create_listview_controlW(0, hwndparentW
);
3577 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3578 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3579 ok(IsWindow(header
), "expected header to be created\n");
3580 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3582 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3584 DestroyWindow(hwnd
);
3585 /* receiving error code defaulting to ansi */
3587 hwnd
= create_listview_controlW(0, hwndparentW
);
3588 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3589 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3590 ok(IsWindow(header
), "expected header to be created\n");
3591 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3593 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3595 DestroyWindow(hwnd
);
3596 /* receiving ansi code from unicode window, use it */
3597 notifyFormat
= NFR_ANSI
;
3598 hwnd
= create_listview_controlW(0, hwndparentW
);
3599 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3600 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3601 ok(IsWindow(header
), "expected header to be created\n");
3602 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3604 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3606 DestroyWindow(hwnd
);
3607 /* unicode listview with ansi parent window */
3609 hwnd
= create_listview_controlW(0, hwndparent
);
3610 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3611 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3612 ok(IsWindow(header
), "expected header to be created\n");
3613 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3615 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3617 DestroyWindow(hwnd
);
3618 /* unicode listview with ansi parent window, return error code */
3620 hwnd
= create_listview_controlW(0, hwndparent
);
3621 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3622 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3623 ok(IsWindow(header
), "expected header to be created\n");
3624 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3626 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3628 DestroyWindow(hwnd
);
3630 DestroyWindow(hwndparentW
);
3633 static void test_indentation(void)
3639 hwnd
= create_listview_control(0);
3640 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3642 memset(&item
, 0, sizeof(item
));
3643 item
.mask
= LVIF_INDENT
;
3645 item
.iIndent
= I_INDENTCALLBACK
;
3646 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3649 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3652 item
.mask
= LVIF_INDENT
;
3653 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3656 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3657 "get indent dispinfo", FALSE
);
3659 DestroyWindow(hwnd
);
3662 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
3667 static BOOL
is_below_comctl_5(void)
3672 hwnd
= create_listview_control(0);
3673 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3674 insert_item(hwnd
, 0);
3676 ret
= SendMessage(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
3678 DestroyWindow(hwnd
);
3683 static void unload_v6_module(ULONG_PTR cookie
)
3686 BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
, ULONG_PTR
);
3688 hKernel32
= GetModuleHandleA("kernel32.dll");
3689 pDeactivateActCtx
= (void*)GetProcAddress(hKernel32
, "DeactivateActCtx");
3690 if (!pDeactivateActCtx
)
3692 win_skip("Activation contexts unsupported\n");
3696 pDeactivateActCtx(0, cookie
);
3698 DeleteFileA(manifest_name
);
3701 static BOOL
load_v6_module(ULONG_PTR
*pcookie
)
3704 HANDLE (WINAPI
*pCreateActCtxA
)(ACTCTXA
*);
3705 BOOL (WINAPI
*pActivateActCtx
)(HANDLE
, ULONG_PTR
*);
3714 hKernel32
= GetModuleHandleA("kernel32.dll");
3715 pCreateActCtxA
= (void*)GetProcAddress(hKernel32
, "CreateActCtxA");
3716 pActivateActCtx
= (void*)GetProcAddress(hKernel32
, "ActivateActCtx");
3717 if (!(pCreateActCtxA
&& pActivateActCtx
))
3719 win_skip("Activation contexts unsupported. No version 6 tests possible.\n");
3723 /* create manifest */
3724 file
= CreateFileA( manifest_name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
3725 if (file
!= INVALID_HANDLE_VALUE
)
3727 ret
= (WriteFile( file
, manifest
, sizeof(manifest
)-1, &written
, NULL
) &&
3728 written
== sizeof(manifest
)-1);
3729 CloseHandle( file
);
3732 DeleteFileA( manifest_name
);
3733 skip("Failed to fill manifest file. Skipping comctl32 V6 tests.\n");
3737 trace("created %s\n", manifest_name
);
3741 skip("Failed to create manifest file. Skipping comctl32 V6 tests.\n");
3745 memset(&ctx
, 0, sizeof(ctx
));
3746 ctx
.cbSize
= sizeof(ctx
);
3747 ctx
.lpSource
= manifest_name
;
3749 hCtx
= pCreateActCtxA(&ctx
);
3750 ok(hCtx
!= 0, "Expected context handle\n");
3752 ret
= pActivateActCtx(hCtx
, pcookie
);
3757 win_skip("A problem during context activation occurred.\n");
3758 DeleteFileA(manifest_name
);
3763 /* this is a XP SP3 failure workaround */
3764 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
3765 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
,
3767 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
3768 if (!IsWindow(hwnd
))
3770 win_skip("FIXME: failed to create ListView window.\n");
3771 unload_v6_module(*pcookie
);
3775 DestroyWindow(hwnd
);
3781 static void test_get_set_view(void)
3787 /* test style->view mapping */
3788 hwnd
= create_listview_control(0);
3789 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3791 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3792 expect(LV_VIEW_DETAILS
, ret
);
3794 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3796 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
3797 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3798 expect(LV_VIEW_ICON
, ret
);
3800 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3801 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
3802 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3803 expect(LV_VIEW_SMALLICON
, ret
);
3805 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3806 SetWindowLongPtr(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
3807 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
3808 expect(LV_VIEW_LIST
, ret
);
3810 /* switching view doesn't touch window style */
3811 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
3813 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3814 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3815 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
3817 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3818 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3819 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
3821 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3822 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
3824 DestroyWindow(hwnd
);
3827 static void test_canceleditlabel(void)
3829 HWND hwnd
, hwndedit
;
3833 static CHAR test
[] = "test";
3834 static const CHAR test1
[] = "test1";
3836 hwnd
= create_listview_control(LVS_EDITLABELS
);
3837 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3839 insert_item(hwnd
, 0);
3841 /* try without edit created */
3842 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3845 /* cancel without data change */
3847 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3848 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3849 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3851 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3853 /* cancel after data change */
3854 memset(&itema
, 0, sizeof(itema
));
3855 itema
.pszText
= test
;
3856 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
3859 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3860 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
3861 ret
= SetWindowText(hwndedit
, test1
);
3862 ok(ret
!= 0, "Expected edit text to change\n");
3863 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
3865 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
3866 memset(&itema
, 0, sizeof(itema
));
3867 itema
.pszText
= buff
;
3868 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3869 ret
= SendMessage(hwnd
, LVM_GETITEMTEXT
, 0, (LPARAM
)&itema
);
3871 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
3873 DestroyWindow(hwnd
);
3876 static void test_mapidindex(void)
3881 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3882 hwnd
= create_listview_control(LVS_OWNERDATA
);
3883 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3884 insert_item(hwnd
, 0);
3885 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3887 DestroyWindow(hwnd
);
3889 hwnd
= create_listview_control(0);
3890 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3892 /* LVM_MAPINDEXTOID with invalid index */
3893 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3896 insert_item(hwnd
, 0);
3897 insert_item(hwnd
, 1);
3899 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
3901 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
3904 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3906 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
3908 /* remove 0 indexed item, id retained */
3909 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
3910 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
3912 /* new id starts from previous value */
3913 insert_item(hwnd
, 1);
3914 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
3917 /* get index by id */
3918 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
3920 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
3922 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
3924 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
3927 DestroyWindow(hwnd
);
3930 static void test_getitemspacing(void)
3939 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
3940 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
3943 hwnd
= create_custom_listview_control(0);
3944 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3946 expect(cx
, LOWORD(ret
));
3947 expect(cy
, HIWORD(ret
));
3949 /* now try with icons */
3950 himl
= ImageList_Create(40, 40, 0, 4, 4);
3951 ok(himl
!= NULL
, "failed to create imagelist\n");
3952 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
3953 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3954 ret
= ImageList_Add(himl
, hbmp
, 0);
3956 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
3959 itema
.mask
= LVIF_IMAGE
;
3963 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
3965 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3967 /* spacing + icon size returned */
3968 expect(cx
+ 40, LOWORD(ret
));
3969 expect(cy
+ 40, HIWORD(ret
));
3971 DestroyWindow(hwnd
);
3973 hwnd
= create_custom_listview_control(LVS_SMALLICON
);
3974 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3976 expect(cx
, LOWORD(ret
));
3977 expect(cy
, HIWORD(ret
));
3979 DestroyWindow(hwnd
);
3981 hwnd
= create_custom_listview_control(LVS_REPORT
);
3982 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3984 expect(cx
, LOWORD(ret
));
3985 expect(cy
, HIWORD(ret
));
3987 DestroyWindow(hwnd
);
3989 hwnd
= create_custom_listview_control(LVS_LIST
);
3990 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
3992 expect(cx
, LOWORD(ret
));
3993 expect(cy
, HIWORD(ret
));
3995 DestroyWindow(hwnd
);
3998 static void test_getcolumnwidth(void)
4005 /* default column width */
4006 hwnd
= create_custom_listview_control(0);
4007 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4009 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4010 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
4011 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4012 todo_wine
expect(8, ret
);
4013 style
= GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
4014 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
4016 ret
= SendMessage(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4018 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4020 DestroyWindow(hwnd
);
4023 static void test_scrollnotify(void)
4028 hwnd
= create_listview_control(0);
4030 insert_column(hwnd
, 0);
4031 insert_column(hwnd
, 1);
4032 insert_item(hwnd
, 0);
4034 /* make it scrollable - resize */
4035 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
4037 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
4040 /* try with dummy call */
4041 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4042 ret
= SendMessage(hwnd
, LVM_SCROLL
, 0, 0);
4044 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4045 "scroll notify 1", TRUE
);
4047 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4048 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 0);
4050 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4051 "scroll notify 2", TRUE
);
4053 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4054 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 1);
4056 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4057 "scroll notify 3", TRUE
);
4059 DestroyWindow(hwnd
);
4062 START_TEST(listview
)
4065 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
4067 ULONG_PTR ctx_cookie
;
4069 hComctl32
= GetModuleHandleA("comctl32.dll");
4070 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
4071 if (pInitCommonControlsEx
)
4073 INITCOMMONCONTROLSEX iccex
;
4074 iccex
.dwSize
= sizeof(iccex
);
4075 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
4076 pInitCommonControlsEx(&iccex
);
4079 InitCommonControls();
4081 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
4083 hwndparent
= create_parent_window(FALSE
);
4084 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4086 g_is_below_5
= is_below_comctl_5();
4094 test_icon_spacing();
4097 test_item_position();
4102 test_subitem_rect();
4106 test_nosortheader();
4110 test_getitemposition();
4111 test_columnscreation();
4113 test_notifyformat();
4115 test_getitemspacing();
4116 test_getcolumnwidth();
4118 if (!load_v6_module(&ctx_cookie
))
4120 DestroyWindow(hwndparent
);
4124 /* comctl32 version 6 tests start here */
4125 test_get_set_view();
4126 test_canceleditlabel();
4128 test_scrollnotify();
4130 unload_v6_module(ctx_cookie
);
4132 DestroyWindow(hwndparent
);