4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009-2011 Nikolay Sivov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
31 #define PARENT_SEQ_INDEX 0
32 #define PARENT_FULL_SEQ_INDEX 1
33 #define LISTVIEW_SEQ_INDEX 2
34 #define EDITBOX_SEQ_INDEX 3
35 #define COMBINED_SEQ_INDEX 4
36 #define NUM_MSG_SEQUENCES 5
41 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
42 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
43 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
45 static const WCHAR testparentclassW
[] =
46 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
48 static HWND hwndparent
, hwndparentW
;
49 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
50 static BOOL blockEdit
;
51 /* return nonzero on NM_HOVER */
52 static BOOL g_block_hover
;
53 /* dumps LVN_ITEMCHANGED message data */
54 static BOOL g_dump_itemchanged
;
55 /* format reported to control:
56 -1 falls to defproc, anything else returned */
57 static INT notifyFormat
;
58 /* indicates we're running < 5.80 version */
59 static BOOL g_is_below_5
;
60 /* item data passed to LVN_GETDISPINFOA */
61 static LVITEMA g_itema
;
62 /* alter notification code A->W */
63 static BOOL g_disp_A_to_W
;
64 /* dispinfo data sent with LVN_LVN_ENDLABELEDIT */
65 static NMLVDISPINFO g_editbox_disp_info
;
67 static HWND
subclass_editbox(HWND hwndListview
);
69 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
71 static const struct message create_ownerdrawfixed_parent_seq
[] = {
72 { WM_NOTIFYFORMAT
, sent
},
73 { WM_QUERYUISTATE
, sent
|optional
}, /* Win2K and higher */
74 { WM_MEASUREITEM
, sent
},
75 { WM_PARENTNOTIFY
, sent
},
79 static const struct message redraw_listview_seq
[] = {
80 { WM_PAINT
, sent
|id
, 0, 0, LISTVIEW_ID
},
81 { WM_PAINT
, sent
|id
, 0, 0, HEADER_ID
},
82 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
83 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, HEADER_ID
},
84 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
85 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
86 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, LISTVIEW_ID
},
90 static const struct message listview_icon_spacing_seq
[] = {
91 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(20, 30) },
92 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(25, 35) },
93 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(-1, -1) },
97 static const struct message listview_color_seq
[] = {
98 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
99 { LVM_GETBKCOLOR
, sent
},
100 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
101 { LVM_GETTEXTCOLOR
, sent
},
102 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
103 { LVM_GETTEXTBKCOLOR
, sent
},
105 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
106 { LVM_GETBKCOLOR
, sent
},
107 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
108 { LVM_GETTEXTCOLOR
, sent
},
109 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
110 { LVM_GETTEXTBKCOLOR
, sent
},
112 { LVM_SETBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
113 { LVM_GETBKCOLOR
, sent
},
114 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, CLR_NONE
},
115 { LVM_GETTEXTCOLOR
, sent
},
116 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
117 { LVM_GETTEXTBKCOLOR
, sent
},
119 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
120 { LVM_GETBKCOLOR
, sent
},
121 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
122 { LVM_GETTEXTCOLOR
, sent
},
123 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
124 { LVM_GETTEXTBKCOLOR
, sent
},
128 static const struct message listview_item_count_seq
[] = {
129 { LVM_GETITEMCOUNT
, sent
},
130 { LVM_INSERTITEM
, sent
},
131 { LVM_INSERTITEM
, sent
},
132 { LVM_INSERTITEM
, sent
},
133 { LVM_GETITEMCOUNT
, sent
},
134 { LVM_DELETEITEM
, sent
|wparam
, 2 },
135 { WM_NCPAINT
, sent
|optional
},
136 { WM_ERASEBKGND
, sent
|optional
},
137 { LVM_GETITEMCOUNT
, sent
},
138 { LVM_DELETEALLITEMS
, sent
},
139 { LVM_GETITEMCOUNT
, sent
},
140 { LVM_INSERTITEM
, sent
},
141 { LVM_INSERTITEM
, sent
},
142 { LVM_GETITEMCOUNT
, sent
},
143 { LVM_INSERTITEM
, sent
},
144 { LVM_GETITEMCOUNT
, sent
},
148 static const struct message listview_itempos_seq
[] = {
149 { LVM_INSERTITEM
, sent
},
150 { LVM_INSERTITEM
, sent
},
151 { LVM_INSERTITEM
, sent
},
152 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 1, MAKELPARAM(10,5) },
153 { WM_NCPAINT
, sent
|optional
},
154 { WM_ERASEBKGND
, sent
|optional
},
155 { LVM_GETITEMPOSITION
, sent
|wparam
, 1 },
156 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 2, MAKELPARAM(0,0) },
157 { LVM_GETITEMPOSITION
, sent
|wparam
, 2 },
158 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 0, MAKELPARAM(20,20) },
159 { LVM_GETITEMPOSITION
, sent
|wparam
, 0 },
163 static const struct message listview_ownerdata_switchto_seq
[] = {
164 { WM_STYLECHANGING
, sent
},
165 { WM_STYLECHANGED
, sent
},
169 static const struct message listview_getorderarray_seq
[] = {
170 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
171 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
175 static const struct message empty_seq
[] = {
179 static const struct message forward_erasebkgnd_parent_seq
[] = {
180 { WM_ERASEBKGND
, sent
},
184 static const struct message ownderdata_select_focus_parent_seq
[] = {
185 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
186 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
187 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
}, /* version 4.7x */
191 static const struct message ownerdata_setstate_all_parent_seq
[] = {
192 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
196 static const struct message ownerdata_defocus_all_parent_seq
[] = {
197 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
198 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
199 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
},
200 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
204 static const struct message ownerdata_deselect_all_parent_seq
[] = {
205 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ODCACHEHINT
},
206 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
210 static const struct message select_all_parent_seq
[] = {
211 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
212 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
214 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
215 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
217 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
218 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
220 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
221 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
223 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
224 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
228 static const struct message textcallback_set_again_parent_seq
[] = {
229 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
230 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
234 static const struct message single_getdispinfo_parent_seq
[] = {
235 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
239 static const struct message getitemposition_seq1
[] = {
240 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
244 static const struct message getitemposition_seq2
[] = {
245 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
246 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
250 static const struct message editbox_create_pos
[] = {
251 /* sequence sent after LVN_BEGINLABELEDIT */
252 /* next two are 4.7x specific */
253 { WM_WINDOWPOSCHANGING
, sent
},
254 { WM_WINDOWPOSCHANGED
, sent
|optional
},
256 { WM_WINDOWPOSCHANGING
, sent
|optional
},
257 { WM_NCCALCSIZE
, sent
},
258 { WM_WINDOWPOSCHANGED
, sent
},
259 { WM_MOVE
, sent
|defwinproc
},
260 { WM_SIZE
, sent
|defwinproc
},
261 /* the rest is todo, skipped in 4.7x */
262 { WM_WINDOWPOSCHANGING
, sent
|optional
},
263 { WM_WINDOWPOSCHANGED
, sent
|optional
},
267 static const struct message scroll_parent_seq
[] = {
268 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_BEGINSCROLL
},
269 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDSCROLL
},
273 static const struct message setredraw_seq
[] = {
274 { WM_SETREDRAW
, sent
|id
|wparam
, FALSE
, 0, LISTVIEW_ID
},
278 static const struct message lvs_ex_transparentbkgnd_seq
[] = {
279 { WM_PRINTCLIENT
, sent
|lparam
, 0, PRF_ERASEBKGND
},
283 static const struct message edit_end_nochange
[] = {
284 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDLABELEDITA
},
285 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
}, /* todo */
286 { WM_NOTIFY
, sent
|id
, 0, 0, NM_SETFOCUS
},
290 static const struct message hover_parent
[] = {
291 { WM_GETDLGCODE
, sent
}, /* todo_wine */
292 { WM_NOTIFY
, sent
|id
, 0, 0, NM_HOVER
},
296 static const struct message listview_destroy
[] = {
297 { 0x0090, sent
|optional
}, /* Vista */
298 { WM_PARENTNOTIFY
, sent
},
299 { WM_SHOWWINDOW
, sent
},
300 { WM_WINDOWPOSCHANGING
, sent
},
301 { WM_WINDOWPOSCHANGED
, sent
|optional
},
302 { WM_DESTROY
, sent
},
303 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_DELETEALLITEMS
},
304 { WM_NCDESTROY
, sent
},
308 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
310 static LONG defwndproc_counter
= 0;
314 msg
.message
= message
;
315 msg
.flags
= sent
|wparam
|lparam
;
316 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
319 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
321 /* log system messages, except for painting */
322 if (message
< WM_USER
&&
323 message
!= WM_PAINT
&&
324 message
!= WM_ERASEBKGND
&&
325 message
!= WM_NCPAINT
&&
326 message
!= WM_NCHITTEST
&&
327 message
!= WM_GETTEXT
&&
328 message
!= WM_GETICON
&&
329 message
!= WM_DEVICECHANGE
)
331 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
333 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
334 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
336 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
342 switch (((NMHDR
*)lParam
)->code
)
344 case LVN_BEGINLABELEDIT
:
348 /* subclass edit box */
350 edit
= subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
354 INT len
= SendMessageA(edit
, EM_GETLIMITTEXT
, 0, 0);
355 ok(len
== 259 || broken(len
== 260) /* includes NULL in NT4 */,
356 "text limit %d, expected 259\n", len
);
361 case LVN_ENDLABELEDIT
:
365 /* always accept new item text */
366 NMLVDISPINFO
*di
= (NMLVDISPINFO
*)lParam
;
367 g_editbox_disp_info
= *di
;
368 trace("LVN_ENDLABELEDIT: text=%s\n", di
->item
.pszText
);
370 /* edit control still available from this notification */
371 edit
= (HWND
)SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETEDITCONTROL
, 0, 0);
372 ok(IsWindow(edit
), "expected valid edit control handle\n");
376 case LVN_BEGINSCROLL
:
379 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
381 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
382 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
385 case LVN_ITEMCHANGED
:
386 if (g_dump_itemchanged
)
388 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
389 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
390 nmlv
->iItem
, nmlv
->uNewState
, nmlv
->uOldState
, nmlv
->uChanged
);
393 case LVN_GETDISPINFOA
:
395 NMLVDISPINFOA
*dispinfo
= (NMLVDISPINFOA
*)lParam
;
396 g_itema
= dispinfo
->item
;
398 if (g_disp_A_to_W
&& (dispinfo
->item
.mask
& LVIF_TEXT
))
400 static const WCHAR testW
[] = {'T','E','S','T',0};
401 dispinfo
->hdr
.code
= LVN_GETDISPINFOW
;
402 memcpy(dispinfo
->item
.pszText
, testW
, sizeof(testW
));
405 /* test control buffer size for text, 10 used to mask cases when control
406 is using caller buffer to process LVM_GETITEM for example */
407 if (dispinfo
->item
.mask
& LVIF_TEXT
&& dispinfo
->item
.cchTextMax
> 10)
408 ok(dispinfo
->item
.cchTextMax
== 260 ||
409 broken(dispinfo
->item
.cchTextMax
== 264) /* NT4 reports aligned size */,
410 "buffer size %d\n", dispinfo
->item
.cchTextMax
);
414 if (g_block_hover
) return 1;
419 case WM_NOTIFYFORMAT
:
421 /* force to return format */
422 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
427 defwndproc_counter
++;
428 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
429 defwndproc_counter
--;
434 static BOOL
register_parent_wnd_class(BOOL Unicode
)
442 clsW
.lpfnWndProc
= parent_wnd_proc
;
445 clsW
.hInstance
= GetModuleHandleW(NULL
);
447 clsW
.hCursor
= LoadCursorA(0, IDC_ARROW
);
448 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
449 clsW
.lpszMenuName
= NULL
;
450 clsW
.lpszClassName
= testparentclassW
;
455 clsA
.lpfnWndProc
= parent_wnd_proc
;
458 clsA
.hInstance
= GetModuleHandleA(NULL
);
460 clsA
.hCursor
= LoadCursorA(0, IDC_ARROW
);
461 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
462 clsA
.lpszMenuName
= NULL
;
463 clsA
.lpszClassName
= "Listview test parent class";
466 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
469 static HWND
create_parent_window(BOOL Unicode
)
471 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
474 if (!register_parent_wnd_class(Unicode
))
481 hwnd
= CreateWindowExW(0, testparentclassW
, nameW
,
482 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
483 WS_MAXIMIZEBOX
| WS_VISIBLE
,
485 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
487 hwnd
= CreateWindowExA(0, "Listview test parent class",
488 "Listview test parent window",
489 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
490 WS_MAXIMIZEBOX
| WS_VISIBLE
,
492 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
493 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
497 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
499 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
500 static LONG defwndproc_counter
= 0;
504 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
506 /* some debug output for style changing */
507 if ((message
== WM_STYLECHANGING
||
508 message
== WM_STYLECHANGED
) && lParam
)
510 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
511 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
514 msg
.message
= message
;
515 msg
.flags
= sent
|wparam
|lparam
;
516 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
519 msg
.id
= LISTVIEW_ID
;
520 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
521 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
523 defwndproc_counter
++;
524 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
525 defwndproc_counter
--;
529 static HWND
create_listview_control(DWORD style
)
535 GetClientRect(hwndparent
, &rect
);
536 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
537 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
538 0, 0, rect
.right
, rect
.bottom
,
539 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
540 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
542 if (!hwnd
) return NULL
;
544 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
545 (LONG_PTR
)listview_subclass_proc
);
546 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
551 /* unicode listview window with specified parent */
552 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
557 static const WCHAR nameW
[] = {'f','o','o',0};
559 GetClientRect(parent
, &rect
);
560 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
561 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
562 0, 0, rect
.right
, rect
.bottom
,
563 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
564 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
566 if (!hwnd
) return NULL
;
568 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
569 (LONG_PTR
)listview_subclass_proc
);
570 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
575 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
577 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
578 static LONG defwndproc_counter
= 0;
582 trace("header: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
584 msg
.message
= message
;
585 msg
.flags
= sent
|wparam
|lparam
;
586 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
590 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
592 defwndproc_counter
++;
593 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
594 defwndproc_counter
--;
598 static HWND
subclass_header(HWND hwndListview
)
603 hwnd
= ListView_GetHeader(hwndListview
);
604 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
605 (LONG_PTR
)header_subclass_proc
);
606 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
611 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
613 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
614 static LONG defwndproc_counter
= 0;
618 msg
.message
= message
;
619 msg
.flags
= sent
|wparam
|lparam
;
620 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
624 /* all we need is sizing */
625 if (message
== WM_WINDOWPOSCHANGING
||
626 message
== WM_NCCALCSIZE
||
627 message
== WM_WINDOWPOSCHANGED
||
628 message
== WM_MOVE
||
631 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
634 defwndproc_counter
++;
635 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
636 defwndproc_counter
--;
640 static HWND
subclass_editbox(HWND hwndListview
)
645 hwnd
= (HWND
)SendMessage(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
646 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
647 (LONG_PTR
)editbox_subclass_proc
);
648 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
653 /* Performs a single LVM_HITTEST test */
654 static void test_lvm_hittest_(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
, UINT broken_flags
,
655 BOOL todo_item
, BOOL todo_flags
, int line
)
664 ret
= SendMessage(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
670 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
671 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
672 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
677 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
678 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
679 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
685 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
687 else if (broken_flags
)
688 ok_(__FILE__
, line
)(lpht
.flags
== flags
|| broken(lpht
.flags
== broken_flags
),
689 "Expected flags %x, got %x\n", flags
, lpht
.flags
);
691 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
694 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
696 /* Performs a single LVM_SUBITEMHITTEST test */
697 static void test_lvm_subitemhittest_(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
698 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
706 ret
= SendMessage(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
712 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
713 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
718 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
719 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
725 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
728 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
733 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
736 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
739 #define test_lvm_subitemhittest(a,b,c,d,e,f,g,h,i) test_lvm_subitemhittest_(a,b,c,d,e,f,g,h,i,__LINE__)
741 static void test_images(void)
749 static CHAR hello
[] = "hello";
751 himl
= ImageList_Create(40, 40, 0, 4, 4);
752 ok(himl
!= NULL
, "failed to create imagelist\n");
754 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
755 ok(hbmp
!= NULL
, "failed to create bitmap\n");
757 r
= ImageList_Add(himl
, hbmp
, 0);
758 ok(r
== 0, "should be zero\n");
760 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
761 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
762 ok(hwnd
!= NULL
, "failed to create listview window\n");
764 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
765 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
767 ok(r
== 0, "should return zero\n");
769 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
770 ok(r
== 0, "should return zero\n");
772 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
773 /* returns dimensions */
775 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
776 ok(r
== 0, "should be zero items\n");
778 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
783 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
784 ok(r
== -1, "should fail\n");
787 item
.pszText
= hello
;
788 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
789 ok(r
== 0, "should not fail\n");
791 memset(&r1
, 0, sizeof r1
);
793 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
796 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
797 ok(r
== TRUE
, "should not fail\n");
800 item
.pszText
= hello
;
801 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
802 ok(r
== 0, "should not fail\n");
804 memset(&r2
, 0, sizeof r2
);
806 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
809 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
814 static void test_checkboxes(void)
819 static CHAR text
[] = "Text",
823 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
824 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
825 ok(hwnd
!= NULL
, "failed to create listview window\n");
827 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
828 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
829 item
.stateMask
= 0xffff;
834 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
835 ok(r
== 0, "ret %d\n", r
);
838 item
.mask
= LVIF_STATE
;
839 item
.stateMask
= 0xffff;
840 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
842 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
844 /* Don't set LVIF_STATE */
845 item
.mask
= LVIF_TEXT
;
846 item
.stateMask
= 0xffff;
851 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
852 ok(r
== 1, "ret %d\n", r
);
855 item
.mask
= LVIF_STATE
;
856 item
.stateMask
= 0xffff;
857 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
859 ok(item
.state
== 0, "state %x\n", item
.state
);
861 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
862 ok(r
== 0, "should return zero\n");
864 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
866 item
.mask
= LVIF_STATE
;
867 item
.stateMask
= 0xffff;
868 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
870 if (item
.state
!= 0x1ccc)
872 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
877 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
879 item
.mask
= LVIF_TEXT
;
881 item
.pszText
= text2
;
882 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
883 ok(r
== 2, "ret %d\n", r
);
886 item
.mask
= LVIF_STATE
;
887 item
.stateMask
= 0xffff;
888 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
890 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
892 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
894 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
895 item
.stateMask
= 0xffff;
897 item
.pszText
= text3
;
898 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
899 ok(r
== 3, "ret %d\n", r
);
902 item
.mask
= LVIF_STATE
;
903 item
.stateMask
= 0xffff;
904 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
906 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
908 /* Set an item's state to checked */
910 item
.mask
= LVIF_STATE
;
911 item
.stateMask
= 0xf000;
913 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
917 item
.mask
= LVIF_STATE
;
918 item
.stateMask
= 0xffff;
919 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
921 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
923 /* Check that only the bits we asked for are returned,
924 * and that all the others are set to zero
927 item
.mask
= LVIF_STATE
;
928 item
.stateMask
= 0xf000;
930 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
932 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
934 /* Set the style again and check that doesn't change an item's state */
935 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
936 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
939 item
.mask
= LVIF_STATE
;
940 item
.stateMask
= 0xffff;
941 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
943 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
945 /* Unsetting the checkbox extended style doesn't change an item's state */
946 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
947 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
950 item
.mask
= LVIF_STATE
;
951 item
.stateMask
= 0xffff;
952 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
954 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
956 /* Now setting the style again will change an item's state */
957 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
958 ok(r
== 0, "ret %x\n", r
);
961 item
.mask
= LVIF_STATE
;
962 item
.stateMask
= 0xffff;
963 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
965 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
967 /* Toggle checkbox tests (bug 9934) */
968 memset (&item
, 0xcc, sizeof(item
));
969 item
.mask
= LVIF_STATE
;
972 item
.state
= LVIS_FOCUSED
;
973 item
.stateMask
= LVIS_FOCUSED
;
974 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
978 item
.mask
= LVIF_STATE
;
979 item
.stateMask
= 0xffff;
980 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
982 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
984 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
986 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
990 item
.mask
= LVIF_STATE
;
991 item
.stateMask
= 0xffff;
992 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
994 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
996 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
998 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1002 item
.mask
= LVIF_STATE
;
1003 item
.stateMask
= 0xffff;
1004 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1005 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1007 DestroyWindow(hwnd
);
1010 static void insert_column(HWND hwnd
, int idx
)
1015 memset(&column
, 0xcc, sizeof(column
));
1016 column
.mask
= LVCF_SUBITEM
;
1017 column
.iSubItem
= idx
;
1019 rc
= ListView_InsertColumn(hwnd
, idx
, &column
);
1023 static void insert_item(HWND hwnd
, int idx
)
1025 static CHAR text
[] = "foo";
1030 memset(&item
, 0xcc, sizeof (item
));
1031 item
.mask
= LVIF_TEXT
;
1034 item
.pszText
= text
;
1036 rc
= ListView_InsertItem(hwnd
, &item
);
1040 static void test_items(void)
1042 const LPARAM lparamTest
= 0x42;
1043 static CHAR text
[] = "Text";
1049 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1050 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1051 ok(hwnd
!= NULL
, "failed to create listview window\n");
1054 * Test setting/getting item params
1057 /* Set up two columns */
1058 insert_column(hwnd
, 0);
1059 insert_column(hwnd
, 1);
1061 /* LVIS_SELECTED with zero stateMask */
1063 memset (&item
, 0, sizeof (item
));
1064 item
.mask
= LVIF_STATE
;
1065 item
.state
= LVIS_SELECTED
;
1069 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1070 ok(r
== 0, "ret %d\n", r
);
1072 memset (&item
, 0xcc, sizeof (item
));
1073 item
.mask
= LVIF_STATE
;
1074 item
.stateMask
= LVIS_SELECTED
;
1078 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1079 ok(r
== 1, "ret %d\n", r
);
1080 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1081 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1083 /* LVIS_SELECTED with zero stateMask */
1085 memset (&item
, 0, sizeof (item
));
1086 item
.mask
= LVIF_STATE
;
1087 item
.state
= LVIS_FOCUSED
;
1091 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1092 ok(r
== 0, "ret %d\n", r
);
1094 memset (&item
, 0xcc, sizeof (item
));
1095 item
.mask
= LVIF_STATE
;
1096 item
.stateMask
= LVIS_FOCUSED
;
1100 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1101 ok(r
== 1, "ret %d\n", r
);
1102 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1103 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1105 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1107 memset (&item
, 0, sizeof (item
));
1108 item
.mask
= LVIF_STATE
;
1109 item
.state
= LVIS_CUT
;
1110 item
.stateMask
= LVIS_FOCUSED
;
1113 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1114 ok(r
== 0, "ret %d\n", r
);
1116 memset (&item
, 0xcc, sizeof (item
));
1117 item
.mask
= LVIF_STATE
;
1118 item
.stateMask
= LVIS_CUT
;
1122 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1123 ok(r
== 1, "ret %d\n", r
);
1124 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1125 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1127 /* Insert an item with just a param */
1128 memset (&item
, 0xcc, sizeof (item
));
1129 item
.mask
= LVIF_PARAM
;
1132 item
.lParam
= lparamTest
;
1133 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1134 ok(r
== 0, "ret %d\n", r
);
1136 /* Test getting of the param */
1137 memset (&item
, 0xcc, sizeof (item
));
1138 item
.mask
= LVIF_PARAM
;
1141 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1142 ok(r
== 1, "ret %d\n", r
);
1143 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1145 /* Set up a subitem */
1146 memset (&item
, 0xcc, sizeof (item
));
1147 item
.mask
= LVIF_TEXT
;
1150 item
.pszText
= text
;
1151 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1152 ok(r
== 1, "ret %d\n", r
);
1154 item
.mask
= LVIF_TEXT
;
1157 item
.pszText
= buffA
;
1158 item
.cchTextMax
= sizeof(buffA
);
1159 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1160 ok(r
== 1, "ret %d\n", r
);
1161 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got text %s, expected %s\n", item
.pszText
, text
);
1163 /* set up with extra flag */
1164 /* 1. reset subitem text */
1165 item
.mask
= LVIF_TEXT
;
1168 item
.pszText
= NULL
;
1169 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1170 ok(r
== 1, "ret %d\n", r
);
1172 item
.mask
= LVIF_TEXT
;
1175 item
.pszText
= buffA
;
1177 item
.cchTextMax
= sizeof(buffA
);
1178 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1179 ok(r
== 1, "ret %d\n", r
);
1180 ok(item
.pszText
[0] == 0, "got %p\n", item
.pszText
);
1182 /* 2. set new text with extra flag specified */
1183 item
.mask
= LVIF_TEXT
| LVIF_DI_SETITEM
;
1186 item
.pszText
= text
;
1187 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1188 ok(r
== 1 || broken(r
== 0) /* NT4 */, "ret %d\n", r
);
1192 item
.mask
= LVIF_TEXT
;
1195 item
.pszText
= buffA
;
1197 item
.cchTextMax
= sizeof(buffA
);
1198 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1199 ok(r
== 1, "ret %d\n", r
);
1200 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got %s, expected %s\n", item
.pszText
, text
);
1203 /* Query param from subitem: returns main item param */
1204 memset (&item
, 0xcc, sizeof (item
));
1205 item
.mask
= LVIF_PARAM
;
1208 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1209 ok(r
== 1, "ret %d\n", r
);
1210 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1212 /* Set up param on first subitem: no effect */
1213 memset (&item
, 0xcc, sizeof (item
));
1214 item
.mask
= LVIF_PARAM
;
1217 item
.lParam
= lparamTest
+1;
1218 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1219 ok(r
== 0, "ret %d\n", r
);
1221 /* Query param from subitem again: should still return main item param */
1222 memset (&item
, 0xcc, sizeof (item
));
1223 item
.mask
= LVIF_PARAM
;
1226 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1227 ok(r
== 1, "ret %d\n", r
);
1228 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1230 /**** Some tests of state highlighting ****/
1231 memset (&item
, 0xcc, sizeof (item
));
1232 item
.mask
= LVIF_STATE
;
1235 item
.state
= LVIS_SELECTED
;
1236 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1237 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1238 ok(r
== 1, "ret %d\n", r
);
1240 item
.state
= LVIS_DROPHILITED
;
1241 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1242 ok(r
== 1, "ret %d\n", r
);
1244 memset (&item
, 0xcc, sizeof (item
));
1245 item
.mask
= LVIF_STATE
;
1248 item
.stateMask
= -1;
1249 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1250 ok(r
== 1, "ret %d\n", r
);
1251 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1253 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1254 ok(r
== 1, "ret %d\n", r
);
1255 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1257 /* some notnull but meaningless masks */
1258 memset (&item
, 0, sizeof(item
));
1259 item
.mask
= LVIF_NORECOMPUTE
;
1262 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1263 ok(r
== 1, "ret %d\n", r
);
1264 memset (&item
, 0, sizeof(item
));
1265 item
.mask
= LVIF_DI_SETITEM
;
1268 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1269 ok(r
== 1, "ret %d\n", r
);
1271 /* set text to callback value already having it */
1272 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1274 memset (&item
, 0, sizeof (item
));
1275 item
.mask
= LVIF_TEXT
;
1276 item
.pszText
= LPSTR_TEXTCALLBACK
;
1278 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1279 ok(r
== 0, "ret %d\n", r
);
1280 memset (&item
, 0, sizeof (item
));
1282 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1284 item
.pszText
= LPSTR_TEXTCALLBACK
;
1285 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0 , (LPARAM
) &item
);
1288 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1289 "check callback text comparison rule", FALSE
);
1291 DestroyWindow(hwnd
);
1294 static void test_columns(void)
1303 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1304 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1305 ok(hwnd
!= NULL
, "failed to create listview window\n");
1307 /* Add a column with no mask */
1308 memset(&column
, 0xcc, sizeof(column
));
1310 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1311 ok(rc
== 0, "Inserting column with no mask failed with %d\n", rc
);
1313 /* Check its width */
1314 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
1315 ok(rc
== 10 || broken(rc
== 0) /* win9x */,
1316 "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1318 DestroyWindow(hwnd
);
1320 /* LVM_GETCOLUMNORDERARRAY */
1321 hwnd
= create_listview_control(LVS_REPORT
);
1322 subclass_header(hwnd
);
1324 memset(&column
, 0, sizeof(column
));
1325 column
.mask
= LVCF_WIDTH
;
1327 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1328 ok(rc
== 0, "Inserting column failed with %d\n", rc
);
1331 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&column
);
1332 ok(rc
== 1, "Inserting column failed with %d\n", rc
);
1334 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1336 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1337 ok(rc
== 1, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1338 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1339 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1341 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1343 /* after column added subitem is considered as present */
1344 insert_item(hwnd
, 0);
1346 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1348 item
.pszText
= buff
;
1349 item
.cchTextMax
= sizeof(buff
);
1352 item
.mask
= LVIF_TEXT
;
1353 memset(&g_itema
, 0, sizeof(g_itema
));
1354 rc
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
1355 ok(rc
== 1, "got %d\n", rc
);
1356 ok(g_itema
.iSubItem
== 1, "got %d\n", g_itema
.iSubItem
);
1358 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
1359 "get subitem text after column added", FALSE
);
1361 DestroyWindow(hwnd
);
1364 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1365 static WNDPROC listviewWndProc
;
1366 static HIMAGELIST test_create_imagelist
;
1368 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1372 if (uMsg
== WM_CREATE
)
1374 LPCREATESTRUCT lpcs
= (LPCREATESTRUCT
)lParam
;
1375 lpcs
->style
|= LVS_REPORT
;
1377 ret
= CallWindowProc(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1378 if (uMsg
== WM_CREATE
) SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1382 static void test_create(void)
1393 cls
.cbSize
= sizeof(WNDCLASSEX
);
1394 ok(GetClassInfoEx(GetModuleHandle(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1395 listviewWndProc
= cls
.lpfnWndProc
;
1396 cls
.lpfnWndProc
= create_test_wndproc
;
1397 cls
.lpszClassName
= "MyListView32";
1398 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
1400 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1401 hList
= CreateWindow("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1402 ok((HIMAGELIST
)SendMessage(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1403 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1405 if (!IsWindow(hHeader
))
1408 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1409 DestroyWindow(hList
);
1413 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1414 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1415 DestroyWindow(hList
);
1417 /* header isn't created on LVS_ICON and LVS_LIST styles */
1418 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1419 GetModuleHandle(NULL
), 0);
1420 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1421 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1422 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1424 memset(&col
, 0, sizeof(LVCOLUMNA
));
1425 col
.mask
= LVCF_WIDTH
;
1427 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1428 ok(r
== 0, "Expected 0 column's inserted\n");
1429 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1430 ok(IsWindow(hHeader
), "Header should be created\n");
1431 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1432 style
= GetWindowLong(hHeader
, GWL_STYLE
);
1433 ok(!(style
& HDS_HIDDEN
), "Not expected HDS_HIDDEN\n");
1434 DestroyWindow(hList
);
1436 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1437 GetModuleHandle(NULL
), 0);
1438 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1439 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1440 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1442 memset(&col
, 0, sizeof(LVCOLUMNA
));
1443 col
.mask
= LVCF_WIDTH
;
1445 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1446 ok(r
== 0, "Expected 0 column's inserted\n");
1447 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1448 ok(IsWindow(hHeader
), "Header should be created\n");
1449 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1450 DestroyWindow(hList
);
1452 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1453 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1454 GetModuleHandle(NULL
), 0);
1455 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLongPtr(hList
, GWL_STYLE
) | LVS_REPORT
);
1456 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1457 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1458 ok(IsWindow(hHeader
), "Header should be created\n");
1459 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLong(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1460 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1461 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1462 ok(IsWindow(hHeader
), "Header should be created\n");
1463 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1464 DestroyWindow(hList
);
1466 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1467 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1468 GetModuleHandle(NULL
), 0);
1469 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1470 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1471 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1472 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1473 ok(IsWindow(hHeader
), "Header should be created\n");
1474 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1475 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1476 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1477 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1478 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1479 ok(IsWindow(hHeader
), "Header should be created\n");
1480 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1481 DestroyWindow(hList
);
1483 /* LVS_REPORT without WS_VISIBLE */
1484 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1485 GetModuleHandle(NULL
), 0);
1486 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1487 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1488 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1490 memset(&col
, 0, sizeof(LVCOLUMNA
));
1491 col
.mask
= LVCF_WIDTH
;
1493 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1494 ok(r
== 0, "Expected 0 column's inserted\n");
1495 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1496 ok(IsWindow(hHeader
), "Header should be created\n");
1497 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1498 DestroyWindow(hList
);
1500 /* LVS_REPORT without WS_VISIBLE, try to show it */
1501 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1502 GetModuleHandle(NULL
), 0);
1503 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1504 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1505 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1506 ShowWindow(hList
, SW_SHOW
);
1507 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1508 ok(IsWindow(hHeader
), "Header should be created\n");
1509 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1510 DestroyWindow(hList
);
1512 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1513 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1514 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1515 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1516 ok(IsWindow(hHeader
), "Header should be created\n");
1517 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1518 /* HDS_DRAGDROP set by default */
1519 ok(GetWindowLongPtr(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1520 DestroyWindow(hList
);
1522 /* setting LVS_EX_HEADERDRAGDROP creates header */
1523 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1524 GetModuleHandle(NULL
), 0);
1525 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1526 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1527 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1528 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1529 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1530 ok(IsWindow(hHeader
) ||
1531 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1532 "Header should be created\n");
1533 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1534 DestroyWindow(hList
);
1536 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1537 hList
= create_listview_control(LVS_ICON
);
1538 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1539 r
= SendMessage(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1540 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1541 DestroyWindow(hList
);
1543 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1544 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1545 GetModuleHandle(NULL
), 0);
1546 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1547 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1549 rect
.left
= LVIR_BOUNDS
;
1551 rect
.right
= rect
.bottom
= -10;
1552 r
= SendMessage(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1553 ok(r
== 1, "Expected not-null LRESULT\n");
1555 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1556 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1557 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1559 DestroyWindow(hList
);
1561 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1562 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1563 hList
= create_listview_control(LVS_OWNERDRAWFIXED
| LVS_REPORT
);
1564 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1565 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1566 DestroyWindow(hList
);
1569 static void test_redraw(void)
1576 hwnd
= create_listview_control(LVS_REPORT
);
1577 subclass_header(hwnd
);
1579 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1581 InvalidateRect(hwnd
, NULL
, TRUE
);
1583 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1585 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1587 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1588 /* 1. Without backbuffer */
1589 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1592 hdc
= GetWindowDC(hwndparent
);
1594 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1595 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1596 ok(r
== 1, "Expected not zero result\n");
1597 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1598 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1600 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1603 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1604 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1605 ok(r
== 1, "Expected not zero result\n");
1606 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1607 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1609 /* 2. With backbuffer */
1610 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1611 LVS_EX_DOUBLEBUFFER
);
1612 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1615 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1616 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1617 ok(r
== 1, "Expected not zero result\n");
1618 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1619 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1621 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1624 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1625 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1626 todo_wine
ok(r
== 1, "Expected not zero result\n");
1627 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1628 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1630 ReleaseDC(hwndparent
, hdc
);
1632 DestroyWindow(hwnd
);
1635 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1637 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1639 if(msg
== WM_NOTIFY
) {
1640 NMHDR
*nmhdr
= (PVOID
)lp
;
1641 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1642 NMLVCUSTOMDRAW
*nmlvcd
= (PVOID
)nmhdr
;
1643 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd
->nmcd
.dwDrawStage
);
1644 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1646 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1647 return CDRF_NOTIFYITEMDRAW
;
1648 case CDDS_ITEMPREPAINT
:
1649 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1650 return CDRF_NOTIFYSUBITEMDRAW
;
1651 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1652 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1653 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1654 return CDRF_NOTIFYPOSTPAINT
;
1655 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1656 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1657 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1658 return CDRF_DODEFAULT
;
1660 return CDRF_DODEFAULT
;
1664 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1667 static void test_customdraw(void)
1672 hwnd
= create_listview_control(LVS_REPORT
);
1674 insert_column(hwnd
, 0);
1675 insert_column(hwnd
, 1);
1676 insert_item(hwnd
, 0);
1678 oldwndproc
= (WNDPROC
)SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
,
1679 (LONG_PTR
)cd_wndproc
);
1681 InvalidateRect(hwnd
, NULL
, TRUE
);
1684 SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1686 DestroyWindow(hwnd
);
1689 static void test_icon_spacing(void)
1691 /* LVM_SETICONSPACING */
1692 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1698 hwnd
= create_listview_control(LVS_ICON
);
1699 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1701 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, NF_REQUERY
);
1702 expect(NFR_ANSI
, r
);
1704 /* reset the icon spacing to defaults */
1705 SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1707 /* now we can request what the defaults are */
1708 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1712 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1714 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1715 ok(r
== MAKELONG(w
, h
) ||
1716 broken(r
== MAKELONG(w
, w
)), /* win98 */
1717 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1719 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1723 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1724 DestroyWindow(hwnd
);
1727 expect(MAKELONG(20,30), r
);
1729 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1730 expect(MAKELONG(25,35), r
);
1732 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1734 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1735 DestroyWindow(hwnd
);
1738 static void test_color(void)
1740 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1747 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1749 hwnd
= create_listview_control(LVS_REPORT
);
1750 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1752 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1754 for (i
= 0; i
< 4; i
++)
1758 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1760 r
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, color
);
1763 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1765 r
= SendMessage(hwnd
, LVM_GETTEXTCOLOR
, 0, color
);
1768 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1770 r
= SendMessage(hwnd
, LVM_GETTEXTBKCOLOR
, 0, color
);
1774 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1776 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1777 DestroyWindow(hwnd
);
1780 static void test_item_count(void)
1782 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1795 static CHAR item0text
[] = "item0";
1796 static CHAR item1text
[] = "item1";
1797 static CHAR item2text
[] = "item2";
1799 hwnd
= create_listview_control(LVS_REPORT
);
1800 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1802 /* resize in dpiaware manner to fit all 3 items added */
1804 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1805 GetTextMetricsA(hdc
, &tm
);
1806 /* 2 extra pixels for bounds and header border */
1807 height
= tm
.tmHeight
+ 2;
1808 SelectObject(hdc
, hOldFont
);
1811 GetWindowRect(hwnd
, &rect
);
1812 /* 3 items + 1 header + 1 to be sure */
1813 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1815 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1817 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1821 item0
.mask
= LVIF_TEXT
;
1824 item0
.pszText
= item0text
;
1825 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1828 /* [item0, item1] */
1829 item1
.mask
= LVIF_TEXT
;
1832 item1
.pszText
= item1text
;
1833 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1836 /* [item0, item1, item2] */
1837 item2
.mask
= LVIF_TEXT
;
1840 item2
.pszText
= item2text
;
1841 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1844 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1847 /* [item0, item1] */
1848 r
= SendMessage(hwnd
, LVM_DELETEITEM
, 2, 0);
1851 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1855 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1858 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1862 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1865 /* [item0, item1] */
1866 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1869 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1872 /* [item0, item1, item2] */
1873 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1876 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1879 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
1881 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1882 DestroyWindow(hwnd
);
1885 static void test_item_position(void)
1887 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1896 static CHAR item0text
[] = "item0";
1897 static CHAR item1text
[] = "item1";
1898 static CHAR item2text
[] = "item2";
1900 hwnd
= create_listview_control(LVS_ICON
);
1901 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1903 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1906 item0
.mask
= LVIF_TEXT
;
1909 item0
.pszText
= item0text
;
1910 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1913 /* [item0, item1] */
1914 item1
.mask
= LVIF_TEXT
;
1917 item1
.pszText
= item1text
;
1918 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1921 /* [item0, item1, item2] */
1922 item2
.mask
= LVIF_TEXT
;
1925 item2
.pszText
= item2text
;
1926 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1929 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
1931 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
1933 expect2(10, 5, position
.x
, position
.y
);
1935 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
1937 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
1939 expect2(0, 0, position
.x
, position
.y
);
1941 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
1943 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
1945 expect2(20, 20, position
.x
, position
.y
);
1947 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
1949 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1950 DestroyWindow(hwnd
);
1953 static void test_getorigin(void)
1961 position
.x
= position
.y
= 0;
1963 hwnd
= create_listview_control(LVS_ICON
);
1964 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1965 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1967 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1969 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1970 DestroyWindow(hwnd
);
1972 hwnd
= create_listview_control(LVS_SMALLICON
);
1973 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1974 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1976 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1978 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1979 DestroyWindow(hwnd
);
1981 hwnd
= create_listview_control(LVS_LIST
);
1982 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1983 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1985 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1987 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1988 DestroyWindow(hwnd
);
1990 hwnd
= create_listview_control(LVS_REPORT
);
1991 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1992 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1994 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1996 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1997 DestroyWindow(hwnd
);
2000 static void test_multiselect(void)
2002 typedef struct t_select_task
2013 int i
,j
,item_count
,selected_count
;
2014 static const int items
=5;
2020 static struct t_select_task task_list
[] = {
2021 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
2022 { "using VK_UP", -1, VK_UP
, -1, -1 },
2023 { "using VK_END", 0, VK_END
, 1, -1 },
2024 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
2028 hwnd
= create_listview_control(LVS_REPORT
);
2030 for (i
=0;i
<items
;i
++) {
2031 insert_item(hwnd
, 0);
2034 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2036 expect(items
,item_count
);
2039 task
= task_list
[i
];
2041 /* deselect all items */
2042 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
2043 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2045 /* set initial position */
2046 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
2047 ListView_SetItemState(hwnd
,(task
.initPos
== -1 ? item_count
-1 : task
.initPos
),LVIS_SELECTED
,LVIS_SELECTED
);
2049 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2051 ok(selected_count
== 1, "There should be only one selected item at the beginning (is %d)\n",selected_count
);
2053 /* Set SHIFT key pressed */
2054 GetKeyboardState(kstate
);
2055 kstate
[VK_SHIFT
]=0x80;
2056 SetKeyboardState(kstate
);
2058 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
2059 r
= SendMessage(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
2061 r
= SendMessage(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
2065 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2067 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
);
2069 /* Set SHIFT key released */
2070 GetKeyboardState(kstate
);
2071 kstate
[VK_SHIFT
]=0x00;
2072 SetKeyboardState(kstate
);
2074 DestroyWindow(hwnd
);
2076 /* make multiple selection, then switch to LVS_SINGLESEL */
2077 hwnd
= create_listview_control(LVS_REPORT
);
2078 for (i
=0;i
<items
;i
++) {
2079 insert_item(hwnd
, 0);
2081 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2082 expect(items
,item_count
);
2084 /* try with NULL pointer */
2085 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, 0);
2088 /* select all, check notifications */
2089 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
2091 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2093 item
.stateMask
= LVIS_SELECTED
;
2094 item
.state
= LVIS_SELECTED
;
2095 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2098 ok_sequence(sequences
, PARENT_SEQ_INDEX
, select_all_parent_seq
,
2099 "select all notification", FALSE
);
2101 /* deselect all items */
2102 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
2103 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2105 ListView_SetItemState(hwnd
, i
, LVIS_SELECTED
, LVIS_SELECTED
);
2108 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2110 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2113 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2114 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2115 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2116 /* check that style is accepted */
2117 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2118 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2121 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2122 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2124 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2126 SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2129 /* select one more */
2130 ListView_SetItemState(hwnd
, 3, LVIS_SELECTED
, LVIS_SELECTED
);
2133 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2134 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2136 r
= ListView_GetItemState(hwnd
, 3, LVIS_SELECTED
);
2137 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2139 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2141 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2144 /* try to select all on LVS_SINGLESEL */
2145 memset(&item
, 0, sizeof(item
));
2146 item
.stateMask
= LVIS_SELECTED
;
2147 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2149 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2151 item
.stateMask
= LVIS_SELECTED
;
2152 item
.state
= LVIS_SELECTED
;
2153 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2156 r
= ListView_GetSelectedCount(hwnd
);
2158 r
= ListView_GetSelectionMark(hwnd
);
2161 /* try to deselect all on LVS_SINGLESEL */
2162 item
.stateMask
= LVIS_SELECTED
;
2163 item
.state
= LVIS_SELECTED
;
2164 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2167 item
.stateMask
= LVIS_SELECTED
;
2169 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2171 r
= ListView_GetSelectedCount(hwnd
);
2174 DestroyWindow(hwnd
);
2177 static void test_subitem_rect(void)
2185 /* test LVM_GETSUBITEMRECT for header */
2186 hwnd
= create_listview_control(LVS_REPORT
);
2187 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2188 /* add some columns */
2189 memset(&col
, 0, sizeof(LVCOLUMN
));
2190 col
.mask
= LVCF_WIDTH
;
2192 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2195 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2198 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2200 /* item = -1 means header, subitem index is 1 based */
2201 rect
.left
= LVIR_BOUNDS
;
2203 rect
.right
= rect
.bottom
= 0;
2204 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2207 rect
.left
= LVIR_BOUNDS
;
2209 rect
.right
= rect
.bottom
= 0;
2210 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2212 ok(r
== 1, "Expected not-null LRESULT\n");
2213 expect(100, rect
.left
);
2214 expect(250, rect
.right
);
2216 expect(3, rect
.top
);
2218 rect
.left
= LVIR_BOUNDS
;
2220 rect
.right
= rect
.bottom
= 0;
2221 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2223 ok(r
== 1, "Expected not-null LRESULT\n");
2224 expect(250, rect
.left
);
2225 expect(450, rect
.right
);
2227 expect(3, rect
.top
);
2229 /* item LVS_REPORT padding isn't applied to subitems */
2230 insert_item(hwnd
, 0);
2232 rect
.left
= LVIR_BOUNDS
;
2234 rect
.right
= rect
.bottom
= 0;
2235 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2236 ok(r
== 1, "Expected not-null LRESULT\n");
2237 expect(100, rect
.left
);
2238 expect(250, rect
.right
);
2240 rect
.left
= LVIR_ICON
;
2242 rect
.right
= rect
.bottom
= 0;
2243 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2244 ok(r
== 1, "Expected not-null LRESULT\n");
2245 /* no icon attached - zero width rectangle, with no left padding */
2246 expect(100, rect
.left
);
2247 expect(100, rect
.right
);
2249 rect
.left
= LVIR_LABEL
;
2251 rect
.right
= rect
.bottom
= 0;
2252 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2253 ok(r
== 1, "Expected not-null LRESULT\n");
2254 /* same as full LVIR_BOUNDS */
2255 expect(100, rect
.left
);
2256 expect(250, rect
.right
);
2258 SendMessage(hwnd
, LVM_SCROLL
, 10, 0);
2260 rect
.left
= LVIR_BOUNDS
;
2262 rect
.right
= rect
.bottom
= 0;
2263 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2264 ok(r
== 1, "Expected not-null LRESULT\n");
2265 expect(90, rect
.left
);
2266 expect(240, rect
.right
);
2268 SendMessage(hwnd
, LVM_SCROLL
, -10, 0);
2270 DestroyWindow(hwnd
);
2272 /* test subitem rects after re-arranging columns */
2273 hwnd
= create_listview_control(LVS_REPORT
);
2274 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2275 memset(&col
, 0, sizeof(LVCOLUMN
));
2276 col
.mask
= LVCF_WIDTH
;
2279 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2283 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2287 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2290 insert_item(hwnd
, 0);
2291 insert_item(hwnd
, 1);
2293 /* wrong item is refused for main item */
2294 rect
.left
= LVIR_BOUNDS
;
2296 rect
.right
= rect
.bottom
= -1;
2297 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect
);
2298 ok(r
== FALSE
, "got %d\n", r
);
2300 /* for subitems rectangle is calculated even if there's no item added */
2301 rect
.left
= LVIR_BOUNDS
;
2303 rect
.right
= rect
.bottom
= -1;
2304 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect
);
2305 ok(r
== TRUE
, "got %d\n", r
);
2307 rect2
.left
= LVIR_BOUNDS
;
2309 rect2
.right
= rect2
.bottom
= -1;
2310 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect2
);
2312 ok(r
== TRUE
, "got %d\n", r
);
2313 expect(rect
.right
, rect2
.right
);
2314 expect(rect
.left
, rect2
.left
);
2315 expect(rect
.bottom
, rect2
.top
);
2316 ok(rect2
.bottom
> rect2
.top
, "expected not zero height\n");
2319 arr
[0] = 1; arr
[1] = 0; arr
[2] = 2;
2320 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 3, (LPARAM
)arr
);
2323 rect
.left
= LVIR_BOUNDS
;
2325 rect
.right
= rect
.bottom
= -1;
2326 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2327 ok(r
== TRUE
, "got %d\n", r
);
2328 expect(0, rect
.left
);
2329 expect(600, rect
.right
);
2331 rect
.left
= LVIR_BOUNDS
;
2333 rect
.right
= rect
.bottom
= -1;
2334 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2335 ok(r
== TRUE
, "got %d\n", r
);
2336 expect(0, rect
.left
);
2337 expect(200, rect
.right
);
2339 rect2
.left
= LVIR_BOUNDS
;
2341 rect2
.right
= rect2
.bottom
= -1;
2342 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect2
);
2343 ok(r
== TRUE
, "got %d\n", r
);
2344 expect(0, rect2
.left
);
2345 expect(200, rect2
.right
);
2346 /* items are of the same height */
2347 ok(rect2
.top
> 0, "expected positive item height\n");
2348 expect(rect
.bottom
, rect2
.top
);
2349 expect(rect
.bottom
* 2 - rect
.top
, rect2
.bottom
);
2351 rect
.left
= LVIR_BOUNDS
;
2353 rect
.right
= rect
.bottom
= -1;
2354 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2355 ok(r
== TRUE
, "got %d\n", r
);
2356 expect(300, rect
.left
);
2357 expect(600, rect
.right
);
2359 DestroyWindow(hwnd
);
2361 /* try it for non LVS_REPORT style */
2362 hwnd
= CreateWindow("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2363 GetModuleHandle(NULL
), 0);
2364 rect
.left
= LVIR_BOUNDS
;
2366 rect
.right
= rect
.bottom
= -10;
2367 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2368 ok(r
== 0, "Expected not-null LRESULT\n");
2369 /* rect is unchanged */
2370 expect(0, rect
.left
);
2371 expect(-10, rect
.right
);
2372 expect(1, rect
.top
);
2373 expect(-10, rect
.bottom
);
2374 DestroyWindow(hwnd
);
2377 /* comparison callback for test_sorting */
2378 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2380 if (first
== second
) return 0;
2381 return (first
> second
? 1 : -1);
2384 static void test_sorting(void)
2390 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2393 hwnd
= create_listview_control(LVS_REPORT
);
2394 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2396 /* insert some items */
2397 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2398 item
.state
= LVIS_SELECTED
;
2402 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2405 item
.mask
= LVIF_PARAM
;
2409 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2412 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2413 item
.state
= LVIS_SELECTED
;
2417 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2420 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2423 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2426 r
= SendMessage(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2429 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2431 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2433 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2435 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2436 expect(LVIS_SELECTED
, r
);
2437 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2438 expect(LVIS_SELECTED
, r
);
2440 DestroyWindow(hwnd
);
2442 /* switch to LVS_SORTASCENDING when some items added */
2443 hwnd
= create_listview_control(LVS_REPORT
);
2444 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2446 item
.mask
= LVIF_TEXT
;
2449 item
.pszText
= names
[1];
2450 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2453 item
.mask
= LVIF_TEXT
;
2456 item
.pszText
= names
[2];
2457 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2460 item
.mask
= LVIF_TEXT
;
2463 item
.pszText
= names
[0];
2464 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2467 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2468 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2469 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2470 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2472 /* no sorting performed when switched to LVS_SORTASCENDING */
2473 item
.mask
= LVIF_TEXT
;
2475 item
.pszText
= buff
;
2476 item
.cchTextMax
= sizeof(buff
);
2477 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2479 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2482 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2484 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2487 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2489 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2491 /* adding new item doesn't resort list */
2492 item
.mask
= LVIF_TEXT
;
2495 item
.pszText
= names
[3];
2496 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2499 item
.mask
= LVIF_TEXT
;
2501 item
.pszText
= buff
;
2502 item
.cchTextMax
= sizeof(buff
);
2503 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2505 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2508 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2510 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2513 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2515 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2518 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2520 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2522 /* corner case - item should be placed at first position */
2523 item
.mask
= LVIF_TEXT
;
2526 item
.pszText
= names
[4];
2527 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2531 item
.pszText
= buff
;
2532 item
.cchTextMax
= sizeof(buff
);
2533 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2535 ok(lstrcmp(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2538 item
.pszText
= buff
;
2539 item
.cchTextMax
= sizeof(buff
);
2540 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2542 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2545 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2547 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2550 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2552 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2555 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2557 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2559 DestroyWindow(hwnd
);
2562 static void test_ownerdata(void)
2565 LONG_PTR style
, ret
;
2569 /* it isn't possible to set LVS_OWNERDATA after creation */
2572 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2576 hwnd
= create_listview_control(LVS_REPORT
);
2577 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2578 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2579 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2581 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2583 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2584 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2585 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2586 "try to switch to LVS_OWNERDATA seq", FALSE
);
2588 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2589 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2590 DestroyWindow(hwnd
);
2593 /* try to set LVS_OWNERDATA after creation just having it */
2594 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2595 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2596 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2597 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2599 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2601 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2602 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2603 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2604 "try to switch to LVS_OWNERDATA seq", FALSE
);
2605 DestroyWindow(hwnd
);
2607 /* try to remove LVS_OWNERDATA after creation just having it */
2610 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2614 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2615 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2616 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2617 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2619 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2621 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2622 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2623 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2624 "try to switch to LVS_OWNERDATA seq", FALSE
);
2625 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2626 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2627 DestroyWindow(hwnd
);
2630 /* try select an item */
2631 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2632 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2633 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2634 ok(res
== 1, "Expected LVM_SETITEMCOUNT to succeed\n");
2635 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2637 memset(&item
, 0, sizeof(item
));
2638 item
.stateMask
= LVIS_SELECTED
;
2639 item
.state
= LVIS_SELECTED
;
2640 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2642 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2644 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2646 DestroyWindow(hwnd
);
2648 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2649 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2650 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2651 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2652 ok(res
== 1, "Expected LVM_SETITEMCOUNT to succeed\n");
2653 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2655 memset(&item
, 0, sizeof(item
));
2656 item
.mask
= LVIF_STATE
;
2658 item
.stateMask
= LVIS_SELECTED
;
2659 item
.state
= LVIS_SELECTED
;
2660 res
= SendMessageA(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2662 DestroyWindow(hwnd
);
2664 /* check notifications after focused/selected changed */
2665 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2666 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2667 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
2668 ok(res
== 1, "Expected LVM_SETITEMCOUNT to succeed\n");
2670 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2672 memset(&item
, 0, sizeof(item
));
2673 item
.stateMask
= LVIS_SELECTED
;
2674 item
.state
= LVIS_SELECTED
;
2675 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2678 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2679 "ownerdata select notification", TRUE
);
2681 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2683 memset(&item
, 0, sizeof(item
));
2684 item
.stateMask
= LVIS_FOCUSED
;
2685 item
.state
= LVIS_FOCUSED
;
2686 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2689 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2690 "ownerdata focus notification", TRUE
);
2692 /* select all, check notifications */
2693 item
.stateMask
= LVIS_SELECTED
;
2695 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2698 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2700 item
.stateMask
= LVIS_SELECTED
;
2701 item
.state
= LVIS_SELECTED
;
2703 g_dump_itemchanged
= TRUE
;
2704 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2706 g_dump_itemchanged
= FALSE
;
2708 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2709 "ownerdata select all notification", TRUE
);
2711 /* select all again, note that all items are selected already */
2712 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2713 item
.stateMask
= LVIS_SELECTED
;
2714 item
.state
= LVIS_SELECTED
;
2715 g_dump_itemchanged
= TRUE
;
2716 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2718 g_dump_itemchanged
= FALSE
;
2719 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2720 "ownerdata select all notification", TRUE
);
2722 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2723 item
.stateMask
= LVIS_SELECTED
;
2725 g_dump_itemchanged
= TRUE
;
2726 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2728 g_dump_itemchanged
= FALSE
;
2729 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2730 "ownerdata deselect all notification", TRUE
);
2732 /* select one, then deselect all */
2733 item
.stateMask
= LVIS_SELECTED
;
2734 item
.state
= LVIS_SELECTED
;
2735 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2737 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2738 item
.stateMask
= LVIS_SELECTED
;
2740 g_dump_itemchanged
= TRUE
;
2741 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2743 g_dump_itemchanged
= FALSE
;
2744 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2745 "ownerdata select all notification", TRUE
);
2747 /* remove focused, try to focus all */
2748 item
.stateMask
= LVIS_FOCUSED
;
2749 item
.state
= LVIS_FOCUSED
;
2750 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2752 item
.stateMask
= LVIS_FOCUSED
;
2754 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2756 item
.stateMask
= LVIS_FOCUSED
;
2757 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
2759 /* setting all to focused returns failure value */
2760 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2761 item
.stateMask
= LVIS_FOCUSED
;
2762 item
.state
= LVIS_FOCUSED
;
2763 g_dump_itemchanged
= TRUE
;
2764 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2766 g_dump_itemchanged
= FALSE
;
2767 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2768 "ownerdata focus all notification", FALSE
);
2769 /* focus single item, remove all */
2770 item
.stateMask
= LVIS_FOCUSED
;
2771 item
.state
= LVIS_FOCUSED
;
2772 res
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2774 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2775 item
.stateMask
= LVIS_FOCUSED
;
2777 g_dump_itemchanged
= TRUE
;
2778 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2780 g_dump_itemchanged
= FALSE
;
2781 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
2782 "ownerdata remove focus all notification", TRUE
);
2784 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2785 item
.stateMask
= LVIS_CUT
;
2786 item
.state
= LVIS_CUT
;
2787 g_dump_itemchanged
= TRUE
;
2788 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2790 g_dump_itemchanged
= FALSE
;
2791 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2792 "ownerdata cut all notification", TRUE
);
2793 /* all marked cut, try again */
2794 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2795 item
.stateMask
= LVIS_CUT
;
2796 item
.state
= LVIS_CUT
;
2797 g_dump_itemchanged
= TRUE
;
2798 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2800 g_dump_itemchanged
= FALSE
;
2801 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2802 "ownerdata cut all notification #2", TRUE
);
2804 DestroyWindow(hwnd
);
2806 /* check notifications on LVM_GETITEM */
2807 /* zero callback mask */
2808 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2809 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2810 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2811 ok(res
== 1, "Expected LVM_SETITEMCOUNT to succeed\n");
2813 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2815 memset(&item
, 0, sizeof(item
));
2816 item
.stateMask
= LVIS_SELECTED
;
2817 item
.mask
= LVIF_STATE
;
2818 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2821 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2822 "ownerdata getitem selected state 1", FALSE
);
2824 /* non zero callback mask but not we asking for */
2825 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
2828 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2830 memset(&item
, 0, sizeof(item
));
2831 item
.stateMask
= LVIS_SELECTED
;
2832 item
.mask
= LVIF_STATE
;
2833 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2836 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2837 "ownerdata getitem selected state 2", FALSE
);
2839 /* LVIS_OVERLAYMASK callback mask, asking for index */
2840 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2842 memset(&item
, 0, sizeof(item
));
2843 item
.stateMask
= LVIS_OVERLAYMASK
;
2844 item
.mask
= LVIF_STATE
;
2845 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2848 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
2849 "ownerdata getitem selected state 2", FALSE
);
2851 DestroyWindow(hwnd
);
2853 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2854 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
| LVS_REPORT
);
2855 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2856 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2857 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2858 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2859 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
2860 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2861 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
2862 DestroyWindow(hwnd
);
2863 /* apparently it's allowed to switch these style on after creation */
2864 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2865 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2866 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2867 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2868 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2869 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2870 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2871 DestroyWindow(hwnd
);
2873 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2874 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2875 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2876 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2877 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
2878 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2879 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
2880 DestroyWindow(hwnd
);
2883 static void test_norecompute(void)
2885 static CHAR testA
[] = "test";
2891 /* self containing control */
2892 hwnd
= create_listview_control(LVS_REPORT
);
2893 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2894 memset(&item
, 0, sizeof(item
));
2895 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
2897 item
.stateMask
= LVIS_SELECTED
;
2898 item
.state
= LVIS_SELECTED
;
2899 item
.pszText
= testA
;
2900 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2902 /* retrieve with LVIF_NORECOMPUTE */
2903 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2905 item
.pszText
= buff
;
2906 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2907 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2909 ok(lstrcmp(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
2911 item
.mask
= LVIF_TEXT
;
2913 item
.pszText
= LPSTR_TEXTCALLBACK
;
2914 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2917 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2919 item
.pszText
= buff
;
2920 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2922 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2923 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2925 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2926 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2927 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
2929 DestroyWindow(hwnd
);
2932 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2933 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2935 item
.mask
= LVIF_STATE
;
2936 item
.stateMask
= LVIS_SELECTED
;
2937 item
.state
= LVIS_SELECTED
;
2939 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2942 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2944 item
.pszText
= buff
;
2945 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2946 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2947 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2949 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2950 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2951 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
2953 DestroyWindow(hwnd
);
2956 static void test_nosortheader(void)
2961 hwnd
= create_listview_control(LVS_REPORT
);
2962 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2964 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2965 ok(IsWindow(header
), "header expected\n");
2967 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2968 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
2970 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2971 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
2972 /* HDS_BUTTONS retained */
2973 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2974 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
2976 DestroyWindow(hwnd
);
2978 /* create with LVS_NOSORTHEADER */
2979 hwnd
= create_listview_control(LVS_NOSORTHEADER
| LVS_REPORT
);
2980 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2982 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2983 ok(IsWindow(header
), "header expected\n");
2985 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2986 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2988 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2989 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
2990 /* not changed here */
2991 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2992 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2994 DestroyWindow(hwnd
);
2997 static void test_setredraw(void)
3005 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3006 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3008 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3009 ListView seems to handle it internally without DefWinProc */
3011 /* default value first */
3012 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3015 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3016 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3017 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3019 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3020 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3021 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3024 /* check update rect after redrawing */
3025 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3027 InvalidateRect(hwnd
, NULL
, FALSE
);
3028 RedrawWindow(hwnd
, NULL
, NULL
, RDW_UPDATENOW
);
3029 rect
.right
= rect
.bottom
= 1;
3030 GetUpdateRect(hwnd
, &rect
, FALSE
);
3031 expect(0, rect
.right
);
3032 expect(0, rect
.bottom
);
3035 hdc
= GetWindowDC(hwndparent
);
3036 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3038 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3040 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3042 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3044 ReleaseDC(hwndparent
, hdc
);
3046 /* check notification messages to show that repainting is disabled */
3047 ret
= SendMessage(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3049 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3051 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3053 InvalidateRect(hwnd
, NULL
, TRUE
);
3055 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3056 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
3058 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
3060 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3061 InvalidateRect(hwnd
, NULL
, TRUE
);
3063 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3064 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
3066 /* message isn't forwarded to header */
3067 subclass_header(hwnd
);
3068 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3069 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3071 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
3072 "WM_SETREDRAW: not forwarded to header", FALSE
);
3074 DestroyWindow(hwnd
);
3077 static void test_hittest(void)
3083 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3087 HIMAGELIST himl
, himl2
;
3090 hwnd
= create_listview_control(LVS_REPORT
);
3091 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3093 /* LVS_REPORT with a single subitem (2 columns) */
3094 insert_column(hwnd
, 0);
3095 insert_column(hwnd
, 1);
3096 insert_item(hwnd
, 0);
3099 /* the only purpose of that line is to be as long as a half item rect */
3100 item
.pszText
= text
;
3101 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
3104 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3106 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3109 memset(&bounds
, 0, sizeof(bounds
));
3110 bounds
.left
= LVIR_BOUNDS
;
3111 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
3113 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
3114 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
3115 r
= SendMessage(hwnd
, LVM_GETITEMSPACING
, TRUE
, 0);
3117 ok(bounds
.bottom
- bounds
.top
== vert
,
3118 "Vertical spacing inconsistent (%d != %d)\n", bounds
.bottom
- bounds
.top
, vert
);
3119 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
3122 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3124 /* outside columns by x position - valid is [0, 199] */
3126 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3127 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TOLEFT
, 0, FALSE
, FALSE
);
3128 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3130 x
= pos
.x
+ 50; /* column half width */
3131 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3132 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, 0, FALSE
, FALSE
);
3133 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3134 x
= pos
.x
+ 150; /* outside column */
3135 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3136 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3137 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3138 y
= (bounds
.bottom
- bounds
.top
) / 2;
3139 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3140 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3141 /* outside possible client rectangle (to right) */
3143 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3144 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3145 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3146 y
= (bounds
.bottom
- bounds
.top
) / 2;
3147 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3148 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3149 /* subitem returned with -1 item too */
3151 y
= bounds
.top
- vert
;
3152 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3153 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3154 /* return values appear to underflow with negative indices */
3158 test_lvm_subitemhittest(hwnd
, x
, y
, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3159 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3163 /* parent client area is 100x100 by default */
3164 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
3165 x
= pos
.x
+ 150; /* outside column */
3166 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3167 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, FALSE
);
3168 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3169 y
= (bounds
.bottom
- bounds
.top
) / 2;
3170 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, TRUE
);
3171 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3172 /* the same with LVS_EX_FULLROWSELECT */
3173 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3174 x
= pos
.x
+ 150; /* outside column */
3175 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3176 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, LVHT_ONITEMLABEL
, FALSE
, FALSE
);
3177 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3178 y
= (bounds
.bottom
- bounds
.top
) / 2;
3179 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3180 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
3181 x
= pos
.x
+ 150; /* outside column */
3182 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3183 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3184 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3185 y
= (bounds
.bottom
- bounds
.top
) / 2;
3186 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3187 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3188 /* outside possible client rectangle (to right) */
3190 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3191 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3192 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3193 y
= (bounds
.bottom
- bounds
.top
) / 2;
3194 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3195 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3196 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3197 himl
= ImageList_Create(16, 16, 0, 4, 4);
3198 ok(himl
!= NULL
, "failed to create imagelist\n");
3199 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3200 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3201 r
= ImageList_Add(himl
, hbmp
, 0);
3202 ok(r
== 0, "should be zero\n");
3203 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3204 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3205 r
= ImageList_Add(himl
, hbmp
, 0);
3206 ok(r
== 1, "should be one\n");
3208 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3209 ok(r
== 0, "should return zero\n");
3211 item
.mask
= LVIF_IMAGE
;
3215 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3219 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3220 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3221 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3222 y
= (bounds
.bottom
- bounds
.top
) / 2;
3223 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3225 /* state icons indices are 1 based, check with valid index */
3226 item
.mask
= LVIF_STATE
;
3227 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3228 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3231 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3235 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3236 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3237 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3238 y
= (bounds
.bottom
- bounds
.top
) / 2;
3239 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3241 himl2
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3242 ok(himl2
== himl
, "should return handle\n");
3244 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3245 ok(r
== 0, "should return zero\n");
3248 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3249 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, 0, FALSE
, FALSE
);
3250 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3251 y
= (bounds
.bottom
- bounds
.top
) / 2;
3252 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3254 DestroyWindow(hwnd
);
3257 static void test_getviewrect(void)
3264 hwnd
= create_listview_control(LVS_REPORT
);
3265 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3268 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3271 insert_column(hwnd
, 0);
3272 insert_column(hwnd
, 1);
3274 memset(&item
, 0, sizeof(item
));
3277 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3279 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3281 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3284 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3285 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3287 /* left is set to (2e31-1) - XP SP2 */
3288 expect(0, rect
.right
);
3289 expect(0, rect
.top
);
3290 expect(0, rect
.bottom
);
3292 /* switch to LVS_ICON */
3293 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3295 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3296 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3298 expect(0, rect
.left
);
3299 expect(0, rect
.top
);
3300 /* precise value differs for 2k, XP and Vista */
3301 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3302 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3304 DestroyWindow(hwnd
);
3307 static void test_getitemposition(void)
3314 hwnd
= create_listview_control(LVS_REPORT
);
3315 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3316 header
= subclass_header(hwnd
);
3318 /* LVS_REPORT, single item, no columns added */
3319 insert_item(hwnd
, 0);
3321 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3324 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3326 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3328 /* LVS_REPORT, single item, single column */
3329 insert_column(hwnd
, 0);
3331 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3334 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3336 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3338 memset(&rect
, 0, sizeof(rect
));
3339 SendMessage(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3342 /* offset by header height */
3343 expect(rect
.bottom
- rect
.top
, pt
.y
);
3345 DestroyWindow(hwnd
);
3348 static void test_columnscreation(void)
3353 hwnd
= create_listview_control(LVS_REPORT
);
3354 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3356 insert_item(hwnd
, 0);
3358 /* headers columns aren't created automatically */
3359 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3360 ok(IsWindow(header
), "Expected header handle\n");
3361 r
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
3364 DestroyWindow(hwnd
);
3367 static void test_getitemrect(void)
3370 HIMAGELIST himl
, himl_ret
;
3380 /* rectangle isn't empty for empty text items */
3381 hwnd
= create_listview_control(LVS_LIST
);
3382 memset(&item
, 0, sizeof(item
));
3385 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3387 rect
.left
= LVIR_LABEL
;
3388 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3390 expect(0, rect
.left
);
3391 expect(0, rect
.top
);
3393 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, rect
.right
);
3394 ReleaseDC(hwnd
, hdc
);
3395 DestroyWindow(hwnd
);
3397 hwnd
= create_listview_control(LVS_REPORT
);
3398 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3401 memset(&item
, 0, sizeof(item
));
3404 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3407 rect
.left
= LVIR_BOUNDS
;
3408 rect
.right
= rect
.top
= rect
.bottom
= -1;
3409 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3412 /* zero width rectangle with no padding */
3413 expect(0, rect
.left
);
3414 expect(0, rect
.right
);
3416 insert_column(hwnd
, 0);
3417 insert_column(hwnd
, 1);
3419 col
.mask
= LVCF_WIDTH
;
3421 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 0, (LPARAM
)&col
);
3424 col
.mask
= LVCF_WIDTH
;
3426 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 1, (LPARAM
)&col
);
3429 rect
.left
= LVIR_BOUNDS
;
3430 rect
.right
= rect
.top
= rect
.bottom
= -1;
3431 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3434 /* still no left padding */
3435 expect(0, rect
.left
);
3436 expect(150, rect
.right
);
3438 rect
.left
= LVIR_SELECTBOUNDS
;
3439 rect
.right
= rect
.top
= rect
.bottom
= -1;
3440 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3443 expect(2, rect
.left
);
3445 rect
.left
= LVIR_LABEL
;
3446 rect
.right
= rect
.top
= rect
.bottom
= -1;
3447 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3449 /* padding, column width */
3450 expect(2, rect
.left
);
3451 expect(50, rect
.right
);
3453 /* no icons attached */
3454 rect
.left
= LVIR_ICON
;
3455 rect
.right
= rect
.top
= rect
.bottom
= -1;
3456 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3459 expect(2, rect
.left
);
3460 expect(2, rect
.right
);
3463 order
[0] = 1; order
[1] = 0;
3464 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3467 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3469 /* 1 indexed column width + padding */
3471 /* rect is at zero too */
3472 rect
.left
= LVIR_BOUNDS
;
3473 rect
.right
= rect
.top
= rect
.bottom
= -1;
3474 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3476 expect(0, rect
.left
);
3477 /* just width sum */
3478 expect(150, rect
.right
);
3480 rect
.left
= LVIR_SELECTBOUNDS
;
3481 rect
.right
= rect
.top
= rect
.bottom
= -1;
3482 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3484 /* column width + padding */
3485 expect(102, rect
.left
);
3487 /* back to initial order */
3488 order
[0] = 0; order
[1] = 1;
3489 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3493 himl
= ImageList_Create(16, 16, 0, 2, 2);
3494 ok(himl
!= NULL
, "failed to create imagelist\n");
3495 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3496 ok(hbm
!= NULL
, "failed to create bitmap\n");
3497 r
= ImageList_Add(himl
, hbm
, 0);
3498 ok(r
== 0, "should be zero\n");
3499 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3500 ok(hbm
!= NULL
, "failed to create bitmap\n");
3501 r
= ImageList_Add(himl
, hbm
, 0);
3502 ok(r
== 1, "should be one\n");
3504 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3505 ok(r
== 0, "should return zero\n");
3507 item
.mask
= LVIF_STATE
;
3508 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3509 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3512 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3516 rect
.left
= LVIR_ICON
;
3517 rect
.right
= rect
.top
= rect
.bottom
= -1;
3518 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3520 /* padding + stateicon width */
3521 expect(18, rect
.left
);
3522 expect(18, rect
.right
);
3524 rect
.left
= LVIR_LABEL
;
3525 rect
.right
= rect
.top
= rect
.bottom
= -1;
3526 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3528 /* padding + stateicon width -> column width */
3529 expect(18, rect
.left
);
3530 expect(50, rect
.right
);
3532 himl_ret
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3533 ok(himl_ret
== himl
, "got %p, expected %p\n", himl_ret
, himl
);
3535 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3536 ok(r
== 0, "should return zero\n");
3538 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3541 item
.stateMask
= ~0;
3544 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3548 rect
.left
= LVIR_ICON
;
3549 rect
.right
= rect
.top
= rect
.bottom
= -1;
3550 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3552 /* padding, icon width */
3553 expect(2, rect
.left
);
3554 expect(18, rect
.right
);
3556 rect
.left
= LVIR_LABEL
;
3557 rect
.right
= rect
.top
= rect
.bottom
= -1;
3558 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3560 /* padding + icon width -> column width */
3561 expect(18, rect
.left
);
3562 expect(50, rect
.right
);
3565 rect
.left
= LVIR_SELECTBOUNDS
;
3566 rect
.right
= rect
.top
= rect
.bottom
= -1;
3567 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3569 /* padding, column width */
3570 expect(2, rect
.left
);
3571 expect(50, rect
.right
);
3573 /* try with indentation */
3574 item
.mask
= LVIF_INDENT
;
3578 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3582 rect
.left
= LVIR_BOUNDS
;
3583 rect
.right
= rect
.top
= rect
.bottom
= -1;
3584 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3586 /* padding + 1 icon width, column width */
3587 expect(0, rect
.left
);
3588 expect(150, rect
.right
);
3591 rect
.left
= LVIR_SELECTBOUNDS
;
3592 rect
.right
= rect
.top
= rect
.bottom
= -1;
3593 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3595 /* padding + 1 icon width, column width */
3596 expect(2 + 16, rect
.left
);
3597 expect(50, rect
.right
);
3600 rect
.left
= LVIR_LABEL
;
3601 rect
.right
= rect
.top
= rect
.bottom
= -1;
3602 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3604 /* padding + 2 icon widths, column width */
3605 expect(2 + 16*2, rect
.left
);
3606 expect(50, rect
.right
);
3609 rect
.left
= LVIR_ICON
;
3610 rect
.right
= rect
.top
= rect
.bottom
= -1;
3611 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3613 /* padding + 1 icon width indentation, icon width */
3614 expect(2 + 16, rect
.left
);
3615 expect(34, rect
.right
);
3617 DestroyWindow(hwnd
);
3620 static void test_editbox(void)
3622 static CHAR testitemA
[] = "testitem";
3623 static CHAR testitem1A
[] = "testitem_quitelongname";
3624 static CHAR testitem2A
[] = "testITEM_quitelongname";
3625 static CHAR buffer
[25];
3626 HWND hwnd
, hwndedit
, hwndedit2
, header
;
3630 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
3631 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3633 insert_column(hwnd
, 0);
3635 memset(&item
, 0, sizeof(item
));
3636 item
.mask
= LVIF_TEXT
;
3637 item
.pszText
= testitemA
;
3640 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3643 /* test notifications without edit created */
3644 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3645 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)0xdeadbeef);
3647 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3648 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE
);
3649 /* same thing but with valid window */
3650 hwndedit
= CreateWindowA("Edit", "Test edit", WS_VISIBLE
| WS_CHILD
, 0, 0, 20,
3651 10, hwnd
, (HMENU
)1, (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
), 0);
3652 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3653 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)hwndedit
);
3655 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3656 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE
);
3657 DestroyWindow(hwndedit
);
3659 /* setting focus is necessary */
3661 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3662 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3664 /* test children Z-order after Edit box created */
3665 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3666 ok(IsWindow(header
), "Expected header to be created\n");
3667 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
3668 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
3670 /* modify initial string */
3671 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3674 /* edit window is resized and repositioned,
3675 check again for Z-order - it should be preserved */
3676 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
3677 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
3679 /* return focus to listview */
3682 memset(&item
, 0, sizeof(item
));
3683 item
.mask
= LVIF_TEXT
;
3684 item
.pszText
= buffer
;
3685 item
.cchTextMax
= sizeof(buffer
);
3688 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3691 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3693 /* send LVM_EDITLABEL on already created edit */
3695 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3696 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3697 /* focus will be set to edit */
3698 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
3699 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3700 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
3702 /* creating label disabled when control isn't focused */
3704 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3705 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3707 /* check EN_KILLFOCUS handling */
3708 memset(&item
, 0, sizeof(item
));
3709 item
.pszText
= testitemA
;
3712 r
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3716 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3717 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3718 /* modify edit and notify control that it lost focus */
3719 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3721 g_editbox_disp_info
.item
.pszText
= NULL
;
3722 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3724 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "expected notification with not null text\n");
3726 memset(&item
, 0, sizeof(item
));
3727 item
.pszText
= buffer
;
3728 item
.cchTextMax
= sizeof(buffer
);
3731 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3732 expect(lstrlen(item
.pszText
), r
);
3733 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3734 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
3736 /* change item name to differ in casing only */
3738 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3739 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3740 /* modify edit and notify control that it lost focus */
3741 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem2A
);
3743 g_editbox_disp_info
.item
.pszText
= NULL
;
3744 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3746 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "got %p\n", g_editbox_disp_info
.item
.pszText
);
3748 memset(&item
, 0, sizeof(item
));
3749 item
.pszText
= buffer
;
3750 item
.cchTextMax
= sizeof(buffer
);
3753 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3754 expect(lstrlen(item
.pszText
), r
);
3755 ok(strcmp(buffer
, testitem2A
) == 0, "got %s, expected %s\n", buffer
, testitem2A
);
3756 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
3758 /* end edit without saving */
3760 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3761 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3762 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
3764 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3765 "edit box - end edit, no change, escape", TRUE
);
3766 /* end edit with saving */
3768 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3769 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3770 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_RETURN
, 0);
3772 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3773 "edit box - end edit, no change, return", TRUE
);
3775 memset(&item
, 0, sizeof(item
));
3776 item
.pszText
= buffer
;
3777 item
.cchTextMax
= sizeof(buffer
);
3780 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3781 expect(lstrlen(item
.pszText
), r
);
3782 ok(strcmp(buffer
, testitem2A
) == 0, "Expected item text to change\n");
3784 /* LVM_EDITLABEL with -1 destroys current edit */
3785 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
3786 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3787 /* no edit present */
3788 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3789 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3790 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3791 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3793 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3794 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3795 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3796 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3797 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3798 /* check another negative value */
3799 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3800 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3801 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3802 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -2, 0);
3803 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3804 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3805 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3806 /* and value greater than max item index */
3807 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3808 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3809 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3810 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3811 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, r
, 0);
3812 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3813 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3814 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3816 /* messaging tests */
3818 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3820 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3821 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3822 /* testing only sizing messages */
3823 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
3824 "edit box create - sizing", FALSE
);
3826 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
3828 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3829 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3830 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3831 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3833 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3834 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE
);
3836 DestroyWindow(hwnd
);
3839 static void test_notifyformat(void)
3844 hwnd
= create_listview_control(LVS_REPORT
);
3845 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3847 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3848 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3849 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3851 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3853 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
3855 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3858 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
3860 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3865 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3866 DestroyWindow(hwnd
);
3870 DestroyWindow(hwnd
);
3872 /* test failure in parent WM_NOTIFYFORMAT */
3874 hwnd
= create_listview_control(LVS_REPORT
);
3875 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3876 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3877 ok(IsWindow(header
), "expected header to be created\n");
3878 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3880 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3881 ok( r
== 1 || broken(r
== 0), /* win9x */ "Expected 1, got %d\n", r
);
3882 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3883 ok(r
!= 0, "Expected valid format\n");
3885 notifyFormat
= NFR_UNICODE
;
3886 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3887 expect(NFR_UNICODE
, r
);
3888 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3890 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3891 ok( r
== 1 || broken(r
== 0), /* win9x */ "Expected 1, got %d\n", r
);
3893 notifyFormat
= NFR_ANSI
;
3894 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3895 expect(NFR_ANSI
, r
);
3896 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3898 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3899 ok( r
== 1 || broken(r
== 0), /* win9x */ "Expected 1, got %d\n", r
);
3901 DestroyWindow(hwnd
);
3903 /* try different unicode window combination and defaults */
3904 if (!GetModuleHandleW(NULL
))
3906 win_skip("Additional notify format tests are incompatible with Win9x\n");
3910 hwndparentW
= create_parent_window(TRUE
);
3911 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
3912 if (!IsWindow(hwndparentW
)) return;
3915 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3916 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3917 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3918 ok(IsWindow(header
), "expected header to be created\n");
3919 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3921 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3923 DestroyWindow(hwnd
);
3924 /* receiving error code defaulting to ansi */
3926 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3927 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3928 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3929 ok(IsWindow(header
), "expected header to be created\n");
3930 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3932 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3934 DestroyWindow(hwnd
);
3935 /* receiving ansi code from unicode window, use it */
3936 notifyFormat
= NFR_ANSI
;
3937 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3938 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3939 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3940 ok(IsWindow(header
), "expected header to be created\n");
3941 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3943 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3945 DestroyWindow(hwnd
);
3946 /* unicode listview with ansi parent window */
3948 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
3949 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3950 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3951 ok(IsWindow(header
), "expected header to be created\n");
3952 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3954 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3956 DestroyWindow(hwnd
);
3957 /* unicode listview with ansi parent window, return error code */
3959 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
3960 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3961 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3962 ok(IsWindow(header
), "expected header to be created\n");
3963 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3965 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3967 DestroyWindow(hwnd
);
3969 DestroyWindow(hwndparentW
);
3972 static void test_indentation(void)
3978 hwnd
= create_listview_control(LVS_REPORT
);
3979 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3981 memset(&item
, 0, sizeof(item
));
3982 item
.mask
= LVIF_INDENT
;
3984 item
.iIndent
= I_INDENTCALLBACK
;
3985 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3988 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3991 item
.mask
= LVIF_INDENT
;
3992 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3995 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3996 "get indent dispinfo", FALSE
);
3998 DestroyWindow(hwnd
);
4001 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
4006 static BOOL
is_below_comctl_5(void)
4011 hwnd
= create_listview_control(LVS_REPORT
);
4012 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4013 insert_item(hwnd
, 0);
4015 ret
= SendMessage(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
4017 DestroyWindow(hwnd
);
4022 static void test_get_set_view(void)
4028 /* test style->view mapping */
4029 hwnd
= create_listview_control(LVS_REPORT
);
4030 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4032 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4033 expect(LV_VIEW_DETAILS
, ret
);
4035 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4037 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
4038 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4039 expect(LV_VIEW_ICON
, ret
);
4041 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4042 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
4043 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4044 expect(LV_VIEW_SMALLICON
, ret
);
4046 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4047 SetWindowLongPtr(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
4048 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4049 expect(LV_VIEW_LIST
, ret
);
4051 /* switching view doesn't touch window style */
4052 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
4054 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4055 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4056 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
4058 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4059 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4060 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
4062 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4063 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4065 DestroyWindow(hwnd
);
4068 static void test_canceleditlabel(void)
4070 HWND hwnd
, hwndedit
;
4074 static CHAR test
[] = "test";
4075 static const CHAR test1
[] = "test1";
4077 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4078 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4080 insert_item(hwnd
, 0);
4082 /* try without edit created */
4083 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4084 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4086 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4087 "cancel edit label without edit", FALSE
);
4089 /* cancel without data change */
4091 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4092 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4093 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4095 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4097 /* cancel after data change */
4098 memset(&itema
, 0, sizeof(itema
));
4099 itema
.pszText
= test
;
4100 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
4103 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4104 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4105 ret
= SetWindowText(hwndedit
, test1
);
4106 ok(ret
== 1, "Expected edit text to change\n");
4107 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4109 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4110 memset(&itema
, 0, sizeof(itema
));
4111 itema
.pszText
= buff
;
4112 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
4113 ret
= SendMessage(hwnd
, LVM_GETITEMTEXT
, 0, (LPARAM
)&itema
);
4115 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
4117 DestroyWindow(hwnd
);
4120 static void test_mapidindex(void)
4125 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4126 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
4127 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4128 insert_item(hwnd
, 0);
4129 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4131 DestroyWindow(hwnd
);
4133 hwnd
= create_listview_control(LVS_REPORT
);
4134 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4136 /* LVM_MAPINDEXTOID with invalid index */
4137 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4140 insert_item(hwnd
, 0);
4141 insert_item(hwnd
, 1);
4143 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
4145 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
4148 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4150 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4152 /* remove 0 indexed item, id retained */
4153 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
4154 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4156 /* new id starts from previous value */
4157 insert_item(hwnd
, 1);
4158 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4161 /* get index by id */
4162 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
4164 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
4166 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
4168 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
4171 DestroyWindow(hwnd
);
4174 static void test_getitemspacing(void)
4183 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
4184 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
4187 hwnd
= create_listview_control(LVS_ICON
);
4188 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4190 expect(cx
, LOWORD(ret
));
4191 expect(cy
, HIWORD(ret
));
4193 /* now try with icons */
4194 himl
= ImageList_Create(40, 40, 0, 4, 4);
4195 ok(himl
!= NULL
, "failed to create imagelist\n");
4196 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4197 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4198 ret
= ImageList_Add(himl
, hbmp
, 0);
4200 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4203 itema
.mask
= LVIF_IMAGE
;
4207 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
4209 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4211 /* spacing + icon size returned */
4212 expect(cx
+ 40, LOWORD(ret
));
4213 expect(cy
+ 40, HIWORD(ret
));
4215 DestroyWindow(hwnd
);
4217 hwnd
= create_listview_control(LVS_SMALLICON
);
4218 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4220 expect(cx
, LOWORD(ret
));
4221 expect(cy
, HIWORD(ret
));
4223 DestroyWindow(hwnd
);
4225 hwnd
= create_listview_control(LVS_REPORT
);
4226 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4228 expect(cx
, LOWORD(ret
));
4229 expect(cy
, HIWORD(ret
));
4231 DestroyWindow(hwnd
);
4233 hwnd
= create_listview_control(LVS_LIST
);
4234 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4236 expect(cx
, LOWORD(ret
));
4237 expect(cy
, HIWORD(ret
));
4239 DestroyWindow(hwnd
);
4242 static void test_getcolumnwidth(void)
4251 /* default column width */
4252 hwnd
= create_listview_control(LVS_ICON
);
4253 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4255 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4256 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
4257 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4258 todo_wine
expect(8, ret
);
4259 style
= GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
4260 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
4262 ret
= SendMessage(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4264 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4266 DestroyWindow(hwnd
);
4268 /* default column width with item added */
4269 hwnd
= create_listview_control(LVS_LIST
);
4270 memset(&itema
, 0, sizeof(itema
));
4271 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4272 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4274 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, ret
);
4275 ReleaseDC(hwnd
, hdc
);
4276 DestroyWindow(hwnd
);
4279 static void test_scrollnotify(void)
4284 hwnd
= create_listview_control(LVS_REPORT
);
4286 insert_column(hwnd
, 0);
4287 insert_column(hwnd
, 1);
4288 insert_item(hwnd
, 0);
4290 /* make it scrollable - resize */
4291 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
4293 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
4296 /* try with dummy call */
4297 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4298 ret
= SendMessage(hwnd
, LVM_SCROLL
, 0, 0);
4300 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4301 "scroll notify 1", TRUE
);
4303 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4304 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 0);
4306 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4307 "scroll notify 2", TRUE
);
4309 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4310 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 1);
4312 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4313 "scroll notify 3", TRUE
);
4315 DestroyWindow(hwnd
);
4318 static void test_LVS_EX_TRANSPARENTBKGND(void)
4324 hwnd
= create_listview_control(LVS_REPORT
);
4326 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4329 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4330 LVS_EX_TRANSPARENTBKGND
);
4332 ret
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, 0);
4333 if (ret
!= CLR_NONE
)
4335 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4336 DestroyWindow(hwnd
);
4340 /* try to set some back color and check this style bit */
4341 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4343 ret
= SendMessage(hwnd
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
4344 ok(!(ret
& LVS_EX_TRANSPARENTBKGND
), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4346 /* now test what this style actually does */
4347 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4348 LVS_EX_TRANSPARENTBKGND
);
4350 hdc
= GetWindowDC(hwndparent
);
4352 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4353 SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
4354 ok_sequence(sequences
, PARENT_SEQ_INDEX
, lvs_ex_transparentbkgnd_seq
,
4355 "LVS_EX_TRANSPARENTBKGND parent", FALSE
);
4357 ReleaseDC(hwndparent
, hdc
);
4359 DestroyWindow(hwnd
);
4362 static void test_approximate_viewrect(void)
4369 static CHAR test
[] = "abracadabra, a very long item label";
4371 hwnd
= create_listview_control(LVS_ICON
);
4372 himl
= ImageList_Create(40, 40, 0, 4, 4);
4373 ok(himl
!= NULL
, "failed to create imagelist\n");
4374 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4375 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4376 ret
= ImageList_Add(himl
, hbmp
, 0);
4378 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4381 itema
.mask
= LVIF_IMAGE
;
4385 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
4388 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(75, 75));
4392 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4396 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4397 ok(MAKELONG(77,827)==ret
,"Incorrect Approximate rect\n");
4399 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(50, 50));
4400 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4401 ok(MAKELONG(102,302)==ret
,"Incorrect Approximate rect\n");
4403 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4404 ok(MAKELONG(52,52)==ret
,"Incorrect Approximate rect\n");
4406 itema
.pszText
= test
;
4407 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
4409 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4410 ok(MAKELONG(52,52)==ret
,"Incorrect Approximate rect\n");
4412 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 0, MAKELPARAM(100,100));
4413 ok(MAKELONG(52,2)==ret
,"Incorrect Approximate rect\n");
4414 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 1, MAKELPARAM(100,100));
4415 ok(MAKELONG(52,52)==ret
,"Incorrect Approximate rect\n");
4416 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 2, MAKELPARAM(100,100));
4417 ok(MAKELONG(102,52)==ret
,"Incorrect Approximate rect\n");
4418 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 3, MAKELPARAM(100,100));
4419 ok(MAKELONG(102,102)==ret
,"Incorrect Approximate rect\n");
4420 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 4, MAKELPARAM(100,100));
4421 ok(MAKELONG(102,102)==ret
,"Incorrect Approximate rect\n");
4422 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 5, MAKELPARAM(100,100));
4423 ok(MAKELONG(102,152)==ret
,"Incorrect Approximate rect\n");
4424 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 6, MAKELPARAM(100,100));
4425 ok(MAKELONG(102,152)==ret
,"Incorrect Approximate rect\n");
4426 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 7, MAKELPARAM(160,100));
4427 ok(MAKELONG(152,152)==ret
,"Incorrect Approximate rect\n");
4429 DestroyWindow(hwnd
);
4432 static void test_finditem(void)
4439 hwnd
= create_listview_control(LVS_REPORT
);
4440 insert_item(hwnd
, 0);
4442 memset(&fi
, 0, sizeof(fi
));
4444 /* full string search, inserted text was "foo" */
4446 fi
.flags
= LVFI_STRING
;
4448 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4450 /* partial string search, inserted text was "foo" */
4452 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4454 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4456 /* partial string search, part after start char */
4458 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4460 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4463 /* try with LVFI_SUBSTRING */
4465 fi
.flags
= LVFI_SUBSTRING
;
4467 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4470 win_skip("LVFI_SUBSTRING not supported\n");
4471 DestroyWindow(hwnd
);
4476 fi
.flags
= LVFI_SUBSTRING
;
4478 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4481 fi
.flags
= LVFI_SUBSTRING
;
4483 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4487 fi
.flags
= LVFI_SUBSTRING
| LVFI_STRING
;
4489 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4492 DestroyWindow(hwnd
);
4495 static void test_LVS_EX_HEADERINALLVIEWS(void)
4500 hwnd
= create_listview_control(LVS_ICON
);
4502 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4503 LVS_EX_HEADERINALLVIEWS
);
4505 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4506 if (!IsWindow(header
))
4508 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4509 DestroyWindow(hwnd
);
4513 /* LVS_NOCOLUMNHEADER works as before */
4514 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4515 SetWindowLongW(hwnd
, GWL_STYLE
, style
| LVS_NOCOLUMNHEADER
);
4516 style
= GetWindowLongA(header
, GWL_STYLE
);
4517 ok(style
& HDS_HIDDEN
, "Expected HDS_HIDDEN\n");
4518 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4519 SetWindowLongW(hwnd
, GWL_STYLE
, style
& ~LVS_NOCOLUMNHEADER
);
4520 style
= GetWindowLongA(header
, GWL_STYLE
);
4521 ok(!(style
& HDS_HIDDEN
), "Expected HDS_HIDDEN to be unset\n");
4523 /* try to remove style */
4524 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
, 0);
4525 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4526 ok(IsWindow(header
), "Expected header to be created\n");
4527 style
= GetWindowLongA(header
, GWL_STYLE
);
4528 ok(!(style
& HDS_HIDDEN
), "HDS_HIDDEN not expected\n");
4530 DestroyWindow(hwnd
);
4532 /* check other styles */
4533 hwnd
= create_listview_control(LVS_LIST
);
4534 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4535 LVS_EX_HEADERINALLVIEWS
);
4536 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4537 ok(IsWindow(header
), "Expected header to be created\n");
4538 DestroyWindow(hwnd
);
4540 hwnd
= create_listview_control(LVS_SMALLICON
);
4541 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4542 LVS_EX_HEADERINALLVIEWS
);
4543 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4544 ok(IsWindow(header
), "Expected header to be created\n");
4545 DestroyWindow(hwnd
);
4547 hwnd
= create_listview_control(LVS_REPORT
);
4548 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4549 LVS_EX_HEADERINALLVIEWS
);
4550 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4551 ok(IsWindow(header
), "Expected header to be created\n");
4552 DestroyWindow(hwnd
);
4555 static void test_hover(void)
4560 hwnd
= create_listview_control(LVS_ICON
);
4562 /* test WM_MOUSEHOVER forwarding */
4563 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4564 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
4566 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER allow test", TRUE
);
4567 g_block_hover
= TRUE
;
4568 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4569 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
4571 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER block test", TRUE
);
4572 g_block_hover
= FALSE
;
4574 r
= SendMessage(hwnd
, LVM_SETHOVERTIME
, 0, 500);
4575 expect(HOVER_DEFAULT
, r
);
4576 r
= SendMessage(hwnd
, LVM_GETHOVERTIME
, 0, 0);
4579 DestroyWindow(hwnd
);
4582 static void test_destroynotify(void)
4586 hwnd
= create_listview_control(LVS_REPORT
);
4587 ok(hwnd
!= NULL
, "failed to create listview window\n");
4589 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4590 DestroyWindow(hwnd
);
4591 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_destroy
, "check destroy order", FALSE
);
4594 static void test_header_notification(void)
4602 list
= create_listview_control(LVS_REPORT
);
4603 ok(list
!= NULL
, "failed to create listview window\n");
4605 memset(&col
, 0, sizeof(col
));
4606 col
.mask
= LVCF_WIDTH
;
4608 ret
= SendMessage(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4609 ok(!ret
, "expected 0, got %ld\n", ret
);
4611 header
= subclass_header(list
);
4613 ret
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
4614 ok(ret
== 1, "expected header item count 1, got %ld\n", ret
);
4616 memset(&item
, 0, sizeof(item
));
4617 item
.mask
= HDI_WIDTH
;
4618 ret
= SendMessage(header
, HDM_GETITEMA
, 0, (LPARAM
)&item
);
4619 ok(ret
, "HDM_GETITEM failed\n");
4620 ok(item
.cxy
== 100, "expected 100, got %d\n", item
.cxy
);
4622 nmh
.hdr
.hwndFrom
= header
;
4623 nmh
.hdr
.idFrom
= GetWindowLongPtr(header
, GWLP_ID
);
4624 nmh
.hdr
.code
= HDN_ITEMCHANGEDA
;
4627 item
.mask
= HDI_WIDTH
;
4630 ret
= SendMessage(list
, WM_NOTIFY
, 0, (LPARAM
)&nmh
);
4631 ok(!ret
, "WM_NOTIFY/HDN_ITEMCHANGED failed\n");
4633 DestroyWindow(list
);
4636 static void test_createdragimage(void)
4642 list
= create_listview_control(LVS_ICON
);
4643 ok(list
!= NULL
, "failed to create listview window\n");
4645 insert_item(list
, 0);
4648 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, 0);
4649 ok(himl
== NULL
, "got %p\n", himl
);
4651 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, (LPARAM
)&pt
);
4652 ok(himl
!= NULL
, "got %p\n", himl
);
4653 ImageList_Destroy(himl
);
4655 DestroyWindow(list
);
4658 static void test_dispinfo(void)
4660 static const char testA
[] = "TEST";
4666 hwnd
= create_listview_control(LVS_ICON
);
4667 ok(hwnd
!= NULL
, "failed to create listview window\n");
4669 insert_item(hwnd
, 0);
4671 memset(&item
, 0, sizeof(item
));
4672 item
.pszText
= LPSTR_TEXTCALLBACKA
;
4673 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
4674 ok(ret
, "got %d\n", ret
);
4676 g_disp_A_to_W
= TRUE
;
4677 item
.pszText
= (char*)buff
;
4678 item
.cchTextMax
= sizeof(buff
)/sizeof(WCHAR
);
4679 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4680 ok(ret
== sizeof(testA
)-1, "got %d, expected 4\n", ret
);
4681 g_disp_A_to_W
= FALSE
;
4683 ok(memcmp(item
.pszText
, testA
, sizeof(testA
)) == 0,
4684 "got %s, expected %s\n", item
.pszText
, testA
);
4686 DestroyWindow(hwnd
);
4689 START_TEST(listview
)
4692 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
4694 ULONG_PTR ctx_cookie
;
4698 hComctl32
= GetModuleHandleA("comctl32.dll");
4699 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
4700 if (pInitCommonControlsEx
)
4702 INITCOMMONCONTROLSEX iccex
;
4703 iccex
.dwSize
= sizeof(iccex
);
4704 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
4705 pInitCommonControlsEx(&iccex
);
4708 InitCommonControls();
4710 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
4712 hwndparent
= create_parent_window(FALSE
);
4713 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4715 g_is_below_5
= is_below_comctl_5();
4717 test_header_notification();
4724 test_icon_spacing();
4727 test_item_position();
4732 test_subitem_rect();
4736 test_nosortheader();
4740 test_getitemposition();
4741 test_columnscreation();
4743 test_notifyformat();
4745 test_getitemspacing();
4746 test_getcolumnwidth();
4747 test_approximate_viewrect();
4750 test_destroynotify();
4751 test_createdragimage();
4754 if (!load_v6_module(&ctx_cookie
, &hCtx
))
4756 DestroyWindow(hwndparent
);
4760 /* this is a XP SP3 failure workaround */
4761 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
4762 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
,
4764 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
4765 if (!IsWindow(hwnd
))
4767 win_skip("FIXME: failed to create ListView window.\n");
4768 unload_v6_module(ctx_cookie
, hCtx
);
4769 DestroyWindow(hwndparent
);
4773 DestroyWindow(hwnd
);
4775 /* comctl32 version 6 tests start here */
4776 test_get_set_view();
4777 test_canceleditlabel();
4779 test_scrollnotify();
4780 test_LVS_EX_TRANSPARENTBKGND();
4781 test_LVS_EX_HEADERINALLVIEWS();
4783 unload_v6_module(ctx_cookie
, hCtx
);
4785 DestroyWindow(hwndparent
);