comctl32/tests: Use the SendMessage instead of ListView_Scroll.
[wine.git] / dlls / comctl32 / tests / listview.c
blob59c3dc1ace727767f3543e4ce2e9860c41b8af9d
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 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 INT notifyFormat;
58 /* indicates we're running < 5.80 version */
59 BOOL g_is_below_5;
61 static HWND subclass_editbox(HWND hwndListview);
63 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
65 static const struct message create_ownerdrawfixed_parent_seq[] = {
66 { WM_NOTIFYFORMAT, sent },
67 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
68 { WM_MEASUREITEM, sent },
69 { WM_PARENTNOTIFY, sent },
70 { 0 }
73 static const struct message redraw_listview_seq[] = {
74 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
75 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
76 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
77 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
78 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
79 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
80 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
81 { 0 }
84 static const struct message listview_icon_spacing_seq[] = {
85 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
86 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
87 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
88 { 0 }
91 static const struct message listview_color_seq[] = {
92 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
93 { LVM_GETBKCOLOR, sent },
94 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
95 { LVM_GETTEXTCOLOR, sent },
96 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
97 { LVM_GETTEXTBKCOLOR, sent },
99 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
100 { LVM_GETBKCOLOR, sent },
101 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
102 { LVM_GETTEXTCOLOR, sent },
103 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
104 { LVM_GETTEXTBKCOLOR, sent },
106 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
107 { LVM_GETBKCOLOR, sent },
108 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
109 { LVM_GETTEXTCOLOR, sent },
110 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
111 { LVM_GETTEXTBKCOLOR, sent },
113 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
114 { LVM_GETBKCOLOR, sent },
115 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
116 { LVM_GETTEXTCOLOR, sent },
117 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
118 { LVM_GETTEXTBKCOLOR, sent },
119 { 0 }
122 static const struct message listview_item_count_seq[] = {
123 { LVM_GETITEMCOUNT, sent },
124 { LVM_INSERTITEM, sent },
125 { LVM_INSERTITEM, sent },
126 { LVM_INSERTITEM, sent },
127 { LVM_GETITEMCOUNT, sent },
128 { LVM_DELETEITEM, sent|wparam, 2 },
129 { WM_NCPAINT, sent|optional },
130 { WM_ERASEBKGND, sent|optional },
131 { LVM_GETITEMCOUNT, sent },
132 { LVM_DELETEALLITEMS, sent },
133 { LVM_GETITEMCOUNT, sent },
134 { LVM_INSERTITEM, sent },
135 { LVM_INSERTITEM, sent },
136 { LVM_GETITEMCOUNT, sent },
137 { LVM_INSERTITEM, sent },
138 { LVM_GETITEMCOUNT, sent },
139 { 0 }
142 static const struct message listview_itempos_seq[] = {
143 { LVM_INSERTITEM, sent },
144 { LVM_INSERTITEM, sent },
145 { LVM_INSERTITEM, sent },
146 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
147 { WM_NCPAINT, sent|optional },
148 { WM_ERASEBKGND, sent|optional },
149 { LVM_GETITEMPOSITION, sent|wparam, 1 },
150 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
151 { LVM_GETITEMPOSITION, sent|wparam, 2 },
152 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
153 { LVM_GETITEMPOSITION, sent|wparam, 0 },
154 { 0 }
157 static const struct message listview_ownerdata_switchto_seq[] = {
158 { WM_STYLECHANGING, sent },
159 { WM_STYLECHANGED, sent },
160 { 0 }
163 static const struct message listview_getorderarray_seq[] = {
164 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
165 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
166 { 0 }
169 static const struct message empty_seq[] = {
170 { 0 }
173 static const struct message forward_erasebkgnd_parent_seq[] = {
174 { WM_ERASEBKGND, sent },
175 { 0 }
178 static const struct message ownderdata_select_focus_parent_seq[] = {
179 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
180 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
181 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
182 { 0 }
185 static const struct message ownerdata_setstate_all_parent_seq[] = {
186 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
187 { 0 }
190 static const struct message ownerdata_defocus_all_parent_seq[] = {
191 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
192 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
193 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
194 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
195 { 0 }
198 static const struct message ownerdata_deselect_all_parent_seq[] = {
199 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
200 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
201 { 0 }
204 static const struct message select_all_parent_seq[] = {
205 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
206 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
208 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
209 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
211 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
212 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
214 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
215 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
217 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
218 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
219 { 0 }
222 static const struct message textcallback_set_again_parent_seq[] = {
223 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
224 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
225 { 0 }
228 static const struct message single_getdispinfo_parent_seq[] = {
229 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
230 { 0 }
233 static const struct message getitemposition_seq1[] = {
234 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
235 { 0 }
238 static const struct message getitemposition_seq2[] = {
239 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
240 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
241 { 0 }
244 static const struct message editbox_create_pos[] = {
245 /* sequence sent after LVN_BEGINLABELEDIT */
246 /* next two are 4.7x specific */
247 { WM_WINDOWPOSCHANGING, sent },
248 { WM_WINDOWPOSCHANGED, sent|optional },
250 { WM_WINDOWPOSCHANGING, sent|optional },
251 { WM_NCCALCSIZE, sent },
252 { WM_WINDOWPOSCHANGED, sent },
253 { WM_MOVE, sent|defwinproc },
254 { WM_SIZE, sent|defwinproc },
255 /* the rest is todo, skipped in 4.7x */
256 { WM_WINDOWPOSCHANGING, sent|optional },
257 { WM_WINDOWPOSCHANGED, sent|optional },
258 { 0 }
261 static const struct message scroll_parent_seq[] = {
262 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
263 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
264 { 0 }
267 static const struct message setredraw_seq[] = {
268 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
269 { 0 }
272 static const struct message lvs_ex_transparentbkgnd_seq[] = {
273 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
274 { 0 }
277 static const struct message edit_end_nochange[] = {
278 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
279 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW }, /* todo */
280 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
281 { 0 }
284 static const struct message hover_parent[] = {
285 { WM_GETDLGCODE, sent }, /* todo_wine */
286 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
287 { 0 }
290 static const struct message listview_destroy[] = {
291 { 0x0090, sent|optional }, /* Vista */
292 { WM_PARENTNOTIFY, sent },
293 { WM_SHOWWINDOW, sent },
294 { WM_WINDOWPOSCHANGING, sent },
295 { WM_WINDOWPOSCHANGED, sent|optional },
296 { WM_DESTROY, sent },
297 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
298 { WM_NCDESTROY, sent },
299 { 0 }
302 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
304 static LONG defwndproc_counter = 0;
305 LRESULT ret;
306 struct message msg;
308 msg.message = message;
309 msg.flags = sent|wparam|lparam;
310 if (defwndproc_counter) msg.flags |= defwinproc;
311 msg.wParam = wParam;
312 msg.lParam = lParam;
313 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
315 /* log system messages, except for painting */
316 if (message < WM_USER &&
317 message != WM_PAINT &&
318 message != WM_ERASEBKGND &&
319 message != WM_NCPAINT &&
320 message != WM_NCHITTEST &&
321 message != WM_GETTEXT &&
322 message != WM_GETICON &&
323 message != WM_DEVICECHANGE)
325 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
327 add_message(sequences, PARENT_SEQ_INDEX, &msg);
328 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
330 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
332 switch (message)
334 case WM_NOTIFY:
336 switch (((NMHDR*)lParam)->code)
338 case LVN_BEGINLABELEDIT:
339 /* subclass edit box */
340 if (!blockEdit)
341 subclass_editbox(((NMHDR*)lParam)->hwndFrom);
343 return blockEdit;
345 case LVN_ENDLABELEDIT:
347 /* always accept new item text */
348 NMLVDISPINFO *di = (NMLVDISPINFO*)lParam;
349 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText);
350 return TRUE;
352 case LVN_BEGINSCROLL:
353 case LVN_ENDSCROLL:
355 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
357 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
358 "BEGIN" : "END", pScroll->dx, pScroll->dy);
360 break;
361 case LVN_ITEMCHANGED:
362 if (g_dump_itemchanged)
364 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
365 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
366 nmlv->iItem, nmlv->uNewState, nmlv->uOldState, nmlv->uChanged);
368 break;
369 case NM_HOVER:
370 if (g_block_hover) return 1;
371 break;
373 break;
375 case WM_NOTIFYFORMAT:
377 /* force to return format */
378 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
379 break;
383 defwndproc_counter++;
384 ret = DefWindowProcA(hwnd, message, wParam, lParam);
385 defwndproc_counter--;
387 return ret;
390 static BOOL register_parent_wnd_class(BOOL Unicode)
392 WNDCLASSA clsA;
393 WNDCLASSW clsW;
395 if (Unicode)
397 clsW.style = 0;
398 clsW.lpfnWndProc = parent_wnd_proc;
399 clsW.cbClsExtra = 0;
400 clsW.cbWndExtra = 0;
401 clsW.hInstance = GetModuleHandleW(NULL);
402 clsW.hIcon = 0;
403 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
404 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
405 clsW.lpszMenuName = NULL;
406 clsW.lpszClassName = testparentclassW;
408 else
410 clsA.style = 0;
411 clsA.lpfnWndProc = parent_wnd_proc;
412 clsA.cbClsExtra = 0;
413 clsA.cbWndExtra = 0;
414 clsA.hInstance = GetModuleHandleA(NULL);
415 clsA.hIcon = 0;
416 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
417 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
418 clsA.lpszMenuName = NULL;
419 clsA.lpszClassName = "Listview test parent class";
422 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
425 static HWND create_parent_window(BOOL Unicode)
427 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
428 HWND hwnd;
430 if (!register_parent_wnd_class(Unicode))
431 return NULL;
433 blockEdit = FALSE;
434 notifyFormat = -1;
436 if (Unicode)
437 hwnd = CreateWindowExW(0, testparentclassW, nameW,
438 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
439 WS_MAXIMIZEBOX | WS_VISIBLE,
440 0, 0, 100, 100,
441 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
442 else
443 hwnd = CreateWindowExA(0, "Listview test parent class",
444 "Listview test parent window",
445 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
446 WS_MAXIMIZEBOX | WS_VISIBLE,
447 0, 0, 100, 100,
448 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
449 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
450 return hwnd;
453 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
455 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
456 static LONG defwndproc_counter = 0;
457 LRESULT ret;
458 struct message msg;
460 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
462 /* some debug output for style changing */
463 if ((message == WM_STYLECHANGING ||
464 message == WM_STYLECHANGED) && lParam)
466 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
467 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
470 msg.message = message;
471 msg.flags = sent|wparam|lparam;
472 if (defwndproc_counter) msg.flags |= defwinproc;
473 msg.wParam = wParam;
474 msg.lParam = lParam;
475 msg.id = LISTVIEW_ID;
476 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
477 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
479 defwndproc_counter++;
480 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
481 defwndproc_counter--;
482 return ret;
485 static HWND create_listview_control(DWORD style)
487 WNDPROC oldproc;
488 HWND hwnd;
489 RECT rect;
491 GetClientRect(hwndparent, &rect);
492 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
493 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
494 0, 0, rect.right, rect.bottom,
495 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
496 ok(hwnd != NULL, "gle=%d\n", GetLastError());
498 if (!hwnd) return NULL;
500 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
501 (LONG_PTR)listview_subclass_proc);
502 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
504 return hwnd;
507 /* unicode listview window with specified parent */
508 static HWND create_listview_controlW(DWORD style, HWND parent)
510 WNDPROC oldproc;
511 HWND hwnd;
512 RECT rect;
513 static const WCHAR nameW[] = {'f','o','o',0};
515 GetClientRect(parent, &rect);
516 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
517 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
518 0, 0, rect.right, rect.bottom,
519 parent, NULL, GetModuleHandleW(NULL), NULL);
520 ok(hwnd != NULL, "gle=%d\n", GetLastError());
522 if (!hwnd) return NULL;
524 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
525 (LONG_PTR)listview_subclass_proc);
526 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
528 return hwnd;
531 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
533 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
534 static LONG defwndproc_counter = 0;
535 LRESULT ret;
536 struct message msg;
538 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
540 msg.message = message;
541 msg.flags = sent|wparam|lparam;
542 if (defwndproc_counter) msg.flags |= defwinproc;
543 msg.wParam = wParam;
544 msg.lParam = lParam;
545 msg.id = HEADER_ID;
546 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
548 defwndproc_counter++;
549 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
550 defwndproc_counter--;
551 return ret;
554 static HWND subclass_header(HWND hwndListview)
556 WNDPROC oldproc;
557 HWND hwnd;
559 hwnd = ListView_GetHeader(hwndListview);
560 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
561 (LONG_PTR)header_subclass_proc);
562 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
564 return hwnd;
567 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
569 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
570 static LONG defwndproc_counter = 0;
571 LRESULT ret;
572 struct message msg;
574 msg.message = message;
575 msg.flags = sent|wparam|lparam;
576 if (defwndproc_counter) msg.flags |= defwinproc;
577 msg.wParam = wParam;
578 msg.lParam = lParam;
580 /* all we need is sizing */
581 if (message == WM_WINDOWPOSCHANGING ||
582 message == WM_NCCALCSIZE ||
583 message == WM_WINDOWPOSCHANGED ||
584 message == WM_MOVE ||
585 message == WM_SIZE)
587 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
590 defwndproc_counter++;
591 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
592 defwndproc_counter--;
593 return ret;
596 static HWND subclass_editbox(HWND hwndListview)
598 WNDPROC oldproc;
599 HWND hwnd;
601 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
602 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
603 (LONG_PTR)editbox_subclass_proc);
604 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
606 return hwnd;
609 /* Performs a single LVM_HITTEST test */
610 static void test_lvm_hittest(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
611 BOOL todo_item, BOOL todo_flags, int line)
613 LVHITTESTINFO lpht;
614 DWORD ret;
616 lpht.pt.x = x;
617 lpht.pt.y = y;
618 lpht.iSubItem = 10;
620 trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
621 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
623 if (todo_item)
625 todo_wine
627 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
628 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
629 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
632 else
634 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
635 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
636 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
639 if (todo_flags)
641 todo_wine
642 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
644 else if (broken_flags)
645 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
646 "Expected flags %x, got %x\n", flags, lpht.flags);
647 else
648 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
651 /* Performs a single LVM_SUBITEMHITTEST test */
652 static void test_lvm_subitemhittest(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
653 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
655 LVHITTESTINFO lpht;
656 DWORD ret;
658 lpht.pt.x = x;
659 lpht.pt.y = y;
661 trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
662 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
664 if (todo_item)
666 todo_wine
668 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
669 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
672 else
674 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
675 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
678 if (todo_subitem)
680 todo_wine
681 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
683 else
684 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
686 if (todo_flags)
688 todo_wine
689 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
691 else
692 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
695 static void test_images(void)
697 HWND hwnd;
698 DWORD r;
699 LVITEM item;
700 HIMAGELIST himl;
701 HBITMAP hbmp;
702 RECT r1, r2;
703 static CHAR hello[] = "hello";
705 himl = ImageList_Create(40, 40, 0, 4, 4);
706 ok(himl != NULL, "failed to create imagelist\n");
708 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
709 ok(hbmp != NULL, "failed to create bitmap\n");
711 r = ImageList_Add(himl, hbmp, 0);
712 ok(r == 0, "should be zero\n");
714 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
715 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
716 ok(hwnd != NULL, "failed to create listview window\n");
718 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
719 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
721 ok(r == 0, "should return zero\n");
723 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
724 ok(r == 0, "should return zero\n");
726 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
727 /* returns dimensions */
729 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
730 ok(r == 0, "should be zero items\n");
732 item.mask = LVIF_IMAGE | LVIF_TEXT;
733 item.iItem = 0;
734 item.iSubItem = 1;
735 item.iImage = 0;
736 item.pszText = 0;
737 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
738 ok(r == -1, "should fail\n");
740 item.iSubItem = 0;
741 item.pszText = hello;
742 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
743 ok(r == 0, "should not fail\n");
745 memset(&r1, 0, sizeof r1);
746 r1.left = LVIR_ICON;
747 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
749 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
750 ok(r == TRUE, "should not 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(&r2, 0, sizeof r2);
758 r2.left = LVIR_ICON;
759 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
761 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
763 DestroyWindow(hwnd);
766 static void test_checkboxes(void)
768 HWND hwnd;
769 LVITEMA item;
770 DWORD r;
771 static CHAR text[] = "Text",
772 text2[] = "Text2",
773 text3[] = "Text3";
775 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
776 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
777 ok(hwnd != NULL, "failed to create listview window\n");
779 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
780 item.mask = LVIF_TEXT | LVIF_STATE;
781 item.stateMask = 0xffff;
782 item.state = 0xfccc;
783 item.iItem = 0;
784 item.iSubItem = 0;
785 item.pszText = text;
786 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
787 ok(r == 0, "ret %d\n", r);
789 item.iItem = 0;
790 item.mask = LVIF_STATE;
791 item.stateMask = 0xffff;
792 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
793 ok(item.state == 0xfccc, "state %x\n", item.state);
795 /* Don't set LVIF_STATE */
796 item.mask = LVIF_TEXT;
797 item.stateMask = 0xffff;
798 item.state = 0xfccc;
799 item.iItem = 1;
800 item.iSubItem = 0;
801 item.pszText = text;
802 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
803 ok(r == 1, "ret %d\n", r);
805 item.iItem = 1;
806 item.mask = LVIF_STATE;
807 item.stateMask = 0xffff;
808 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
809 ok(item.state == 0, "state %x\n", item.state);
811 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
812 ok(r == 0, "should return zero\n");
814 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
815 item.iItem = 0;
816 item.mask = LVIF_STATE;
817 item.stateMask = 0xffff;
818 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
819 if (item.state != 0x1ccc)
821 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
822 DestroyWindow(hwnd);
823 return;
826 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
827 item.iItem = 2;
828 item.mask = LVIF_TEXT;
829 item.state = 0;
830 item.pszText = text2;
831 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
832 ok(r == 2, "ret %d\n", r);
834 item.iItem = 2;
835 item.mask = LVIF_STATE;
836 item.stateMask = 0xffff;
837 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
838 ok(item.state == 0x1000, "state %x\n", item.state);
840 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
841 item.iItem = 3;
842 item.mask = LVIF_TEXT | LVIF_STATE;
843 item.stateMask = 0xffff;
844 item.state = 0x2aaa;
845 item.pszText = text3;
846 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
847 ok(r == 3, "ret %d\n", r);
849 item.iItem = 3;
850 item.mask = LVIF_STATE;
851 item.stateMask = 0xffff;
852 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
853 ok(item.state == 0x1aaa, "state %x\n", item.state);
855 /* Set an item's state to checked */
856 item.iItem = 3;
857 item.mask = LVIF_STATE;
858 item.stateMask = 0xf000;
859 item.state = 0x2000;
860 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
862 item.iItem = 3;
863 item.mask = LVIF_STATE;
864 item.stateMask = 0xffff;
865 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
866 ok(item.state == 0x2aaa, "state %x\n", item.state);
868 /* Check that only the bits we asked for are returned,
869 * and that all the others are set to zero
871 item.iItem = 3;
872 item.mask = LVIF_STATE;
873 item.stateMask = 0xf000;
874 item.state = 0xffff;
875 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
876 ok(item.state == 0x2000, "state %x\n", item.state);
878 /* Set the style again and check that doesn't change an item's state */
879 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
880 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
882 item.iItem = 3;
883 item.mask = LVIF_STATE;
884 item.stateMask = 0xffff;
885 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
886 ok(item.state == 0x2aaa, "state %x\n", item.state);
888 /* Unsetting the checkbox extended style doesn't change an item's state */
889 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
890 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
892 item.iItem = 3;
893 item.mask = LVIF_STATE;
894 item.stateMask = 0xffff;
895 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
896 ok(item.state == 0x2aaa, "state %x\n", item.state);
898 /* Now setting the style again will change an item's state */
899 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
900 ok(r == 0, "ret %x\n", r);
902 item.iItem = 3;
903 item.mask = LVIF_STATE;
904 item.stateMask = 0xffff;
905 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
906 ok(item.state == 0x1aaa, "state %x\n", item.state);
908 /* Toggle checkbox tests (bug 9934) */
909 memset (&item, 0xcc, sizeof(item));
910 item.mask = LVIF_STATE;
911 item.iItem = 3;
912 item.iSubItem = 0;
913 item.state = LVIS_FOCUSED;
914 item.stateMask = LVIS_FOCUSED;
915 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
916 expect(1, r);
918 item.iItem = 3;
919 item.mask = LVIF_STATE;
920 item.stateMask = 0xffff;
921 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
922 ok(item.state == 0x1aab, "state %x\n", item.state);
924 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
925 expect(0, r);
926 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
927 expect(0, r);
929 item.iItem = 3;
930 item.mask = LVIF_STATE;
931 item.stateMask = 0xffff;
932 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
933 ok(item.state == 0x2aab, "state %x\n", item.state);
935 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
936 expect(0, r);
937 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
938 expect(0, r);
940 item.iItem = 3;
941 item.mask = LVIF_STATE;
942 item.stateMask = 0xffff;
943 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
944 ok(item.state == 0x1aab, "state %x\n", item.state);
946 DestroyWindow(hwnd);
949 static void insert_column(HWND hwnd, int idx)
951 LVCOLUMN column;
952 DWORD rc;
954 memset(&column, 0xcc, sizeof(column));
955 column.mask = LVCF_SUBITEM;
956 column.iSubItem = idx;
958 rc = ListView_InsertColumn(hwnd, idx, &column);
959 expect(idx, rc);
962 static void insert_item(HWND hwnd, int idx)
964 static CHAR text[] = "foo";
966 LVITEMA item;
967 DWORD rc;
969 memset(&item, 0xcc, sizeof (item));
970 item.mask = LVIF_TEXT;
971 item.iItem = idx;
972 item.iSubItem = 0;
973 item.pszText = text;
975 rc = ListView_InsertItem(hwnd, &item);
976 expect(idx, rc);
979 static void test_items(void)
981 const LPARAM lparamTest = 0x42;
982 HWND hwnd;
983 LVITEMA item;
984 DWORD r;
985 static CHAR text[] = "Text";
987 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
988 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
989 ok(hwnd != NULL, "failed to create listview window\n");
992 * Test setting/getting item params
995 /* Set up two columns */
996 insert_column(hwnd, 0);
997 insert_column(hwnd, 1);
999 /* LVIS_SELECTED with zero stateMask */
1000 /* set */
1001 memset (&item, 0, sizeof (item));
1002 item.mask = LVIF_STATE;
1003 item.state = LVIS_SELECTED;
1004 item.stateMask = 0;
1005 item.iItem = 0;
1006 item.iSubItem = 0;
1007 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1008 ok(r == 0, "ret %d\n", r);
1009 /* get */
1010 memset (&item, 0xcc, sizeof (item));
1011 item.mask = LVIF_STATE;
1012 item.stateMask = LVIS_SELECTED;
1013 item.state = 0;
1014 item.iItem = 0;
1015 item.iSubItem = 0;
1016 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1017 ok(r != 0, "ret %d\n", r);
1018 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1019 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1021 /* LVIS_SELECTED with zero stateMask */
1022 /* set */
1023 memset (&item, 0, sizeof (item));
1024 item.mask = LVIF_STATE;
1025 item.state = LVIS_FOCUSED;
1026 item.stateMask = 0;
1027 item.iItem = 0;
1028 item.iSubItem = 0;
1029 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1030 ok(r == 0, "ret %d\n", r);
1031 /* get */
1032 memset (&item, 0xcc, sizeof (item));
1033 item.mask = LVIF_STATE;
1034 item.stateMask = LVIS_FOCUSED;
1035 item.state = 0;
1036 item.iItem = 0;
1037 item.iSubItem = 0;
1038 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1039 ok(r != 0, "ret %d\n", r);
1040 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1041 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1043 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1044 /* set */
1045 memset (&item, 0, sizeof (item));
1046 item.mask = LVIF_STATE;
1047 item.state = LVIS_CUT;
1048 item.stateMask = LVIS_FOCUSED;
1049 item.iItem = 0;
1050 item.iSubItem = 0;
1051 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1052 ok(r == 0, "ret %d\n", r);
1053 /* get */
1054 memset (&item, 0xcc, sizeof (item));
1055 item.mask = LVIF_STATE;
1056 item.stateMask = LVIS_CUT;
1057 item.state = 0;
1058 item.iItem = 0;
1059 item.iSubItem = 0;
1060 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1061 ok(r != 0, "ret %d\n", r);
1062 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1063 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1065 /* Insert an item with just a param */
1066 memset (&item, 0xcc, sizeof (item));
1067 item.mask = LVIF_PARAM;
1068 item.iItem = 0;
1069 item.iSubItem = 0;
1070 item.lParam = lparamTest;
1071 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1072 ok(r == 0, "ret %d\n", r);
1074 /* Test getting of the param */
1075 memset (&item, 0xcc, sizeof (item));
1076 item.mask = LVIF_PARAM;
1077 item.iItem = 0;
1078 item.iSubItem = 0;
1079 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1080 ok(r != 0, "ret %d\n", r);
1081 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1083 /* Set up a subitem */
1084 memset (&item, 0xcc, sizeof (item));
1085 item.mask = LVIF_TEXT;
1086 item.iItem = 0;
1087 item.iSubItem = 1;
1088 item.pszText = text;
1089 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1090 ok(r != 0, "ret %d\n", r);
1092 /* Query param from subitem: returns main item param */
1093 memset (&item, 0xcc, sizeof (item));
1094 item.mask = LVIF_PARAM;
1095 item.iItem = 0;
1096 item.iSubItem = 1;
1097 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1098 ok(r != 0, "ret %d\n", r);
1099 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1101 /* Set up param on first subitem: no effect */
1102 memset (&item, 0xcc, sizeof (item));
1103 item.mask = LVIF_PARAM;
1104 item.iItem = 0;
1105 item.iSubItem = 1;
1106 item.lParam = lparamTest+1;
1107 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1108 ok(r == 0, "ret %d\n", r);
1110 /* Query param from subitem again: should still return main item param */
1111 memset (&item, 0xcc, sizeof (item));
1112 item.mask = LVIF_PARAM;
1113 item.iItem = 0;
1114 item.iSubItem = 1;
1115 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1116 ok(r != 0, "ret %d\n", r);
1117 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1119 /**** Some tests of state highlighting ****/
1120 memset (&item, 0xcc, sizeof (item));
1121 item.mask = LVIF_STATE;
1122 item.iItem = 0;
1123 item.iSubItem = 0;
1124 item.state = LVIS_SELECTED;
1125 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1126 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1127 ok(r != 0, "ret %d\n", r);
1128 item.iSubItem = 1;
1129 item.state = LVIS_DROPHILITED;
1130 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1131 ok(r != 0, "ret %d\n", r);
1133 memset (&item, 0xcc, sizeof (item));
1134 item.mask = LVIF_STATE;
1135 item.iItem = 0;
1136 item.iSubItem = 0;
1137 item.stateMask = -1;
1138 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1139 ok(r != 0, "ret %d\n", r);
1140 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1141 item.iSubItem = 1;
1142 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1143 ok(r != 0, "ret %d\n", r);
1144 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1146 /* some notnull but meaningless masks */
1147 memset (&item, 0, sizeof(item));
1148 item.mask = LVIF_NORECOMPUTE;
1149 item.iItem = 0;
1150 item.iSubItem = 0;
1151 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1152 ok(r != 0, "ret %d\n", r);
1153 memset (&item, 0, sizeof(item));
1154 item.mask = LVIF_DI_SETITEM;
1155 item.iItem = 0;
1156 item.iSubItem = 0;
1157 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1158 ok(r != 0, "ret %d\n", r);
1160 /* set text to callback value already having it */
1161 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1162 expect(TRUE, r);
1163 memset (&item, 0, sizeof (item));
1164 item.mask = LVIF_TEXT;
1165 item.pszText = LPSTR_TEXTCALLBACK;
1166 item.iItem = 0;
1167 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1168 ok(r == 0, "ret %d\n", r);
1169 memset (&item, 0, sizeof (item));
1171 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1173 item.pszText = LPSTR_TEXTCALLBACK;
1174 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1175 expect(TRUE, r);
1177 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1178 "check callback text comparison rule", FALSE);
1180 DestroyWindow(hwnd);
1183 static void test_columns(void)
1185 HWND hwnd, hwndheader;
1186 LVCOLUMN column;
1187 DWORD rc;
1188 INT order[2];
1190 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1191 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1192 ok(hwnd != NULL, "failed to create listview window\n");
1194 /* Add a column with no mask */
1195 memset(&column, 0xcc, sizeof(column));
1196 column.mask = 0;
1197 rc = ListView_InsertColumn(hwnd, 0, &column);
1198 ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
1200 /* Check its width */
1201 rc = ListView_GetColumnWidth(hwnd, 0);
1202 ok(rc==10 ||
1203 broken(rc==0), /* win9x */
1204 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1206 DestroyWindow(hwnd);
1208 /* LVM_GETCOLUMNORDERARRAY */
1209 hwnd = create_listview_control(LVS_REPORT);
1210 hwndheader = subclass_header(hwnd);
1212 memset(&column, 0, sizeof(column));
1213 column.mask = LVCF_WIDTH;
1214 column.cx = 100;
1215 rc = ListView_InsertColumn(hwnd, 0, &column);
1216 ok(rc == 0, "Inserting column failed with %d\n", rc);
1218 column.cx = 200;
1219 rc = ListView_InsertColumn(hwnd, 1, &column);
1220 ok(rc == 1, "Inserting column failed with %d\n", rc);
1222 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1224 rc = SendMessage(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1225 ok(rc != 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1226 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1227 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1229 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1231 DestroyWindow(hwnd);
1233 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1234 static WNDPROC listviewWndProc;
1235 static HIMAGELIST test_create_imagelist;
1237 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1239 LRESULT ret;
1241 if (uMsg == WM_CREATE)
1243 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1244 lpcs->style |= LVS_REPORT;
1246 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1247 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1248 return ret;
1251 static void test_create(void)
1253 HWND hList;
1254 HWND hHeader;
1255 LONG_PTR ret;
1256 LONG r;
1257 LVCOLUMNA col;
1258 RECT rect;
1259 WNDCLASSEX cls;
1260 DWORD style;
1262 cls.cbSize = sizeof(WNDCLASSEX);
1263 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1264 listviewWndProc = cls.lpfnWndProc;
1265 cls.lpfnWndProc = create_test_wndproc;
1266 cls.lpszClassName = "MyListView32";
1267 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1269 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1270 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1271 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1272 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1274 if (!IsWindow(hHeader))
1276 /* version 4.0 */
1277 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1278 DestroyWindow(hList);
1279 return;
1282 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1283 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1284 DestroyWindow(hList);
1286 /* header isn't created on LVS_ICON and LVS_LIST styles */
1287 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1288 GetModuleHandle(NULL), 0);
1289 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1290 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1291 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1292 /* insert column */
1293 memset(&col, 0, sizeof(LVCOLUMNA));
1294 col.mask = LVCF_WIDTH;
1295 col.cx = 100;
1296 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1297 ok(r == 0, "Expected 0 column's inserted\n");
1298 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1299 ok(IsWindow(hHeader), "Header should be created\n");
1300 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1301 style = GetWindowLong(hHeader, GWL_STYLE);
1302 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1303 DestroyWindow(hList);
1305 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1306 GetModuleHandle(NULL), 0);
1307 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1308 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1309 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1310 /* insert column */
1311 memset(&col, 0, sizeof(LVCOLUMNA));
1312 col.mask = LVCF_WIDTH;
1313 col.cx = 100;
1314 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1315 ok(r == 0, "Expected 0 column's inserted\n");
1316 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1317 ok(IsWindow(hHeader), "Header should be created\n");
1318 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1319 DestroyWindow(hList);
1321 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1322 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1323 GetModuleHandle(NULL), 0);
1324 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1325 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1326 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1327 ok(IsWindow(hHeader), "Header should be created\n");
1328 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1329 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1330 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1331 ok(IsWindow(hHeader), "Header should be created\n");
1332 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1333 DestroyWindow(hList);
1335 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1336 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1337 GetModuleHandle(NULL), 0);
1338 ret = SetWindowLongPtr(hList, GWL_STYLE,
1339 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1340 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1341 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1342 ok(IsWindow(hHeader), "Header should be created\n");
1343 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1344 ret = SetWindowLongPtr(hList, GWL_STYLE,
1345 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1346 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1347 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1348 ok(IsWindow(hHeader), "Header should be created\n");
1349 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1350 DestroyWindow(hList);
1352 /* LVS_REPORT without WS_VISIBLE */
1353 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1354 GetModuleHandle(NULL), 0);
1355 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1356 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1357 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1358 /* insert column */
1359 memset(&col, 0, sizeof(LVCOLUMNA));
1360 col.mask = LVCF_WIDTH;
1361 col.cx = 100;
1362 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1363 ok(r == 0, "Expected 0 column's inserted\n");
1364 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1365 ok(IsWindow(hHeader), "Header should be created\n");
1366 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1367 DestroyWindow(hList);
1369 /* LVS_REPORT without WS_VISIBLE, try to show it */
1370 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1371 GetModuleHandle(NULL), 0);
1372 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1373 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1374 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1375 ShowWindow(hList, SW_SHOW);
1376 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1377 ok(IsWindow(hHeader), "Header should be created\n");
1378 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1379 DestroyWindow(hList);
1381 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1382 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1383 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1384 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1385 ok(IsWindow(hHeader), "Header should be created\n");
1386 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1387 /* HDS_DRAGDROP set by default */
1388 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1389 DestroyWindow(hList);
1391 /* setting LVS_EX_HEADERDRAGDROP creates header */
1392 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1393 GetModuleHandle(NULL), 0);
1394 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1395 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1396 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1397 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1398 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1399 ok(IsWindow(hHeader) ||
1400 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1401 "Header should be created\n");
1402 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1403 DestroyWindow(hList);
1405 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1406 hList = create_listview_control(LVS_ICON);
1407 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1408 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1409 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1410 DestroyWindow(hList);
1412 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1413 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1414 GetModuleHandle(NULL), 0);
1415 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1416 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1418 rect.left = LVIR_BOUNDS;
1419 rect.top = 1;
1420 rect.right = rect.bottom = -10;
1421 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1422 ok(r != 0, "Expected not-null LRESULT\n");
1424 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1425 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1426 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1428 DestroyWindow(hList);
1430 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1431 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1432 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1433 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1434 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1435 DestroyWindow(hList);
1438 static void test_redraw(void)
1440 HWND hwnd, hwndheader;
1441 HDC hdc;
1442 BOOL res;
1443 DWORD r;
1445 hwnd = create_listview_control(LVS_REPORT);
1446 hwndheader = subclass_header(hwnd);
1448 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1450 trace("invalidate & update\n");
1451 InvalidateRect(hwnd, NULL, TRUE);
1452 UpdateWindow(hwnd);
1453 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1455 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1457 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1458 /* 1. Without backbuffer */
1459 res = ListView_SetBkColor(hwnd, CLR_NONE);
1460 expect(TRUE, res);
1462 hdc = GetWindowDC(hwndparent);
1464 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1465 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1466 ok(r != 0, "Expected not zero result\n");
1467 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1468 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1470 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1471 expect(TRUE, res);
1473 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1474 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1475 ok(r != 0, "Expected not zero result\n");
1476 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1477 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1479 /* 2. With backbuffer */
1480 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1481 LVS_EX_DOUBLEBUFFER);
1482 res = ListView_SetBkColor(hwnd, CLR_NONE);
1483 expect(TRUE, res);
1485 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1486 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1487 ok(r != 0, "Expected not zero result\n");
1488 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1489 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1491 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1492 expect(TRUE, res);
1494 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1495 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1496 todo_wine ok(r != 0, "Expected not zero result\n");
1497 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1498 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1500 ReleaseDC(hwndparent, hdc);
1502 DestroyWindow(hwnd);
1505 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1507 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1509 if(msg == WM_NOTIFY) {
1510 NMHDR *nmhdr = (PVOID)lp;
1511 if(nmhdr->code == NM_CUSTOMDRAW) {
1512 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1513 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1514 switch(nmlvcd->nmcd.dwDrawStage) {
1515 case CDDS_PREPAINT:
1516 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1517 return CDRF_NOTIFYITEMDRAW;
1518 case CDDS_ITEMPREPAINT:
1519 nmlvcd->clrTextBk = CLR_DEFAULT;
1520 return CDRF_NOTIFYSUBITEMDRAW;
1521 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1522 clr = GetBkColor(nmlvcd->nmcd.hdc);
1523 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1524 return CDRF_NOTIFYPOSTPAINT;
1525 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1526 clr = GetBkColor(nmlvcd->nmcd.hdc);
1527 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1528 return CDRF_DODEFAULT;
1530 return CDRF_DODEFAULT;
1534 return DefWindowProcA(hwnd, msg, wp, lp);
1537 static void test_customdraw(void)
1539 HWND hwnd;
1540 WNDPROC oldwndproc;
1542 hwnd = create_listview_control(LVS_REPORT);
1544 insert_column(hwnd, 0);
1545 insert_column(hwnd, 1);
1546 insert_item(hwnd, 0);
1548 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1549 (LONG_PTR)cd_wndproc);
1551 InvalidateRect(hwnd, NULL, TRUE);
1552 UpdateWindow(hwnd);
1554 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1556 DestroyWindow(hwnd);
1559 static void test_icon_spacing(void)
1561 /* LVM_SETICONSPACING */
1562 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1564 HWND hwnd;
1565 WORD w, h;
1566 DWORD r;
1568 hwnd = create_listview_control(LVS_ICON);
1569 ok(hwnd != NULL, "failed to create a listview window\n");
1571 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1572 expect(NFR_ANSI, r);
1574 /* reset the icon spacing to defaults */
1575 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1577 /* now we can request what the defaults are */
1578 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1579 w = LOWORD(r);
1580 h = HIWORD(r);
1582 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1584 trace("test icon spacing\n");
1586 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1587 ok(r == MAKELONG(w, h) ||
1588 broken(r == MAKELONG(w, w)), /* win98 */
1589 "Expected %d, got %d\n", MAKELONG(w, h), r);
1591 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1592 if (r == 0)
1594 /* version 4.0 */
1595 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1596 DestroyWindow(hwnd);
1597 return;
1599 expect(MAKELONG(20,30), r);
1601 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1602 expect(MAKELONG(25,35), r);
1604 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1606 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1607 DestroyWindow(hwnd);
1610 static void test_color(void)
1612 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1614 HWND hwnd;
1615 DWORD r;
1616 int i;
1618 COLORREF color;
1619 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1621 hwnd = create_listview_control(LVS_REPORT);
1622 ok(hwnd != NULL, "failed to create a listview window\n");
1624 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1626 trace("test color seq\n");
1627 for (i = 0; i < 4; i++)
1629 color = colors[i];
1631 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1632 expect(TRUE, r);
1633 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1634 expect(color, r);
1636 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1637 expect (TRUE, r);
1638 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1639 expect(color, r);
1641 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1642 expect(TRUE, r);
1643 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1644 expect(color, r);
1647 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1649 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1650 DestroyWindow(hwnd);
1653 static void test_item_count(void)
1655 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1657 HWND hwnd;
1658 DWORD r;
1659 HDC hdc;
1660 HFONT hOldFont;
1661 TEXTMETRICA tm;
1662 RECT rect;
1663 INT height;
1665 LVITEM item0;
1666 LVITEM item1;
1667 LVITEM item2;
1668 static CHAR item0text[] = "item0";
1669 static CHAR item1text[] = "item1";
1670 static CHAR item2text[] = "item2";
1672 hwnd = create_listview_control(LVS_REPORT);
1673 ok(hwnd != NULL, "failed to create a listview window\n");
1675 /* resize in dpiaware manner to fit all 3 items added */
1676 hdc = GetDC(0);
1677 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1678 GetTextMetricsA(hdc, &tm);
1679 /* 2 extra pixels for bounds and header border */
1680 height = tm.tmHeight + 2;
1681 SelectObject(hdc, hOldFont);
1682 ReleaseDC(0, hdc);
1684 GetWindowRect(hwnd, &rect);
1685 /* 3 items + 1 header + 1 to be sure */
1686 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1688 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1690 trace("test item count\n");
1692 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1693 expect(0, r);
1695 /* [item0] */
1696 item0.mask = LVIF_TEXT;
1697 item0.iItem = 0;
1698 item0.iSubItem = 0;
1699 item0.pszText = item0text;
1700 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1701 expect(0, r);
1703 /* [item0, item1] */
1704 item1.mask = LVIF_TEXT;
1705 item1.iItem = 1;
1706 item1.iSubItem = 0;
1707 item1.pszText = item1text;
1708 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1709 expect(1, r);
1711 /* [item0, item1, item2] */
1712 item2.mask = LVIF_TEXT;
1713 item2.iItem = 2;
1714 item2.iSubItem = 0;
1715 item2.pszText = item2text;
1716 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1717 expect(2, r);
1719 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1720 expect(3, r);
1722 /* [item0, item1] */
1723 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1724 expect(TRUE, r);
1726 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1727 expect(2, r);
1729 /* [] */
1730 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1731 expect(TRUE, r);
1733 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1734 expect(0, r);
1736 /* [item0] */
1737 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1738 expect(0, r);
1740 /* [item0, item1] */
1741 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1742 expect(1, r);
1744 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1745 expect(2, r);
1747 /* [item0, item1, item2] */
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 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1756 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1757 DestroyWindow(hwnd);
1760 static void test_item_position(void)
1762 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1764 HWND hwnd;
1765 DWORD r;
1766 POINT position;
1768 LVITEM item0;
1769 LVITEM item1;
1770 LVITEM item2;
1771 static CHAR item0text[] = "item0";
1772 static CHAR item1text[] = "item1";
1773 static CHAR item2text[] = "item2";
1775 hwnd = create_listview_control(LVS_ICON);
1776 ok(hwnd != NULL, "failed to create a listview window\n");
1778 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1780 trace("test item position\n");
1782 /* [item0] */
1783 item0.mask = LVIF_TEXT;
1784 item0.iItem = 0;
1785 item0.iSubItem = 0;
1786 item0.pszText = item0text;
1787 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1788 expect(0, r);
1790 /* [item0, item1] */
1791 item1.mask = LVIF_TEXT;
1792 item1.iItem = 1;
1793 item1.iSubItem = 0;
1794 item1.pszText = item1text;
1795 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1796 expect(1, r);
1798 /* [item0, item1, item2] */
1799 item2.mask = LVIF_TEXT;
1800 item2.iItem = 2;
1801 item2.iSubItem = 0;
1802 item2.pszText = item2text;
1803 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1804 expect(2, r);
1806 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1807 expect(TRUE, r);
1808 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1809 expect(TRUE, r);
1810 expect2(10, 5, position.x, position.y);
1812 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1813 expect(TRUE, r);
1814 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1815 expect(TRUE, r);
1816 expect2(0, 0, position.x, position.y);
1818 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1819 expect(TRUE, r);
1820 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1821 expect(TRUE, r);
1822 expect2(20, 20, position.x, position.y);
1824 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1826 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1827 DestroyWindow(hwnd);
1830 static void test_getorigin(void)
1832 /* LVM_GETORIGIN */
1834 HWND hwnd;
1835 DWORD r;
1836 POINT position;
1838 position.x = position.y = 0;
1840 hwnd = create_listview_control(LVS_ICON);
1841 ok(hwnd != NULL, "failed to create a listview window\n");
1842 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1843 trace("test get origin results\n");
1844 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1845 expect(TRUE, r);
1846 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1847 DestroyWindow(hwnd);
1849 hwnd = create_listview_control(LVS_SMALLICON);
1850 ok(hwnd != NULL, "failed to create a listview window\n");
1851 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1852 trace("test get origin results\n");
1853 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1854 expect(TRUE, r);
1855 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1856 DestroyWindow(hwnd);
1858 hwnd = create_listview_control(LVS_LIST);
1859 ok(hwnd != NULL, "failed to create a listview window\n");
1860 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1861 trace("test get origin results\n");
1862 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1863 expect(FALSE, r);
1864 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1865 DestroyWindow(hwnd);
1867 hwnd = create_listview_control(LVS_REPORT);
1868 ok(hwnd != NULL, "failed to create a listview window\n");
1869 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1870 trace("test get origin results\n");
1871 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1872 expect(FALSE, r);
1873 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1874 DestroyWindow(hwnd);
1878 static void test_multiselect(void)
1880 typedef struct t_select_task
1882 const char *descr;
1883 int initPos;
1884 int loopVK;
1885 int count;
1886 int result;
1887 } select_task;
1889 HWND hwnd;
1890 DWORD r;
1891 int i,j,item_count,selected_count;
1892 static const int items=5;
1893 BYTE kstate[256];
1894 select_task task;
1895 LONG_PTR style;
1896 LVITEMA item;
1898 static struct t_select_task task_list[] = {
1899 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1900 { "using VK_UP", -1, VK_UP, -1, -1 },
1901 { "using VK_END", 0, VK_END, 1, -1 },
1902 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1906 hwnd = create_listview_control(LVS_REPORT);
1908 for (i=0;i<items;i++) {
1909 insert_item(hwnd, 0);
1912 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1914 expect(items,item_count);
1916 for (i=0;i<4;i++) {
1917 task = task_list[i];
1919 /* deselect all items */
1920 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1921 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1923 /* set initial position */
1924 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1925 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1927 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1929 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1931 /* Set SHIFT key pressed */
1932 GetKeyboardState(kstate);
1933 kstate[VK_SHIFT]=0x80;
1934 SetKeyboardState(kstate);
1936 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1937 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1938 expect(0,r);
1939 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1940 expect(0,r);
1943 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1945 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);
1947 /* Set SHIFT key released */
1948 GetKeyboardState(kstate);
1949 kstate[VK_SHIFT]=0x00;
1950 SetKeyboardState(kstate);
1952 DestroyWindow(hwnd);
1954 /* make multiple selection, then switch to LVS_SINGLESEL */
1955 hwnd = create_listview_control(LVS_REPORT);
1956 for (i=0;i<items;i++) {
1957 insert_item(hwnd, 0);
1959 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1960 expect(items,item_count);
1962 /* try with NULL pointer */
1963 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
1964 expect(FALSE, r);
1966 /* select all, check notifications */
1967 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1969 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1971 item.stateMask = LVIS_SELECTED;
1972 item.state = LVIS_SELECTED;
1973 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1974 expect(TRUE, r);
1976 ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
1977 "select all notification", FALSE);
1979 /* deselect all items */
1980 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1981 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1982 for (i=0;i<3;i++) {
1983 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
1986 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1987 expect(3, r);
1988 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1989 expect(-1, r);
1991 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1992 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
1993 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
1994 /* check that style is accepted */
1995 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1996 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
1998 for (i=0;i<3;i++) {
1999 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2000 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2002 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2003 expect(3, r);
2004 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2005 expect(3, r);
2007 /* select one more */
2008 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2010 for (i=0;i<3;i++) {
2011 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2012 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2014 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2015 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2017 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2018 expect(1, r);
2019 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2020 expect(-1, r);
2022 /* try to select all on LVS_SINGLESEL */
2023 memset(&item, 0, sizeof(item));
2024 item.stateMask = LVIS_SELECTED;
2025 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2026 expect(TRUE, r);
2027 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2029 item.stateMask = LVIS_SELECTED;
2030 item.state = LVIS_SELECTED;
2031 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2032 expect(FALSE, r);
2034 r = ListView_GetSelectedCount(hwnd);
2035 expect(0, r);
2036 r = ListView_GetSelectionMark(hwnd);
2037 expect(-1, r);
2039 /* try to deselect all on LVS_SINGLESEL */
2040 item.stateMask = LVIS_SELECTED;
2041 item.state = LVIS_SELECTED;
2042 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2043 expect(TRUE, r);
2045 item.stateMask = LVIS_SELECTED;
2046 item.state = 0;
2047 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2048 expect(TRUE, r);
2049 r = ListView_GetSelectedCount(hwnd);
2050 expect(0, r);
2052 DestroyWindow(hwnd);
2055 static void test_subitem_rect(void)
2057 HWND hwnd;
2058 DWORD r;
2059 LVCOLUMN col;
2060 RECT rect;
2062 /* test LVM_GETSUBITEMRECT for header */
2063 hwnd = create_listview_control(LVS_REPORT);
2064 ok(hwnd != NULL, "failed to create a listview window\n");
2065 /* add some columns */
2066 memset(&col, 0, sizeof(LVCOLUMN));
2067 col.mask = LVCF_WIDTH;
2068 col.cx = 100;
2069 r = -1;
2070 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2071 expect(0, r);
2072 col.cx = 150;
2073 r = -1;
2074 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2075 expect(1, r);
2076 col.cx = 200;
2077 r = -1;
2078 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2079 expect(2, r);
2080 /* item = -1 means header, subitem index is 1 based */
2081 rect.left = LVIR_BOUNDS;
2082 rect.top = 0;
2083 rect.right = rect.bottom = 0;
2084 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2085 expect(0, r);
2087 rect.left = LVIR_BOUNDS;
2088 rect.top = 1;
2089 rect.right = rect.bottom = 0;
2090 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2092 ok(r != 0, "Expected not-null LRESULT\n");
2093 expect(100, rect.left);
2094 expect(250, rect.right);
2095 todo_wine
2096 expect(3, rect.top);
2098 rect.left = LVIR_BOUNDS;
2099 rect.top = 2;
2100 rect.right = rect.bottom = 0;
2101 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2103 ok(r != 0, "Expected not-null LRESULT\n");
2104 expect(250, rect.left);
2105 expect(450, rect.right);
2106 todo_wine
2107 expect(3, rect.top);
2109 /* item LVS_REPORT padding isn't applied to subitems */
2110 insert_item(hwnd, 0);
2112 rect.left = LVIR_BOUNDS;
2113 rect.top = 1;
2114 rect.right = rect.bottom = 0;
2115 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2116 ok(r != 0, "Expected not-null LRESULT\n");
2117 expect(100, rect.left);
2118 expect(250, rect.right);
2120 rect.left = LVIR_ICON;
2121 rect.top = 1;
2122 rect.right = rect.bottom = 0;
2123 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2124 ok(r != 0, "Expected not-null LRESULT\n");
2125 /* no icon attached - zero width rectangle, with no left padding */
2126 expect(100, rect.left);
2127 expect(100, rect.right);
2129 rect.left = LVIR_LABEL;
2130 rect.top = 1;
2131 rect.right = rect.bottom = 0;
2132 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2133 ok(r != 0, "Expected not-null LRESULT\n");
2134 /* same as full LVIR_BOUNDS */
2135 expect(100, rect.left);
2136 expect(250, rect.right);
2138 SendMessage(hwnd, LVM_SCROLL, 10, 0);
2140 rect.left = LVIR_BOUNDS;
2141 rect.top = 1;
2142 rect.right = rect.bottom = 0;
2143 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2144 ok(r != 0, "Expected not-null LRESULT\n");
2145 expect(90, rect.left);
2146 expect(240, rect.right);
2148 SendMessage(hwnd, LVM_SCROLL, -10, 0);
2150 DestroyWindow(hwnd);
2152 /* try it for non LVS_REPORT style */
2153 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2154 GetModuleHandle(NULL), 0);
2155 rect.left = LVIR_BOUNDS;
2156 rect.top = 1;
2157 rect.right = rect.bottom = -10;
2158 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2159 ok(r == 0, "Expected not-null LRESULT\n");
2160 /* rect is unchanged */
2161 expect(0, rect.left);
2162 expect(-10, rect.right);
2163 expect(1, rect.top);
2164 expect(-10, rect.bottom);
2165 DestroyWindow(hwnd);
2168 /* comparison callback for test_sorting */
2169 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2171 if (first == second) return 0;
2172 return (first > second ? 1 : -1);
2175 static void test_sorting(void)
2177 HWND hwnd;
2178 LVITEMA item = {0};
2179 DWORD r;
2180 LONG_PTR style;
2181 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2182 CHAR buff[10];
2184 hwnd = create_listview_control(LVS_REPORT);
2185 ok(hwnd != NULL, "failed to create a listview window\n");
2187 /* insert some items */
2188 item.mask = LVIF_PARAM | LVIF_STATE;
2189 item.state = LVIS_SELECTED;
2190 item.iItem = 0;
2191 item.iSubItem = 0;
2192 item.lParam = 3;
2193 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2194 expect(0, r);
2196 item.mask = LVIF_PARAM;
2197 item.iItem = 1;
2198 item.iSubItem = 0;
2199 item.lParam = 2;
2200 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2201 expect(1, r);
2203 item.mask = LVIF_STATE | LVIF_PARAM;
2204 item.state = LVIS_SELECTED;
2205 item.iItem = 2;
2206 item.iSubItem = 0;
2207 item.lParam = 4;
2208 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2209 expect(2, r);
2211 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2212 expect(-1, r);
2214 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2215 expect(2, r);
2217 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2218 expect(TRUE, r);
2220 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2221 expect(2, r);
2222 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2223 expect(-1, r);
2224 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2225 expect(0, r);
2226 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2227 expect(LVIS_SELECTED, r);
2228 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2229 expect(LVIS_SELECTED, r);
2231 DestroyWindow(hwnd);
2233 /* switch to LVS_SORTASCENDING when some items added */
2234 hwnd = create_listview_control(LVS_REPORT);
2235 ok(hwnd != NULL, "failed to create a listview window\n");
2237 item.mask = LVIF_TEXT;
2238 item.iItem = 0;
2239 item.iSubItem = 0;
2240 item.pszText = names[1];
2241 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2242 expect(0, r);
2244 item.mask = LVIF_TEXT;
2245 item.iItem = 1;
2246 item.iSubItem = 0;
2247 item.pszText = names[2];
2248 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2249 expect(1, r);
2251 item.mask = LVIF_TEXT;
2252 item.iItem = 2;
2253 item.iSubItem = 0;
2254 item.pszText = names[0];
2255 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2256 expect(2, r);
2258 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2259 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2260 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2261 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2263 /* no sorting performed when switched to LVS_SORTASCENDING */
2264 item.mask = LVIF_TEXT;
2265 item.iItem = 0;
2266 item.pszText = buff;
2267 item.cchTextMax = sizeof(buff);
2268 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2269 expect(TRUE, r);
2270 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2272 item.iItem = 1;
2273 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2274 expect(TRUE, r);
2275 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2277 item.iItem = 2;
2278 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2279 expect(TRUE, r);
2280 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2282 /* adding new item doesn't resort list */
2283 item.mask = LVIF_TEXT;
2284 item.iItem = 3;
2285 item.iSubItem = 0;
2286 item.pszText = names[3];
2287 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2288 expect(3, r);
2290 item.mask = LVIF_TEXT;
2291 item.iItem = 0;
2292 item.pszText = buff;
2293 item.cchTextMax = sizeof(buff);
2294 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2295 expect(TRUE, r);
2296 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2298 item.iItem = 1;
2299 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2300 expect(TRUE, r);
2301 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2303 item.iItem = 2;
2304 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2305 expect(TRUE, r);
2306 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2308 item.iItem = 3;
2309 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2310 expect(TRUE, r);
2311 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2313 /* corner case - item should be placed at first position */
2314 item.mask = LVIF_TEXT;
2315 item.iItem = 4;
2316 item.iSubItem = 0;
2317 item.pszText = names[4];
2318 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2319 expect(0, r);
2321 item.iItem = 0;
2322 item.pszText = buff;
2323 item.cchTextMax = sizeof(buff);
2324 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2325 expect(TRUE, r);
2326 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2328 item.iItem = 1;
2329 item.pszText = buff;
2330 item.cchTextMax = sizeof(buff);
2331 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2332 expect(TRUE, r);
2333 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2335 item.iItem = 2;
2336 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2337 expect(TRUE, r);
2338 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2340 item.iItem = 3;
2341 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2342 expect(TRUE, r);
2343 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2345 item.iItem = 4;
2346 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2347 expect(TRUE, r);
2348 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2350 DestroyWindow(hwnd);
2353 static void test_ownerdata(void)
2355 HWND hwnd;
2356 LONG_PTR style, ret;
2357 DWORD res;
2358 LVITEMA item;
2360 /* it isn't possible to set LVS_OWNERDATA after creation */
2361 if (g_is_below_5)
2363 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2365 else
2367 hwnd = create_listview_control(LVS_REPORT);
2368 ok(hwnd != NULL, "failed to create a listview window\n");
2369 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2370 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2372 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2374 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2375 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2376 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2377 "try to switch to LVS_OWNERDATA seq", FALSE);
2379 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2380 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2381 DestroyWindow(hwnd);
2384 /* try to set LVS_OWNERDATA after creation just having it */
2385 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2386 ok(hwnd != NULL, "failed to create a listview window\n");
2387 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2388 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2390 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2392 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2393 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2394 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2395 "try to switch to LVS_OWNERDATA seq", FALSE);
2396 DestroyWindow(hwnd);
2398 /* try to remove LVS_OWNERDATA after creation just having it */
2399 if (g_is_below_5)
2401 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2403 else
2405 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2406 ok(hwnd != NULL, "failed to create a listview window\n");
2407 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2408 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2410 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2412 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2413 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2414 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2415 "try to switch to LVS_OWNERDATA seq", FALSE);
2416 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2417 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2418 DestroyWindow(hwnd);
2421 /* try select an item */
2422 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2423 ok(hwnd != NULL, "failed to create a listview window\n");
2424 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2425 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2426 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2427 expect(0, res);
2428 memset(&item, 0, sizeof(item));
2429 item.stateMask = LVIS_SELECTED;
2430 item.state = LVIS_SELECTED;
2431 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2432 expect(TRUE, res);
2433 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2434 expect(1, res);
2435 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2436 expect(1, res);
2437 DestroyWindow(hwnd);
2439 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2440 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2441 ok(hwnd != NULL, "failed to create a listview window\n");
2442 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2443 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2444 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2445 expect(1, res);
2446 memset(&item, 0, sizeof(item));
2447 item.mask = LVIF_STATE;
2448 item.iItem = 0;
2449 item.stateMask = LVIS_SELECTED;
2450 item.state = LVIS_SELECTED;
2451 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2452 expect(FALSE, res);
2453 DestroyWindow(hwnd);
2455 /* check notifications after focused/selected changed */
2456 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2457 ok(hwnd != NULL, "failed to create a listview window\n");
2458 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2459 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2461 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2463 memset(&item, 0, sizeof(item));
2464 item.stateMask = LVIS_SELECTED;
2465 item.state = LVIS_SELECTED;
2466 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2467 expect(TRUE, res);
2469 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2470 "ownerdata select notification", TRUE);
2472 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2474 memset(&item, 0, sizeof(item));
2475 item.stateMask = LVIS_FOCUSED;
2476 item.state = LVIS_FOCUSED;
2477 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2478 expect(TRUE, res);
2480 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2481 "ownerdata focus notification", TRUE);
2483 /* select all, check notifications */
2484 item.stateMask = LVIS_SELECTED;
2485 item.state = 0;
2486 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2487 expect(TRUE, res);
2489 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2491 item.stateMask = LVIS_SELECTED;
2492 item.state = LVIS_SELECTED;
2494 g_dump_itemchanged = TRUE;
2495 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2496 expect(TRUE, res);
2497 g_dump_itemchanged = FALSE;
2499 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2500 "ownerdata select all notification", TRUE);
2502 /* select all again, note that all items are selected already */
2503 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2504 item.stateMask = LVIS_SELECTED;
2505 item.state = LVIS_SELECTED;
2506 g_dump_itemchanged = TRUE;
2507 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2508 expect(TRUE, res);
2509 g_dump_itemchanged = FALSE;
2510 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2511 "ownerdata select all notification", TRUE);
2512 /* deselect all */
2513 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2514 item.stateMask = LVIS_SELECTED;
2515 item.state = 0;
2516 g_dump_itemchanged = TRUE;
2517 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2518 expect(TRUE, res);
2519 g_dump_itemchanged = FALSE;
2520 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2521 "ownerdata deselect all notification", TRUE);
2523 /* select one, then deselect all */
2524 item.stateMask = LVIS_SELECTED;
2525 item.state = LVIS_SELECTED;
2526 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2527 expect(TRUE, res);
2528 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2529 item.stateMask = LVIS_SELECTED;
2530 item.state = 0;
2531 g_dump_itemchanged = TRUE;
2532 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2533 expect(TRUE, res);
2534 g_dump_itemchanged = FALSE;
2535 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2536 "ownerdata select all notification", TRUE);
2538 /* remove focused, try to focus all */
2539 item.stateMask = LVIS_FOCUSED;
2540 item.state = LVIS_FOCUSED;
2541 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2542 expect(TRUE, res);
2543 item.stateMask = LVIS_FOCUSED;
2544 item.state = 0;
2545 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2546 expect(TRUE, res);
2547 item.stateMask = LVIS_FOCUSED;
2548 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
2549 expect(0, res);
2550 /* setting all to focused returns failure value */
2551 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2552 item.stateMask = LVIS_FOCUSED;
2553 item.state = LVIS_FOCUSED;
2554 g_dump_itemchanged = TRUE;
2555 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2556 expect(FALSE, res);
2557 g_dump_itemchanged = FALSE;
2558 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2559 "ownerdata focus all notification", FALSE);
2560 /* focus single item, remove all */
2561 item.stateMask = LVIS_FOCUSED;
2562 item.state = LVIS_FOCUSED;
2563 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2564 expect(TRUE, res);
2565 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2566 item.stateMask = LVIS_FOCUSED;
2567 item.state = 0;
2568 g_dump_itemchanged = TRUE;
2569 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2570 expect(TRUE, res);
2571 g_dump_itemchanged = FALSE;
2572 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
2573 "ownerdata remove focus all notification", TRUE);
2574 /* set all cut */
2575 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2576 item.stateMask = LVIS_CUT;
2577 item.state = LVIS_CUT;
2578 g_dump_itemchanged = TRUE;
2579 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2580 expect(TRUE, res);
2581 g_dump_itemchanged = FALSE;
2582 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2583 "ownerdata cut all notification", TRUE);
2584 /* all marked cut, try again */
2585 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2586 item.stateMask = LVIS_CUT;
2587 item.state = LVIS_CUT;
2588 g_dump_itemchanged = TRUE;
2589 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2590 expect(TRUE, res);
2591 g_dump_itemchanged = FALSE;
2592 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2593 "ownerdata cut all notification #2", TRUE);
2595 DestroyWindow(hwnd);
2597 /* check notifications on LVM_GETITEM */
2598 /* zero callback mask */
2599 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2600 ok(hwnd != NULL, "failed to create a listview window\n");
2601 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2602 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2604 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2606 memset(&item, 0, sizeof(item));
2607 item.stateMask = LVIS_SELECTED;
2608 item.mask = LVIF_STATE;
2609 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2610 expect(TRUE, res);
2612 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2613 "ownerdata getitem selected state 1", FALSE);
2615 /* non zero callback mask but not we asking for */
2616 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2617 expect(TRUE, res);
2619 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2621 memset(&item, 0, sizeof(item));
2622 item.stateMask = LVIS_SELECTED;
2623 item.mask = LVIF_STATE;
2624 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2625 expect(TRUE, res);
2627 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2628 "ownerdata getitem selected state 2", FALSE);
2630 /* LVIS_OVERLAYMASK callback mask, asking for index */
2631 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2633 memset(&item, 0, sizeof(item));
2634 item.stateMask = LVIS_OVERLAYMASK;
2635 item.mask = LVIF_STATE;
2636 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2637 expect(TRUE, res);
2639 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2640 "ownerdata getitem selected state 2", FALSE);
2642 DestroyWindow(hwnd);
2644 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2645 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
2646 ok(hwnd != NULL, "failed to create a listview window\n");
2647 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2648 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2649 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2650 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2651 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2652 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2653 DestroyWindow(hwnd);
2654 /* apparently it's allowed to switch these style on after creation */
2655 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2656 ok(hwnd != NULL, "failed to create a listview window\n");
2657 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2658 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2659 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2660 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2661 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2662 DestroyWindow(hwnd);
2664 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2665 ok(hwnd != NULL, "failed to create a listview window\n");
2666 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2667 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2668 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2669 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2670 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2671 DestroyWindow(hwnd);
2674 static void test_norecompute(void)
2676 static CHAR testA[] = "test";
2677 CHAR buff[10];
2678 LVITEMA item;
2679 HWND hwnd;
2680 DWORD res;
2682 /* self containing control */
2683 hwnd = create_listview_control(LVS_REPORT);
2684 ok(hwnd != NULL, "failed to create a listview window\n");
2685 memset(&item, 0, sizeof(item));
2686 item.mask = LVIF_TEXT | LVIF_STATE;
2687 item.iItem = 0;
2688 item.stateMask = LVIS_SELECTED;
2689 item.state = LVIS_SELECTED;
2690 item.pszText = testA;
2691 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2692 expect(0, res);
2693 /* retrieve with LVIF_NORECOMPUTE */
2694 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2695 item.iItem = 0;
2696 item.pszText = buff;
2697 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2698 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2699 expect(TRUE, res);
2700 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2702 item.mask = LVIF_TEXT;
2703 item.iItem = 1;
2704 item.pszText = LPSTR_TEXTCALLBACK;
2705 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2706 expect(1, res);
2708 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2709 item.iItem = 1;
2710 item.pszText = buff;
2711 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2713 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2714 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2715 expect(TRUE, res);
2716 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2717 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2718 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2720 DestroyWindow(hwnd);
2722 /* LVS_OWNERDATA */
2723 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2724 ok(hwnd != NULL, "failed to create a listview window\n");
2726 item.mask = LVIF_STATE;
2727 item.stateMask = LVIS_SELECTED;
2728 item.state = LVIS_SELECTED;
2729 item.iItem = 0;
2730 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2731 expect(0, res);
2733 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2734 item.iItem = 0;
2735 item.pszText = buff;
2736 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2737 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2738 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2739 expect(TRUE, res);
2740 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2741 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2742 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2744 DestroyWindow(hwnd);
2747 static void test_nosortheader(void)
2749 HWND hwnd, header;
2750 LONG_PTR style;
2752 hwnd = create_listview_control(LVS_REPORT);
2753 ok(hwnd != NULL, "failed to create a listview window\n");
2755 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2756 ok(IsWindow(header), "header expected\n");
2758 style = GetWindowLongPtr(header, GWL_STYLE);
2759 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2761 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2762 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2763 /* HDS_BUTTONS retained */
2764 style = GetWindowLongPtr(header, GWL_STYLE);
2765 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2767 DestroyWindow(hwnd);
2769 /* create with LVS_NOSORTHEADER */
2770 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
2771 ok(hwnd != NULL, "failed to create a listview window\n");
2773 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2774 ok(IsWindow(header), "header expected\n");
2776 style = GetWindowLongPtr(header, GWL_STYLE);
2777 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2779 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2780 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2781 /* not changed here */
2782 style = GetWindowLongPtr(header, GWL_STYLE);
2783 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2785 DestroyWindow(hwnd);
2788 static void test_setredraw(void)
2790 HWND hwnd;
2791 DWORD_PTR style;
2792 DWORD ret;
2793 HDC hdc;
2794 RECT rect;
2796 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2797 ok(hwnd != NULL, "failed to create a listview window\n");
2799 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2800 ListView seems to handle it internally without DefWinProc */
2802 /* default value first */
2803 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2804 expect(0, ret);
2805 /* disable */
2806 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2807 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2808 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2809 expect(0, ret);
2810 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2811 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2812 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2813 expect(0, ret);
2815 /* check update rect after redrawing */
2816 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2817 expect(0, ret);
2818 InvalidateRect(hwnd, NULL, FALSE);
2819 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
2820 rect.right = rect.bottom = 1;
2821 GetUpdateRect(hwnd, &rect, FALSE);
2822 expect(0, rect.right);
2823 expect(0, rect.bottom);
2825 /* WM_ERASEBKGND */
2826 hdc = GetWindowDC(hwndparent);
2827 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2828 expect(TRUE, ret);
2829 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2830 expect(0, ret);
2831 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
2832 expect(TRUE, ret);
2833 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2834 expect(0, ret);
2835 ReleaseDC(hwndparent, hdc);
2837 /* check notification messages to show that repainting is disabled */
2838 ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
2839 expect(TRUE, ret);
2840 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2841 expect(0, ret);
2842 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2844 InvalidateRect(hwnd, NULL, TRUE);
2845 UpdateWindow(hwnd);
2846 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2847 "redraw after WM_SETREDRAW (FALSE)", FALSE);
2849 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
2850 expect(TRUE, ret);
2851 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2852 InvalidateRect(hwnd, NULL, TRUE);
2853 UpdateWindow(hwnd);
2854 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2855 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
2857 /* message isn't forwarded to header */
2858 subclass_header(hwnd);
2859 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2860 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2861 expect(0, ret);
2862 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
2863 "WM_SETREDRAW: not forwarded to header", FALSE);
2865 DestroyWindow(hwnd);
2868 static void test_hittest(void)
2870 HWND hwnd;
2871 DWORD r;
2872 RECT bounds;
2873 LVITEMA item;
2874 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2875 POINT pos;
2876 INT x, y;
2877 HIMAGELIST himl, himl2;
2878 HBITMAP hbmp;
2880 hwnd = create_listview_control(LVS_REPORT);
2881 ok(hwnd != NULL, "failed to create a listview window\n");
2883 /* LVS_REPORT with a single subitem (2 columns) */
2884 insert_column(hwnd, 0);
2885 insert_column(hwnd, 1);
2886 insert_item(hwnd, 0);
2888 item.iSubItem = 0;
2889 /* the only purpose of that line is to be as long as a half item rect */
2890 item.pszText = text;
2891 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2892 expect(TRUE, r);
2894 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2895 expect(TRUE, r);
2896 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
2897 expect(TRUE, r);
2899 memset(&bounds, 0, sizeof(bounds));
2900 bounds.left = LVIR_BOUNDS;
2901 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
2902 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
2903 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
2904 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
2905 expect(TRUE, r);
2907 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2908 x = pos.x + 50; /* column half width */
2909 y = pos.y + (bounds.bottom - bounds.top) / 2;
2910 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE, __LINE__);
2911 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2912 x = pos.x + 150; /* outside column */
2913 y = pos.y + (bounds.bottom - bounds.top) / 2;
2914 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2915 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2916 y = (bounds.bottom - bounds.top) / 2;
2917 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2918 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2919 /* outside possible client rectangle (to right) */
2920 x = pos.x + 500;
2921 y = pos.y + (bounds.bottom - bounds.top) / 2;
2922 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2923 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2924 y = (bounds.bottom - bounds.top) / 2;
2925 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2926 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2927 /* subitem returned with -1 item too */
2928 x = pos.x + 150;
2929 y = -10;
2930 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2931 /* parent client area is 100x100 by default */
2932 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
2933 x = pos.x + 150; /* outside column */
2934 y = pos.y + (bounds.bottom - bounds.top) / 2;
2935 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE, __LINE__);
2936 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2937 y = (bounds.bottom - bounds.top) / 2;
2938 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE, __LINE__);
2939 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2940 /* the same with LVS_EX_FULLROWSELECT */
2941 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
2942 x = pos.x + 150; /* outside column */
2943 y = pos.y + (bounds.bottom - bounds.top) / 2;
2944 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE, __LINE__);
2945 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2946 y = (bounds.bottom - bounds.top) / 2;
2947 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2948 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
2949 x = pos.x + 150; /* outside column */
2950 y = pos.y + (bounds.bottom - bounds.top) / 2;
2951 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2952 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2953 y = (bounds.bottom - bounds.top) / 2;
2954 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2955 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2956 /* outside possible client rectangle (to right) */
2957 x = pos.x + 500;
2958 y = pos.y + (bounds.bottom - bounds.top) / 2;
2959 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE, __LINE__);
2960 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2961 y = (bounds.bottom - bounds.top) / 2;
2962 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE, __LINE__);
2963 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE, __LINE__);
2964 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2965 himl = ImageList_Create(16, 16, 0, 4, 4);
2966 ok(himl != NULL, "failed to create imagelist\n");
2967 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2968 ok(hbmp != NULL, "failed to create bitmap\n");
2969 r = ImageList_Add(himl, hbmp, 0);
2970 ok(r == 0, "should be zero\n");
2971 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2972 ok(hbmp != NULL, "failed to create bitmap\n");
2973 r = ImageList_Add(himl, hbmp, 0);
2974 ok(r == 1, "should be one\n");
2976 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2977 ok(r == 0, "should return zero\n");
2979 item.mask = LVIF_IMAGE;
2980 item.iImage = 0;
2981 item.iItem = 0;
2982 item.iSubItem = 0;
2983 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2984 expect(TRUE, r);
2985 /* on state icon */
2986 x = pos.x + 8;
2987 y = pos.y + (bounds.bottom - bounds.top) / 2;
2988 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE, __LINE__);
2989 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2990 y = (bounds.bottom - bounds.top) / 2;
2991 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2993 /* state icons indices are 1 based, check with valid index */
2994 item.mask = LVIF_STATE;
2995 item.state = INDEXTOSTATEIMAGEMASK(1);
2996 item.stateMask = LVIS_STATEIMAGEMASK;
2997 item.iItem = 0;
2998 item.iSubItem = 0;
2999 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3000 expect(TRUE, r);
3001 /* on state icon */
3002 x = pos.x + 8;
3003 y = pos.y + (bounds.bottom - bounds.top) / 2;
3004 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE, __LINE__);
3005 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
3006 y = (bounds.bottom - bounds.top) / 2;
3007 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
3009 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3010 ok(himl2 == himl, "should return handle\n");
3012 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3013 ok(r == 0, "should return zero\n");
3014 /* on item icon */
3015 x = pos.x + 8;
3016 y = pos.y + (bounds.bottom - bounds.top) / 2;
3017 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE, __LINE__);
3018 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
3019 y = (bounds.bottom - bounds.top) / 2;
3020 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
3022 DestroyWindow(hwnd);
3025 static void test_getviewrect(void)
3027 HWND hwnd;
3028 DWORD r;
3029 RECT rect;
3030 LVITEMA item;
3032 hwnd = create_listview_control(LVS_REPORT);
3033 ok(hwnd != NULL, "failed to create a listview window\n");
3035 /* empty */
3036 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3037 expect(TRUE, r);
3039 insert_column(hwnd, 0);
3040 insert_column(hwnd, 1);
3042 memset(&item, 0, sizeof(item));
3043 item.iItem = 0;
3044 item.iSubItem = 0;
3045 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3047 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3048 expect(TRUE, r);
3049 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3050 expect(TRUE, r);
3052 rect.left = rect.right = rect.top = rect.bottom = -1;
3053 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3054 expect(TRUE, r);
3055 /* left is set to (2e31-1) - XP SP2 */
3056 expect(0, rect.right);
3057 expect(0, rect.top);
3058 expect(0, rect.bottom);
3060 /* switch to LVS_ICON */
3061 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3063 rect.left = rect.right = rect.top = rect.bottom = -1;
3064 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3065 expect(TRUE, r);
3066 expect(0, rect.left);
3067 expect(0, rect.top);
3068 /* precise value differs for 2k, XP and Vista */
3069 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3070 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3072 DestroyWindow(hwnd);
3075 static void test_getitemposition(void)
3077 HWND hwnd, header;
3078 DWORD r;
3079 POINT pt;
3080 RECT rect;
3082 hwnd = create_listview_control(LVS_REPORT);
3083 ok(hwnd != NULL, "failed to create a listview window\n");
3084 header = subclass_header(hwnd);
3086 /* LVS_REPORT, single item, no columns added */
3087 insert_item(hwnd, 0);
3089 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3091 pt.x = pt.y = -1;
3092 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3093 expect(TRUE, r);
3094 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3096 /* LVS_REPORT, single item, single column */
3097 insert_column(hwnd, 0);
3099 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3101 pt.x = pt.y = -1;
3102 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3103 expect(TRUE, r);
3104 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3106 memset(&rect, 0, sizeof(rect));
3107 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3108 /* some padding? */
3109 expect(2, pt.x);
3110 /* offset by header height */
3111 expect(rect.bottom - rect.top, pt.y);
3113 DestroyWindow(hwnd);
3116 static void test_columnscreation(void)
3118 HWND hwnd, header;
3119 DWORD r;
3121 hwnd = create_listview_control(LVS_REPORT);
3122 ok(hwnd != NULL, "failed to create a listview window\n");
3124 insert_item(hwnd, 0);
3126 /* headers columns aren't created automatically */
3127 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3128 ok(IsWindow(header), "Expected header handle\n");
3129 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3130 expect(0, r);
3132 DestroyWindow(hwnd);
3135 static void test_getitemrect(void)
3137 HWND hwnd;
3138 HIMAGELIST himl;
3139 HBITMAP hbm;
3140 RECT rect;
3141 DWORD r;
3142 LVITEMA item;
3143 LVCOLUMNA col;
3144 INT order[2];
3145 POINT pt;
3147 /* rectangle isn't empty for empty text items */
3148 hwnd = create_listview_control(LVS_LIST);
3149 memset(&item, 0, sizeof(item));
3150 item.mask = 0;
3151 item.iItem = 0;
3152 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3153 expect(0, r);
3154 rect.left = LVIR_LABEL;
3155 SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3156 expect(0, rect.left);
3157 expect(0, rect.top);
3158 todo_wine expect(96, rect.right);
3159 DestroyWindow(hwnd);
3161 hwnd = create_listview_control(LVS_REPORT);
3162 ok(hwnd != NULL, "failed to create a listview window\n");
3164 /* empty item */
3165 memset(&item, 0, sizeof(item));
3166 item.iItem = 0;
3167 item.iSubItem = 0;
3168 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3169 expect(0, r);
3171 rect.left = LVIR_BOUNDS;
3172 rect.right = rect.top = rect.bottom = -1;
3173 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3174 expect(TRUE, r);
3176 /* zero width rectangle with no padding */
3177 expect(0, rect.left);
3178 expect(0, rect.right);
3180 insert_column(hwnd, 0);
3181 insert_column(hwnd, 1);
3183 col.mask = LVCF_WIDTH;
3184 col.cx = 50;
3185 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3186 expect(TRUE, r);
3188 col.mask = LVCF_WIDTH;
3189 col.cx = 100;
3190 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3191 expect(TRUE, r);
3193 rect.left = LVIR_BOUNDS;
3194 rect.right = rect.top = rect.bottom = -1;
3195 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3196 expect(TRUE, r);
3198 /* still no left padding */
3199 expect(0, rect.left);
3200 expect(150, rect.right);
3202 rect.left = LVIR_SELECTBOUNDS;
3203 rect.right = rect.top = rect.bottom = -1;
3204 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3205 expect(TRUE, r);
3206 /* padding */
3207 expect(2, rect.left);
3209 rect.left = LVIR_LABEL;
3210 rect.right = rect.top = rect.bottom = -1;
3211 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3212 expect(TRUE, r);
3213 /* padding, column width */
3214 expect(2, rect.left);
3215 expect(50, rect.right);
3217 /* no icons attached */
3218 rect.left = LVIR_ICON;
3219 rect.right = rect.top = rect.bottom = -1;
3220 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3221 expect(TRUE, r);
3222 /* padding */
3223 expect(2, rect.left);
3224 expect(2, rect.right);
3226 /* change order */
3227 order[0] = 1; order[1] = 0;
3228 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3229 expect(TRUE, r);
3230 pt.x = -1;
3231 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3232 expect(TRUE, r);
3233 /* 1 indexed column width + padding */
3234 expect(102, pt.x);
3235 /* rect is at zero too */
3236 rect.left = LVIR_BOUNDS;
3237 rect.right = rect.top = rect.bottom = -1;
3238 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3239 expect(TRUE, r);
3240 expect(0, rect.left);
3241 /* just width sum */
3242 expect(150, rect.right);
3244 rect.left = LVIR_SELECTBOUNDS;
3245 rect.right = rect.top = rect.bottom = -1;
3246 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3247 expect(TRUE, r);
3248 /* column width + padding */
3249 expect(102, rect.left);
3251 /* back to initial order */
3252 order[0] = 0; order[1] = 1;
3253 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3254 expect(TRUE, r);
3256 /* state icons */
3257 himl = ImageList_Create(16, 16, 0, 2, 2);
3258 ok(himl != NULL, "failed to create imagelist\n");
3259 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3260 ok(hbm != NULL, "failed to create bitmap\n");
3261 r = ImageList_Add(himl, hbm, 0);
3262 ok(r == 0, "should be zero\n");
3263 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3264 ok(hbm != NULL, "failed to create bitmap\n");
3265 r = ImageList_Add(himl, hbm, 0);
3266 ok(r == 1, "should be one\n");
3268 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3269 ok(r == 0, "should return zero\n");
3271 item.mask = LVIF_STATE;
3272 item.state = INDEXTOSTATEIMAGEMASK(1);
3273 item.stateMask = LVIS_STATEIMAGEMASK;
3274 item.iItem = 0;
3275 item.iSubItem = 0;
3276 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3277 expect(TRUE, r);
3279 /* icon bounds */
3280 rect.left = LVIR_ICON;
3281 rect.right = rect.top = rect.bottom = -1;
3282 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3283 expect(TRUE, r);
3284 /* padding + stateicon width */
3285 expect(18, rect.left);
3286 expect(18, rect.right);
3287 /* label bounds */
3288 rect.left = LVIR_LABEL;
3289 rect.right = rect.top = rect.bottom = -1;
3290 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3291 expect(TRUE, r);
3292 /* padding + stateicon width -> column width */
3293 expect(18, rect.left);
3294 expect(50, rect.right);
3296 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3297 ok(r != 0, "should return current list handle\n");
3299 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3300 ok(r == 0, "should return zero\n");
3302 item.mask = LVIF_STATE | LVIF_IMAGE;
3303 item.iImage = 1;
3304 item.state = 0;
3305 item.stateMask = ~0;
3306 item.iItem = 0;
3307 item.iSubItem = 0;
3308 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3309 expect(TRUE, r);
3311 /* icon bounds */
3312 rect.left = LVIR_ICON;
3313 rect.right = rect.top = rect.bottom = -1;
3314 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3315 expect(TRUE, r);
3316 /* padding, icon width */
3317 expect(2, rect.left);
3318 expect(18, rect.right);
3319 /* label bounds */
3320 rect.left = LVIR_LABEL;
3321 rect.right = rect.top = rect.bottom = -1;
3322 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3323 expect(TRUE, r);
3324 /* padding + icon width -> column width */
3325 expect(18, rect.left);
3326 expect(50, rect.right);
3328 /* select bounds */
3329 rect.left = LVIR_SELECTBOUNDS;
3330 rect.right = rect.top = rect.bottom = -1;
3331 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3332 expect(TRUE, r);
3333 /* padding, column width */
3334 expect(2, rect.left);
3335 expect(50, rect.right);
3337 /* try with indentation */
3338 item.mask = LVIF_INDENT;
3339 item.iIndent = 1;
3340 item.iItem = 0;
3341 item.iSubItem = 0;
3342 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3343 expect(TRUE, r);
3345 /* bounds */
3346 rect.left = LVIR_BOUNDS;
3347 rect.right = rect.top = rect.bottom = -1;
3348 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3349 expect(TRUE, r);
3350 /* padding + 1 icon width, column width */
3351 expect(0, rect.left);
3352 expect(150, rect.right);
3354 /* select bounds */
3355 rect.left = LVIR_SELECTBOUNDS;
3356 rect.right = rect.top = rect.bottom = -1;
3357 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3358 expect(TRUE, r);
3359 /* padding + 1 icon width, column width */
3360 expect(2 + 16, rect.left);
3361 expect(50, rect.right);
3363 /* label bounds */
3364 rect.left = LVIR_LABEL;
3365 rect.right = rect.top = rect.bottom = -1;
3366 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3367 expect(TRUE, r);
3368 /* padding + 2 icon widths, column width */
3369 expect(2 + 16*2, rect.left);
3370 expect(50, rect.right);
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 + 1 icon width indentation, icon width */
3378 expect(2 + 16, rect.left);
3379 expect(34, rect.right);
3382 DestroyWindow(hwnd);
3385 static void test_editbox(void)
3387 HWND hwnd, hwndedit, hwndedit2;
3388 LVITEMA item;
3389 DWORD r;
3390 static CHAR testitemA[] = "testitem";
3391 static CHAR testitem1A[] = "testitem1";
3392 static CHAR buffer[10];
3394 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3395 ok(hwnd != NULL, "failed to create a listview window\n");
3397 insert_column(hwnd, 0);
3399 memset(&item, 0, sizeof(item));
3400 item.mask = LVIF_TEXT;
3401 item.pszText = testitemA;
3402 item.iItem = 0;
3403 item.iSubItem = 0;
3404 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3405 expect(0, r);
3407 /* setting focus is necessary */
3408 SetFocus(hwnd);
3409 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3410 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3412 /* modify initial string */
3413 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3414 expect(TRUE, r);
3415 /* return focus to listview */
3416 SetFocus(hwnd);
3418 memset(&item, 0, sizeof(item));
3419 item.mask = LVIF_TEXT;
3420 item.pszText = buffer;
3421 item.cchTextMax = 10;
3422 item.iItem = 0;
3423 item.iSubItem = 0;
3424 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3425 expect(TRUE, r);
3427 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3429 /* send LVM_EDITLABEL on already created edit */
3430 SetFocus(hwnd);
3431 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3432 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3433 /* focus will be set to edit */
3434 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3435 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3436 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3438 /* creating label disabled when control isn't focused */
3439 SetFocus(0);
3440 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3441 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3443 /* check EN_KILLFOCUS handling */
3444 memset(&item, 0, sizeof(item));
3445 item.pszText = testitemA;
3446 item.iItem = 0;
3447 item.iSubItem = 0;
3448 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3449 expect(TRUE, r);
3451 SetFocus(hwnd);
3452 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3453 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3454 /* modify edit and notify control that it lost focus */
3455 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3456 expect(TRUE, r);
3457 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3458 expect(0, r);
3459 memset(&item, 0, sizeof(item));
3460 item.pszText = buffer;
3461 item.cchTextMax = 10;
3462 item.iItem = 0;
3463 item.iSubItem = 0;
3464 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3465 expect(lstrlen(item.pszText), r);
3466 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3467 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
3468 /* end edit without saving */
3469 SetFocus(hwnd);
3470 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3471 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3472 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3473 expect(0, r);
3474 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3475 "edit box - end edit, no change, escape", TRUE);
3476 /* end edit with saving */
3477 SetFocus(hwnd);
3478 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3479 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3480 r = SendMessage(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
3481 expect(0, r);
3482 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3483 "edit box - end edit, no change, return", TRUE);
3485 memset(&item, 0, sizeof(item));
3486 item.pszText = buffer;
3487 item.cchTextMax = 10;
3488 item.iItem = 0;
3489 item.iSubItem = 0;
3490 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3491 expect(lstrlen(item.pszText), r);
3492 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3494 /* LVM_EDITLABEL with -1 destroys current edit */
3495 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3496 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3497 /* no edit present */
3498 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3499 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3500 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3501 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3502 /* edit present */
3503 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3504 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3505 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3506 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3507 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3508 /* check another negative value */
3509 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3510 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3511 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3512 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3513 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3514 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3515 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3516 /* and value greater than max item index */
3517 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3518 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3519 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3520 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3521 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3522 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3523 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3524 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3526 /* messaging tests */
3527 SetFocus(hwnd);
3528 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3529 blockEdit = FALSE;
3530 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3531 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3532 /* testing only sizing messages */
3533 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3534 "edit box create - sizing", FALSE);
3536 /* WM_COMMAND with EN_KILLFOCUS isn't forwared to parent */
3537 SetFocus(hwnd);
3538 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3539 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3540 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3541 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3542 expect(0, r);
3543 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3544 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
3546 DestroyWindow(hwnd);
3549 static void test_notifyformat(void)
3551 HWND hwnd, header;
3552 DWORD r;
3554 hwnd = create_listview_control(LVS_REPORT);
3555 ok(hwnd != NULL, "failed to create a listview window\n");
3557 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3558 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3559 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3560 expect(0, r);
3561 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3562 /* set */
3563 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3564 expect(0, r);
3565 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3566 if (r == 1)
3568 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3569 expect(1, r);
3570 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3571 expect(0, r);
3573 else
3575 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3576 DestroyWindow(hwnd);
3577 return;
3580 DestroyWindow(hwnd);
3582 /* test failure in parent WM_NOTIFYFORMAT */
3583 notifyFormat = 0;
3584 hwnd = create_listview_control(LVS_REPORT);
3585 ok(hwnd != NULL, "failed to create a listview window\n");
3586 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3587 ok(IsWindow(header), "expected header to be created\n");
3588 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3589 expect(0, r);
3590 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3591 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3592 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3593 ok(r != 0, "Expected valid format\n");
3595 notifyFormat = NFR_UNICODE;
3596 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3597 expect(NFR_UNICODE, r);
3598 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3599 expect(1, r);
3600 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3601 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3603 notifyFormat = NFR_ANSI;
3604 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3605 expect(NFR_ANSI, r);
3606 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3607 expect(0, r);
3608 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3609 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3611 DestroyWindow(hwnd);
3613 /* try different unicode window combination and defaults */
3614 if (!GetModuleHandleW(NULL))
3616 win_skip("Additional notify format tests are incompatible with Win9x\n");
3617 return;
3620 hwndparentW = create_parent_window(TRUE);
3621 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3622 if (!IsWindow(hwndparentW)) return;
3624 notifyFormat = -1;
3625 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3626 ok(hwnd != NULL, "failed to create a listview window\n");
3627 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3628 ok(IsWindow(header), "expected header to be created\n");
3629 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3630 expect(1, r);
3631 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3632 expect(1, r);
3633 DestroyWindow(hwnd);
3634 /* receiving error code defaulting to ansi */
3635 notifyFormat = 0;
3636 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3637 ok(hwnd != NULL, "failed to create a listview window\n");
3638 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3639 ok(IsWindow(header), "expected header to be created\n");
3640 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3641 expect(0, r);
3642 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3643 expect(1, r);
3644 DestroyWindow(hwnd);
3645 /* receiving ansi code from unicode window, use it */
3646 notifyFormat = NFR_ANSI;
3647 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3648 ok(hwnd != NULL, "failed to create a listview window\n");
3649 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3650 ok(IsWindow(header), "expected header to be created\n");
3651 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3652 expect(0, r);
3653 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3654 expect(1, r);
3655 DestroyWindow(hwnd);
3656 /* unicode listview with ansi parent window */
3657 notifyFormat = -1;
3658 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3659 ok(hwnd != NULL, "failed to create a listview window\n");
3660 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3661 ok(IsWindow(header), "expected header to be created\n");
3662 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3663 expect(0, r);
3664 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3665 expect(1, r);
3666 DestroyWindow(hwnd);
3667 /* unicode listview with ansi parent window, return error code */
3668 notifyFormat = 0;
3669 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3670 ok(hwnd != NULL, "failed to create a listview window\n");
3671 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3672 ok(IsWindow(header), "expected header to be created\n");
3673 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3674 expect(0, r);
3675 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3676 expect(1, r);
3677 DestroyWindow(hwnd);
3679 DestroyWindow(hwndparentW);
3682 static void test_indentation(void)
3684 HWND hwnd;
3685 LVITEMA item;
3686 DWORD r;
3688 hwnd = create_listview_control(LVS_REPORT);
3689 ok(hwnd != NULL, "failed to create a listview window\n");
3691 memset(&item, 0, sizeof(item));
3692 item.mask = LVIF_INDENT;
3693 item.iItem = 0;
3694 item.iIndent = I_INDENTCALLBACK;
3695 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3696 expect(0, r);
3698 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3700 item.iItem = 0;
3701 item.mask = LVIF_INDENT;
3702 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3703 expect(TRUE, r);
3705 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3706 "get indent dispinfo", FALSE);
3708 DestroyWindow(hwnd);
3711 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
3713 return 0;
3716 static BOOL is_below_comctl_5(void)
3718 HWND hwnd;
3719 BOOL ret;
3721 hwnd = create_listview_control(LVS_REPORT);
3722 ok(hwnd != NULL, "failed to create a listview window\n");
3723 insert_item(hwnd, 0);
3725 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
3727 DestroyWindow(hwnd);
3729 return !ret;
3732 static void test_get_set_view(void)
3734 HWND hwnd;
3735 DWORD ret;
3736 DWORD_PTR style;
3738 /* test style->view mapping */
3739 hwnd = create_listview_control(LVS_REPORT);
3740 ok(hwnd != NULL, "failed to create a listview window\n");
3742 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3743 expect(LV_VIEW_DETAILS, ret);
3745 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3746 /* LVS_ICON == 0 */
3747 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
3748 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3749 expect(LV_VIEW_ICON, ret);
3751 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3752 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
3753 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3754 expect(LV_VIEW_SMALLICON, ret);
3756 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3757 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
3758 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
3759 expect(LV_VIEW_LIST, ret);
3761 /* switching view doesn't touch window style */
3762 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
3763 expect(1, ret);
3764 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3765 ok(style & LVS_LIST, "Expected style to be preserved\n");
3766 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
3767 expect(1, ret);
3768 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3769 ok(style & LVS_LIST, "Expected style to be preserved\n");
3770 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
3771 expect(1, ret);
3772 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3773 ok(style & LVS_LIST, "Expected style to be preserved\n");
3775 DestroyWindow(hwnd);
3778 static void test_canceleditlabel(void)
3780 HWND hwnd, hwndedit;
3781 DWORD ret;
3782 CHAR buff[10];
3783 LVITEMA itema;
3784 static CHAR test[] = "test";
3785 static const CHAR test1[] = "test1";
3787 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3788 ok(hwnd != NULL, "failed to create a listview window\n");
3790 insert_item(hwnd, 0);
3792 /* try without edit created */
3793 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3794 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3795 expect(TRUE, ret);
3796 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3797 "cancel edit label without edit", FALSE);
3799 /* cancel without data change */
3800 SetFocus(hwnd);
3801 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3802 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3803 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3804 expect(TRUE, ret);
3805 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3807 /* cancel after data change */
3808 memset(&itema, 0, sizeof(itema));
3809 itema.pszText = test;
3810 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
3811 expect(TRUE, ret);
3812 SetFocus(hwnd);
3813 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3814 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
3815 ret = SetWindowText(hwndedit, test1);
3816 ok(ret != 0, "Expected edit text to change\n");
3817 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
3818 expect(TRUE, ret);
3819 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
3820 memset(&itema, 0, sizeof(itema));
3821 itema.pszText = buff;
3822 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
3823 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
3824 expect(5, ret);
3825 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
3827 DestroyWindow(hwnd);
3830 static void test_mapidindex(void)
3832 HWND hwnd;
3833 DWORD ret;
3835 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
3836 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3837 ok(hwnd != NULL, "failed to create a listview window\n");
3838 insert_item(hwnd, 0);
3839 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3840 expect(-1, ret);
3841 DestroyWindow(hwnd);
3843 hwnd = create_listview_control(LVS_REPORT);
3844 ok(hwnd != NULL, "failed to create a listview window\n");
3846 /* LVM_MAPINDEXTOID with invalid index */
3847 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3848 expect(-1, ret);
3850 insert_item(hwnd, 0);
3851 insert_item(hwnd, 1);
3853 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
3854 expect(-1, ret);
3855 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
3856 expect(-1, ret);
3858 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3859 expect(0, ret);
3860 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3861 expect(1, ret);
3862 /* remove 0 indexed item, id retained */
3863 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
3864 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
3865 expect(1, ret);
3866 /* new id starts from previous value */
3867 insert_item(hwnd, 1);
3868 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
3869 expect(2, ret);
3871 /* get index by id */
3872 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
3873 expect(-1, ret);
3874 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
3875 expect(-1, ret);
3876 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
3877 expect(0, ret);
3878 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
3879 expect(1, ret);
3881 DestroyWindow(hwnd);
3884 static void test_getitemspacing(void)
3886 HWND hwnd;
3887 DWORD ret;
3888 INT cx, cy;
3889 HIMAGELIST himl;
3890 HBITMAP hbmp;
3891 LVITEMA itema;
3893 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
3894 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
3896 /* LVS_ICON */
3897 hwnd = create_listview_control(LVS_ICON);
3898 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3899 todo_wine {
3900 expect(cx, LOWORD(ret));
3901 expect(cy, HIWORD(ret));
3903 /* now try with icons */
3904 himl = ImageList_Create(40, 40, 0, 4, 4);
3905 ok(himl != NULL, "failed to create imagelist\n");
3906 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
3907 ok(hbmp != NULL, "failed to create bitmap\n");
3908 ret = ImageList_Add(himl, hbmp, 0);
3909 expect(0, ret);
3910 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
3911 expect(0, ret);
3913 itema.mask = LVIF_IMAGE;
3914 itema.iImage = 0;
3915 itema.iItem = 0;
3916 itema.iSubItem = 0;
3917 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
3918 expect(0, ret);
3919 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3920 todo_wine {
3921 /* spacing + icon size returned */
3922 expect(cx + 40, LOWORD(ret));
3923 expect(cy + 40, HIWORD(ret));
3925 DestroyWindow(hwnd);
3926 /* LVS_SMALLICON */
3927 hwnd = create_listview_control(LVS_SMALLICON);
3928 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3929 todo_wine {
3930 expect(cx, LOWORD(ret));
3931 expect(cy, HIWORD(ret));
3933 DestroyWindow(hwnd);
3934 /* LVS_REPORT */
3935 hwnd = create_listview_control(LVS_REPORT);
3936 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3937 todo_wine {
3938 expect(cx, LOWORD(ret));
3939 expect(cy, HIWORD(ret));
3941 DestroyWindow(hwnd);
3942 /* LVS_LIST */
3943 hwnd = create_listview_control(LVS_LIST);
3944 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
3945 todo_wine {
3946 expect(cx, LOWORD(ret));
3947 expect(cy, HIWORD(ret));
3949 DestroyWindow(hwnd);
3952 static void test_getcolumnwidth(void)
3954 HWND hwnd;
3955 DWORD ret;
3956 DWORD_PTR style;
3957 LVCOLUMNA col;
3958 LVITEMA itema;
3960 /* default column width */
3961 hwnd = create_listview_control(LVS_ICON);
3962 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3963 expect(0, ret);
3964 style = GetWindowLong(hwnd, GWL_STYLE);
3965 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
3966 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3967 todo_wine expect(8, ret);
3968 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
3969 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
3970 col.mask = 0;
3971 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
3972 expect(0, ret);
3973 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3974 expect(10, ret);
3975 DestroyWindow(hwnd);
3977 /* default column width with item added */
3978 hwnd = create_listview_control(LVS_LIST);
3979 memset(&itema, 0, sizeof(itema));
3980 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
3981 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
3982 todo_wine expect(96, ret);
3983 DestroyWindow(hwnd);
3986 static void test_scrollnotify(void)
3988 HWND hwnd;
3989 DWORD ret;
3991 hwnd = create_listview_control(LVS_REPORT);
3993 insert_column(hwnd, 0);
3994 insert_column(hwnd, 1);
3995 insert_item(hwnd, 0);
3997 /* make it scrollable - resize */
3998 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3999 expect(TRUE, ret);
4000 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4001 expect(TRUE, ret);
4003 /* try with dummy call */
4004 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4005 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
4006 expect(TRUE, ret);
4007 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4008 "scroll notify 1", TRUE);
4010 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4011 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
4012 expect(TRUE, ret);
4013 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4014 "scroll notify 2", TRUE);
4016 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4017 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4018 expect(TRUE, ret);
4019 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4020 "scroll notify 3", TRUE);
4022 DestroyWindow(hwnd);
4025 static void test_LVS_EX_TRANSPARENTBKGND(void)
4027 HWND hwnd;
4028 DWORD ret;
4029 HDC hdc;
4031 hwnd = create_listview_control(LVS_REPORT);
4033 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4034 expect(TRUE, ret);
4036 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4037 LVS_EX_TRANSPARENTBKGND);
4039 ret = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
4040 if (ret != CLR_NONE)
4042 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4043 DestroyWindow(hwnd);
4044 return;
4047 /* try to set some back color and check this style bit */
4048 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4049 expect(TRUE, ret);
4050 ret = SendMessage(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4051 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4053 /* now test what this style actually does */
4054 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4055 LVS_EX_TRANSPARENTBKGND);
4057 hdc = GetWindowDC(hwndparent);
4059 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4060 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4061 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4062 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4064 ReleaseDC(hwndparent, hdc);
4066 DestroyWindow(hwnd);
4069 static void test_approximate_viewrect(void)
4071 HWND hwnd;
4072 DWORD ret;
4073 INT cx, cy;
4074 HIMAGELIST himl;
4075 HBITMAP hbmp;
4076 LVITEMA itema;
4077 static CHAR test[] = "abracadabra, a very long item label";
4079 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4080 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4082 hwnd = create_listview_control(LVS_ICON);
4083 himl = ImageList_Create(40, 40, 0, 4, 4);
4084 ok(himl != NULL, "failed to create imagelist\n");
4085 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4086 ok(hbmp != NULL, "failed to create bitmap\n");
4087 ret = ImageList_Add(himl, hbmp, 0);
4088 expect(0, ret);
4089 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4090 expect(0, ret);
4092 itema.mask = LVIF_IMAGE;
4093 itema.iImage = 0;
4094 itema.iItem = 0;
4095 itema.iSubItem = 0;
4096 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4097 expect(0, ret);
4099 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4100 if (ret == 0)
4102 /* version 4.0 */
4103 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4104 return;
4107 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4108 ok(MAKELONG(77,827)==ret,"Incorrect Approximate rect\n");
4110 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4111 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4112 ok(MAKELONG(102,302)==ret,"Incorrect Approximate rect\n");
4114 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4115 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4117 itema.pszText = test;
4118 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4119 expect(TRUE, ret);
4120 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4121 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4123 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4124 ok(MAKELONG(52,2)==ret,"Incorrect Approximate rect\n");
4125 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4126 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4127 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4128 ok(MAKELONG(102,52)==ret,"Incorrect Approximate rect\n");
4129 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4130 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4131 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4132 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4133 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4134 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4135 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4136 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4137 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4138 ok(MAKELONG(152,152)==ret,"Incorrect Approximate rect\n");
4140 DestroyWindow(hwnd);
4143 static void test_finditem(void)
4145 LVFINDINFOA fi;
4146 static char f[5];
4147 HWND hwnd;
4148 DWORD r;
4150 hwnd = create_listview_control(LVS_REPORT);
4151 insert_item(hwnd, 0);
4153 memset(&fi, 0, sizeof(fi));
4155 /* full string search, inserted text was "foo" */
4156 strcpy(f, "foo");
4157 fi.flags = LVFI_STRING;
4158 fi.psz = f;
4159 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4160 expect(0, r);
4161 /* partial string search, inserted text was "foo" */
4162 strcpy(f, "fo");
4163 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4164 fi.psz = f;
4165 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4166 expect(0, r);
4167 /* partial string search, part after start char */
4168 strcpy(f, "oo");
4169 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4170 fi.psz = f;
4171 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4172 expect(-1, r);
4174 /* try with LVFI_SUBSTRING */
4175 strcpy(f, "fo");
4176 fi.flags = LVFI_SUBSTRING;
4177 fi.psz = f;
4178 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4179 if (r == -1)
4181 win_skip("LVFI_SUBSTRING not supported\n");
4182 DestroyWindow(hwnd);
4183 return;
4185 expect(0, r);
4186 strcpy(f, "f");
4187 fi.flags = LVFI_SUBSTRING;
4188 fi.psz = f;
4189 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4190 expect(0, r);
4191 strcpy(f, "o");
4192 fi.flags = LVFI_SUBSTRING;
4193 fi.psz = f;
4194 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4195 expect(-1, r);
4197 strcpy(f, "f");
4198 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
4199 fi.psz = f;
4200 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4201 expect(0, r);
4203 DestroyWindow(hwnd);
4206 static void test_LVS_EX_HEADERINALLVIEWS(void)
4208 HWND hwnd, header;
4209 DWORD style;
4211 hwnd = create_listview_control(LVS_ICON);
4213 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4214 LVS_EX_HEADERINALLVIEWS);
4216 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4217 if (!IsWindow(header))
4219 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4220 DestroyWindow(hwnd);
4221 return;
4224 /* LVS_NOCOLUMNHEADER works as before */
4225 style = GetWindowLongA(hwnd, GWL_STYLE);
4226 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
4227 style = GetWindowLongA(header, GWL_STYLE);
4228 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
4229 style = GetWindowLongA(hwnd, GWL_STYLE);
4230 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
4231 style = GetWindowLongA(header, GWL_STYLE);
4232 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
4234 /* try to remove style */
4235 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
4236 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4237 ok(IsWindow(header), "Expected header to be created\n");
4238 style = GetWindowLongA(header, GWL_STYLE);
4239 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
4241 DestroyWindow(hwnd);
4243 /* check other styles */
4244 hwnd = create_listview_control(LVS_LIST);
4245 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4246 LVS_EX_HEADERINALLVIEWS);
4247 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4248 ok(IsWindow(header), "Expected header to be created\n");
4249 DestroyWindow(hwnd);
4251 hwnd = create_listview_control(LVS_SMALLICON);
4252 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4253 LVS_EX_HEADERINALLVIEWS);
4254 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4255 ok(IsWindow(header), "Expected header to be created\n");
4256 DestroyWindow(hwnd);
4258 hwnd = create_listview_control(LVS_REPORT);
4259 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4260 LVS_EX_HEADERINALLVIEWS);
4261 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4262 ok(IsWindow(header), "Expected header to be created\n");
4263 DestroyWindow(hwnd);
4266 static void test_hover(void)
4268 HWND hwnd;
4269 DWORD r;
4271 hwnd = create_listview_control(LVS_ICON);
4273 /* test WM_MOUSEHOVER forwarding */
4274 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4275 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4276 expect(0, r);
4277 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
4278 g_block_hover = TRUE;
4279 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4280 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4281 expect(0, r);
4282 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
4283 g_block_hover = FALSE;
4285 r = SendMessage(hwnd, LVM_SETHOVERTIME, 0, 500);
4286 expect(HOVER_DEFAULT, r);
4287 r = SendMessage(hwnd, LVM_GETHOVERTIME, 0, 0);
4288 expect(500, r);
4290 DestroyWindow(hwnd);
4293 static void test_destroynotify(void)
4295 HWND hwnd;
4297 hwnd = create_listview_control(LVS_REPORT);
4298 ok(hwnd != NULL, "failed to create listview window\n");
4300 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4301 DestroyWindow(hwnd);
4302 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
4305 static void test_header_notification(void)
4307 HWND list, header;
4308 HDITEMA item;
4309 NMHEADER nmh;
4310 LVCOLUMNA col;
4311 LRESULT ret;
4313 list = create_listview_control(LVS_REPORT);
4314 ok(list != 0, "failed to create listview window\n");
4316 memset(&col, 0, sizeof(col));
4317 col.mask = LVCF_WIDTH;
4318 col.cx = 100;
4319 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4320 ok(!ret, "expected 0, got %ld\n", ret);
4322 header = subclass_header(list);
4324 ret = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
4325 ok(ret == 1, "expected header item count 1, got %ld\n", ret);
4327 memset(&item, 0, sizeof(item));
4328 item.mask = HDI_WIDTH;
4329 ret = SendMessage(header, HDM_GETITEMA, 0, (LPARAM)&item);
4330 ok(ret, "HDM_GETITEM failed\n");
4331 ok(item.cxy == 100, "expected 100, got %d\n", item.cxy);
4333 nmh.hdr.hwndFrom = header;
4334 nmh.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
4335 nmh.hdr.code = HDN_ITEMCHANGEDA;
4336 nmh.iItem = 0;
4337 nmh.iButton = 0;
4338 item.mask = HDI_WIDTH;
4339 item.cxy = 50;
4340 nmh.pitem = &item;
4341 ret = SendMessage(list, WM_NOTIFY, 0, (LPARAM)&nmh);
4342 ok(!ret, "WM_NOTIFY/HDN_ITEMCHANGED failed\n");
4344 DestroyWindow(list);
4347 START_TEST(listview)
4349 HMODULE hComctl32;
4350 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
4352 ULONG_PTR ctx_cookie;
4353 HANDLE hCtx;
4354 HWND hwnd;
4356 hComctl32 = GetModuleHandleA("comctl32.dll");
4357 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
4358 if (pInitCommonControlsEx)
4360 INITCOMMONCONTROLSEX iccex;
4361 iccex.dwSize = sizeof(iccex);
4362 iccex.dwICC = ICC_LISTVIEW_CLASSES;
4363 pInitCommonControlsEx(&iccex);
4365 else
4366 InitCommonControls();
4368 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
4370 hwndparent = create_parent_window(FALSE);
4371 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4373 g_is_below_5 = is_below_comctl_5();
4375 test_header_notification();
4376 test_images();
4377 test_checkboxes();
4378 test_items();
4379 test_create();
4380 test_redraw();
4381 test_customdraw();
4382 test_icon_spacing();
4383 test_color();
4384 test_item_count();
4385 test_item_position();
4386 test_columns();
4387 test_getorigin();
4388 test_multiselect();
4389 test_getitemrect();
4390 test_subitem_rect();
4391 test_sorting();
4392 test_ownerdata();
4393 test_norecompute();
4394 test_nosortheader();
4395 test_setredraw();
4396 test_hittest();
4397 test_getviewrect();
4398 test_getitemposition();
4399 test_columnscreation();
4400 test_editbox();
4401 test_notifyformat();
4402 test_indentation();
4403 test_getitemspacing();
4404 test_getcolumnwidth();
4405 test_approximate_viewrect();
4406 test_finditem();
4407 test_hover();
4408 test_destroynotify();
4410 if (!load_v6_module(&ctx_cookie, &hCtx))
4412 DestroyWindow(hwndparent);
4413 return;
4416 /* this is a XP SP3 failure workaround */
4417 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
4418 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
4419 0, 0, 100, 100,
4420 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
4421 if (!IsWindow(hwnd))
4423 win_skip("FIXME: failed to create ListView window.\n");
4424 unload_v6_module(ctx_cookie, hCtx);
4425 DestroyWindow(hwndparent);
4426 return;
4428 else
4429 DestroyWindow(hwnd);
4431 /* comctl32 version 6 tests start here */
4432 test_get_set_view();
4433 test_canceleditlabel();
4434 test_mapidindex();
4435 test_scrollnotify();
4436 test_LVS_EX_TRANSPARENTBKGND();
4437 test_LVS_EX_HEADERINALLVIEWS();
4439 unload_v6_module(ctx_cookie, hCtx);
4441 DestroyWindow(hwndparent);