push 5aff8350ceade24f8243f07a9cf7ecb816236fb1
[wine/hacks.git] / dlls / comctl32 / tests / listview.c
blob72abdff47b000a120c187c4e0834e0064c477398
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 "msg.h"
29 #define PARENT_SEQ_INDEX 0
30 #define PARENT_FULL_SEQ_INDEX 1
31 #define LISTVIEW_SEQ_INDEX 2
32 #define EDITBOX_SEQ_INDEX 3
33 #define NUM_MSG_SEQUENCES 4
35 #define LISTVIEW_ID 0
36 #define HEADER_ID 1
38 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
39 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
40 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
42 #ifdef __i386__
43 #define ARCH "x86"
44 #elif defined __x86_64__
45 #define ARCH "amd64"
46 #else
47 #define ARCH "none"
48 #endif
50 static const CHAR manifest_name[] = "cc6.manifest";
52 static const CHAR manifest[] =
53 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
54 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">\n"
55 " <assemblyIdentity\n"
56 " type=\"win32\"\n"
57 " name=\"Wine.ComCtl32.Tests\"\n"
58 " version=\"1.0.0.0\"\n"
59 " processorArchitecture=\"" ARCH "\"\n"
60 " />\n"
61 "<description>Wine comctl32 test suite</description>\n"
62 "<dependency>\n"
63 " <dependentAssembly>\n"
64 " <assemblyIdentity\n"
65 " type=\"win32\"\n"
66 " name=\"microsoft.windows.common-controls\"\n"
67 " version=\"6.0.0.0\"\n"
68 " processorArchitecture=\"" ARCH "\"\n"
69 " publicKeyToken=\"6595b64144ccf1df\"\n"
70 " language=\"*\"\n"
71 " />\n"
72 "</dependentAssembly>\n"
73 "</dependency>\n"
74 "</assembly>\n";
76 static const WCHAR testparentclassW[] =
77 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
79 HWND hwndparent, hwndparentW;
80 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
81 BOOL blockEdit;
82 /* dumps LVN_ITEMCHANGED message data */
83 static BOOL g_dump_itemchanged;
84 /* format reported to control:
85 -1 falls to defproc, anything else returned */
86 INT notifyFormat;
87 /* indicates we're running < 5.80 version */
88 BOOL g_is_below_5;
90 static HWND subclass_editbox(HWND hwndListview);
92 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
94 static const struct message create_ownerdrawfixed_parent_seq[] = {
95 { WM_NOTIFYFORMAT, sent },
96 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
97 { WM_MEASUREITEM, sent },
98 { WM_PARENTNOTIFY, sent },
99 { 0 }
102 static const struct message redraw_listview_seq[] = {
103 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
104 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
105 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
106 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, HEADER_ID },
107 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
108 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
109 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
110 { 0 }
113 static const struct message listview_icon_spacing_seq[] = {
114 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
115 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
116 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
117 { 0 }
120 static const struct message listview_color_seq[] = {
121 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
122 { LVM_GETBKCOLOR, sent },
123 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
124 { LVM_GETTEXTCOLOR, sent },
125 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
126 { LVM_GETTEXTBKCOLOR, sent },
128 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
129 { LVM_GETBKCOLOR, sent },
130 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
131 { LVM_GETTEXTCOLOR, sent },
132 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
133 { LVM_GETTEXTBKCOLOR, sent },
135 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
136 { LVM_GETBKCOLOR, sent },
137 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
138 { LVM_GETTEXTCOLOR, sent },
139 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
140 { LVM_GETTEXTBKCOLOR, sent },
142 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
143 { LVM_GETBKCOLOR, sent },
144 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
145 { LVM_GETTEXTCOLOR, sent },
146 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
147 { LVM_GETTEXTBKCOLOR, sent },
148 { 0 }
151 static const struct message listview_item_count_seq[] = {
152 { LVM_GETITEMCOUNT, sent },
153 { LVM_INSERTITEM, sent },
154 { LVM_INSERTITEM, sent },
155 { LVM_INSERTITEM, sent },
156 { LVM_GETITEMCOUNT, sent },
157 { LVM_DELETEITEM, sent|wparam, 2 },
158 { LVM_GETITEMCOUNT, sent },
159 { LVM_DELETEALLITEMS, sent },
160 { LVM_GETITEMCOUNT, sent },
161 { LVM_INSERTITEM, sent },
162 { LVM_INSERTITEM, sent },
163 { LVM_GETITEMCOUNT, sent },
164 { LVM_INSERTITEM, sent },
165 { LVM_GETITEMCOUNT, sent },
166 { 0 }
169 static const struct message listview_itempos_seq[] = {
170 { LVM_INSERTITEM, sent },
171 { LVM_INSERTITEM, sent },
172 { LVM_INSERTITEM, sent },
173 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
174 { LVM_GETITEMPOSITION, sent|wparam, 1 },
175 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
176 { LVM_GETITEMPOSITION, sent|wparam, 2 },
177 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
178 { LVM_GETITEMPOSITION, sent|wparam, 0 },
179 { 0 }
182 static const struct message listview_ownerdata_switchto_seq[] = {
183 { WM_STYLECHANGING, sent },
184 { WM_STYLECHANGED, sent },
185 { 0 }
188 static const struct message listview_getorderarray_seq[] = {
189 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
190 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
191 { 0 }
194 static const struct message empty_seq[] = {
195 { 0 }
198 static const struct message forward_erasebkgnd_parent_seq[] = {
199 { WM_ERASEBKGND, sent },
200 { 0 }
203 static const struct message ownderdata_select_focus_parent_seq[] = {
204 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
205 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
206 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
207 { 0 }
210 static const struct message ownerdata_setstate_all_parent_seq[] = {
211 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
212 { 0 }
215 static const struct message ownerdata_defocus_all_parent_seq[] = {
216 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
217 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
218 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
219 { 0 }
222 static const struct message ownerdata_deselect_all_parent_seq[] = {
223 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
224 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
225 { 0 }
228 static const struct message select_all_parent_seq[] = {
229 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
230 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
232 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
233 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
235 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
236 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
238 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
239 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
241 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
242 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
243 { 0 }
246 static const struct message textcallback_set_again_parent_seq[] = {
247 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
248 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
249 { 0 }
252 static const struct message single_getdispinfo_parent_seq[] = {
253 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
254 { 0 }
257 static const struct message getitemposition_seq1[] = {
258 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
259 { 0 }
262 static const struct message getitemposition_seq2[] = {
263 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
264 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
265 { 0 }
268 static const struct message editbox_create_pos[] = {
269 /* sequence sent after LVN_BEGINLABELEDIT */
270 /* next two are 4.7x specific */
271 { WM_WINDOWPOSCHANGING, sent },
272 { WM_WINDOWPOSCHANGED, sent|optional },
274 { WM_WINDOWPOSCHANGING, sent|optional },
275 { WM_NCCALCSIZE, sent },
276 { WM_WINDOWPOSCHANGED, sent },
277 { WM_MOVE, sent|defwinproc },
278 { WM_SIZE, sent|defwinproc },
279 /* the rest is todo, skipped in 4.7x */
280 { WM_WINDOWPOSCHANGING, sent|optional },
281 { WM_WINDOWPOSCHANGED, sent|optional },
282 { 0 }
285 static const struct message scroll_parent_seq[] = {
286 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
287 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
288 { 0 }
291 struct subclass_info
293 WNDPROC oldproc;
296 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
298 static LONG defwndproc_counter = 0;
299 LRESULT ret;
300 struct message msg;
302 msg.message = message;
303 msg.flags = sent|wparam|lparam;
304 if (defwndproc_counter) msg.flags |= defwinproc;
305 msg.wParam = wParam;
306 msg.lParam = lParam;
307 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
309 /* log system messages, except for painting */
310 if (message < WM_USER &&
311 message != WM_PAINT &&
312 message != WM_ERASEBKGND &&
313 message != WM_NCPAINT &&
314 message != WM_NCHITTEST &&
315 message != WM_GETTEXT &&
316 message != WM_GETICON &&
317 message != WM_DEVICECHANGE)
319 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
321 add_message(sequences, PARENT_SEQ_INDEX, &msg);
323 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
325 switch (message)
327 case WM_NOTIFY:
329 switch (((NMHDR*)lParam)->code)
331 case LVN_BEGINLABELEDIT:
332 /* subclass edit box */
333 if (!blockEdit)
334 subclass_editbox(((NMHDR*)lParam)->hwndFrom);
336 return blockEdit;
338 case LVN_ENDLABELEDIT:
339 /* always accept new item text */
340 return TRUE;
341 case LVN_BEGINSCROLL:
342 case LVN_ENDSCROLL:
344 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
346 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
347 "BEGIN" : "END", pScroll->dx, pScroll->dy);
349 break;
350 case LVN_ITEMCHANGED:
351 if (g_dump_itemchanged)
353 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
354 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
355 nmlv->iItem, nmlv->uNewState, nmlv->uOldState, nmlv->uChanged);
357 break;
359 break;
361 case WM_NOTIFYFORMAT:
363 /* force to return format */
364 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
365 break;
369 defwndproc_counter++;
370 ret = DefWindowProcA(hwnd, message, wParam, lParam);
371 defwndproc_counter--;
373 return ret;
376 static BOOL register_parent_wnd_class(BOOL Unicode)
378 WNDCLASSA clsA;
379 WNDCLASSW clsW;
381 if (Unicode)
383 clsW.style = 0;
384 clsW.lpfnWndProc = parent_wnd_proc;
385 clsW.cbClsExtra = 0;
386 clsW.cbWndExtra = 0;
387 clsW.hInstance = GetModuleHandleW(NULL);
388 clsW.hIcon = 0;
389 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
390 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
391 clsW.lpszMenuName = NULL;
392 clsW.lpszClassName = testparentclassW;
394 else
396 clsA.style = 0;
397 clsA.lpfnWndProc = parent_wnd_proc;
398 clsA.cbClsExtra = 0;
399 clsA.cbWndExtra = 0;
400 clsA.hInstance = GetModuleHandleA(NULL);
401 clsA.hIcon = 0;
402 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
403 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
404 clsA.lpszMenuName = NULL;
405 clsA.lpszClassName = "Listview test parent class";
408 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
411 static HWND create_parent_window(BOOL Unicode)
413 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W'};
415 if (!register_parent_wnd_class(Unicode))
416 return NULL;
418 blockEdit = FALSE;
419 notifyFormat = -1;
421 if (Unicode)
422 return CreateWindowExW(0, testparentclassW, nameW,
423 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
424 WS_MAXIMIZEBOX | WS_VISIBLE,
425 0, 0, 100, 100,
426 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
427 else
428 return CreateWindowExA(0, "Listview test parent class",
429 "Listview test parent window",
430 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
431 WS_MAXIMIZEBOX | WS_VISIBLE,
432 0, 0, 100, 100,
433 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
436 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
438 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
439 static LONG defwndproc_counter = 0;
440 LRESULT ret;
441 struct message msg;
443 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
445 /* some debug output for style changing */
446 if ((message == WM_STYLECHANGING ||
447 message == WM_STYLECHANGED) && lParam)
449 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
450 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
453 msg.message = message;
454 msg.flags = sent|wparam|lparam;
455 if (defwndproc_counter) msg.flags |= defwinproc;
456 msg.wParam = wParam;
457 msg.lParam = lParam;
458 msg.id = LISTVIEW_ID;
459 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
461 defwndproc_counter++;
462 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
463 defwndproc_counter--;
464 return ret;
467 static HWND create_listview_control(DWORD style)
469 struct subclass_info *info;
470 HWND hwnd;
471 RECT rect;
473 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
474 if (!info)
475 return NULL;
477 GetClientRect(hwndparent, &rect);
478 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
479 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
480 0, 0, rect.right, rect.bottom,
481 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
482 ok(hwnd != NULL, "gle=%d\n", GetLastError());
484 if (!hwnd)
486 HeapFree(GetProcessHeap(), 0, info);
487 return NULL;
490 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
491 (LONG_PTR)listview_subclass_proc);
492 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
494 return hwnd;
497 /* unicode listview window with specified parent */
498 static HWND create_listview_controlW(DWORD style, HWND parent)
500 struct subclass_info *info;
501 HWND hwnd;
502 RECT rect;
503 static const WCHAR nameW[] = {'f','o','o',0};
505 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
506 if (!info)
507 return NULL;
509 GetClientRect(parent, &rect);
510 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
511 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
512 0, 0, rect.right, rect.bottom,
513 parent, NULL, GetModuleHandleW(NULL), NULL);
514 ok(hwnd != NULL, "gle=%d\n", GetLastError());
516 if (!hwnd)
518 HeapFree(GetProcessHeap(), 0, info);
519 return NULL;
522 info->oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
523 (LONG_PTR)listview_subclass_proc);
524 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)info);
526 return hwnd;
529 static HWND create_custom_listview_control(DWORD style)
531 struct subclass_info *info;
532 HWND hwnd;
533 RECT rect;
535 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
536 if (!info)
537 return NULL;
539 GetClientRect(hwndparent, &rect);
540 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
541 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
542 0, 0, rect.right, rect.bottom,
543 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
544 ok(hwnd != NULL, "gle=%d\n", GetLastError());
546 if (!hwnd)
548 HeapFree(GetProcessHeap(), 0, info);
549 return NULL;
552 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
553 (LONG_PTR)listview_subclass_proc);
554 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
556 return hwnd;
559 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
561 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
562 static LONG defwndproc_counter = 0;
563 LRESULT ret;
564 struct message msg;
566 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
568 msg.message = message;
569 msg.flags = sent|wparam|lparam;
570 if (defwndproc_counter) msg.flags |= defwinproc;
571 msg.wParam = wParam;
572 msg.lParam = lParam;
573 msg.id = HEADER_ID;
574 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
576 defwndproc_counter++;
577 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
578 defwndproc_counter--;
579 return ret;
582 static HWND subclass_header(HWND hwndListview)
584 struct subclass_info *info;
585 HWND hwnd;
587 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
588 if (!info)
589 return NULL;
591 hwnd = ListView_GetHeader(hwndListview);
592 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
593 (LONG_PTR)header_subclass_proc);
594 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
596 return hwnd;
599 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
601 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
602 static LONG defwndproc_counter = 0;
603 LRESULT ret;
604 struct message msg;
606 msg.message = message;
607 msg.flags = sent|wparam|lparam;
608 if (defwndproc_counter) msg.flags |= defwinproc;
609 msg.wParam = wParam;
610 msg.lParam = lParam;
612 /* all we need is sizing */
613 if (message == WM_WINDOWPOSCHANGING ||
614 message == WM_NCCALCSIZE ||
615 message == WM_WINDOWPOSCHANGED ||
616 message == WM_MOVE ||
617 message == WM_SIZE)
619 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
622 defwndproc_counter++;
623 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
624 defwndproc_counter--;
625 return ret;
628 static HWND subclass_editbox(HWND hwndListview)
630 struct subclass_info *info;
631 HWND hwnd;
633 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
634 if (!info)
635 return NULL;
637 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
638 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
639 (LONG_PTR)editbox_subclass_proc);
640 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
642 return hwnd;
645 /* Performs a single LVM_HITTEST test */
646 static void test_lvm_hittest(HWND hwnd, INT x, INT y, INT item, UINT flags,
647 BOOL todo_item, BOOL todo_flags, int line)
649 LVHITTESTINFO lpht;
650 DWORD ret;
652 lpht.pt.x = x;
653 lpht.pt.y = y;
654 lpht.iSubItem = 10;
656 trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
657 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
659 if (todo_item)
661 todo_wine
663 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
664 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
665 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
668 else
670 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
671 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
672 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
675 if (todo_flags)
677 todo_wine
678 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
680 else
681 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
684 /* Performs a single LVM_SUBITEMHITTEST test */
685 static void test_lvm_subitemhittest(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
686 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
688 LVHITTESTINFO lpht;
689 DWORD ret;
691 lpht.pt.x = x;
692 lpht.pt.y = y;
694 trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
695 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
697 if (todo_item)
699 todo_wine
701 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
702 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
705 else
707 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
708 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
711 if (todo_subitem)
713 todo_wine
714 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
716 else
717 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
719 if (todo_flags)
721 todo_wine
722 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
724 else
725 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
728 static void test_images(void)
730 HWND hwnd;
731 DWORD r;
732 LVITEM item;
733 HIMAGELIST himl;
734 HBITMAP hbmp;
735 RECT r1, r2;
736 static CHAR hello[] = "hello";
738 himl = ImageList_Create(40, 40, 0, 4, 4);
739 ok(himl != NULL, "failed to create imagelist\n");
741 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
742 ok(hbmp != NULL, "failed to create bitmap\n");
744 r = ImageList_Add(himl, hbmp, 0);
745 ok(r == 0, "should be zero\n");
747 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
748 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
749 ok(hwnd != NULL, "failed to create listview window\n");
751 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
752 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
754 ok(r == 0, "should return zero\n");
756 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
757 ok(r == 0, "should return zero\n");
759 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
760 /* returns dimensions */
762 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
763 ok(r == 0, "should be zero items\n");
765 item.mask = LVIF_IMAGE | LVIF_TEXT;
766 item.iItem = 0;
767 item.iSubItem = 1;
768 item.iImage = 0;
769 item.pszText = 0;
770 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
771 ok(r == -1, "should fail\n");
773 item.iSubItem = 0;
774 item.pszText = hello;
775 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
776 ok(r == 0, "should not fail\n");
778 memset(&r1, 0, sizeof r1);
779 r1.left = LVIR_ICON;
780 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
782 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
783 ok(r == TRUE, "should not fail\n");
785 item.iSubItem = 0;
786 item.pszText = hello;
787 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
788 ok(r == 0, "should not fail\n");
790 memset(&r2, 0, sizeof r2);
791 r2.left = LVIR_ICON;
792 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
794 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
796 DestroyWindow(hwnd);
799 static void test_checkboxes(void)
801 HWND hwnd;
802 LVITEMA item;
803 DWORD r;
804 static CHAR text[] = "Text",
805 text2[] = "Text2",
806 text3[] = "Text3";
808 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
809 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
810 ok(hwnd != NULL, "failed to create listview window\n");
812 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
813 item.mask = LVIF_TEXT | LVIF_STATE;
814 item.stateMask = 0xffff;
815 item.state = 0xfccc;
816 item.iItem = 0;
817 item.iSubItem = 0;
818 item.pszText = text;
819 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
820 ok(r == 0, "ret %d\n", r);
822 item.iItem = 0;
823 item.mask = LVIF_STATE;
824 item.stateMask = 0xffff;
825 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
826 ok(item.state == 0xfccc, "state %x\n", item.state);
828 /* Don't set LVIF_STATE */
829 item.mask = LVIF_TEXT;
830 item.stateMask = 0xffff;
831 item.state = 0xfccc;
832 item.iItem = 1;
833 item.iSubItem = 0;
834 item.pszText = text;
835 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
836 ok(r == 1, "ret %d\n", r);
838 item.iItem = 1;
839 item.mask = LVIF_STATE;
840 item.stateMask = 0xffff;
841 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
842 ok(item.state == 0, "state %x\n", item.state);
844 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
845 ok(r == 0, "should return zero\n");
847 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
848 item.iItem = 0;
849 item.mask = LVIF_STATE;
850 item.stateMask = 0xffff;
851 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
852 ok(item.state == 0x1ccc, "state %x\n", item.state);
854 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
855 item.iItem = 2;
856 item.mask = LVIF_TEXT;
857 item.state = 0;
858 item.pszText = text2;
859 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
860 ok(r == 2, "ret %d\n", r);
862 item.iItem = 2;
863 item.mask = LVIF_STATE;
864 item.stateMask = 0xffff;
865 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
866 ok(item.state == 0x1000, "state %x\n", item.state);
868 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
869 item.iItem = 3;
870 item.mask = LVIF_TEXT | LVIF_STATE;
871 item.stateMask = 0xffff;
872 item.state = 0x2aaa;
873 item.pszText = text3;
874 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
875 ok(r == 3, "ret %d\n", r);
877 item.iItem = 3;
878 item.mask = LVIF_STATE;
879 item.stateMask = 0xffff;
880 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
881 ok(item.state == 0x1aaa, "state %x\n", item.state);
883 /* Set an item's state to checked */
884 item.iItem = 3;
885 item.mask = LVIF_STATE;
886 item.stateMask = 0xf000;
887 item.state = 0x2000;
888 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
890 item.iItem = 3;
891 item.mask = LVIF_STATE;
892 item.stateMask = 0xffff;
893 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
894 ok(item.state == 0x2aaa, "state %x\n", item.state);
896 /* Check that only the bits we asked for are returned,
897 * and that all the others are set to zero
899 item.iItem = 3;
900 item.mask = LVIF_STATE;
901 item.stateMask = 0xf000;
902 item.state = 0xffff;
903 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
904 ok(item.state == 0x2000, "state %x\n", item.state);
906 /* Set the style again and check that doesn't change an item's state */
907 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
908 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
910 item.iItem = 3;
911 item.mask = LVIF_STATE;
912 item.stateMask = 0xffff;
913 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
914 ok(item.state == 0x2aaa, "state %x\n", item.state);
916 /* Unsetting the checkbox extended style doesn't change an item's state */
917 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
918 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
920 item.iItem = 3;
921 item.mask = LVIF_STATE;
922 item.stateMask = 0xffff;
923 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
924 ok(item.state == 0x2aaa, "state %x\n", item.state);
926 /* Now setting the style again will change an item's state */
927 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
928 ok(r == 0, "ret %x\n", r);
930 item.iItem = 3;
931 item.mask = LVIF_STATE;
932 item.stateMask = 0xffff;
933 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
934 ok(item.state == 0x1aaa, "state %x\n", item.state);
936 /* Toggle checkbox tests (bug 9934) */
937 memset (&item, 0xcc, sizeof(item));
938 item.mask = LVIF_STATE;
939 item.iItem = 3;
940 item.iSubItem = 0;
941 item.state = LVIS_FOCUSED;
942 item.stateMask = LVIS_FOCUSED;
943 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
944 expect(1, r);
946 item.iItem = 3;
947 item.mask = LVIF_STATE;
948 item.stateMask = 0xffff;
949 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
950 ok(item.state == 0x1aab, "state %x\n", item.state);
952 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
953 expect(0, r);
954 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
955 expect(0, r);
957 item.iItem = 3;
958 item.mask = LVIF_STATE;
959 item.stateMask = 0xffff;
960 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
961 ok(item.state == 0x2aab, "state %x\n", item.state);
963 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
964 expect(0, r);
965 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
966 expect(0, r);
968 item.iItem = 3;
969 item.mask = LVIF_STATE;
970 item.stateMask = 0xffff;
971 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
972 ok(item.state == 0x1aab, "state %x\n", item.state);
974 DestroyWindow(hwnd);
977 static void insert_column(HWND hwnd, int idx)
979 LVCOLUMN column;
980 DWORD rc;
982 memset(&column, 0xcc, sizeof(column));
983 column.mask = LVCF_SUBITEM;
984 column.iSubItem = idx;
986 rc = ListView_InsertColumn(hwnd, idx, &column);
987 expect(idx, rc);
990 static void insert_item(HWND hwnd, int idx)
992 static CHAR text[] = "foo";
994 LVITEMA item;
995 DWORD rc;
997 memset(&item, 0xcc, sizeof (item));
998 item.mask = LVIF_TEXT;
999 item.iItem = idx;
1000 item.iSubItem = 0;
1001 item.pszText = text;
1003 rc = ListView_InsertItem(hwnd, &item);
1004 expect(idx, rc);
1007 static void test_items(void)
1009 const LPARAM lparamTest = 0x42;
1010 HWND hwnd;
1011 LVITEMA item;
1012 DWORD r;
1013 static CHAR text[] = "Text";
1015 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1016 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1017 ok(hwnd != NULL, "failed to create listview window\n");
1020 * Test setting/getting item params
1023 /* Set up two columns */
1024 insert_column(hwnd, 0);
1025 insert_column(hwnd, 1);
1027 /* LVIS_SELECTED with zero stateMask */
1028 /* set */
1029 memset (&item, 0, sizeof (item));
1030 item.mask = LVIF_STATE;
1031 item.state = LVIS_SELECTED;
1032 item.stateMask = 0;
1033 item.iItem = 0;
1034 item.iSubItem = 0;
1035 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1036 ok(r == 0, "ret %d\n", r);
1037 /* get */
1038 memset (&item, 0xcc, sizeof (item));
1039 item.mask = LVIF_STATE;
1040 item.stateMask = LVIS_SELECTED;
1041 item.state = 0;
1042 item.iItem = 0;
1043 item.iSubItem = 0;
1044 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1045 ok(r != 0, "ret %d\n", r);
1046 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1047 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1049 /* LVIS_SELECTED with zero stateMask */
1050 /* set */
1051 memset (&item, 0, sizeof (item));
1052 item.mask = LVIF_STATE;
1053 item.state = LVIS_FOCUSED;
1054 item.stateMask = 0;
1055 item.iItem = 0;
1056 item.iSubItem = 0;
1057 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1058 ok(r == 0, "ret %d\n", r);
1059 /* get */
1060 memset (&item, 0xcc, sizeof (item));
1061 item.mask = LVIF_STATE;
1062 item.stateMask = LVIS_FOCUSED;
1063 item.state = 0;
1064 item.iItem = 0;
1065 item.iSubItem = 0;
1066 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1067 ok(r != 0, "ret %d\n", r);
1068 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1069 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1071 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1072 /* set */
1073 memset (&item, 0, sizeof (item));
1074 item.mask = LVIF_STATE;
1075 item.state = LVIS_CUT;
1076 item.stateMask = LVIS_FOCUSED;
1077 item.iItem = 0;
1078 item.iSubItem = 0;
1079 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1080 ok(r == 0, "ret %d\n", r);
1081 /* get */
1082 memset (&item, 0xcc, sizeof (item));
1083 item.mask = LVIF_STATE;
1084 item.stateMask = LVIS_CUT;
1085 item.state = 0;
1086 item.iItem = 0;
1087 item.iSubItem = 0;
1088 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1089 ok(r != 0, "ret %d\n", r);
1090 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1091 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1093 /* Insert an item with just a param */
1094 memset (&item, 0xcc, sizeof (item));
1095 item.mask = LVIF_PARAM;
1096 item.iItem = 0;
1097 item.iSubItem = 0;
1098 item.lParam = lparamTest;
1099 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1100 ok(r == 0, "ret %d\n", r);
1102 /* Test getting of the param */
1103 memset (&item, 0xcc, sizeof (item));
1104 item.mask = LVIF_PARAM;
1105 item.iItem = 0;
1106 item.iSubItem = 0;
1107 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1108 ok(r != 0, "ret %d\n", r);
1109 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1111 /* Set up a subitem */
1112 memset (&item, 0xcc, sizeof (item));
1113 item.mask = LVIF_TEXT;
1114 item.iItem = 0;
1115 item.iSubItem = 1;
1116 item.pszText = text;
1117 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1118 ok(r != 0, "ret %d\n", r);
1120 /* Query param from subitem: returns main item param */
1121 memset (&item, 0xcc, sizeof (item));
1122 item.mask = LVIF_PARAM;
1123 item.iItem = 0;
1124 item.iSubItem = 1;
1125 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1126 ok(r != 0, "ret %d\n", r);
1127 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1129 /* Set up param on first subitem: no effect */
1130 memset (&item, 0xcc, sizeof (item));
1131 item.mask = LVIF_PARAM;
1132 item.iItem = 0;
1133 item.iSubItem = 1;
1134 item.lParam = lparamTest+1;
1135 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1136 ok(r == 0, "ret %d\n", r);
1138 /* Query param from subitem again: should still return main item param */
1139 memset (&item, 0xcc, sizeof (item));
1140 item.mask = LVIF_PARAM;
1141 item.iItem = 0;
1142 item.iSubItem = 1;
1143 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1144 ok(r != 0, "ret %d\n", r);
1145 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1147 /**** Some tests of state highlighting ****/
1148 memset (&item, 0xcc, sizeof (item));
1149 item.mask = LVIF_STATE;
1150 item.iItem = 0;
1151 item.iSubItem = 0;
1152 item.state = LVIS_SELECTED;
1153 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1154 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1155 ok(r != 0, "ret %d\n", r);
1156 item.iSubItem = 1;
1157 item.state = LVIS_DROPHILITED;
1158 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1159 ok(r != 0, "ret %d\n", r);
1161 memset (&item, 0xcc, sizeof (item));
1162 item.mask = LVIF_STATE;
1163 item.iItem = 0;
1164 item.iSubItem = 0;
1165 item.stateMask = -1;
1166 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1167 ok(r != 0, "ret %d\n", r);
1168 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1169 item.iSubItem = 1;
1170 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1171 ok(r != 0, "ret %d\n", r);
1172 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1174 /* some notnull but meaningless masks */
1175 memset (&item, 0, sizeof(item));
1176 item.mask = LVIF_NORECOMPUTE;
1177 item.iItem = 0;
1178 item.iSubItem = 0;
1179 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1180 ok(r != 0, "ret %d\n", r);
1181 memset (&item, 0, sizeof(item));
1182 item.mask = LVIF_DI_SETITEM;
1183 item.iItem = 0;
1184 item.iSubItem = 0;
1185 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1186 ok(r != 0, "ret %d\n", r);
1188 /* set text to callback value already having it */
1189 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1190 expect(TRUE, r);
1191 memset (&item, 0, sizeof (item));
1192 item.mask = LVIF_TEXT;
1193 item.pszText = LPSTR_TEXTCALLBACK;
1194 item.iItem = 0;
1195 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1196 ok(r == 0, "ret %d\n", r);
1197 memset (&item, 0, sizeof (item));
1199 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1201 item.pszText = LPSTR_TEXTCALLBACK;
1202 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1203 expect(TRUE, r);
1205 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1206 "check callback text comparison rule", FALSE);
1208 DestroyWindow(hwnd);
1211 static void test_columns(void)
1213 HWND hwnd, hwndheader;
1214 LVCOLUMN column;
1215 DWORD rc;
1216 INT order[2];
1218 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1219 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1220 ok(hwnd != NULL, "failed to create listview window\n");
1222 /* Add a column with no mask */
1223 memset(&column, 0xcc, sizeof(column));
1224 column.mask = 0;
1225 rc = ListView_InsertColumn(hwnd, 0, &column);
1226 ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
1228 /* Check its width */
1229 rc = ListView_GetColumnWidth(hwnd, 0);
1230 ok(rc==10 ||
1231 broken(rc==0), /* win9x */
1232 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1234 DestroyWindow(hwnd);
1236 /* LVM_GETCOLUMNORDERARRAY */
1237 hwnd = create_listview_control(0);
1238 hwndheader = subclass_header(hwnd);
1240 memset(&column, 0, sizeof(column));
1241 column.mask = LVCF_WIDTH;
1242 column.cx = 100;
1243 rc = ListView_InsertColumn(hwnd, 0, &column);
1244 ok(rc == 0, "Inserting column failed with %d\n", rc);
1246 column.cx = 200;
1247 rc = ListView_InsertColumn(hwnd, 1, &column);
1248 ok(rc == 1, "Inserting column failed with %d\n", rc);
1250 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1252 rc = SendMessage(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1253 ok(rc != 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1254 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1255 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1257 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1259 DestroyWindow(hwnd);
1261 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1262 static WNDPROC listviewWndProc;
1263 static HIMAGELIST test_create_imagelist;
1265 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1267 LRESULT ret;
1269 if (uMsg == WM_CREATE)
1271 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1272 lpcs->style |= LVS_REPORT;
1274 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1275 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1276 return ret;
1279 static void test_create(void)
1281 HWND hList;
1282 HWND hHeader;
1283 LONG_PTR ret;
1284 LONG r;
1285 LVCOLUMNA col;
1286 RECT rect;
1287 WNDCLASSEX cls;
1288 cls.cbSize = sizeof(WNDCLASSEX);
1289 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1290 listviewWndProc = cls.lpfnWndProc;
1291 cls.lpfnWndProc = create_test_wndproc;
1292 cls.lpszClassName = "MyListView32";
1293 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1295 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1296 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1297 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1298 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1299 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1300 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1301 DestroyWindow(hList);
1303 /* header isn't created on LVS_ICON and LVS_LIST styles */
1304 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1305 GetModuleHandle(NULL), 0);
1306 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1307 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1308 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1309 /* insert column */
1310 memset(&col, 0, sizeof(LVCOLUMNA));
1311 col.mask = LVCF_WIDTH;
1312 col.cx = 100;
1313 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1314 ok(r == 0, "Expected 0 column's inserted\n");
1315 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1316 ok(IsWindow(hHeader), "Header should be created\n");
1317 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1318 DestroyWindow(hList);
1320 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1321 GetModuleHandle(NULL), 0);
1322 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1323 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1324 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1325 /* insert column */
1326 memset(&col, 0, sizeof(LVCOLUMNA));
1327 col.mask = LVCF_WIDTH;
1328 col.cx = 100;
1329 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1330 ok(r == 0, "Expected 0 column's inserted\n");
1331 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1332 ok(IsWindow(hHeader), "Header should be created\n");
1333 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1334 DestroyWindow(hList);
1336 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1337 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1338 GetModuleHandle(NULL), 0);
1339 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1340 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1341 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1342 ok(IsWindow(hHeader), "Header should be created\n");
1343 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
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 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1351 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1352 GetModuleHandle(NULL), 0);
1353 ret = SetWindowLongPtr(hList, GWL_STYLE,
1354 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1355 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1356 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1357 ok(IsWindow(hHeader), "Header should be created\n");
1358 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1359 ret = SetWindowLongPtr(hList, GWL_STYLE,
1360 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1361 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\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 */
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 /* insert column */
1374 memset(&col, 0, sizeof(LVCOLUMNA));
1375 col.mask = LVCF_WIDTH;
1376 col.cx = 100;
1377 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1378 ok(r == 0, "Expected 0 column's inserted\n");
1379 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1380 ok(IsWindow(hHeader), "Header should be created\n");
1381 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1382 DestroyWindow(hList);
1384 /* LVS_REPORT without WS_VISIBLE, try to show it */
1385 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1386 GetModuleHandle(NULL), 0);
1387 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1388 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1389 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1390 ShowWindow(hList, SW_SHOW);
1391 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1392 ok(IsWindow(hHeader), "Header should be created\n");
1393 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1394 DestroyWindow(hList);
1396 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1397 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1398 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1399 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1400 ok(IsWindow(hHeader), "Header should be created\n");
1401 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1402 /* HDS_DRAGDROP set by default */
1403 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1404 DestroyWindow(hList);
1406 /* setting LVS_EX_HEADERDRAGDROP creates header */
1407 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1408 GetModuleHandle(NULL), 0);
1409 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1410 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1411 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1412 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1413 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1414 ok(IsWindow(hHeader) ||
1415 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1416 "Header should be created\n");
1417 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1418 DestroyWindow(hList);
1420 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1421 hList = create_custom_listview_control(0);
1422 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1423 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1424 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1425 DestroyWindow(hList);
1427 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1428 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1429 GetModuleHandle(NULL), 0);
1430 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1431 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1433 rect.left = LVIR_BOUNDS;
1434 rect.top = 1;
1435 rect.right = rect.bottom = -10;
1436 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1437 ok(r != 0, "Expected not-null LRESULT\n");
1439 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1440 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1441 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1443 DestroyWindow(hList);
1445 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1446 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1447 hList = create_listview_control(LVS_OWNERDRAWFIXED);
1448 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1449 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1450 DestroyWindow(hList);
1453 static void test_redraw(void)
1455 HWND hwnd, hwndheader;
1456 HDC hdc;
1457 BOOL res;
1458 DWORD r;
1460 hwnd = create_listview_control(0);
1461 hwndheader = subclass_header(hwnd);
1463 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1465 trace("invalidate & update\n");
1466 InvalidateRect(hwnd, NULL, TRUE);
1467 UpdateWindow(hwnd);
1468 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1470 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1472 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1473 /* 1. Without backbuffer */
1474 res = ListView_SetBkColor(hwnd, CLR_NONE);
1475 expect(TRUE, res);
1477 hdc = GetWindowDC(hwndparent);
1479 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1480 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1481 ok(r != 0, "Expected not zero result\n");
1482 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1483 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1485 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1486 expect(TRUE, res);
1488 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1489 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1490 ok(r != 0, "Expected not zero result\n");
1491 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1492 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1494 /* 2. With backbuffer */
1495 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1496 LVS_EX_DOUBLEBUFFER);
1497 res = ListView_SetBkColor(hwnd, CLR_NONE);
1498 expect(TRUE, res);
1500 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1501 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1502 ok(r != 0, "Expected not zero result\n");
1503 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1504 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1506 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1507 expect(TRUE, res);
1509 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1510 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1511 todo_wine ok(r != 0, "Expected not zero result\n");
1512 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1513 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1515 ReleaseDC(hwndparent, hdc);
1517 DestroyWindow(hwnd);
1520 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1522 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1524 if(msg == WM_NOTIFY) {
1525 NMHDR *nmhdr = (PVOID)lp;
1526 if(nmhdr->code == NM_CUSTOMDRAW) {
1527 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1528 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1529 switch(nmlvcd->nmcd.dwDrawStage) {
1530 case CDDS_PREPAINT:
1531 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1532 return CDRF_NOTIFYITEMDRAW;
1533 case CDDS_ITEMPREPAINT:
1534 nmlvcd->clrTextBk = CLR_DEFAULT;
1535 return CDRF_NOTIFYSUBITEMDRAW;
1536 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1537 clr = GetBkColor(nmlvcd->nmcd.hdc);
1538 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1539 return CDRF_NOTIFYPOSTPAINT;
1540 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1541 clr = GetBkColor(nmlvcd->nmcd.hdc);
1542 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1543 return CDRF_DODEFAULT;
1545 return CDRF_DODEFAULT;
1549 return DefWindowProcA(hwnd, msg, wp, lp);
1552 static void test_customdraw(void)
1554 HWND hwnd;
1555 WNDPROC oldwndproc;
1557 hwnd = create_listview_control(0);
1559 insert_column(hwnd, 0);
1560 insert_column(hwnd, 1);
1561 insert_item(hwnd, 0);
1563 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1564 (LONG_PTR)cd_wndproc);
1566 InvalidateRect(hwnd, NULL, TRUE);
1567 UpdateWindow(hwnd);
1569 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1571 DestroyWindow(hwnd);
1574 static void test_icon_spacing(void)
1576 /* LVM_SETICONSPACING */
1577 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1579 HWND hwnd;
1580 WORD w, h;
1581 DWORD r;
1583 hwnd = create_custom_listview_control(LVS_ICON);
1584 ok(hwnd != NULL, "failed to create a listview window\n");
1586 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
1587 expect(NFR_ANSI, r);
1589 /* reset the icon spacing to defaults */
1590 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1592 /* now we can request what the defaults are */
1593 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1594 w = LOWORD(r);
1595 h = HIWORD(r);
1597 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1599 trace("test icon spacing\n");
1601 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1602 ok(r == MAKELONG(w, h) ||
1603 broken(r == MAKELONG(w, w)), /* win98 */
1604 "Expected %d, got %d\n", MAKELONG(w, h), r);
1606 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1607 expect(MAKELONG(20,30), r);
1609 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1610 expect(MAKELONG(25,35), r);
1612 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1614 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1615 DestroyWindow(hwnd);
1618 static void test_color(void)
1620 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1622 HWND hwnd;
1623 DWORD r;
1624 int i;
1626 COLORREF color;
1627 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1629 hwnd = create_listview_control(0);
1630 ok(hwnd != NULL, "failed to create a listview window\n");
1632 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1634 trace("test color seq\n");
1635 for (i = 0; i < 4; i++)
1637 color = colors[i];
1639 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1640 expect(TRUE, r);
1641 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1642 expect(color, r);
1644 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1645 expect (TRUE, r);
1646 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1647 expect(color, r);
1649 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1650 expect(TRUE, r);
1651 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1652 expect(color, r);
1655 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1657 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1658 DestroyWindow(hwnd);
1661 static void test_item_count(void)
1663 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1665 HWND hwnd;
1666 DWORD r;
1667 HDC hdc;
1668 HFONT hOldFont;
1669 TEXTMETRICA tm;
1670 RECT rect;
1671 INT height;
1673 LVITEM item0;
1674 LVITEM item1;
1675 LVITEM item2;
1676 static CHAR item0text[] = "item0";
1677 static CHAR item1text[] = "item1";
1678 static CHAR item2text[] = "item2";
1680 hwnd = create_listview_control(0);
1681 ok(hwnd != NULL, "failed to create a listview window\n");
1683 /* resize in dpiaware manner to fit all 3 items added */
1684 hdc = GetDC(0);
1685 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1686 GetTextMetricsA(hdc, &tm);
1687 /* 2 extra pixels for bounds and header border */
1688 height = tm.tmHeight + 2;
1689 SelectObject(hdc, hOldFont);
1690 ReleaseDC(0, hdc);
1692 GetWindowRect(hwnd, &rect);
1693 /* 3 items + 1 header + 1 to be sure */
1694 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1696 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1698 trace("test item count\n");
1700 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1701 expect(0, r);
1703 /* [item0] */
1704 item0.mask = LVIF_TEXT;
1705 item0.iItem = 0;
1706 item0.iSubItem = 0;
1707 item0.pszText = item0text;
1708 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1709 expect(0, r);
1711 /* [item0, item1] */
1712 item1.mask = LVIF_TEXT;
1713 item1.iItem = 1;
1714 item1.iSubItem = 0;
1715 item1.pszText = item1text;
1716 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1717 expect(1, r);
1719 /* [item0, item1, item2] */
1720 item2.mask = LVIF_TEXT;
1721 item2.iItem = 2;
1722 item2.iSubItem = 0;
1723 item2.pszText = item2text;
1724 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1725 expect(2, r);
1727 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1728 expect(3, r);
1730 /* [item0, item1] */
1731 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1732 expect(TRUE, r);
1734 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1735 expect(2, r);
1737 /* [] */
1738 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1739 expect(TRUE, r);
1741 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1742 expect(0, r);
1744 /* [item0] */
1745 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1746 expect(0, r);
1748 /* [item0, item1] */
1749 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1750 expect(1, r);
1752 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1753 expect(2, r);
1755 /* [item0, item1, item2] */
1756 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1757 expect(2, r);
1759 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1760 expect(3, r);
1762 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1764 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1765 DestroyWindow(hwnd);
1768 static void test_item_position(void)
1770 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1772 HWND hwnd;
1773 DWORD r;
1774 POINT position;
1776 LVITEM item0;
1777 LVITEM item1;
1778 LVITEM item2;
1779 static CHAR item0text[] = "item0";
1780 static CHAR item1text[] = "item1";
1781 static CHAR item2text[] = "item2";
1783 hwnd = create_custom_listview_control(LVS_ICON);
1784 ok(hwnd != NULL, "failed to create a listview window\n");
1786 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1788 trace("test item position\n");
1790 /* [item0] */
1791 item0.mask = LVIF_TEXT;
1792 item0.iItem = 0;
1793 item0.iSubItem = 0;
1794 item0.pszText = item0text;
1795 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1796 expect(0, r);
1798 /* [item0, item1] */
1799 item1.mask = LVIF_TEXT;
1800 item1.iItem = 1;
1801 item1.iSubItem = 0;
1802 item1.pszText = item1text;
1803 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1804 expect(1, r);
1806 /* [item0, item1, item2] */
1807 item2.mask = LVIF_TEXT;
1808 item2.iItem = 2;
1809 item2.iSubItem = 0;
1810 item2.pszText = item2text;
1811 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1812 expect(2, r);
1814 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1815 expect(TRUE, r);
1816 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1817 expect(TRUE, r);
1818 expect2(10, 5, position.x, position.y);
1820 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1821 expect(TRUE, r);
1822 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1823 expect(TRUE, r);
1824 expect2(0, 0, position.x, position.y);
1826 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1827 expect(TRUE, r);
1828 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1829 expect(TRUE, r);
1830 expect2(20, 20, position.x, position.y);
1832 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1834 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1835 DestroyWindow(hwnd);
1838 static void test_getorigin(void)
1840 /* LVM_GETORIGIN */
1842 HWND hwnd;
1843 DWORD r;
1844 POINT position;
1846 position.x = position.y = 0;
1848 hwnd = create_custom_listview_control(LVS_ICON);
1849 ok(hwnd != NULL, "failed to create a listview window\n");
1850 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1851 trace("test get origin results\n");
1852 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1853 expect(TRUE, r);
1854 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1855 DestroyWindow(hwnd);
1857 hwnd = create_custom_listview_control(LVS_SMALLICON);
1858 ok(hwnd != NULL, "failed to create a listview window\n");
1859 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1860 trace("test get origin results\n");
1861 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1862 expect(TRUE, r);
1863 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1864 DestroyWindow(hwnd);
1866 hwnd = create_custom_listview_control(LVS_LIST);
1867 ok(hwnd != NULL, "failed to create a listview window\n");
1868 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1869 trace("test get origin results\n");
1870 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1871 expect(FALSE, r);
1872 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1873 DestroyWindow(hwnd);
1875 hwnd = create_custom_listview_control(LVS_REPORT);
1876 ok(hwnd != NULL, "failed to create a listview window\n");
1877 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1878 trace("test get origin results\n");
1879 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1880 expect(FALSE, r);
1881 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1882 DestroyWindow(hwnd);
1886 static void test_multiselect(void)
1888 typedef struct t_select_task
1890 const char *descr;
1891 int initPos;
1892 int loopVK;
1893 int count;
1894 int result;
1895 } select_task;
1897 HWND hwnd;
1898 DWORD r;
1899 int i,j,item_count,selected_count;
1900 static const int items=5;
1901 BYTE kstate[256];
1902 select_task task;
1903 LONG_PTR style;
1904 LVITEMA item;
1906 static struct t_select_task task_list[] = {
1907 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1908 { "using VK_UP", -1, VK_UP, -1, -1 },
1909 { "using VK_END", 0, VK_END, 1, -1 },
1910 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1914 hwnd = create_listview_control(0);
1916 for (i=0;i<items;i++) {
1917 insert_item(hwnd, 0);
1920 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1922 expect(items,item_count);
1924 for (i=0;i<4;i++) {
1925 task = task_list[i];
1927 /* deselect all items */
1928 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1929 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1931 /* set initial position */
1932 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1933 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1935 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1937 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1939 /* Set SHIFT key pressed */
1940 GetKeyboardState(kstate);
1941 kstate[VK_SHIFT]=0x80;
1942 SetKeyboardState(kstate);
1944 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1945 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1946 expect(0,r);
1947 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1948 expect(0,r);
1951 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1953 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);
1955 /* Set SHIFT key released */
1956 GetKeyboardState(kstate);
1957 kstate[VK_SHIFT]=0x00;
1958 SetKeyboardState(kstate);
1960 DestroyWindow(hwnd);
1962 /* make multiple selection, then switch to LVS_SINGLESEL */
1963 hwnd = create_listview_control(0);
1964 for (i=0;i<items;i++) {
1965 insert_item(hwnd, 0);
1967 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1968 expect(items,item_count);
1970 /* try with NULL pointer */
1971 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)NULL);
1972 expect(FALSE, r);
1974 /* select all, check notifications */
1975 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1977 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1979 item.stateMask = LVIS_SELECTED;
1980 item.state = LVIS_SELECTED;
1981 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1982 expect(TRUE, r);
1984 ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
1985 "select all notification", FALSE);
1987 /* deselect all items */
1988 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1989 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1990 for (i=0;i<3;i++) {
1991 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
1994 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1995 expect(3, r);
1996 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1997 expect(-1, r);
1999 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2000 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2001 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2002 /* check that style is accepted */
2003 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2004 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2006 for (i=0;i<3;i++) {
2007 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2008 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2010 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2011 expect(3, r);
2012 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2013 expect(3, r);
2015 /* select one more */
2016 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2018 for (i=0;i<3;i++) {
2019 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2020 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2022 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2023 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2025 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2026 expect(1, r);
2027 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2028 expect(-1, r);
2030 /* try to select all on LVS_SINGLESEL */
2031 memset(&item, 0, sizeof(item));
2032 item.stateMask = LVIS_SELECTED;
2033 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2034 expect(TRUE, r);
2035 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2037 item.stateMask = LVIS_SELECTED;
2038 item.state = LVIS_SELECTED;
2039 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2040 expect(FALSE, r);
2042 r = ListView_GetSelectedCount(hwnd);
2043 expect(0, r);
2044 r = ListView_GetSelectionMark(hwnd);
2045 expect(-1, r);
2047 /* try to deselect all on LVS_SINGLESEL */
2048 item.stateMask = LVIS_SELECTED;
2049 item.state = LVIS_SELECTED;
2050 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2051 expect(TRUE, r);
2053 item.stateMask = LVIS_SELECTED;
2054 item.state = 0;
2055 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2056 expect(TRUE, r);
2057 r = ListView_GetSelectedCount(hwnd);
2058 expect(0, r);
2060 DestroyWindow(hwnd);
2063 static void test_subitem_rect(void)
2065 HWND hwnd;
2066 DWORD r;
2067 LVCOLUMN col;
2068 RECT rect;
2070 /* test LVM_GETSUBITEMRECT for header */
2071 hwnd = create_listview_control(0);
2072 ok(hwnd != NULL, "failed to create a listview window\n");
2073 /* add some columns */
2074 memset(&col, 0, sizeof(LVCOLUMN));
2075 col.mask = LVCF_WIDTH;
2076 col.cx = 100;
2077 r = -1;
2078 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2079 expect(0, r);
2080 col.cx = 150;
2081 r = -1;
2082 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2083 expect(1, r);
2084 col.cx = 200;
2085 r = -1;
2086 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2087 expect(2, r);
2088 /* item = -1 means header, subitem index is 1 based */
2089 rect.left = LVIR_BOUNDS;
2090 rect.top = 0;
2091 rect.right = rect.bottom = 0;
2092 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2093 expect(0, r);
2095 rect.left = LVIR_BOUNDS;
2096 rect.top = 1;
2097 rect.right = rect.bottom = 0;
2098 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2100 ok(r != 0, "Expected not-null LRESULT\n");
2101 expect(100, rect.left);
2102 expect(250, rect.right);
2103 todo_wine
2104 expect(3, rect.top);
2106 rect.left = LVIR_BOUNDS;
2107 rect.top = 2;
2108 rect.right = rect.bottom = 0;
2109 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2111 ok(r != 0, "Expected not-null LRESULT\n");
2112 expect(250, rect.left);
2113 expect(450, rect.right);
2114 todo_wine
2115 expect(3, rect.top);
2117 /* item LVS_REPORT padding isn't applied to subitems */
2118 insert_item(hwnd, 0);
2120 rect.left = LVIR_BOUNDS;
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 expect(100, rect.left);
2126 expect(250, rect.right);
2128 rect.left = LVIR_ICON;
2129 rect.top = 1;
2130 rect.right = rect.bottom = 0;
2131 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2132 ok(r != 0, "Expected not-null LRESULT\n");
2133 /* no icon attached - zero width rectangle, with no left padding */
2134 expect(100, rect.left);
2135 expect(100, rect.right);
2137 rect.left = LVIR_LABEL;
2138 rect.top = 1;
2139 rect.right = rect.bottom = 0;
2140 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2141 ok(r != 0, "Expected not-null LRESULT\n");
2142 /* same as full LVIR_BOUNDS */
2143 expect(100, rect.left);
2144 expect(250, rect.right);
2146 DestroyWindow(hwnd);
2148 /* try it for non LVS_REPORT style */
2149 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2150 GetModuleHandle(NULL), 0);
2151 rect.left = LVIR_BOUNDS;
2152 rect.top = 1;
2153 rect.right = rect.bottom = -10;
2154 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2155 ok(r == 0, "Expected not-null LRESULT\n");
2156 /* rect is unchanged */
2157 expect(0, rect.left);
2158 expect(-10, rect.right);
2159 expect(1, rect.top);
2160 expect(-10, rect.bottom);
2161 DestroyWindow(hwnd);
2164 /* comparison callback for test_sorting */
2165 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2167 if (first == second) return 0;
2168 return (first > second ? 1 : -1);
2171 static void test_sorting(void)
2173 HWND hwnd;
2174 LVITEMA item = {0};
2175 DWORD r;
2176 LONG_PTR style;
2177 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2178 CHAR buff[10];
2180 hwnd = create_listview_control(0);
2181 ok(hwnd != NULL, "failed to create a listview window\n");
2183 /* insert some items */
2184 item.mask = LVIF_PARAM | LVIF_STATE;
2185 item.state = LVIS_SELECTED;
2186 item.iItem = 0;
2187 item.iSubItem = 0;
2188 item.lParam = 3;
2189 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2190 expect(0, r);
2192 item.mask = LVIF_PARAM;
2193 item.iItem = 1;
2194 item.iSubItem = 0;
2195 item.lParam = 2;
2196 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2197 expect(1, r);
2199 item.mask = LVIF_STATE | LVIF_PARAM;
2200 item.state = LVIS_SELECTED;
2201 item.iItem = 2;
2202 item.iSubItem = 0;
2203 item.lParam = 4;
2204 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2205 expect(2, r);
2207 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2208 expect(-1, r);
2210 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2211 expect(2, r);
2213 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2214 expect(TRUE, r);
2216 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2217 expect(2, r);
2218 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2219 expect(-1, r);
2220 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2221 expect(0, r);
2222 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2223 expect(LVIS_SELECTED, r);
2224 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2225 expect(LVIS_SELECTED, r);
2227 DestroyWindow(hwnd);
2229 /* switch to LVS_SORTASCENDING when some items added */
2230 hwnd = create_listview_control(0);
2231 ok(hwnd != NULL, "failed to create a listview window\n");
2233 item.mask = LVIF_TEXT;
2234 item.iItem = 0;
2235 item.iSubItem = 0;
2236 item.pszText = names[1];
2237 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2238 expect(0, r);
2240 item.mask = LVIF_TEXT;
2241 item.iItem = 1;
2242 item.iSubItem = 0;
2243 item.pszText = names[2];
2244 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2245 expect(1, r);
2247 item.mask = LVIF_TEXT;
2248 item.iItem = 2;
2249 item.iSubItem = 0;
2250 item.pszText = names[0];
2251 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2252 expect(2, r);
2254 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2255 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2256 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2257 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2259 /* no sorting performed when switched to LVS_SORTASCENDING */
2260 item.mask = LVIF_TEXT;
2261 item.iItem = 0;
2262 item.pszText = buff;
2263 item.cchTextMax = sizeof(buff);
2264 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2265 expect(TRUE, r);
2266 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2268 item.iItem = 1;
2269 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2270 expect(TRUE, r);
2271 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2273 item.iItem = 2;
2274 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2275 expect(TRUE, r);
2276 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2278 /* adding new item doesn't resort list */
2279 item.mask = LVIF_TEXT;
2280 item.iItem = 3;
2281 item.iSubItem = 0;
2282 item.pszText = names[3];
2283 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2284 expect(3, r);
2286 item.mask = LVIF_TEXT;
2287 item.iItem = 0;
2288 item.pszText = buff;
2289 item.cchTextMax = sizeof(buff);
2290 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2291 expect(TRUE, r);
2292 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2294 item.iItem = 1;
2295 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2296 expect(TRUE, r);
2297 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2299 item.iItem = 2;
2300 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2301 expect(TRUE, r);
2302 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2304 item.iItem = 3;
2305 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2306 expect(TRUE, r);
2307 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2309 /* corner case - item should be placed at first position */
2310 item.mask = LVIF_TEXT;
2311 item.iItem = 4;
2312 item.iSubItem = 0;
2313 item.pszText = names[4];
2314 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2315 expect(0, r);
2317 item.iItem = 0;
2318 item.pszText = buff;
2319 item.cchTextMax = sizeof(buff);
2320 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2321 expect(TRUE, r);
2322 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2324 item.iItem = 1;
2325 item.pszText = buff;
2326 item.cchTextMax = sizeof(buff);
2327 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2328 expect(TRUE, r);
2329 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2331 item.iItem = 2;
2332 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2333 expect(TRUE, r);
2334 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2336 item.iItem = 3;
2337 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2338 expect(TRUE, r);
2339 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2341 item.iItem = 4;
2342 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2343 expect(TRUE, r);
2344 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2346 DestroyWindow(hwnd);
2349 static void test_ownerdata(void)
2351 HWND hwnd;
2352 LONG_PTR style, ret;
2353 DWORD res;
2354 LVITEMA item;
2356 /* it isn't possible to set LVS_OWNERDATA after creation */
2357 if (g_is_below_5)
2359 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2361 else
2363 hwnd = create_listview_control(0);
2364 ok(hwnd != NULL, "failed to create a listview window\n");
2365 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2366 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2368 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2370 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2371 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2372 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2373 "try to switch to LVS_OWNERDATA seq", FALSE);
2375 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2376 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2377 DestroyWindow(hwnd);
2380 /* try to set LVS_OWNERDATA after creation just having it */
2381 hwnd = create_listview_control(LVS_OWNERDATA);
2382 ok(hwnd != NULL, "failed to create a listview window\n");
2383 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2384 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2386 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2388 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2389 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2390 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2391 "try to switch to LVS_OWNERDATA seq", FALSE);
2392 DestroyWindow(hwnd);
2394 /* try to remove LVS_OWNERDATA after creation just having it */
2395 if (g_is_below_5)
2397 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2399 else
2401 hwnd = create_listview_control(LVS_OWNERDATA);
2402 ok(hwnd != NULL, "failed to create a listview window\n");
2403 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2404 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2406 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2408 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2409 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2410 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2411 "try to switch to LVS_OWNERDATA seq", FALSE);
2412 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2413 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2414 DestroyWindow(hwnd);
2417 /* try select an item */
2418 hwnd = create_listview_control(LVS_OWNERDATA);
2419 ok(hwnd != NULL, "failed to create a listview window\n");
2420 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2421 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2422 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2423 expect(0, res);
2424 memset(&item, 0, sizeof(item));
2425 item.stateMask = LVIS_SELECTED;
2426 item.state = LVIS_SELECTED;
2427 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2428 expect(TRUE, res);
2429 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2430 expect(1, res);
2431 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2432 expect(1, res);
2433 DestroyWindow(hwnd);
2435 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2436 hwnd = create_listview_control(LVS_OWNERDATA);
2437 ok(hwnd != NULL, "failed to create a listview window\n");
2438 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2439 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2440 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2441 expect(1, res);
2442 memset(&item, 0, sizeof(item));
2443 item.mask = LVIF_STATE;
2444 item.iItem = 0;
2445 item.stateMask = LVIS_SELECTED;
2446 item.state = LVIS_SELECTED;
2447 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2448 expect(FALSE, res);
2449 DestroyWindow(hwnd);
2451 /* check notifications after focused/selected changed */
2452 hwnd = create_listview_control(LVS_OWNERDATA);
2453 ok(hwnd != NULL, "failed to create a listview window\n");
2454 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2455 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2457 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2459 memset(&item, 0, sizeof(item));
2460 item.stateMask = LVIS_SELECTED;
2461 item.state = LVIS_SELECTED;
2462 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2463 expect(TRUE, res);
2465 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2466 "ownerdata select notification", TRUE);
2468 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2470 memset(&item, 0, sizeof(item));
2471 item.stateMask = LVIS_FOCUSED;
2472 item.state = LVIS_FOCUSED;
2473 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2474 expect(TRUE, res);
2476 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2477 "ownerdata focus notification", TRUE);
2479 /* select all, check notifications */
2480 item.stateMask = LVIS_SELECTED;
2481 item.state = 0;
2482 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2483 expect(TRUE, res);
2485 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2487 item.stateMask = LVIS_SELECTED;
2488 item.state = LVIS_SELECTED;
2490 g_dump_itemchanged = TRUE;
2491 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2492 expect(TRUE, res);
2493 g_dump_itemchanged = FALSE;
2495 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2496 "ownerdata select all notification", TRUE);
2498 /* select all again, note that all items are selected already */
2499 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2500 item.stateMask = LVIS_SELECTED;
2501 item.state = LVIS_SELECTED;
2502 g_dump_itemchanged = TRUE;
2503 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2504 expect(TRUE, res);
2505 g_dump_itemchanged = FALSE;
2506 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2507 "ownerdata select all notification", TRUE);
2508 /* deselect all */
2509 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2510 item.stateMask = LVIS_SELECTED;
2511 item.state = 0;
2512 g_dump_itemchanged = TRUE;
2513 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2514 expect(TRUE, res);
2515 g_dump_itemchanged = FALSE;
2516 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2517 "ownerdata deselect all notification", TRUE);
2519 /* select one, then deselect all */
2520 item.stateMask = LVIS_SELECTED;
2521 item.state = LVIS_SELECTED;
2522 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2523 expect(TRUE, res);
2524 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2525 item.stateMask = LVIS_SELECTED;
2526 item.state = 0;
2527 g_dump_itemchanged = TRUE;
2528 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2529 expect(TRUE, res);
2530 g_dump_itemchanged = FALSE;
2531 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2532 "ownerdata select all notification", TRUE);
2534 /* remove focused, try to focus all */
2535 item.stateMask = LVIS_FOCUSED;
2536 item.state = LVIS_FOCUSED;
2537 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2538 expect(TRUE, res);
2539 item.stateMask = LVIS_FOCUSED;
2540 item.state = 0;
2541 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2542 expect(TRUE, res);
2543 item.stateMask = LVIS_FOCUSED;
2544 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
2545 expect(0, res);
2546 /* setting all to focused returns failure value */
2547 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2548 item.stateMask = LVIS_FOCUSED;
2549 item.state = LVIS_FOCUSED;
2550 g_dump_itemchanged = TRUE;
2551 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2552 expect(FALSE, res);
2553 g_dump_itemchanged = FALSE;
2554 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2555 "ownerdata focus all notification", FALSE);
2556 /* focus single item, remove all */
2557 item.stateMask = LVIS_FOCUSED;
2558 item.state = LVIS_FOCUSED;
2559 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2560 expect(TRUE, res);
2561 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2562 item.stateMask = LVIS_FOCUSED;
2563 item.state = 0;
2564 g_dump_itemchanged = TRUE;
2565 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2566 expect(TRUE, res);
2567 g_dump_itemchanged = FALSE;
2568 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
2569 "ownerdata remove focus all notification", TRUE);
2570 /* set all cut */
2571 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2572 item.stateMask = LVIS_CUT;
2573 item.state = LVIS_CUT;
2574 g_dump_itemchanged = TRUE;
2575 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2576 expect(TRUE, res);
2577 g_dump_itemchanged = FALSE;
2578 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2579 "ownerdata cut all notification", TRUE);
2580 /* all marked cut, try again */
2581 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2582 item.stateMask = LVIS_CUT;
2583 item.state = LVIS_CUT;
2584 g_dump_itemchanged = TRUE;
2585 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2586 expect(TRUE, res);
2587 g_dump_itemchanged = FALSE;
2588 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2589 "ownerdata cut all notification #2", TRUE);
2591 DestroyWindow(hwnd);
2593 /* check notifications on LVM_GETITEM */
2594 /* zero callback mask */
2595 hwnd = create_listview_control(LVS_OWNERDATA);
2596 ok(hwnd != NULL, "failed to create a listview window\n");
2597 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2598 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2600 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2602 memset(&item, 0, sizeof(item));
2603 item.stateMask = LVIS_SELECTED;
2604 item.mask = LVIF_STATE;
2605 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2606 expect(TRUE, res);
2608 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2609 "ownerdata getitem selected state 1", FALSE);
2611 /* non zero callback mask but not we asking for */
2612 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2613 expect(TRUE, res);
2615 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2617 memset(&item, 0, sizeof(item));
2618 item.stateMask = LVIS_SELECTED;
2619 item.mask = LVIF_STATE;
2620 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2621 expect(TRUE, res);
2623 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2624 "ownerdata getitem selected state 2", FALSE);
2626 /* LVIS_OVERLAYMASK callback mask, asking for index */
2627 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2629 memset(&item, 0, sizeof(item));
2630 item.stateMask = LVIS_OVERLAYMASK;
2631 item.mask = LVIF_STATE;
2632 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2633 expect(TRUE, res);
2635 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2636 "ownerdata getitem selected state 2", FALSE);
2638 DestroyWindow(hwnd);
2640 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2641 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING);
2642 ok(hwnd != NULL, "failed to create a listview window\n");
2643 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2644 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2645 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2646 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2647 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2648 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2649 DestroyWindow(hwnd);
2650 /* apparently it's allowed to switch these style on after creation */
2651 hwnd = create_listview_control(LVS_OWNERDATA);
2652 ok(hwnd != NULL, "failed to create a listview window\n");
2653 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2654 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2655 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2656 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2657 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2658 DestroyWindow(hwnd);
2660 hwnd = create_listview_control(LVS_OWNERDATA);
2661 ok(hwnd != NULL, "failed to create a listview window\n");
2662 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2663 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2664 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2665 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2666 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2667 DestroyWindow(hwnd);
2670 static void test_norecompute(void)
2672 static CHAR testA[] = "test";
2673 CHAR buff[10];
2674 LVITEMA item;
2675 HWND hwnd;
2676 DWORD res;
2678 /* self containing control */
2679 hwnd = create_listview_control(0);
2680 ok(hwnd != NULL, "failed to create a listview window\n");
2681 memset(&item, 0, sizeof(item));
2682 item.mask = LVIF_TEXT | LVIF_STATE;
2683 item.iItem = 0;
2684 item.stateMask = LVIS_SELECTED;
2685 item.state = LVIS_SELECTED;
2686 item.pszText = testA;
2687 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2688 expect(0, res);
2689 /* retrieve with LVIF_NORECOMPUTE */
2690 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2691 item.iItem = 0;
2692 item.pszText = buff;
2693 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2694 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2695 expect(TRUE, res);
2696 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2698 item.mask = LVIF_TEXT;
2699 item.iItem = 1;
2700 item.pszText = LPSTR_TEXTCALLBACK;
2701 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2702 expect(1, res);
2704 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2705 item.iItem = 1;
2706 item.pszText = buff;
2707 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2709 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2710 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2711 expect(TRUE, res);
2712 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2713 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2714 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2716 DestroyWindow(hwnd);
2718 /* LVS_OWNERDATA */
2719 hwnd = create_listview_control(LVS_OWNERDATA);
2720 ok(hwnd != NULL, "failed to create a listview window\n");
2722 item.mask = LVIF_STATE;
2723 item.stateMask = LVIS_SELECTED;
2724 item.state = LVIS_SELECTED;
2725 item.iItem = 0;
2726 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2727 expect(0, res);
2729 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2730 item.iItem = 0;
2731 item.pszText = buff;
2732 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2733 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2734 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2735 expect(TRUE, res);
2736 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2737 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2738 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2740 DestroyWindow(hwnd);
2743 static void test_nosortheader(void)
2745 HWND hwnd, header;
2746 LONG_PTR style;
2748 hwnd = create_listview_control(0);
2749 ok(hwnd != NULL, "failed to create a listview window\n");
2751 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2752 ok(IsWindow(header), "header expected\n");
2754 style = GetWindowLongPtr(header, GWL_STYLE);
2755 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2757 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2758 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2759 /* HDS_BUTTONS retained */
2760 style = GetWindowLongPtr(header, GWL_STYLE);
2761 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2763 DestroyWindow(hwnd);
2765 /* create with LVS_NOSORTHEADER */
2766 hwnd = create_listview_control(LVS_NOSORTHEADER);
2767 ok(hwnd != NULL, "failed to create a listview window\n");
2769 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2770 ok(IsWindow(header), "header expected\n");
2772 style = GetWindowLongPtr(header, GWL_STYLE);
2773 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2775 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2776 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2777 /* not changed here */
2778 style = GetWindowLongPtr(header, GWL_STYLE);
2779 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2781 DestroyWindow(hwnd);
2784 static void test_setredraw(void)
2786 HWND hwnd;
2787 DWORD_PTR style;
2788 DWORD ret;
2790 hwnd = create_listview_control(0);
2791 ok(hwnd != NULL, "failed to create a listview window\n");
2793 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2794 ListView seems to handle it internally without DefWinProc */
2796 /* default value first */
2797 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2798 expect(0, ret);
2799 /* disable */
2800 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2801 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2802 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2803 expect(0, ret);
2804 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2805 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2807 DestroyWindow(hwnd);
2810 static void test_hittest(void)
2812 HWND hwnd;
2813 DWORD r;
2814 RECT bounds;
2815 LVITEMA item;
2816 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2817 POINT pos;
2818 INT x, y;
2819 HIMAGELIST himl, himl2;
2820 HBITMAP hbmp;
2822 hwnd = create_listview_control(0);
2823 ok(hwnd != NULL, "failed to create a listview window\n");
2825 /* LVS_REPORT with a single subitem (2 columns) */
2826 insert_column(hwnd, 0);
2827 insert_column(hwnd, 1);
2828 insert_item(hwnd, 0);
2830 item.iSubItem = 0;
2831 /* the only purpose of that line is to be as long as a half item rect */
2832 item.pszText = text;
2833 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2834 expect(TRUE, r);
2836 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2837 expect(TRUE, r);
2838 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
2839 expect(TRUE, r);
2841 memset(&bounds, 0, sizeof(bounds));
2842 bounds.left = LVIR_BOUNDS;
2843 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
2844 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
2845 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
2846 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
2847 expect(TRUE, r);
2849 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2850 x = pos.x + 50; /* column half width */
2851 y = pos.y + (bounds.bottom - bounds.top) / 2;
2852 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, FALSE, FALSE, __LINE__);
2853 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2854 x = pos.x + 150; /* outside column */
2855 y = pos.y + (bounds.bottom - bounds.top) / 2;
2856 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2857 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2858 y = (bounds.bottom - bounds.top) / 2;
2859 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, TRUE, __LINE__);
2860 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2861 /* outside possible client rectangle (to right) */
2862 x = pos.x + 500;
2863 y = pos.y + (bounds.bottom - bounds.top) / 2;
2864 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2865 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2866 y = (bounds.bottom - bounds.top) / 2;
2867 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, TRUE, __LINE__);
2868 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2869 /* subitem returned with -1 item too */
2870 x = pos.x + 150;
2871 y = -10;
2872 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2873 /* parent client area is 100x100 by default */
2874 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
2875 x = pos.x + 150; /* outside column */
2876 y = pos.y + (bounds.bottom - bounds.top) / 2;
2877 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, FALSE, FALSE, __LINE__);
2878 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2879 y = (bounds.bottom - bounds.top) / 2;
2880 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, FALSE, TRUE, __LINE__);
2881 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2882 /* the same with LVS_EX_FULLROWSELECT */
2883 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
2884 x = pos.x + 150; /* outside column */
2885 y = pos.y + (bounds.bottom - bounds.top) / 2;
2886 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, FALSE, FALSE, __LINE__);
2887 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2888 y = (bounds.bottom - bounds.top) / 2;
2889 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2890 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
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, 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, 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, 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, FALSE, TRUE, __LINE__);
2905 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2906 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2907 himl = ImageList_Create(16, 16, 0, 4, 4);
2908 ok(himl != NULL, "failed to create imagelist\n");
2909 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2910 ok(hbmp != NULL, "failed to create bitmap\n");
2911 r = ImageList_Add(himl, hbmp, 0);
2912 ok(r == 0, "should be zero\n");
2913 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2914 ok(hbmp != NULL, "failed to create bitmap\n");
2915 r = ImageList_Add(himl, hbmp, 0);
2916 ok(r == 1, "should be one\n");
2918 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2919 ok(r == 0, "should return zero\n");
2921 item.mask = LVIF_IMAGE;
2922 item.iImage = 0;
2923 item.iItem = 0;
2924 item.iSubItem = 0;
2925 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2926 expect(TRUE, r);
2927 /* on state icon */
2928 x = pos.x + 8;
2929 y = pos.y + (bounds.bottom - bounds.top) / 2;
2930 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2931 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2932 y = (bounds.bottom - bounds.top) / 2;
2933 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2935 /* state icons indices are 1 based, check with valid index */
2936 item.mask = LVIF_STATE;
2937 item.state = INDEXTOSTATEIMAGEMASK(1);
2938 item.stateMask = LVIS_STATEIMAGEMASK;
2939 item.iItem = 0;
2940 item.iSubItem = 0;
2941 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2942 expect(TRUE, r);
2943 /* on state icon */
2944 x = pos.x + 8;
2945 y = pos.y + (bounds.bottom - bounds.top) / 2;
2946 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2947 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2948 y = (bounds.bottom - bounds.top) / 2;
2949 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2951 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
2952 ok(himl2 == himl, "should return handle\n");
2954 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
2955 ok(r == 0, "should return zero\n");
2956 /* on item icon */
2957 x = pos.x + 8;
2958 y = pos.y + (bounds.bottom - bounds.top) / 2;
2959 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, FALSE, FALSE, __LINE__);
2960 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
2961 y = (bounds.bottom - bounds.top) / 2;
2962 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
2964 DestroyWindow(hwnd);
2967 static void test_getviewrect(void)
2969 HWND hwnd;
2970 DWORD r;
2971 RECT rect;
2972 LVITEMA item;
2974 hwnd = create_listview_control(0);
2975 ok(hwnd != NULL, "failed to create a listview window\n");
2977 /* empty */
2978 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2979 expect(TRUE, r);
2981 insert_column(hwnd, 0);
2982 insert_column(hwnd, 1);
2984 memset(&item, 0, sizeof(item));
2985 item.iItem = 0;
2986 item.iSubItem = 0;
2987 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2989 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2990 expect(TRUE, r);
2991 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
2992 expect(TRUE, r);
2994 rect.left = rect.right = rect.top = rect.bottom = -1;
2995 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2996 expect(TRUE, r);
2997 /* left is set to (2e31-1) - XP SP2 */
2998 expect(0, rect.right);
2999 expect(0, rect.top);
3000 expect(0, rect.bottom);
3002 /* switch to LVS_ICON */
3003 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3005 rect.left = rect.right = rect.top = rect.bottom = -1;
3006 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3007 expect(TRUE, r);
3008 expect(0, rect.left);
3009 expect(0, rect.top);
3010 /* precise value differs for 2k, XP and Vista */
3011 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3012 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3014 DestroyWindow(hwnd);
3017 static void test_getitemposition(void)
3019 HWND hwnd, header;
3020 DWORD r;
3021 POINT pt;
3022 RECT rect;
3024 hwnd = create_listview_control(0);
3025 ok(hwnd != NULL, "failed to create a listview window\n");
3026 header = subclass_header(hwnd);
3028 /* LVS_REPORT, single item, no columns added */
3029 insert_item(hwnd, 0);
3031 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3033 pt.x = pt.y = -1;
3034 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3035 expect(TRUE, r);
3036 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3038 /* LVS_REPORT, single item, single column */
3039 insert_column(hwnd, 0);
3041 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3043 pt.x = pt.y = -1;
3044 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3045 expect(TRUE, r);
3046 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3048 memset(&rect, 0, sizeof(rect));
3049 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3050 /* some padding? */
3051 expect(2, pt.x);
3052 /* offset by header height */
3053 expect(rect.bottom - rect.top, pt.y);
3055 DestroyWindow(hwnd);
3058 static void test_columnscreation(void)
3060 HWND hwnd, header;
3061 DWORD r;
3063 hwnd = create_listview_control(0);
3064 ok(hwnd != NULL, "failed to create a listview window\n");
3066 insert_item(hwnd, 0);
3068 /* headers columns aren't created automatically */
3069 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3070 ok(IsWindow(header), "Expected header handle\n");
3071 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3072 expect(0, r);
3074 DestroyWindow(hwnd);
3077 static void test_getitemrect(void)
3079 HWND hwnd;
3080 HIMAGELIST himl;
3081 HBITMAP hbm;
3082 RECT rect;
3083 DWORD r;
3084 LVITEMA item;
3085 LVCOLUMNA col;
3086 INT order[2];
3087 POINT pt;
3089 hwnd = create_listview_control(0);
3090 ok(hwnd != NULL, "failed to create a listview window\n");
3092 /* empty item */
3093 memset(&item, 0, sizeof(item));
3094 item.iItem = 0;
3095 item.iSubItem = 0;
3096 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3097 expect(0, r);
3099 rect.left = LVIR_BOUNDS;
3100 rect.right = rect.top = rect.bottom = -1;
3101 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3102 expect(TRUE, r);
3104 /* zero width rectangle with no padding */
3105 expect(0, rect.left);
3106 expect(0, rect.right);
3108 insert_column(hwnd, 0);
3109 insert_column(hwnd, 1);
3111 col.mask = LVCF_WIDTH;
3112 col.cx = 50;
3113 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3114 expect(TRUE, r);
3116 col.mask = LVCF_WIDTH;
3117 col.cx = 100;
3118 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3119 expect(TRUE, r);
3121 rect.left = LVIR_BOUNDS;
3122 rect.right = rect.top = rect.bottom = -1;
3123 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3124 expect(TRUE, r);
3126 /* still no left padding */
3127 expect(0, rect.left);
3128 expect(150, rect.right);
3130 rect.left = LVIR_SELECTBOUNDS;
3131 rect.right = rect.top = rect.bottom = -1;
3132 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3133 expect(TRUE, r);
3134 /* padding */
3135 expect(2, rect.left);
3137 rect.left = LVIR_LABEL;
3138 rect.right = rect.top = rect.bottom = -1;
3139 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3140 expect(TRUE, r);
3141 /* padding, column width */
3142 expect(2, rect.left);
3143 expect(50, rect.right);
3145 /* no icons attached */
3146 rect.left = LVIR_ICON;
3147 rect.right = rect.top = rect.bottom = -1;
3148 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3149 expect(TRUE, r);
3150 /* padding */
3151 expect(2, rect.left);
3152 expect(2, rect.right);
3154 /* change order */
3155 order[0] = 1; order[1] = 0;
3156 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3157 expect(TRUE, r);
3158 pt.x = -1;
3159 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3160 expect(TRUE, r);
3161 /* 1 indexed column width + padding */
3162 expect(102, pt.x);
3163 /* rect is at zero too */
3164 rect.left = LVIR_BOUNDS;
3165 rect.right = rect.top = rect.bottom = -1;
3166 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3167 expect(TRUE, r);
3168 expect(0, rect.left);
3169 /* just width sum */
3170 expect(150, rect.right);
3172 rect.left = LVIR_SELECTBOUNDS;
3173 rect.right = rect.top = rect.bottom = -1;
3174 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3175 expect(TRUE, r);
3176 /* column width + padding */
3177 expect(102, rect.left);
3179 /* back to initial order */
3180 order[0] = 0; order[1] = 1;
3181 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3182 expect(TRUE, r);
3184 /* state icons */
3185 himl = ImageList_Create(16, 16, 0, 2, 2);
3186 ok(himl != NULL, "failed to create imagelist\n");
3187 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3188 ok(hbm != NULL, "failed to create bitmap\n");
3189 r = ImageList_Add(himl, hbm, 0);
3190 ok(r == 0, "should be zero\n");
3191 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3192 ok(hbm != NULL, "failed to create bitmap\n");
3193 r = ImageList_Add(himl, hbm, 0);
3194 ok(r == 1, "should be one\n");
3196 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3197 ok(r == 0, "should return zero\n");
3199 item.mask = LVIF_STATE;
3200 item.state = INDEXTOSTATEIMAGEMASK(1);
3201 item.stateMask = LVIS_STATEIMAGEMASK;
3202 item.iItem = 0;
3203 item.iSubItem = 0;
3204 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3205 expect(TRUE, r);
3207 /* icon bounds */
3208 rect.left = LVIR_ICON;
3209 rect.right = rect.top = rect.bottom = -1;
3210 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3211 expect(TRUE, r);
3212 /* padding + stateicon width */
3213 expect(18, rect.left);
3214 expect(18, rect.right);
3215 /* label bounds */
3216 rect.left = LVIR_LABEL;
3217 rect.right = rect.top = rect.bottom = -1;
3218 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3219 expect(TRUE, r);
3220 /* padding + stateicon width -> column width */
3221 expect(18, rect.left);
3222 expect(50, rect.right);
3224 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
3225 ok(r != 0, "should return current list handle\n");
3227 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3228 ok(r == 0, "should return zero\n");
3230 item.mask = LVIF_STATE | LVIF_IMAGE;
3231 item.iImage = 1;
3232 item.state = 0;
3233 item.stateMask = ~0;
3234 item.iItem = 0;
3235 item.iSubItem = 0;
3236 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3237 expect(TRUE, r);
3239 /* icon bounds */
3240 rect.left = LVIR_ICON;
3241 rect.right = rect.top = rect.bottom = -1;
3242 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3243 expect(TRUE, r);
3244 /* padding, icon width */
3245 expect(2, rect.left);
3246 expect(18, rect.right);
3247 /* label bounds */
3248 rect.left = LVIR_LABEL;
3249 rect.right = rect.top = rect.bottom = -1;
3250 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3251 expect(TRUE, r);
3252 /* padding + icon width -> column width */
3253 expect(18, rect.left);
3254 expect(50, rect.right);
3256 /* select bounds */
3257 rect.left = LVIR_SELECTBOUNDS;
3258 rect.right = rect.top = rect.bottom = -1;
3259 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3260 expect(TRUE, r);
3261 /* padding, column width */
3262 expect(2, rect.left);
3263 expect(50, rect.right);
3265 /* try with indentation */
3266 item.mask = LVIF_INDENT;
3267 item.iIndent = 1;
3268 item.iItem = 0;
3269 item.iSubItem = 0;
3270 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3271 expect(TRUE, r);
3273 /* bounds */
3274 rect.left = LVIR_BOUNDS;
3275 rect.right = rect.top = rect.bottom = -1;
3276 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3277 expect(TRUE, r);
3278 /* padding + 1 icon width, column width */
3279 expect(0, rect.left);
3280 expect(150, rect.right);
3282 /* select bounds */
3283 rect.left = LVIR_SELECTBOUNDS;
3284 rect.right = rect.top = rect.bottom = -1;
3285 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3286 expect(TRUE, r);
3287 /* padding + 1 icon width, column width */
3288 expect(2 + 16, rect.left);
3289 expect(50, rect.right);
3291 /* label bounds */
3292 rect.left = LVIR_LABEL;
3293 rect.right = rect.top = rect.bottom = -1;
3294 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3295 expect(TRUE, r);
3296 /* padding + 2 icon widths, column width */
3297 expect(2 + 16*2, rect.left);
3298 expect(50, rect.right);
3300 /* icon bounds */
3301 rect.left = LVIR_ICON;
3302 rect.right = rect.top = rect.bottom = -1;
3303 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3304 expect(TRUE, r);
3305 /* padding + 1 icon width indentation, icon width */
3306 expect(2 + 16, rect.left);
3307 expect(34, rect.right);
3310 DestroyWindow(hwnd);
3313 static void test_editbox(void)
3315 HWND hwnd, hwndedit, hwndedit2;
3316 LVITEMA item;
3317 DWORD r;
3318 static CHAR testitemA[] = "testitem";
3319 static CHAR testitem1A[] = "testitem1";
3320 static CHAR buffer[10];
3322 hwnd = create_listview_control(LVS_EDITLABELS);
3323 ok(hwnd != NULL, "failed to create a listview window\n");
3325 insert_column(hwnd, 0);
3327 memset(&item, 0, sizeof(item));
3328 item.mask = LVIF_TEXT;
3329 item.pszText = testitemA;
3330 item.iItem = 0;
3331 item.iSubItem = 0;
3332 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3333 expect(0, r);
3335 /* setting focus is necessary */
3336 SetFocus(hwnd);
3337 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3338 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3340 /* modify initial string */
3341 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3342 expect(TRUE, r);
3343 /* return focus to listview */
3344 SetFocus(hwnd);
3346 memset(&item, 0, sizeof(item));
3347 item.mask = LVIF_TEXT;
3348 item.pszText = buffer;
3349 item.cchTextMax = 10;
3350 item.iItem = 0;
3351 item.iSubItem = 0;
3352 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3353 expect(TRUE, r);
3355 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3357 /* send LVM_EDITLABEL on already created edit */
3358 SetFocus(hwnd);
3359 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3360 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3361 /* focus will be set to edit */
3362 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3363 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3364 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3366 /* creating label disabled when control isn't focused */
3367 SetFocus(0);
3368 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3369 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3371 /* check EN_KILLFOCUS handling */
3372 memset(&item, 0, sizeof(item));
3373 item.pszText = testitemA;
3374 item.iItem = 0;
3375 item.iSubItem = 0;
3376 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3377 expect(TRUE, r);
3379 SetFocus(hwnd);
3380 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3381 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3382 /* modify edit and notify control that it lost focus */
3383 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3384 expect(TRUE, r);
3385 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3386 expect(0, r);
3387 memset(&item, 0, sizeof(item));
3388 item.pszText = buffer;
3389 item.cchTextMax = 10;
3390 item.iItem = 0;
3391 item.iSubItem = 0;
3392 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3393 expect(lstrlen(item.pszText), r);
3394 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3395 /* end edit without saving */
3396 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3397 expect(0, r);
3398 memset(&item, 0, sizeof(item));
3399 item.pszText = buffer;
3400 item.cchTextMax = 10;
3401 item.iItem = 0;
3402 item.iSubItem = 0;
3403 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3404 expect(lstrlen(item.pszText), r);
3405 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3407 /* LVM_EDITLABEL with -1 destroys current edit */
3408 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3409 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3410 /* no edit present */
3411 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3412 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3413 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3414 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3415 /* edit present */
3416 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3417 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3418 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3419 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3420 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3421 /* check another negative value */
3422 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3423 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3424 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3425 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3426 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3427 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3428 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3429 /* and value greater than max item index */
3430 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3431 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3432 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3433 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3434 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3435 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3436 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3437 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3439 /* messaging tests */
3440 SetFocus(hwnd);
3441 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3442 blockEdit = FALSE;
3443 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3444 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3445 /* testing only sizing messages */
3446 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3447 "edit box create - sizing", FALSE);
3449 DestroyWindow(hwnd);
3452 static void test_notifyformat(void)
3454 HWND hwnd, header;
3455 DWORD r;
3457 hwnd = create_listview_control(0);
3458 ok(hwnd != NULL, "failed to create a listview window\n");
3460 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3461 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3462 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3463 expect(0, r);
3464 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3465 /* set */
3466 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3467 expect(0, r);
3468 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3469 if (r == 1)
3471 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3472 expect(1, r);
3473 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3474 expect(0, r);
3476 else
3478 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3479 DestroyWindow(hwnd);
3480 return;
3483 DestroyWindow(hwnd);
3485 /* test failure in parent WM_NOTIFYFORMAT */
3486 notifyFormat = 0;
3487 hwnd = create_listview_control(0);
3488 ok(hwnd != NULL, "failed to create a listview window\n");
3489 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3490 ok(IsWindow(header), "expected header to be created\n");
3491 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3492 expect(0, r);
3493 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3494 expect(1, r);
3495 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3496 ok(r != 0, "Expected valid format\n");
3498 notifyFormat = NFR_UNICODE;
3499 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3500 expect(NFR_UNICODE, r);
3501 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3502 expect(1, r);
3503 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3504 expect(1, r);
3506 notifyFormat = NFR_ANSI;
3507 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3508 expect(NFR_ANSI, r);
3509 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3510 expect(0, r);
3511 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3512 expect(1, r);
3514 DestroyWindow(hwnd);
3516 /* try different unicode window combination and defaults */
3517 if (!GetModuleHandleW(NULL))
3519 win_skip("Additional notify format tests are incompatible with Win9x\n");
3520 return;
3523 hwndparentW = create_parent_window(TRUE);
3524 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3525 if (!IsWindow(hwndparentW)) return;
3527 notifyFormat = -1;
3528 hwnd = create_listview_controlW(0, hwndparentW);
3529 ok(hwnd != NULL, "failed to create a listview window\n");
3530 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3531 ok(IsWindow(header), "expected header to be created\n");
3532 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3533 expect(1, r);
3534 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3535 expect(1, r);
3536 DestroyWindow(hwnd);
3537 /* receiving error code defaulting to ansi */
3538 notifyFormat = 0;
3539 hwnd = create_listview_controlW(0, hwndparentW);
3540 ok(hwnd != NULL, "failed to create a listview window\n");
3541 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3542 ok(IsWindow(header), "expected header to be created\n");
3543 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3544 expect(0, r);
3545 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3546 expect(1, r);
3547 DestroyWindow(hwnd);
3548 /* receiving ansi code from unicode window, use it */
3549 notifyFormat = NFR_ANSI;
3550 hwnd = create_listview_controlW(0, hwndparentW);
3551 ok(hwnd != NULL, "failed to create a listview window\n");
3552 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3553 ok(IsWindow(header), "expected header to be created\n");
3554 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3555 expect(0, r);
3556 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3557 expect(1, r);
3558 DestroyWindow(hwnd);
3559 /* unicode listview with ansi parent window */
3560 notifyFormat = -1;
3561 hwnd = create_listview_controlW(0, hwndparent);
3562 ok(hwnd != NULL, "failed to create a listview window\n");
3563 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3564 ok(IsWindow(header), "expected header to be created\n");
3565 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3566 expect(0, r);
3567 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3568 expect(1, r);
3569 DestroyWindow(hwnd);
3570 /* unicode listview with ansi parent window, return error code */
3571 notifyFormat = 0;
3572 hwnd = create_listview_controlW(0, hwndparent);
3573 ok(hwnd != NULL, "failed to create a listview window\n");
3574 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3575 ok(IsWindow(header), "expected header to be created\n");
3576 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3577 expect(0, r);
3578 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3579 expect(1, r);
3580 DestroyWindow(hwnd);
3582 DestroyWindow(hwndparentW);
3585 static void test_indentation(void)
3587 HWND hwnd;
3588 LVITEMA item;
3589 DWORD r;
3591 hwnd = create_listview_control(0);
3592 ok(hwnd != NULL, "failed to create a listview window\n");
3594 memset(&item, 0, sizeof(item));
3595 item.mask = LVIF_INDENT;
3596 item.iItem = 0;
3597 item.iIndent = I_INDENTCALLBACK;
3598 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3599 expect(0, r);
3601 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3603 item.iItem = 0;
3604 item.mask = LVIF_INDENT;
3605 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3606 expect(TRUE, r);
3608 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3609 "get indent dispinfo", FALSE);
3611 DestroyWindow(hwnd);
3614 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
3616 return 0;
3619 static BOOL is_below_comctl_5(void)
3621 HWND hwnd;
3622 BOOL ret;
3624 hwnd = create_listview_control(0);
3625 ok(hwnd != NULL, "failed to create a listview window\n");
3626 insert_item(hwnd, 0);
3628 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
3630 DestroyWindow(hwnd);
3632 return !ret;
3635 static void unload_v6_module(ULONG_PTR cookie)
3637 HANDLE hKernel32;
3638 BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
3640 hKernel32 = GetModuleHandleA("kernel32.dll");
3641 pDeactivateActCtx = (void*)GetProcAddress(hKernel32, "DeactivateActCtx");
3642 if (!pDeactivateActCtx)
3644 win_skip("Activation contexts unsupported\n");
3645 return;
3648 pDeactivateActCtx(0, cookie);
3650 DeleteFileA(manifest_name);
3653 static BOOL load_v6_module(ULONG_PTR *pcookie)
3655 HANDLE hKernel32;
3656 HANDLE (WINAPI *pCreateActCtxA)(ACTCTXA*);
3657 BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR*);
3659 ACTCTXA ctx;
3660 HANDLE hCtx;
3661 BOOL ret;
3662 HANDLE file;
3663 DWORD written;
3664 HWND hwnd;
3666 hKernel32 = GetModuleHandleA("kernel32.dll");
3667 pCreateActCtxA = (void*)GetProcAddress(hKernel32, "CreateActCtxA");
3668 pActivateActCtx = (void*)GetProcAddress(hKernel32, "ActivateActCtx");
3669 if (!(pCreateActCtxA && pActivateActCtx))
3671 win_skip("Activation contexts unsupported. No version 6 tests possible.\n");
3672 return FALSE;
3675 /* create manifest */
3676 file = CreateFileA( manifest_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
3677 if (file != INVALID_HANDLE_VALUE)
3679 ret = (WriteFile( file, manifest, sizeof(manifest)-1, &written, NULL ) &&
3680 written == sizeof(manifest)-1);
3681 CloseHandle( file );
3682 if (!ret)
3684 DeleteFileA( manifest_name );
3685 skip("Failed to fill manifest file. Skipping comctl32 V6 tests.\n");
3686 return FALSE;
3688 else
3689 trace("created %s\n", manifest_name);
3691 else
3693 skip("Failed to create manifest file. Skipping comctl32 V6 tests.\n");
3694 return FALSE;
3697 memset(&ctx, 0, sizeof(ctx));
3698 ctx.cbSize = sizeof(ctx);
3699 ctx.lpSource = manifest_name;
3701 hCtx = pCreateActCtxA(&ctx);
3702 ok(hCtx != 0, "Expected context handle\n");
3704 ret = pActivateActCtx(hCtx, pcookie);
3705 expect(TRUE, ret);
3707 if (!ret)
3709 win_skip("A problem during context activation occurred.\n");
3710 DeleteFileA(manifest_name);
3713 else
3715 /* this is a XP SP3 failure workaround */
3716 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
3717 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
3718 0, 0, 100, 100,
3719 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
3720 if (!IsWindow(hwnd))
3722 win_skip("FIXME: failed to create ListView window.\n");
3723 unload_v6_module(*pcookie);
3724 return FALSE;
3726 else
3727 DestroyWindow(hwnd);
3730 return ret;
3733 static void test_get_set_view(void)
3735 HWND hwnd;
3736 DWORD ret;
3737 DWORD_PTR style;
3739 /* test style->view mapping */
3740 hwnd = create_listview_control(0);
3741 ok(hwnd != NULL, "failed to create a listview window\n");
3743 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3744 expect(LV_VIEW_DETAILS, ret);
3746 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3747 /* LVS_ICON == 0 */
3748 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
3749 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3750 expect(LV_VIEW_ICON, ret);
3752 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3753 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
3754 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3755 expect(LV_VIEW_SMALLICON, ret);
3757 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3758 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
3759 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3760 expect(LV_VIEW_LIST, ret);
3762 /* switching view doesn't touch window style */
3763 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
3764 expect(1, ret);
3765 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3766 ok(style & LVS_LIST, "Expected style to be preserved\n");
3767 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
3768 expect(1, ret);
3769 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3770 ok(style & LVS_LIST, "Expected style to be preserved\n");
3771 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
3772 expect(1, ret);
3773 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3774 ok(style & LVS_LIST, "Expected style to be preserved\n");
3776 DestroyWindow(hwnd);
3779 static void test_canceleditlabel(void)
3781 HWND hwnd, hwndedit;
3782 DWORD ret;
3783 CHAR buff[10];
3784 LVITEMA itema;
3785 static CHAR test[] = "test";
3786 static const CHAR test1[] = "test1";
3788 hwnd = create_listview_control(LVS_EDITLABELS);
3789 ok(hwnd != NULL, "failed to create a listview window\n");
3791 insert_item(hwnd, 0);
3793 /* try without edit created */
3794 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3795 expect(TRUE, ret);
3797 /* cancel without data change */
3798 SetFocus(hwnd);
3799 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3800 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3801 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3802 expect(TRUE, ret);
3803 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3805 /* cancel after data change */
3806 memset(&itema, 0, sizeof(itema));
3807 itema.pszText = test;
3808 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
3809 expect(TRUE, ret);
3810 SetFocus(hwnd);
3811 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3812 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3813 ret = SetWindowText(hwndedit, test1);
3814 ok(ret != 0, "Expected edit text to change\n");
3815 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3816 expect(TRUE, ret);
3817 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3818 memset(&itema, 0, sizeof(itema));
3819 itema.pszText = buff;
3820 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
3821 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
3822 expect(5, ret);
3823 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
3825 DestroyWindow(hwnd);
3828 static void test_mapidindex(void)
3830 HWND hwnd;
3831 DWORD ret;
3833 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3834 hwnd = create_listview_control(LVS_OWNERDATA);
3835 ok(hwnd != NULL, "failed to create a listview window\n");
3836 insert_item(hwnd, 0);
3837 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3838 expect(-1, ret);
3839 DestroyWindow(hwnd);
3841 hwnd = create_listview_control(0);
3842 ok(hwnd != NULL, "failed to create a listview window\n");
3844 /* LVM_MAPINDEXTOID with invalid index */
3845 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3846 expect(-1, ret);
3848 insert_item(hwnd, 0);
3849 insert_item(hwnd, 1);
3851 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
3852 expect(-1, ret);
3853 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
3854 expect(-1, ret);
3856 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3857 expect(0, ret);
3858 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3859 expect(1, ret);
3860 /* remove 0 indexed item, id retained */
3861 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
3862 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3863 expect(1, ret);
3864 /* new id starts from previous value */
3865 insert_item(hwnd, 1);
3866 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3867 expect(2, ret);
3869 /* get index by id */
3870 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
3871 expect(-1, ret);
3872 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
3873 expect(-1, ret);
3874 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
3875 expect(0, ret);
3876 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
3877 expect(1, ret);
3879 DestroyWindow(hwnd);
3882 static void test_getitemspacing(void)
3884 HWND hwnd;
3885 DWORD ret;
3886 INT cx, cy;
3887 HIMAGELIST himl;
3888 HBITMAP hbmp;
3889 LVITEMA itema;
3891 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
3892 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
3894 /* LVS_ICON */
3895 hwnd = create_custom_listview_control(0);
3896 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3897 todo_wine {
3898 expect(cx, LOWORD(ret));
3899 expect(cy, HIWORD(ret));
3901 /* now try with icons */
3902 himl = ImageList_Create(40, 40, 0, 4, 4);
3903 ok(himl != NULL, "failed to create imagelist\n");
3904 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
3905 ok(hbmp != NULL, "failed to create bitmap\n");
3906 ret = ImageList_Add(himl, hbmp, 0);
3907 expect(0, ret);
3908 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
3909 expect(0, ret);
3911 itema.mask = LVIF_IMAGE;
3912 itema.iImage = 0;
3913 itema.iItem = 0;
3914 itema.iSubItem = 0;
3915 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
3916 expect(0, ret);
3917 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3918 todo_wine {
3919 /* spacing + icon size returned */
3920 expect(cx + 40, LOWORD(ret));
3921 expect(cy + 40, HIWORD(ret));
3923 DestroyWindow(hwnd);
3924 /* LVS_SMALLICON */
3925 hwnd = create_custom_listview_control(LVS_SMALLICON);
3926 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3927 todo_wine {
3928 expect(cx, LOWORD(ret));
3929 expect(cy, HIWORD(ret));
3931 DestroyWindow(hwnd);
3932 /* LVS_REPORT */
3933 hwnd = create_custom_listview_control(LVS_REPORT);
3934 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3935 todo_wine {
3936 expect(cx, LOWORD(ret));
3937 expect(cy, HIWORD(ret));
3939 DestroyWindow(hwnd);
3940 /* LVS_LIST */
3941 hwnd = create_custom_listview_control(LVS_LIST);
3942 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3943 todo_wine {
3944 expect(cx, LOWORD(ret));
3945 expect(cy, HIWORD(ret));
3947 DestroyWindow(hwnd);
3950 static void test_getcolumnwidth(void)
3952 HWND hwnd;
3953 DWORD ret;
3954 DWORD_PTR style;
3955 LVCOLUMNA col;
3957 /* default column width */
3958 hwnd = create_custom_listview_control(0);
3959 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3960 expect(0, ret);
3961 style = GetWindowLong(hwnd, GWL_STYLE);
3962 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
3963 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3964 todo_wine expect(8, ret);
3965 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
3966 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
3967 col.mask = 0;
3968 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
3969 expect(0, ret);
3970 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3971 expect(10, ret);
3972 DestroyWindow(hwnd);
3975 static void test_scrollnotify(void)
3977 HWND hwnd;
3978 DWORD ret;
3980 hwnd = create_listview_control(0);
3982 insert_column(hwnd, 0);
3983 insert_column(hwnd, 1);
3984 insert_item(hwnd, 0);
3986 /* make it scrollable - resize */
3987 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3988 expect(TRUE, ret);
3989 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3990 expect(TRUE, ret);
3992 /* try with dummy call */
3993 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3994 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
3995 expect(TRUE, ret);
3996 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
3997 "scroll notify 1", TRUE);
3999 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4000 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
4001 expect(TRUE, ret);
4002 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4003 "scroll notify 2", TRUE);
4005 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4006 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4007 expect(TRUE, ret);
4008 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4009 "scroll notify 3", TRUE);
4011 DestroyWindow(hwnd);
4014 START_TEST(listview)
4016 HMODULE hComctl32;
4017 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
4019 ULONG_PTR ctx_cookie;
4021 hComctl32 = GetModuleHandleA("comctl32.dll");
4022 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
4023 if (pInitCommonControlsEx)
4025 INITCOMMONCONTROLSEX iccex;
4026 iccex.dwSize = sizeof(iccex);
4027 iccex.dwICC = ICC_LISTVIEW_CLASSES;
4028 pInitCommonControlsEx(&iccex);
4030 else
4031 InitCommonControls();
4033 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
4035 hwndparent = create_parent_window(FALSE);
4036 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4038 g_is_below_5 = is_below_comctl_5();
4040 test_images();
4041 test_checkboxes();
4042 test_items();
4043 test_create();
4044 test_redraw();
4045 test_customdraw();
4046 test_icon_spacing();
4047 test_color();
4048 test_item_count();
4049 test_item_position();
4050 test_columns();
4051 test_getorigin();
4052 test_multiselect();
4053 test_getitemrect();
4054 test_subitem_rect();
4055 test_sorting();
4056 test_ownerdata();
4057 test_norecompute();
4058 test_nosortheader();
4059 test_setredraw();
4060 test_hittest();
4061 test_getviewrect();
4062 test_getitemposition();
4063 test_columnscreation();
4064 test_editbox();
4065 test_notifyformat();
4066 test_indentation();
4067 test_getitemspacing();
4068 test_getcolumnwidth();
4070 if (!load_v6_module(&ctx_cookie))
4072 DestroyWindow(hwndparent);
4073 return;
4076 /* comctl32 version 6 tests start here */
4077 test_get_set_view();
4078 test_canceleditlabel();
4079 test_mapidindex();
4080 test_scrollnotify();
4082 unload_v6_module(ctx_cookie);
4084 DestroyWindow(hwndparent);