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
? di
->item
.pszText
: "(null)");
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");
380 ok((GetWindowLongA(edit
, GWL_STYLE
) & ES_MULTILINE
) == 0, "edit is multiline\n");
384 case LVN_BEGINSCROLL
:
387 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
389 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
390 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
393 case LVN_ITEMCHANGED
:
394 if (g_dump_itemchanged
)
396 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
397 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
398 nmlv
->iItem
, nmlv
->uNewState
, nmlv
->uOldState
, nmlv
->uChanged
);
401 case LVN_GETDISPINFOA
:
403 NMLVDISPINFOA
*dispinfo
= (NMLVDISPINFOA
*)lParam
;
404 g_itema
= dispinfo
->item
;
406 if (g_disp_A_to_W
&& (dispinfo
->item
.mask
& LVIF_TEXT
))
408 static const WCHAR testW
[] = {'T','E','S','T',0};
409 dispinfo
->hdr
.code
= LVN_GETDISPINFOW
;
410 memcpy(dispinfo
->item
.pszText
, testW
, sizeof(testW
));
413 /* test control buffer size for text, 10 used to mask cases when control
414 is using caller buffer to process LVM_GETITEM for example */
415 if (dispinfo
->item
.mask
& LVIF_TEXT
&& dispinfo
->item
.cchTextMax
> 10)
416 ok(dispinfo
->item
.cchTextMax
== 260 ||
417 broken(dispinfo
->item
.cchTextMax
== 264) /* NT4 reports aligned size */,
418 "buffer size %d\n", dispinfo
->item
.cchTextMax
);
422 if (g_block_hover
) return 1;
427 case WM_NOTIFYFORMAT
:
429 /* force to return format */
430 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
435 defwndproc_counter
++;
436 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
437 defwndproc_counter
--;
442 static BOOL
register_parent_wnd_class(BOOL Unicode
)
450 clsW
.lpfnWndProc
= parent_wnd_proc
;
453 clsW
.hInstance
= GetModuleHandleW(NULL
);
455 clsW
.hCursor
= LoadCursorA(0, IDC_ARROW
);
456 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
457 clsW
.lpszMenuName
= NULL
;
458 clsW
.lpszClassName
= testparentclassW
;
463 clsA
.lpfnWndProc
= parent_wnd_proc
;
466 clsA
.hInstance
= GetModuleHandleA(NULL
);
468 clsA
.hCursor
= LoadCursorA(0, IDC_ARROW
);
469 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
470 clsA
.lpszMenuName
= NULL
;
471 clsA
.lpszClassName
= "Listview test parent class";
474 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
477 static HWND
create_parent_window(BOOL Unicode
)
479 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
482 if (!register_parent_wnd_class(Unicode
))
489 hwnd
= CreateWindowExW(0, testparentclassW
, nameW
,
490 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
491 WS_MAXIMIZEBOX
| WS_VISIBLE
,
493 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
495 hwnd
= CreateWindowExA(0, "Listview test parent class",
496 "Listview test parent window",
497 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
498 WS_MAXIMIZEBOX
| WS_VISIBLE
,
500 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
501 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
505 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
507 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
508 static LONG defwndproc_counter
= 0;
512 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
514 /* some debug output for style changing */
515 if ((message
== WM_STYLECHANGING
||
516 message
== WM_STYLECHANGED
) && lParam
)
518 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
519 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
522 msg
.message
= message
;
523 msg
.flags
= sent
|wparam
|lparam
;
524 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
527 msg
.id
= LISTVIEW_ID
;
528 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
529 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
531 defwndproc_counter
++;
532 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
533 defwndproc_counter
--;
537 static HWND
create_listview_control(DWORD style
)
543 GetClientRect(hwndparent
, &rect
);
544 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
545 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
546 0, 0, rect
.right
, rect
.bottom
,
547 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
548 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
550 if (!hwnd
) return NULL
;
552 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
553 (LONG_PTR
)listview_subclass_proc
);
554 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
559 /* unicode listview window with specified parent */
560 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
565 static const WCHAR nameW
[] = {'f','o','o',0};
567 GetClientRect(parent
, &rect
);
568 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
569 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
570 0, 0, rect
.right
, rect
.bottom
,
571 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
572 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
574 if (!hwnd
) return NULL
;
576 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
577 (LONG_PTR
)listview_subclass_proc
);
578 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
583 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
585 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
586 static LONG defwndproc_counter
= 0;
590 trace("header: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
592 msg
.message
= message
;
593 msg
.flags
= sent
|wparam
|lparam
;
594 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
598 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
600 defwndproc_counter
++;
601 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
602 defwndproc_counter
--;
606 static HWND
subclass_header(HWND hwndListview
)
611 hwnd
= ListView_GetHeader(hwndListview
);
612 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
613 (LONG_PTR
)header_subclass_proc
);
614 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
619 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
621 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
622 static LONG defwndproc_counter
= 0;
626 msg
.message
= message
;
627 msg
.flags
= sent
|wparam
|lparam
;
628 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
632 /* all we need is sizing */
633 if (message
== WM_WINDOWPOSCHANGING
||
634 message
== WM_NCCALCSIZE
||
635 message
== WM_WINDOWPOSCHANGED
||
636 message
== WM_MOVE
||
639 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
642 defwndproc_counter
++;
643 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
644 defwndproc_counter
--;
648 static HWND
subclass_editbox(HWND hwndListview
)
653 hwnd
= (HWND
)SendMessage(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
654 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
655 (LONG_PTR
)editbox_subclass_proc
);
656 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
661 /* Performs a single LVM_HITTEST test */
662 static void test_lvm_hittest_(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
, UINT broken_flags
,
663 BOOL todo_item
, BOOL todo_flags
, int line
)
672 ret
= SendMessage(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
678 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
679 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
680 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
685 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
686 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
687 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
693 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
695 else if (broken_flags
)
696 ok_(__FILE__
, line
)(lpht
.flags
== flags
|| broken(lpht
.flags
== broken_flags
),
697 "Expected flags %x, got %x\n", flags
, lpht
.flags
);
699 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
702 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
704 /* Performs a single LVM_SUBITEMHITTEST test */
705 static void test_lvm_subitemhittest_(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
706 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
714 ret
= SendMessage(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
720 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
721 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
726 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
727 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
733 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
736 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
741 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
744 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
747 #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__)
749 static void test_images(void)
757 static CHAR hello
[] = "hello";
759 himl
= ImageList_Create(40, 40, 0, 4, 4);
760 ok(himl
!= NULL
, "failed to create imagelist\n");
762 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
763 ok(hbmp
!= NULL
, "failed to create bitmap\n");
765 r
= ImageList_Add(himl
, hbmp
, 0);
766 ok(r
== 0, "should be zero\n");
768 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
769 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
770 ok(hwnd
!= NULL
, "failed to create listview window\n");
772 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
773 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
775 ok(r
== 0, "should return zero\n");
777 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
778 ok(r
== 0, "should return zero\n");
780 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
781 ok(r
!= 0, "got 0\n");
783 /* returns dimensions */
785 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
786 ok(r
== 0, "should be zero items\n");
788 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
793 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
794 ok(r
== -1, "should fail\n");
797 item
.pszText
= hello
;
798 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
799 ok(r
== 0, "should not fail\n");
801 memset(&r1
, 0, sizeof r1
);
803 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
806 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
807 ok(r
== TRUE
, "should not fail\n");
810 item
.pszText
= hello
;
811 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
812 ok(r
== 0, "should not fail\n");
814 memset(&r2
, 0, sizeof r2
);
816 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
819 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
824 static void test_checkboxes(void)
829 static CHAR text
[] = "Text",
833 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
834 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
835 ok(hwnd
!= NULL
, "failed to create listview window\n");
837 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
838 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
839 item
.stateMask
= 0xffff;
844 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
848 item
.mask
= LVIF_STATE
;
849 item
.stateMask
= 0xffff;
850 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
852 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
854 /* Don't set LVIF_STATE */
855 item
.mask
= LVIF_TEXT
;
856 item
.stateMask
= 0xffff;
861 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
865 item
.mask
= LVIF_STATE
;
866 item
.stateMask
= 0xffff;
867 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
869 ok(item
.state
== 0, "state %x\n", item
.state
);
871 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
874 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
876 item
.mask
= LVIF_STATE
;
877 item
.stateMask
= 0xffff;
878 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
880 if (item
.state
!= 0x1ccc)
882 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
887 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
889 item
.mask
= LVIF_TEXT
;
891 item
.pszText
= text2
;
892 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
896 item
.mask
= LVIF_STATE
;
897 item
.stateMask
= 0xffff;
898 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
900 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
902 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
904 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
905 item
.stateMask
= 0xffff;
907 item
.pszText
= text3
;
908 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
912 item
.mask
= LVIF_STATE
;
913 item
.stateMask
= 0xffff;
914 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
916 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
918 /* Set an item's state to checked */
920 item
.mask
= LVIF_STATE
;
921 item
.stateMask
= 0xf000;
923 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
927 item
.mask
= LVIF_STATE
;
928 item
.stateMask
= 0xffff;
929 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
931 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
933 /* Check that only the bits we asked for are returned,
934 * and that all the others are set to zero
937 item
.mask
= LVIF_STATE
;
938 item
.stateMask
= 0xf000;
940 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
942 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
944 /* Set the style again and check that doesn't change an item's state */
945 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
946 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
949 item
.mask
= LVIF_STATE
;
950 item
.stateMask
= 0xffff;
951 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
953 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
955 /* Unsetting the checkbox extended style doesn't change an item's state */
956 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
957 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
960 item
.mask
= LVIF_STATE
;
961 item
.stateMask
= 0xffff;
962 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
964 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
966 /* Now setting the style again will change an item's state */
967 r
= SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
971 item
.mask
= LVIF_STATE
;
972 item
.stateMask
= 0xffff;
973 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
975 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
977 /* Toggle checkbox tests (bug 9934) */
978 memset (&item
, 0xcc, sizeof(item
));
979 item
.mask
= LVIF_STATE
;
982 item
.state
= LVIS_FOCUSED
;
983 item
.stateMask
= LVIS_FOCUSED
;
984 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
988 item
.mask
= LVIF_STATE
;
989 item
.stateMask
= 0xffff;
990 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
992 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
994 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
996 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1000 item
.mask
= LVIF_STATE
;
1001 item
.stateMask
= 0xffff;
1002 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1004 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
1006 r
= SendMessage(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1008 r
= SendMessage(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1012 item
.mask
= LVIF_STATE
;
1013 item
.stateMask
= 0xffff;
1014 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1016 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1018 DestroyWindow(hwnd
);
1021 static void insert_column(HWND hwnd
, int idx
)
1026 memset(&column
, 0xcc, sizeof(column
));
1027 column
.mask
= LVCF_SUBITEM
;
1028 column
.iSubItem
= idx
;
1030 rc
= ListView_InsertColumn(hwnd
, idx
, &column
);
1034 static void insert_item(HWND hwnd
, int idx
)
1036 static CHAR text
[] = "foo";
1041 memset(&item
, 0xcc, sizeof (item
));
1042 item
.mask
= LVIF_TEXT
;
1045 item
.pszText
= text
;
1047 rc
= ListView_InsertItem(hwnd
, &item
);
1051 static void test_items(void)
1053 const LPARAM lparamTest
= 0x42;
1054 static CHAR text
[] = "Text";
1060 hwnd
= CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT
,
1061 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1062 ok(hwnd
!= NULL
, "failed to create listview window\n");
1065 * Test setting/getting item params
1068 /* Set up two columns */
1069 insert_column(hwnd
, 0);
1070 insert_column(hwnd
, 1);
1072 /* LVIS_SELECTED with zero stateMask */
1074 memset (&item
, 0, sizeof (item
));
1075 item
.mask
= LVIF_STATE
;
1076 item
.state
= LVIS_SELECTED
;
1080 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1083 memset (&item
, 0xcc, sizeof (item
));
1084 item
.mask
= LVIF_STATE
;
1085 item
.stateMask
= LVIS_SELECTED
;
1089 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1091 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1092 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1094 /* LVIS_SELECTED with zero stateMask */
1096 memset (&item
, 0, sizeof (item
));
1097 item
.mask
= LVIF_STATE
;
1098 item
.state
= LVIS_FOCUSED
;
1102 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1105 memset (&item
, 0xcc, sizeof (item
));
1106 item
.mask
= LVIF_STATE
;
1107 item
.stateMask
= LVIS_FOCUSED
;
1111 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1113 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1114 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1116 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1118 memset (&item
, 0, sizeof (item
));
1119 item
.mask
= LVIF_STATE
;
1120 item
.state
= LVIS_CUT
;
1121 item
.stateMask
= LVIS_FOCUSED
;
1124 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1127 memset (&item
, 0xcc, sizeof (item
));
1128 item
.mask
= LVIF_STATE
;
1129 item
.stateMask
= LVIS_CUT
;
1133 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1135 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1136 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
1138 /* Insert an item with just a param */
1139 memset (&item
, 0xcc, sizeof (item
));
1140 item
.mask
= LVIF_PARAM
;
1143 item
.lParam
= lparamTest
;
1144 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1147 /* Test getting of the param */
1148 memset (&item
, 0xcc, sizeof (item
));
1149 item
.mask
= LVIF_PARAM
;
1152 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1154 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1156 /* Set up a subitem */
1157 memset (&item
, 0xcc, sizeof (item
));
1158 item
.mask
= LVIF_TEXT
;
1161 item
.pszText
= text
;
1162 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1165 item
.mask
= LVIF_TEXT
;
1168 item
.pszText
= buffA
;
1169 item
.cchTextMax
= sizeof(buffA
);
1170 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1172 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got text %s, expected %s\n", item
.pszText
, text
);
1174 /* set up with extra flag */
1175 /* 1. reset subitem text */
1176 item
.mask
= LVIF_TEXT
;
1179 item
.pszText
= NULL
;
1180 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1183 item
.mask
= LVIF_TEXT
;
1186 item
.pszText
= buffA
;
1188 item
.cchTextMax
= sizeof(buffA
);
1189 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1191 ok(item
.pszText
[0] == 0, "got %p\n", item
.pszText
);
1193 /* 2. set new text with extra flag specified */
1194 item
.mask
= LVIF_TEXT
| LVIF_DI_SETITEM
;
1197 item
.pszText
= text
;
1198 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1199 ok(r
== 1 || broken(r
== 0) /* NT4 */, "ret %d\n", r
);
1203 item
.mask
= LVIF_TEXT
;
1206 item
.pszText
= buffA
;
1208 item
.cchTextMax
= sizeof(buffA
);
1209 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1211 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got %s, expected %s\n", item
.pszText
, text
);
1214 /* Query param from subitem: returns main item param */
1215 memset (&item
, 0xcc, sizeof (item
));
1216 item
.mask
= LVIF_PARAM
;
1219 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1221 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1223 /* Set up param on first subitem: no effect */
1224 memset (&item
, 0xcc, sizeof (item
));
1225 item
.mask
= LVIF_PARAM
;
1228 item
.lParam
= lparamTest
+1;
1229 r
= SendMessage(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1232 /* Query param from subitem again: should still return main item param */
1233 memset (&item
, 0xcc, sizeof (item
));
1234 item
.mask
= LVIF_PARAM
;
1237 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1239 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1241 /**** Some tests of state highlighting ****/
1242 memset (&item
, 0xcc, sizeof (item
));
1243 item
.mask
= LVIF_STATE
;
1246 item
.state
= LVIS_SELECTED
;
1247 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1248 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1251 item
.state
= LVIS_DROPHILITED
;
1252 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
) &item
);
1255 memset (&item
, 0xcc, sizeof (item
));
1256 item
.mask
= LVIF_STATE
;
1259 item
.stateMask
= -1;
1260 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1262 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1264 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
1266 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1268 /* some notnull but meaningless masks */
1269 memset (&item
, 0, sizeof(item
));
1270 item
.mask
= LVIF_NORECOMPUTE
;
1273 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1275 memset (&item
, 0, sizeof(item
));
1276 item
.mask
= LVIF_DI_SETITEM
;
1279 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1282 /* set text to callback value already having it */
1283 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1285 memset (&item
, 0, sizeof (item
));
1286 item
.mask
= LVIF_TEXT
;
1287 item
.pszText
= LPSTR_TEXTCALLBACK
;
1289 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1291 memset (&item
, 0, sizeof (item
));
1293 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1295 item
.pszText
= LPSTR_TEXTCALLBACK
;
1296 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0 , (LPARAM
) &item
);
1299 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1300 "check callback text comparison rule", FALSE
);
1302 DestroyWindow(hwnd
);
1305 static void test_columns(void)
1314 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1315 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1316 ok(hwnd
!= NULL
, "failed to create listview window\n");
1318 /* Add a column with no mask */
1319 memset(&column
, 0xcc, sizeof(column
));
1321 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1322 ok(rc
== 0, "Inserting column with no mask failed with %d\n", rc
);
1324 /* Check its width */
1325 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
1326 ok(rc
== 10, "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 /* setting LVS_EX_GRIDLINES creates header */
1547 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1548 GetModuleHandle(NULL
), 0);
1549 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1550 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1551 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1552 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_GRIDLINES
);
1553 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1554 ok(IsWindow(hHeader
) ||
1555 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1556 "Header should be created\n");
1557 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1558 DestroyWindow(hList
);
1560 /* setting LVS_EX_FULLROWSELECT creates header */
1561 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1562 GetModuleHandle(NULL
), 0);
1563 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1564 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1565 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1566 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
1567 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1568 ok(IsWindow(hHeader
) ||
1569 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1570 "Header should be created\n");
1571 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1572 DestroyWindow(hList
);
1574 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1575 hList
= create_listview_control(LVS_ICON
);
1576 SendMessage(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1577 r
= SendMessage(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1578 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1579 DestroyWindow(hList
);
1581 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1582 hList
= CreateWindow("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1583 GetModuleHandle(NULL
), 0);
1584 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1585 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1587 rect
.left
= LVIR_BOUNDS
;
1589 rect
.right
= rect
.bottom
= -10;
1590 r
= SendMessage(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1593 hHeader
= (HWND
)SendMessage(hList
, LVM_GETHEADER
, 0, 0);
1594 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1595 ok(GetDlgItem(hList
, 0) == NULL
, "NULL dialog item expected\n");
1597 DestroyWindow(hList
);
1599 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1600 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1601 hList
= create_listview_control(LVS_OWNERDRAWFIXED
| LVS_REPORT
);
1602 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1603 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1604 DestroyWindow(hList
);
1607 static void test_redraw(void)
1614 hwnd
= create_listview_control(LVS_REPORT
);
1615 subclass_header(hwnd
);
1617 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1619 InvalidateRect(hwnd
, NULL
, TRUE
);
1621 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1623 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1625 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1626 /* 1. Without backbuffer */
1627 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1630 hdc
= GetWindowDC(hwndparent
);
1632 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1633 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1634 ok(r
== 1, "Expected not zero result\n");
1635 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1636 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1638 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1641 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1642 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1644 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1645 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1647 /* 2. With backbuffer */
1648 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1649 LVS_EX_DOUBLEBUFFER
);
1650 res
= ListView_SetBkColor(hwnd
, CLR_NONE
);
1653 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1654 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1656 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1657 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1659 res
= ListView_SetBkColor(hwnd
, CLR_DEFAULT
);
1662 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1663 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1664 todo_wine
expect(1, r
);
1665 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1666 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1668 ReleaseDC(hwndparent
, hdc
);
1670 DestroyWindow(hwnd
);
1673 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1675 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1677 if(msg
== WM_NOTIFY
) {
1678 NMHDR
*nmhdr
= (PVOID
)lp
;
1679 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1680 NMLVCUSTOMDRAW
*nmlvcd
= (PVOID
)nmhdr
;
1681 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd
->nmcd
.dwDrawStage
);
1682 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1684 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1685 return CDRF_NOTIFYITEMDRAW
;
1686 case CDDS_ITEMPREPAINT
:
1687 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1688 return CDRF_NOTIFYSUBITEMDRAW
;
1689 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1690 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1691 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1692 return CDRF_NOTIFYPOSTPAINT
;
1693 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1694 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1695 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1696 return CDRF_DODEFAULT
;
1698 return CDRF_DODEFAULT
;
1702 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1705 static void test_customdraw(void)
1710 hwnd
= create_listview_control(LVS_REPORT
);
1712 insert_column(hwnd
, 0);
1713 insert_column(hwnd
, 1);
1714 insert_item(hwnd
, 0);
1716 oldwndproc
= (WNDPROC
)SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
,
1717 (LONG_PTR
)cd_wndproc
);
1719 InvalidateRect(hwnd
, NULL
, TRUE
);
1722 SetWindowLongPtr(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1724 DestroyWindow(hwnd
);
1727 static void test_icon_spacing(void)
1729 /* LVM_SETICONSPACING */
1730 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1736 hwnd
= create_listview_control(LVS_ICON
);
1737 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1739 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, NF_REQUERY
);
1740 expect(NFR_ANSI
, r
);
1742 /* reset the icon spacing to defaults */
1743 SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1745 /* now we can request what the defaults are */
1746 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1750 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1752 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1753 ok(r
== MAKELONG(w
, h
) ||
1754 broken(r
== MAKELONG(w
, w
)), /* win98 */
1755 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1757 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1761 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1762 DestroyWindow(hwnd
);
1765 expect(MAKELONG(20,30), r
);
1767 r
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1768 expect(MAKELONG(25,35), r
);
1770 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1772 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1773 DestroyWindow(hwnd
);
1776 static void test_color(void)
1784 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1786 hwnd
= create_listview_control(LVS_REPORT
);
1787 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1789 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1791 for (i
= 0; i
< 4; i
++)
1795 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1797 r
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, 0);
1800 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1802 r
= SendMessage(hwnd
, LVM_GETTEXTCOLOR
, 0, 0);
1805 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1807 r
= SendMessage(hwnd
, LVM_GETTEXTBKCOLOR
, 0, 0);
1811 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1812 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1814 /* invalidation test done separately to avoid a message chain mess */
1815 r
= ValidateRect(hwnd
, NULL
);
1817 r
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, colors
[0]);
1820 rect
.right
= rect
.bottom
= 1;
1821 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1822 todo_wine
expect(FALSE
, r
);
1823 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1825 r
= ValidateRect(hwnd
, NULL
);
1827 r
= SendMessage(hwnd
, LVM_SETTEXTCOLOR
, 0, colors
[0]);
1830 rect
.right
= rect
.bottom
= 1;
1831 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1832 todo_wine
expect(FALSE
, r
);
1833 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1835 r
= ValidateRect(hwnd
, NULL
);
1837 r
= SendMessage(hwnd
, LVM_SETTEXTBKCOLOR
, 0, colors
[0]);
1840 rect
.right
= rect
.bottom
= 1;
1841 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1842 todo_wine
expect(FALSE
, r
);
1843 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1845 DestroyWindow(hwnd
);
1848 static void test_item_count(void)
1850 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1863 static CHAR item0text
[] = "item0";
1864 static CHAR item1text
[] = "item1";
1865 static CHAR item2text
[] = "item2";
1867 hwnd
= create_listview_control(LVS_REPORT
);
1868 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1870 /* resize in dpiaware manner to fit all 3 items added */
1872 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1873 GetTextMetricsA(hdc
, &tm
);
1874 /* 2 extra pixels for bounds and header border */
1875 height
= tm
.tmHeight
+ 2;
1876 SelectObject(hdc
, hOldFont
);
1879 GetWindowRect(hwnd
, &rect
);
1880 /* 3 items + 1 header + 1 to be sure */
1881 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1883 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1885 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1889 item0
.mask
= LVIF_TEXT
;
1892 item0
.pszText
= item0text
;
1893 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1896 /* [item0, item1] */
1897 item1
.mask
= LVIF_TEXT
;
1900 item1
.pszText
= item1text
;
1901 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1904 /* [item0, item1, item2] */
1905 item2
.mask
= LVIF_TEXT
;
1908 item2
.pszText
= item2text
;
1909 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1912 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1915 /* [item0, item1] */
1916 r
= SendMessage(hwnd
, LVM_DELETEITEM
, 2, 0);
1919 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1923 r
= SendMessage(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1926 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1930 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1933 /* [item0, item1] */
1934 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1937 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1940 /* [item0, item1, item2] */
1941 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1944 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1947 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
1949 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1950 DestroyWindow(hwnd
);
1953 static void test_item_position(void)
1955 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1964 static CHAR item0text
[] = "item0";
1965 static CHAR item1text
[] = "item1";
1966 static CHAR item2text
[] = "item2";
1968 hwnd
= create_listview_control(LVS_ICON
);
1969 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1971 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1974 item0
.mask
= LVIF_TEXT
;
1977 item0
.pszText
= item0text
;
1978 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item0
);
1981 /* [item0, item1] */
1982 item1
.mask
= LVIF_TEXT
;
1985 item1
.pszText
= item1text
;
1986 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item1
);
1989 /* [item0, item1, item2] */
1990 item2
.mask
= LVIF_TEXT
;
1993 item2
.pszText
= item2text
;
1994 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item2
);
1997 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
1999 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
2001 expect2(10, 5, position
.x
, position
.y
);
2003 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
2005 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
2007 expect2(0, 0, position
.x
, position
.y
);
2009 r
= SendMessage(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
2011 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
2013 expect2(20, 20, position
.x
, position
.y
);
2015 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
2017 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2018 DestroyWindow(hwnd
);
2021 static void test_getorigin(void)
2029 position
.x
= position
.y
= 0;
2031 hwnd
= create_listview_control(LVS_ICON
);
2032 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2033 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2035 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2037 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2038 DestroyWindow(hwnd
);
2040 hwnd
= create_listview_control(LVS_SMALLICON
);
2041 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2042 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2044 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2046 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2047 DestroyWindow(hwnd
);
2049 hwnd
= create_listview_control(LVS_LIST
);
2050 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2051 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2053 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2055 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2056 DestroyWindow(hwnd
);
2058 hwnd
= create_listview_control(LVS_REPORT
);
2059 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2060 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2062 r
= SendMessage(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2064 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2065 DestroyWindow(hwnd
);
2068 static void test_multiselect(void)
2070 typedef struct t_select_task
2081 int i
,j
,item_count
,selected_count
;
2082 static const int items
=5;
2088 static struct t_select_task task_list
[] = {
2089 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
2090 { "using VK_UP", -1, VK_UP
, -1, -1 },
2091 { "using VK_END", 0, VK_END
, 1, -1 },
2092 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
2096 hwnd
= create_listview_control(LVS_REPORT
);
2098 for (i
=0;i
<items
;i
++) {
2099 insert_item(hwnd
, 0);
2102 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2104 expect(items
,item_count
);
2107 task
= task_list
[i
];
2109 /* deselect all items */
2110 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
2111 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2113 /* set initial position */
2114 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
2115 ListView_SetItemState(hwnd
,(task
.initPos
== -1 ? item_count
-1 : task
.initPos
),LVIS_SELECTED
,LVIS_SELECTED
);
2117 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2119 ok(selected_count
== 1, "There should be only one selected item at the beginning (is %d)\n",selected_count
);
2121 /* Set SHIFT key pressed */
2122 GetKeyboardState(kstate
);
2123 kstate
[VK_SHIFT
]=0x80;
2124 SetKeyboardState(kstate
);
2126 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
2127 r
= SendMessage(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
2129 r
= SendMessage(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
2133 selected_count
= (int)SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2135 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
);
2137 /* Set SHIFT key released */
2138 GetKeyboardState(kstate
);
2139 kstate
[VK_SHIFT
]=0x00;
2140 SetKeyboardState(kstate
);
2142 DestroyWindow(hwnd
);
2144 /* make multiple selection, then switch to LVS_SINGLESEL */
2145 hwnd
= create_listview_control(LVS_REPORT
);
2146 for (i
=0;i
<items
;i
++) {
2147 insert_item(hwnd
, 0);
2149 item_count
= (int)SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2150 expect(items
,item_count
);
2152 /* try with NULL pointer */
2153 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, 0);
2156 /* select all, check notifications */
2157 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
2159 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2161 item
.stateMask
= LVIS_SELECTED
;
2162 item
.state
= LVIS_SELECTED
;
2163 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2166 ok_sequence(sequences
, PARENT_SEQ_INDEX
, select_all_parent_seq
,
2167 "select all notification", FALSE
);
2169 /* deselect all items */
2170 ListView_SetItemState(hwnd
, -1, 0, LVIS_SELECTED
);
2171 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2173 ListView_SetItemState(hwnd
, i
, LVIS_SELECTED
, LVIS_SELECTED
);
2176 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2178 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2181 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2182 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2183 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2184 /* check that style is accepted */
2185 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2186 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2189 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2190 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2192 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2194 SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2197 /* select one more */
2198 ListView_SetItemState(hwnd
, 3, LVIS_SELECTED
, LVIS_SELECTED
);
2201 r
= ListView_GetItemState(hwnd
, i
, LVIS_SELECTED
);
2202 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2204 r
= ListView_GetItemState(hwnd
, 3, LVIS_SELECTED
);
2205 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2207 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2209 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2212 /* try to select all on LVS_SINGLESEL */
2213 memset(&item
, 0, sizeof(item
));
2214 item
.stateMask
= LVIS_SELECTED
;
2215 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2217 SendMessage(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2219 item
.stateMask
= LVIS_SELECTED
;
2220 item
.state
= LVIS_SELECTED
;
2221 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2224 r
= ListView_GetSelectedCount(hwnd
);
2226 r
= ListView_GetSelectionMark(hwnd
);
2229 /* try to deselect all on LVS_SINGLESEL */
2230 item
.stateMask
= LVIS_SELECTED
;
2231 item
.state
= LVIS_SELECTED
;
2232 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2235 item
.stateMask
= LVIS_SELECTED
;
2237 r
= SendMessage(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2239 r
= ListView_GetSelectedCount(hwnd
);
2242 DestroyWindow(hwnd
);
2245 static void test_subitem_rect(void)
2253 /* test LVM_GETSUBITEMRECT for header */
2254 hwnd
= create_listview_control(LVS_REPORT
);
2255 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2256 /* add some columns */
2257 memset(&col
, 0, sizeof(LVCOLUMN
));
2258 col
.mask
= LVCF_WIDTH
;
2260 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2263 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2266 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2268 /* item = -1 means header, subitem index is 1 based */
2269 rect
.left
= LVIR_BOUNDS
;
2271 rect
.right
= rect
.bottom
= 0;
2272 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2275 rect
.left
= LVIR_BOUNDS
;
2277 rect
.right
= rect
.bottom
= 0;
2278 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2281 expect(100, rect
.left
);
2282 expect(250, rect
.right
);
2284 expect(3, rect
.top
);
2286 rect
.left
= LVIR_BOUNDS
;
2288 rect
.right
= rect
.bottom
= 0;
2289 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2292 expect(250, rect
.left
);
2293 expect(450, rect
.right
);
2295 expect(3, rect
.top
);
2297 /* item LVS_REPORT padding isn't applied to subitems */
2298 insert_item(hwnd
, 0);
2300 rect
.left
= LVIR_BOUNDS
;
2302 rect
.right
= rect
.bottom
= 0;
2303 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2305 expect(100, rect
.left
);
2306 expect(250, rect
.right
);
2308 rect
.left
= LVIR_ICON
;
2310 rect
.right
= rect
.bottom
= 0;
2311 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2313 /* no icon attached - zero width rectangle, with no left padding */
2314 expect(100, rect
.left
);
2315 expect(100, rect
.right
);
2317 rect
.left
= LVIR_LABEL
;
2319 rect
.right
= rect
.bottom
= 0;
2320 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2322 /* same as full LVIR_BOUNDS */
2323 expect(100, rect
.left
);
2324 expect(250, rect
.right
);
2326 SendMessage(hwnd
, LVM_SCROLL
, 10, 0);
2328 rect
.left
= LVIR_BOUNDS
;
2330 rect
.right
= rect
.bottom
= 0;
2331 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2333 expect(90, rect
.left
);
2334 expect(240, rect
.right
);
2336 SendMessage(hwnd
, LVM_SCROLL
, -10, 0);
2338 DestroyWindow(hwnd
);
2340 /* test subitem rects after re-arranging columns */
2341 hwnd
= create_listview_control(LVS_REPORT
);
2342 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2343 memset(&col
, 0, sizeof(LVCOLUMN
));
2344 col
.mask
= LVCF_WIDTH
;
2347 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 0, (LPARAM
)&col
);
2351 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 1, (LPARAM
)&col
);
2355 r
= SendMessage(hwnd
, LVM_INSERTCOLUMN
, 2, (LPARAM
)&col
);
2358 insert_item(hwnd
, 0);
2359 insert_item(hwnd
, 1);
2361 /* wrong item is refused for main item */
2362 rect
.left
= LVIR_BOUNDS
;
2364 rect
.right
= rect
.bottom
= -1;
2365 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect
);
2368 /* for subitems rectangle is calculated even if there's no item added */
2369 rect
.left
= LVIR_BOUNDS
;
2371 rect
.right
= rect
.bottom
= -1;
2372 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect
);
2375 rect2
.left
= LVIR_BOUNDS
;
2377 rect2
.right
= rect2
.bottom
= -1;
2378 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect2
);
2381 expect(rect
.right
, rect2
.right
);
2382 expect(rect
.left
, rect2
.left
);
2383 expect(rect
.bottom
, rect2
.top
);
2384 ok(rect2
.bottom
> rect2
.top
, "expected not zero height\n");
2387 arr
[0] = 1; arr
[1] = 0; arr
[2] = 2;
2388 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 3, (LPARAM
)arr
);
2391 rect
.left
= LVIR_BOUNDS
;
2393 rect
.right
= rect
.bottom
= -1;
2394 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2396 expect(0, rect
.left
);
2397 expect(600, rect
.right
);
2399 rect
.left
= LVIR_BOUNDS
;
2401 rect
.right
= rect
.bottom
= -1;
2402 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2404 expect(0, rect
.left
);
2405 expect(200, rect
.right
);
2407 rect2
.left
= LVIR_BOUNDS
;
2409 rect2
.right
= rect2
.bottom
= -1;
2410 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect2
);
2412 expect(0, rect2
.left
);
2413 expect(200, rect2
.right
);
2414 /* items are of the same height */
2415 ok(rect2
.top
> 0, "expected positive item height\n");
2416 expect(rect
.bottom
, rect2
.top
);
2417 expect(rect
.bottom
* 2 - rect
.top
, rect2
.bottom
);
2419 rect
.left
= LVIR_BOUNDS
;
2421 rect
.right
= rect
.bottom
= -1;
2422 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2424 expect(300, rect
.left
);
2425 expect(600, rect
.right
);
2427 DestroyWindow(hwnd
);
2429 /* try it for non LVS_REPORT style */
2430 hwnd
= CreateWindow("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2431 GetModuleHandle(NULL
), 0);
2432 rect
.left
= LVIR_BOUNDS
;
2434 rect
.right
= rect
.bottom
= -10;
2435 r
= SendMessage(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2437 /* rect is unchanged */
2438 expect(0, rect
.left
);
2439 expect(-10, rect
.right
);
2440 expect(1, rect
.top
);
2441 expect(-10, rect
.bottom
);
2442 DestroyWindow(hwnd
);
2445 /* comparison callback for test_sorting */
2446 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2448 if (first
== second
) return 0;
2449 return (first
> second
? 1 : -1);
2452 static void test_sorting(void)
2458 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2461 hwnd
= create_listview_control(LVS_REPORT
);
2462 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2464 /* insert some items */
2465 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2466 item
.state
= LVIS_SELECTED
;
2470 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2473 item
.mask
= LVIF_PARAM
;
2477 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2480 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2481 item
.state
= LVIS_SELECTED
;
2485 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2488 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2491 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2494 r
= SendMessage(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2497 r
= SendMessage(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2499 r
= SendMessage(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2501 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2503 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2504 expect(LVIS_SELECTED
, r
);
2505 r
= SendMessage(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2506 expect(LVIS_SELECTED
, r
);
2508 DestroyWindow(hwnd
);
2510 /* switch to LVS_SORTASCENDING when some items added */
2511 hwnd
= create_listview_control(LVS_REPORT
);
2512 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2514 item
.mask
= LVIF_TEXT
;
2517 item
.pszText
= names
[1];
2518 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2521 item
.mask
= LVIF_TEXT
;
2524 item
.pszText
= names
[2];
2525 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2528 item
.mask
= LVIF_TEXT
;
2531 item
.pszText
= names
[0];
2532 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2535 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2536 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2537 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2538 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2540 /* no sorting performed when switched to LVS_SORTASCENDING */
2541 item
.mask
= LVIF_TEXT
;
2543 item
.pszText
= buff
;
2544 item
.cchTextMax
= sizeof(buff
);
2545 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2547 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2550 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2552 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2555 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2557 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2559 /* adding new item doesn't resort list */
2560 item
.mask
= LVIF_TEXT
;
2563 item
.pszText
= names
[3];
2564 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2567 item
.mask
= LVIF_TEXT
;
2569 item
.pszText
= buff
;
2570 item
.cchTextMax
= sizeof(buff
);
2571 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2573 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2576 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2578 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2581 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2583 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2586 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2588 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2590 /* corner case - item should be placed at first position */
2591 item
.mask
= LVIF_TEXT
;
2594 item
.pszText
= names
[4];
2595 r
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
) &item
);
2599 item
.pszText
= buff
;
2600 item
.cchTextMax
= sizeof(buff
);
2601 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2603 ok(lstrcmp(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2606 item
.pszText
= buff
;
2607 item
.cchTextMax
= sizeof(buff
);
2608 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2610 ok(lstrcmp(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2613 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2615 ok(lstrcmp(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2618 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2620 ok(lstrcmp(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2623 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
) &item
);
2625 ok(lstrcmp(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2627 DestroyWindow(hwnd
);
2630 static void test_ownerdata(void)
2633 LONG_PTR style
, ret
;
2637 /* it isn't possible to set LVS_OWNERDATA after creation */
2640 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2644 hwnd
= create_listview_control(LVS_REPORT
);
2645 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2646 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2647 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2649 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2651 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2652 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2653 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2654 "try to switch to LVS_OWNERDATA seq", FALSE
);
2656 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2657 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2658 DestroyWindow(hwnd
);
2661 /* try to set LVS_OWNERDATA after creation just having it */
2662 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2663 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2664 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2665 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2667 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2669 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2670 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2671 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2672 "try to switch to LVS_OWNERDATA seq", FALSE
);
2673 DestroyWindow(hwnd
);
2675 /* try to remove LVS_OWNERDATA after creation just having it */
2678 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2682 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2683 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2684 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2685 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2687 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2689 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2690 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2691 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2692 "try to switch to LVS_OWNERDATA seq", FALSE
);
2693 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2694 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2695 DestroyWindow(hwnd
);
2698 /* try select an item */
2699 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2700 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2701 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2703 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2705 memset(&item
, 0, sizeof(item
));
2706 item
.stateMask
= LVIS_SELECTED
;
2707 item
.state
= LVIS_SELECTED
;
2708 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2710 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2712 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2714 DestroyWindow(hwnd
);
2716 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2717 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2718 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2719 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2721 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2723 memset(&item
, 0, sizeof(item
));
2724 item
.mask
= LVIF_STATE
;
2726 item
.stateMask
= LVIS_SELECTED
;
2727 item
.state
= LVIS_SELECTED
;
2728 res
= SendMessageA(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
2730 DestroyWindow(hwnd
);
2732 /* check notifications after focused/selected changed */
2733 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2734 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2735 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
2738 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2740 memset(&item
, 0, sizeof(item
));
2741 item
.stateMask
= LVIS_SELECTED
;
2742 item
.state
= LVIS_SELECTED
;
2743 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2746 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2747 "ownerdata select notification", TRUE
);
2749 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2751 memset(&item
, 0, sizeof(item
));
2752 item
.stateMask
= LVIS_FOCUSED
;
2753 item
.state
= LVIS_FOCUSED
;
2754 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2757 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
2758 "ownerdata focus notification", TRUE
);
2760 /* select all, check notifications */
2761 item
.stateMask
= LVIS_SELECTED
;
2763 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2766 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2768 item
.stateMask
= LVIS_SELECTED
;
2769 item
.state
= LVIS_SELECTED
;
2771 g_dump_itemchanged
= TRUE
;
2772 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2774 g_dump_itemchanged
= FALSE
;
2776 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2777 "ownerdata select all notification", TRUE
);
2779 /* select all again, note that all items are selected already */
2780 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2781 item
.stateMask
= LVIS_SELECTED
;
2782 item
.state
= LVIS_SELECTED
;
2783 g_dump_itemchanged
= TRUE
;
2784 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2786 g_dump_itemchanged
= FALSE
;
2787 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2788 "ownerdata select all notification", TRUE
);
2790 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2791 item
.stateMask
= LVIS_SELECTED
;
2793 g_dump_itemchanged
= TRUE
;
2794 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2796 g_dump_itemchanged
= FALSE
;
2797 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2798 "ownerdata deselect all notification", TRUE
);
2800 /* select one, then deselect all */
2801 item
.stateMask
= LVIS_SELECTED
;
2802 item
.state
= LVIS_SELECTED
;
2803 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2805 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2806 item
.stateMask
= LVIS_SELECTED
;
2808 g_dump_itemchanged
= TRUE
;
2809 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2811 g_dump_itemchanged
= FALSE
;
2812 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
2813 "ownerdata select all notification", TRUE
);
2815 /* remove focused, try to focus all */
2816 item
.stateMask
= LVIS_FOCUSED
;
2817 item
.state
= LVIS_FOCUSED
;
2818 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2820 item
.stateMask
= LVIS_FOCUSED
;
2822 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2824 item
.stateMask
= LVIS_FOCUSED
;
2825 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
2827 /* setting all to focused returns failure value */
2828 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2829 item
.stateMask
= LVIS_FOCUSED
;
2830 item
.state
= LVIS_FOCUSED
;
2831 g_dump_itemchanged
= TRUE
;
2832 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2834 g_dump_itemchanged
= FALSE
;
2835 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2836 "ownerdata focus all notification", FALSE
);
2837 /* focus single item, remove all */
2838 item
.stateMask
= LVIS_FOCUSED
;
2839 item
.state
= LVIS_FOCUSED
;
2840 res
= SendMessage(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2842 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2843 item
.stateMask
= LVIS_FOCUSED
;
2845 g_dump_itemchanged
= TRUE
;
2846 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2848 g_dump_itemchanged
= FALSE
;
2849 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
2850 "ownerdata remove focus all notification", TRUE
);
2852 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2853 item
.stateMask
= LVIS_CUT
;
2854 item
.state
= LVIS_CUT
;
2855 g_dump_itemchanged
= TRUE
;
2856 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2858 g_dump_itemchanged
= FALSE
;
2859 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2860 "ownerdata cut all notification", TRUE
);
2861 /* all marked cut, try again */
2862 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2863 item
.stateMask
= LVIS_CUT
;
2864 item
.state
= LVIS_CUT
;
2865 g_dump_itemchanged
= TRUE
;
2866 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2868 g_dump_itemchanged
= FALSE
;
2869 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
2870 "ownerdata cut all notification #2", TRUE
);
2872 DestroyWindow(hwnd
);
2874 /* check notifications on LVM_GETITEM */
2875 /* zero callback mask */
2876 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2877 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2878 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
2881 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2883 memset(&item
, 0, sizeof(item
));
2884 item
.stateMask
= LVIS_SELECTED
;
2885 item
.mask
= LVIF_STATE
;
2886 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2889 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2890 "ownerdata getitem selected state 1", FALSE
);
2892 /* non zero callback mask but not we asking for */
2893 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
2896 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2898 memset(&item
, 0, sizeof(item
));
2899 item
.stateMask
= LVIS_SELECTED
;
2900 item
.mask
= LVIF_STATE
;
2901 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2904 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
2905 "ownerdata getitem selected state 2", FALSE
);
2907 /* LVIS_OVERLAYMASK callback mask, asking for index */
2908 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2910 memset(&item
, 0, sizeof(item
));
2911 item
.stateMask
= LVIS_OVERLAYMASK
;
2912 item
.mask
= LVIF_STATE
;
2913 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
2916 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
2917 "ownerdata getitem selected state 2", FALSE
);
2919 DestroyWindow(hwnd
);
2921 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2922 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
| LVS_REPORT
);
2923 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2924 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2925 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2926 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2927 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
2928 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2929 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
2930 DestroyWindow(hwnd
);
2931 /* apparently it's allowed to switch these style on after creation */
2932 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2933 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2934 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2935 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2936 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2937 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2938 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2939 DestroyWindow(hwnd
);
2941 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2942 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2943 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2944 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
2945 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
2946 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2947 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
2948 DestroyWindow(hwnd
);
2951 static void test_norecompute(void)
2953 static CHAR testA
[] = "test";
2959 /* self containing control */
2960 hwnd
= create_listview_control(LVS_REPORT
);
2961 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2962 memset(&item
, 0, sizeof(item
));
2963 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
2965 item
.stateMask
= LVIS_SELECTED
;
2966 item
.state
= LVIS_SELECTED
;
2967 item
.pszText
= testA
;
2968 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2970 /* retrieve with LVIF_NORECOMPUTE */
2971 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2973 item
.pszText
= buff
;
2974 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2975 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2977 ok(lstrcmp(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
2979 item
.mask
= LVIF_TEXT
;
2981 item
.pszText
= LPSTR_TEXTCALLBACK
;
2982 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
2985 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
2987 item
.pszText
= buff
;
2988 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
2990 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2991 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
2993 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
2994 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
2995 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
2997 DestroyWindow(hwnd
);
3000 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3001 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3003 item
.mask
= LVIF_STATE
;
3004 item
.stateMask
= LVIS_SELECTED
;
3005 item
.state
= LVIS_SELECTED
;
3007 res
= SendMessageA(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&item
);
3010 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3012 item
.pszText
= buff
;
3013 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3014 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3015 res
= SendMessageA(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
3017 ok(item
.pszText
== LPSTR_TEXTCALLBACK
, "Expected (%p), got (%p)\n",
3018 LPSTR_TEXTCALLBACK
, (VOID
*)item
.pszText
);
3019 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
3021 DestroyWindow(hwnd
);
3024 static void test_nosortheader(void)
3029 hwnd
= create_listview_control(LVS_REPORT
);
3030 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3032 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3033 ok(IsWindow(header
), "header expected\n");
3035 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3036 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
3038 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3039 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
3040 /* HDS_BUTTONS retained */
3041 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3042 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
3044 DestroyWindow(hwnd
);
3046 /* create with LVS_NOSORTHEADER */
3047 hwnd
= create_listview_control(LVS_NOSORTHEADER
| LVS_REPORT
);
3048 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3050 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3051 ok(IsWindow(header
), "header expected\n");
3053 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3054 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3056 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3057 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
3058 /* not changed here */
3059 style
= GetWindowLongPtr(header
, GWL_STYLE
);
3060 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3062 DestroyWindow(hwnd
);
3065 static void test_setredraw(void)
3073 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3074 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3076 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3077 ListView seems to handle it internally without DefWinProc */
3079 /* default value first */
3080 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3083 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3084 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3085 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3087 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
3088 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3089 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3092 /* check update rect after redrawing */
3093 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3095 InvalidateRect(hwnd
, NULL
, FALSE
);
3096 RedrawWindow(hwnd
, NULL
, NULL
, RDW_UPDATENOW
);
3097 rect
.right
= rect
.bottom
= 1;
3098 GetUpdateRect(hwnd
, &rect
, FALSE
);
3099 expect(0, rect
.right
);
3100 expect(0, rect
.bottom
);
3103 hdc
= GetWindowDC(hwndparent
);
3104 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3106 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3108 ret
= SendMessage(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3110 ret
= SendMessage(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3112 ReleaseDC(hwndparent
, hdc
);
3114 /* check notification messages to show that repainting is disabled */
3115 ret
= SendMessage(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3117 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3119 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3121 InvalidateRect(hwnd
, NULL
, TRUE
);
3123 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3124 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
3126 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
3128 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3129 InvalidateRect(hwnd
, NULL
, TRUE
);
3131 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3132 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
3134 /* message isn't forwarded to header */
3135 subclass_header(hwnd
);
3136 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3137 ret
= SendMessage(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3139 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
3140 "WM_SETREDRAW: not forwarded to header", FALSE
);
3142 DestroyWindow(hwnd
);
3145 static void test_hittest(void)
3151 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3155 HIMAGELIST himl
, himl2
;
3158 hwnd
= create_listview_control(LVS_REPORT
);
3159 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3161 /* LVS_REPORT with a single subitem (2 columns) */
3162 insert_column(hwnd
, 0);
3163 insert_column(hwnd
, 1);
3164 insert_item(hwnd
, 0);
3167 /* the only purpose of that line is to be as long as a half item rect */
3168 item
.pszText
= text
;
3169 r
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&item
);
3172 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3174 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3177 memset(&bounds
, 0, sizeof(bounds
));
3178 bounds
.left
= LVIR_BOUNDS
;
3179 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
3181 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
3182 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
3183 r
= SendMessage(hwnd
, LVM_GETITEMSPACING
, TRUE
, 0);
3185 ok(bounds
.bottom
- bounds
.top
== vert
,
3186 "Vertical spacing inconsistent (%d != %d)\n", bounds
.bottom
- bounds
.top
, vert
);
3187 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
3190 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3192 /* outside columns by x position - valid is [0, 199] */
3194 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3195 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TOLEFT
, 0, FALSE
, FALSE
);
3196 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3198 x
= pos
.x
+ 50; /* column half width */
3199 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3200 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, 0, FALSE
, FALSE
);
3201 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3202 x
= pos
.x
+ 150; /* outside column */
3203 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3204 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3205 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3206 y
= (bounds
.bottom
- bounds
.top
) / 2;
3207 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3208 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3209 /* outside possible client rectangle (to right) */
3211 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3212 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3213 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3214 y
= (bounds
.bottom
- bounds
.top
) / 2;
3215 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3216 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3217 /* subitem returned with -1 item too */
3219 y
= bounds
.top
- vert
;
3220 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3221 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3222 /* return values appear to underflow with negative indices */
3226 test_lvm_subitemhittest(hwnd
, x
, y
, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3227 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3231 /* parent client area is 100x100 by default */
3232 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
3233 x
= pos
.x
+ 150; /* outside column */
3234 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3235 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, FALSE
);
3236 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3237 y
= (bounds
.bottom
- bounds
.top
) / 2;
3238 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, TRUE
);
3239 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3240 /* the same with LVS_EX_FULLROWSELECT */
3241 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3242 x
= pos
.x
+ 150; /* outside column */
3243 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3244 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, LVHT_ONITEMLABEL
, FALSE
, FALSE
);
3245 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3246 y
= (bounds
.bottom
- bounds
.top
) / 2;
3247 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3248 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
3249 x
= pos
.x
+ 150; /* outside column */
3250 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3251 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3252 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3253 y
= (bounds
.bottom
- bounds
.top
) / 2;
3254 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3255 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3256 /* outside possible client rectangle (to right) */
3258 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3259 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3260 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3261 y
= (bounds
.bottom
- bounds
.top
) / 2;
3262 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3263 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3264 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3265 himl
= ImageList_Create(16, 16, 0, 4, 4);
3266 ok(himl
!= NULL
, "failed to create imagelist\n");
3267 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3268 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3269 r
= ImageList_Add(himl
, hbmp
, 0);
3270 ok(r
== 0, "should be zero\n");
3271 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3272 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3273 r
= ImageList_Add(himl
, hbmp
, 0);
3274 ok(r
== 1, "should be one\n");
3276 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3279 item
.mask
= LVIF_IMAGE
;
3283 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3287 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3288 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3289 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3290 y
= (bounds
.bottom
- bounds
.top
) / 2;
3291 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3293 /* state icons indices are 1 based, check with valid index */
3294 item
.mask
= LVIF_STATE
;
3295 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3296 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3299 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3303 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3304 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3305 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3306 y
= (bounds
.bottom
- bounds
.top
) / 2;
3307 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3309 himl2
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3310 ok(himl2
== himl
, "should return handle\n");
3312 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3316 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3317 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, 0, FALSE
, FALSE
);
3318 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3319 y
= (bounds
.bottom
- bounds
.top
) / 2;
3320 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3322 DestroyWindow(hwnd
);
3325 static void test_getviewrect(void)
3332 hwnd
= create_listview_control(LVS_REPORT
);
3333 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3336 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3339 insert_column(hwnd
, 0);
3340 insert_column(hwnd
, 1);
3342 memset(&item
, 0, sizeof(item
));
3345 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3347 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3349 r
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3352 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3353 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3355 /* left is set to (2e31-1) - XP SP2 */
3356 expect(0, rect
.right
);
3357 expect(0, rect
.top
);
3358 expect(0, rect
.bottom
);
3360 /* switch to LVS_ICON */
3361 SetWindowLong(hwnd
, GWL_STYLE
, GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3363 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3364 r
= SendMessage(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3366 expect(0, rect
.left
);
3367 expect(0, rect
.top
);
3368 /* precise value differs for 2k, XP and Vista */
3369 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3370 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3372 DestroyWindow(hwnd
);
3375 static void test_getitemposition(void)
3382 hwnd
= create_listview_control(LVS_REPORT
);
3383 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3384 header
= subclass_header(hwnd
);
3386 /* LVS_REPORT, single item, no columns added */
3387 insert_item(hwnd
, 0);
3389 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3392 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3394 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3396 /* LVS_REPORT, single item, single column */
3397 insert_column(hwnd
, 0);
3399 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3402 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3404 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3406 memset(&rect
, 0, sizeof(rect
));
3407 SendMessage(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3410 /* offset by header height */
3411 expect(rect
.bottom
- rect
.top
, pt
.y
);
3413 DestroyWindow(hwnd
);
3416 static void test_columnscreation(void)
3421 hwnd
= create_listview_control(LVS_REPORT
);
3422 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3424 insert_item(hwnd
, 0);
3426 /* headers columns aren't created automatically */
3427 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3428 ok(IsWindow(header
), "Expected header handle\n");
3429 r
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
3432 DestroyWindow(hwnd
);
3435 static void test_getitemrect(void)
3438 HIMAGELIST himl
, himl_ret
;
3448 /* rectangle isn't empty for empty text items */
3449 hwnd
= create_listview_control(LVS_LIST
);
3450 memset(&item
, 0, sizeof(item
));
3453 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3455 rect
.left
= LVIR_LABEL
;
3456 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3458 expect(0, rect
.left
);
3459 expect(0, rect
.top
);
3461 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, rect
.right
);
3462 ReleaseDC(hwnd
, hdc
);
3463 DestroyWindow(hwnd
);
3465 hwnd
= create_listview_control(LVS_REPORT
);
3466 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3469 memset(&item
, 0, sizeof(item
));
3472 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3475 rect
.left
= LVIR_BOUNDS
;
3476 rect
.right
= rect
.top
= rect
.bottom
= -1;
3477 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3480 /* zero width rectangle with no padding */
3481 expect(0, rect
.left
);
3482 expect(0, rect
.right
);
3484 insert_column(hwnd
, 0);
3485 insert_column(hwnd
, 1);
3487 col
.mask
= LVCF_WIDTH
;
3489 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 0, (LPARAM
)&col
);
3492 col
.mask
= LVCF_WIDTH
;
3494 r
= SendMessage(hwnd
, LVM_SETCOLUMN
, 1, (LPARAM
)&col
);
3497 rect
.left
= LVIR_BOUNDS
;
3498 rect
.right
= rect
.top
= rect
.bottom
= -1;
3499 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3502 /* still no left padding */
3503 expect(0, rect
.left
);
3504 expect(150, rect
.right
);
3506 rect
.left
= LVIR_SELECTBOUNDS
;
3507 rect
.right
= rect
.top
= rect
.bottom
= -1;
3508 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3511 expect(2, rect
.left
);
3513 rect
.left
= LVIR_LABEL
;
3514 rect
.right
= rect
.top
= rect
.bottom
= -1;
3515 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3517 /* padding, column width */
3518 expect(2, rect
.left
);
3519 expect(50, rect
.right
);
3521 /* no icons attached */
3522 rect
.left
= LVIR_ICON
;
3523 rect
.right
= rect
.top
= rect
.bottom
= -1;
3524 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3527 expect(2, rect
.left
);
3528 expect(2, rect
.right
);
3531 order
[0] = 1; order
[1] = 0;
3532 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3535 r
= SendMessage(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3537 /* 1 indexed column width + padding */
3539 /* rect is at zero too */
3540 rect
.left
= LVIR_BOUNDS
;
3541 rect
.right
= rect
.top
= rect
.bottom
= -1;
3542 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3544 expect(0, rect
.left
);
3545 /* just width sum */
3546 expect(150, rect
.right
);
3548 rect
.left
= LVIR_SELECTBOUNDS
;
3549 rect
.right
= rect
.top
= rect
.bottom
= -1;
3550 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3552 /* column width + padding */
3553 expect(102, rect
.left
);
3555 /* back to initial order */
3556 order
[0] = 0; order
[1] = 1;
3557 r
= SendMessage(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3561 himl
= ImageList_Create(16, 16, 0, 2, 2);
3562 ok(himl
!= NULL
, "failed to create imagelist\n");
3563 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3564 ok(hbm
!= NULL
, "failed to create bitmap\n");
3565 r
= ImageList_Add(himl
, hbm
, 0);
3567 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3568 ok(hbm
!= NULL
, "failed to create bitmap\n");
3569 r
= ImageList_Add(himl
, hbm
, 0);
3572 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3575 item
.mask
= LVIF_STATE
;
3576 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3577 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3580 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3584 rect
.left
= LVIR_ICON
;
3585 rect
.right
= rect
.top
= rect
.bottom
= -1;
3586 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3588 /* padding + stateicon width */
3589 expect(18, rect
.left
);
3590 expect(18, rect
.right
);
3592 rect
.left
= LVIR_LABEL
;
3593 rect
.right
= rect
.top
= rect
.bottom
= -1;
3594 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3596 /* padding + stateicon width -> column width */
3597 expect(18, rect
.left
);
3598 expect(50, rect
.right
);
3600 himl_ret
= (HIMAGELIST
)SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3601 ok(himl_ret
== himl
, "got %p, expected %p\n", himl_ret
, himl
);
3603 r
= SendMessage(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3606 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3609 item
.stateMask
= ~0;
3612 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3616 rect
.left
= LVIR_ICON
;
3617 rect
.right
= rect
.top
= rect
.bottom
= -1;
3618 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3620 /* padding, icon width */
3621 expect(2, rect
.left
);
3622 expect(18, rect
.right
);
3624 rect
.left
= LVIR_LABEL
;
3625 rect
.right
= rect
.top
= rect
.bottom
= -1;
3626 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3628 /* padding + icon width -> column width */
3629 expect(18, rect
.left
);
3630 expect(50, rect
.right
);
3633 rect
.left
= LVIR_SELECTBOUNDS
;
3634 rect
.right
= rect
.top
= rect
.bottom
= -1;
3635 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3637 /* padding, column width */
3638 expect(2, rect
.left
);
3639 expect(50, rect
.right
);
3641 /* try with indentation */
3642 item
.mask
= LVIF_INDENT
;
3646 r
= SendMessage(hwnd
, LVM_SETITEM
, 0, (LPARAM
)&item
);
3650 rect
.left
= LVIR_BOUNDS
;
3651 rect
.right
= rect
.top
= rect
.bottom
= -1;
3652 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3654 /* padding + 1 icon width, column width */
3655 expect(0, rect
.left
);
3656 expect(150, rect
.right
);
3659 rect
.left
= LVIR_SELECTBOUNDS
;
3660 rect
.right
= rect
.top
= rect
.bottom
= -1;
3661 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3663 /* padding + 1 icon width, column width */
3664 expect(2 + 16, rect
.left
);
3665 expect(50, rect
.right
);
3668 rect
.left
= LVIR_LABEL
;
3669 rect
.right
= rect
.top
= rect
.bottom
= -1;
3670 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3672 /* padding + 2 icon widths, column width */
3673 expect(2 + 16*2, rect
.left
);
3674 expect(50, rect
.right
);
3677 rect
.left
= LVIR_ICON
;
3678 rect
.right
= rect
.top
= rect
.bottom
= -1;
3679 r
= SendMessage(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3681 /* padding + 1 icon width indentation, icon width */
3682 expect(2 + 16, rect
.left
);
3683 expect(34, rect
.right
);
3685 DestroyWindow(hwnd
);
3688 static void test_editbox(void)
3690 static CHAR testitemA
[] = "testitem";
3691 static CHAR testitem1A
[] = "testitem_quitelongname";
3692 static CHAR testitem2A
[] = "testITEM_quitelongname";
3693 static CHAR buffer
[25];
3694 HWND hwnd
, hwndedit
, hwndedit2
, header
;
3698 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
3699 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3701 insert_column(hwnd
, 0);
3703 memset(&item
, 0, sizeof(item
));
3704 item
.mask
= LVIF_TEXT
;
3705 item
.pszText
= testitemA
;
3708 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3711 /* test notifications without edit created */
3712 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3713 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)0xdeadbeef);
3715 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3716 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE
);
3717 /* same thing but with valid window */
3718 hwndedit
= CreateWindowA("Edit", "Test edit", WS_VISIBLE
| WS_CHILD
, 0, 0, 20,
3719 10, hwnd
, (HMENU
)1, (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
), 0);
3720 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3721 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)hwndedit
);
3723 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3724 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE
);
3725 DestroyWindow(hwndedit
);
3727 /* setting focus is necessary */
3729 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3730 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3732 /* test children Z-order after Edit box created */
3733 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3734 ok(IsWindow(header
), "Expected header to be created\n");
3735 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
3736 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
3738 /* modify initial string */
3739 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3742 /* edit window is resized and repositioned,
3743 check again for Z-order - it should be preserved */
3744 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
3745 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
3747 /* return focus to listview */
3750 memset(&item
, 0, sizeof(item
));
3751 item
.mask
= LVIF_TEXT
;
3752 item
.pszText
= buffer
;
3753 item
.cchTextMax
= sizeof(buffer
);
3756 r
= SendMessage(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3759 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3761 /* send LVM_EDITLABEL on already created edit */
3763 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3764 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3765 /* focus will be set to edit */
3766 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
3767 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3768 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
3770 /* creating label disabled when control isn't focused */
3772 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3773 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3775 /* check EN_KILLFOCUS handling */
3776 memset(&item
, 0, sizeof(item
));
3777 item
.pszText
= testitemA
;
3780 r
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3784 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3785 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3786 /* modify edit and notify control that it lost focus */
3787 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
3789 g_editbox_disp_info
.item
.pszText
= NULL
;
3790 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3792 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "expected notification with not null text\n");
3794 memset(&item
, 0, sizeof(item
));
3795 item
.pszText
= buffer
;
3796 item
.cchTextMax
= sizeof(buffer
);
3799 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3800 expect(lstrlen(item
.pszText
), r
);
3801 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
3802 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
3804 /* change item name to differ in casing only */
3806 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3807 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3808 /* modify edit and notify control that it lost focus */
3809 r
= SendMessage(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem2A
);
3811 g_editbox_disp_info
.item
.pszText
= NULL
;
3812 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3814 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "got %p\n", g_editbox_disp_info
.item
.pszText
);
3816 memset(&item
, 0, sizeof(item
));
3817 item
.pszText
= buffer
;
3818 item
.cchTextMax
= sizeof(buffer
);
3821 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3822 expect(lstrlen(item
.pszText
), r
);
3823 ok(strcmp(buffer
, testitem2A
) == 0, "got %s, expected %s\n", buffer
, testitem2A
);
3824 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
3826 /* end edit without saving */
3828 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3829 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3830 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
3832 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3833 "edit box - end edit, no change, escape", TRUE
);
3834 /* end edit with saving */
3836 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3837 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3838 r
= SendMessage(hwndedit
, WM_KEYDOWN
, VK_RETURN
, 0);
3840 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3841 "edit box - end edit, no change, return", TRUE
);
3843 memset(&item
, 0, sizeof(item
));
3844 item
.pszText
= buffer
;
3845 item
.cchTextMax
= sizeof(buffer
);
3848 r
= SendMessage(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
3849 expect(lstrlen(item
.pszText
), r
);
3850 ok(strcmp(buffer
, testitem2A
) == 0, "Expected item text to change\n");
3852 /* LVM_EDITLABEL with -1 destroys current edit */
3853 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
3854 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3855 /* no edit present */
3856 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3857 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
3858 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3859 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3861 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3862 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -1, 0);
3863 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3864 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3865 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3866 /* check another negative value */
3867 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3868 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3869 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3870 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, -2, 0);
3871 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3872 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3873 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3874 /* and value greater than max item index */
3875 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3876 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3877 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
3878 r
= SendMessage(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3879 hwndedit2
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, r
, 0);
3880 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
3881 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
3882 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
3884 /* messaging tests */
3886 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3888 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3889 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3890 /* testing only sizing messages */
3891 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
3892 "edit box create - sizing", FALSE
);
3894 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
3896 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
3897 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
3898 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3899 r
= SendMessage(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
3901 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
3902 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE
);
3904 DestroyWindow(hwnd
);
3907 static void test_notifyformat(void)
3912 hwnd
= create_listview_control(LVS_REPORT
);
3913 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3915 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3916 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3917 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3919 SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3921 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
3923 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3926 r
= SendMessage(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
3928 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3933 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3934 DestroyWindow(hwnd
);
3938 DestroyWindow(hwnd
);
3940 /* test failure in parent WM_NOTIFYFORMAT */
3942 hwnd
= create_listview_control(LVS_REPORT
);
3943 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3944 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3945 ok(IsWindow(header
), "expected header to be created\n");
3946 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3948 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3949 ok( r
== 1, "Expected 1, got %d\n", r
);
3950 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
3951 ok(r
!= 0, "Expected valid format\n");
3953 notifyFormat
= NFR_UNICODE
;
3954 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3955 expect(NFR_UNICODE
, r
);
3956 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3958 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3959 ok( r
== 1, "Expected 1, got %d\n", r
);
3961 notifyFormat
= NFR_ANSI
;
3962 r
= SendMessage(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
3963 expect(NFR_ANSI
, r
);
3964 r
= SendMessage(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3966 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3967 ok( r
== 1, "Expected 1, got %d\n", r
);
3969 DestroyWindow(hwnd
);
3971 hwndparentW
= create_parent_window(TRUE
);
3972 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
3973 if (!IsWindow(hwndparentW
)) return;
3976 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3977 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3978 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3979 ok(IsWindow(header
), "expected header to be created\n");
3980 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3982 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3984 DestroyWindow(hwnd
);
3985 /* receiving error code defaulting to ansi */
3987 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3988 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3989 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
3990 ok(IsWindow(header
), "expected header to be created\n");
3991 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
3993 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
3995 DestroyWindow(hwnd
);
3996 /* receiving ansi code from unicode window, use it */
3997 notifyFormat
= NFR_ANSI
;
3998 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
3999 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4000 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4001 ok(IsWindow(header
), "expected header to be created\n");
4002 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4004 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4006 DestroyWindow(hwnd
);
4007 /* unicode listview with ansi parent window */
4009 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4010 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4011 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4012 ok(IsWindow(header
), "expected header to be created\n");
4013 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4015 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4017 DestroyWindow(hwnd
);
4018 /* unicode listview with ansi parent window, return error code */
4020 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4021 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4022 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4023 ok(IsWindow(header
), "expected header to be created\n");
4024 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4026 r
= SendMessage(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4028 DestroyWindow(hwnd
);
4030 DestroyWindow(hwndparentW
);
4033 static void test_indentation(void)
4039 hwnd
= create_listview_control(LVS_REPORT
);
4040 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4042 memset(&item
, 0, sizeof(item
));
4043 item
.mask
= LVIF_INDENT
;
4045 item
.iIndent
= I_INDENTCALLBACK
;
4046 r
= SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4049 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4052 item
.mask
= LVIF_INDENT
;
4053 r
= SendMessage(hwnd
, LVM_GETITEM
, 0, (LPARAM
)&item
);
4056 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
4057 "get indent dispinfo", FALSE
);
4059 DestroyWindow(hwnd
);
4062 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
4067 static BOOL
is_below_comctl_5(void)
4072 hwnd
= create_listview_control(LVS_REPORT
);
4073 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4074 insert_item(hwnd
, 0);
4076 ret
= SendMessage(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
4078 DestroyWindow(hwnd
);
4083 static void test_get_set_view(void)
4089 /* test style->view mapping */
4090 hwnd
= create_listview_control(LVS_REPORT
);
4091 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4093 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4094 expect(LV_VIEW_DETAILS
, ret
);
4096 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4098 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
4099 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4100 expect(LV_VIEW_ICON
, ret
);
4102 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4103 SetWindowLongPtr(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
4104 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4105 expect(LV_VIEW_SMALLICON
, ret
);
4107 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4108 SetWindowLongPtr(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
4109 ret
= SendMessage(hwnd
, LVM_GETVIEW
, 0, 0);
4110 expect(LV_VIEW_LIST
, ret
);
4112 /* switching view doesn't touch window style */
4113 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
4115 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4116 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4117 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
4119 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4120 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4121 ret
= SendMessage(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
4123 style
= GetWindowLongPtr(hwnd
, GWL_STYLE
);
4124 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4126 DestroyWindow(hwnd
);
4129 static void test_canceleditlabel(void)
4131 HWND hwnd
, hwndedit
;
4135 static CHAR test
[] = "test";
4136 static const CHAR test1
[] = "test1";
4138 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4139 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4141 insert_item(hwnd
, 0);
4143 /* try without edit created */
4144 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4145 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4147 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4148 "cancel edit label without edit", FALSE
);
4150 /* cancel without data change */
4152 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4153 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4154 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4156 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4158 /* cancel after data change */
4159 memset(&itema
, 0, sizeof(itema
));
4160 itema
.pszText
= test
;
4161 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
4164 hwndedit
= (HWND
)SendMessage(hwnd
, LVM_EDITLABEL
, 0, 0);
4165 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4166 ret
= SetWindowText(hwndedit
, test1
);
4168 ret
= SendMessage(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4170 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4171 memset(&itema
, 0, sizeof(itema
));
4172 itema
.pszText
= buff
;
4173 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
4174 ret
= SendMessage(hwnd
, LVM_GETITEMTEXT
, 0, (LPARAM
)&itema
);
4176 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
4178 DestroyWindow(hwnd
);
4181 static void test_mapidindex(void)
4186 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4187 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
4188 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4189 insert_item(hwnd
, 0);
4190 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4192 DestroyWindow(hwnd
);
4194 hwnd
= create_listview_control(LVS_REPORT
);
4195 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4197 /* LVM_MAPINDEXTOID with invalid index */
4198 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4201 insert_item(hwnd
, 0);
4202 insert_item(hwnd
, 1);
4204 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
4206 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
4209 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4211 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4213 /* remove 0 indexed item, id retained */
4214 SendMessage(hwnd
, LVM_DELETEITEM
, 0, 0);
4215 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4217 /* new id starts from previous value */
4218 insert_item(hwnd
, 1);
4219 ret
= SendMessage(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4222 /* get index by id */
4223 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
4225 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
4227 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
4229 ret
= SendMessage(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
4232 DestroyWindow(hwnd
);
4235 static void test_getitemspacing(void)
4244 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
4245 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
4248 hwnd
= create_listview_control(LVS_ICON
);
4249 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4251 expect(cx
, LOWORD(ret
));
4252 expect(cy
, HIWORD(ret
));
4254 /* now try with icons */
4255 himl
= ImageList_Create(40, 40, 0, 4, 4);
4256 ok(himl
!= NULL
, "failed to create imagelist\n");
4257 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4258 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4259 ret
= ImageList_Add(himl
, hbmp
, 0);
4261 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4264 itema
.mask
= LVIF_IMAGE
;
4268 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
4270 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4272 /* spacing + icon size returned */
4273 expect(cx
+ 40, LOWORD(ret
));
4274 expect(cy
+ 40, HIWORD(ret
));
4276 DestroyWindow(hwnd
);
4278 hwnd
= create_listview_control(LVS_SMALLICON
);
4279 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4281 expect(cx
, LOWORD(ret
));
4282 expect(cy
, HIWORD(ret
));
4284 DestroyWindow(hwnd
);
4286 hwnd
= create_listview_control(LVS_REPORT
);
4287 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4289 expect(cx
, LOWORD(ret
));
4290 expect(cy
, HIWORD(ret
));
4292 DestroyWindow(hwnd
);
4294 hwnd
= create_listview_control(LVS_LIST
);
4295 ret
= SendMessage(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4297 expect(cx
, LOWORD(ret
));
4298 expect(cy
, HIWORD(ret
));
4300 DestroyWindow(hwnd
);
4303 static void test_getcolumnwidth(void)
4312 /* default column width */
4313 hwnd
= create_listview_control(LVS_ICON
);
4314 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4316 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4317 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
4318 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4319 todo_wine
expect(8, ret
);
4320 style
= GetWindowLong(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
4321 SetWindowLong(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
4323 ret
= SendMessage(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4325 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4327 DestroyWindow(hwnd
);
4329 /* default column width with item added */
4330 hwnd
= create_listview_control(LVS_LIST
);
4331 memset(&itema
, 0, sizeof(itema
));
4332 SendMessage(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4333 ret
= SendMessage(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4335 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, ret
);
4336 ReleaseDC(hwnd
, hdc
);
4337 DestroyWindow(hwnd
);
4340 static void test_scrollnotify(void)
4345 hwnd
= create_listview_control(LVS_REPORT
);
4347 insert_column(hwnd
, 0);
4348 insert_column(hwnd
, 1);
4349 insert_item(hwnd
, 0);
4351 /* make it scrollable - resize */
4352 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
4354 ret
= SendMessage(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
4357 /* try with dummy call */
4358 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4359 ret
= SendMessage(hwnd
, LVM_SCROLL
, 0, 0);
4361 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4362 "scroll notify 1", TRUE
);
4364 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4365 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 0);
4367 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4368 "scroll notify 2", TRUE
);
4370 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4371 ret
= SendMessage(hwnd
, LVM_SCROLL
, 1, 1);
4373 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4374 "scroll notify 3", TRUE
);
4376 DestroyWindow(hwnd
);
4379 static void test_LVS_EX_TRANSPARENTBKGND(void)
4385 hwnd
= create_listview_control(LVS_REPORT
);
4387 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4390 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4391 LVS_EX_TRANSPARENTBKGND
);
4393 ret
= SendMessage(hwnd
, LVM_GETBKCOLOR
, 0, 0);
4394 if (ret
!= CLR_NONE
)
4396 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4397 DestroyWindow(hwnd
);
4401 /* try to set some back color and check this style bit */
4402 ret
= SendMessage(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4404 ret
= SendMessage(hwnd
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
4405 ok(!(ret
& LVS_EX_TRANSPARENTBKGND
), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4407 /* now test what this style actually does */
4408 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4409 LVS_EX_TRANSPARENTBKGND
);
4411 hdc
= GetWindowDC(hwndparent
);
4413 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4414 SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
4415 ok_sequence(sequences
, PARENT_SEQ_INDEX
, lvs_ex_transparentbkgnd_seq
,
4416 "LVS_EX_TRANSPARENTBKGND parent", FALSE
);
4418 ReleaseDC(hwndparent
, hdc
);
4420 DestroyWindow(hwnd
);
4423 static void test_approximate_viewrect(void)
4430 static CHAR test
[] = "abracadabra, a very long item label";
4432 hwnd
= create_listview_control(LVS_ICON
);
4433 himl
= ImageList_Create(40, 40, 0, 4, 4);
4434 ok(himl
!= NULL
, "failed to create imagelist\n");
4435 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4436 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4437 ret
= ImageList_Add(himl
, hbmp
, 0);
4439 ret
= SendMessage(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4442 itema
.mask
= LVIF_IMAGE
;
4446 ret
= SendMessage(hwnd
, LVM_INSERTITEM
, 0, (LPARAM
)&itema
);
4449 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(75, 75));
4453 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4457 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4458 expect(MAKELONG(77,827), ret
);
4460 ret
= SendMessage(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(50, 50));
4461 ok(ret
!= 0, "got 0\n");
4463 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4464 expect(MAKELONG(102,302), ret
);
4466 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4467 expect(MAKELONG(52,52), ret
);
4469 itema
.pszText
= test
;
4470 ret
= SendMessage(hwnd
, LVM_SETITEMTEXT
, 0, (LPARAM
)&itema
);
4472 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4473 expect(MAKELONG(52,52), ret
);
4475 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 0, MAKELPARAM(100,100));
4476 expect(MAKELONG(52,2), ret
);
4477 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 1, MAKELPARAM(100,100));
4478 expect(MAKELONG(52,52), ret
);
4479 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 2, MAKELPARAM(100,100));
4480 expect(MAKELONG(102,52), ret
);
4481 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 3, MAKELPARAM(100,100));
4482 expect(MAKELONG(102,102), ret
);
4483 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 4, MAKELPARAM(100,100));
4484 expect(MAKELONG(102,102), ret
);
4485 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 5, MAKELPARAM(100,100));
4486 expect(MAKELONG(102,152), ret
);
4487 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 6, MAKELPARAM(100,100));
4488 expect(MAKELONG(102,152), ret
);
4489 ret
= SendMessage(hwnd
, LVM_APPROXIMATEVIEWRECT
, 7, MAKELPARAM(160,100));
4490 expect(MAKELONG(152,152), ret
);
4492 DestroyWindow(hwnd
);
4495 static void test_finditem(void)
4502 hwnd
= create_listview_control(LVS_REPORT
);
4503 insert_item(hwnd
, 0);
4505 memset(&fi
, 0, sizeof(fi
));
4507 /* full string search, inserted text was "foo" */
4509 fi
.flags
= LVFI_STRING
;
4511 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4513 /* partial string search, inserted text was "foo" */
4515 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4517 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4519 /* partial string search, part after start char */
4521 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4523 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4526 /* try with LVFI_SUBSTRING */
4528 fi
.flags
= LVFI_SUBSTRING
;
4530 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4533 win_skip("LVFI_SUBSTRING not supported\n");
4534 DestroyWindow(hwnd
);
4539 fi
.flags
= LVFI_SUBSTRING
;
4541 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4544 fi
.flags
= LVFI_SUBSTRING
;
4546 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4550 fi
.flags
= LVFI_SUBSTRING
| LVFI_STRING
;
4552 r
= SendMessage(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4555 DestroyWindow(hwnd
);
4558 static void test_LVS_EX_HEADERINALLVIEWS(void)
4563 hwnd
= create_listview_control(LVS_ICON
);
4565 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4566 LVS_EX_HEADERINALLVIEWS
);
4568 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4569 if (!IsWindow(header
))
4571 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4572 DestroyWindow(hwnd
);
4576 /* LVS_NOCOLUMNHEADER works as before */
4577 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4578 SetWindowLongW(hwnd
, GWL_STYLE
, style
| LVS_NOCOLUMNHEADER
);
4579 style
= GetWindowLongA(header
, GWL_STYLE
);
4580 ok(style
& HDS_HIDDEN
, "Expected HDS_HIDDEN\n");
4581 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4582 SetWindowLongW(hwnd
, GWL_STYLE
, style
& ~LVS_NOCOLUMNHEADER
);
4583 style
= GetWindowLongA(header
, GWL_STYLE
);
4584 ok(!(style
& HDS_HIDDEN
), "Expected HDS_HIDDEN to be unset\n");
4586 /* try to remove style */
4587 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
, 0);
4588 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4589 ok(IsWindow(header
), "Expected header to be created\n");
4590 style
= GetWindowLongA(header
, GWL_STYLE
);
4591 ok(!(style
& HDS_HIDDEN
), "HDS_HIDDEN not expected\n");
4593 DestroyWindow(hwnd
);
4595 /* check other styles */
4596 hwnd
= create_listview_control(LVS_LIST
);
4597 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4598 LVS_EX_HEADERINALLVIEWS
);
4599 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4600 ok(IsWindow(header
), "Expected header to be created\n");
4601 DestroyWindow(hwnd
);
4603 hwnd
= create_listview_control(LVS_SMALLICON
);
4604 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4605 LVS_EX_HEADERINALLVIEWS
);
4606 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4607 ok(IsWindow(header
), "Expected header to be created\n");
4608 DestroyWindow(hwnd
);
4610 hwnd
= create_listview_control(LVS_REPORT
);
4611 SendMessage(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
4612 LVS_EX_HEADERINALLVIEWS
);
4613 header
= (HWND
)SendMessage(hwnd
, LVM_GETHEADER
, 0, 0);
4614 ok(IsWindow(header
), "Expected header to be created\n");
4615 DestroyWindow(hwnd
);
4618 static void test_hover(void)
4623 hwnd
= create_listview_control(LVS_ICON
);
4625 /* test WM_MOUSEHOVER forwarding */
4626 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4627 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
4629 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER allow test", TRUE
);
4630 g_block_hover
= TRUE
;
4631 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4632 r
= SendMessage(hwnd
, WM_MOUSEHOVER
, 0, 0);
4634 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER block test", TRUE
);
4635 g_block_hover
= FALSE
;
4637 r
= SendMessage(hwnd
, LVM_SETHOVERTIME
, 0, 500);
4638 expect(HOVER_DEFAULT
, r
);
4639 r
= SendMessage(hwnd
, LVM_GETHOVERTIME
, 0, 0);
4642 DestroyWindow(hwnd
);
4645 static void test_destroynotify(void)
4649 hwnd
= create_listview_control(LVS_REPORT
);
4650 ok(hwnd
!= NULL
, "failed to create listview window\n");
4652 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4653 DestroyWindow(hwnd
);
4654 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_destroy
, "check destroy order", FALSE
);
4657 static void test_header_notification(void)
4659 static char textA
[] = "newtext";
4667 list
= create_listview_control(LVS_REPORT
);
4668 ok(list
!= NULL
, "failed to create listview window\n");
4670 memset(&col
, 0, sizeof(col
));
4671 col
.mask
= LVCF_WIDTH
;
4673 ret
= SendMessage(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4676 /* check list parent notification after header item changed,
4677 this test should be placed before header subclassing to avoid
4678 Listview -> Header messages to be logged */
4679 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4681 col
.mask
= LVCF_TEXT
;
4682 col
.pszText
= textA
;
4683 r
= SendMessage(list
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
4686 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_changed_seq
,
4687 "header notify, listview", FALSE
);
4688 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4689 "header notify, parent", FALSE
);
4691 header
= subclass_header(list
);
4693 ret
= SendMessage(header
, HDM_GETITEMCOUNT
, 0, 0);
4696 memset(&item
, 0, sizeof(item
));
4697 item
.mask
= HDI_WIDTH
;
4698 ret
= SendMessage(header
, HDM_GETITEMA
, 0, (LPARAM
)&item
);
4700 expect(100, item
.cxy
);
4702 nmh
.hdr
.hwndFrom
= header
;
4703 nmh
.hdr
.idFrom
= GetWindowLongPtr(header
, GWLP_ID
);
4704 nmh
.hdr
.code
= HDN_ITEMCHANGEDA
;
4707 item
.mask
= HDI_WIDTH
;
4710 ret
= SendMessage(list
, WM_NOTIFY
, 0, (LPARAM
)&nmh
);
4713 DestroyWindow(list
);
4716 static void test_createdragimage(void)
4722 list
= create_listview_control(LVS_ICON
);
4723 ok(list
!= NULL
, "failed to create listview window\n");
4725 insert_item(list
, 0);
4728 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, 0);
4729 ok(himl
== NULL
, "got %p\n", himl
);
4731 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, (LPARAM
)&pt
);
4732 ok(himl
!= NULL
, "got %p\n", himl
);
4733 ImageList_Destroy(himl
);
4735 DestroyWindow(list
);
4738 static void test_dispinfo(void)
4740 static const char testA
[] = "TEST";
4746 hwnd
= create_listview_control(LVS_ICON
);
4747 ok(hwnd
!= NULL
, "failed to create listview window\n");
4749 insert_item(hwnd
, 0);
4751 memset(&item
, 0, sizeof(item
));
4752 item
.pszText
= LPSTR_TEXTCALLBACKA
;
4753 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
4756 g_disp_A_to_W
= TRUE
;
4757 item
.pszText
= (char*)buff
;
4758 item
.cchTextMax
= sizeof(buff
)/sizeof(WCHAR
);
4759 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4760 ok(ret
== sizeof(testA
)-1, "got %d, expected 4\n", ret
);
4761 g_disp_A_to_W
= FALSE
;
4763 ok(memcmp(item
.pszText
, testA
, sizeof(testA
)) == 0,
4764 "got %s, expected %s\n", item
.pszText
, testA
);
4766 DestroyWindow(hwnd
);
4769 static void test_LVM_SETITEMTEXT(void)
4771 static char testA
[] = "TEST";
4776 hwnd
= create_listview_control(LVS_ICON
);
4777 ok(hwnd
!= NULL
, "failed to create listview window\n");
4779 insert_item(hwnd
, 0);
4781 /* null item pointer */
4782 ret
= SendMessage(hwnd
, LVM_SETITEMTEXTA
, 0, 0);
4785 ret
= SendMessage(hwnd
, LVM_SETITEMTEXTW
, 0, 0);
4788 /* index out of bounds */
4789 item
.pszText
= testA
;
4790 item
.cchTextMax
= 0; /* ignored */
4793 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 1, (LPARAM
)&item
);
4796 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, -1, (LPARAM
)&item
);
4799 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
4802 DestroyWindow(hwnd
);
4805 START_TEST(listview
)
4808 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
4810 ULONG_PTR ctx_cookie
;
4814 hComctl32
= GetModuleHandleA("comctl32.dll");
4815 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
4816 if (pInitCommonControlsEx
)
4818 INITCOMMONCONTROLSEX iccex
;
4819 iccex
.dwSize
= sizeof(iccex
);
4820 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
4821 pInitCommonControlsEx(&iccex
);
4824 InitCommonControls();
4826 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
4828 hwndparent
= create_parent_window(FALSE
);
4829 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4831 g_is_below_5
= is_below_comctl_5();
4833 test_header_notification();
4840 test_icon_spacing();
4843 test_item_position();
4848 test_subitem_rect();
4852 test_nosortheader();
4856 test_getitemposition();
4857 test_columnscreation();
4859 test_notifyformat();
4861 test_getitemspacing();
4862 test_getcolumnwidth();
4863 test_approximate_viewrect();
4866 test_destroynotify();
4867 test_createdragimage();
4869 test_LVM_SETITEMTEXT();
4871 if (!load_v6_module(&ctx_cookie
, &hCtx
))
4873 DestroyWindow(hwndparent
);
4877 /* this is a XP SP3 failure workaround */
4878 hwnd
= CreateWindowExA(0, WC_LISTVIEW
, "foo",
4879 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| LVS_REPORT
,
4881 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
4882 if (!IsWindow(hwnd
))
4884 win_skip("FIXME: failed to create ListView window.\n");
4885 unload_v6_module(ctx_cookie
, hCtx
);
4886 DestroyWindow(hwndparent
);
4890 DestroyWindow(hwnd
);
4892 /* comctl32 version 6 tests start here */
4893 test_get_set_view();
4894 test_canceleditlabel();
4896 test_scrollnotify();
4897 test_LVS_EX_TRANSPARENTBKGND();
4898 test_LVS_EX_HEADERINALLVIEWS();
4900 unload_v6_module(ctx_cookie
, hCtx
);
4902 DestroyWindow(hwndparent
);