comctl32/listview: Call default handler for WM_PAINT disabled by WM_SETREDRAW.
[wine/multimedia.git] / dlls / comctl32 / tests / listview.c
blob244f3a53536817a48da7ac0ffeff58b86fc33fd1
1 /*
2 * ListView tests
4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdio.h>
23 #include <windows.h>
24 #include <commctrl.h>
26 #include "wine/test.h"
27 #include "v6util.h"
28 #include "msg.h"
30 #define PARENT_SEQ_INDEX 0
31 #define PARENT_FULL_SEQ_INDEX 1
32 #define LISTVIEW_SEQ_INDEX 2
33 #define EDITBOX_SEQ_INDEX 3
34 #define NUM_MSG_SEQUENCES 4
36 #define LISTVIEW_ID 0
37 #define HEADER_ID 1
39 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
40 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
41 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
43 static const WCHAR testparentclassW[] =
44 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
46 HWND hwndparent, hwndparentW;
47 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
48 BOOL blockEdit;
49 /* dumps LVN_ITEMCHANGED message data */
50 static BOOL g_dump_itemchanged;
51 /* format reported to control:
52 -1 falls to defproc, anything else returned */
53 INT notifyFormat;
54 /* indicates we're running < 5.80 version */
55 BOOL g_is_below_5;
57 static HWND subclass_editbox(HWND hwndListview);
59 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
61 static const struct message create_ownerdrawfixed_parent_seq[] = {
62 { WM_NOTIFYFORMAT, sent },
63 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
64 { WM_MEASUREITEM, sent },
65 { WM_PARENTNOTIFY, sent },
66 { 0 }
69 static const struct message redraw_listview_seq[] = {
70 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
71 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
72 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
73 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
74 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
75 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
76 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
77 { 0 }
80 static const struct message listview_icon_spacing_seq[] = {
81 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
82 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
83 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
84 { 0 }
87 static const struct message listview_color_seq[] = {
88 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
89 { LVM_GETBKCOLOR, sent },
90 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
91 { LVM_GETTEXTCOLOR, sent },
92 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
93 { LVM_GETTEXTBKCOLOR, sent },
95 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
96 { LVM_GETBKCOLOR, sent },
97 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
98 { LVM_GETTEXTCOLOR, sent },
99 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
100 { LVM_GETTEXTBKCOLOR, sent },
102 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
103 { LVM_GETBKCOLOR, sent },
104 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
105 { LVM_GETTEXTCOLOR, sent },
106 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
107 { LVM_GETTEXTBKCOLOR, sent },
109 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
110 { LVM_GETBKCOLOR, sent },
111 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
112 { LVM_GETTEXTCOLOR, sent },
113 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
114 { LVM_GETTEXTBKCOLOR, sent },
115 { 0 }
118 static const struct message listview_item_count_seq[] = {
119 { LVM_GETITEMCOUNT, sent },
120 { LVM_INSERTITEM, sent },
121 { LVM_INSERTITEM, sent },
122 { LVM_INSERTITEM, sent },
123 { LVM_GETITEMCOUNT, sent },
124 { LVM_DELETEITEM, sent|wparam, 2 },
125 { WM_NCPAINT, sent|optional },
126 { WM_ERASEBKGND, sent|optional },
127 { LVM_GETITEMCOUNT, sent },
128 { LVM_DELETEALLITEMS, sent },
129 { LVM_GETITEMCOUNT, sent },
130 { LVM_INSERTITEM, sent },
131 { LVM_INSERTITEM, sent },
132 { LVM_GETITEMCOUNT, sent },
133 { LVM_INSERTITEM, sent },
134 { LVM_GETITEMCOUNT, sent },
135 { 0 }
138 static const struct message listview_itempos_seq[] = {
139 { LVM_INSERTITEM, sent },
140 { LVM_INSERTITEM, sent },
141 { LVM_INSERTITEM, sent },
142 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
143 { WM_NCPAINT, sent|optional },
144 { WM_ERASEBKGND, sent|optional },
145 { LVM_GETITEMPOSITION, sent|wparam, 1 },
146 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
147 { LVM_GETITEMPOSITION, sent|wparam, 2 },
148 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
149 { LVM_GETITEMPOSITION, sent|wparam, 0 },
150 { 0 }
153 static const struct message listview_ownerdata_switchto_seq[] = {
154 { WM_STYLECHANGING, sent },
155 { WM_STYLECHANGED, sent },
156 { 0 }
159 static const struct message listview_getorderarray_seq[] = {
160 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
161 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
162 { 0 }
165 static const struct message empty_seq[] = {
166 { 0 }
169 static const struct message forward_erasebkgnd_parent_seq[] = {
170 { WM_ERASEBKGND, sent },
171 { 0 }
174 static const struct message ownderdata_select_focus_parent_seq[] = {
175 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
176 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
177 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
178 { 0 }
181 static const struct message ownerdata_setstate_all_parent_seq[] = {
182 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
183 { 0 }
186 static const struct message ownerdata_defocus_all_parent_seq[] = {
187 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
188 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
189 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
190 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
191 { 0 }
194 static const struct message ownerdata_deselect_all_parent_seq[] = {
195 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
196 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
197 { 0 }
200 static const struct message select_all_parent_seq[] = {
201 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
202 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
204 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
205 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
207 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
208 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
210 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
211 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
213 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
214 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
215 { 0 }
218 static const struct message textcallback_set_again_parent_seq[] = {
219 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
220 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
221 { 0 }
224 static const struct message single_getdispinfo_parent_seq[] = {
225 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
226 { 0 }
229 static const struct message getitemposition_seq1[] = {
230 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
231 { 0 }
234 static const struct message getitemposition_seq2[] = {
235 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
236 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
237 { 0 }
240 static const struct message editbox_create_pos[] = {
241 /* sequence sent after LVN_BEGINLABELEDIT */
242 /* next two are 4.7x specific */
243 { WM_WINDOWPOSCHANGING, sent },
244 { WM_WINDOWPOSCHANGED, sent|optional },
246 { WM_WINDOWPOSCHANGING, sent|optional },
247 { WM_NCCALCSIZE, sent },
248 { WM_WINDOWPOSCHANGED, sent },
249 { WM_MOVE, sent|defwinproc },
250 { WM_SIZE, sent|defwinproc },
251 /* the rest is todo, skipped in 4.7x */
252 { WM_WINDOWPOSCHANGING, sent|optional },
253 { WM_WINDOWPOSCHANGED, sent|optional },
254 { 0 }
257 static const struct message scroll_parent_seq[] = {
258 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
259 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
260 { 0 }
263 static const struct message setredraw_seq[] = {
264 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
265 { 0 }
268 struct subclass_info
270 WNDPROC oldproc;
273 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
275 static LONG defwndproc_counter = 0;
276 LRESULT ret;
277 struct message msg;
279 msg.message = message;
280 msg.flags = sent|wparam|lparam;
281 if (defwndproc_counter) msg.flags |= defwinproc;
282 msg.wParam = wParam;
283 msg.lParam = lParam;
284 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
286 /* log system messages, except for painting */
287 if (message < WM_USER &&
288 message != WM_PAINT &&
289 message != WM_ERASEBKGND &&
290 message != WM_NCPAINT &&
291 message != WM_NCHITTEST &&
292 message != WM_GETTEXT &&
293 message != WM_GETICON &&
294 message != WM_DEVICECHANGE)
296 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
298 add_message(sequences, PARENT_SEQ_INDEX, &msg);
300 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
302 switch (message)
304 case WM_NOTIFY:
306 switch (((NMHDR*)lParam)->code)
308 case LVN_BEGINLABELEDIT:
309 /* subclass edit box */
310 if (!blockEdit)
311 subclass_editbox(((NMHDR*)lParam)->hwndFrom);
313 return blockEdit;
315 case LVN_ENDLABELEDIT:
316 /* always accept new item text */
317 return TRUE;
318 case LVN_BEGINSCROLL:
319 case LVN_ENDSCROLL:
321 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
323 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
324 "BEGIN" : "END", pScroll->dx, pScroll->dy);
326 break;
327 case LVN_ITEMCHANGED:
328 if (g_dump_itemchanged)
330 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
331 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
332 nmlv->iItem, nmlv->uNewState, nmlv->uOldState, nmlv->uChanged);
334 break;
336 break;
338 case WM_NOTIFYFORMAT:
340 /* force to return format */
341 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
342 break;
346 defwndproc_counter++;
347 ret = DefWindowProcA(hwnd, message, wParam, lParam);
348 defwndproc_counter--;
350 return ret;
353 static BOOL register_parent_wnd_class(BOOL Unicode)
355 WNDCLASSA clsA;
356 WNDCLASSW clsW;
358 if (Unicode)
360 clsW.style = 0;
361 clsW.lpfnWndProc = parent_wnd_proc;
362 clsW.cbClsExtra = 0;
363 clsW.cbWndExtra = 0;
364 clsW.hInstance = GetModuleHandleW(NULL);
365 clsW.hIcon = 0;
366 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
367 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
368 clsW.lpszMenuName = NULL;
369 clsW.lpszClassName = testparentclassW;
371 else
373 clsA.style = 0;
374 clsA.lpfnWndProc = parent_wnd_proc;
375 clsA.cbClsExtra = 0;
376 clsA.cbWndExtra = 0;
377 clsA.hInstance = GetModuleHandleA(NULL);
378 clsA.hIcon = 0;
379 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
380 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
381 clsA.lpszMenuName = NULL;
382 clsA.lpszClassName = "Listview test parent class";
385 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
388 static HWND create_parent_window(BOOL Unicode)
390 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W'};
391 HWND hwnd;
393 if (!register_parent_wnd_class(Unicode))
394 return NULL;
396 blockEdit = FALSE;
397 notifyFormat = -1;
399 if (Unicode)
400 hwnd = CreateWindowExW(0, testparentclassW, nameW,
401 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
402 WS_MAXIMIZEBOX | WS_VISIBLE,
403 0, 0, 100, 100,
404 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
405 else
406 hwnd = CreateWindowExA(0, "Listview test parent class",
407 "Listview test parent window",
408 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
409 WS_MAXIMIZEBOX | WS_VISIBLE,
410 0, 0, 100, 100,
411 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
412 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
413 return hwnd;
416 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
418 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
419 static LONG defwndproc_counter = 0;
420 LRESULT ret;
421 struct message msg;
423 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
425 /* some debug output for style changing */
426 if ((message == WM_STYLECHANGING ||
427 message == WM_STYLECHANGED) && lParam)
429 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
430 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
433 msg.message = message;
434 msg.flags = sent|wparam|lparam;
435 if (defwndproc_counter) msg.flags |= defwinproc;
436 msg.wParam = wParam;
437 msg.lParam = lParam;
438 msg.id = LISTVIEW_ID;
439 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
441 defwndproc_counter++;
442 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
443 defwndproc_counter--;
444 return ret;
447 static HWND create_listview_control(DWORD style)
449 struct subclass_info *info;
450 HWND hwnd;
451 RECT rect;
453 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
454 if (!info)
455 return NULL;
457 GetClientRect(hwndparent, &rect);
458 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
459 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
460 0, 0, rect.right, rect.bottom,
461 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
462 ok(hwnd != NULL, "gle=%d\n", GetLastError());
464 if (!hwnd)
466 HeapFree(GetProcessHeap(), 0, info);
467 return NULL;
470 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
471 (LONG_PTR)listview_subclass_proc);
472 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
474 return hwnd;
477 /* unicode listview window with specified parent */
478 static HWND create_listview_controlW(DWORD style, HWND parent)
480 struct subclass_info *info;
481 HWND hwnd;
482 RECT rect;
483 static const WCHAR nameW[] = {'f','o','o',0};
485 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
486 if (!info)
487 return NULL;
489 GetClientRect(parent, &rect);
490 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
491 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
492 0, 0, rect.right, rect.bottom,
493 parent, NULL, GetModuleHandleW(NULL), NULL);
494 ok(hwnd != NULL, "gle=%d\n", GetLastError());
496 if (!hwnd)
498 HeapFree(GetProcessHeap(), 0, info);
499 return NULL;
502 info->oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
503 (LONG_PTR)listview_subclass_proc);
504 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)info);
506 return hwnd;
509 static HWND create_custom_listview_control(DWORD style)
511 struct subclass_info *info;
512 HWND hwnd;
513 RECT rect;
515 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
516 if (!info)
517 return NULL;
519 GetClientRect(hwndparent, &rect);
520 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
521 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
522 0, 0, rect.right, rect.bottom,
523 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
524 ok(hwnd != NULL, "gle=%d\n", GetLastError());
526 if (!hwnd)
528 HeapFree(GetProcessHeap(), 0, info);
529 return NULL;
532 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
533 (LONG_PTR)listview_subclass_proc);
534 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
536 return hwnd;
539 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
541 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
542 static LONG defwndproc_counter = 0;
543 LRESULT ret;
544 struct message msg;
546 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
548 msg.message = message;
549 msg.flags = sent|wparam|lparam;
550 if (defwndproc_counter) msg.flags |= defwinproc;
551 msg.wParam = wParam;
552 msg.lParam = lParam;
553 msg.id = HEADER_ID;
554 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
556 defwndproc_counter++;
557 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
558 defwndproc_counter--;
559 return ret;
562 static HWND subclass_header(HWND hwndListview)
564 struct subclass_info *info;
565 HWND hwnd;
567 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
568 if (!info)
569 return NULL;
571 hwnd = ListView_GetHeader(hwndListview);
572 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
573 (LONG_PTR)header_subclass_proc);
574 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
576 return hwnd;
579 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
581 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
582 static LONG defwndproc_counter = 0;
583 LRESULT ret;
584 struct message msg;
586 msg.message = message;
587 msg.flags = sent|wparam|lparam;
588 if (defwndproc_counter) msg.flags |= defwinproc;
589 msg.wParam = wParam;
590 msg.lParam = lParam;
592 /* all we need is sizing */
593 if (message == WM_WINDOWPOSCHANGING ||
594 message == WM_NCCALCSIZE ||
595 message == WM_WINDOWPOSCHANGED ||
596 message == WM_MOVE ||
597 message == WM_SIZE)
599 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
602 defwndproc_counter++;
603 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
604 defwndproc_counter--;
605 return ret;
608 static HWND subclass_editbox(HWND hwndListview)
610 struct subclass_info *info;
611 HWND hwnd;
613 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
614 if (!info)
615 return NULL;
617 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
618 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
619 (LONG_PTR)editbox_subclass_proc);
620 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
622 return hwnd;
625 /* Performs a single LVM_HITTEST test */
626 static void test_lvm_hittest(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
627 BOOL todo_item, BOOL todo_flags, int line)
629 LVHITTESTINFO lpht;
630 DWORD ret;
632 lpht.pt.x = x;
633 lpht.pt.y = y;
634 lpht.iSubItem = 10;
636 trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
637 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
639 if (todo_item)
641 todo_wine
643 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
644 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
645 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
648 else
650 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
651 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
652 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
655 if (todo_flags)
657 todo_wine
658 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
660 else if (broken_flags)
661 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
662 "Expected flags %x, got %x\n", flags, lpht.flags);
663 else
664 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
667 /* Performs a single LVM_SUBITEMHITTEST test */
668 static void test_lvm_subitemhittest(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
669 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
671 LVHITTESTINFO lpht;
672 DWORD ret;
674 lpht.pt.x = x;
675 lpht.pt.y = y;
677 trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
678 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
680 if (todo_item)
682 todo_wine
684 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
685 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
688 else
690 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
691 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
694 if (todo_subitem)
696 todo_wine
697 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
699 else
700 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
702 if (todo_flags)
704 todo_wine
705 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
707 else
708 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
711 static void test_images(void)
713 HWND hwnd;
714 DWORD r;
715 LVITEM item;
716 HIMAGELIST himl;
717 HBITMAP hbmp;
718 RECT r1, r2;
719 static CHAR hello[] = "hello";
721 himl = ImageList_Create(40, 40, 0, 4, 4);
722 ok(himl != NULL, "failed to create imagelist\n");
724 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
725 ok(hbmp != NULL, "failed to create bitmap\n");
727 r = ImageList_Add(himl, hbmp, 0);
728 ok(r == 0, "should be zero\n");
730 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
731 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
732 ok(hwnd != NULL, "failed to create listview window\n");
734 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
735 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
737 ok(r == 0, "should return zero\n");
739 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
740 ok(r == 0, "should return zero\n");
742 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
743 /* returns dimensions */
745 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
746 ok(r == 0, "should be zero items\n");
748 item.mask = LVIF_IMAGE | LVIF_TEXT;
749 item.iItem = 0;
750 item.iSubItem = 1;
751 item.iImage = 0;
752 item.pszText = 0;
753 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
754 ok(r == -1, "should fail\n");
756 item.iSubItem = 0;
757 item.pszText = hello;
758 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
759 ok(r == 0, "should not fail\n");
761 memset(&r1, 0, sizeof r1);
762 r1.left = LVIR_ICON;
763 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
765 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
766 ok(r == TRUE, "should not fail\n");
768 item.iSubItem = 0;
769 item.pszText = hello;
770 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
771 ok(r == 0, "should not fail\n");
773 memset(&r2, 0, sizeof r2);
774 r2.left = LVIR_ICON;
775 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
777 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
779 DestroyWindow(hwnd);
782 static void test_checkboxes(void)
784 HWND hwnd;
785 LVITEMA item;
786 DWORD r;
787 static CHAR text[] = "Text",
788 text2[] = "Text2",
789 text3[] = "Text3";
791 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
792 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
793 ok(hwnd != NULL, "failed to create listview window\n");
795 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
796 item.mask = LVIF_TEXT | LVIF_STATE;
797 item.stateMask = 0xffff;
798 item.state = 0xfccc;
799 item.iItem = 0;
800 item.iSubItem = 0;
801 item.pszText = text;
802 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
803 ok(r == 0, "ret %d\n", r);
805 item.iItem = 0;
806 item.mask = LVIF_STATE;
807 item.stateMask = 0xffff;
808 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
809 ok(item.state == 0xfccc, "state %x\n", item.state);
811 /* Don't set LVIF_STATE */
812 item.mask = LVIF_TEXT;
813 item.stateMask = 0xffff;
814 item.state = 0xfccc;
815 item.iItem = 1;
816 item.iSubItem = 0;
817 item.pszText = text;
818 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
819 ok(r == 1, "ret %d\n", r);
821 item.iItem = 1;
822 item.mask = LVIF_STATE;
823 item.stateMask = 0xffff;
824 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
825 ok(item.state == 0, "state %x\n", item.state);
827 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
828 ok(r == 0, "should return zero\n");
830 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
831 item.iItem = 0;
832 item.mask = LVIF_STATE;
833 item.stateMask = 0xffff;
834 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
835 ok(item.state == 0x1ccc, "state %x\n", item.state);
837 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
838 item.iItem = 2;
839 item.mask = LVIF_TEXT;
840 item.state = 0;
841 item.pszText = text2;
842 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
843 ok(r == 2, "ret %d\n", r);
845 item.iItem = 2;
846 item.mask = LVIF_STATE;
847 item.stateMask = 0xffff;
848 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
849 ok(item.state == 0x1000, "state %x\n", item.state);
851 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
852 item.iItem = 3;
853 item.mask = LVIF_TEXT | LVIF_STATE;
854 item.stateMask = 0xffff;
855 item.state = 0x2aaa;
856 item.pszText = text3;
857 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
858 ok(r == 3, "ret %d\n", r);
860 item.iItem = 3;
861 item.mask = LVIF_STATE;
862 item.stateMask = 0xffff;
863 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
864 ok(item.state == 0x1aaa, "state %x\n", item.state);
866 /* Set an item's state to checked */
867 item.iItem = 3;
868 item.mask = LVIF_STATE;
869 item.stateMask = 0xf000;
870 item.state = 0x2000;
871 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
873 item.iItem = 3;
874 item.mask = LVIF_STATE;
875 item.stateMask = 0xffff;
876 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
877 ok(item.state == 0x2aaa, "state %x\n", item.state);
879 /* Check that only the bits we asked for are returned,
880 * and that all the others are set to zero
882 item.iItem = 3;
883 item.mask = LVIF_STATE;
884 item.stateMask = 0xf000;
885 item.state = 0xffff;
886 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
887 ok(item.state == 0x2000, "state %x\n", item.state);
889 /* Set the style again and check that doesn't change an item's state */
890 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
891 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
893 item.iItem = 3;
894 item.mask = LVIF_STATE;
895 item.stateMask = 0xffff;
896 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
897 ok(item.state == 0x2aaa, "state %x\n", item.state);
899 /* Unsetting the checkbox extended style doesn't change an item's state */
900 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
901 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
903 item.iItem = 3;
904 item.mask = LVIF_STATE;
905 item.stateMask = 0xffff;
906 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
907 ok(item.state == 0x2aaa, "state %x\n", item.state);
909 /* Now setting the style again will change an item's state */
910 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
911 ok(r == 0, "ret %x\n", r);
913 item.iItem = 3;
914 item.mask = LVIF_STATE;
915 item.stateMask = 0xffff;
916 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
917 ok(item.state == 0x1aaa, "state %x\n", item.state);
919 /* Toggle checkbox tests (bug 9934) */
920 memset (&item, 0xcc, sizeof(item));
921 item.mask = LVIF_STATE;
922 item.iItem = 3;
923 item.iSubItem = 0;
924 item.state = LVIS_FOCUSED;
925 item.stateMask = LVIS_FOCUSED;
926 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
927 expect(1, r);
929 item.iItem = 3;
930 item.mask = LVIF_STATE;
931 item.stateMask = 0xffff;
932 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
933 ok(item.state == 0x1aab, "state %x\n", item.state);
935 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
936 expect(0, r);
937 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
938 expect(0, r);
940 item.iItem = 3;
941 item.mask = LVIF_STATE;
942 item.stateMask = 0xffff;
943 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
944 ok(item.state == 0x2aab, "state %x\n", item.state);
946 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
947 expect(0, r);
948 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
949 expect(0, r);
951 item.iItem = 3;
952 item.mask = LVIF_STATE;
953 item.stateMask = 0xffff;
954 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
955 ok(item.state == 0x1aab, "state %x\n", item.state);
957 DestroyWindow(hwnd);
960 static void insert_column(HWND hwnd, int idx)
962 LVCOLUMN column;
963 DWORD rc;
965 memset(&column, 0xcc, sizeof(column));
966 column.mask = LVCF_SUBITEM;
967 column.iSubItem = idx;
969 rc = ListView_InsertColumn(hwnd, idx, &column);
970 expect(idx, rc);
973 static void insert_item(HWND hwnd, int idx)
975 static CHAR text[] = "foo";
977 LVITEMA item;
978 DWORD rc;
980 memset(&item, 0xcc, sizeof (item));
981 item.mask = LVIF_TEXT;
982 item.iItem = idx;
983 item.iSubItem = 0;
984 item.pszText = text;
986 rc = ListView_InsertItem(hwnd, &item);
987 expect(idx, rc);
990 static void test_items(void)
992 const LPARAM lparamTest = 0x42;
993 HWND hwnd;
994 LVITEMA item;
995 DWORD r;
996 static CHAR text[] = "Text";
998 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
999 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1000 ok(hwnd != NULL, "failed to create listview window\n");
1003 * Test setting/getting item params
1006 /* Set up two columns */
1007 insert_column(hwnd, 0);
1008 insert_column(hwnd, 1);
1010 /* LVIS_SELECTED with zero stateMask */
1011 /* set */
1012 memset (&item, 0, sizeof (item));
1013 item.mask = LVIF_STATE;
1014 item.state = LVIS_SELECTED;
1015 item.stateMask = 0;
1016 item.iItem = 0;
1017 item.iSubItem = 0;
1018 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1019 ok(r == 0, "ret %d\n", r);
1020 /* get */
1021 memset (&item, 0xcc, sizeof (item));
1022 item.mask = LVIF_STATE;
1023 item.stateMask = LVIS_SELECTED;
1024 item.state = 0;
1025 item.iItem = 0;
1026 item.iSubItem = 0;
1027 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1028 ok(r != 0, "ret %d\n", r);
1029 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1030 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1032 /* LVIS_SELECTED with zero stateMask */
1033 /* set */
1034 memset (&item, 0, sizeof (item));
1035 item.mask = LVIF_STATE;
1036 item.state = LVIS_FOCUSED;
1037 item.stateMask = 0;
1038 item.iItem = 0;
1039 item.iSubItem = 0;
1040 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1041 ok(r == 0, "ret %d\n", r);
1042 /* get */
1043 memset (&item, 0xcc, sizeof (item));
1044 item.mask = LVIF_STATE;
1045 item.stateMask = LVIS_FOCUSED;
1046 item.state = 0;
1047 item.iItem = 0;
1048 item.iSubItem = 0;
1049 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1050 ok(r != 0, "ret %d\n", r);
1051 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1052 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1054 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1055 /* set */
1056 memset (&item, 0, sizeof (item));
1057 item.mask = LVIF_STATE;
1058 item.state = LVIS_CUT;
1059 item.stateMask = LVIS_FOCUSED;
1060 item.iItem = 0;
1061 item.iSubItem = 0;
1062 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1063 ok(r == 0, "ret %d\n", r);
1064 /* get */
1065 memset (&item, 0xcc, sizeof (item));
1066 item.mask = LVIF_STATE;
1067 item.stateMask = LVIS_CUT;
1068 item.state = 0;
1069 item.iItem = 0;
1070 item.iSubItem = 0;
1071 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1072 ok(r != 0, "ret %d\n", r);
1073 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1074 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1076 /* Insert an item with just a param */
1077 memset (&item, 0xcc, sizeof (item));
1078 item.mask = LVIF_PARAM;
1079 item.iItem = 0;
1080 item.iSubItem = 0;
1081 item.lParam = lparamTest;
1082 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1083 ok(r == 0, "ret %d\n", r);
1085 /* Test getting of the param */
1086 memset (&item, 0xcc, sizeof (item));
1087 item.mask = LVIF_PARAM;
1088 item.iItem = 0;
1089 item.iSubItem = 0;
1090 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1091 ok(r != 0, "ret %d\n", r);
1092 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1094 /* Set up a subitem */
1095 memset (&item, 0xcc, sizeof (item));
1096 item.mask = LVIF_TEXT;
1097 item.iItem = 0;
1098 item.iSubItem = 1;
1099 item.pszText = text;
1100 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1101 ok(r != 0, "ret %d\n", r);
1103 /* Query param from subitem: returns main item param */
1104 memset (&item, 0xcc, sizeof (item));
1105 item.mask = LVIF_PARAM;
1106 item.iItem = 0;
1107 item.iSubItem = 1;
1108 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1109 ok(r != 0, "ret %d\n", r);
1110 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1112 /* Set up param on first subitem: no effect */
1113 memset (&item, 0xcc, sizeof (item));
1114 item.mask = LVIF_PARAM;
1115 item.iItem = 0;
1116 item.iSubItem = 1;
1117 item.lParam = lparamTest+1;
1118 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1119 ok(r == 0, "ret %d\n", r);
1121 /* Query param from subitem again: should still return main item param */
1122 memset (&item, 0xcc, sizeof (item));
1123 item.mask = LVIF_PARAM;
1124 item.iItem = 0;
1125 item.iSubItem = 1;
1126 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1127 ok(r != 0, "ret %d\n", r);
1128 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1130 /**** Some tests of state highlighting ****/
1131 memset (&item, 0xcc, sizeof (item));
1132 item.mask = LVIF_STATE;
1133 item.iItem = 0;
1134 item.iSubItem = 0;
1135 item.state = LVIS_SELECTED;
1136 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1137 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1138 ok(r != 0, "ret %d\n", r);
1139 item.iSubItem = 1;
1140 item.state = LVIS_DROPHILITED;
1141 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1142 ok(r != 0, "ret %d\n", r);
1144 memset (&item, 0xcc, sizeof (item));
1145 item.mask = LVIF_STATE;
1146 item.iItem = 0;
1147 item.iSubItem = 0;
1148 item.stateMask = -1;
1149 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1150 ok(r != 0, "ret %d\n", r);
1151 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1152 item.iSubItem = 1;
1153 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1154 ok(r != 0, "ret %d\n", r);
1155 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1157 /* some notnull but meaningless masks */
1158 memset (&item, 0, sizeof(item));
1159 item.mask = LVIF_NORECOMPUTE;
1160 item.iItem = 0;
1161 item.iSubItem = 0;
1162 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1163 ok(r != 0, "ret %d\n", r);
1164 memset (&item, 0, sizeof(item));
1165 item.mask = LVIF_DI_SETITEM;
1166 item.iItem = 0;
1167 item.iSubItem = 0;
1168 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1169 ok(r != 0, "ret %d\n", r);
1171 /* set text to callback value already having it */
1172 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1173 expect(TRUE, r);
1174 memset (&item, 0, sizeof (item));
1175 item.mask = LVIF_TEXT;
1176 item.pszText = LPSTR_TEXTCALLBACK;
1177 item.iItem = 0;
1178 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1179 ok(r == 0, "ret %d\n", r);
1180 memset (&item, 0, sizeof (item));
1182 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1184 item.pszText = LPSTR_TEXTCALLBACK;
1185 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1186 expect(TRUE, r);
1188 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1189 "check callback text comparison rule", FALSE);
1191 DestroyWindow(hwnd);
1194 static void test_columns(void)
1196 HWND hwnd, hwndheader;
1197 LVCOLUMN column;
1198 DWORD rc;
1199 INT order[2];
1201 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1202 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1203 ok(hwnd != NULL, "failed to create listview window\n");
1205 /* Add a column with no mask */
1206 memset(&column, 0xcc, sizeof(column));
1207 column.mask = 0;
1208 rc = ListView_InsertColumn(hwnd, 0, &column);
1209 ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
1211 /* Check its width */
1212 rc = ListView_GetColumnWidth(hwnd, 0);
1213 ok(rc==10 ||
1214 broken(rc==0), /* win9x */
1215 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1217 DestroyWindow(hwnd);
1219 /* LVM_GETCOLUMNORDERARRAY */
1220 hwnd = create_listview_control(0);
1221 hwndheader = subclass_header(hwnd);
1223 memset(&column, 0, sizeof(column));
1224 column.mask = LVCF_WIDTH;
1225 column.cx = 100;
1226 rc = ListView_InsertColumn(hwnd, 0, &column);
1227 ok(rc == 0, "Inserting column failed with %d\n", rc);
1229 column.cx = 200;
1230 rc = ListView_InsertColumn(hwnd, 1, &column);
1231 ok(rc == 1, "Inserting column failed with %d\n", rc);
1233 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1235 rc = SendMessage(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1236 ok(rc != 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1237 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1238 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1240 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1242 DestroyWindow(hwnd);
1244 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1245 static WNDPROC listviewWndProc;
1246 static HIMAGELIST test_create_imagelist;
1248 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1250 LRESULT ret;
1252 if (uMsg == WM_CREATE)
1254 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1255 lpcs->style |= LVS_REPORT;
1257 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1258 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1259 return ret;
1262 static void test_create(void)
1264 HWND hList;
1265 HWND hHeader;
1266 LONG_PTR ret;
1267 LONG r;
1268 LVCOLUMNA col;
1269 RECT rect;
1270 WNDCLASSEX cls;
1271 cls.cbSize = sizeof(WNDCLASSEX);
1272 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1273 listviewWndProc = cls.lpfnWndProc;
1274 cls.lpfnWndProc = create_test_wndproc;
1275 cls.lpszClassName = "MyListView32";
1276 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1278 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1279 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1280 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1281 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1282 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1283 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1284 DestroyWindow(hList);
1286 /* header isn't created on LVS_ICON and LVS_LIST styles */
1287 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1288 GetModuleHandle(NULL), 0);
1289 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1290 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1291 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1292 /* insert column */
1293 memset(&col, 0, sizeof(LVCOLUMNA));
1294 col.mask = LVCF_WIDTH;
1295 col.cx = 100;
1296 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1297 ok(r == 0, "Expected 0 column's inserted\n");
1298 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1299 ok(IsWindow(hHeader), "Header should be created\n");
1300 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1301 DestroyWindow(hList);
1303 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1304 GetModuleHandle(NULL), 0);
1305 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1306 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1307 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1308 /* insert column */
1309 memset(&col, 0, sizeof(LVCOLUMNA));
1310 col.mask = LVCF_WIDTH;
1311 col.cx = 100;
1312 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1313 ok(r == 0, "Expected 0 column's inserted\n");
1314 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1315 ok(IsWindow(hHeader), "Header should be created\n");
1316 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1317 DestroyWindow(hList);
1319 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1320 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1321 GetModuleHandle(NULL), 0);
1322 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1323 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1324 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1325 ok(IsWindow(hHeader), "Header should be created\n");
1326 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1327 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1328 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1329 ok(IsWindow(hHeader), "Header should be created\n");
1330 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1331 DestroyWindow(hList);
1333 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1334 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1335 GetModuleHandle(NULL), 0);
1336 ret = SetWindowLongPtr(hList, GWL_STYLE,
1337 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1338 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1339 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1340 ok(IsWindow(hHeader), "Header should be created\n");
1341 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1342 ret = SetWindowLongPtr(hList, GWL_STYLE,
1343 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1344 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1345 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1346 ok(IsWindow(hHeader), "Header should be created\n");
1347 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1348 DestroyWindow(hList);
1350 /* LVS_REPORT without WS_VISIBLE */
1351 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1352 GetModuleHandle(NULL), 0);
1353 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1354 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1355 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1356 /* insert column */
1357 memset(&col, 0, sizeof(LVCOLUMNA));
1358 col.mask = LVCF_WIDTH;
1359 col.cx = 100;
1360 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1361 ok(r == 0, "Expected 0 column's inserted\n");
1362 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1363 ok(IsWindow(hHeader), "Header should be created\n");
1364 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1365 DestroyWindow(hList);
1367 /* LVS_REPORT without WS_VISIBLE, try to show it */
1368 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1369 GetModuleHandle(NULL), 0);
1370 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1371 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1372 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1373 ShowWindow(hList, SW_SHOW);
1374 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1375 ok(IsWindow(hHeader), "Header should be created\n");
1376 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1377 DestroyWindow(hList);
1379 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1380 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1381 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1382 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1383 ok(IsWindow(hHeader), "Header should be created\n");
1384 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1385 /* HDS_DRAGDROP set by default */
1386 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1387 DestroyWindow(hList);
1389 /* setting LVS_EX_HEADERDRAGDROP creates header */
1390 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1391 GetModuleHandle(NULL), 0);
1392 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1393 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1394 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1395 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1396 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1397 ok(IsWindow(hHeader) ||
1398 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1399 "Header should be created\n");
1400 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1401 DestroyWindow(hList);
1403 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1404 hList = create_custom_listview_control(0);
1405 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1406 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1407 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1408 DestroyWindow(hList);
1410 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1411 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1412 GetModuleHandle(NULL), 0);
1413 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1414 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1416 rect.left = LVIR_BOUNDS;
1417 rect.top = 1;
1418 rect.right = rect.bottom = -10;
1419 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1420 ok(r != 0, "Expected not-null LRESULT\n");
1422 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1423 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1424 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1426 DestroyWindow(hList);
1428 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1429 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1430 hList = create_listview_control(LVS_OWNERDRAWFIXED);
1431 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1432 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1433 DestroyWindow(hList);
1436 static void test_redraw(void)
1438 HWND hwnd, hwndheader;
1439 HDC hdc;
1440 BOOL res;
1441 DWORD r;
1443 hwnd = create_listview_control(0);
1444 hwndheader = subclass_header(hwnd);
1446 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1448 trace("invalidate & update\n");
1449 InvalidateRect(hwnd, NULL, TRUE);
1450 UpdateWindow(hwnd);
1451 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1453 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1455 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1456 /* 1. Without backbuffer */
1457 res = ListView_SetBkColor(hwnd, CLR_NONE);
1458 expect(TRUE, res);
1460 hdc = GetWindowDC(hwndparent);
1462 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1463 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1464 ok(r != 0, "Expected not zero result\n");
1465 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1466 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1468 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1469 expect(TRUE, res);
1471 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1472 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1473 ok(r != 0, "Expected not zero result\n");
1474 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1475 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1477 /* 2. With backbuffer */
1478 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1479 LVS_EX_DOUBLEBUFFER);
1480 res = ListView_SetBkColor(hwnd, CLR_NONE);
1481 expect(TRUE, res);
1483 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1484 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1485 ok(r != 0, "Expected not zero result\n");
1486 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1487 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1489 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1490 expect(TRUE, res);
1492 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1493 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1494 todo_wine ok(r != 0, "Expected not zero result\n");
1495 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1496 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1498 ReleaseDC(hwndparent, hdc);
1500 DestroyWindow(hwnd);
1503 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1505 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1507 if(msg == WM_NOTIFY) {
1508 NMHDR *nmhdr = (PVOID)lp;
1509 if(nmhdr->code == NM_CUSTOMDRAW) {
1510 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1511 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1512 switch(nmlvcd->nmcd.dwDrawStage) {
1513 case CDDS_PREPAINT:
1514 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1515 return CDRF_NOTIFYITEMDRAW;
1516 case CDDS_ITEMPREPAINT:
1517 nmlvcd->clrTextBk = CLR_DEFAULT;
1518 return CDRF_NOTIFYSUBITEMDRAW;
1519 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1520 clr = GetBkColor(nmlvcd->nmcd.hdc);
1521 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1522 return CDRF_NOTIFYPOSTPAINT;
1523 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1524 clr = GetBkColor(nmlvcd->nmcd.hdc);
1525 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1526 return CDRF_DODEFAULT;
1528 return CDRF_DODEFAULT;
1532 return DefWindowProcA(hwnd, msg, wp, lp);
1535 static void test_customdraw(void)
1537 HWND hwnd;
1538 WNDPROC oldwndproc;
1540 hwnd = create_listview_control(0);
1542 insert_column(hwnd, 0);
1543 insert_column(hwnd, 1);
1544 insert_item(hwnd, 0);
1546 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1547 (LONG_PTR)cd_wndproc);
1549 InvalidateRect(hwnd, NULL, TRUE);
1550 UpdateWindow(hwnd);
1552 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1554 DestroyWindow(hwnd);
1557 static void test_icon_spacing(void)
1559 /* LVM_SETICONSPACING */
1560 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1562 HWND hwnd;
1563 WORD w, h;
1564 DWORD r;
1566 hwnd = create_custom_listview_control(LVS_ICON);
1567 ok(hwnd != NULL, "failed to create a listview window\n");
1569 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
1570 expect(NFR_ANSI, r);
1572 /* reset the icon spacing to defaults */
1573 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1575 /* now we can request what the defaults are */
1576 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1577 w = LOWORD(r);
1578 h = HIWORD(r);
1580 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1582 trace("test icon spacing\n");
1584 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1585 ok(r == MAKELONG(w, h) ||
1586 broken(r == MAKELONG(w, w)), /* win98 */
1587 "Expected %d, got %d\n", MAKELONG(w, h), r);
1589 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1590 expect(MAKELONG(20,30), r);
1592 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1593 expect(MAKELONG(25,35), r);
1595 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1597 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1598 DestroyWindow(hwnd);
1601 static void test_color(void)
1603 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1605 HWND hwnd;
1606 DWORD r;
1607 int i;
1609 COLORREF color;
1610 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1612 hwnd = create_listview_control(0);
1613 ok(hwnd != NULL, "failed to create a listview window\n");
1615 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1617 trace("test color seq\n");
1618 for (i = 0; i < 4; i++)
1620 color = colors[i];
1622 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1623 expect(TRUE, r);
1624 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1625 expect(color, r);
1627 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1628 expect (TRUE, r);
1629 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1630 expect(color, r);
1632 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1633 expect(TRUE, r);
1634 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1635 expect(color, r);
1638 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1640 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1641 DestroyWindow(hwnd);
1644 static void test_item_count(void)
1646 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1648 HWND hwnd;
1649 DWORD r;
1650 HDC hdc;
1651 HFONT hOldFont;
1652 TEXTMETRICA tm;
1653 RECT rect;
1654 INT height;
1656 LVITEM item0;
1657 LVITEM item1;
1658 LVITEM item2;
1659 static CHAR item0text[] = "item0";
1660 static CHAR item1text[] = "item1";
1661 static CHAR item2text[] = "item2";
1663 hwnd = create_listview_control(0);
1664 ok(hwnd != NULL, "failed to create a listview window\n");
1666 /* resize in dpiaware manner to fit all 3 items added */
1667 hdc = GetDC(0);
1668 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1669 GetTextMetricsA(hdc, &tm);
1670 /* 2 extra pixels for bounds and header border */
1671 height = tm.tmHeight + 2;
1672 SelectObject(hdc, hOldFont);
1673 ReleaseDC(0, hdc);
1675 GetWindowRect(hwnd, &rect);
1676 /* 3 items + 1 header + 1 to be sure */
1677 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1679 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1681 trace("test item count\n");
1683 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1684 expect(0, r);
1686 /* [item0] */
1687 item0.mask = LVIF_TEXT;
1688 item0.iItem = 0;
1689 item0.iSubItem = 0;
1690 item0.pszText = item0text;
1691 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1692 expect(0, r);
1694 /* [item0, item1] */
1695 item1.mask = LVIF_TEXT;
1696 item1.iItem = 1;
1697 item1.iSubItem = 0;
1698 item1.pszText = item1text;
1699 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1700 expect(1, r);
1702 /* [item0, item1, item2] */
1703 item2.mask = LVIF_TEXT;
1704 item2.iItem = 2;
1705 item2.iSubItem = 0;
1706 item2.pszText = item2text;
1707 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1708 expect(2, r);
1710 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1711 expect(3, r);
1713 /* [item0, item1] */
1714 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1715 expect(TRUE, r);
1717 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1718 expect(2, r);
1720 /* [] */
1721 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1722 expect(TRUE, r);
1724 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1725 expect(0, r);
1727 /* [item0] */
1728 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1729 expect(0, r);
1731 /* [item0, item1] */
1732 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1733 expect(1, r);
1735 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1736 expect(2, r);
1738 /* [item0, item1, item2] */
1739 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1740 expect(2, r);
1742 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1743 expect(3, r);
1745 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1747 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1748 DestroyWindow(hwnd);
1751 static void test_item_position(void)
1753 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1755 HWND hwnd;
1756 DWORD r;
1757 POINT position;
1759 LVITEM item0;
1760 LVITEM item1;
1761 LVITEM item2;
1762 static CHAR item0text[] = "item0";
1763 static CHAR item1text[] = "item1";
1764 static CHAR item2text[] = "item2";
1766 hwnd = create_custom_listview_control(LVS_ICON);
1767 ok(hwnd != NULL, "failed to create a listview window\n");
1769 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1771 trace("test item position\n");
1773 /* [item0] */
1774 item0.mask = LVIF_TEXT;
1775 item0.iItem = 0;
1776 item0.iSubItem = 0;
1777 item0.pszText = item0text;
1778 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1779 expect(0, r);
1781 /* [item0, item1] */
1782 item1.mask = LVIF_TEXT;
1783 item1.iItem = 1;
1784 item1.iSubItem = 0;
1785 item1.pszText = item1text;
1786 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1787 expect(1, r);
1789 /* [item0, item1, item2] */
1790 item2.mask = LVIF_TEXT;
1791 item2.iItem = 2;
1792 item2.iSubItem = 0;
1793 item2.pszText = item2text;
1794 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1795 expect(2, r);
1797 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1798 expect(TRUE, r);
1799 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1800 expect(TRUE, r);
1801 expect2(10, 5, position.x, position.y);
1803 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1804 expect(TRUE, r);
1805 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1806 expect(TRUE, r);
1807 expect2(0, 0, position.x, position.y);
1809 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1810 expect(TRUE, r);
1811 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1812 expect(TRUE, r);
1813 expect2(20, 20, position.x, position.y);
1815 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1817 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1818 DestroyWindow(hwnd);
1821 static void test_getorigin(void)
1823 /* LVM_GETORIGIN */
1825 HWND hwnd;
1826 DWORD r;
1827 POINT position;
1829 position.x = position.y = 0;
1831 hwnd = create_custom_listview_control(LVS_ICON);
1832 ok(hwnd != NULL, "failed to create a listview window\n");
1833 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1834 trace("test get origin results\n");
1835 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1836 expect(TRUE, r);
1837 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1838 DestroyWindow(hwnd);
1840 hwnd = create_custom_listview_control(LVS_SMALLICON);
1841 ok(hwnd != NULL, "failed to create a listview window\n");
1842 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1843 trace("test get origin results\n");
1844 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1845 expect(TRUE, r);
1846 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1847 DestroyWindow(hwnd);
1849 hwnd = create_custom_listview_control(LVS_LIST);
1850 ok(hwnd != NULL, "failed to create a listview window\n");
1851 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1852 trace("test get origin results\n");
1853 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1854 expect(FALSE, r);
1855 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1856 DestroyWindow(hwnd);
1858 hwnd = create_custom_listview_control(LVS_REPORT);
1859 ok(hwnd != NULL, "failed to create a listview window\n");
1860 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1861 trace("test get origin results\n");
1862 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1863 expect(FALSE, r);
1864 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1865 DestroyWindow(hwnd);
1869 static void test_multiselect(void)
1871 typedef struct t_select_task
1873 const char *descr;
1874 int initPos;
1875 int loopVK;
1876 int count;
1877 int result;
1878 } select_task;
1880 HWND hwnd;
1881 DWORD r;
1882 int i,j,item_count,selected_count;
1883 static const int items=5;
1884 BYTE kstate[256];
1885 select_task task;
1886 LONG_PTR style;
1887 LVITEMA item;
1889 static struct t_select_task task_list[] = {
1890 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1891 { "using VK_UP", -1, VK_UP, -1, -1 },
1892 { "using VK_END", 0, VK_END, 1, -1 },
1893 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1897 hwnd = create_listview_control(0);
1899 for (i=0;i<items;i++) {
1900 insert_item(hwnd, 0);
1903 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1905 expect(items,item_count);
1907 for (i=0;i<4;i++) {
1908 task = task_list[i];
1910 /* deselect all items */
1911 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1912 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1914 /* set initial position */
1915 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1916 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1918 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1920 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1922 /* Set SHIFT key pressed */
1923 GetKeyboardState(kstate);
1924 kstate[VK_SHIFT]=0x80;
1925 SetKeyboardState(kstate);
1927 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1928 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1929 expect(0,r);
1930 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1931 expect(0,r);
1934 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1936 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);
1938 /* Set SHIFT key released */
1939 GetKeyboardState(kstate);
1940 kstate[VK_SHIFT]=0x00;
1941 SetKeyboardState(kstate);
1943 DestroyWindow(hwnd);
1945 /* make multiple selection, then switch to LVS_SINGLESEL */
1946 hwnd = create_listview_control(0);
1947 for (i=0;i<items;i++) {
1948 insert_item(hwnd, 0);
1950 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1951 expect(items,item_count);
1953 /* try with NULL pointer */
1954 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)NULL);
1955 expect(FALSE, r);
1957 /* select all, check notifications */
1958 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1960 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1962 item.stateMask = LVIS_SELECTED;
1963 item.state = LVIS_SELECTED;
1964 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1965 expect(TRUE, r);
1967 ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
1968 "select all notification", FALSE);
1970 /* deselect all items */
1971 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1972 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1973 for (i=0;i<3;i++) {
1974 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
1977 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1978 expect(3, r);
1979 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1980 expect(-1, r);
1982 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1983 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
1984 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
1985 /* check that style is accepted */
1986 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1987 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
1989 for (i=0;i<3;i++) {
1990 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
1991 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
1993 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1994 expect(3, r);
1995 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1996 expect(3, r);
1998 /* select one more */
1999 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2001 for (i=0;i<3;i++) {
2002 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2003 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2005 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2006 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2008 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2009 expect(1, r);
2010 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2011 expect(-1, r);
2013 /* try to select all on LVS_SINGLESEL */
2014 memset(&item, 0, sizeof(item));
2015 item.stateMask = LVIS_SELECTED;
2016 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2017 expect(TRUE, r);
2018 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2020 item.stateMask = LVIS_SELECTED;
2021 item.state = LVIS_SELECTED;
2022 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2023 expect(FALSE, r);
2025 r = ListView_GetSelectedCount(hwnd);
2026 expect(0, r);
2027 r = ListView_GetSelectionMark(hwnd);
2028 expect(-1, r);
2030 /* try to deselect all on LVS_SINGLESEL */
2031 item.stateMask = LVIS_SELECTED;
2032 item.state = LVIS_SELECTED;
2033 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2034 expect(TRUE, r);
2036 item.stateMask = LVIS_SELECTED;
2037 item.state = 0;
2038 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2039 expect(TRUE, r);
2040 r = ListView_GetSelectedCount(hwnd);
2041 expect(0, r);
2043 DestroyWindow(hwnd);
2046 static void test_subitem_rect(void)
2048 HWND hwnd;
2049 DWORD r;
2050 LVCOLUMN col;
2051 RECT rect;
2053 /* test LVM_GETSUBITEMRECT for header */
2054 hwnd = create_listview_control(0);
2055 ok(hwnd != NULL, "failed to create a listview window\n");
2056 /* add some columns */
2057 memset(&col, 0, sizeof(LVCOLUMN));
2058 col.mask = LVCF_WIDTH;
2059 col.cx = 100;
2060 r = -1;
2061 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2062 expect(0, r);
2063 col.cx = 150;
2064 r = -1;
2065 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2066 expect(1, r);
2067 col.cx = 200;
2068 r = -1;
2069 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2070 expect(2, r);
2071 /* item = -1 means header, subitem index is 1 based */
2072 rect.left = LVIR_BOUNDS;
2073 rect.top = 0;
2074 rect.right = rect.bottom = 0;
2075 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2076 expect(0, r);
2078 rect.left = LVIR_BOUNDS;
2079 rect.top = 1;
2080 rect.right = rect.bottom = 0;
2081 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2083 ok(r != 0, "Expected not-null LRESULT\n");
2084 expect(100, rect.left);
2085 expect(250, rect.right);
2086 todo_wine
2087 expect(3, rect.top);
2089 rect.left = LVIR_BOUNDS;
2090 rect.top = 2;
2091 rect.right = rect.bottom = 0;
2092 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2094 ok(r != 0, "Expected not-null LRESULT\n");
2095 expect(250, rect.left);
2096 expect(450, rect.right);
2097 todo_wine
2098 expect(3, rect.top);
2100 /* item LVS_REPORT padding isn't applied to subitems */
2101 insert_item(hwnd, 0);
2103 rect.left = LVIR_BOUNDS;
2104 rect.top = 1;
2105 rect.right = rect.bottom = 0;
2106 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2107 ok(r != 0, "Expected not-null LRESULT\n");
2108 expect(100, rect.left);
2109 expect(250, rect.right);
2111 rect.left = LVIR_ICON;
2112 rect.top = 1;
2113 rect.right = rect.bottom = 0;
2114 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2115 ok(r != 0, "Expected not-null LRESULT\n");
2116 /* no icon attached - zero width rectangle, with no left padding */
2117 expect(100, rect.left);
2118 expect(100, rect.right);
2120 rect.left = LVIR_LABEL;
2121 rect.top = 1;
2122 rect.right = rect.bottom = 0;
2123 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2124 ok(r != 0, "Expected not-null LRESULT\n");
2125 /* same as full LVIR_BOUNDS */
2126 expect(100, rect.left);
2127 expect(250, rect.right);
2129 DestroyWindow(hwnd);
2131 /* try it for non LVS_REPORT style */
2132 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2133 GetModuleHandle(NULL), 0);
2134 rect.left = LVIR_BOUNDS;
2135 rect.top = 1;
2136 rect.right = rect.bottom = -10;
2137 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2138 ok(r == 0, "Expected not-null LRESULT\n");
2139 /* rect is unchanged */
2140 expect(0, rect.left);
2141 expect(-10, rect.right);
2142 expect(1, rect.top);
2143 expect(-10, rect.bottom);
2144 DestroyWindow(hwnd);
2147 /* comparison callback for test_sorting */
2148 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2150 if (first == second) return 0;
2151 return (first > second ? 1 : -1);
2154 static void test_sorting(void)
2156 HWND hwnd;
2157 LVITEMA item = {0};
2158 DWORD r;
2159 LONG_PTR style;
2160 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2161 CHAR buff[10];
2163 hwnd = create_listview_control(0);
2164 ok(hwnd != NULL, "failed to create a listview window\n");
2166 /* insert some items */
2167 item.mask = LVIF_PARAM | LVIF_STATE;
2168 item.state = LVIS_SELECTED;
2169 item.iItem = 0;
2170 item.iSubItem = 0;
2171 item.lParam = 3;
2172 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2173 expect(0, r);
2175 item.mask = LVIF_PARAM;
2176 item.iItem = 1;
2177 item.iSubItem = 0;
2178 item.lParam = 2;
2179 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2180 expect(1, r);
2182 item.mask = LVIF_STATE | LVIF_PARAM;
2183 item.state = LVIS_SELECTED;
2184 item.iItem = 2;
2185 item.iSubItem = 0;
2186 item.lParam = 4;
2187 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2188 expect(2, r);
2190 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2191 expect(-1, r);
2193 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2194 expect(2, r);
2196 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2197 expect(TRUE, r);
2199 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2200 expect(2, r);
2201 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2202 expect(-1, r);
2203 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2204 expect(0, r);
2205 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2206 expect(LVIS_SELECTED, r);
2207 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2208 expect(LVIS_SELECTED, r);
2210 DestroyWindow(hwnd);
2212 /* switch to LVS_SORTASCENDING when some items added */
2213 hwnd = create_listview_control(0);
2214 ok(hwnd != NULL, "failed to create a listview window\n");
2216 item.mask = LVIF_TEXT;
2217 item.iItem = 0;
2218 item.iSubItem = 0;
2219 item.pszText = names[1];
2220 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2221 expect(0, r);
2223 item.mask = LVIF_TEXT;
2224 item.iItem = 1;
2225 item.iSubItem = 0;
2226 item.pszText = names[2];
2227 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2228 expect(1, r);
2230 item.mask = LVIF_TEXT;
2231 item.iItem = 2;
2232 item.iSubItem = 0;
2233 item.pszText = names[0];
2234 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2235 expect(2, r);
2237 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2238 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2239 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2240 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2242 /* no sorting performed when switched to LVS_SORTASCENDING */
2243 item.mask = LVIF_TEXT;
2244 item.iItem = 0;
2245 item.pszText = buff;
2246 item.cchTextMax = sizeof(buff);
2247 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2248 expect(TRUE, r);
2249 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2251 item.iItem = 1;
2252 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2253 expect(TRUE, r);
2254 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2256 item.iItem = 2;
2257 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2258 expect(TRUE, r);
2259 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2261 /* adding new item doesn't resort list */
2262 item.mask = LVIF_TEXT;
2263 item.iItem = 3;
2264 item.iSubItem = 0;
2265 item.pszText = names[3];
2266 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2267 expect(3, r);
2269 item.mask = LVIF_TEXT;
2270 item.iItem = 0;
2271 item.pszText = buff;
2272 item.cchTextMax = sizeof(buff);
2273 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2274 expect(TRUE, r);
2275 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2277 item.iItem = 1;
2278 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2279 expect(TRUE, r);
2280 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2282 item.iItem = 2;
2283 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2284 expect(TRUE, r);
2285 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2287 item.iItem = 3;
2288 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2289 expect(TRUE, r);
2290 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2292 /* corner case - item should be placed at first position */
2293 item.mask = LVIF_TEXT;
2294 item.iItem = 4;
2295 item.iSubItem = 0;
2296 item.pszText = names[4];
2297 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2298 expect(0, r);
2300 item.iItem = 0;
2301 item.pszText = buff;
2302 item.cchTextMax = sizeof(buff);
2303 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2304 expect(TRUE, r);
2305 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2307 item.iItem = 1;
2308 item.pszText = buff;
2309 item.cchTextMax = sizeof(buff);
2310 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2311 expect(TRUE, r);
2312 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2314 item.iItem = 2;
2315 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2316 expect(TRUE, r);
2317 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2319 item.iItem = 3;
2320 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2321 expect(TRUE, r);
2322 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2324 item.iItem = 4;
2325 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2326 expect(TRUE, r);
2327 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2329 DestroyWindow(hwnd);
2332 static void test_ownerdata(void)
2334 HWND hwnd;
2335 LONG_PTR style, ret;
2336 DWORD res;
2337 LVITEMA item;
2339 /* it isn't possible to set LVS_OWNERDATA after creation */
2340 if (g_is_below_5)
2342 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2344 else
2346 hwnd = create_listview_control(0);
2347 ok(hwnd != NULL, "failed to create a listview window\n");
2348 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2349 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2351 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2353 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2354 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2355 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2356 "try to switch to LVS_OWNERDATA seq", FALSE);
2358 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2359 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2360 DestroyWindow(hwnd);
2363 /* try to set LVS_OWNERDATA after creation just having it */
2364 hwnd = create_listview_control(LVS_OWNERDATA);
2365 ok(hwnd != NULL, "failed to create a listview window\n");
2366 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2367 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2369 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2371 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2372 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2373 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2374 "try to switch to LVS_OWNERDATA seq", FALSE);
2375 DestroyWindow(hwnd);
2377 /* try to remove LVS_OWNERDATA after creation just having it */
2378 if (g_is_below_5)
2380 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2382 else
2384 hwnd = create_listview_control(LVS_OWNERDATA);
2385 ok(hwnd != NULL, "failed to create a listview window\n");
2386 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2387 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2389 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2391 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2392 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2393 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2394 "try to switch to LVS_OWNERDATA seq", FALSE);
2395 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2396 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2397 DestroyWindow(hwnd);
2400 /* try select an item */
2401 hwnd = create_listview_control(LVS_OWNERDATA);
2402 ok(hwnd != NULL, "failed to create a listview window\n");
2403 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2404 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2405 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2406 expect(0, res);
2407 memset(&item, 0, sizeof(item));
2408 item.stateMask = LVIS_SELECTED;
2409 item.state = LVIS_SELECTED;
2410 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2411 expect(TRUE, res);
2412 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2413 expect(1, res);
2414 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2415 expect(1, res);
2416 DestroyWindow(hwnd);
2418 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2419 hwnd = create_listview_control(LVS_OWNERDATA);
2420 ok(hwnd != NULL, "failed to create a listview window\n");
2421 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2422 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2423 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2424 expect(1, res);
2425 memset(&item, 0, sizeof(item));
2426 item.mask = LVIF_STATE;
2427 item.iItem = 0;
2428 item.stateMask = LVIS_SELECTED;
2429 item.state = LVIS_SELECTED;
2430 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2431 expect(FALSE, res);
2432 DestroyWindow(hwnd);
2434 /* check notifications after focused/selected changed */
2435 hwnd = create_listview_control(LVS_OWNERDATA);
2436 ok(hwnd != NULL, "failed to create a listview window\n");
2437 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2438 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2440 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2442 memset(&item, 0, sizeof(item));
2443 item.stateMask = LVIS_SELECTED;
2444 item.state = LVIS_SELECTED;
2445 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2446 expect(TRUE, res);
2448 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2449 "ownerdata select notification", TRUE);
2451 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2453 memset(&item, 0, sizeof(item));
2454 item.stateMask = LVIS_FOCUSED;
2455 item.state = LVIS_FOCUSED;
2456 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2457 expect(TRUE, res);
2459 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2460 "ownerdata focus notification", TRUE);
2462 /* select all, check notifications */
2463 item.stateMask = LVIS_SELECTED;
2464 item.state = 0;
2465 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2466 expect(TRUE, res);
2468 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2470 item.stateMask = LVIS_SELECTED;
2471 item.state = LVIS_SELECTED;
2473 g_dump_itemchanged = TRUE;
2474 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2475 expect(TRUE, res);
2476 g_dump_itemchanged = FALSE;
2478 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2479 "ownerdata select all notification", TRUE);
2481 /* select all again, note that all items are selected already */
2482 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2483 item.stateMask = LVIS_SELECTED;
2484 item.state = LVIS_SELECTED;
2485 g_dump_itemchanged = TRUE;
2486 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2487 expect(TRUE, res);
2488 g_dump_itemchanged = FALSE;
2489 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2490 "ownerdata select all notification", TRUE);
2491 /* deselect all */
2492 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2493 item.stateMask = LVIS_SELECTED;
2494 item.state = 0;
2495 g_dump_itemchanged = TRUE;
2496 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2497 expect(TRUE, res);
2498 g_dump_itemchanged = FALSE;
2499 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2500 "ownerdata deselect all notification", TRUE);
2502 /* select one, then deselect all */
2503 item.stateMask = LVIS_SELECTED;
2504 item.state = LVIS_SELECTED;
2505 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2506 expect(TRUE, res);
2507 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2508 item.stateMask = LVIS_SELECTED;
2509 item.state = 0;
2510 g_dump_itemchanged = TRUE;
2511 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2512 expect(TRUE, res);
2513 g_dump_itemchanged = FALSE;
2514 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2515 "ownerdata select all notification", TRUE);
2517 /* remove focused, try to focus all */
2518 item.stateMask = LVIS_FOCUSED;
2519 item.state = LVIS_FOCUSED;
2520 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2521 expect(TRUE, res);
2522 item.stateMask = LVIS_FOCUSED;
2523 item.state = 0;
2524 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2525 expect(TRUE, res);
2526 item.stateMask = LVIS_FOCUSED;
2527 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
2528 expect(0, res);
2529 /* setting all to focused returns failure value */
2530 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2531 item.stateMask = LVIS_FOCUSED;
2532 item.state = LVIS_FOCUSED;
2533 g_dump_itemchanged = TRUE;
2534 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2535 expect(FALSE, res);
2536 g_dump_itemchanged = FALSE;
2537 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2538 "ownerdata focus all notification", FALSE);
2539 /* focus single item, remove all */
2540 item.stateMask = LVIS_FOCUSED;
2541 item.state = LVIS_FOCUSED;
2542 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2543 expect(TRUE, res);
2544 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2545 item.stateMask = LVIS_FOCUSED;
2546 item.state = 0;
2547 g_dump_itemchanged = TRUE;
2548 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2549 expect(TRUE, res);
2550 g_dump_itemchanged = FALSE;
2551 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
2552 "ownerdata remove focus all notification", TRUE);
2553 /* set all cut */
2554 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2555 item.stateMask = LVIS_CUT;
2556 item.state = LVIS_CUT;
2557 g_dump_itemchanged = TRUE;
2558 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2559 expect(TRUE, res);
2560 g_dump_itemchanged = FALSE;
2561 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2562 "ownerdata cut all notification", TRUE);
2563 /* all marked cut, try again */
2564 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2565 item.stateMask = LVIS_CUT;
2566 item.state = LVIS_CUT;
2567 g_dump_itemchanged = TRUE;
2568 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2569 expect(TRUE, res);
2570 g_dump_itemchanged = FALSE;
2571 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2572 "ownerdata cut all notification #2", TRUE);
2574 DestroyWindow(hwnd);
2576 /* check notifications on LVM_GETITEM */
2577 /* zero callback mask */
2578 hwnd = create_listview_control(LVS_OWNERDATA);
2579 ok(hwnd != NULL, "failed to create a listview window\n");
2580 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2581 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2583 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2585 memset(&item, 0, sizeof(item));
2586 item.stateMask = LVIS_SELECTED;
2587 item.mask = LVIF_STATE;
2588 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2589 expect(TRUE, res);
2591 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2592 "ownerdata getitem selected state 1", FALSE);
2594 /* non zero callback mask but not we asking for */
2595 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2596 expect(TRUE, res);
2598 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2600 memset(&item, 0, sizeof(item));
2601 item.stateMask = LVIS_SELECTED;
2602 item.mask = LVIF_STATE;
2603 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2604 expect(TRUE, res);
2606 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2607 "ownerdata getitem selected state 2", FALSE);
2609 /* LVIS_OVERLAYMASK callback mask, asking for index */
2610 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2612 memset(&item, 0, sizeof(item));
2613 item.stateMask = LVIS_OVERLAYMASK;
2614 item.mask = LVIF_STATE;
2615 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2616 expect(TRUE, res);
2618 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2619 "ownerdata getitem selected state 2", FALSE);
2621 DestroyWindow(hwnd);
2623 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2624 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING);
2625 ok(hwnd != NULL, "failed to create a listview window\n");
2626 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2627 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2628 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2629 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2630 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2631 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2632 DestroyWindow(hwnd);
2633 /* apparently it's allowed to switch these style on after creation */
2634 hwnd = create_listview_control(LVS_OWNERDATA);
2635 ok(hwnd != NULL, "failed to create a listview window\n");
2636 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2637 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2638 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2639 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2640 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2641 DestroyWindow(hwnd);
2643 hwnd = create_listview_control(LVS_OWNERDATA);
2644 ok(hwnd != NULL, "failed to create a listview window\n");
2645 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2646 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2647 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2648 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2649 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2650 DestroyWindow(hwnd);
2653 static void test_norecompute(void)
2655 static CHAR testA[] = "test";
2656 CHAR buff[10];
2657 LVITEMA item;
2658 HWND hwnd;
2659 DWORD res;
2661 /* self containing control */
2662 hwnd = create_listview_control(0);
2663 ok(hwnd != NULL, "failed to create a listview window\n");
2664 memset(&item, 0, sizeof(item));
2665 item.mask = LVIF_TEXT | LVIF_STATE;
2666 item.iItem = 0;
2667 item.stateMask = LVIS_SELECTED;
2668 item.state = LVIS_SELECTED;
2669 item.pszText = testA;
2670 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2671 expect(0, res);
2672 /* retrieve with LVIF_NORECOMPUTE */
2673 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2674 item.iItem = 0;
2675 item.pszText = buff;
2676 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2677 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2678 expect(TRUE, res);
2679 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2681 item.mask = LVIF_TEXT;
2682 item.iItem = 1;
2683 item.pszText = LPSTR_TEXTCALLBACK;
2684 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2685 expect(1, res);
2687 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2688 item.iItem = 1;
2689 item.pszText = buff;
2690 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2692 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2693 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2694 expect(TRUE, res);
2695 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2696 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2697 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2699 DestroyWindow(hwnd);
2701 /* LVS_OWNERDATA */
2702 hwnd = create_listview_control(LVS_OWNERDATA);
2703 ok(hwnd != NULL, "failed to create a listview window\n");
2705 item.mask = LVIF_STATE;
2706 item.stateMask = LVIS_SELECTED;
2707 item.state = LVIS_SELECTED;
2708 item.iItem = 0;
2709 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2710 expect(0, res);
2712 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2713 item.iItem = 0;
2714 item.pszText = buff;
2715 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2716 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2717 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2718 expect(TRUE, res);
2719 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2720 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2721 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2723 DestroyWindow(hwnd);
2726 static void test_nosortheader(void)
2728 HWND hwnd, header;
2729 LONG_PTR style;
2731 hwnd = create_listview_control(0);
2732 ok(hwnd != NULL, "failed to create a listview window\n");
2734 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2735 ok(IsWindow(header), "header expected\n");
2737 style = GetWindowLongPtr(header, GWL_STYLE);
2738 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2740 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2741 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2742 /* HDS_BUTTONS retained */
2743 style = GetWindowLongPtr(header, GWL_STYLE);
2744 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2746 DestroyWindow(hwnd);
2748 /* create with LVS_NOSORTHEADER */
2749 hwnd = create_listview_control(LVS_NOSORTHEADER);
2750 ok(hwnd != NULL, "failed to create a listview window\n");
2752 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2753 ok(IsWindow(header), "header expected\n");
2755 style = GetWindowLongPtr(header, GWL_STYLE);
2756 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2758 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2759 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2760 /* not changed here */
2761 style = GetWindowLongPtr(header, GWL_STYLE);
2762 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2764 DestroyWindow(hwnd);
2767 static void test_setredraw(void)
2769 HWND hwnd;
2770 DWORD_PTR style;
2771 DWORD ret;
2772 HDC hdc;
2773 RECT rect;
2775 hwnd = create_listview_control(LVS_OWNERDATA);
2776 ok(hwnd != NULL, "failed to create a listview window\n");
2778 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2779 ListView seems to handle it internally without DefWinProc */
2781 /* default value first */
2782 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2783 expect(0, ret);
2784 /* disable */
2785 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2786 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2787 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2788 expect(0, ret);
2789 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2790 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2791 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2792 expect(0, ret);
2794 /* check update rect after redrawing */
2795 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2796 expect(0, ret);
2797 InvalidateRect(hwnd, NULL, FALSE);
2798 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
2799 rect.right = rect.bottom = 1;
2800 GetUpdateRect(hwnd, &rect, FALSE);
2801 expect(0, rect.right);
2802 expect(0, rect.bottom);
2804 /* WM_ERASEBKGND */
2805 hdc = GetWindowDC(hwndparent);
2806 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2807 expect(TRUE, ret);
2808 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2809 expect(0, ret);
2810 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2811 expect(TRUE, ret);
2812 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2813 expect(0, ret);
2814 ReleaseDC(hwndparent, hdc);
2816 /* check notification messages to show that repainting is disabled */
2817 ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
2818 expect(TRUE, ret);
2819 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2820 expect(0, ret);
2821 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2823 InvalidateRect(hwnd, NULL, TRUE);
2824 UpdateWindow(hwnd);
2825 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2826 "redraw after WM_SETREDRAW (FALSE)", FALSE);
2828 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
2829 expect(TRUE, ret);
2830 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2831 InvalidateRect(hwnd, NULL, TRUE);
2832 UpdateWindow(hwnd);
2833 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2834 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
2836 /* message isn't forwarded to header */
2837 subclass_header(hwnd);
2838 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2839 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2840 expect(0, ret);
2841 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
2842 "WM_SETREDRAW: not forwarded to header", FALSE);
2844 DestroyWindow(hwnd);
2847 static void test_hittest(void)
2849 HWND hwnd;
2850 DWORD r;
2851 RECT bounds;
2852 LVITEMA item;
2853 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2854 POINT pos;
2855 INT x, y;
2856 HIMAGELIST himl, himl2;
2857 HBITMAP hbmp;
2859 hwnd = create_listview_control(0);
2860 ok(hwnd != NULL, "failed to create a listview window\n");
2862 /* LVS_REPORT with a single subitem (2 columns) */
2863 insert_column(hwnd, 0);
2864 insert_column(hwnd, 1);
2865 insert_item(hwnd, 0);
2867 item.iSubItem = 0;
2868 /* the only purpose of that line is to be as long as a half item rect */
2869 item.pszText = text;
2870 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2871 expect(TRUE, r);
2873 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2874 expect(TRUE, r);
2875 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
2876 expect(TRUE, r);
2878 memset(&bounds, 0, sizeof(bounds));
2879 bounds.left = LVIR_BOUNDS;
2880 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
2881 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
2882 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
2883 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
2884 expect(TRUE, r);
2886 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2887 x = pos.x + 50; /* column half width */
2888 y = pos.y + (bounds.bottom - bounds.top) / 2;
2889 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE, __LINE__);
2890 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2891 x = pos.x + 150; /* outside column */
2892 y = pos.y + (bounds.bottom - bounds.top) / 2;
2893 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2894 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2895 y = (bounds.bottom - bounds.top) / 2;
2896 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2897 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2898 /* outside possible client rectangle (to right) */
2899 x = pos.x + 500;
2900 y = pos.y + (bounds.bottom - bounds.top) / 2;
2901 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2902 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2903 y = (bounds.bottom - bounds.top) / 2;
2904 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2905 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2906 /* subitem returned with -1 item too */
2907 x = pos.x + 150;
2908 y = -10;
2909 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2910 /* parent client area is 100x100 by default */
2911 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
2912 x = pos.x + 150; /* outside column */
2913 y = pos.y + (bounds.bottom - bounds.top) / 2;
2914 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE, __LINE__);
2915 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2916 y = (bounds.bottom - bounds.top) / 2;
2917 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE, __LINE__);
2918 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2919 /* the same with LVS_EX_FULLROWSELECT */
2920 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
2921 x = pos.x + 150; /* outside column */
2922 y = pos.y + (bounds.bottom - bounds.top) / 2;
2923 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE, __LINE__);
2924 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2925 y = (bounds.bottom - bounds.top) / 2;
2926 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2927 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
2928 x = pos.x + 150; /* outside column */
2929 y = pos.y + (bounds.bottom - bounds.top) / 2;
2930 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2931 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2932 y = (bounds.bottom - bounds.top) / 2;
2933 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2934 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2935 /* outside possible client rectangle (to right) */
2936 x = pos.x + 500;
2937 y = pos.y + (bounds.bottom - bounds.top) / 2;
2938 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2939 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2940 y = (bounds.bottom - bounds.top) / 2;
2941 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2942 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2943 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2944 himl = ImageList_Create(16, 16, 0, 4, 4);
2945 ok(himl != NULL, "failed to create imagelist\n");
2946 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2947 ok(hbmp != NULL, "failed to create bitmap\n");
2948 r = ImageList_Add(himl, hbmp, 0);
2949 ok(r == 0, "should be zero\n");
2950 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2951 ok(hbmp != NULL, "failed to create bitmap\n");
2952 r = ImageList_Add(himl, hbmp, 0);
2953 ok(r == 1, "should be one\n");
2955 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2956 ok(r == 0, "should return zero\n");
2958 item.mask = LVIF_IMAGE;
2959 item.iImage = 0;
2960 item.iItem = 0;
2961 item.iSubItem = 0;
2962 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2963 expect(TRUE, r);
2964 /* on state icon */
2965 x = pos.x + 8;
2966 y = pos.y + (bounds.bottom - bounds.top) / 2;
2967 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE, __LINE__);
2968 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2969 y = (bounds.bottom - bounds.top) / 2;
2970 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2972 /* state icons indices are 1 based, check with valid index */
2973 item.mask = LVIF_STATE;
2974 item.state = INDEXTOSTATEIMAGEMASK(1);
2975 item.stateMask = LVIS_STATEIMAGEMASK;
2976 item.iItem = 0;
2977 item.iSubItem = 0;
2978 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2979 expect(TRUE, r);
2980 /* on state icon */
2981 x = pos.x + 8;
2982 y = pos.y + (bounds.bottom - bounds.top) / 2;
2983 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE, __LINE__);
2984 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2985 y = (bounds.bottom - bounds.top) / 2;
2986 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2988 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
2989 ok(himl2 == himl, "should return handle\n");
2991 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
2992 ok(r == 0, "should return zero\n");
2993 /* on item icon */
2994 x = pos.x + 8;
2995 y = pos.y + (bounds.bottom - bounds.top) / 2;
2996 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE, __LINE__);
2997 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
2998 y = (bounds.bottom - bounds.top) / 2;
2999 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
3001 DestroyWindow(hwnd);
3004 static void test_getviewrect(void)
3006 HWND hwnd;
3007 DWORD r;
3008 RECT rect;
3009 LVITEMA item;
3011 hwnd = create_listview_control(0);
3012 ok(hwnd != NULL, "failed to create a listview window\n");
3014 /* empty */
3015 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3016 expect(TRUE, r);
3018 insert_column(hwnd, 0);
3019 insert_column(hwnd, 1);
3021 memset(&item, 0, sizeof(item));
3022 item.iItem = 0;
3023 item.iSubItem = 0;
3024 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3026 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3027 expect(TRUE, r);
3028 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3029 expect(TRUE, r);
3031 rect.left = rect.right = rect.top = rect.bottom = -1;
3032 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3033 expect(TRUE, r);
3034 /* left is set to (2e31-1) - XP SP2 */
3035 expect(0, rect.right);
3036 expect(0, rect.top);
3037 expect(0, rect.bottom);
3039 /* switch to LVS_ICON */
3040 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3042 rect.left = rect.right = rect.top = rect.bottom = -1;
3043 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3044 expect(TRUE, r);
3045 expect(0, rect.left);
3046 expect(0, rect.top);
3047 /* precise value differs for 2k, XP and Vista */
3048 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3049 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3051 DestroyWindow(hwnd);
3054 static void test_getitemposition(void)
3056 HWND hwnd, header;
3057 DWORD r;
3058 POINT pt;
3059 RECT rect;
3061 hwnd = create_listview_control(0);
3062 ok(hwnd != NULL, "failed to create a listview window\n");
3063 header = subclass_header(hwnd);
3065 /* LVS_REPORT, single item, no columns added */
3066 insert_item(hwnd, 0);
3068 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3070 pt.x = pt.y = -1;
3071 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3072 expect(TRUE, r);
3073 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3075 /* LVS_REPORT, single item, single column */
3076 insert_column(hwnd, 0);
3078 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3080 pt.x = pt.y = -1;
3081 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3082 expect(TRUE, r);
3083 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3085 memset(&rect, 0, sizeof(rect));
3086 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3087 /* some padding? */
3088 expect(2, pt.x);
3089 /* offset by header height */
3090 expect(rect.bottom - rect.top, pt.y);
3092 DestroyWindow(hwnd);
3095 static void test_columnscreation(void)
3097 HWND hwnd, header;
3098 DWORD r;
3100 hwnd = create_listview_control(0);
3101 ok(hwnd != NULL, "failed to create a listview window\n");
3103 insert_item(hwnd, 0);
3105 /* headers columns aren't created automatically */
3106 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3107 ok(IsWindow(header), "Expected header handle\n");
3108 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3109 expect(0, r);
3111 DestroyWindow(hwnd);
3114 static void test_getitemrect(void)
3116 HWND hwnd;
3117 HIMAGELIST himl;
3118 HBITMAP hbm;
3119 RECT rect;
3120 DWORD r;
3121 LVITEMA item;
3122 LVCOLUMNA col;
3123 INT order[2];
3124 POINT pt;
3126 hwnd = create_listview_control(0);
3127 ok(hwnd != NULL, "failed to create a listview window\n");
3129 /* empty item */
3130 memset(&item, 0, sizeof(item));
3131 item.iItem = 0;
3132 item.iSubItem = 0;
3133 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3134 expect(0, r);
3136 rect.left = LVIR_BOUNDS;
3137 rect.right = rect.top = rect.bottom = -1;
3138 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3139 expect(TRUE, r);
3141 /* zero width rectangle with no padding */
3142 expect(0, rect.left);
3143 expect(0, rect.right);
3145 insert_column(hwnd, 0);
3146 insert_column(hwnd, 1);
3148 col.mask = LVCF_WIDTH;
3149 col.cx = 50;
3150 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3151 expect(TRUE, r);
3153 col.mask = LVCF_WIDTH;
3154 col.cx = 100;
3155 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3156 expect(TRUE, r);
3158 rect.left = LVIR_BOUNDS;
3159 rect.right = rect.top = rect.bottom = -1;
3160 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3161 expect(TRUE, r);
3163 /* still no left padding */
3164 expect(0, rect.left);
3165 expect(150, rect.right);
3167 rect.left = LVIR_SELECTBOUNDS;
3168 rect.right = rect.top = rect.bottom = -1;
3169 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3170 expect(TRUE, r);
3171 /* padding */
3172 expect(2, rect.left);
3174 rect.left = LVIR_LABEL;
3175 rect.right = rect.top = rect.bottom = -1;
3176 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3177 expect(TRUE, r);
3178 /* padding, column width */
3179 expect(2, rect.left);
3180 expect(50, rect.right);
3182 /* no icons attached */
3183 rect.left = LVIR_ICON;
3184 rect.right = rect.top = rect.bottom = -1;
3185 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3186 expect(TRUE, r);
3187 /* padding */
3188 expect(2, rect.left);
3189 expect(2, rect.right);
3191 /* change order */
3192 order[0] = 1; order[1] = 0;
3193 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3194 expect(TRUE, r);
3195 pt.x = -1;
3196 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3197 expect(TRUE, r);
3198 /* 1 indexed column width + padding */
3199 expect(102, pt.x);
3200 /* rect is at zero too */
3201 rect.left = LVIR_BOUNDS;
3202 rect.right = rect.top = rect.bottom = -1;
3203 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3204 expect(TRUE, r);
3205 expect(0, rect.left);
3206 /* just width sum */
3207 expect(150, rect.right);
3209 rect.left = LVIR_SELECTBOUNDS;
3210 rect.right = rect.top = rect.bottom = -1;
3211 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3212 expect(TRUE, r);
3213 /* column width + padding */
3214 expect(102, rect.left);
3216 /* back to initial order */
3217 order[0] = 0; order[1] = 1;
3218 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3219 expect(TRUE, r);
3221 /* state icons */
3222 himl = ImageList_Create(16, 16, 0, 2, 2);
3223 ok(himl != NULL, "failed to create imagelist\n");
3224 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3225 ok(hbm != NULL, "failed to create bitmap\n");
3226 r = ImageList_Add(himl, hbm, 0);
3227 ok(r == 0, "should be zero\n");
3228 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3229 ok(hbm != NULL, "failed to create bitmap\n");
3230 r = ImageList_Add(himl, hbm, 0);
3231 ok(r == 1, "should be one\n");
3233 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3234 ok(r == 0, "should return zero\n");
3236 item.mask = LVIF_STATE;
3237 item.state = INDEXTOSTATEIMAGEMASK(1);
3238 item.stateMask = LVIS_STATEIMAGEMASK;
3239 item.iItem = 0;
3240 item.iSubItem = 0;
3241 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3242 expect(TRUE, r);
3244 /* icon bounds */
3245 rect.left = LVIR_ICON;
3246 rect.right = rect.top = rect.bottom = -1;
3247 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3248 expect(TRUE, r);
3249 /* padding + stateicon width */
3250 expect(18, rect.left);
3251 expect(18, rect.right);
3252 /* label bounds */
3253 rect.left = LVIR_LABEL;
3254 rect.right = rect.top = rect.bottom = -1;
3255 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3256 expect(TRUE, r);
3257 /* padding + stateicon width -> column width */
3258 expect(18, rect.left);
3259 expect(50, rect.right);
3261 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
3262 ok(r != 0, "should return current list handle\n");
3264 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3265 ok(r == 0, "should return zero\n");
3267 item.mask = LVIF_STATE | LVIF_IMAGE;
3268 item.iImage = 1;
3269 item.state = 0;
3270 item.stateMask = ~0;
3271 item.iItem = 0;
3272 item.iSubItem = 0;
3273 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3274 expect(TRUE, r);
3276 /* icon bounds */
3277 rect.left = LVIR_ICON;
3278 rect.right = rect.top = rect.bottom = -1;
3279 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3280 expect(TRUE, r);
3281 /* padding, icon width */
3282 expect(2, rect.left);
3283 expect(18, rect.right);
3284 /* label bounds */
3285 rect.left = LVIR_LABEL;
3286 rect.right = rect.top = rect.bottom = -1;
3287 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3288 expect(TRUE, r);
3289 /* padding + icon width -> column width */
3290 expect(18, rect.left);
3291 expect(50, rect.right);
3293 /* select bounds */
3294 rect.left = LVIR_SELECTBOUNDS;
3295 rect.right = rect.top = rect.bottom = -1;
3296 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3297 expect(TRUE, r);
3298 /* padding, column width */
3299 expect(2, rect.left);
3300 expect(50, rect.right);
3302 /* try with indentation */
3303 item.mask = LVIF_INDENT;
3304 item.iIndent = 1;
3305 item.iItem = 0;
3306 item.iSubItem = 0;
3307 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3308 expect(TRUE, r);
3310 /* bounds */
3311 rect.left = LVIR_BOUNDS;
3312 rect.right = rect.top = rect.bottom = -1;
3313 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3314 expect(TRUE, r);
3315 /* padding + 1 icon width, column width */
3316 expect(0, rect.left);
3317 expect(150, rect.right);
3319 /* select bounds */
3320 rect.left = LVIR_SELECTBOUNDS;
3321 rect.right = rect.top = rect.bottom = -1;
3322 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3323 expect(TRUE, r);
3324 /* padding + 1 icon width, column width */
3325 expect(2 + 16, rect.left);
3326 expect(50, rect.right);
3328 /* label bounds */
3329 rect.left = LVIR_LABEL;
3330 rect.right = rect.top = rect.bottom = -1;
3331 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3332 expect(TRUE, r);
3333 /* padding + 2 icon widths, column width */
3334 expect(2 + 16*2, rect.left);
3335 expect(50, rect.right);
3337 /* icon bounds */
3338 rect.left = LVIR_ICON;
3339 rect.right = rect.top = rect.bottom = -1;
3340 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3341 expect(TRUE, r);
3342 /* padding + 1 icon width indentation, icon width */
3343 expect(2 + 16, rect.left);
3344 expect(34, rect.right);
3347 DestroyWindow(hwnd);
3350 static void test_editbox(void)
3352 HWND hwnd, hwndedit, hwndedit2;
3353 LVITEMA item;
3354 DWORD r;
3355 static CHAR testitemA[] = "testitem";
3356 static CHAR testitem1A[] = "testitem1";
3357 static CHAR buffer[10];
3359 hwnd = create_listview_control(LVS_EDITLABELS);
3360 ok(hwnd != NULL, "failed to create a listview window\n");
3362 insert_column(hwnd, 0);
3364 memset(&item, 0, sizeof(item));
3365 item.mask = LVIF_TEXT;
3366 item.pszText = testitemA;
3367 item.iItem = 0;
3368 item.iSubItem = 0;
3369 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3370 expect(0, r);
3372 /* setting focus is necessary */
3373 SetFocus(hwnd);
3374 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3375 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3377 /* modify initial string */
3378 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3379 expect(TRUE, r);
3380 /* return focus to listview */
3381 SetFocus(hwnd);
3383 memset(&item, 0, sizeof(item));
3384 item.mask = LVIF_TEXT;
3385 item.pszText = buffer;
3386 item.cchTextMax = 10;
3387 item.iItem = 0;
3388 item.iSubItem = 0;
3389 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3390 expect(TRUE, r);
3392 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3394 /* send LVM_EDITLABEL on already created edit */
3395 SetFocus(hwnd);
3396 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3397 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3398 /* focus will be set to edit */
3399 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3400 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3401 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3403 /* creating label disabled when control isn't focused */
3404 SetFocus(0);
3405 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3406 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3408 /* check EN_KILLFOCUS handling */
3409 memset(&item, 0, sizeof(item));
3410 item.pszText = testitemA;
3411 item.iItem = 0;
3412 item.iSubItem = 0;
3413 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3414 expect(TRUE, r);
3416 SetFocus(hwnd);
3417 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3418 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3419 /* modify edit and notify control that it lost focus */
3420 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3421 expect(TRUE, r);
3422 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3423 expect(0, r);
3424 memset(&item, 0, sizeof(item));
3425 item.pszText = buffer;
3426 item.cchTextMax = 10;
3427 item.iItem = 0;
3428 item.iSubItem = 0;
3429 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3430 expect(lstrlen(item.pszText), r);
3431 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3432 /* end edit without saving */
3433 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3434 expect(0, r);
3435 memset(&item, 0, sizeof(item));
3436 item.pszText = buffer;
3437 item.cchTextMax = 10;
3438 item.iItem = 0;
3439 item.iSubItem = 0;
3440 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3441 expect(lstrlen(item.pszText), r);
3442 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3444 /* LVM_EDITLABEL with -1 destroys current edit */
3445 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3446 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3447 /* no edit present */
3448 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3449 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3450 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3451 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3452 /* edit present */
3453 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3454 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3455 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3456 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3457 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3458 /* check another negative value */
3459 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3460 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3461 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3462 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3463 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3464 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3465 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3466 /* and value greater than max item index */
3467 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3468 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3469 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3470 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3471 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3472 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3473 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3474 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3476 /* messaging tests */
3477 SetFocus(hwnd);
3478 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3479 blockEdit = FALSE;
3480 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3481 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3482 /* testing only sizing messages */
3483 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3484 "edit box create - sizing", FALSE);
3486 DestroyWindow(hwnd);
3489 static void test_notifyformat(void)
3491 HWND hwnd, header;
3492 DWORD r;
3494 hwnd = create_listview_control(0);
3495 ok(hwnd != NULL, "failed to create a listview window\n");
3497 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3498 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3499 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3500 expect(0, r);
3501 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3502 /* set */
3503 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3504 expect(0, r);
3505 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3506 if (r == 1)
3508 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3509 expect(1, r);
3510 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3511 expect(0, r);
3513 else
3515 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3516 DestroyWindow(hwnd);
3517 return;
3520 DestroyWindow(hwnd);
3522 /* test failure in parent WM_NOTIFYFORMAT */
3523 notifyFormat = 0;
3524 hwnd = create_listview_control(0);
3525 ok(hwnd != NULL, "failed to create a listview window\n");
3526 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3527 ok(IsWindow(header), "expected header to be created\n");
3528 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3529 expect(0, r);
3530 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3531 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3532 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3533 ok(r != 0, "Expected valid format\n");
3535 notifyFormat = NFR_UNICODE;
3536 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3537 expect(NFR_UNICODE, r);
3538 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3539 expect(1, r);
3540 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3541 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3543 notifyFormat = NFR_ANSI;
3544 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3545 expect(NFR_ANSI, r);
3546 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3547 expect(0, r);
3548 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3549 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3551 DestroyWindow(hwnd);
3553 /* try different unicode window combination and defaults */
3554 if (!GetModuleHandleW(NULL))
3556 win_skip("Additional notify format tests are incompatible with Win9x\n");
3557 return;
3560 hwndparentW = create_parent_window(TRUE);
3561 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3562 if (!IsWindow(hwndparentW)) return;
3564 notifyFormat = -1;
3565 hwnd = create_listview_controlW(0, hwndparentW);
3566 ok(hwnd != NULL, "failed to create a listview window\n");
3567 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3568 ok(IsWindow(header), "expected header to be created\n");
3569 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3570 expect(1, r);
3571 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3572 expect(1, r);
3573 DestroyWindow(hwnd);
3574 /* receiving error code defaulting to ansi */
3575 notifyFormat = 0;
3576 hwnd = create_listview_controlW(0, hwndparentW);
3577 ok(hwnd != NULL, "failed to create a listview window\n");
3578 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3579 ok(IsWindow(header), "expected header to be created\n");
3580 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3581 expect(0, r);
3582 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3583 expect(1, r);
3584 DestroyWindow(hwnd);
3585 /* receiving ansi code from unicode window, use it */
3586 notifyFormat = NFR_ANSI;
3587 hwnd = create_listview_controlW(0, hwndparentW);
3588 ok(hwnd != NULL, "failed to create a listview window\n");
3589 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3590 ok(IsWindow(header), "expected header to be created\n");
3591 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3592 expect(0, r);
3593 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3594 expect(1, r);
3595 DestroyWindow(hwnd);
3596 /* unicode listview with ansi parent window */
3597 notifyFormat = -1;
3598 hwnd = create_listview_controlW(0, hwndparent);
3599 ok(hwnd != NULL, "failed to create a listview window\n");
3600 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3601 ok(IsWindow(header), "expected header to be created\n");
3602 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3603 expect(0, r);
3604 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3605 expect(1, r);
3606 DestroyWindow(hwnd);
3607 /* unicode listview with ansi parent window, return error code */
3608 notifyFormat = 0;
3609 hwnd = create_listview_controlW(0, hwndparent);
3610 ok(hwnd != NULL, "failed to create a listview window\n");
3611 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3612 ok(IsWindow(header), "expected header to be created\n");
3613 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3614 expect(0, r);
3615 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3616 expect(1, r);
3617 DestroyWindow(hwnd);
3619 DestroyWindow(hwndparentW);
3622 static void test_indentation(void)
3624 HWND hwnd;
3625 LVITEMA item;
3626 DWORD r;
3628 hwnd = create_listview_control(0);
3629 ok(hwnd != NULL, "failed to create a listview window\n");
3631 memset(&item, 0, sizeof(item));
3632 item.mask = LVIF_INDENT;
3633 item.iItem = 0;
3634 item.iIndent = I_INDENTCALLBACK;
3635 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3636 expect(0, r);
3638 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3640 item.iItem = 0;
3641 item.mask = LVIF_INDENT;
3642 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3643 expect(TRUE, r);
3645 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3646 "get indent dispinfo", FALSE);
3648 DestroyWindow(hwnd);
3651 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
3653 return 0;
3656 static BOOL is_below_comctl_5(void)
3658 HWND hwnd;
3659 BOOL ret;
3661 hwnd = create_listview_control(0);
3662 ok(hwnd != NULL, "failed to create a listview window\n");
3663 insert_item(hwnd, 0);
3665 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
3667 DestroyWindow(hwnd);
3669 return !ret;
3672 static void test_get_set_view(void)
3674 HWND hwnd;
3675 DWORD ret;
3676 DWORD_PTR style;
3678 /* test style->view mapping */
3679 hwnd = create_listview_control(0);
3680 ok(hwnd != NULL, "failed to create a listview window\n");
3682 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3683 expect(LV_VIEW_DETAILS, ret);
3685 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3686 /* LVS_ICON == 0 */
3687 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
3688 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3689 expect(LV_VIEW_ICON, ret);
3691 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3692 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
3693 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3694 expect(LV_VIEW_SMALLICON, ret);
3696 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3697 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
3698 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3699 expect(LV_VIEW_LIST, ret);
3701 /* switching view doesn't touch window style */
3702 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
3703 expect(1, ret);
3704 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3705 ok(style & LVS_LIST, "Expected style to be preserved\n");
3706 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
3707 expect(1, ret);
3708 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3709 ok(style & LVS_LIST, "Expected style to be preserved\n");
3710 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
3711 expect(1, ret);
3712 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3713 ok(style & LVS_LIST, "Expected style to be preserved\n");
3715 DestroyWindow(hwnd);
3718 static void test_canceleditlabel(void)
3720 HWND hwnd, hwndedit;
3721 DWORD ret;
3722 CHAR buff[10];
3723 LVITEMA itema;
3724 static CHAR test[] = "test";
3725 static const CHAR test1[] = "test1";
3727 hwnd = create_listview_control(LVS_EDITLABELS);
3728 ok(hwnd != NULL, "failed to create a listview window\n");
3730 insert_item(hwnd, 0);
3732 /* try without edit created */
3733 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3734 expect(TRUE, ret);
3736 /* cancel without data change */
3737 SetFocus(hwnd);
3738 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3739 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3740 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3741 expect(TRUE, ret);
3742 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3744 /* cancel after data change */
3745 memset(&itema, 0, sizeof(itema));
3746 itema.pszText = test;
3747 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
3748 expect(TRUE, ret);
3749 SetFocus(hwnd);
3750 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3751 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3752 ret = SetWindowText(hwndedit, test1);
3753 ok(ret != 0, "Expected edit text to change\n");
3754 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3755 expect(TRUE, ret);
3756 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3757 memset(&itema, 0, sizeof(itema));
3758 itema.pszText = buff;
3759 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
3760 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
3761 expect(5, ret);
3762 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
3764 DestroyWindow(hwnd);
3767 static void test_mapidindex(void)
3769 HWND hwnd;
3770 DWORD ret;
3772 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3773 hwnd = create_listview_control(LVS_OWNERDATA);
3774 ok(hwnd != NULL, "failed to create a listview window\n");
3775 insert_item(hwnd, 0);
3776 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3777 expect(-1, ret);
3778 DestroyWindow(hwnd);
3780 hwnd = create_listview_control(0);
3781 ok(hwnd != NULL, "failed to create a listview window\n");
3783 /* LVM_MAPINDEXTOID with invalid index */
3784 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3785 expect(-1, ret);
3787 insert_item(hwnd, 0);
3788 insert_item(hwnd, 1);
3790 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
3791 expect(-1, ret);
3792 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
3793 expect(-1, ret);
3795 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3796 expect(0, ret);
3797 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3798 expect(1, ret);
3799 /* remove 0 indexed item, id retained */
3800 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
3801 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3802 expect(1, ret);
3803 /* new id starts from previous value */
3804 insert_item(hwnd, 1);
3805 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3806 expect(2, ret);
3808 /* get index by id */
3809 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
3810 expect(-1, ret);
3811 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
3812 expect(-1, ret);
3813 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
3814 expect(0, ret);
3815 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
3816 expect(1, ret);
3818 DestroyWindow(hwnd);
3821 static void test_getitemspacing(void)
3823 HWND hwnd;
3824 DWORD ret;
3825 INT cx, cy;
3826 HIMAGELIST himl;
3827 HBITMAP hbmp;
3828 LVITEMA itema;
3830 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
3831 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
3833 /* LVS_ICON */
3834 hwnd = create_custom_listview_control(0);
3835 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3836 todo_wine {
3837 expect(cx, LOWORD(ret));
3838 expect(cy, HIWORD(ret));
3840 /* now try with icons */
3841 himl = ImageList_Create(40, 40, 0, 4, 4);
3842 ok(himl != NULL, "failed to create imagelist\n");
3843 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
3844 ok(hbmp != NULL, "failed to create bitmap\n");
3845 ret = ImageList_Add(himl, hbmp, 0);
3846 expect(0, ret);
3847 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
3848 expect(0, ret);
3850 itema.mask = LVIF_IMAGE;
3851 itema.iImage = 0;
3852 itema.iItem = 0;
3853 itema.iSubItem = 0;
3854 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
3855 expect(0, ret);
3856 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3857 todo_wine {
3858 /* spacing + icon size returned */
3859 expect(cx + 40, LOWORD(ret));
3860 expect(cy + 40, HIWORD(ret));
3862 DestroyWindow(hwnd);
3863 /* LVS_SMALLICON */
3864 hwnd = create_custom_listview_control(LVS_SMALLICON);
3865 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3866 todo_wine {
3867 expect(cx, LOWORD(ret));
3868 expect(cy, HIWORD(ret));
3870 DestroyWindow(hwnd);
3871 /* LVS_REPORT */
3872 hwnd = create_custom_listview_control(LVS_REPORT);
3873 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3874 todo_wine {
3875 expect(cx, LOWORD(ret));
3876 expect(cy, HIWORD(ret));
3878 DestroyWindow(hwnd);
3879 /* LVS_LIST */
3880 hwnd = create_custom_listview_control(LVS_LIST);
3881 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3882 todo_wine {
3883 expect(cx, LOWORD(ret));
3884 expect(cy, HIWORD(ret));
3886 DestroyWindow(hwnd);
3889 static void test_getcolumnwidth(void)
3891 HWND hwnd;
3892 DWORD ret;
3893 DWORD_PTR style;
3894 LVCOLUMNA col;
3896 /* default column width */
3897 hwnd = create_custom_listview_control(0);
3898 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3899 expect(0, ret);
3900 style = GetWindowLong(hwnd, GWL_STYLE);
3901 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
3902 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3903 todo_wine expect(8, ret);
3904 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
3905 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
3906 col.mask = 0;
3907 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
3908 expect(0, ret);
3909 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3910 expect(10, ret);
3911 DestroyWindow(hwnd);
3914 static void test_scrollnotify(void)
3916 HWND hwnd;
3917 DWORD ret;
3919 hwnd = create_listview_control(0);
3921 insert_column(hwnd, 0);
3922 insert_column(hwnd, 1);
3923 insert_item(hwnd, 0);
3925 /* make it scrollable - resize */
3926 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3927 expect(TRUE, ret);
3928 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3929 expect(TRUE, ret);
3931 /* try with dummy call */
3932 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3933 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
3934 expect(TRUE, ret);
3935 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
3936 "scroll notify 1", TRUE);
3938 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3939 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
3940 expect(TRUE, ret);
3941 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
3942 "scroll notify 2", TRUE);
3944 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3945 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
3946 expect(TRUE, ret);
3947 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
3948 "scroll notify 3", TRUE);
3950 DestroyWindow(hwnd);
3953 START_TEST(listview)
3955 HMODULE hComctl32;
3956 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
3958 ULONG_PTR ctx_cookie;
3959 HWND hwnd;
3961 hComctl32 = GetModuleHandleA("comctl32.dll");
3962 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
3963 if (pInitCommonControlsEx)
3965 INITCOMMONCONTROLSEX iccex;
3966 iccex.dwSize = sizeof(iccex);
3967 iccex.dwICC = ICC_LISTVIEW_CLASSES;
3968 pInitCommonControlsEx(&iccex);
3970 else
3971 InitCommonControls();
3973 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
3975 hwndparent = create_parent_window(FALSE);
3976 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3978 g_is_below_5 = is_below_comctl_5();
3980 test_images();
3981 test_checkboxes();
3982 test_items();
3983 test_create();
3984 test_redraw();
3985 test_customdraw();
3986 test_icon_spacing();
3987 test_color();
3988 test_item_count();
3989 test_item_position();
3990 test_columns();
3991 test_getorigin();
3992 test_multiselect();
3993 test_getitemrect();
3994 test_subitem_rect();
3995 test_sorting();
3996 test_ownerdata();
3997 test_norecompute();
3998 test_nosortheader();
3999 test_setredraw();
4000 test_hittest();
4001 test_getviewrect();
4002 test_getitemposition();
4003 test_columnscreation();
4004 test_editbox();
4005 test_notifyformat();
4006 test_indentation();
4007 test_getitemspacing();
4008 test_getcolumnwidth();
4010 if (!load_v6_module(&ctx_cookie))
4012 DestroyWindow(hwndparent);
4013 return;
4016 /* this is a XP SP3 failure workaround */
4017 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
4018 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
4019 0, 0, 100, 100,
4020 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
4021 if (!IsWindow(hwnd))
4023 win_skip("FIXME: failed to create ListView window.\n");
4024 unload_v6_module(ctx_cookie);
4025 return;
4027 else
4028 DestroyWindow(hwnd);
4030 /* comctl32 version 6 tests start here */
4031 test_get_set_view();
4032 test_canceleditlabel();
4033 test_mapidindex();
4034 test_scrollnotify();
4036 unload_v6_module(ctx_cookie);
4038 DestroyWindow(hwndparent);