push 6377a023768d7480eb1b17e57456824888936b43
[wine/hacks.git] / dlls / comctl32 / tests / listview.c
blob888b323bb3b11a73ba0a8fa7ca5eda1f1b6283c3
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 { WM_WINDOWPOSCHANGING, sent },
271 { WM_NCCALCSIZE, sent },
272 { WM_WINDOWPOSCHANGED, sent },
273 { WM_MOVE, sent|defwinproc },
274 { WM_SIZE, sent|defwinproc },
275 /* the rest is todo */
276 { WM_WINDOWPOSCHANGING, sent },
277 { WM_WINDOWPOSCHANGED, sent },
278 { 0 }
281 static const struct message scroll_parent_seq[] = {
282 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
283 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
284 { 0 }
287 struct subclass_info
289 WNDPROC oldproc;
292 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
294 static LONG defwndproc_counter = 0;
295 LRESULT ret;
296 struct message msg;
298 msg.message = message;
299 msg.flags = sent|wparam|lparam;
300 if (defwndproc_counter) msg.flags |= defwinproc;
301 msg.wParam = wParam;
302 msg.lParam = lParam;
303 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
305 /* log system messages, except for painting */
306 if (message < WM_USER &&
307 message != WM_PAINT &&
308 message != WM_ERASEBKGND &&
309 message != WM_NCPAINT &&
310 message != WM_NCHITTEST &&
311 message != WM_GETTEXT &&
312 message != WM_GETICON &&
313 message != WM_DEVICECHANGE)
315 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
317 add_message(sequences, PARENT_SEQ_INDEX, &msg);
319 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
321 switch (message)
323 case WM_NOTIFY:
325 switch (((NMHDR*)lParam)->code)
327 case LVN_BEGINLABELEDIT:
328 /* subclass edit box */
329 if (!blockEdit)
330 subclass_editbox(((NMHDR*)lParam)->hwndFrom);
332 return blockEdit;
334 case LVN_ENDLABELEDIT:
335 /* always accept new item text */
336 return TRUE;
337 case LVN_BEGINSCROLL:
338 case LVN_ENDSCROLL:
340 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
342 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
343 "BEGIN" : "END", pScroll->dx, pScroll->dy);
345 break;
346 case LVN_ITEMCHANGED:
347 if (g_dump_itemchanged)
349 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
350 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
351 nmlv->iItem, nmlv->uNewState, nmlv->uOldState, nmlv->uChanged);
353 break;
355 break;
357 case WM_NOTIFYFORMAT:
359 /* force to return format */
360 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
361 break;
365 defwndproc_counter++;
366 ret = DefWindowProcA(hwnd, message, wParam, lParam);
367 defwndproc_counter--;
369 return ret;
372 static BOOL register_parent_wnd_class(BOOL Unicode)
374 WNDCLASSA clsA;
375 WNDCLASSW clsW;
377 if (Unicode)
379 clsW.style = 0;
380 clsW.lpfnWndProc = parent_wnd_proc;
381 clsW.cbClsExtra = 0;
382 clsW.cbWndExtra = 0;
383 clsW.hInstance = GetModuleHandleW(NULL);
384 clsW.hIcon = 0;
385 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
386 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
387 clsW.lpszMenuName = NULL;
388 clsW.lpszClassName = testparentclassW;
390 else
392 clsA.style = 0;
393 clsA.lpfnWndProc = parent_wnd_proc;
394 clsA.cbClsExtra = 0;
395 clsA.cbWndExtra = 0;
396 clsA.hInstance = GetModuleHandleA(NULL);
397 clsA.hIcon = 0;
398 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
399 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
400 clsA.lpszMenuName = NULL;
401 clsA.lpszClassName = "Listview test parent class";
404 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
407 static HWND create_parent_window(BOOL Unicode)
409 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W'};
411 if (!register_parent_wnd_class(Unicode))
412 return NULL;
414 blockEdit = FALSE;
415 notifyFormat = -1;
417 if (Unicode)
418 return CreateWindowExW(0, testparentclassW, nameW,
419 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
420 WS_MAXIMIZEBOX | WS_VISIBLE,
421 0, 0, 100, 100,
422 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
423 else
424 return CreateWindowExA(0, "Listview test parent class",
425 "Listview test parent window",
426 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
427 WS_MAXIMIZEBOX | WS_VISIBLE,
428 0, 0, 100, 100,
429 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
432 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
434 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
435 static LONG defwndproc_counter = 0;
436 LRESULT ret;
437 struct message msg;
439 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
441 /* some debug output for style changing */
442 if ((message == WM_STYLECHANGING ||
443 message == WM_STYLECHANGED) && lParam)
445 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
446 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
449 msg.message = message;
450 msg.flags = sent|wparam|lparam;
451 if (defwndproc_counter) msg.flags |= defwinproc;
452 msg.wParam = wParam;
453 msg.lParam = lParam;
454 msg.id = LISTVIEW_ID;
455 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
457 defwndproc_counter++;
458 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
459 defwndproc_counter--;
460 return ret;
463 static HWND create_listview_control(DWORD style)
465 struct subclass_info *info;
466 HWND hwnd;
467 RECT rect;
469 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
470 if (!info)
471 return NULL;
473 GetClientRect(hwndparent, &rect);
474 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
475 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
476 0, 0, rect.right, rect.bottom,
477 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
478 ok(hwnd != NULL, "gle=%d\n", GetLastError());
480 if (!hwnd)
482 HeapFree(GetProcessHeap(), 0, info);
483 return NULL;
486 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
487 (LONG_PTR)listview_subclass_proc);
488 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
490 return hwnd;
493 /* unicode listview window with specified parent */
494 static HWND create_listview_controlW(DWORD style, HWND parent)
496 struct subclass_info *info;
497 HWND hwnd;
498 RECT rect;
499 static const WCHAR nameW[] = {'f','o','o',0};
501 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
502 if (!info)
503 return NULL;
505 GetClientRect(parent, &rect);
506 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
507 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
508 0, 0, rect.right, rect.bottom,
509 parent, NULL, GetModuleHandleW(NULL), NULL);
510 ok(hwnd != NULL, "gle=%d\n", GetLastError());
512 if (!hwnd)
514 HeapFree(GetProcessHeap(), 0, info);
515 return NULL;
518 info->oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
519 (LONG_PTR)listview_subclass_proc);
520 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)info);
522 return hwnd;
525 static HWND create_custom_listview_control(DWORD style)
527 struct subclass_info *info;
528 HWND hwnd;
529 RECT rect;
531 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
532 if (!info)
533 return NULL;
535 GetClientRect(hwndparent, &rect);
536 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
537 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
538 0, 0, rect.right, rect.bottom,
539 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
540 ok(hwnd != NULL, "gle=%d\n", GetLastError());
542 if (!hwnd)
544 HeapFree(GetProcessHeap(), 0, info);
545 return NULL;
548 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
549 (LONG_PTR)listview_subclass_proc);
550 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
552 return hwnd;
555 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
557 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
558 static LONG defwndproc_counter = 0;
559 LRESULT ret;
560 struct message msg;
562 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
564 msg.message = message;
565 msg.flags = sent|wparam|lparam;
566 if (defwndproc_counter) msg.flags |= defwinproc;
567 msg.wParam = wParam;
568 msg.lParam = lParam;
569 msg.id = HEADER_ID;
570 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
572 defwndproc_counter++;
573 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
574 defwndproc_counter--;
575 return ret;
578 static HWND subclass_header(HWND hwndListview)
580 struct subclass_info *info;
581 HWND hwnd;
583 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
584 if (!info)
585 return NULL;
587 hwnd = ListView_GetHeader(hwndListview);
588 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
589 (LONG_PTR)header_subclass_proc);
590 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
592 return hwnd;
595 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
597 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
598 static LONG defwndproc_counter = 0;
599 LRESULT ret;
600 struct message msg;
602 msg.message = message;
603 msg.flags = sent|wparam|lparam;
604 if (defwndproc_counter) msg.flags |= defwinproc;
605 msg.wParam = wParam;
606 msg.lParam = lParam;
608 /* all we need is sizing */
609 if (message == WM_WINDOWPOSCHANGING ||
610 message == WM_NCCALCSIZE ||
611 message == WM_WINDOWPOSCHANGED ||
612 message == WM_MOVE ||
613 message == WM_SIZE)
615 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
618 defwndproc_counter++;
619 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
620 defwndproc_counter--;
621 return ret;
624 static HWND subclass_editbox(HWND hwndListview)
626 struct subclass_info *info;
627 HWND hwnd;
629 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
630 if (!info)
631 return NULL;
633 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
634 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
635 (LONG_PTR)editbox_subclass_proc);
636 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
638 return hwnd;
641 /* Performs a single LVM_HITTEST test */
642 static void test_lvm_hittest(HWND hwnd, INT x, INT y, INT item, UINT flags,
643 BOOL todo_item, BOOL todo_flags, int line)
645 LVHITTESTINFO lpht;
646 DWORD ret;
648 lpht.pt.x = x;
649 lpht.pt.y = y;
650 lpht.iSubItem = 10;
652 trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
653 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
655 if (todo_item)
657 todo_wine
659 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
660 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
661 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
664 else
666 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
667 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
668 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
671 if (todo_flags)
673 todo_wine
674 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
676 else
677 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
680 /* Performs a single LVM_SUBITEMHITTEST test */
681 static void test_lvm_subitemhittest(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
682 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
684 LVHITTESTINFO lpht;
685 DWORD ret;
687 lpht.pt.x = x;
688 lpht.pt.y = y;
690 trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
691 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
693 if (todo_item)
695 todo_wine
697 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
698 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
701 else
703 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
704 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
707 if (todo_subitem)
709 todo_wine
710 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
712 else
713 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
715 if (todo_flags)
717 todo_wine
718 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
720 else
721 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
724 static void test_images(void)
726 HWND hwnd;
727 DWORD r;
728 LVITEM item;
729 HIMAGELIST himl;
730 HBITMAP hbmp;
731 RECT r1, r2;
732 static CHAR hello[] = "hello";
734 himl = ImageList_Create(40, 40, 0, 4, 4);
735 ok(himl != NULL, "failed to create imagelist\n");
737 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
738 ok(hbmp != NULL, "failed to create bitmap\n");
740 r = ImageList_Add(himl, hbmp, 0);
741 ok(r == 0, "should be zero\n");
743 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
744 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
745 ok(hwnd != NULL, "failed to create listview window\n");
747 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
748 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
750 ok(r == 0, "should return zero\n");
752 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
753 ok(r == 0, "should return zero\n");
755 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
756 /* returns dimensions */
758 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
759 ok(r == 0, "should be zero items\n");
761 item.mask = LVIF_IMAGE | LVIF_TEXT;
762 item.iItem = 0;
763 item.iSubItem = 1;
764 item.iImage = 0;
765 item.pszText = 0;
766 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
767 ok(r == -1, "should fail\n");
769 item.iSubItem = 0;
770 item.pszText = hello;
771 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
772 ok(r == 0, "should not fail\n");
774 memset(&r1, 0, sizeof r1);
775 r1.left = LVIR_ICON;
776 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
778 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
779 ok(r == TRUE, "should not fail\n");
781 item.iSubItem = 0;
782 item.pszText = hello;
783 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
784 ok(r == 0, "should not fail\n");
786 memset(&r2, 0, sizeof r2);
787 r2.left = LVIR_ICON;
788 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
790 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
792 DestroyWindow(hwnd);
795 static void test_checkboxes(void)
797 HWND hwnd;
798 LVITEMA item;
799 DWORD r;
800 static CHAR text[] = "Text",
801 text2[] = "Text2",
802 text3[] = "Text3";
804 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
805 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
806 ok(hwnd != NULL, "failed to create listview window\n");
808 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
809 item.mask = LVIF_TEXT | LVIF_STATE;
810 item.stateMask = 0xffff;
811 item.state = 0xfccc;
812 item.iItem = 0;
813 item.iSubItem = 0;
814 item.pszText = text;
815 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
816 ok(r == 0, "ret %d\n", r);
818 item.iItem = 0;
819 item.mask = LVIF_STATE;
820 item.stateMask = 0xffff;
821 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
822 ok(item.state == 0xfccc, "state %x\n", item.state);
824 /* Don't set LVIF_STATE */
825 item.mask = LVIF_TEXT;
826 item.stateMask = 0xffff;
827 item.state = 0xfccc;
828 item.iItem = 1;
829 item.iSubItem = 0;
830 item.pszText = text;
831 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
832 ok(r == 1, "ret %d\n", r);
834 item.iItem = 1;
835 item.mask = LVIF_STATE;
836 item.stateMask = 0xffff;
837 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
838 ok(item.state == 0, "state %x\n", item.state);
840 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
841 ok(r == 0, "should return zero\n");
843 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
844 item.iItem = 0;
845 item.mask = LVIF_STATE;
846 item.stateMask = 0xffff;
847 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
848 ok(item.state == 0x1ccc, "state %x\n", item.state);
850 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
851 item.iItem = 2;
852 item.mask = LVIF_TEXT;
853 item.state = 0;
854 item.pszText = text2;
855 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
856 ok(r == 2, "ret %d\n", r);
858 item.iItem = 2;
859 item.mask = LVIF_STATE;
860 item.stateMask = 0xffff;
861 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
862 ok(item.state == 0x1000, "state %x\n", item.state);
864 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
865 item.iItem = 3;
866 item.mask = LVIF_TEXT | LVIF_STATE;
867 item.stateMask = 0xffff;
868 item.state = 0x2aaa;
869 item.pszText = text3;
870 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
871 ok(r == 3, "ret %d\n", r);
873 item.iItem = 3;
874 item.mask = LVIF_STATE;
875 item.stateMask = 0xffff;
876 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
877 ok(item.state == 0x1aaa, "state %x\n", item.state);
879 /* Set an item's state to checked */
880 item.iItem = 3;
881 item.mask = LVIF_STATE;
882 item.stateMask = 0xf000;
883 item.state = 0x2000;
884 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
886 item.iItem = 3;
887 item.mask = LVIF_STATE;
888 item.stateMask = 0xffff;
889 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
890 ok(item.state == 0x2aaa, "state %x\n", item.state);
892 /* Check that only the bits we asked for are returned,
893 * and that all the others are set to zero
895 item.iItem = 3;
896 item.mask = LVIF_STATE;
897 item.stateMask = 0xf000;
898 item.state = 0xffff;
899 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
900 ok(item.state == 0x2000, "state %x\n", item.state);
902 /* Set the style again and check that doesn't change an item's state */
903 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
904 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
906 item.iItem = 3;
907 item.mask = LVIF_STATE;
908 item.stateMask = 0xffff;
909 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
910 ok(item.state == 0x2aaa, "state %x\n", item.state);
912 /* Unsetting the checkbox extended style doesn't change an item's state */
913 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
914 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
916 item.iItem = 3;
917 item.mask = LVIF_STATE;
918 item.stateMask = 0xffff;
919 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
920 ok(item.state == 0x2aaa, "state %x\n", item.state);
922 /* Now setting the style again will change an item's state */
923 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
924 ok(r == 0, "ret %x\n", r);
926 item.iItem = 3;
927 item.mask = LVIF_STATE;
928 item.stateMask = 0xffff;
929 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
930 ok(item.state == 0x1aaa, "state %x\n", item.state);
932 /* Toggle checkbox tests (bug 9934) */
933 memset (&item, 0xcc, sizeof(item));
934 item.mask = LVIF_STATE;
935 item.iItem = 3;
936 item.iSubItem = 0;
937 item.state = LVIS_FOCUSED;
938 item.stateMask = LVIS_FOCUSED;
939 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
940 expect(1, r);
942 item.iItem = 3;
943 item.mask = LVIF_STATE;
944 item.stateMask = 0xffff;
945 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
946 ok(item.state == 0x1aab, "state %x\n", item.state);
948 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
949 expect(0, r);
950 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
951 expect(0, r);
953 item.iItem = 3;
954 item.mask = LVIF_STATE;
955 item.stateMask = 0xffff;
956 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
957 ok(item.state == 0x2aab, "state %x\n", item.state);
959 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
960 expect(0, r);
961 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
962 expect(0, r);
964 item.iItem = 3;
965 item.mask = LVIF_STATE;
966 item.stateMask = 0xffff;
967 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
968 ok(item.state == 0x1aab, "state %x\n", item.state);
970 DestroyWindow(hwnd);
973 static void insert_column(HWND hwnd, int idx)
975 LVCOLUMN column;
976 DWORD rc;
978 memset(&column, 0xcc, sizeof(column));
979 column.mask = LVCF_SUBITEM;
980 column.iSubItem = idx;
982 rc = ListView_InsertColumn(hwnd, idx, &column);
983 expect(idx, rc);
986 static void insert_item(HWND hwnd, int idx)
988 static CHAR text[] = "foo";
990 LVITEMA item;
991 DWORD rc;
993 memset(&item, 0xcc, sizeof (item));
994 item.mask = LVIF_TEXT;
995 item.iItem = idx;
996 item.iSubItem = 0;
997 item.pszText = text;
999 rc = ListView_InsertItem(hwnd, &item);
1000 expect(idx, rc);
1003 static void test_items(void)
1005 const LPARAM lparamTest = 0x42;
1006 HWND hwnd;
1007 LVITEMA item;
1008 DWORD r;
1009 static CHAR text[] = "Text";
1011 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1012 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1013 ok(hwnd != NULL, "failed to create listview window\n");
1016 * Test setting/getting item params
1019 /* Set up two columns */
1020 insert_column(hwnd, 0);
1021 insert_column(hwnd, 1);
1023 /* LVIS_SELECTED with zero stateMask */
1024 /* set */
1025 memset (&item, 0, sizeof (item));
1026 item.mask = LVIF_STATE;
1027 item.state = LVIS_SELECTED;
1028 item.stateMask = 0;
1029 item.iItem = 0;
1030 item.iSubItem = 0;
1031 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1032 ok(r == 0, "ret %d\n", r);
1033 /* get */
1034 memset (&item, 0xcc, sizeof (item));
1035 item.mask = LVIF_STATE;
1036 item.stateMask = LVIS_SELECTED;
1037 item.state = 0;
1038 item.iItem = 0;
1039 item.iSubItem = 0;
1040 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1041 ok(r != 0, "ret %d\n", r);
1042 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1043 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1045 /* LVIS_SELECTED with zero stateMask */
1046 /* set */
1047 memset (&item, 0, sizeof (item));
1048 item.mask = LVIF_STATE;
1049 item.state = LVIS_FOCUSED;
1050 item.stateMask = 0;
1051 item.iItem = 0;
1052 item.iSubItem = 0;
1053 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1054 ok(r == 0, "ret %d\n", r);
1055 /* get */
1056 memset (&item, 0xcc, sizeof (item));
1057 item.mask = LVIF_STATE;
1058 item.stateMask = LVIS_FOCUSED;
1059 item.state = 0;
1060 item.iItem = 0;
1061 item.iSubItem = 0;
1062 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1063 ok(r != 0, "ret %d\n", r);
1064 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1065 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1067 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1068 /* set */
1069 memset (&item, 0, sizeof (item));
1070 item.mask = LVIF_STATE;
1071 item.state = LVIS_CUT;
1072 item.stateMask = LVIS_FOCUSED;
1073 item.iItem = 0;
1074 item.iSubItem = 0;
1075 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1076 ok(r == 0, "ret %d\n", r);
1077 /* get */
1078 memset (&item, 0xcc, sizeof (item));
1079 item.mask = LVIF_STATE;
1080 item.stateMask = LVIS_CUT;
1081 item.state = 0;
1082 item.iItem = 0;
1083 item.iSubItem = 0;
1084 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1085 ok(r != 0, "ret %d\n", r);
1086 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1087 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1089 /* Insert an item with just a param */
1090 memset (&item, 0xcc, sizeof (item));
1091 item.mask = LVIF_PARAM;
1092 item.iItem = 0;
1093 item.iSubItem = 0;
1094 item.lParam = lparamTest;
1095 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1096 ok(r == 0, "ret %d\n", r);
1098 /* Test getting of the param */
1099 memset (&item, 0xcc, sizeof (item));
1100 item.mask = LVIF_PARAM;
1101 item.iItem = 0;
1102 item.iSubItem = 0;
1103 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1104 ok(r != 0, "ret %d\n", r);
1105 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1107 /* Set up a subitem */
1108 memset (&item, 0xcc, sizeof (item));
1109 item.mask = LVIF_TEXT;
1110 item.iItem = 0;
1111 item.iSubItem = 1;
1112 item.pszText = text;
1113 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1114 ok(r != 0, "ret %d\n", r);
1116 /* Query param from subitem: returns main item param */
1117 memset (&item, 0xcc, sizeof (item));
1118 item.mask = LVIF_PARAM;
1119 item.iItem = 0;
1120 item.iSubItem = 1;
1121 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1122 ok(r != 0, "ret %d\n", r);
1123 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1125 /* Set up param on first subitem: no effect */
1126 memset (&item, 0xcc, sizeof (item));
1127 item.mask = LVIF_PARAM;
1128 item.iItem = 0;
1129 item.iSubItem = 1;
1130 item.lParam = lparamTest+1;
1131 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1132 ok(r == 0, "ret %d\n", r);
1134 /* Query param from subitem again: should still return main item param */
1135 memset (&item, 0xcc, sizeof (item));
1136 item.mask = LVIF_PARAM;
1137 item.iItem = 0;
1138 item.iSubItem = 1;
1139 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1140 ok(r != 0, "ret %d\n", r);
1141 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1143 /**** Some tests of state highlighting ****/
1144 memset (&item, 0xcc, sizeof (item));
1145 item.mask = LVIF_STATE;
1146 item.iItem = 0;
1147 item.iSubItem = 0;
1148 item.state = LVIS_SELECTED;
1149 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1150 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1151 ok(r != 0, "ret %d\n", r);
1152 item.iSubItem = 1;
1153 item.state = LVIS_DROPHILITED;
1154 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1155 ok(r != 0, "ret %d\n", r);
1157 memset (&item, 0xcc, sizeof (item));
1158 item.mask = LVIF_STATE;
1159 item.iItem = 0;
1160 item.iSubItem = 0;
1161 item.stateMask = -1;
1162 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1163 ok(r != 0, "ret %d\n", r);
1164 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1165 item.iSubItem = 1;
1166 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1167 ok(r != 0, "ret %d\n", r);
1168 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1170 /* some notnull but meaningless masks */
1171 memset (&item, 0, sizeof(item));
1172 item.mask = LVIF_NORECOMPUTE;
1173 item.iItem = 0;
1174 item.iSubItem = 0;
1175 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1176 ok(r != 0, "ret %d\n", r);
1177 memset (&item, 0, sizeof(item));
1178 item.mask = LVIF_DI_SETITEM;
1179 item.iItem = 0;
1180 item.iSubItem = 0;
1181 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1182 ok(r != 0, "ret %d\n", r);
1184 /* set text to callback value already having it */
1185 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1186 expect(TRUE, r);
1187 memset (&item, 0, sizeof (item));
1188 item.mask = LVIF_TEXT;
1189 item.pszText = LPSTR_TEXTCALLBACK;
1190 item.iItem = 0;
1191 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1192 ok(r == 0, "ret %d\n", r);
1193 memset (&item, 0, sizeof (item));
1195 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1197 item.pszText = LPSTR_TEXTCALLBACK;
1198 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1199 expect(TRUE, r);
1201 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1202 "check callback text comparison rule", FALSE);
1204 DestroyWindow(hwnd);
1207 static void test_columns(void)
1209 HWND hwnd, hwndheader;
1210 LVCOLUMN column;
1211 DWORD rc;
1212 INT order[2];
1214 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1215 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1216 ok(hwnd != NULL, "failed to create listview window\n");
1218 /* Add a column with no mask */
1219 memset(&column, 0xcc, sizeof(column));
1220 column.mask = 0;
1221 rc = ListView_InsertColumn(hwnd, 0, &column);
1222 ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
1224 /* Check its width */
1225 rc = ListView_GetColumnWidth(hwnd, 0);
1226 ok(rc==10 ||
1227 broken(rc==0), /* win9x */
1228 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1230 DestroyWindow(hwnd);
1232 /* LVM_GETCOLUMNORDERARRAY */
1233 hwnd = create_listview_control(0);
1234 hwndheader = subclass_header(hwnd);
1236 memset(&column, 0, sizeof(column));
1237 column.mask = LVCF_WIDTH;
1238 column.cx = 100;
1239 rc = ListView_InsertColumn(hwnd, 0, &column);
1240 ok(rc == 0, "Inserting column failed with %d\n", rc);
1242 column.cx = 200;
1243 rc = ListView_InsertColumn(hwnd, 1, &column);
1244 ok(rc == 1, "Inserting column failed with %d\n", rc);
1246 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1248 rc = SendMessage(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1249 ok(rc != 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1250 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1251 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1253 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1255 DestroyWindow(hwnd);
1257 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1258 static WNDPROC listviewWndProc;
1259 static HIMAGELIST test_create_imagelist;
1261 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1263 LRESULT ret;
1265 if (uMsg == WM_CREATE)
1267 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1268 lpcs->style |= LVS_REPORT;
1270 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1271 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1272 return ret;
1275 static void test_create(void)
1277 HWND hList;
1278 HWND hHeader;
1279 LONG_PTR ret;
1280 LONG r;
1281 LVCOLUMNA col;
1282 RECT rect;
1283 WNDCLASSEX cls;
1284 cls.cbSize = sizeof(WNDCLASSEX);
1285 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1286 listviewWndProc = cls.lpfnWndProc;
1287 cls.lpfnWndProc = create_test_wndproc;
1288 cls.lpszClassName = "MyListView32";
1289 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1291 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1292 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1293 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1294 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1295 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1296 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1297 DestroyWindow(hList);
1299 /* header isn't created on LVS_ICON and LVS_LIST styles */
1300 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1301 GetModuleHandle(NULL), 0);
1302 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1303 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1304 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1305 /* insert column */
1306 memset(&col, 0, sizeof(LVCOLUMNA));
1307 col.mask = LVCF_WIDTH;
1308 col.cx = 100;
1309 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1310 ok(r == 0, "Expected 0 column's inserted\n");
1311 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1312 ok(IsWindow(hHeader), "Header should be created\n");
1313 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1314 DestroyWindow(hList);
1316 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1317 GetModuleHandle(NULL), 0);
1318 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1319 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1320 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1321 /* insert column */
1322 memset(&col, 0, sizeof(LVCOLUMNA));
1323 col.mask = LVCF_WIDTH;
1324 col.cx = 100;
1325 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1326 ok(r == 0, "Expected 0 column's inserted\n");
1327 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1328 ok(IsWindow(hHeader), "Header should be created\n");
1329 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1330 DestroyWindow(hList);
1332 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1333 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1334 GetModuleHandle(NULL), 0);
1335 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1336 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1337 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1338 ok(IsWindow(hHeader), "Header should be created\n");
1339 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1340 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1341 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1342 ok(IsWindow(hHeader), "Header should be created\n");
1343 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1344 DestroyWindow(hList);
1346 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1347 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1348 GetModuleHandle(NULL), 0);
1349 ret = SetWindowLongPtr(hList, GWL_STYLE,
1350 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1351 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1352 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1353 ok(IsWindow(hHeader), "Header should be created\n");
1354 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1355 ret = SetWindowLongPtr(hList, GWL_STYLE,
1356 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1357 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1358 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1359 ok(IsWindow(hHeader), "Header should be created\n");
1360 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1361 DestroyWindow(hList);
1363 /* LVS_REPORT without WS_VISIBLE */
1364 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1365 GetModuleHandle(NULL), 0);
1366 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1367 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1368 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1369 /* insert column */
1370 memset(&col, 0, sizeof(LVCOLUMNA));
1371 col.mask = LVCF_WIDTH;
1372 col.cx = 100;
1373 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1374 ok(r == 0, "Expected 0 column's inserted\n");
1375 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1376 ok(IsWindow(hHeader), "Header should be created\n");
1377 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1378 DestroyWindow(hList);
1380 /* LVS_REPORT without WS_VISIBLE, try to show it */
1381 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1382 GetModuleHandle(NULL), 0);
1383 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1384 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1385 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1386 ShowWindow(hList, SW_SHOW);
1387 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1388 ok(IsWindow(hHeader), "Header should be created\n");
1389 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1390 DestroyWindow(hList);
1392 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1393 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1394 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1395 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1396 ok(IsWindow(hHeader), "Header should be created\n");
1397 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1398 /* HDS_DRAGDROP set by default */
1399 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1400 DestroyWindow(hList);
1402 /* setting LVS_EX_HEADERDRAGDROP creates header */
1403 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1404 GetModuleHandle(NULL), 0);
1405 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1406 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1407 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1408 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1409 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1410 ok(IsWindow(hHeader) ||
1411 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1412 "Header should be created\n");
1413 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1414 DestroyWindow(hList);
1416 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1417 hList = create_custom_listview_control(0);
1418 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1419 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1420 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1421 DestroyWindow(hList);
1423 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1424 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1425 GetModuleHandle(NULL), 0);
1426 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1427 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1429 rect.left = LVIR_BOUNDS;
1430 rect.top = 1;
1431 rect.right = rect.bottom = -10;
1432 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1433 ok(r != 0, "Expected not-null LRESULT\n");
1435 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1436 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1437 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1439 DestroyWindow(hList);
1441 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1442 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1443 hList = create_listview_control(LVS_OWNERDRAWFIXED);
1444 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1445 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1446 DestroyWindow(hList);
1449 static void test_redraw(void)
1451 HWND hwnd, hwndheader;
1452 HDC hdc;
1453 BOOL res;
1454 DWORD r;
1456 hwnd = create_listview_control(0);
1457 hwndheader = subclass_header(hwnd);
1459 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1461 trace("invalidate & update\n");
1462 InvalidateRect(hwnd, NULL, TRUE);
1463 UpdateWindow(hwnd);
1464 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1466 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1468 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1469 /* 1. Without backbuffer */
1470 res = ListView_SetBkColor(hwnd, CLR_NONE);
1471 expect(TRUE, res);
1473 hdc = GetWindowDC(hwndparent);
1475 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1476 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1477 ok(r != 0, "Expected not zero result\n");
1478 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1479 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1481 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1482 expect(TRUE, res);
1484 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1485 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1486 ok(r != 0, "Expected not zero result\n");
1487 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1488 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1490 /* 2. With backbuffer */
1491 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1492 LVS_EX_DOUBLEBUFFER);
1493 res = ListView_SetBkColor(hwnd, CLR_NONE);
1494 expect(TRUE, res);
1496 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1497 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1498 ok(r != 0, "Expected not zero result\n");
1499 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1500 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1502 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1503 expect(TRUE, res);
1505 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1506 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1507 todo_wine ok(r != 0, "Expected not zero result\n");
1508 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1509 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1511 ReleaseDC(hwndparent, hdc);
1513 DestroyWindow(hwnd);
1516 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1518 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1520 if(msg == WM_NOTIFY) {
1521 NMHDR *nmhdr = (PVOID)lp;
1522 if(nmhdr->code == NM_CUSTOMDRAW) {
1523 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1524 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1525 switch(nmlvcd->nmcd.dwDrawStage) {
1526 case CDDS_PREPAINT:
1527 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1528 return CDRF_NOTIFYITEMDRAW;
1529 case CDDS_ITEMPREPAINT:
1530 nmlvcd->clrTextBk = CLR_DEFAULT;
1531 return CDRF_NOTIFYSUBITEMDRAW;
1532 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1533 clr = GetBkColor(nmlvcd->nmcd.hdc);
1534 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1535 return CDRF_NOTIFYPOSTPAINT;
1536 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1537 clr = GetBkColor(nmlvcd->nmcd.hdc);
1538 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1539 return CDRF_DODEFAULT;
1541 return CDRF_DODEFAULT;
1545 return DefWindowProcA(hwnd, msg, wp, lp);
1548 static void test_customdraw(void)
1550 HWND hwnd;
1551 WNDPROC oldwndproc;
1553 hwnd = create_listview_control(0);
1555 insert_column(hwnd, 0);
1556 insert_column(hwnd, 1);
1557 insert_item(hwnd, 0);
1559 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1560 (LONG_PTR)cd_wndproc);
1562 InvalidateRect(hwnd, NULL, TRUE);
1563 UpdateWindow(hwnd);
1565 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1567 DestroyWindow(hwnd);
1570 static void test_icon_spacing(void)
1572 /* LVM_SETICONSPACING */
1573 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1575 HWND hwnd;
1576 WORD w, h;
1577 DWORD r;
1579 hwnd = create_custom_listview_control(LVS_ICON);
1580 ok(hwnd != NULL, "failed to create a listview window\n");
1582 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
1583 expect(NFR_ANSI, r);
1585 /* reset the icon spacing to defaults */
1586 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1588 /* now we can request what the defaults are */
1589 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1590 w = LOWORD(r);
1591 h = HIWORD(r);
1593 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1595 trace("test icon spacing\n");
1597 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1598 ok(r == MAKELONG(w, h) ||
1599 broken(r == MAKELONG(w, w)), /* win98 */
1600 "Expected %d, got %d\n", MAKELONG(w, h), r);
1602 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1603 expect(MAKELONG(20,30), r);
1605 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1606 expect(MAKELONG(25,35), r);
1608 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1610 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1611 DestroyWindow(hwnd);
1614 static void test_color(void)
1616 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1618 HWND hwnd;
1619 DWORD r;
1620 int i;
1622 COLORREF color;
1623 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1625 hwnd = create_listview_control(0);
1626 ok(hwnd != NULL, "failed to create a listview window\n");
1628 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1630 trace("test color seq\n");
1631 for (i = 0; i < 4; i++)
1633 color = colors[i];
1635 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1636 expect(TRUE, r);
1637 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1638 expect(color, r);
1640 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1641 expect (TRUE, r);
1642 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1643 expect(color, r);
1645 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1646 expect(TRUE, r);
1647 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1648 expect(color, r);
1651 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1653 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1654 DestroyWindow(hwnd);
1657 static void test_item_count(void)
1659 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1661 HWND hwnd;
1662 DWORD r;
1663 HDC hdc;
1664 HFONT hOldFont;
1665 TEXTMETRICA tm;
1666 RECT rect;
1667 INT height;
1669 LVITEM item0;
1670 LVITEM item1;
1671 LVITEM item2;
1672 static CHAR item0text[] = "item0";
1673 static CHAR item1text[] = "item1";
1674 static CHAR item2text[] = "item2";
1676 hwnd = create_listview_control(0);
1677 ok(hwnd != NULL, "failed to create a listview window\n");
1679 /* resize in dpiaware manner to fit all 3 items added */
1680 hdc = GetDC(0);
1681 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1682 GetTextMetricsA(hdc, &tm);
1683 /* 2 extra pixels for bounds and header border */
1684 height = tm.tmHeight + 2;
1685 SelectObject(hdc, hOldFont);
1686 ReleaseDC(0, hdc);
1688 GetWindowRect(hwnd, &rect);
1689 /* 3 items + 1 header + 1 to be sure */
1690 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1692 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1694 trace("test item count\n");
1696 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1697 expect(0, r);
1699 /* [item0] */
1700 item0.mask = LVIF_TEXT;
1701 item0.iItem = 0;
1702 item0.iSubItem = 0;
1703 item0.pszText = item0text;
1704 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1705 expect(0, r);
1707 /* [item0, item1] */
1708 item1.mask = LVIF_TEXT;
1709 item1.iItem = 1;
1710 item1.iSubItem = 0;
1711 item1.pszText = item1text;
1712 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1713 expect(1, r);
1715 /* [item0, item1, item2] */
1716 item2.mask = LVIF_TEXT;
1717 item2.iItem = 2;
1718 item2.iSubItem = 0;
1719 item2.pszText = item2text;
1720 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1721 expect(2, r);
1723 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1724 expect(3, r);
1726 /* [item0, item1] */
1727 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1728 expect(TRUE, r);
1730 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1731 expect(2, r);
1733 /* [] */
1734 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1735 expect(TRUE, r);
1737 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1738 expect(0, r);
1740 /* [item0] */
1741 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1742 expect(0, r);
1744 /* [item0, item1] */
1745 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1746 expect(1, r);
1748 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1749 expect(2, r);
1751 /* [item0, item1, item2] */
1752 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1753 expect(2, r);
1755 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1756 expect(3, r);
1758 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1760 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1761 DestroyWindow(hwnd);
1764 static void test_item_position(void)
1766 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1768 HWND hwnd;
1769 DWORD r;
1770 POINT position;
1772 LVITEM item0;
1773 LVITEM item1;
1774 LVITEM item2;
1775 static CHAR item0text[] = "item0";
1776 static CHAR item1text[] = "item1";
1777 static CHAR item2text[] = "item2";
1779 hwnd = create_custom_listview_control(LVS_ICON);
1780 ok(hwnd != NULL, "failed to create a listview window\n");
1782 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1784 trace("test item position\n");
1786 /* [item0] */
1787 item0.mask = LVIF_TEXT;
1788 item0.iItem = 0;
1789 item0.iSubItem = 0;
1790 item0.pszText = item0text;
1791 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1792 expect(0, r);
1794 /* [item0, item1] */
1795 item1.mask = LVIF_TEXT;
1796 item1.iItem = 1;
1797 item1.iSubItem = 0;
1798 item1.pszText = item1text;
1799 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1800 expect(1, r);
1802 /* [item0, item1, item2] */
1803 item2.mask = LVIF_TEXT;
1804 item2.iItem = 2;
1805 item2.iSubItem = 0;
1806 item2.pszText = item2text;
1807 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1808 expect(2, r);
1810 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1811 expect(TRUE, r);
1812 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1813 expect(TRUE, r);
1814 expect2(10, 5, position.x, position.y);
1816 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1817 expect(TRUE, r);
1818 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1819 expect(TRUE, r);
1820 expect2(0, 0, position.x, position.y);
1822 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1823 expect(TRUE, r);
1824 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1825 expect(TRUE, r);
1826 expect2(20, 20, position.x, position.y);
1828 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1830 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1831 DestroyWindow(hwnd);
1834 static void test_getorigin(void)
1836 /* LVM_GETORIGIN */
1838 HWND hwnd;
1839 DWORD r;
1840 POINT position;
1842 position.x = position.y = 0;
1844 hwnd = create_custom_listview_control(LVS_ICON);
1845 ok(hwnd != NULL, "failed to create a listview window\n");
1846 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1847 trace("test get origin results\n");
1848 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1849 expect(TRUE, r);
1850 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1851 DestroyWindow(hwnd);
1853 hwnd = create_custom_listview_control(LVS_SMALLICON);
1854 ok(hwnd != NULL, "failed to create a listview window\n");
1855 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1856 trace("test get origin results\n");
1857 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1858 expect(TRUE, r);
1859 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1860 DestroyWindow(hwnd);
1862 hwnd = create_custom_listview_control(LVS_LIST);
1863 ok(hwnd != NULL, "failed to create a listview window\n");
1864 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1865 trace("test get origin results\n");
1866 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1867 expect(FALSE, r);
1868 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1869 DestroyWindow(hwnd);
1871 hwnd = create_custom_listview_control(LVS_REPORT);
1872 ok(hwnd != NULL, "failed to create a listview window\n");
1873 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1874 trace("test get origin results\n");
1875 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1876 expect(FALSE, r);
1877 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1878 DestroyWindow(hwnd);
1882 static void test_multiselect(void)
1884 typedef struct t_select_task
1886 const char *descr;
1887 int initPos;
1888 int loopVK;
1889 int count;
1890 int result;
1891 } select_task;
1893 HWND hwnd;
1894 DWORD r;
1895 int i,j,item_count,selected_count;
1896 static const int items=5;
1897 BYTE kstate[256];
1898 select_task task;
1899 LONG_PTR style;
1900 LVITEMA item;
1902 static struct t_select_task task_list[] = {
1903 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1904 { "using VK_UP", -1, VK_UP, -1, -1 },
1905 { "using VK_END", 0, VK_END, 1, -1 },
1906 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1910 hwnd = create_listview_control(0);
1912 for (i=0;i<items;i++) {
1913 insert_item(hwnd, 0);
1916 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1918 expect(items,item_count);
1920 for (i=0;i<4;i++) {
1921 task = task_list[i];
1923 /* deselect all items */
1924 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1925 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1927 /* set initial position */
1928 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1929 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1931 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1933 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1935 /* Set SHIFT key pressed */
1936 GetKeyboardState(kstate);
1937 kstate[VK_SHIFT]=0x80;
1938 SetKeyboardState(kstate);
1940 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1941 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1942 expect(0,r);
1943 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1944 expect(0,r);
1947 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1949 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);
1951 /* Set SHIFT key released */
1952 GetKeyboardState(kstate);
1953 kstate[VK_SHIFT]=0x00;
1954 SetKeyboardState(kstate);
1956 DestroyWindow(hwnd);
1958 /* make multiple selection, then switch to LVS_SINGLESEL */
1959 hwnd = create_listview_control(0);
1960 for (i=0;i<items;i++) {
1961 insert_item(hwnd, 0);
1963 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1964 expect(items,item_count);
1966 /* try with NULL pointer */
1967 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)NULL);
1968 expect(FALSE, r);
1970 /* select all, check notifications */
1971 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1973 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1975 item.stateMask = LVIS_SELECTED;
1976 item.state = LVIS_SELECTED;
1977 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1978 expect(TRUE, r);
1980 ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
1981 "select all notification", FALSE);
1983 /* deselect all items */
1984 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1985 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1986 for (i=0;i<3;i++) {
1987 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
1990 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1991 expect(3, r);
1992 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1993 expect(-1, r);
1995 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1996 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
1997 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
1998 /* check that style is accepted */
1999 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2000 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2002 for (i=0;i<3;i++) {
2003 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2004 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2006 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2007 expect(3, r);
2008 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2009 expect(3, r);
2011 /* select one more */
2012 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2014 for (i=0;i<3;i++) {
2015 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2016 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2018 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2019 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2021 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2022 expect(1, r);
2023 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2024 expect(-1, r);
2026 /* try to select all on LVS_SINGLESEL */
2027 memset(&item, 0, sizeof(item));
2028 item.stateMask = LVIS_SELECTED;
2029 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2030 expect(TRUE, r);
2031 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2033 item.stateMask = LVIS_SELECTED;
2034 item.state = LVIS_SELECTED;
2035 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2036 expect(FALSE, r);
2038 r = ListView_GetSelectedCount(hwnd);
2039 expect(0, r);
2040 r = ListView_GetSelectionMark(hwnd);
2041 expect(-1, r);
2043 /* try to deselect all on LVS_SINGLESEL */
2044 item.stateMask = LVIS_SELECTED;
2045 item.state = LVIS_SELECTED;
2046 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2047 expect(TRUE, r);
2049 item.stateMask = LVIS_SELECTED;
2050 item.state = 0;
2051 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2052 expect(TRUE, r);
2053 r = ListView_GetSelectedCount(hwnd);
2054 expect(0, r);
2056 DestroyWindow(hwnd);
2059 static void test_subitem_rect(void)
2061 HWND hwnd;
2062 DWORD r;
2063 LVCOLUMN col;
2064 RECT rect;
2066 /* test LVM_GETSUBITEMRECT for header */
2067 hwnd = create_listview_control(0);
2068 ok(hwnd != NULL, "failed to create a listview window\n");
2069 /* add some columns */
2070 memset(&col, 0, sizeof(LVCOLUMN));
2071 col.mask = LVCF_WIDTH;
2072 col.cx = 100;
2073 r = -1;
2074 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2075 expect(0, r);
2076 col.cx = 150;
2077 r = -1;
2078 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2079 expect(1, r);
2080 col.cx = 200;
2081 r = -1;
2082 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2083 expect(2, r);
2084 /* item = -1 means header, subitem index is 1 based */
2085 rect.left = LVIR_BOUNDS;
2086 rect.top = 0;
2087 rect.right = rect.bottom = 0;
2088 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2089 expect(0, r);
2091 rect.left = LVIR_BOUNDS;
2092 rect.top = 1;
2093 rect.right = rect.bottom = 0;
2094 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2096 ok(r != 0, "Expected not-null LRESULT\n");
2097 expect(100, rect.left);
2098 expect(250, rect.right);
2099 todo_wine
2100 expect(3, rect.top);
2102 rect.left = LVIR_BOUNDS;
2103 rect.top = 2;
2104 rect.right = rect.bottom = 0;
2105 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2107 ok(r != 0, "Expected not-null LRESULT\n");
2108 expect(250, rect.left);
2109 expect(450, rect.right);
2110 todo_wine
2111 expect(3, rect.top);
2113 /* item LVS_REPORT padding isn't applied to subitems */
2114 insert_item(hwnd, 0);
2116 rect.left = LVIR_BOUNDS;
2117 rect.top = 1;
2118 rect.right = rect.bottom = 0;
2119 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2120 ok(r != 0, "Expected not-null LRESULT\n");
2121 expect(100, rect.left);
2122 expect(250, rect.right);
2124 rect.left = LVIR_ICON;
2125 rect.top = 1;
2126 rect.right = rect.bottom = 0;
2127 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2128 ok(r != 0, "Expected not-null LRESULT\n");
2129 /* no icon attached - zero width rectangle, with no left padding */
2130 expect(100, rect.left);
2131 expect(100, rect.right);
2133 rect.left = LVIR_LABEL;
2134 rect.top = 1;
2135 rect.right = rect.bottom = 0;
2136 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2137 ok(r != 0, "Expected not-null LRESULT\n");
2138 /* same as full LVIR_BOUNDS */
2139 expect(100, rect.left);
2140 expect(250, rect.right);
2142 DestroyWindow(hwnd);
2144 /* try it for non LVS_REPORT style */
2145 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2146 GetModuleHandle(NULL), 0);
2147 rect.left = LVIR_BOUNDS;
2148 rect.top = 1;
2149 rect.right = rect.bottom = -10;
2150 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2151 ok(r == 0, "Expected not-null LRESULT\n");
2152 /* rect is unchanged */
2153 expect(0, rect.left);
2154 expect(-10, rect.right);
2155 expect(1, rect.top);
2156 expect(-10, rect.bottom);
2157 DestroyWindow(hwnd);
2160 /* comparison callback for test_sorting */
2161 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2163 if (first == second) return 0;
2164 return (first > second ? 1 : -1);
2167 static void test_sorting(void)
2169 HWND hwnd;
2170 LVITEMA item = {0};
2171 DWORD r;
2172 LONG_PTR style;
2173 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2174 CHAR buff[10];
2176 hwnd = create_listview_control(0);
2177 ok(hwnd != NULL, "failed to create a listview window\n");
2179 /* insert some items */
2180 item.mask = LVIF_PARAM | LVIF_STATE;
2181 item.state = LVIS_SELECTED;
2182 item.iItem = 0;
2183 item.iSubItem = 0;
2184 item.lParam = 3;
2185 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2186 expect(0, r);
2188 item.mask = LVIF_PARAM;
2189 item.iItem = 1;
2190 item.iSubItem = 0;
2191 item.lParam = 2;
2192 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2193 expect(1, r);
2195 item.mask = LVIF_STATE | LVIF_PARAM;
2196 item.state = LVIS_SELECTED;
2197 item.iItem = 2;
2198 item.iSubItem = 0;
2199 item.lParam = 4;
2200 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2201 expect(2, r);
2203 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2204 expect(-1, r);
2206 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2207 expect(2, r);
2209 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2210 expect(TRUE, r);
2212 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2213 expect(2, r);
2214 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2215 expect(-1, r);
2216 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2217 expect(0, r);
2218 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2219 expect(LVIS_SELECTED, r);
2220 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2221 expect(LVIS_SELECTED, r);
2223 DestroyWindow(hwnd);
2225 /* switch to LVS_SORTASCENDING when some items added */
2226 hwnd = create_listview_control(0);
2227 ok(hwnd != NULL, "failed to create a listview window\n");
2229 item.mask = LVIF_TEXT;
2230 item.iItem = 0;
2231 item.iSubItem = 0;
2232 item.pszText = names[1];
2233 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2234 expect(0, r);
2236 item.mask = LVIF_TEXT;
2237 item.iItem = 1;
2238 item.iSubItem = 0;
2239 item.pszText = names[2];
2240 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2241 expect(1, r);
2243 item.mask = LVIF_TEXT;
2244 item.iItem = 2;
2245 item.iSubItem = 0;
2246 item.pszText = names[0];
2247 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2248 expect(2, r);
2250 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2251 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2252 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2253 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2255 /* no sorting performed when switched to LVS_SORTASCENDING */
2256 item.mask = LVIF_TEXT;
2257 item.iItem = 0;
2258 item.pszText = buff;
2259 item.cchTextMax = sizeof(buff);
2260 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2261 expect(TRUE, r);
2262 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2264 item.iItem = 1;
2265 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2266 expect(TRUE, r);
2267 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2269 item.iItem = 2;
2270 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2271 expect(TRUE, r);
2272 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2274 /* adding new item doesn't resort list */
2275 item.mask = LVIF_TEXT;
2276 item.iItem = 3;
2277 item.iSubItem = 0;
2278 item.pszText = names[3];
2279 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2280 expect(3, r);
2282 item.mask = LVIF_TEXT;
2283 item.iItem = 0;
2284 item.pszText = buff;
2285 item.cchTextMax = sizeof(buff);
2286 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2287 expect(TRUE, r);
2288 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2290 item.iItem = 1;
2291 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2292 expect(TRUE, r);
2293 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2295 item.iItem = 2;
2296 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2297 expect(TRUE, r);
2298 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2300 item.iItem = 3;
2301 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2302 expect(TRUE, r);
2303 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2305 /* corner case - item should be placed at first position */
2306 item.mask = LVIF_TEXT;
2307 item.iItem = 4;
2308 item.iSubItem = 0;
2309 item.pszText = names[4];
2310 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2311 expect(0, r);
2313 item.iItem = 0;
2314 item.pszText = buff;
2315 item.cchTextMax = sizeof(buff);
2316 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2317 expect(TRUE, r);
2318 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2320 item.iItem = 1;
2321 item.pszText = buff;
2322 item.cchTextMax = sizeof(buff);
2323 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2324 expect(TRUE, r);
2325 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2327 item.iItem = 2;
2328 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2329 expect(TRUE, r);
2330 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2332 item.iItem = 3;
2333 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2334 expect(TRUE, r);
2335 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2337 item.iItem = 4;
2338 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2339 expect(TRUE, r);
2340 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2342 DestroyWindow(hwnd);
2345 static void test_ownerdata(void)
2347 HWND hwnd;
2348 LONG_PTR style, ret;
2349 DWORD res;
2350 LVITEMA item;
2352 /* it isn't possible to set LVS_OWNERDATA after creation */
2353 if (g_is_below_5)
2355 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2357 else
2359 hwnd = create_listview_control(0);
2360 ok(hwnd != NULL, "failed to create a listview window\n");
2361 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2362 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2364 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2366 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2367 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2368 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2369 "try to switch to LVS_OWNERDATA seq", FALSE);
2371 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2372 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2373 DestroyWindow(hwnd);
2376 /* try to set LVS_OWNERDATA after creation just having it */
2377 hwnd = create_listview_control(LVS_OWNERDATA);
2378 ok(hwnd != NULL, "failed to create a listview window\n");
2379 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2380 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2382 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2384 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2385 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2386 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2387 "try to switch to LVS_OWNERDATA seq", FALSE);
2388 DestroyWindow(hwnd);
2390 /* try to remove LVS_OWNERDATA after creation just having it */
2391 if (g_is_below_5)
2393 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2395 else
2397 hwnd = create_listview_control(LVS_OWNERDATA);
2398 ok(hwnd != NULL, "failed to create a listview window\n");
2399 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2400 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2402 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2404 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2405 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2406 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2407 "try to switch to LVS_OWNERDATA seq", FALSE);
2408 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2409 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2410 DestroyWindow(hwnd);
2413 /* try select an item */
2414 hwnd = create_listview_control(LVS_OWNERDATA);
2415 ok(hwnd != NULL, "failed to create a listview window\n");
2416 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2417 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2418 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2419 expect(0, res);
2420 memset(&item, 0, sizeof(item));
2421 item.stateMask = LVIS_SELECTED;
2422 item.state = LVIS_SELECTED;
2423 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2424 expect(TRUE, res);
2425 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2426 expect(1, res);
2427 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2428 expect(1, res);
2429 DestroyWindow(hwnd);
2431 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2432 hwnd = create_listview_control(LVS_OWNERDATA);
2433 ok(hwnd != NULL, "failed to create a listview window\n");
2434 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2435 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2436 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2437 expect(1, res);
2438 memset(&item, 0, sizeof(item));
2439 item.mask = LVIF_STATE;
2440 item.iItem = 0;
2441 item.stateMask = LVIS_SELECTED;
2442 item.state = LVIS_SELECTED;
2443 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2444 expect(FALSE, res);
2445 DestroyWindow(hwnd);
2447 /* check notifications after focused/selected changed */
2448 hwnd = create_listview_control(LVS_OWNERDATA);
2449 ok(hwnd != NULL, "failed to create a listview window\n");
2450 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2451 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2453 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2455 memset(&item, 0, sizeof(item));
2456 item.stateMask = LVIS_SELECTED;
2457 item.state = LVIS_SELECTED;
2458 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2459 expect(TRUE, res);
2461 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2462 "ownerdata select notification", TRUE);
2464 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2466 memset(&item, 0, sizeof(item));
2467 item.stateMask = LVIS_FOCUSED;
2468 item.state = LVIS_FOCUSED;
2469 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2470 expect(TRUE, res);
2472 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2473 "ownerdata focus notification", TRUE);
2475 /* select all, check notifications */
2476 item.stateMask = LVIS_SELECTED;
2477 item.state = 0;
2478 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2479 expect(TRUE, res);
2481 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2483 item.stateMask = LVIS_SELECTED;
2484 item.state = LVIS_SELECTED;
2486 g_dump_itemchanged = TRUE;
2487 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2488 expect(TRUE, res);
2489 g_dump_itemchanged = FALSE;
2491 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2492 "ownerdata select all notification", TRUE);
2494 /* select all again, note that all items are selected already */
2495 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2496 item.stateMask = LVIS_SELECTED;
2497 item.state = LVIS_SELECTED;
2498 g_dump_itemchanged = TRUE;
2499 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2500 expect(TRUE, res);
2501 g_dump_itemchanged = FALSE;
2502 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2503 "ownerdata select all notification", TRUE);
2504 /* deselect all */
2505 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2506 item.stateMask = LVIS_SELECTED;
2507 item.state = 0;
2508 g_dump_itemchanged = TRUE;
2509 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2510 expect(TRUE, res);
2511 g_dump_itemchanged = FALSE;
2512 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2513 "ownerdata deselect all notification", TRUE);
2515 /* select one, then deselect all */
2516 item.stateMask = LVIS_SELECTED;
2517 item.state = LVIS_SELECTED;
2518 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2519 expect(TRUE, res);
2520 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2521 item.stateMask = LVIS_SELECTED;
2522 item.state = 0;
2523 g_dump_itemchanged = TRUE;
2524 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2525 expect(TRUE, res);
2526 g_dump_itemchanged = FALSE;
2527 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2528 "ownerdata select all notification", TRUE);
2530 /* remove focused, try to focus all */
2531 item.stateMask = LVIS_FOCUSED;
2532 item.state = LVIS_FOCUSED;
2533 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2534 expect(TRUE, res);
2535 item.stateMask = LVIS_FOCUSED;
2536 item.state = 0;
2537 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2538 expect(TRUE, res);
2539 item.stateMask = LVIS_FOCUSED;
2540 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
2541 expect(0, res);
2542 /* setting all to focused returns failure value */
2543 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2544 item.stateMask = LVIS_FOCUSED;
2545 item.state = LVIS_FOCUSED;
2546 g_dump_itemchanged = TRUE;
2547 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2548 expect(FALSE, res);
2549 g_dump_itemchanged = FALSE;
2550 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2551 "ownerdata focus all notification", FALSE);
2552 /* focus single item, remove all */
2553 item.stateMask = LVIS_FOCUSED;
2554 item.state = LVIS_FOCUSED;
2555 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2556 expect(TRUE, res);
2557 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2558 item.stateMask = LVIS_FOCUSED;
2559 item.state = 0;
2560 g_dump_itemchanged = TRUE;
2561 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2562 expect(TRUE, res);
2563 g_dump_itemchanged = FALSE;
2564 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
2565 "ownerdata remove focus all notification", TRUE);
2566 /* set all cut */
2567 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2568 item.stateMask = LVIS_CUT;
2569 item.state = LVIS_CUT;
2570 g_dump_itemchanged = TRUE;
2571 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2572 expect(TRUE, res);
2573 g_dump_itemchanged = FALSE;
2574 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2575 "ownerdata cut all notification", TRUE);
2576 /* all marked cut, try again */
2577 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2578 item.stateMask = LVIS_CUT;
2579 item.state = LVIS_CUT;
2580 g_dump_itemchanged = TRUE;
2581 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2582 expect(TRUE, res);
2583 g_dump_itemchanged = FALSE;
2584 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2585 "ownerdata cut all notification #2", TRUE);
2587 DestroyWindow(hwnd);
2589 /* check notifications on LVM_GETITEM */
2590 /* zero callback mask */
2591 hwnd = create_listview_control(LVS_OWNERDATA);
2592 ok(hwnd != NULL, "failed to create a listview window\n");
2593 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2594 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2596 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2598 memset(&item, 0, sizeof(item));
2599 item.stateMask = LVIS_SELECTED;
2600 item.mask = LVIF_STATE;
2601 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2602 expect(TRUE, res);
2604 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2605 "ownerdata getitem selected state 1", FALSE);
2607 /* non zero callback mask but not we asking for */
2608 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2609 expect(TRUE, res);
2611 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2613 memset(&item, 0, sizeof(item));
2614 item.stateMask = LVIS_SELECTED;
2615 item.mask = LVIF_STATE;
2616 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2617 expect(TRUE, res);
2619 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2620 "ownerdata getitem selected state 2", FALSE);
2622 /* LVIS_OVERLAYMASK callback mask, asking for index */
2623 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2625 memset(&item, 0, sizeof(item));
2626 item.stateMask = LVIS_OVERLAYMASK;
2627 item.mask = LVIF_STATE;
2628 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2629 expect(TRUE, res);
2631 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2632 "ownerdata getitem selected state 2", FALSE);
2634 DestroyWindow(hwnd);
2636 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2637 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING);
2638 ok(hwnd != NULL, "failed to create a listview window\n");
2639 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2640 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2641 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2642 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2643 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2644 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2645 DestroyWindow(hwnd);
2646 /* apparently it's allowed to switch these style on after creation */
2647 hwnd = create_listview_control(LVS_OWNERDATA);
2648 ok(hwnd != NULL, "failed to create a listview window\n");
2649 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2650 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2651 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2652 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2653 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2654 DestroyWindow(hwnd);
2656 hwnd = create_listview_control(LVS_OWNERDATA);
2657 ok(hwnd != NULL, "failed to create a listview window\n");
2658 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2659 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2660 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2661 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2662 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2663 DestroyWindow(hwnd);
2666 static void test_norecompute(void)
2668 static CHAR testA[] = "test";
2669 CHAR buff[10];
2670 LVITEMA item;
2671 HWND hwnd;
2672 DWORD res;
2674 /* self containing control */
2675 hwnd = create_listview_control(0);
2676 ok(hwnd != NULL, "failed to create a listview window\n");
2677 memset(&item, 0, sizeof(item));
2678 item.mask = LVIF_TEXT | LVIF_STATE;
2679 item.iItem = 0;
2680 item.stateMask = LVIS_SELECTED;
2681 item.state = LVIS_SELECTED;
2682 item.pszText = testA;
2683 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2684 expect(0, res);
2685 /* retrieve with LVIF_NORECOMPUTE */
2686 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2687 item.iItem = 0;
2688 item.pszText = buff;
2689 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2690 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2691 expect(TRUE, res);
2692 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2694 item.mask = LVIF_TEXT;
2695 item.iItem = 1;
2696 item.pszText = LPSTR_TEXTCALLBACK;
2697 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2698 expect(1, res);
2700 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2701 item.iItem = 1;
2702 item.pszText = buff;
2703 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2705 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2706 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2707 expect(TRUE, res);
2708 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2709 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2710 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2712 DestroyWindow(hwnd);
2714 /* LVS_OWNERDATA */
2715 hwnd = create_listview_control(LVS_OWNERDATA);
2716 ok(hwnd != NULL, "failed to create a listview window\n");
2718 item.mask = LVIF_STATE;
2719 item.stateMask = LVIS_SELECTED;
2720 item.state = LVIS_SELECTED;
2721 item.iItem = 0;
2722 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2723 expect(0, res);
2725 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2726 item.iItem = 0;
2727 item.pszText = buff;
2728 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2729 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2730 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2731 expect(TRUE, res);
2732 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2733 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2734 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2736 DestroyWindow(hwnd);
2739 static void test_nosortheader(void)
2741 HWND hwnd, header;
2742 LONG_PTR style;
2744 hwnd = create_listview_control(0);
2745 ok(hwnd != NULL, "failed to create a listview window\n");
2747 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2748 ok(IsWindow(header), "header expected\n");
2750 style = GetWindowLongPtr(header, GWL_STYLE);
2751 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2753 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2754 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2755 /* HDS_BUTTONS retained */
2756 style = GetWindowLongPtr(header, GWL_STYLE);
2757 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2759 DestroyWindow(hwnd);
2761 /* create with LVS_NOSORTHEADER */
2762 hwnd = create_listview_control(LVS_NOSORTHEADER);
2763 ok(hwnd != NULL, "failed to create a listview window\n");
2765 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2766 ok(IsWindow(header), "header expected\n");
2768 style = GetWindowLongPtr(header, GWL_STYLE);
2769 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2771 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2772 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2773 /* not changed here */
2774 style = GetWindowLongPtr(header, GWL_STYLE);
2775 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2777 DestroyWindow(hwnd);
2780 static void test_setredraw(void)
2782 HWND hwnd;
2783 DWORD_PTR style;
2784 DWORD ret;
2786 hwnd = create_listview_control(0);
2787 ok(hwnd != NULL, "failed to create a listview window\n");
2789 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2790 ListView seems to handle it internally without DefWinProc */
2792 /* default value first */
2793 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2794 expect(0, ret);
2795 /* disable */
2796 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2797 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2798 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2799 expect(0, ret);
2800 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2801 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2803 DestroyWindow(hwnd);
2806 static void test_hittest(void)
2808 HWND hwnd;
2809 DWORD r;
2810 RECT bounds;
2811 LVITEMA item;
2812 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2813 POINT pos;
2814 INT x, y;
2815 HIMAGELIST himl, himl2;
2816 HBITMAP hbmp;
2818 hwnd = create_listview_control(0);
2819 ok(hwnd != NULL, "failed to create a listview window\n");
2821 /* LVS_REPORT with a single subitem (2 columns) */
2822 insert_column(hwnd, 0);
2823 insert_column(hwnd, 1);
2824 insert_item(hwnd, 0);
2826 item.iSubItem = 0;
2827 /* the only purpose of that line is to be as long as a half item rect */
2828 item.pszText = text;
2829 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2830 expect(TRUE, r);
2832 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2833 expect(TRUE, r);
2834 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
2835 expect(TRUE, r);
2837 memset(&bounds, 0, sizeof(bounds));
2838 bounds.left = LVIR_BOUNDS;
2839 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
2840 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
2841 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
2842 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
2843 expect(TRUE, r);
2845 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2846 x = pos.x + 50; /* column half width */
2847 y = pos.y + (bounds.bottom - bounds.top) / 2;
2848 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, FALSE, FALSE, __LINE__);
2849 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2850 x = pos.x + 150; /* outside column */
2851 y = pos.y + (bounds.bottom - bounds.top) / 2;
2852 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2853 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2854 y = (bounds.bottom - bounds.top) / 2;
2855 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, TRUE, __LINE__);
2856 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2857 /* outside possible client rectangle (to right) */
2858 x = pos.x + 500;
2859 y = pos.y + (bounds.bottom - bounds.top) / 2;
2860 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2861 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2862 y = (bounds.bottom - bounds.top) / 2;
2863 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, TRUE, __LINE__);
2864 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2865 /* subitem returned with -1 item too */
2866 x = pos.x + 150;
2867 y = -10;
2868 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2869 /* parent client area is 100x100 by default */
2870 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
2871 x = pos.x + 150; /* outside column */
2872 y = pos.y + (bounds.bottom - bounds.top) / 2;
2873 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, FALSE, FALSE, __LINE__);
2874 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2875 y = (bounds.bottom - bounds.top) / 2;
2876 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, FALSE, TRUE, __LINE__);
2877 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2878 /* the same with LVS_EX_FULLROWSELECT */
2879 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
2880 x = pos.x + 150; /* outside column */
2881 y = pos.y + (bounds.bottom - bounds.top) / 2;
2882 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, FALSE, FALSE, __LINE__);
2883 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2884 y = (bounds.bottom - bounds.top) / 2;
2885 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2886 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
2887 x = pos.x + 150; /* outside column */
2888 y = pos.y + (bounds.bottom - bounds.top) / 2;
2889 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2890 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2891 y = (bounds.bottom - bounds.top) / 2;
2892 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, TRUE, __LINE__);
2893 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2894 /* outside possible client rectangle (to right) */
2895 x = pos.x + 500;
2896 y = pos.y + (bounds.bottom - bounds.top) / 2;
2897 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2898 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2899 y = (bounds.bottom - bounds.top) / 2;
2900 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, TRUE, __LINE__);
2901 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2902 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2903 himl = ImageList_Create(16, 16, 0, 4, 4);
2904 ok(himl != NULL, "failed to create imagelist\n");
2905 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2906 ok(hbmp != NULL, "failed to create bitmap\n");
2907 r = ImageList_Add(himl, hbmp, 0);
2908 ok(r == 0, "should be zero\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 == 1, "should be one\n");
2914 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2915 ok(r == 0, "should return zero\n");
2917 item.mask = LVIF_IMAGE;
2918 item.iImage = 0;
2919 item.iItem = 0;
2920 item.iSubItem = 0;
2921 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2922 expect(TRUE, r);
2923 /* on state icon */
2924 x = pos.x + 8;
2925 y = pos.y + (bounds.bottom - bounds.top) / 2;
2926 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2927 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2928 y = (bounds.bottom - bounds.top) / 2;
2929 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2931 /* state icons indices are 1 based, check with valid index */
2932 item.mask = LVIF_STATE;
2933 item.state = INDEXTOSTATEIMAGEMASK(1);
2934 item.stateMask = LVIS_STATEIMAGEMASK;
2935 item.iItem = 0;
2936 item.iSubItem = 0;
2937 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2938 expect(TRUE, r);
2939 /* on state icon */
2940 x = pos.x + 8;
2941 y = pos.y + (bounds.bottom - bounds.top) / 2;
2942 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2943 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2944 y = (bounds.bottom - bounds.top) / 2;
2945 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2947 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
2948 ok(himl2 == himl, "should return handle\n");
2950 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
2951 ok(r == 0, "should return zero\n");
2952 /* on item icon */
2953 x = pos.x + 8;
2954 y = pos.y + (bounds.bottom - bounds.top) / 2;
2955 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, FALSE, FALSE, __LINE__);
2956 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
2957 y = (bounds.bottom - bounds.top) / 2;
2958 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
2960 DestroyWindow(hwnd);
2963 static void test_getviewrect(void)
2965 HWND hwnd;
2966 DWORD r;
2967 RECT rect;
2968 LVITEMA item;
2970 hwnd = create_listview_control(0);
2971 ok(hwnd != NULL, "failed to create a listview window\n");
2973 /* empty */
2974 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2975 expect(TRUE, r);
2977 insert_column(hwnd, 0);
2978 insert_column(hwnd, 1);
2980 memset(&item, 0, sizeof(item));
2981 item.iItem = 0;
2982 item.iSubItem = 0;
2983 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2985 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2986 expect(TRUE, r);
2987 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
2988 expect(TRUE, r);
2990 rect.left = rect.right = rect.top = rect.bottom = -1;
2991 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2992 expect(TRUE, r);
2993 /* left is set to (2e31-1) - XP SP2 */
2994 expect(0, rect.right);
2995 expect(0, rect.top);
2996 expect(0, rect.bottom);
2998 /* switch to LVS_ICON */
2999 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3001 rect.left = rect.right = rect.top = rect.bottom = -1;
3002 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3003 expect(TRUE, r);
3004 expect(0, rect.left);
3005 expect(0, rect.top);
3006 /* precise value differs for 2k, XP and Vista */
3007 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3008 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3010 DestroyWindow(hwnd);
3013 static void test_getitemposition(void)
3015 HWND hwnd, header;
3016 DWORD r;
3017 POINT pt;
3018 RECT rect;
3020 hwnd = create_listview_control(0);
3021 ok(hwnd != NULL, "failed to create a listview window\n");
3022 header = subclass_header(hwnd);
3024 /* LVS_REPORT, single item, no columns added */
3025 insert_item(hwnd, 0);
3027 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3029 pt.x = pt.y = -1;
3030 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3031 expect(TRUE, r);
3032 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3034 /* LVS_REPORT, single item, single column */
3035 insert_column(hwnd, 0);
3037 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3039 pt.x = pt.y = -1;
3040 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3041 expect(TRUE, r);
3042 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3044 memset(&rect, 0, sizeof(rect));
3045 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3046 /* some padding? */
3047 expect(2, pt.x);
3048 /* offset by header height */
3049 expect(rect.bottom - rect.top, pt.y);
3051 DestroyWindow(hwnd);
3054 static void test_columnscreation(void)
3056 HWND hwnd, header;
3057 DWORD r;
3059 hwnd = create_listview_control(0);
3060 ok(hwnd != NULL, "failed to create a listview window\n");
3062 insert_item(hwnd, 0);
3064 /* headers columns aren't created automatically */
3065 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3066 ok(IsWindow(header), "Expected header handle\n");
3067 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3068 expect(0, r);
3070 DestroyWindow(hwnd);
3073 static void test_getitemrect(void)
3075 HWND hwnd;
3076 HIMAGELIST himl;
3077 HBITMAP hbm;
3078 RECT rect;
3079 DWORD r;
3080 LVITEMA item;
3081 LVCOLUMNA col;
3082 INT order[2];
3083 POINT pt;
3085 hwnd = create_listview_control(0);
3086 ok(hwnd != NULL, "failed to create a listview window\n");
3088 /* empty item */
3089 memset(&item, 0, sizeof(item));
3090 item.iItem = 0;
3091 item.iSubItem = 0;
3092 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3093 expect(0, r);
3095 rect.left = LVIR_BOUNDS;
3096 rect.right = rect.top = rect.bottom = -1;
3097 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3098 expect(TRUE, r);
3100 /* zero width rectangle with no padding */
3101 expect(0, rect.left);
3102 expect(0, rect.right);
3104 insert_column(hwnd, 0);
3105 insert_column(hwnd, 1);
3107 col.mask = LVCF_WIDTH;
3108 col.cx = 50;
3109 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3110 expect(TRUE, r);
3112 col.mask = LVCF_WIDTH;
3113 col.cx = 100;
3114 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3115 expect(TRUE, r);
3117 rect.left = LVIR_BOUNDS;
3118 rect.right = rect.top = rect.bottom = -1;
3119 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3120 expect(TRUE, r);
3122 /* still no left padding */
3123 expect(0, rect.left);
3124 expect(150, rect.right);
3126 rect.left = LVIR_SELECTBOUNDS;
3127 rect.right = rect.top = rect.bottom = -1;
3128 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3129 expect(TRUE, r);
3130 /* padding */
3131 expect(2, rect.left);
3133 rect.left = LVIR_LABEL;
3134 rect.right = rect.top = rect.bottom = -1;
3135 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3136 expect(TRUE, r);
3137 /* padding, column width */
3138 expect(2, rect.left);
3139 expect(50, rect.right);
3141 /* no icons attached */
3142 rect.left = LVIR_ICON;
3143 rect.right = rect.top = rect.bottom = -1;
3144 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3145 expect(TRUE, r);
3146 /* padding */
3147 expect(2, rect.left);
3148 expect(2, rect.right);
3150 /* change order */
3151 order[0] = 1; order[1] = 0;
3152 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3153 expect(TRUE, r);
3154 pt.x = -1;
3155 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3156 expect(TRUE, r);
3157 /* 1 indexed column width + padding */
3158 todo_wine expect(102, pt.x);
3159 /* rect is at zero too */
3160 rect.left = LVIR_BOUNDS;
3161 rect.right = rect.top = rect.bottom = -1;
3162 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3163 expect(TRUE, r);
3164 expect(0, rect.left);
3165 /* just width sum */
3166 expect(150, rect.right);
3168 rect.left = LVIR_SELECTBOUNDS;
3169 rect.right = rect.top = rect.bottom = -1;
3170 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3171 expect(TRUE, r);
3172 /* column width + padding */
3173 todo_wine expect(102, rect.left);
3175 /* back to initial order */
3176 order[0] = 0; order[1] = 1;
3177 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3178 expect(TRUE, r);
3180 /* state icons */
3181 himl = ImageList_Create(16, 16, 0, 2, 2);
3182 ok(himl != NULL, "failed to create imagelist\n");
3183 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3184 ok(hbm != NULL, "failed to create bitmap\n");
3185 r = ImageList_Add(himl, hbm, 0);
3186 ok(r == 0, "should be zero\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 == 1, "should be one\n");
3192 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3193 ok(r == 0, "should return zero\n");
3195 item.mask = LVIF_STATE;
3196 item.state = INDEXTOSTATEIMAGEMASK(1);
3197 item.stateMask = LVIS_STATEIMAGEMASK;
3198 item.iItem = 0;
3199 item.iSubItem = 0;
3200 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3201 expect(TRUE, r);
3203 /* icon bounds */
3204 rect.left = LVIR_ICON;
3205 rect.right = rect.top = rect.bottom = -1;
3206 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3207 expect(TRUE, r);
3208 /* padding + stateicon width */
3209 expect(18, rect.left);
3210 expect(18, rect.right);
3211 /* label bounds */
3212 rect.left = LVIR_LABEL;
3213 rect.right = rect.top = rect.bottom = -1;
3214 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3215 expect(TRUE, r);
3216 /* padding + stateicon width -> column width */
3217 expect(18, rect.left);
3218 expect(50, rect.right);
3220 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
3221 ok(r != 0, "should return current list handle\n");
3223 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3224 ok(r == 0, "should return zero\n");
3226 item.mask = LVIF_STATE | LVIF_IMAGE;
3227 item.iImage = 1;
3228 item.state = 0;
3229 item.stateMask = ~0;
3230 item.iItem = 0;
3231 item.iSubItem = 0;
3232 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3233 expect(TRUE, r);
3235 /* icon bounds */
3236 rect.left = LVIR_ICON;
3237 rect.right = rect.top = rect.bottom = -1;
3238 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3239 expect(TRUE, r);
3240 /* padding, icon width */
3241 expect(2, rect.left);
3242 expect(18, rect.right);
3243 /* label bounds */
3244 rect.left = LVIR_LABEL;
3245 rect.right = rect.top = rect.bottom = -1;
3246 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3247 expect(TRUE, r);
3248 /* padding + icon width -> column width */
3249 expect(18, rect.left);
3250 expect(50, rect.right);
3252 /* select bounds */
3253 rect.left = LVIR_SELECTBOUNDS;
3254 rect.right = rect.top = rect.bottom = -1;
3255 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3256 expect(TRUE, r);
3257 /* padding, column width */
3258 expect(2, rect.left);
3259 expect(50, rect.right);
3261 /* try with indentation */
3262 item.mask = LVIF_INDENT;
3263 item.iIndent = 1;
3264 item.iItem = 0;
3265 item.iSubItem = 0;
3266 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3267 expect(TRUE, r);
3269 /* bounds */
3270 rect.left = LVIR_BOUNDS;
3271 rect.right = rect.top = rect.bottom = -1;
3272 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3273 expect(TRUE, r);
3274 /* padding + 1 icon width, column width */
3275 expect(0, rect.left);
3276 expect(150, rect.right);
3278 /* select bounds */
3279 rect.left = LVIR_SELECTBOUNDS;
3280 rect.right = rect.top = rect.bottom = -1;
3281 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3282 expect(TRUE, r);
3283 /* padding + 1 icon width, column width */
3284 expect(2 + 16, rect.left);
3285 expect(50, rect.right);
3287 /* label bounds */
3288 rect.left = LVIR_LABEL;
3289 rect.right = rect.top = rect.bottom = -1;
3290 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3291 expect(TRUE, r);
3292 /* padding + 2 icon widths, column width */
3293 expect(2 + 16*2, rect.left);
3294 expect(50, rect.right);
3296 /* icon bounds */
3297 rect.left = LVIR_ICON;
3298 rect.right = rect.top = rect.bottom = -1;
3299 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3300 expect(TRUE, r);
3301 /* padding + 1 icon width indentation, icon width */
3302 expect(2 + 16, rect.left);
3303 expect(34, rect.right);
3306 DestroyWindow(hwnd);
3309 static void test_editbox(void)
3311 HWND hwnd, hwndedit, hwndedit2;
3312 LVITEMA item;
3313 DWORD r;
3314 static CHAR testitemA[] = "testitem";
3315 static CHAR testitem1A[] = "testitem1";
3316 static CHAR buffer[10];
3318 hwnd = create_listview_control(LVS_EDITLABELS);
3319 ok(hwnd != NULL, "failed to create a listview window\n");
3321 insert_column(hwnd, 0);
3323 memset(&item, 0, sizeof(item));
3324 item.mask = LVIF_TEXT;
3325 item.pszText = testitemA;
3326 item.iItem = 0;
3327 item.iSubItem = 0;
3328 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3329 expect(0, r);
3331 /* setting focus is necessary */
3332 SetFocus(hwnd);
3333 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3334 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3336 /* modify initial string */
3337 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3338 expect(TRUE, r);
3339 /* return focus to listview */
3340 SetFocus(hwnd);
3342 memset(&item, 0, sizeof(item));
3343 item.mask = LVIF_TEXT;
3344 item.pszText = buffer;
3345 item.cchTextMax = 10;
3346 item.iItem = 0;
3347 item.iSubItem = 0;
3348 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3349 expect(TRUE, r);
3351 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3353 /* send LVM_EDITLABEL on already created edit */
3354 SetFocus(hwnd);
3355 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3356 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3357 /* focus will be set to edit */
3358 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3359 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3360 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3362 /* creating label disabled when control isn't focused */
3363 SetFocus(0);
3364 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3365 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3367 /* check EN_KILLFOCUS handling */
3368 memset(&item, 0, sizeof(item));
3369 item.pszText = testitemA;
3370 item.iItem = 0;
3371 item.iSubItem = 0;
3372 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3373 expect(TRUE, r);
3375 SetFocus(hwnd);
3376 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3377 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3378 /* modify edit and notify control that it lost focus */
3379 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3380 expect(TRUE, r);
3381 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3382 expect(0, r);
3383 memset(&item, 0, sizeof(item));
3384 item.pszText = buffer;
3385 item.cchTextMax = 10;
3386 item.iItem = 0;
3387 item.iSubItem = 0;
3388 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3389 expect(lstrlen(item.pszText), r);
3390 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3391 /* end edit without saving */
3392 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3393 expect(0, r);
3394 memset(&item, 0, sizeof(item));
3395 item.pszText = buffer;
3396 item.cchTextMax = 10;
3397 item.iItem = 0;
3398 item.iSubItem = 0;
3399 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3400 expect(lstrlen(item.pszText), r);
3401 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3403 /* LVM_EDITLABEL with -1 destroys current edit */
3404 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3405 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3406 /* no edit present */
3407 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3408 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3409 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3410 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3411 /* edit present */
3412 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3413 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3414 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3415 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3416 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3417 /* check another negative value */
3418 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3419 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3420 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3421 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3422 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3423 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3424 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3425 /* and value greater than max item index */
3426 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3427 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3428 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3429 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3430 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3431 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3432 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3433 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3435 /* messaging tests */
3436 SetFocus(hwnd);
3437 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3438 blockEdit = FALSE;
3439 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3440 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3441 /* testing only sizing messages */
3442 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3443 "edit box create - sizing", TRUE);
3445 DestroyWindow(hwnd);
3448 static void test_notifyformat(void)
3450 HWND hwnd, header;
3451 DWORD r;
3453 hwnd = create_listview_control(0);
3454 ok(hwnd != NULL, "failed to create a listview window\n");
3456 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3457 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3458 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3459 expect(0, r);
3460 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3461 /* set */
3462 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3463 expect(0, r);
3464 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3465 if (r == 1)
3467 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3468 expect(1, r);
3469 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3470 expect(0, r);
3472 else
3474 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3475 DestroyWindow(hwnd);
3476 return;
3479 DestroyWindow(hwnd);
3481 /* test failure in parent WM_NOTIFYFORMAT */
3482 notifyFormat = 0;
3483 hwnd = create_listview_control(0);
3484 ok(hwnd != NULL, "failed to create a listview window\n");
3485 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3486 ok(IsWindow(header), "expected header to be created\n");
3487 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3488 expect(0, r);
3489 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3490 expect(1, r);
3491 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3492 ok(r != 0, "Expected valid format\n");
3494 notifyFormat = NFR_UNICODE;
3495 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3496 expect(NFR_UNICODE, r);
3497 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3498 expect(1, r);
3499 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3500 expect(1, r);
3502 notifyFormat = NFR_ANSI;
3503 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3504 expect(NFR_ANSI, r);
3505 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3506 expect(0, r);
3507 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3508 expect(1, r);
3510 DestroyWindow(hwnd);
3512 /* try different unicode window combination and defaults */
3513 if (!GetModuleHandleW(NULL))
3515 win_skip("Additional notify format tests are incompatible with Win9x\n");
3516 return;
3519 hwndparentW = create_parent_window(TRUE);
3520 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3521 if (!IsWindow(hwndparentW)) return;
3523 notifyFormat = -1;
3524 hwnd = create_listview_controlW(0, hwndparentW);
3525 ok(hwnd != NULL, "failed to create a listview window\n");
3526 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3527 ok(IsWindow(header), "expected header to be created\n");
3528 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3529 expect(1, r);
3530 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3531 expect(1, r);
3532 DestroyWindow(hwnd);
3533 /* receiving error code defaulting to ansi */
3534 notifyFormat = 0;
3535 hwnd = create_listview_controlW(0, hwndparentW);
3536 ok(hwnd != NULL, "failed to create a listview window\n");
3537 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3538 ok(IsWindow(header), "expected header to be created\n");
3539 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3540 expect(0, r);
3541 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3542 expect(1, r);
3543 DestroyWindow(hwnd);
3544 /* receiving ansi code from unicode window, use it */
3545 notifyFormat = NFR_ANSI;
3546 hwnd = create_listview_controlW(0, hwndparentW);
3547 ok(hwnd != NULL, "failed to create a listview window\n");
3548 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3549 ok(IsWindow(header), "expected header to be created\n");
3550 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3551 expect(0, r);
3552 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3553 expect(1, r);
3554 DestroyWindow(hwnd);
3555 /* unicode listview with ansi parent window */
3556 notifyFormat = -1;
3557 hwnd = create_listview_controlW(0, hwndparent);
3558 ok(hwnd != NULL, "failed to create a listview window\n");
3559 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3560 ok(IsWindow(header), "expected header to be created\n");
3561 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3562 expect(0, r);
3563 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3564 expect(1, r);
3565 DestroyWindow(hwnd);
3566 /* unicode listview with ansi parent window, return error code */
3567 notifyFormat = 0;
3568 hwnd = create_listview_controlW(0, hwndparent);
3569 ok(hwnd != NULL, "failed to create a listview window\n");
3570 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3571 ok(IsWindow(header), "expected header to be created\n");
3572 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3573 expect(0, r);
3574 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3575 expect(1, r);
3576 DestroyWindow(hwnd);
3578 DestroyWindow(hwndparentW);
3581 static void test_indentation(void)
3583 HWND hwnd;
3584 LVITEMA item;
3585 DWORD r;
3587 hwnd = create_listview_control(0);
3588 ok(hwnd != NULL, "failed to create a listview window\n");
3590 memset(&item, 0, sizeof(item));
3591 item.mask = LVIF_INDENT;
3592 item.iItem = 0;
3593 item.iIndent = I_INDENTCALLBACK;
3594 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3595 expect(0, r);
3597 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3599 item.iItem = 0;
3600 item.mask = LVIF_INDENT;
3601 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3602 expect(TRUE, r);
3604 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3605 "get indent dispinfo", FALSE);
3607 DestroyWindow(hwnd);
3610 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
3612 return 0;
3615 static BOOL is_below_comctl_5(void)
3617 HWND hwnd;
3618 BOOL ret;
3620 hwnd = create_listview_control(0);
3621 ok(hwnd != NULL, "failed to create a listview window\n");
3622 insert_item(hwnd, 0);
3624 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
3626 DestroyWindow(hwnd);
3628 return !ret;
3631 static void unload_v6_module(ULONG_PTR cookie)
3633 HANDLE hKernel32;
3634 BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
3636 hKernel32 = GetModuleHandleA("kernel32.dll");
3637 pDeactivateActCtx = (void*)GetProcAddress(hKernel32, "DeactivateActCtx");
3638 if (!pDeactivateActCtx)
3640 win_skip("Activation contexts unsupported\n");
3641 return;
3644 pDeactivateActCtx(0, cookie);
3646 DeleteFileA(manifest_name);
3649 static BOOL load_v6_module(ULONG_PTR *pcookie)
3651 HANDLE hKernel32;
3652 HANDLE (WINAPI *pCreateActCtxA)(ACTCTXA*);
3653 BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR*);
3655 ACTCTXA ctx;
3656 HANDLE hCtx;
3657 BOOL ret;
3658 HANDLE file;
3659 DWORD written;
3660 HWND hwnd;
3662 hKernel32 = GetModuleHandleA("kernel32.dll");
3663 pCreateActCtxA = (void*)GetProcAddress(hKernel32, "CreateActCtxA");
3664 pActivateActCtx = (void*)GetProcAddress(hKernel32, "ActivateActCtx");
3665 if (!(pCreateActCtxA && pActivateActCtx))
3667 win_skip("Activation contexts unsupported. No version 6 tests possible.\n");
3668 return FALSE;
3671 /* create manifest */
3672 file = CreateFileA( manifest_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
3673 if (file != INVALID_HANDLE_VALUE)
3675 ret = (WriteFile( file, manifest, sizeof(manifest)-1, &written, NULL ) &&
3676 written == sizeof(manifest)-1);
3677 CloseHandle( file );
3678 if (!ret)
3680 DeleteFileA( manifest_name );
3681 skip("Failed to fill manifest file. Skipping comctl32 V6 tests.\n");
3682 return FALSE;
3684 else
3685 trace("created %s\n", manifest_name);
3687 else
3689 skip("Failed to create manifest file. Skipping comctl32 V6 tests.\n");
3690 return FALSE;
3693 memset(&ctx, 0, sizeof(ctx));
3694 ctx.cbSize = sizeof(ctx);
3695 ctx.lpSource = manifest_name;
3697 hCtx = pCreateActCtxA(&ctx);
3698 ok(hCtx != 0, "Expected context handle\n");
3700 ret = pActivateActCtx(hCtx, pcookie);
3701 expect(TRUE, ret);
3703 if (!ret)
3705 win_skip("A problem during context activation occurred.\n");
3706 DeleteFileA(manifest_name);
3709 else
3711 /* this is a XP SP3 failure workaround */
3712 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
3713 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
3714 0, 0, 100, 100,
3715 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
3716 if (!IsWindow(hwnd))
3718 win_skip("FIXME: failed to create ListView window.\n");
3719 unload_v6_module(*pcookie);
3720 return FALSE;
3722 else
3723 DestroyWindow(hwnd);
3726 return ret;
3729 static void test_get_set_view(void)
3731 HWND hwnd;
3732 DWORD ret;
3733 DWORD_PTR style;
3735 /* test style->view mapping */
3736 hwnd = create_listview_control(0);
3737 ok(hwnd != NULL, "failed to create a listview window\n");
3739 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3740 expect(LV_VIEW_DETAILS, ret);
3742 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3743 /* LVS_ICON == 0 */
3744 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
3745 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3746 expect(LV_VIEW_ICON, ret);
3748 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3749 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
3750 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3751 expect(LV_VIEW_SMALLICON, ret);
3753 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3754 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
3755 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3756 expect(LV_VIEW_LIST, ret);
3758 /* switching view doesn't touch window style */
3759 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
3760 expect(1, ret);
3761 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3762 ok(style & LVS_LIST, "Expected style to be preserved\n");
3763 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 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_SMALLICON, 0);
3768 expect(1, ret);
3769 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3770 ok(style & LVS_LIST, "Expected style to be preserved\n");
3772 DestroyWindow(hwnd);
3775 static void test_canceleditlabel(void)
3777 HWND hwnd, hwndedit;
3778 DWORD ret;
3779 CHAR buff[10];
3780 LVITEMA itema;
3781 static CHAR test[] = "test";
3782 static const CHAR test1[] = "test1";
3784 hwnd = create_listview_control(LVS_EDITLABELS);
3785 ok(hwnd != NULL, "failed to create a listview window\n");
3787 insert_item(hwnd, 0);
3789 /* try without edit created */
3790 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3791 expect(TRUE, ret);
3793 /* cancel without data change */
3794 SetFocus(hwnd);
3795 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3796 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3797 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3798 expect(TRUE, ret);
3799 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3801 /* cancel after data change */
3802 memset(&itema, 0, sizeof(itema));
3803 itema.pszText = test;
3804 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
3805 expect(TRUE, ret);
3806 SetFocus(hwnd);
3807 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3808 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3809 ret = SetWindowText(hwndedit, test1);
3810 ok(ret != 0, "Expected edit text to change\n");
3811 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3812 expect(TRUE, ret);
3813 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3814 memset(&itema, 0, sizeof(itema));
3815 itema.pszText = buff;
3816 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
3817 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
3818 expect(5, ret);
3819 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
3821 DestroyWindow(hwnd);
3824 static void test_mapidindex(void)
3826 HWND hwnd;
3827 DWORD ret;
3829 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3830 hwnd = create_listview_control(LVS_OWNERDATA);
3831 ok(hwnd != NULL, "failed to create a listview window\n");
3832 insert_item(hwnd, 0);
3833 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3834 expect(-1, ret);
3835 DestroyWindow(hwnd);
3837 hwnd = create_listview_control(0);
3838 ok(hwnd != NULL, "failed to create a listview window\n");
3840 /* LVM_MAPINDEXTOID with invalid index */
3841 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3842 expect(-1, ret);
3844 insert_item(hwnd, 0);
3845 insert_item(hwnd, 1);
3847 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
3848 expect(-1, ret);
3849 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
3850 expect(-1, ret);
3852 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3853 expect(0, ret);
3854 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3855 expect(1, ret);
3856 /* remove 0 indexed item, id retained */
3857 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
3858 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3859 expect(1, ret);
3860 /* new id starts from previous value */
3861 insert_item(hwnd, 1);
3862 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3863 expect(2, ret);
3865 /* get index by id */
3866 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
3867 expect(-1, ret);
3868 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
3869 expect(-1, ret);
3870 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
3871 expect(0, ret);
3872 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
3873 expect(1, ret);
3875 DestroyWindow(hwnd);
3878 static void test_getitemspacing(void)
3880 HWND hwnd;
3881 DWORD ret;
3882 INT cx, cy;
3883 HIMAGELIST himl;
3884 HBITMAP hbmp;
3885 LVITEMA itema;
3887 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
3888 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
3890 /* LVS_ICON */
3891 hwnd = create_custom_listview_control(0);
3892 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3893 todo_wine {
3894 expect(cx, LOWORD(ret));
3895 expect(cy, HIWORD(ret));
3897 /* now try with icons */
3898 himl = ImageList_Create(40, 40, 0, 4, 4);
3899 ok(himl != NULL, "failed to create imagelist\n");
3900 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
3901 ok(hbmp != NULL, "failed to create bitmap\n");
3902 ret = ImageList_Add(himl, hbmp, 0);
3903 expect(0, ret);
3904 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
3905 expect(0, ret);
3907 itema.mask = LVIF_IMAGE;
3908 itema.iImage = 0;
3909 itema.iItem = 0;
3910 itema.iSubItem = 0;
3911 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
3912 expect(0, ret);
3913 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3914 todo_wine {
3915 /* spacing + icon size returned */
3916 expect(cx + 40, LOWORD(ret));
3917 expect(cy + 40, HIWORD(ret));
3919 DestroyWindow(hwnd);
3920 /* LVS_SMALLICON */
3921 hwnd = create_custom_listview_control(LVS_SMALLICON);
3922 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3923 todo_wine {
3924 expect(cx, LOWORD(ret));
3925 expect(cy, HIWORD(ret));
3927 DestroyWindow(hwnd);
3928 /* LVS_REPORT */
3929 hwnd = create_custom_listview_control(LVS_REPORT);
3930 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3931 todo_wine {
3932 expect(cx, LOWORD(ret));
3933 expect(cy, HIWORD(ret));
3935 DestroyWindow(hwnd);
3936 /* LVS_LIST */
3937 hwnd = create_custom_listview_control(LVS_LIST);
3938 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3939 todo_wine {
3940 expect(cx, LOWORD(ret));
3941 expect(cy, HIWORD(ret));
3943 DestroyWindow(hwnd);
3946 static void test_getcolumnwidth(void)
3948 HWND hwnd;
3949 DWORD ret;
3950 DWORD_PTR style;
3951 LVCOLUMNA col;
3953 /* default column width */
3954 hwnd = create_custom_listview_control(0);
3955 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3956 expect(0, ret);
3957 style = GetWindowLong(hwnd, GWL_STYLE);
3958 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
3959 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3960 todo_wine expect(8, ret);
3961 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
3962 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
3963 col.mask = 0;
3964 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
3965 expect(0, ret);
3966 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3967 expect(10, ret);
3968 DestroyWindow(hwnd);
3971 static void test_scrollnotify(void)
3973 HWND hwnd;
3974 DWORD ret;
3976 hwnd = create_listview_control(0);
3978 insert_column(hwnd, 0);
3979 insert_column(hwnd, 1);
3980 insert_item(hwnd, 0);
3982 /* make it scrollable - resize */
3983 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3984 expect(TRUE, ret);
3985 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3986 expect(TRUE, ret);
3988 /* try with dummy call */
3989 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3990 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
3991 expect(TRUE, ret);
3992 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
3993 "scroll notify 1", TRUE);
3995 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3996 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
3997 expect(TRUE, ret);
3998 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
3999 "scroll notify 2", TRUE);
4001 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4002 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4003 expect(TRUE, ret);
4004 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4005 "scroll notify 3", TRUE);
4007 DestroyWindow(hwnd);
4010 START_TEST(listview)
4012 HMODULE hComctl32;
4013 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
4015 ULONG_PTR ctx_cookie;
4017 hComctl32 = GetModuleHandleA("comctl32.dll");
4018 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
4019 if (pInitCommonControlsEx)
4021 INITCOMMONCONTROLSEX iccex;
4022 iccex.dwSize = sizeof(iccex);
4023 iccex.dwICC = ICC_LISTVIEW_CLASSES;
4024 pInitCommonControlsEx(&iccex);
4026 else
4027 InitCommonControls();
4029 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
4031 hwndparent = create_parent_window(FALSE);
4032 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4034 g_is_below_5 = is_below_comctl_5();
4036 test_images();
4037 test_checkboxes();
4038 test_items();
4039 test_create();
4040 test_redraw();
4041 test_customdraw();
4042 test_icon_spacing();
4043 test_color();
4044 test_item_count();
4045 test_item_position();
4046 test_columns();
4047 test_getorigin();
4048 test_multiselect();
4049 test_getitemrect();
4050 test_subitem_rect();
4051 test_sorting();
4052 test_ownerdata();
4053 test_norecompute();
4054 test_nosortheader();
4055 test_setredraw();
4056 test_hittest();
4057 test_getviewrect();
4058 test_getitemposition();
4059 test_columnscreation();
4060 test_editbox();
4061 test_notifyformat();
4062 test_indentation();
4063 test_getitemspacing();
4064 test_getcolumnwidth();
4066 if (!load_v6_module(&ctx_cookie))
4068 DestroyWindow(hwndparent);
4069 return;
4072 /* comctl32 version 6 tests start here */
4073 test_get_set_view();
4074 test_canceleditlabel();
4075 test_mapidindex();
4076 test_scrollnotify();
4078 unload_v6_module(ctx_cookie);
4080 DestroyWindow(hwndparent);