4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009-2013 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
23 #include <wine/test.h>
26 //#include <windows.h>
34 #define PARENT_SEQ_INDEX 0
35 #define PARENT_FULL_SEQ_INDEX 1
36 #define LISTVIEW_SEQ_INDEX 2
37 #define EDITBOX_SEQ_INDEX 3
38 #define COMBINED_SEQ_INDEX 4
39 #define NUM_MSG_SEQUENCES 5
44 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
45 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
46 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
48 static const WCHAR testparentclassW
[] =
49 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
51 static HWND hwndparent
, hwndparentW
;
52 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
53 static BOOL blockEdit
;
54 /* return nonzero on NM_HOVER */
55 static BOOL g_block_hover
;
56 /* notification data for LVN_ITEMCHANGED */
57 static NMLISTVIEW g_nmlistview
;
58 /* notification data for LVN_ITEMCHANGING */
59 static NMLISTVIEW g_nmlistview_changing
;
60 /* format reported to control:
61 -1 falls to defproc, anything else returned */
62 static INT notifyFormat
;
63 /* indicates we're running < 5.80 version */
64 static BOOL g_is_below_5
;
65 /* item data passed to LVN_GETDISPINFOA */
66 static LVITEMA g_itema
;
67 /* alter notification code A->W */
68 static BOOL g_disp_A_to_W
;
69 /* dispinfo data sent with LVN_LVN_ENDLABELEDIT */
70 static NMLVDISPINFOA g_editbox_disp_info
;
71 /* when this is set focus will be tested on LVN_DELETEITEM */
72 static BOOL g_focus_test_LVN_DELETEITEM
;
74 static HWND
subclass_editbox(HWND hwndListview
);
76 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
78 static const struct message create_ownerdrawfixed_parent_seq
[] = {
79 { WM_NOTIFYFORMAT
, sent
},
80 { WM_QUERYUISTATE
, sent
|optional
}, /* Win2K and higher */
81 { WM_MEASUREITEM
, sent
},
82 { WM_PARENTNOTIFY
, sent
},
86 static const struct message redraw_listview_seq
[] = {
87 { WM_PAINT
, sent
|id
, 0, 0, LISTVIEW_ID
},
88 { WM_PAINT
, sent
|id
, 0, 0, HEADER_ID
},
89 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, HEADER_ID
},
90 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, HEADER_ID
},
91 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
92 { WM_NCPAINT
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
93 { WM_ERASEBKGND
, sent
|id
|defwinproc
|optional
, 0, 0, LISTVIEW_ID
},
97 static const struct message listview_icon_spacing_seq
[] = {
98 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(20, 30) },
99 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(25, 35) },
100 { LVM_SETICONSPACING
, sent
|lparam
, 0, MAKELPARAM(-1, -1) },
104 static const struct message listview_color_seq
[] = {
105 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
106 { LVM_GETBKCOLOR
, sent
},
107 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
108 { LVM_GETTEXTCOLOR
, sent
},
109 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(0,0,0) },
110 { LVM_GETTEXTBKCOLOR
, sent
},
112 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
113 { LVM_GETBKCOLOR
, sent
},
114 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
115 { LVM_GETTEXTCOLOR
, sent
},
116 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(100,50,200) },
117 { LVM_GETTEXTBKCOLOR
, sent
},
119 { LVM_SETBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
120 { LVM_GETBKCOLOR
, sent
},
121 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, CLR_NONE
},
122 { LVM_GETTEXTCOLOR
, sent
},
123 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, CLR_NONE
},
124 { LVM_GETTEXTBKCOLOR
, sent
},
126 { LVM_SETBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
127 { LVM_GETBKCOLOR
, sent
},
128 { LVM_SETTEXTCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
129 { LVM_GETTEXTCOLOR
, sent
},
130 { LVM_SETTEXTBKCOLOR
, sent
|lparam
, 0, RGB(255,255,255) },
131 { LVM_GETTEXTBKCOLOR
, sent
},
135 static const struct message listview_item_count_seq
[] = {
136 { LVM_GETITEMCOUNT
, sent
},
137 { LVM_INSERTITEMA
, sent
},
138 { LVM_INSERTITEMA
, sent
},
139 { LVM_INSERTITEMA
, sent
},
140 { LVM_GETITEMCOUNT
, sent
},
141 { LVM_DELETEITEM
, sent
|wparam
, 2 },
142 { WM_NCPAINT
, sent
|optional
},
143 { WM_ERASEBKGND
, sent
|optional
},
144 { LVM_GETITEMCOUNT
, sent
},
145 { LVM_DELETEALLITEMS
, sent
},
146 { LVM_GETITEMCOUNT
, sent
},
147 { LVM_INSERTITEMA
, sent
},
148 { LVM_INSERTITEMA
, sent
},
149 { LVM_GETITEMCOUNT
, sent
},
150 { LVM_INSERTITEMA
, sent
},
151 { LVM_GETITEMCOUNT
, sent
},
155 static const struct message listview_itempos_seq
[] = {
156 { LVM_INSERTITEMA
, sent
},
157 { LVM_INSERTITEMA
, sent
},
158 { LVM_INSERTITEMA
, sent
},
159 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 1, MAKELPARAM(10,5) },
160 { WM_NCPAINT
, sent
|optional
},
161 { WM_ERASEBKGND
, sent
|optional
},
162 { LVM_GETITEMPOSITION
, sent
|wparam
, 1 },
163 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 2, MAKELPARAM(0,0) },
164 { LVM_GETITEMPOSITION
, sent
|wparam
, 2 },
165 { LVM_SETITEMPOSITION
, sent
|wparam
|lparam
, 0, MAKELPARAM(20,20) },
166 { LVM_GETITEMPOSITION
, sent
|wparam
, 0 },
170 static const struct message listview_ownerdata_switchto_seq
[] = {
171 { WM_STYLECHANGING
, sent
},
172 { WM_STYLECHANGED
, sent
},
176 static const struct message listview_getorderarray_seq
[] = {
177 { LVM_GETCOLUMNORDERARRAY
, sent
|id
|wparam
, 2, 0, LISTVIEW_ID
},
178 { HDM_GETORDERARRAY
, sent
|id
|wparam
, 2, 0, HEADER_ID
},
182 static const struct message empty_seq
[] = {
186 static const struct message forward_erasebkgnd_parent_seq
[] = {
187 { WM_ERASEBKGND
, sent
},
191 static const struct message ownderdata_select_focus_parent_seq
[] = {
192 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
193 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
194 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
}, /* version 4.7x */
198 static const struct message ownerdata_setstate_all_parent_seq
[] = {
199 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
203 static const struct message ownerdata_defocus_all_parent_seq
[] = {
204 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
205 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
206 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, LVN_GETDISPINFOA
},
207 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
211 static const struct message ownerdata_deselect_all_parent_seq
[] = {
212 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ODCACHEHINT
},
213 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
217 static const struct message change_all_parent_seq
[] = {
218 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
219 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
221 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
222 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
224 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
225 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
227 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
228 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
230 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
231 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
235 static const struct message changing_all_parent_seq
[] = {
236 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
237 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
238 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
239 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
240 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
244 static const struct message textcallback_set_again_parent_seq
[] = {
245 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
246 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
250 static const struct message single_getdispinfo_parent_seq
[] = {
251 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_GETDISPINFOA
},
255 static const struct message getitemposition_seq1
[] = {
256 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
260 static const struct message getitemposition_seq2
[] = {
261 { LVM_GETITEMPOSITION
, sent
|id
, 0, 0, LISTVIEW_ID
},
262 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
266 static const struct message getsubitemrect_seq
[] = {
267 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, -1, 0, LISTVIEW_ID
},
268 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
269 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, 0, 0, LISTVIEW_ID
},
270 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
271 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, -10, 0, LISTVIEW_ID
},
272 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
273 { LVM_GETSUBITEMRECT
, sent
|id
|wparam
, 20, 0, LISTVIEW_ID
},
274 { HDM_GETITEMRECT
, sent
|id
, 0, 0, HEADER_ID
},
278 static const struct message editbox_create_pos
[] = {
279 /* sequence sent after LVN_BEGINLABELEDIT */
280 /* next two are 4.7x specific */
281 { WM_WINDOWPOSCHANGING
, sent
},
282 { WM_WINDOWPOSCHANGED
, sent
|optional
},
284 { WM_WINDOWPOSCHANGING
, sent
|optional
},
285 { WM_NCCALCSIZE
, sent
},
286 { WM_WINDOWPOSCHANGED
, sent
},
287 { WM_MOVE
, sent
|defwinproc
},
288 { WM_SIZE
, sent
|defwinproc
},
289 /* the rest is todo, skipped in 4.7x */
290 { WM_WINDOWPOSCHANGING
, sent
|optional
},
291 { WM_WINDOWPOSCHANGED
, sent
|optional
},
295 static const struct message scroll_parent_seq
[] = {
296 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_BEGINSCROLL
},
297 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDSCROLL
},
301 static const struct message setredraw_seq
[] = {
302 { WM_SETREDRAW
, sent
|id
|wparam
, FALSE
, 0, LISTVIEW_ID
},
306 static const struct message lvs_ex_transparentbkgnd_seq
[] = {
307 { WM_PRINTCLIENT
, sent
|lparam
, 0, PRF_ERASEBKGND
},
311 static const struct message edit_end_nochange
[] = {
312 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ENDLABELEDITA
},
313 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
}, /* todo */
314 { WM_NOTIFY
, sent
|id
, 0, 0, NM_SETFOCUS
},
318 static const struct message hover_parent
[] = {
319 { WM_GETDLGCODE
, sent
}, /* todo_wine */
320 { WM_NOTIFY
, sent
|id
, 0, 0, NM_HOVER
},
324 static const struct message listview_destroy
[] = {
325 { 0x0090, sent
|optional
}, /* Vista */
326 { WM_PARENTNOTIFY
, sent
},
327 { WM_SHOWWINDOW
, sent
},
328 { WM_WINDOWPOSCHANGING
, sent
},
329 { WM_WINDOWPOSCHANGED
, sent
|optional
},
330 { WM_DESTROY
, sent
},
331 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_DELETEALLITEMS
},
332 { WM_NCDESTROY
, sent
},
336 static const struct message listview_ownerdata_destroy
[] = {
337 { 0x0090, sent
|optional
}, /* Vista */
338 { WM_PARENTNOTIFY
, sent
},
339 { WM_SHOWWINDOW
, sent
},
340 { WM_WINDOWPOSCHANGING
, sent
},
341 { WM_WINDOWPOSCHANGED
, sent
|optional
},
342 { WM_DESTROY
, sent
},
343 { WM_NCDESTROY
, sent
},
347 static const struct message listview_ownerdata_deleteall
[] = {
348 { LVM_DELETEALLITEMS
, sent
},
349 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_DELETEALLITEMS
},
353 static const struct message listview_header_changed_seq
[] = {
354 { LVM_SETCOLUMNA
, sent
},
355 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
356 { WM_NOTIFY
, sent
|id
|defwinproc
, 0, 0, LISTVIEW_ID
},
360 static const struct message parent_header_click_seq
[] = {
361 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_COLUMNCLICK
},
362 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCLICKA
},
366 static const struct message parent_header_divider_dclick_seq
[] = {
367 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCHANGINGA
},
368 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
},
369 { WM_NOTIFY
, sent
|id
, 0, 0, NM_CUSTOMDRAW
},
370 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_ITEMCHANGEDA
},
371 { WM_NOTIFY
, sent
|id
, 0, 0, HDN_DIVIDERDBLCLICKA
},
375 static const struct message listview_set_imagelist
[] = {
376 { LVM_SETIMAGELIST
, sent
|id
, 0, 0, LISTVIEW_ID
},
380 static const struct message listview_header_set_imagelist
[] = {
381 { LVM_SETIMAGELIST
, sent
|id
, 0, 0, LISTVIEW_ID
},
382 { HDM_SETIMAGELIST
, sent
|id
, 0, 0, HEADER_ID
},
386 static const struct message parent_insert_focused_seq
[] = {
387 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
388 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGING
},
389 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
390 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_ITEMCHANGED
},
391 { WM_NOTIFY
, sent
|id
, 0, 0, LVN_INSERTITEM
},
395 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
397 static LONG defwndproc_counter
= 0;
401 msg
.message
= message
;
402 msg
.flags
= sent
|wparam
|lparam
;
403 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
406 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
408 /* log system messages, except for painting */
409 if (message
< WM_USER
&&
410 message
!= WM_PAINT
&&
411 message
!= WM_ERASEBKGND
&&
412 message
!= WM_NCPAINT
&&
413 message
!= WM_NCHITTEST
&&
414 message
!= WM_GETTEXT
&&
415 message
!= WM_GETICON
&&
416 message
!= WM_DEVICECHANGE
)
418 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
419 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
421 add_message(sequences
, PARENT_FULL_SEQ_INDEX
, &msg
);
427 switch (((NMHDR
*)lParam
)->code
)
429 case LVN_BEGINLABELEDITA
:
433 /* subclass edit box */
435 edit
= subclass_editbox(((NMHDR
*)lParam
)->hwndFrom
);
439 INT len
= SendMessageA(edit
, EM_GETLIMITTEXT
, 0, 0);
440 ok(len
== 259 || broken(len
== 260) /* includes NULL in NT4 */,
441 "text limit %d, expected 259\n", len
);
446 case LVN_ENDLABELEDITA
:
450 /* always accept new item text */
451 NMLVDISPINFOA
*di
= (NMLVDISPINFOA
*)lParam
;
452 g_editbox_disp_info
= *di
;
453 trace("LVN_ENDLABELEDIT: text=%s\n", di
->item
.pszText
? di
->item
.pszText
: "(null)");
455 /* edit control still available from this notification */
456 edit
= (HWND
)SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETEDITCONTROL
, 0, 0);
457 ok(IsWindow(edit
), "expected valid edit control handle\n");
458 ok((GetWindowLongA(edit
, GWL_STYLE
) & ES_MULTILINE
) == 0, "edit is multiline\n");
462 case LVN_BEGINSCROLL
:
465 NMLVSCROLL
*pScroll
= (NMLVSCROLL
*)lParam
;
467 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll
->hdr
.code
== LVN_BEGINSCROLL
?
468 "BEGIN" : "END", pScroll
->dx
, pScroll
->dy
);
471 case LVN_ITEMCHANGING
:
473 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
474 g_nmlistview_changing
= *nmlv
;
477 case LVN_ITEMCHANGED
:
479 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
480 g_nmlistview
= *nmlv
;
483 case LVN_GETDISPINFOA
:
485 NMLVDISPINFOA
*dispinfo
= (NMLVDISPINFOA
*)lParam
;
486 g_itema
= dispinfo
->item
;
488 if (g_disp_A_to_W
&& (dispinfo
->item
.mask
& LVIF_TEXT
))
490 static const WCHAR testW
[] = {'T','E','S','T',0};
491 dispinfo
->hdr
.code
= LVN_GETDISPINFOW
;
492 memcpy(dispinfo
->item
.pszText
, testW
, sizeof(testW
));
495 /* test control buffer size for text, 10 used to mask cases when control
496 is using caller buffer to process LVM_GETITEM for example */
497 if (dispinfo
->item
.mask
& LVIF_TEXT
&& dispinfo
->item
.cchTextMax
> 10)
498 ok(dispinfo
->item
.cchTextMax
== 260 ||
499 broken(dispinfo
->item
.cchTextMax
== 264) /* NT4 reports aligned size */,
500 "buffer size %d\n", dispinfo
->item
.cchTextMax
);
504 if (g_focus_test_LVN_DELETEITEM
)
506 NMLISTVIEW
*nmlv
= (NMLISTVIEW
*)lParam
;
509 state
= SendMessageA(((NMHDR
*)lParam
)->hwndFrom
, LVM_GETITEMSTATE
, nmlv
->iItem
, LVIS_FOCUSED
);
510 ok(state
== 0, "got state %x\n", state
);
514 if (g_block_hover
) return 1;
519 case WM_NOTIFYFORMAT
:
521 /* force to return format */
522 if (lParam
== NF_QUERY
&& notifyFormat
!= -1) return notifyFormat
;
527 defwndproc_counter
++;
528 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
529 defwndproc_counter
--;
534 static BOOL
register_parent_wnd_class(BOOL Unicode
)
542 clsW
.lpfnWndProc
= parent_wnd_proc
;
545 clsW
.hInstance
= GetModuleHandleW(NULL
);
547 clsW
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
548 clsW
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
549 clsW
.lpszMenuName
= NULL
;
550 clsW
.lpszClassName
= testparentclassW
;
555 clsA
.lpfnWndProc
= parent_wnd_proc
;
558 clsA
.hInstance
= GetModuleHandleA(NULL
);
560 clsA
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
561 clsA
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
562 clsA
.lpszMenuName
= NULL
;
563 clsA
.lpszClassName
= "Listview test parent class";
566 return Unicode
? RegisterClassW(&clsW
) : RegisterClassA(&clsA
);
569 static HWND
create_parent_window(BOOL Unicode
)
571 static const WCHAR nameW
[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
574 if (!register_parent_wnd_class(Unicode
))
581 hwnd
= CreateWindowExW(0, testparentclassW
, nameW
,
582 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
583 WS_MAXIMIZEBOX
| WS_VISIBLE
,
585 GetDesktopWindow(), NULL
, GetModuleHandleW(NULL
), NULL
);
587 hwnd
= CreateWindowExA(0, "Listview test parent class",
588 "Listview test parent window",
589 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
590 WS_MAXIMIZEBOX
| WS_VISIBLE
,
592 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
593 SetWindowPos( hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
597 static LRESULT WINAPI
listview_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
599 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
600 static LONG defwndproc_counter
= 0;
604 /* some debug output for style changing */
605 if ((message
== WM_STYLECHANGING
||
606 message
== WM_STYLECHANGED
) && lParam
)
608 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
609 trace("\told style: 0x%08x, new style: 0x%08x\n", style
->styleOld
, style
->styleNew
);
612 msg
.message
= message
;
613 msg
.flags
= sent
|wparam
|lparam
;
614 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
617 msg
.id
= LISTVIEW_ID
;
618 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
619 add_message(sequences
, COMBINED_SEQ_INDEX
, &msg
);
621 defwndproc_counter
++;
622 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
623 defwndproc_counter
--;
627 static HWND
create_listview_control(DWORD style
)
633 GetClientRect(hwndparent
, &rect
);
634 hwnd
= CreateWindowExA(0, WC_LISTVIEWA
, "foo",
635 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
636 0, 0, rect
.right
, rect
.bottom
,
637 hwndparent
, NULL
, GetModuleHandleA(NULL
), NULL
);
638 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
640 if (!hwnd
) return NULL
;
642 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
643 (LONG_PTR
)listview_subclass_proc
);
644 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
649 /* unicode listview window with specified parent */
650 static HWND
create_listview_controlW(DWORD style
, HWND parent
)
655 static const WCHAR nameW
[] = {'f','o','o',0};
657 GetClientRect(parent
, &rect
);
658 hwnd
= CreateWindowExW(0, WC_LISTVIEWW
, nameW
,
659 WS_CHILD
| WS_BORDER
| WS_VISIBLE
| style
,
660 0, 0, rect
.right
, rect
.bottom
,
661 parent
, NULL
, GetModuleHandleW(NULL
), NULL
);
662 ok(hwnd
!= NULL
, "gle=%d\n", GetLastError());
664 if (!hwnd
) return NULL
;
666 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
,
667 (LONG_PTR
)listview_subclass_proc
);
668 SetWindowLongPtrW(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
673 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
675 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
676 static LONG defwndproc_counter
= 0;
680 msg
.message
= message
;
681 msg
.flags
= sent
|wparam
|lparam
;
682 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
686 add_message(sequences
, LISTVIEW_SEQ_INDEX
, &msg
);
688 defwndproc_counter
++;
689 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
690 defwndproc_counter
--;
694 static HWND
subclass_header(HWND hwndListview
)
699 hwnd
= (HWND
)SendMessageA(hwndListview
, LVM_GETHEADER
, 0, 0);
700 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
701 (LONG_PTR
)header_subclass_proc
);
702 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
707 static LRESULT WINAPI
editbox_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
709 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
710 static LONG defwndproc_counter
= 0;
714 msg
.message
= message
;
715 msg
.flags
= sent
|wparam
|lparam
;
716 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
721 /* all we need is sizing */
722 if (message
== WM_WINDOWPOSCHANGING
||
723 message
== WM_NCCALCSIZE
||
724 message
== WM_WINDOWPOSCHANGED
||
725 message
== WM_MOVE
||
728 add_message(sequences
, EDITBOX_SEQ_INDEX
, &msg
);
731 defwndproc_counter
++;
732 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
733 defwndproc_counter
--;
737 static HWND
subclass_editbox(HWND hwndListview
)
742 hwnd
= (HWND
)SendMessageA(hwndListview
, LVM_GETEDITCONTROL
, 0, 0);
743 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
,
744 (LONG_PTR
)editbox_subclass_proc
);
745 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
750 /* Performs a single LVM_HITTEST test */
751 static void test_lvm_hittest_(HWND hwnd
, INT x
, INT y
, INT item
, UINT flags
, UINT broken_flags
,
752 BOOL todo_item
, BOOL todo_flags
, int line
)
761 ret
= SendMessageA(hwnd
, LVM_HITTEST
, 0, (LPARAM
)&lpht
);
767 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
768 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
769 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
774 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
775 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
776 ok_(__FILE__
, line
)(lpht
.iSubItem
== 10, "Expected subitem not overwrited\n");
782 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
784 else if (broken_flags
)
785 ok_(__FILE__
, line
)(lpht
.flags
== flags
|| broken(lpht
.flags
== broken_flags
),
786 "Expected flags %x, got %x\n", flags
, lpht
.flags
);
788 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
791 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
793 /* Performs a single LVM_SUBITEMHITTEST test */
794 static void test_lvm_subitemhittest_(HWND hwnd
, INT x
, INT y
, INT item
, INT subitem
, UINT flags
,
795 BOOL todo_item
, BOOL todo_subitem
, BOOL todo_flags
, int line
)
803 ret
= SendMessageA(hwnd
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lpht
);
809 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
810 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
815 ok_(__FILE__
, line
)(ret
== item
, "Expected %d retval, got %d\n", item
, ret
);
816 ok_(__FILE__
, line
)(lpht
.iItem
== item
, "Expected %d item, got %d\n", item
, lpht
.iItem
);
822 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
825 ok_(__FILE__
, line
)(lpht
.iSubItem
== subitem
, "Expected subitem %d, got %d\n", subitem
, lpht
.iSubItem
);
830 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
833 ok_(__FILE__
, line
)(lpht
.flags
== flags
, "Expected flags 0x%x, got 0x%x\n", flags
, lpht
.flags
);
836 #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__)
838 static void test_images(void)
846 static CHAR hello
[] = "hello";
848 himl
= ImageList_Create(40, 40, 0, 4, 4);
849 ok(himl
!= NULL
, "failed to create imagelist\n");
851 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
852 ok(hbmp
!= NULL
, "failed to create bitmap\n");
854 r
= ImageList_Add(himl
, hbmp
, 0);
855 ok(r
== 0, "should be zero\n");
857 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED
,
858 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
859 ok(hwnd
!= NULL
, "failed to create listview window\n");
861 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0,
862 LVS_EX_UNDERLINEHOT
| LVS_EX_FLATSB
| LVS_EX_ONECLICKACTIVATE
);
864 ok(r
== 0, "should return zero\n");
866 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
867 ok(r
== 0, "should return zero\n");
869 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELONG(100,50));
870 ok(r
!= 0, "got 0\n");
872 /* returns dimensions */
874 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
875 ok(r
== 0, "should be zero items\n");
877 item
.mask
= LVIF_IMAGE
| LVIF_TEXT
;
882 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
883 ok(r
== -1, "should fail\n");
886 item
.pszText
= hello
;
887 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
888 ok(r
== 0, "should not fail\n");
890 memset(&r1
, 0, sizeof r1
);
892 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r1
);
895 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
896 ok(r
== TRUE
, "should not fail\n");
899 item
.pszText
= hello
;
900 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
901 ok(r
== 0, "should not fail\n");
903 memset(&r2
, 0, sizeof r2
);
905 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
) &r2
);
908 ok(!memcmp(&r1
, &r2
, sizeof r1
), "rectangle should be the same\n");
913 static void test_checkboxes(void)
918 static CHAR text
[] = "Text",
922 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
923 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
924 ok(hwnd
!= NULL
, "failed to create listview window\n");
926 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
927 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
928 item
.stateMask
= 0xffff;
933 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
937 item
.mask
= LVIF_STATE
;
938 item
.stateMask
= 0xffff;
939 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
941 ok(item
.state
== 0xfccc, "state %x\n", item
.state
);
943 /* Don't set LVIF_STATE */
944 item
.mask
= LVIF_TEXT
;
945 item
.stateMask
= 0xffff;
950 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
954 item
.mask
= LVIF_STATE
;
955 item
.stateMask
= 0xffff;
956 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
958 ok(item
.state
== 0, "state %x\n", item
.state
);
960 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
963 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
965 item
.mask
= LVIF_STATE
;
966 item
.stateMask
= 0xffff;
967 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
969 if (item
.state
!= 0x1ccc)
971 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
976 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
978 item
.mask
= LVIF_TEXT
;
980 item
.pszText
= text2
;
981 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
985 item
.mask
= LVIF_STATE
;
986 item
.stateMask
= 0xffff;
987 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
989 ok(item
.state
== 0x1000, "state %x\n", item
.state
);
991 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
993 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
994 item
.stateMask
= 0xffff;
996 item
.pszText
= text3
;
997 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1001 item
.mask
= LVIF_STATE
;
1002 item
.stateMask
= 0xffff;
1003 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1005 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
1007 /* Set an item's state to checked */
1009 item
.mask
= LVIF_STATE
;
1010 item
.stateMask
= 0xf000;
1011 item
.state
= 0x2000;
1012 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1016 item
.mask
= LVIF_STATE
;
1017 item
.stateMask
= 0xffff;
1018 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1020 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1022 /* Check that only the bits we asked for are returned,
1023 * and that all the others are set to zero
1026 item
.mask
= LVIF_STATE
;
1027 item
.stateMask
= 0xf000;
1028 item
.state
= 0xffff;
1029 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1031 ok(item
.state
== 0x2000, "state %x\n", item
.state
);
1033 /* Set the style again and check that doesn't change an item's state */
1034 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1035 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1038 item
.mask
= LVIF_STATE
;
1039 item
.stateMask
= 0xffff;
1040 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1042 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1044 /* Unsetting the checkbox extended style doesn't change an item's state */
1045 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, 0);
1046 ok(r
== LVS_EX_CHECKBOXES
, "ret %x\n", r
);
1049 item
.mask
= LVIF_STATE
;
1050 item
.stateMask
= 0xffff;
1051 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1053 ok(item
.state
== 0x2aaa, "state %x\n", item
.state
);
1055 /* Now setting the style again will change an item's state */
1056 r
= SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_CHECKBOXES
, LVS_EX_CHECKBOXES
);
1060 item
.mask
= LVIF_STATE
;
1061 item
.stateMask
= 0xffff;
1062 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1064 ok(item
.state
== 0x1aaa, "state %x\n", item
.state
);
1066 /* Toggle checkbox tests (bug 9934) */
1067 memset (&item
, 0xcc, sizeof(item
));
1068 item
.mask
= LVIF_STATE
;
1071 item
.state
= LVIS_FOCUSED
;
1072 item
.stateMask
= LVIS_FOCUSED
;
1073 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1077 item
.mask
= LVIF_STATE
;
1078 item
.stateMask
= 0xffff;
1079 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1081 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1083 r
= SendMessageA(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1085 r
= SendMessageA(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1089 item
.mask
= LVIF_STATE
;
1090 item
.stateMask
= 0xffff;
1091 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1093 ok(item
.state
== 0x2aab, "state %x\n", item
.state
);
1095 r
= SendMessageA(hwnd
, WM_KEYDOWN
, VK_SPACE
, 0);
1097 r
= SendMessageA(hwnd
, WM_KEYUP
, VK_SPACE
, 0);
1101 item
.mask
= LVIF_STATE
;
1102 item
.stateMask
= 0xffff;
1103 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1105 ok(item
.state
== 0x1aab, "state %x\n", item
.state
);
1107 DestroyWindow(hwnd
);
1110 static void insert_column(HWND hwnd
, int idx
)
1115 memset(&column
, 0xcc, sizeof(column
));
1116 column
.mask
= LVCF_SUBITEM
;
1117 column
.iSubItem
= idx
;
1119 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, idx
, (LPARAM
)&column
);
1123 static void insert_item(HWND hwnd
, int idx
)
1125 static CHAR text
[] = "foo";
1130 memset(&item
, 0xcc, sizeof (item
));
1131 item
.mask
= LVIF_TEXT
;
1134 item
.pszText
= text
;
1136 rc
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
1140 static void test_items(void)
1142 const LPARAM lparamTest
= 0x42;
1143 static CHAR text
[] = "Text";
1149 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1150 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1151 ok(hwnd
!= NULL
, "failed to create listview window\n");
1154 * Test setting/getting item params
1157 /* Set up two columns */
1158 insert_column(hwnd
, 0);
1159 insert_column(hwnd
, 1);
1161 /* LVIS_SELECTED with zero stateMask */
1163 memset (&item
, 0, sizeof (item
));
1164 item
.mask
= LVIF_STATE
;
1165 item
.state
= LVIS_SELECTED
;
1169 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1172 memset (&item
, 0xcc, sizeof (item
));
1173 item
.mask
= LVIF_STATE
;
1174 item
.stateMask
= LVIS_SELECTED
;
1178 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1180 ok(item
.state
& LVIS_SELECTED
, "Expected LVIS_SELECTED\n");
1181 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1183 /* LVIS_SELECTED with zero stateMask */
1185 memset (&item
, 0, sizeof (item
));
1186 item
.mask
= LVIF_STATE
;
1187 item
.state
= LVIS_FOCUSED
;
1191 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1194 memset (&item
, 0xcc, sizeof (item
));
1195 item
.mask
= LVIF_STATE
;
1196 item
.stateMask
= LVIS_FOCUSED
;
1200 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1202 ok(item
.state
& LVIS_FOCUSED
, "Expected LVIS_FOCUSED\n");
1203 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1205 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1207 memset (&item
, 0, sizeof (item
));
1208 item
.mask
= LVIF_STATE
;
1209 item
.state
= LVIS_CUT
;
1210 item
.stateMask
= LVIS_FOCUSED
;
1213 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1216 memset (&item
, 0xcc, sizeof (item
));
1217 item
.mask
= LVIF_STATE
;
1218 item
.stateMask
= LVIS_CUT
;
1222 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1224 ok(item
.state
& LVIS_CUT
, "Expected LVIS_CUT\n");
1225 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
1227 /* Insert an item with just a param */
1228 memset (&item
, 0xcc, sizeof (item
));
1229 item
.mask
= LVIF_PARAM
;
1232 item
.lParam
= lparamTest
;
1233 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1236 /* Test getting of the param */
1237 memset (&item
, 0xcc, sizeof (item
));
1238 item
.mask
= LVIF_PARAM
;
1241 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1243 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1245 /* Set up a subitem */
1246 memset (&item
, 0xcc, sizeof (item
));
1247 item
.mask
= LVIF_TEXT
;
1250 item
.pszText
= text
;
1251 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1254 item
.mask
= LVIF_TEXT
;
1257 item
.pszText
= buffA
;
1258 item
.cchTextMax
= sizeof(buffA
);
1259 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1261 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got text %s, expected %s\n", item
.pszText
, text
);
1263 /* set up with extra flag */
1264 /* 1. reset subitem text */
1265 item
.mask
= LVIF_TEXT
;
1268 item
.pszText
= NULL
;
1269 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1272 item
.mask
= LVIF_TEXT
;
1275 item
.pszText
= buffA
;
1277 item
.cchTextMax
= sizeof(buffA
);
1278 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1280 ok(item
.pszText
[0] == 0, "got %p\n", item
.pszText
);
1282 /* 2. set new text with extra flag specified */
1283 item
.mask
= LVIF_TEXT
| LVIF_DI_SETITEM
;
1286 item
.pszText
= text
;
1287 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1288 ok(r
== 1 || broken(r
== 0) /* NT4 */, "ret %d\n", r
);
1292 item
.mask
= LVIF_TEXT
;
1295 item
.pszText
= buffA
;
1297 item
.cchTextMax
= sizeof(buffA
);
1298 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1300 ok(!memcmp(item
.pszText
, text
, sizeof(text
)), "got %s, expected %s\n", item
.pszText
, text
);
1303 /* Query param from subitem: returns main item param */
1304 memset (&item
, 0xcc, sizeof (item
));
1305 item
.mask
= LVIF_PARAM
;
1308 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1310 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1312 /* Set up param on first subitem: no effect */
1313 memset (&item
, 0xcc, sizeof (item
));
1314 item
.mask
= LVIF_PARAM
;
1317 item
.lParam
= lparamTest
+1;
1318 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1321 /* Query param from subitem again: should still return main item param */
1322 memset (&item
, 0xcc, sizeof (item
));
1323 item
.mask
= LVIF_PARAM
;
1326 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1328 ok(item
.lParam
== lparamTest
, "got lParam %lx, expected %lx\n", item
.lParam
, lparamTest
);
1330 /**** Some tests of state highlighting ****/
1331 memset (&item
, 0xcc, sizeof (item
));
1332 item
.mask
= LVIF_STATE
;
1335 item
.state
= LVIS_SELECTED
;
1336 item
.stateMask
= LVIS_SELECTED
| LVIS_DROPHILITED
;
1337 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1340 item
.state
= LVIS_DROPHILITED
;
1341 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
) &item
);
1344 memset (&item
, 0xcc, sizeof (item
));
1345 item
.mask
= LVIF_STATE
;
1348 item
.stateMask
= -1;
1349 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1351 ok(item
.state
== LVIS_SELECTED
, "got state %x, expected %x\n", item
.state
, LVIS_SELECTED
);
1353 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1355 todo_wine
ok(item
.state
== LVIS_DROPHILITED
, "got state %x, expected %x\n", item
.state
, LVIS_DROPHILITED
);
1357 /* some notnull but meaningless masks */
1358 memset (&item
, 0, sizeof(item
));
1359 item
.mask
= LVIF_NORECOMPUTE
;
1362 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1364 memset (&item
, 0, sizeof(item
));
1365 item
.mask
= LVIF_DI_SETITEM
;
1368 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
1371 /* set text to callback value already having it */
1372 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
1374 memset (&item
, 0, sizeof (item
));
1375 item
.mask
= LVIF_TEXT
;
1376 item
.pszText
= LPSTR_TEXTCALLBACKA
;
1378 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
1380 memset (&item
, 0, sizeof (item
));
1382 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1384 item
.pszText
= LPSTR_TEXTCALLBACKA
;
1385 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0 , (LPARAM
) &item
);
1388 ok_sequence(sequences
, PARENT_SEQ_INDEX
, textcallback_set_again_parent_seq
,
1389 "check callback text comparison rule", FALSE
);
1391 DestroyWindow(hwnd
);
1394 static void test_columns(void)
1403 hwnd
= CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT
,
1404 10, 10, 100, 200, hwndparent
, NULL
, NULL
, NULL
);
1405 ok(hwnd
!= NULL
, "failed to create listview window\n");
1407 /* Add a column with no mask */
1408 memset(&column
, 0xcc, sizeof(column
));
1410 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1411 ok(rc
== 0, "Inserting column with no mask failed with %d\n", rc
);
1413 /* Check its width */
1414 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
1415 ok(rc
== 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc
);
1417 DestroyWindow(hwnd
);
1419 /* LVM_GETCOLUMNORDERARRAY */
1420 hwnd
= create_listview_control(LVS_REPORT
);
1421 subclass_header(hwnd
);
1423 memset(&column
, 0, sizeof(column
));
1424 column
.mask
= LVCF_WIDTH
;
1426 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&column
);
1430 rc
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&column
);
1433 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1435 rc
= SendMessageA(hwnd
, LVM_GETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
1437 ok(order
[0] == 0, "Expected order 0, got %d\n", order
[0]);
1438 ok(order
[1] == 1, "Expected order 1, got %d\n", order
[1]);
1440 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_getorderarray_seq
, "get order array", FALSE
);
1442 /* after column added subitem is considered as present */
1443 insert_item(hwnd
, 0);
1445 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1447 item
.pszText
= buff
;
1448 item
.cchTextMax
= sizeof(buff
);
1451 item
.mask
= LVIF_TEXT
;
1452 memset(&g_itema
, 0, sizeof(g_itema
));
1453 rc
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
1455 ok(g_itema
.iSubItem
== 1, "got %d\n", g_itema
.iSubItem
);
1457 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
1458 "get subitem text after column added", FALSE
);
1460 DestroyWindow(hwnd
);
1463 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1464 static WNDPROC listviewWndProc
;
1465 static HIMAGELIST test_create_imagelist
;
1467 static LRESULT CALLBACK
create_test_wndproc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1471 if (uMsg
== WM_CREATE
)
1473 CREATESTRUCTA
*lpcs
= (CREATESTRUCTA
*)lParam
;
1474 lpcs
->style
|= LVS_REPORT
;
1476 ret
= CallWindowProcA(listviewWndProc
, hwnd
, uMsg
, wParam
, lParam
);
1477 if (uMsg
== WM_CREATE
) SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)test_create_imagelist
);
1481 static void test_create(void)
1492 cls
.cbSize
= sizeof(WNDCLASSEXA
);
1493 ok(GetClassInfoExA(GetModuleHandleA(NULL
), "SysListView32", &cls
), "GetClassInfoEx failed\n");
1494 listviewWndProc
= cls
.lpfnWndProc
;
1495 cls
.lpfnWndProc
= create_test_wndproc
;
1496 cls
.lpszClassName
= "MyListView32";
1497 ok(RegisterClassExA(&cls
), "RegisterClassEx failed\n");
1499 test_create_imagelist
= ImageList_Create(16, 16, 0, 5, 10);
1500 hList
= CreateWindowA("MyListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1501 ok((HIMAGELIST
)SendMessageA(hList
, LVM_GETIMAGELIST
, 0, 0) == test_create_imagelist
, "Image list not obtained\n");
1502 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1504 if (!IsWindow(hHeader
))
1507 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1508 DestroyWindow(hList
);
1512 ok(IsWindow(hHeader
) && IsWindowVisible(hHeader
), "Listview not in report mode\n");
1513 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1514 DestroyWindow(hList
);
1516 /* header isn't created on LVS_ICON and LVS_LIST styles */
1517 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1518 GetModuleHandleA(NULL
), 0);
1519 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1520 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1521 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1523 memset(&col
, 0, sizeof(LVCOLUMNA
));
1524 col
.mask
= LVCF_WIDTH
;
1526 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1528 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1529 ok(IsWindow(hHeader
), "Header should be created\n");
1530 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1531 style
= GetWindowLongA(hHeader
, GWL_STYLE
);
1532 ok(!(style
& HDS_HIDDEN
), "Not expected HDS_HIDDEN\n");
1533 DestroyWindow(hList
);
1535 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1536 GetModuleHandleA(NULL
), 0);
1537 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1538 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1539 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1541 memset(&col
, 0, sizeof(LVCOLUMNA
));
1542 col
.mask
= LVCF_WIDTH
;
1544 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1546 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1547 ok(IsWindow(hHeader
), "Header should be created\n");
1548 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1549 DestroyWindow(hList
);
1551 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1552 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
, 0, 0, 100, 100, NULL
, NULL
,
1553 GetModuleHandleA(NULL
), 0);
1554 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
, GetWindowLongPtrA(hList
, GWL_STYLE
) | LVS_REPORT
);
1555 ok(ret
& WS_VISIBLE
, "Style wrong, should have WS_VISIBLE\n");
1556 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1557 ok(IsWindow(hHeader
), "Header should be created\n");
1558 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
, GetWindowLongA(hList
, GWL_STYLE
) & ~LVS_REPORT
);
1559 ok((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1560 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1561 ok(IsWindow(hHeader
), "Header should be created\n");
1562 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1563 DestroyWindow(hList
);
1565 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1566 hList
= CreateWindowA("SysListView32", "Test", WS_VISIBLE
|LVS_LIST
, 0, 0, 100, 100, NULL
, NULL
,
1567 GetModuleHandleA(NULL
), 0);
1568 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
,
1569 (GetWindowLongPtrA(hList
, GWL_STYLE
) & ~LVS_LIST
) | LVS_REPORT
);
1570 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_LIST
)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1571 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1572 ok(IsWindow(hHeader
), "Header should be created\n");
1573 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1574 ret
= SetWindowLongPtrA(hList
, GWL_STYLE
,
1575 (GetWindowLongPtrA(hList
, GWL_STYLE
) & ~LVS_REPORT
) | LVS_LIST
);
1576 ok(((ret
& WS_VISIBLE
) && (ret
& LVS_REPORT
)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1577 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1578 ok(IsWindow(hHeader
), "Header should be created\n");
1579 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1580 DestroyWindow(hList
);
1582 /* LVS_REPORT without WS_VISIBLE */
1583 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1584 GetModuleHandleA(NULL
), 0);
1585 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1586 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1587 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1589 memset(&col
, 0, sizeof(LVCOLUMNA
));
1590 col
.mask
= LVCF_WIDTH
;
1592 r
= SendMessageA(hList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
1594 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1595 ok(IsWindow(hHeader
), "Header should be created\n");
1596 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1597 DestroyWindow(hList
);
1599 /* LVS_REPORT without WS_VISIBLE, try to show it */
1600 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1601 GetModuleHandleA(NULL
), 0);
1602 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1603 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1604 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1605 ShowWindow(hList
, SW_SHOW
);
1606 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1607 ok(IsWindow(hHeader
), "Header should be created\n");
1608 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1609 DestroyWindow(hList
);
1611 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1612 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
|LVS_NOCOLUMNHEADER
|WS_VISIBLE
,
1613 0, 0, 100, 100, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1614 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1615 ok(IsWindow(hHeader
), "Header should be created\n");
1616 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1617 /* HDS_DRAGDROP set by default */
1618 ok(GetWindowLongPtrA(hHeader
, GWL_STYLE
) & HDS_DRAGDROP
, "Expected header to have HDS_DRAGDROP\n");
1619 DestroyWindow(hList
);
1621 /* setting LVS_EX_HEADERDRAGDROP creates header */
1622 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1623 GetModuleHandleA(NULL
), 0);
1624 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1625 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1626 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1627 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1628 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1629 ok(IsWindow(hHeader
) ||
1630 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1631 "Header should be created\n");
1632 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1633 DestroyWindow(hList
);
1635 /* setting LVS_EX_GRIDLINES creates header */
1636 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1637 GetModuleHandleA(NULL
), 0);
1638 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1639 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1640 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1641 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_GRIDLINES
);
1642 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1643 ok(IsWindow(hHeader
) ||
1644 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1645 "Header should be created\n");
1646 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1647 DestroyWindow(hList
);
1649 /* setting LVS_EX_FULLROWSELECT creates header */
1650 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1651 GetModuleHandleA(NULL
), 0);
1652 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1653 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1654 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1655 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
1656 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1657 ok(IsWindow(hHeader
) ||
1658 broken(!IsWindow(hHeader
)), /* 4.7x common controls */
1659 "Header should be created\n");
1660 ok(hHeader
== GetDlgItem(hList
, 0), "Expected header as dialog item\n");
1661 DestroyWindow(hList
);
1663 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1664 hList
= create_listview_control(LVS_ICON
);
1665 SendMessageA(hList
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_HEADERDRAGDROP
);
1666 r
= SendMessageA(hList
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
1667 ok(r
& LVS_EX_HEADERDRAGDROP
, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1668 DestroyWindow(hList
);
1670 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1671 hList
= CreateWindowA("SysListView32", "Test", LVS_REPORT
, 0, 0, 100, 100, NULL
, NULL
,
1672 GetModuleHandleA(NULL
), 0);
1673 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1674 ok(NULL
== GetDlgItem(hList
, 0), "NULL dialog item expected\n");
1676 rect
.left
= LVIR_BOUNDS
;
1678 rect
.right
= rect
.bottom
= -10;
1679 r
= SendMessageA(hList
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
1680 /* right value contains garbage, probably because header columns are not set up */
1681 expect(0, rect
.bottom
);
1684 hHeader
= (HWND
)SendMessageA(hList
, LVM_GETHEADER
, 0, 0);
1685 ok(!IsWindow(hHeader
), "Header shouldn't be created\n");
1686 ok(GetDlgItem(hList
, 0) == NULL
, "NULL dialog item expected\n");
1688 DestroyWindow(hList
);
1690 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1691 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1692 hList
= create_listview_control(LVS_OWNERDRAWFIXED
| LVS_REPORT
);
1693 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_ownerdrawfixed_parent_seq
,
1694 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE
);
1695 DestroyWindow(hList
);
1698 static void test_redraw(void)
1705 hwnd
= create_listview_control(LVS_REPORT
);
1706 subclass_header(hwnd
);
1708 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1710 InvalidateRect(hwnd
, NULL
, TRUE
);
1712 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, redraw_listview_seq
, "redraw listview", FALSE
);
1714 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1716 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1717 /* 1. Without backbuffer */
1718 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
1721 hdc
= GetWindowDC(hwndparent
);
1723 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1724 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1725 ok(r
== 1, "Expected not zero result\n");
1726 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1727 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1729 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_DEFAULT
);
1732 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1733 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1735 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1736 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1738 /* 2. With backbuffer */
1739 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_DOUBLEBUFFER
,
1740 LVS_EX_DOUBLEBUFFER
);
1741 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
1744 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1745 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1747 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, forward_erasebkgnd_parent_seq
,
1748 "forward WM_ERASEBKGND on CLR_NONE", FALSE
);
1750 res
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_DEFAULT
);
1753 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1754 r
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
1755 todo_wine
expect(1, r
);
1756 ok_sequence(sequences
, PARENT_FULL_SEQ_INDEX
, empty_seq
,
1757 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE
);
1759 ReleaseDC(hwndparent
, hdc
);
1761 DestroyWindow(hwnd
);
1764 static LRESULT WINAPI
cd_wndproc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1766 COLORREF clr
, c0ffee
= RGB(0xc0, 0xff, 0xee);
1768 if(msg
== WM_NOTIFY
) {
1769 NMHDR
*nmhdr
= (PVOID
)lp
;
1770 if(nmhdr
->code
== NM_CUSTOMDRAW
) {
1771 NMLVCUSTOMDRAW
*nmlvcd
= (NMLVCUSTOMDRAW
*)nmhdr
;
1773 switch(nmlvcd
->nmcd
.dwDrawStage
) {
1775 SetBkColor(nmlvcd
->nmcd
.hdc
, c0ffee
);
1776 return CDRF_NOTIFYITEMDRAW
;
1777 case CDDS_ITEMPREPAINT
:
1778 nmlvcd
->clrTextBk
= CLR_DEFAULT
;
1779 return CDRF_NOTIFYSUBITEMDRAW
;
1780 case CDDS_ITEMPREPAINT
| CDDS_SUBITEM
:
1781 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1782 if (nmlvcd
->iSubItem
)
1783 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1785 ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1786 return CDRF_NOTIFYPOSTPAINT
;
1787 case CDDS_ITEMPOSTPAINT
| CDDS_SUBITEM
:
1788 clr
= GetBkColor(nmlvcd
->nmcd
.hdc
);
1789 todo_wine
ok(clr
== c0ffee
, "clr=%.8x\n", clr
);
1790 return CDRF_DODEFAULT
;
1792 return CDRF_DODEFAULT
;
1796 return DefWindowProcA(hwnd
, msg
, wp
, lp
);
1799 static void test_customdraw(void)
1804 hwnd
= create_listview_control(LVS_REPORT
);
1806 insert_column(hwnd
, 0);
1807 insert_column(hwnd
, 1);
1808 insert_item(hwnd
, 0);
1810 oldwndproc
= (WNDPROC
)SetWindowLongPtrA(hwndparent
, GWLP_WNDPROC
,
1811 (LONG_PTR
)cd_wndproc
);
1813 InvalidateRect(hwnd
, NULL
, TRUE
);
1816 SetWindowLongPtrA(hwndparent
, GWLP_WNDPROC
, (LONG_PTR
)oldwndproc
);
1818 DestroyWindow(hwnd
);
1821 static void test_icon_spacing(void)
1823 /* LVM_SETICONSPACING */
1824 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1830 hwnd
= create_listview_control(LVS_ICON
);
1831 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1833 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, (WPARAM
)hwndparent
, NF_REQUERY
);
1834 expect(NFR_ANSI
, r
);
1836 /* reset the icon spacing to defaults */
1837 SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1839 /* now we can request what the defaults are */
1840 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1, -1));
1844 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1846 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(20, 30));
1847 ok(r
== MAKELONG(w
, h
) ||
1848 broken(r
== MAKELONG(w
, w
)), /* win98 */
1849 "Expected %d, got %d\n", MAKELONG(w
, h
), r
);
1851 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(25, 35));
1855 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1856 DestroyWindow(hwnd
);
1859 expect(MAKELONG(20,30), r
);
1861 r
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(-1,-1));
1862 expect(MAKELONG(25,35), r
);
1864 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_icon_spacing_seq
, "test icon spacing seq", FALSE
);
1866 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1867 DestroyWindow(hwnd
);
1870 static void test_color(void)
1878 COLORREF colors
[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE
, RGB(255,255,255)};
1880 hwnd
= create_listview_control(LVS_REPORT
);
1881 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1883 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1885 for (i
= 0; i
< 4; i
++)
1889 r
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, color
);
1891 r
= SendMessageA(hwnd
, LVM_GETBKCOLOR
, 0, 0);
1894 r
= SendMessageA(hwnd
, LVM_SETTEXTCOLOR
, 0, color
);
1896 r
= SendMessageA(hwnd
, LVM_GETTEXTCOLOR
, 0, 0);
1899 r
= SendMessageA(hwnd
, LVM_SETTEXTBKCOLOR
, 0, color
);
1901 r
= SendMessageA(hwnd
, LVM_GETTEXTBKCOLOR
, 0, 0);
1905 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_color_seq
, "test color seq", FALSE
);
1906 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1908 /* invalidation test done separately to avoid a message chain mess */
1909 r
= ValidateRect(hwnd
, NULL
);
1911 r
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, colors
[0]);
1914 rect
.right
= rect
.bottom
= 1;
1915 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1916 todo_wine
expect(FALSE
, r
);
1917 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1919 r
= ValidateRect(hwnd
, NULL
);
1921 r
= SendMessageA(hwnd
, LVM_SETTEXTCOLOR
, 0, colors
[0]);
1924 rect
.right
= rect
.bottom
= 1;
1925 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1926 todo_wine
expect(FALSE
, r
);
1927 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1929 r
= ValidateRect(hwnd
, NULL
);
1931 r
= SendMessageA(hwnd
, LVM_SETTEXTBKCOLOR
, 0, colors
[0]);
1934 rect
.right
= rect
.bottom
= 1;
1935 r
= GetUpdateRect(hwnd
, &rect
, TRUE
);
1936 todo_wine
expect(FALSE
, r
);
1937 ok(rect
.right
== 0 && rect
.bottom
== 0, "got update rectangle\n");
1939 DestroyWindow(hwnd
);
1942 static void test_item_count(void)
1944 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1957 static CHAR item0text
[] = "item0";
1958 static CHAR item1text
[] = "item1";
1959 static CHAR item2text
[] = "item2";
1961 hwnd
= create_listview_control(LVS_REPORT
);
1962 ok(hwnd
!= NULL
, "failed to create a listview window\n");
1964 /* resize in dpiaware manner to fit all 3 items added */
1966 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1967 GetTextMetricsA(hdc
, &tm
);
1968 /* 2 extra pixels for bounds and header border */
1969 height
= tm
.tmHeight
+ 2;
1970 SelectObject(hdc
, hOldFont
);
1973 GetWindowRect(hwnd
, &rect
);
1974 /* 3 items + 1 header + 1 to be sure */
1975 MoveWindow(hwnd
, 0, 0, rect
.right
- rect
.left
, 5 * height
, FALSE
);
1977 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1979 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
1983 item0
.mask
= LVIF_TEXT
;
1986 item0
.pszText
= item0text
;
1987 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item0
);
1990 /* [item0, item1] */
1991 item1
.mask
= LVIF_TEXT
;
1994 item1
.pszText
= item1text
;
1995 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
1998 /* [item0, item1, item2] */
1999 item2
.mask
= LVIF_TEXT
;
2002 item2
.pszText
= item2text
;
2003 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2006 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2009 /* [item0, item1] */
2010 r
= SendMessageA(hwnd
, LVM_DELETEITEM
, 2, 0);
2013 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2017 r
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
2020 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2024 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2027 /* [item0, item1] */
2028 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2031 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2034 /* [item0, item1, item2] */
2035 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2038 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2041 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_item_count_seq
, "test item count seq", FALSE
);
2043 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2044 DestroyWindow(hwnd
);
2047 static void test_item_position(void)
2049 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2058 static CHAR item0text
[] = "item0";
2059 static CHAR item1text
[] = "item1";
2060 static CHAR item2text
[] = "item2";
2062 hwnd
= create_listview_control(LVS_ICON
);
2063 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2065 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2068 item0
.mask
= LVIF_TEXT
;
2071 item0
.pszText
= item0text
;
2072 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item0
);
2075 /* [item0, item1] */
2076 item1
.mask
= LVIF_TEXT
;
2079 item1
.pszText
= item1text
;
2080 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item1
);
2083 /* [item0, item1, item2] */
2084 item2
.mask
= LVIF_TEXT
;
2087 item2
.pszText
= item2text
;
2088 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item2
);
2091 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 1, MAKELPARAM(10,5));
2093 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 1, (LPARAM
) &position
);
2095 expect2(10, 5, position
.x
, position
.y
);
2097 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 2, MAKELPARAM(0,0));
2099 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 2, (LPARAM
) &position
);
2101 expect2(0, 0, position
.x
, position
.y
);
2103 r
= SendMessageA(hwnd
, LVM_SETITEMPOSITION
, 0, MAKELPARAM(20,20));
2105 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
) &position
);
2107 expect2(20, 20, position
.x
, position
.y
);
2109 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_itempos_seq
, "test item position seq", TRUE
);
2111 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2112 DestroyWindow(hwnd
);
2115 static void test_getorigin(void)
2123 position
.x
= position
.y
= 0;
2125 hwnd
= create_listview_control(LVS_ICON
);
2126 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2127 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2129 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2131 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2132 DestroyWindow(hwnd
);
2134 hwnd
= create_listview_control(LVS_SMALLICON
);
2135 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2136 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2138 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2140 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2141 DestroyWindow(hwnd
);
2143 hwnd
= create_listview_control(LVS_LIST
);
2144 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2145 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2147 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2149 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2150 DestroyWindow(hwnd
);
2152 hwnd
= create_listview_control(LVS_REPORT
);
2153 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2154 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2156 r
= SendMessageA(hwnd
, LVM_GETORIGIN
, 0, (LPARAM
)&position
);
2158 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2159 DestroyWindow(hwnd
);
2162 static void test_multiselect(void)
2164 typedef struct t_select_task
2175 int i
,j
,item_count
,selected_count
;
2176 static const int items
=5;
2182 static struct t_select_task task_list
[] = {
2183 { "using VK_DOWN", 0, VK_DOWN
, -1, -1 },
2184 { "using VK_UP", -1, VK_UP
, -1, -1 },
2185 { "using VK_END", 0, VK_END
, 1, -1 },
2186 { "using VK_HOME", -1, VK_HOME
, 1, -1 }
2189 hwnd
= create_listview_control(LVS_REPORT
);
2191 for (i
= 0; i
< items
; i
++)
2192 insert_item(hwnd
, 0);
2194 item_count
= (int)SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2195 expect(items
, item_count
);
2197 for (i
= 0; i
< 4; i
++) {
2200 task
= task_list
[i
];
2202 /* deselect all items */
2204 item
.stateMask
= LVIS_SELECTED
;
2205 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2206 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2208 /* set initial position */
2209 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, (task
.initPos
== -1 ? item_count
-1 : task
.initPos
));
2211 item
.state
= LVIS_SELECTED
;
2212 item
.stateMask
= LVIS_SELECTED
;
2213 SendMessageA(hwnd
, LVM_SETITEMSTATE
, task
.initPos
== -1 ? item_count
-1 : task
.initPos
, (LPARAM
)&item
);
2215 selected_count
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2216 ok(selected_count
== 1, "expected 1, got %d\n", selected_count
);
2218 /* Set SHIFT key pressed */
2219 GetKeyboardState(kstate
);
2220 kstate
[VK_SHIFT
]=0x80;
2221 SetKeyboardState(kstate
);
2223 for (j
=1;j
<=(task
.count
== -1 ? item_count
: task
.count
);j
++) {
2224 r
= SendMessageA(hwnd
, WM_KEYDOWN
, task
.loopVK
, 0);
2226 r
= SendMessageA(hwnd
, WM_KEYUP
, task
.loopVK
, 0);
2230 selected_count
= (int)SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2232 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
);
2234 /* Set SHIFT key released */
2235 GetKeyboardState(kstate
);
2236 kstate
[VK_SHIFT
]=0x00;
2237 SetKeyboardState(kstate
);
2239 DestroyWindow(hwnd
);
2241 /* make multiple selection, then switch to LVS_SINGLESEL */
2242 hwnd
= create_listview_control(LVS_REPORT
);
2243 for (i
=0;i
<items
;i
++) {
2244 insert_item(hwnd
, 0);
2246 item_count
= (int)SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
2247 expect(items
,item_count
);
2249 /* try with NULL pointer */
2250 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, 0);
2253 /* select all, check notifications */
2255 item
.stateMask
= LVIS_SELECTED
;
2256 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2258 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2260 item
.stateMask
= LVIS_SELECTED
;
2261 item
.state
= LVIS_SELECTED
;
2262 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2265 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2266 "select all notification", FALSE
);
2268 /* select all again (all selected already) */
2269 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2271 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2273 item
.stateMask
= LVIS_SELECTED
;
2274 item
.state
= LVIS_SELECTED
;
2275 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2278 ok(g_nmlistview_changing
.uNewState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2279 ok(g_nmlistview_changing
.uOldState
== LVIS_SELECTED
, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2280 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2282 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2283 "select all notification 2", FALSE
);
2285 /* deselect all items */
2286 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2289 item
.stateMask
= LVIS_SELECTED
;
2290 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2292 ok_sequence(sequences
, PARENT_SEQ_INDEX
, change_all_parent_seq
,
2293 "deselect all notification", FALSE
);
2295 /* deselect all items again */
2296 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2298 item
.stateMask
= LVIS_SELECTED
;
2299 SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2300 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "deselect all notification 2", FALSE
);
2302 /* any non-zero state value does the same */
2303 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2305 memset(&g_nmlistview_changing
, 0xcc, sizeof(g_nmlistview_changing
));
2307 item
.stateMask
= LVIS_SELECTED
;
2308 item
.state
= LVIS_CUT
;
2309 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2312 ok(g_nmlistview_changing
.uNewState
== 0, "got 0x%x\n", g_nmlistview_changing
.uNewState
);
2313 ok(g_nmlistview_changing
.uOldState
== 0, "got 0x%x\n", g_nmlistview_changing
.uOldState
);
2314 ok(g_nmlistview_changing
.uChanged
== LVIF_STATE
, "got 0x%x\n", g_nmlistview_changing
.uChanged
);
2316 ok_sequence(sequences
, PARENT_SEQ_INDEX
, changing_all_parent_seq
,
2317 "set state all notification 3", FALSE
);
2319 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2320 for (i
= 0; i
< 3; i
++) {
2321 item
.state
= LVIS_SELECTED
;
2322 item
.stateMask
= LVIS_SELECTED
;
2323 SendMessageA(hwnd
, LVM_SETITEMSTATE
, i
, (LPARAM
)&item
);
2326 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2328 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2331 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2332 ok(!(style
& LVS_SINGLESEL
), "LVS_SINGLESEL isn't expected\n");
2333 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SINGLESEL
);
2334 /* check that style is accepted */
2335 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2336 ok(style
& LVS_SINGLESEL
, "LVS_SINGLESEL expected\n");
2339 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, i
, LVIS_SELECTED
);
2340 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2342 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2344 SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2347 /* select one more */
2348 item
.state
= LVIS_SELECTED
;
2349 item
.stateMask
= LVIS_SELECTED
;
2350 SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
2353 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, i
, LVIS_SELECTED
);
2354 ok(!(r
& LVIS_SELECTED
), "Expected item %d to be unselected\n", i
);
2357 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 3, LVIS_SELECTED
);
2358 ok(r
& LVIS_SELECTED
, "Expected item %d to be selected\n", i
);
2360 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2362 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2365 /* try to select all on LVS_SINGLESEL */
2366 memset(&item
, 0, sizeof(item
));
2367 item
.stateMask
= LVIS_SELECTED
;
2368 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2370 SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2372 item
.stateMask
= LVIS_SELECTED
;
2373 item
.state
= LVIS_SELECTED
;
2374 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2377 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2379 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2382 /* try to deselect all on LVS_SINGLESEL */
2383 item
.stateMask
= LVIS_SELECTED
;
2384 item
.state
= LVIS_SELECTED
;
2385 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2388 item
.stateMask
= LVIS_SELECTED
;
2390 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2392 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2395 /* 1. selection mark is update when new focused item is set */
2396 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2397 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2399 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2402 item
.stateMask
= LVIS_FOCUSED
;
2403 item
.state
= LVIS_FOCUSED
;
2404 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
2407 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2410 /* it's not updated if already set */
2411 item
.stateMask
= LVIS_FOCUSED
;
2412 item
.state
= LVIS_FOCUSED
;
2413 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2416 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2419 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2422 item
.stateMask
= LVIS_FOCUSED
;
2423 item
.state
= LVIS_FOCUSED
;
2424 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 1, (LPARAM
)&item
);
2427 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2430 /* need to reset focused item first */
2431 item
.stateMask
= LVIS_FOCUSED
;
2433 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2436 item
.stateMask
= LVIS_FOCUSED
;
2437 item
.state
= LVIS_FOCUSED
;
2438 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
2441 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2444 item
.stateMask
= LVIS_FOCUSED
;
2446 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2449 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2452 /* 2. same tests, with LVM_SETITEM */
2453 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2454 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SINGLESEL
);
2456 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2459 item
.stateMask
= LVIS_FOCUSED
;
2460 item
.state
= LVIS_FOCUSED
;
2461 item
.mask
= LVIF_STATE
;
2462 item
.iItem
= item
.iSubItem
= 0;
2463 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2466 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2469 /* it's not updated if already set */
2470 item
.stateMask
= LVIS_FOCUSED
;
2471 item
.state
= LVIS_FOCUSED
;
2472 item
.mask
= LVIF_STATE
;
2475 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2478 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2481 r
= SendMessageA(hwnd
, LVM_SETSELECTIONMARK
, 0, -1);
2484 item
.stateMask
= LVIS_FOCUSED
;
2485 item
.state
= LVIS_FOCUSED
;
2486 item
.mask
= LVIF_STATE
;
2489 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2492 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2495 /* need to reset focused item first */
2496 item
.stateMask
= LVIS_FOCUSED
;
2498 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2501 item
.stateMask
= LVIS_FOCUSED
;
2502 item
.state
= LVIS_FOCUSED
;
2503 item
.mask
= LVIF_STATE
;
2506 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
2509 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2512 item
.stateMask
= LVIS_FOCUSED
;
2514 r
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
2517 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2520 DestroyWindow(hwnd
);
2523 static void test_subitem_rect(void)
2531 /* test LVM_GETSUBITEMRECT for header */
2532 hwnd
= create_listview_control(LVS_REPORT
);
2533 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2534 /* add some columns */
2535 memset(&col
, 0, sizeof(LVCOLUMNA
));
2536 col
.mask
= LVCF_WIDTH
;
2538 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
2541 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&col
);
2544 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 2, (LPARAM
)&col
);
2546 /* item = -1 means header, subitem index is 1 based */
2547 rect
.left
= LVIR_BOUNDS
;
2549 rect
.right
= rect
.bottom
= 0;
2550 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2553 rect
.left
= LVIR_BOUNDS
;
2555 rect
.right
= rect
.bottom
= 0;
2556 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2559 expect(100, rect
.left
);
2560 expect(250, rect
.right
);
2561 expect(3, rect
.top
);
2563 rect
.left
= LVIR_BOUNDS
;
2565 rect
.right
= rect
.bottom
= 0;
2566 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2569 expect(250, rect
.left
);
2570 expect(450, rect
.right
);
2571 expect(3, rect
.top
);
2573 /* item LVS_REPORT padding isn't applied to subitems */
2574 insert_item(hwnd
, 0);
2576 rect
.left
= LVIR_BOUNDS
;
2578 rect
.right
= rect
.bottom
= 0;
2579 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2581 expect(100, rect
.left
);
2582 expect(250, rect
.right
);
2584 rect
.left
= LVIR_ICON
;
2586 rect
.right
= rect
.bottom
= 0;
2587 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2589 /* no icon attached - zero width rectangle, with no left padding */
2590 expect(100, rect
.left
);
2591 expect(100, rect
.right
);
2593 rect
.left
= LVIR_LABEL
;
2595 rect
.right
= rect
.bottom
= 0;
2596 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2598 /* same as full LVIR_BOUNDS */
2599 expect(100, rect
.left
);
2600 expect(250, rect
.right
);
2602 SendMessageA(hwnd
, LVM_SCROLL
, 10, 0);
2604 rect
.left
= LVIR_BOUNDS
;
2606 rect
.right
= rect
.bottom
= 0;
2607 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2609 expect(90, rect
.left
);
2610 expect(240, rect
.right
);
2612 SendMessageA(hwnd
, LVM_SCROLL
, -10, 0);
2614 /* test header interaction */
2615 subclass_header(hwnd
);
2616 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2618 rect
.left
= LVIR_BOUNDS
;
2620 rect
.right
= rect
.bottom
= 0;
2621 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2624 rect
.left
= LVIR_BOUNDS
;
2626 rect
.right
= rect
.bottom
= 0;
2627 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2630 rect
.left
= LVIR_BOUNDS
;
2632 rect
.right
= rect
.bottom
= 0;
2633 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -10, (LPARAM
)&rect
);
2636 rect
.left
= LVIR_BOUNDS
;
2638 rect
.right
= rect
.bottom
= 0;
2639 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 20, (LPARAM
)&rect
);
2642 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getsubitemrect_seq
, "LVM_GETSUBITEMRECT negative index", FALSE
);
2644 DestroyWindow(hwnd
);
2646 /* test subitem rects after re-arranging columns */
2647 hwnd
= create_listview_control(LVS_REPORT
);
2648 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2649 memset(&col
, 0, sizeof(LVCOLUMNA
));
2650 col
.mask
= LVCF_WIDTH
;
2653 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
2657 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 1, (LPARAM
)&col
);
2661 r
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 2, (LPARAM
)&col
);
2664 insert_item(hwnd
, 0);
2665 insert_item(hwnd
, 1);
2667 /* wrong item is refused for main item */
2668 rect
.left
= LVIR_BOUNDS
;
2670 rect
.right
= rect
.bottom
= -1;
2671 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect
);
2674 /* for subitems rectangle is calculated even if there's no item added */
2675 rect
.left
= LVIR_BOUNDS
;
2677 rect
.right
= rect
.bottom
= -1;
2678 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect
);
2681 rect2
.left
= LVIR_BOUNDS
;
2683 rect2
.right
= rect2
.bottom
= -1;
2684 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 2, (LPARAM
)&rect2
);
2686 expect(rect
.right
, rect2
.right
);
2687 expect(rect
.left
, rect2
.left
);
2688 expect(rect
.bottom
, rect2
.top
);
2689 ok(rect2
.bottom
> rect2
.top
, "expected not zero height\n");
2691 arr
[0] = 1; arr
[1] = 0; arr
[2] = 2;
2692 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 3, (LPARAM
)arr
);
2695 rect
.left
= LVIR_BOUNDS
;
2697 rect
.right
= rect
.bottom
= -1;
2698 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2700 expect(0, rect
.left
);
2701 expect(600, rect
.right
);
2703 rect
.left
= LVIR_BOUNDS
;
2705 rect
.right
= rect
.bottom
= -1;
2706 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2708 expect(0, rect
.left
);
2709 expect(200, rect
.right
);
2711 rect2
.left
= LVIR_BOUNDS
;
2713 rect2
.right
= rect2
.bottom
= -1;
2714 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 1, (LPARAM
)&rect2
);
2716 expect(0, rect2
.left
);
2717 expect(200, rect2
.right
);
2718 /* items are of the same height */
2719 ok(rect2
.top
> 0, "expected positive item height\n");
2720 expect(rect
.bottom
, rect2
.top
);
2721 expect(rect
.bottom
* 2 - rect
.top
, rect2
.bottom
);
2723 rect
.left
= LVIR_BOUNDS
;
2725 rect
.right
= rect
.bottom
= -1;
2726 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, 0, (LPARAM
)&rect
);
2728 expect(300, rect
.left
);
2729 expect(600, rect
.right
);
2731 DestroyWindow(hwnd
);
2733 /* try it for non LVS_REPORT style */
2734 hwnd
= CreateWindowA("SysListView32", "Test", LVS_ICON
, 0, 0, 100, 100, NULL
, NULL
,
2735 GetModuleHandleA(NULL
), 0);
2736 rect
.left
= LVIR_BOUNDS
;
2738 rect
.right
= rect
.bottom
= -10;
2739 r
= SendMessageA(hwnd
, LVM_GETSUBITEMRECT
, -1, (LPARAM
)&rect
);
2741 /* rect is unchanged */
2742 expect(0, rect
.left
);
2743 expect(-10, rect
.right
);
2744 expect(1, rect
.top
);
2745 expect(-10, rect
.bottom
);
2746 DestroyWindow(hwnd
);
2749 /* comparison callback for test_sorting */
2750 static INT WINAPI
test_CallBackCompare(LPARAM first
, LPARAM second
, LPARAM lParam
)
2752 if (first
== second
) return 0;
2753 return (first
> second
? 1 : -1);
2756 static void test_sorting(void)
2762 static CHAR names
[][5] = {"A", "B", "C", "D", "0"};
2765 hwnd
= create_listview_control(LVS_REPORT
);
2766 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2768 /* insert some items */
2769 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
2770 item
.state
= LVIS_SELECTED
;
2774 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2777 item
.mask
= LVIF_PARAM
;
2781 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2784 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
2785 item
.state
= LVIS_SELECTED
;
2789 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2792 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2795 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2798 r
= SendMessageA(hwnd
, LVM_SORTITEMS
, 0, (LPARAM
)test_CallBackCompare
);
2801 r
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
2803 r
= SendMessageA(hwnd
, LVM_GETSELECTIONMARK
, 0, 0);
2805 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_SELECTED
);
2807 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_SELECTED
);
2808 expect(LVIS_SELECTED
, r
);
2809 r
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_SELECTED
);
2810 expect(LVIS_SELECTED
, r
);
2812 DestroyWindow(hwnd
);
2814 /* switch to LVS_SORTASCENDING when some items added */
2815 hwnd
= create_listview_control(LVS_REPORT
);
2816 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2818 item
.mask
= LVIF_TEXT
;
2821 item
.pszText
= names
[1];
2822 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2825 item
.mask
= LVIF_TEXT
;
2828 item
.pszText
= names
[2];
2829 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2832 item
.mask
= LVIF_TEXT
;
2835 item
.pszText
= names
[0];
2836 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2839 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2840 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
2841 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2842 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
2844 /* no sorting performed when switched to LVS_SORTASCENDING */
2845 item
.mask
= LVIF_TEXT
;
2847 item
.pszText
= buff
;
2848 item
.cchTextMax
= sizeof(buff
);
2849 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2851 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2854 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2856 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2859 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2861 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2863 /* adding new item doesn't resort list */
2864 item
.mask
= LVIF_TEXT
;
2867 item
.pszText
= names
[3];
2868 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2871 item
.mask
= LVIF_TEXT
;
2873 item
.pszText
= buff
;
2874 item
.cchTextMax
= sizeof(buff
);
2875 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2877 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2880 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2882 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2885 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2887 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2890 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2892 ok(lstrcmpA(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2894 /* corner case - item should be placed at first position */
2895 item
.mask
= LVIF_TEXT
;
2898 item
.pszText
= names
[4];
2899 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
) &item
);
2903 item
.pszText
= buff
;
2904 item
.cchTextMax
= sizeof(buff
);
2905 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2907 ok(lstrcmpA(buff
, names
[4]) == 0, "Expected '%s', got '%s'\n", names
[4], buff
);
2910 item
.pszText
= buff
;
2911 item
.cchTextMax
= sizeof(buff
);
2912 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2914 ok(lstrcmpA(buff
, names
[1]) == 0, "Expected '%s', got '%s'\n", names
[1], buff
);
2917 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2919 ok(lstrcmpA(buff
, names
[2]) == 0, "Expected '%s', got '%s'\n", names
[2], buff
);
2922 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2924 ok(lstrcmpA(buff
, names
[0]) == 0, "Expected '%s', got '%s'\n", names
[0], buff
);
2927 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
) &item
);
2929 ok(lstrcmpA(buff
, names
[3]) == 0, "Expected '%s', got '%s'\n", names
[3], buff
);
2931 DestroyWindow(hwnd
);
2934 static void test_ownerdata(void)
2936 static char test_str
[] = "test";
2939 LONG_PTR style
, ret
;
2943 /* it isn't possible to set LVS_OWNERDATA after creation */
2946 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2950 hwnd
= create_listview_control(LVS_REPORT
);
2951 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2952 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2953 ok(!(style
& LVS_OWNERDATA
) && style
, "LVS_OWNERDATA isn't expected\n");
2955 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2957 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2958 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2959 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2960 "try to switch to LVS_OWNERDATA seq", FALSE
);
2962 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2963 ok(!(style
& LVS_OWNERDATA
), "LVS_OWNERDATA isn't expected\n");
2964 DestroyWindow(hwnd
);
2967 /* try to set LVS_OWNERDATA after creation just having it */
2968 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2969 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2970 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2971 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2973 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2975 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_OWNERDATA
);
2976 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2977 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2978 "try to switch to LVS_OWNERDATA seq", FALSE
);
2979 DestroyWindow(hwnd
);
2981 /* try to remove LVS_OWNERDATA after creation just having it */
2984 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2988 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
2989 ok(hwnd
!= NULL
, "failed to create a listview window\n");
2990 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
2991 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
2993 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2995 ret
= SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_OWNERDATA
);
2996 ok(ret
== style
, "Expected set GWL_STYLE to succeed\n");
2997 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_ownerdata_switchto_seq
,
2998 "try to switch to LVS_OWNERDATA seq", FALSE
);
2999 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3000 ok(style
& LVS_OWNERDATA
, "LVS_OWNERDATA is expected\n");
3001 DestroyWindow(hwnd
);
3004 /* try select an item */
3005 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3006 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3007 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3009 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
3011 memset(&item
, 0, sizeof(item
));
3012 item
.stateMask
= LVIS_SELECTED
;
3013 item
.state
= LVIS_SELECTED
;
3014 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3016 res
= SendMessageA(hwnd
, LVM_GETSELECTEDCOUNT
, 0, 0);
3018 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3020 DestroyWindow(hwnd
);
3022 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
3023 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3024 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3025 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3027 res
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
3029 memset(&item
, 0, sizeof(item
));
3030 item
.mask
= LVIF_STATE
;
3032 item
.stateMask
= LVIS_SELECTED
;
3033 item
.state
= LVIS_SELECTED
;
3034 res
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3036 memset(&item
, 0, sizeof(item
));
3037 item
.pszText
= test_str
;
3038 res
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3040 DestroyWindow(hwnd
);
3042 /* check notifications after focused/selected changed */
3043 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3044 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3045 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 20, 0);
3048 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3050 memset(&item
, 0, sizeof(item
));
3051 item
.stateMask
= LVIS_SELECTED
;
3052 item
.state
= LVIS_SELECTED
;
3053 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3056 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
3057 "ownerdata select notification", TRUE
);
3059 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3061 memset(&item
, 0, sizeof(item
));
3062 item
.stateMask
= LVIS_FOCUSED
;
3063 item
.state
= LVIS_FOCUSED
;
3064 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3067 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownderdata_select_focus_parent_seq
,
3068 "ownerdata focus notification", TRUE
);
3070 /* select all, check notifications */
3071 item
.stateMask
= LVIS_SELECTED
;
3073 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3076 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3078 item
.stateMask
= LVIS_SELECTED
;
3079 item
.state
= LVIS_SELECTED
;
3081 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3082 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3084 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3085 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3086 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3087 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3088 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3089 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3090 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3092 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3093 "ownerdata select all notification", FALSE
);
3095 /* select all again, note that all items are selected already */
3096 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3097 item
.stateMask
= LVIS_SELECTED
;
3098 item
.state
= LVIS_SELECTED
;
3100 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3101 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3103 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3104 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3105 ok(g_nmlistview
.uNewState
== LVIS_SELECTED
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3106 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3107 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3108 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3109 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3111 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3112 "ownerdata select all notification", FALSE
);
3115 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3116 item
.stateMask
= LVIS_SELECTED
;
3119 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3120 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3122 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3123 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3124 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3125 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3126 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3127 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3128 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3130 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3131 "ownerdata deselect all notification", TRUE
);
3133 /* nothing selected, deselect all again */
3134 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3135 item
.stateMask
= LVIS_SELECTED
;
3138 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3141 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "ownerdata deselect all notification", FALSE
);
3143 /* select one, then deselect all */
3144 item
.stateMask
= LVIS_SELECTED
;
3145 item
.state
= LVIS_SELECTED
;
3146 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3148 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3149 item
.stateMask
= LVIS_SELECTED
;
3152 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3153 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3155 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3156 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3157 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3158 ok(g_nmlistview
.uOldState
== LVIS_SELECTED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3159 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3160 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3161 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3163 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_deselect_all_parent_seq
,
3164 "ownerdata select all notification", TRUE
);
3166 /* remove focused, try to focus all */
3167 item
.stateMask
= LVIS_FOCUSED
;
3168 item
.state
= LVIS_FOCUSED
;
3169 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3171 item
.stateMask
= LVIS_FOCUSED
;
3173 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3175 item
.stateMask
= LVIS_FOCUSED
;
3176 res
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
3179 /* setting all to focused returns failure value */
3180 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3181 item
.stateMask
= LVIS_FOCUSED
;
3182 item
.state
= LVIS_FOCUSED
;
3184 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3187 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3188 "ownerdata focus all notification", FALSE
);
3190 /* focus single item, remove all */
3191 item
.stateMask
= LVIS_FOCUSED
;
3192 item
.state
= LVIS_FOCUSED
;
3193 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
3195 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3196 item
.stateMask
= LVIS_FOCUSED
;
3199 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3200 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3202 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3203 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3204 ok(g_nmlistview
.uNewState
== 0, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3205 ok(g_nmlistview
.uOldState
== LVIS_FOCUSED
, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3206 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3207 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3208 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3210 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_defocus_all_parent_seq
,
3211 "ownerdata remove focus all notification", TRUE
);
3214 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3215 item
.stateMask
= LVIS_CUT
;
3216 item
.state
= LVIS_CUT
;
3218 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3219 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3221 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3222 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3223 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3224 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3225 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3226 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3227 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3229 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3230 "ownerdata cut all notification", FALSE
);
3232 /* all marked cut, try again */
3233 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3234 item
.stateMask
= LVIS_CUT
;
3235 item
.state
= LVIS_CUT
;
3237 memset(&g_nmlistview
, 0xcc, sizeof(g_nmlistview
));
3238 res
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, -1, (LPARAM
)&item
);
3240 ok(g_nmlistview
.iItem
== -1, "got item %d\n", g_nmlistview
.iItem
);
3241 ok(g_nmlistview
.iSubItem
== 0, "got subitem %d\n", g_nmlistview
.iSubItem
);
3242 ok(g_nmlistview
.uNewState
== LVIS_CUT
, "got new state 0x%08x\n", g_nmlistview
.uNewState
);
3243 ok(g_nmlistview
.uOldState
== 0, "got old state 0x%08x\n", g_nmlistview
.uOldState
);
3244 ok(g_nmlistview
.uChanged
== LVIF_STATE
, "got changed 0x%08x\n", g_nmlistview
.uChanged
);
3245 ok(g_nmlistview
.ptAction
.x
== 0 && g_nmlistview
.ptAction
.y
== 0, "got wrong ptAction value\n");
3246 ok(g_nmlistview
.lParam
== 0, "got wrong lparam\n");
3248 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ownerdata_setstate_all_parent_seq
,
3249 "ownerdata cut all notification #2", FALSE
);
3251 DestroyWindow(hwnd
);
3253 /* check notifications on LVM_GETITEM */
3254 /* zero callback mask */
3255 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3256 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3257 res
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3260 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3262 memset(&item
, 0, sizeof(item
));
3263 item
.stateMask
= LVIS_SELECTED
;
3264 item
.mask
= LVIF_STATE
;
3265 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3268 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3269 "ownerdata getitem selected state 1", FALSE
);
3271 /* non zero callback mask but not we asking for */
3272 res
= SendMessageA(hwnd
, LVM_SETCALLBACKMASK
, LVIS_OVERLAYMASK
, 0);
3275 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3277 memset(&item
, 0, sizeof(item
));
3278 item
.stateMask
= LVIS_SELECTED
;
3279 item
.mask
= LVIF_STATE
;
3280 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3283 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3284 "ownerdata getitem selected state 2", FALSE
);
3286 /* LVIS_OVERLAYMASK callback mask, asking for index */
3287 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3289 memset(&item
, 0, sizeof(item
));
3290 item
.stateMask
= LVIS_OVERLAYMASK
;
3291 item
.mask
= LVIF_STATE
;
3292 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3295 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
3296 "ownerdata getitem selected state 2", FALSE
);
3298 DestroyWindow(hwnd
);
3300 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3301 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_SORTASCENDING
| LVS_REPORT
);
3302 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3303 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3304 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3305 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3306 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_SORTASCENDING
);
3307 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3308 ok(!(style
& LVS_SORTASCENDING
), "Expected LVS_SORTASCENDING not set\n");
3309 DestroyWindow(hwnd
);
3310 /* apparently it's allowed to switch these style on after creation */
3311 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3312 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3313 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3314 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3315 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTASCENDING
);
3316 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3317 ok(style
& LVS_SORTASCENDING
, "Expected LVS_SORTASCENDING to be set\n");
3318 DestroyWindow(hwnd
);
3320 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3321 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3322 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3323 ok(style
& LVS_OWNERDATA
, "Expected LVS_OWNERDATA\n");
3324 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SORTDESCENDING
);
3325 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3326 ok(style
& LVS_SORTDESCENDING
, "Expected LVS_SORTDESCENDING to be set\n");
3327 DestroyWindow(hwnd
);
3330 static void test_norecompute(void)
3332 static CHAR testA
[] = "test";
3338 /* self containing control */
3339 hwnd
= create_listview_control(LVS_REPORT
);
3340 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3341 memset(&item
, 0, sizeof(item
));
3342 item
.mask
= LVIF_TEXT
| LVIF_STATE
;
3344 item
.stateMask
= LVIS_SELECTED
;
3345 item
.state
= LVIS_SELECTED
;
3346 item
.pszText
= testA
;
3347 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3349 /* retrieve with LVIF_NORECOMPUTE */
3350 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3352 item
.pszText
= buff
;
3353 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3354 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3356 ok(lstrcmpA(buff
, testA
) == 0, "Expected (%s), got (%s)\n", testA
, buff
);
3358 item
.mask
= LVIF_TEXT
;
3360 item
.pszText
= LPSTR_TEXTCALLBACKA
;
3361 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3364 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3366 item
.pszText
= buff
;
3367 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3369 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3370 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3372 ok(item
.pszText
== LPSTR_TEXTCALLBACKA
, "Expected (%p), got (%p)\n",
3373 LPSTR_TEXTCALLBACKA
, (VOID
*)item
.pszText
);
3374 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq", FALSE
);
3376 DestroyWindow(hwnd
);
3379 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3380 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3382 item
.mask
= LVIF_STATE
;
3383 item
.stateMask
= LVIS_SELECTED
;
3384 item
.state
= LVIS_SELECTED
;
3386 res
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3389 item
.mask
= LVIF_TEXT
| LVIF_NORECOMPUTE
;
3391 item
.pszText
= buff
;
3392 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
3393 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3394 res
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
3396 ok(item
.pszText
== LPSTR_TEXTCALLBACKA
, "Expected (%p), got (%p)\n",
3397 LPSTR_TEXTCALLBACKA
, (VOID
*)item
.pszText
);
3398 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE
);
3400 DestroyWindow(hwnd
);
3403 static void test_nosortheader(void)
3408 hwnd
= create_listview_control(LVS_REPORT
);
3409 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3411 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3412 ok(IsWindow(header
), "header expected\n");
3414 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3415 ok(style
& HDS_BUTTONS
, "expected header to have HDS_BUTTONS\n");
3417 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3418 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_NOSORTHEADER
);
3419 /* HDS_BUTTONS retained */
3420 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3421 ok(style
& HDS_BUTTONS
, "expected header to retain HDS_BUTTONS\n");
3423 DestroyWindow(hwnd
);
3425 /* create with LVS_NOSORTHEADER */
3426 hwnd
= create_listview_control(LVS_NOSORTHEADER
| LVS_REPORT
);
3427 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3429 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3430 ok(IsWindow(header
), "header expected\n");
3432 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3433 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3435 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3436 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_NOSORTHEADER
);
3437 /* not changed here */
3438 style
= GetWindowLongPtrA(header
, GWL_STYLE
);
3439 ok(!(style
& HDS_BUTTONS
), "expected header to have no HDS_BUTTONS\n");
3441 DestroyWindow(hwnd
);
3444 static void test_setredraw(void)
3452 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
3453 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3455 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3456 ListView seems to handle it internally without DefWinProc */
3458 /* default value first */
3459 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3462 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3463 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3464 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3466 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
3467 ok(style
& WS_VISIBLE
, "Expected WS_VISIBLE to be set\n");
3468 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3471 /* check update rect after redrawing */
3472 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3474 InvalidateRect(hwnd
, NULL
, FALSE
);
3475 RedrawWindow(hwnd
, NULL
, NULL
, RDW_UPDATENOW
);
3476 rect
.right
= rect
.bottom
= 1;
3477 GetUpdateRect(hwnd
, &rect
, FALSE
);
3478 expect(0, rect
.right
);
3479 expect(0, rect
.bottom
);
3482 hdc
= GetWindowDC(hwndparent
);
3483 ret
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3485 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3487 ret
= SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
3489 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, TRUE
, 0);
3491 ReleaseDC(hwndparent
, hdc
);
3493 /* check notification messages to show that repainting is disabled */
3494 ret
= SendMessageA(hwnd
, LVM_SETITEMCOUNT
, 1, 0);
3496 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3498 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3500 InvalidateRect(hwnd
, NULL
, TRUE
);
3502 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3503 "redraw after WM_SETREDRAW (FALSE)", FALSE
);
3505 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, CLR_NONE
);
3507 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3508 InvalidateRect(hwnd
, NULL
, TRUE
);
3510 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
3511 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE
);
3513 /* message isn't forwarded to header */
3514 subclass_header(hwnd
);
3515 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3516 ret
= SendMessageA(hwnd
, WM_SETREDRAW
, FALSE
, 0);
3518 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, setredraw_seq
,
3519 "WM_SETREDRAW: not forwarded to header", FALSE
);
3521 DestroyWindow(hwnd
);
3524 static void test_hittest(void)
3530 static CHAR text
[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3534 HIMAGELIST himl
, himl2
;
3537 hwnd
= create_listview_control(LVS_REPORT
);
3538 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3540 /* LVS_REPORT with a single subitem (2 columns) */
3541 insert_column(hwnd
, 0);
3542 insert_column(hwnd
, 1);
3543 insert_item(hwnd
, 0);
3546 /* the only purpose of that line is to be as long as a half item rect */
3547 item
.pszText
= text
;
3548 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
3551 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3553 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
3556 memset(&bounds
, 0, sizeof(bounds
));
3557 bounds
.left
= LVIR_BOUNDS
;
3558 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&bounds
);
3560 ok(bounds
.bottom
- bounds
.top
> 0, "Expected non zero item height\n");
3561 ok(bounds
.right
- bounds
.left
> 0, "Expected non zero item width\n");
3562 r
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, TRUE
, 0);
3564 ok(bounds
.bottom
- bounds
.top
== vert
,
3565 "Vertical spacing inconsistent (%d != %d)\n", bounds
.bottom
- bounds
.top
, vert
);
3566 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pos
);
3569 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3571 /* outside columns by x position - valid is [0, 199] */
3573 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3574 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TOLEFT
, 0, FALSE
, FALSE
);
3575 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3577 x
= pos
.x
+ 50; /* column half width */
3578 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3579 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMLABEL
, 0, FALSE
, FALSE
);
3580 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3581 x
= pos
.x
+ 150; /* outside column */
3582 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3583 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3584 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3585 y
= (bounds
.bottom
- bounds
.top
) / 2;
3586 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3587 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3588 /* outside possible client rectangle (to right) */
3590 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3591 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3592 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3593 y
= (bounds
.bottom
- bounds
.top
) / 2;
3594 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3595 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3596 /* subitem returned with -1 item too */
3598 y
= bounds
.top
- vert
;
3599 test_lvm_subitemhittest(hwnd
, x
, y
, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3600 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, -1, 1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3601 /* return values appear to underflow with negative indices */
3605 test_lvm_subitemhittest(hwnd
, x
, y
, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3606 test_lvm_subitemhittest(hwnd
, x
, y
- vert
+ 1, i
, 1, LVHT_ONITEMLABEL
, TRUE
, FALSE
, TRUE
);
3610 /* parent client area is 100x100 by default */
3611 MoveWindow(hwnd
, 0, 0, 300, 100, FALSE
);
3612 x
= pos
.x
+ 150; /* outside column */
3613 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3614 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, FALSE
);
3615 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3616 y
= (bounds
.bottom
- bounds
.top
) / 2;
3617 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_NOWHERE
, 0, FALSE
, TRUE
);
3618 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3619 /* the same with LVS_EX_FULLROWSELECT */
3620 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, LVS_EX_FULLROWSELECT
);
3621 x
= pos
.x
+ 150; /* outside column */
3622 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3623 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEM
, LVHT_ONITEMLABEL
, FALSE
, FALSE
);
3624 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3625 y
= (bounds
.bottom
- bounds
.top
) / 2;
3626 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3627 MoveWindow(hwnd
, 0, 0, 100, 100, FALSE
);
3628 x
= pos
.x
+ 150; /* outside column */
3629 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3630 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3631 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3632 y
= (bounds
.bottom
- bounds
.top
) / 2;
3633 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3634 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 1, LVHT_ONITEMLABEL
, FALSE
, FALSE
, FALSE
);
3635 /* outside possible client rectangle (to right) */
3637 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3638 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, FALSE
);
3639 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3640 y
= (bounds
.bottom
- bounds
.top
) / 2;
3641 test_lvm_hittest(hwnd
, x
, y
, -1, LVHT_TORIGHT
, 0, FALSE
, TRUE
);
3642 test_lvm_subitemhittest(hwnd
, x
, y
, -1, -1, LVHT_NOWHERE
, FALSE
, FALSE
, FALSE
);
3643 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3644 himl
= ImageList_Create(16, 16, 0, 4, 4);
3645 ok(himl
!= NULL
, "failed to create imagelist\n");
3646 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3647 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3648 r
= ImageList_Add(himl
, hbmp
, 0);
3649 ok(r
== 0, "should be zero\n");
3650 hbmp
= CreateBitmap(16, 16, 1, 1, NULL
);
3651 ok(hbmp
!= NULL
, "failed to create bitmap\n");
3652 r
= ImageList_Add(himl
, hbmp
, 0);
3653 ok(r
== 1, "should be one\n");
3655 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3658 item
.mask
= LVIF_IMAGE
;
3662 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3666 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3667 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3668 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3669 y
= (bounds
.bottom
- bounds
.top
) / 2;
3670 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3672 /* state icons indices are 1 based, check with valid index */
3673 item
.mask
= LVIF_STATE
;
3674 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3675 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3678 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3682 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3683 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMSTATEICON
, 0, FALSE
, FALSE
);
3684 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3685 y
= (bounds
.bottom
- bounds
.top
) / 2;
3686 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMSTATEICON
, FALSE
, FALSE
, FALSE
);
3688 himl2
= (HIMAGELIST
)SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3689 ok(himl2
== himl
, "should return handle\n");
3691 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3695 y
= pos
.y
+ (bounds
.bottom
- bounds
.top
) / 2;
3696 test_lvm_hittest(hwnd
, x
, y
, 0, LVHT_ONITEMICON
, 0, FALSE
, FALSE
);
3697 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3698 y
= (bounds
.bottom
- bounds
.top
) / 2;
3699 test_lvm_subitemhittest(hwnd
, x
, y
, 0, 0, LVHT_ONITEMICON
, FALSE
, FALSE
, FALSE
);
3701 DestroyWindow(hwnd
);
3704 static void test_getviewrect(void)
3711 hwnd
= create_listview_control(LVS_REPORT
);
3712 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3715 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3718 insert_column(hwnd
, 0);
3719 insert_column(hwnd
, 1);
3721 memset(&item
, 0, sizeof(item
));
3724 SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3726 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
3728 r
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(120, 0));
3731 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3732 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3734 /* left is set to (2e31-1) - XP SP2 */
3735 expect(0, rect
.right
);
3736 expect(0, rect
.top
);
3737 expect(0, rect
.bottom
);
3739 /* switch to LVS_ICON */
3740 SetWindowLongA(hwnd
, GWL_STYLE
, GetWindowLongA(hwnd
, GWL_STYLE
) & ~LVS_REPORT
);
3742 rect
.left
= rect
.right
= rect
.top
= rect
.bottom
= -1;
3743 r
= SendMessageA(hwnd
, LVM_GETVIEWRECT
, 0, (LPARAM
)&rect
);
3745 expect(0, rect
.left
);
3746 expect(0, rect
.top
);
3747 /* precise value differs for 2k, XP and Vista */
3748 ok(rect
.bottom
> 0, "Expected positive bottom value, got %d\n", rect
.bottom
);
3749 ok(rect
.right
> 0, "Expected positive right value, got %d\n", rect
.right
);
3751 DestroyWindow(hwnd
);
3754 static void test_getitemposition(void)
3761 hwnd
= create_listview_control(LVS_REPORT
);
3762 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3763 header
= subclass_header(hwnd
);
3765 /* LVS_REPORT, single item, no columns added */
3766 insert_item(hwnd
, 0);
3768 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3771 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3773 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq1
, "get item position 1", FALSE
);
3775 /* LVS_REPORT, single item, single column */
3776 insert_column(hwnd
, 0);
3778 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
3781 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3783 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, getitemposition_seq2
, "get item position 2", TRUE
);
3785 memset(&rect
, 0, sizeof(rect
));
3786 SendMessageA(header
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3789 /* offset by header height */
3790 expect(rect
.bottom
- rect
.top
, pt
.y
);
3792 DestroyWindow(hwnd
);
3795 static void test_columnscreation(void)
3800 hwnd
= create_listview_control(LVS_REPORT
);
3801 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3803 insert_item(hwnd
, 0);
3805 /* headers columns aren't created automatically */
3806 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
3807 ok(IsWindow(header
), "Expected header handle\n");
3808 r
= SendMessageA(header
, HDM_GETITEMCOUNT
, 0, 0);
3811 DestroyWindow(hwnd
);
3814 static void test_getitemrect(void)
3817 HIMAGELIST himl
, himl_ret
;
3827 /* rectangle isn't empty for empty text items */
3828 hwnd
= create_listview_control(LVS_LIST
);
3829 memset(&item
, 0, sizeof(item
));
3832 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3834 rect
.left
= LVIR_LABEL
;
3835 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3837 expect(0, rect
.left
);
3838 expect(0, rect
.top
);
3840 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, rect
.right
);
3841 ReleaseDC(hwnd
, hdc
);
3842 DestroyWindow(hwnd
);
3844 hwnd
= create_listview_control(LVS_REPORT
);
3845 ok(hwnd
!= NULL
, "failed to create a listview window\n");
3848 memset(&item
, 0, sizeof(item
));
3851 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
3854 rect
.left
= LVIR_BOUNDS
;
3855 rect
.right
= rect
.top
= rect
.bottom
= -1;
3856 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3859 /* zero width rectangle with no padding */
3860 expect(0, rect
.left
);
3861 expect(0, rect
.right
);
3863 insert_column(hwnd
, 0);
3864 insert_column(hwnd
, 1);
3866 col
.mask
= LVCF_WIDTH
;
3868 r
= SendMessageA(hwnd
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
3871 col
.mask
= LVCF_WIDTH
;
3873 r
= SendMessageA(hwnd
, LVM_SETCOLUMNA
, 1, (LPARAM
)&col
);
3876 rect
.left
= LVIR_BOUNDS
;
3877 rect
.right
= rect
.top
= rect
.bottom
= -1;
3878 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3881 /* still no left padding */
3882 expect(0, rect
.left
);
3883 expect(150, rect
.right
);
3885 rect
.left
= LVIR_SELECTBOUNDS
;
3886 rect
.right
= rect
.top
= rect
.bottom
= -1;
3887 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3890 expect(2, rect
.left
);
3892 rect
.left
= LVIR_LABEL
;
3893 rect
.right
= rect
.top
= rect
.bottom
= -1;
3894 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3896 /* padding, column width */
3897 expect(2, rect
.left
);
3898 expect(50, rect
.right
);
3900 /* no icons attached */
3901 rect
.left
= LVIR_ICON
;
3902 rect
.right
= rect
.top
= rect
.bottom
= -1;
3903 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3906 expect(2, rect
.left
);
3907 expect(2, rect
.right
);
3910 order
[0] = 1; order
[1] = 0;
3911 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3914 r
= SendMessageA(hwnd
, LVM_GETITEMPOSITION
, 0, (LPARAM
)&pt
);
3916 /* 1 indexed column width + padding */
3918 /* rect is at zero too */
3919 rect
.left
= LVIR_BOUNDS
;
3920 rect
.right
= rect
.top
= rect
.bottom
= -1;
3921 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3923 expect(0, rect
.left
);
3924 /* just width sum */
3925 expect(150, rect
.right
);
3927 rect
.left
= LVIR_SELECTBOUNDS
;
3928 rect
.right
= rect
.top
= rect
.bottom
= -1;
3929 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3931 /* column width + padding */
3932 expect(102, rect
.left
);
3934 /* back to initial order */
3935 order
[0] = 0; order
[1] = 1;
3936 r
= SendMessageA(hwnd
, LVM_SETCOLUMNORDERARRAY
, 2, (LPARAM
)&order
);
3940 himl
= ImageList_Create(16, 16, 0, 2, 2);
3941 ok(himl
!= NULL
, "failed to create imagelist\n");
3942 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3943 ok(hbm
!= NULL
, "failed to create bitmap\n");
3944 r
= ImageList_Add(himl
, hbm
, 0);
3946 hbm
= CreateBitmap(16, 16, 1, 1, NULL
);
3947 ok(hbm
!= NULL
, "failed to create bitmap\n");
3948 r
= ImageList_Add(himl
, hbm
, 0);
3951 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl
);
3954 item
.mask
= LVIF_STATE
;
3955 item
.state
= INDEXTOSTATEIMAGEMASK(1);
3956 item
.stateMask
= LVIS_STATEIMAGEMASK
;
3959 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3963 rect
.left
= LVIR_ICON
;
3964 rect
.right
= rect
.top
= rect
.bottom
= -1;
3965 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3967 /* padding + stateicon width */
3968 expect(18, rect
.left
);
3969 expect(18, rect
.right
);
3971 rect
.left
= LVIR_LABEL
;
3972 rect
.right
= rect
.top
= rect
.bottom
= -1;
3973 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3975 /* padding + stateicon width -> column width */
3976 expect(18, rect
.left
);
3977 expect(50, rect
.right
);
3979 himl_ret
= (HIMAGELIST
)SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, 0);
3980 ok(himl_ret
== himl
, "got %p, expected %p\n", himl_ret
, himl
);
3982 r
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl
);
3985 item
.mask
= LVIF_STATE
| LVIF_IMAGE
;
3988 item
.stateMask
= ~0;
3991 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
3995 rect
.left
= LVIR_ICON
;
3996 rect
.right
= rect
.top
= rect
.bottom
= -1;
3997 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
3999 /* padding, icon width */
4000 expect(2, rect
.left
);
4001 expect(18, rect
.right
);
4003 rect
.left
= LVIR_LABEL
;
4004 rect
.right
= rect
.top
= rect
.bottom
= -1;
4005 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4007 /* padding + icon width -> column width */
4008 expect(18, rect
.left
);
4009 expect(50, rect
.right
);
4012 rect
.left
= LVIR_SELECTBOUNDS
;
4013 rect
.right
= rect
.top
= rect
.bottom
= -1;
4014 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4016 /* padding, column width */
4017 expect(2, rect
.left
);
4018 expect(50, rect
.right
);
4020 /* try with indentation */
4021 item
.mask
= LVIF_INDENT
;
4025 r
= SendMessageA(hwnd
, LVM_SETITEMA
, 0, (LPARAM
)&item
);
4029 rect
.left
= LVIR_BOUNDS
;
4030 rect
.right
= rect
.top
= rect
.bottom
= -1;
4031 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4033 /* padding + 1 icon width, column width */
4034 expect(0, rect
.left
);
4035 expect(150, rect
.right
);
4038 rect
.left
= LVIR_SELECTBOUNDS
;
4039 rect
.right
= rect
.top
= rect
.bottom
= -1;
4040 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4042 /* padding + 1 icon width, column width */
4043 expect(2 + 16, rect
.left
);
4044 expect(50, rect
.right
);
4047 rect
.left
= LVIR_LABEL
;
4048 rect
.right
= rect
.top
= rect
.bottom
= -1;
4049 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4051 /* padding + 2 icon widths, column width */
4052 expect(2 + 16*2, rect
.left
);
4053 expect(50, rect
.right
);
4056 rect
.left
= LVIR_ICON
;
4057 rect
.right
= rect
.top
= rect
.bottom
= -1;
4058 r
= SendMessageA(hwnd
, LVM_GETITEMRECT
, 0, (LPARAM
)&rect
);
4060 /* padding + 1 icon width indentation, icon width */
4061 expect(2 + 16, rect
.left
);
4062 expect(34, rect
.right
);
4064 DestroyWindow(hwnd
);
4067 static void test_editbox(void)
4069 static CHAR testitemA
[] = "testitem";
4070 static CHAR testitem1A
[] = "testitem_quitelongname";
4071 static CHAR testitem2A
[] = "testITEM_quitelongname";
4072 static CHAR buffer
[25];
4073 HWND hwnd
, hwndedit
, hwndedit2
, header
;
4077 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4078 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4080 insert_column(hwnd
, 0);
4082 memset(&item
, 0, sizeof(item
));
4083 item
.mask
= LVIF_TEXT
;
4084 item
.pszText
= testitemA
;
4087 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4090 /* test notifications without edit created */
4091 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4092 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)0xdeadbeef);
4094 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4095 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE
);
4096 /* same thing but with valid window */
4097 hwndedit
= CreateWindowA("Edit", "Test edit", WS_VISIBLE
| WS_CHILD
, 0, 0, 20,
4098 10, hwnd
, (HMENU
)1, (HINSTANCE
)GetWindowLongPtrA(hwnd
, GWLP_HINSTANCE
), 0);
4099 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4100 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_SETFOCUS
), (LPARAM
)hwndedit
);
4102 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4103 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE
);
4104 DestroyWindow(hwndedit
);
4106 /* setting focus is necessary */
4108 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4109 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4111 /* test children Z-order after Edit box created */
4112 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4113 ok(IsWindow(header
), "Expected header to be created\n");
4114 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4115 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4117 /* modify initial string */
4118 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4121 /* edit window is resized and repositioned,
4122 check again for Z-order - it should be preserved */
4123 ok(GetTopWindow(hwnd
) == header
, "Expected header to be on top\n");
4124 ok(GetNextWindow(header
, GW_HWNDNEXT
) == hwndedit
, "got %p\n", GetNextWindow(header
, GW_HWNDNEXT
));
4126 /* return focus to listview */
4129 memset(&item
, 0, sizeof(item
));
4130 item
.mask
= LVIF_TEXT
;
4131 item
.pszText
= buffer
;
4132 item
.cchTextMax
= sizeof(buffer
);
4135 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
4138 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4140 /* send LVM_EDITLABEL on already created edit */
4142 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4143 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4144 /* focus will be set to edit */
4145 ok(GetFocus() == hwndedit
, "Expected Edit window to be focused\n");
4146 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4147 ok(IsWindow(hwndedit2
), "Expected Edit window to be created\n");
4149 /* creating label disabled when control isn't focused */
4151 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4152 todo_wine
ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4154 /* check EN_KILLFOCUS handling */
4155 memset(&item
, 0, sizeof(item
));
4156 item
.pszText
= testitemA
;
4159 r
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
4163 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4164 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4165 /* modify edit and notify control that it lost focus */
4166 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem1A
);
4168 g_editbox_disp_info
.item
.pszText
= NULL
;
4169 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4171 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "expected notification with not null text\n");
4173 memset(&item
, 0, sizeof(item
));
4174 item
.pszText
= buffer
;
4175 item
.cchTextMax
= sizeof(buffer
);
4178 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4179 expect(lstrlenA(item
.pszText
), r
);
4180 ok(strcmp(buffer
, testitem1A
) == 0, "Expected item text to change\n");
4181 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4183 /* change item name to differ in casing only */
4185 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4186 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4187 /* modify edit and notify control that it lost focus */
4188 r
= SendMessageA(hwndedit
, WM_SETTEXT
, 0, (LPARAM
)testitem2A
);
4190 g_editbox_disp_info
.item
.pszText
= NULL
;
4191 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4193 ok(g_editbox_disp_info
.item
.pszText
!= NULL
, "got %p\n", g_editbox_disp_info
.item
.pszText
);
4195 memset(&item
, 0, sizeof(item
));
4196 item
.pszText
= buffer
;
4197 item
.cchTextMax
= sizeof(buffer
);
4200 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4201 expect(lstrlenA(item
.pszText
), r
);
4202 ok(strcmp(buffer
, testitem2A
) == 0, "got %s, expected %s\n", buffer
, testitem2A
);
4203 ok(!IsWindow(hwndedit
), "Expected Edit window to be freed\n");
4205 /* end edit without saving */
4207 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4208 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4209 r
= SendMessageA(hwndedit
, WM_KEYDOWN
, VK_ESCAPE
, 0);
4211 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4212 "edit box - end edit, no change, escape", TRUE
);
4213 /* end edit with saving */
4215 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4216 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4217 r
= SendMessageA(hwndedit
, WM_KEYDOWN
, VK_RETURN
, 0);
4219 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4220 "edit box - end edit, no change, return", TRUE
);
4222 memset(&item
, 0, sizeof(item
));
4223 item
.pszText
= buffer
;
4224 item
.cchTextMax
= sizeof(buffer
);
4227 r
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
4228 expect(lstrlenA(item
.pszText
), r
);
4229 ok(strcmp(buffer
, testitem2A
) == 0, "Expected item text to change\n");
4231 /* LVM_EDITLABEL with -1 destroys current edit */
4232 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_GETEDITCONTROL
, 0, 0);
4233 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4234 /* no edit present */
4235 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -1, 0);
4236 ok(hwndedit
== NULL
, "Expected Edit window not to be created\n");
4237 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4238 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4240 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4241 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -1, 0);
4242 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4243 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4244 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4245 /* check another negative value */
4246 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4247 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4248 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4249 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, -2, 0);
4250 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4251 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4252 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4253 /* and value greater than max item index */
4254 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4255 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4256 ok(GetFocus() == hwndedit
, "Expected Edit to be focused\n");
4257 r
= SendMessageA(hwnd
, LVM_GETITEMCOUNT
, 0, 0);
4258 hwndedit2
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, r
, 0);
4259 ok(hwndedit2
== NULL
, "Expected Edit window not to be created\n");
4260 ok(!IsWindow(hwndedit
), "Expected Edit window to be destroyed\n");
4261 ok(GetFocus() == hwnd
, "Expected List to be focused\n");
4263 /* messaging tests */
4265 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4267 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4268 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4269 /* testing only sizing messages */
4270 ok_sequence(sequences
, EDITBOX_SEQ_INDEX
, editbox_create_pos
,
4271 "edit box create - sizing", FALSE
);
4273 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4275 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4276 ok(IsWindow(hwndedit
), "Expected Edit window to be created\n");
4277 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4278 r
= SendMessageA(hwnd
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hwndedit
);
4280 ok_sequence(sequences
, PARENT_SEQ_INDEX
, edit_end_nochange
,
4281 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE
);
4283 DestroyWindow(hwnd
);
4286 static void test_notifyformat(void)
4291 hwnd
= create_listview_control(LVS_REPORT
);
4292 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4294 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4295 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4296 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4298 SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4300 r
= SendMessageA(hwnd
, LVM_SETUNICODEFORMAT
, 1, 0);
4302 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4305 r
= SendMessageA(hwnd
, LVM_SETUNICODEFORMAT
, 0, 0);
4307 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4312 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4313 DestroyWindow(hwnd
);
4317 DestroyWindow(hwnd
);
4319 /* test failure in parent WM_NOTIFYFORMAT */
4321 hwnd
= create_listview_control(LVS_REPORT
);
4322 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4323 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4324 ok(IsWindow(header
), "expected header to be created\n");
4325 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4327 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4328 ok( r
== 1, "Expected 1, got %d\n", r
);
4329 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_QUERY
);
4330 ok(r
!= 0, "Expected valid format\n");
4332 notifyFormat
= NFR_UNICODE
;
4333 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4334 expect(NFR_UNICODE
, r
);
4335 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4337 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4338 ok( r
== 1, "Expected 1, got %d\n", r
);
4340 notifyFormat
= NFR_ANSI
;
4341 r
= SendMessageA(hwnd
, WM_NOTIFYFORMAT
, 0, NF_REQUERY
);
4342 expect(NFR_ANSI
, r
);
4343 r
= SendMessageA(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4345 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4346 ok( r
== 1, "Expected 1, got %d\n", r
);
4348 DestroyWindow(hwnd
);
4350 hwndparentW
= create_parent_window(TRUE
);
4351 ok(IsWindow(hwndparentW
), "Unicode parent creation failed\n");
4352 if (!IsWindow(hwndparentW
)) return;
4355 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4356 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4357 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4358 ok(IsWindow(header
), "expected header to be created\n");
4359 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4361 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4363 DestroyWindow(hwnd
);
4364 /* receiving error code defaulting to ansi */
4366 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4367 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4368 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4369 ok(IsWindow(header
), "expected header to be created\n");
4370 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4372 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4374 DestroyWindow(hwnd
);
4375 /* receiving ansi code from unicode window, use it */
4376 notifyFormat
= NFR_ANSI
;
4377 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparentW
);
4378 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4379 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4380 ok(IsWindow(header
), "expected header to be created\n");
4381 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4383 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4385 DestroyWindow(hwnd
);
4386 /* unicode listview with ansi parent window */
4388 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4389 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4390 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4391 ok(IsWindow(header
), "expected header to be created\n");
4392 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4394 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4396 DestroyWindow(hwnd
);
4397 /* unicode listview with ansi parent window, return error code */
4399 hwnd
= create_listview_controlW(LVS_REPORT
, hwndparent
);
4400 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4401 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
4402 ok(IsWindow(header
), "expected header to be created\n");
4403 r
= SendMessageW(hwnd
, LVM_GETUNICODEFORMAT
, 0, 0);
4405 r
= SendMessageA(header
, HDM_GETUNICODEFORMAT
, 0, 0);
4407 DestroyWindow(hwnd
);
4409 DestroyWindow(hwndparentW
);
4412 static void test_indentation(void)
4418 hwnd
= create_listview_control(LVS_REPORT
);
4419 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4421 memset(&item
, 0, sizeof(item
));
4422 item
.mask
= LVIF_INDENT
;
4424 item
.iIndent
= I_INDENTCALLBACK
;
4425 r
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
4428 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4431 item
.mask
= LVIF_INDENT
;
4432 r
= SendMessageA(hwnd
, LVM_GETITEMA
, 0, (LPARAM
)&item
);
4435 ok_sequence(sequences
, PARENT_SEQ_INDEX
, single_getdispinfo_parent_seq
,
4436 "get indent dispinfo", FALSE
);
4438 DestroyWindow(hwnd
);
4441 static INT CALLBACK
DummyCompareEx(LPARAM first
, LPARAM second
, LPARAM param
)
4446 static BOOL
is_below_comctl_5(void)
4451 hwnd
= create_listview_control(LVS_REPORT
);
4452 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4453 insert_item(hwnd
, 0);
4455 ret
= SendMessageA(hwnd
, LVM_SORTITEMSEX
, 0, (LPARAM
)&DummyCompareEx
);
4457 DestroyWindow(hwnd
);
4462 static void test_get_set_view(void)
4468 /* test style->view mapping */
4469 hwnd
= create_listview_control(LVS_REPORT
);
4470 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4472 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4473 expect(LV_VIEW_DETAILS
, ret
);
4475 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4477 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
& ~LVS_REPORT
);
4478 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4479 expect(LV_VIEW_ICON
, ret
);
4481 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4482 SetWindowLongPtrA(hwnd
, GWL_STYLE
, style
| LVS_SMALLICON
);
4483 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4484 expect(LV_VIEW_SMALLICON
, ret
);
4486 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4487 SetWindowLongPtrA(hwnd
, GWL_STYLE
, (style
& ~LVS_SMALLICON
) | LVS_LIST
);
4488 ret
= SendMessageA(hwnd
, LVM_GETVIEW
, 0, 0);
4489 expect(LV_VIEW_LIST
, ret
);
4491 /* switching view doesn't touch window style */
4492 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_DETAILS
, 0);
4494 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4495 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4496 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_ICON
, 0);
4498 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4499 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4500 ret
= SendMessageA(hwnd
, LVM_SETVIEW
, LV_VIEW_SMALLICON
, 0);
4502 style
= GetWindowLongPtrA(hwnd
, GWL_STYLE
);
4503 ok(style
& LVS_LIST
, "Expected style to be preserved\n");
4505 DestroyWindow(hwnd
);
4508 static void test_canceleditlabel(void)
4510 HWND hwnd
, hwndedit
;
4514 static CHAR test
[] = "test";
4515 static const CHAR test1
[] = "test1";
4517 hwnd
= create_listview_control(LVS_EDITLABELS
| LVS_REPORT
);
4518 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4520 insert_item(hwnd
, 0);
4522 /* try without edit created */
4523 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4524 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4526 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
4527 "cancel edit label without edit", FALSE
);
4529 /* cancel without data change */
4531 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4532 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4533 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4535 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4537 /* cancel after data change */
4538 memset(&itema
, 0, sizeof(itema
));
4539 itema
.pszText
= test
;
4540 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&itema
);
4543 hwndedit
= (HWND
)SendMessageA(hwnd
, LVM_EDITLABELA
, 0, 0);
4544 ok(IsWindow(hwndedit
), "Expected edit control to be created\n");
4545 ret
= SetWindowTextA(hwndedit
, test1
);
4547 ret
= SendMessageA(hwnd
, LVM_CANCELEDITLABEL
, 0, 0);
4549 ok(!IsWindow(hwndedit
), "Expected edit control to be destroyed\n");
4550 memset(&itema
, 0, sizeof(itema
));
4551 itema
.pszText
= buff
;
4552 itema
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
4553 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&itema
);
4555 ok(strcmp(buff
, test1
) == 0, "Expected label text not to change\n");
4557 DestroyWindow(hwnd
);
4560 static void test_mapidindex(void)
4565 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4566 hwnd
= create_listview_control(LVS_OWNERDATA
| LVS_REPORT
);
4567 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4568 insert_item(hwnd
, 0);
4569 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4571 DestroyWindow(hwnd
);
4573 hwnd
= create_listview_control(LVS_REPORT
);
4574 ok(hwnd
!= NULL
, "failed to create a listview window\n");
4576 /* LVM_MAPINDEXTOID with invalid index */
4577 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4580 insert_item(hwnd
, 0);
4581 insert_item(hwnd
, 1);
4583 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, -1, 0);
4585 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 2, 0);
4588 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4590 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4592 /* remove 0 indexed item, id retained */
4593 SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
4594 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 0, 0);
4596 /* new id starts from previous value */
4597 insert_item(hwnd
, 1);
4598 ret
= SendMessageA(hwnd
, LVM_MAPINDEXTOID
, 1, 0);
4601 /* get index by id */
4602 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, -1, 0);
4604 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 0, 0);
4606 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 1, 0);
4608 ret
= SendMessageA(hwnd
, LVM_MAPIDTOINDEX
, 2, 0);
4611 DestroyWindow(hwnd
);
4614 static void test_getitemspacing(void)
4619 HIMAGELIST himl40
, himl80
;
4621 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
4622 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
4625 hwnd
= create_listview_control(LVS_ICON
);
4626 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4627 expect(cx
, LOWORD(ret
));
4628 expect(cy
, HIWORD(ret
));
4630 /* now try with icons */
4631 himl40
= ImageList_Create(40, 40, 0, 4, 4);
4632 ok(himl40
!= NULL
, "failed to create imagelist\n");
4633 himl80
= ImageList_Create(80, 80, 0, 4, 4);
4634 ok(himl80
!= NULL
, "failed to create imagelist\n");
4635 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4638 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4639 /* spacing + icon size returned */
4640 expect(cx
+ 40, LOWORD(ret
));
4641 expect(cy
+ 40, HIWORD(ret
));
4642 /* try changing icon size */
4643 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl80
);
4645 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4646 /* spacing + icon size returned */
4647 expect(cx
+ 80, LOWORD(ret
));
4648 expect(cy
+ 80, HIWORD(ret
));
4650 /* set own icon spacing */
4651 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(100, 100));
4652 expect(cx
+ 80, LOWORD(ret
));
4653 expect(cy
+ 80, HIWORD(ret
));
4655 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4656 /* set size returned */
4657 expect(100, LOWORD(ret
));
4658 expect(100, HIWORD(ret
));
4660 /* now change image list - icon spacing should be unaffected */
4661 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4663 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4664 /* set size returned */
4665 expect(100, LOWORD(ret
));
4666 expect(100, HIWORD(ret
));
4668 /* spacing = 0 - keep previous value */
4669 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(0, -1));
4670 expect(100, LOWORD(ret
));
4671 expect(100, HIWORD(ret
));
4673 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4674 expect(100, LOWORD(ret
));
4676 expect(0xFFFF, HIWORD(ret
));
4678 if (sizeof(void*) == 8)
4680 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4681 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, (DWORD
)-1);
4682 expect(100, LOWORD(ret
));
4683 expect(0xFFFF, HIWORD(ret
));
4685 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, -1);
4686 expect(0xFFFF, LOWORD(ret
));
4687 expect(0xFFFF, HIWORD(ret
));
4691 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, -1);
4692 expect(100, LOWORD(ret
));
4693 expect(0xFFFF, HIWORD(ret
));
4695 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4696 /* spacing + icon size returned */
4697 expect(cx
+ 40, LOWORD(ret
));
4698 expect(cy
+ 40, HIWORD(ret
));
4700 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, 0);
4701 ImageList_Destroy(himl80
);
4702 DestroyWindow(hwnd
);
4704 hwnd
= create_listview_control(LVS_SMALLICON
);
4705 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4706 expect(cx
, LOWORD(ret
));
4707 expect(cy
, HIWORD(ret
));
4709 /* spacing does not depend on selected view type */
4710 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl40
);
4713 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4714 /* spacing + icon size returned */
4715 expect(cx
+ 40, LOWORD(ret
));
4716 expect(cy
+ 40, HIWORD(ret
));
4718 SendMessageA(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, 0);
4719 ImageList_Destroy(himl40
);
4720 DestroyWindow(hwnd
);
4722 hwnd
= create_listview_control(LVS_REPORT
);
4723 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4724 expect(cx
, LOWORD(ret
));
4725 expect(cy
, HIWORD(ret
));
4727 DestroyWindow(hwnd
);
4729 hwnd
= create_listview_control(LVS_LIST
);
4730 ret
= SendMessageA(hwnd
, LVM_GETITEMSPACING
, FALSE
, 0);
4731 expect(cx
, LOWORD(ret
));
4732 expect(cy
, HIWORD(ret
));
4734 DestroyWindow(hwnd
);
4737 static void test_getcolumnwidth(void)
4746 /* default column width */
4747 hwnd
= create_listview_control(LVS_ICON
);
4748 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4750 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
4751 SetWindowLongA(hwnd
, GWL_STYLE
, style
| LVS_LIST
);
4752 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4753 todo_wine
expect(8, ret
);
4754 style
= GetWindowLongA(hwnd
, GWL_STYLE
) & ~LVS_LIST
;
4755 SetWindowLongA(hwnd
, GWL_STYLE
, style
| LVS_REPORT
);
4757 ret
= SendMessageA(hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
4759 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4761 DestroyWindow(hwnd
);
4763 /* default column width with item added */
4764 hwnd
= create_listview_control(LVS_LIST
);
4765 memset(&itema
, 0, sizeof(itema
));
4766 SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4767 ret
= SendMessageA(hwnd
, LVM_GETCOLUMNWIDTH
, 0, 0);
4769 todo_wine
expect(((GetDeviceCaps(hdc
, LOGPIXELSX
) + 15) / 16) * 16, ret
);
4770 ReleaseDC(hwnd
, hdc
);
4771 DestroyWindow(hwnd
);
4774 static void test_scrollnotify(void)
4779 hwnd
= create_listview_control(LVS_REPORT
);
4781 insert_column(hwnd
, 0);
4782 insert_column(hwnd
, 1);
4783 insert_item(hwnd
, 0);
4785 /* make it scrollable - resize */
4786 ret
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 0, MAKELPARAM(100, 0));
4788 ret
= SendMessageA(hwnd
, LVM_SETCOLUMNWIDTH
, 1, MAKELPARAM(100, 0));
4791 /* try with dummy call */
4792 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4793 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 0, 0);
4795 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4796 "scroll notify 1", TRUE
);
4798 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4799 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 1, 0);
4801 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4802 "scroll notify 2", TRUE
);
4804 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4805 ret
= SendMessageA(hwnd
, LVM_SCROLL
, 1, 1);
4807 ok_sequence(sequences
, PARENT_SEQ_INDEX
, scroll_parent_seq
,
4808 "scroll notify 3", TRUE
);
4810 DestroyWindow(hwnd
);
4813 static void test_LVS_EX_TRANSPARENTBKGND(void)
4819 hwnd
= create_listview_control(LVS_REPORT
);
4821 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4824 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4825 LVS_EX_TRANSPARENTBKGND
);
4827 ret
= SendMessageA(hwnd
, LVM_GETBKCOLOR
, 0, 0);
4828 if (ret
!= CLR_NONE
)
4830 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4831 DestroyWindow(hwnd
);
4835 /* try to set some back color and check this style bit */
4836 ret
= SendMessageA(hwnd
, LVM_SETBKCOLOR
, 0, RGB(0, 0, 0));
4838 ret
= SendMessageA(hwnd
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
4839 ok(!(ret
& LVS_EX_TRANSPARENTBKGND
), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4841 /* now test what this style actually does */
4842 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_TRANSPARENTBKGND
,
4843 LVS_EX_TRANSPARENTBKGND
);
4845 hdc
= GetWindowDC(hwndparent
);
4847 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
4848 SendMessageA(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
4849 ok_sequence(sequences
, PARENT_SEQ_INDEX
, lvs_ex_transparentbkgnd_seq
,
4850 "LVS_EX_TRANSPARENTBKGND parent", FALSE
);
4852 ReleaseDC(hwndparent
, hdc
);
4854 DestroyWindow(hwnd
);
4857 static void test_approximate_viewrect(void)
4864 static CHAR test
[] = "abracadabra, a very long item label";
4866 hwnd
= create_listview_control(LVS_ICON
);
4867 himl
= ImageList_Create(40, 40, 0, 4, 4);
4868 ok(himl
!= NULL
, "failed to create imagelist\n");
4869 hbmp
= CreateBitmap(40, 40, 1, 1, NULL
);
4870 ok(hbmp
!= NULL
, "failed to create bitmap\n");
4871 ret
= ImageList_Add(himl
, hbmp
, 0);
4873 ret
= SendMessageA(hwnd
, LVM_SETIMAGELIST
, 0, (LPARAM
)himl
);
4876 itema
.mask
= LVIF_IMAGE
;
4880 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&itema
);
4883 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(75, 75));
4887 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4891 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4892 expect(MAKELONG(77,827), ret
);
4894 ret
= SendMessageA(hwnd
, LVM_SETICONSPACING
, 0, MAKELPARAM(50, 50));
4895 ok(ret
!= 0, "got 0\n");
4897 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 11, MAKELPARAM(100,100));
4898 expect(MAKELONG(102,302), ret
);
4900 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4901 expect(MAKELONG(52,52), ret
);
4903 itema
.pszText
= test
;
4904 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&itema
);
4906 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, -1, MAKELPARAM(100,100));
4907 expect(MAKELONG(52,52), ret
);
4909 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 0, MAKELPARAM(100,100));
4910 expect(MAKELONG(52,2), ret
);
4911 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 1, MAKELPARAM(100,100));
4912 expect(MAKELONG(52,52), ret
);
4913 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 2, MAKELPARAM(100,100));
4914 expect(MAKELONG(102,52), ret
);
4915 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 3, MAKELPARAM(100,100));
4916 expect(MAKELONG(102,102), ret
);
4917 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 4, MAKELPARAM(100,100));
4918 expect(MAKELONG(102,102), ret
);
4919 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 5, MAKELPARAM(100,100));
4920 expect(MAKELONG(102,152), ret
);
4921 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 6, MAKELPARAM(100,100));
4922 expect(MAKELONG(102,152), ret
);
4923 ret
= SendMessageA(hwnd
, LVM_APPROXIMATEVIEWRECT
, 7, MAKELPARAM(160,100));
4924 expect(MAKELONG(152,152), ret
);
4926 DestroyWindow(hwnd
);
4929 static void test_finditem(void)
4936 hwnd
= create_listview_control(LVS_REPORT
);
4937 insert_item(hwnd
, 0);
4939 memset(&fi
, 0, sizeof(fi
));
4941 /* full string search, inserted text was "foo" */
4943 fi
.flags
= LVFI_STRING
;
4945 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4947 /* partial string search, inserted text was "foo" */
4949 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4951 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4953 /* partial string search, part after start char */
4955 fi
.flags
= LVFI_STRING
| LVFI_PARTIAL
;
4957 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4960 /* try with LVFI_SUBSTRING */
4962 fi
.flags
= LVFI_SUBSTRING
;
4964 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4967 win_skip("LVFI_SUBSTRING not supported\n");
4968 DestroyWindow(hwnd
);
4973 fi
.flags
= LVFI_SUBSTRING
;
4975 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4978 fi
.flags
= LVFI_SUBSTRING
;
4980 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4984 fi
.flags
= LVFI_SUBSTRING
| LVFI_STRING
;
4986 r
= SendMessageA(hwnd
, LVM_FINDITEMA
, -1, (LPARAM
)&fi
);
4989 DestroyWindow(hwnd
);
4992 static void test_LVS_EX_HEADERINALLVIEWS(void)
4997 hwnd
= create_listview_control(LVS_ICON
);
4999 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5000 LVS_EX_HEADERINALLVIEWS
);
5002 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5003 if (!IsWindow(header
))
5005 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
5006 DestroyWindow(hwnd
);
5010 /* LVS_NOCOLUMNHEADER works as before */
5011 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5012 SetWindowLongW(hwnd
, GWL_STYLE
, style
| LVS_NOCOLUMNHEADER
);
5013 style
= GetWindowLongA(header
, GWL_STYLE
);
5014 ok(style
& HDS_HIDDEN
, "Expected HDS_HIDDEN\n");
5015 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
5016 SetWindowLongW(hwnd
, GWL_STYLE
, style
& ~LVS_NOCOLUMNHEADER
);
5017 style
= GetWindowLongA(header
, GWL_STYLE
);
5018 ok(!(style
& HDS_HIDDEN
), "Expected HDS_HIDDEN to be unset\n");
5020 /* try to remove style */
5021 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
, 0);
5022 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5023 ok(IsWindow(header
), "Expected header to be created\n");
5024 style
= GetWindowLongA(header
, GWL_STYLE
);
5025 ok(!(style
& HDS_HIDDEN
), "HDS_HIDDEN not expected\n");
5027 DestroyWindow(hwnd
);
5029 /* check other styles */
5030 hwnd
= create_listview_control(LVS_LIST
);
5031 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5032 LVS_EX_HEADERINALLVIEWS
);
5033 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5034 ok(IsWindow(header
), "Expected header to be created\n");
5035 DestroyWindow(hwnd
);
5037 hwnd
= create_listview_control(LVS_SMALLICON
);
5038 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5039 LVS_EX_HEADERINALLVIEWS
);
5040 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5041 ok(IsWindow(header
), "Expected header to be created\n");
5042 DestroyWindow(hwnd
);
5044 hwnd
= create_listview_control(LVS_REPORT
);
5045 SendMessageA(hwnd
, LVM_SETEXTENDEDLISTVIEWSTYLE
, LVS_EX_HEADERINALLVIEWS
,
5046 LVS_EX_HEADERINALLVIEWS
);
5047 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5048 ok(IsWindow(header
), "Expected header to be created\n");
5049 DestroyWindow(hwnd
);
5052 static void test_hover(void)
5057 hwnd
= create_listview_control(LVS_ICON
);
5059 /* test WM_MOUSEHOVER forwarding */
5060 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5061 r
= SendMessageA(hwnd
, WM_MOUSEHOVER
, 0, 0);
5063 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER allow test", TRUE
);
5064 g_block_hover
= TRUE
;
5065 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5066 r
= SendMessageA(hwnd
, WM_MOUSEHOVER
, 0, 0);
5068 ok_sequence(sequences
, PARENT_SEQ_INDEX
, hover_parent
, "NM_HOVER block test", TRUE
);
5069 g_block_hover
= FALSE
;
5071 r
= SendMessageA(hwnd
, LVM_SETHOVERTIME
, 0, 500);
5072 expect(HOVER_DEFAULT
, r
);
5073 r
= SendMessageA(hwnd
, LVM_GETHOVERTIME
, 0, 0);
5076 DestroyWindow(hwnd
);
5079 static void test_destroynotify(void)
5084 hwnd
= create_listview_control(LVS_REPORT
);
5085 ok(hwnd
!= NULL
, "failed to create listview window\n");
5087 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5088 DestroyWindow(hwnd
);
5089 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_destroy
, "check destroy order", FALSE
);
5091 /* same for ownerdata list */
5092 hwnd
= create_listview_control(LVS_REPORT
|LVS_OWNERDATA
);
5093 ok(hwnd
!= NULL
, "failed to create listview window\n");
5095 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5096 DestroyWindow(hwnd
);
5097 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_ownerdata_destroy
, "check destroy order, ownerdata", FALSE
);
5099 hwnd
= create_listview_control(LVS_REPORT
|LVS_OWNERDATA
);
5100 ok(hwnd
!= NULL
, "failed to create listview window\n");
5102 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5103 ret
= SendMessageA(hwnd
, LVM_DELETEALLITEMS
, 0, 0);
5104 ok(ret
== TRUE
, "got %d\n", ret
);
5105 ok_sequence(sequences
, COMBINED_SEQ_INDEX
, listview_ownerdata_deleteall
, "deleteall ownerdata", FALSE
);
5106 DestroyWindow(hwnd
);
5109 static void test_header_notification(void)
5111 static char textA
[] = "newtext";
5119 list
= create_listview_control(LVS_REPORT
);
5120 ok(list
!= NULL
, "failed to create listview window\n");
5122 memset(&col
, 0, sizeof(col
));
5123 col
.mask
= LVCF_WIDTH
;
5125 ret
= SendMessageA(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5128 /* check list parent notification after header item changed,
5129 this test should be placed before header subclassing to avoid
5130 Listview -> Header messages to be logged */
5131 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5133 col
.mask
= LVCF_TEXT
;
5134 col
.pszText
= textA
;
5135 r
= SendMessageA(list
, LVM_SETCOLUMNA
, 0, (LPARAM
)&col
);
5138 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_changed_seq
,
5139 "header notify, listview", FALSE
);
5140 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5141 "header notify, parent", FALSE
);
5143 header
= subclass_header(list
);
5145 ret
= SendMessageA(header
, HDM_GETITEMCOUNT
, 0, 0);
5148 memset(&item
, 0, sizeof(item
));
5149 item
.mask
= HDI_WIDTH
;
5150 ret
= SendMessageA(header
, HDM_GETITEMA
, 0, (LPARAM
)&item
);
5152 expect(100, item
.cxy
);
5154 nmh
.hdr
.hwndFrom
= header
;
5155 nmh
.hdr
.idFrom
= GetWindowLongPtrA(header
, GWLP_ID
);
5156 nmh
.hdr
.code
= HDN_ITEMCHANGEDA
;
5159 item
.mask
= HDI_WIDTH
;
5162 ret
= SendMessageA(list
, WM_NOTIFY
, 0, (LPARAM
)&nmh
);
5165 DestroyWindow(list
);
5168 static void test_header_notification2(void)
5170 static char textA
[] = "newtext";
5177 struct message parent_header_notify_seq
[] = {
5178 { WM_NOTIFY
, sent
|id
, 0, 0, 0 },
5182 list
= create_listview_control(LVS_REPORT
);
5183 ok(list
!= NULL
, "failed to create listview window\n");
5185 memset(&col
, 0, sizeof(col
));
5186 col
.mask
= LVCF_WIDTH
| LVCF_TEXT
;
5188 col
.pszText
= textA
;
5189 ret
= SendMessageA(list
, LVM_INSERTCOLUMNA
, 0, (LPARAM
)&col
);
5192 header
= (HWND
)SendMessageA(list
, LVM_GETHEADER
, 0, 0);
5193 ok(header
!= 0, "No header\n");
5194 memset(&itemW
, 0, sizeof(itemW
));
5195 itemW
.mask
= HDI_WIDTH
| HDI_ORDER
| HDI_TEXT
;
5196 itemW
.pszText
= buffer
;
5197 itemW
.cchTextMax
= sizeof(buffer
);
5198 ret
= SendMessageW(header
, HDM_GETITEMW
, 0, (LPARAM
)&itemW
);
5201 nmhdr
.hdr
.hwndFrom
= header
;
5202 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(header
, GWLP_ID
);
5205 nmhdr
.pitem
= &itemW
;
5207 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5208 nmhdr
.hdr
.code
= HDN_ITEMCHANGINGW
;
5209 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5210 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGINGA
;
5211 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5212 "header notify, parent", TRUE
);
5214 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGINGA
, "Expected ANSI notification code\n");
5215 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5216 nmhdr
.hdr
.code
= HDN_ITEMCHANGEDW
;
5217 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5218 parent_header_notify_seq
[0].id
= HDN_ITEMCHANGEDA
;
5219 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5220 "header notify, parent", TRUE
);
5222 ok(nmhdr
.hdr
.code
== HDN_ITEMCHANGEDA
, "Expected ANSI notification code\n");
5223 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5225 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5226 nmhdr
.hdr
.code
= HDN_ITEMCLICKW
;
5227 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5228 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_click_seq
,
5229 "header notify, parent", FALSE
);
5230 ok(nmhdr
.hdr
.code
== HDN_ITEMCLICKA
, "Expected ANSI notification code\n");
5231 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5232 nmhdr
.hdr
.code
= HDN_ITEMDBLCLICKW
;
5233 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5234 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5235 "header notify, parent", FALSE
);
5236 ok(nmhdr
.hdr
.code
== HDN_ITEMDBLCLICKW
, "Expected Unicode notification code\n");
5237 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5238 nmhdr
.hdr
.code
= HDN_DIVIDERDBLCLICKW
;
5239 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5240 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_divider_dclick_seq
,
5241 "header notify, parent", TRUE
);
5242 ok(nmhdr
.hdr
.code
== HDN_DIVIDERDBLCLICKA
, "Expected ANSI notification code\n");
5243 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5244 nmhdr
.hdr
.code
= HDN_BEGINTRACKW
;
5245 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5246 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5247 "header notify, parent", FALSE
);
5248 ok(nmhdr
.hdr
.code
== HDN_BEGINTRACKW
, "Expected Unicode notification code\n");
5249 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5250 nmhdr
.hdr
.code
= HDN_ENDTRACKW
;
5251 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5252 parent_header_notify_seq
[0].id
= HDN_ENDTRACKA
;
5253 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5254 "header notify, parent", FALSE
);
5255 ok(nmhdr
.hdr
.code
== HDN_ENDTRACKA
, "Expected ANSI notification code\n");
5256 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5257 nmhdr
.hdr
.code
= HDN_TRACKW
;
5258 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5259 parent_header_notify_seq
[0].id
= HDN_TRACKA
;
5260 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5261 "header notify, parent", FALSE
);
5262 ok(nmhdr
.hdr
.code
== HDN_TRACKA
, "Expected ANSI notification code\n");
5263 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5264 nmhdr
.hdr
.code
= HDN_BEGINDRAG
;
5265 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5266 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5267 "header notify, parent", FALSE
);
5268 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5269 nmhdr
.hdr
.code
= HDN_ENDDRAG
;
5270 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5271 parent_header_notify_seq
[0].id
= HDN_ENDDRAG
;
5272 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5273 "header notify, parent", FALSE
);
5274 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5275 nmhdr
.hdr
.code
= HDN_FILTERCHANGE
;
5276 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5277 parent_header_notify_seq
[0].id
= HDN_FILTERCHANGE
;
5278 parent_header_notify_seq
[0].flags
|= optional
; /* NT4 does not send this message */
5279 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_header_notify_seq
,
5280 "header notify, parent", FALSE
);
5281 parent_header_notify_seq
[0].flags
&= ~optional
;
5282 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5283 nmhdr
.hdr
.code
= HDN_BEGINFILTEREDIT
;
5284 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5285 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5286 "header notify, parent", FALSE
);
5287 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5288 nmhdr
.hdr
.code
= HDN_ENDFILTEREDIT
;
5289 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5290 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5291 "header notify, parent", FALSE
);
5292 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5293 nmhdr
.hdr
.code
= HDN_ITEMSTATEICONCLICK
;
5294 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5295 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5296 "header notify, parent", FALSE
);
5297 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5298 nmhdr
.hdr
.code
= HDN_ITEMKEYDOWN
;
5299 ret
= SendMessageW(list
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
5300 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
5301 "header notify, parent", FALSE
);
5303 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5305 DestroyWindow(list
);
5308 static void test_createdragimage(void)
5314 list
= create_listview_control(LVS_ICON
);
5315 ok(list
!= NULL
, "failed to create listview window\n");
5317 insert_item(list
, 0);
5320 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, 0);
5321 ok(himl
== NULL
, "got %p\n", himl
);
5323 himl
= (HIMAGELIST
)SendMessageA(list
, LVM_CREATEDRAGIMAGE
, 0, (LPARAM
)&pt
);
5324 ok(himl
!= NULL
, "got %p\n", himl
);
5325 ImageList_Destroy(himl
);
5327 DestroyWindow(list
);
5330 static void test_dispinfo(void)
5332 static const char testA
[] = "TEST";
5338 hwnd
= create_listview_control(LVS_ICON
);
5339 ok(hwnd
!= NULL
, "failed to create listview window\n");
5341 insert_item(hwnd
, 0);
5343 memset(&item
, 0, sizeof(item
));
5344 item
.pszText
= LPSTR_TEXTCALLBACKA
;
5345 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5348 g_disp_A_to_W
= TRUE
;
5349 item
.pszText
= (char*)buff
;
5350 item
.cchTextMax
= sizeof(buff
)/sizeof(WCHAR
);
5351 ret
= SendMessageA(hwnd
, LVM_GETITEMTEXTA
, 0, (LPARAM
)&item
);
5352 ok(ret
== sizeof(testA
)-1, "got %d, expected 4\n", ret
);
5353 g_disp_A_to_W
= FALSE
;
5355 ok(memcmp(item
.pszText
, testA
, sizeof(testA
)) == 0,
5356 "got %s, expected %s\n", item
.pszText
, testA
);
5358 DestroyWindow(hwnd
);
5361 static void test_LVM_SETITEMTEXT(void)
5363 static char testA
[] = "TEST";
5368 hwnd
= create_listview_control(LVS_ICON
);
5369 ok(hwnd
!= NULL
, "failed to create listview window\n");
5371 insert_item(hwnd
, 0);
5373 /* null item pointer */
5374 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, 0);
5377 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTW
, 0, 0);
5380 /* index out of bounds */
5381 item
.pszText
= testA
;
5382 item
.cchTextMax
= 0; /* ignored */
5385 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 1, (LPARAM
)&item
);
5388 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, -1, (LPARAM
)&item
);
5391 ret
= SendMessageA(hwnd
, LVM_SETITEMTEXTA
, 0, (LPARAM
)&item
);
5394 DestroyWindow(hwnd
);
5397 static void test_imagelists(void)
5400 HIMAGELIST himl1
, himl2
, himl3
;
5403 himl1
= ImageList_Create(40, 40, 0, 4, 4);
5404 himl2
= ImageList_Create(40, 40, 0, 4, 4);
5405 himl3
= ImageList_Create(40, 40, 0, 4, 4);
5406 ok(himl1
!= NULL
, "Failed to create imagelist\n");
5407 ok(himl2
!= NULL
, "Failed to create imagelist\n");
5408 ok(himl3
!= NULL
, "Failed to create imagelist\n");
5410 hwnd
= create_listview_control(LVS_REPORT
| LVS_SHAREIMAGELISTS
);
5411 header
= subclass_header(hwnd
);
5413 ok(header
!= NULL
, "Expected header\n");
5414 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5415 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5417 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5419 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5420 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5421 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5422 "set normal image list", FALSE
);
5424 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5426 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5427 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5428 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5429 "set state image list", TRUE
);
5431 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5432 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5434 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5436 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5437 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5438 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_header_set_imagelist
,
5439 "set small image list", FALSE
);
5441 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5442 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5443 DestroyWindow(hwnd
);
5445 hwnd
= create_listview_control(WS_VISIBLE
| LVS_ICON
);
5447 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5449 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)himl1
);
5450 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5451 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5452 "set normal image list", FALSE
);
5454 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5456 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_STATE
, (LPARAM
)himl2
);
5457 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5458 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5459 "set state image list", FALSE
);
5461 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5463 ret
= SendMessageW(hwnd
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)himl3
);
5464 ok(ret
== 0, "Expected no imagelist, got %p\n", (HIMAGELIST
)ret
);
5465 ok_sequence(sequences
, LISTVIEW_SEQ_INDEX
, listview_set_imagelist
,
5466 "set small image list", FALSE
);
5468 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5469 ok(header
== NULL
, "Expected no header, got %p\n", header
);
5471 SetWindowLongPtrA(hwnd
, GWL_STYLE
, GetWindowLongPtrA(hwnd
, GWL_STYLE
) | LVS_REPORT
);
5473 header
= (HWND
)SendMessageA(hwnd
, LVM_GETHEADER
, 0, 0);
5474 ok(header
!= NULL
, "Expected header, got NULL\n");
5476 ret
= SendMessageA(header
, HDM_GETIMAGELIST
, 0, 0);
5477 ok((HIMAGELIST
)ret
== himl3
, "Expected imagelist %p, got %p\n", himl3
, (HIMAGELIST
)ret
);
5479 DestroyWindow(hwnd
);
5482 static void test_deleteitem(void)
5489 hwnd
= create_listview_control(LVS_REPORT
);
5491 insert_item(hwnd
, 0);
5492 insert_item(hwnd
, 0);
5493 insert_item(hwnd
, 0);
5494 insert_item(hwnd
, 0);
5495 insert_item(hwnd
, 0);
5497 g_focus_test_LVN_DELETEITEM
= TRUE
;
5499 /* delete focused item (not the last index) */
5500 item
.stateMask
= LVIS_FOCUSED
;
5501 item
.state
= LVIS_FOCUSED
;
5502 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 2, (LPARAM
)&item
);
5503 ok(ret
== TRUE
, "got %d\n", ret
);
5504 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 2, 0);
5505 ok(ret
== TRUE
, "got %d\n", ret
);
5506 /* next item gets focus */
5507 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5508 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5510 /* focus last item and delete it */
5511 item
.stateMask
= LVIS_FOCUSED
;
5512 item
.state
= LVIS_FOCUSED
;
5513 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 3, (LPARAM
)&item
);
5514 ok(ret
== TRUE
, "got %d\n", ret
);
5515 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 3, 0);
5516 ok(ret
== TRUE
, "got %d\n", ret
);
5517 /* new last item gets focus */
5518 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 2, LVIS_FOCUSED
);
5519 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5521 /* focus first item and delete it */
5522 item
.stateMask
= LVIS_FOCUSED
;
5523 item
.state
= LVIS_FOCUSED
;
5524 ret
= SendMessageA(hwnd
, LVM_SETITEMSTATE
, 0, (LPARAM
)&item
);
5525 ok(ret
== TRUE
, "got %d\n", ret
);
5526 ret
= SendMessageA(hwnd
, LVM_DELETEITEM
, 0, 0);
5527 ok(ret
== TRUE
, "got %d\n", ret
);
5528 /* new first item gets focus */
5529 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5530 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5532 g_focus_test_LVN_DELETEITEM
= FALSE
;
5534 DestroyWindow(hwnd
);
5537 static void test_insertitem(void)
5544 hwnd
= create_listview_control(LVS_REPORT
);
5546 /* insert item 0 focused */
5547 item
.mask
= LVIF_STATE
;
5548 item
.state
= LVIS_FOCUSED
;
5549 item
.stateMask
= LVIS_FOCUSED
;
5552 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5553 ok(ret
== 0, "got %d\n", ret
);
5555 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 0, LVIS_FOCUSED
);
5556 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5558 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5560 /* insert item 1, focus shift */
5561 item
.mask
= LVIF_STATE
;
5562 item
.state
= LVIS_FOCUSED
;
5563 item
.stateMask
= LVIS_FOCUSED
;
5566 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5567 ok(ret
== 1, "got %d\n", ret
);
5569 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_insert_focused_seq
, "insert focused", TRUE
);
5571 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5572 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5574 /* insert item 2, no focus shift */
5575 item
.mask
= LVIF_STATE
;
5577 item
.stateMask
= LVIS_FOCUSED
;
5580 ret
= SendMessageA(hwnd
, LVM_INSERTITEMA
, 0, (LPARAM
)&item
);
5581 ok(ret
== 2, "got %d\n", ret
);
5583 state
= SendMessageA(hwnd
, LVM_GETITEMSTATE
, 1, LVIS_FOCUSED
);
5584 ok(state
== LVIS_FOCUSED
, "got %x\n", state
);
5586 DestroyWindow(hwnd
);
5589 START_TEST(listview
)
5592 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
5594 ULONG_PTR ctx_cookie
;
5597 hComctl32
= GetModuleHandleA("comctl32.dll");
5598 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
5599 if (pInitCommonControlsEx
)
5601 INITCOMMONCONTROLSEX iccex
;
5602 iccex
.dwSize
= sizeof(iccex
);
5603 iccex
.dwICC
= ICC_LISTVIEW_CLASSES
;
5604 pInitCommonControlsEx(&iccex
);
5607 InitCommonControls();
5609 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
5611 hwndparent
= create_parent_window(FALSE
);
5612 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
5614 g_is_below_5
= is_below_comctl_5();
5616 test_header_notification();
5617 test_header_notification2();
5624 test_icon_spacing();
5627 test_item_position();
5632 test_subitem_rect();
5636 test_nosortheader();
5640 test_getitemposition();
5641 test_columnscreation();
5643 test_notifyformat();
5645 test_getitemspacing();
5646 test_getcolumnwidth();
5647 test_approximate_viewrect();
5650 test_destroynotify();
5651 test_createdragimage();
5653 test_LVM_SETITEMTEXT();
5658 if (!load_v6_module(&ctx_cookie
, &hCtx
))
5660 DestroyWindow(hwndparent
);
5664 /* comctl32 version 6 tests start here */
5665 test_get_set_view();
5666 test_canceleditlabel();
5668 test_scrollnotify();
5669 test_LVS_EX_TRANSPARENTBKGND();
5670 test_LVS_EX_HEADERINALLVIEWS();
5675 unload_v6_module(ctx_cookie
, hCtx
);
5677 DestroyWindow(hwndparent
);