wined3d: Fix a comment.
[wine/hramrach.git] / dlls / comctl32 / tests / listview.c
blob929583d34c71f99ba8d1c99dbaf46bd04ef4f974
1 /*
2 * ListView tests
4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009 Nikolay Sivov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdio.h>
24 #include <windows.h>
25 #include <commctrl.h>
27 #include "wine/test.h"
28 #include "v6util.h"
29 #include "msg.h"
31 #define PARENT_SEQ_INDEX 0
32 #define PARENT_FULL_SEQ_INDEX 1
33 #define LISTVIEW_SEQ_INDEX 2
34 #define EDITBOX_SEQ_INDEX 3
35 #define COMBINED_SEQ_INDEX 4
36 #define NUM_MSG_SEQUENCES 5
38 #define LISTVIEW_ID 0
39 #define HEADER_ID 1
41 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
42 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
43 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
45 static const WCHAR testparentclassW[] =
46 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
48 static HWND hwndparent, hwndparentW;
49 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
50 static BOOL blockEdit;
51 /* return nonzero on NM_HOVER */
52 static BOOL g_block_hover;
53 /* dumps LVN_ITEMCHANGED message data */
54 static BOOL g_dump_itemchanged;
55 /* format reported to control:
56 -1 falls to defproc, anything else returned */
57 static INT notifyFormat;
58 /* indicates we're running < 5.80 version */
59 static BOOL g_is_below_5;
60 /* item data passed to LVN_GETDISPINFOA */
61 static LVITEMA g_itema;
63 static HWND subclass_editbox(HWND hwndListview);
65 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
67 static const struct message create_ownerdrawfixed_parent_seq[] = {
68 { WM_NOTIFYFORMAT, sent },
69 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
70 { WM_MEASUREITEM, sent },
71 { WM_PARENTNOTIFY, sent },
72 { 0 }
75 static const struct message redraw_listview_seq[] = {
76 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
77 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
78 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
79 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
80 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
81 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
82 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
83 { 0 }
86 static const struct message listview_icon_spacing_seq[] = {
87 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
88 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
89 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
90 { 0 }
93 static const struct message listview_color_seq[] = {
94 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
95 { LVM_GETBKCOLOR, sent },
96 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
97 { LVM_GETTEXTCOLOR, sent },
98 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
99 { LVM_GETTEXTBKCOLOR, sent },
101 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
102 { LVM_GETBKCOLOR, sent },
103 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
104 { LVM_GETTEXTCOLOR, sent },
105 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
106 { LVM_GETTEXTBKCOLOR, sent },
108 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
109 { LVM_GETBKCOLOR, sent },
110 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
111 { LVM_GETTEXTCOLOR, sent },
112 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
113 { LVM_GETTEXTBKCOLOR, sent },
115 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
116 { LVM_GETBKCOLOR, sent },
117 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
118 { LVM_GETTEXTCOLOR, sent },
119 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
120 { LVM_GETTEXTBKCOLOR, sent },
121 { 0 }
124 static const struct message listview_item_count_seq[] = {
125 { LVM_GETITEMCOUNT, sent },
126 { LVM_INSERTITEM, sent },
127 { LVM_INSERTITEM, sent },
128 { LVM_INSERTITEM, sent },
129 { LVM_GETITEMCOUNT, sent },
130 { LVM_DELETEITEM, sent|wparam, 2 },
131 { WM_NCPAINT, sent|optional },
132 { WM_ERASEBKGND, sent|optional },
133 { LVM_GETITEMCOUNT, sent },
134 { LVM_DELETEALLITEMS, sent },
135 { LVM_GETITEMCOUNT, sent },
136 { LVM_INSERTITEM, sent },
137 { LVM_INSERTITEM, sent },
138 { LVM_GETITEMCOUNT, sent },
139 { LVM_INSERTITEM, sent },
140 { LVM_GETITEMCOUNT, sent },
141 { 0 }
144 static const struct message listview_itempos_seq[] = {
145 { LVM_INSERTITEM, sent },
146 { LVM_INSERTITEM, sent },
147 { LVM_INSERTITEM, sent },
148 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
149 { WM_NCPAINT, sent|optional },
150 { WM_ERASEBKGND, sent|optional },
151 { LVM_GETITEMPOSITION, sent|wparam, 1 },
152 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
153 { LVM_GETITEMPOSITION, sent|wparam, 2 },
154 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
155 { LVM_GETITEMPOSITION, sent|wparam, 0 },
156 { 0 }
159 static const struct message listview_ownerdata_switchto_seq[] = {
160 { WM_STYLECHANGING, sent },
161 { WM_STYLECHANGED, sent },
162 { 0 }
165 static const struct message listview_getorderarray_seq[] = {
166 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
167 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
168 { 0 }
171 static const struct message empty_seq[] = {
172 { 0 }
175 static const struct message forward_erasebkgnd_parent_seq[] = {
176 { WM_ERASEBKGND, sent },
177 { 0 }
180 static const struct message ownderdata_select_focus_parent_seq[] = {
181 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
182 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
183 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
184 { 0 }
187 static const struct message ownerdata_setstate_all_parent_seq[] = {
188 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
189 { 0 }
192 static const struct message ownerdata_defocus_all_parent_seq[] = {
193 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
194 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
195 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
196 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
197 { 0 }
200 static const struct message ownerdata_deselect_all_parent_seq[] = {
201 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
202 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
203 { 0 }
206 static const struct message select_all_parent_seq[] = {
207 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
208 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
210 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
211 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
213 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
214 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
216 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
217 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
219 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
220 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
221 { 0 }
224 static const struct message 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 /* next two are 4.7x specific */
249 { WM_WINDOWPOSCHANGING, sent },
250 { WM_WINDOWPOSCHANGED, sent|optional },
252 { WM_WINDOWPOSCHANGING, sent|optional },
253 { WM_NCCALCSIZE, sent },
254 { WM_WINDOWPOSCHANGED, sent },
255 { WM_MOVE, sent|defwinproc },
256 { WM_SIZE, sent|defwinproc },
257 /* the rest is todo, skipped in 4.7x */
258 { WM_WINDOWPOSCHANGING, sent|optional },
259 { WM_WINDOWPOSCHANGED, sent|optional },
260 { 0 }
263 static const struct message scroll_parent_seq[] = {
264 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
265 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
266 { 0 }
269 static const struct message setredraw_seq[] = {
270 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
271 { 0 }
274 static const struct message lvs_ex_transparentbkgnd_seq[] = {
275 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
276 { 0 }
279 static const struct message edit_end_nochange[] = {
280 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
281 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW }, /* todo */
282 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
283 { 0 }
286 static const struct message hover_parent[] = {
287 { WM_GETDLGCODE, sent }, /* todo_wine */
288 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
289 { 0 }
292 static const struct message listview_destroy[] = {
293 { 0x0090, sent|optional }, /* Vista */
294 { WM_PARENTNOTIFY, sent },
295 { WM_SHOWWINDOW, sent },
296 { WM_WINDOWPOSCHANGING, sent },
297 { WM_WINDOWPOSCHANGED, sent|optional },
298 { WM_DESTROY, sent },
299 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
300 { WM_NCDESTROY, sent },
301 { 0 }
304 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
306 static LONG defwndproc_counter = 0;
307 LRESULT ret;
308 struct message msg;
310 msg.message = message;
311 msg.flags = sent|wparam|lparam;
312 if (defwndproc_counter) msg.flags |= defwinproc;
313 msg.wParam = wParam;
314 msg.lParam = lParam;
315 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
317 /* log system messages, except for painting */
318 if (message < WM_USER &&
319 message != WM_PAINT &&
320 message != WM_ERASEBKGND &&
321 message != WM_NCPAINT &&
322 message != WM_NCHITTEST &&
323 message != WM_GETTEXT &&
324 message != WM_GETICON &&
325 message != WM_DEVICECHANGE)
327 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
329 add_message(sequences, PARENT_SEQ_INDEX, &msg);
330 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
332 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
334 switch (message)
336 case WM_NOTIFY:
338 switch (((NMHDR*)lParam)->code)
340 case LVN_BEGINLABELEDIT:
341 /* subclass edit box */
342 if (!blockEdit)
343 subclass_editbox(((NMHDR*)lParam)->hwndFrom);
345 return blockEdit;
347 case LVN_ENDLABELEDIT:
349 /* always accept new item text */
350 NMLVDISPINFO *di = (NMLVDISPINFO*)lParam;
351 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText);
352 return TRUE;
354 case LVN_BEGINSCROLL:
355 case LVN_ENDSCROLL:
357 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
359 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
360 "BEGIN" : "END", pScroll->dx, pScroll->dy);
362 break;
363 case LVN_ITEMCHANGED:
364 if (g_dump_itemchanged)
366 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
367 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
368 nmlv->iItem, nmlv->uNewState, nmlv->uOldState, nmlv->uChanged);
370 break;
371 case LVN_GETDISPINFOA:
373 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
374 g_itema = dispinfo->item;
376 break;
377 case NM_HOVER:
378 if (g_block_hover) return 1;
379 break;
381 break;
383 case WM_NOTIFYFORMAT:
385 /* force to return format */
386 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
387 break;
391 defwndproc_counter++;
392 ret = DefWindowProcA(hwnd, message, wParam, lParam);
393 defwndproc_counter--;
395 return ret;
398 static BOOL register_parent_wnd_class(BOOL Unicode)
400 WNDCLASSA clsA;
401 WNDCLASSW clsW;
403 if (Unicode)
405 clsW.style = 0;
406 clsW.lpfnWndProc = parent_wnd_proc;
407 clsW.cbClsExtra = 0;
408 clsW.cbWndExtra = 0;
409 clsW.hInstance = GetModuleHandleW(NULL);
410 clsW.hIcon = 0;
411 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
412 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
413 clsW.lpszMenuName = NULL;
414 clsW.lpszClassName = testparentclassW;
416 else
418 clsA.style = 0;
419 clsA.lpfnWndProc = parent_wnd_proc;
420 clsA.cbClsExtra = 0;
421 clsA.cbWndExtra = 0;
422 clsA.hInstance = GetModuleHandleA(NULL);
423 clsA.hIcon = 0;
424 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
425 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
426 clsA.lpszMenuName = NULL;
427 clsA.lpszClassName = "Listview test parent class";
430 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
433 static HWND create_parent_window(BOOL Unicode)
435 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
436 HWND hwnd;
438 if (!register_parent_wnd_class(Unicode))
439 return NULL;
441 blockEdit = FALSE;
442 notifyFormat = -1;
444 if (Unicode)
445 hwnd = CreateWindowExW(0, testparentclassW, nameW,
446 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
447 WS_MAXIMIZEBOX | WS_VISIBLE,
448 0, 0, 100, 100,
449 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
450 else
451 hwnd = CreateWindowExA(0, "Listview test parent class",
452 "Listview test parent window",
453 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
454 WS_MAXIMIZEBOX | WS_VISIBLE,
455 0, 0, 100, 100,
456 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
457 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
458 return hwnd;
461 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
463 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
464 static LONG defwndproc_counter = 0;
465 LRESULT ret;
466 struct message msg;
468 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
470 /* some debug output for style changing */
471 if ((message == WM_STYLECHANGING ||
472 message == WM_STYLECHANGED) && lParam)
474 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
475 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
478 msg.message = message;
479 msg.flags = sent|wparam|lparam;
480 if (defwndproc_counter) msg.flags |= defwinproc;
481 msg.wParam = wParam;
482 msg.lParam = lParam;
483 msg.id = LISTVIEW_ID;
484 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
485 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
487 defwndproc_counter++;
488 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
489 defwndproc_counter--;
490 return ret;
493 static HWND create_listview_control(DWORD style)
495 WNDPROC oldproc;
496 HWND hwnd;
497 RECT rect;
499 GetClientRect(hwndparent, &rect);
500 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
501 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
502 0, 0, rect.right, rect.bottom,
503 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
504 ok(hwnd != NULL, "gle=%d\n", GetLastError());
506 if (!hwnd) return NULL;
508 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
509 (LONG_PTR)listview_subclass_proc);
510 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
512 return hwnd;
515 /* unicode listview window with specified parent */
516 static HWND create_listview_controlW(DWORD style, HWND parent)
518 WNDPROC oldproc;
519 HWND hwnd;
520 RECT rect;
521 static const WCHAR nameW[] = {'f','o','o',0};
523 GetClientRect(parent, &rect);
524 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
525 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
526 0, 0, rect.right, rect.bottom,
527 parent, NULL, GetModuleHandleW(NULL), NULL);
528 ok(hwnd != NULL, "gle=%d\n", GetLastError());
530 if (!hwnd) return NULL;
532 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
533 (LONG_PTR)listview_subclass_proc);
534 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
536 return hwnd;
539 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
541 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
542 static LONG defwndproc_counter = 0;
543 LRESULT ret;
544 struct message msg;
546 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
548 msg.message = message;
549 msg.flags = sent|wparam|lparam;
550 if (defwndproc_counter) msg.flags |= defwinproc;
551 msg.wParam = wParam;
552 msg.lParam = lParam;
553 msg.id = HEADER_ID;
554 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
556 defwndproc_counter++;
557 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
558 defwndproc_counter--;
559 return ret;
562 static HWND subclass_header(HWND hwndListview)
564 WNDPROC oldproc;
565 HWND hwnd;
567 hwnd = ListView_GetHeader(hwndListview);
568 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
569 (LONG_PTR)header_subclass_proc);
570 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
572 return hwnd;
575 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
577 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
578 static LONG defwndproc_counter = 0;
579 LRESULT ret;
580 struct message msg;
582 msg.message = message;
583 msg.flags = sent|wparam|lparam;
584 if (defwndproc_counter) msg.flags |= defwinproc;
585 msg.wParam = wParam;
586 msg.lParam = lParam;
588 /* all we need is sizing */
589 if (message == WM_WINDOWPOSCHANGING ||
590 message == WM_NCCALCSIZE ||
591 message == WM_WINDOWPOSCHANGED ||
592 message == WM_MOVE ||
593 message == WM_SIZE)
595 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
598 defwndproc_counter++;
599 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
600 defwndproc_counter--;
601 return ret;
604 static HWND subclass_editbox(HWND hwndListview)
606 WNDPROC oldproc;
607 HWND hwnd;
609 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
610 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
611 (LONG_PTR)editbox_subclass_proc);
612 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
614 return hwnd;
617 /* Performs a single LVM_HITTEST test */
618 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
619 BOOL todo_item, BOOL todo_flags, int line)
621 LVHITTESTINFO lpht;
622 DWORD ret;
624 lpht.pt.x = x;
625 lpht.pt.y = y;
626 lpht.iSubItem = 10;
628 trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
629 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
631 if (todo_item)
633 todo_wine
635 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
636 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
637 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
640 else
642 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
643 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
644 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
647 if (todo_flags)
649 todo_wine
650 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
652 else if (broken_flags)
653 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
654 "Expected flags %x, got %x\n", flags, lpht.flags);
655 else
656 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
659 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
661 /* Performs a single LVM_SUBITEMHITTEST test */
662 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
663 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
665 LVHITTESTINFO lpht;
666 DWORD ret;
668 lpht.pt.x = x;
669 lpht.pt.y = y;
671 trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
672 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
674 if (todo_item)
676 todo_wine
678 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
679 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
682 else
684 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
685 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
688 if (todo_subitem)
690 todo_wine
691 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
693 else
694 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
696 if (todo_flags)
698 todo_wine
699 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
701 else
702 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
705 #define test_lvm_subitemhittest(a,b,c,d,e,f,g,h,i) test_lvm_subitemhittest_(a,b,c,d,e,f,g,h,i,__LINE__)
707 static void test_images(void)
709 HWND hwnd;
710 DWORD r;
711 LVITEM item;
712 HIMAGELIST himl;
713 HBITMAP hbmp;
714 RECT r1, r2;
715 static CHAR hello[] = "hello";
717 himl = ImageList_Create(40, 40, 0, 4, 4);
718 ok(himl != NULL, "failed to create imagelist\n");
720 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
721 ok(hbmp != NULL, "failed to create bitmap\n");
723 r = ImageList_Add(himl, hbmp, 0);
724 ok(r == 0, "should be zero\n");
726 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
727 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
728 ok(hwnd != NULL, "failed to create listview window\n");
730 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
731 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
733 ok(r == 0, "should return zero\n");
735 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
736 ok(r == 0, "should return zero\n");
738 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
739 /* returns dimensions */
741 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
742 ok(r == 0, "should be zero items\n");
744 item.mask = LVIF_IMAGE | LVIF_TEXT;
745 item.iItem = 0;
746 item.iSubItem = 1;
747 item.iImage = 0;
748 item.pszText = 0;
749 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
750 ok(r == -1, "should fail\n");
752 item.iSubItem = 0;
753 item.pszText = hello;
754 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
755 ok(r == 0, "should not fail\n");
757 memset(&r1, 0, sizeof r1);
758 r1.left = LVIR_ICON;
759 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
761 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
762 ok(r == TRUE, "should not fail\n");
764 item.iSubItem = 0;
765 item.pszText = hello;
766 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
767 ok(r == 0, "should not fail\n");
769 memset(&r2, 0, sizeof r2);
770 r2.left = LVIR_ICON;
771 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
773 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
775 DestroyWindow(hwnd);
778 static void test_checkboxes(void)
780 HWND hwnd;
781 LVITEMA item;
782 DWORD r;
783 static CHAR text[] = "Text",
784 text2[] = "Text2",
785 text3[] = "Text3";
787 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
788 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
789 ok(hwnd != NULL, "failed to create listview window\n");
791 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
792 item.mask = LVIF_TEXT | LVIF_STATE;
793 item.stateMask = 0xffff;
794 item.state = 0xfccc;
795 item.iItem = 0;
796 item.iSubItem = 0;
797 item.pszText = text;
798 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
799 ok(r == 0, "ret %d\n", r);
801 item.iItem = 0;
802 item.mask = LVIF_STATE;
803 item.stateMask = 0xffff;
804 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
805 ok(item.state == 0xfccc, "state %x\n", item.state);
807 /* Don't set LVIF_STATE */
808 item.mask = LVIF_TEXT;
809 item.stateMask = 0xffff;
810 item.state = 0xfccc;
811 item.iItem = 1;
812 item.iSubItem = 0;
813 item.pszText = text;
814 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
815 ok(r == 1, "ret %d\n", r);
817 item.iItem = 1;
818 item.mask = LVIF_STATE;
819 item.stateMask = 0xffff;
820 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
821 ok(item.state == 0, "state %x\n", item.state);
823 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
824 ok(r == 0, "should return zero\n");
826 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
827 item.iItem = 0;
828 item.mask = LVIF_STATE;
829 item.stateMask = 0xffff;
830 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
831 if (item.state != 0x1ccc)
833 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
834 DestroyWindow(hwnd);
835 return;
838 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
839 item.iItem = 2;
840 item.mask = LVIF_TEXT;
841 item.state = 0;
842 item.pszText = text2;
843 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
844 ok(r == 2, "ret %d\n", r);
846 item.iItem = 2;
847 item.mask = LVIF_STATE;
848 item.stateMask = 0xffff;
849 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
850 ok(item.state == 0x1000, "state %x\n", item.state);
852 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
853 item.iItem = 3;
854 item.mask = LVIF_TEXT | LVIF_STATE;
855 item.stateMask = 0xffff;
856 item.state = 0x2aaa;
857 item.pszText = text3;
858 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
859 ok(r == 3, "ret %d\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 == 0x1aaa, "state %x\n", item.state);
867 /* Set an item's state to checked */
868 item.iItem = 3;
869 item.mask = LVIF_STATE;
870 item.stateMask = 0xf000;
871 item.state = 0x2000;
872 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
874 item.iItem = 3;
875 item.mask = LVIF_STATE;
876 item.stateMask = 0xffff;
877 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
878 ok(item.state == 0x2aaa, "state %x\n", item.state);
880 /* Check that only the bits we asked for are returned,
881 * and that all the others are set to zero
883 item.iItem = 3;
884 item.mask = LVIF_STATE;
885 item.stateMask = 0xf000;
886 item.state = 0xffff;
887 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
888 ok(item.state == 0x2000, "state %x\n", item.state);
890 /* Set the style again and check that doesn't change an item's state */
891 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
892 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
894 item.iItem = 3;
895 item.mask = LVIF_STATE;
896 item.stateMask = 0xffff;
897 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
898 ok(item.state == 0x2aaa, "state %x\n", item.state);
900 /* Unsetting the checkbox extended style doesn't change an item's state */
901 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
902 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
904 item.iItem = 3;
905 item.mask = LVIF_STATE;
906 item.stateMask = 0xffff;
907 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
908 ok(item.state == 0x2aaa, "state %x\n", item.state);
910 /* Now setting the style again will change an item's state */
911 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
912 ok(r == 0, "ret %x\n", r);
914 item.iItem = 3;
915 item.mask = LVIF_STATE;
916 item.stateMask = 0xffff;
917 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
918 ok(item.state == 0x1aaa, "state %x\n", item.state);
920 /* Toggle checkbox tests (bug 9934) */
921 memset (&item, 0xcc, sizeof(item));
922 item.mask = LVIF_STATE;
923 item.iItem = 3;
924 item.iSubItem = 0;
925 item.state = LVIS_FOCUSED;
926 item.stateMask = LVIS_FOCUSED;
927 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
928 expect(1, r);
930 item.iItem = 3;
931 item.mask = LVIF_STATE;
932 item.stateMask = 0xffff;
933 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
934 ok(item.state == 0x1aab, "state %x\n", item.state);
936 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
937 expect(0, r);
938 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
939 expect(0, r);
941 item.iItem = 3;
942 item.mask = LVIF_STATE;
943 item.stateMask = 0xffff;
944 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
945 ok(item.state == 0x2aab, "state %x\n", item.state);
947 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
948 expect(0, r);
949 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
950 expect(0, r);
952 item.iItem = 3;
953 item.mask = LVIF_STATE;
954 item.stateMask = 0xffff;
955 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
956 ok(item.state == 0x1aab, "state %x\n", item.state);
958 DestroyWindow(hwnd);
961 static void insert_column(HWND hwnd, int idx)
963 LVCOLUMN column;
964 DWORD rc;
966 memset(&column, 0xcc, sizeof(column));
967 column.mask = LVCF_SUBITEM;
968 column.iSubItem = idx;
970 rc = ListView_InsertColumn(hwnd, idx, &column);
971 expect(idx, rc);
974 static void insert_item(HWND hwnd, int idx)
976 static CHAR text[] = "foo";
978 LVITEMA item;
979 DWORD rc;
981 memset(&item, 0xcc, sizeof (item));
982 item.mask = LVIF_TEXT;
983 item.iItem = idx;
984 item.iSubItem = 0;
985 item.pszText = text;
987 rc = ListView_InsertItem(hwnd, &item);
988 expect(idx, rc);
991 static void test_items(void)
993 const LPARAM lparamTest = 0x42;
994 HWND hwnd;
995 LVITEMA item;
996 DWORD r;
997 static CHAR text[] = "Text";
999 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1000 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1001 ok(hwnd != NULL, "failed to create listview window\n");
1004 * Test setting/getting item params
1007 /* Set up two columns */
1008 insert_column(hwnd, 0);
1009 insert_column(hwnd, 1);
1011 /* LVIS_SELECTED with zero stateMask */
1012 /* set */
1013 memset (&item, 0, sizeof (item));
1014 item.mask = LVIF_STATE;
1015 item.state = LVIS_SELECTED;
1016 item.stateMask = 0;
1017 item.iItem = 0;
1018 item.iSubItem = 0;
1019 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1020 ok(r == 0, "ret %d\n", r);
1021 /* get */
1022 memset (&item, 0xcc, sizeof (item));
1023 item.mask = LVIF_STATE;
1024 item.stateMask = LVIS_SELECTED;
1025 item.state = 0;
1026 item.iItem = 0;
1027 item.iSubItem = 0;
1028 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1029 ok(r != 0, "ret %d\n", r);
1030 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1031 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1033 /* LVIS_SELECTED with zero stateMask */
1034 /* set */
1035 memset (&item, 0, sizeof (item));
1036 item.mask = LVIF_STATE;
1037 item.state = LVIS_FOCUSED;
1038 item.stateMask = 0;
1039 item.iItem = 0;
1040 item.iSubItem = 0;
1041 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1042 ok(r == 0, "ret %d\n", r);
1043 /* get */
1044 memset (&item, 0xcc, sizeof (item));
1045 item.mask = LVIF_STATE;
1046 item.stateMask = LVIS_FOCUSED;
1047 item.state = 0;
1048 item.iItem = 0;
1049 item.iSubItem = 0;
1050 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1051 ok(r != 0, "ret %d\n", r);
1052 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1053 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1055 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1056 /* set */
1057 memset (&item, 0, sizeof (item));
1058 item.mask = LVIF_STATE;
1059 item.state = LVIS_CUT;
1060 item.stateMask = LVIS_FOCUSED;
1061 item.iItem = 0;
1062 item.iSubItem = 0;
1063 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1064 ok(r == 0, "ret %d\n", r);
1065 /* get */
1066 memset (&item, 0xcc, sizeof (item));
1067 item.mask = LVIF_STATE;
1068 item.stateMask = LVIS_CUT;
1069 item.state = 0;
1070 item.iItem = 0;
1071 item.iSubItem = 0;
1072 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1073 ok(r != 0, "ret %d\n", r);
1074 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1075 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1077 /* Insert an item with just a param */
1078 memset (&item, 0xcc, sizeof (item));
1079 item.mask = LVIF_PARAM;
1080 item.iItem = 0;
1081 item.iSubItem = 0;
1082 item.lParam = lparamTest;
1083 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1084 ok(r == 0, "ret %d\n", r);
1086 /* Test getting of the param */
1087 memset (&item, 0xcc, sizeof (item));
1088 item.mask = LVIF_PARAM;
1089 item.iItem = 0;
1090 item.iSubItem = 0;
1091 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1092 ok(r != 0, "ret %d\n", r);
1093 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1095 /* Set up a subitem */
1096 memset (&item, 0xcc, sizeof (item));
1097 item.mask = LVIF_TEXT;
1098 item.iItem = 0;
1099 item.iSubItem = 1;
1100 item.pszText = text;
1101 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1102 ok(r != 0, "ret %d\n", r);
1104 /* Query param from subitem: returns main item param */
1105 memset (&item, 0xcc, sizeof (item));
1106 item.mask = LVIF_PARAM;
1107 item.iItem = 0;
1108 item.iSubItem = 1;
1109 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1110 ok(r != 0, "ret %d\n", r);
1111 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1113 /* Set up param on first subitem: no effect */
1114 memset (&item, 0xcc, sizeof (item));
1115 item.mask = LVIF_PARAM;
1116 item.iItem = 0;
1117 item.iSubItem = 1;
1118 item.lParam = lparamTest+1;
1119 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1120 ok(r == 0, "ret %d\n", r);
1122 /* Query param from subitem again: should still return main item param */
1123 memset (&item, 0xcc, sizeof (item));
1124 item.mask = LVIF_PARAM;
1125 item.iItem = 0;
1126 item.iSubItem = 1;
1127 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1128 ok(r != 0, "ret %d\n", r);
1129 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1131 /**** Some tests of state highlighting ****/
1132 memset (&item, 0xcc, sizeof (item));
1133 item.mask = LVIF_STATE;
1134 item.iItem = 0;
1135 item.iSubItem = 0;
1136 item.state = LVIS_SELECTED;
1137 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1138 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1139 ok(r != 0, "ret %d\n", r);
1140 item.iSubItem = 1;
1141 item.state = LVIS_DROPHILITED;
1142 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1143 ok(r != 0, "ret %d\n", r);
1145 memset (&item, 0xcc, sizeof (item));
1146 item.mask = LVIF_STATE;
1147 item.iItem = 0;
1148 item.iSubItem = 0;
1149 item.stateMask = -1;
1150 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1151 ok(r != 0, "ret %d\n", r);
1152 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1153 item.iSubItem = 1;
1154 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1155 ok(r != 0, "ret %d\n", r);
1156 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1158 /* some notnull but meaningless masks */
1159 memset (&item, 0, sizeof(item));
1160 item.mask = LVIF_NORECOMPUTE;
1161 item.iItem = 0;
1162 item.iSubItem = 0;
1163 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1164 ok(r != 0, "ret %d\n", r);
1165 memset (&item, 0, sizeof(item));
1166 item.mask = LVIF_DI_SETITEM;
1167 item.iItem = 0;
1168 item.iSubItem = 0;
1169 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1170 ok(r != 0, "ret %d\n", r);
1172 /* set text to callback value already having it */
1173 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1174 expect(TRUE, r);
1175 memset (&item, 0, sizeof (item));
1176 item.mask = LVIF_TEXT;
1177 item.pszText = LPSTR_TEXTCALLBACK;
1178 item.iItem = 0;
1179 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1180 ok(r == 0, "ret %d\n", r);
1181 memset (&item, 0, sizeof (item));
1183 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1185 item.pszText = LPSTR_TEXTCALLBACK;
1186 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1187 expect(TRUE, r);
1189 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1190 "check callback text comparison rule", FALSE);
1192 DestroyWindow(hwnd);
1195 static void test_columns(void)
1197 HWND hwnd;
1198 LVCOLUMNA column;
1199 LVITEMA item;
1200 INT order[2];
1201 CHAR buff[5];
1202 DWORD rc;
1204 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1205 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1206 ok(hwnd != NULL, "failed to create listview window\n");
1208 /* Add a column with no mask */
1209 memset(&column, 0xcc, sizeof(column));
1210 column.mask = 0;
1211 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1212 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1214 /* Check its width */
1215 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1216 ok(rc == 10 || broken(rc == 0) /* win9x */,
1217 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1219 DestroyWindow(hwnd);
1221 /* LVM_GETCOLUMNORDERARRAY */
1222 hwnd = create_listview_control(LVS_REPORT);
1223 subclass_header(hwnd);
1225 memset(&column, 0, sizeof(column));
1226 column.mask = LVCF_WIDTH;
1227 column.cx = 100;
1228 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1229 ok(rc == 0, "Inserting column failed with %d\n", rc);
1231 column.cx = 200;
1232 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1233 ok(rc == 1, "Inserting column failed with %d\n", rc);
1235 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1237 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1238 ok(rc == 1, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1239 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1240 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1242 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1244 /* after column added subitem is considered as present */
1245 insert_item(hwnd, 0);
1247 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1249 item.pszText = buff;
1250 item.cchTextMax = sizeof(buff);
1251 item.iItem = 0;
1252 item.iSubItem = 1;
1253 item.mask = LVIF_TEXT;
1254 memset(&g_itema, 0, sizeof(g_itema));
1255 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1256 ok(rc == 1, "got %d\n", rc);
1257 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1259 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1260 "get subitem text after column added", FALSE);
1262 DestroyWindow(hwnd);
1265 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1266 static WNDPROC listviewWndProc;
1267 static HIMAGELIST test_create_imagelist;
1269 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1271 LRESULT ret;
1273 if (uMsg == WM_CREATE)
1275 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1276 lpcs->style |= LVS_REPORT;
1278 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1279 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1280 return ret;
1283 static void test_create(void)
1285 HWND hList;
1286 HWND hHeader;
1287 LONG_PTR ret;
1288 LONG r;
1289 LVCOLUMNA col;
1290 RECT rect;
1291 WNDCLASSEX cls;
1292 DWORD style;
1294 cls.cbSize = sizeof(WNDCLASSEX);
1295 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1296 listviewWndProc = cls.lpfnWndProc;
1297 cls.lpfnWndProc = create_test_wndproc;
1298 cls.lpszClassName = "MyListView32";
1299 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1301 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1302 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1303 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1304 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1306 if (!IsWindow(hHeader))
1308 /* version 4.0 */
1309 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1310 DestroyWindow(hList);
1311 return;
1314 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1315 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1316 DestroyWindow(hList);
1318 /* header isn't created on LVS_ICON and LVS_LIST styles */
1319 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 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 style = GetWindowLong(hHeader, GWL_STYLE);
1334 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1335 DestroyWindow(hList);
1337 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1338 GetModuleHandle(NULL), 0);
1339 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1340 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1341 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1342 /* insert column */
1343 memset(&col, 0, sizeof(LVCOLUMNA));
1344 col.mask = LVCF_WIDTH;
1345 col.cx = 100;
1346 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1347 ok(r == 0, "Expected 0 column's inserted\n");
1348 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1349 ok(IsWindow(hHeader), "Header should be created\n");
1350 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1351 DestroyWindow(hList);
1353 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1354 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1355 GetModuleHandle(NULL), 0);
1356 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1357 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1358 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1359 ok(IsWindow(hHeader), "Header should be created\n");
1360 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1361 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1362 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1363 ok(IsWindow(hHeader), "Header should be created\n");
1364 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1365 DestroyWindow(hList);
1367 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1368 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1369 GetModuleHandle(NULL), 0);
1370 ret = SetWindowLongPtr(hList, GWL_STYLE,
1371 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1372 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1373 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1374 ok(IsWindow(hHeader), "Header should be created\n");
1375 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1376 ret = SetWindowLongPtr(hList, GWL_STYLE,
1377 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1378 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1379 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1380 ok(IsWindow(hHeader), "Header should be created\n");
1381 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1382 DestroyWindow(hList);
1384 /* LVS_REPORT without WS_VISIBLE */
1385 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1386 GetModuleHandle(NULL), 0);
1387 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1388 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1389 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1390 /* insert column */
1391 memset(&col, 0, sizeof(LVCOLUMNA));
1392 col.mask = LVCF_WIDTH;
1393 col.cx = 100;
1394 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1395 ok(r == 0, "Expected 0 column's inserted\n");
1396 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1397 ok(IsWindow(hHeader), "Header should be created\n");
1398 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1399 DestroyWindow(hList);
1401 /* LVS_REPORT without WS_VISIBLE, try to show it */
1402 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1403 GetModuleHandle(NULL), 0);
1404 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1405 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1406 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1407 ShowWindow(hList, SW_SHOW);
1408 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1409 ok(IsWindow(hHeader), "Header should be created\n");
1410 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1411 DestroyWindow(hList);
1413 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1414 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1415 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1416 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1417 ok(IsWindow(hHeader), "Header should be created\n");
1418 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1419 /* HDS_DRAGDROP set by default */
1420 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1421 DestroyWindow(hList);
1423 /* setting LVS_EX_HEADERDRAGDROP creates header */
1424 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1425 GetModuleHandle(NULL), 0);
1426 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1427 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1428 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1429 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1430 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1431 ok(IsWindow(hHeader) ||
1432 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1433 "Header should be created\n");
1434 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1435 DestroyWindow(hList);
1437 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1438 hList = create_listview_control(LVS_ICON);
1439 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1440 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1441 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1442 DestroyWindow(hList);
1444 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1445 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1446 GetModuleHandle(NULL), 0);
1447 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1448 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1450 rect.left = LVIR_BOUNDS;
1451 rect.top = 1;
1452 rect.right = rect.bottom = -10;
1453 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1454 ok(r != 0, "Expected not-null LRESULT\n");
1456 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1457 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1458 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1460 DestroyWindow(hList);
1462 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1463 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1464 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1465 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1466 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1467 DestroyWindow(hList);
1470 static void test_redraw(void)
1472 HWND hwnd;
1473 HDC hdc;
1474 BOOL res;
1475 DWORD r;
1477 hwnd = create_listview_control(LVS_REPORT);
1478 subclass_header(hwnd);
1480 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1482 trace("invalidate & update\n");
1483 InvalidateRect(hwnd, NULL, TRUE);
1484 UpdateWindow(hwnd);
1485 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1487 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1489 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1490 /* 1. Without backbuffer */
1491 res = ListView_SetBkColor(hwnd, CLR_NONE);
1492 expect(TRUE, res);
1494 hdc = GetWindowDC(hwndparent);
1496 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1497 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1498 ok(r != 0, "Expected not zero result\n");
1499 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1500 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1502 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1503 expect(TRUE, res);
1505 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1506 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1507 ok(r != 0, "Expected not zero result\n");
1508 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1509 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1511 /* 2. With backbuffer */
1512 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1513 LVS_EX_DOUBLEBUFFER);
1514 res = ListView_SetBkColor(hwnd, CLR_NONE);
1515 expect(TRUE, res);
1517 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1518 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1519 ok(r != 0, "Expected not zero result\n");
1520 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1521 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1523 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1524 expect(TRUE, res);
1526 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1527 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1528 todo_wine ok(r != 0, "Expected not zero result\n");
1529 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1530 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1532 ReleaseDC(hwndparent, hdc);
1534 DestroyWindow(hwnd);
1537 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1539 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1541 if(msg == WM_NOTIFY) {
1542 NMHDR *nmhdr = (PVOID)lp;
1543 if(nmhdr->code == NM_CUSTOMDRAW) {
1544 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1545 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1546 switch(nmlvcd->nmcd.dwDrawStage) {
1547 case CDDS_PREPAINT:
1548 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1549 return CDRF_NOTIFYITEMDRAW;
1550 case CDDS_ITEMPREPAINT:
1551 nmlvcd->clrTextBk = CLR_DEFAULT;
1552 return CDRF_NOTIFYSUBITEMDRAW;
1553 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1554 clr = GetBkColor(nmlvcd->nmcd.hdc);
1555 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1556 return CDRF_NOTIFYPOSTPAINT;
1557 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1558 clr = GetBkColor(nmlvcd->nmcd.hdc);
1559 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1560 return CDRF_DODEFAULT;
1562 return CDRF_DODEFAULT;
1566 return DefWindowProcA(hwnd, msg, wp, lp);
1569 static void test_customdraw(void)
1571 HWND hwnd;
1572 WNDPROC oldwndproc;
1574 hwnd = create_listview_control(LVS_REPORT);
1576 insert_column(hwnd, 0);
1577 insert_column(hwnd, 1);
1578 insert_item(hwnd, 0);
1580 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1581 (LONG_PTR)cd_wndproc);
1583 InvalidateRect(hwnd, NULL, TRUE);
1584 UpdateWindow(hwnd);
1586 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1588 DestroyWindow(hwnd);
1591 static void test_icon_spacing(void)
1593 /* LVM_SETICONSPACING */
1594 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1596 HWND hwnd;
1597 WORD w, h;
1598 DWORD r;
1600 hwnd = create_listview_control(LVS_ICON);
1601 ok(hwnd != NULL, "failed to create a listview window\n");
1603 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1604 expect(NFR_ANSI, r);
1606 /* reset the icon spacing to defaults */
1607 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1609 /* now we can request what the defaults are */
1610 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1611 w = LOWORD(r);
1612 h = HIWORD(r);
1614 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1616 trace("test icon spacing\n");
1618 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1619 ok(r == MAKELONG(w, h) ||
1620 broken(r == MAKELONG(w, w)), /* win98 */
1621 "Expected %d, got %d\n", MAKELONG(w, h), r);
1623 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1624 if (r == 0)
1626 /* version 4.0 */
1627 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1628 DestroyWindow(hwnd);
1629 return;
1631 expect(MAKELONG(20,30), r);
1633 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1634 expect(MAKELONG(25,35), r);
1636 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1638 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1639 DestroyWindow(hwnd);
1642 static void test_color(void)
1644 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1646 HWND hwnd;
1647 DWORD r;
1648 int i;
1650 COLORREF color;
1651 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1653 hwnd = create_listview_control(LVS_REPORT);
1654 ok(hwnd != NULL, "failed to create a listview window\n");
1656 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1658 trace("test color seq\n");
1659 for (i = 0; i < 4; i++)
1661 color = colors[i];
1663 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1664 expect(TRUE, r);
1665 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1666 expect(color, r);
1668 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1669 expect (TRUE, r);
1670 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1671 expect(color, r);
1673 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1674 expect(TRUE, r);
1675 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1676 expect(color, r);
1679 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1681 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1682 DestroyWindow(hwnd);
1685 static void test_item_count(void)
1687 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1689 HWND hwnd;
1690 DWORD r;
1691 HDC hdc;
1692 HFONT hOldFont;
1693 TEXTMETRICA tm;
1694 RECT rect;
1695 INT height;
1697 LVITEM item0;
1698 LVITEM item1;
1699 LVITEM item2;
1700 static CHAR item0text[] = "item0";
1701 static CHAR item1text[] = "item1";
1702 static CHAR item2text[] = "item2";
1704 hwnd = create_listview_control(LVS_REPORT);
1705 ok(hwnd != NULL, "failed to create a listview window\n");
1707 /* resize in dpiaware manner to fit all 3 items added */
1708 hdc = GetDC(0);
1709 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1710 GetTextMetricsA(hdc, &tm);
1711 /* 2 extra pixels for bounds and header border */
1712 height = tm.tmHeight + 2;
1713 SelectObject(hdc, hOldFont);
1714 ReleaseDC(0, hdc);
1716 GetWindowRect(hwnd, &rect);
1717 /* 3 items + 1 header + 1 to be sure */
1718 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1720 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1722 trace("test item count\n");
1724 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1725 expect(0, r);
1727 /* [item0] */
1728 item0.mask = LVIF_TEXT;
1729 item0.iItem = 0;
1730 item0.iSubItem = 0;
1731 item0.pszText = item0text;
1732 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1733 expect(0, r);
1735 /* [item0, item1] */
1736 item1.mask = LVIF_TEXT;
1737 item1.iItem = 1;
1738 item1.iSubItem = 0;
1739 item1.pszText = item1text;
1740 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1741 expect(1, r);
1743 /* [item0, item1, item2] */
1744 item2.mask = LVIF_TEXT;
1745 item2.iItem = 2;
1746 item2.iSubItem = 0;
1747 item2.pszText = item2text;
1748 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1749 expect(2, r);
1751 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1752 expect(3, r);
1754 /* [item0, item1] */
1755 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1756 expect(TRUE, r);
1758 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1759 expect(2, r);
1761 /* [] */
1762 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1763 expect(TRUE, r);
1765 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1766 expect(0, r);
1768 /* [item0] */
1769 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1770 expect(0, r);
1772 /* [item0, item1] */
1773 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1774 expect(1, r);
1776 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1777 expect(2, r);
1779 /* [item0, item1, item2] */
1780 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1781 expect(2, r);
1783 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1784 expect(3, r);
1786 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1788 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1789 DestroyWindow(hwnd);
1792 static void test_item_position(void)
1794 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1796 HWND hwnd;
1797 DWORD r;
1798 POINT position;
1800 LVITEM item0;
1801 LVITEM item1;
1802 LVITEM item2;
1803 static CHAR item0text[] = "item0";
1804 static CHAR item1text[] = "item1";
1805 static CHAR item2text[] = "item2";
1807 hwnd = create_listview_control(LVS_ICON);
1808 ok(hwnd != NULL, "failed to create a listview window\n");
1810 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1812 trace("test item position\n");
1814 /* [item0] */
1815 item0.mask = LVIF_TEXT;
1816 item0.iItem = 0;
1817 item0.iSubItem = 0;
1818 item0.pszText = item0text;
1819 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1820 expect(0, r);
1822 /* [item0, item1] */
1823 item1.mask = LVIF_TEXT;
1824 item1.iItem = 1;
1825 item1.iSubItem = 0;
1826 item1.pszText = item1text;
1827 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1828 expect(1, r);
1830 /* [item0, item1, item2] */
1831 item2.mask = LVIF_TEXT;
1832 item2.iItem = 2;
1833 item2.iSubItem = 0;
1834 item2.pszText = item2text;
1835 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1836 expect(2, r);
1838 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1839 expect(TRUE, r);
1840 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1841 expect(TRUE, r);
1842 expect2(10, 5, position.x, position.y);
1844 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1845 expect(TRUE, r);
1846 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1847 expect(TRUE, r);
1848 expect2(0, 0, position.x, position.y);
1850 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1851 expect(TRUE, r);
1852 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1853 expect(TRUE, r);
1854 expect2(20, 20, position.x, position.y);
1856 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1858 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1859 DestroyWindow(hwnd);
1862 static void test_getorigin(void)
1864 /* LVM_GETORIGIN */
1866 HWND hwnd;
1867 DWORD r;
1868 POINT position;
1870 position.x = position.y = 0;
1872 hwnd = create_listview_control(LVS_ICON);
1873 ok(hwnd != NULL, "failed to create a listview window\n");
1874 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1875 trace("test get origin results\n");
1876 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1877 expect(TRUE, r);
1878 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1879 DestroyWindow(hwnd);
1881 hwnd = create_listview_control(LVS_SMALLICON);
1882 ok(hwnd != NULL, "failed to create a listview window\n");
1883 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1884 trace("test get origin results\n");
1885 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1886 expect(TRUE, r);
1887 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1888 DestroyWindow(hwnd);
1890 hwnd = create_listview_control(LVS_LIST);
1891 ok(hwnd != NULL, "failed to create a listview window\n");
1892 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1893 trace("test get origin results\n");
1894 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1895 expect(FALSE, r);
1896 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1897 DestroyWindow(hwnd);
1899 hwnd = create_listview_control(LVS_REPORT);
1900 ok(hwnd != NULL, "failed to create a listview window\n");
1901 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1902 trace("test get origin results\n");
1903 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1904 expect(FALSE, r);
1905 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1906 DestroyWindow(hwnd);
1910 static void test_multiselect(void)
1912 typedef struct t_select_task
1914 const char *descr;
1915 int initPos;
1916 int loopVK;
1917 int count;
1918 int result;
1919 } select_task;
1921 HWND hwnd;
1922 DWORD r;
1923 int i,j,item_count,selected_count;
1924 static const int items=5;
1925 BYTE kstate[256];
1926 select_task task;
1927 LONG_PTR style;
1928 LVITEMA item;
1930 static struct t_select_task task_list[] = {
1931 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1932 { "using VK_UP", -1, VK_UP, -1, -1 },
1933 { "using VK_END", 0, VK_END, 1, -1 },
1934 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1938 hwnd = create_listview_control(LVS_REPORT);
1940 for (i=0;i<items;i++) {
1941 insert_item(hwnd, 0);
1944 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1946 expect(items,item_count);
1948 for (i=0;i<4;i++) {
1949 task = task_list[i];
1951 /* deselect all items */
1952 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1953 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1955 /* set initial position */
1956 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1957 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1959 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1961 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1963 /* Set SHIFT key pressed */
1964 GetKeyboardState(kstate);
1965 kstate[VK_SHIFT]=0x80;
1966 SetKeyboardState(kstate);
1968 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1969 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1970 expect(0,r);
1971 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1972 expect(0,r);
1975 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1977 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);
1979 /* Set SHIFT key released */
1980 GetKeyboardState(kstate);
1981 kstate[VK_SHIFT]=0x00;
1982 SetKeyboardState(kstate);
1984 DestroyWindow(hwnd);
1986 /* make multiple selection, then switch to LVS_SINGLESEL */
1987 hwnd = create_listview_control(LVS_REPORT);
1988 for (i=0;i<items;i++) {
1989 insert_item(hwnd, 0);
1991 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1992 expect(items,item_count);
1994 /* try with NULL pointer */
1995 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
1996 expect(FALSE, r);
1998 /* select all, check notifications */
1999 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2001 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2003 item.stateMask = LVIS_SELECTED;
2004 item.state = LVIS_SELECTED;
2005 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2006 expect(TRUE, r);
2008 ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
2009 "select all notification", FALSE);
2011 /* deselect all items */
2012 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2013 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2014 for (i=0;i<3;i++) {
2015 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
2018 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2019 expect(3, r);
2020 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2021 expect(-1, r);
2023 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2024 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2025 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2026 /* check that style is accepted */
2027 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2028 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2030 for (i=0;i<3;i++) {
2031 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2032 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2034 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2035 expect(3, r);
2036 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2037 expect(3, r);
2039 /* select one more */
2040 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2042 for (i=0;i<3;i++) {
2043 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2044 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2046 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2047 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2049 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2050 expect(1, r);
2051 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2052 expect(-1, r);
2054 /* try to select all on LVS_SINGLESEL */
2055 memset(&item, 0, sizeof(item));
2056 item.stateMask = LVIS_SELECTED;
2057 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2058 expect(TRUE, r);
2059 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2061 item.stateMask = LVIS_SELECTED;
2062 item.state = LVIS_SELECTED;
2063 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2064 expect(FALSE, r);
2066 r = ListView_GetSelectedCount(hwnd);
2067 expect(0, r);
2068 r = ListView_GetSelectionMark(hwnd);
2069 expect(-1, r);
2071 /* try to deselect all on LVS_SINGLESEL */
2072 item.stateMask = LVIS_SELECTED;
2073 item.state = LVIS_SELECTED;
2074 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2075 expect(TRUE, r);
2077 item.stateMask = LVIS_SELECTED;
2078 item.state = 0;
2079 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2080 expect(TRUE, r);
2081 r = ListView_GetSelectedCount(hwnd);
2082 expect(0, r);
2084 DestroyWindow(hwnd);
2087 static void test_subitem_rect(void)
2089 HWND hwnd;
2090 DWORD r;
2091 LVCOLUMN col;
2092 RECT rect;
2093 INT arr[3];
2095 /* test LVM_GETSUBITEMRECT for header */
2096 hwnd = create_listview_control(LVS_REPORT);
2097 ok(hwnd != NULL, "failed to create a listview window\n");
2098 /* add some columns */
2099 memset(&col, 0, sizeof(LVCOLUMN));
2100 col.mask = LVCF_WIDTH;
2101 col.cx = 100;
2102 r = -1;
2103 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2104 expect(0, r);
2105 col.cx = 150;
2106 r = -1;
2107 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2108 expect(1, r);
2109 col.cx = 200;
2110 r = -1;
2111 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2112 expect(2, r);
2113 /* item = -1 means header, subitem index is 1 based */
2114 rect.left = LVIR_BOUNDS;
2115 rect.top = 0;
2116 rect.right = rect.bottom = 0;
2117 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2118 expect(0, r);
2120 rect.left = LVIR_BOUNDS;
2121 rect.top = 1;
2122 rect.right = rect.bottom = 0;
2123 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2125 ok(r != 0, "Expected not-null LRESULT\n");
2126 expect(100, rect.left);
2127 expect(250, rect.right);
2128 todo_wine
2129 expect(3, rect.top);
2131 rect.left = LVIR_BOUNDS;
2132 rect.top = 2;
2133 rect.right = rect.bottom = 0;
2134 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2136 ok(r != 0, "Expected not-null LRESULT\n");
2137 expect(250, rect.left);
2138 expect(450, rect.right);
2139 todo_wine
2140 expect(3, rect.top);
2142 /* item LVS_REPORT padding isn't applied to subitems */
2143 insert_item(hwnd, 0);
2145 rect.left = LVIR_BOUNDS;
2146 rect.top = 1;
2147 rect.right = rect.bottom = 0;
2148 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2149 ok(r != 0, "Expected not-null LRESULT\n");
2150 expect(100, rect.left);
2151 expect(250, rect.right);
2153 rect.left = LVIR_ICON;
2154 rect.top = 1;
2155 rect.right = rect.bottom = 0;
2156 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2157 ok(r != 0, "Expected not-null LRESULT\n");
2158 /* no icon attached - zero width rectangle, with no left padding */
2159 expect(100, rect.left);
2160 expect(100, rect.right);
2162 rect.left = LVIR_LABEL;
2163 rect.top = 1;
2164 rect.right = rect.bottom = 0;
2165 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2166 ok(r != 0, "Expected not-null LRESULT\n");
2167 /* same as full LVIR_BOUNDS */
2168 expect(100, rect.left);
2169 expect(250, rect.right);
2171 SendMessage(hwnd, LVM_SCROLL, 10, 0);
2173 rect.left = LVIR_BOUNDS;
2174 rect.top = 1;
2175 rect.right = rect.bottom = 0;
2176 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2177 ok(r != 0, "Expected not-null LRESULT\n");
2178 expect(90, rect.left);
2179 expect(240, rect.right);
2181 SendMessage(hwnd, LVM_SCROLL, -10, 0);
2183 DestroyWindow(hwnd);
2185 /* test subitem rects after re-arranging columns */
2186 hwnd = create_listview_control(LVS_REPORT);
2187 ok(hwnd != NULL, "failed to create a listview window\n");
2188 memset(&col, 0, sizeof(LVCOLUMN));
2189 col.mask = LVCF_WIDTH;
2191 col.cx = 100;
2192 r = -1;
2193 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2194 expect(0, r);
2196 col.cx = 200;
2197 r = -1;
2198 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2199 expect(1, r);
2201 col.cx = 300;
2202 r = -1;
2203 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2204 expect(2, r);
2206 insert_item(hwnd, 0);
2208 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2209 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2210 expect(TRUE, r);
2212 rect.left = LVIR_BOUNDS;
2213 rect.top = 0;
2214 rect.right = rect.bottom = -1;
2215 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2216 ok(r != 0, "Expected not-null LRESULT\n");
2217 expect(0, rect.left);
2218 expect(600, rect.right);
2220 rect.left = LVIR_BOUNDS;
2221 rect.top = 1;
2222 rect.right = rect.bottom = -1;
2223 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2224 ok(r != 0, "Expected not-null LRESULT\n");
2225 expect(0, rect.left);
2226 expect(200, rect.right);
2228 rect.left = LVIR_BOUNDS;
2229 rect.top = 2;
2230 rect.right = rect.bottom = -1;
2231 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2232 ok(r != 0, "Expected not-null LRESULT\n");
2233 expect(300, rect.left);
2234 expect(600, rect.right);
2236 DestroyWindow(hwnd);
2238 /* try it for non LVS_REPORT style */
2239 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2240 GetModuleHandle(NULL), 0);
2241 rect.left = LVIR_BOUNDS;
2242 rect.top = 1;
2243 rect.right = rect.bottom = -10;
2244 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2245 ok(r == 0, "Expected not-null LRESULT\n");
2246 /* rect is unchanged */
2247 expect(0, rect.left);
2248 expect(-10, rect.right);
2249 expect(1, rect.top);
2250 expect(-10, rect.bottom);
2251 DestroyWindow(hwnd);
2254 /* comparison callback for test_sorting */
2255 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2257 if (first == second) return 0;
2258 return (first > second ? 1 : -1);
2261 static void test_sorting(void)
2263 HWND hwnd;
2264 LVITEMA item = {0};
2265 DWORD r;
2266 LONG_PTR style;
2267 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2268 CHAR buff[10];
2270 hwnd = create_listview_control(LVS_REPORT);
2271 ok(hwnd != NULL, "failed to create a listview window\n");
2273 /* insert some items */
2274 item.mask = LVIF_PARAM | LVIF_STATE;
2275 item.state = LVIS_SELECTED;
2276 item.iItem = 0;
2277 item.iSubItem = 0;
2278 item.lParam = 3;
2279 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2280 expect(0, r);
2282 item.mask = LVIF_PARAM;
2283 item.iItem = 1;
2284 item.iSubItem = 0;
2285 item.lParam = 2;
2286 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2287 expect(1, r);
2289 item.mask = LVIF_STATE | LVIF_PARAM;
2290 item.state = LVIS_SELECTED;
2291 item.iItem = 2;
2292 item.iSubItem = 0;
2293 item.lParam = 4;
2294 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2295 expect(2, r);
2297 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2298 expect(-1, r);
2300 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2301 expect(2, r);
2303 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2304 expect(TRUE, r);
2306 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2307 expect(2, r);
2308 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2309 expect(-1, r);
2310 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2311 expect(0, r);
2312 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2313 expect(LVIS_SELECTED, r);
2314 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2315 expect(LVIS_SELECTED, r);
2317 DestroyWindow(hwnd);
2319 /* switch to LVS_SORTASCENDING when some items added */
2320 hwnd = create_listview_control(LVS_REPORT);
2321 ok(hwnd != NULL, "failed to create a listview window\n");
2323 item.mask = LVIF_TEXT;
2324 item.iItem = 0;
2325 item.iSubItem = 0;
2326 item.pszText = names[1];
2327 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2328 expect(0, r);
2330 item.mask = LVIF_TEXT;
2331 item.iItem = 1;
2332 item.iSubItem = 0;
2333 item.pszText = names[2];
2334 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2335 expect(1, r);
2337 item.mask = LVIF_TEXT;
2338 item.iItem = 2;
2339 item.iSubItem = 0;
2340 item.pszText = names[0];
2341 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2342 expect(2, r);
2344 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2345 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2346 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2347 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2349 /* no sorting performed when switched to LVS_SORTASCENDING */
2350 item.mask = LVIF_TEXT;
2351 item.iItem = 0;
2352 item.pszText = buff;
2353 item.cchTextMax = sizeof(buff);
2354 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2355 expect(TRUE, r);
2356 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2358 item.iItem = 1;
2359 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2360 expect(TRUE, r);
2361 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2363 item.iItem = 2;
2364 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2365 expect(TRUE, r);
2366 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2368 /* adding new item doesn't resort list */
2369 item.mask = LVIF_TEXT;
2370 item.iItem = 3;
2371 item.iSubItem = 0;
2372 item.pszText = names[3];
2373 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2374 expect(3, r);
2376 item.mask = LVIF_TEXT;
2377 item.iItem = 0;
2378 item.pszText = buff;
2379 item.cchTextMax = sizeof(buff);
2380 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2381 expect(TRUE, r);
2382 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2384 item.iItem = 1;
2385 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2386 expect(TRUE, r);
2387 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2389 item.iItem = 2;
2390 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2391 expect(TRUE, r);
2392 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2394 item.iItem = 3;
2395 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2396 expect(TRUE, r);
2397 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2399 /* corner case - item should be placed at first position */
2400 item.mask = LVIF_TEXT;
2401 item.iItem = 4;
2402 item.iSubItem = 0;
2403 item.pszText = names[4];
2404 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2405 expect(0, r);
2407 item.iItem = 0;
2408 item.pszText = buff;
2409 item.cchTextMax = sizeof(buff);
2410 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2411 expect(TRUE, r);
2412 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2414 item.iItem = 1;
2415 item.pszText = buff;
2416 item.cchTextMax = sizeof(buff);
2417 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2418 expect(TRUE, r);
2419 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2421 item.iItem = 2;
2422 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2423 expect(TRUE, r);
2424 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2426 item.iItem = 3;
2427 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2428 expect(TRUE, r);
2429 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2431 item.iItem = 4;
2432 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2433 expect(TRUE, r);
2434 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2436 DestroyWindow(hwnd);
2439 static void test_ownerdata(void)
2441 HWND hwnd;
2442 LONG_PTR style, ret;
2443 DWORD res;
2444 LVITEMA item;
2446 /* it isn't possible to set LVS_OWNERDATA after creation */
2447 if (g_is_below_5)
2449 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2451 else
2453 hwnd = create_listview_control(LVS_REPORT);
2454 ok(hwnd != NULL, "failed to create a listview window\n");
2455 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2456 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2458 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2460 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2461 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2462 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2463 "try to switch to LVS_OWNERDATA seq", FALSE);
2465 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2466 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2467 DestroyWindow(hwnd);
2470 /* try to set LVS_OWNERDATA after creation just having it */
2471 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2472 ok(hwnd != NULL, "failed to create a listview window\n");
2473 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2474 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2476 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2478 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2479 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2480 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2481 "try to switch to LVS_OWNERDATA seq", FALSE);
2482 DestroyWindow(hwnd);
2484 /* try to remove LVS_OWNERDATA after creation just having it */
2485 if (g_is_below_5)
2487 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2489 else
2491 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2492 ok(hwnd != NULL, "failed to create a listview window\n");
2493 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2494 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2496 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2498 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2499 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2500 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2501 "try to switch to LVS_OWNERDATA seq", FALSE);
2502 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2503 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2504 DestroyWindow(hwnd);
2507 /* try select an item */
2508 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2509 ok(hwnd != NULL, "failed to create a listview window\n");
2510 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2511 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2512 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2513 expect(0, res);
2514 memset(&item, 0, sizeof(item));
2515 item.stateMask = LVIS_SELECTED;
2516 item.state = LVIS_SELECTED;
2517 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2518 expect(TRUE, res);
2519 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2520 expect(1, res);
2521 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2522 expect(1, res);
2523 DestroyWindow(hwnd);
2525 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2526 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2527 ok(hwnd != NULL, "failed to create a listview window\n");
2528 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2529 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2530 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2531 expect(1, res);
2532 memset(&item, 0, sizeof(item));
2533 item.mask = LVIF_STATE;
2534 item.iItem = 0;
2535 item.stateMask = LVIS_SELECTED;
2536 item.state = LVIS_SELECTED;
2537 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2538 expect(FALSE, res);
2539 DestroyWindow(hwnd);
2541 /* check notifications after focused/selected changed */
2542 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2543 ok(hwnd != NULL, "failed to create a listview window\n");
2544 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2545 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2547 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2549 memset(&item, 0, sizeof(item));
2550 item.stateMask = LVIS_SELECTED;
2551 item.state = LVIS_SELECTED;
2552 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2553 expect(TRUE, res);
2555 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2556 "ownerdata select notification", TRUE);
2558 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2560 memset(&item, 0, sizeof(item));
2561 item.stateMask = LVIS_FOCUSED;
2562 item.state = LVIS_FOCUSED;
2563 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2564 expect(TRUE, res);
2566 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2567 "ownerdata focus notification", TRUE);
2569 /* select all, check notifications */
2570 item.stateMask = LVIS_SELECTED;
2571 item.state = 0;
2572 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2573 expect(TRUE, res);
2575 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2577 item.stateMask = LVIS_SELECTED;
2578 item.state = LVIS_SELECTED;
2580 g_dump_itemchanged = TRUE;
2581 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2582 expect(TRUE, res);
2583 g_dump_itemchanged = FALSE;
2585 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2586 "ownerdata select all notification", TRUE);
2588 /* select all again, note that all items are selected already */
2589 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2590 item.stateMask = LVIS_SELECTED;
2591 item.state = LVIS_SELECTED;
2592 g_dump_itemchanged = TRUE;
2593 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2594 expect(TRUE, res);
2595 g_dump_itemchanged = FALSE;
2596 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2597 "ownerdata select all notification", TRUE);
2598 /* deselect all */
2599 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2600 item.stateMask = LVIS_SELECTED;
2601 item.state = 0;
2602 g_dump_itemchanged = TRUE;
2603 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2604 expect(TRUE, res);
2605 g_dump_itemchanged = FALSE;
2606 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2607 "ownerdata deselect all notification", TRUE);
2609 /* select one, then deselect all */
2610 item.stateMask = LVIS_SELECTED;
2611 item.state = LVIS_SELECTED;
2612 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2613 expect(TRUE, res);
2614 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2615 item.stateMask = LVIS_SELECTED;
2616 item.state = 0;
2617 g_dump_itemchanged = TRUE;
2618 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2619 expect(TRUE, res);
2620 g_dump_itemchanged = FALSE;
2621 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2622 "ownerdata select all notification", TRUE);
2624 /* remove focused, try to focus all */
2625 item.stateMask = LVIS_FOCUSED;
2626 item.state = LVIS_FOCUSED;
2627 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2628 expect(TRUE, res);
2629 item.stateMask = LVIS_FOCUSED;
2630 item.state = 0;
2631 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2632 expect(TRUE, res);
2633 item.stateMask = LVIS_FOCUSED;
2634 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
2635 expect(0, res);
2636 /* setting all to focused returns failure value */
2637 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2638 item.stateMask = LVIS_FOCUSED;
2639 item.state = LVIS_FOCUSED;
2640 g_dump_itemchanged = TRUE;
2641 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2642 expect(FALSE, res);
2643 g_dump_itemchanged = FALSE;
2644 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2645 "ownerdata focus all notification", FALSE);
2646 /* focus single item, remove all */
2647 item.stateMask = LVIS_FOCUSED;
2648 item.state = LVIS_FOCUSED;
2649 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2650 expect(TRUE, res);
2651 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2652 item.stateMask = LVIS_FOCUSED;
2653 item.state = 0;
2654 g_dump_itemchanged = TRUE;
2655 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2656 expect(TRUE, res);
2657 g_dump_itemchanged = FALSE;
2658 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
2659 "ownerdata remove focus all notification", TRUE);
2660 /* set all cut */
2661 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2662 item.stateMask = LVIS_CUT;
2663 item.state = LVIS_CUT;
2664 g_dump_itemchanged = TRUE;
2665 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2666 expect(TRUE, res);
2667 g_dump_itemchanged = FALSE;
2668 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2669 "ownerdata cut all notification", TRUE);
2670 /* all marked cut, try again */
2671 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2672 item.stateMask = LVIS_CUT;
2673 item.state = LVIS_CUT;
2674 g_dump_itemchanged = TRUE;
2675 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2676 expect(TRUE, res);
2677 g_dump_itemchanged = FALSE;
2678 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2679 "ownerdata cut all notification #2", TRUE);
2681 DestroyWindow(hwnd);
2683 /* check notifications on LVM_GETITEM */
2684 /* zero callback mask */
2685 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2686 ok(hwnd != NULL, "failed to create a listview window\n");
2687 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2688 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2690 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2692 memset(&item, 0, sizeof(item));
2693 item.stateMask = LVIS_SELECTED;
2694 item.mask = LVIF_STATE;
2695 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2696 expect(TRUE, res);
2698 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2699 "ownerdata getitem selected state 1", FALSE);
2701 /* non zero callback mask but not we asking for */
2702 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2703 expect(TRUE, res);
2705 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2707 memset(&item, 0, sizeof(item));
2708 item.stateMask = LVIS_SELECTED;
2709 item.mask = LVIF_STATE;
2710 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2711 expect(TRUE, res);
2713 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2714 "ownerdata getitem selected state 2", FALSE);
2716 /* LVIS_OVERLAYMASK callback mask, asking for index */
2717 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2719 memset(&item, 0, sizeof(item));
2720 item.stateMask = LVIS_OVERLAYMASK;
2721 item.mask = LVIF_STATE;
2722 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2723 expect(TRUE, res);
2725 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2726 "ownerdata getitem selected state 2", FALSE);
2728 DestroyWindow(hwnd);
2730 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2731 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
2732 ok(hwnd != NULL, "failed to create a listview window\n");
2733 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2734 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2735 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2736 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2737 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2738 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2739 DestroyWindow(hwnd);
2740 /* apparently it's allowed to switch these style on after creation */
2741 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2742 ok(hwnd != NULL, "failed to create a listview window\n");
2743 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2744 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2745 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2746 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2747 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2748 DestroyWindow(hwnd);
2750 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2751 ok(hwnd != NULL, "failed to create a listview window\n");
2752 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2753 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2754 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2755 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2756 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2757 DestroyWindow(hwnd);
2760 static void test_norecompute(void)
2762 static CHAR testA[] = "test";
2763 CHAR buff[10];
2764 LVITEMA item;
2765 HWND hwnd;
2766 DWORD res;
2768 /* self containing control */
2769 hwnd = create_listview_control(LVS_REPORT);
2770 ok(hwnd != NULL, "failed to create a listview window\n");
2771 memset(&item, 0, sizeof(item));
2772 item.mask = LVIF_TEXT | LVIF_STATE;
2773 item.iItem = 0;
2774 item.stateMask = LVIS_SELECTED;
2775 item.state = LVIS_SELECTED;
2776 item.pszText = testA;
2777 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2778 expect(0, res);
2779 /* retrieve with LVIF_NORECOMPUTE */
2780 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2781 item.iItem = 0;
2782 item.pszText = buff;
2783 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2784 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2785 expect(TRUE, res);
2786 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2788 item.mask = LVIF_TEXT;
2789 item.iItem = 1;
2790 item.pszText = LPSTR_TEXTCALLBACK;
2791 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2792 expect(1, res);
2794 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2795 item.iItem = 1;
2796 item.pszText = buff;
2797 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2799 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2800 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2801 expect(TRUE, res);
2802 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2803 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2804 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2806 DestroyWindow(hwnd);
2808 /* LVS_OWNERDATA */
2809 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2810 ok(hwnd != NULL, "failed to create a listview window\n");
2812 item.mask = LVIF_STATE;
2813 item.stateMask = LVIS_SELECTED;
2814 item.state = LVIS_SELECTED;
2815 item.iItem = 0;
2816 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2817 expect(0, res);
2819 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2820 item.iItem = 0;
2821 item.pszText = buff;
2822 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2823 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2824 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2825 expect(TRUE, res);
2826 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2827 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2828 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2830 DestroyWindow(hwnd);
2833 static void test_nosortheader(void)
2835 HWND hwnd, header;
2836 LONG_PTR style;
2838 hwnd = create_listview_control(LVS_REPORT);
2839 ok(hwnd != NULL, "failed to create a listview window\n");
2841 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2842 ok(IsWindow(header), "header expected\n");
2844 style = GetWindowLongPtr(header, GWL_STYLE);
2845 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2847 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2848 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2849 /* HDS_BUTTONS retained */
2850 style = GetWindowLongPtr(header, GWL_STYLE);
2851 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2853 DestroyWindow(hwnd);
2855 /* create with LVS_NOSORTHEADER */
2856 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
2857 ok(hwnd != NULL, "failed to create a listview window\n");
2859 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2860 ok(IsWindow(header), "header expected\n");
2862 style = GetWindowLongPtr(header, GWL_STYLE);
2863 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2865 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2866 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2867 /* not changed here */
2868 style = GetWindowLongPtr(header, GWL_STYLE);
2869 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2871 DestroyWindow(hwnd);
2874 static void test_setredraw(void)
2876 HWND hwnd;
2877 DWORD_PTR style;
2878 DWORD ret;
2879 HDC hdc;
2880 RECT rect;
2882 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2883 ok(hwnd != NULL, "failed to create a listview window\n");
2885 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2886 ListView seems to handle it internally without DefWinProc */
2888 /* default value first */
2889 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2890 expect(0, ret);
2891 /* disable */
2892 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2893 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2894 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2895 expect(0, ret);
2896 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2897 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2898 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2899 expect(0, ret);
2901 /* check update rect after redrawing */
2902 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2903 expect(0, ret);
2904 InvalidateRect(hwnd, NULL, FALSE);
2905 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
2906 rect.right = rect.bottom = 1;
2907 GetUpdateRect(hwnd, &rect, FALSE);
2908 expect(0, rect.right);
2909 expect(0, rect.bottom);
2911 /* WM_ERASEBKGND */
2912 hdc = GetWindowDC(hwndparent);
2913 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2914 expect(TRUE, ret);
2915 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2916 expect(0, ret);
2917 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2918 expect(TRUE, ret);
2919 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2920 expect(0, ret);
2921 ReleaseDC(hwndparent, hdc);
2923 /* check notification messages to show that repainting is disabled */
2924 ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
2925 expect(TRUE, ret);
2926 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2927 expect(0, ret);
2928 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2930 InvalidateRect(hwnd, NULL, TRUE);
2931 UpdateWindow(hwnd);
2932 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2933 "redraw after WM_SETREDRAW (FALSE)", FALSE);
2935 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
2936 expect(TRUE, ret);
2937 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2938 InvalidateRect(hwnd, NULL, TRUE);
2939 UpdateWindow(hwnd);
2940 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2941 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
2943 /* message isn't forwarded to header */
2944 subclass_header(hwnd);
2945 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2946 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2947 expect(0, ret);
2948 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
2949 "WM_SETREDRAW: not forwarded to header", FALSE);
2951 DestroyWindow(hwnd);
2954 static void test_hittest(void)
2956 HWND hwnd;
2957 DWORD r;
2958 RECT bounds;
2959 LVITEMA item;
2960 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2961 POINT pos;
2962 INT x, y;
2963 HIMAGELIST himl, himl2;
2964 HBITMAP hbmp;
2966 hwnd = create_listview_control(LVS_REPORT);
2967 ok(hwnd != NULL, "failed to create a listview window\n");
2969 /* LVS_REPORT with a single subitem (2 columns) */
2970 insert_column(hwnd, 0);
2971 insert_column(hwnd, 1);
2972 insert_item(hwnd, 0);
2974 item.iSubItem = 0;
2975 /* the only purpose of that line is to be as long as a half item rect */
2976 item.pszText = text;
2977 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2978 expect(TRUE, r);
2980 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2981 expect(TRUE, r);
2982 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
2983 expect(TRUE, r);
2985 memset(&bounds, 0, sizeof(bounds));
2986 bounds.left = LVIR_BOUNDS;
2987 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
2988 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
2989 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
2990 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
2991 expect(TRUE, r);
2993 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2995 /* outside columns by x position - valid is [0, 199] */
2996 x = -1;
2997 y = pos.y + (bounds.bottom - bounds.top) / 2;
2998 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
2999 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3001 x = pos.x + 50; /* column half width */
3002 y = pos.y + (bounds.bottom - bounds.top) / 2;
3003 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3004 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3005 x = pos.x + 150; /* outside column */
3006 y = pos.y + (bounds.bottom - bounds.top) / 2;
3007 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3008 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3009 y = (bounds.bottom - bounds.top) / 2;
3010 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3011 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3012 /* outside possible client rectangle (to right) */
3013 x = pos.x + 500;
3014 y = pos.y + (bounds.bottom - bounds.top) / 2;
3015 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3016 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3017 y = (bounds.bottom - bounds.top) / 2;
3018 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3019 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3020 /* subitem returned with -1 item too */
3021 x = pos.x + 150;
3022 y = -10;
3023 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3024 /* parent client area is 100x100 by default */
3025 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3026 x = pos.x + 150; /* outside column */
3027 y = pos.y + (bounds.bottom - bounds.top) / 2;
3028 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3029 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3030 y = (bounds.bottom - bounds.top) / 2;
3031 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3032 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3033 /* the same with LVS_EX_FULLROWSELECT */
3034 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3035 x = pos.x + 150; /* outside column */
3036 y = pos.y + (bounds.bottom - bounds.top) / 2;
3037 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3038 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3039 y = (bounds.bottom - bounds.top) / 2;
3040 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3041 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3042 x = pos.x + 150; /* outside column */
3043 y = pos.y + (bounds.bottom - bounds.top) / 2;
3044 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3045 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3046 y = (bounds.bottom - bounds.top) / 2;
3047 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3048 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3049 /* outside possible client rectangle (to right) */
3050 x = pos.x + 500;
3051 y = pos.y + (bounds.bottom - bounds.top) / 2;
3052 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3053 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3054 y = (bounds.bottom - bounds.top) / 2;
3055 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3056 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3057 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3058 himl = ImageList_Create(16, 16, 0, 4, 4);
3059 ok(himl != NULL, "failed to create imagelist\n");
3060 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3061 ok(hbmp != NULL, "failed to create bitmap\n");
3062 r = ImageList_Add(himl, hbmp, 0);
3063 ok(r == 0, "should be zero\n");
3064 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3065 ok(hbmp != NULL, "failed to create bitmap\n");
3066 r = ImageList_Add(himl, hbmp, 0);
3067 ok(r == 1, "should be one\n");
3069 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3070 ok(r == 0, "should return zero\n");
3072 item.mask = LVIF_IMAGE;
3073 item.iImage = 0;
3074 item.iItem = 0;
3075 item.iSubItem = 0;
3076 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3077 expect(TRUE, r);
3078 /* on state icon */
3079 x = pos.x + 8;
3080 y = pos.y + (bounds.bottom - bounds.top) / 2;
3081 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3082 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3083 y = (bounds.bottom - bounds.top) / 2;
3084 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3086 /* state icons indices are 1 based, check with valid index */
3087 item.mask = LVIF_STATE;
3088 item.state = INDEXTOSTATEIMAGEMASK(1);
3089 item.stateMask = LVIS_STATEIMAGEMASK;
3090 item.iItem = 0;
3091 item.iSubItem = 0;
3092 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3093 expect(TRUE, r);
3094 /* on state icon */
3095 x = pos.x + 8;
3096 y = pos.y + (bounds.bottom - bounds.top) / 2;
3097 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3098 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3099 y = (bounds.bottom - bounds.top) / 2;
3100 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3102 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3103 ok(himl2 == himl, "should return handle\n");
3105 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3106 ok(r == 0, "should return zero\n");
3107 /* on item icon */
3108 x = pos.x + 8;
3109 y = pos.y + (bounds.bottom - bounds.top) / 2;
3110 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3111 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3112 y = (bounds.bottom - bounds.top) / 2;
3113 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3115 DestroyWindow(hwnd);
3118 static void test_getviewrect(void)
3120 HWND hwnd;
3121 DWORD r;
3122 RECT rect;
3123 LVITEMA item;
3125 hwnd = create_listview_control(LVS_REPORT);
3126 ok(hwnd != NULL, "failed to create a listview window\n");
3128 /* empty */
3129 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3130 expect(TRUE, r);
3132 insert_column(hwnd, 0);
3133 insert_column(hwnd, 1);
3135 memset(&item, 0, sizeof(item));
3136 item.iItem = 0;
3137 item.iSubItem = 0;
3138 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3140 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3141 expect(TRUE, r);
3142 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3143 expect(TRUE, r);
3145 rect.left = rect.right = rect.top = rect.bottom = -1;
3146 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3147 expect(TRUE, r);
3148 /* left is set to (2e31-1) - XP SP2 */
3149 expect(0, rect.right);
3150 expect(0, rect.top);
3151 expect(0, rect.bottom);
3153 /* switch to LVS_ICON */
3154 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3156 rect.left = rect.right = rect.top = rect.bottom = -1;
3157 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3158 expect(TRUE, r);
3159 expect(0, rect.left);
3160 expect(0, rect.top);
3161 /* precise value differs for 2k, XP and Vista */
3162 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3163 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3165 DestroyWindow(hwnd);
3168 static void test_getitemposition(void)
3170 HWND hwnd, header;
3171 DWORD r;
3172 POINT pt;
3173 RECT rect;
3175 hwnd = create_listview_control(LVS_REPORT);
3176 ok(hwnd != NULL, "failed to create a listview window\n");
3177 header = subclass_header(hwnd);
3179 /* LVS_REPORT, single item, no columns added */
3180 insert_item(hwnd, 0);
3182 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3184 pt.x = pt.y = -1;
3185 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3186 expect(TRUE, r);
3187 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3189 /* LVS_REPORT, single item, single column */
3190 insert_column(hwnd, 0);
3192 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3194 pt.x = pt.y = -1;
3195 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3196 expect(TRUE, r);
3197 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3199 memset(&rect, 0, sizeof(rect));
3200 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3201 /* some padding? */
3202 expect(2, pt.x);
3203 /* offset by header height */
3204 expect(rect.bottom - rect.top, pt.y);
3206 DestroyWindow(hwnd);
3209 static void test_columnscreation(void)
3211 HWND hwnd, header;
3212 DWORD r;
3214 hwnd = create_listview_control(LVS_REPORT);
3215 ok(hwnd != NULL, "failed to create a listview window\n");
3217 insert_item(hwnd, 0);
3219 /* headers columns aren't created automatically */
3220 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3221 ok(IsWindow(header), "Expected header handle\n");
3222 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3223 expect(0, r);
3225 DestroyWindow(hwnd);
3228 static void test_getitemrect(void)
3230 HWND hwnd;
3231 HIMAGELIST himl;
3232 HBITMAP hbm;
3233 RECT rect;
3234 DWORD r;
3235 LVITEMA item;
3236 LVCOLUMNA col;
3237 INT order[2];
3238 POINT pt;
3240 /* rectangle isn't empty for empty text items */
3241 hwnd = create_listview_control(LVS_LIST);
3242 memset(&item, 0, sizeof(item));
3243 item.mask = 0;
3244 item.iItem = 0;
3245 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3246 expect(0, r);
3247 rect.left = LVIR_LABEL;
3248 SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3249 expect(0, rect.left);
3250 expect(0, rect.top);
3251 todo_wine expect(96, rect.right);
3252 DestroyWindow(hwnd);
3254 hwnd = create_listview_control(LVS_REPORT);
3255 ok(hwnd != NULL, "failed to create a listview window\n");
3257 /* empty item */
3258 memset(&item, 0, sizeof(item));
3259 item.iItem = 0;
3260 item.iSubItem = 0;
3261 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3262 expect(0, r);
3264 rect.left = LVIR_BOUNDS;
3265 rect.right = rect.top = rect.bottom = -1;
3266 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3267 expect(TRUE, r);
3269 /* zero width rectangle with no padding */
3270 expect(0, rect.left);
3271 expect(0, rect.right);
3273 insert_column(hwnd, 0);
3274 insert_column(hwnd, 1);
3276 col.mask = LVCF_WIDTH;
3277 col.cx = 50;
3278 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3279 expect(TRUE, r);
3281 col.mask = LVCF_WIDTH;
3282 col.cx = 100;
3283 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3284 expect(TRUE, r);
3286 rect.left = LVIR_BOUNDS;
3287 rect.right = rect.top = rect.bottom = -1;
3288 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3289 expect(TRUE, r);
3291 /* still no left padding */
3292 expect(0, rect.left);
3293 expect(150, rect.right);
3295 rect.left = LVIR_SELECTBOUNDS;
3296 rect.right = rect.top = rect.bottom = -1;
3297 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3298 expect(TRUE, r);
3299 /* padding */
3300 expect(2, rect.left);
3302 rect.left = LVIR_LABEL;
3303 rect.right = rect.top = rect.bottom = -1;
3304 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3305 expect(TRUE, r);
3306 /* padding, column width */
3307 expect(2, rect.left);
3308 expect(50, rect.right);
3310 /* no icons attached */
3311 rect.left = LVIR_ICON;
3312 rect.right = rect.top = rect.bottom = -1;
3313 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3314 expect(TRUE, r);
3315 /* padding */
3316 expect(2, rect.left);
3317 expect(2, rect.right);
3319 /* change order */
3320 order[0] = 1; order[1] = 0;
3321 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3322 expect(TRUE, r);
3323 pt.x = -1;
3324 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3325 expect(TRUE, r);
3326 /* 1 indexed column width + padding */
3327 expect(102, pt.x);
3328 /* rect is at zero too */
3329 rect.left = LVIR_BOUNDS;
3330 rect.right = rect.top = rect.bottom = -1;
3331 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3332 expect(TRUE, r);
3333 expect(0, rect.left);
3334 /* just width sum */
3335 expect(150, rect.right);
3337 rect.left = LVIR_SELECTBOUNDS;
3338 rect.right = rect.top = rect.bottom = -1;
3339 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3340 expect(TRUE, r);
3341 /* column width + padding */
3342 expect(102, rect.left);
3344 /* back to initial order */
3345 order[0] = 0; order[1] = 1;
3346 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3347 expect(TRUE, r);
3349 /* state icons */
3350 himl = ImageList_Create(16, 16, 0, 2, 2);
3351 ok(himl != NULL, "failed to create imagelist\n");
3352 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3353 ok(hbm != NULL, "failed to create bitmap\n");
3354 r = ImageList_Add(himl, hbm, 0);
3355 ok(r == 0, "should be zero\n");
3356 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3357 ok(hbm != NULL, "failed to create bitmap\n");
3358 r = ImageList_Add(himl, hbm, 0);
3359 ok(r == 1, "should be one\n");
3361 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3362 ok(r == 0, "should return zero\n");
3364 item.mask = LVIF_STATE;
3365 item.state = INDEXTOSTATEIMAGEMASK(1);
3366 item.stateMask = LVIS_STATEIMAGEMASK;
3367 item.iItem = 0;
3368 item.iSubItem = 0;
3369 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3370 expect(TRUE, r);
3372 /* icon bounds */
3373 rect.left = LVIR_ICON;
3374 rect.right = rect.top = rect.bottom = -1;
3375 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3376 expect(TRUE, r);
3377 /* padding + stateicon width */
3378 expect(18, rect.left);
3379 expect(18, rect.right);
3380 /* label bounds */
3381 rect.left = LVIR_LABEL;
3382 rect.right = rect.top = rect.bottom = -1;
3383 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3384 expect(TRUE, r);
3385 /* padding + stateicon width -> column width */
3386 expect(18, rect.left);
3387 expect(50, rect.right);
3389 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3390 ok(r != 0, "should return current list handle\n");
3392 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3393 ok(r == 0, "should return zero\n");
3395 item.mask = LVIF_STATE | LVIF_IMAGE;
3396 item.iImage = 1;
3397 item.state = 0;
3398 item.stateMask = ~0;
3399 item.iItem = 0;
3400 item.iSubItem = 0;
3401 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3402 expect(TRUE, r);
3404 /* icon bounds */
3405 rect.left = LVIR_ICON;
3406 rect.right = rect.top = rect.bottom = -1;
3407 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3408 expect(TRUE, r);
3409 /* padding, icon width */
3410 expect(2, rect.left);
3411 expect(18, rect.right);
3412 /* label bounds */
3413 rect.left = LVIR_LABEL;
3414 rect.right = rect.top = rect.bottom = -1;
3415 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3416 expect(TRUE, r);
3417 /* padding + icon width -> column width */
3418 expect(18, rect.left);
3419 expect(50, rect.right);
3421 /* select bounds */
3422 rect.left = LVIR_SELECTBOUNDS;
3423 rect.right = rect.top = rect.bottom = -1;
3424 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3425 expect(TRUE, r);
3426 /* padding, column width */
3427 expect(2, rect.left);
3428 expect(50, rect.right);
3430 /* try with indentation */
3431 item.mask = LVIF_INDENT;
3432 item.iIndent = 1;
3433 item.iItem = 0;
3434 item.iSubItem = 0;
3435 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3436 expect(TRUE, r);
3438 /* bounds */
3439 rect.left = LVIR_BOUNDS;
3440 rect.right = rect.top = rect.bottom = -1;
3441 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3442 expect(TRUE, r);
3443 /* padding + 1 icon width, column width */
3444 expect(0, rect.left);
3445 expect(150, rect.right);
3447 /* select bounds */
3448 rect.left = LVIR_SELECTBOUNDS;
3449 rect.right = rect.top = rect.bottom = -1;
3450 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3451 expect(TRUE, r);
3452 /* padding + 1 icon width, column width */
3453 expect(2 + 16, rect.left);
3454 expect(50, rect.right);
3456 /* label bounds */
3457 rect.left = LVIR_LABEL;
3458 rect.right = rect.top = rect.bottom = -1;
3459 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3460 expect(TRUE, r);
3461 /* padding + 2 icon widths, column width */
3462 expect(2 + 16*2, rect.left);
3463 expect(50, rect.right);
3465 /* icon bounds */
3466 rect.left = LVIR_ICON;
3467 rect.right = rect.top = rect.bottom = -1;
3468 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3469 expect(TRUE, r);
3470 /* padding + 1 icon width indentation, icon width */
3471 expect(2 + 16, rect.left);
3472 expect(34, rect.right);
3474 DestroyWindow(hwnd);
3477 static void test_editbox(void)
3479 static CHAR testitemA[] = "testitem";
3480 static CHAR testitem1A[] = "testitem_quitelongname";
3481 static CHAR buffer[25];
3482 HWND hwnd, hwndedit, hwndedit2, header;
3483 LVITEMA item;
3484 DWORD r;
3486 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3487 ok(hwnd != NULL, "failed to create a listview window\n");
3489 insert_column(hwnd, 0);
3491 memset(&item, 0, sizeof(item));
3492 item.mask = LVIF_TEXT;
3493 item.pszText = testitemA;
3494 item.iItem = 0;
3495 item.iSubItem = 0;
3496 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3497 expect(0, r);
3499 /* setting focus is necessary */
3500 SetFocus(hwnd);
3501 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3502 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3504 /* test children Z-order after Edit box created */
3505 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3506 ok(IsWindow(header), "Expected header to be created\n");
3507 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3508 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3510 /* modify initial string */
3511 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3512 expect(TRUE, r);
3514 /* edit window is resized and repositioned,
3515 check again for Z-order - it should be preserved */
3516 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3517 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3519 /* return focus to listview */
3520 SetFocus(hwnd);
3522 memset(&item, 0, sizeof(item));
3523 item.mask = LVIF_TEXT;
3524 item.pszText = buffer;
3525 item.cchTextMax = sizeof(buffer);
3526 item.iItem = 0;
3527 item.iSubItem = 0;
3528 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3529 expect(TRUE, r);
3531 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3533 /* send LVM_EDITLABEL on already created edit */
3534 SetFocus(hwnd);
3535 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3536 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3537 /* focus will be set to edit */
3538 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3539 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3540 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3542 /* creating label disabled when control isn't focused */
3543 SetFocus(0);
3544 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3545 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3547 /* check EN_KILLFOCUS handling */
3548 memset(&item, 0, sizeof(item));
3549 item.pszText = testitemA;
3550 item.iItem = 0;
3551 item.iSubItem = 0;
3552 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3553 expect(TRUE, r);
3555 SetFocus(hwnd);
3556 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3557 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3558 /* modify edit and notify control that it lost focus */
3559 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3560 expect(TRUE, r);
3561 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3562 expect(0, r);
3563 memset(&item, 0, sizeof(item));
3564 item.pszText = buffer;
3565 item.cchTextMax = sizeof(buffer);
3566 item.iItem = 0;
3567 item.iSubItem = 0;
3568 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3569 expect(lstrlen(item.pszText), r);
3570 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3571 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
3572 /* end edit without saving */
3573 SetFocus(hwnd);
3574 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3575 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3576 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3577 expect(0, r);
3578 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3579 "edit box - end edit, no change, escape", TRUE);
3580 /* end edit with saving */
3581 SetFocus(hwnd);
3582 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3583 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3584 r = SendMessage(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
3585 expect(0, r);
3586 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3587 "edit box - end edit, no change, return", TRUE);
3589 memset(&item, 0, sizeof(item));
3590 item.pszText = buffer;
3591 item.cchTextMax = sizeof(buffer);
3592 item.iItem = 0;
3593 item.iSubItem = 0;
3594 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3595 expect(lstrlen(item.pszText), r);
3596 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3598 /* LVM_EDITLABEL with -1 destroys current edit */
3599 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3600 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3601 /* no edit present */
3602 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3603 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3604 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3605 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3606 /* edit present */
3607 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3608 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3609 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3610 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3611 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3612 /* check another negative value */
3613 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3614 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3615 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3616 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3617 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3618 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3619 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3620 /* and value greater than max item index */
3621 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3622 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3623 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3624 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3625 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3626 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3627 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3628 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3630 /* messaging tests */
3631 SetFocus(hwnd);
3632 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3633 blockEdit = FALSE;
3634 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3635 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3636 /* testing only sizing messages */
3637 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3638 "edit box create - sizing", FALSE);
3640 /* WM_COMMAND with EN_KILLFOCUS isn't forwared to parent */
3641 SetFocus(hwnd);
3642 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3643 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3644 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3645 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3646 expect(0, r);
3647 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3648 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
3650 DestroyWindow(hwnd);
3653 static void test_notifyformat(void)
3655 HWND hwnd, header;
3656 DWORD r;
3658 hwnd = create_listview_control(LVS_REPORT);
3659 ok(hwnd != NULL, "failed to create a listview window\n");
3661 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3662 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3663 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3664 expect(0, r);
3665 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3666 /* set */
3667 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3668 expect(0, r);
3669 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3670 if (r == 1)
3672 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3673 expect(1, r);
3674 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3675 expect(0, r);
3677 else
3679 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3680 DestroyWindow(hwnd);
3681 return;
3684 DestroyWindow(hwnd);
3686 /* test failure in parent WM_NOTIFYFORMAT */
3687 notifyFormat = 0;
3688 hwnd = create_listview_control(LVS_REPORT);
3689 ok(hwnd != NULL, "failed to create a listview window\n");
3690 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3691 ok(IsWindow(header), "expected header to be created\n");
3692 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3693 expect(0, r);
3694 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3695 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3696 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3697 ok(r != 0, "Expected valid format\n");
3699 notifyFormat = NFR_UNICODE;
3700 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3701 expect(NFR_UNICODE, r);
3702 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3703 expect(1, r);
3704 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3705 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3707 notifyFormat = NFR_ANSI;
3708 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3709 expect(NFR_ANSI, r);
3710 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3711 expect(0, r);
3712 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3713 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3715 DestroyWindow(hwnd);
3717 /* try different unicode window combination and defaults */
3718 if (!GetModuleHandleW(NULL))
3720 win_skip("Additional notify format tests are incompatible with Win9x\n");
3721 return;
3724 hwndparentW = create_parent_window(TRUE);
3725 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3726 if (!IsWindow(hwndparentW)) return;
3728 notifyFormat = -1;
3729 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3730 ok(hwnd != NULL, "failed to create a listview window\n");
3731 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3732 ok(IsWindow(header), "expected header to be created\n");
3733 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3734 expect(1, r);
3735 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3736 expect(1, r);
3737 DestroyWindow(hwnd);
3738 /* receiving error code defaulting to ansi */
3739 notifyFormat = 0;
3740 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3741 ok(hwnd != NULL, "failed to create a listview window\n");
3742 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3743 ok(IsWindow(header), "expected header to be created\n");
3744 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3745 expect(0, r);
3746 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3747 expect(1, r);
3748 DestroyWindow(hwnd);
3749 /* receiving ansi code from unicode window, use it */
3750 notifyFormat = NFR_ANSI;
3751 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3752 ok(hwnd != NULL, "failed to create a listview window\n");
3753 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3754 ok(IsWindow(header), "expected header to be created\n");
3755 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3756 expect(0, r);
3757 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3758 expect(1, r);
3759 DestroyWindow(hwnd);
3760 /* unicode listview with ansi parent window */
3761 notifyFormat = -1;
3762 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3763 ok(hwnd != NULL, "failed to create a listview window\n");
3764 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3765 ok(IsWindow(header), "expected header to be created\n");
3766 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3767 expect(0, r);
3768 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3769 expect(1, r);
3770 DestroyWindow(hwnd);
3771 /* unicode listview with ansi parent window, return error code */
3772 notifyFormat = 0;
3773 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3774 ok(hwnd != NULL, "failed to create a listview window\n");
3775 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3776 ok(IsWindow(header), "expected header to be created\n");
3777 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3778 expect(0, r);
3779 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3780 expect(1, r);
3781 DestroyWindow(hwnd);
3783 DestroyWindow(hwndparentW);
3786 static void test_indentation(void)
3788 HWND hwnd;
3789 LVITEMA item;
3790 DWORD r;
3792 hwnd = create_listview_control(LVS_REPORT);
3793 ok(hwnd != NULL, "failed to create a listview window\n");
3795 memset(&item, 0, sizeof(item));
3796 item.mask = LVIF_INDENT;
3797 item.iItem = 0;
3798 item.iIndent = I_INDENTCALLBACK;
3799 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3800 expect(0, r);
3802 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3804 item.iItem = 0;
3805 item.mask = LVIF_INDENT;
3806 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3807 expect(TRUE, r);
3809 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3810 "get indent dispinfo", FALSE);
3812 DestroyWindow(hwnd);
3815 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
3817 return 0;
3820 static BOOL is_below_comctl_5(void)
3822 HWND hwnd;
3823 BOOL ret;
3825 hwnd = create_listview_control(LVS_REPORT);
3826 ok(hwnd != NULL, "failed to create a listview window\n");
3827 insert_item(hwnd, 0);
3829 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
3831 DestroyWindow(hwnd);
3833 return !ret;
3836 static void test_get_set_view(void)
3838 HWND hwnd;
3839 DWORD ret;
3840 DWORD_PTR style;
3842 /* test style->view mapping */
3843 hwnd = create_listview_control(LVS_REPORT);
3844 ok(hwnd != NULL, "failed to create a listview window\n");
3846 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3847 expect(LV_VIEW_DETAILS, ret);
3849 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3850 /* LVS_ICON == 0 */
3851 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
3852 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3853 expect(LV_VIEW_ICON, ret);
3855 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3856 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
3857 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3858 expect(LV_VIEW_SMALLICON, ret);
3860 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3861 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
3862 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3863 expect(LV_VIEW_LIST, ret);
3865 /* switching view doesn't touch window style */
3866 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
3867 expect(1, ret);
3868 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3869 ok(style & LVS_LIST, "Expected style to be preserved\n");
3870 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
3871 expect(1, ret);
3872 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3873 ok(style & LVS_LIST, "Expected style to be preserved\n");
3874 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
3875 expect(1, ret);
3876 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3877 ok(style & LVS_LIST, "Expected style to be preserved\n");
3879 DestroyWindow(hwnd);
3882 static void test_canceleditlabel(void)
3884 HWND hwnd, hwndedit;
3885 DWORD ret;
3886 CHAR buff[10];
3887 LVITEMA itema;
3888 static CHAR test[] = "test";
3889 static const CHAR test1[] = "test1";
3891 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3892 ok(hwnd != NULL, "failed to create a listview window\n");
3894 insert_item(hwnd, 0);
3896 /* try without edit created */
3897 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3898 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3899 expect(TRUE, ret);
3900 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3901 "cancel edit label without edit", FALSE);
3903 /* cancel without data change */
3904 SetFocus(hwnd);
3905 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3906 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3907 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3908 expect(TRUE, ret);
3909 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3911 /* cancel after data change */
3912 memset(&itema, 0, sizeof(itema));
3913 itema.pszText = test;
3914 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
3915 expect(TRUE, ret);
3916 SetFocus(hwnd);
3917 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3918 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3919 ret = SetWindowText(hwndedit, test1);
3920 ok(ret != 0, "Expected edit text to change\n");
3921 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3922 expect(TRUE, ret);
3923 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3924 memset(&itema, 0, sizeof(itema));
3925 itema.pszText = buff;
3926 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
3927 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
3928 expect(5, ret);
3929 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
3931 DestroyWindow(hwnd);
3934 static void test_mapidindex(void)
3936 HWND hwnd;
3937 DWORD ret;
3939 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3940 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3941 ok(hwnd != NULL, "failed to create a listview window\n");
3942 insert_item(hwnd, 0);
3943 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3944 expect(-1, ret);
3945 DestroyWindow(hwnd);
3947 hwnd = create_listview_control(LVS_REPORT);
3948 ok(hwnd != NULL, "failed to create a listview window\n");
3950 /* LVM_MAPINDEXTOID with invalid index */
3951 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3952 expect(-1, ret);
3954 insert_item(hwnd, 0);
3955 insert_item(hwnd, 1);
3957 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
3958 expect(-1, ret);
3959 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
3960 expect(-1, ret);
3962 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3963 expect(0, ret);
3964 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3965 expect(1, ret);
3966 /* remove 0 indexed item, id retained */
3967 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
3968 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3969 expect(1, ret);
3970 /* new id starts from previous value */
3971 insert_item(hwnd, 1);
3972 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3973 expect(2, ret);
3975 /* get index by id */
3976 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
3977 expect(-1, ret);
3978 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
3979 expect(-1, ret);
3980 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
3981 expect(0, ret);
3982 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
3983 expect(1, ret);
3985 DestroyWindow(hwnd);
3988 static void test_getitemspacing(void)
3990 HWND hwnd;
3991 DWORD ret;
3992 INT cx, cy;
3993 HIMAGELIST himl;
3994 HBITMAP hbmp;
3995 LVITEMA itema;
3997 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
3998 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4000 /* LVS_ICON */
4001 hwnd = create_listview_control(LVS_ICON);
4002 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4003 todo_wine {
4004 expect(cx, LOWORD(ret));
4005 expect(cy, HIWORD(ret));
4007 /* now try with icons */
4008 himl = ImageList_Create(40, 40, 0, 4, 4);
4009 ok(himl != NULL, "failed to create imagelist\n");
4010 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4011 ok(hbmp != NULL, "failed to create bitmap\n");
4012 ret = ImageList_Add(himl, hbmp, 0);
4013 expect(0, ret);
4014 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4015 expect(0, ret);
4017 itema.mask = LVIF_IMAGE;
4018 itema.iImage = 0;
4019 itema.iItem = 0;
4020 itema.iSubItem = 0;
4021 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4022 expect(0, ret);
4023 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4024 todo_wine {
4025 /* spacing + icon size returned */
4026 expect(cx + 40, LOWORD(ret));
4027 expect(cy + 40, HIWORD(ret));
4029 DestroyWindow(hwnd);
4030 /* LVS_SMALLICON */
4031 hwnd = create_listview_control(LVS_SMALLICON);
4032 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4033 todo_wine {
4034 expect(cx, LOWORD(ret));
4035 expect(cy, HIWORD(ret));
4037 DestroyWindow(hwnd);
4038 /* LVS_REPORT */
4039 hwnd = create_listview_control(LVS_REPORT);
4040 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4041 todo_wine {
4042 expect(cx, LOWORD(ret));
4043 expect(cy, HIWORD(ret));
4045 DestroyWindow(hwnd);
4046 /* LVS_LIST */
4047 hwnd = create_listview_control(LVS_LIST);
4048 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4049 todo_wine {
4050 expect(cx, LOWORD(ret));
4051 expect(cy, HIWORD(ret));
4053 DestroyWindow(hwnd);
4056 static void test_getcolumnwidth(void)
4058 HWND hwnd;
4059 DWORD ret;
4060 DWORD_PTR style;
4061 LVCOLUMNA col;
4062 LVITEMA itema;
4064 /* default column width */
4065 hwnd = create_listview_control(LVS_ICON);
4066 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4067 expect(0, ret);
4068 style = GetWindowLong(hwnd, GWL_STYLE);
4069 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
4070 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4071 todo_wine expect(8, ret);
4072 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
4073 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
4074 col.mask = 0;
4075 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4076 expect(0, ret);
4077 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4078 expect(10, ret);
4079 DestroyWindow(hwnd);
4081 /* default column width with item added */
4082 hwnd = create_listview_control(LVS_LIST);
4083 memset(&itema, 0, sizeof(itema));
4084 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4085 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4086 todo_wine expect(96, ret);
4087 DestroyWindow(hwnd);
4090 static void test_scrollnotify(void)
4092 HWND hwnd;
4093 DWORD ret;
4095 hwnd = create_listview_control(LVS_REPORT);
4097 insert_column(hwnd, 0);
4098 insert_column(hwnd, 1);
4099 insert_item(hwnd, 0);
4101 /* make it scrollable - resize */
4102 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4103 expect(TRUE, ret);
4104 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4105 expect(TRUE, ret);
4107 /* try with dummy call */
4108 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4109 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
4110 expect(TRUE, ret);
4111 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4112 "scroll notify 1", TRUE);
4114 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4115 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
4116 expect(TRUE, ret);
4117 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4118 "scroll notify 2", TRUE);
4120 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4121 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4122 expect(TRUE, ret);
4123 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4124 "scroll notify 3", TRUE);
4126 DestroyWindow(hwnd);
4129 static void test_LVS_EX_TRANSPARENTBKGND(void)
4131 HWND hwnd;
4132 DWORD ret;
4133 HDC hdc;
4135 hwnd = create_listview_control(LVS_REPORT);
4137 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4138 expect(TRUE, ret);
4140 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4141 LVS_EX_TRANSPARENTBKGND);
4143 ret = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
4144 if (ret != CLR_NONE)
4146 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4147 DestroyWindow(hwnd);
4148 return;
4151 /* try to set some back color and check this style bit */
4152 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4153 expect(TRUE, ret);
4154 ret = SendMessage(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4155 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4157 /* now test what this style actually does */
4158 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4159 LVS_EX_TRANSPARENTBKGND);
4161 hdc = GetWindowDC(hwndparent);
4163 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4164 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4165 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4166 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4168 ReleaseDC(hwndparent, hdc);
4170 DestroyWindow(hwnd);
4173 static void test_approximate_viewrect(void)
4175 HWND hwnd;
4176 DWORD ret;
4177 HIMAGELIST himl;
4178 HBITMAP hbmp;
4179 LVITEMA itema;
4180 static CHAR test[] = "abracadabra, a very long item label";
4182 hwnd = create_listview_control(LVS_ICON);
4183 himl = ImageList_Create(40, 40, 0, 4, 4);
4184 ok(himl != NULL, "failed to create imagelist\n");
4185 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4186 ok(hbmp != NULL, "failed to create bitmap\n");
4187 ret = ImageList_Add(himl, hbmp, 0);
4188 expect(0, ret);
4189 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4190 expect(0, ret);
4192 itema.mask = LVIF_IMAGE;
4193 itema.iImage = 0;
4194 itema.iItem = 0;
4195 itema.iSubItem = 0;
4196 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4197 expect(0, ret);
4199 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4200 if (ret == 0)
4202 /* version 4.0 */
4203 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4204 return;
4207 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4208 ok(MAKELONG(77,827)==ret,"Incorrect Approximate rect\n");
4210 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4211 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4212 ok(MAKELONG(102,302)==ret,"Incorrect Approximate rect\n");
4214 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4215 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4217 itema.pszText = test;
4218 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4219 expect(TRUE, ret);
4220 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4221 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4223 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4224 ok(MAKELONG(52,2)==ret,"Incorrect Approximate rect\n");
4225 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4226 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4227 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4228 ok(MAKELONG(102,52)==ret,"Incorrect Approximate rect\n");
4229 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4230 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4231 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4232 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4233 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4234 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4235 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4236 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4237 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4238 ok(MAKELONG(152,152)==ret,"Incorrect Approximate rect\n");
4240 DestroyWindow(hwnd);
4243 static void test_finditem(void)
4245 LVFINDINFOA fi;
4246 static char f[5];
4247 HWND hwnd;
4248 DWORD r;
4250 hwnd = create_listview_control(LVS_REPORT);
4251 insert_item(hwnd, 0);
4253 memset(&fi, 0, sizeof(fi));
4255 /* full string search, inserted text was "foo" */
4256 strcpy(f, "foo");
4257 fi.flags = LVFI_STRING;
4258 fi.psz = f;
4259 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4260 expect(0, r);
4261 /* partial string search, inserted text was "foo" */
4262 strcpy(f, "fo");
4263 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4264 fi.psz = f;
4265 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4266 expect(0, r);
4267 /* partial string search, part after start char */
4268 strcpy(f, "oo");
4269 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4270 fi.psz = f;
4271 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4272 expect(-1, r);
4274 /* try with LVFI_SUBSTRING */
4275 strcpy(f, "fo");
4276 fi.flags = LVFI_SUBSTRING;
4277 fi.psz = f;
4278 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4279 if (r == -1)
4281 win_skip("LVFI_SUBSTRING not supported\n");
4282 DestroyWindow(hwnd);
4283 return;
4285 expect(0, r);
4286 strcpy(f, "f");
4287 fi.flags = LVFI_SUBSTRING;
4288 fi.psz = f;
4289 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4290 expect(0, r);
4291 strcpy(f, "o");
4292 fi.flags = LVFI_SUBSTRING;
4293 fi.psz = f;
4294 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4295 expect(-1, r);
4297 strcpy(f, "f");
4298 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
4299 fi.psz = f;
4300 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4301 expect(0, r);
4303 DestroyWindow(hwnd);
4306 static void test_LVS_EX_HEADERINALLVIEWS(void)
4308 HWND hwnd, header;
4309 DWORD style;
4311 hwnd = create_listview_control(LVS_ICON);
4313 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4314 LVS_EX_HEADERINALLVIEWS);
4316 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4317 if (!IsWindow(header))
4319 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4320 DestroyWindow(hwnd);
4321 return;
4324 /* LVS_NOCOLUMNHEADER works as before */
4325 style = GetWindowLongA(hwnd, GWL_STYLE);
4326 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
4327 style = GetWindowLongA(header, GWL_STYLE);
4328 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
4329 style = GetWindowLongA(hwnd, GWL_STYLE);
4330 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
4331 style = GetWindowLongA(header, GWL_STYLE);
4332 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
4334 /* try to remove style */
4335 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
4336 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4337 ok(IsWindow(header), "Expected header to be created\n");
4338 style = GetWindowLongA(header, GWL_STYLE);
4339 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
4341 DestroyWindow(hwnd);
4343 /* check other styles */
4344 hwnd = create_listview_control(LVS_LIST);
4345 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4346 LVS_EX_HEADERINALLVIEWS);
4347 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4348 ok(IsWindow(header), "Expected header to be created\n");
4349 DestroyWindow(hwnd);
4351 hwnd = create_listview_control(LVS_SMALLICON);
4352 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4353 LVS_EX_HEADERINALLVIEWS);
4354 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4355 ok(IsWindow(header), "Expected header to be created\n");
4356 DestroyWindow(hwnd);
4358 hwnd = create_listview_control(LVS_REPORT);
4359 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4360 LVS_EX_HEADERINALLVIEWS);
4361 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4362 ok(IsWindow(header), "Expected header to be created\n");
4363 DestroyWindow(hwnd);
4366 static void test_hover(void)
4368 HWND hwnd;
4369 DWORD r;
4371 hwnd = create_listview_control(LVS_ICON);
4373 /* test WM_MOUSEHOVER forwarding */
4374 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4375 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4376 expect(0, r);
4377 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
4378 g_block_hover = TRUE;
4379 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4380 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4381 expect(0, r);
4382 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
4383 g_block_hover = FALSE;
4385 r = SendMessage(hwnd, LVM_SETHOVERTIME, 0, 500);
4386 expect(HOVER_DEFAULT, r);
4387 r = SendMessage(hwnd, LVM_GETHOVERTIME, 0, 0);
4388 expect(500, r);
4390 DestroyWindow(hwnd);
4393 static void test_destroynotify(void)
4395 HWND hwnd;
4397 hwnd = create_listview_control(LVS_REPORT);
4398 ok(hwnd != NULL, "failed to create listview window\n");
4400 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4401 DestroyWindow(hwnd);
4402 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
4405 static void test_header_notification(void)
4407 HWND list, header;
4408 HDITEMA item;
4409 NMHEADER nmh;
4410 LVCOLUMNA col;
4411 LRESULT ret;
4413 list = create_listview_control(LVS_REPORT);
4414 ok(list != 0, "failed to create listview window\n");
4416 memset(&col, 0, sizeof(col));
4417 col.mask = LVCF_WIDTH;
4418 col.cx = 100;
4419 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4420 ok(!ret, "expected 0, got %ld\n", ret);
4422 header = subclass_header(list);
4424 ret = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
4425 ok(ret == 1, "expected header item count 1, got %ld\n", ret);
4427 memset(&item, 0, sizeof(item));
4428 item.mask = HDI_WIDTH;
4429 ret = SendMessage(header, HDM_GETITEMA, 0, (LPARAM)&item);
4430 ok(ret, "HDM_GETITEM failed\n");
4431 ok(item.cxy == 100, "expected 100, got %d\n", item.cxy);
4433 nmh.hdr.hwndFrom = header;
4434 nmh.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
4435 nmh.hdr.code = HDN_ITEMCHANGEDA;
4436 nmh.iItem = 0;
4437 nmh.iButton = 0;
4438 item.mask = HDI_WIDTH;
4439 item.cxy = 50;
4440 nmh.pitem = &item;
4441 ret = SendMessage(list, WM_NOTIFY, 0, (LPARAM)&nmh);
4442 ok(!ret, "WM_NOTIFY/HDN_ITEMCHANGED failed\n");
4444 DestroyWindow(list);
4447 static void test_createdragimage(void)
4449 HIMAGELIST himl;
4450 POINT pt;
4451 HWND list;
4453 list = create_listview_control(LVS_ICON);
4454 ok(list != 0, "failed to create listview window\n");
4456 insert_item(list, 0);
4458 /* NULL point */
4459 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
4460 ok(himl == NULL, "got %p\n", himl);
4462 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
4463 ok(himl != NULL, "got %p\n", himl);
4464 ImageList_Destroy(himl);
4466 DestroyWindow(list);
4469 START_TEST(listview)
4471 HMODULE hComctl32;
4472 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
4474 ULONG_PTR ctx_cookie;
4475 HANDLE hCtx;
4476 HWND hwnd;
4478 hComctl32 = GetModuleHandleA("comctl32.dll");
4479 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
4480 if (pInitCommonControlsEx)
4482 INITCOMMONCONTROLSEX iccex;
4483 iccex.dwSize = sizeof(iccex);
4484 iccex.dwICC = ICC_LISTVIEW_CLASSES;
4485 pInitCommonControlsEx(&iccex);
4487 else
4488 InitCommonControls();
4490 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
4492 hwndparent = create_parent_window(FALSE);
4493 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4495 g_is_below_5 = is_below_comctl_5();
4497 test_header_notification();
4498 test_images();
4499 test_checkboxes();
4500 test_items();
4501 test_create();
4502 test_redraw();
4503 test_customdraw();
4504 test_icon_spacing();
4505 test_color();
4506 test_item_count();
4507 test_item_position();
4508 test_columns();
4509 test_getorigin();
4510 test_multiselect();
4511 test_getitemrect();
4512 test_subitem_rect();
4513 test_sorting();
4514 test_ownerdata();
4515 test_norecompute();
4516 test_nosortheader();
4517 test_setredraw();
4518 test_hittest();
4519 test_getviewrect();
4520 test_getitemposition();
4521 test_columnscreation();
4522 test_editbox();
4523 test_notifyformat();
4524 test_indentation();
4525 test_getitemspacing();
4526 test_getcolumnwidth();
4527 test_approximate_viewrect();
4528 test_finditem();
4529 test_hover();
4530 test_destroynotify();
4531 test_createdragimage();
4533 if (!load_v6_module(&ctx_cookie, &hCtx))
4535 DestroyWindow(hwndparent);
4536 return;
4539 /* this is a XP SP3 failure workaround */
4540 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
4541 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
4542 0, 0, 100, 100,
4543 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
4544 if (!IsWindow(hwnd))
4546 win_skip("FIXME: failed to create ListView window.\n");
4547 unload_v6_module(ctx_cookie, hCtx);
4548 DestroyWindow(hwndparent);
4549 return;
4551 else
4552 DestroyWindow(hwnd);
4554 /* comctl32 version 6 tests start here */
4555 test_get_set_view();
4556 test_canceleditlabel();
4557 test_mapidindex();
4558 test_scrollnotify();
4559 test_LVS_EX_TRANSPARENTBKGND();
4560 test_LVS_EX_HEADERINALLVIEWS();
4562 unload_v6_module(ctx_cookie, hCtx);
4564 DestroyWindow(hwndparent);