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 const struct message listview_header_changed_seq
[] = {
309 { LVM_SETCOLUMNA
, sent
},
310 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
311 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
315 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
317 static LONG defwndproc_counter
= 0;
321 msg
.message
= message
;
322 msg
.flags
= sent
|wparam
|lparam
;
323 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
326 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
328 /* log system messages, except for painting */
329 if (message
< WM_USER
&&
330 message
!= WM_PAINT
&&
331 message
!= WM_ERASEBKGND
&&
332 message
!= WM_NCPAINT
&&
333 message
!= WM_NCHITTEST
&&
334 message
!= WM_GETTEXT
&&
335 message
!= WM_GETICON
&&
336 message
!= WM_DEVICECHANGE
)
338 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
340 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
341 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
343 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
349 switch (((NMHDR
*)lParam
)->code
)
351 case LVN_BEGINLABELEDIT
:
355 /* subclass edit box */
357 edit
= subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
361 INT len
= SendMessageA(edit
, EM_GETLIMITTEXT
, 0, 0);
362 ok(len
== 259 || broken(len
== 260) /* includes NULL in NT4 */,
363 "text limit %d, expected 259\n", len
);
368 case LVN_ENDLABELEDIT
:
372 /* always accept new item text */
373 NMLVDISPINFO
*di
= (NMLVDISPINFO
*)lParam
;
374 g_editbox_disp_info
= *di
;
375 trace("LVN_ENDLABELEDIT: text=%s\n", di
->item
.pszText
);
377 /* edit control still available from this notification */
378 edit
= (HWND
)SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETEDITCONTROL
, 0, 0);
379 ok(IsWindow(edit
), "expected valid edit control handle\n");
383 case LVN_BEGINSCROLL
:
386 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
388 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
389 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
392 case LVN_ITEMCHANGED
:
393 if (g_dump_itemchanged
)
395 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
396 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
397 nmlv
->iItem
, nmlv
->uNewState
, nmlv
->uOldState
, nmlv
->uChanged
);
400 case LVN_GETDISPINFOA
:
402 NMLVDISPINFOA
*dispinfo
= (NMLVDISPINFOA
*)lParam
;
403 g_itema
= dispinfo
->item
;
405 if (g_disp_A_to_W
&& (dispinfo
->item
.mask
& LVIF_TEXT
))
407 static const WCHAR testW
[] = {'T','E','S','T',0};
408 dispinfo
->hdr
.code
= LVN_GETDISPINFOW
;
409 memcpy(dispinfo
->item
.pszText
, testW
, sizeof(testW
));
412 /* test control buffer size for text, 10 used to mask cases when control
413 is using caller buffer to process LVM_GETITEM for example */
414 if (dispinfo
->item
.mask
& LVIF_TEXT
&& dispinfo
->item
.cchTextMax
> 10)
415 ok(dispinfo
->item
.cchTextMax
== 260 ||
416 broken(dispinfo
->item
.cchTextMax
== 264) /* NT4 reports aligned size */,
417 "buffer size %d\n", dispinfo
->item
.cchTextMax
);
421 if (g_block_hover
) return 1;
426 case WM_NOTIFYFORMAT
:
428 /* force to return format */
429 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
434 defwndproc_counter
++;
435 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
436 defwndproc_counter
--;
441 static BOOL
register_parent_wnd_class(BOOL Unicode
)
449 clsW
.lpfnWndProc
= parent_wnd_proc
;
452 clsW
.hInstance
= GetModuleHandleW(NULL
);
454 clsW
.hCursor
= LoadCursorA(0, IDC_ARROW
);
455 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
456 clsW
.lpszMenuName
= NULL
;
457 clsW
.lpszClassName
= testparentclassW
;
462 clsA
.lpfnWndProc
= parent_wnd_proc
;
465 clsA
.hInstance
= GetModuleHandleA(NULL
);
467 clsA
.hCursor
= LoadCursorA(0, IDC_ARROW
);
468 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
469 clsA
.lpszMenuName
= NULL
;
470 clsA
.lpszClassName
= "Listview test parent class";
473 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
476 static HWND
create_parent_window(BOOL Unicode
)
478 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
481 if (!register_parent_wnd_class(Unicode
))
488 hwnd
= CreateWindowExW(0, testparentclassW
, nameW
,
489 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
490 WS_MAXIMIZEBOX
| WS_VISIBLE
,
492 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
494 hwnd
= CreateWindowExA(0, "Listview test parent class",
495 "Listview test parent window",
496 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
497 WS_MAXIMIZEBOX
| WS_VISIBLE
,
499 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
500 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
504 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
506 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
507 static LONG defwndproc_counter
= 0;
511 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
513 /* some debug output for style changing */
514 if ((message
== WM_STYLECHANGING
||
515 message
== WM_STYLECHANGED
) && lParam
)
517 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
518 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
521 msg
.message
= message
;
522 msg
.flags
= sent
|wparam
|lparam
;
523 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
526 msg
.id
= LISTVIEW_ID
;
527 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
528 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
530 defwndproc_counter
++;
531 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
532 defwndproc_counter
--;
536 static HWND
create_listview_control(DWORD style
)
542 GetClientRect(hwndparent
, &rect
);
543 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
544 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
545 0, 0, rect
.right
, rect
.bottom
,
546 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
547 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
549 if (!hwnd
) return NULL
;
551 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
552 (LONG_PTR
)listview_subclass_proc
);
553 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
558 /* unicode listview window with specified parent */
559 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
564 static const WCHAR nameW
[] = {'f','o','o',0};
566 GetClientRect(parent
, &rect
);
567 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
568 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
569 0, 0, rect
.right
, rect
.bottom
,
570 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
571 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
573 if (!hwnd
) return NULL
;
575 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
576 (LONG_PTR
)listview_subclass_proc
);
577 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
582 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
584 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
585 static LONG defwndproc_counter
= 0;
589 trace("header: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
591 msg
.message
= message
;
592 msg
.flags
= sent
|wparam
|lparam
;
593 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
597 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
599 defwndproc_counter
++;
600 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
601 defwndproc_counter
--;
605 static HWND
subclass_header(HWND hwndListview
)
610 hwnd
= ListView_GetHeader(hwndListview
);
611 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
612 (LONG_PTR
)header_subclass_proc
);
613 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
618 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
620 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
621 static LONG defwndproc_counter
= 0;
625 msg
.message
= message
;
626 msg
.flags
= sent
|wparam
|lparam
;
627 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
631 /* all we need is sizing */
632 if (message
== WM_WINDOWPOSCHANGING
||
633 message
== WM_NCCALCSIZE
||
634 message
== WM_WINDOWPOSCHANGED
||
635 message
== WM_MOVE
||
638 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
641 defwndproc_counter
++;
642 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
643 defwndproc_counter
--;
647 static HWND
subclass_editbox(HWND hwndListview
)
652 hwnd
= (HWND
)SendMessage(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
653 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
654 (LONG_PTR
)editbox_subclass_proc
);
655 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
660 /* Performs a single LVM_HITTEST test */
661 static void test_lvm_hittest_(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
, UINT broken_flags
,
662 BOOL todo_item
, BOOL todo_flags
, int line
)
671 ret
= SendMessage(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
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");
684 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
685 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
686 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
692 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
694 else if (broken_flags
)
695 ok_(__FILE__
, line
)(lpht
.flags
== flags
|| broken(lpht
.flags
== broken_flags
),
696 "Expected flags %x, got %x\n", flags
, lpht
.flags
);
698 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
701 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
703 /* Performs a single LVM_SUBITEMHITTEST test */
704 static void test_lvm_subitemhittest_(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
705 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
713 ret
= SendMessage(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
719 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
720 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
725 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
726 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
732 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
735 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
740 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
743 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
746 #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__)
748 static void test_images(void)
756 static CHAR hello
[] = "hello";
758 himl
= ImageList_Create(40, 40, 0, 4, 4);
759 ok(himl
!= NULL
, "failed to create imagelist\n");
761 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
762 ok(hbmp
!= NULL
, "failed to create bitmap\n");
764 r
= ImageList_Add(himl
, hbmp
, 0);
765 ok(r
== 0, "should be zero\n");
767 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
768 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
769 ok(hwnd
!= NULL
, "failed to create listview window\n");
771 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
772 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
774 ok(r
== 0, "should return zero\n");
776 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
777 ok(r
== 0, "should return zero\n");
779 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
780 ok(r
!= 0, "got 0\n");
782 /* returns dimensions */
784 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
785 ok(r
== 0, "should be zero items\n");
787 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
792 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
793 ok(r
== -1, "should fail\n");
796 item
.pszText
= hello
;
797 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
798 ok(r
== 0, "should not fail\n");
800 memset(&r1
, 0, sizeof r1
);
802 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
805 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
806 ok(r
== TRUE
, "should not fail\n");
809 item
.pszText
= hello
;
810 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
811 ok(r
== 0, "should not fail\n");
813 memset(&r2
, 0, sizeof r2
);
815 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
818 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
823 static void test_checkboxes(void)
828 static CHAR text
[] = "Text",
832 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
833 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
834 ok(hwnd
!= NULL
, "failed to create listview window\n");
836 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
837 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
838 item
.stateMask
= 0xffff;
843 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
847 item
.mask
= LVIF_STATE
;
848 item
.stateMask
= 0xffff;
849 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
851 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
853 /* Don't set LVIF_STATE */
854 item
.mask
= LVIF_TEXT
;
855 item
.stateMask
= 0xffff;
860 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
864 item
.mask
= LVIF_STATE
;
865 item
.stateMask
= 0xffff;
866 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
868 ok(item
.state
== 0, "state %x\n", item
.state
);
870 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
873 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
875 item
.mask
= LVIF_STATE
;
876 item
.stateMask
= 0xffff;
877 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
879 if (item
.state
!= 0x1ccc)
881 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
886 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
888 item
.mask
= LVIF_TEXT
;
890 item
.pszText
= text2
;
891 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
895 item
.mask
= LVIF_STATE
;
896 item
.stateMask
= 0xffff;
897 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
899 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
901 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
903 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
904 item
.stateMask
= 0xffff;
906 item
.pszText
= text3
;
907 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
911 item
.mask
= LVIF_STATE
;
912 item
.stateMask
= 0xffff;
913 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
915 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
917 /* Set an item's state to checked */
919 item
.mask
= LVIF_STATE
;
920 item
.stateMask
= 0xf000;
922 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
926 item
.mask
= LVIF_STATE
;
927 item
.stateMask
= 0xffff;
928 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
930 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
932 /* Check that only the bits we asked for are returned,
933 * and that all the others are set to zero
936 item
.mask
= LVIF_STATE
;
937 item
.stateMask
= 0xf000;
939 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
941 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
943 /* Set the style again and check that doesn't change an item's state */
944 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
945 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
948 item
.mask
= LVIF_STATE
;
949 item
.stateMask
= 0xffff;
950 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
952 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
954 /* Unsetting the checkbox extended style doesn't change an item's state */
955 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
956 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
959 item
.mask
= LVIF_STATE
;
960 item
.stateMask
= 0xffff;
961 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
963 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
965 /* Now setting the style again will change an item's state */
966 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
970 item
.mask
= LVIF_STATE
;
971 item
.stateMask
= 0xffff;
972 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
974 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
976 /* Toggle checkbox tests (bug 9934) */
977 memset (&item
, 0xcc, sizeof(item
));
978 item
.mask
= LVIF_STATE
;
981 item
.state
= LVIS_FOCUSED
;
982 item
.stateMask
= LVIS_FOCUSED
;
983 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
987 item
.mask
= LVIF_STATE
;
988 item
.stateMask
= 0xffff;
989 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
991 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
993 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
995 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
999 item
.mask
= LVIF_STATE
;
1000 item
.stateMask
= 0xffff;
1001 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1003 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
1005 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1007 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1011 item
.mask
= LVIF_STATE
;
1012 item
.stateMask
= 0xffff;
1013 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1015 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1017 DestroyWindow(hwnd
);
1020 static void insert_column(HWND hwnd
, int idx
)
1025 memset(&column
, 0xcc, sizeof(column
));
1026 column
.mask
= LVCF_SUBITEM
;
1027 column
.iSubItem
= idx
;
1029 rc
= ListView_InsertColumn(hwnd
, idx
, &column
);
1033 static void insert_item(HWND hwnd
, int idx
)
1035 static CHAR text
[] = "foo";
1040 memset(&item
, 0xcc, sizeof (item
));
1041 item
.mask
= LVIF_TEXT
;
1044 item
.pszText
= text
;
1046 rc
= ListView_InsertItem(hwnd
, &item
);
1050 static void test_items(void)
1052 const LPARAM lparamTest
= 0x42;
1053 static CHAR text
[] = "Text";
1059 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1060 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1061 ok(hwnd
!= NULL
, "failed to create listview window\n");
1064 * Test setting/getting item params
1067 /* Set up two columns */
1068 insert_column(hwnd
, 0);
1069 insert_column(hwnd
, 1);
1071 /* LVIS_SELECTED with zero stateMask */
1073 memset (&item
, 0, sizeof (item
));
1074 item
.mask
= LVIF_STATE
;
1075 item
.state
= LVIS_SELECTED
;
1079 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1082 memset (&item
, 0xcc, sizeof (item
));
1083 item
.mask
= LVIF_STATE
;
1084 item
.stateMask
= LVIS_SELECTED
;
1088 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1090 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1091 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1093 /* LVIS_SELECTED with zero stateMask */
1095 memset (&item
, 0, sizeof (item
));
1096 item
.mask
= LVIF_STATE
;
1097 item
.state
= LVIS_FOCUSED
;
1101 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1104 memset (&item
, 0xcc, sizeof (item
));
1105 item
.mask
= LVIF_STATE
;
1106 item
.stateMask
= LVIS_FOCUSED
;
1110 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1112 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1113 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1115 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1117 memset (&item
, 0, sizeof (item
));
1118 item
.mask
= LVIF_STATE
;
1119 item
.state
= LVIS_CUT
;
1120 item
.stateMask
= LVIS_FOCUSED
;
1123 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1126 memset (&item
, 0xcc, sizeof (item
));
1127 item
.mask
= LVIF_STATE
;
1128 item
.stateMask
= LVIS_CUT
;
1132 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1134 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1135 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1137 /* Insert an item with just a param */
1138 memset (&item
, 0xcc, sizeof (item
));
1139 item
.mask
= LVIF_PARAM
;
1142 item
.lParam
= lparamTest
;
1143 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1146 /* Test getting of the param */
1147 memset (&item
, 0xcc, sizeof (item
));
1148 item
.mask
= LVIF_PARAM
;
1151 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1153 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1155 /* Set up a subitem */
1156 memset (&item
, 0xcc, sizeof (item
));
1157 item
.mask
= LVIF_TEXT
;
1160 item
.pszText
= text
;
1161 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1164 item
.mask
= LVIF_TEXT
;
1167 item
.pszText
= buffA
;
1168 item
.cchTextMax
= sizeof(buffA
);
1169 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1171 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got text %s, expected %s\n", item
.pszText
, text
);
1173 /* set up with extra flag */
1174 /* 1. reset subitem text */
1175 item
.mask
= LVIF_TEXT
;
1178 item
.pszText
= NULL
;
1179 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1182 item
.mask
= LVIF_TEXT
;
1185 item
.pszText
= buffA
;
1187 item
.cchTextMax
= sizeof(buffA
);
1188 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1190 ok(item
.pszText
[0] == 0, "got %p\n", item
.pszText
);
1192 /* 2. set new text with extra flag specified */
1193 item
.mask
= LVIF_TEXT
| LVIF_DI_SETITEM
;
1196 item
.pszText
= text
;
1197 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1198 ok(r
== 1 || broken(r
== 0) /* NT4 */, "ret %d\n", r
);
1202 item
.mask
= LVIF_TEXT
;
1205 item
.pszText
= buffA
;
1207 item
.cchTextMax
= sizeof(buffA
);
1208 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1210 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got %s, expected %s\n", item
.pszText
, text
);
1213 /* Query param from subitem: returns main item param */
1214 memset (&item
, 0xcc, sizeof (item
));
1215 item
.mask
= LVIF_PARAM
;
1218 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1220 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1222 /* Set up param on first subitem: no effect */
1223 memset (&item
, 0xcc, sizeof (item
));
1224 item
.mask
= LVIF_PARAM
;
1227 item
.lParam
= lparamTest
+1;
1228 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1231 /* Query param from subitem again: should still return main item param */
1232 memset (&item
, 0xcc, sizeof (item
));
1233 item
.mask
= LVIF_PARAM
;
1236 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1238 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1240 /**** Some tests of state highlighting ****/
1241 memset (&item
, 0xcc, sizeof (item
));
1242 item
.mask
= LVIF_STATE
;
1245 item
.state
= LVIS_SELECTED
;
1246 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1247 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1250 item
.state
= LVIS_DROPHILITED
;
1251 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1254 memset (&item
, 0xcc, sizeof (item
));
1255 item
.mask
= LVIF_STATE
;
1258 item
.stateMask
= -1;
1259 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1261 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1263 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1265 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1267 /* some notnull but meaningless masks */
1268 memset (&item
, 0, sizeof(item
));
1269 item
.mask
= LVIF_NORECOMPUTE
;
1272 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1274 memset (&item
, 0, sizeof(item
));
1275 item
.mask
= LVIF_DI_SETITEM
;
1278 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1281 /* set text to callback value already having it */
1282 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1284 memset (&item
, 0, sizeof (item
));
1285 item
.mask
= LVIF_TEXT
;
1286 item
.pszText
= LPSTR_TEXTCALLBACK
;
1288 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1290 memset (&item
, 0, sizeof (item
));
1292 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1294 item
.pszText
= LPSTR_TEXTCALLBACK
;
1295 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0 , (LPARAM
) &item
);
1298 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1299 "check callback text comparison rule", FALSE
);
1301 DestroyWindow(hwnd
);
1304 static void test_columns(void)
1313 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1314 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1315 ok(hwnd
!= NULL
, "failed to create listview window\n");
1317 /* Add a column with no mask */
1318 memset(&column
, 0xcc, sizeof(column
));
1320 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1321 ok(rc
== 0, "Inserting column with no mask failed with %d\n", rc
);
1323 /* Check its width */
1324 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
1325 ok(rc
== 10 || broken(rc
== 0) /* win9x */,
1326 "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1328 DestroyWindow(hwnd
);
1330 /* LVM_GETCOLUMNORDERARRAY */
1331 hwnd
= create_listview_control(LVS_REPORT
);
1332 subclass_header(hwnd
);
1334 memset(&column
, 0, sizeof(column
));
1335 column
.mask
= LVCF_WIDTH
;
1337 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1341 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&column
);
1344 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1346 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1348 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1349 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1351 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1353 /* after column added subitem is considered as present */
1354 insert_item(hwnd
, 0);
1356 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1358 item
.pszText
= buff
;
1359 item
.cchTextMax
= sizeof(buff
);
1362 item
.mask
= LVIF_TEXT
;
1363 memset(&g_itema
, 0, sizeof(g_itema
));
1364 rc
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
1366 ok(g_itema
.iSubItem
== 1, "got %d\n", g_itema
.iSubItem
);
1368 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
1369 "get subitem text after column added", FALSE
);
1371 DestroyWindow(hwnd
);
1374 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1375 static WNDPROC listviewWndProc
;
1376 static HIMAGELIST test_create_imagelist
;
1378 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1382 if (uMsg
== WM_CREATE
)
1384 LPCREATESTRUCT lpcs
= (LPCREATESTRUCT
)lParam
;
1385 lpcs
->style
|= LVS_REPORT
;
1387 ret
= CallWindowProc(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1388 if (uMsg
== WM_CREATE
) SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1392 static void test_create(void)
1403 cls
.cbSize
= sizeof(WNDCLASSEX
);
1404 ok(GetClassInfoEx(GetModuleHandle(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1405 listviewWndProc
= cls
.lpfnWndProc
;
1406 cls
.lpfnWndProc
= create_test_wndproc
;
1407 cls
.lpszClassName
= "MyListView32";
1408 ok(RegisterClassEx(&cls
), "RegisterClassEx failed\n");
1410 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1411 hList
= CreateWindow("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1412 ok((HIMAGELIST
)SendMessage(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1413 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1415 if (!IsWindow(hHeader
))
1418 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1419 DestroyWindow(hList
);
1423 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1424 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1425 DestroyWindow(hList
);
1427 /* header isn't created on LVS_ICON and LVS_LIST styles */
1428 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1429 GetModuleHandle(NULL
), 0);
1430 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1431 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1432 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1434 memset(&col
, 0, sizeof(LVCOLUMNA
));
1435 col
.mask
= LVCF_WIDTH
;
1437 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1439 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1440 ok(IsWindow(hHeader
), "Header should be created\n");
1441 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1442 style
= GetWindowLong(hHeader
, GWL_STYLE
);
1443 ok(!(style
& HDS_HIDDEN
), "Not expected HDS_HIDDEN\n");
1444 DestroyWindow(hList
);
1446 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1447 GetModuleHandle(NULL
), 0);
1448 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1449 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1450 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1452 memset(&col
, 0, sizeof(LVCOLUMNA
));
1453 col
.mask
= LVCF_WIDTH
;
1455 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1457 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1458 ok(IsWindow(hHeader
), "Header should be created\n");
1459 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1460 DestroyWindow(hList
);
1462 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1463 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1464 GetModuleHandle(NULL
), 0);
1465 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLongPtr(hList
, GWL_STYLE
) | LVS_REPORT
);
1466 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1467 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1468 ok(IsWindow(hHeader
), "Header should be created\n");
1469 ret
= SetWindowLongPtr(hList
, GWL_STYLE
, GetWindowLong(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1470 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1471 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1472 ok(IsWindow(hHeader
), "Header should be created\n");
1473 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1474 DestroyWindow(hList
);
1476 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1477 hList
= CreateWindow("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1478 GetModuleHandle(NULL
), 0);
1479 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1480 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1481 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1482 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1483 ok(IsWindow(hHeader
), "Header should be created\n");
1484 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1485 ret
= SetWindowLongPtr(hList
, GWL_STYLE
,
1486 (GetWindowLongPtr(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1487 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1488 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1489 ok(IsWindow(hHeader
), "Header should be created\n");
1490 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1491 DestroyWindow(hList
);
1493 /* LVS_REPORT without WS_VISIBLE */
1494 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1495 GetModuleHandle(NULL
), 0);
1496 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1497 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1498 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1500 memset(&col
, 0, sizeof(LVCOLUMNA
));
1501 col
.mask
= LVCF_WIDTH
;
1503 r
= SendMessage(hList
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
1505 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1506 ok(IsWindow(hHeader
), "Header should be created\n");
1507 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1508 DestroyWindow(hList
);
1510 /* LVS_REPORT without WS_VISIBLE, try to show it */
1511 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1512 GetModuleHandle(NULL
), 0);
1513 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1514 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1515 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1516 ShowWindow(hList
, SW_SHOW
);
1517 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1518 ok(IsWindow(hHeader
), "Header should be created\n");
1519 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1520 DestroyWindow(hList
);
1522 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1523 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1524 0, 0, 100, 100, NULL
, NULL
, GetModuleHandle(NULL
), 0);
1525 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1526 ok(IsWindow(hHeader
), "Header should be created\n");
1527 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1528 /* HDS_DRAGDROP set by default */
1529 ok(GetWindowLongPtr(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1530 DestroyWindow(hList
);
1532 /* setting LVS_EX_HEADERDRAGDROP creates header */
1533 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1534 GetModuleHandle(NULL
), 0);
1535 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1536 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1537 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1538 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1539 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1540 ok(IsWindow(hHeader
) ||
1541 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1542 "Header should be created\n");
1543 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1544 DestroyWindow(hList
);
1546 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1547 hList
= create_listview_control(LVS_ICON
);
1548 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1549 r
= SendMessage(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1550 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1551 DestroyWindow(hList
);
1553 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1554 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1555 GetModuleHandle(NULL
), 0);
1556 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1557 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1559 rect
.left
= LVIR_BOUNDS
;
1561 rect
.right
= rect
.bottom
= -10;
1562 r
= SendMessage(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1565 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1566 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1567 ok(GetDlgItem(hList
, 0) == NULL
, "NULL dialog item expected\n");
1569 DestroyWindow(hList
);
1571 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1572 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1573 hList
= create_listview_control(LVS_OWNERDRAWFIXED
| LVS_REPORT
);
1574 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1575 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1576 DestroyWindow(hList
);
1579 static void test_redraw(void)
1586 hwnd
= create_listview_control(LVS_REPORT
);
1587 subclass_header(hwnd
);
1589 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1591 InvalidateRect(hwnd
, NULL
, TRUE
);
1593 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1595 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1597 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1598 /* 1. Without backbuffer */
1599 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1602 hdc
= GetWindowDC(hwndparent
);
1604 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1605 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1606 ok(r
== 1, "Expected not zero result\n");
1607 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1608 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1610 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1613 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1614 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1616 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1617 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1619 /* 2. With backbuffer */
1620 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1621 LVS_EX_DOUBLEBUFFER
);
1622 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1625 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1626 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1628 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1629 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1631 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1634 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1635 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1636 todo_wine
expect(1, r
);
1637 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1638 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1640 ReleaseDC(hwndparent
, hdc
);
1642 DestroyWindow(hwnd
);
1645 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1647 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1649 if(msg
== WM_NOTIFY
) {
1650 NMHDR
*nmhdr
= (PVOID
)lp
;
1651 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1652 NMLVCUSTOMDRAW
*nmlvcd
= (PVOID
)nmhdr
;
1653 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd
->nmcd
.dwDrawStage
);
1654 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1656 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1657 return CDRF_NOTIFYITEMDRAW
;
1658 case CDDS_ITEMPREPAINT
:
1659 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1660 return CDRF_NOTIFYSUBITEMDRAW
;
1661 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1662 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1663 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1664 return CDRF_NOTIFYPOSTPAINT
;
1665 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1666 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1667 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1668 return CDRF_DODEFAULT
;
1670 return CDRF_DODEFAULT
;
1674 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1677 static void test_customdraw(void)
1682 hwnd
= create_listview_control(LVS_REPORT
);
1684 insert_column(hwnd
, 0);
1685 insert_column(hwnd
, 1);
1686 insert_item(hwnd
, 0);
1688 oldwndproc
= (WNDPROC
)SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
,
1689 (LONG_PTR
)cd_wndproc
);
1691 InvalidateRect(hwnd
, NULL
, TRUE
);
1694 SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1696 DestroyWindow(hwnd
);
1699 static void test_icon_spacing(void)
1701 /* LVM_SETICONSPACING */
1702 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1708 hwnd
= create_listview_control(LVS_ICON
);
1709 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1711 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, NF_REQUERY
);
1712 expect(NFR_ANSI
, r
);
1714 /* reset the icon spacing to defaults */
1715 SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1717 /* now we can request what the defaults are */
1718 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1722 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1724 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1725 ok(r
== MAKELONG(w
, h
) ||
1726 broken(r
== MAKELONG(w
, w
)), /* win98 */
1727 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1729 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1733 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1734 DestroyWindow(hwnd
);
1737 expect(MAKELONG(20,30), r
);
1739 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1740 expect(MAKELONG(25,35), r
);
1742 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1744 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1745 DestroyWindow(hwnd
);
1748 static void test_color(void)
1750 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1757 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1759 hwnd
= create_listview_control(LVS_REPORT
);
1760 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1762 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1764 for (i
= 0; i
< 4; i
++)
1768 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1770 r
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, color
);
1773 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1775 r
= SendMessage(hwnd
, LVM_GETTEXTCOLOR
, 0, color
);
1778 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1780 r
= SendMessage(hwnd
, LVM_GETTEXTBKCOLOR
, 0, color
);
1784 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1786 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1787 DestroyWindow(hwnd
);
1790 static void test_item_count(void)
1792 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1805 static CHAR item0text
[] = "item0";
1806 static CHAR item1text
[] = "item1";
1807 static CHAR item2text
[] = "item2";
1809 hwnd
= create_listview_control(LVS_REPORT
);
1810 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1812 /* resize in dpiaware manner to fit all 3 items added */
1814 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1815 GetTextMetricsA(hdc
, &tm
);
1816 /* 2 extra pixels for bounds and header border */
1817 height
= tm
.tmHeight
+ 2;
1818 SelectObject(hdc
, hOldFont
);
1821 GetWindowRect(hwnd
, &rect
);
1822 /* 3 items + 1 header + 1 to be sure */
1823 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1825 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1827 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1831 item0
.mask
= LVIF_TEXT
;
1834 item0
.pszText
= item0text
;
1835 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1838 /* [item0, item1] */
1839 item1
.mask
= LVIF_TEXT
;
1842 item1
.pszText
= item1text
;
1843 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1846 /* [item0, item1, item2] */
1847 item2
.mask
= LVIF_TEXT
;
1850 item2
.pszText
= item2text
;
1851 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1854 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1857 /* [item0, item1] */
1858 r
= SendMessage(hwnd
, LVM_DELETEITEM
, 2, 0);
1861 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1865 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1868 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1872 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1875 /* [item0, item1] */
1876 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1879 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1882 /* [item0, item1, item2] */
1883 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1886 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1889 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
1891 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1892 DestroyWindow(hwnd
);
1895 static void test_item_position(void)
1897 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1906 static CHAR item0text
[] = "item0";
1907 static CHAR item1text
[] = "item1";
1908 static CHAR item2text
[] = "item2";
1910 hwnd
= create_listview_control(LVS_ICON
);
1911 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1913 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1916 item0
.mask
= LVIF_TEXT
;
1919 item0
.pszText
= item0text
;
1920 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1923 /* [item0, item1] */
1924 item1
.mask
= LVIF_TEXT
;
1927 item1
.pszText
= item1text
;
1928 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1931 /* [item0, item1, item2] */
1932 item2
.mask
= LVIF_TEXT
;
1935 item2
.pszText
= item2text
;
1936 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1939 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
1941 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
1943 expect2(10, 5, position
.x
, position
.y
);
1945 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
1947 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
1949 expect2(0, 0, position
.x
, position
.y
);
1951 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
1953 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
1955 expect2(20, 20, position
.x
, position
.y
);
1957 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
1959 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1960 DestroyWindow(hwnd
);
1963 static void test_getorigin(void)
1971 position
.x
= position
.y
= 0;
1973 hwnd
= create_listview_control(LVS_ICON
);
1974 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1975 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1977 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1979 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1980 DestroyWindow(hwnd
);
1982 hwnd
= create_listview_control(LVS_SMALLICON
);
1983 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1984 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1986 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1988 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1989 DestroyWindow(hwnd
);
1991 hwnd
= create_listview_control(LVS_LIST
);
1992 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1993 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1995 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
1997 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1998 DestroyWindow(hwnd
);
2000 hwnd
= create_listview_control(LVS_REPORT
);
2001 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2002 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2004 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2006 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2007 DestroyWindow(hwnd
);
2010 static void test_multiselect(void)
2012 typedef struct t_select_task
2023 int i
,j
,item_count
,selected_count
;
2024 static const int items
=5;
2030 static struct t_select_task task_list
[] = {
2031 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
2032 { "using VK_UP", -1, VK_UP
, -1, -1 },
2033 { "using VK_END", 0, VK_END
, 1, -1 },
2034 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
2038 hwnd
= create_listview_control(LVS_REPORT
);
2040 for (i
=0;i
<items
;i
++) {
2041 insert_item(hwnd
, 0);
2044 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2046 expect(items
,item_count
);
2049 task
= task_list
[i
];
2051 /* deselect all items */
2052 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
2053 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2055 /* set initial position */
2056 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
2057 ListView_SetItemState(hwnd
,(task
.initPos
== -1 ? item_count
-1 : task
.initPos
),LVIS_SELECTED
,LVIS_SELECTED
);
2059 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2061 ok(selected_count
== 1, "There should be only one selected item at the beginning (is %d)\n",selected_count
);
2063 /* Set SHIFT key pressed */
2064 GetKeyboardState(kstate
);
2065 kstate
[VK_SHIFT
]=0x80;
2066 SetKeyboardState(kstate
);
2068 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
2069 r
= SendMessage(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
2071 r
= SendMessage(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
2075 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2077 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
);
2079 /* Set SHIFT key released */
2080 GetKeyboardState(kstate
);
2081 kstate
[VK_SHIFT
]=0x00;
2082 SetKeyboardState(kstate
);
2084 DestroyWindow(hwnd
);
2086 /* make multiple selection, then switch to LVS_SINGLESEL */
2087 hwnd
= create_listview_control(LVS_REPORT
);
2088 for (i
=0;i
<items
;i
++) {
2089 insert_item(hwnd
, 0);
2091 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2092 expect(items
,item_count
);
2094 /* try with NULL pointer */
2095 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, 0);
2098 /* select all, check notifications */
2099 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
2101 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2103 item
.stateMask
= LVIS_SELECTED
;
2104 item
.state
= LVIS_SELECTED
;
2105 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2108 ok_sequence(sequences
, PARENT_SEQ_INDEX
, select_all_parent_seq
,
2109 "select all notification", FALSE
);
2111 /* deselect all items */
2112 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
2113 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2115 ListView_SetItemState(hwnd
, i
, LVIS_SELECTED
, LVIS_SELECTED
);
2118 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2120 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2123 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2124 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2125 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2126 /* check that style is accepted */
2127 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2128 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2131 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2132 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2134 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2136 SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2139 /* select one more */
2140 ListView_SetItemState(hwnd
, 3, LVIS_SELECTED
, LVIS_SELECTED
);
2143 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2144 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2146 r
= ListView_GetItemState(hwnd
, 3, LVIS_SELECTED
);
2147 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2149 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2151 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2154 /* try to select all on LVS_SINGLESEL */
2155 memset(&item
, 0, sizeof(item
));
2156 item
.stateMask
= LVIS_SELECTED
;
2157 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2159 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2161 item
.stateMask
= LVIS_SELECTED
;
2162 item
.state
= LVIS_SELECTED
;
2163 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2166 r
= ListView_GetSelectedCount(hwnd
);
2168 r
= ListView_GetSelectionMark(hwnd
);
2171 /* try to deselect all on LVS_SINGLESEL */
2172 item
.stateMask
= LVIS_SELECTED
;
2173 item
.state
= LVIS_SELECTED
;
2174 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2177 item
.stateMask
= LVIS_SELECTED
;
2179 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2181 r
= ListView_GetSelectedCount(hwnd
);
2184 DestroyWindow(hwnd
);
2187 static void test_subitem_rect(void)
2195 /* test LVM_GETSUBITEMRECT for header */
2196 hwnd
= create_listview_control(LVS_REPORT
);
2197 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2198 /* add some columns */
2199 memset(&col
, 0, sizeof(LVCOLUMN
));
2200 col
.mask
= LVCF_WIDTH
;
2202 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2205 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2208 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2210 /* item = -1 means header, subitem index is 1 based */
2211 rect
.left
= LVIR_BOUNDS
;
2213 rect
.right
= rect
.bottom
= 0;
2214 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2217 rect
.left
= LVIR_BOUNDS
;
2219 rect
.right
= rect
.bottom
= 0;
2220 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2223 expect(100, rect
.left
);
2224 expect(250, rect
.right
);
2226 expect(3, rect
.top
);
2228 rect
.left
= LVIR_BOUNDS
;
2230 rect
.right
= rect
.bottom
= 0;
2231 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2234 expect(250, rect
.left
);
2235 expect(450, rect
.right
);
2237 expect(3, rect
.top
);
2239 /* item LVS_REPORT padding isn't applied to subitems */
2240 insert_item(hwnd
, 0);
2242 rect
.left
= LVIR_BOUNDS
;
2244 rect
.right
= rect
.bottom
= 0;
2245 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2247 expect(100, rect
.left
);
2248 expect(250, rect
.right
);
2250 rect
.left
= LVIR_ICON
;
2252 rect
.right
= rect
.bottom
= 0;
2253 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2255 /* no icon attached - zero width rectangle, with no left padding */
2256 expect(100, rect
.left
);
2257 expect(100, rect
.right
);
2259 rect
.left
= LVIR_LABEL
;
2261 rect
.right
= rect
.bottom
= 0;
2262 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2264 /* same as full LVIR_BOUNDS */
2265 expect(100, rect
.left
);
2266 expect(250, rect
.right
);
2268 SendMessage(hwnd
, LVM_SCROLL
, 10, 0);
2270 rect
.left
= LVIR_BOUNDS
;
2272 rect
.right
= rect
.bottom
= 0;
2273 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2275 expect(90, rect
.left
);
2276 expect(240, rect
.right
);
2278 SendMessage(hwnd
, LVM_SCROLL
, -10, 0);
2280 DestroyWindow(hwnd
);
2282 /* test subitem rects after re-arranging columns */
2283 hwnd
= create_listview_control(LVS_REPORT
);
2284 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2285 memset(&col
, 0, sizeof(LVCOLUMN
));
2286 col
.mask
= LVCF_WIDTH
;
2289 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2293 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2297 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2300 insert_item(hwnd
, 0);
2301 insert_item(hwnd
, 1);
2303 /* wrong item is refused for main item */
2304 rect
.left
= LVIR_BOUNDS
;
2306 rect
.right
= rect
.bottom
= -1;
2307 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect
);
2310 /* for subitems rectangle is calculated even if there's no item added */
2311 rect
.left
= LVIR_BOUNDS
;
2313 rect
.right
= rect
.bottom
= -1;
2314 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect
);
2317 rect2
.left
= LVIR_BOUNDS
;
2319 rect2
.right
= rect2
.bottom
= -1;
2320 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect2
);
2323 expect(rect
.right
, rect2
.right
);
2324 expect(rect
.left
, rect2
.left
);
2325 expect(rect
.bottom
, rect2
.top
);
2326 ok(rect2
.bottom
> rect2
.top
, "expected not zero height\n");
2329 arr
[0] = 1; arr
[1] = 0; arr
[2] = 2;
2330 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 3, (LPARAM
)arr
);
2333 rect
.left
= LVIR_BOUNDS
;
2335 rect
.right
= rect
.bottom
= -1;
2336 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2338 expect(0, rect
.left
);
2339 expect(600, rect
.right
);
2341 rect
.left
= LVIR_BOUNDS
;
2343 rect
.right
= rect
.bottom
= -1;
2344 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2346 expect(0, rect
.left
);
2347 expect(200, rect
.right
);
2349 rect2
.left
= LVIR_BOUNDS
;
2351 rect2
.right
= rect2
.bottom
= -1;
2352 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect2
);
2354 expect(0, rect2
.left
);
2355 expect(200, rect2
.right
);
2356 /* items are of the same height */
2357 ok(rect2
.top
> 0, "expected positive item height\n");
2358 expect(rect
.bottom
, rect2
.top
);
2359 expect(rect
.bottom
* 2 - rect
.top
, rect2
.bottom
);
2361 rect
.left
= LVIR_BOUNDS
;
2363 rect
.right
= rect
.bottom
= -1;
2364 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2366 expect(300, rect
.left
);
2367 expect(600, rect
.right
);
2369 DestroyWindow(hwnd
);
2371 /* try it for non LVS_REPORT style */
2372 hwnd
= CreateWindow("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2373 GetModuleHandle(NULL
), 0);
2374 rect
.left
= LVIR_BOUNDS
;
2376 rect
.right
= rect
.bottom
= -10;
2377 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2379 /* rect is unchanged */
2380 expect(0, rect
.left
);
2381 expect(-10, rect
.right
);
2382 expect(1, rect
.top
);
2383 expect(-10, rect
.bottom
);
2384 DestroyWindow(hwnd
);
2387 /* comparison callback for test_sorting */
2388 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2390 if (first
== second
) return 0;
2391 return (first
> second
? 1 : -1);
2394 static void test_sorting(void)
2400 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2403 hwnd
= create_listview_control(LVS_REPORT
);
2404 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2406 /* insert some items */
2407 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2408 item
.state
= LVIS_SELECTED
;
2412 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2415 item
.mask
= LVIF_PARAM
;
2419 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2422 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2423 item
.state
= LVIS_SELECTED
;
2427 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2430 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2433 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2436 r
= SendMessage(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2439 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2441 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2443 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2445 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2446 expect(LVIS_SELECTED
, r
);
2447 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2448 expect(LVIS_SELECTED
, r
);
2450 DestroyWindow(hwnd
);
2452 /* switch to LVS_SORTASCENDING when some items added */
2453 hwnd
= create_listview_control(LVS_REPORT
);
2454 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2456 item
.mask
= LVIF_TEXT
;
2459 item
.pszText
= names
[1];
2460 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2463 item
.mask
= LVIF_TEXT
;
2466 item
.pszText
= names
[2];
2467 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2470 item
.mask
= LVIF_TEXT
;
2473 item
.pszText
= names
[0];
2474 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2477 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2478 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2479 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2480 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2482 /* no sorting performed when switched to LVS_SORTASCENDING */
2483 item
.mask
= LVIF_TEXT
;
2485 item
.pszText
= buff
;
2486 item
.cchTextMax
= sizeof(buff
);
2487 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2489 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2492 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2494 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2497 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2499 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2501 /* adding new item doesn't resort list */
2502 item
.mask
= LVIF_TEXT
;
2505 item
.pszText
= names
[3];
2506 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2509 item
.mask
= LVIF_TEXT
;
2511 item
.pszText
= buff
;
2512 item
.cchTextMax
= sizeof(buff
);
2513 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2515 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2518 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2520 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2523 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2525 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2528 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2530 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2532 /* corner case - item should be placed at first position */
2533 item
.mask
= LVIF_TEXT
;
2536 item
.pszText
= names
[4];
2537 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2541 item
.pszText
= buff
;
2542 item
.cchTextMax
= sizeof(buff
);
2543 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2545 ok(lstrcmp(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2548 item
.pszText
= buff
;
2549 item
.cchTextMax
= sizeof(buff
);
2550 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2552 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2555 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2557 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2560 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2562 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2565 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2567 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2569 DestroyWindow(hwnd
);
2572 static void test_ownerdata(void)
2575 LONG_PTR style
, ret
;
2579 /* it isn't possible to set LVS_OWNERDATA after creation */
2582 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2586 hwnd
= create_listview_control(LVS_REPORT
);
2587 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2588 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2589 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2591 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2593 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2594 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2595 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2596 "try to switch to LVS_OWNERDATA seq", FALSE
);
2598 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2599 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2600 DestroyWindow(hwnd
);
2603 /* try to set LVS_OWNERDATA after creation just having it */
2604 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2605 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2606 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2607 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2609 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2611 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2612 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2613 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2614 "try to switch to LVS_OWNERDATA seq", FALSE
);
2615 DestroyWindow(hwnd
);
2617 /* try to remove LVS_OWNERDATA after creation just having it */
2620 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2624 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2625 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2626 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2627 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2629 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2631 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2632 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2633 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2634 "try to switch to LVS_OWNERDATA seq", FALSE
);
2635 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2636 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2637 DestroyWindow(hwnd
);
2640 /* try select an item */
2641 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2642 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2643 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2645 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2647 memset(&item
, 0, sizeof(item
));
2648 item
.stateMask
= LVIS_SELECTED
;
2649 item
.state
= LVIS_SELECTED
;
2650 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2652 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2654 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2656 DestroyWindow(hwnd
);
2658 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2659 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2660 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2661 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2663 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2665 memset(&item
, 0, sizeof(item
));
2666 item
.mask
= LVIF_STATE
;
2668 item
.stateMask
= LVIS_SELECTED
;
2669 item
.state
= LVIS_SELECTED
;
2670 res
= SendMessageA(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2672 DestroyWindow(hwnd
);
2674 /* check notifications after focused/selected changed */
2675 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2676 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2677 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
2680 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2682 memset(&item
, 0, sizeof(item
));
2683 item
.stateMask
= LVIS_SELECTED
;
2684 item
.state
= LVIS_SELECTED
;
2685 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2688 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2689 "ownerdata select notification", TRUE
);
2691 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2693 memset(&item
, 0, sizeof(item
));
2694 item
.stateMask
= LVIS_FOCUSED
;
2695 item
.state
= LVIS_FOCUSED
;
2696 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2699 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2700 "ownerdata focus notification", TRUE
);
2702 /* select all, check notifications */
2703 item
.stateMask
= LVIS_SELECTED
;
2705 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2708 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2710 item
.stateMask
= LVIS_SELECTED
;
2711 item
.state
= LVIS_SELECTED
;
2713 g_dump_itemchanged
= TRUE
;
2714 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2716 g_dump_itemchanged
= FALSE
;
2718 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2719 "ownerdata select all notification", TRUE
);
2721 /* select all again, note that all items are selected already */
2722 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2723 item
.stateMask
= LVIS_SELECTED
;
2724 item
.state
= 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_setstate_all_parent_seq
,
2730 "ownerdata select all notification", TRUE
);
2732 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2733 item
.stateMask
= LVIS_SELECTED
;
2735 g_dump_itemchanged
= TRUE
;
2736 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2738 g_dump_itemchanged
= FALSE
;
2739 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2740 "ownerdata deselect all notification", TRUE
);
2742 /* select one, then deselect all */
2743 item
.stateMask
= LVIS_SELECTED
;
2744 item
.state
= LVIS_SELECTED
;
2745 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2747 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2748 item
.stateMask
= LVIS_SELECTED
;
2750 g_dump_itemchanged
= TRUE
;
2751 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2753 g_dump_itemchanged
= FALSE
;
2754 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2755 "ownerdata select all notification", TRUE
);
2757 /* remove focused, try to focus all */
2758 item
.stateMask
= LVIS_FOCUSED
;
2759 item
.state
= LVIS_FOCUSED
;
2760 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2762 item
.stateMask
= LVIS_FOCUSED
;
2764 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2766 item
.stateMask
= LVIS_FOCUSED
;
2767 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
2769 /* setting all to focused returns failure value */
2770 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2771 item
.stateMask
= LVIS_FOCUSED
;
2772 item
.state
= LVIS_FOCUSED
;
2773 g_dump_itemchanged
= TRUE
;
2774 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2776 g_dump_itemchanged
= FALSE
;
2777 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2778 "ownerdata focus all notification", FALSE
);
2779 /* focus single item, remove all */
2780 item
.stateMask
= LVIS_FOCUSED
;
2781 item
.state
= LVIS_FOCUSED
;
2782 res
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2784 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2785 item
.stateMask
= LVIS_FOCUSED
;
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_defocus_all_parent_seq
,
2792 "ownerdata remove focus all notification", TRUE
);
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", TRUE
);
2803 /* all marked cut, try again */
2804 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2805 item
.stateMask
= LVIS_CUT
;
2806 item
.state
= LVIS_CUT
;
2807 g_dump_itemchanged
= TRUE
;
2808 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2810 g_dump_itemchanged
= FALSE
;
2811 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2812 "ownerdata cut all notification #2", TRUE
);
2814 DestroyWindow(hwnd
);
2816 /* check notifications on LVM_GETITEM */
2817 /* zero callback mask */
2818 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2819 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2820 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2823 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2825 memset(&item
, 0, sizeof(item
));
2826 item
.stateMask
= LVIS_SELECTED
;
2827 item
.mask
= LVIF_STATE
;
2828 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2831 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2832 "ownerdata getitem selected state 1", FALSE
);
2834 /* non zero callback mask but not we asking for */
2835 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
2838 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2840 memset(&item
, 0, sizeof(item
));
2841 item
.stateMask
= LVIS_SELECTED
;
2842 item
.mask
= LVIF_STATE
;
2843 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2846 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2847 "ownerdata getitem selected state 2", FALSE
);
2849 /* LVIS_OVERLAYMASK callback mask, asking for index */
2850 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2852 memset(&item
, 0, sizeof(item
));
2853 item
.stateMask
= LVIS_OVERLAYMASK
;
2854 item
.mask
= LVIF_STATE
;
2855 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2858 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
2859 "ownerdata getitem selected state 2", FALSE
);
2861 DestroyWindow(hwnd
);
2863 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2864 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
| 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 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2869 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
2870 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2871 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
2872 DestroyWindow(hwnd
);
2873 /* apparently it's allowed to switch these style on after creation */
2874 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2875 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2876 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2877 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2878 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2879 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2880 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2881 DestroyWindow(hwnd
);
2883 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2884 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2885 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2886 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2887 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
2888 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2889 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
2890 DestroyWindow(hwnd
);
2893 static void test_norecompute(void)
2895 static CHAR testA
[] = "test";
2901 /* self containing control */
2902 hwnd
= create_listview_control(LVS_REPORT
);
2903 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2904 memset(&item
, 0, sizeof(item
));
2905 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
2907 item
.stateMask
= LVIS_SELECTED
;
2908 item
.state
= LVIS_SELECTED
;
2909 item
.pszText
= testA
;
2910 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2912 /* retrieve with LVIF_NORECOMPUTE */
2913 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2915 item
.pszText
= buff
;
2916 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2917 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2919 ok(lstrcmp(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
2921 item
.mask
= LVIF_TEXT
;
2923 item
.pszText
= LPSTR_TEXTCALLBACK
;
2924 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2927 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2929 item
.pszText
= buff
;
2930 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2932 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2933 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2935 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2936 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2937 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
2939 DestroyWindow(hwnd
);
2942 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2943 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2945 item
.mask
= LVIF_STATE
;
2946 item
.stateMask
= LVIS_SELECTED
;
2947 item
.state
= LVIS_SELECTED
;
2949 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2952 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2954 item
.pszText
= buff
;
2955 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2956 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2957 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2959 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2960 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2961 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
2963 DestroyWindow(hwnd
);
2966 static void test_nosortheader(void)
2971 hwnd
= create_listview_control(LVS_REPORT
);
2972 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2974 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2975 ok(IsWindow(header
), "header expected\n");
2977 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2978 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
2980 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2981 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
2982 /* HDS_BUTTONS retained */
2983 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2984 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
2986 DestroyWindow(hwnd
);
2988 /* create with LVS_NOSORTHEADER */
2989 hwnd
= create_listview_control(LVS_NOSORTHEADER
| LVS_REPORT
);
2990 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2992 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
2993 ok(IsWindow(header
), "header expected\n");
2995 style
= GetWindowLongPtr(header
, GWL_STYLE
);
2996 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
2998 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
2999 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
3000 /* not changed here */
3001 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3002 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3004 DestroyWindow(hwnd
);
3007 static void test_setredraw(void)
3015 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3016 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3018 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3019 ListView seems to handle it internally without DefWinProc */
3021 /* default value first */
3022 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3025 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3026 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3027 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3029 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3030 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3031 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3034 /* check update rect after redrawing */
3035 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3037 InvalidateRect(hwnd
, NULL
, FALSE
);
3038 RedrawWindow(hwnd
, NULL
, NULL
, RDW_UPDATENOW
);
3039 rect
.right
= rect
.bottom
= 1;
3040 GetUpdateRect(hwnd
, &rect
, FALSE
);
3041 expect(0, rect
.right
);
3042 expect(0, rect
.bottom
);
3045 hdc
= GetWindowDC(hwndparent
);
3046 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3048 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3050 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3052 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3054 ReleaseDC(hwndparent
, hdc
);
3056 /* check notification messages to show that repainting is disabled */
3057 ret
= SendMessage(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3059 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3061 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3063 InvalidateRect(hwnd
, NULL
, TRUE
);
3065 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3066 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
3068 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
3070 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3071 InvalidateRect(hwnd
, NULL
, TRUE
);
3073 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3074 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
3076 /* message isn't forwarded to header */
3077 subclass_header(hwnd
);
3078 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3079 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3081 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
3082 "WM_SETREDRAW: not forwarded to header", FALSE
);
3084 DestroyWindow(hwnd
);
3087 static void test_hittest(void)
3093 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3097 HIMAGELIST himl
, himl2
;
3100 hwnd
= create_listview_control(LVS_REPORT
);
3101 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3103 /* LVS_REPORT with a single subitem (2 columns) */
3104 insert_column(hwnd
, 0);
3105 insert_column(hwnd
, 1);
3106 insert_item(hwnd
, 0);
3109 /* the only purpose of that line is to be as long as a half item rect */
3110 item
.pszText
= text
;
3111 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
3114 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3116 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3119 memset(&bounds
, 0, sizeof(bounds
));
3120 bounds
.left
= LVIR_BOUNDS
;
3121 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
3123 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
3124 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
3125 r
= SendMessage(hwnd
, LVM_GETITEMSPACING
, TRUE
, 0);
3127 ok(bounds
.bottom
- bounds
.top
== vert
,
3128 "Vertical spacing inconsistent (%d != %d)\n", bounds
.bottom
- bounds
.top
, vert
);
3129 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
3132 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3134 /* outside columns by x position - valid is [0, 199] */
3136 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3137 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TOLEFT
, 0, FALSE
, FALSE
);
3138 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3140 x
= pos
.x
+ 50; /* column half width */
3141 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3142 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, 0, FALSE
, FALSE
);
3143 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3144 x
= pos
.x
+ 150; /* outside column */
3145 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3146 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3147 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3148 y
= (bounds
.bottom
- bounds
.top
) / 2;
3149 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3150 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3151 /* outside possible client rectangle (to right) */
3153 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3154 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3155 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3156 y
= (bounds
.bottom
- bounds
.top
) / 2;
3157 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3158 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3159 /* subitem returned with -1 item too */
3161 y
= bounds
.top
- vert
;
3162 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3163 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3164 /* return values appear to underflow with negative indices */
3168 test_lvm_subitemhittest(hwnd
, x
, y
, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3169 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3173 /* parent client area is 100x100 by default */
3174 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
3175 x
= pos
.x
+ 150; /* outside column */
3176 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3177 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, FALSE
);
3178 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3179 y
= (bounds
.bottom
- bounds
.top
) / 2;
3180 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, TRUE
);
3181 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3182 /* the same with LVS_EX_FULLROWSELECT */
3183 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3184 x
= pos
.x
+ 150; /* outside column */
3185 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3186 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, LVHT_ONITEMLABEL
, FALSE
, FALSE
);
3187 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3188 y
= (bounds
.bottom
- bounds
.top
) / 2;
3189 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3190 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
3191 x
= pos
.x
+ 150; /* outside column */
3192 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3193 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3194 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3195 y
= (bounds
.bottom
- bounds
.top
) / 2;
3196 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3197 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3198 /* outside possible client rectangle (to right) */
3200 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3201 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3202 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3203 y
= (bounds
.bottom
- bounds
.top
) / 2;
3204 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3205 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3206 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3207 himl
= ImageList_Create(16, 16, 0, 4, 4);
3208 ok(himl
!= NULL
, "failed to create imagelist\n");
3209 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3210 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3211 r
= ImageList_Add(himl
, hbmp
, 0);
3212 ok(r
== 0, "should be zero\n");
3213 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3214 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3215 r
= ImageList_Add(himl
, hbmp
, 0);
3216 ok(r
== 1, "should be one\n");
3218 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3221 item
.mask
= LVIF_IMAGE
;
3225 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3229 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3230 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3231 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3232 y
= (bounds
.bottom
- bounds
.top
) / 2;
3233 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3235 /* state icons indices are 1 based, check with valid index */
3236 item
.mask
= LVIF_STATE
;
3237 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3238 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3241 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3245 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3246 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3247 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3248 y
= (bounds
.bottom
- bounds
.top
) / 2;
3249 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3251 himl2
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3252 ok(himl2
== himl
, "should return handle\n");
3254 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3258 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3259 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, 0, FALSE
, FALSE
);
3260 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3261 y
= (bounds
.bottom
- bounds
.top
) / 2;
3262 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3264 DestroyWindow(hwnd
);
3267 static void test_getviewrect(void)
3274 hwnd
= create_listview_control(LVS_REPORT
);
3275 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3278 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3281 insert_column(hwnd
, 0);
3282 insert_column(hwnd
, 1);
3284 memset(&item
, 0, sizeof(item
));
3287 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3289 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3291 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3294 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3295 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3297 /* left is set to (2e31-1) - XP SP2 */
3298 expect(0, rect
.right
);
3299 expect(0, rect
.top
);
3300 expect(0, rect
.bottom
);
3302 /* switch to LVS_ICON */
3303 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3305 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3306 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3308 expect(0, rect
.left
);
3309 expect(0, rect
.top
);
3310 /* precise value differs for 2k, XP and Vista */
3311 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3312 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3314 DestroyWindow(hwnd
);
3317 static void test_getitemposition(void)
3324 hwnd
= create_listview_control(LVS_REPORT
);
3325 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3326 header
= subclass_header(hwnd
);
3328 /* LVS_REPORT, single item, no columns added */
3329 insert_item(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_seq1
, "get item position 1", FALSE
);
3338 /* LVS_REPORT, single item, single column */
3339 insert_column(hwnd
, 0);
3341 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3344 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3346 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3348 memset(&rect
, 0, sizeof(rect
));
3349 SendMessage(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3352 /* offset by header height */
3353 expect(rect
.bottom
- rect
.top
, pt
.y
);
3355 DestroyWindow(hwnd
);
3358 static void test_columnscreation(void)
3363 hwnd
= create_listview_control(LVS_REPORT
);
3364 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3366 insert_item(hwnd
, 0);
3368 /* headers columns aren't created automatically */
3369 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3370 ok(IsWindow(header
), "Expected header handle\n");
3371 r
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
3374 DestroyWindow(hwnd
);
3377 static void test_getitemrect(void)
3380 HIMAGELIST himl
, himl_ret
;
3390 /* rectangle isn't empty for empty text items */
3391 hwnd
= create_listview_control(LVS_LIST
);
3392 memset(&item
, 0, sizeof(item
));
3395 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3397 rect
.left
= LVIR_LABEL
;
3398 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3400 expect(0, rect
.left
);
3401 expect(0, rect
.top
);
3403 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, rect
.right
);
3404 ReleaseDC(hwnd
, hdc
);
3405 DestroyWindow(hwnd
);
3407 hwnd
= create_listview_control(LVS_REPORT
);
3408 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3411 memset(&item
, 0, sizeof(item
));
3414 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3417 rect
.left
= LVIR_BOUNDS
;
3418 rect
.right
= rect
.top
= rect
.bottom
= -1;
3419 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3422 /* zero width rectangle with no padding */
3423 expect(0, rect
.left
);
3424 expect(0, rect
.right
);
3426 insert_column(hwnd
, 0);
3427 insert_column(hwnd
, 1);
3429 col
.mask
= LVCF_WIDTH
;
3431 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 0, (LPARAM
)&col
);
3434 col
.mask
= LVCF_WIDTH
;
3436 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 1, (LPARAM
)&col
);
3439 rect
.left
= LVIR_BOUNDS
;
3440 rect
.right
= rect
.top
= rect
.bottom
= -1;
3441 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3444 /* still no left padding */
3445 expect(0, rect
.left
);
3446 expect(150, rect
.right
);
3448 rect
.left
= LVIR_SELECTBOUNDS
;
3449 rect
.right
= rect
.top
= rect
.bottom
= -1;
3450 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3453 expect(2, rect
.left
);
3455 rect
.left
= LVIR_LABEL
;
3456 rect
.right
= rect
.top
= rect
.bottom
= -1;
3457 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3459 /* padding, column width */
3460 expect(2, rect
.left
);
3461 expect(50, rect
.right
);
3463 /* no icons attached */
3464 rect
.left
= LVIR_ICON
;
3465 rect
.right
= rect
.top
= rect
.bottom
= -1;
3466 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3469 expect(2, rect
.left
);
3470 expect(2, rect
.right
);
3473 order
[0] = 1; order
[1] = 0;
3474 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3477 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3479 /* 1 indexed column width + padding */
3481 /* rect is at zero too */
3482 rect
.left
= LVIR_BOUNDS
;
3483 rect
.right
= rect
.top
= rect
.bottom
= -1;
3484 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3486 expect(0, rect
.left
);
3487 /* just width sum */
3488 expect(150, rect
.right
);
3490 rect
.left
= LVIR_SELECTBOUNDS
;
3491 rect
.right
= rect
.top
= rect
.bottom
= -1;
3492 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3494 /* column width + padding */
3495 expect(102, rect
.left
);
3497 /* back to initial order */
3498 order
[0] = 0; order
[1] = 1;
3499 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3503 himl
= ImageList_Create(16, 16, 0, 2, 2);
3504 ok(himl
!= NULL
, "failed to create imagelist\n");
3505 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3506 ok(hbm
!= NULL
, "failed to create bitmap\n");
3507 r
= ImageList_Add(himl
, hbm
, 0);
3509 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3510 ok(hbm
!= NULL
, "failed to create bitmap\n");
3511 r
= ImageList_Add(himl
, hbm
, 0);
3514 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3517 item
.mask
= LVIF_STATE
;
3518 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3519 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3522 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3526 rect
.left
= LVIR_ICON
;
3527 rect
.right
= rect
.top
= rect
.bottom
= -1;
3528 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3530 /* padding + stateicon width */
3531 expect(18, rect
.left
);
3532 expect(18, rect
.right
);
3534 rect
.left
= LVIR_LABEL
;
3535 rect
.right
= rect
.top
= rect
.bottom
= -1;
3536 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3538 /* padding + stateicon width -> column width */
3539 expect(18, rect
.left
);
3540 expect(50, rect
.right
);
3542 himl_ret
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3543 ok(himl_ret
== himl
, "got %p, expected %p\n", himl_ret
, himl
);
3545 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3548 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3551 item
.stateMask
= ~0;
3554 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3558 rect
.left
= LVIR_ICON
;
3559 rect
.right
= rect
.top
= rect
.bottom
= -1;
3560 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3562 /* padding, icon width */
3563 expect(2, rect
.left
);
3564 expect(18, rect
.right
);
3566 rect
.left
= LVIR_LABEL
;
3567 rect
.right
= rect
.top
= rect
.bottom
= -1;
3568 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3570 /* padding + icon width -> column width */
3571 expect(18, rect
.left
);
3572 expect(50, rect
.right
);
3575 rect
.left
= LVIR_SELECTBOUNDS
;
3576 rect
.right
= rect
.top
= rect
.bottom
= -1;
3577 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3579 /* padding, column width */
3580 expect(2, rect
.left
);
3581 expect(50, rect
.right
);
3583 /* try with indentation */
3584 item
.mask
= LVIF_INDENT
;
3588 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3592 rect
.left
= LVIR_BOUNDS
;
3593 rect
.right
= rect
.top
= rect
.bottom
= -1;
3594 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3596 /* padding + 1 icon width, column width */
3597 expect(0, rect
.left
);
3598 expect(150, rect
.right
);
3601 rect
.left
= LVIR_SELECTBOUNDS
;
3602 rect
.right
= rect
.top
= rect
.bottom
= -1;
3603 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3605 /* padding + 1 icon width, column width */
3606 expect(2 + 16, rect
.left
);
3607 expect(50, rect
.right
);
3610 rect
.left
= LVIR_LABEL
;
3611 rect
.right
= rect
.top
= rect
.bottom
= -1;
3612 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3614 /* padding + 2 icon widths, column width */
3615 expect(2 + 16*2, rect
.left
);
3616 expect(50, rect
.right
);
3619 rect
.left
= LVIR_ICON
;
3620 rect
.right
= rect
.top
= rect
.bottom
= -1;
3621 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3623 /* padding + 1 icon width indentation, icon width */
3624 expect(2 + 16, rect
.left
);
3625 expect(34, rect
.right
);
3627 DestroyWindow(hwnd
);
3630 static void test_editbox(void)
3632 static CHAR testitemA
[] = "testitem";
3633 static CHAR testitem1A
[] = "testitem_quitelongname";
3634 static CHAR testitem2A
[] = "testITEM_quitelongname";
3635 static CHAR buffer
[25];
3636 HWND hwnd
, hwndedit
, hwndedit2
, header
;
3640 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
3641 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3643 insert_column(hwnd
, 0);
3645 memset(&item
, 0, sizeof(item
));
3646 item
.mask
= LVIF_TEXT
;
3647 item
.pszText
= testitemA
;
3650 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3653 /* test notifications without edit created */
3654 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3655 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)0xdeadbeef);
3657 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3658 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE
);
3659 /* same thing but with valid window */
3660 hwndedit
= CreateWindowA("Edit", "Test edit", WS_VISIBLE
| WS_CHILD
, 0, 0, 20,
3661 10, hwnd
, (HMENU
)1, (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
), 0);
3662 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3663 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)hwndedit
);
3665 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3666 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE
);
3667 DestroyWindow(hwndedit
);
3669 /* setting focus is necessary */
3671 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3672 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3674 /* test children Z-order after Edit box created */
3675 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3676 ok(IsWindow(header
), "Expected header to be created\n");
3677 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
3678 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
3680 /* modify initial string */
3681 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3684 /* edit window is resized and repositioned,
3685 check again for Z-order - it should be preserved */
3686 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
3687 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
3689 /* return focus to listview */
3692 memset(&item
, 0, sizeof(item
));
3693 item
.mask
= LVIF_TEXT
;
3694 item
.pszText
= buffer
;
3695 item
.cchTextMax
= sizeof(buffer
);
3698 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3701 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3703 /* send LVM_EDITLABEL on already created edit */
3705 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3706 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3707 /* focus will be set to edit */
3708 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
3709 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3710 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
3712 /* creating label disabled when control isn't focused */
3714 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3715 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3717 /* check EN_KILLFOCUS handling */
3718 memset(&item
, 0, sizeof(item
));
3719 item
.pszText
= testitemA
;
3722 r
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3726 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3727 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3728 /* modify edit and notify control that it lost focus */
3729 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3731 g_editbox_disp_info
.item
.pszText
= NULL
;
3732 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3734 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "expected notification with not null text\n");
3736 memset(&item
, 0, sizeof(item
));
3737 item
.pszText
= buffer
;
3738 item
.cchTextMax
= sizeof(buffer
);
3741 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3742 expect(lstrlen(item
.pszText
), r
);
3743 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3744 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
3746 /* change item name to differ in casing only */
3748 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3749 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3750 /* modify edit and notify control that it lost focus */
3751 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem2A
);
3753 g_editbox_disp_info
.item
.pszText
= NULL
;
3754 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3756 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "got %p\n", g_editbox_disp_info
.item
.pszText
);
3758 memset(&item
, 0, sizeof(item
));
3759 item
.pszText
= buffer
;
3760 item
.cchTextMax
= sizeof(buffer
);
3763 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3764 expect(lstrlen(item
.pszText
), r
);
3765 ok(strcmp(buffer
, testitem2A
) == 0, "got %s, expected %s\n", buffer
, testitem2A
);
3766 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
3768 /* end edit without saving */
3770 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3771 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3772 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
3774 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3775 "edit box - end edit, no change, escape", TRUE
);
3776 /* end edit with saving */
3778 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3779 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3780 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_RETURN
, 0);
3782 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3783 "edit box - end edit, no change, return", TRUE
);
3785 memset(&item
, 0, sizeof(item
));
3786 item
.pszText
= buffer
;
3787 item
.cchTextMax
= sizeof(buffer
);
3790 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3791 expect(lstrlen(item
.pszText
), r
);
3792 ok(strcmp(buffer
, testitem2A
) == 0, "Expected item text to change\n");
3794 /* LVM_EDITLABEL with -1 destroys current edit */
3795 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
3796 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3797 /* no edit present */
3798 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3799 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3800 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3801 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3803 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3804 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3805 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3806 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3807 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3808 /* check another negative value */
3809 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3810 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3811 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3812 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -2, 0);
3813 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3814 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3815 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3816 /* and value greater than max item index */
3817 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3818 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3819 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3820 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3821 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, r
, 0);
3822 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3823 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3824 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3826 /* messaging tests */
3828 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3830 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3831 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3832 /* testing only sizing messages */
3833 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
3834 "edit box create - sizing", FALSE
);
3836 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
3838 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3839 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3840 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3841 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3843 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3844 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE
);
3846 DestroyWindow(hwnd
);
3849 static void test_notifyformat(void)
3854 hwnd
= create_listview_control(LVS_REPORT
);
3855 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3857 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3858 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3859 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3861 SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3863 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
3865 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3868 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
3870 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3875 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3876 DestroyWindow(hwnd
);
3880 DestroyWindow(hwnd
);
3882 /* test failure in parent WM_NOTIFYFORMAT */
3884 hwnd
= create_listview_control(LVS_REPORT
);
3885 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3886 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3887 ok(IsWindow(header
), "expected header to be created\n");
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
);
3892 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3893 ok(r
!= 0, "Expected valid format\n");
3895 notifyFormat
= NFR_UNICODE
;
3896 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3897 expect(NFR_UNICODE
, r
);
3898 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3900 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3901 ok( r
== 1 || broken(r
== 0), /* win9x */ "Expected 1, got %d\n", r
);
3903 notifyFormat
= NFR_ANSI
;
3904 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3905 expect(NFR_ANSI
, r
);
3906 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3908 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3909 ok( r
== 1 || broken(r
== 0), /* win9x */ "Expected 1, got %d\n", r
);
3911 DestroyWindow(hwnd
);
3913 /* try different unicode window combination and defaults */
3914 if (!GetModuleHandleW(NULL
))
3916 win_skip("Additional notify format tests are incompatible with Win9x\n");
3920 hwndparentW
= create_parent_window(TRUE
);
3921 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
3922 if (!IsWindow(hwndparentW
)) return;
3925 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3926 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3927 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3928 ok(IsWindow(header
), "expected header to be created\n");
3929 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3931 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3933 DestroyWindow(hwnd
);
3934 /* receiving error code defaulting to ansi */
3936 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3937 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3938 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3939 ok(IsWindow(header
), "expected header to be created\n");
3940 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3942 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3944 DestroyWindow(hwnd
);
3945 /* receiving ansi code from unicode window, use it */
3946 notifyFormat
= NFR_ANSI
;
3947 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3948 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3949 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3950 ok(IsWindow(header
), "expected header to be created\n");
3951 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3953 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3955 DestroyWindow(hwnd
);
3956 /* unicode listview with ansi parent window */
3958 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
3959 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3960 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3961 ok(IsWindow(header
), "expected header to be created\n");
3962 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3964 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3966 DestroyWindow(hwnd
);
3967 /* unicode listview with ansi parent window, return error code */
3969 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
3970 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3971 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3972 ok(IsWindow(header
), "expected header to be created\n");
3973 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3975 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3977 DestroyWindow(hwnd
);
3979 DestroyWindow(hwndparentW
);
3982 static void test_indentation(void)
3988 hwnd
= create_listview_control(LVS_REPORT
);
3989 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3991 memset(&item
, 0, sizeof(item
));
3992 item
.mask
= LVIF_INDENT
;
3994 item
.iIndent
= I_INDENTCALLBACK
;
3995 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3998 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4001 item
.mask
= LVIF_INDENT
;
4002 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
4005 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
4006 "get indent dispinfo", FALSE
);
4008 DestroyWindow(hwnd
);
4011 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
4016 static BOOL
is_below_comctl_5(void)
4021 hwnd
= create_listview_control(LVS_REPORT
);
4022 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4023 insert_item(hwnd
, 0);
4025 ret
= SendMessage(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
4027 DestroyWindow(hwnd
);
4032 static void test_get_set_view(void)
4038 /* test style->view mapping */
4039 hwnd
= create_listview_control(LVS_REPORT
);
4040 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4042 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4043 expect(LV_VIEW_DETAILS
, ret
);
4045 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4047 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
4048 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4049 expect(LV_VIEW_ICON
, ret
);
4051 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4052 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
4053 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4054 expect(LV_VIEW_SMALLICON
, ret
);
4056 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4057 SetWindowLongPtr(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
4058 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4059 expect(LV_VIEW_LIST
, ret
);
4061 /* switching view doesn't touch window style */
4062 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
4064 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4065 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4066 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
4068 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4069 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4070 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
4072 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4073 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4075 DestroyWindow(hwnd
);
4078 static void test_canceleditlabel(void)
4080 HWND hwnd
, hwndedit
;
4084 static CHAR test
[] = "test";
4085 static const CHAR test1
[] = "test1";
4087 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4088 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4090 insert_item(hwnd
, 0);
4092 /* try without edit created */
4093 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4094 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4096 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4097 "cancel edit label without edit", FALSE
);
4099 /* cancel without data change */
4101 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4102 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4103 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4105 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4107 /* cancel after data change */
4108 memset(&itema
, 0, sizeof(itema
));
4109 itema
.pszText
= test
;
4110 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
4113 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4114 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4115 ret
= SetWindowText(hwndedit
, test1
);
4117 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4119 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4120 memset(&itema
, 0, sizeof(itema
));
4121 itema
.pszText
= buff
;
4122 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
4123 ret
= SendMessage(hwnd
, LVM_GETITEMTEXT
, 0, (LPARAM
)&itema
);
4125 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
4127 DestroyWindow(hwnd
);
4130 static void test_mapidindex(void)
4135 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4136 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
4137 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4138 insert_item(hwnd
, 0);
4139 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4141 DestroyWindow(hwnd
);
4143 hwnd
= create_listview_control(LVS_REPORT
);
4144 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4146 /* LVM_MAPINDEXTOID with invalid index */
4147 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4150 insert_item(hwnd
, 0);
4151 insert_item(hwnd
, 1);
4153 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
4155 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
4158 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4160 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4162 /* remove 0 indexed item, id retained */
4163 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
4164 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4166 /* new id starts from previous value */
4167 insert_item(hwnd
, 1);
4168 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4171 /* get index by id */
4172 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
4174 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
4176 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
4178 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
4181 DestroyWindow(hwnd
);
4184 static void test_getitemspacing(void)
4193 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
4194 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
4197 hwnd
= create_listview_control(LVS_ICON
);
4198 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4200 expect(cx
, LOWORD(ret
));
4201 expect(cy
, HIWORD(ret
));
4203 /* now try with icons */
4204 himl
= ImageList_Create(40, 40, 0, 4, 4);
4205 ok(himl
!= NULL
, "failed to create imagelist\n");
4206 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4207 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4208 ret
= ImageList_Add(himl
, hbmp
, 0);
4210 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4213 itema
.mask
= LVIF_IMAGE
;
4217 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
4219 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4221 /* spacing + icon size returned */
4222 expect(cx
+ 40, LOWORD(ret
));
4223 expect(cy
+ 40, HIWORD(ret
));
4225 DestroyWindow(hwnd
);
4227 hwnd
= create_listview_control(LVS_SMALLICON
);
4228 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4230 expect(cx
, LOWORD(ret
));
4231 expect(cy
, HIWORD(ret
));
4233 DestroyWindow(hwnd
);
4235 hwnd
= create_listview_control(LVS_REPORT
);
4236 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4238 expect(cx
, LOWORD(ret
));
4239 expect(cy
, HIWORD(ret
));
4241 DestroyWindow(hwnd
);
4243 hwnd
= create_listview_control(LVS_LIST
);
4244 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4246 expect(cx
, LOWORD(ret
));
4247 expect(cy
, HIWORD(ret
));
4249 DestroyWindow(hwnd
);
4252 static void test_getcolumnwidth(void)
4261 /* default column width */
4262 hwnd
= create_listview_control(LVS_ICON
);
4263 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4265 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4266 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
4267 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4268 todo_wine
expect(8, ret
);
4269 style
= GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
4270 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
4272 ret
= SendMessage(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4274 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4276 DestroyWindow(hwnd
);
4278 /* default column width with item added */
4279 hwnd
= create_listview_control(LVS_LIST
);
4280 memset(&itema
, 0, sizeof(itema
));
4281 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4282 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4284 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, ret
);
4285 ReleaseDC(hwnd
, hdc
);
4286 DestroyWindow(hwnd
);
4289 static void test_scrollnotify(void)
4294 hwnd
= create_listview_control(LVS_REPORT
);
4296 insert_column(hwnd
, 0);
4297 insert_column(hwnd
, 1);
4298 insert_item(hwnd
, 0);
4300 /* make it scrollable - resize */
4301 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
4303 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
4306 /* try with dummy call */
4307 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4308 ret
= SendMessage(hwnd
, LVM_SCROLL
, 0, 0);
4310 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4311 "scroll notify 1", TRUE
);
4313 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4314 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 0);
4316 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4317 "scroll notify 2", TRUE
);
4319 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4320 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 1);
4322 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4323 "scroll notify 3", TRUE
);
4325 DestroyWindow(hwnd
);
4328 static void test_LVS_EX_TRANSPARENTBKGND(void)
4334 hwnd
= create_listview_control(LVS_REPORT
);
4336 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4339 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4340 LVS_EX_TRANSPARENTBKGND
);
4342 ret
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, 0);
4343 if (ret
!= CLR_NONE
)
4345 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4346 DestroyWindow(hwnd
);
4350 /* try to set some back color and check this style bit */
4351 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4353 ret
= SendMessage(hwnd
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
4354 ok(!(ret
& LVS_EX_TRANSPARENTBKGND
), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4356 /* now test what this style actually does */
4357 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4358 LVS_EX_TRANSPARENTBKGND
);
4360 hdc
= GetWindowDC(hwndparent
);
4362 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4363 SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
4364 ok_sequence(sequences
, PARENT_SEQ_INDEX
, lvs_ex_transparentbkgnd_seq
,
4365 "LVS_EX_TRANSPARENTBKGND parent", FALSE
);
4367 ReleaseDC(hwndparent
, hdc
);
4369 DestroyWindow(hwnd
);
4372 static void test_approximate_viewrect(void)
4379 static CHAR test
[] = "abracadabra, a very long item label";
4381 hwnd
= create_listview_control(LVS_ICON
);
4382 himl
= ImageList_Create(40, 40, 0, 4, 4);
4383 ok(himl
!= NULL
, "failed to create imagelist\n");
4384 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4385 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4386 ret
= ImageList_Add(himl
, hbmp
, 0);
4388 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4391 itema
.mask
= LVIF_IMAGE
;
4395 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
4398 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(75, 75));
4402 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4406 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4407 expect(MAKELONG(77,827), ret
);
4409 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(50, 50));
4410 ok(ret
!= 0, "got 0\n");
4412 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4413 expect(MAKELONG(102,302), ret
);
4415 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4416 expect(MAKELONG(52,52), ret
);
4418 itema
.pszText
= test
;
4419 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
4421 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4422 expect(MAKELONG(52,52), ret
);
4424 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 0, MAKELPARAM(100,100));
4425 expect(MAKELONG(52,2), ret
);
4426 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 1, MAKELPARAM(100,100));
4427 expect(MAKELONG(52,52), ret
);
4428 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 2, MAKELPARAM(100,100));
4429 expect(MAKELONG(102,52), ret
);
4430 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 3, MAKELPARAM(100,100));
4431 expect(MAKELONG(102,102), ret
);
4432 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 4, MAKELPARAM(100,100));
4433 expect(MAKELONG(102,102), ret
);
4434 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 5, MAKELPARAM(100,100));
4435 expect(MAKELONG(102,152), ret
);
4436 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 6, MAKELPARAM(100,100));
4437 expect(MAKELONG(102,152), ret
);
4438 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 7, MAKELPARAM(160,100));
4439 expect(MAKELONG(152,152), ret
);
4441 DestroyWindow(hwnd
);
4444 static void test_finditem(void)
4451 hwnd
= create_listview_control(LVS_REPORT
);
4452 insert_item(hwnd
, 0);
4454 memset(&fi
, 0, sizeof(fi
));
4456 /* full string search, inserted text was "foo" */
4458 fi
.flags
= LVFI_STRING
;
4460 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4462 /* partial string search, inserted text was "foo" */
4464 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4466 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4468 /* partial string search, part after start char */
4470 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4472 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4475 /* try with LVFI_SUBSTRING */
4477 fi
.flags
= LVFI_SUBSTRING
;
4479 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4482 win_skip("LVFI_SUBSTRING not supported\n");
4483 DestroyWindow(hwnd
);
4488 fi
.flags
= LVFI_SUBSTRING
;
4490 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4493 fi
.flags
= LVFI_SUBSTRING
;
4495 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4499 fi
.flags
= LVFI_SUBSTRING
| LVFI_STRING
;
4501 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4504 DestroyWindow(hwnd
);
4507 static void test_LVS_EX_HEADERINALLVIEWS(void)
4512 hwnd
= create_listview_control(LVS_ICON
);
4514 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4515 LVS_EX_HEADERINALLVIEWS
);
4517 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4518 if (!IsWindow(header
))
4520 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4521 DestroyWindow(hwnd
);
4525 /* LVS_NOCOLUMNHEADER works as before */
4526 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4527 SetWindowLongW(hwnd
, GWL_STYLE
, style
| LVS_NOCOLUMNHEADER
);
4528 style
= GetWindowLongA(header
, GWL_STYLE
);
4529 ok(style
& HDS_HIDDEN
, "Expected HDS_HIDDEN\n");
4530 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4531 SetWindowLongW(hwnd
, GWL_STYLE
, style
& ~LVS_NOCOLUMNHEADER
);
4532 style
= GetWindowLongA(header
, GWL_STYLE
);
4533 ok(!(style
& HDS_HIDDEN
), "Expected HDS_HIDDEN to be unset\n");
4535 /* try to remove style */
4536 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
, 0);
4537 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4538 ok(IsWindow(header
), "Expected header to be created\n");
4539 style
= GetWindowLongA(header
, GWL_STYLE
);
4540 ok(!(style
& HDS_HIDDEN
), "HDS_HIDDEN not expected\n");
4542 DestroyWindow(hwnd
);
4544 /* check other styles */
4545 hwnd
= create_listview_control(LVS_LIST
);
4546 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4547 LVS_EX_HEADERINALLVIEWS
);
4548 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4549 ok(IsWindow(header
), "Expected header to be created\n");
4550 DestroyWindow(hwnd
);
4552 hwnd
= create_listview_control(LVS_SMALLICON
);
4553 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4554 LVS_EX_HEADERINALLVIEWS
);
4555 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4556 ok(IsWindow(header
), "Expected header to be created\n");
4557 DestroyWindow(hwnd
);
4559 hwnd
= create_listview_control(LVS_REPORT
);
4560 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4561 LVS_EX_HEADERINALLVIEWS
);
4562 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4563 ok(IsWindow(header
), "Expected header to be created\n");
4564 DestroyWindow(hwnd
);
4567 static void test_hover(void)
4572 hwnd
= create_listview_control(LVS_ICON
);
4574 /* test WM_MOUSEHOVER forwarding */
4575 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4576 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
4578 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER allow test", TRUE
);
4579 g_block_hover
= TRUE
;
4580 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4581 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
4583 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER block test", TRUE
);
4584 g_block_hover
= FALSE
;
4586 r
= SendMessage(hwnd
, LVM_SETHOVERTIME
, 0, 500);
4587 expect(HOVER_DEFAULT
, r
);
4588 r
= SendMessage(hwnd
, LVM_GETHOVERTIME
, 0, 0);
4591 DestroyWindow(hwnd
);
4594 static void test_destroynotify(void)
4598 hwnd
= create_listview_control(LVS_REPORT
);
4599 ok(hwnd
!= NULL
, "failed to create listview window\n");
4601 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4602 DestroyWindow(hwnd
);
4603 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_destroy
, "check destroy order", FALSE
);
4606 static void test_header_notification(void)
4608 static char textA
[] = "newtext";
4616 list
= create_listview_control(LVS_REPORT
);
4617 ok(list
!= NULL
, "failed to create listview window\n");
4619 memset(&col
, 0, sizeof(col
));
4620 col
.mask
= LVCF_WIDTH
;
4622 ret
= SendMessage(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4625 /* check list parent notification after header item changed,
4626 this test should be placed before header subclassing to avoid
4627 Listview -> Header messages to be logged */
4628 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4630 col
.mask
= LVCF_TEXT
;
4631 col
.pszText
= textA
;
4632 r
= SendMessage(list
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
4635 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_changed_seq
,
4636 "header notify, listview", FALSE
);
4637 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4638 "header notify, parent", FALSE
);
4640 header
= subclass_header(list
);
4642 ret
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
4645 memset(&item
, 0, sizeof(item
));
4646 item
.mask
= HDI_WIDTH
;
4647 ret
= SendMessage(header
, HDM_GETITEMA
, 0, (LPARAM
)&item
);
4649 expect(100, item
.cxy
);
4651 nmh
.hdr
.hwndFrom
= header
;
4652 nmh
.hdr
.idFrom
= GetWindowLongPtr(header
, GWLP_ID
);
4653 nmh
.hdr
.code
= HDN_ITEMCHANGEDA
;
4656 item
.mask
= HDI_WIDTH
;
4659 ret
= SendMessage(list
, WM_NOTIFY
, 0, (LPARAM
)&nmh
);
4662 DestroyWindow(list
);
4665 static void test_createdragimage(void)
4671 list
= create_listview_control(LVS_ICON
);
4672 ok(list
!= NULL
, "failed to create listview window\n");
4674 insert_item(list
, 0);
4677 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, 0);
4678 ok(himl
== NULL
, "got %p\n", himl
);
4680 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, (LPARAM
)&pt
);
4681 ok(himl
!= NULL
, "got %p\n", himl
);
4682 ImageList_Destroy(himl
);
4684 DestroyWindow(list
);
4687 static void test_dispinfo(void)
4689 static const char testA
[] = "TEST";
4695 hwnd
= create_listview_control(LVS_ICON
);
4696 ok(hwnd
!= NULL
, "failed to create listview window\n");
4698 insert_item(hwnd
, 0);
4700 memset(&item
, 0, sizeof(item
));
4701 item
.pszText
= LPSTR_TEXTCALLBACKA
;
4702 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
4705 g_disp_A_to_W
= TRUE
;
4706 item
.pszText
= (char*)buff
;
4707 item
.cchTextMax
= sizeof(buff
)/sizeof(WCHAR
);
4708 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4709 ok(ret
== sizeof(testA
)-1, "got %d, expected 4\n", ret
);
4710 g_disp_A_to_W
= FALSE
;
4712 ok(memcmp(item
.pszText
, testA
, sizeof(testA
)) == 0,
4713 "got %s, expected %s\n", item
.pszText
, testA
);
4715 DestroyWindow(hwnd
);
4718 static void test_LVM_SETITEMTEXT(void)
4720 static char testA
[] = "TEST";
4725 hwnd
= create_listview_control(LVS_ICON
);
4726 ok(hwnd
!= NULL
, "failed to create listview window\n");
4728 insert_item(hwnd
, 0);
4730 /* null item pointer */
4731 ret
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, 0);
4734 ret
= SendMessage(hwnd
, LVM_SETITEMTEXTW
, 0, 0);
4737 /* index out of bounds */
4738 item
.pszText
= testA
;
4739 item
.cchTextMax
= 0; /* ignored */
4742 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 1, (LPARAM
)&item
);
4745 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, -1, (LPARAM
)&item
);
4748 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
4751 DestroyWindow(hwnd
);
4754 START_TEST(listview
)
4757 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
4759 ULONG_PTR ctx_cookie
;
4763 hComctl32
= GetModuleHandleA("comctl32.dll");
4764 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
4765 if (pInitCommonControlsEx
)
4767 INITCOMMONCONTROLSEX iccex
;
4768 iccex
.dwSize
= sizeof(iccex
);
4769 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
4770 pInitCommonControlsEx(&iccex
);
4773 InitCommonControls();
4775 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
4777 hwndparent
= create_parent_window(FALSE
);
4778 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4780 g_is_below_5
= is_below_comctl_5();
4782 test_header_notification();
4789 test_icon_spacing();
4792 test_item_position();
4797 test_subitem_rect();
4801 test_nosortheader();
4805 test_getitemposition();
4806 test_columnscreation();
4808 test_notifyformat();
4810 test_getitemspacing();
4811 test_getcolumnwidth();
4812 test_approximate_viewrect();
4815 test_destroynotify();
4816 test_createdragimage();
4818 test_LVM_SETITEMTEXT();
4820 if (!load_v6_module(&ctx_cookie
, &hCtx
))
4822 DestroyWindow(hwndparent
);
4826 /* this is a XP SP3 failure workaround */
4827 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
4828 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
,
4830 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
4831 if (!IsWindow(hwnd
))
4833 win_skip("FIXME: failed to create ListView window.\n");
4834 unload_v6_module(ctx_cookie
, hCtx
);
4835 DestroyWindow(hwndparent
);
4839 DestroyWindow(hwnd
);
4841 /* comctl32 version 6 tests start here */
4842 test_get_set_view();
4843 test_canceleditlabel();
4845 test_scrollnotify();
4846 test_LVS_EX_TRANSPARENTBKGND();
4847 test_LVS_EX_HEADERINALLVIEWS();
4849 unload_v6_module(ctx_cookie
, hCtx
);
4851 DestroyWindow(hwndparent
);