comctl32/listview: Make edit box handle available from LVN_ENDLABELEDIT notification.
[wine/multimedia.git] / dlls / comctl32 / tests / listview.c
blob3bf3dcbb9c1458e979f0dbddd218c58bf57893de
1 /*
2 * ListView tests
4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009-2011 Nikolay Sivov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdio.h>
24 #include <windows.h>
25 #include <commctrl.h>
27 #include "wine/test.h"
28 #include "v6util.h"
29 #include "msg.h"
31 #define PARENT_SEQ_INDEX 0
32 #define PARENT_FULL_SEQ_INDEX 1
33 #define LISTVIEW_SEQ_INDEX 2
34 #define EDITBOX_SEQ_INDEX 3
35 #define COMBINED_SEQ_INDEX 4
36 #define NUM_MSG_SEQUENCES 5
38 #define LISTVIEW_ID 0
39 #define HEADER_ID 1
41 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
42 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
43 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
45 static const WCHAR testparentclassW[] =
46 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
48 static HWND hwndparent, hwndparentW;
49 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
50 static BOOL blockEdit;
51 /* return nonzero on NM_HOVER */
52 static BOOL g_block_hover;
53 /* dumps LVN_ITEMCHANGED message data */
54 static BOOL g_dump_itemchanged;
55 /* format reported to control:
56 -1 falls to defproc, anything else returned */
57 static INT notifyFormat;
58 /* indicates we're running < 5.80 version */
59 static BOOL g_is_below_5;
60 /* item data passed to LVN_GETDISPINFOA */
61 static LVITEMA g_itema;
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 LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
310 static LONG defwndproc_counter = 0;
311 LRESULT ret;
312 struct message msg;
314 msg.message = message;
315 msg.flags = sent|wparam|lparam;
316 if (defwndproc_counter) msg.flags |= defwinproc;
317 msg.wParam = wParam;
318 msg.lParam = lParam;
319 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
321 /* log system messages, except for painting */
322 if (message < WM_USER &&
323 message != WM_PAINT &&
324 message != WM_ERASEBKGND &&
325 message != WM_NCPAINT &&
326 message != WM_NCHITTEST &&
327 message != WM_GETTEXT &&
328 message != WM_GETICON &&
329 message != WM_DEVICECHANGE)
331 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
333 add_message(sequences, PARENT_SEQ_INDEX, &msg);
334 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
336 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
338 switch (message)
340 case WM_NOTIFY:
342 switch (((NMHDR*)lParam)->code)
344 case LVN_BEGINLABELEDIT:
346 HWND edit = NULL;
348 /* subclass edit box */
349 if (!blockEdit)
350 edit = subclass_editbox(((NMHDR*)lParam)->hwndFrom);
352 if (edit)
354 INT len = SendMessageA(edit, EM_GETLIMITTEXT, 0, 0);
355 ok(len == 259 || broken(len == 260) /* includes NULL in NT4 */,
356 "text limit %d, expected 259\n", len);
359 return blockEdit;
361 case LVN_ENDLABELEDIT:
363 HWND edit;
365 /* always accept new item text */
366 NMLVDISPINFO *di = (NMLVDISPINFO*)lParam;
367 g_editbox_disp_info = *di;
368 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText);
370 /* edit control still available from this notification */
371 edit = (HWND)SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETEDITCONTROL, 0, 0);
372 ok(IsWindow(edit), "expected valid edit control handle\n");
374 return TRUE;
376 case LVN_BEGINSCROLL:
377 case LVN_ENDSCROLL:
379 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
381 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
382 "BEGIN" : "END", pScroll->dx, pScroll->dy);
384 break;
385 case LVN_ITEMCHANGED:
386 if (g_dump_itemchanged)
388 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
389 trace("LVN_ITEMCHANGED: item=%d,new=%x,old=%x,changed=%x\n",
390 nmlv->iItem, nmlv->uNewState, nmlv->uOldState, nmlv->uChanged);
392 break;
393 case LVN_GETDISPINFOA:
395 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
396 g_itema = dispinfo->item;
398 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
400 static const WCHAR testW[] = {'T','E','S','T',0};
401 dispinfo->hdr.code = LVN_GETDISPINFOW;
402 memcpy(dispinfo->item.pszText, testW, sizeof(testW));
405 /* test control buffer size for text, 10 used to mask cases when control
406 is using caller buffer to process LVM_GETITEM for example */
407 if (dispinfo->item.mask & LVIF_TEXT && dispinfo->item.cchTextMax > 10)
408 ok(dispinfo->item.cchTextMax == 260 ||
409 broken(dispinfo->item.cchTextMax == 264) /* NT4 reports aligned size */,
410 "buffer size %d\n", dispinfo->item.cchTextMax);
412 break;
413 case NM_HOVER:
414 if (g_block_hover) return 1;
415 break;
417 break;
419 case WM_NOTIFYFORMAT:
421 /* force to return format */
422 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
423 break;
427 defwndproc_counter++;
428 ret = DefWindowProcA(hwnd, message, wParam, lParam);
429 defwndproc_counter--;
431 return ret;
434 static BOOL register_parent_wnd_class(BOOL Unicode)
436 WNDCLASSA clsA;
437 WNDCLASSW clsW;
439 if (Unicode)
441 clsW.style = 0;
442 clsW.lpfnWndProc = parent_wnd_proc;
443 clsW.cbClsExtra = 0;
444 clsW.cbWndExtra = 0;
445 clsW.hInstance = GetModuleHandleW(NULL);
446 clsW.hIcon = 0;
447 clsW.hCursor = LoadCursorA(0, IDC_ARROW);
448 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
449 clsW.lpszMenuName = NULL;
450 clsW.lpszClassName = testparentclassW;
452 else
454 clsA.style = 0;
455 clsA.lpfnWndProc = parent_wnd_proc;
456 clsA.cbClsExtra = 0;
457 clsA.cbWndExtra = 0;
458 clsA.hInstance = GetModuleHandleA(NULL);
459 clsA.hIcon = 0;
460 clsA.hCursor = LoadCursorA(0, IDC_ARROW);
461 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
462 clsA.lpszMenuName = NULL;
463 clsA.lpszClassName = "Listview test parent class";
466 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
469 static HWND create_parent_window(BOOL Unicode)
471 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
472 HWND hwnd;
474 if (!register_parent_wnd_class(Unicode))
475 return NULL;
477 blockEdit = FALSE;
478 notifyFormat = -1;
480 if (Unicode)
481 hwnd = CreateWindowExW(0, testparentclassW, nameW,
482 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
483 WS_MAXIMIZEBOX | WS_VISIBLE,
484 0, 0, 100, 100,
485 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
486 else
487 hwnd = CreateWindowExA(0, "Listview test parent class",
488 "Listview test parent window",
489 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
490 WS_MAXIMIZEBOX | WS_VISIBLE,
491 0, 0, 100, 100,
492 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
493 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
494 return hwnd;
497 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
499 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
500 static LONG defwndproc_counter = 0;
501 LRESULT ret;
502 struct message msg;
504 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
506 /* some debug output for style changing */
507 if ((message == WM_STYLECHANGING ||
508 message == WM_STYLECHANGED) && lParam)
510 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
511 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
514 msg.message = message;
515 msg.flags = sent|wparam|lparam;
516 if (defwndproc_counter) msg.flags |= defwinproc;
517 msg.wParam = wParam;
518 msg.lParam = lParam;
519 msg.id = LISTVIEW_ID;
520 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
521 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
523 defwndproc_counter++;
524 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
525 defwndproc_counter--;
526 return ret;
529 static HWND create_listview_control(DWORD style)
531 WNDPROC oldproc;
532 HWND hwnd;
533 RECT rect;
535 GetClientRect(hwndparent, &rect);
536 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
537 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
538 0, 0, rect.right, rect.bottom,
539 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
540 ok(hwnd != NULL, "gle=%d\n", GetLastError());
542 if (!hwnd) return NULL;
544 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
545 (LONG_PTR)listview_subclass_proc);
546 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
548 return hwnd;
551 /* unicode listview window with specified parent */
552 static HWND create_listview_controlW(DWORD style, HWND parent)
554 WNDPROC oldproc;
555 HWND hwnd;
556 RECT rect;
557 static const WCHAR nameW[] = {'f','o','o',0};
559 GetClientRect(parent, &rect);
560 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
561 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
562 0, 0, rect.right, rect.bottom,
563 parent, NULL, GetModuleHandleW(NULL), NULL);
564 ok(hwnd != NULL, "gle=%d\n", GetLastError());
566 if (!hwnd) return NULL;
568 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
569 (LONG_PTR)listview_subclass_proc);
570 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
572 return hwnd;
575 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
577 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
578 static LONG defwndproc_counter = 0;
579 LRESULT ret;
580 struct message msg;
582 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
584 msg.message = message;
585 msg.flags = sent|wparam|lparam;
586 if (defwndproc_counter) msg.flags |= defwinproc;
587 msg.wParam = wParam;
588 msg.lParam = lParam;
589 msg.id = HEADER_ID;
590 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
592 defwndproc_counter++;
593 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
594 defwndproc_counter--;
595 return ret;
598 static HWND subclass_header(HWND hwndListview)
600 WNDPROC oldproc;
601 HWND hwnd;
603 hwnd = ListView_GetHeader(hwndListview);
604 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
605 (LONG_PTR)header_subclass_proc);
606 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
608 return hwnd;
611 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
613 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
614 static LONG defwndproc_counter = 0;
615 LRESULT ret;
616 struct message msg;
618 msg.message = message;
619 msg.flags = sent|wparam|lparam;
620 if (defwndproc_counter) msg.flags |= defwinproc;
621 msg.wParam = wParam;
622 msg.lParam = lParam;
624 /* all we need is sizing */
625 if (message == WM_WINDOWPOSCHANGING ||
626 message == WM_NCCALCSIZE ||
627 message == WM_WINDOWPOSCHANGED ||
628 message == WM_MOVE ||
629 message == WM_SIZE)
631 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
634 defwndproc_counter++;
635 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
636 defwndproc_counter--;
637 return ret;
640 static HWND subclass_editbox(HWND hwndListview)
642 WNDPROC oldproc;
643 HWND hwnd;
645 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
646 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
647 (LONG_PTR)editbox_subclass_proc);
648 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
650 return hwnd;
653 /* Performs a single LVM_HITTEST test */
654 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
655 BOOL todo_item, BOOL todo_flags, int line)
657 LVHITTESTINFO lpht;
658 DWORD ret;
660 lpht.pt.x = x;
661 lpht.pt.y = y;
662 lpht.iSubItem = 10;
664 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
666 if (todo_item)
668 todo_wine
670 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
671 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
672 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
675 else
677 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
678 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
679 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
682 if (todo_flags)
684 todo_wine
685 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
687 else if (broken_flags)
688 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
689 "Expected flags %x, got %x\n", flags, lpht.flags);
690 else
691 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
694 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
696 /* Performs a single LVM_SUBITEMHITTEST test */
697 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
698 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
700 LVHITTESTINFO lpht;
701 DWORD ret;
703 lpht.pt.x = x;
704 lpht.pt.y = y;
706 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
708 if (todo_item)
710 todo_wine
712 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
713 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
716 else
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 if (todo_subitem)
724 todo_wine
725 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
727 else
728 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
730 if (todo_flags)
732 todo_wine
733 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
735 else
736 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
739 #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__)
741 static void test_images(void)
743 HWND hwnd;
744 DWORD r;
745 LVITEM item;
746 HIMAGELIST himl;
747 HBITMAP hbmp;
748 RECT r1, r2;
749 static CHAR hello[] = "hello";
751 himl = ImageList_Create(40, 40, 0, 4, 4);
752 ok(himl != NULL, "failed to create imagelist\n");
754 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
755 ok(hbmp != NULL, "failed to create bitmap\n");
757 r = ImageList_Add(himl, hbmp, 0);
758 ok(r == 0, "should be zero\n");
760 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
761 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
762 ok(hwnd != NULL, "failed to create listview window\n");
764 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
765 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
767 ok(r == 0, "should return zero\n");
769 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
770 ok(r == 0, "should return zero\n");
772 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
773 /* returns dimensions */
775 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
776 ok(r == 0, "should be zero items\n");
778 item.mask = LVIF_IMAGE | LVIF_TEXT;
779 item.iItem = 0;
780 item.iSubItem = 1;
781 item.iImage = 0;
782 item.pszText = 0;
783 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
784 ok(r == -1, "should fail\n");
786 item.iSubItem = 0;
787 item.pszText = hello;
788 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
789 ok(r == 0, "should not fail\n");
791 memset(&r1, 0, sizeof r1);
792 r1.left = LVIR_ICON;
793 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
794 expect(1, r);
796 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
797 ok(r == TRUE, "should not fail\n");
799 item.iSubItem = 0;
800 item.pszText = hello;
801 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
802 ok(r == 0, "should not fail\n");
804 memset(&r2, 0, sizeof r2);
805 r2.left = LVIR_ICON;
806 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
807 expect(1, r);
809 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
811 DestroyWindow(hwnd);
814 static void test_checkboxes(void)
816 HWND hwnd;
817 LVITEMA item;
818 DWORD r;
819 static CHAR text[] = "Text",
820 text2[] = "Text2",
821 text3[] = "Text3";
823 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
824 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
825 ok(hwnd != NULL, "failed to create listview window\n");
827 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
828 item.mask = LVIF_TEXT | LVIF_STATE;
829 item.stateMask = 0xffff;
830 item.state = 0xfccc;
831 item.iItem = 0;
832 item.iSubItem = 0;
833 item.pszText = text;
834 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
835 ok(r == 0, "ret %d\n", r);
837 item.iItem = 0;
838 item.mask = LVIF_STATE;
839 item.stateMask = 0xffff;
840 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
841 expect(1, r);
842 ok(item.state == 0xfccc, "state %x\n", item.state);
844 /* Don't set LVIF_STATE */
845 item.mask = LVIF_TEXT;
846 item.stateMask = 0xffff;
847 item.state = 0xfccc;
848 item.iItem = 1;
849 item.iSubItem = 0;
850 item.pszText = text;
851 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
852 ok(r == 1, "ret %d\n", r);
854 item.iItem = 1;
855 item.mask = LVIF_STATE;
856 item.stateMask = 0xffff;
857 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
858 expect(1, r);
859 ok(item.state == 0, "state %x\n", item.state);
861 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
862 ok(r == 0, "should return zero\n");
864 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
865 item.iItem = 0;
866 item.mask = LVIF_STATE;
867 item.stateMask = 0xffff;
868 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
869 expect(1, r);
870 if (item.state != 0x1ccc)
872 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
873 DestroyWindow(hwnd);
874 return;
877 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
878 item.iItem = 2;
879 item.mask = LVIF_TEXT;
880 item.state = 0;
881 item.pszText = text2;
882 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
883 ok(r == 2, "ret %d\n", r);
885 item.iItem = 2;
886 item.mask = LVIF_STATE;
887 item.stateMask = 0xffff;
888 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
889 expect(1, r);
890 ok(item.state == 0x1000, "state %x\n", item.state);
892 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
893 item.iItem = 3;
894 item.mask = LVIF_TEXT | LVIF_STATE;
895 item.stateMask = 0xffff;
896 item.state = 0x2aaa;
897 item.pszText = text3;
898 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
899 ok(r == 3, "ret %d\n", r);
901 item.iItem = 3;
902 item.mask = LVIF_STATE;
903 item.stateMask = 0xffff;
904 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
905 expect(1, r);
906 ok(item.state == 0x1aaa, "state %x\n", item.state);
908 /* Set an item's state to checked */
909 item.iItem = 3;
910 item.mask = LVIF_STATE;
911 item.stateMask = 0xf000;
912 item.state = 0x2000;
913 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
914 expect(1, r);
916 item.iItem = 3;
917 item.mask = LVIF_STATE;
918 item.stateMask = 0xffff;
919 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
920 expect(1, r);
921 ok(item.state == 0x2aaa, "state %x\n", item.state);
923 /* Check that only the bits we asked for are returned,
924 * and that all the others are set to zero
926 item.iItem = 3;
927 item.mask = LVIF_STATE;
928 item.stateMask = 0xf000;
929 item.state = 0xffff;
930 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
931 expect(1, r);
932 ok(item.state == 0x2000, "state %x\n", item.state);
934 /* Set the style again and check that doesn't change an item's state */
935 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
936 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
938 item.iItem = 3;
939 item.mask = LVIF_STATE;
940 item.stateMask = 0xffff;
941 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
942 expect(1, r);
943 ok(item.state == 0x2aaa, "state %x\n", item.state);
945 /* Unsetting the checkbox extended style doesn't change an item's state */
946 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
947 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
949 item.iItem = 3;
950 item.mask = LVIF_STATE;
951 item.stateMask = 0xffff;
952 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
953 expect(1, r);
954 ok(item.state == 0x2aaa, "state %x\n", item.state);
956 /* Now setting the style again will change an item's state */
957 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
958 ok(r == 0, "ret %x\n", r);
960 item.iItem = 3;
961 item.mask = LVIF_STATE;
962 item.stateMask = 0xffff;
963 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
964 expect(1, r);
965 ok(item.state == 0x1aaa, "state %x\n", item.state);
967 /* Toggle checkbox tests (bug 9934) */
968 memset (&item, 0xcc, sizeof(item));
969 item.mask = LVIF_STATE;
970 item.iItem = 3;
971 item.iSubItem = 0;
972 item.state = LVIS_FOCUSED;
973 item.stateMask = LVIS_FOCUSED;
974 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
975 expect(1, r);
977 item.iItem = 3;
978 item.mask = LVIF_STATE;
979 item.stateMask = 0xffff;
980 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
981 expect(1, r);
982 ok(item.state == 0x1aab, "state %x\n", item.state);
984 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
985 expect(0, r);
986 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
987 expect(0, r);
989 item.iItem = 3;
990 item.mask = LVIF_STATE;
991 item.stateMask = 0xffff;
992 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
993 expect(1, r);
994 ok(item.state == 0x2aab, "state %x\n", item.state);
996 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
997 expect(0, r);
998 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
999 expect(0, r);
1001 item.iItem = 3;
1002 item.mask = LVIF_STATE;
1003 item.stateMask = 0xffff;
1004 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1005 ok(item.state == 0x1aab, "state %x\n", item.state);
1007 DestroyWindow(hwnd);
1010 static void insert_column(HWND hwnd, int idx)
1012 LVCOLUMN column;
1013 DWORD rc;
1015 memset(&column, 0xcc, sizeof(column));
1016 column.mask = LVCF_SUBITEM;
1017 column.iSubItem = idx;
1019 rc = ListView_InsertColumn(hwnd, idx, &column);
1020 expect(idx, rc);
1023 static void insert_item(HWND hwnd, int idx)
1025 static CHAR text[] = "foo";
1027 LVITEMA item;
1028 DWORD rc;
1030 memset(&item, 0xcc, sizeof (item));
1031 item.mask = LVIF_TEXT;
1032 item.iItem = idx;
1033 item.iSubItem = 0;
1034 item.pszText = text;
1036 rc = ListView_InsertItem(hwnd, &item);
1037 expect(idx, rc);
1040 static void test_items(void)
1042 const LPARAM lparamTest = 0x42;
1043 static CHAR text[] = "Text";
1044 char buffA[5];
1045 HWND hwnd;
1046 LVITEMA item;
1047 DWORD r;
1049 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1050 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1051 ok(hwnd != NULL, "failed to create listview window\n");
1054 * Test setting/getting item params
1057 /* Set up two columns */
1058 insert_column(hwnd, 0);
1059 insert_column(hwnd, 1);
1061 /* LVIS_SELECTED with zero stateMask */
1062 /* set */
1063 memset (&item, 0, sizeof (item));
1064 item.mask = LVIF_STATE;
1065 item.state = LVIS_SELECTED;
1066 item.stateMask = 0;
1067 item.iItem = 0;
1068 item.iSubItem = 0;
1069 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1070 ok(r == 0, "ret %d\n", r);
1071 /* get */
1072 memset (&item, 0xcc, sizeof (item));
1073 item.mask = LVIF_STATE;
1074 item.stateMask = LVIS_SELECTED;
1075 item.state = 0;
1076 item.iItem = 0;
1077 item.iSubItem = 0;
1078 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1079 ok(r == 1, "ret %d\n", r);
1080 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1081 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1083 /* LVIS_SELECTED with zero stateMask */
1084 /* set */
1085 memset (&item, 0, sizeof (item));
1086 item.mask = LVIF_STATE;
1087 item.state = LVIS_FOCUSED;
1088 item.stateMask = 0;
1089 item.iItem = 0;
1090 item.iSubItem = 0;
1091 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1092 ok(r == 0, "ret %d\n", r);
1093 /* get */
1094 memset (&item, 0xcc, sizeof (item));
1095 item.mask = LVIF_STATE;
1096 item.stateMask = LVIS_FOCUSED;
1097 item.state = 0;
1098 item.iItem = 0;
1099 item.iSubItem = 0;
1100 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1101 ok(r == 1, "ret %d\n", r);
1102 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1103 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1105 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1106 /* set */
1107 memset (&item, 0, sizeof (item));
1108 item.mask = LVIF_STATE;
1109 item.state = LVIS_CUT;
1110 item.stateMask = LVIS_FOCUSED;
1111 item.iItem = 0;
1112 item.iSubItem = 0;
1113 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1114 ok(r == 0, "ret %d\n", r);
1115 /* get */
1116 memset (&item, 0xcc, sizeof (item));
1117 item.mask = LVIF_STATE;
1118 item.stateMask = LVIS_CUT;
1119 item.state = 0;
1120 item.iItem = 0;
1121 item.iSubItem = 0;
1122 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1123 ok(r == 1, "ret %d\n", r);
1124 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1125 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
1127 /* Insert an item with just a param */
1128 memset (&item, 0xcc, sizeof (item));
1129 item.mask = LVIF_PARAM;
1130 item.iItem = 0;
1131 item.iSubItem = 0;
1132 item.lParam = lparamTest;
1133 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1134 ok(r == 0, "ret %d\n", r);
1136 /* Test getting of the param */
1137 memset (&item, 0xcc, sizeof (item));
1138 item.mask = LVIF_PARAM;
1139 item.iItem = 0;
1140 item.iSubItem = 0;
1141 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1142 ok(r == 1, "ret %d\n", r);
1143 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1145 /* Set up a subitem */
1146 memset (&item, 0xcc, sizeof (item));
1147 item.mask = LVIF_TEXT;
1148 item.iItem = 0;
1149 item.iSubItem = 1;
1150 item.pszText = text;
1151 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1152 ok(r == 1, "ret %d\n", r);
1154 item.mask = LVIF_TEXT;
1155 item.iItem = 0;
1156 item.iSubItem = 1;
1157 item.pszText = buffA;
1158 item.cchTextMax = sizeof(buffA);
1159 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1160 ok(r == 1, "ret %d\n", r);
1161 ok(!memcmp(item.pszText, text, sizeof(text)), "got text %s, expected %s\n", item.pszText, text);
1163 /* set up with extra flag */
1164 /* 1. reset subitem text */
1165 item.mask = LVIF_TEXT;
1166 item.iItem = 0;
1167 item.iSubItem = 1;
1168 item.pszText = NULL;
1169 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1170 ok(r == 1, "ret %d\n", r);
1172 item.mask = LVIF_TEXT;
1173 item.iItem = 0;
1174 item.iSubItem = 1;
1175 item.pszText = buffA;
1176 buffA[0] = 'a';
1177 item.cchTextMax = sizeof(buffA);
1178 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1179 ok(r == 1, "ret %d\n", r);
1180 ok(item.pszText[0] == 0, "got %p\n", item.pszText);
1182 /* 2. set new text with extra flag specified */
1183 item.mask = LVIF_TEXT | LVIF_DI_SETITEM;
1184 item.iItem = 0;
1185 item.iSubItem = 1;
1186 item.pszText = text;
1187 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1188 ok(r == 1 || broken(r == 0) /* NT4 */, "ret %d\n", r);
1190 if (r == 1)
1192 item.mask = LVIF_TEXT;
1193 item.iItem = 0;
1194 item.iSubItem = 1;
1195 item.pszText = buffA;
1196 buffA[0] = 'a';
1197 item.cchTextMax = sizeof(buffA);
1198 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1199 ok(r == 1, "ret %d\n", r);
1200 ok(!memcmp(item.pszText, text, sizeof(text)), "got %s, expected %s\n", item.pszText, text);
1203 /* Query param from subitem: returns main item param */
1204 memset (&item, 0xcc, sizeof (item));
1205 item.mask = LVIF_PARAM;
1206 item.iItem = 0;
1207 item.iSubItem = 1;
1208 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1209 ok(r == 1, "ret %d\n", r);
1210 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1212 /* Set up param on first subitem: no effect */
1213 memset (&item, 0xcc, sizeof (item));
1214 item.mask = LVIF_PARAM;
1215 item.iItem = 0;
1216 item.iSubItem = 1;
1217 item.lParam = lparamTest+1;
1218 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1219 ok(r == 0, "ret %d\n", r);
1221 /* Query param from subitem again: should still return main item param */
1222 memset (&item, 0xcc, sizeof (item));
1223 item.mask = LVIF_PARAM;
1224 item.iItem = 0;
1225 item.iSubItem = 1;
1226 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1227 ok(r == 1, "ret %d\n", r);
1228 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1230 /**** Some tests of state highlighting ****/
1231 memset (&item, 0xcc, sizeof (item));
1232 item.mask = LVIF_STATE;
1233 item.iItem = 0;
1234 item.iSubItem = 0;
1235 item.state = LVIS_SELECTED;
1236 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1237 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1238 ok(r == 1, "ret %d\n", r);
1239 item.iSubItem = 1;
1240 item.state = LVIS_DROPHILITED;
1241 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
1242 ok(r == 1, "ret %d\n", r);
1244 memset (&item, 0xcc, sizeof (item));
1245 item.mask = LVIF_STATE;
1246 item.iItem = 0;
1247 item.iSubItem = 0;
1248 item.stateMask = -1;
1249 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1250 ok(r == 1, "ret %d\n", r);
1251 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1252 item.iSubItem = 1;
1253 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1254 ok(r == 1, "ret %d\n", r);
1255 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1257 /* some notnull but meaningless masks */
1258 memset (&item, 0, sizeof(item));
1259 item.mask = LVIF_NORECOMPUTE;
1260 item.iItem = 0;
1261 item.iSubItem = 0;
1262 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1263 ok(r == 1, "ret %d\n", r);
1264 memset (&item, 0, sizeof(item));
1265 item.mask = LVIF_DI_SETITEM;
1266 item.iItem = 0;
1267 item.iSubItem = 0;
1268 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1269 ok(r == 1, "ret %d\n", r);
1271 /* set text to callback value already having it */
1272 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1273 expect(TRUE, r);
1274 memset (&item, 0, sizeof (item));
1275 item.mask = LVIF_TEXT;
1276 item.pszText = LPSTR_TEXTCALLBACK;
1277 item.iItem = 0;
1278 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1279 ok(r == 0, "ret %d\n", r);
1280 memset (&item, 0, sizeof (item));
1282 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1284 item.pszText = LPSTR_TEXTCALLBACK;
1285 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1286 expect(TRUE, r);
1288 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1289 "check callback text comparison rule", FALSE);
1291 DestroyWindow(hwnd);
1294 static void test_columns(void)
1296 HWND hwnd;
1297 LVCOLUMNA column;
1298 LVITEMA item;
1299 INT order[2];
1300 CHAR buff[5];
1301 DWORD rc;
1303 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1304 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1305 ok(hwnd != NULL, "failed to create listview window\n");
1307 /* Add a column with no mask */
1308 memset(&column, 0xcc, sizeof(column));
1309 column.mask = 0;
1310 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1311 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1313 /* Check its width */
1314 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1315 ok(rc == 10 || broken(rc == 0) /* win9x */,
1316 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1318 DestroyWindow(hwnd);
1320 /* LVM_GETCOLUMNORDERARRAY */
1321 hwnd = create_listview_control(LVS_REPORT);
1322 subclass_header(hwnd);
1324 memset(&column, 0, sizeof(column));
1325 column.mask = LVCF_WIDTH;
1326 column.cx = 100;
1327 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1328 ok(rc == 0, "Inserting column failed with %d\n", rc);
1330 column.cx = 200;
1331 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1332 ok(rc == 1, "Inserting column failed with %d\n", rc);
1334 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1336 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1337 ok(rc == 1, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1338 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1339 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1341 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1343 /* after column added subitem is considered as present */
1344 insert_item(hwnd, 0);
1346 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1348 item.pszText = buff;
1349 item.cchTextMax = sizeof(buff);
1350 item.iItem = 0;
1351 item.iSubItem = 1;
1352 item.mask = LVIF_TEXT;
1353 memset(&g_itema, 0, sizeof(g_itema));
1354 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1355 ok(rc == 1, "got %d\n", rc);
1356 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1358 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1359 "get subitem text after column added", FALSE);
1361 DestroyWindow(hwnd);
1364 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1365 static WNDPROC listviewWndProc;
1366 static HIMAGELIST test_create_imagelist;
1368 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1370 LRESULT ret;
1372 if (uMsg == WM_CREATE)
1374 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1375 lpcs->style |= LVS_REPORT;
1377 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1378 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1379 return ret;
1382 static void test_create(void)
1384 HWND hList;
1385 HWND hHeader;
1386 LONG_PTR ret;
1387 LONG r;
1388 LVCOLUMNA col;
1389 RECT rect;
1390 WNDCLASSEX cls;
1391 DWORD style;
1393 cls.cbSize = sizeof(WNDCLASSEX);
1394 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1395 listviewWndProc = cls.lpfnWndProc;
1396 cls.lpfnWndProc = create_test_wndproc;
1397 cls.lpszClassName = "MyListView32";
1398 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1400 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1401 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1402 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1403 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1405 if (!IsWindow(hHeader))
1407 /* version 4.0 */
1408 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1409 DestroyWindow(hList);
1410 return;
1413 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1414 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1415 DestroyWindow(hList);
1417 /* header isn't created on LVS_ICON and LVS_LIST styles */
1418 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1419 GetModuleHandle(NULL), 0);
1420 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1421 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1422 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1423 /* insert column */
1424 memset(&col, 0, sizeof(LVCOLUMNA));
1425 col.mask = LVCF_WIDTH;
1426 col.cx = 100;
1427 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1428 ok(r == 0, "Expected 0 column's inserted\n");
1429 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1430 ok(IsWindow(hHeader), "Header should be created\n");
1431 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1432 style = GetWindowLong(hHeader, GWL_STYLE);
1433 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1434 DestroyWindow(hList);
1436 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1437 GetModuleHandle(NULL), 0);
1438 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1439 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1440 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1441 /* insert column */
1442 memset(&col, 0, sizeof(LVCOLUMNA));
1443 col.mask = LVCF_WIDTH;
1444 col.cx = 100;
1445 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1446 ok(r == 0, "Expected 0 column's inserted\n");
1447 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1448 ok(IsWindow(hHeader), "Header should be created\n");
1449 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1450 DestroyWindow(hList);
1452 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1453 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1454 GetModuleHandle(NULL), 0);
1455 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1456 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1457 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1458 ok(IsWindow(hHeader), "Header should be created\n");
1459 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1460 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1461 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1462 ok(IsWindow(hHeader), "Header should be created\n");
1463 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1464 DestroyWindow(hList);
1466 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1467 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1468 GetModuleHandle(NULL), 0);
1469 ret = SetWindowLongPtr(hList, GWL_STYLE,
1470 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1471 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1472 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1473 ok(IsWindow(hHeader), "Header should be created\n");
1474 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1475 ret = SetWindowLongPtr(hList, GWL_STYLE,
1476 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1477 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1478 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1479 ok(IsWindow(hHeader), "Header should be created\n");
1480 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1481 DestroyWindow(hList);
1483 /* LVS_REPORT without WS_VISIBLE */
1484 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1485 GetModuleHandle(NULL), 0);
1486 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1487 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1488 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1489 /* insert column */
1490 memset(&col, 0, sizeof(LVCOLUMNA));
1491 col.mask = LVCF_WIDTH;
1492 col.cx = 100;
1493 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1494 ok(r == 0, "Expected 0 column's inserted\n");
1495 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1496 ok(IsWindow(hHeader), "Header should be created\n");
1497 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1498 DestroyWindow(hList);
1500 /* LVS_REPORT without WS_VISIBLE, try to show it */
1501 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1502 GetModuleHandle(NULL), 0);
1503 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1504 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1505 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1506 ShowWindow(hList, SW_SHOW);
1507 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1508 ok(IsWindow(hHeader), "Header should be created\n");
1509 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1510 DestroyWindow(hList);
1512 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1513 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1514 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
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 /* HDS_DRAGDROP set by default */
1519 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1520 DestroyWindow(hList);
1522 /* setting LVS_EX_HEADERDRAGDROP creates header */
1523 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1524 GetModuleHandle(NULL), 0);
1525 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1526 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1527 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1528 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1529 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1530 ok(IsWindow(hHeader) ||
1531 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1532 "Header should be created\n");
1533 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1534 DestroyWindow(hList);
1536 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1537 hList = create_listview_control(LVS_ICON);
1538 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1539 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1540 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1541 DestroyWindow(hList);
1543 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1544 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1545 GetModuleHandle(NULL), 0);
1546 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1547 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1549 rect.left = LVIR_BOUNDS;
1550 rect.top = 1;
1551 rect.right = rect.bottom = -10;
1552 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1553 ok(r == 1, "Expected not-null LRESULT\n");
1555 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1556 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1557 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1559 DestroyWindow(hList);
1561 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1562 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1563 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1564 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1565 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1566 DestroyWindow(hList);
1569 static void test_redraw(void)
1571 HWND hwnd;
1572 HDC hdc;
1573 BOOL res;
1574 DWORD r;
1576 hwnd = create_listview_control(LVS_REPORT);
1577 subclass_header(hwnd);
1579 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1581 InvalidateRect(hwnd, NULL, TRUE);
1582 UpdateWindow(hwnd);
1583 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1585 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1587 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1588 /* 1. Without backbuffer */
1589 res = ListView_SetBkColor(hwnd, CLR_NONE);
1590 expect(TRUE, res);
1592 hdc = GetWindowDC(hwndparent);
1594 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1595 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1596 ok(r == 1, "Expected not zero result\n");
1597 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1598 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1600 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1601 expect(TRUE, res);
1603 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1604 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1605 ok(r == 1, "Expected not zero result\n");
1606 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1607 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1609 /* 2. With backbuffer */
1610 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1611 LVS_EX_DOUBLEBUFFER);
1612 res = ListView_SetBkColor(hwnd, CLR_NONE);
1613 expect(TRUE, res);
1615 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1616 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1617 ok(r == 1, "Expected not zero result\n");
1618 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1619 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1621 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1622 expect(TRUE, res);
1624 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1625 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1626 todo_wine ok(r == 1, "Expected not zero result\n");
1627 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1628 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1630 ReleaseDC(hwndparent, hdc);
1632 DestroyWindow(hwnd);
1635 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1637 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1639 if(msg == WM_NOTIFY) {
1640 NMHDR *nmhdr = (PVOID)lp;
1641 if(nmhdr->code == NM_CUSTOMDRAW) {
1642 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1643 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1644 switch(nmlvcd->nmcd.dwDrawStage) {
1645 case CDDS_PREPAINT:
1646 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1647 return CDRF_NOTIFYITEMDRAW;
1648 case CDDS_ITEMPREPAINT:
1649 nmlvcd->clrTextBk = CLR_DEFAULT;
1650 return CDRF_NOTIFYSUBITEMDRAW;
1651 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1652 clr = GetBkColor(nmlvcd->nmcd.hdc);
1653 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1654 return CDRF_NOTIFYPOSTPAINT;
1655 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1656 clr = GetBkColor(nmlvcd->nmcd.hdc);
1657 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1658 return CDRF_DODEFAULT;
1660 return CDRF_DODEFAULT;
1664 return DefWindowProcA(hwnd, msg, wp, lp);
1667 static void test_customdraw(void)
1669 HWND hwnd;
1670 WNDPROC oldwndproc;
1672 hwnd = create_listview_control(LVS_REPORT);
1674 insert_column(hwnd, 0);
1675 insert_column(hwnd, 1);
1676 insert_item(hwnd, 0);
1678 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1679 (LONG_PTR)cd_wndproc);
1681 InvalidateRect(hwnd, NULL, TRUE);
1682 UpdateWindow(hwnd);
1684 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1686 DestroyWindow(hwnd);
1689 static void test_icon_spacing(void)
1691 /* LVM_SETICONSPACING */
1692 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1694 HWND hwnd;
1695 WORD w, h;
1696 DWORD r;
1698 hwnd = create_listview_control(LVS_ICON);
1699 ok(hwnd != NULL, "failed to create a listview window\n");
1701 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1702 expect(NFR_ANSI, r);
1704 /* reset the icon spacing to defaults */
1705 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1707 /* now we can request what the defaults are */
1708 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1709 w = LOWORD(r);
1710 h = HIWORD(r);
1712 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1714 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1715 ok(r == MAKELONG(w, h) ||
1716 broken(r == MAKELONG(w, w)), /* win98 */
1717 "Expected %d, got %d\n", MAKELONG(w, h), r);
1719 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1720 if (r == 0)
1722 /* version 4.0 */
1723 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1724 DestroyWindow(hwnd);
1725 return;
1727 expect(MAKELONG(20,30), r);
1729 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1730 expect(MAKELONG(25,35), r);
1732 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1734 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1735 DestroyWindow(hwnd);
1738 static void test_color(void)
1740 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1742 HWND hwnd;
1743 DWORD r;
1744 int i;
1746 COLORREF color;
1747 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1749 hwnd = create_listview_control(LVS_REPORT);
1750 ok(hwnd != NULL, "failed to create a listview window\n");
1752 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1754 for (i = 0; i < 4; i++)
1756 color = colors[i];
1758 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1759 expect(TRUE, r);
1760 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1761 expect(color, r);
1763 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1764 expect (TRUE, r);
1765 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1766 expect(color, r);
1768 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1769 expect(TRUE, r);
1770 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1771 expect(color, r);
1774 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1776 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1777 DestroyWindow(hwnd);
1780 static void test_item_count(void)
1782 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1784 HWND hwnd;
1785 DWORD r;
1786 HDC hdc;
1787 HFONT hOldFont;
1788 TEXTMETRICA tm;
1789 RECT rect;
1790 INT height;
1792 LVITEM item0;
1793 LVITEM item1;
1794 LVITEM item2;
1795 static CHAR item0text[] = "item0";
1796 static CHAR item1text[] = "item1";
1797 static CHAR item2text[] = "item2";
1799 hwnd = create_listview_control(LVS_REPORT);
1800 ok(hwnd != NULL, "failed to create a listview window\n");
1802 /* resize in dpiaware manner to fit all 3 items added */
1803 hdc = GetDC(0);
1804 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1805 GetTextMetricsA(hdc, &tm);
1806 /* 2 extra pixels for bounds and header border */
1807 height = tm.tmHeight + 2;
1808 SelectObject(hdc, hOldFont);
1809 ReleaseDC(0, hdc);
1811 GetWindowRect(hwnd, &rect);
1812 /* 3 items + 1 header + 1 to be sure */
1813 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1815 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1817 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1818 expect(0, r);
1820 /* [item0] */
1821 item0.mask = LVIF_TEXT;
1822 item0.iItem = 0;
1823 item0.iSubItem = 0;
1824 item0.pszText = item0text;
1825 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1826 expect(0, r);
1828 /* [item0, item1] */
1829 item1.mask = LVIF_TEXT;
1830 item1.iItem = 1;
1831 item1.iSubItem = 0;
1832 item1.pszText = item1text;
1833 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1834 expect(1, r);
1836 /* [item0, item1, item2] */
1837 item2.mask = LVIF_TEXT;
1838 item2.iItem = 2;
1839 item2.iSubItem = 0;
1840 item2.pszText = item2text;
1841 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1842 expect(2, r);
1844 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1845 expect(3, r);
1847 /* [item0, item1] */
1848 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1849 expect(TRUE, r);
1851 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1852 expect(2, r);
1854 /* [] */
1855 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1856 expect(TRUE, r);
1858 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1859 expect(0, r);
1861 /* [item0] */
1862 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1863 expect(0, r);
1865 /* [item0, item1] */
1866 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1867 expect(1, r);
1869 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1870 expect(2, r);
1872 /* [item0, item1, item2] */
1873 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1874 expect(2, r);
1876 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1877 expect(3, r);
1879 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1881 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1882 DestroyWindow(hwnd);
1885 static void test_item_position(void)
1887 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1889 HWND hwnd;
1890 DWORD r;
1891 POINT position;
1893 LVITEM item0;
1894 LVITEM item1;
1895 LVITEM item2;
1896 static CHAR item0text[] = "item0";
1897 static CHAR item1text[] = "item1";
1898 static CHAR item2text[] = "item2";
1900 hwnd = create_listview_control(LVS_ICON);
1901 ok(hwnd != NULL, "failed to create a listview window\n");
1903 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1905 /* [item0] */
1906 item0.mask = LVIF_TEXT;
1907 item0.iItem = 0;
1908 item0.iSubItem = 0;
1909 item0.pszText = item0text;
1910 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1911 expect(0, r);
1913 /* [item0, item1] */
1914 item1.mask = LVIF_TEXT;
1915 item1.iItem = 1;
1916 item1.iSubItem = 0;
1917 item1.pszText = item1text;
1918 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1919 expect(1, r);
1921 /* [item0, item1, item2] */
1922 item2.mask = LVIF_TEXT;
1923 item2.iItem = 2;
1924 item2.iSubItem = 0;
1925 item2.pszText = item2text;
1926 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1927 expect(2, r);
1929 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1930 expect(TRUE, r);
1931 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1932 expect(TRUE, r);
1933 expect2(10, 5, position.x, position.y);
1935 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1936 expect(TRUE, r);
1937 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1938 expect(TRUE, r);
1939 expect2(0, 0, position.x, position.y);
1941 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1942 expect(TRUE, r);
1943 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1944 expect(TRUE, r);
1945 expect2(20, 20, position.x, position.y);
1947 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1949 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1950 DestroyWindow(hwnd);
1953 static void test_getorigin(void)
1955 /* LVM_GETORIGIN */
1957 HWND hwnd;
1958 DWORD r;
1959 POINT position;
1961 position.x = position.y = 0;
1963 hwnd = create_listview_control(LVS_ICON);
1964 ok(hwnd != NULL, "failed to create a listview window\n");
1965 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1967 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1968 expect(TRUE, r);
1969 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1970 DestroyWindow(hwnd);
1972 hwnd = create_listview_control(LVS_SMALLICON);
1973 ok(hwnd != NULL, "failed to create a listview window\n");
1974 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1976 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1977 expect(TRUE, r);
1978 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1979 DestroyWindow(hwnd);
1981 hwnd = create_listview_control(LVS_LIST);
1982 ok(hwnd != NULL, "failed to create a listview window\n");
1983 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1985 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1986 expect(FALSE, r);
1987 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1988 DestroyWindow(hwnd);
1990 hwnd = create_listview_control(LVS_REPORT);
1991 ok(hwnd != NULL, "failed to create a listview window\n");
1992 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1994 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1995 expect(FALSE, r);
1996 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1997 DestroyWindow(hwnd);
2000 static void test_multiselect(void)
2002 typedef struct t_select_task
2004 const char *descr;
2005 int initPos;
2006 int loopVK;
2007 int count;
2008 int result;
2009 } select_task;
2011 HWND hwnd;
2012 DWORD r;
2013 int i,j,item_count,selected_count;
2014 static const int items=5;
2015 BYTE kstate[256];
2016 select_task task;
2017 LONG_PTR style;
2018 LVITEMA item;
2020 static struct t_select_task task_list[] = {
2021 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
2022 { "using VK_UP", -1, VK_UP, -1, -1 },
2023 { "using VK_END", 0, VK_END, 1, -1 },
2024 { "using VK_HOME", -1, VK_HOME, 1, -1 }
2028 hwnd = create_listview_control(LVS_REPORT);
2030 for (i=0;i<items;i++) {
2031 insert_item(hwnd, 0);
2034 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2036 expect(items,item_count);
2038 for (i=0;i<4;i++) {
2039 task = task_list[i];
2041 /* deselect all items */
2042 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2043 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2045 /* set initial position */
2046 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
2047 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
2049 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2051 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
2053 /* Set SHIFT key pressed */
2054 GetKeyboardState(kstate);
2055 kstate[VK_SHIFT]=0x80;
2056 SetKeyboardState(kstate);
2058 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
2059 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
2060 expect(0,r);
2061 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
2062 expect(0,r);
2065 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2067 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);
2069 /* Set SHIFT key released */
2070 GetKeyboardState(kstate);
2071 kstate[VK_SHIFT]=0x00;
2072 SetKeyboardState(kstate);
2074 DestroyWindow(hwnd);
2076 /* make multiple selection, then switch to LVS_SINGLESEL */
2077 hwnd = create_listview_control(LVS_REPORT);
2078 for (i=0;i<items;i++) {
2079 insert_item(hwnd, 0);
2081 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
2082 expect(items,item_count);
2084 /* try with NULL pointer */
2085 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
2086 expect(FALSE, r);
2088 /* select all, check notifications */
2089 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2091 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2093 item.stateMask = LVIS_SELECTED;
2094 item.state = LVIS_SELECTED;
2095 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2096 expect(TRUE, r);
2098 ok_sequence(sequences, PARENT_SEQ_INDEX, select_all_parent_seq,
2099 "select all notification", FALSE);
2101 /* deselect all items */
2102 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
2103 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2104 for (i=0;i<3;i++) {
2105 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
2108 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2109 expect(3, r);
2110 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2111 expect(-1, r);
2113 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2114 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2115 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2116 /* check that style is accepted */
2117 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2118 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2120 for (i=0;i<3;i++) {
2121 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2122 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2124 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2125 expect(3, r);
2126 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2127 expect(3, r);
2129 /* select one more */
2130 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
2132 for (i=0;i<3;i++) {
2133 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
2134 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2136 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
2137 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2139 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2140 expect(1, r);
2141 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2142 expect(-1, r);
2144 /* try to select all on LVS_SINGLESEL */
2145 memset(&item, 0, sizeof(item));
2146 item.stateMask = LVIS_SELECTED;
2147 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2148 expect(TRUE, r);
2149 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2151 item.stateMask = LVIS_SELECTED;
2152 item.state = LVIS_SELECTED;
2153 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2154 expect(FALSE, r);
2156 r = ListView_GetSelectedCount(hwnd);
2157 expect(0, r);
2158 r = ListView_GetSelectionMark(hwnd);
2159 expect(-1, r);
2161 /* try to deselect all on LVS_SINGLESEL */
2162 item.stateMask = LVIS_SELECTED;
2163 item.state = LVIS_SELECTED;
2164 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2165 expect(TRUE, r);
2167 item.stateMask = LVIS_SELECTED;
2168 item.state = 0;
2169 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2170 expect(TRUE, r);
2171 r = ListView_GetSelectedCount(hwnd);
2172 expect(0, r);
2174 DestroyWindow(hwnd);
2177 static void test_subitem_rect(void)
2179 HWND hwnd;
2180 DWORD r;
2181 LVCOLUMN col;
2182 RECT rect, rect2;
2183 INT arr[3];
2185 /* test LVM_GETSUBITEMRECT for header */
2186 hwnd = create_listview_control(LVS_REPORT);
2187 ok(hwnd != NULL, "failed to create a listview window\n");
2188 /* add some columns */
2189 memset(&col, 0, sizeof(LVCOLUMN));
2190 col.mask = LVCF_WIDTH;
2191 col.cx = 100;
2192 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2193 expect(0, r);
2194 col.cx = 150;
2195 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2196 expect(1, r);
2197 col.cx = 200;
2198 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2199 expect(2, r);
2200 /* item = -1 means header, subitem index is 1 based */
2201 rect.left = LVIR_BOUNDS;
2202 rect.top = 0;
2203 rect.right = rect.bottom = 0;
2204 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2205 expect(0, r);
2207 rect.left = LVIR_BOUNDS;
2208 rect.top = 1;
2209 rect.right = rect.bottom = 0;
2210 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2212 ok(r == 1, "Expected not-null LRESULT\n");
2213 expect(100, rect.left);
2214 expect(250, rect.right);
2215 todo_wine
2216 expect(3, rect.top);
2218 rect.left = LVIR_BOUNDS;
2219 rect.top = 2;
2220 rect.right = rect.bottom = 0;
2221 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2223 ok(r == 1, "Expected not-null LRESULT\n");
2224 expect(250, rect.left);
2225 expect(450, rect.right);
2226 todo_wine
2227 expect(3, rect.top);
2229 /* item LVS_REPORT padding isn't applied to subitems */
2230 insert_item(hwnd, 0);
2232 rect.left = LVIR_BOUNDS;
2233 rect.top = 1;
2234 rect.right = rect.bottom = 0;
2235 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2236 ok(r == 1, "Expected not-null LRESULT\n");
2237 expect(100, rect.left);
2238 expect(250, rect.right);
2240 rect.left = LVIR_ICON;
2241 rect.top = 1;
2242 rect.right = rect.bottom = 0;
2243 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2244 ok(r == 1, "Expected not-null LRESULT\n");
2245 /* no icon attached - zero width rectangle, with no left padding */
2246 expect(100, rect.left);
2247 expect(100, rect.right);
2249 rect.left = LVIR_LABEL;
2250 rect.top = 1;
2251 rect.right = rect.bottom = 0;
2252 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2253 ok(r == 1, "Expected not-null LRESULT\n");
2254 /* same as full LVIR_BOUNDS */
2255 expect(100, rect.left);
2256 expect(250, rect.right);
2258 SendMessage(hwnd, LVM_SCROLL, 10, 0);
2260 rect.left = LVIR_BOUNDS;
2261 rect.top = 1;
2262 rect.right = rect.bottom = 0;
2263 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2264 ok(r == 1, "Expected not-null LRESULT\n");
2265 expect(90, rect.left);
2266 expect(240, rect.right);
2268 SendMessage(hwnd, LVM_SCROLL, -10, 0);
2270 DestroyWindow(hwnd);
2272 /* test subitem rects after re-arranging columns */
2273 hwnd = create_listview_control(LVS_REPORT);
2274 ok(hwnd != NULL, "failed to create a listview window\n");
2275 memset(&col, 0, sizeof(LVCOLUMN));
2276 col.mask = LVCF_WIDTH;
2278 col.cx = 100;
2279 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
2280 expect(0, r);
2282 col.cx = 200;
2283 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
2284 expect(1, r);
2286 col.cx = 300;
2287 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
2288 expect(2, r);
2290 insert_item(hwnd, 0);
2291 insert_item(hwnd, 1);
2293 /* wrong item is refused for main item */
2294 rect.left = LVIR_BOUNDS;
2295 rect.top = 0;
2296 rect.right = rect.bottom = -1;
2297 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect);
2298 ok(r == FALSE, "got %d\n", r);
2300 /* for subitems rectangle is calculated even if there's no item added */
2301 rect.left = LVIR_BOUNDS;
2302 rect.top = 1;
2303 rect.right = rect.bottom = -1;
2304 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect);
2305 ok(r == TRUE, "got %d\n", r);
2307 rect2.left = LVIR_BOUNDS;
2308 rect2.top = 1;
2309 rect2.right = rect2.bottom = -1;
2310 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect2);
2311 todo_wine {
2312 ok(r == TRUE, "got %d\n", r);
2313 expect(rect.right, rect2.right);
2314 expect(rect.left, rect2.left);
2315 expect(rect.bottom, rect2.top);
2316 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2319 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2320 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2321 expect(TRUE, r);
2323 rect.left = LVIR_BOUNDS;
2324 rect.top = 0;
2325 rect.right = rect.bottom = -1;
2326 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2327 ok(r == TRUE, "got %d\n", r);
2328 expect(0, rect.left);
2329 expect(600, rect.right);
2331 rect.left = LVIR_BOUNDS;
2332 rect.top = 1;
2333 rect.right = rect.bottom = -1;
2334 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2335 ok(r == TRUE, "got %d\n", r);
2336 expect(0, rect.left);
2337 expect(200, rect.right);
2339 rect2.left = LVIR_BOUNDS;
2340 rect2.top = 1;
2341 rect2.right = rect2.bottom = -1;
2342 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect2);
2343 ok(r == TRUE, "got %d\n", r);
2344 expect(0, rect2.left);
2345 expect(200, rect2.right);
2346 /* items are of the same height */
2347 ok(rect2.top > 0, "expected positive item height\n");
2348 expect(rect.bottom, rect2.top);
2349 expect(rect.bottom * 2 - rect.top, rect2.bottom);
2351 rect.left = LVIR_BOUNDS;
2352 rect.top = 2;
2353 rect.right = rect.bottom = -1;
2354 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2355 ok(r == TRUE, "got %d\n", r);
2356 expect(300, rect.left);
2357 expect(600, rect.right);
2359 DestroyWindow(hwnd);
2361 /* try it for non LVS_REPORT style */
2362 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2363 GetModuleHandle(NULL), 0);
2364 rect.left = LVIR_BOUNDS;
2365 rect.top = 1;
2366 rect.right = rect.bottom = -10;
2367 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2368 ok(r == 0, "Expected not-null LRESULT\n");
2369 /* rect is unchanged */
2370 expect(0, rect.left);
2371 expect(-10, rect.right);
2372 expect(1, rect.top);
2373 expect(-10, rect.bottom);
2374 DestroyWindow(hwnd);
2377 /* comparison callback for test_sorting */
2378 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2380 if (first == second) return 0;
2381 return (first > second ? 1 : -1);
2384 static void test_sorting(void)
2386 HWND hwnd;
2387 LVITEMA item = {0};
2388 DWORD r;
2389 LONG_PTR style;
2390 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2391 CHAR buff[10];
2393 hwnd = create_listview_control(LVS_REPORT);
2394 ok(hwnd != NULL, "failed to create a listview window\n");
2396 /* insert some items */
2397 item.mask = LVIF_PARAM | LVIF_STATE;
2398 item.state = LVIS_SELECTED;
2399 item.iItem = 0;
2400 item.iSubItem = 0;
2401 item.lParam = 3;
2402 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2403 expect(0, r);
2405 item.mask = LVIF_PARAM;
2406 item.iItem = 1;
2407 item.iSubItem = 0;
2408 item.lParam = 2;
2409 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2410 expect(1, r);
2412 item.mask = LVIF_STATE | LVIF_PARAM;
2413 item.state = LVIS_SELECTED;
2414 item.iItem = 2;
2415 item.iSubItem = 0;
2416 item.lParam = 4;
2417 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2418 expect(2, r);
2420 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2421 expect(-1, r);
2423 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2424 expect(2, r);
2426 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2427 expect(TRUE, r);
2429 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2430 expect(2, r);
2431 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2432 expect(-1, r);
2433 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2434 expect(0, r);
2435 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2436 expect(LVIS_SELECTED, r);
2437 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2438 expect(LVIS_SELECTED, r);
2440 DestroyWindow(hwnd);
2442 /* switch to LVS_SORTASCENDING when some items added */
2443 hwnd = create_listview_control(LVS_REPORT);
2444 ok(hwnd != NULL, "failed to create a listview window\n");
2446 item.mask = LVIF_TEXT;
2447 item.iItem = 0;
2448 item.iSubItem = 0;
2449 item.pszText = names[1];
2450 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2451 expect(0, r);
2453 item.mask = LVIF_TEXT;
2454 item.iItem = 1;
2455 item.iSubItem = 0;
2456 item.pszText = names[2];
2457 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2458 expect(1, r);
2460 item.mask = LVIF_TEXT;
2461 item.iItem = 2;
2462 item.iSubItem = 0;
2463 item.pszText = names[0];
2464 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2465 expect(2, r);
2467 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2468 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2469 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2470 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2472 /* no sorting performed when switched to LVS_SORTASCENDING */
2473 item.mask = LVIF_TEXT;
2474 item.iItem = 0;
2475 item.pszText = buff;
2476 item.cchTextMax = sizeof(buff);
2477 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2478 expect(TRUE, r);
2479 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2481 item.iItem = 1;
2482 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2483 expect(TRUE, r);
2484 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2486 item.iItem = 2;
2487 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2488 expect(TRUE, r);
2489 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2491 /* adding new item doesn't resort list */
2492 item.mask = LVIF_TEXT;
2493 item.iItem = 3;
2494 item.iSubItem = 0;
2495 item.pszText = names[3];
2496 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2497 expect(3, r);
2499 item.mask = LVIF_TEXT;
2500 item.iItem = 0;
2501 item.pszText = buff;
2502 item.cchTextMax = sizeof(buff);
2503 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2504 expect(TRUE, r);
2505 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2507 item.iItem = 1;
2508 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2509 expect(TRUE, r);
2510 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2512 item.iItem = 2;
2513 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2514 expect(TRUE, r);
2515 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2517 item.iItem = 3;
2518 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2519 expect(TRUE, r);
2520 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2522 /* corner case - item should be placed at first position */
2523 item.mask = LVIF_TEXT;
2524 item.iItem = 4;
2525 item.iSubItem = 0;
2526 item.pszText = names[4];
2527 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2528 expect(0, r);
2530 item.iItem = 0;
2531 item.pszText = buff;
2532 item.cchTextMax = sizeof(buff);
2533 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2534 expect(TRUE, r);
2535 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2537 item.iItem = 1;
2538 item.pszText = buff;
2539 item.cchTextMax = sizeof(buff);
2540 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2541 expect(TRUE, r);
2542 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2544 item.iItem = 2;
2545 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2546 expect(TRUE, r);
2547 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2549 item.iItem = 3;
2550 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2551 expect(TRUE, r);
2552 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2554 item.iItem = 4;
2555 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2556 expect(TRUE, r);
2557 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2559 DestroyWindow(hwnd);
2562 static void test_ownerdata(void)
2564 HWND hwnd;
2565 LONG_PTR style, ret;
2566 DWORD res;
2567 LVITEMA item;
2569 /* it isn't possible to set LVS_OWNERDATA after creation */
2570 if (g_is_below_5)
2572 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2574 else
2576 hwnd = create_listview_control(LVS_REPORT);
2577 ok(hwnd != NULL, "failed to create a listview window\n");
2578 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2579 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2581 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2583 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2584 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2585 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2586 "try to switch to LVS_OWNERDATA seq", FALSE);
2588 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2589 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2590 DestroyWindow(hwnd);
2593 /* try to set LVS_OWNERDATA after creation just having it */
2594 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2595 ok(hwnd != NULL, "failed to create a listview window\n");
2596 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2597 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2599 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2601 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2602 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2603 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2604 "try to switch to LVS_OWNERDATA seq", FALSE);
2605 DestroyWindow(hwnd);
2607 /* try to remove LVS_OWNERDATA after creation just having it */
2608 if (g_is_below_5)
2610 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2612 else
2614 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2615 ok(hwnd != NULL, "failed to create a listview window\n");
2616 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2617 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2619 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2621 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2622 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2623 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2624 "try to switch to LVS_OWNERDATA seq", FALSE);
2625 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2626 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2627 DestroyWindow(hwnd);
2630 /* try select an item */
2631 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2632 ok(hwnd != NULL, "failed to create a listview window\n");
2633 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2634 ok(res == 1, "Expected LVM_SETITEMCOUNT to succeed\n");
2635 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2636 expect(0, res);
2637 memset(&item, 0, sizeof(item));
2638 item.stateMask = LVIS_SELECTED;
2639 item.state = LVIS_SELECTED;
2640 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2641 expect(TRUE, res);
2642 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2643 expect(1, res);
2644 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2645 expect(1, res);
2646 DestroyWindow(hwnd);
2648 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2649 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2650 ok(hwnd != NULL, "failed to create a listview window\n");
2651 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2652 ok(res == 1, "Expected LVM_SETITEMCOUNT to succeed\n");
2653 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2654 expect(1, res);
2655 memset(&item, 0, sizeof(item));
2656 item.mask = LVIF_STATE;
2657 item.iItem = 0;
2658 item.stateMask = LVIS_SELECTED;
2659 item.state = LVIS_SELECTED;
2660 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2661 expect(FALSE, res);
2662 DestroyWindow(hwnd);
2664 /* check notifications after focused/selected changed */
2665 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2666 ok(hwnd != NULL, "failed to create a listview window\n");
2667 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
2668 ok(res == 1, "Expected LVM_SETITEMCOUNT to succeed\n");
2670 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2672 memset(&item, 0, sizeof(item));
2673 item.stateMask = LVIS_SELECTED;
2674 item.state = LVIS_SELECTED;
2675 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2676 expect(TRUE, res);
2678 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2679 "ownerdata select notification", TRUE);
2681 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2683 memset(&item, 0, sizeof(item));
2684 item.stateMask = LVIS_FOCUSED;
2685 item.state = LVIS_FOCUSED;
2686 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2687 expect(TRUE, res);
2689 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2690 "ownerdata focus notification", TRUE);
2692 /* select all, check notifications */
2693 item.stateMask = LVIS_SELECTED;
2694 item.state = 0;
2695 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2696 expect(TRUE, res);
2698 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2700 item.stateMask = LVIS_SELECTED;
2701 item.state = LVIS_SELECTED;
2703 g_dump_itemchanged = TRUE;
2704 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2705 expect(TRUE, res);
2706 g_dump_itemchanged = FALSE;
2708 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2709 "ownerdata select all notification", TRUE);
2711 /* select all again, note that all items are selected already */
2712 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2713 item.stateMask = LVIS_SELECTED;
2714 item.state = LVIS_SELECTED;
2715 g_dump_itemchanged = TRUE;
2716 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2717 expect(TRUE, res);
2718 g_dump_itemchanged = FALSE;
2719 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2720 "ownerdata select all notification", TRUE);
2721 /* deselect all */
2722 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2723 item.stateMask = LVIS_SELECTED;
2724 item.state = 0;
2725 g_dump_itemchanged = TRUE;
2726 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2727 expect(TRUE, res);
2728 g_dump_itemchanged = FALSE;
2729 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2730 "ownerdata deselect all notification", TRUE);
2732 /* select one, then deselect all */
2733 item.stateMask = LVIS_SELECTED;
2734 item.state = LVIS_SELECTED;
2735 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2736 expect(TRUE, res);
2737 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2738 item.stateMask = LVIS_SELECTED;
2739 item.state = 0;
2740 g_dump_itemchanged = TRUE;
2741 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2742 expect(TRUE, res);
2743 g_dump_itemchanged = FALSE;
2744 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
2745 "ownerdata select all notification", TRUE);
2747 /* remove focused, try to focus all */
2748 item.stateMask = LVIS_FOCUSED;
2749 item.state = LVIS_FOCUSED;
2750 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2751 expect(TRUE, res);
2752 item.stateMask = LVIS_FOCUSED;
2753 item.state = 0;
2754 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2755 expect(TRUE, res);
2756 item.stateMask = LVIS_FOCUSED;
2757 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
2758 expect(0, res);
2759 /* setting all to focused returns failure value */
2760 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2761 item.stateMask = LVIS_FOCUSED;
2762 item.state = LVIS_FOCUSED;
2763 g_dump_itemchanged = TRUE;
2764 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2765 expect(FALSE, res);
2766 g_dump_itemchanged = FALSE;
2767 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2768 "ownerdata focus all notification", FALSE);
2769 /* focus single item, remove all */
2770 item.stateMask = LVIS_FOCUSED;
2771 item.state = LVIS_FOCUSED;
2772 res = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2773 expect(TRUE, res);
2774 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2775 item.stateMask = LVIS_FOCUSED;
2776 item.state = 0;
2777 g_dump_itemchanged = TRUE;
2778 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2779 expect(TRUE, res);
2780 g_dump_itemchanged = FALSE;
2781 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
2782 "ownerdata remove focus all notification", TRUE);
2783 /* set all cut */
2784 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2785 item.stateMask = LVIS_CUT;
2786 item.state = LVIS_CUT;
2787 g_dump_itemchanged = TRUE;
2788 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2789 expect(TRUE, res);
2790 g_dump_itemchanged = FALSE;
2791 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2792 "ownerdata cut all notification", TRUE);
2793 /* all marked cut, try again */
2794 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2795 item.stateMask = LVIS_CUT;
2796 item.state = LVIS_CUT;
2797 g_dump_itemchanged = TRUE;
2798 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2799 expect(TRUE, res);
2800 g_dump_itemchanged = FALSE;
2801 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
2802 "ownerdata cut all notification #2", TRUE);
2804 DestroyWindow(hwnd);
2806 /* check notifications on LVM_GETITEM */
2807 /* zero callback mask */
2808 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2809 ok(hwnd != NULL, "failed to create a listview window\n");
2810 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2811 ok(res == 1, "Expected LVM_SETITEMCOUNT to succeed\n");
2813 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2815 memset(&item, 0, sizeof(item));
2816 item.stateMask = LVIS_SELECTED;
2817 item.mask = LVIF_STATE;
2818 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2819 expect(TRUE, res);
2821 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2822 "ownerdata getitem selected state 1", FALSE);
2824 /* non zero callback mask but not we asking for */
2825 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2826 expect(TRUE, res);
2828 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2830 memset(&item, 0, sizeof(item));
2831 item.stateMask = LVIS_SELECTED;
2832 item.mask = LVIF_STATE;
2833 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2834 expect(TRUE, res);
2836 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2837 "ownerdata getitem selected state 2", FALSE);
2839 /* LVIS_OVERLAYMASK callback mask, asking for index */
2840 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2842 memset(&item, 0, sizeof(item));
2843 item.stateMask = LVIS_OVERLAYMASK;
2844 item.mask = LVIF_STATE;
2845 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2846 expect(TRUE, res);
2848 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2849 "ownerdata getitem selected state 2", FALSE);
2851 DestroyWindow(hwnd);
2853 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2854 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
2855 ok(hwnd != NULL, "failed to create a listview window\n");
2856 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2857 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2858 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2859 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2860 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2861 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2862 DestroyWindow(hwnd);
2863 /* apparently it's allowed to switch these style on after creation */
2864 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2865 ok(hwnd != NULL, "failed to create a listview window\n");
2866 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2867 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2868 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2869 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2870 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2871 DestroyWindow(hwnd);
2873 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2874 ok(hwnd != NULL, "failed to create a listview window\n");
2875 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2876 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2877 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2878 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2879 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2880 DestroyWindow(hwnd);
2883 static void test_norecompute(void)
2885 static CHAR testA[] = "test";
2886 CHAR buff[10];
2887 LVITEMA item;
2888 HWND hwnd;
2889 DWORD res;
2891 /* self containing control */
2892 hwnd = create_listview_control(LVS_REPORT);
2893 ok(hwnd != NULL, "failed to create a listview window\n");
2894 memset(&item, 0, sizeof(item));
2895 item.mask = LVIF_TEXT | LVIF_STATE;
2896 item.iItem = 0;
2897 item.stateMask = LVIS_SELECTED;
2898 item.state = LVIS_SELECTED;
2899 item.pszText = testA;
2900 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2901 expect(0, res);
2902 /* retrieve with LVIF_NORECOMPUTE */
2903 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2904 item.iItem = 0;
2905 item.pszText = buff;
2906 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2907 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2908 expect(TRUE, res);
2909 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2911 item.mask = LVIF_TEXT;
2912 item.iItem = 1;
2913 item.pszText = LPSTR_TEXTCALLBACK;
2914 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2915 expect(1, res);
2917 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2918 item.iItem = 1;
2919 item.pszText = buff;
2920 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2922 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2923 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2924 expect(TRUE, res);
2925 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2926 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2927 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2929 DestroyWindow(hwnd);
2931 /* LVS_OWNERDATA */
2932 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2933 ok(hwnd != NULL, "failed to create a listview window\n");
2935 item.mask = LVIF_STATE;
2936 item.stateMask = LVIS_SELECTED;
2937 item.state = LVIS_SELECTED;
2938 item.iItem = 0;
2939 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2940 expect(0, res);
2942 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2943 item.iItem = 0;
2944 item.pszText = buff;
2945 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2946 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2947 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2948 expect(TRUE, res);
2949 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2950 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2951 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2953 DestroyWindow(hwnd);
2956 static void test_nosortheader(void)
2958 HWND hwnd, header;
2959 LONG_PTR style;
2961 hwnd = create_listview_control(LVS_REPORT);
2962 ok(hwnd != NULL, "failed to create a listview window\n");
2964 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2965 ok(IsWindow(header), "header expected\n");
2967 style = GetWindowLongPtr(header, GWL_STYLE);
2968 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2970 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2971 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2972 /* HDS_BUTTONS retained */
2973 style = GetWindowLongPtr(header, GWL_STYLE);
2974 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2976 DestroyWindow(hwnd);
2978 /* create with LVS_NOSORTHEADER */
2979 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
2980 ok(hwnd != NULL, "failed to create a listview window\n");
2982 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2983 ok(IsWindow(header), "header expected\n");
2985 style = GetWindowLongPtr(header, GWL_STYLE);
2986 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2988 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2989 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2990 /* not changed here */
2991 style = GetWindowLongPtr(header, GWL_STYLE);
2992 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2994 DestroyWindow(hwnd);
2997 static void test_setredraw(void)
2999 HWND hwnd;
3000 DWORD_PTR style;
3001 DWORD ret;
3002 HDC hdc;
3003 RECT rect;
3005 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3006 ok(hwnd != NULL, "failed to create a listview window\n");
3008 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3009 ListView seems to handle it internally without DefWinProc */
3011 /* default value first */
3012 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3013 expect(0, ret);
3014 /* disable */
3015 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3016 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3017 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3018 expect(0, ret);
3019 style = GetWindowLongPtr(hwnd, GWL_STYLE);
3020 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3021 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3022 expect(0, ret);
3024 /* check update rect after redrawing */
3025 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3026 expect(0, ret);
3027 InvalidateRect(hwnd, NULL, FALSE);
3028 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
3029 rect.right = rect.bottom = 1;
3030 GetUpdateRect(hwnd, &rect, FALSE);
3031 expect(0, rect.right);
3032 expect(0, rect.bottom);
3034 /* WM_ERASEBKGND */
3035 hdc = GetWindowDC(hwndparent);
3036 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3037 expect(TRUE, ret);
3038 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3039 expect(0, ret);
3040 ret = SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3041 expect(TRUE, ret);
3042 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
3043 expect(0, ret);
3044 ReleaseDC(hwndparent, hdc);
3046 /* check notification messages to show that repainting is disabled */
3047 ret = SendMessage(hwnd, LVM_SETITEMCOUNT, 1, 0);
3048 expect(TRUE, ret);
3049 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3050 expect(0, ret);
3051 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3053 InvalidateRect(hwnd, NULL, TRUE);
3054 UpdateWindow(hwnd);
3055 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3056 "redraw after WM_SETREDRAW (FALSE)", FALSE);
3058 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3059 expect(TRUE, ret);
3060 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3061 InvalidateRect(hwnd, NULL, TRUE);
3062 UpdateWindow(hwnd);
3063 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3064 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3066 /* message isn't forwarded to header */
3067 subclass_header(hwnd);
3068 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3069 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
3070 expect(0, ret);
3071 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3072 "WM_SETREDRAW: not forwarded to header", FALSE);
3074 DestroyWindow(hwnd);
3077 static void test_hittest(void)
3079 HWND hwnd;
3080 DWORD r;
3081 RECT bounds;
3082 LVITEMA item;
3083 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3084 POINT pos;
3085 INT x, y, i;
3086 WORD vert;
3087 HIMAGELIST himl, himl2;
3088 HBITMAP hbmp;
3090 hwnd = create_listview_control(LVS_REPORT);
3091 ok(hwnd != NULL, "failed to create a listview window\n");
3093 /* LVS_REPORT with a single subitem (2 columns) */
3094 insert_column(hwnd, 0);
3095 insert_column(hwnd, 1);
3096 insert_item(hwnd, 0);
3098 item.iSubItem = 0;
3099 /* the only purpose of that line is to be as long as a half item rect */
3100 item.pszText = text;
3101 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
3102 expect(TRUE, r);
3104 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3105 expect(TRUE, r);
3106 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3107 expect(TRUE, r);
3109 memset(&bounds, 0, sizeof(bounds));
3110 bounds.left = LVIR_BOUNDS;
3111 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3112 expect(1, r);
3113 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3114 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3115 r = SendMessage(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3116 vert = HIWORD(r);
3117 ok(bounds.bottom - bounds.top == vert,
3118 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3119 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3120 expect(TRUE, r);
3122 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3124 /* outside columns by x position - valid is [0, 199] */
3125 x = -1;
3126 y = pos.y + (bounds.bottom - bounds.top) / 2;
3127 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3128 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3130 x = pos.x + 50; /* column half width */
3131 y = pos.y + (bounds.bottom - bounds.top) / 2;
3132 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3133 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3134 x = pos.x + 150; /* outside column */
3135 y = pos.y + (bounds.bottom - bounds.top) / 2;
3136 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3137 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3138 y = (bounds.bottom - bounds.top) / 2;
3139 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3140 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3141 /* outside possible client rectangle (to right) */
3142 x = pos.x + 500;
3143 y = pos.y + (bounds.bottom - bounds.top) / 2;
3144 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3145 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3146 y = (bounds.bottom - bounds.top) / 2;
3147 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3148 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3149 /* subitem returned with -1 item too */
3150 x = pos.x + 150;
3151 y = bounds.top - vert;
3152 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3153 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3154 /* return values appear to underflow with negative indices */
3155 i = -2;
3156 y = y - vert;
3157 while (i > -10) {
3158 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3159 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3160 y = y - vert;
3161 i--;
3163 /* parent client area is 100x100 by default */
3164 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3165 x = pos.x + 150; /* outside column */
3166 y = pos.y + (bounds.bottom - bounds.top) / 2;
3167 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3168 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3169 y = (bounds.bottom - bounds.top) / 2;
3170 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3171 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3172 /* the same with LVS_EX_FULLROWSELECT */
3173 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3174 x = pos.x + 150; /* outside column */
3175 y = pos.y + (bounds.bottom - bounds.top) / 2;
3176 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3177 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3178 y = (bounds.bottom - bounds.top) / 2;
3179 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3180 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3181 x = pos.x + 150; /* outside column */
3182 y = pos.y + (bounds.bottom - bounds.top) / 2;
3183 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3184 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3185 y = (bounds.bottom - bounds.top) / 2;
3186 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3187 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3188 /* outside possible client rectangle (to right) */
3189 x = pos.x + 500;
3190 y = pos.y + (bounds.bottom - bounds.top) / 2;
3191 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3192 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3193 y = (bounds.bottom - bounds.top) / 2;
3194 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3195 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3196 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3197 himl = ImageList_Create(16, 16, 0, 4, 4);
3198 ok(himl != NULL, "failed to create imagelist\n");
3199 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3200 ok(hbmp != NULL, "failed to create bitmap\n");
3201 r = ImageList_Add(himl, hbmp, 0);
3202 ok(r == 0, "should be zero\n");
3203 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3204 ok(hbmp != NULL, "failed to create bitmap\n");
3205 r = ImageList_Add(himl, hbmp, 0);
3206 ok(r == 1, "should be one\n");
3208 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3209 ok(r == 0, "should return zero\n");
3211 item.mask = LVIF_IMAGE;
3212 item.iImage = 0;
3213 item.iItem = 0;
3214 item.iSubItem = 0;
3215 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3216 expect(TRUE, r);
3217 /* on state icon */
3218 x = pos.x + 8;
3219 y = pos.y + (bounds.bottom - bounds.top) / 2;
3220 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3221 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3222 y = (bounds.bottom - bounds.top) / 2;
3223 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3225 /* state icons indices are 1 based, check with valid index */
3226 item.mask = LVIF_STATE;
3227 item.state = INDEXTOSTATEIMAGEMASK(1);
3228 item.stateMask = LVIS_STATEIMAGEMASK;
3229 item.iItem = 0;
3230 item.iSubItem = 0;
3231 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3232 expect(TRUE, r);
3233 /* on state icon */
3234 x = pos.x + 8;
3235 y = pos.y + (bounds.bottom - bounds.top) / 2;
3236 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3237 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3238 y = (bounds.bottom - bounds.top) / 2;
3239 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3241 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3242 ok(himl2 == himl, "should return handle\n");
3244 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3245 ok(r == 0, "should return zero\n");
3246 /* on item icon */
3247 x = pos.x + 8;
3248 y = pos.y + (bounds.bottom - bounds.top) / 2;
3249 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3250 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3251 y = (bounds.bottom - bounds.top) / 2;
3252 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3254 DestroyWindow(hwnd);
3257 static void test_getviewrect(void)
3259 HWND hwnd;
3260 DWORD r;
3261 RECT rect;
3262 LVITEMA item;
3264 hwnd = create_listview_control(LVS_REPORT);
3265 ok(hwnd != NULL, "failed to create a listview window\n");
3267 /* empty */
3268 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3269 expect(TRUE, r);
3271 insert_column(hwnd, 0);
3272 insert_column(hwnd, 1);
3274 memset(&item, 0, sizeof(item));
3275 item.iItem = 0;
3276 item.iSubItem = 0;
3277 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3279 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3280 expect(TRUE, r);
3281 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3282 expect(TRUE, r);
3284 rect.left = rect.right = rect.top = rect.bottom = -1;
3285 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3286 expect(TRUE, r);
3287 /* left is set to (2e31-1) - XP SP2 */
3288 expect(0, rect.right);
3289 expect(0, rect.top);
3290 expect(0, rect.bottom);
3292 /* switch to LVS_ICON */
3293 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
3295 rect.left = rect.right = rect.top = rect.bottom = -1;
3296 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3297 expect(TRUE, r);
3298 expect(0, rect.left);
3299 expect(0, rect.top);
3300 /* precise value differs for 2k, XP and Vista */
3301 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3302 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3304 DestroyWindow(hwnd);
3307 static void test_getitemposition(void)
3309 HWND hwnd, header;
3310 DWORD r;
3311 POINT pt;
3312 RECT rect;
3314 hwnd = create_listview_control(LVS_REPORT);
3315 ok(hwnd != NULL, "failed to create a listview window\n");
3316 header = subclass_header(hwnd);
3318 /* LVS_REPORT, single item, no columns added */
3319 insert_item(hwnd, 0);
3321 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3323 pt.x = pt.y = -1;
3324 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3325 expect(TRUE, r);
3326 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3328 /* LVS_REPORT, single item, single column */
3329 insert_column(hwnd, 0);
3331 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3333 pt.x = pt.y = -1;
3334 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3335 expect(TRUE, r);
3336 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3338 memset(&rect, 0, sizeof(rect));
3339 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3340 /* some padding? */
3341 expect(2, pt.x);
3342 /* offset by header height */
3343 expect(rect.bottom - rect.top, pt.y);
3345 DestroyWindow(hwnd);
3348 static void test_columnscreation(void)
3350 HWND hwnd, header;
3351 DWORD r;
3353 hwnd = create_listview_control(LVS_REPORT);
3354 ok(hwnd != NULL, "failed to create a listview window\n");
3356 insert_item(hwnd, 0);
3358 /* headers columns aren't created automatically */
3359 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3360 ok(IsWindow(header), "Expected header handle\n");
3361 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
3362 expect(0, r);
3364 DestroyWindow(hwnd);
3367 static void test_getitemrect(void)
3369 HWND hwnd;
3370 HIMAGELIST himl, himl_ret;
3371 HBITMAP hbm;
3372 RECT rect;
3373 DWORD r;
3374 LVITEMA item;
3375 LVCOLUMNA col;
3376 INT order[2];
3377 POINT pt;
3378 HDC hdc;
3380 /* rectangle isn't empty for empty text items */
3381 hwnd = create_listview_control(LVS_LIST);
3382 memset(&item, 0, sizeof(item));
3383 item.mask = 0;
3384 item.iItem = 0;
3385 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3386 expect(0, r);
3387 rect.left = LVIR_LABEL;
3388 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3389 expect(TRUE, r);
3390 expect(0, rect.left);
3391 expect(0, rect.top);
3392 hdc = GetDC(hwnd);
3393 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, rect.right);
3394 ReleaseDC(hwnd, hdc);
3395 DestroyWindow(hwnd);
3397 hwnd = create_listview_control(LVS_REPORT);
3398 ok(hwnd != NULL, "failed to create a listview window\n");
3400 /* empty item */
3401 memset(&item, 0, sizeof(item));
3402 item.iItem = 0;
3403 item.iSubItem = 0;
3404 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3405 expect(0, r);
3407 rect.left = LVIR_BOUNDS;
3408 rect.right = rect.top = rect.bottom = -1;
3409 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3410 expect(TRUE, r);
3412 /* zero width rectangle with no padding */
3413 expect(0, rect.left);
3414 expect(0, rect.right);
3416 insert_column(hwnd, 0);
3417 insert_column(hwnd, 1);
3419 col.mask = LVCF_WIDTH;
3420 col.cx = 50;
3421 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
3422 expect(TRUE, r);
3424 col.mask = LVCF_WIDTH;
3425 col.cx = 100;
3426 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
3427 expect(TRUE, r);
3429 rect.left = LVIR_BOUNDS;
3430 rect.right = rect.top = rect.bottom = -1;
3431 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3432 expect(TRUE, r);
3434 /* still no left padding */
3435 expect(0, rect.left);
3436 expect(150, rect.right);
3438 rect.left = LVIR_SELECTBOUNDS;
3439 rect.right = rect.top = rect.bottom = -1;
3440 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3441 expect(TRUE, r);
3442 /* padding */
3443 expect(2, rect.left);
3445 rect.left = LVIR_LABEL;
3446 rect.right = rect.top = rect.bottom = -1;
3447 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3448 expect(TRUE, r);
3449 /* padding, column width */
3450 expect(2, rect.left);
3451 expect(50, rect.right);
3453 /* no icons attached */
3454 rect.left = LVIR_ICON;
3455 rect.right = rect.top = rect.bottom = -1;
3456 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3457 expect(TRUE, r);
3458 /* padding */
3459 expect(2, rect.left);
3460 expect(2, rect.right);
3462 /* change order */
3463 order[0] = 1; order[1] = 0;
3464 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3465 expect(TRUE, r);
3466 pt.x = -1;
3467 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3468 expect(TRUE, r);
3469 /* 1 indexed column width + padding */
3470 expect(102, pt.x);
3471 /* rect is at zero too */
3472 rect.left = LVIR_BOUNDS;
3473 rect.right = rect.top = rect.bottom = -1;
3474 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3475 expect(TRUE, r);
3476 expect(0, rect.left);
3477 /* just width sum */
3478 expect(150, rect.right);
3480 rect.left = LVIR_SELECTBOUNDS;
3481 rect.right = rect.top = rect.bottom = -1;
3482 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3483 expect(TRUE, r);
3484 /* column width + padding */
3485 expect(102, rect.left);
3487 /* back to initial order */
3488 order[0] = 0; order[1] = 1;
3489 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3490 expect(TRUE, r);
3492 /* state icons */
3493 himl = ImageList_Create(16, 16, 0, 2, 2);
3494 ok(himl != NULL, "failed to create imagelist\n");
3495 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3496 ok(hbm != NULL, "failed to create bitmap\n");
3497 r = ImageList_Add(himl, hbm, 0);
3498 ok(r == 0, "should be zero\n");
3499 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3500 ok(hbm != NULL, "failed to create bitmap\n");
3501 r = ImageList_Add(himl, hbm, 0);
3502 ok(r == 1, "should be one\n");
3504 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3505 ok(r == 0, "should return zero\n");
3507 item.mask = LVIF_STATE;
3508 item.state = INDEXTOSTATEIMAGEMASK(1);
3509 item.stateMask = LVIS_STATEIMAGEMASK;
3510 item.iItem = 0;
3511 item.iSubItem = 0;
3512 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3513 expect(TRUE, r);
3515 /* icon bounds */
3516 rect.left = LVIR_ICON;
3517 rect.right = rect.top = rect.bottom = -1;
3518 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3519 expect(TRUE, r);
3520 /* padding + stateicon width */
3521 expect(18, rect.left);
3522 expect(18, rect.right);
3523 /* label bounds */
3524 rect.left = LVIR_LABEL;
3525 rect.right = rect.top = rect.bottom = -1;
3526 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3527 expect(TRUE, r);
3528 /* padding + stateicon width -> column width */
3529 expect(18, rect.left);
3530 expect(50, rect.right);
3532 himl_ret = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3533 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
3535 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3536 ok(r == 0, "should return zero\n");
3538 item.mask = LVIF_STATE | LVIF_IMAGE;
3539 item.iImage = 1;
3540 item.state = 0;
3541 item.stateMask = ~0;
3542 item.iItem = 0;
3543 item.iSubItem = 0;
3544 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3545 expect(TRUE, r);
3547 /* icon bounds */
3548 rect.left = LVIR_ICON;
3549 rect.right = rect.top = rect.bottom = -1;
3550 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3551 expect(TRUE, r);
3552 /* padding, icon width */
3553 expect(2, rect.left);
3554 expect(18, rect.right);
3555 /* label bounds */
3556 rect.left = LVIR_LABEL;
3557 rect.right = rect.top = rect.bottom = -1;
3558 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3559 expect(TRUE, r);
3560 /* padding + icon width -> column width */
3561 expect(18, rect.left);
3562 expect(50, rect.right);
3564 /* select bounds */
3565 rect.left = LVIR_SELECTBOUNDS;
3566 rect.right = rect.top = rect.bottom = -1;
3567 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3568 expect(TRUE, r);
3569 /* padding, column width */
3570 expect(2, rect.left);
3571 expect(50, rect.right);
3573 /* try with indentation */
3574 item.mask = LVIF_INDENT;
3575 item.iIndent = 1;
3576 item.iItem = 0;
3577 item.iSubItem = 0;
3578 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
3579 expect(TRUE, r);
3581 /* bounds */
3582 rect.left = LVIR_BOUNDS;
3583 rect.right = rect.top = rect.bottom = -1;
3584 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3585 expect(TRUE, r);
3586 /* padding + 1 icon width, column width */
3587 expect(0, rect.left);
3588 expect(150, rect.right);
3590 /* select bounds */
3591 rect.left = LVIR_SELECTBOUNDS;
3592 rect.right = rect.top = rect.bottom = -1;
3593 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3594 expect(TRUE, r);
3595 /* padding + 1 icon width, column width */
3596 expect(2 + 16, rect.left);
3597 expect(50, rect.right);
3599 /* label bounds */
3600 rect.left = LVIR_LABEL;
3601 rect.right = rect.top = rect.bottom = -1;
3602 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3603 expect(TRUE, r);
3604 /* padding + 2 icon widths, column width */
3605 expect(2 + 16*2, rect.left);
3606 expect(50, rect.right);
3608 /* icon bounds */
3609 rect.left = LVIR_ICON;
3610 rect.right = rect.top = rect.bottom = -1;
3611 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3612 expect(TRUE, r);
3613 /* padding + 1 icon width indentation, icon width */
3614 expect(2 + 16, rect.left);
3615 expect(34, rect.right);
3617 DestroyWindow(hwnd);
3620 static void test_editbox(void)
3622 static CHAR testitemA[] = "testitem";
3623 static CHAR testitem1A[] = "testitem_quitelongname";
3624 static CHAR testitem2A[] = "testITEM_quitelongname";
3625 static CHAR buffer[25];
3626 HWND hwnd, hwndedit, hwndedit2, header;
3627 LVITEMA item;
3628 DWORD r;
3630 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
3631 ok(hwnd != NULL, "failed to create a listview window\n");
3633 insert_column(hwnd, 0);
3635 memset(&item, 0, sizeof(item));
3636 item.mask = LVIF_TEXT;
3637 item.pszText = testitemA;
3638 item.iItem = 0;
3639 item.iSubItem = 0;
3640 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3641 expect(0, r);
3643 /* test notifications without edit created */
3644 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3645 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
3646 expect(0, r);
3647 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3648 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
3649 /* same thing but with valid window */
3650 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
3651 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
3652 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3653 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
3654 expect(0, r);
3655 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3656 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
3657 DestroyWindow(hwndedit);
3659 /* setting focus is necessary */
3660 SetFocus(hwnd);
3661 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3662 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3664 /* test children Z-order after Edit box created */
3665 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3666 ok(IsWindow(header), "Expected header to be created\n");
3667 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3668 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3670 /* modify initial string */
3671 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3672 expect(TRUE, r);
3674 /* edit window is resized and repositioned,
3675 check again for Z-order - it should be preserved */
3676 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
3677 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
3679 /* return focus to listview */
3680 SetFocus(hwnd);
3682 memset(&item, 0, sizeof(item));
3683 item.mask = LVIF_TEXT;
3684 item.pszText = buffer;
3685 item.cchTextMax = sizeof(buffer);
3686 item.iItem = 0;
3687 item.iSubItem = 0;
3688 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3689 expect(TRUE, r);
3691 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3693 /* send LVM_EDITLABEL on already created edit */
3694 SetFocus(hwnd);
3695 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3696 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3697 /* focus will be set to edit */
3698 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
3699 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3700 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
3702 /* creating label disabled when control isn't focused */
3703 SetFocus(0);
3704 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3705 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3707 /* check EN_KILLFOCUS handling */
3708 memset(&item, 0, sizeof(item));
3709 item.pszText = testitemA;
3710 item.iItem = 0;
3711 item.iSubItem = 0;
3712 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3713 expect(TRUE, r);
3715 SetFocus(hwnd);
3716 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3717 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3718 /* modify edit and notify control that it lost focus */
3719 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3720 expect(TRUE, r);
3721 g_editbox_disp_info.item.pszText = NULL;
3722 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3723 expect(0, r);
3724 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
3726 memset(&item, 0, sizeof(item));
3727 item.pszText = buffer;
3728 item.cchTextMax = sizeof(buffer);
3729 item.iItem = 0;
3730 item.iSubItem = 0;
3731 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3732 expect(lstrlen(item.pszText), r);
3733 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3734 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
3736 /* change item name to differ in casing only */
3737 SetFocus(hwnd);
3738 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3739 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3740 /* modify edit and notify control that it lost focus */
3741 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
3742 expect(TRUE, r);
3743 g_editbox_disp_info.item.pszText = NULL;
3744 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3745 expect(0, r);
3746 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
3748 memset(&item, 0, sizeof(item));
3749 item.pszText = buffer;
3750 item.cchTextMax = sizeof(buffer);
3751 item.iItem = 0;
3752 item.iSubItem = 0;
3753 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3754 expect(lstrlen(item.pszText), r);
3755 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
3756 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
3758 /* end edit without saving */
3759 SetFocus(hwnd);
3760 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3761 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3762 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3763 expect(0, r);
3764 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3765 "edit box - end edit, no change, escape", TRUE);
3766 /* end edit with saving */
3767 SetFocus(hwnd);
3768 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3769 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3770 r = SendMessage(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
3771 expect(0, r);
3772 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3773 "edit box - end edit, no change, return", TRUE);
3775 memset(&item, 0, sizeof(item));
3776 item.pszText = buffer;
3777 item.cchTextMax = sizeof(buffer);
3778 item.iItem = 0;
3779 item.iSubItem = 0;
3780 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3781 expect(lstrlen(item.pszText), r);
3782 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
3784 /* LVM_EDITLABEL with -1 destroys current edit */
3785 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3786 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3787 /* no edit present */
3788 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3789 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3790 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3791 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3792 /* edit present */
3793 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3794 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3795 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3796 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3797 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3798 /* check another negative value */
3799 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3800 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3801 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3802 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3803 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3804 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3805 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3806 /* and value greater than max item index */
3807 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3808 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3809 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3810 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3811 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3812 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3813 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3814 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3816 /* messaging tests */
3817 SetFocus(hwnd);
3818 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3819 blockEdit = FALSE;
3820 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3821 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3822 /* testing only sizing messages */
3823 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3824 "edit box create - sizing", FALSE);
3826 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
3827 SetFocus(hwnd);
3828 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3829 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3830 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3831 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3832 expect(0, r);
3833 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
3834 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
3836 DestroyWindow(hwnd);
3839 static void test_notifyformat(void)
3841 HWND hwnd, header;
3842 DWORD r;
3844 hwnd = create_listview_control(LVS_REPORT);
3845 ok(hwnd != NULL, "failed to create a listview window\n");
3847 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
3848 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
3849 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3850 expect(0, r);
3851 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3852 /* set */
3853 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
3854 expect(0, r);
3855 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3856 if (r == 1)
3858 r = SendMessage(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
3859 expect(1, r);
3860 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3861 expect(0, r);
3863 else
3865 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
3866 DestroyWindow(hwnd);
3867 return;
3870 DestroyWindow(hwnd);
3872 /* test failure in parent WM_NOTIFYFORMAT */
3873 notifyFormat = 0;
3874 hwnd = create_listview_control(LVS_REPORT);
3875 ok(hwnd != NULL, "failed to create a listview window\n");
3876 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3877 ok(IsWindow(header), "expected header to be created\n");
3878 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3879 expect(0, r);
3880 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3881 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3882 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
3883 ok(r != 0, "Expected valid format\n");
3885 notifyFormat = NFR_UNICODE;
3886 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3887 expect(NFR_UNICODE, r);
3888 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3889 expect(1, r);
3890 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3891 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3893 notifyFormat = NFR_ANSI;
3894 r = SendMessage(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
3895 expect(NFR_ANSI, r);
3896 r = SendMessage(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3897 expect(0, r);
3898 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3899 ok( r == 1 || broken(r == 0), /* win9x */ "Expected 1, got %d\n", r );
3901 DestroyWindow(hwnd);
3903 /* try different unicode window combination and defaults */
3904 if (!GetModuleHandleW(NULL))
3906 win_skip("Additional notify format tests are incompatible with Win9x\n");
3907 return;
3910 hwndparentW = create_parent_window(TRUE);
3911 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
3912 if (!IsWindow(hwndparentW)) return;
3914 notifyFormat = -1;
3915 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3916 ok(hwnd != NULL, "failed to create a listview window\n");
3917 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3918 ok(IsWindow(header), "expected header to be created\n");
3919 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3920 expect(1, r);
3921 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3922 expect(1, r);
3923 DestroyWindow(hwnd);
3924 /* receiving error code defaulting to ansi */
3925 notifyFormat = 0;
3926 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3927 ok(hwnd != NULL, "failed to create a listview window\n");
3928 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3929 ok(IsWindow(header), "expected header to be created\n");
3930 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3931 expect(0, r);
3932 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3933 expect(1, r);
3934 DestroyWindow(hwnd);
3935 /* receiving ansi code from unicode window, use it */
3936 notifyFormat = NFR_ANSI;
3937 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
3938 ok(hwnd != NULL, "failed to create a listview window\n");
3939 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3940 ok(IsWindow(header), "expected header to be created\n");
3941 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3942 expect(0, r);
3943 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3944 expect(1, r);
3945 DestroyWindow(hwnd);
3946 /* unicode listview with ansi parent window */
3947 notifyFormat = -1;
3948 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3949 ok(hwnd != NULL, "failed to create a listview window\n");
3950 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3951 ok(IsWindow(header), "expected header to be created\n");
3952 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3953 expect(0, r);
3954 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3955 expect(1, r);
3956 DestroyWindow(hwnd);
3957 /* unicode listview with ansi parent window, return error code */
3958 notifyFormat = 0;
3959 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
3960 ok(hwnd != NULL, "failed to create a listview window\n");
3961 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
3962 ok(IsWindow(header), "expected header to be created\n");
3963 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
3964 expect(0, r);
3965 r = SendMessage(header, HDM_GETUNICODEFORMAT, 0, 0);
3966 expect(1, r);
3967 DestroyWindow(hwnd);
3969 DestroyWindow(hwndparentW);
3972 static void test_indentation(void)
3974 HWND hwnd;
3975 LVITEMA item;
3976 DWORD r;
3978 hwnd = create_listview_control(LVS_REPORT);
3979 ok(hwnd != NULL, "failed to create a listview window\n");
3981 memset(&item, 0, sizeof(item));
3982 item.mask = LVIF_INDENT;
3983 item.iItem = 0;
3984 item.iIndent = I_INDENTCALLBACK;
3985 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3986 expect(0, r);
3988 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3990 item.iItem = 0;
3991 item.mask = LVIF_INDENT;
3992 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
3993 expect(TRUE, r);
3995 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3996 "get indent dispinfo", FALSE);
3998 DestroyWindow(hwnd);
4001 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
4003 return 0;
4006 static BOOL is_below_comctl_5(void)
4008 HWND hwnd;
4009 BOOL ret;
4011 hwnd = create_listview_control(LVS_REPORT);
4012 ok(hwnd != NULL, "failed to create a listview window\n");
4013 insert_item(hwnd, 0);
4015 ret = SendMessage(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
4017 DestroyWindow(hwnd);
4019 return !ret;
4022 static void test_get_set_view(void)
4024 HWND hwnd;
4025 DWORD ret;
4026 DWORD_PTR style;
4028 /* test style->view mapping */
4029 hwnd = create_listview_control(LVS_REPORT);
4030 ok(hwnd != NULL, "failed to create a listview window\n");
4032 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4033 expect(LV_VIEW_DETAILS, ret);
4035 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4036 /* LVS_ICON == 0 */
4037 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4038 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4039 expect(LV_VIEW_ICON, ret);
4041 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4042 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4043 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4044 expect(LV_VIEW_SMALLICON, ret);
4046 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4047 SetWindowLongPtr(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4048 ret = SendMessage(hwnd, LVM_GETVIEW, 0, 0);
4049 expect(LV_VIEW_LIST, ret);
4051 /* switching view doesn't touch window style */
4052 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4053 expect(1, ret);
4054 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4055 ok(style & LVS_LIST, "Expected style to be preserved\n");
4056 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4057 expect(1, ret);
4058 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4059 ok(style & LVS_LIST, "Expected style to be preserved\n");
4060 ret = SendMessage(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4061 expect(1, ret);
4062 style = GetWindowLongPtr(hwnd, GWL_STYLE);
4063 ok(style & LVS_LIST, "Expected style to be preserved\n");
4065 DestroyWindow(hwnd);
4068 static void test_canceleditlabel(void)
4070 HWND hwnd, hwndedit;
4071 DWORD ret;
4072 CHAR buff[10];
4073 LVITEMA itema;
4074 static CHAR test[] = "test";
4075 static const CHAR test1[] = "test1";
4077 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4078 ok(hwnd != NULL, "failed to create a listview window\n");
4080 insert_item(hwnd, 0);
4082 /* try without edit created */
4083 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4084 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4085 expect(TRUE, ret);
4086 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4087 "cancel edit label without edit", FALSE);
4089 /* cancel without data change */
4090 SetFocus(hwnd);
4091 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4092 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4093 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4094 expect(TRUE, ret);
4095 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4097 /* cancel after data change */
4098 memset(&itema, 0, sizeof(itema));
4099 itema.pszText = test;
4100 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4101 expect(TRUE, ret);
4102 SetFocus(hwnd);
4103 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
4104 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4105 ret = SetWindowText(hwndedit, test1);
4106 ok(ret == 1, "Expected edit text to change\n");
4107 ret = SendMessage(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4108 expect(TRUE, ret);
4109 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4110 memset(&itema, 0, sizeof(itema));
4111 itema.pszText = buff;
4112 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4113 ret = SendMessage(hwnd, LVM_GETITEMTEXT, 0, (LPARAM)&itema);
4114 expect(5, ret);
4115 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4117 DestroyWindow(hwnd);
4120 static void test_mapidindex(void)
4122 HWND hwnd;
4123 DWORD ret;
4125 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4126 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4127 ok(hwnd != NULL, "failed to create a listview window\n");
4128 insert_item(hwnd, 0);
4129 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4130 expect(-1, ret);
4131 DestroyWindow(hwnd);
4133 hwnd = create_listview_control(LVS_REPORT);
4134 ok(hwnd != NULL, "failed to create a listview window\n");
4136 /* LVM_MAPINDEXTOID with invalid index */
4137 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4138 expect(-1, ret);
4140 insert_item(hwnd, 0);
4141 insert_item(hwnd, 1);
4143 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, -1, 0);
4144 expect(-1, ret);
4145 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 2, 0);
4146 expect(-1, ret);
4148 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4149 expect(0, ret);
4150 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4151 expect(1, ret);
4152 /* remove 0 indexed item, id retained */
4153 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
4154 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 0, 0);
4155 expect(1, ret);
4156 /* new id starts from previous value */
4157 insert_item(hwnd, 1);
4158 ret = SendMessage(hwnd, LVM_MAPINDEXTOID, 1, 0);
4159 expect(2, ret);
4161 /* get index by id */
4162 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4163 expect(-1, ret);
4164 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4165 expect(-1, ret);
4166 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4167 expect(0, ret);
4168 ret = SendMessage(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4169 expect(1, ret);
4171 DestroyWindow(hwnd);
4174 static void test_getitemspacing(void)
4176 HWND hwnd;
4177 DWORD ret;
4178 INT cx, cy;
4179 HIMAGELIST himl;
4180 HBITMAP hbmp;
4181 LVITEMA itema;
4183 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4184 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4186 /* LVS_ICON */
4187 hwnd = create_listview_control(LVS_ICON);
4188 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4189 todo_wine {
4190 expect(cx, LOWORD(ret));
4191 expect(cy, HIWORD(ret));
4193 /* now try with icons */
4194 himl = ImageList_Create(40, 40, 0, 4, 4);
4195 ok(himl != NULL, "failed to create imagelist\n");
4196 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4197 ok(hbmp != NULL, "failed to create bitmap\n");
4198 ret = ImageList_Add(himl, hbmp, 0);
4199 expect(0, ret);
4200 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4201 expect(0, ret);
4203 itema.mask = LVIF_IMAGE;
4204 itema.iImage = 0;
4205 itema.iItem = 0;
4206 itema.iSubItem = 0;
4207 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4208 expect(0, ret);
4209 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4210 todo_wine {
4211 /* spacing + icon size returned */
4212 expect(cx + 40, LOWORD(ret));
4213 expect(cy + 40, HIWORD(ret));
4215 DestroyWindow(hwnd);
4216 /* LVS_SMALLICON */
4217 hwnd = create_listview_control(LVS_SMALLICON);
4218 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4219 todo_wine {
4220 expect(cx, LOWORD(ret));
4221 expect(cy, HIWORD(ret));
4223 DestroyWindow(hwnd);
4224 /* LVS_REPORT */
4225 hwnd = create_listview_control(LVS_REPORT);
4226 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4227 todo_wine {
4228 expect(cx, LOWORD(ret));
4229 expect(cy, HIWORD(ret));
4231 DestroyWindow(hwnd);
4232 /* LVS_LIST */
4233 hwnd = create_listview_control(LVS_LIST);
4234 ret = SendMessage(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4235 todo_wine {
4236 expect(cx, LOWORD(ret));
4237 expect(cy, HIWORD(ret));
4239 DestroyWindow(hwnd);
4242 static void test_getcolumnwidth(void)
4244 HWND hwnd;
4245 DWORD ret;
4246 DWORD_PTR style;
4247 LVCOLUMNA col;
4248 LVITEMA itema;
4249 HDC hdc;
4251 /* default column width */
4252 hwnd = create_listview_control(LVS_ICON);
4253 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4254 expect(0, ret);
4255 style = GetWindowLong(hwnd, GWL_STYLE);
4256 SetWindowLong(hwnd, GWL_STYLE, style | LVS_LIST);
4257 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4258 todo_wine expect(8, ret);
4259 style = GetWindowLong(hwnd, GWL_STYLE) & ~LVS_LIST;
4260 SetWindowLong(hwnd, GWL_STYLE, style | LVS_REPORT);
4261 col.mask = 0;
4262 ret = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4263 expect(0, ret);
4264 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4265 expect(10, ret);
4266 DestroyWindow(hwnd);
4268 /* default column width with item added */
4269 hwnd = create_listview_control(LVS_LIST);
4270 memset(&itema, 0, sizeof(itema));
4271 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4272 ret = SendMessage(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4273 hdc = GetDC(hwnd);
4274 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, ret);
4275 ReleaseDC(hwnd, hdc);
4276 DestroyWindow(hwnd);
4279 static void test_scrollnotify(void)
4281 HWND hwnd;
4282 DWORD ret;
4284 hwnd = create_listview_control(LVS_REPORT);
4286 insert_column(hwnd, 0);
4287 insert_column(hwnd, 1);
4288 insert_item(hwnd, 0);
4290 /* make it scrollable - resize */
4291 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4292 expect(TRUE, ret);
4293 ret = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4294 expect(TRUE, ret);
4296 /* try with dummy call */
4297 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4298 ret = SendMessage(hwnd, LVM_SCROLL, 0, 0);
4299 expect(TRUE, ret);
4300 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4301 "scroll notify 1", TRUE);
4303 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4304 ret = SendMessage(hwnd, LVM_SCROLL, 1, 0);
4305 expect(TRUE, ret);
4306 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4307 "scroll notify 2", TRUE);
4309 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4310 ret = SendMessage(hwnd, LVM_SCROLL, 1, 1);
4311 expect(TRUE, ret);
4312 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4313 "scroll notify 3", TRUE);
4315 DestroyWindow(hwnd);
4318 static void test_LVS_EX_TRANSPARENTBKGND(void)
4320 HWND hwnd;
4321 DWORD ret;
4322 HDC hdc;
4324 hwnd = create_listview_control(LVS_REPORT);
4326 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4327 expect(TRUE, ret);
4329 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4330 LVS_EX_TRANSPARENTBKGND);
4332 ret = SendMessage(hwnd, LVM_GETBKCOLOR, 0, 0);
4333 if (ret != CLR_NONE)
4335 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4336 DestroyWindow(hwnd);
4337 return;
4340 /* try to set some back color and check this style bit */
4341 ret = SendMessage(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4342 expect(TRUE, ret);
4343 ret = SendMessage(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4344 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4346 /* now test what this style actually does */
4347 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4348 LVS_EX_TRANSPARENTBKGND);
4350 hdc = GetWindowDC(hwndparent);
4352 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4353 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4354 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4355 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4357 ReleaseDC(hwndparent, hdc);
4359 DestroyWindow(hwnd);
4362 static void test_approximate_viewrect(void)
4364 HWND hwnd;
4365 DWORD ret;
4366 HIMAGELIST himl;
4367 HBITMAP hbmp;
4368 LVITEMA itema;
4369 static CHAR test[] = "abracadabra, a very long item label";
4371 hwnd = create_listview_control(LVS_ICON);
4372 himl = ImageList_Create(40, 40, 0, 4, 4);
4373 ok(himl != NULL, "failed to create imagelist\n");
4374 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4375 ok(hbmp != NULL, "failed to create bitmap\n");
4376 ret = ImageList_Add(himl, hbmp, 0);
4377 expect(0, ret);
4378 ret = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4379 expect(0, ret);
4381 itema.mask = LVIF_IMAGE;
4382 itema.iImage = 0;
4383 itema.iItem = 0;
4384 itema.iSubItem = 0;
4385 ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&itema);
4386 expect(0, ret);
4388 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4389 if (ret == 0)
4391 /* version 4.0 */
4392 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4393 return;
4396 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4397 ok(MAKELONG(77,827)==ret,"Incorrect Approximate rect\n");
4399 ret = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4400 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4401 ok(MAKELONG(102,302)==ret,"Incorrect Approximate rect\n");
4403 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4404 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4406 itema.pszText = test;
4407 ret = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&itema);
4408 expect(TRUE, ret);
4409 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4410 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4412 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4413 ok(MAKELONG(52,2)==ret,"Incorrect Approximate rect\n");
4414 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4415 ok(MAKELONG(52,52)==ret,"Incorrect Approximate rect\n");
4416 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4417 ok(MAKELONG(102,52)==ret,"Incorrect Approximate rect\n");
4418 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4419 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4420 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4421 ok(MAKELONG(102,102)==ret,"Incorrect Approximate rect\n");
4422 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4423 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4424 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4425 ok(MAKELONG(102,152)==ret,"Incorrect Approximate rect\n");
4426 ret = SendMessage(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4427 ok(MAKELONG(152,152)==ret,"Incorrect Approximate rect\n");
4429 DestroyWindow(hwnd);
4432 static void test_finditem(void)
4434 LVFINDINFOA fi;
4435 static char f[5];
4436 HWND hwnd;
4437 DWORD r;
4439 hwnd = create_listview_control(LVS_REPORT);
4440 insert_item(hwnd, 0);
4442 memset(&fi, 0, sizeof(fi));
4444 /* full string search, inserted text was "foo" */
4445 strcpy(f, "foo");
4446 fi.flags = LVFI_STRING;
4447 fi.psz = f;
4448 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4449 expect(0, r);
4450 /* partial string search, inserted text was "foo" */
4451 strcpy(f, "fo");
4452 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4453 fi.psz = f;
4454 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4455 expect(0, r);
4456 /* partial string search, part after start char */
4457 strcpy(f, "oo");
4458 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4459 fi.psz = f;
4460 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4461 expect(-1, r);
4463 /* try with LVFI_SUBSTRING */
4464 strcpy(f, "fo");
4465 fi.flags = LVFI_SUBSTRING;
4466 fi.psz = f;
4467 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4468 if (r == -1)
4470 win_skip("LVFI_SUBSTRING not supported\n");
4471 DestroyWindow(hwnd);
4472 return;
4474 expect(0, r);
4475 strcpy(f, "f");
4476 fi.flags = LVFI_SUBSTRING;
4477 fi.psz = f;
4478 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4479 expect(0, r);
4480 strcpy(f, "o");
4481 fi.flags = LVFI_SUBSTRING;
4482 fi.psz = f;
4483 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4484 expect(-1, r);
4486 strcpy(f, "f");
4487 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
4488 fi.psz = f;
4489 r = SendMessage(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4490 expect(0, r);
4492 DestroyWindow(hwnd);
4495 static void test_LVS_EX_HEADERINALLVIEWS(void)
4497 HWND hwnd, header;
4498 DWORD style;
4500 hwnd = create_listview_control(LVS_ICON);
4502 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4503 LVS_EX_HEADERINALLVIEWS);
4505 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4506 if (!IsWindow(header))
4508 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
4509 DestroyWindow(hwnd);
4510 return;
4513 /* LVS_NOCOLUMNHEADER works as before */
4514 style = GetWindowLongA(hwnd, GWL_STYLE);
4515 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
4516 style = GetWindowLongA(header, GWL_STYLE);
4517 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
4518 style = GetWindowLongA(hwnd, GWL_STYLE);
4519 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
4520 style = GetWindowLongA(header, GWL_STYLE);
4521 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
4523 /* try to remove style */
4524 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
4525 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4526 ok(IsWindow(header), "Expected header to be created\n");
4527 style = GetWindowLongA(header, GWL_STYLE);
4528 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
4530 DestroyWindow(hwnd);
4532 /* check other styles */
4533 hwnd = create_listview_control(LVS_LIST);
4534 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4535 LVS_EX_HEADERINALLVIEWS);
4536 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4537 ok(IsWindow(header), "Expected header to be created\n");
4538 DestroyWindow(hwnd);
4540 hwnd = create_listview_control(LVS_SMALLICON);
4541 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4542 LVS_EX_HEADERINALLVIEWS);
4543 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4544 ok(IsWindow(header), "Expected header to be created\n");
4545 DestroyWindow(hwnd);
4547 hwnd = create_listview_control(LVS_REPORT);
4548 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
4549 LVS_EX_HEADERINALLVIEWS);
4550 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
4551 ok(IsWindow(header), "Expected header to be created\n");
4552 DestroyWindow(hwnd);
4555 static void test_hover(void)
4557 HWND hwnd;
4558 DWORD r;
4560 hwnd = create_listview_control(LVS_ICON);
4562 /* test WM_MOUSEHOVER forwarding */
4563 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4564 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4565 expect(0, r);
4566 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
4567 g_block_hover = TRUE;
4568 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4569 r = SendMessage(hwnd, WM_MOUSEHOVER, 0, 0);
4570 expect(0, r);
4571 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
4572 g_block_hover = FALSE;
4574 r = SendMessage(hwnd, LVM_SETHOVERTIME, 0, 500);
4575 expect(HOVER_DEFAULT, r);
4576 r = SendMessage(hwnd, LVM_GETHOVERTIME, 0, 0);
4577 expect(500, r);
4579 DestroyWindow(hwnd);
4582 static void test_destroynotify(void)
4584 HWND hwnd;
4586 hwnd = create_listview_control(LVS_REPORT);
4587 ok(hwnd != NULL, "failed to create listview window\n");
4589 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4590 DestroyWindow(hwnd);
4591 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
4594 static void test_header_notification(void)
4596 HWND list, header;
4597 HDITEMA item;
4598 NMHEADER nmh;
4599 LVCOLUMNA col;
4600 LRESULT ret;
4602 list = create_listview_control(LVS_REPORT);
4603 ok(list != NULL, "failed to create listview window\n");
4605 memset(&col, 0, sizeof(col));
4606 col.mask = LVCF_WIDTH;
4607 col.cx = 100;
4608 ret = SendMessage(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4609 ok(!ret, "expected 0, got %ld\n", ret);
4611 header = subclass_header(list);
4613 ret = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
4614 ok(ret == 1, "expected header item count 1, got %ld\n", ret);
4616 memset(&item, 0, sizeof(item));
4617 item.mask = HDI_WIDTH;
4618 ret = SendMessage(header, HDM_GETITEMA, 0, (LPARAM)&item);
4619 ok(ret, "HDM_GETITEM failed\n");
4620 ok(item.cxy == 100, "expected 100, got %d\n", item.cxy);
4622 nmh.hdr.hwndFrom = header;
4623 nmh.hdr.idFrom = GetWindowLongPtr(header, GWLP_ID);
4624 nmh.hdr.code = HDN_ITEMCHANGEDA;
4625 nmh.iItem = 0;
4626 nmh.iButton = 0;
4627 item.mask = HDI_WIDTH;
4628 item.cxy = 50;
4629 nmh.pitem = &item;
4630 ret = SendMessage(list, WM_NOTIFY, 0, (LPARAM)&nmh);
4631 ok(!ret, "WM_NOTIFY/HDN_ITEMCHANGED failed\n");
4633 DestroyWindow(list);
4636 static void test_createdragimage(void)
4638 HIMAGELIST himl;
4639 POINT pt;
4640 HWND list;
4642 list = create_listview_control(LVS_ICON);
4643 ok(list != NULL, "failed to create listview window\n");
4645 insert_item(list, 0);
4647 /* NULL point */
4648 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
4649 ok(himl == NULL, "got %p\n", himl);
4651 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
4652 ok(himl != NULL, "got %p\n", himl);
4653 ImageList_Destroy(himl);
4655 DestroyWindow(list);
4658 static void test_dispinfo(void)
4660 static const char testA[] = "TEST";
4661 WCHAR buff[10];
4662 LVITEMA item;
4663 HWND hwnd;
4664 INT ret;
4666 hwnd = create_listview_control(LVS_ICON);
4667 ok(hwnd != NULL, "failed to create listview window\n");
4669 insert_item(hwnd, 0);
4671 memset(&item, 0, sizeof(item));
4672 item.pszText = LPSTR_TEXTCALLBACKA;
4673 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4674 ok(ret, "got %d\n", ret);
4676 g_disp_A_to_W = TRUE;
4677 item.pszText = (char*)buff;
4678 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
4679 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4680 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
4681 g_disp_A_to_W = FALSE;
4683 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
4684 "got %s, expected %s\n", item.pszText, testA);
4686 DestroyWindow(hwnd);
4689 START_TEST(listview)
4691 HMODULE hComctl32;
4692 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
4694 ULONG_PTR ctx_cookie;
4695 HANDLE hCtx;
4696 HWND hwnd;
4698 hComctl32 = GetModuleHandleA("comctl32.dll");
4699 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
4700 if (pInitCommonControlsEx)
4702 INITCOMMONCONTROLSEX iccex;
4703 iccex.dwSize = sizeof(iccex);
4704 iccex.dwICC = ICC_LISTVIEW_CLASSES;
4705 pInitCommonControlsEx(&iccex);
4707 else
4708 InitCommonControls();
4710 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
4712 hwndparent = create_parent_window(FALSE);
4713 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4715 g_is_below_5 = is_below_comctl_5();
4717 test_header_notification();
4718 test_images();
4719 test_checkboxes();
4720 test_items();
4721 test_create();
4722 test_redraw();
4723 test_customdraw();
4724 test_icon_spacing();
4725 test_color();
4726 test_item_count();
4727 test_item_position();
4728 test_columns();
4729 test_getorigin();
4730 test_multiselect();
4731 test_getitemrect();
4732 test_subitem_rect();
4733 test_sorting();
4734 test_ownerdata();
4735 test_norecompute();
4736 test_nosortheader();
4737 test_setredraw();
4738 test_hittest();
4739 test_getviewrect();
4740 test_getitemposition();
4741 test_columnscreation();
4742 test_editbox();
4743 test_notifyformat();
4744 test_indentation();
4745 test_getitemspacing();
4746 test_getcolumnwidth();
4747 test_approximate_viewrect();
4748 test_finditem();
4749 test_hover();
4750 test_destroynotify();
4751 test_createdragimage();
4752 test_dispinfo();
4754 if (!load_v6_module(&ctx_cookie, &hCtx))
4756 DestroyWindow(hwndparent);
4757 return;
4760 /* this is a XP SP3 failure workaround */
4761 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
4762 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
4763 0, 0, 100, 100,
4764 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
4765 if (!IsWindow(hwnd))
4767 win_skip("FIXME: failed to create ListView window.\n");
4768 unload_v6_module(ctx_cookie, hCtx);
4769 DestroyWindow(hwndparent);
4770 return;
4772 else
4773 DestroyWindow(hwnd);
4775 /* comctl32 version 6 tests start here */
4776 test_get_set_view();
4777 test_canceleditlabel();
4778 test_mapidindex();
4779 test_scrollnotify();
4780 test_LVS_EX_TRANSPARENTBKGND();
4781 test_LVS_EX_HEADERINALLVIEWS();
4783 unload_v6_module(ctx_cookie, hCtx);
4785 DestroyWindow(hwndparent);