comctl32/tests: Don't delete the global font object.
[wine.git] / dlls / comctl32 / tests / listview.c
blob255ef50d140597a2db565ecb8ebdc4374cf09df6
1 /*
2 * ListView tests
4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009-2012 Nikolay Sivov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdio.h>
24 #include <windows.h>
25 #include <commctrl.h>
27 #include "wine/test.h"
28 #include "v6util.h"
29 #include "msg.h"
31 #define PARENT_SEQ_INDEX 0
32 #define PARENT_FULL_SEQ_INDEX 1
33 #define LISTVIEW_SEQ_INDEX 2
34 #define EDITBOX_SEQ_INDEX 3
35 #define COMBINED_SEQ_INDEX 4
36 #define NUM_MSG_SEQUENCES 5
38 #define LISTVIEW_ID 0
39 #define HEADER_ID 1
41 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
42 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
43 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
45 static const WCHAR testparentclassW[] =
46 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
48 static HWND hwndparent, hwndparentW;
49 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
50 static BOOL blockEdit;
51 /* return nonzero on NM_HOVER */
52 static BOOL g_block_hover;
53 /* notification data for LVN_ITEMCHANGED */
54 static NMLISTVIEW g_nmlistview;
55 /* format reported to control:
56 -1 falls to defproc, anything else returned */
57 static INT notifyFormat;
58 /* indicates we're running < 5.80 version */
59 static BOOL g_is_below_5;
60 /* item data passed to LVN_GETDISPINFOA */
61 static LVITEMA g_itema;
62 /* alter notification code A->W */
63 static BOOL g_disp_A_to_W;
64 /* dispinfo data sent with LVN_LVN_ENDLABELEDIT */
65 static NMLVDISPINFO g_editbox_disp_info;
67 static HWND subclass_editbox(HWND hwndListview);
69 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
71 static const struct message create_ownerdrawfixed_parent_seq[] = {
72 { WM_NOTIFYFORMAT, sent },
73 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
74 { WM_MEASUREITEM, sent },
75 { WM_PARENTNOTIFY, sent },
76 { 0 }
79 static const struct message redraw_listview_seq[] = {
80 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
81 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
82 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
83 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
84 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
85 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
86 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
87 { 0 }
90 static const struct message listview_icon_spacing_seq[] = {
91 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
92 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
93 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
94 { 0 }
97 static const struct message listview_color_seq[] = {
98 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
99 { LVM_GETBKCOLOR, sent },
100 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
101 { LVM_GETTEXTCOLOR, sent },
102 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
103 { LVM_GETTEXTBKCOLOR, sent },
105 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
106 { LVM_GETBKCOLOR, sent },
107 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
108 { LVM_GETTEXTCOLOR, sent },
109 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
110 { LVM_GETTEXTBKCOLOR, sent },
112 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
113 { LVM_GETBKCOLOR, sent },
114 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
115 { LVM_GETTEXTCOLOR, sent },
116 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
117 { LVM_GETTEXTBKCOLOR, sent },
119 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
120 { LVM_GETBKCOLOR, sent },
121 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
122 { LVM_GETTEXTCOLOR, sent },
123 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
124 { LVM_GETTEXTBKCOLOR, sent },
125 { 0 }
128 static const struct message listview_item_count_seq[] = {
129 { LVM_GETITEMCOUNT, sent },
130 { LVM_INSERTITEM, sent },
131 { LVM_INSERTITEM, sent },
132 { LVM_INSERTITEM, sent },
133 { LVM_GETITEMCOUNT, sent },
134 { LVM_DELETEITEM, sent|wparam, 2 },
135 { WM_NCPAINT, sent|optional },
136 { WM_ERASEBKGND, sent|optional },
137 { LVM_GETITEMCOUNT, sent },
138 { LVM_DELETEALLITEMS, sent },
139 { LVM_GETITEMCOUNT, sent },
140 { LVM_INSERTITEM, sent },
141 { LVM_INSERTITEM, sent },
142 { LVM_GETITEMCOUNT, sent },
143 { LVM_INSERTITEM, sent },
144 { LVM_GETITEMCOUNT, sent },
145 { 0 }
148 static const struct message listview_itempos_seq[] = {
149 { LVM_INSERTITEM, sent },
150 { LVM_INSERTITEM, sent },
151 { LVM_INSERTITEM, sent },
152 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
153 { WM_NCPAINT, sent|optional },
154 { WM_ERASEBKGND, sent|optional },
155 { LVM_GETITEMPOSITION, sent|wparam, 1 },
156 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
157 { LVM_GETITEMPOSITION, sent|wparam, 2 },
158 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
159 { LVM_GETITEMPOSITION, sent|wparam, 0 },
160 { 0 }
163 static const struct message listview_ownerdata_switchto_seq[] = {
164 { WM_STYLECHANGING, sent },
165 { WM_STYLECHANGED, sent },
166 { 0 }
169 static const struct message listview_getorderarray_seq[] = {
170 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
171 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
172 { 0 }
175 static const struct message empty_seq[] = {
176 { 0 }
179 static const struct message forward_erasebkgnd_parent_seq[] = {
180 { WM_ERASEBKGND, sent },
181 { 0 }
184 static const struct message ownderdata_select_focus_parent_seq[] = {
185 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
186 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
187 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
188 { 0 }
191 static const struct message ownerdata_setstate_all_parent_seq[] = {
192 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
193 { 0 }
196 static const struct message ownerdata_defocus_all_parent_seq[] = {
197 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
198 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
199 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
200 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
201 { 0 }
204 static const struct message ownerdata_deselect_all_parent_seq[] = {
205 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
206 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
207 { 0 }
210 static const struct message select_all_parent_seq[] = {
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 },
220 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
221 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
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 textcallback_set_again_parent_seq[] = {
229 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
230 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
231 { 0 }
234 static const struct message single_getdispinfo_parent_seq[] = {
235 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
236 { 0 }
239 static const struct message getitemposition_seq1[] = {
240 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
241 { 0 }
244 static const struct message getitemposition_seq2[] = {
245 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
246 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
247 { 0 }
250 static const struct message editbox_create_pos[] = {
251 /* sequence sent after LVN_BEGINLABELEDIT */
252 /* next two are 4.7x specific */
253 { WM_WINDOWPOSCHANGING, sent },
254 { WM_WINDOWPOSCHANGED, sent|optional },
256 { WM_WINDOWPOSCHANGING, sent|optional },
257 { WM_NCCALCSIZE, sent },
258 { WM_WINDOWPOSCHANGED, sent },
259 { WM_MOVE, sent|defwinproc },
260 { WM_SIZE, sent|defwinproc },
261 /* the rest is todo, skipped in 4.7x */
262 { WM_WINDOWPOSCHANGING, sent|optional },
263 { WM_WINDOWPOSCHANGED, sent|optional },
264 { 0 }
267 static const struct message scroll_parent_seq[] = {
268 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
269 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
270 { 0 }
273 static const struct message setredraw_seq[] = {
274 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
275 { 0 }
278 static const struct message lvs_ex_transparentbkgnd_seq[] = {
279 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
280 { 0 }
283 static const struct message edit_end_nochange[] = {
284 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
285 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW }, /* todo */
286 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
287 { 0 }
290 static const struct message hover_parent[] = {
291 { WM_GETDLGCODE, sent }, /* todo_wine */
292 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
293 { 0 }
296 static const struct message listview_destroy[] = {
297 { 0x0090, sent|optional }, /* Vista */
298 { WM_PARENTNOTIFY, sent },
299 { WM_SHOWWINDOW, sent },
300 { WM_WINDOWPOSCHANGING, sent },
301 { WM_WINDOWPOSCHANGED, sent|optional },
302 { WM_DESTROY, sent },
303 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
304 { WM_NCDESTROY, sent },
305 { 0 }
308 static const struct message listview_header_changed_seq[] = {
309 { LVM_SETCOLUMNA, sent },
310 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
311 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
312 { 0 }
315 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
317 static LONG defwndproc_counter = 0;
318 LRESULT ret;
319 struct message msg;
321 msg.message = message;
322 msg.flags = sent|wparam|lparam;
323 if (defwndproc_counter) msg.flags |= defwinproc;
324 msg.wParam = wParam;
325 msg.lParam = lParam;
326 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
328 /* log system messages, except for painting */
329 if (message < WM_USER &&
330 message != WM_PAINT &&
331 message != WM_ERASEBKGND &&
332 message != WM_NCPAINT &&
333 message != WM_NCHITTEST &&
334 message != WM_GETTEXT &&
335 message != WM_GETICON &&
336 message != WM_DEVICECHANGE)
338 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
340 add_message(sequences, PARENT_SEQ_INDEX, &msg);
341 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
343 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
345 switch (message)
347 case WM_NOTIFY:
349 switch (((NMHDR*)lParam)->code)
351 case LVN_BEGINLABELEDIT:
353 HWND edit = NULL;
355 /* subclass edit box */
356 if (!blockEdit)
357 edit = subclass_editbox(((NMHDR*)lParam)->hwndFrom);
359 if (edit)
361 INT len = SendMessageA(edit, EM_GETLIMITTEXT, 0, 0);
362 ok(len == 259 || broken(len == 260) /* includes NULL in NT4 */,
363 "text limit %d, expected 259\n", len);
366 return blockEdit;
368 case LVN_ENDLABELEDIT:
370 HWND edit;
372 /* always accept new item text */
373 NMLVDISPINFO *di = (NMLVDISPINFO*)lParam;
374 g_editbox_disp_info = *di;
375 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText ? di->item.pszText : "(null)");
377 /* edit control still available from this notification */
378 edit = (HWND)SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETEDITCONTROL, 0, 0);
379 ok(IsWindow(edit), "expected valid edit control handle\n");
380 ok((GetWindowLongA(edit, GWL_STYLE) & ES_MULTILINE) == 0, "edit is multiline\n");
382 return TRUE;
384 case LVN_BEGINSCROLL:
385 case LVN_ENDSCROLL:
387 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
389 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
390 "BEGIN" : "END", pScroll->dx, pScroll->dy);
392 break;
393 case LVN_ITEMCHANGED:
395 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
396 g_nmlistview = *nmlv;
398 break;
399 case LVN_GETDISPINFOA:
401 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
402 g_itema = dispinfo->item;
404 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
406 static const WCHAR testW[] = {'T','E','S','T',0};
407 dispinfo->hdr.code = LVN_GETDISPINFOW;
408 memcpy(dispinfo->item.pszText, testW, sizeof(testW));
411 /* test control buffer size for text, 10 used to mask cases when control
412 is using caller buffer to process LVM_GETITEM for example */
413 if (dispinfo->item.mask & LVIF_TEXT && dispinfo->item.cchTextMax > 10)
414 ok(dispinfo->item.cchTextMax == 260 ||
415 broken(dispinfo->item.cchTextMax == 264) /* NT4 reports aligned size */,
416 "buffer size %d\n", dispinfo->item.cchTextMax);
418 break;
419 case NM_HOVER:
420 if (g_block_hover) return 1;
421 break;
423 break;
425 case WM_NOTIFYFORMAT:
427 /* force to return format */
428 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
429 break;
433 defwndproc_counter++;
434 ret = DefWindowProcA(hwnd, message, wParam, lParam);
435 defwndproc_counter--;
437 return ret;
440 static BOOL register_parent_wnd_class(BOOL Unicode)
442 WNDCLASSA clsA;
443 WNDCLASSW clsW;
445 if (Unicode)
447 clsW.style = 0;
448 clsW.lpfnWndProc = parent_wnd_proc;
449 clsW.cbClsExtra = 0;
450 clsW.cbWndExtra = 0;
451 clsW.hInstance = GetModuleHandleW(NULL);
452 clsW.hIcon = 0;
453 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
454 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
455 clsW.lpszMenuName = NULL;
456 clsW.lpszClassName = testparentclassW;
458 else
460 clsA.style = 0;
461 clsA.lpfnWndProc = parent_wnd_proc;
462 clsA.cbClsExtra = 0;
463 clsA.cbWndExtra = 0;
464 clsA.hInstance = GetModuleHandleA(NULL);
465 clsA.hIcon = 0;
466 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
467 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
468 clsA.lpszMenuName = NULL;
469 clsA.lpszClassName = "Listview test parent class";
472 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
475 static HWND create_parent_window(BOOL Unicode)
477 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
478 HWND hwnd;
480 if (!register_parent_wnd_class(Unicode))
481 return NULL;
483 blockEdit = FALSE;
484 notifyFormat = -1;
486 if (Unicode)
487 hwnd = CreateWindowExW(0, testparentclassW, nameW,
488 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
489 WS_MAXIMIZEBOX | WS_VISIBLE,
490 0, 0, 100, 100,
491 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
492 else
493 hwnd = CreateWindowExA(0, "Listview test parent class",
494 "Listview test parent window",
495 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
496 WS_MAXIMIZEBOX | WS_VISIBLE,
497 0, 0, 100, 100,
498 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
499 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
500 return hwnd;
503 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
505 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
506 static LONG defwndproc_counter = 0;
507 LRESULT ret;
508 struct message msg;
510 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
512 /* some debug output for style changing */
513 if ((message == WM_STYLECHANGING ||
514 message == WM_STYLECHANGED) && lParam)
516 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
517 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
520 msg.message = message;
521 msg.flags = sent|wparam|lparam;
522 if (defwndproc_counter) msg.flags |= defwinproc;
523 msg.wParam = wParam;
524 msg.lParam = lParam;
525 msg.id = LISTVIEW_ID;
526 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
527 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
529 defwndproc_counter++;
530 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
531 defwndproc_counter--;
532 return ret;
535 static HWND create_listview_control(DWORD style)
537 WNDPROC oldproc;
538 HWND hwnd;
539 RECT rect;
541 GetClientRect(hwndparent, &rect);
542 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
543 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
544 0, 0, rect.right, rect.bottom,
545 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
546 ok(hwnd != NULL, "gle=%d\n", GetLastError());
548 if (!hwnd) return NULL;
550 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
551 (LONG_PTR)listview_subclass_proc);
552 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
554 return hwnd;
557 /* unicode listview window with specified parent */
558 static HWND create_listview_controlW(DWORD style, HWND parent)
560 WNDPROC oldproc;
561 HWND hwnd;
562 RECT rect;
563 static const WCHAR nameW[] = {'f','o','o',0};
565 GetClientRect(parent, &rect);
566 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
567 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
568 0, 0, rect.right, rect.bottom,
569 parent, NULL, GetModuleHandleW(NULL), NULL);
570 ok(hwnd != NULL, "gle=%d\n", GetLastError());
572 if (!hwnd) return NULL;
574 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
575 (LONG_PTR)listview_subclass_proc);
576 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
578 return hwnd;
581 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
583 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
584 static LONG defwndproc_counter = 0;
585 LRESULT ret;
586 struct message msg;
588 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
590 msg.message = message;
591 msg.flags = sent|wparam|lparam;
592 if (defwndproc_counter) msg.flags |= defwinproc;
593 msg.wParam = wParam;
594 msg.lParam = lParam;
595 msg.id = HEADER_ID;
596 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
598 defwndproc_counter++;
599 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
600 defwndproc_counter--;
601 return ret;
604 static HWND subclass_header(HWND hwndListview)
606 WNDPROC oldproc;
607 HWND hwnd;
609 hwnd = ListView_GetHeader(hwndListview);
610 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
611 (LONG_PTR)header_subclass_proc);
612 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
614 return hwnd;
617 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
619 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
620 static LONG defwndproc_counter = 0;
621 LRESULT ret;
622 struct message msg;
624 msg.message = message;
625 msg.flags = sent|wparam|lparam;
626 if (defwndproc_counter) msg.flags |= defwinproc;
627 msg.wParam = wParam;
628 msg.lParam = lParam;
630 /* all we need is sizing */
631 if (message == WM_WINDOWPOSCHANGING ||
632 message == WM_NCCALCSIZE ||
633 message == WM_WINDOWPOSCHANGED ||
634 message == WM_MOVE ||
635 message == WM_SIZE)
637 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
640 defwndproc_counter++;
641 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
642 defwndproc_counter--;
643 return ret;
646 static HWND subclass_editbox(HWND hwndListview)
648 WNDPROC oldproc;
649 HWND hwnd;
651 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
652 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
653 (LONG_PTR)editbox_subclass_proc);
654 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
656 return hwnd;
659 /* Performs a single LVM_HITTEST test */
660 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
661 BOOL todo_item, BOOL todo_flags, int line)
663 LVHITTESTINFO lpht;
664 INT ret;
666 lpht.pt.x = x;
667 lpht.pt.y = y;
668 lpht.iSubItem = 10;
670 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
672 if (todo_item)
674 todo_wine
676 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
677 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
678 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
681 else
683 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
684 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
685 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
688 if (todo_flags)
690 todo_wine
691 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
693 else if (broken_flags)
694 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
695 "Expected flags %x, got %x\n", flags, lpht.flags);
696 else
697 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
700 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
702 /* Performs a single LVM_SUBITEMHITTEST test */
703 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
704 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
706 LVHITTESTINFO lpht;
707 INT ret;
709 lpht.pt.x = x;
710 lpht.pt.y = y;
712 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
714 if (todo_item)
716 todo_wine
718 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
719 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
722 else
724 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
725 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
728 if (todo_subitem)
730 todo_wine
731 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
733 else
734 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
736 if (todo_flags)
738 todo_wine
739 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
741 else
742 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
745 #define test_lvm_subitemhittest(a,b,c,d,e,f,g,h,i) test_lvm_subitemhittest_(a,b,c,d,e,f,g,h,i,__LINE__)
747 static void test_images(void)
749 HWND hwnd;
750 INT r;
751 LVITEM item;
752 HIMAGELIST himl;
753 HBITMAP hbmp;
754 RECT r1, r2;
755 static CHAR hello[] = "hello";
757 himl = ImageList_Create(40, 40, 0, 4, 4);
758 ok(himl != NULL, "failed to create imagelist\n");
760 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
761 ok(hbmp != NULL, "failed to create bitmap\n");
763 r = ImageList_Add(himl, hbmp, 0);
764 ok(r == 0, "should be zero\n");
766 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
767 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
768 ok(hwnd != NULL, "failed to create listview window\n");
770 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
771 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
773 ok(r == 0, "should return zero\n");
775 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
776 ok(r == 0, "should return zero\n");
778 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
779 ok(r != 0, "got 0\n");
781 /* returns dimensions */
783 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
784 ok(r == 0, "should be zero items\n");
786 item.mask = LVIF_IMAGE | LVIF_TEXT;
787 item.iItem = 0;
788 item.iSubItem = 1;
789 item.iImage = 0;
790 item.pszText = 0;
791 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
792 ok(r == -1, "should fail\n");
794 item.iSubItem = 0;
795 item.pszText = hello;
796 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
797 ok(r == 0, "should not fail\n");
799 memset(&r1, 0, sizeof r1);
800 r1.left = LVIR_ICON;
801 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
802 expect(1, r);
804 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
805 ok(r == TRUE, "should not fail\n");
807 item.iSubItem = 0;
808 item.pszText = hello;
809 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
810 ok(r == 0, "should not fail\n");
812 memset(&r2, 0, sizeof r2);
813 r2.left = LVIR_ICON;
814 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
815 expect(1, r);
817 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
819 DestroyWindow(hwnd);
822 static void test_checkboxes(void)
824 HWND hwnd;
825 LVITEMA item;
826 DWORD r;
827 static CHAR text[] = "Text",
828 text2[] = "Text2",
829 text3[] = "Text3";
831 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
832 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
833 ok(hwnd != NULL, "failed to create listview window\n");
835 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
836 item.mask = LVIF_TEXT | LVIF_STATE;
837 item.stateMask = 0xffff;
838 item.state = 0xfccc;
839 item.iItem = 0;
840 item.iSubItem = 0;
841 item.pszText = text;
842 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
843 expect(0, r);
845 item.iItem = 0;
846 item.mask = LVIF_STATE;
847 item.stateMask = 0xffff;
848 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
849 expect(1, r);
850 ok(item.state == 0xfccc, "state %x\n", item.state);
852 /* Don't set LVIF_STATE */
853 item.mask = LVIF_TEXT;
854 item.stateMask = 0xffff;
855 item.state = 0xfccc;
856 item.iItem = 1;
857 item.iSubItem = 0;
858 item.pszText = text;
859 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
860 expect(1, r);
862 item.iItem = 1;
863 item.mask = LVIF_STATE;
864 item.stateMask = 0xffff;
865 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
866 expect(1, r);
867 ok(item.state == 0, "state %x\n", item.state);
869 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
870 expect(0, r);
872 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
873 item.iItem = 0;
874 item.mask = LVIF_STATE;
875 item.stateMask = 0xffff;
876 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
877 expect(1, r);
878 if (item.state != 0x1ccc)
880 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
881 DestroyWindow(hwnd);
882 return;
885 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
886 item.iItem = 2;
887 item.mask = LVIF_TEXT;
888 item.state = 0;
889 item.pszText = text2;
890 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
891 expect(2, r);
893 item.iItem = 2;
894 item.mask = LVIF_STATE;
895 item.stateMask = 0xffff;
896 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
897 expect(1, r);
898 ok(item.state == 0x1000, "state %x\n", item.state);
900 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
901 item.iItem = 3;
902 item.mask = LVIF_TEXT | LVIF_STATE;
903 item.stateMask = 0xffff;
904 item.state = 0x2aaa;
905 item.pszText = text3;
906 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
907 expect(3, r);
909 item.iItem = 3;
910 item.mask = LVIF_STATE;
911 item.stateMask = 0xffff;
912 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
913 expect(1, r);
914 ok(item.state == 0x1aaa, "state %x\n", item.state);
916 /* Set an item's state to checked */
917 item.iItem = 3;
918 item.mask = LVIF_STATE;
919 item.stateMask = 0xf000;
920 item.state = 0x2000;
921 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
922 expect(1, r);
924 item.iItem = 3;
925 item.mask = LVIF_STATE;
926 item.stateMask = 0xffff;
927 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
928 expect(1, r);
929 ok(item.state == 0x2aaa, "state %x\n", item.state);
931 /* Check that only the bits we asked for are returned,
932 * and that all the others are set to zero
934 item.iItem = 3;
935 item.mask = LVIF_STATE;
936 item.stateMask = 0xf000;
937 item.state = 0xffff;
938 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
939 expect(1, r);
940 ok(item.state == 0x2000, "state %x\n", item.state);
942 /* Set the style again and check that doesn't change an item's state */
943 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
944 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
946 item.iItem = 3;
947 item.mask = LVIF_STATE;
948 item.stateMask = 0xffff;
949 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
950 expect(1, r);
951 ok(item.state == 0x2aaa, "state %x\n", item.state);
953 /* Unsetting the checkbox extended style doesn't change an item's state */
954 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
955 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
957 item.iItem = 3;
958 item.mask = LVIF_STATE;
959 item.stateMask = 0xffff;
960 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
961 expect(1, r);
962 ok(item.state == 0x2aaa, "state %x\n", item.state);
964 /* Now setting the style again will change an item's state */
965 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
966 expect(0, r);
968 item.iItem = 3;
969 item.mask = LVIF_STATE;
970 item.stateMask = 0xffff;
971 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
972 expect(1, r);
973 ok(item.state == 0x1aaa, "state %x\n", item.state);
975 /* Toggle checkbox tests (bug 9934) */
976 memset (&item, 0xcc, sizeof(item));
977 item.mask = LVIF_STATE;
978 item.iItem = 3;
979 item.iSubItem = 0;
980 item.state = LVIS_FOCUSED;
981 item.stateMask = LVIS_FOCUSED;
982 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
983 expect(1, r);
985 item.iItem = 3;
986 item.mask = LVIF_STATE;
987 item.stateMask = 0xffff;
988 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
989 expect(1, r);
990 ok(item.state == 0x1aab, "state %x\n", item.state);
992 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
993 expect(0, r);
994 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
995 expect(0, r);
997 item.iItem = 3;
998 item.mask = LVIF_STATE;
999 item.stateMask = 0xffff;
1000 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1001 expect(1, r);
1002 ok(item.state == 0x2aab, "state %x\n", item.state);
1004 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1005 expect(0, r);
1006 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
1007 expect(0, r);
1009 item.iItem = 3;
1010 item.mask = LVIF_STATE;
1011 item.stateMask = 0xffff;
1012 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1013 expect(1, r);
1014 ok(item.state == 0x1aab, "state %x\n", item.state);
1016 DestroyWindow(hwnd);
1019 static void insert_column(HWND hwnd, int idx)
1021 LVCOLUMN column;
1022 INT rc;
1024 memset(&column, 0xcc, sizeof(column));
1025 column.mask = LVCF_SUBITEM;
1026 column.iSubItem = idx;
1028 rc = ListView_InsertColumn(hwnd, idx, &column);
1029 expect(idx, rc);
1032 static void insert_item(HWND hwnd, int idx)
1034 static CHAR text[] = "foo";
1036 LVITEMA item;
1037 INT rc;
1039 memset(&item, 0xcc, sizeof (item));
1040 item.mask = LVIF_TEXT;
1041 item.iItem = idx;
1042 item.iSubItem = 0;
1043 item.pszText = text;
1045 rc = ListView_InsertItem(hwnd, &item);
1046 expect(idx, rc);
1049 static void test_items(void)
1051 const LPARAM lparamTest = 0x42;
1052 static CHAR text[] = "Text";
1053 char buffA[5];
1054 HWND hwnd;
1055 LVITEMA item;
1056 DWORD r;
1058 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1059 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1060 ok(hwnd != NULL, "failed to create listview window\n");
1063 * Test setting/getting item params
1066 /* Set up two columns */
1067 insert_column(hwnd, 0);
1068 insert_column(hwnd, 1);
1070 /* LVIS_SELECTED with zero stateMask */
1071 /* set */
1072 memset (&item, 0, sizeof (item));
1073 item.mask = LVIF_STATE;
1074 item.state = LVIS_SELECTED;
1075 item.stateMask = 0;
1076 item.iItem = 0;
1077 item.iSubItem = 0;
1078 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1079 expect(0, r);
1080 /* get */
1081 memset (&item, 0xcc, sizeof (item));
1082 item.mask = LVIF_STATE;
1083 item.stateMask = LVIS_SELECTED;
1084 item.state = 0;
1085 item.iItem = 0;
1086 item.iSubItem = 0;
1087 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1088 expect(1, r);
1089 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1090 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1092 /* LVIS_SELECTED with zero stateMask */
1093 /* set */
1094 memset (&item, 0, sizeof (item));
1095 item.mask = LVIF_STATE;
1096 item.state = LVIS_FOCUSED;
1097 item.stateMask = 0;
1098 item.iItem = 0;
1099 item.iSubItem = 0;
1100 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1101 expect(0, r);
1102 /* get */
1103 memset (&item, 0xcc, sizeof (item));
1104 item.mask = LVIF_STATE;
1105 item.stateMask = LVIS_FOCUSED;
1106 item.state = 0;
1107 item.iItem = 0;
1108 item.iSubItem = 0;
1109 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1110 expect(1, r);
1111 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1112 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1114 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1115 /* set */
1116 memset (&item, 0, sizeof (item));
1117 item.mask = LVIF_STATE;
1118 item.state = LVIS_CUT;
1119 item.stateMask = LVIS_FOCUSED;
1120 item.iItem = 0;
1121 item.iSubItem = 0;
1122 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1123 expect(0, r);
1124 /* get */
1125 memset (&item, 0xcc, sizeof (item));
1126 item.mask = LVIF_STATE;
1127 item.stateMask = LVIS_CUT;
1128 item.state = 0;
1129 item.iItem = 0;
1130 item.iSubItem = 0;
1131 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1132 expect(1, r);
1133 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1134 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1136 /* Insert an item with just a param */
1137 memset (&item, 0xcc, sizeof (item));
1138 item.mask = LVIF_PARAM;
1139 item.iItem = 0;
1140 item.iSubItem = 0;
1141 item.lParam = lparamTest;
1142 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1143 expect(0, r);
1145 /* Test getting of the param */
1146 memset (&item, 0xcc, sizeof (item));
1147 item.mask = LVIF_PARAM;
1148 item.iItem = 0;
1149 item.iSubItem = 0;
1150 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1151 expect(1, r);
1152 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1154 /* Set up a subitem */
1155 memset (&item, 0xcc, sizeof (item));
1156 item.mask = LVIF_TEXT;
1157 item.iItem = 0;
1158 item.iSubItem = 1;
1159 item.pszText = text;
1160 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1161 expect(1, r);
1163 item.mask = LVIF_TEXT;
1164 item.iItem = 0;
1165 item.iSubItem = 1;
1166 item.pszText = buffA;
1167 item.cchTextMax = sizeof(buffA);
1168 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1169 expect(1, r);
1170 ok(!memcmp(item.pszText, text, sizeof(text)), "got text %s, expected %s\n", item.pszText, text);
1172 /* set up with extra flag */
1173 /* 1. reset subitem text */
1174 item.mask = LVIF_TEXT;
1175 item.iItem = 0;
1176 item.iSubItem = 1;
1177 item.pszText = NULL;
1178 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1179 expect(1, r);
1181 item.mask = LVIF_TEXT;
1182 item.iItem = 0;
1183 item.iSubItem = 1;
1184 item.pszText = buffA;
1185 buffA[0] = 'a';
1186 item.cchTextMax = sizeof(buffA);
1187 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1188 expect(1, r);
1189 ok(item.pszText[0] == 0, "got %p\n", item.pszText);
1191 /* 2. set new text with extra flag specified */
1192 item.mask = LVIF_TEXT | LVIF_DI_SETITEM;
1193 item.iItem = 0;
1194 item.iSubItem = 1;
1195 item.pszText = text;
1196 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1197 ok(r == 1 || broken(r == 0) /* NT4 */, "ret %d\n", r);
1199 if (r == 1)
1201 item.mask = LVIF_TEXT;
1202 item.iItem = 0;
1203 item.iSubItem = 1;
1204 item.pszText = buffA;
1205 buffA[0] = 'a';
1206 item.cchTextMax = sizeof(buffA);
1207 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1208 expect(1, r);
1209 ok(!memcmp(item.pszText, text, sizeof(text)), "got %s, expected %s\n", item.pszText, text);
1212 /* Query param from subitem: returns main item param */
1213 memset (&item, 0xcc, sizeof (item));
1214 item.mask = LVIF_PARAM;
1215 item.iItem = 0;
1216 item.iSubItem = 1;
1217 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1218 expect(1, r);
1219 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1221 /* Set up param on first subitem: no effect */
1222 memset (&item, 0xcc, sizeof (item));
1223 item.mask = LVIF_PARAM;
1224 item.iItem = 0;
1225 item.iSubItem = 1;
1226 item.lParam = lparamTest+1;
1227 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1228 expect(0, r);
1230 /* Query param from subitem again: should still return main item param */
1231 memset (&item, 0xcc, sizeof (item));
1232 item.mask = LVIF_PARAM;
1233 item.iItem = 0;
1234 item.iSubItem = 1;
1235 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1236 expect(1, r);
1237 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1239 /**** Some tests of state highlighting ****/
1240 memset (&item, 0xcc, sizeof (item));
1241 item.mask = LVIF_STATE;
1242 item.iItem = 0;
1243 item.iSubItem = 0;
1244 item.state = LVIS_SELECTED;
1245 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1246 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1247 expect(1, r);
1248 item.iSubItem = 1;
1249 item.state = LVIS_DROPHILITED;
1250 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1251 expect(1, r);
1253 memset (&item, 0xcc, sizeof (item));
1254 item.mask = LVIF_STATE;
1255 item.iItem = 0;
1256 item.iSubItem = 0;
1257 item.stateMask = -1;
1258 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1259 expect(1, r);
1260 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1261 item.iSubItem = 1;
1262 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1263 expect(1, r);
1264 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1266 /* some notnull but meaningless masks */
1267 memset (&item, 0, sizeof(item));
1268 item.mask = LVIF_NORECOMPUTE;
1269 item.iItem = 0;
1270 item.iSubItem = 0;
1271 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1272 expect(1, r);
1273 memset (&item, 0, sizeof(item));
1274 item.mask = LVIF_DI_SETITEM;
1275 item.iItem = 0;
1276 item.iSubItem = 0;
1277 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1278 expect(1, r);
1280 /* set text to callback value already having it */
1281 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1282 expect(TRUE, r);
1283 memset (&item, 0, sizeof (item));
1284 item.mask = LVIF_TEXT;
1285 item.pszText = LPSTR_TEXTCALLBACK;
1286 item.iItem = 0;
1287 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1288 expect(0, r);
1289 memset (&item, 0, sizeof (item));
1291 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1293 item.pszText = LPSTR_TEXTCALLBACK;
1294 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1295 expect(TRUE, r);
1297 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1298 "check callback text comparison rule", FALSE);
1300 DestroyWindow(hwnd);
1303 static void test_columns(void)
1305 HWND hwnd;
1306 LVCOLUMNA column;
1307 LVITEMA item;
1308 INT order[2];
1309 CHAR buff[5];
1310 DWORD rc;
1312 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1313 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1314 ok(hwnd != NULL, "failed to create listview window\n");
1316 /* Add a column with no mask */
1317 memset(&column, 0xcc, sizeof(column));
1318 column.mask = 0;
1319 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1320 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1322 /* Check its width */
1323 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1324 ok(rc == 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1326 DestroyWindow(hwnd);
1328 /* LVM_GETCOLUMNORDERARRAY */
1329 hwnd = create_listview_control(LVS_REPORT);
1330 subclass_header(hwnd);
1332 memset(&column, 0, sizeof(column));
1333 column.mask = LVCF_WIDTH;
1334 column.cx = 100;
1335 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1336 expect(0, rc);
1338 column.cx = 200;
1339 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1340 expect(1, rc);
1342 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1344 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1345 expect(1, rc);
1346 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1347 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1349 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1351 /* after column added subitem is considered as present */
1352 insert_item(hwnd, 0);
1354 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1356 item.pszText = buff;
1357 item.cchTextMax = sizeof(buff);
1358 item.iItem = 0;
1359 item.iSubItem = 1;
1360 item.mask = LVIF_TEXT;
1361 memset(&g_itema, 0, sizeof(g_itema));
1362 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1363 expect(1, rc);
1364 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1366 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1367 "get subitem text after column added", FALSE);
1369 DestroyWindow(hwnd);
1372 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1373 static WNDPROC listviewWndProc;
1374 static HIMAGELIST test_create_imagelist;
1376 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1378 LRESULT ret;
1380 if (uMsg == WM_CREATE)
1382 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1383 lpcs->style |= LVS_REPORT;
1385 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1386 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1387 return ret;
1390 static void test_create(void)
1392 HWND hList;
1393 HWND hHeader;
1394 LONG_PTR ret;
1395 LONG r;
1396 LVCOLUMNA col;
1397 RECT rect;
1398 WNDCLASSEX cls;
1399 DWORD style;
1401 cls.cbSize = sizeof(WNDCLASSEX);
1402 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1403 listviewWndProc = cls.lpfnWndProc;
1404 cls.lpfnWndProc = create_test_wndproc;
1405 cls.lpszClassName = "MyListView32";
1406 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1408 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1409 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1410 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1411 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1413 if (!IsWindow(hHeader))
1415 /* version 4.0 */
1416 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1417 DestroyWindow(hList);
1418 return;
1421 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1422 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1423 DestroyWindow(hList);
1425 /* header isn't created on LVS_ICON and LVS_LIST styles */
1426 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1427 GetModuleHandle(NULL), 0);
1428 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1429 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1430 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1431 /* insert column */
1432 memset(&col, 0, sizeof(LVCOLUMNA));
1433 col.mask = LVCF_WIDTH;
1434 col.cx = 100;
1435 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1436 expect(0, r);
1437 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1438 ok(IsWindow(hHeader), "Header should be created\n");
1439 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1440 style = GetWindowLong(hHeader, GWL_STYLE);
1441 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1442 DestroyWindow(hList);
1444 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1445 GetModuleHandle(NULL), 0);
1446 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1447 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1448 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1449 /* insert column */
1450 memset(&col, 0, sizeof(LVCOLUMNA));
1451 col.mask = LVCF_WIDTH;
1452 col.cx = 100;
1453 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1454 expect(0, r);
1455 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1456 ok(IsWindow(hHeader), "Header should be created\n");
1457 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1458 DestroyWindow(hList);
1460 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1461 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1462 GetModuleHandle(NULL), 0);
1463 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1464 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1465 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1466 ok(IsWindow(hHeader), "Header should be created\n");
1467 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1468 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1469 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1470 ok(IsWindow(hHeader), "Header should be created\n");
1471 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1472 DestroyWindow(hList);
1474 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1475 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1476 GetModuleHandle(NULL), 0);
1477 ret = SetWindowLongPtr(hList, GWL_STYLE,
1478 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1479 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1480 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1481 ok(IsWindow(hHeader), "Header should be created\n");
1482 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1483 ret = SetWindowLongPtr(hList, GWL_STYLE,
1484 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1485 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1486 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1487 ok(IsWindow(hHeader), "Header should be created\n");
1488 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1489 DestroyWindow(hList);
1491 /* LVS_REPORT without WS_VISIBLE */
1492 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1493 GetModuleHandle(NULL), 0);
1494 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1495 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1496 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1497 /* insert column */
1498 memset(&col, 0, sizeof(LVCOLUMNA));
1499 col.mask = LVCF_WIDTH;
1500 col.cx = 100;
1501 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1502 expect(0, r);
1503 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1504 ok(IsWindow(hHeader), "Header should be created\n");
1505 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1506 DestroyWindow(hList);
1508 /* LVS_REPORT without WS_VISIBLE, try to show it */
1509 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1510 GetModuleHandle(NULL), 0);
1511 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1512 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1513 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1514 ShowWindow(hList, SW_SHOW);
1515 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1516 ok(IsWindow(hHeader), "Header should be created\n");
1517 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1518 DestroyWindow(hList);
1520 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1521 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1522 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1523 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1524 ok(IsWindow(hHeader), "Header should be created\n");
1525 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1526 /* HDS_DRAGDROP set by default */
1527 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1528 DestroyWindow(hList);
1530 /* setting LVS_EX_HEADERDRAGDROP creates header */
1531 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1532 GetModuleHandle(NULL), 0);
1533 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1534 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1535 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1536 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1537 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1538 ok(IsWindow(hHeader) ||
1539 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1540 "Header should be created\n");
1541 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1542 DestroyWindow(hList);
1544 /* setting LVS_EX_GRIDLINES creates header */
1545 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1546 GetModuleHandle(NULL), 0);
1547 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1548 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1549 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1550 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_GRIDLINES);
1551 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1552 ok(IsWindow(hHeader) ||
1553 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1554 "Header should be created\n");
1555 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1556 DestroyWindow(hList);
1558 /* setting LVS_EX_FULLROWSELECT creates header */
1559 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1560 GetModuleHandle(NULL), 0);
1561 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1562 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1563 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1564 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
1565 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1566 ok(IsWindow(hHeader) ||
1567 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1568 "Header should be created\n");
1569 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1570 DestroyWindow(hList);
1572 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1573 hList = create_listview_control(LVS_ICON);
1574 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1575 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1576 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1577 DestroyWindow(hList);
1579 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1580 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1581 GetModuleHandle(NULL), 0);
1582 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1583 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1585 rect.left = LVIR_BOUNDS;
1586 rect.top = 1;
1587 rect.right = rect.bottom = -10;
1588 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1589 expect(1, r);
1591 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1592 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1593 ok(GetDlgItem(hList, 0) == NULL, "NULL dialog item expected\n");
1595 DestroyWindow(hList);
1597 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1598 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1599 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1600 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1601 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1602 DestroyWindow(hList);
1605 static void test_redraw(void)
1607 HWND hwnd;
1608 HDC hdc;
1609 BOOL res;
1610 DWORD r;
1612 hwnd = create_listview_control(LVS_REPORT);
1613 subclass_header(hwnd);
1615 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1617 InvalidateRect(hwnd, NULL, TRUE);
1618 UpdateWindow(hwnd);
1619 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1621 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1623 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1624 /* 1. Without backbuffer */
1625 res = ListView_SetBkColor(hwnd, CLR_NONE);
1626 expect(TRUE, res);
1628 hdc = GetWindowDC(hwndparent);
1630 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1631 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1632 ok(r == 1, "Expected not zero result\n");
1633 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1634 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1636 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1637 expect(TRUE, res);
1639 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1640 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1641 expect(1, r);
1642 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1643 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1645 /* 2. With backbuffer */
1646 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1647 LVS_EX_DOUBLEBUFFER);
1648 res = ListView_SetBkColor(hwnd, CLR_NONE);
1649 expect(TRUE, res);
1651 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1652 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1653 expect(1, r);
1654 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1655 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1657 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1658 expect(TRUE, res);
1660 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1661 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1662 todo_wine expect(1, r);
1663 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1664 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1666 ReleaseDC(hwndparent, hdc);
1668 DestroyWindow(hwnd);
1671 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1673 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1675 if(msg == WM_NOTIFY) {
1676 NMHDR *nmhdr = (PVOID)lp;
1677 if(nmhdr->code == NM_CUSTOMDRAW) {
1678 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1679 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1680 switch(nmlvcd->nmcd.dwDrawStage) {
1681 case CDDS_PREPAINT:
1682 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1683 return CDRF_NOTIFYITEMDRAW;
1684 case CDDS_ITEMPREPAINT:
1685 nmlvcd->clrTextBk = CLR_DEFAULT;
1686 return CDRF_NOTIFYSUBITEMDRAW;
1687 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1688 clr = GetBkColor(nmlvcd->nmcd.hdc);
1689 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1690 return CDRF_NOTIFYPOSTPAINT;
1691 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1692 clr = GetBkColor(nmlvcd->nmcd.hdc);
1693 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1694 return CDRF_DODEFAULT;
1696 return CDRF_DODEFAULT;
1700 return DefWindowProcA(hwnd, msg, wp, lp);
1703 static void test_customdraw(void)
1705 HWND hwnd;
1706 WNDPROC oldwndproc;
1708 hwnd = create_listview_control(LVS_REPORT);
1710 insert_column(hwnd, 0);
1711 insert_column(hwnd, 1);
1712 insert_item(hwnd, 0);
1714 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1715 (LONG_PTR)cd_wndproc);
1717 InvalidateRect(hwnd, NULL, TRUE);
1718 UpdateWindow(hwnd);
1720 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1722 DestroyWindow(hwnd);
1725 static void test_icon_spacing(void)
1727 /* LVM_SETICONSPACING */
1728 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1730 HWND hwnd;
1731 WORD w, h;
1732 INT r;
1734 hwnd = create_listview_control(LVS_ICON);
1735 ok(hwnd != NULL, "failed to create a listview window\n");
1737 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1738 expect(NFR_ANSI, r);
1740 /* reset the icon spacing to defaults */
1741 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1743 /* now we can request what the defaults are */
1744 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1745 w = LOWORD(r);
1746 h = HIWORD(r);
1748 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1750 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1751 ok(r == MAKELONG(w, h) ||
1752 broken(r == MAKELONG(w, w)), /* win98 */
1753 "Expected %d, got %d\n", MAKELONG(w, h), r);
1755 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1756 if (r == 0)
1758 /* version 4.0 */
1759 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1760 DestroyWindow(hwnd);
1761 return;
1763 expect(MAKELONG(20,30), r);
1765 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1766 expect(MAKELONG(25,35), r);
1768 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1770 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1771 DestroyWindow(hwnd);
1774 static void test_color(void)
1776 RECT rect;
1777 HWND hwnd;
1778 DWORD r;
1779 int i;
1781 COLORREF color;
1782 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1784 hwnd = create_listview_control(LVS_REPORT);
1785 ok(hwnd != NULL, "failed to create a listview window\n");
1787 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1789 for (i = 0; i < 4; i++)
1791 color = colors[i];
1793 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1794 expect(TRUE, r);
1795 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
1796 expect(color, r);
1798 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1799 expect (TRUE, r);
1800 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, 0);
1801 expect(color, r);
1803 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1804 expect(TRUE, r);
1805 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, 0);
1806 expect(color, r);
1809 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1810 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1812 /* invalidation test done separately to avoid a message chain mess */
1813 r = ValidateRect(hwnd, NULL);
1814 expect(TRUE, r);
1815 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, colors[0]);
1816 expect(TRUE, r);
1818 rect.right = rect.bottom = 1;
1819 r = GetUpdateRect(hwnd, &rect, TRUE);
1820 todo_wine expect(FALSE, r);
1821 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1823 r = ValidateRect(hwnd, NULL);
1824 expect(TRUE, r);
1825 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, colors[0]);
1826 expect(TRUE, r);
1828 rect.right = rect.bottom = 1;
1829 r = GetUpdateRect(hwnd, &rect, TRUE);
1830 todo_wine expect(FALSE, r);
1831 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1833 r = ValidateRect(hwnd, NULL);
1834 expect(TRUE, r);
1835 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, colors[0]);
1836 expect(TRUE, r);
1838 rect.right = rect.bottom = 1;
1839 r = GetUpdateRect(hwnd, &rect, TRUE);
1840 todo_wine expect(FALSE, r);
1841 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1843 DestroyWindow(hwnd);
1846 static void test_item_count(void)
1848 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1850 HWND hwnd;
1851 DWORD r;
1852 HDC hdc;
1853 HFONT hOldFont;
1854 TEXTMETRICA tm;
1855 RECT rect;
1856 INT height;
1858 LVITEM item0;
1859 LVITEM item1;
1860 LVITEM item2;
1861 static CHAR item0text[] = "item0";
1862 static CHAR item1text[] = "item1";
1863 static CHAR item2text[] = "item2";
1865 hwnd = create_listview_control(LVS_REPORT);
1866 ok(hwnd != NULL, "failed to create a listview window\n");
1868 /* resize in dpiaware manner to fit all 3 items added */
1869 hdc = GetDC(0);
1870 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1871 GetTextMetricsA(hdc, &tm);
1872 /* 2 extra pixels for bounds and header border */
1873 height = tm.tmHeight + 2;
1874 SelectObject(hdc, hOldFont);
1875 ReleaseDC(0, hdc);
1877 GetWindowRect(hwnd, &rect);
1878 /* 3 items + 1 header + 1 to be sure */
1879 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1881 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1883 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1884 expect(0, r);
1886 /* [item0] */
1887 item0.mask = LVIF_TEXT;
1888 item0.iItem = 0;
1889 item0.iSubItem = 0;
1890 item0.pszText = item0text;
1891 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1892 expect(0, r);
1894 /* [item0, item1] */
1895 item1.mask = LVIF_TEXT;
1896 item1.iItem = 1;
1897 item1.iSubItem = 0;
1898 item1.pszText = item1text;
1899 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1900 expect(1, r);
1902 /* [item0, item1, item2] */
1903 item2.mask = LVIF_TEXT;
1904 item2.iItem = 2;
1905 item2.iSubItem = 0;
1906 item2.pszText = item2text;
1907 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1908 expect(2, r);
1910 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1911 expect(3, r);
1913 /* [item0, item1] */
1914 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1915 expect(TRUE, r);
1917 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1918 expect(2, r);
1920 /* [] */
1921 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1922 expect(TRUE, r);
1924 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1925 expect(0, r);
1927 /* [item0] */
1928 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1929 expect(0, r);
1931 /* [item0, item1] */
1932 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1933 expect(1, r);
1935 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1936 expect(2, r);
1938 /* [item0, item1, item2] */
1939 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1940 expect(2, r);
1942 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1943 expect(3, r);
1945 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1947 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1948 DestroyWindow(hwnd);
1951 static void test_item_position(void)
1953 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1955 HWND hwnd;
1956 DWORD r;
1957 POINT position;
1959 LVITEM item0;
1960 LVITEM item1;
1961 LVITEM item2;
1962 static CHAR item0text[] = "item0";
1963 static CHAR item1text[] = "item1";
1964 static CHAR item2text[] = "item2";
1966 hwnd = create_listview_control(LVS_ICON);
1967 ok(hwnd != NULL, "failed to create a listview window\n");
1969 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1971 /* [item0] */
1972 item0.mask = LVIF_TEXT;
1973 item0.iItem = 0;
1974 item0.iSubItem = 0;
1975 item0.pszText = item0text;
1976 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1977 expect(0, r);
1979 /* [item0, item1] */
1980 item1.mask = LVIF_TEXT;
1981 item1.iItem = 1;
1982 item1.iSubItem = 0;
1983 item1.pszText = item1text;
1984 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1985 expect(1, r);
1987 /* [item0, item1, item2] */
1988 item2.mask = LVIF_TEXT;
1989 item2.iItem = 2;
1990 item2.iSubItem = 0;
1991 item2.pszText = item2text;
1992 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1993 expect(2, r);
1995 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1996 expect(TRUE, r);
1997 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1998 expect(TRUE, r);
1999 expect2(10, 5, position.x, position.y);
2001 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
2002 expect(TRUE, r);
2003 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
2004 expect(TRUE, r);
2005 expect2(0, 0, position.x, position.y);
2007 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
2008 expect(TRUE, r);
2009 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
2010 expect(TRUE, r);
2011 expect2(20, 20, position.x, position.y);
2013 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
2015 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2016 DestroyWindow(hwnd);
2019 static void test_getorigin(void)
2021 /* LVM_GETORIGIN */
2023 HWND hwnd;
2024 DWORD r;
2025 POINT position;
2027 position.x = position.y = 0;
2029 hwnd = create_listview_control(LVS_ICON);
2030 ok(hwnd != NULL, "failed to create a listview window\n");
2031 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2033 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2034 expect(TRUE, r);
2035 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2036 DestroyWindow(hwnd);
2038 hwnd = create_listview_control(LVS_SMALLICON);
2039 ok(hwnd != NULL, "failed to create a listview window\n");
2040 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2042 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2043 expect(TRUE, r);
2044 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2045 DestroyWindow(hwnd);
2047 hwnd = create_listview_control(LVS_LIST);
2048 ok(hwnd != NULL, "failed to create a listview window\n");
2049 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2051 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2052 expect(FALSE, r);
2053 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2054 DestroyWindow(hwnd);
2056 hwnd = create_listview_control(LVS_REPORT);
2057 ok(hwnd != NULL, "failed to create a listview window\n");
2058 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2060 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2061 expect(FALSE, r);
2062 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2063 DestroyWindow(hwnd);
2066 static void test_multiselect(void)
2068 typedef struct t_select_task
2070 const char *descr;
2071 int initPos;
2072 int loopVK;
2073 int count;
2074 int result;
2075 } select_task;
2077 HWND hwnd;
2078 INT r;
2079 int i,j,item_count,selected_count;
2080 static const int items=5;
2081 BYTE kstate[256];
2082 select_task task;
2083 LONG_PTR style;
2084 LVITEMA item;
2086 static struct t_select_task task_list[] = {
2087 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
2088 { "using VK_UP", -1, VK_UP, -1, -1 },
2089 { "using VK_END", 0, VK_END, 1, -1 },
2090 { "using VK_HOME", -1, VK_HOME, 1, -1 }
2093 hwnd = create_listview_control(LVS_REPORT);
2095 for (i=0;i<items;i++) {
2096 insert_item(hwnd, 0);
2099 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2101 expect(items,item_count);
2103 for (i=0;i<4;i++) {
2104 task = task_list[i];
2106 /* deselect all items */
2107 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2108 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2110 /* set initial position */
2111 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
2112 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
2114 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2116 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
2118 /* Set SHIFT key pressed */
2119 GetKeyboardState(kstate);
2120 kstate[VK_SHIFT]=0x80;
2121 SetKeyboardState(kstate);
2123 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
2124 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
2125 expect(0,r);
2126 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
2127 expect(0,r);
2130 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2132 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);
2134 /* Set SHIFT key released */
2135 GetKeyboardState(kstate);
2136 kstate[VK_SHIFT]=0x00;
2137 SetKeyboardState(kstate);
2139 DestroyWindow(hwnd);
2141 /* make multiple selection, then switch to LVS_SINGLESEL */
2142 hwnd = create_listview_control(LVS_REPORT);
2143 for (i=0;i<items;i++) {
2144 insert_item(hwnd, 0);
2146 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2147 expect(items,item_count);
2149 /* try with NULL pointer */
2150 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
2151 expect(FALSE, r);
2153 /* select all, check notifications */
2154 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2156 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2158 item.stateMask = LVIS_SELECTED;
2159 item.state = LVIS_SELECTED;
2160 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2161 expect(TRUE, r);
2163 ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
2164 "select all notification", FALSE);
2166 /* deselect all items */
2167 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2168 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2169 for (i=0;i<3;i++) {
2170 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
2173 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2174 expect(3, r);
2175 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2176 expect(-1, r);
2178 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2179 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2180 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2181 /* check that style is accepted */
2182 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2183 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2185 for (i=0;i<3;i++) {
2186 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2187 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2189 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2190 expect(3, r);
2191 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2192 expect(3, r);
2194 /* select one more */
2195 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2197 for (i=0;i<3;i++) {
2198 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2199 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2201 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2202 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2204 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2205 expect(1, r);
2206 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2207 expect(-1, r);
2209 /* try to select all on LVS_SINGLESEL */
2210 memset(&item, 0, sizeof(item));
2211 item.stateMask = LVIS_SELECTED;
2212 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2213 expect(TRUE, r);
2214 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2216 item.stateMask = LVIS_SELECTED;
2217 item.state = LVIS_SELECTED;
2218 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2219 expect(FALSE, r);
2221 r = ListView_GetSelectedCount(hwnd);
2222 expect(0, r);
2223 r = ListView_GetSelectionMark(hwnd);
2224 expect(-1, r);
2226 /* try to deselect all on LVS_SINGLESEL */
2227 item.stateMask = LVIS_SELECTED;
2228 item.state = LVIS_SELECTED;
2229 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2230 expect(TRUE, r);
2232 item.stateMask = LVIS_SELECTED;
2233 item.state = 0;
2234 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2235 expect(TRUE, r);
2236 r = ListView_GetSelectedCount(hwnd);
2237 expect(0, r);
2239 /* 1. selection mark is update when new focused item is set */
2240 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2241 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2243 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2244 expect(-1, r);
2246 item.stateMask = LVIS_FOCUSED;
2247 item.state = LVIS_FOCUSED;
2248 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2249 expect(TRUE, r);
2251 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2252 expect(0, r);
2254 /* it's not updated if already set */
2255 item.stateMask = LVIS_FOCUSED;
2256 item.state = LVIS_FOCUSED;
2257 r = SendMessage(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2258 expect(TRUE, r);
2260 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2261 expect(0, r);
2263 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2264 expect(0, r);
2266 item.stateMask = LVIS_FOCUSED;
2267 item.state = LVIS_FOCUSED;
2268 r = SendMessage(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2269 expect(TRUE, r);
2271 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2272 expect(-1, r);
2274 /* need to reset focused item first */
2275 item.stateMask = LVIS_FOCUSED;
2276 item.state = 0;
2277 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2278 expect(TRUE, r);
2280 item.stateMask = LVIS_FOCUSED;
2281 item.state = LVIS_FOCUSED;
2282 r = SendMessage(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
2283 expect(TRUE, r);
2285 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2286 expect(2, r);
2288 item.stateMask = LVIS_FOCUSED;
2289 item.state = 0;
2290 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2291 expect(TRUE, r);
2293 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2294 expect(2, r);
2296 /* 2. same tests, with LVM_SETITEM */
2297 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2298 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2300 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2301 expect(2, r);
2303 item.stateMask = LVIS_FOCUSED;
2304 item.state = LVIS_FOCUSED;
2305 item.mask = LVIF_STATE;
2306 item.iItem = item.iSubItem = 0;
2307 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2308 expect(TRUE, r);
2310 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2311 expect(0, r);
2313 /* it's not updated if already set */
2314 item.stateMask = LVIS_FOCUSED;
2315 item.state = LVIS_FOCUSED;
2316 item.mask = LVIF_STATE;
2317 item.iItem = 1;
2318 item.iSubItem = 0;
2319 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2320 expect(TRUE, r);
2322 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2323 expect(0, r);
2325 r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2326 expect(0, r);
2328 item.stateMask = LVIS_FOCUSED;
2329 item.state = LVIS_FOCUSED;
2330 item.mask = LVIF_STATE;
2331 item.iItem = 1;
2332 item.iSubItem = 0;
2333 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2334 expect(TRUE, r);
2336 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2337 expect(-1, r);
2339 /* need to reset focused item first */
2340 item.stateMask = LVIS_FOCUSED;
2341 item.state = 0;
2342 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2343 expect(TRUE, r);
2345 item.stateMask = LVIS_FOCUSED;
2346 item.state = LVIS_FOCUSED;
2347 item.mask = LVIF_STATE;
2348 item.iItem = 2;
2349 item.iSubItem = 0;
2350 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2351 expect(TRUE, r);
2353 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2354 expect(2, r);
2356 item.stateMask = LVIS_FOCUSED;
2357 item.state = 0;
2358 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2359 expect(TRUE, r);
2361 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2362 expect(2, r);
2364 DestroyWindow(hwnd);
2367 static void test_subitem_rect(void)
2369 HWND hwnd;
2370 DWORD r;
2371 LVCOLUMN col;
2372 RECT rect, rect2;
2373 INT arr[3];
2375 /* test LVM_GETSUBITEMRECT for header */
2376 hwnd = create_listview_control(LVS_REPORT);
2377 ok(hwnd != NULL, "failed to create a listview window\n");
2378 /* add some columns */
2379 memset(&col, 0, sizeof(LVCOLUMN));
2380 col.mask = LVCF_WIDTH;
2381 col.cx = 100;
2382 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2383 expect(0, r);
2384 col.cx = 150;
2385 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2386 expect(1, r);
2387 col.cx = 200;
2388 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2389 expect(2, r);
2390 /* item = -1 means header, subitem index is 1 based */
2391 rect.left = LVIR_BOUNDS;
2392 rect.top = 0;
2393 rect.right = rect.bottom = 0;
2394 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2395 expect(0, r);
2397 rect.left = LVIR_BOUNDS;
2398 rect.top = 1;
2399 rect.right = rect.bottom = 0;
2400 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2401 expect(1, r);
2403 expect(100, rect.left);
2404 expect(250, rect.right);
2405 todo_wine
2406 expect(3, rect.top);
2408 rect.left = LVIR_BOUNDS;
2409 rect.top = 2;
2410 rect.right = rect.bottom = 0;
2411 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2412 expect(1, r);
2414 expect(250, rect.left);
2415 expect(450, rect.right);
2416 todo_wine
2417 expect(3, rect.top);
2419 /* item LVS_REPORT padding isn't applied to subitems */
2420 insert_item(hwnd, 0);
2422 rect.left = LVIR_BOUNDS;
2423 rect.top = 1;
2424 rect.right = rect.bottom = 0;
2425 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2426 expect(1, r);
2427 expect(100, rect.left);
2428 expect(250, rect.right);
2430 rect.left = LVIR_ICON;
2431 rect.top = 1;
2432 rect.right = rect.bottom = 0;
2433 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2434 expect(1, r);
2435 /* no icon attached - zero width rectangle, with no left padding */
2436 expect(100, rect.left);
2437 expect(100, rect.right);
2439 rect.left = LVIR_LABEL;
2440 rect.top = 1;
2441 rect.right = rect.bottom = 0;
2442 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2443 expect(1, r);
2444 /* same as full LVIR_BOUNDS */
2445 expect(100, rect.left);
2446 expect(250, rect.right);
2448 SendMessage(hwnd, LVM_SCROLL, 10, 0);
2450 rect.left = LVIR_BOUNDS;
2451 rect.top = 1;
2452 rect.right = rect.bottom = 0;
2453 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2454 expect(1, r);
2455 expect(90, rect.left);
2456 expect(240, rect.right);
2458 SendMessage(hwnd, LVM_SCROLL, -10, 0);
2460 DestroyWindow(hwnd);
2462 /* test subitem rects after re-arranging columns */
2463 hwnd = create_listview_control(LVS_REPORT);
2464 ok(hwnd != NULL, "failed to create a listview window\n");
2465 memset(&col, 0, sizeof(LVCOLUMN));
2466 col.mask = LVCF_WIDTH;
2468 col.cx = 100;
2469 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2470 expect(0, r);
2472 col.cx = 200;
2473 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2474 expect(1, r);
2476 col.cx = 300;
2477 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2478 expect(2, r);
2480 insert_item(hwnd, 0);
2481 insert_item(hwnd, 1);
2483 /* wrong item is refused for main item */
2484 rect.left = LVIR_BOUNDS;
2485 rect.top = 0;
2486 rect.right = rect.bottom = -1;
2487 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect);
2488 expect(FALSE, r);
2490 /* for subitems rectangle is calculated even if there's no item added */
2491 rect.left = LVIR_BOUNDS;
2492 rect.top = 1;
2493 rect.right = rect.bottom = -1;
2494 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect);
2495 expect(TRUE, r);
2497 rect2.left = LVIR_BOUNDS;
2498 rect2.top = 1;
2499 rect2.right = rect2.bottom = -1;
2500 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect2);
2501 todo_wine {
2502 expect(TRUE, r);
2503 expect(rect.right, rect2.right);
2504 expect(rect.left, rect2.left);
2505 expect(rect.bottom, rect2.top);
2506 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2509 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2510 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2511 expect(TRUE, r);
2513 rect.left = LVIR_BOUNDS;
2514 rect.top = 0;
2515 rect.right = rect.bottom = -1;
2516 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2517 expect(TRUE, r);
2518 expect(0, rect.left);
2519 expect(600, rect.right);
2521 rect.left = LVIR_BOUNDS;
2522 rect.top = 1;
2523 rect.right = rect.bottom = -1;
2524 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2525 expect(TRUE, r);
2526 expect(0, rect.left);
2527 expect(200, rect.right);
2529 rect2.left = LVIR_BOUNDS;
2530 rect2.top = 1;
2531 rect2.right = rect2.bottom = -1;
2532 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect2);
2533 expect(TRUE, r);
2534 expect(0, rect2.left);
2535 expect(200, rect2.right);
2536 /* items are of the same height */
2537 ok(rect2.top > 0, "expected positive item height\n");
2538 expect(rect.bottom, rect2.top);
2539 expect(rect.bottom * 2 - rect.top, rect2.bottom);
2541 rect.left = LVIR_BOUNDS;
2542 rect.top = 2;
2543 rect.right = rect.bottom = -1;
2544 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2545 expect(TRUE, r);
2546 expect(300, rect.left);
2547 expect(600, rect.right);
2549 DestroyWindow(hwnd);
2551 /* try it for non LVS_REPORT style */
2552 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2553 GetModuleHandle(NULL), 0);
2554 rect.left = LVIR_BOUNDS;
2555 rect.top = 1;
2556 rect.right = rect.bottom = -10;
2557 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2558 expect(0, r);
2559 /* rect is unchanged */
2560 expect(0, rect.left);
2561 expect(-10, rect.right);
2562 expect(1, rect.top);
2563 expect(-10, rect.bottom);
2564 DestroyWindow(hwnd);
2567 /* comparison callback for test_sorting */
2568 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2570 if (first == second) return 0;
2571 return (first > second ? 1 : -1);
2574 static void test_sorting(void)
2576 HWND hwnd;
2577 LVITEMA item = {0};
2578 INT r;
2579 LONG_PTR style;
2580 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2581 CHAR buff[10];
2583 hwnd = create_listview_control(LVS_REPORT);
2584 ok(hwnd != NULL, "failed to create a listview window\n");
2586 /* insert some items */
2587 item.mask = LVIF_PARAM | LVIF_STATE;
2588 item.state = LVIS_SELECTED;
2589 item.iItem = 0;
2590 item.iSubItem = 0;
2591 item.lParam = 3;
2592 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2593 expect(0, r);
2595 item.mask = LVIF_PARAM;
2596 item.iItem = 1;
2597 item.iSubItem = 0;
2598 item.lParam = 2;
2599 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2600 expect(1, r);
2602 item.mask = LVIF_STATE | LVIF_PARAM;
2603 item.state = LVIS_SELECTED;
2604 item.iItem = 2;
2605 item.iSubItem = 0;
2606 item.lParam = 4;
2607 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2608 expect(2, r);
2610 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2611 expect(-1, r);
2613 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2614 expect(2, r);
2616 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2617 expect(TRUE, r);
2619 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2620 expect(2, r);
2621 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2622 expect(-1, r);
2623 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2624 expect(0, r);
2625 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2626 expect(LVIS_SELECTED, r);
2627 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2628 expect(LVIS_SELECTED, r);
2630 DestroyWindow(hwnd);
2632 /* switch to LVS_SORTASCENDING when some items added */
2633 hwnd = create_listview_control(LVS_REPORT);
2634 ok(hwnd != NULL, "failed to create a listview window\n");
2636 item.mask = LVIF_TEXT;
2637 item.iItem = 0;
2638 item.iSubItem = 0;
2639 item.pszText = names[1];
2640 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2641 expect(0, r);
2643 item.mask = LVIF_TEXT;
2644 item.iItem = 1;
2645 item.iSubItem = 0;
2646 item.pszText = names[2];
2647 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2648 expect(1, r);
2650 item.mask = LVIF_TEXT;
2651 item.iItem = 2;
2652 item.iSubItem = 0;
2653 item.pszText = names[0];
2654 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2655 expect(2, r);
2657 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2658 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2659 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2660 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2662 /* no sorting performed when switched to LVS_SORTASCENDING */
2663 item.mask = LVIF_TEXT;
2664 item.iItem = 0;
2665 item.pszText = buff;
2666 item.cchTextMax = sizeof(buff);
2667 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2668 expect(TRUE, r);
2669 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2671 item.iItem = 1;
2672 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2673 expect(TRUE, r);
2674 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2676 item.iItem = 2;
2677 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2678 expect(TRUE, r);
2679 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2681 /* adding new item doesn't resort list */
2682 item.mask = LVIF_TEXT;
2683 item.iItem = 3;
2684 item.iSubItem = 0;
2685 item.pszText = names[3];
2686 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2687 expect(3, r);
2689 item.mask = LVIF_TEXT;
2690 item.iItem = 0;
2691 item.pszText = buff;
2692 item.cchTextMax = sizeof(buff);
2693 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2694 expect(TRUE, r);
2695 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2697 item.iItem = 1;
2698 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2699 expect(TRUE, r);
2700 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2702 item.iItem = 2;
2703 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2704 expect(TRUE, r);
2705 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2707 item.iItem = 3;
2708 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2709 expect(TRUE, r);
2710 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2712 /* corner case - item should be placed at first position */
2713 item.mask = LVIF_TEXT;
2714 item.iItem = 4;
2715 item.iSubItem = 0;
2716 item.pszText = names[4];
2717 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2718 expect(0, r);
2720 item.iItem = 0;
2721 item.pszText = buff;
2722 item.cchTextMax = sizeof(buff);
2723 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2724 expect(TRUE, r);
2725 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2727 item.iItem = 1;
2728 item.pszText = buff;
2729 item.cchTextMax = sizeof(buff);
2730 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2731 expect(TRUE, r);
2732 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2734 item.iItem = 2;
2735 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2736 expect(TRUE, r);
2737 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2739 item.iItem = 3;
2740 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2741 expect(TRUE, r);
2742 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2744 item.iItem = 4;
2745 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2746 expect(TRUE, r);
2747 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2749 DestroyWindow(hwnd);
2752 static void test_ownerdata(void)
2754 static char test_str[] = "test";
2756 HWND hwnd;
2757 LONG_PTR style, ret;
2758 DWORD res;
2759 LVITEMA item;
2761 /* it isn't possible to set LVS_OWNERDATA after creation */
2762 if (g_is_below_5)
2764 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2766 else
2768 hwnd = create_listview_control(LVS_REPORT);
2769 ok(hwnd != NULL, "failed to create a listview window\n");
2770 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2771 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2773 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2775 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2776 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2777 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2778 "try to switch to LVS_OWNERDATA seq", FALSE);
2780 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2781 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2782 DestroyWindow(hwnd);
2785 /* try to set LVS_OWNERDATA after creation just having it */
2786 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2787 ok(hwnd != NULL, "failed to create a listview window\n");
2788 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2789 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2791 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2793 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2794 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2795 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2796 "try to switch to LVS_OWNERDATA seq", FALSE);
2797 DestroyWindow(hwnd);
2799 /* try to remove LVS_OWNERDATA after creation just having it */
2800 if (g_is_below_5)
2802 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2804 else
2806 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2807 ok(hwnd != NULL, "failed to create a listview window\n");
2808 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2809 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2811 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2813 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2814 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2815 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2816 "try to switch to LVS_OWNERDATA seq", FALSE);
2817 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2818 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2819 DestroyWindow(hwnd);
2822 /* try select an item */
2823 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2824 ok(hwnd != NULL, "failed to create a listview window\n");
2825 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2826 expect(1, res);
2827 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2828 expect(0, res);
2829 memset(&item, 0, sizeof(item));
2830 item.stateMask = LVIS_SELECTED;
2831 item.state = LVIS_SELECTED;
2832 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2833 expect(TRUE, res);
2834 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2835 expect(1, res);
2836 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2837 expect(1, res);
2838 DestroyWindow(hwnd);
2840 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
2841 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2842 ok(hwnd != NULL, "failed to create a listview window\n");
2843 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2844 expect(1, res);
2845 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2846 expect(1, res);
2847 memset(&item, 0, sizeof(item));
2848 item.mask = LVIF_STATE;
2849 item.iItem = 0;
2850 item.stateMask = LVIS_SELECTED;
2851 item.state = LVIS_SELECTED;
2852 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2853 expect(FALSE, res);
2854 memset(&item, 0, sizeof(item));
2855 item.pszText = test_str;
2856 res = SendMessageA(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2857 expect(FALSE, res);
2858 DestroyWindow(hwnd);
2860 /* check notifications after focused/selected changed */
2861 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2862 ok(hwnd != NULL, "failed to create a listview window\n");
2863 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2864 expect(1, res);
2866 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2868 memset(&item, 0, sizeof(item));
2869 item.stateMask = LVIS_SELECTED;
2870 item.state = LVIS_SELECTED;
2871 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2872 expect(TRUE, res);
2874 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2875 "ownerdata select notification", TRUE);
2877 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2879 memset(&item, 0, sizeof(item));
2880 item.stateMask = LVIS_FOCUSED;
2881 item.state = LVIS_FOCUSED;
2882 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2883 expect(TRUE, res);
2885 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2886 "ownerdata focus notification", TRUE);
2888 /* select all, check notifications */
2889 item.stateMask = LVIS_SELECTED;
2890 item.state = 0;
2891 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2892 expect(TRUE, res);
2894 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2896 item.stateMask = LVIS_SELECTED;
2897 item.state = LVIS_SELECTED;
2899 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
2900 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2901 expect(TRUE, res);
2902 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
2903 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
2904 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
2905 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
2906 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
2907 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
2908 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
2910 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2911 "ownerdata select all notification", FALSE);
2913 /* select all again, note that all items are selected already */
2914 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2915 item.stateMask = LVIS_SELECTED;
2916 item.state = LVIS_SELECTED;
2918 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
2919 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2920 expect(TRUE, res);
2921 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
2922 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
2923 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
2924 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
2925 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
2926 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
2927 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
2929 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2930 "ownerdata select all notification", FALSE);
2932 /* deselect all */
2933 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2934 item.stateMask = LVIS_SELECTED;
2935 item.state = 0;
2937 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
2938 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2939 expect(TRUE, res);
2940 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
2941 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
2942 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
2943 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
2944 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
2945 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
2946 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
2948 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2949 "ownerdata deselect all notification", TRUE);
2951 /* nothing selected, deselect all again */
2952 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2953 item.stateMask = LVIS_SELECTED;
2954 item.state = 0;
2956 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2957 expect(TRUE, res);
2959 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "ownerdata deselect all notification", TRUE);
2961 /* select one, then deselect all */
2962 item.stateMask = LVIS_SELECTED;
2963 item.state = LVIS_SELECTED;
2964 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2965 expect(TRUE, res);
2966 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2967 item.stateMask = LVIS_SELECTED;
2968 item.state = 0;
2970 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
2971 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2972 expect(TRUE, res);
2973 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
2974 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
2975 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
2976 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
2977 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
2978 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
2979 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
2981 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2982 "ownerdata select all notification", TRUE);
2984 /* remove focused, try to focus all */
2985 item.stateMask = LVIS_FOCUSED;
2986 item.state = LVIS_FOCUSED;
2987 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2988 expect(TRUE, res);
2989 item.stateMask = LVIS_FOCUSED;
2990 item.state = 0;
2991 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2992 expect(TRUE, res);
2993 item.stateMask = LVIS_FOCUSED;
2994 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
2995 expect(0, res);
2997 /* setting all to focused returns failure value */
2998 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2999 item.stateMask = LVIS_FOCUSED;
3000 item.state = LVIS_FOCUSED;
3002 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3003 expect(FALSE, res);
3005 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3006 "ownerdata focus all notification", FALSE);
3008 /* focus single item, remove all */
3009 item.stateMask = LVIS_FOCUSED;
3010 item.state = LVIS_FOCUSED;
3011 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3012 expect(TRUE, res);
3013 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3014 item.stateMask = LVIS_FOCUSED;
3015 item.state = 0;
3017 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3018 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3019 expect(TRUE, res);
3020 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3021 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3022 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3023 ok(g_nmlistview.uOldState == LVIS_FOCUSED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3024 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3025 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3026 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3028 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
3029 "ownerdata remove focus all notification", TRUE);
3031 /* set all cut */
3032 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3033 item.stateMask = LVIS_CUT;
3034 item.state = LVIS_CUT;
3036 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3037 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3038 expect(TRUE, res);
3039 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3040 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3041 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3042 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3043 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3044 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3045 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3047 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3048 "ownerdata cut all notification", FALSE);
3050 /* all marked cut, try again */
3051 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3052 item.stateMask = LVIS_CUT;
3053 item.state = LVIS_CUT;
3055 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3056 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3057 expect(TRUE, res);
3058 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3059 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3060 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3061 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3062 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3063 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3064 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3066 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3067 "ownerdata cut all notification #2", FALSE);
3069 DestroyWindow(hwnd);
3071 /* check notifications on LVM_GETITEM */
3072 /* zero callback mask */
3073 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3074 ok(hwnd != NULL, "failed to create a listview window\n");
3075 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3076 expect(1, res);
3078 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3080 memset(&item, 0, sizeof(item));
3081 item.stateMask = LVIS_SELECTED;
3082 item.mask = LVIF_STATE;
3083 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3084 expect(TRUE, res);
3086 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3087 "ownerdata getitem selected state 1", FALSE);
3089 /* non zero callback mask but not we asking for */
3090 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
3091 expect(TRUE, res);
3093 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3095 memset(&item, 0, sizeof(item));
3096 item.stateMask = LVIS_SELECTED;
3097 item.mask = LVIF_STATE;
3098 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3099 expect(TRUE, res);
3101 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3102 "ownerdata getitem selected state 2", FALSE);
3104 /* LVIS_OVERLAYMASK callback mask, asking for index */
3105 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3107 memset(&item, 0, sizeof(item));
3108 item.stateMask = LVIS_OVERLAYMASK;
3109 item.mask = LVIF_STATE;
3110 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3111 expect(TRUE, res);
3113 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3114 "ownerdata getitem selected state 2", FALSE);
3116 DestroyWindow(hwnd);
3118 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3119 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
3120 ok(hwnd != NULL, "failed to create a listview window\n");
3121 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3122 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3123 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3124 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
3125 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3126 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
3127 DestroyWindow(hwnd);
3128 /* apparently it's allowed to switch these style on after creation */
3129 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3130 ok(hwnd != NULL, "failed to create a listview window\n");
3131 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3132 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3133 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
3134 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3135 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3136 DestroyWindow(hwnd);
3138 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3139 ok(hwnd != NULL, "failed to create a listview window\n");
3140 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3141 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3142 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
3143 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3144 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
3145 DestroyWindow(hwnd);
3148 static void test_norecompute(void)
3150 static CHAR testA[] = "test";
3151 CHAR buff[10];
3152 LVITEMA item;
3153 HWND hwnd;
3154 DWORD res;
3156 /* self containing control */
3157 hwnd = create_listview_control(LVS_REPORT);
3158 ok(hwnd != NULL, "failed to create a listview window\n");
3159 memset(&item, 0, sizeof(item));
3160 item.mask = LVIF_TEXT | LVIF_STATE;
3161 item.iItem = 0;
3162 item.stateMask = LVIS_SELECTED;
3163 item.state = LVIS_SELECTED;
3164 item.pszText = testA;
3165 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3166 expect(0, res);
3167 /* retrieve with LVIF_NORECOMPUTE */
3168 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3169 item.iItem = 0;
3170 item.pszText = buff;
3171 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3172 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3173 expect(TRUE, res);
3174 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
3176 item.mask = LVIF_TEXT;
3177 item.iItem = 1;
3178 item.pszText = LPSTR_TEXTCALLBACK;
3179 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3180 expect(1, res);
3182 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3183 item.iItem = 1;
3184 item.pszText = buff;
3185 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3187 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3188 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3189 expect(TRUE, res);
3190 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
3191 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
3192 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
3194 DestroyWindow(hwnd);
3196 /* LVS_OWNERDATA */
3197 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3198 ok(hwnd != NULL, "failed to create a listview window\n");
3200 item.mask = LVIF_STATE;
3201 item.stateMask = LVIS_SELECTED;
3202 item.state = LVIS_SELECTED;
3203 item.iItem = 0;
3204 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
3205 expect(0, res);
3207 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3208 item.iItem = 0;
3209 item.pszText = buff;
3210 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3211 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3212 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3213 expect(TRUE, res);
3214 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
3215 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
3216 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
3218 DestroyWindow(hwnd);
3221 static void test_nosortheader(void)
3223 HWND hwnd, header;
3224 LONG_PTR style;
3226 hwnd = create_listview_control(LVS_REPORT);
3227 ok(hwnd != NULL, "failed to create a listview window\n");
3229 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3230 ok(IsWindow(header), "header expected\n");
3232 style = GetWindowLongPtr(header, GWL_STYLE);
3233 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
3235 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3236 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
3237 /* HDS_BUTTONS retained */
3238 style = GetWindowLongPtr(header, GWL_STYLE);
3239 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
3241 DestroyWindow(hwnd);
3243 /* create with LVS_NOSORTHEADER */
3244 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
3245 ok(hwnd != NULL, "failed to create a listview window\n");
3247 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3248 ok(IsWindow(header), "header expected\n");
3250 style = GetWindowLongPtr(header, GWL_STYLE);
3251 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3253 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3254 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
3255 /* not changed here */
3256 style = GetWindowLongPtr(header, GWL_STYLE);
3257 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3259 DestroyWindow(hwnd);
3262 static void test_setredraw(void)
3264 HWND hwnd;
3265 DWORD_PTR style;
3266 DWORD ret;
3267 HDC hdc;
3268 RECT rect;
3270 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3271 ok(hwnd != NULL, "failed to create a listview window\n");
3273 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3274 ListView seems to handle it internally without DefWinProc */
3276 /* default value first */
3277 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3278 expect(0, ret);
3279 /* disable */
3280 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3281 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3282 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3283 expect(0, ret);
3284 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3285 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3286 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3287 expect(0, ret);
3289 /* check update rect after redrawing */
3290 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3291 expect(0, ret);
3292 InvalidateRect(hwnd, NULL, FALSE);
3293 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
3294 rect.right = rect.bottom = 1;
3295 GetUpdateRect(hwnd, &rect, FALSE);
3296 expect(0, rect.right);
3297 expect(0, rect.bottom);
3299 /* WM_ERASEBKGND */
3300 hdc = GetWindowDC(hwndparent);
3301 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3302 expect(TRUE, ret);
3303 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3304 expect(0, ret);
3305 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3306 expect(TRUE, ret);
3307 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3308 expect(0, ret);
3309 ReleaseDC(hwndparent, hdc);
3311 /* check notification messages to show that repainting is disabled */
3312 ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
3313 expect(TRUE, ret);
3314 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3315 expect(0, ret);
3316 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3318 InvalidateRect(hwnd, NULL, TRUE);
3319 UpdateWindow(hwnd);
3320 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3321 "redraw after WM_SETREDRAW (FALSE)", FALSE);
3323 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3324 expect(TRUE, ret);
3325 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3326 InvalidateRect(hwnd, NULL, TRUE);
3327 UpdateWindow(hwnd);
3328 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3329 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3331 /* message isn't forwarded to header */
3332 subclass_header(hwnd);
3333 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3334 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3335 expect(0, ret);
3336 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3337 "WM_SETREDRAW: not forwarded to header", FALSE);
3339 DestroyWindow(hwnd);
3342 static void test_hittest(void)
3344 HWND hwnd;
3345 DWORD r;
3346 RECT bounds;
3347 LVITEMA item;
3348 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3349 POINT pos;
3350 INT x, y, i;
3351 WORD vert;
3352 HIMAGELIST himl, himl2;
3353 HBITMAP hbmp;
3355 hwnd = create_listview_control(LVS_REPORT);
3356 ok(hwnd != NULL, "failed to create a listview window\n");
3358 /* LVS_REPORT with a single subitem (2 columns) */
3359 insert_column(hwnd, 0);
3360 insert_column(hwnd, 1);
3361 insert_item(hwnd, 0);
3363 item.iSubItem = 0;
3364 /* the only purpose of that line is to be as long as a half item rect */
3365 item.pszText = text;
3366 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
3367 expect(TRUE, r);
3369 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3370 expect(TRUE, r);
3371 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3372 expect(TRUE, r);
3374 memset(&bounds, 0, sizeof(bounds));
3375 bounds.left = LVIR_BOUNDS;
3376 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3377 expect(1, r);
3378 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3379 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3380 r = SendMessage(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3381 vert = HIWORD(r);
3382 ok(bounds.bottom - bounds.top == vert,
3383 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3384 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3385 expect(TRUE, r);
3387 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3389 /* outside columns by x position - valid is [0, 199] */
3390 x = -1;
3391 y = pos.y + (bounds.bottom - bounds.top) / 2;
3392 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3393 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3395 x = pos.x + 50; /* column half width */
3396 y = pos.y + (bounds.bottom - bounds.top) / 2;
3397 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3398 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3399 x = pos.x + 150; /* outside column */
3400 y = pos.y + (bounds.bottom - bounds.top) / 2;
3401 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3402 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3403 y = (bounds.bottom - bounds.top) / 2;
3404 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3405 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3406 /* outside possible client rectangle (to right) */
3407 x = pos.x + 500;
3408 y = pos.y + (bounds.bottom - bounds.top) / 2;
3409 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3410 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3411 y = (bounds.bottom - bounds.top) / 2;
3412 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3413 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3414 /* subitem returned with -1 item too */
3415 x = pos.x + 150;
3416 y = bounds.top - vert;
3417 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3418 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3419 /* return values appear to underflow with negative indices */
3420 i = -2;
3421 y = y - vert;
3422 while (i > -10) {
3423 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3424 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3425 y = y - vert;
3426 i--;
3428 /* parent client area is 100x100 by default */
3429 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3430 x = pos.x + 150; /* outside column */
3431 y = pos.y + (bounds.bottom - bounds.top) / 2;
3432 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3433 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3434 y = (bounds.bottom - bounds.top) / 2;
3435 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3436 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3437 /* the same with LVS_EX_FULLROWSELECT */
3438 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3439 x = pos.x + 150; /* outside column */
3440 y = pos.y + (bounds.bottom - bounds.top) / 2;
3441 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3442 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3443 y = (bounds.bottom - bounds.top) / 2;
3444 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3445 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3446 x = pos.x + 150; /* outside column */
3447 y = pos.y + (bounds.bottom - bounds.top) / 2;
3448 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3449 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3450 y = (bounds.bottom - bounds.top) / 2;
3451 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3452 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3453 /* outside possible client rectangle (to right) */
3454 x = pos.x + 500;
3455 y = pos.y + (bounds.bottom - bounds.top) / 2;
3456 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3457 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3458 y = (bounds.bottom - bounds.top) / 2;
3459 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3460 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3461 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3462 himl = ImageList_Create(16, 16, 0, 4, 4);
3463 ok(himl != NULL, "failed to create imagelist\n");
3464 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3465 ok(hbmp != NULL, "failed to create bitmap\n");
3466 r = ImageList_Add(himl, hbmp, 0);
3467 ok(r == 0, "should be zero\n");
3468 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3469 ok(hbmp != NULL, "failed to create bitmap\n");
3470 r = ImageList_Add(himl, hbmp, 0);
3471 ok(r == 1, "should be one\n");
3473 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3474 expect(0, r);
3476 item.mask = LVIF_IMAGE;
3477 item.iImage = 0;
3478 item.iItem = 0;
3479 item.iSubItem = 0;
3480 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3481 expect(TRUE, r);
3482 /* on state icon */
3483 x = pos.x + 8;
3484 y = pos.y + (bounds.bottom - bounds.top) / 2;
3485 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3486 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3487 y = (bounds.bottom - bounds.top) / 2;
3488 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3490 /* state icons indices are 1 based, check with valid index */
3491 item.mask = LVIF_STATE;
3492 item.state = INDEXTOSTATEIMAGEMASK(1);
3493 item.stateMask = LVIS_STATEIMAGEMASK;
3494 item.iItem = 0;
3495 item.iSubItem = 0;
3496 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3497 expect(TRUE, r);
3498 /* on state icon */
3499 x = pos.x + 8;
3500 y = pos.y + (bounds.bottom - bounds.top) / 2;
3501 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3502 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3503 y = (bounds.bottom - bounds.top) / 2;
3504 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3506 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3507 ok(himl2 == himl, "should return handle\n");
3509 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3510 expect(0, r);
3511 /* on item icon */
3512 x = pos.x + 8;
3513 y = pos.y + (bounds.bottom - bounds.top) / 2;
3514 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3515 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3516 y = (bounds.bottom - bounds.top) / 2;
3517 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3519 DestroyWindow(hwnd);
3522 static void test_getviewrect(void)
3524 HWND hwnd;
3525 DWORD r;
3526 RECT rect;
3527 LVITEMA item;
3529 hwnd = create_listview_control(LVS_REPORT);
3530 ok(hwnd != NULL, "failed to create a listview window\n");
3532 /* empty */
3533 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3534 expect(TRUE, r);
3536 insert_column(hwnd, 0);
3537 insert_column(hwnd, 1);
3539 memset(&item, 0, sizeof(item));
3540 item.iItem = 0;
3541 item.iSubItem = 0;
3542 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3544 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3545 expect(TRUE, r);
3546 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3547 expect(TRUE, r);
3549 rect.left = rect.right = rect.top = rect.bottom = -1;
3550 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3551 expect(TRUE, r);
3552 /* left is set to (2e31-1) - XP SP2 */
3553 expect(0, rect.right);
3554 expect(0, rect.top);
3555 expect(0, rect.bottom);
3557 /* switch to LVS_ICON */
3558 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3560 rect.left = rect.right = rect.top = rect.bottom = -1;
3561 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3562 expect(TRUE, r);
3563 expect(0, rect.left);
3564 expect(0, rect.top);
3565 /* precise value differs for 2k, XP and Vista */
3566 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3567 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3569 DestroyWindow(hwnd);
3572 static void test_getitemposition(void)
3574 HWND hwnd, header;
3575 DWORD r;
3576 POINT pt;
3577 RECT rect;
3579 hwnd = create_listview_control(LVS_REPORT);
3580 ok(hwnd != NULL, "failed to create a listview window\n");
3581 header = subclass_header(hwnd);
3583 /* LVS_REPORT, single item, no columns added */
3584 insert_item(hwnd, 0);
3586 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3588 pt.x = pt.y = -1;
3589 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3590 expect(TRUE, r);
3591 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3593 /* LVS_REPORT, single item, single column */
3594 insert_column(hwnd, 0);
3596 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3598 pt.x = pt.y = -1;
3599 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3600 expect(TRUE, r);
3601 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3603 memset(&rect, 0, sizeof(rect));
3604 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3605 /* some padding? */
3606 expect(2, pt.x);
3607 /* offset by header height */
3608 expect(rect.bottom - rect.top, pt.y);
3610 DestroyWindow(hwnd);
3613 static void test_columnscreation(void)
3615 HWND hwnd, header;
3616 DWORD r;
3618 hwnd = create_listview_control(LVS_REPORT);
3619 ok(hwnd != NULL, "failed to create a listview window\n");
3621 insert_item(hwnd, 0);
3623 /* headers columns aren't created automatically */
3624 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3625 ok(IsWindow(header), "Expected header handle\n");
3626 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3627 expect(0, r);
3629 DestroyWindow(hwnd);
3632 static void test_getitemrect(void)
3634 HWND hwnd;
3635 HIMAGELIST himl, himl_ret;
3636 HBITMAP hbm;
3637 RECT rect;
3638 DWORD r;
3639 LVITEMA item;
3640 LVCOLUMNA col;
3641 INT order[2];
3642 POINT pt;
3643 HDC hdc;
3645 /* rectangle isn't empty for empty text items */
3646 hwnd = create_listview_control(LVS_LIST);
3647 memset(&item, 0, sizeof(item));
3648 item.mask = 0;
3649 item.iItem = 0;
3650 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3651 expect(0, r);
3652 rect.left = LVIR_LABEL;
3653 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3654 expect(TRUE, r);
3655 expect(0, rect.left);
3656 expect(0, rect.top);
3657 hdc = GetDC(hwnd);
3658 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, rect.right);
3659 ReleaseDC(hwnd, hdc);
3660 DestroyWindow(hwnd);
3662 hwnd = create_listview_control(LVS_REPORT);
3663 ok(hwnd != NULL, "failed to create a listview window\n");
3665 /* empty item */
3666 memset(&item, 0, sizeof(item));
3667 item.iItem = 0;
3668 item.iSubItem = 0;
3669 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3670 expect(0, r);
3672 rect.left = LVIR_BOUNDS;
3673 rect.right = rect.top = rect.bottom = -1;
3674 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3675 expect(TRUE, r);
3677 /* zero width rectangle with no padding */
3678 expect(0, rect.left);
3679 expect(0, rect.right);
3681 insert_column(hwnd, 0);
3682 insert_column(hwnd, 1);
3684 col.mask = LVCF_WIDTH;
3685 col.cx = 50;
3686 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3687 expect(TRUE, r);
3689 col.mask = LVCF_WIDTH;
3690 col.cx = 100;
3691 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3692 expect(TRUE, r);
3694 rect.left = LVIR_BOUNDS;
3695 rect.right = rect.top = rect.bottom = -1;
3696 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3697 expect(TRUE, r);
3699 /* still no left padding */
3700 expect(0, rect.left);
3701 expect(150, rect.right);
3703 rect.left = LVIR_SELECTBOUNDS;
3704 rect.right = rect.top = rect.bottom = -1;
3705 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3706 expect(TRUE, r);
3707 /* padding */
3708 expect(2, rect.left);
3710 rect.left = LVIR_LABEL;
3711 rect.right = rect.top = rect.bottom = -1;
3712 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3713 expect(TRUE, r);
3714 /* padding, column width */
3715 expect(2, rect.left);
3716 expect(50, rect.right);
3718 /* no icons attached */
3719 rect.left = LVIR_ICON;
3720 rect.right = rect.top = rect.bottom = -1;
3721 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3722 expect(TRUE, r);
3723 /* padding */
3724 expect(2, rect.left);
3725 expect(2, rect.right);
3727 /* change order */
3728 order[0] = 1; order[1] = 0;
3729 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3730 expect(TRUE, r);
3731 pt.x = -1;
3732 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3733 expect(TRUE, r);
3734 /* 1 indexed column width + padding */
3735 expect(102, pt.x);
3736 /* rect is at zero too */
3737 rect.left = LVIR_BOUNDS;
3738 rect.right = rect.top = rect.bottom = -1;
3739 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3740 expect(TRUE, r);
3741 expect(0, rect.left);
3742 /* just width sum */
3743 expect(150, rect.right);
3745 rect.left = LVIR_SELECTBOUNDS;
3746 rect.right = rect.top = rect.bottom = -1;
3747 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3748 expect(TRUE, r);
3749 /* column width + padding */
3750 expect(102, rect.left);
3752 /* back to initial order */
3753 order[0] = 0; order[1] = 1;
3754 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3755 expect(TRUE, r);
3757 /* state icons */
3758 himl = ImageList_Create(16, 16, 0, 2, 2);
3759 ok(himl != NULL, "failed to create imagelist\n");
3760 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3761 ok(hbm != NULL, "failed to create bitmap\n");
3762 r = ImageList_Add(himl, hbm, 0);
3763 expect(0, r);
3764 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3765 ok(hbm != NULL, "failed to create bitmap\n");
3766 r = ImageList_Add(himl, hbm, 0);
3767 expect(1, r);
3769 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3770 expect(0, r);
3772 item.mask = LVIF_STATE;
3773 item.state = INDEXTOSTATEIMAGEMASK(1);
3774 item.stateMask = LVIS_STATEIMAGEMASK;
3775 item.iItem = 0;
3776 item.iSubItem = 0;
3777 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3778 expect(TRUE, r);
3780 /* icon bounds */
3781 rect.left = LVIR_ICON;
3782 rect.right = rect.top = rect.bottom = -1;
3783 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3784 expect(TRUE, r);
3785 /* padding + stateicon width */
3786 expect(18, rect.left);
3787 expect(18, rect.right);
3788 /* label bounds */
3789 rect.left = LVIR_LABEL;
3790 rect.right = rect.top = rect.bottom = -1;
3791 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3792 expect(TRUE, r);
3793 /* padding + stateicon width -> column width */
3794 expect(18, rect.left);
3795 expect(50, rect.right);
3797 himl_ret = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3798 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
3800 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3801 expect(0, r);
3803 item.mask = LVIF_STATE | LVIF_IMAGE;
3804 item.iImage = 1;
3805 item.state = 0;
3806 item.stateMask = ~0;
3807 item.iItem = 0;
3808 item.iSubItem = 0;
3809 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3810 expect(TRUE, r);
3812 /* icon bounds */
3813 rect.left = LVIR_ICON;
3814 rect.right = rect.top = rect.bottom = -1;
3815 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3816 expect(TRUE, r);
3817 /* padding, icon width */
3818 expect(2, rect.left);
3819 expect(18, rect.right);
3820 /* label bounds */
3821 rect.left = LVIR_LABEL;
3822 rect.right = rect.top = rect.bottom = -1;
3823 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3824 expect(TRUE, r);
3825 /* padding + icon width -> column width */
3826 expect(18, rect.left);
3827 expect(50, rect.right);
3829 /* select bounds */
3830 rect.left = LVIR_SELECTBOUNDS;
3831 rect.right = rect.top = rect.bottom = -1;
3832 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3833 expect(TRUE, r);
3834 /* padding, column width */
3835 expect(2, rect.left);
3836 expect(50, rect.right);
3838 /* try with indentation */
3839 item.mask = LVIF_INDENT;
3840 item.iIndent = 1;
3841 item.iItem = 0;
3842 item.iSubItem = 0;
3843 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3844 expect(TRUE, r);
3846 /* bounds */
3847 rect.left = LVIR_BOUNDS;
3848 rect.right = rect.top = rect.bottom = -1;
3849 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3850 expect(TRUE, r);
3851 /* padding + 1 icon width, column width */
3852 expect(0, rect.left);
3853 expect(150, rect.right);
3855 /* select bounds */
3856 rect.left = LVIR_SELECTBOUNDS;
3857 rect.right = rect.top = rect.bottom = -1;
3858 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3859 expect(TRUE, r);
3860 /* padding + 1 icon width, column width */
3861 expect(2 + 16, rect.left);
3862 expect(50, rect.right);
3864 /* label bounds */
3865 rect.left = LVIR_LABEL;
3866 rect.right = rect.top = rect.bottom = -1;
3867 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3868 expect(TRUE, r);
3869 /* padding + 2 icon widths, column width */
3870 expect(2 + 16*2, rect.left);
3871 expect(50, rect.right);
3873 /* icon bounds */
3874 rect.left = LVIR_ICON;
3875 rect.right = rect.top = rect.bottom = -1;
3876 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3877 expect(TRUE, r);
3878 /* padding + 1 icon width indentation, icon width */
3879 expect(2 + 16, rect.left);
3880 expect(34, rect.right);
3882 DestroyWindow(hwnd);
3885 static void test_editbox(void)
3887 static CHAR testitemA[] = "testitem";
3888 static CHAR testitem1A[] = "testitem_quitelongname";
3889 static CHAR testitem2A[] = "testITEM_quitelongname";
3890 static CHAR buffer[25];
3891 HWND hwnd, hwndedit, hwndedit2, header;
3892 LVITEMA item;
3893 INT r;
3895 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3896 ok(hwnd != NULL, "failed to create a listview window\n");
3898 insert_column(hwnd, 0);
3900 memset(&item, 0, sizeof(item));
3901 item.mask = LVIF_TEXT;
3902 item.pszText = testitemA;
3903 item.iItem = 0;
3904 item.iSubItem = 0;
3905 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3906 expect(0, r);
3908 /* test notifications without edit created */
3909 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3910 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
3911 expect(0, r);
3912 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3913 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
3914 /* same thing but with valid window */
3915 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
3916 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
3917 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3918 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
3919 expect(0, r);
3920 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3921 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
3922 DestroyWindow(hwndedit);
3924 /* setting focus is necessary */
3925 SetFocus(hwnd);
3926 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3927 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3929 /* test children Z-order after Edit box created */
3930 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3931 ok(IsWindow(header), "Expected header to be created\n");
3932 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3933 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3935 /* modify initial string */
3936 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3937 expect(TRUE, r);
3939 /* edit window is resized and repositioned,
3940 check again for Z-order - it should be preserved */
3941 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3942 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3944 /* return focus to listview */
3945 SetFocus(hwnd);
3947 memset(&item, 0, sizeof(item));
3948 item.mask = LVIF_TEXT;
3949 item.pszText = buffer;
3950 item.cchTextMax = sizeof(buffer);
3951 item.iItem = 0;
3952 item.iSubItem = 0;
3953 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3954 expect(TRUE, r);
3956 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3958 /* send LVM_EDITLABEL on already created edit */
3959 SetFocus(hwnd);
3960 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3961 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3962 /* focus will be set to edit */
3963 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3964 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3965 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3967 /* creating label disabled when control isn't focused */
3968 SetFocus(0);
3969 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3970 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3972 /* check EN_KILLFOCUS handling */
3973 memset(&item, 0, sizeof(item));
3974 item.pszText = testitemA;
3975 item.iItem = 0;
3976 item.iSubItem = 0;
3977 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3978 expect(TRUE, r);
3980 SetFocus(hwnd);
3981 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3982 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3983 /* modify edit and notify control that it lost focus */
3984 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3985 expect(TRUE, r);
3986 g_editbox_disp_info.item.pszText = NULL;
3987 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3988 expect(0, r);
3989 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
3991 memset(&item, 0, sizeof(item));
3992 item.pszText = buffer;
3993 item.cchTextMax = sizeof(buffer);
3994 item.iItem = 0;
3995 item.iSubItem = 0;
3996 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3997 expect(lstrlen(item.pszText), r);
3998 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3999 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4001 /* change item name to differ in casing only */
4002 SetFocus(hwnd);
4003 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4004 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4005 /* modify edit and notify control that it lost focus */
4006 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
4007 expect(TRUE, r);
4008 g_editbox_disp_info.item.pszText = NULL;
4009 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4010 expect(0, r);
4011 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
4013 memset(&item, 0, sizeof(item));
4014 item.pszText = buffer;
4015 item.cchTextMax = sizeof(buffer);
4016 item.iItem = 0;
4017 item.iSubItem = 0;
4018 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4019 expect(lstrlen(item.pszText), r);
4020 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
4021 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4023 /* end edit without saving */
4024 SetFocus(hwnd);
4025 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4026 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4027 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
4028 expect(0, r);
4029 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4030 "edit box - end edit, no change, escape", TRUE);
4031 /* end edit with saving */
4032 SetFocus(hwnd);
4033 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4034 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4035 r = SendMessage(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
4036 expect(0, r);
4037 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4038 "edit box - end edit, no change, return", TRUE);
4040 memset(&item, 0, sizeof(item));
4041 item.pszText = buffer;
4042 item.cchTextMax = sizeof(buffer);
4043 item.iItem = 0;
4044 item.iSubItem = 0;
4045 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4046 expect(lstrlen(item.pszText), r);
4047 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
4049 /* LVM_EDITLABEL with -1 destroys current edit */
4050 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
4051 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4052 /* no edit present */
4053 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
4054 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4055 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4056 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4057 /* edit present */
4058 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4059 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
4060 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4061 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4062 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4063 /* check another negative value */
4064 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4065 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4066 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4067 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
4068 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4069 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4070 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4071 /* and value greater than max item index */
4072 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4073 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4074 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4075 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
4076 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
4077 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4078 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4079 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4081 /* messaging tests */
4082 SetFocus(hwnd);
4083 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4084 blockEdit = FALSE;
4085 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4086 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4087 /* testing only sizing messages */
4088 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
4089 "edit box create - sizing", FALSE);
4091 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4092 SetFocus(hwnd);
4093 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4094 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4095 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4096 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4097 expect(0, r);
4098 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4099 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
4101 DestroyWindow(hwnd);
4104 static void test_notifyformat(void)
4106 HWND hwnd, header;
4107 DWORD r;
4109 hwnd = create_listview_control(LVS_REPORT);
4110 ok(hwnd != NULL, "failed to create a listview window\n");
4112 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4113 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4114 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4115 expect(0, r);
4116 SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4117 /* set */
4118 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
4119 expect(0, r);
4120 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4121 if (r == 1)
4123 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
4124 expect(1, r);
4125 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4126 expect(0, r);
4128 else
4130 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4131 DestroyWindow(hwnd);
4132 return;
4135 DestroyWindow(hwnd);
4137 /* test failure in parent WM_NOTIFYFORMAT */
4138 notifyFormat = 0;
4139 hwnd = create_listview_control(LVS_REPORT);
4140 ok(hwnd != NULL, "failed to create a listview window\n");
4141 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4142 ok(IsWindow(header), "expected header to be created\n");
4143 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4144 expect(0, r);
4145 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4146 ok( r == 1, "Expected 1, got %d\n", r );
4147 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4148 ok(r != 0, "Expected valid format\n");
4150 notifyFormat = NFR_UNICODE;
4151 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4152 expect(NFR_UNICODE, r);
4153 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4154 expect(1, r);
4155 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4156 ok( r == 1, "Expected 1, got %d\n", r );
4158 notifyFormat = NFR_ANSI;
4159 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4160 expect(NFR_ANSI, r);
4161 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4162 expect(0, r);
4163 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4164 ok( r == 1, "Expected 1, got %d\n", r );
4166 DestroyWindow(hwnd);
4168 hwndparentW = create_parent_window(TRUE);
4169 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
4170 if (!IsWindow(hwndparentW)) return;
4172 notifyFormat = -1;
4173 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4174 ok(hwnd != NULL, "failed to create a listview window\n");
4175 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4176 ok(IsWindow(header), "expected header to be created\n");
4177 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4178 expect(1, r);
4179 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4180 expect(1, r);
4181 DestroyWindow(hwnd);
4182 /* receiving error code defaulting to ansi */
4183 notifyFormat = 0;
4184 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4185 ok(hwnd != NULL, "failed to create a listview window\n");
4186 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4187 ok(IsWindow(header), "expected header to be created\n");
4188 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4189 expect(0, r);
4190 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4191 expect(1, r);
4192 DestroyWindow(hwnd);
4193 /* receiving ansi code from unicode window, use it */
4194 notifyFormat = NFR_ANSI;
4195 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4196 ok(hwnd != NULL, "failed to create a listview window\n");
4197 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4198 ok(IsWindow(header), "expected header to be created\n");
4199 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4200 expect(0, r);
4201 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4202 expect(1, r);
4203 DestroyWindow(hwnd);
4204 /* unicode listview with ansi parent window */
4205 notifyFormat = -1;
4206 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4207 ok(hwnd != NULL, "failed to create a listview window\n");
4208 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4209 ok(IsWindow(header), "expected header to be created\n");
4210 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4211 expect(0, r);
4212 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4213 expect(1, r);
4214 DestroyWindow(hwnd);
4215 /* unicode listview with ansi parent window, return error code */
4216 notifyFormat = 0;
4217 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4218 ok(hwnd != NULL, "failed to create a listview window\n");
4219 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4220 ok(IsWindow(header), "expected header to be created\n");
4221 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4222 expect(0, r);
4223 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
4224 expect(1, r);
4225 DestroyWindow(hwnd);
4227 DestroyWindow(hwndparentW);
4230 static void test_indentation(void)
4232 HWND hwnd;
4233 LVITEMA item;
4234 DWORD r;
4236 hwnd = create_listview_control(LVS_REPORT);
4237 ok(hwnd != NULL, "failed to create a listview window\n");
4239 memset(&item, 0, sizeof(item));
4240 item.mask = LVIF_INDENT;
4241 item.iItem = 0;
4242 item.iIndent = I_INDENTCALLBACK;
4243 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4244 expect(0, r);
4246 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4248 item.iItem = 0;
4249 item.mask = LVIF_INDENT;
4250 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
4251 expect(TRUE, r);
4253 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
4254 "get indent dispinfo", FALSE);
4256 DestroyWindow(hwnd);
4259 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
4261 return 0;
4264 static BOOL is_below_comctl_5(void)
4266 HWND hwnd;
4267 BOOL ret;
4269 hwnd = create_listview_control(LVS_REPORT);
4270 ok(hwnd != NULL, "failed to create a listview window\n");
4271 insert_item(hwnd, 0);
4273 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
4275 DestroyWindow(hwnd);
4277 return !ret;
4280 static void test_get_set_view(void)
4282 HWND hwnd;
4283 DWORD ret;
4284 DWORD_PTR style;
4286 /* test style->view mapping */
4287 hwnd = create_listview_control(LVS_REPORT);
4288 ok(hwnd != NULL, "failed to create a listview window\n");
4290 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4291 expect(LV_VIEW_DETAILS, ret);
4293 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4294 /* LVS_ICON == 0 */
4295 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4296 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4297 expect(LV_VIEW_ICON, ret);
4299 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4300 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4301 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4302 expect(LV_VIEW_SMALLICON, ret);
4304 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4305 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4306 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4307 expect(LV_VIEW_LIST, ret);
4309 /* switching view doesn't touch window style */
4310 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4311 expect(1, ret);
4312 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4313 ok(style & LVS_LIST, "Expected style to be preserved\n");
4314 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4315 expect(1, ret);
4316 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4317 ok(style & LVS_LIST, "Expected style to be preserved\n");
4318 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4319 expect(1, ret);
4320 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4321 ok(style & LVS_LIST, "Expected style to be preserved\n");
4323 DestroyWindow(hwnd);
4326 static void test_canceleditlabel(void)
4328 HWND hwnd, hwndedit;
4329 DWORD ret;
4330 CHAR buff[10];
4331 LVITEMA itema;
4332 static CHAR test[] = "test";
4333 static const CHAR test1[] = "test1";
4335 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4336 ok(hwnd != NULL, "failed to create a listview window\n");
4338 insert_item(hwnd, 0);
4340 /* try without edit created */
4341 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4342 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4343 expect(TRUE, ret);
4344 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4345 "cancel edit label without edit", FALSE);
4347 /* cancel without data change */
4348 SetFocus(hwnd);
4349 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4350 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4351 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4352 expect(TRUE, ret);
4353 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4355 /* cancel after data change */
4356 memset(&itema, 0, sizeof(itema));
4357 itema.pszText = test;
4358 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4359 expect(TRUE, ret);
4360 SetFocus(hwnd);
4361 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4362 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4363 ret = SetWindowText(hwndedit, test1);
4364 expect(1, ret);
4365 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4366 expect(TRUE, ret);
4367 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4368 memset(&itema, 0, sizeof(itema));
4369 itema.pszText = buff;
4370 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4371 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
4372 expect(5, ret);
4373 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4375 DestroyWindow(hwnd);
4378 static void test_mapidindex(void)
4380 HWND hwnd;
4381 INT ret;
4383 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4384 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4385 ok(hwnd != NULL, "failed to create a listview window\n");
4386 insert_item(hwnd, 0);
4387 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4388 expect(-1, ret);
4389 DestroyWindow(hwnd);
4391 hwnd = create_listview_control(LVS_REPORT);
4392 ok(hwnd != NULL, "failed to create a listview window\n");
4394 /* LVM_MAPINDEXTOID with invalid index */
4395 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4396 expect(-1, ret);
4398 insert_item(hwnd, 0);
4399 insert_item(hwnd, 1);
4401 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
4402 expect(-1, ret);
4403 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
4404 expect(-1, ret);
4406 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4407 expect(0, ret);
4408 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4409 expect(1, ret);
4410 /* remove 0 indexed item, id retained */
4411 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
4412 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4413 expect(1, ret);
4414 /* new id starts from previous value */
4415 insert_item(hwnd, 1);
4416 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4417 expect(2, ret);
4419 /* get index by id */
4420 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4421 expect(-1, ret);
4422 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4423 expect(-1, ret);
4424 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4425 expect(0, ret);
4426 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4427 expect(1, ret);
4429 DestroyWindow(hwnd);
4432 static void test_getitemspacing(void)
4434 HWND hwnd;
4435 DWORD ret;
4436 INT cx, cy;
4437 HIMAGELIST himl;
4438 HBITMAP hbmp;
4439 LVITEMA itema;
4441 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4442 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4444 /* LVS_ICON */
4445 hwnd = create_listview_control(LVS_ICON);
4446 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4447 todo_wine {
4448 expect(cx, LOWORD(ret));
4449 expect(cy, HIWORD(ret));
4451 /* now try with icons */
4452 himl = ImageList_Create(40, 40, 0, 4, 4);
4453 ok(himl != NULL, "failed to create imagelist\n");
4454 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4455 ok(hbmp != NULL, "failed to create bitmap\n");
4456 ret = ImageList_Add(himl, hbmp, 0);
4457 expect(0, ret);
4458 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4459 expect(0, ret);
4461 itema.mask = LVIF_IMAGE;
4462 itema.iImage = 0;
4463 itema.iItem = 0;
4464 itema.iSubItem = 0;
4465 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4466 expect(0, ret);
4467 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4468 todo_wine {
4469 /* spacing + icon size returned */
4470 expect(cx + 40, LOWORD(ret));
4471 expect(cy + 40, HIWORD(ret));
4473 DestroyWindow(hwnd);
4474 /* LVS_SMALLICON */
4475 hwnd = create_listview_control(LVS_SMALLICON);
4476 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4477 todo_wine {
4478 expect(cx, LOWORD(ret));
4479 expect(cy, HIWORD(ret));
4481 DestroyWindow(hwnd);
4482 /* LVS_REPORT */
4483 hwnd = create_listview_control(LVS_REPORT);
4484 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4485 todo_wine {
4486 expect(cx, LOWORD(ret));
4487 expect(cy, HIWORD(ret));
4489 DestroyWindow(hwnd);
4490 /* LVS_LIST */
4491 hwnd = create_listview_control(LVS_LIST);
4492 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4493 todo_wine {
4494 expect(cx, LOWORD(ret));
4495 expect(cy, HIWORD(ret));
4497 DestroyWindow(hwnd);
4500 static void test_getcolumnwidth(void)
4502 HWND hwnd;
4503 INT ret;
4504 DWORD_PTR style;
4505 LVCOLUMNA col;
4506 LVITEMA itema;
4507 HDC hdc;
4509 /* default column width */
4510 hwnd = create_listview_control(LVS_ICON);
4511 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4512 expect(0, ret);
4513 style = GetWindowLong(hwnd, GWL_STYLE);
4514 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
4515 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4516 todo_wine expect(8, ret);
4517 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
4518 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
4519 col.mask = 0;
4520 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4521 expect(0, ret);
4522 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4523 expect(10, ret);
4524 DestroyWindow(hwnd);
4526 /* default column width with item added */
4527 hwnd = create_listview_control(LVS_LIST);
4528 memset(&itema, 0, sizeof(itema));
4529 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4530 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4531 hdc = GetDC(hwnd);
4532 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, ret);
4533 ReleaseDC(hwnd, hdc);
4534 DestroyWindow(hwnd);
4537 static void test_scrollnotify(void)
4539 HWND hwnd;
4540 DWORD ret;
4542 hwnd = create_listview_control(LVS_REPORT);
4544 insert_column(hwnd, 0);
4545 insert_column(hwnd, 1);
4546 insert_item(hwnd, 0);
4548 /* make it scrollable - resize */
4549 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4550 expect(TRUE, ret);
4551 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4552 expect(TRUE, ret);
4554 /* try with dummy call */
4555 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4556 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
4557 expect(TRUE, ret);
4558 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4559 "scroll notify 1", TRUE);
4561 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4562 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
4563 expect(TRUE, ret);
4564 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4565 "scroll notify 2", TRUE);
4567 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4568 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4569 expect(TRUE, ret);
4570 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4571 "scroll notify 3", TRUE);
4573 DestroyWindow(hwnd);
4576 static void test_LVS_EX_TRANSPARENTBKGND(void)
4578 HWND hwnd;
4579 DWORD ret;
4580 HDC hdc;
4582 hwnd = create_listview_control(LVS_REPORT);
4584 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4585 expect(TRUE, ret);
4587 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4588 LVS_EX_TRANSPARENTBKGND);
4590 ret = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
4591 if (ret != CLR_NONE)
4593 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4594 DestroyWindow(hwnd);
4595 return;
4598 /* try to set some back color and check this style bit */
4599 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4600 expect(TRUE, ret);
4601 ret = SendMessage(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4602 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4604 /* now test what this style actually does */
4605 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4606 LVS_EX_TRANSPARENTBKGND);
4608 hdc = GetWindowDC(hwndparent);
4610 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4611 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4612 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4613 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4615 ReleaseDC(hwndparent, hdc);
4617 DestroyWindow(hwnd);
4620 static void test_approximate_viewrect(void)
4622 HWND hwnd;
4623 DWORD ret;
4624 HIMAGELIST himl;
4625 HBITMAP hbmp;
4626 LVITEMA itema;
4627 static CHAR test[] = "abracadabra, a very long item label";
4629 hwnd = create_listview_control(LVS_ICON);
4630 himl = ImageList_Create(40, 40, 0, 4, 4);
4631 ok(himl != NULL, "failed to create imagelist\n");
4632 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4633 ok(hbmp != NULL, "failed to create bitmap\n");
4634 ret = ImageList_Add(himl, hbmp, 0);
4635 expect(0, ret);
4636 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4637 expect(0, ret);
4639 itema.mask = LVIF_IMAGE;
4640 itema.iImage = 0;
4641 itema.iItem = 0;
4642 itema.iSubItem = 0;
4643 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4644 expect(0, ret);
4646 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4647 if (ret == 0)
4649 /* version 4.0 */
4650 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4651 return;
4654 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4655 expect(MAKELONG(77,827), ret);
4657 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4658 ok(ret != 0, "got 0\n");
4660 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4661 expect(MAKELONG(102,302), ret);
4663 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4664 expect(MAKELONG(52,52), ret);
4666 itema.pszText = test;
4667 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4668 expect(TRUE, ret);
4669 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4670 expect(MAKELONG(52,52), ret);
4672 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4673 expect(MAKELONG(52,2), ret);
4674 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4675 expect(MAKELONG(52,52), ret);
4676 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4677 expect(MAKELONG(102,52), ret);
4678 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4679 expect(MAKELONG(102,102), ret);
4680 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4681 expect(MAKELONG(102,102), ret);
4682 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4683 expect(MAKELONG(102,152), ret);
4684 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4685 expect(MAKELONG(102,152), ret);
4686 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4687 expect(MAKELONG(152,152), ret);
4689 DestroyWindow(hwnd);
4692 static void test_finditem(void)
4694 LVFINDINFOA fi;
4695 static char f[5];
4696 HWND hwnd;
4697 INT r;
4699 hwnd = create_listview_control(LVS_REPORT);
4700 insert_item(hwnd, 0);
4702 memset(&fi, 0, sizeof(fi));
4704 /* full string search, inserted text was "foo" */
4705 strcpy(f, "foo");
4706 fi.flags = LVFI_STRING;
4707 fi.psz = f;
4708 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4709 expect(0, r);
4710 /* partial string search, inserted text was "foo" */
4711 strcpy(f, "fo");
4712 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4713 fi.psz = f;
4714 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4715 expect(0, r);
4716 /* partial string search, part after start char */
4717 strcpy(f, "oo");
4718 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4719 fi.psz = f;
4720 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4721 expect(-1, r);
4723 /* try with LVFI_SUBSTRING */
4724 strcpy(f, "fo");
4725 fi.flags = LVFI_SUBSTRING;
4726 fi.psz = f;
4727 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4728 if (r == -1)
4730 win_skip("LVFI_SUBSTRING not supported\n");
4731 DestroyWindow(hwnd);
4732 return;
4734 expect(0, r);
4735 strcpy(f, "f");
4736 fi.flags = LVFI_SUBSTRING;
4737 fi.psz = f;
4738 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4739 expect(0, r);
4740 strcpy(f, "o");
4741 fi.flags = LVFI_SUBSTRING;
4742 fi.psz = f;
4743 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4744 expect(-1, r);
4746 strcpy(f, "f");
4747 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
4748 fi.psz = f;
4749 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4750 expect(0, r);
4752 DestroyWindow(hwnd);
4755 static void test_LVS_EX_HEADERINALLVIEWS(void)
4757 HWND hwnd, header;
4758 DWORD style;
4760 hwnd = create_listview_control(LVS_ICON);
4762 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4763 LVS_EX_HEADERINALLVIEWS);
4765 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4766 if (!IsWindow(header))
4768 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4769 DestroyWindow(hwnd);
4770 return;
4773 /* LVS_NOCOLUMNHEADER works as before */
4774 style = GetWindowLongA(hwnd, GWL_STYLE);
4775 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
4776 style = GetWindowLongA(header, GWL_STYLE);
4777 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
4778 style = GetWindowLongA(hwnd, GWL_STYLE);
4779 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
4780 style = GetWindowLongA(header, GWL_STYLE);
4781 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
4783 /* try to remove style */
4784 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
4785 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4786 ok(IsWindow(header), "Expected header to be created\n");
4787 style = GetWindowLongA(header, GWL_STYLE);
4788 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
4790 DestroyWindow(hwnd);
4792 /* check other styles */
4793 hwnd = create_listview_control(LVS_LIST);
4794 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4795 LVS_EX_HEADERINALLVIEWS);
4796 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4797 ok(IsWindow(header), "Expected header to be created\n");
4798 DestroyWindow(hwnd);
4800 hwnd = create_listview_control(LVS_SMALLICON);
4801 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4802 LVS_EX_HEADERINALLVIEWS);
4803 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4804 ok(IsWindow(header), "Expected header to be created\n");
4805 DestroyWindow(hwnd);
4807 hwnd = create_listview_control(LVS_REPORT);
4808 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4809 LVS_EX_HEADERINALLVIEWS);
4810 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4811 ok(IsWindow(header), "Expected header to be created\n");
4812 DestroyWindow(hwnd);
4815 static void test_hover(void)
4817 HWND hwnd;
4818 DWORD r;
4820 hwnd = create_listview_control(LVS_ICON);
4822 /* test WM_MOUSEHOVER forwarding */
4823 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4824 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4825 expect(0, r);
4826 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
4827 g_block_hover = TRUE;
4828 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4829 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4830 expect(0, r);
4831 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
4832 g_block_hover = FALSE;
4834 r = SendMessage(hwnd, LVM_SETHOVERTIME, 0, 500);
4835 expect(HOVER_DEFAULT, r);
4836 r = SendMessage(hwnd, LVM_GETHOVERTIME, 0, 0);
4837 expect(500, r);
4839 DestroyWindow(hwnd);
4842 static void test_destroynotify(void)
4844 HWND hwnd;
4846 hwnd = create_listview_control(LVS_REPORT);
4847 ok(hwnd != NULL, "failed to create listview window\n");
4849 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4850 DestroyWindow(hwnd);
4851 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
4854 static void test_header_notification(void)
4856 static char textA[] = "newtext";
4857 HWND list, header;
4858 HDITEMA item;
4859 NMHEADER nmh;
4860 LVCOLUMNA col;
4861 DWORD ret;
4862 BOOL r;
4864 list = create_listview_control(LVS_REPORT);
4865 ok(list != NULL, "failed to create listview window\n");
4867 memset(&col, 0, sizeof(col));
4868 col.mask = LVCF_WIDTH;
4869 col.cx = 100;
4870 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4871 expect(0, ret);
4873 /* check list parent notification after header item changed,
4874 this test should be placed before header subclassing to avoid
4875 Listview -> Header messages to be logged */
4876 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4878 col.mask = LVCF_TEXT;
4879 col.pszText = textA;
4880 r = SendMessage(list, LVM_SETCOLUMNA, 0, (LPARAM)&col);
4881 expect(TRUE, r);
4883 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_changed_seq,
4884 "header notify, listview", FALSE);
4885 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4886 "header notify, parent", FALSE);
4888 header = subclass_header(list);
4890 ret = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
4891 expect(1, ret);
4893 memset(&item, 0, sizeof(item));
4894 item.mask = HDI_WIDTH;
4895 ret = SendMessage(header, HDM_GETITEMA, 0, (LPARAM)&item);
4896 expect(1, ret);
4897 expect(100, item.cxy);
4899 nmh.hdr.hwndFrom = header;
4900 nmh.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
4901 nmh.hdr.code = HDN_ITEMCHANGEDA;
4902 nmh.iItem = 0;
4903 nmh.iButton = 0;
4904 item.mask = HDI_WIDTH;
4905 item.cxy = 50;
4906 nmh.pitem = &item;
4907 ret = SendMessage(list, WM_NOTIFY, 0, (LPARAM)&nmh);
4908 expect(0, ret);
4910 DestroyWindow(list);
4913 static void test_createdragimage(void)
4915 HIMAGELIST himl;
4916 POINT pt;
4917 HWND list;
4919 list = create_listview_control(LVS_ICON);
4920 ok(list != NULL, "failed to create listview window\n");
4922 insert_item(list, 0);
4924 /* NULL point */
4925 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
4926 ok(himl == NULL, "got %p\n", himl);
4928 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
4929 ok(himl != NULL, "got %p\n", himl);
4930 ImageList_Destroy(himl);
4932 DestroyWindow(list);
4935 static void test_dispinfo(void)
4937 static const char testA[] = "TEST";
4938 WCHAR buff[10];
4939 LVITEMA item;
4940 HWND hwnd;
4941 DWORD ret;
4943 hwnd = create_listview_control(LVS_ICON);
4944 ok(hwnd != NULL, "failed to create listview window\n");
4946 insert_item(hwnd, 0);
4948 memset(&item, 0, sizeof(item));
4949 item.pszText = LPSTR_TEXTCALLBACKA;
4950 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4951 expect(1, ret);
4953 g_disp_A_to_W = TRUE;
4954 item.pszText = (char*)buff;
4955 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
4956 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4957 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
4958 g_disp_A_to_W = FALSE;
4960 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
4961 "got %s, expected %s\n", item.pszText, testA);
4963 DestroyWindow(hwnd);
4966 static void test_LVM_SETITEMTEXT(void)
4968 static char testA[] = "TEST";
4969 LVITEMA item;
4970 HWND hwnd;
4971 DWORD ret;
4973 hwnd = create_listview_control(LVS_ICON);
4974 ok(hwnd != NULL, "failed to create listview window\n");
4976 insert_item(hwnd, 0);
4978 /* null item pointer */
4979 ret = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, 0);
4980 expect(FALSE, ret);
4982 ret = SendMessage(hwnd, LVM_SETITEMTEXTW, 0, 0);
4983 expect(FALSE, ret);
4985 /* index out of bounds */
4986 item.pszText = testA;
4987 item.cchTextMax = 0; /* ignored */
4988 item.iSubItem = 0;
4990 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 1, (LPARAM)&item);
4991 expect(FALSE, ret);
4993 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, -1, (LPARAM)&item);
4994 expect(FALSE, ret);
4996 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4997 expect(TRUE, ret);
4999 DestroyWindow(hwnd);
5002 START_TEST(listview)
5004 HMODULE hComctl32;
5005 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
5007 ULONG_PTR ctx_cookie;
5008 HANDLE hCtx;
5009 HWND hwnd;
5011 hComctl32 = GetModuleHandleA("comctl32.dll");
5012 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
5013 if (pInitCommonControlsEx)
5015 INITCOMMONCONTROLSEX iccex;
5016 iccex.dwSize = sizeof(iccex);
5017 iccex.dwICC = ICC_LISTVIEW_CLASSES;
5018 pInitCommonControlsEx(&iccex);
5020 else
5021 InitCommonControls();
5023 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
5025 hwndparent = create_parent_window(FALSE);
5026 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5028 g_is_below_5 = is_below_comctl_5();
5030 test_header_notification();
5031 test_images();
5032 test_checkboxes();
5033 test_items();
5034 test_create();
5035 test_redraw();
5036 test_customdraw();
5037 test_icon_spacing();
5038 test_color();
5039 test_item_count();
5040 test_item_position();
5041 test_columns();
5042 test_getorigin();
5043 test_multiselect();
5044 test_getitemrect();
5045 test_subitem_rect();
5046 test_sorting();
5047 test_ownerdata();
5048 test_norecompute();
5049 test_nosortheader();
5050 test_setredraw();
5051 test_hittest();
5052 test_getviewrect();
5053 test_getitemposition();
5054 test_columnscreation();
5055 test_editbox();
5056 test_notifyformat();
5057 test_indentation();
5058 test_getitemspacing();
5059 test_getcolumnwidth();
5060 test_approximate_viewrect();
5061 test_finditem();
5062 test_hover();
5063 test_destroynotify();
5064 test_createdragimage();
5065 test_dispinfo();
5066 test_LVM_SETITEMTEXT();
5068 if (!load_v6_module(&ctx_cookie, &hCtx))
5070 DestroyWindow(hwndparent);
5071 return;
5074 /* this is a XP SP3 failure workaround */
5075 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
5076 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
5077 0, 0, 100, 100,
5078 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
5079 if (!IsWindow(hwnd))
5081 win_skip("FIXME: failed to create ListView window.\n");
5082 unload_v6_module(ctx_cookie, hCtx);
5083 DestroyWindow(hwndparent);
5084 return;
5086 else
5087 DestroyWindow(hwnd);
5089 /* comctl32 version 6 tests start here */
5090 test_get_set_view();
5091 test_canceleditlabel();
5092 test_mapidindex();
5093 test_scrollnotify();
5094 test_LVS_EX_TRANSPARENTBKGND();
5095 test_LVS_EX_HEADERINALLVIEWS();
5097 unload_v6_module(ctx_cookie, hCtx);
5099 DestroyWindow(hwndparent);