comctl32/listview: XP SP3 comctl32 V6 test workaround.
[wine/wine-gecko.git] / dlls / comctl32 / tests / listview.c
blob6c6a3b8f7cf757809dde4c35db79d6917667b612
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 /* format reported to control:
83 -1 falls to defproc, anything else returned */
84 INT notifyFormat;
85 /* indicates we're running < 5.80 version */
86 BOOL g_is_below_5;
88 static HWND subclass_editbox(HWND hwndListview);
90 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
92 static const struct message create_parent_wnd_seq[] = {
93 { WM_GETMINMAXINFO, sent },
94 { WM_NCCREATE, sent },
95 { WM_NCCALCSIZE, sent|wparam, 0 },
96 { WM_CREATE, sent },
97 { WM_SHOWWINDOW, sent|wparam, 1 },
98 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
99 { WM_QUERYNEWPALETTE, sent|optional },
100 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
101 { WM_WINDOWPOSCHANGED, sent|optional },
102 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
103 { WM_ACTIVATEAPP, sent|wparam, 1 },
104 { WM_NCACTIVATE, sent|wparam, 1 },
105 { WM_ACTIVATE, sent|wparam, 1 },
106 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
107 { WM_IME_NOTIFY, sent|defwinproc|optional },
108 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
109 /* Win9x adds SWP_NOZORDER below */
110 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
111 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
112 { WM_SIZE, sent },
113 { WM_MOVE, sent },
114 { 0 }
117 static const struct message redraw_listview_seq[] = {
118 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
119 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
120 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
121 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, HEADER_ID },
122 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
123 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
124 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
125 { 0 }
128 static const struct message listview_icon_spacing_seq[] = {
129 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
130 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
131 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
132 { 0 }
135 static const struct message listview_color_seq[] = {
136 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
137 { LVM_GETBKCOLOR, sent },
138 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
139 { LVM_GETTEXTCOLOR, sent },
140 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
141 { LVM_GETTEXTBKCOLOR, sent },
143 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
144 { LVM_GETBKCOLOR, sent },
145 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
146 { LVM_GETTEXTCOLOR, sent },
147 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
148 { LVM_GETTEXTBKCOLOR, sent },
150 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
151 { LVM_GETBKCOLOR, sent },
152 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
153 { LVM_GETTEXTCOLOR, sent },
154 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
155 { LVM_GETTEXTBKCOLOR, sent },
157 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
158 { LVM_GETBKCOLOR, sent },
159 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
160 { LVM_GETTEXTCOLOR, sent },
161 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
162 { LVM_GETTEXTBKCOLOR, sent },
163 { 0 }
166 static const struct message listview_item_count_seq[] = {
167 { LVM_GETITEMCOUNT, sent },
168 { LVM_INSERTITEM, sent },
169 { LVM_INSERTITEM, sent },
170 { LVM_INSERTITEM, sent },
171 { LVM_GETITEMCOUNT, sent },
172 { LVM_DELETEITEM, sent|wparam, 2 },
173 { LVM_GETITEMCOUNT, sent },
174 { LVM_DELETEALLITEMS, sent },
175 { LVM_GETITEMCOUNT, sent },
176 { LVM_INSERTITEM, sent },
177 { LVM_INSERTITEM, sent },
178 { LVM_GETITEMCOUNT, sent },
179 { LVM_INSERTITEM, sent },
180 { LVM_GETITEMCOUNT, sent },
181 { 0 }
184 static const struct message listview_itempos_seq[] = {
185 { LVM_INSERTITEM, sent },
186 { LVM_INSERTITEM, sent },
187 { LVM_INSERTITEM, sent },
188 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
189 { LVM_GETITEMPOSITION, sent|wparam, 1 },
190 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
191 { LVM_GETITEMPOSITION, sent|wparam, 2 },
192 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
193 { LVM_GETITEMPOSITION, sent|wparam, 0 },
194 { 0 }
197 static const struct message listview_ownerdata_switchto_seq[] = {
198 { WM_STYLECHANGING, sent },
199 { WM_STYLECHANGED, sent },
200 { 0 }
203 static const struct message listview_getorderarray_seq[] = {
204 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
205 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
206 { 0 }
209 static const struct message empty_seq[] = {
210 { 0 }
213 static const struct message forward_erasebkgnd_parent_seq[] = {
214 { WM_ERASEBKGND, sent },
215 { 0 }
218 static const struct message ownderdata_select_focus_parent_seq[] = {
219 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
220 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
221 { 0 }
224 static const struct message textcallback_set_again_parent_seq[] = {
225 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
226 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
227 { 0 }
230 static const struct message single_getdispinfo_parent_seq[] = {
231 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
232 { 0 }
235 static const struct message getitemposition_seq1[] = {
236 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
237 { 0 }
240 static const struct message getitemposition_seq2[] = {
241 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
242 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
243 { 0 }
246 static const struct message editbox_create_pos[] = {
247 /* sequence sent after LVN_BEGINLABELEDIT */
248 { WM_WINDOWPOSCHANGING, sent },
249 { WM_NCCALCSIZE, sent },
250 { WM_WINDOWPOSCHANGED, sent },
251 { WM_MOVE, sent|defwinproc },
252 { WM_SIZE, sent|defwinproc },
253 /* the rest is todo */
254 { WM_WINDOWPOSCHANGING, sent },
255 { WM_WINDOWPOSCHANGED, sent },
256 { 0 }
259 struct subclass_info
261 WNDPROC oldproc;
264 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
266 static LONG defwndproc_counter = 0;
267 LRESULT ret;
268 struct message msg;
270 msg.message = message;
271 msg.flags = sent|wparam|lparam;
272 if (defwndproc_counter) msg.flags |= defwinproc;
273 msg.wParam = wParam;
274 msg.lParam = lParam;
275 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
277 /* log system messages, except for painting */
278 if (message < WM_USER &&
279 message != WM_PAINT &&
280 message != WM_ERASEBKGND &&
281 message != WM_NCPAINT &&
282 message != WM_NCHITTEST &&
283 message != WM_GETTEXT &&
284 message != WM_GETICON &&
285 message != WM_DEVICECHANGE)
287 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
289 add_message(sequences, PARENT_SEQ_INDEX, &msg);
291 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
293 switch (message)
295 case WM_NOTIFY:
297 switch (((NMHDR*)lParam)->code)
299 case LVN_BEGINLABELEDIT:
300 /* subclass edit box */
301 if (!blockEdit)
302 subclass_editbox(((NMHDR*)lParam)->hwndFrom);
304 return blockEdit;
306 case LVN_ENDLABELEDIT:
307 /* always accept new item text */
308 return TRUE;
310 break;
312 case WM_NOTIFYFORMAT:
314 /* force to return format */
315 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
316 break;
320 defwndproc_counter++;
321 ret = DefWindowProcA(hwnd, message, wParam, lParam);
322 defwndproc_counter--;
324 return ret;
327 static BOOL register_parent_wnd_class(BOOL Unicode)
329 WNDCLASSA clsA;
330 WNDCLASSW clsW;
332 if (Unicode)
334 clsW.style = 0;
335 clsW.lpfnWndProc = parent_wnd_proc;
336 clsW.cbClsExtra = 0;
337 clsW.cbWndExtra = 0;
338 clsW.hInstance = GetModuleHandleW(NULL);
339 clsW.hIcon = 0;
340 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
341 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
342 clsW.lpszMenuName = NULL;
343 clsW.lpszClassName = testparentclassW;
345 else
347 clsA.style = 0;
348 clsA.lpfnWndProc = parent_wnd_proc;
349 clsA.cbClsExtra = 0;
350 clsA.cbWndExtra = 0;
351 clsA.hInstance = GetModuleHandleA(NULL);
352 clsA.hIcon = 0;
353 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
354 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
355 clsA.lpszMenuName = NULL;
356 clsA.lpszClassName = "Listview test parent class";
359 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
362 static HWND create_parent_window(BOOL Unicode)
364 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W'};
366 if (!register_parent_wnd_class(Unicode))
367 return NULL;
369 blockEdit = FALSE;
370 notifyFormat = -1;
372 if (Unicode)
373 return CreateWindowExW(0, testparentclassW, nameW,
374 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
375 WS_MAXIMIZEBOX | WS_VISIBLE,
376 0, 0, 100, 100,
377 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
378 else
379 return CreateWindowExA(0, "Listview test parent class",
380 "Listview test parent window",
381 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
382 WS_MAXIMIZEBOX | WS_VISIBLE,
383 0, 0, 100, 100,
384 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
387 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
389 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
390 static LONG defwndproc_counter = 0;
391 LRESULT ret;
392 struct message msg;
394 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
396 /* some debug output for style changing */
397 if ((message == WM_STYLECHANGING ||
398 message == WM_STYLECHANGED) && lParam)
400 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
401 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
404 msg.message = message;
405 msg.flags = sent|wparam|lparam;
406 if (defwndproc_counter) msg.flags |= defwinproc;
407 msg.wParam = wParam;
408 msg.lParam = lParam;
409 msg.id = LISTVIEW_ID;
410 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
412 defwndproc_counter++;
413 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
414 defwndproc_counter--;
415 return ret;
418 static HWND create_listview_control(DWORD style)
420 struct subclass_info *info;
421 HWND hwnd;
422 RECT rect;
424 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
425 if (!info)
426 return NULL;
428 GetClientRect(hwndparent, &rect);
429 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
430 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
431 0, 0, rect.right, rect.bottom,
432 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
433 ok(hwnd != NULL, "gle=%d\n", GetLastError());
435 if (!hwnd)
437 HeapFree(GetProcessHeap(), 0, info);
438 return NULL;
441 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
442 (LONG_PTR)listview_subclass_proc);
443 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
445 return hwnd;
448 /* unicode listview window with specified parent */
449 static HWND create_listview_controlW(DWORD style, HWND parent)
451 struct subclass_info *info;
452 HWND hwnd;
453 RECT rect;
454 static const WCHAR nameW[] = {'f','o','o',0};
456 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
457 if (!info)
458 return NULL;
460 GetClientRect(parent, &rect);
461 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
462 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
463 0, 0, rect.right, rect.bottom,
464 parent, NULL, GetModuleHandleW(NULL), NULL);
465 ok(hwnd != NULL, "gle=%d\n", GetLastError());
467 if (!hwnd)
469 HeapFree(GetProcessHeap(), 0, info);
470 return NULL;
473 info->oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
474 (LONG_PTR)listview_subclass_proc);
475 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)info);
477 return hwnd;
480 static HWND create_custom_listview_control(DWORD style)
482 struct subclass_info *info;
483 HWND hwnd;
484 RECT rect;
486 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
487 if (!info)
488 return NULL;
490 GetClientRect(hwndparent, &rect);
491 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
492 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
493 0, 0, rect.right, rect.bottom,
494 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
495 ok(hwnd != NULL, "gle=%d\n", GetLastError());
497 if (!hwnd)
499 HeapFree(GetProcessHeap(), 0, info);
500 return NULL;
503 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
504 (LONG_PTR)listview_subclass_proc);
505 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
507 return hwnd;
510 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
512 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
513 static LONG defwndproc_counter = 0;
514 LRESULT ret;
515 struct message msg;
517 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
519 msg.message = message;
520 msg.flags = sent|wparam|lparam;
521 if (defwndproc_counter) msg.flags |= defwinproc;
522 msg.wParam = wParam;
523 msg.lParam = lParam;
524 msg.id = HEADER_ID;
525 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
527 defwndproc_counter++;
528 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
529 defwndproc_counter--;
530 return ret;
533 static HWND subclass_header(HWND hwndListview)
535 struct subclass_info *info;
536 HWND hwnd;
538 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
539 if (!info)
540 return NULL;
542 hwnd = ListView_GetHeader(hwndListview);
543 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
544 (LONG_PTR)header_subclass_proc);
545 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
547 return hwnd;
550 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
552 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
553 static LONG defwndproc_counter = 0;
554 LRESULT ret;
555 struct message msg;
557 msg.message = message;
558 msg.flags = sent|wparam|lparam;
559 if (defwndproc_counter) msg.flags |= defwinproc;
560 msg.wParam = wParam;
561 msg.lParam = lParam;
563 /* all we need is sizing */
564 if (message == WM_WINDOWPOSCHANGING ||
565 message == WM_NCCALCSIZE ||
566 message == WM_WINDOWPOSCHANGED ||
567 message == WM_MOVE ||
568 message == WM_SIZE)
570 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
573 defwndproc_counter++;
574 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
575 defwndproc_counter--;
576 return ret;
579 static HWND subclass_editbox(HWND hwndListview)
581 struct subclass_info *info;
582 HWND hwnd;
584 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
585 if (!info)
586 return NULL;
588 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
589 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
590 (LONG_PTR)editbox_subclass_proc);
591 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
593 return hwnd;
596 /* Performs a single LVM_HITTEST test */
597 static void test_lvm_hittest(HWND hwnd, INT x, INT y, INT item, UINT flags,
598 BOOL todo_item, BOOL todo_flags, int line)
600 LVHITTESTINFO lpht;
601 DWORD ret;
603 lpht.pt.x = x;
604 lpht.pt.y = y;
605 lpht.iSubItem = 10;
607 trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
608 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
610 if (todo_item)
612 todo_wine
614 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
615 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
616 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
619 else
621 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
622 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
623 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
626 if (todo_flags)
628 todo_wine
629 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
631 else
632 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
635 /* Performs a single LVM_SUBITEMHITTEST test */
636 static void test_lvm_subitemhittest(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
637 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
639 LVHITTESTINFO lpht;
640 DWORD ret;
642 lpht.pt.x = x;
643 lpht.pt.y = y;
645 trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
646 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
648 if (todo_item)
650 todo_wine
652 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
653 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
656 else
658 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
659 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
662 if (todo_subitem)
664 todo_wine
665 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
667 else
668 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
670 if (todo_flags)
672 todo_wine
673 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
675 else
676 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
679 static void test_images(void)
681 HWND hwnd;
682 DWORD r;
683 LVITEM item;
684 HIMAGELIST himl;
685 HBITMAP hbmp;
686 RECT r1, r2;
687 static CHAR hello[] = "hello";
689 himl = ImageList_Create(40, 40, 0, 4, 4);
690 ok(himl != NULL, "failed to create imagelist\n");
692 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
693 ok(hbmp != NULL, "failed to create bitmap\n");
695 r = ImageList_Add(himl, hbmp, 0);
696 ok(r == 0, "should be zero\n");
698 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
699 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
700 ok(hwnd != NULL, "failed to create listview window\n");
702 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
703 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
705 ok(r == 0, "should return zero\n");
707 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
708 ok(r == 0, "should return zero\n");
710 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
711 /* returns dimensions */
713 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
714 ok(r == 0, "should be zero items\n");
716 item.mask = LVIF_IMAGE | LVIF_TEXT;
717 item.iItem = 0;
718 item.iSubItem = 1;
719 item.iImage = 0;
720 item.pszText = 0;
721 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
722 ok(r == -1, "should fail\n");
724 item.iSubItem = 0;
725 item.pszText = hello;
726 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
727 ok(r == 0, "should not fail\n");
729 memset(&r1, 0, sizeof r1);
730 r1.left = LVIR_ICON;
731 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
733 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
734 ok(r == TRUE, "should not fail\n");
736 item.iSubItem = 0;
737 item.pszText = hello;
738 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
739 ok(r == 0, "should not fail\n");
741 memset(&r2, 0, sizeof r2);
742 r2.left = LVIR_ICON;
743 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
745 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
747 DestroyWindow(hwnd);
750 static void test_checkboxes(void)
752 HWND hwnd;
753 LVITEMA item;
754 DWORD r;
755 static CHAR text[] = "Text",
756 text2[] = "Text2",
757 text3[] = "Text3";
759 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
760 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
761 ok(hwnd != NULL, "failed to create listview window\n");
763 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
764 item.mask = LVIF_TEXT | LVIF_STATE;
765 item.stateMask = 0xffff;
766 item.state = 0xfccc;
767 item.iItem = 0;
768 item.iSubItem = 0;
769 item.pszText = text;
770 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
771 ok(r == 0, "ret %d\n", r);
773 item.iItem = 0;
774 item.mask = LVIF_STATE;
775 item.stateMask = 0xffff;
776 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
777 ok(item.state == 0xfccc, "state %x\n", item.state);
779 /* Don't set LVIF_STATE */
780 item.mask = LVIF_TEXT;
781 item.stateMask = 0xffff;
782 item.state = 0xfccc;
783 item.iItem = 1;
784 item.iSubItem = 0;
785 item.pszText = text;
786 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
787 ok(r == 1, "ret %d\n", r);
789 item.iItem = 1;
790 item.mask = LVIF_STATE;
791 item.stateMask = 0xffff;
792 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
793 ok(item.state == 0, "state %x\n", item.state);
795 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
796 ok(r == 0, "should return zero\n");
798 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
799 item.iItem = 0;
800 item.mask = LVIF_STATE;
801 item.stateMask = 0xffff;
802 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
803 ok(item.state == 0x1ccc, "state %x\n", item.state);
805 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
806 item.iItem = 2;
807 item.mask = LVIF_TEXT;
808 item.state = 0;
809 item.pszText = text2;
810 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
811 ok(r == 2, "ret %d\n", r);
813 item.iItem = 2;
814 item.mask = LVIF_STATE;
815 item.stateMask = 0xffff;
816 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
817 ok(item.state == 0x1000, "state %x\n", item.state);
819 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
820 item.iItem = 3;
821 item.mask = LVIF_TEXT | LVIF_STATE;
822 item.stateMask = 0xffff;
823 item.state = 0x2aaa;
824 item.pszText = text3;
825 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
826 ok(r == 3, "ret %d\n", r);
828 item.iItem = 3;
829 item.mask = LVIF_STATE;
830 item.stateMask = 0xffff;
831 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
832 ok(item.state == 0x1aaa, "state %x\n", item.state);
834 /* Set an item's state to checked */
835 item.iItem = 3;
836 item.mask = LVIF_STATE;
837 item.stateMask = 0xf000;
838 item.state = 0x2000;
839 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
841 item.iItem = 3;
842 item.mask = LVIF_STATE;
843 item.stateMask = 0xffff;
844 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
845 ok(item.state == 0x2aaa, "state %x\n", item.state);
847 /* Check that only the bits we asked for are returned,
848 * and that all the others are set to zero
850 item.iItem = 3;
851 item.mask = LVIF_STATE;
852 item.stateMask = 0xf000;
853 item.state = 0xffff;
854 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
855 ok(item.state == 0x2000, "state %x\n", item.state);
857 /* Set the style again and check that doesn't change an item's state */
858 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
859 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
861 item.iItem = 3;
862 item.mask = LVIF_STATE;
863 item.stateMask = 0xffff;
864 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
865 ok(item.state == 0x2aaa, "state %x\n", item.state);
867 /* Unsetting the checkbox extended style doesn't change an item's state */
868 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
869 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
871 item.iItem = 3;
872 item.mask = LVIF_STATE;
873 item.stateMask = 0xffff;
874 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
875 ok(item.state == 0x2aaa, "state %x\n", item.state);
877 /* Now setting the style again will change an item's state */
878 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
879 ok(r == 0, "ret %x\n", r);
881 item.iItem = 3;
882 item.mask = LVIF_STATE;
883 item.stateMask = 0xffff;
884 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
885 ok(item.state == 0x1aaa, "state %x\n", item.state);
887 /* Toggle checkbox tests (bug 9934) */
888 memset (&item, 0xcc, sizeof(item));
889 item.mask = LVIF_STATE;
890 item.iItem = 3;
891 item.iSubItem = 0;
892 item.state = LVIS_FOCUSED;
893 item.stateMask = LVIS_FOCUSED;
894 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
895 expect(1, r);
897 item.iItem = 3;
898 item.mask = LVIF_STATE;
899 item.stateMask = 0xffff;
900 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
901 ok(item.state == 0x1aab, "state %x\n", item.state);
903 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
904 expect(0, r);
905 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
906 expect(0, r);
908 item.iItem = 3;
909 item.mask = LVIF_STATE;
910 item.stateMask = 0xffff;
911 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
912 ok(item.state == 0x2aab, "state %x\n", item.state);
914 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
915 expect(0, r);
916 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
917 expect(0, r);
919 item.iItem = 3;
920 item.mask = LVIF_STATE;
921 item.stateMask = 0xffff;
922 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
923 ok(item.state == 0x1aab, "state %x\n", item.state);
925 DestroyWindow(hwnd);
928 static void insert_column(HWND hwnd, int idx)
930 LVCOLUMN column;
931 DWORD rc;
933 memset(&column, 0xcc, sizeof(column));
934 column.mask = LVCF_SUBITEM;
935 column.iSubItem = idx;
937 rc = ListView_InsertColumn(hwnd, idx, &column);
938 expect(idx, rc);
941 static void insert_item(HWND hwnd, int idx)
943 static CHAR text[] = "foo";
945 LVITEMA item;
946 DWORD rc;
948 memset(&item, 0xcc, sizeof (item));
949 item.mask = LVIF_TEXT;
950 item.iItem = idx;
951 item.iSubItem = 0;
952 item.pszText = text;
954 rc = ListView_InsertItem(hwnd, &item);
955 expect(idx, rc);
958 static void test_items(void)
960 const LPARAM lparamTest = 0x42;
961 HWND hwnd;
962 LVITEMA item;
963 DWORD r;
964 static CHAR text[] = "Text";
966 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
967 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
968 ok(hwnd != NULL, "failed to create listview window\n");
971 * Test setting/getting item params
974 /* Set up two columns */
975 insert_column(hwnd, 0);
976 insert_column(hwnd, 1);
978 /* LVIS_SELECTED with zero stateMask */
979 /* set */
980 memset (&item, 0, sizeof (item));
981 item.mask = LVIF_STATE;
982 item.state = LVIS_SELECTED;
983 item.stateMask = 0;
984 item.iItem = 0;
985 item.iSubItem = 0;
986 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
987 ok(r == 0, "ret %d\n", r);
988 /* get */
989 memset (&item, 0xcc, sizeof (item));
990 item.mask = LVIF_STATE;
991 item.stateMask = LVIS_SELECTED;
992 item.state = 0;
993 item.iItem = 0;
994 item.iSubItem = 0;
995 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
996 ok(r != 0, "ret %d\n", r);
997 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
998 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1000 /* LVIS_SELECTED with zero stateMask */
1001 /* set */
1002 memset (&item, 0, sizeof (item));
1003 item.mask = LVIF_STATE;
1004 item.state = LVIS_FOCUSED;
1005 item.stateMask = 0;
1006 item.iItem = 0;
1007 item.iSubItem = 0;
1008 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1009 ok(r == 0, "ret %d\n", r);
1010 /* get */
1011 memset (&item, 0xcc, sizeof (item));
1012 item.mask = LVIF_STATE;
1013 item.stateMask = LVIS_FOCUSED;
1014 item.state = 0;
1015 item.iItem = 0;
1016 item.iSubItem = 0;
1017 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1018 ok(r != 0, "ret %d\n", r);
1019 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1020 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1022 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1023 /* set */
1024 memset (&item, 0, sizeof (item));
1025 item.mask = LVIF_STATE;
1026 item.state = LVIS_CUT;
1027 item.stateMask = LVIS_FOCUSED;
1028 item.iItem = 0;
1029 item.iSubItem = 0;
1030 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1031 ok(r == 0, "ret %d\n", r);
1032 /* get */
1033 memset (&item, 0xcc, sizeof (item));
1034 item.mask = LVIF_STATE;
1035 item.stateMask = LVIS_CUT;
1036 item.state = 0;
1037 item.iItem = 0;
1038 item.iSubItem = 0;
1039 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1040 ok(r != 0, "ret %d\n", r);
1041 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1042 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1044 /* Insert an item with just a param */
1045 memset (&item, 0xcc, sizeof (item));
1046 item.mask = LVIF_PARAM;
1047 item.iItem = 0;
1048 item.iSubItem = 0;
1049 item.lParam = lparamTest;
1050 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1051 ok(r == 0, "ret %d\n", r);
1053 /* Test getting of the param */
1054 memset (&item, 0xcc, sizeof (item));
1055 item.mask = LVIF_PARAM;
1056 item.iItem = 0;
1057 item.iSubItem = 0;
1058 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1059 ok(r != 0, "ret %d\n", r);
1060 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1062 /* Set up a subitem */
1063 memset (&item, 0xcc, sizeof (item));
1064 item.mask = LVIF_TEXT;
1065 item.iItem = 0;
1066 item.iSubItem = 1;
1067 item.pszText = text;
1068 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1069 ok(r != 0, "ret %d\n", r);
1071 /* Query param from subitem: returns main item param */
1072 memset (&item, 0xcc, sizeof (item));
1073 item.mask = LVIF_PARAM;
1074 item.iItem = 0;
1075 item.iSubItem = 1;
1076 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1077 ok(r != 0, "ret %d\n", r);
1078 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1080 /* Set up param on first subitem: no effect */
1081 memset (&item, 0xcc, sizeof (item));
1082 item.mask = LVIF_PARAM;
1083 item.iItem = 0;
1084 item.iSubItem = 1;
1085 item.lParam = lparamTest+1;
1086 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1087 ok(r == 0, "ret %d\n", r);
1089 /* Query param from subitem again: should still return main item param */
1090 memset (&item, 0xcc, sizeof (item));
1091 item.mask = LVIF_PARAM;
1092 item.iItem = 0;
1093 item.iSubItem = 1;
1094 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1095 ok(r != 0, "ret %d\n", r);
1096 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1098 /**** Some tests of state highlighting ****/
1099 memset (&item, 0xcc, sizeof (item));
1100 item.mask = LVIF_STATE;
1101 item.iItem = 0;
1102 item.iSubItem = 0;
1103 item.state = LVIS_SELECTED;
1104 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1105 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1106 ok(r != 0, "ret %d\n", r);
1107 item.iSubItem = 1;
1108 item.state = LVIS_DROPHILITED;
1109 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1110 ok(r != 0, "ret %d\n", r);
1112 memset (&item, 0xcc, sizeof (item));
1113 item.mask = LVIF_STATE;
1114 item.iItem = 0;
1115 item.iSubItem = 0;
1116 item.stateMask = -1;
1117 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1118 ok(r != 0, "ret %d\n", r);
1119 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1120 item.iSubItem = 1;
1121 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1122 ok(r != 0, "ret %d\n", r);
1123 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1125 /* some notnull but meaningless masks */
1126 memset (&item, 0, sizeof(item));
1127 item.mask = LVIF_NORECOMPUTE;
1128 item.iItem = 0;
1129 item.iSubItem = 0;
1130 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1131 ok(r != 0, "ret %d\n", r);
1132 memset (&item, 0, sizeof(item));
1133 item.mask = LVIF_DI_SETITEM;
1134 item.iItem = 0;
1135 item.iSubItem = 0;
1136 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1137 ok(r != 0, "ret %d\n", r);
1139 /* set text to callback value already having it */
1140 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1141 expect(TRUE, r);
1142 memset (&item, 0, sizeof (item));
1143 item.mask = LVIF_TEXT;
1144 item.pszText = LPSTR_TEXTCALLBACK;
1145 item.iItem = 0;
1146 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1147 ok(r == 0, "ret %d\n", r);
1148 memset (&item, 0, sizeof (item));
1150 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1152 item.pszText = LPSTR_TEXTCALLBACK;
1153 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1154 expect(TRUE, r);
1156 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1157 "check callback text comparison rule", FALSE);
1159 DestroyWindow(hwnd);
1162 static void test_columns(void)
1164 HWND hwnd, hwndheader;
1165 LVCOLUMN column;
1166 DWORD rc;
1167 INT order[2];
1169 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1170 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1171 ok(hwnd != NULL, "failed to create listview window\n");
1173 /* Add a column with no mask */
1174 memset(&column, 0xcc, sizeof(column));
1175 column.mask = 0;
1176 rc = ListView_InsertColumn(hwnd, 0, &column);
1177 ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
1179 /* Check its width */
1180 rc = ListView_GetColumnWidth(hwnd, 0);
1181 ok(rc==10 ||
1182 broken(rc==0), /* win9x */
1183 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1185 DestroyWindow(hwnd);
1187 /* LVM_GETCOLUMNORDERARRAY */
1188 hwnd = create_listview_control(0);
1189 hwndheader = subclass_header(hwnd);
1191 memset(&column, 0, sizeof(column));
1192 column.mask = LVCF_WIDTH;
1193 column.cx = 100;
1194 rc = ListView_InsertColumn(hwnd, 0, &column);
1195 ok(rc == 0, "Inserting column failed with %d\n", rc);
1197 column.cx = 200;
1198 rc = ListView_InsertColumn(hwnd, 1, &column);
1199 ok(rc == 1, "Inserting column failed with %d\n", rc);
1201 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1203 rc = SendMessage(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1204 ok(rc != 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1205 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1206 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1208 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1210 DestroyWindow(hwnd);
1212 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1213 static WNDPROC listviewWndProc;
1214 static HIMAGELIST test_create_imagelist;
1216 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1218 LRESULT ret;
1220 if (uMsg == WM_CREATE)
1222 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1223 lpcs->style |= LVS_REPORT;
1225 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1226 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1227 return ret;
1230 static void test_create(void)
1232 HWND hList;
1233 HWND hHeader;
1234 LONG_PTR ret;
1235 LONG r;
1236 LVCOLUMNA col;
1237 RECT rect;
1238 WNDCLASSEX cls;
1239 cls.cbSize = sizeof(WNDCLASSEX);
1240 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1241 listviewWndProc = cls.lpfnWndProc;
1242 cls.lpfnWndProc = create_test_wndproc;
1243 cls.lpszClassName = "MyListView32";
1244 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1246 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1247 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1248 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1249 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1250 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1251 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1252 DestroyWindow(hList);
1254 /* header isn't created on LVS_ICON and LVS_LIST styles */
1255 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1256 GetModuleHandle(NULL), 0);
1257 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1258 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1259 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1260 /* insert column */
1261 memset(&col, 0, sizeof(LVCOLUMNA));
1262 col.mask = LVCF_WIDTH;
1263 col.cx = 100;
1264 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1265 ok(r == 0, "Expected 0 column's inserted\n");
1266 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1267 ok(IsWindow(hHeader), "Header should be created\n");
1268 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1269 DestroyWindow(hList);
1271 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1272 GetModuleHandle(NULL), 0);
1273 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1274 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1275 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1276 /* insert column */
1277 memset(&col, 0, sizeof(LVCOLUMNA));
1278 col.mask = LVCF_WIDTH;
1279 col.cx = 100;
1280 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1281 ok(r == 0, "Expected 0 column's inserted\n");
1282 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1283 ok(IsWindow(hHeader), "Header should be created\n");
1284 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1285 DestroyWindow(hList);
1287 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1288 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1289 GetModuleHandle(NULL), 0);
1290 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1291 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1292 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1293 ok(IsWindow(hHeader), "Header should be created\n");
1294 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1295 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1296 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1297 ok(IsWindow(hHeader), "Header should be created\n");
1298 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1299 DestroyWindow(hList);
1301 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1302 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1303 GetModuleHandle(NULL), 0);
1304 ret = SetWindowLongPtr(hList, GWL_STYLE,
1305 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1306 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1307 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1308 ok(IsWindow(hHeader), "Header should be created\n");
1309 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1310 ret = SetWindowLongPtr(hList, GWL_STYLE,
1311 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1312 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1313 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1314 ok(IsWindow(hHeader), "Header should be created\n");
1315 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1316 DestroyWindow(hList);
1318 /* LVS_REPORT without WS_VISIBLE */
1319 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1320 GetModuleHandle(NULL), 0);
1321 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1322 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1323 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1324 /* insert column */
1325 memset(&col, 0, sizeof(LVCOLUMNA));
1326 col.mask = LVCF_WIDTH;
1327 col.cx = 100;
1328 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1329 ok(r == 0, "Expected 0 column's inserted\n");
1330 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1331 ok(IsWindow(hHeader), "Header should be created\n");
1332 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1333 DestroyWindow(hList);
1335 /* LVS_REPORT without WS_VISIBLE, try to show it */
1336 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1337 GetModuleHandle(NULL), 0);
1338 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1339 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1340 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1341 ShowWindow(hList, SW_SHOW);
1342 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1343 ok(IsWindow(hHeader), "Header should be created\n");
1344 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1345 DestroyWindow(hList);
1347 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1348 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1349 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1350 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1351 ok(IsWindow(hHeader), "Header should be created\n");
1352 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1353 /* HDS_DRAGDROP set by default */
1354 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1355 DestroyWindow(hList);
1357 /* setting LVS_EX_HEADERDRAGDROP creates header */
1358 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1359 GetModuleHandle(NULL), 0);
1360 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1361 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1362 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1363 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1364 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1365 ok(IsWindow(hHeader) ||
1366 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1367 "Header should be created\n");
1368 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1369 DestroyWindow(hList);
1371 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1372 hList = create_custom_listview_control(0);
1373 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1374 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1375 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1376 DestroyWindow(hList);
1378 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1379 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1380 GetModuleHandle(NULL), 0);
1381 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1382 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1384 rect.left = LVIR_BOUNDS;
1385 rect.top = 1;
1386 rect.right = rect.bottom = -10;
1387 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1388 ok(r != 0, "Expected not-null LRESULT\n");
1390 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1391 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1392 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1394 DestroyWindow(hList);
1397 static void test_redraw(void)
1399 HWND hwnd, hwndheader;
1400 HDC hdc;
1401 BOOL res;
1402 DWORD r;
1404 hwnd = create_listview_control(0);
1405 hwndheader = subclass_header(hwnd);
1407 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1409 trace("invalidate & update\n");
1410 InvalidateRect(hwnd, NULL, TRUE);
1411 UpdateWindow(hwnd);
1412 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1414 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1416 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1417 /* 1. Without backbuffer */
1418 res = ListView_SetBkColor(hwnd, CLR_NONE);
1419 expect(TRUE, res);
1421 hdc = GetWindowDC(hwndparent);
1423 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1424 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1425 ok(r != 0, "Expected not zero result\n");
1426 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1427 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1429 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1430 expect(TRUE, res);
1432 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1433 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1434 ok(r != 0, "Expected not zero result\n");
1435 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1436 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1438 /* 2. With backbuffer */
1439 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1440 LVS_EX_DOUBLEBUFFER);
1441 res = ListView_SetBkColor(hwnd, CLR_NONE);
1442 expect(TRUE, res);
1444 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1445 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1446 ok(r != 0, "Expected not zero result\n");
1447 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1448 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1450 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1451 expect(TRUE, res);
1453 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1454 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1455 todo_wine ok(r != 0, "Expected not zero result\n");
1456 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1457 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1459 ReleaseDC(hwndparent, hdc);
1461 DestroyWindow(hwnd);
1464 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1466 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1468 if(msg == WM_NOTIFY) {
1469 NMHDR *nmhdr = (PVOID)lp;
1470 if(nmhdr->code == NM_CUSTOMDRAW) {
1471 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1472 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1473 switch(nmlvcd->nmcd.dwDrawStage) {
1474 case CDDS_PREPAINT:
1475 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1476 return CDRF_NOTIFYITEMDRAW;
1477 case CDDS_ITEMPREPAINT:
1478 nmlvcd->clrTextBk = CLR_DEFAULT;
1479 return CDRF_NOTIFYSUBITEMDRAW;
1480 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1481 clr = GetBkColor(nmlvcd->nmcd.hdc);
1482 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1483 return CDRF_NOTIFYPOSTPAINT;
1484 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1485 clr = GetBkColor(nmlvcd->nmcd.hdc);
1486 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1487 return CDRF_DODEFAULT;
1489 return CDRF_DODEFAULT;
1493 return DefWindowProcA(hwnd, msg, wp, lp);
1496 static void test_customdraw(void)
1498 HWND hwnd;
1499 WNDPROC oldwndproc;
1501 hwnd = create_listview_control(0);
1503 insert_column(hwnd, 0);
1504 insert_column(hwnd, 1);
1505 insert_item(hwnd, 0);
1507 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1508 (LONG_PTR)cd_wndproc);
1510 InvalidateRect(hwnd, NULL, TRUE);
1511 UpdateWindow(hwnd);
1513 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1515 DestroyWindow(hwnd);
1518 static void test_icon_spacing(void)
1520 /* LVM_SETICONSPACING */
1521 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1523 HWND hwnd;
1524 WORD w, h;
1525 DWORD r;
1527 hwnd = create_custom_listview_control(LVS_ICON);
1528 ok(hwnd != NULL, "failed to create a listview window\n");
1530 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
1531 expect(NFR_ANSI, r);
1533 /* reset the icon spacing to defaults */
1534 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1536 /* now we can request what the defaults are */
1537 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1538 w = LOWORD(r);
1539 h = HIWORD(r);
1541 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1543 trace("test icon spacing\n");
1545 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1546 ok(r == MAKELONG(w, h) ||
1547 broken(r == MAKELONG(w, w)), /* win98 */
1548 "Expected %d, got %d\n", MAKELONG(w, h), r);
1550 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1551 expect(MAKELONG(20,30), r);
1553 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1554 expect(MAKELONG(25,35), r);
1556 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1558 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1559 DestroyWindow(hwnd);
1562 static void test_color(void)
1564 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1566 HWND hwnd;
1567 DWORD r;
1568 int i;
1570 COLORREF color;
1571 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1573 hwnd = create_listview_control(0);
1574 ok(hwnd != NULL, "failed to create a listview window\n");
1576 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1578 trace("test color seq\n");
1579 for (i = 0; i < 4; i++)
1581 color = colors[i];
1583 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1584 expect(TRUE, r);
1585 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1586 expect(color, r);
1588 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1589 expect (TRUE, r);
1590 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1591 expect(color, r);
1593 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1594 expect(TRUE, r);
1595 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1596 expect(color, r);
1599 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1601 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1602 DestroyWindow(hwnd);
1605 static void test_item_count(void)
1607 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1609 HWND hwnd;
1610 DWORD r;
1611 HDC hdc;
1612 HFONT hOldFont;
1613 TEXTMETRICA tm;
1614 RECT rect;
1615 INT height;
1617 LVITEM item0;
1618 LVITEM item1;
1619 LVITEM item2;
1620 static CHAR item0text[] = "item0";
1621 static CHAR item1text[] = "item1";
1622 static CHAR item2text[] = "item2";
1624 hwnd = create_listview_control(0);
1625 ok(hwnd != NULL, "failed to create a listview window\n");
1627 /* resize in dpiaware manner to fit all 3 items added */
1628 hdc = GetDC(0);
1629 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1630 GetTextMetricsA(hdc, &tm);
1631 /* 2 extra pixels for bounds and header border */
1632 height = tm.tmHeight + 2;
1633 SelectObject(hdc, hOldFont);
1634 ReleaseDC(0, hdc);
1636 GetWindowRect(hwnd, &rect);
1637 /* 3 items + 1 header + 1 to be sure */
1638 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1640 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1642 trace("test item count\n");
1644 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1645 expect(0, r);
1647 /* [item0] */
1648 item0.mask = LVIF_TEXT;
1649 item0.iItem = 0;
1650 item0.iSubItem = 0;
1651 item0.pszText = item0text;
1652 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1653 expect(0, r);
1655 /* [item0, item1] */
1656 item1.mask = LVIF_TEXT;
1657 item1.iItem = 1;
1658 item1.iSubItem = 0;
1659 item1.pszText = item1text;
1660 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1661 expect(1, r);
1663 /* [item0, item1, item2] */
1664 item2.mask = LVIF_TEXT;
1665 item2.iItem = 2;
1666 item2.iSubItem = 0;
1667 item2.pszText = item2text;
1668 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1669 expect(2, r);
1671 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1672 expect(3, r);
1674 /* [item0, item1] */
1675 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1676 expect(TRUE, r);
1678 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1679 expect(2, r);
1681 /* [] */
1682 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1683 expect(TRUE, r);
1685 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1686 expect(0, r);
1688 /* [item0] */
1689 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1690 expect(0, r);
1692 /* [item0, item1] */
1693 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1694 expect(1, r);
1696 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1697 expect(2, r);
1699 /* [item0, item1, item2] */
1700 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1701 expect(2, r);
1703 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1704 expect(3, r);
1706 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1708 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1709 DestroyWindow(hwnd);
1712 static void test_item_position(void)
1714 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1716 HWND hwnd;
1717 DWORD r;
1718 POINT position;
1720 LVITEM item0;
1721 LVITEM item1;
1722 LVITEM item2;
1723 static CHAR item0text[] = "item0";
1724 static CHAR item1text[] = "item1";
1725 static CHAR item2text[] = "item2";
1727 hwnd = create_custom_listview_control(LVS_ICON);
1728 ok(hwnd != NULL, "failed to create a listview window\n");
1730 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1732 trace("test item position\n");
1734 /* [item0] */
1735 item0.mask = LVIF_TEXT;
1736 item0.iItem = 0;
1737 item0.iSubItem = 0;
1738 item0.pszText = item0text;
1739 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1740 expect(0, r);
1742 /* [item0, item1] */
1743 item1.mask = LVIF_TEXT;
1744 item1.iItem = 1;
1745 item1.iSubItem = 0;
1746 item1.pszText = item1text;
1747 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1748 expect(1, r);
1750 /* [item0, item1, item2] */
1751 item2.mask = LVIF_TEXT;
1752 item2.iItem = 2;
1753 item2.iSubItem = 0;
1754 item2.pszText = item2text;
1755 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1756 expect(2, r);
1758 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1759 expect(TRUE, r);
1760 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1761 expect(TRUE, r);
1762 expect2(10, 5, position.x, position.y);
1764 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1765 expect(TRUE, r);
1766 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1767 expect(TRUE, r);
1768 expect2(0, 0, position.x, position.y);
1770 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1771 expect(TRUE, r);
1772 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1773 expect(TRUE, r);
1774 expect2(20, 20, position.x, position.y);
1776 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1778 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1779 DestroyWindow(hwnd);
1782 static void test_getorigin(void)
1784 /* LVM_GETORIGIN */
1786 HWND hwnd;
1787 DWORD r;
1788 POINT position;
1790 position.x = position.y = 0;
1792 hwnd = create_custom_listview_control(LVS_ICON);
1793 ok(hwnd != NULL, "failed to create a listview window\n");
1794 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1795 trace("test get origin results\n");
1796 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1797 expect(TRUE, r);
1798 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1799 DestroyWindow(hwnd);
1801 hwnd = create_custom_listview_control(LVS_SMALLICON);
1802 ok(hwnd != NULL, "failed to create a listview window\n");
1803 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1804 trace("test get origin results\n");
1805 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1806 expect(TRUE, r);
1807 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1808 DestroyWindow(hwnd);
1810 hwnd = create_custom_listview_control(LVS_LIST);
1811 ok(hwnd != NULL, "failed to create a listview window\n");
1812 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1813 trace("test get origin results\n");
1814 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1815 expect(FALSE, r);
1816 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1817 DestroyWindow(hwnd);
1819 hwnd = create_custom_listview_control(LVS_REPORT);
1820 ok(hwnd != NULL, "failed to create a listview window\n");
1821 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1822 trace("test get origin results\n");
1823 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1824 expect(FALSE, r);
1825 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1826 DestroyWindow(hwnd);
1830 static void test_multiselect(void)
1832 typedef struct t_select_task
1834 const char *descr;
1835 int initPos;
1836 int loopVK;
1837 int count;
1838 int result;
1839 } select_task;
1841 HWND hwnd;
1842 DWORD r;
1843 int i,j,item_count,selected_count;
1844 static const int items=5;
1845 BYTE kstate[256];
1846 select_task task;
1847 LONG_PTR style;
1848 LVITEMA item;
1850 static struct t_select_task task_list[] = {
1851 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1852 { "using VK_UP", -1, VK_UP, -1, -1 },
1853 { "using VK_END", 0, VK_END, 1, -1 },
1854 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1858 hwnd = create_listview_control(0);
1860 for (i=0;i<items;i++) {
1861 insert_item(hwnd, 0);
1864 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1866 expect(items,item_count);
1868 for (i=0;i<4;i++) {
1869 task = task_list[i];
1871 /* deselect all items */
1872 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1873 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1875 /* set initial position */
1876 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1877 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1879 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1881 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1883 /* Set SHIFT key pressed */
1884 GetKeyboardState(kstate);
1885 kstate[VK_SHIFT]=0x80;
1886 SetKeyboardState(kstate);
1888 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1889 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1890 expect(0,r);
1891 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1892 expect(0,r);
1895 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1897 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);
1899 /* Set SHIFT key released */
1900 GetKeyboardState(kstate);
1901 kstate[VK_SHIFT]=0x00;
1902 SetKeyboardState(kstate);
1904 DestroyWindow(hwnd);
1906 /* make multiple selection, then switch to LVS_SINGLESEL */
1907 hwnd = create_listview_control(0);
1908 for (i=0;i<items;i++) {
1909 insert_item(hwnd, 0);
1911 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1912 expect(items,item_count);
1913 /* deselect all items */
1914 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1915 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1916 for (i=0;i<3;i++) {
1917 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
1920 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1921 expect(3, r);
1922 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1923 todo_wine
1924 expect(-1, r);
1926 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1927 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
1928 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
1929 /* check that style is accepted */
1930 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1931 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
1933 for (i=0;i<3;i++) {
1934 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
1935 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
1937 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1938 expect(3, r);
1939 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1940 expect(3, r);
1942 /* select one more */
1943 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
1945 for (i=0;i<3;i++) {
1946 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
1947 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
1949 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
1950 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
1952 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1953 expect(1, r);
1954 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1955 todo_wine
1956 expect(-1, r);
1958 /* try to select all on LVS_SINGLESEL */
1959 memset(&item, 0, sizeof(item));
1960 item.stateMask = LVIS_SELECTED;
1961 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1962 expect(TRUE, r);
1963 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1965 item.stateMask = LVIS_SELECTED;
1966 item.state = LVIS_SELECTED;
1967 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1968 expect(FALSE, r);
1970 r = ListView_GetSelectedCount(hwnd);
1971 expect(0, r);
1972 r = ListView_GetSelectionMark(hwnd);
1973 expect(-1, r);
1975 /* try to deselect all on LVS_SINGLESEL */
1976 item.stateMask = LVIS_SELECTED;
1977 item.state = LVIS_SELECTED;
1978 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
1979 expect(TRUE, r);
1981 item.stateMask = LVIS_SELECTED;
1982 item.state = 0;
1983 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1984 expect(TRUE, r);
1985 r = ListView_GetSelectedCount(hwnd);
1986 expect(0, r);
1988 DestroyWindow(hwnd);
1991 static void test_subitem_rect(void)
1993 HWND hwnd;
1994 DWORD r;
1995 LVCOLUMN col;
1996 RECT rect;
1998 /* test LVM_GETSUBITEMRECT for header */
1999 hwnd = create_listview_control(0);
2000 ok(hwnd != NULL, "failed to create a listview window\n");
2001 /* add some columns */
2002 memset(&col, 0, sizeof(LVCOLUMN));
2003 col.mask = LVCF_WIDTH;
2004 col.cx = 100;
2005 r = -1;
2006 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2007 expect(0, r);
2008 col.cx = 150;
2009 r = -1;
2010 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2011 expect(1, r);
2012 col.cx = 200;
2013 r = -1;
2014 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2015 expect(2, r);
2016 /* item = -1 means header, subitem index is 1 based */
2017 rect.left = LVIR_BOUNDS;
2018 rect.top = 0;
2019 rect.right = rect.bottom = 0;
2020 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2021 expect(0, r);
2023 rect.left = LVIR_BOUNDS;
2024 rect.top = 1;
2025 rect.right = rect.bottom = 0;
2026 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2028 ok(r != 0, "Expected not-null LRESULT\n");
2029 expect(100, rect.left);
2030 expect(250, rect.right);
2031 todo_wine
2032 expect(3, rect.top);
2034 rect.left = LVIR_BOUNDS;
2035 rect.top = 2;
2036 rect.right = rect.bottom = 0;
2037 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2039 ok(r != 0, "Expected not-null LRESULT\n");
2040 expect(250, rect.left);
2041 expect(450, rect.right);
2042 todo_wine
2043 expect(3, rect.top);
2045 /* item LVS_REPORT padding isn't applied to subitems */
2046 insert_item(hwnd, 0);
2048 rect.left = LVIR_BOUNDS;
2049 rect.top = 1;
2050 rect.right = rect.bottom = 0;
2051 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2052 ok(r != 0, "Expected not-null LRESULT\n");
2053 expect(100, rect.left);
2054 expect(250, rect.right);
2056 rect.left = LVIR_ICON;
2057 rect.top = 1;
2058 rect.right = rect.bottom = 0;
2059 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2060 ok(r != 0, "Expected not-null LRESULT\n");
2061 /* no icon attached - zero width rectangle, with no left padding */
2062 expect(100, rect.left);
2063 expect(100, rect.right);
2065 rect.left = LVIR_LABEL;
2066 rect.top = 1;
2067 rect.right = rect.bottom = 0;
2068 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2069 ok(r != 0, "Expected not-null LRESULT\n");
2070 /* same as full LVIR_BOUNDS */
2071 expect(100, rect.left);
2072 expect(250, rect.right);
2074 DestroyWindow(hwnd);
2076 /* try it for non LVS_REPORT style */
2077 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2078 GetModuleHandle(NULL), 0);
2079 rect.left = LVIR_BOUNDS;
2080 rect.top = 1;
2081 rect.right = rect.bottom = -10;
2082 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2083 ok(r == 0, "Expected not-null LRESULT\n");
2084 /* rect is unchanged */
2085 expect(0, rect.left);
2086 expect(-10, rect.right);
2087 expect(1, rect.top);
2088 expect(-10, rect.bottom);
2089 DestroyWindow(hwnd);
2092 /* comparison callback for test_sorting */
2093 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2095 if (first == second) return 0;
2096 return (first > second ? 1 : -1);
2099 static void test_sorting(void)
2101 HWND hwnd;
2102 LVITEMA item = {0};
2103 DWORD r;
2104 LONG_PTR style;
2105 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2106 CHAR buff[10];
2108 hwnd = create_listview_control(0);
2109 ok(hwnd != NULL, "failed to create a listview window\n");
2111 /* insert some items */
2112 item.mask = LVIF_PARAM | LVIF_STATE;
2113 item.state = LVIS_SELECTED;
2114 item.iItem = 0;
2115 item.iSubItem = 0;
2116 item.lParam = 3;
2117 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2118 expect(0, r);
2120 item.mask = LVIF_PARAM;
2121 item.iItem = 1;
2122 item.iSubItem = 0;
2123 item.lParam = 2;
2124 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2125 expect(1, r);
2127 item.mask = LVIF_STATE | LVIF_PARAM;
2128 item.state = LVIS_SELECTED;
2129 item.iItem = 2;
2130 item.iSubItem = 0;
2131 item.lParam = 4;
2132 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2133 expect(2, r);
2135 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2136 expect(-1, r);
2138 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2139 expect(2, r);
2141 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2142 expect(TRUE, r);
2144 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2145 expect(2, r);
2146 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2147 expect(-1, r);
2148 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2149 expect(0, r);
2150 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2151 expect(LVIS_SELECTED, r);
2152 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2153 expect(LVIS_SELECTED, r);
2155 DestroyWindow(hwnd);
2157 /* switch to LVS_SORTASCENDING when some items added */
2158 hwnd = create_listview_control(0);
2159 ok(hwnd != NULL, "failed to create a listview window\n");
2161 item.mask = LVIF_TEXT;
2162 item.iItem = 0;
2163 item.iSubItem = 0;
2164 item.pszText = names[1];
2165 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2166 expect(0, r);
2168 item.mask = LVIF_TEXT;
2169 item.iItem = 1;
2170 item.iSubItem = 0;
2171 item.pszText = names[2];
2172 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2173 expect(1, r);
2175 item.mask = LVIF_TEXT;
2176 item.iItem = 2;
2177 item.iSubItem = 0;
2178 item.pszText = names[0];
2179 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2180 expect(2, r);
2182 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2183 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2184 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2185 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2187 /* no sorting performed when switched to LVS_SORTASCENDING */
2188 item.mask = LVIF_TEXT;
2189 item.iItem = 0;
2190 item.pszText = buff;
2191 item.cchTextMax = sizeof(buff);
2192 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2193 expect(TRUE, r);
2194 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2196 item.iItem = 1;
2197 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2198 expect(TRUE, r);
2199 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2201 item.iItem = 2;
2202 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2203 expect(TRUE, r);
2204 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2206 /* adding new item doesn't resort list */
2207 item.mask = LVIF_TEXT;
2208 item.iItem = 3;
2209 item.iSubItem = 0;
2210 item.pszText = names[3];
2211 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2212 expect(3, r);
2214 item.mask = LVIF_TEXT;
2215 item.iItem = 0;
2216 item.pszText = buff;
2217 item.cchTextMax = sizeof(buff);
2218 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2219 expect(TRUE, r);
2220 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2222 item.iItem = 1;
2223 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2224 expect(TRUE, r);
2225 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2227 item.iItem = 2;
2228 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2229 expect(TRUE, r);
2230 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2232 item.iItem = 3;
2233 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2234 expect(TRUE, r);
2235 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2237 /* corner case - item should be placed at first position */
2238 item.mask = LVIF_TEXT;
2239 item.iItem = 4;
2240 item.iSubItem = 0;
2241 item.pszText = names[4];
2242 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2243 expect(0, r);
2245 item.iItem = 0;
2246 item.pszText = buff;
2247 item.cchTextMax = sizeof(buff);
2248 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2249 expect(TRUE, r);
2250 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2252 item.iItem = 1;
2253 item.pszText = buff;
2254 item.cchTextMax = sizeof(buff);
2255 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2256 expect(TRUE, r);
2257 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2259 item.iItem = 2;
2260 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2261 expect(TRUE, r);
2262 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2264 item.iItem = 3;
2265 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2266 expect(TRUE, r);
2267 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2269 item.iItem = 4;
2270 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2271 expect(TRUE, r);
2272 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2274 DestroyWindow(hwnd);
2277 static void test_ownerdata(void)
2279 HWND hwnd;
2280 LONG_PTR style, ret;
2281 DWORD res;
2282 LVITEMA item;
2284 /* it isn't possible to set LVS_OWNERDATA after creation */
2285 if (g_is_below_5)
2287 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2289 else
2291 hwnd = create_listview_control(0);
2292 ok(hwnd != NULL, "failed to create a listview window\n");
2293 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2294 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2296 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2298 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2299 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2300 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2301 "try to switch to LVS_OWNERDATA seq", FALSE);
2303 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2304 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2305 DestroyWindow(hwnd);
2308 /* try to set LVS_OWNERDATA after creation just having it */
2309 hwnd = create_listview_control(LVS_OWNERDATA);
2310 ok(hwnd != NULL, "failed to create a listview window\n");
2311 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2312 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2314 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2316 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2317 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2318 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2319 "try to switch to LVS_OWNERDATA seq", FALSE);
2320 DestroyWindow(hwnd);
2322 /* try to remove LVS_OWNERDATA after creation just having it */
2323 if (g_is_below_5)
2325 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2327 else
2329 hwnd = create_listview_control(LVS_OWNERDATA);
2330 ok(hwnd != NULL, "failed to create a listview window\n");
2331 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2332 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2334 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2336 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2337 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2338 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2339 "try to switch to LVS_OWNERDATA seq", FALSE);
2340 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2341 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2342 DestroyWindow(hwnd);
2345 /* try select an item */
2346 hwnd = create_listview_control(LVS_OWNERDATA);
2347 ok(hwnd != NULL, "failed to create a listview window\n");
2348 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2349 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2350 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2351 expect(0, res);
2352 memset(&item, 0, sizeof(item));
2353 item.stateMask = LVIS_SELECTED;
2354 item.state = LVIS_SELECTED;
2355 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2356 expect(TRUE, res);
2357 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2358 expect(1, res);
2359 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2360 expect(1, res);
2361 DestroyWindow(hwnd);
2363 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2364 hwnd = create_listview_control(LVS_OWNERDATA);
2365 ok(hwnd != NULL, "failed to create a listview window\n");
2366 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2367 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2368 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2369 expect(1, res);
2370 memset(&item, 0, sizeof(item));
2371 item.mask = LVIF_STATE;
2372 item.iItem = 0;
2373 item.stateMask = LVIS_SELECTED;
2374 item.state = LVIS_SELECTED;
2375 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2376 expect(FALSE, res);
2377 DestroyWindow(hwnd);
2379 /* check notifications after focused/selected changed */
2380 hwnd = create_listview_control(LVS_OWNERDATA);
2381 ok(hwnd != NULL, "failed to create a listview window\n");
2382 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2383 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2385 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2387 memset(&item, 0, sizeof(item));
2388 item.stateMask = LVIS_SELECTED;
2389 item.state = LVIS_SELECTED;
2390 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2391 expect(TRUE, res);
2393 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2394 "ownerdata select notification", TRUE);
2396 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2398 memset(&item, 0, sizeof(item));
2399 item.stateMask = LVIS_FOCUSED;
2400 item.state = LVIS_FOCUSED;
2401 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2402 expect(TRUE, res);
2404 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2405 "ownerdata focus notification", TRUE);
2406 DestroyWindow(hwnd);
2408 /* check notifications on LVM_GETITEM */
2409 /* zero callback mask */
2410 hwnd = create_listview_control(LVS_OWNERDATA);
2411 ok(hwnd != NULL, "failed to create a listview window\n");
2412 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2413 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2415 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2417 memset(&item, 0, sizeof(item));
2418 item.stateMask = LVIS_SELECTED;
2419 item.mask = LVIF_STATE;
2420 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2421 expect(TRUE, res);
2423 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2424 "ownerdata getitem selected state 1", FALSE);
2426 /* non zero callback mask but not we asking for */
2427 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2428 expect(TRUE, res);
2430 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2432 memset(&item, 0, sizeof(item));
2433 item.stateMask = LVIS_SELECTED;
2434 item.mask = LVIF_STATE;
2435 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2436 expect(TRUE, res);
2438 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2439 "ownerdata getitem selected state 2", FALSE);
2441 /* LVIS_OVERLAYMASK callback mask, asking for index */
2442 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2444 memset(&item, 0, sizeof(item));
2445 item.stateMask = LVIS_OVERLAYMASK;
2446 item.mask = LVIF_STATE;
2447 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2448 expect(TRUE, res);
2450 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2451 "ownerdata getitem selected state 2", FALSE);
2453 DestroyWindow(hwnd);
2455 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2456 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING);
2457 ok(hwnd != NULL, "failed to create a listview window\n");
2458 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2459 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2460 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2461 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2462 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2463 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2464 DestroyWindow(hwnd);
2465 /* apparently it's allowed to switch these style on after creation */
2466 hwnd = create_listview_control(LVS_OWNERDATA);
2467 ok(hwnd != NULL, "failed to create a listview window\n");
2468 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2469 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2470 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2471 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2472 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2473 DestroyWindow(hwnd);
2475 hwnd = create_listview_control(LVS_OWNERDATA);
2476 ok(hwnd != NULL, "failed to create a listview window\n");
2477 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2478 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2479 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2480 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2481 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2482 DestroyWindow(hwnd);
2485 static void test_norecompute(void)
2487 static CHAR testA[] = "test";
2488 CHAR buff[10];
2489 LVITEMA item;
2490 HWND hwnd;
2491 DWORD res;
2493 /* self containing control */
2494 hwnd = create_listview_control(0);
2495 ok(hwnd != NULL, "failed to create a listview window\n");
2496 memset(&item, 0, sizeof(item));
2497 item.mask = LVIF_TEXT | LVIF_STATE;
2498 item.iItem = 0;
2499 item.stateMask = LVIS_SELECTED;
2500 item.state = LVIS_SELECTED;
2501 item.pszText = testA;
2502 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2503 expect(0, res);
2504 /* retrieve with LVIF_NORECOMPUTE */
2505 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2506 item.iItem = 0;
2507 item.pszText = buff;
2508 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2509 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2510 expect(TRUE, res);
2511 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2513 item.mask = LVIF_TEXT;
2514 item.iItem = 1;
2515 item.pszText = LPSTR_TEXTCALLBACK;
2516 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2517 expect(1, res);
2519 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2520 item.iItem = 1;
2521 item.pszText = buff;
2522 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2524 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2525 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2526 expect(TRUE, res);
2527 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2528 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2529 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2531 DestroyWindow(hwnd);
2533 /* LVS_OWNERDATA */
2534 hwnd = create_listview_control(LVS_OWNERDATA);
2535 ok(hwnd != NULL, "failed to create a listview window\n");
2537 item.mask = LVIF_STATE;
2538 item.stateMask = LVIS_SELECTED;
2539 item.state = LVIS_SELECTED;
2540 item.iItem = 0;
2541 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2542 expect(0, res);
2544 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2545 item.iItem = 0;
2546 item.pszText = buff;
2547 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2548 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2549 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2550 expect(TRUE, res);
2551 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2552 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2553 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2555 DestroyWindow(hwnd);
2558 static void test_nosortheader(void)
2560 HWND hwnd, header;
2561 LONG_PTR style;
2563 hwnd = create_listview_control(0);
2564 ok(hwnd != NULL, "failed to create a listview window\n");
2566 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2567 ok(IsWindow(header), "header expected\n");
2569 style = GetWindowLongPtr(header, GWL_STYLE);
2570 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2572 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2573 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2574 /* HDS_BUTTONS retained */
2575 style = GetWindowLongPtr(header, GWL_STYLE);
2576 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2578 DestroyWindow(hwnd);
2580 /* create with LVS_NOSORTHEADER */
2581 hwnd = create_listview_control(LVS_NOSORTHEADER);
2582 ok(hwnd != NULL, "failed to create a listview window\n");
2584 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2585 ok(IsWindow(header), "header expected\n");
2587 style = GetWindowLongPtr(header, GWL_STYLE);
2588 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2590 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2591 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2592 /* not changed here */
2593 style = GetWindowLongPtr(header, GWL_STYLE);
2594 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2596 DestroyWindow(hwnd);
2599 static void test_setredraw(void)
2601 HWND hwnd;
2602 DWORD_PTR style;
2603 DWORD ret;
2605 hwnd = create_listview_control(0);
2606 ok(hwnd != NULL, "failed to create a listview window\n");
2608 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2609 ListView seems to handle it internally without DefWinProc */
2611 /* default value first */
2612 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2613 expect(0, ret);
2614 /* disable */
2615 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2616 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2617 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2618 expect(0, ret);
2619 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2620 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2622 DestroyWindow(hwnd);
2625 static void test_hittest(void)
2627 HWND hwnd;
2628 DWORD r;
2629 RECT bounds;
2630 LVITEMA item;
2631 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2632 POINT pos;
2633 INT x, y;
2634 HIMAGELIST himl, himl2;
2635 HBITMAP hbmp;
2637 hwnd = create_listview_control(0);
2638 ok(hwnd != NULL, "failed to create a listview window\n");
2640 /* LVS_REPORT with a single subitem (2 columns) */
2641 insert_column(hwnd, 0);
2642 insert_column(hwnd, 1);
2643 insert_item(hwnd, 0);
2645 item.iSubItem = 0;
2646 /* the only purpose of that line is to be as long as a half item rect */
2647 item.pszText = text;
2648 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2649 expect(TRUE, r);
2651 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2652 expect(TRUE, r);
2653 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
2654 expect(TRUE, r);
2656 memset(&bounds, 0, sizeof(bounds));
2657 bounds.left = LVIR_BOUNDS;
2658 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
2659 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
2660 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
2661 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
2662 expect(TRUE, r);
2664 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2665 x = pos.x + 50; /* column half width */
2666 y = pos.y + (bounds.bottom - bounds.top) / 2;
2667 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, FALSE, FALSE, __LINE__);
2668 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2669 x = pos.x + 150; /* outside column */
2670 y = pos.y + (bounds.bottom - bounds.top) / 2;
2671 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2672 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, TRUE, TRUE, TRUE, __LINE__);
2673 /* parent client area is 100x100 by default */
2674 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
2675 x = pos.x + 150; /* outside column */
2676 y = pos.y + (bounds.bottom - bounds.top) / 2;
2677 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, FALSE, FALSE, __LINE__);
2678 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2679 /* the same with LVS_EX_FULLROWSELECT */
2680 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
2681 x = pos.x + 150; /* outside column */
2682 y = pos.y + (bounds.bottom - bounds.top) / 2;
2683 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, FALSE, FALSE, __LINE__);
2684 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2685 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
2686 x = pos.x + 150; /* outside column */
2687 y = pos.y + (bounds.bottom - bounds.top) / 2;
2688 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2689 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, TRUE, TRUE, TRUE, __LINE__);
2690 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2691 himl = ImageList_Create(16, 16, 0, 4, 4);
2692 ok(himl != NULL, "failed to create imagelist\n");
2693 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2694 ok(hbmp != NULL, "failed to create bitmap\n");
2695 r = ImageList_Add(himl, hbmp, 0);
2696 ok(r == 0, "should be zero\n");
2697 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2698 ok(hbmp != NULL, "failed to create bitmap\n");
2699 r = ImageList_Add(himl, hbmp, 0);
2700 ok(r == 1, "should be one\n");
2702 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2703 ok(r == 0, "should return zero\n");
2705 item.mask = LVIF_IMAGE;
2706 item.iImage = 0;
2707 item.iItem = 0;
2708 item.iSubItem = 0;
2709 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2710 expect(TRUE, r);
2711 /* on state icon */
2712 x = pos.x + 8;
2713 y = pos.y + (bounds.bottom - bounds.top) / 2;
2714 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2715 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2717 /* state icons indices are 1 based, check with valid index */
2718 item.mask = LVIF_STATE;
2719 item.state = INDEXTOSTATEIMAGEMASK(1);
2720 item.stateMask = LVIS_STATEIMAGEMASK;
2721 item.iItem = 0;
2722 item.iSubItem = 0;
2723 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2724 expect(TRUE, r);
2725 /* on state icon */
2726 x = pos.x + 8;
2727 y = pos.y + (bounds.bottom - bounds.top) / 2;
2728 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2729 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2731 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
2732 ok(himl2 == himl, "should return handle\n");
2734 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
2735 ok(r == 0, "should return zero\n");
2736 /* on item icon */
2737 x = pos.x + 8;
2738 y = pos.y + (bounds.bottom - bounds.top) / 2;
2739 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, FALSE, FALSE, __LINE__);
2740 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
2742 DestroyWindow(hwnd);
2745 static void test_getviewrect(void)
2747 HWND hwnd;
2748 DWORD r;
2749 RECT rect;
2750 LVITEMA item;
2752 hwnd = create_listview_control(0);
2753 ok(hwnd != NULL, "failed to create a listview window\n");
2755 /* empty */
2756 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2757 expect(TRUE, r);
2759 insert_column(hwnd, 0);
2760 insert_column(hwnd, 1);
2762 memset(&item, 0, sizeof(item));
2763 item.iItem = 0;
2764 item.iSubItem = 0;
2765 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2767 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2768 expect(TRUE, r);
2769 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
2770 expect(TRUE, r);
2772 rect.left = rect.right = rect.top = rect.bottom = -1;
2773 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2774 expect(TRUE, r);
2775 /* left is set to (2e31-1) - XP SP2 */
2776 expect(0, rect.right);
2777 expect(0, rect.top);
2778 expect(0, rect.bottom);
2780 /* switch to LVS_ICON */
2781 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
2783 rect.left = rect.right = rect.top = rect.bottom = -1;
2784 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2785 expect(TRUE, r);
2786 expect(0, rect.left);
2787 expect(0, rect.top);
2788 /* precise value differs for 2k, XP and Vista */
2789 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
2790 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
2792 DestroyWindow(hwnd);
2795 static void test_getitemposition(void)
2797 HWND hwnd, header;
2798 DWORD r;
2799 POINT pt;
2800 RECT rect;
2802 hwnd = create_listview_control(0);
2803 ok(hwnd != NULL, "failed to create a listview window\n");
2804 header = subclass_header(hwnd);
2806 /* LVS_REPORT, single item, no columns added */
2807 insert_item(hwnd, 0);
2809 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2811 pt.x = pt.y = -1;
2812 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2813 expect(TRUE, r);
2814 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
2816 /* LVS_REPORT, single item, single column */
2817 insert_column(hwnd, 0);
2819 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2821 pt.x = pt.y = -1;
2822 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2823 expect(TRUE, r);
2824 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
2826 memset(&rect, 0, sizeof(rect));
2827 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
2828 /* some padding? */
2829 expect(2, pt.x);
2830 /* offset by header height */
2831 expect(rect.bottom - rect.top, pt.y);
2833 DestroyWindow(hwnd);
2836 static void test_columnscreation(void)
2838 HWND hwnd, header;
2839 DWORD r;
2841 hwnd = create_listview_control(0);
2842 ok(hwnd != NULL, "failed to create a listview window\n");
2844 insert_item(hwnd, 0);
2846 /* headers columns aren't created automatically */
2847 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
2848 ok(IsWindow(header), "Expected header handle\n");
2849 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
2850 expect(0, r);
2852 DestroyWindow(hwnd);
2855 static void test_getitemrect(void)
2857 HWND hwnd;
2858 HIMAGELIST himl;
2859 HBITMAP hbm;
2860 RECT rect;
2861 DWORD r;
2862 LVITEMA item;
2863 LVCOLUMNA col;
2864 INT order[2];
2865 POINT pt;
2867 hwnd = create_listview_control(0);
2868 ok(hwnd != NULL, "failed to create a listview window\n");
2870 /* empty item */
2871 memset(&item, 0, sizeof(item));
2872 item.iItem = 0;
2873 item.iSubItem = 0;
2874 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2875 expect(0, r);
2877 rect.left = LVIR_BOUNDS;
2878 rect.right = rect.top = rect.bottom = -1;
2879 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2880 expect(TRUE, r);
2882 /* zero width rectangle with no padding */
2883 expect(0, rect.left);
2884 expect(0, rect.right);
2886 insert_column(hwnd, 0);
2887 insert_column(hwnd, 1);
2889 col.mask = LVCF_WIDTH;
2890 col.cx = 50;
2891 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
2892 expect(TRUE, r);
2894 col.mask = LVCF_WIDTH;
2895 col.cx = 100;
2896 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
2897 expect(TRUE, r);
2899 rect.left = LVIR_BOUNDS;
2900 rect.right = rect.top = rect.bottom = -1;
2901 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2902 expect(TRUE, r);
2904 /* still no left padding */
2905 expect(0, rect.left);
2906 expect(150, rect.right);
2908 rect.left = LVIR_SELECTBOUNDS;
2909 rect.right = rect.top = rect.bottom = -1;
2910 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2911 expect(TRUE, r);
2912 /* padding */
2913 expect(2, rect.left);
2915 rect.left = LVIR_LABEL;
2916 rect.right = rect.top = rect.bottom = -1;
2917 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2918 expect(TRUE, r);
2919 /* padding, column width */
2920 expect(2, rect.left);
2921 expect(50, rect.right);
2923 /* no icons attached */
2924 rect.left = LVIR_ICON;
2925 rect.right = rect.top = rect.bottom = -1;
2926 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2927 expect(TRUE, r);
2928 /* padding */
2929 expect(2, rect.left);
2930 expect(2, rect.right);
2932 /* change order */
2933 order[0] = 1; order[1] = 0;
2934 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
2935 expect(TRUE, r);
2936 pt.x = -1;
2937 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2938 expect(TRUE, r);
2939 /* 1 indexed column width + padding */
2940 todo_wine expect(102, pt.x);
2941 /* rect is at zero too */
2942 rect.left = LVIR_BOUNDS;
2943 rect.right = rect.top = rect.bottom = -1;
2944 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2945 expect(TRUE, r);
2946 expect(0, rect.left);
2947 /* just width sum */
2948 expect(150, rect.right);
2950 rect.left = LVIR_SELECTBOUNDS;
2951 rect.right = rect.top = rect.bottom = -1;
2952 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2953 expect(TRUE, r);
2954 /* column width + padding */
2955 todo_wine expect(102, rect.left);
2957 /* back to initial order */
2958 order[0] = 0; order[1] = 1;
2959 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
2960 expect(TRUE, r);
2962 /* state icons */
2963 himl = ImageList_Create(16, 16, 0, 2, 2);
2964 ok(himl != NULL, "failed to create imagelist\n");
2965 hbm = CreateBitmap(16, 16, 1, 1, NULL);
2966 ok(hbm != NULL, "failed to create bitmap\n");
2967 r = ImageList_Add(himl, hbm, 0);
2968 ok(r == 0, "should be zero\n");
2969 hbm = CreateBitmap(16, 16, 1, 1, NULL);
2970 ok(hbm != NULL, "failed to create bitmap\n");
2971 r = ImageList_Add(himl, hbm, 0);
2972 ok(r == 1, "should be one\n");
2974 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2975 ok(r == 0, "should return zero\n");
2977 item.mask = LVIF_STATE;
2978 item.state = INDEXTOSTATEIMAGEMASK(1);
2979 item.stateMask = LVIS_STATEIMAGEMASK;
2980 item.iItem = 0;
2981 item.iSubItem = 0;
2982 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2983 expect(TRUE, r);
2985 /* icon bounds */
2986 rect.left = LVIR_ICON;
2987 rect.right = rect.top = rect.bottom = -1;
2988 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2989 expect(TRUE, r);
2990 /* padding + stateicon width */
2991 expect(18, rect.left);
2992 expect(18, rect.right);
2993 /* label bounds */
2994 rect.left = LVIR_LABEL;
2995 rect.right = rect.top = rect.bottom = -1;
2996 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2997 expect(TRUE, r);
2998 /* padding + stateicon width -> column width */
2999 expect(18, rect.left);
3000 expect(50, rect.right);
3002 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
3003 ok(r != 0, "should return current list handle\n");
3005 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3006 ok(r == 0, "should return zero\n");
3008 item.mask = LVIF_STATE | LVIF_IMAGE;
3009 item.iImage = 1;
3010 item.state = 0;
3011 item.stateMask = ~0;
3012 item.iItem = 0;
3013 item.iSubItem = 0;
3014 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3015 expect(TRUE, r);
3017 /* icon bounds */
3018 rect.left = LVIR_ICON;
3019 rect.right = rect.top = rect.bottom = -1;
3020 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3021 expect(TRUE, r);
3022 /* padding, icon width */
3023 expect(2, rect.left);
3024 expect(18, rect.right);
3025 /* label bounds */
3026 rect.left = LVIR_LABEL;
3027 rect.right = rect.top = rect.bottom = -1;
3028 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3029 expect(TRUE, r);
3030 /* padding + icon width -> column width */
3031 expect(18, rect.left);
3032 expect(50, rect.right);
3034 /* select bounds */
3035 rect.left = LVIR_SELECTBOUNDS;
3036 rect.right = rect.top = rect.bottom = -1;
3037 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3038 expect(TRUE, r);
3039 /* padding, column width */
3040 expect(2, rect.left);
3041 todo_wine expect(50, rect.right);
3043 /* try with indentation */
3044 item.mask = LVIF_INDENT;
3045 item.iIndent = 1;
3046 item.iItem = 0;
3047 item.iSubItem = 0;
3048 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3049 expect(TRUE, r);
3051 /* bounds */
3052 rect.left = LVIR_BOUNDS;
3053 rect.right = rect.top = rect.bottom = -1;
3054 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3055 expect(TRUE, r);
3056 /* padding + 1 icon width, column width */
3057 expect(0, rect.left);
3058 expect(150, rect.right);
3060 /* select bounds */
3061 rect.left = LVIR_SELECTBOUNDS;
3062 rect.right = rect.top = rect.bottom = -1;
3063 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3064 expect(TRUE, r);
3065 /* padding + 1 icon width, column width */
3066 expect(2 + 16, rect.left);
3067 todo_wine expect(50, rect.right);
3069 /* label bounds */
3070 rect.left = LVIR_LABEL;
3071 rect.right = rect.top = rect.bottom = -1;
3072 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3073 expect(TRUE, r);
3074 /* padding + 2 icon widths, column width */
3075 expect(2 + 16*2, rect.left);
3076 expect(50, rect.right);
3078 /* icon bounds */
3079 rect.left = LVIR_ICON;
3080 rect.right = rect.top = rect.bottom = -1;
3081 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3082 expect(TRUE, r);
3083 /* padding + 1 icon width indentation, icon width */
3084 expect(2 + 16, rect.left);
3085 expect(34, rect.right);
3088 DestroyWindow(hwnd);
3091 static void test_editbox(void)
3093 HWND hwnd, hwndedit, hwndedit2;
3094 LVITEMA item;
3095 DWORD r;
3096 static CHAR testitemA[] = "testitem";
3097 static CHAR testitem1A[] = "testitem1";
3098 static CHAR buffer[10];
3100 hwnd = create_listview_control(LVS_EDITLABELS);
3101 ok(hwnd != NULL, "failed to create a listview window\n");
3103 insert_column(hwnd, 0);
3105 memset(&item, 0, sizeof(item));
3106 item.mask = LVIF_TEXT;
3107 item.pszText = testitemA;
3108 item.iItem = 0;
3109 item.iSubItem = 0;
3110 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3111 expect(0, r);
3113 /* setting focus is necessary */
3114 SetFocus(hwnd);
3115 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3116 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3118 /* modify initial string */
3119 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3120 expect(TRUE, r);
3121 /* return focus to listview */
3122 SetFocus(hwnd);
3124 memset(&item, 0, sizeof(item));
3125 item.mask = LVIF_TEXT;
3126 item.pszText = buffer;
3127 item.cchTextMax = 10;
3128 item.iItem = 0;
3129 item.iSubItem = 0;
3130 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3131 expect(TRUE, r);
3133 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3135 /* send LVM_EDITLABEL on already created edit */
3136 SetFocus(hwnd);
3137 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3138 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3139 /* focus will be set to edit */
3140 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3141 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3142 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3144 /* creating label disabled when control isn't focused */
3145 SetFocus(0);
3146 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3147 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3149 /* check EN_KILLFOCUS handling */
3150 memset(&item, 0, sizeof(item));
3151 item.pszText = testitemA;
3152 item.iItem = 0;
3153 item.iSubItem = 0;
3154 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3155 expect(TRUE, r);
3157 SetFocus(hwnd);
3158 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3159 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3160 /* modify edit and notify control that it lost focus */
3161 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3162 expect(TRUE, r);
3163 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3164 expect(0, r);
3165 memset(&item, 0, sizeof(item));
3166 item.pszText = buffer;
3167 item.cchTextMax = 10;
3168 item.iItem = 0;
3169 item.iSubItem = 0;
3170 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3171 expect(lstrlen(item.pszText), r);
3172 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3173 /* end edit without saving */
3174 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3175 expect(0, r);
3176 memset(&item, 0, sizeof(item));
3177 item.pszText = buffer;
3178 item.cchTextMax = 10;
3179 item.iItem = 0;
3180 item.iSubItem = 0;
3181 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3182 expect(lstrlen(item.pszText), r);
3183 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3185 /* LVM_EDITLABEL with -1 destroys current edit */
3186 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3187 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3188 /* no edit present */
3189 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3190 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3191 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3192 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3193 /* edit present */
3194 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3195 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3196 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3197 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3198 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3199 /* check another negative value */
3200 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3201 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3202 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3203 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3204 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3205 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3206 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3207 /* and value greater then max item index */
3208 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3209 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3210 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3211 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3212 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3213 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3214 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3215 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3217 /* messaging tests */
3218 SetFocus(hwnd);
3219 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3220 blockEdit = FALSE;
3221 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3222 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3223 /* testing only sizing messages */
3224 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3225 "edit box create - sizing", TRUE);
3227 DestroyWindow(hwnd);
3230 static void test_notifyformat(void)
3232 HWND hwnd, header;
3233 DWORD r;
3235 hwnd = create_listview_control(0);
3236 ok(hwnd != NULL, "failed to create a listview window\n");
3238 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3239 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3240 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3241 expect(0, r);
3242 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3243 /* set */
3244 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3245 expect(0, r);
3246 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3247 if (r == 1)
3249 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3250 expect(1, r);
3251 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3252 expect(0, r);
3254 else
3256 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3257 DestroyWindow(hwnd);
3258 return;
3261 DestroyWindow(hwnd);
3263 /* test failure in parent WM_NOTIFYFORMAT */
3264 notifyFormat = 0;
3265 hwnd = create_listview_control(0);
3266 ok(hwnd != NULL, "failed to create a listview window\n");
3267 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3268 ok(IsWindow(header), "expected header to be created\n");
3269 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3270 expect(0, r);
3271 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3272 expect(1, r);
3273 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3274 ok(r != 0, "Expected valid format\n");
3276 notifyFormat = NFR_UNICODE;
3277 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3278 expect(NFR_UNICODE, r);
3279 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3280 expect(1, r);
3281 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3282 expect(1, r);
3284 notifyFormat = NFR_ANSI;
3285 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3286 expect(NFR_ANSI, r);
3287 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3288 expect(0, r);
3289 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3290 expect(1, r);
3292 DestroyWindow(hwnd);
3294 /* try different unicode window combination and defaults */
3295 if (!GetModuleHandleW(NULL))
3297 win_skip("Additional notify format tests are incompatible with Win9x\n");
3298 return;
3301 hwndparentW = create_parent_window(TRUE);
3302 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3303 if (!IsWindow(hwndparentW)) return;
3305 notifyFormat = -1;
3306 hwnd = create_listview_controlW(0, hwndparentW);
3307 ok(hwnd != NULL, "failed to create a listview window\n");
3308 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3309 ok(IsWindow(header), "expected header to be created\n");
3310 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3311 expect(1, r);
3312 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3313 expect(1, r);
3314 DestroyWindow(hwnd);
3315 /* recieving error code defaulting to ansi */
3316 notifyFormat = 0;
3317 hwnd = create_listview_controlW(0, hwndparentW);
3318 ok(hwnd != NULL, "failed to create a listview window\n");
3319 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3320 ok(IsWindow(header), "expected header to be created\n");
3321 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3322 expect(0, r);
3323 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3324 expect(1, r);
3325 DestroyWindow(hwnd);
3326 /* recieving ansi code from unicode window, use it */
3327 notifyFormat = NFR_ANSI;
3328 hwnd = create_listview_controlW(0, hwndparentW);
3329 ok(hwnd != NULL, "failed to create a listview window\n");
3330 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3331 ok(IsWindow(header), "expected header to be created\n");
3332 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3333 expect(0, r);
3334 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3335 expect(1, r);
3336 DestroyWindow(hwnd);
3337 /* unicode listview with ansi parent window */
3338 notifyFormat = -1;
3339 hwnd = create_listview_controlW(0, hwndparent);
3340 ok(hwnd != NULL, "failed to create a listview window\n");
3341 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3342 ok(IsWindow(header), "expected header to be created\n");
3343 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3344 expect(0, r);
3345 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3346 expect(1, r);
3347 DestroyWindow(hwnd);
3348 /* unicode listview with ansi parent window, return error code */
3349 notifyFormat = 0;
3350 hwnd = create_listview_controlW(0, hwndparent);
3351 ok(hwnd != NULL, "failed to create a listview window\n");
3352 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3353 ok(IsWindow(header), "expected header to be created\n");
3354 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3355 expect(0, r);
3356 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3357 expect(1, r);
3358 DestroyWindow(hwnd);
3360 DestroyWindow(hwndparentW);
3363 static void test_indentation(void)
3365 HWND hwnd;
3366 LVITEMA item;
3367 DWORD r;
3369 hwnd = create_listview_control(0);
3370 ok(hwnd != NULL, "failed to create a listview window\n");
3372 memset(&item, 0, sizeof(item));
3373 item.mask = LVIF_INDENT;
3374 item.iItem = 0;
3375 item.iIndent = I_INDENTCALLBACK;
3376 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3377 expect(0, r);
3379 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3381 item.iItem = 0;
3382 item.mask = LVIF_INDENT;
3383 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3384 expect(TRUE, r);
3386 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3387 "get indent dispinfo", FALSE);
3389 DestroyWindow(hwnd);
3392 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
3394 return 0;
3397 static BOOL is_below_comctl_5(void)
3399 HWND hwnd;
3400 BOOL ret;
3402 hwnd = create_listview_control(0);
3403 ok(hwnd != NULL, "failed to create a listview window\n");
3404 insert_item(hwnd, 0);
3406 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
3408 DestroyWindow(hwnd);
3410 return !ret;
3413 static void unload_v6_module(ULONG_PTR cookie)
3415 HANDLE hKernel32;
3416 BOOL (WINAPI *pDeactivateActCtx)(DWORD, ULONG_PTR);
3418 hKernel32 = GetModuleHandleA("kernel32.dll");
3419 pDeactivateActCtx = (void*)GetProcAddress(hKernel32, "DeactivateActCtx");
3420 if (!pDeactivateActCtx)
3422 win_skip("Activation contexts unsupported\n");
3423 return;
3426 pDeactivateActCtx(0, cookie);
3428 DeleteFileA(manifest_name);
3431 static BOOL load_v6_module(ULONG_PTR *pcookie)
3433 HANDLE hKernel32;
3434 HANDLE (WINAPI *pCreateActCtxA)(ACTCTXA*);
3435 BOOL (WINAPI *pActivateActCtx)(HANDLE, ULONG_PTR*);
3437 ACTCTXA ctx;
3438 HANDLE hCtx;
3439 BOOL ret;
3440 HANDLE file;
3441 DWORD written;
3442 HWND hwnd;
3444 hKernel32 = GetModuleHandleA("kernel32.dll");
3445 pCreateActCtxA = (void*)GetProcAddress(hKernel32, "CreateActCtxA");
3446 pActivateActCtx = (void*)GetProcAddress(hKernel32, "ActivateActCtx");
3447 if (!(pCreateActCtxA && pActivateActCtx))
3449 win_skip("Activation contexts unsupported. No version 6 tests possible.\n");
3450 return FALSE;
3453 /* create manifest */
3454 file = CreateFileA( manifest_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
3455 if (file != INVALID_HANDLE_VALUE)
3457 ret = (WriteFile( file, manifest, sizeof(manifest)-1, &written, NULL ) &&
3458 written == sizeof(manifest)-1);
3459 CloseHandle( file );
3460 if (!ret)
3462 DeleteFileA( manifest_name );
3463 skip("Failed to fill manifest file. Skipping comctl32 V6 tests.\n");
3464 return FALSE;
3466 else
3467 trace("created %s\n", manifest_name);
3469 else
3471 skip("Failed to create manifest file. Skipping comctl32 V6 tests.\n");
3472 return FALSE;
3475 memset(&ctx, 0, sizeof(ctx));
3476 ctx.cbSize = sizeof(ctx);
3477 ctx.lpSource = manifest_name;
3479 hCtx = pCreateActCtxA(&ctx);
3480 ok(hCtx != 0, "Expected context handle\n");
3482 ret = pActivateActCtx(hCtx, pcookie);
3483 expect(TRUE, ret);
3485 if (!ret)
3487 win_skip("A problem during context activation occured.\n");
3488 DeleteFileA(manifest_name);
3490 else
3492 /* this is a XP SP3 failure workaround */
3493 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
3494 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
3495 0, 0, 100, 100,
3496 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
3497 if (!IsWindow(hwnd))
3499 win_skip("FIXME: failed to create ListView window.\n");
3500 unload_v6_module(*pcookie);
3501 return FALSE;
3503 else
3504 DestroyWindow(hwnd);
3507 return ret;
3510 static void test_get_set_view(void)
3512 HWND hwnd;
3513 DWORD ret;
3514 DWORD_PTR style;
3516 /* test style->view mapping */
3517 hwnd = create_listview_control(0);
3518 ok(hwnd != NULL, "failed to create a listview window\n");
3520 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3521 expect(LV_VIEW_DETAILS, ret);
3523 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3524 /* LVS_ICON == 0 */
3525 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
3526 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3527 expect(LV_VIEW_ICON, ret);
3529 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3530 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
3531 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3532 expect(LV_VIEW_SMALLICON, ret);
3534 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3535 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
3536 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3537 expect(LV_VIEW_LIST, ret);
3539 /* switching view doesn't touch window style */
3540 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
3541 expect(1, ret);
3542 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3543 ok(style & LVS_LIST, "Expected style to be preserved\n");
3544 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
3545 expect(1, ret);
3546 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3547 ok(style & LVS_LIST, "Expected style to be preserved\n");
3548 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
3549 expect(1, ret);
3550 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3551 ok(style & LVS_LIST, "Expected style to be preserved\n");
3553 DestroyWindow(hwnd);
3556 static void test_canceleditlabel(void)
3558 HWND hwnd, hwndedit;
3559 DWORD ret;
3560 CHAR buff[10];
3561 LVITEMA itema;
3562 static CHAR test[] = "test";
3563 static const CHAR test1[] = "test1";
3565 hwnd = create_listview_control(LVS_EDITLABELS);
3566 ok(hwnd != NULL, "failed to create a listview window\n");
3568 insert_item(hwnd, 0);
3570 /* try without edit created */
3571 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3572 expect(TRUE, ret);
3574 /* cancel without data change */
3575 SetFocus(hwnd);
3576 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3577 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3578 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3579 expect(TRUE, ret);
3580 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3582 /* cancel after data change */
3583 memset(&itema, 0, sizeof(itema));
3584 itema.pszText = test;
3585 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
3586 expect(TRUE, ret);
3587 SetFocus(hwnd);
3588 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3589 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3590 ret = SetWindowText(hwndedit, test1);
3591 ok(ret != 0, "Expected edit text to change\n");
3592 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3593 expect(TRUE, ret);
3594 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3595 memset(&itema, 0, sizeof(itema));
3596 itema.pszText = buff;
3597 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
3598 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
3599 expect(5, ret);
3600 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
3602 DestroyWindow(hwnd);
3605 static void test_mapidindex(void)
3607 HWND hwnd;
3608 DWORD ret;
3610 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3611 hwnd = create_listview_control(LVS_OWNERDATA);
3612 ok(hwnd != NULL, "failed to create a listview window\n");
3613 insert_item(hwnd, 0);
3614 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3615 expect(-1, ret);
3616 DestroyWindow(hwnd);
3618 hwnd = create_listview_control(0);
3619 ok(hwnd != NULL, "failed to create a listview window\n");
3621 /* LVM_MAPINDEXTOID with invalid index */
3622 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3623 expect(-1, ret);
3625 insert_item(hwnd, 0);
3626 insert_item(hwnd, 1);
3628 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
3629 expect(-1, ret);
3630 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
3631 expect(-1, ret);
3633 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3634 expect(0, ret);
3635 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3636 expect(1, ret);
3637 /* remove 0 indexed item, id retained */
3638 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
3639 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3640 expect(1, ret);
3641 /* new id starts from previous value */
3642 insert_item(hwnd, 1);
3643 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3644 expect(2, ret);
3646 /* get index by id */
3647 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
3648 expect(-1, ret);
3649 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
3650 expect(-1, ret);
3651 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
3652 expect(0, ret);
3653 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
3654 expect(1, ret);
3656 DestroyWindow(hwnd);
3659 START_TEST(listview)
3661 HMODULE hComctl32;
3662 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
3664 ULONG_PTR ctx_cookie;
3666 hComctl32 = GetModuleHandleA("comctl32.dll");
3667 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
3668 if (pInitCommonControlsEx)
3670 INITCOMMONCONTROLSEX iccex;
3671 iccex.dwSize = sizeof(iccex);
3672 iccex.dwICC = ICC_LISTVIEW_CLASSES;
3673 pInitCommonControlsEx(&iccex);
3675 else
3676 InitCommonControls();
3678 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
3680 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3681 hwndparent = create_parent_window(FALSE);
3682 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent window", TRUE);
3683 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3685 g_is_below_5 = is_below_comctl_5();
3687 test_images();
3688 test_checkboxes();
3689 test_items();
3690 test_create();
3691 test_redraw();
3692 test_customdraw();
3693 test_icon_spacing();
3694 test_color();
3695 test_item_count();
3696 test_item_position();
3697 test_columns();
3698 test_getorigin();
3699 test_multiselect();
3700 test_getitemrect();
3701 test_subitem_rect();
3702 test_sorting();
3703 test_ownerdata();
3704 test_norecompute();
3705 test_nosortheader();
3706 test_setredraw();
3707 test_hittest();
3708 test_getviewrect();
3709 test_getitemposition();
3710 test_columnscreation();
3711 test_editbox();
3712 test_notifyformat();
3713 test_indentation();
3715 if (!load_v6_module(&ctx_cookie))
3717 DestroyWindow(hwndparent);
3718 return;
3721 /* comctl32 version 6 tests start here */
3722 test_get_set_view();
3723 test_canceleditlabel();
3724 test_mapidindex();
3726 unload_v6_module(ctx_cookie);
3728 DestroyWindow(hwndparent);