4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
29 #define PARENT_SEQ_INDEX 0
30 #define PARENT_FULL_SEQ_INDEX 1
31 #define LISTVIEW_SEQ_INDEX 2
32 #define EDITBOX_SEQ_INDEX 3
33 #define NUM_MSG_SEQUENCES 4
38 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
39 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
40 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
43 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
45 static HWND subclass_editbox(HWND hwndListview);
47 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
49 static const struct message create_parent_wnd_seq[] = {
50 { WM_GETMINMAXINFO, sent },
51 { WM_NCCREATE, sent },
52 { WM_NCCALCSIZE, sent|wparam, 0 },
54 { WM_SHOWWINDOW, sent|wparam, 1 },
55 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
56 { WM_QUERYNEWPALETTE, sent|optional },
57 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
58 { WM_WINDOWPOSCHANGED, sent|optional },
59 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
60 { WM_ACTIVATEAPP, sent|wparam, 1 },
61 { WM_NCACTIVATE, sent|wparam, 1 },
62 { WM_ACTIVATE, sent|wparam, 1 },
63 { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
64 { WM_IME_NOTIFY, sent|defwinproc|optional },
65 { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
66 /* Win9x adds SWP_NOZORDER below */
67 { WM_WINDOWPOSCHANGED, sent, /*|wparam, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE*/ },
68 { WM_NCCALCSIZE, sent|wparam|optional, 1 },
74 static const struct message redraw_listview_seq[] = {
75 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
76 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
77 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
78 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, HEADER_ID },
79 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
80 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
81 { WM_ERASEBKGND, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
85 static const struct message listview_icon_spacing_seq[] = {
86 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
87 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
88 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
92 static const struct message listview_color_seq[] = {
93 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
94 { LVM_GETBKCOLOR, sent },
95 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
96 { LVM_GETTEXTCOLOR, sent },
97 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
98 { LVM_GETTEXTBKCOLOR, sent },
100 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
101 { LVM_GETBKCOLOR, sent },
102 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
103 { LVM_GETTEXTCOLOR, sent },
104 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
105 { LVM_GETTEXTBKCOLOR, sent },
107 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
108 { LVM_GETBKCOLOR, sent },
109 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
110 { LVM_GETTEXTCOLOR, sent },
111 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
112 { LVM_GETTEXTBKCOLOR, sent },
114 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
115 { LVM_GETBKCOLOR, sent },
116 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
117 { LVM_GETTEXTCOLOR, sent },
118 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
119 { LVM_GETTEXTBKCOLOR, sent },
123 static const struct message listview_item_count_seq[] = {
124 { LVM_GETITEMCOUNT, sent },
125 { LVM_INSERTITEM, sent },
126 { LVM_INSERTITEM, sent },
127 { LVM_INSERTITEM, sent },
128 { LVM_GETITEMCOUNT, sent },
129 { LVM_DELETEITEM, sent|wparam, 2 },
130 { LVM_GETITEMCOUNT, sent },
131 { LVM_DELETEALLITEMS, sent },
132 { LVM_GETITEMCOUNT, sent },
133 { LVM_INSERTITEM, sent },
134 { LVM_INSERTITEM, sent },
135 { LVM_GETITEMCOUNT, sent },
136 { LVM_INSERTITEM, sent },
137 { LVM_GETITEMCOUNT, sent },
141 static const struct message listview_itempos_seq[] = {
142 { LVM_INSERTITEM, sent },
143 { LVM_INSERTITEM, sent },
144 { LVM_INSERTITEM, sent },
145 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
146 { LVM_GETITEMPOSITION, sent|wparam, 1 },
147 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
148 { LVM_GETITEMPOSITION, sent|wparam, 2 },
149 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
150 { LVM_GETITEMPOSITION, sent|wparam, 0 },
154 static const struct message listview_ownerdata_switchto_seq[] = {
155 { WM_STYLECHANGING, sent },
156 { WM_STYLECHANGED, sent },
160 static const struct message listview_getorderarray_seq[] = {
161 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
162 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
166 static const struct message empty_seq[] = {
170 static const struct message forward_erasebkgnd_parent_seq[] = {
171 { WM_ERASEBKGND, sent },
175 static const struct message ownderdata_select_focus_parent_seq[] = {
176 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
177 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
181 static const struct message textcallback_set_again_parent_seq[] = {
182 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
183 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
187 static const struct message single_getdispinfo_parent_seq[] = {
188 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
192 static const struct message getitemposition_seq1[] = {
193 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
197 static const struct message getitemposition_seq2[] = {
198 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
199 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
203 static const struct message editbox_create_pos[] = {
204 /* sequence sent after LVN_BEGINLABELEDIT */
205 { WM_WINDOWPOSCHANGING, sent },
206 { WM_NCCALCSIZE, sent },
207 { WM_WINDOWPOSCHANGED, sent },
208 { WM_MOVE, sent|defwinproc },
209 { WM_SIZE, sent|defwinproc },
210 /* the rest is todo */
211 { WM_WINDOWPOSCHANGING, sent },
212 { WM_WINDOWPOSCHANGED, sent },
221 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
223 static LONG defwndproc_counter = 0;
227 msg.message = message;
228 msg.flags = sent|wparam|lparam;
229 if (defwndproc_counter) msg.flags |= defwinproc;
232 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
234 /* log system messages, except for painting */
235 if (message < WM_USER &&
236 message != WM_PAINT &&
237 message != WM_ERASEBKGND &&
238 message != WM_NCPAINT &&
239 message != WM_NCHITTEST &&
240 message != WM_GETTEXT &&
241 message != WM_GETICON &&
242 message != WM_DEVICECHANGE)
244 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
246 add_message(sequences, PARENT_SEQ_INDEX, &msg);
248 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
250 if (message == WM_NOTIFY && lParam)
252 switch (((NMHDR*)lParam)->code)
254 case LVN_BEGINLABELEDIT:
255 /* subclass edit box */
257 subclass_editbox(((NMHDR*)lParam)->hwndFrom);
261 case LVN_ENDLABELEDIT:
262 /* always accept new item text */
267 defwndproc_counter++;
268 ret = DefWindowProcA(hwnd, message, wParam, lParam);
269 defwndproc_counter--;
274 static BOOL register_parent_wnd_class(void)
279 cls.lpfnWndProc = parent_wnd_proc;
282 cls.hInstance = GetModuleHandleA(NULL);
284 cls.hCursor = LoadCursorA(0, IDC_ARROW);
285 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
286 cls.lpszMenuName = NULL;
287 cls.lpszClassName = "Listview test parent class";
288 return RegisterClassA(&cls);
291 static HWND create_parent_window(void)
293 if (!register_parent_wnd_class())
298 return CreateWindowEx(0, "Listview test parent class",
299 "Listview test parent window",
300 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
301 WS_MAXIMIZEBOX | WS_VISIBLE,
303 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
306 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
308 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
309 static LONG defwndproc_counter = 0;
313 trace("listview: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
315 /* some debug output for style changing */
316 if ((message == WM_STYLECHANGING ||
317 message == WM_STYLECHANGED) && lParam)
319 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
320 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
323 msg.message = message;
324 msg.flags = sent|wparam|lparam;
325 if (defwndproc_counter) msg.flags |= defwinproc;
328 msg.id = LISTVIEW_ID;
329 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
331 defwndproc_counter++;
332 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
333 defwndproc_counter--;
337 static HWND create_listview_control(DWORD style)
339 struct subclass_info *info;
343 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
347 GetClientRect(hwndparent, &rect);
348 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
349 WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT | style,
350 0, 0, rect.right, rect.bottom,
351 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
352 ok(hwnd != NULL, "gle=%d\n", GetLastError());
356 HeapFree(GetProcessHeap(), 0, info);
360 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
361 (LONG_PTR)listview_subclass_proc);
362 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
367 static HWND create_custom_listview_control(DWORD style)
369 struct subclass_info *info;
373 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
377 GetClientRect(hwndparent, &rect);
378 hwnd = CreateWindowExA(0, WC_LISTVIEW, "foo",
379 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
380 0, 0, rect.right, rect.bottom,
381 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
382 ok(hwnd != NULL, "gle=%d\n", GetLastError());
386 HeapFree(GetProcessHeap(), 0, info);
390 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
391 (LONG_PTR)listview_subclass_proc);
392 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
397 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
399 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
400 static LONG defwndproc_counter = 0;
404 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
406 msg.message = message;
407 msg.flags = sent|wparam|lparam;
408 if (defwndproc_counter) msg.flags |= defwinproc;
412 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
414 defwndproc_counter++;
415 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
416 defwndproc_counter--;
420 static HWND subclass_header(HWND hwndListview)
422 struct subclass_info *info;
425 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
429 hwnd = ListView_GetHeader(hwndListview);
430 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
431 (LONG_PTR)header_subclass_proc);
432 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
437 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
439 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
440 static LONG defwndproc_counter = 0;
444 msg.message = message;
445 msg.flags = sent|wparam|lparam;
446 if (defwndproc_counter) msg.flags |= defwinproc;
450 /* all we need is sizing */
451 if (message == WM_WINDOWPOSCHANGING ||
452 message == WM_NCCALCSIZE ||
453 message == WM_WINDOWPOSCHANGED ||
454 message == WM_MOVE ||
457 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
460 defwndproc_counter++;
461 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
462 defwndproc_counter--;
466 static HWND subclass_editbox(HWND hwndListview)
468 struct subclass_info *info;
471 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
475 hwnd = (HWND)SendMessage(hwndListview, LVM_GETEDITCONTROL, 0, 0);
476 info->oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
477 (LONG_PTR)editbox_subclass_proc);
478 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)info);
483 /* Performs a single LVM_HITTEST test */
484 static void test_lvm_hittest(HWND hwnd, INT x, INT y, INT item, UINT flags,
485 BOOL todo_item, BOOL todo_flags, int line)
494 trace("hittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
495 ret = SendMessage(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
501 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
502 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
503 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
508 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
509 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
510 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
516 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
519 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
522 /* Performs a single LVM_SUBITEMHITTEST test */
523 static void test_lvm_subitemhittest(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
524 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
532 trace("subhittesting pt=(%d,%d)\n", lpht.pt.x, lpht.pt.y);
533 ret = SendMessage(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
539 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
540 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
545 ok_(__FILE__, line)(ret == item, "Expected %d item, got %d\n", item, ret);
546 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
552 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
555 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
560 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
563 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags %x, got %x\n", flags, lpht.flags);
566 static void test_images(void)
574 static CHAR hello[] = "hello";
576 himl = ImageList_Create(40, 40, 0, 4, 4);
577 ok(himl != NULL, "failed to create imagelist\n");
579 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
580 ok(hbmp != NULL, "failed to create bitmap\n");
582 r = ImageList_Add(himl, hbmp, 0);
583 ok(r == 0, "should be zero\n");
585 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
586 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
587 ok(hwnd != NULL, "failed to create listview window\n");
589 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
590 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
592 ok(r == 0, "should return zero\n");
594 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
595 ok(r == 0, "should return zero\n");
597 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
598 /* returns dimensions */
600 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
601 ok(r == 0, "should be zero items\n");
603 item.mask = LVIF_IMAGE | LVIF_TEXT;
608 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
609 ok(r == -1, "should fail\n");
612 item.pszText = hello;
613 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
614 ok(r == 0, "should not fail\n");
616 memset(&r1, 0, sizeof r1);
618 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
620 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
621 ok(r == TRUE, "should not fail\n");
624 item.pszText = hello;
625 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
626 ok(r == 0, "should not fail\n");
628 memset(&r2, 0, sizeof r2);
630 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
632 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
637 static void test_checkboxes(void)
642 static CHAR text[] = "Text",
646 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
647 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
648 ok(hwnd != NULL, "failed to create listview window\n");
650 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
651 item.mask = LVIF_TEXT | LVIF_STATE;
652 item.stateMask = 0xffff;
657 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
658 ok(r == 0, "ret %d\n", r);
661 item.mask = LVIF_STATE;
662 item.stateMask = 0xffff;
663 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
664 ok(item.state == 0xfccc, "state %x\n", item.state);
666 /* Don't set LVIF_STATE */
667 item.mask = LVIF_TEXT;
668 item.stateMask = 0xffff;
673 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
674 ok(r == 1, "ret %d\n", r);
677 item.mask = LVIF_STATE;
678 item.stateMask = 0xffff;
679 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
680 ok(item.state == 0, "state %x\n", item.state);
682 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
683 ok(r == 0, "should return zero\n");
685 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
687 item.mask = LVIF_STATE;
688 item.stateMask = 0xffff;
689 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
690 ok(item.state == 0x1ccc, "state %x\n", item.state);
692 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
694 item.mask = LVIF_TEXT;
696 item.pszText = text2;
697 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
698 ok(r == 2, "ret %d\n", r);
701 item.mask = LVIF_STATE;
702 item.stateMask = 0xffff;
703 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
704 ok(item.state == 0x1000, "state %x\n", item.state);
706 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
708 item.mask = LVIF_TEXT | LVIF_STATE;
709 item.stateMask = 0xffff;
711 item.pszText = text3;
712 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
713 ok(r == 3, "ret %d\n", r);
716 item.mask = LVIF_STATE;
717 item.stateMask = 0xffff;
718 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
719 ok(item.state == 0x1aaa, "state %x\n", item.state);
721 /* Set an item's state to checked */
723 item.mask = LVIF_STATE;
724 item.stateMask = 0xf000;
726 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
729 item.mask = LVIF_STATE;
730 item.stateMask = 0xffff;
731 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
732 ok(item.state == 0x2aaa, "state %x\n", item.state);
734 /* Check that only the bits we asked for are returned,
735 * and that all the others are set to zero
738 item.mask = LVIF_STATE;
739 item.stateMask = 0xf000;
741 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
742 ok(item.state == 0x2000, "state %x\n", item.state);
744 /* Set the style again and check that doesn't change an item's state */
745 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
746 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
749 item.mask = LVIF_STATE;
750 item.stateMask = 0xffff;
751 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
752 ok(item.state == 0x2aaa, "state %x\n", item.state);
754 /* Unsetting the checkbox extended style doesn't change an item's state */
755 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
756 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
759 item.mask = LVIF_STATE;
760 item.stateMask = 0xffff;
761 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
762 ok(item.state == 0x2aaa, "state %x\n", item.state);
764 /* Now setting the style again will change an item's state */
765 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
766 ok(r == 0, "ret %x\n", r);
769 item.mask = LVIF_STATE;
770 item.stateMask = 0xffff;
771 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
772 ok(item.state == 0x1aaa, "state %x\n", item.state);
774 /* Toggle checkbox tests (bug 9934) */
775 memset (&item, 0xcc, sizeof(item));
776 item.mask = LVIF_STATE;
779 item.state = LVIS_FOCUSED;
780 item.stateMask = LVIS_FOCUSED;
781 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
785 item.mask = LVIF_STATE;
786 item.stateMask = 0xffff;
787 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
788 ok(item.state == 0x1aab, "state %x\n", item.state);
790 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
792 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
796 item.mask = LVIF_STATE;
797 item.stateMask = 0xffff;
798 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
799 ok(item.state == 0x2aab, "state %x\n", item.state);
801 r = SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
803 r = SendMessage(hwnd, WM_KEYUP, VK_SPACE, 0);
807 item.mask = LVIF_STATE;
808 item.stateMask = 0xffff;
809 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
810 ok(item.state == 0x1aab, "state %x\n", item.state);
815 static void insert_column(HWND hwnd, int idx)
820 memset(&column, 0xcc, sizeof(column));
821 column.mask = LVCF_SUBITEM;
822 column.iSubItem = idx;
824 rc = ListView_InsertColumn(hwnd, idx, &column);
828 static void insert_item(HWND hwnd, int idx)
830 static CHAR text[] = "foo";
835 memset(&item, 0xcc, sizeof (item));
836 item.mask = LVIF_TEXT;
841 rc = ListView_InsertItem(hwnd, &item);
845 static void test_items(void)
847 const LPARAM lparamTest = 0x42;
851 static CHAR text[] = "Text";
853 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
854 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
855 ok(hwnd != NULL, "failed to create listview window\n");
858 * Test setting/getting item params
861 /* Set up two columns */
862 insert_column(hwnd, 0);
863 insert_column(hwnd, 1);
865 /* LVIS_SELECTED with zero stateMask */
867 memset (&item, 0, sizeof (item));
868 item.mask = LVIF_STATE;
869 item.state = LVIS_SELECTED;
873 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
874 ok(r == 0, "ret %d\n", r);
876 memset (&item, 0xcc, sizeof (item));
877 item.mask = LVIF_STATE;
878 item.stateMask = LVIS_SELECTED;
882 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
883 ok(r != 0, "ret %d\n", r);
884 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
885 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
887 /* LVIS_SELECTED with zero stateMask */
889 memset (&item, 0, sizeof (item));
890 item.mask = LVIF_STATE;
891 item.state = LVIS_FOCUSED;
895 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
896 ok(r == 0, "ret %d\n", r);
898 memset (&item, 0xcc, sizeof (item));
899 item.mask = LVIF_STATE;
900 item.stateMask = LVIS_FOCUSED;
904 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
905 ok(r != 0, "ret %d\n", r);
906 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
907 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
909 /* LVIS_CUT with LVIS_FOCUSED stateMask */
911 memset (&item, 0, sizeof (item));
912 item.mask = LVIF_STATE;
913 item.state = LVIS_CUT;
914 item.stateMask = LVIS_FOCUSED;
917 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
918 ok(r == 0, "ret %d\n", r);
920 memset (&item, 0xcc, sizeof (item));
921 item.mask = LVIF_STATE;
922 item.stateMask = LVIS_CUT;
926 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
927 ok(r != 0, "ret %d\n", r);
928 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
929 SendMessage(hwnd, LVM_DELETEITEM, 0, 0);
931 /* Insert an item with just a param */
932 memset (&item, 0xcc, sizeof (item));
933 item.mask = LVIF_PARAM;
936 item.lParam = lparamTest;
937 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
938 ok(r == 0, "ret %d\n", r);
940 /* Test getting of the param */
941 memset (&item, 0xcc, sizeof (item));
942 item.mask = LVIF_PARAM;
945 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
946 ok(r != 0, "ret %d\n", r);
947 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
949 /* Set up a subitem */
950 memset (&item, 0xcc, sizeof (item));
951 item.mask = LVIF_TEXT;
955 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
956 ok(r != 0, "ret %d\n", r);
958 /* Query param from subitem: returns main item param */
959 memset (&item, 0xcc, sizeof (item));
960 item.mask = LVIF_PARAM;
963 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
964 ok(r != 0, "ret %d\n", r);
965 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
967 /* Set up param on first subitem: no effect */
968 memset (&item, 0xcc, sizeof (item));
969 item.mask = LVIF_PARAM;
972 item.lParam = lparamTest+1;
973 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
974 ok(r == 0, "ret %d\n", r);
976 /* Query param from subitem again: should still return main item param */
977 memset (&item, 0xcc, sizeof (item));
978 item.mask = LVIF_PARAM;
981 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
982 ok(r != 0, "ret %d\n", r);
983 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
985 /**** Some tests of state highlighting ****/
986 memset (&item, 0xcc, sizeof (item));
987 item.mask = LVIF_STATE;
990 item.state = LVIS_SELECTED;
991 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
992 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
993 ok(r != 0, "ret %d\n", r);
995 item.state = LVIS_DROPHILITED;
996 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
997 ok(r != 0, "ret %d\n", r);
999 memset (&item, 0xcc, sizeof (item));
1000 item.mask = LVIF_STATE;
1003 item.stateMask = -1;
1004 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1005 ok(r != 0, "ret %d\n", r);
1006 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1008 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
1009 ok(r != 0, "ret %d\n", r);
1010 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1012 /* some notnull but meaningless masks */
1013 memset (&item, 0, sizeof(item));
1014 item.mask = LVIF_NORECOMPUTE;
1017 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1018 ok(r != 0, "ret %d\n", r);
1019 memset (&item, 0, sizeof(item));
1020 item.mask = LVIF_DI_SETITEM;
1023 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1024 ok(r != 0, "ret %d\n", r);
1026 /* set text to callback value already having it */
1027 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1029 memset (&item, 0, sizeof (item));
1030 item.mask = LVIF_TEXT;
1031 item.pszText = LPSTR_TEXTCALLBACK;
1033 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1034 ok(r == 0, "ret %d\n", r);
1035 memset (&item, 0, sizeof (item));
1037 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1039 item.pszText = LPSTR_TEXTCALLBACK;
1040 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0 , (LPARAM) &item);
1043 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1044 "check callback text comparison rule", TRUE);
1046 DestroyWindow(hwnd);
1049 static void test_columns(void)
1051 HWND hwnd, hwndheader;
1056 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
1057 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1058 ok(hwnd != NULL, "failed to create listview window\n");
1060 /* Add a column with no mask */
1061 memset(&column, 0xcc, sizeof(column));
1063 rc = ListView_InsertColumn(hwnd, 0, &column);
1064 ok(rc==0, "Inserting column with no mask failed with %d\n", rc);
1066 /* Check its width */
1067 rc = ListView_GetColumnWidth(hwnd, 0);
1069 broken(rc==0), /* win9x */
1070 "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1072 DestroyWindow(hwnd);
1074 /* LVM_GETCOLUMNORDERARRAY */
1075 hwnd = create_listview_control(0);
1076 hwndheader = subclass_header(hwnd);
1078 memset(&column, 0, sizeof(column));
1079 column.mask = LVCF_WIDTH;
1081 rc = ListView_InsertColumn(hwnd, 0, &column);
1082 ok(rc == 0, "Inserting column failed with %d\n", rc);
1085 rc = ListView_InsertColumn(hwnd, 1, &column);
1086 ok(rc == 1, "Inserting column failed with %d\n", rc);
1088 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1090 rc = SendMessage(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1091 ok(rc != 0, "Expected LVM_GETCOLUMNORDERARRAY to succeed\n");
1092 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1093 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1095 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1097 DestroyWindow(hwnd);
1099 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1100 static WNDPROC listviewWndProc;
1101 static HIMAGELIST test_create_imagelist;
1103 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1107 if (uMsg == WM_CREATE)
1109 LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
1110 lpcs->style |= LVS_REPORT;
1112 ret = CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
1113 if (uMsg == WM_CREATE) SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1117 static void test_create(void)
1126 cls.cbSize = sizeof(WNDCLASSEX);
1127 ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1128 listviewWndProc = cls.lpfnWndProc;
1129 cls.lpfnWndProc = create_test_wndproc;
1130 cls.lpszClassName = "MyListView32";
1131 ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
1133 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1134 hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1135 ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1136 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1137 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1138 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1139 DestroyWindow(hList);
1141 /* header isn't created on LVS_ICON and LVS_LIST styles */
1142 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1143 GetModuleHandle(NULL), 0);
1144 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1145 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1146 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1148 memset(&col, 0, sizeof(LVCOLUMNA));
1149 col.mask = LVCF_WIDTH;
1151 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1152 ok(r == 0, "Expected 0 column's inserted\n");
1153 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1154 ok(IsWindow(hHeader), "Header should be created\n");
1155 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1156 DestroyWindow(hList);
1158 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1159 GetModuleHandle(NULL), 0);
1160 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1161 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1162 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1164 memset(&col, 0, sizeof(LVCOLUMNA));
1165 col.mask = LVCF_WIDTH;
1167 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1168 ok(r == 0, "Expected 0 column's inserted\n");
1169 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1170 ok(IsWindow(hHeader), "Header should be created\n");
1171 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1172 DestroyWindow(hList);
1174 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1175 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1176 GetModuleHandle(NULL), 0);
1177 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLongPtr(hList, GWL_STYLE) | LVS_REPORT);
1178 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1179 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1180 ok(IsWindow(hHeader), "Header should be created\n");
1181 ret = SetWindowLongPtr(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) & ~LVS_REPORT);
1182 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1183 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1184 ok(IsWindow(hHeader), "Header should be created\n");
1185 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1186 DestroyWindow(hList);
1188 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1189 hList = CreateWindow("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1190 GetModuleHandle(NULL), 0);
1191 ret = SetWindowLongPtr(hList, GWL_STYLE,
1192 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1193 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1194 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1195 ok(IsWindow(hHeader), "Header should be created\n");
1196 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1197 ret = SetWindowLongPtr(hList, GWL_STYLE,
1198 (GetWindowLongPtr(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1199 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1200 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1201 ok(IsWindow(hHeader), "Header should be created\n");
1202 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1203 DestroyWindow(hList);
1205 /* LVS_REPORT without WS_VISIBLE */
1206 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1207 GetModuleHandle(NULL), 0);
1208 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1209 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1210 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1212 memset(&col, 0, sizeof(LVCOLUMNA));
1213 col.mask = LVCF_WIDTH;
1215 r = SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1216 ok(r == 0, "Expected 0 column's inserted\n");
1217 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1218 ok(IsWindow(hHeader), "Header should be created\n");
1219 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1220 DestroyWindow(hList);
1222 /* LVS_REPORT without WS_VISIBLE, try to show it */
1223 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1224 GetModuleHandle(NULL), 0);
1225 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1226 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1227 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1228 ShowWindow(hList, SW_SHOW);
1229 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1230 ok(IsWindow(hHeader), "Header should be created\n");
1231 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1232 DestroyWindow(hList);
1234 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1235 hList = CreateWindow("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1236 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
1237 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1238 ok(IsWindow(hHeader), "Header should be created\n");
1239 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1240 /* HDS_DRAGDROP set by default */
1241 ok(GetWindowLongPtr(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1242 DestroyWindow(hList);
1244 /* setting LVS_EX_HEADERDRAGDROP creates header */
1245 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1246 GetModuleHandle(NULL), 0);
1247 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1248 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1249 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1250 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1251 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1252 ok(IsWindow(hHeader), "Header should be created\n");
1253 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1254 DestroyWindow(hList);
1256 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1257 hList = create_custom_listview_control(0);
1258 SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1259 r = SendMessage(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1260 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1261 DestroyWindow(hList);
1263 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1264 hList = CreateWindow("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1265 GetModuleHandle(NULL), 0);
1266 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1267 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1269 rect.left = LVIR_BOUNDS;
1271 rect.right = rect.bottom = -10;
1272 r = SendMessage(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1273 ok(r != 0, "Expected not-null LRESULT\n");
1275 hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
1276 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1277 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1279 DestroyWindow(hList);
1282 static void test_redraw(void)
1284 HWND hwnd, hwndheader;
1289 hwnd = create_listview_control(0);
1290 hwndheader = subclass_header(hwnd);
1292 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1294 trace("invalidate & update\n");
1295 InvalidateRect(hwnd, NULL, TRUE);
1297 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1299 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1301 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1302 /* 1. Without backbuffer */
1303 res = ListView_SetBkColor(hwnd, CLR_NONE);
1306 hdc = GetWindowDC(hwndparent);
1308 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1309 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1310 ok(r != 0, "Expected not zero result\n");
1311 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1312 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1314 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1317 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1318 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1319 ok(r != 0, "Expected not zero result\n");
1320 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1321 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1323 /* 2. With backbuffer */
1324 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1325 LVS_EX_DOUBLEBUFFER);
1326 res = ListView_SetBkColor(hwnd, CLR_NONE);
1329 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1330 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1331 ok(r != 0, "Expected not zero result\n");
1332 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1333 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1335 res = ListView_SetBkColor(hwnd, CLR_DEFAULT);
1338 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1339 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1340 todo_wine ok(r != 0, "Expected not zero result\n");
1341 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1342 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1344 ReleaseDC(hwndparent, hdc);
1346 DestroyWindow(hwnd);
1349 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1351 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1353 if(msg == WM_NOTIFY) {
1354 NMHDR *nmhdr = (PVOID)lp;
1355 if(nmhdr->code == NM_CUSTOMDRAW) {
1356 NMLVCUSTOMDRAW *nmlvcd = (PVOID)nmhdr;
1357 trace("NMCUSTOMDRAW (0x%.8x)\n", nmlvcd->nmcd.dwDrawStage);
1358 switch(nmlvcd->nmcd.dwDrawStage) {
1360 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1361 return CDRF_NOTIFYITEMDRAW;
1362 case CDDS_ITEMPREPAINT:
1363 nmlvcd->clrTextBk = CLR_DEFAULT;
1364 return CDRF_NOTIFYSUBITEMDRAW;
1365 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1366 clr = GetBkColor(nmlvcd->nmcd.hdc);
1367 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1368 return CDRF_NOTIFYPOSTPAINT;
1369 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1370 clr = GetBkColor(nmlvcd->nmcd.hdc);
1371 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1372 return CDRF_DODEFAULT;
1374 return CDRF_DODEFAULT;
1378 return DefWindowProcA(hwnd, msg, wp, lp);
1381 static void test_customdraw(void)
1386 hwnd = create_listview_control(0);
1388 insert_column(hwnd, 0);
1389 insert_column(hwnd, 1);
1390 insert_item(hwnd, 0);
1392 oldwndproc = (WNDPROC)SetWindowLongPtr(hwndparent, GWLP_WNDPROC,
1393 (LONG_PTR)cd_wndproc);
1395 InvalidateRect(hwnd, NULL, TRUE);
1398 SetWindowLongPtr(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1400 DestroyWindow(hwnd);
1403 static void test_icon_spacing(void)
1405 /* LVM_SETICONSPACING */
1406 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1412 hwnd = create_custom_listview_control(LVS_ICON);
1413 ok(hwnd != NULL, "failed to create a listview window\n");
1415 r = SendMessage(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, (LPARAM)NF_REQUERY);
1416 expect(NFR_ANSI, r);
1418 /* reset the icon spacing to defaults */
1419 SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1421 /* now we can request what the defaults are */
1422 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1426 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1428 trace("test icon spacing\n");
1430 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1431 ok(r == MAKELONG(w, h) ||
1432 broken(r == MAKELONG(w, w)), /* win98 */
1433 "Expected %d, got %d\n", MAKELONG(w, h), r);
1435 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1436 expect(MAKELONG(20,30), r);
1438 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1439 expect(MAKELONG(25,35), r);
1441 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1443 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1444 DestroyWindow(hwnd);
1447 static void test_color(void)
1449 /* SETBKCOLOR/GETBKCOLOR, SETTEXTCOLOR/GETTEXTCOLOR, SETTEXTBKCOLOR/GETTEXTBKCOLOR */
1456 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1458 hwnd = create_listview_control(0);
1459 ok(hwnd != NULL, "failed to create a listview window\n");
1461 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1463 trace("test color seq\n");
1464 for (i = 0; i < 4; i++)
1468 r = SendMessage(hwnd, LVM_SETBKCOLOR, 0, color);
1470 r = SendMessage(hwnd, LVM_GETBKCOLOR, 0, color);
1473 r = SendMessage(hwnd, LVM_SETTEXTCOLOR, 0, color);
1475 r = SendMessage(hwnd, LVM_GETTEXTCOLOR, 0, color);
1478 r = SendMessage(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1480 r = SendMessage(hwnd, LVM_GETTEXTBKCOLOR, 0, color);
1484 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1486 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1487 DestroyWindow(hwnd);
1490 static void test_item_count(void)
1492 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1500 static CHAR item0text[] = "item0";
1501 static CHAR item1text[] = "item1";
1502 static CHAR item2text[] = "item2";
1504 hwnd = create_listview_control(0);
1505 ok(hwnd != NULL, "failed to create a listview window\n");
1507 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1509 trace("test item count\n");
1511 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1515 item0.mask = LVIF_TEXT;
1518 item0.pszText = item0text;
1519 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1522 /* [item0, item1] */
1523 item1.mask = LVIF_TEXT;
1526 item1.pszText = item1text;
1527 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1530 /* [item0, item1, item2] */
1531 item2.mask = LVIF_TEXT;
1534 item2.pszText = item2text;
1535 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1538 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1541 /* [item0, item1] */
1542 r = SendMessage(hwnd, LVM_DELETEITEM, 2, 0);
1545 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1549 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
1552 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1556 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1559 /* [item0, item1] */
1560 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1563 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1566 /* [item0, item1, item2] */
1567 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1570 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1573 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
1575 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1576 DestroyWindow(hwnd);
1579 static void test_item_position(void)
1581 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
1590 static CHAR item0text[] = "item0";
1591 static CHAR item1text[] = "item1";
1592 static CHAR item2text[] = "item2";
1594 hwnd = create_custom_listview_control(LVS_ICON);
1595 ok(hwnd != NULL, "failed to create a listview window\n");
1597 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1599 trace("test item position\n");
1602 item0.mask = LVIF_TEXT;
1605 item0.pszText = item0text;
1606 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item0);
1609 /* [item0, item1] */
1610 item1.mask = LVIF_TEXT;
1613 item1.pszText = item1text;
1614 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item1);
1617 /* [item0, item1, item2] */
1618 item2.mask = LVIF_TEXT;
1621 item2.pszText = item2text;
1622 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item2);
1625 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
1627 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
1629 expect2(10, 5, position.x, position.y);
1631 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
1633 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
1635 expect2(0, 0, position.x, position.y);
1637 r = SendMessage(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
1639 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
1641 expect2(20, 20, position.x, position.y);
1643 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
1645 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1646 DestroyWindow(hwnd);
1649 static void test_getorigin(void)
1657 position.x = position.y = 0;
1659 hwnd = create_custom_listview_control(LVS_ICON);
1660 ok(hwnd != NULL, "failed to create a listview window\n");
1661 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1662 trace("test get origin results\n");
1663 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1665 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1666 DestroyWindow(hwnd);
1668 hwnd = create_custom_listview_control(LVS_SMALLICON);
1669 ok(hwnd != NULL, "failed to create a listview window\n");
1670 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1671 trace("test get origin results\n");
1672 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1674 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1675 DestroyWindow(hwnd);
1677 hwnd = create_custom_listview_control(LVS_LIST);
1678 ok(hwnd != NULL, "failed to create a listview window\n");
1679 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1680 trace("test get origin results\n");
1681 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1683 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1684 DestroyWindow(hwnd);
1686 hwnd = create_custom_listview_control(LVS_REPORT);
1687 ok(hwnd != NULL, "failed to create a listview window\n");
1688 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1689 trace("test get origin results\n");
1690 r = SendMessage(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
1692 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1693 DestroyWindow(hwnd);
1697 static void test_multiselect(void)
1699 typedef struct t_select_task
1710 int i,j,item_count,selected_count;
1711 static const int items=5;
1717 static struct t_select_task task_list[] = {
1718 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
1719 { "using VK_UP", -1, VK_UP, -1, -1 },
1720 { "using VK_END", 0, VK_END, 1, -1 },
1721 { "using VK_HOME", -1, VK_HOME, 1, -1 }
1725 hwnd = create_listview_control(0);
1727 for (i=0;i<items;i++) {
1728 insert_item(hwnd, 0);
1731 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1733 expect(items,item_count);
1736 task = task_list[i];
1738 /* deselect all items */
1739 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1740 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1742 /* set initial position */
1743 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
1744 ListView_SetItemState(hwnd,(task.initPos == -1 ? item_count -1 : task.initPos),LVIS_SELECTED ,LVIS_SELECTED);
1746 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1748 ok(selected_count == 1, "There should be only one selected item at the beginning (is %d)\n",selected_count);
1750 /* Set SHIFT key pressed */
1751 GetKeyboardState(kstate);
1752 kstate[VK_SHIFT]=0x80;
1753 SetKeyboardState(kstate);
1755 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
1756 r = SendMessage(hwnd, WM_KEYDOWN, task.loopVK, 0);
1758 r = SendMessage(hwnd, WM_KEYUP, task.loopVK, 0);
1762 selected_count = (int)SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1764 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);
1766 /* Set SHIFT key released */
1767 GetKeyboardState(kstate);
1768 kstate[VK_SHIFT]=0x00;
1769 SetKeyboardState(kstate);
1771 DestroyWindow(hwnd);
1773 /* make multiple selection, then switch to LVS_SINGLESEL */
1774 hwnd = create_listview_control(0);
1775 for (i=0;i<items;i++) {
1776 insert_item(hwnd, 0);
1778 item_count = (int)SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
1779 expect(items,item_count);
1780 /* deselect all items */
1781 ListView_SetItemState(hwnd, -1, 0, LVIS_SELECTED);
1782 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1784 ListView_SetItemState(hwnd, i, LVIS_SELECTED, LVIS_SELECTED);
1787 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1789 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1793 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1794 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
1795 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
1796 /* check that style is accepted */
1797 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
1798 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
1801 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
1802 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
1804 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1806 SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1809 /* select one more */
1810 ListView_SetItemState(hwnd, 3, LVIS_SELECTED, LVIS_SELECTED);
1813 r = ListView_GetItemState(hwnd, i, LVIS_SELECTED);
1814 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
1816 r = ListView_GetItemState(hwnd, 3, LVIS_SELECTED);
1817 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
1819 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
1821 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
1825 /* try to select all on LVS_SINGLESEL */
1826 memset(&item, 0, sizeof(item));
1827 item.stateMask = LVIS_SELECTED;
1828 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1830 SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
1832 item.stateMask = LVIS_SELECTED;
1833 item.state = LVIS_SELECTED;
1834 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1837 r = ListView_GetSelectedCount(hwnd);
1839 r = ListView_GetSelectionMark(hwnd);
1842 /* try to deselect all on LVS_SINGLESEL */
1843 item.stateMask = LVIS_SELECTED;
1844 item.state = LVIS_SELECTED;
1845 r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
1848 item.stateMask = LVIS_SELECTED;
1850 r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
1852 r = ListView_GetSelectedCount(hwnd);
1855 DestroyWindow(hwnd);
1858 static void test_subitem_rect(void)
1865 /* test LVM_GETSUBITEMRECT for header */
1866 hwnd = create_listview_control(0);
1867 ok(hwnd != NULL, "failed to create a listview window\n");
1868 /* add some columns */
1869 memset(&col, 0, sizeof(LVCOLUMN));
1870 col.mask = LVCF_WIDTH;
1873 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
1877 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
1881 r = SendMessage(hwnd, LVM_INSERTCOLUMN, 2, (LPARAM)&col);
1883 /* item = -1 means header, subitem index is 1 based */
1884 rect.left = LVIR_BOUNDS;
1886 rect.right = rect.bottom = 0;
1887 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1890 rect.left = LVIR_BOUNDS;
1892 rect.right = rect.bottom = 0;
1893 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1895 ok(r != 0, "Expected not-null LRESULT\n");
1896 expect(100, rect.left);
1897 expect(250, rect.right);
1899 expect(3, rect.top);
1901 rect.left = LVIR_BOUNDS;
1903 rect.right = rect.bottom = 0;
1904 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1906 ok(r != 0, "Expected not-null LRESULT\n");
1907 expect(250, rect.left);
1908 expect(450, rect.right);
1910 expect(3, rect.top);
1912 /* item LVS_REPORT padding isn't applied to subitems */
1913 insert_item(hwnd, 0);
1915 rect.left = LVIR_BOUNDS;
1917 rect.right = rect.bottom = 0;
1918 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
1919 ok(r != 0, "Expected not-null LRESULT\n");
1920 expect(100, rect.left);
1921 expect(250, rect.right);
1923 rect.left = LVIR_ICON;
1925 rect.right = rect.bottom = 0;
1926 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
1927 ok(r != 0, "Expected not-null LRESULT\n");
1928 /* no icon attached - zero width rectangle, with no left padding */
1929 expect(100, rect.left);
1930 expect(100, rect.right);
1932 rect.left = LVIR_LABEL;
1934 rect.right = rect.bottom = 0;
1935 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
1936 ok(r != 0, "Expected not-null LRESULT\n");
1937 /* same as full LVIR_BOUNDS */
1938 expect(100, rect.left);
1939 expect(250, rect.right);
1941 DestroyWindow(hwnd);
1943 /* try it for non LVS_REPORT style */
1944 hwnd = CreateWindow("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
1945 GetModuleHandle(NULL), 0);
1946 rect.left = LVIR_BOUNDS;
1948 rect.right = rect.bottom = -10;
1949 r = SendMessage(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1950 ok(r == 0, "Expected not-null LRESULT\n");
1951 /* rect is unchanged */
1952 expect(0, rect.left);
1953 expect(-10, rect.right);
1954 expect(1, rect.top);
1955 expect(-10, rect.bottom);
1956 DestroyWindow(hwnd);
1959 /* comparison callback for test_sorting */
1960 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
1962 if (first == second) return 0;
1963 return (first > second ? 1 : -1);
1966 static void test_sorting(void)
1972 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
1975 hwnd = create_listview_control(0);
1976 ok(hwnd != NULL, "failed to create a listview window\n");
1978 /* insert some items */
1979 item.mask = LVIF_PARAM | LVIF_STATE;
1980 item.state = LVIS_SELECTED;
1984 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
1987 item.mask = LVIF_PARAM;
1991 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
1994 item.mask = LVIF_STATE | LVIF_PARAM;
1995 item.state = LVIS_SELECTED;
1999 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2002 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2005 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2008 r = SendMessage(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2011 r = SendMessage(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2013 r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2015 r = SendMessage(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2017 r = SendMessage(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2018 expect(LVIS_SELECTED, r);
2019 r = SendMessage(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2020 expect(LVIS_SELECTED, r);
2022 DestroyWindow(hwnd);
2024 /* switch to LVS_SORTASCENDING when some items added */
2025 hwnd = create_listview_control(0);
2026 ok(hwnd != NULL, "failed to create a listview window\n");
2028 item.mask = LVIF_TEXT;
2031 item.pszText = names[1];
2032 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2035 item.mask = LVIF_TEXT;
2038 item.pszText = names[2];
2039 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2042 item.mask = LVIF_TEXT;
2045 item.pszText = names[0];
2046 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2049 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2050 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2051 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2052 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2054 /* no sorting performed when switched to LVS_SORTASCENDING */
2055 item.mask = LVIF_TEXT;
2057 item.pszText = buff;
2058 item.cchTextMax = sizeof(buff);
2059 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2061 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2064 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2066 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2069 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2071 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2073 /* adding new item doesn't resort list */
2074 item.mask = LVIF_TEXT;
2077 item.pszText = names[3];
2078 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2081 item.mask = LVIF_TEXT;
2083 item.pszText = buff;
2084 item.cchTextMax = sizeof(buff);
2085 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2087 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2090 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2092 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2095 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2097 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2100 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2102 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2104 /* corner case - item should be placed at first position */
2105 item.mask = LVIF_TEXT;
2108 item.pszText = names[4];
2109 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
2113 item.pszText = buff;
2114 item.cchTextMax = sizeof(buff);
2115 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2117 ok(lstrcmp(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2120 item.pszText = buff;
2121 item.cchTextMax = sizeof(buff);
2122 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2124 ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2127 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2129 ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2132 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2134 ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2137 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
2139 ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2141 DestroyWindow(hwnd);
2144 static void test_ownerdata(void)
2147 LONG_PTR style, ret;
2151 /* it isn't possible to set LVS_OWNERDATA after creation */
2152 hwnd = create_listview_control(0);
2153 ok(hwnd != NULL, "failed to create a listview window\n");
2154 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2155 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2157 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2159 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2160 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2161 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2162 "try to switch to LVS_OWNERDATA seq", FALSE);
2164 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2165 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2166 DestroyWindow(hwnd);
2168 /* try to set LVS_OWNERDATA after creation just having it */
2169 hwnd = create_listview_control(LVS_OWNERDATA);
2170 ok(hwnd != NULL, "failed to create a listview window\n");
2171 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2172 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2174 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2176 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2177 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2178 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2179 "try to switch to LVS_OWNERDATA seq", FALSE);
2180 DestroyWindow(hwnd);
2182 /* try to remove LVS_OWNERDATA after creation just having it */
2183 hwnd = create_listview_control(LVS_OWNERDATA);
2184 ok(hwnd != NULL, "failed to create a listview window\n");
2185 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2186 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2188 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2190 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2191 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2192 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2193 "try to switch to LVS_OWNERDATA seq", FALSE);
2194 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2195 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2196 DestroyWindow(hwnd);
2198 /* try select an item */
2199 hwnd = create_listview_control(LVS_OWNERDATA);
2200 ok(hwnd != NULL, "failed to create a listview window\n");
2201 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2202 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2203 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2205 memset(&item, 0, sizeof(item));
2206 item.stateMask = LVIS_SELECTED;
2207 item.state = LVIS_SELECTED;
2208 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2210 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2212 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2214 DestroyWindow(hwnd);
2216 /* LVM_SETITEM is unsupported on LVS_OWNERDATA */
2217 hwnd = create_listview_control(LVS_OWNERDATA);
2218 ok(hwnd != NULL, "failed to create a listview window\n");
2219 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2220 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2221 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2223 memset(&item, 0, sizeof(item));
2224 item.mask = LVIF_STATE;
2226 item.stateMask = LVIS_SELECTED;
2227 item.state = LVIS_SELECTED;
2228 res = SendMessageA(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2230 DestroyWindow(hwnd);
2232 /* check notifications after focused/selected changed */
2233 hwnd = create_listview_control(LVS_OWNERDATA);
2234 ok(hwnd != NULL, "failed to create a listview window\n");
2235 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2236 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2238 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2240 memset(&item, 0, sizeof(item));
2241 item.stateMask = LVIS_SELECTED;
2242 item.state = LVIS_SELECTED;
2243 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2246 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2247 "ownerdata select notification", TRUE);
2249 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2251 memset(&item, 0, sizeof(item));
2252 item.stateMask = LVIS_FOCUSED;
2253 item.state = LVIS_FOCUSED;
2254 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2257 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
2258 "ownerdata focus notification", TRUE);
2259 DestroyWindow(hwnd);
2261 /* check notifications on LVM_GETITEM */
2262 /* zero callback mask */
2263 hwnd = create_listview_control(LVS_OWNERDATA);
2264 ok(hwnd != NULL, "failed to create a listview window\n");
2265 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
2266 ok(res != 0, "Expected LVM_SETITEMCOUNT to succeed\n");
2268 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2270 memset(&item, 0, sizeof(item));
2271 item.stateMask = LVIS_SELECTED;
2272 item.mask = LVIF_STATE;
2273 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2276 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2277 "ownerdata getitem selected state 1", FALSE);
2279 /* non zero callback mask but not we asking for */
2280 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
2283 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2285 memset(&item, 0, sizeof(item));
2286 item.stateMask = LVIS_SELECTED;
2287 item.mask = LVIF_STATE;
2288 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2291 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
2292 "ownerdata getitem selected state 2", FALSE);
2294 /* LVIS_OVERLAYMASK callback mask, asking for index */
2295 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2297 memset(&item, 0, sizeof(item));
2298 item.stateMask = LVIS_OVERLAYMASK;
2299 item.mask = LVIF_STATE;
2300 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2303 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
2304 "ownerdata getitem selected state 2", FALSE);
2306 DestroyWindow(hwnd);
2308 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
2309 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING);
2310 ok(hwnd != NULL, "failed to create a listview window\n");
2311 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2312 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2313 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2314 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
2315 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2316 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
2317 DestroyWindow(hwnd);
2318 /* apparently it's allowed to switch these style on after creation */
2319 hwnd = create_listview_control(LVS_OWNERDATA);
2320 ok(hwnd != NULL, "failed to create a listview window\n");
2321 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2322 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2323 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2324 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2325 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2326 DestroyWindow(hwnd);
2328 hwnd = create_listview_control(LVS_OWNERDATA);
2329 ok(hwnd != NULL, "failed to create a listview window\n");
2330 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2331 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
2332 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
2333 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2334 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
2335 DestroyWindow(hwnd);
2338 static void test_norecompute(void)
2340 static CHAR testA[] = "test";
2346 /* self containing control */
2347 hwnd = create_listview_control(0);
2348 ok(hwnd != NULL, "failed to create a listview window\n");
2349 memset(&item, 0, sizeof(item));
2350 item.mask = LVIF_TEXT | LVIF_STATE;
2352 item.stateMask = LVIS_SELECTED;
2353 item.state = LVIS_SELECTED;
2354 item.pszText = testA;
2355 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2357 /* retrieve with LVIF_NORECOMPUTE */
2358 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2360 item.pszText = buff;
2361 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2362 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2364 ok(lstrcmp(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
2366 item.mask = LVIF_TEXT;
2368 item.pszText = LPSTR_TEXTCALLBACK;
2369 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2372 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2374 item.pszText = buff;
2375 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2377 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2378 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2380 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2381 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2382 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
2384 DestroyWindow(hwnd);
2387 hwnd = create_listview_control(LVS_OWNERDATA);
2388 ok(hwnd != NULL, "failed to create a listview window\n");
2390 item.mask = LVIF_STATE;
2391 item.stateMask = LVIS_SELECTED;
2392 item.state = LVIS_SELECTED;
2394 res = SendMessageA(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
2397 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
2399 item.pszText = buff;
2400 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
2401 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2402 res = SendMessageA(hwnd, LVM_GETITEM, 0, (LPARAM)&item);
2404 ok(item.pszText == LPSTR_TEXTCALLBACK, "Expected (%p), got (%p)\n",
2405 LPSTR_TEXTCALLBACK, (VOID*)item.pszText);
2406 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
2408 DestroyWindow(hwnd);
2411 static void test_nosortheader(void)
2416 hwnd = create_listview_control(0);
2417 ok(hwnd != NULL, "failed to create a listview window\n");
2419 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2420 ok(IsWindow(header), "header expected\n");
2422 style = GetWindowLongPtr(header, GWL_STYLE);
2423 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
2425 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2426 SetWindowLongPtr(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
2427 /* HDS_BUTTONS retained */
2428 style = GetWindowLongPtr(header, GWL_STYLE);
2429 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
2431 DestroyWindow(hwnd);
2433 /* create with LVS_NOSORTHEADER */
2434 hwnd = create_listview_control(LVS_NOSORTHEADER);
2435 ok(hwnd != NULL, "failed to create a listview window\n");
2437 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
2438 ok(IsWindow(header), "header expected\n");
2440 style = GetWindowLongPtr(header, GWL_STYLE);
2441 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2443 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2444 SetWindowLongPtr(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
2445 /* not changed here */
2446 style = GetWindowLongPtr(header, GWL_STYLE);
2447 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
2449 DestroyWindow(hwnd);
2452 static void test_setredraw(void)
2458 hwnd = create_listview_control(0);
2459 ok(hwnd != NULL, "failed to create a listview window\n");
2461 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
2462 ListView seems to handle it internally without DefWinProc */
2464 /* default value first */
2465 ret = SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
2468 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2469 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2470 ret = SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
2472 style = GetWindowLongPtr(hwnd, GWL_STYLE);
2473 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
2475 DestroyWindow(hwnd);
2478 static void test_hittest(void)
2484 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
2487 HIMAGELIST himl, himl2;
2490 hwnd = create_listview_control(0);
2491 ok(hwnd != NULL, "failed to create a listview window\n");
2493 /* LVS_REPORT with a single subitem (2 columns) */
2494 insert_column(hwnd, 0);
2495 insert_column(hwnd, 1);
2496 insert_item(hwnd, 0);
2499 /* the only purpose of that line is to be as long as a half item rect */
2500 item.pszText = text;
2501 r = SendMessage(hwnd, LVM_SETITEMTEXT, 0, (LPARAM)&item);
2504 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2506 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
2509 memset(&bounds, 0, sizeof(bounds));
2510 bounds.left = LVIR_BOUNDS;
2511 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
2512 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
2513 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
2514 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
2517 /* LVS_EX_FULLROWSELECT not set, no icons attached */
2518 x = pos.x + 50; /* column half width */
2519 y = pos.y + (bounds.bottom - bounds.top) / 2;
2520 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, FALSE, FALSE, __LINE__);
2521 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2522 x = pos.x + 150; /* outside column */
2523 y = pos.y + (bounds.bottom - bounds.top) / 2;
2524 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2525 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, TRUE, TRUE, TRUE, __LINE__);
2526 /* parent client area is 100x100 by default */
2527 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
2528 x = pos.x + 150; /* outside column */
2529 y = pos.y + (bounds.bottom - bounds.top) / 2;
2530 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, FALSE, FALSE, __LINE__);
2531 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2532 /* the same with LVS_EX_FULLROWSELECT */
2533 SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
2534 x = pos.x + 150; /* outside column */
2535 y = pos.y + (bounds.bottom - bounds.top) / 2;
2536 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, FALSE, FALSE, __LINE__);
2537 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE, __LINE__);
2538 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
2539 x = pos.x + 150; /* outside column */
2540 y = pos.y + (bounds.bottom - bounds.top) / 2;
2541 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, FALSE, FALSE, __LINE__);
2542 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, TRUE, TRUE, TRUE, __LINE__);
2543 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
2544 himl = ImageList_Create(16, 16, 0, 4, 4);
2545 ok(himl != NULL, "failed to create imagelist\n");
2546 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2547 ok(hbmp != NULL, "failed to create bitmap\n");
2548 r = ImageList_Add(himl, hbmp, 0);
2549 ok(r == 0, "should be zero\n");
2550 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
2551 ok(hbmp != NULL, "failed to create bitmap\n");
2552 r = ImageList_Add(himl, hbmp, 0);
2553 ok(r == 1, "should be one\n");
2555 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2556 ok(r == 0, "should return zero\n");
2558 item.mask = LVIF_IMAGE;
2562 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2566 y = pos.y + (bounds.bottom - bounds.top) / 2;
2567 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2568 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2570 /* state icons indices are 1 based, check with valid index */
2571 item.mask = LVIF_STATE;
2572 item.state = INDEXTOSTATEIMAGEMASK(1);
2573 item.stateMask = LVIS_STATEIMAGEMASK;
2576 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2580 y = pos.y + (bounds.bottom - bounds.top) / 2;
2581 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, __LINE__);
2582 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE, __LINE__);
2584 himl2 = (HIMAGELIST)SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
2585 ok(himl2 == himl, "should return handle\n");
2587 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
2588 ok(r == 0, "should return zero\n");
2591 y = pos.y + (bounds.bottom - bounds.top) / 2;
2592 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, FALSE, FALSE, __LINE__);
2593 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE, __LINE__);
2595 DestroyWindow(hwnd);
2598 static void test_getviewrect(void)
2605 hwnd = create_listview_control(0);
2606 ok(hwnd != NULL, "failed to create a listview window\n");
2609 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2612 insert_column(hwnd, 0);
2613 insert_column(hwnd, 1);
2615 memset(&item, 0, sizeof(item));
2618 SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2620 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
2622 r = SendMessage(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
2625 rect.left = rect.right = rect.top = rect.bottom = -1;
2626 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2628 /* left is set to (2e31-1) - XP SP2 */
2629 expect(0, rect.right);
2630 expect(0, rect.top);
2631 expect(0, rect.bottom);
2633 /* switch to LVS_ICON */
2634 SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~LVS_REPORT);
2636 rect.left = rect.right = rect.top = rect.bottom = -1;
2637 r = SendMessage(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
2639 expect(0, rect.left);
2640 expect(0, rect.top);
2641 /* precise value differs for 2k, XP and Vista */
2642 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
2643 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
2645 DestroyWindow(hwnd);
2648 static void test_getitemposition(void)
2655 hwnd = create_listview_control(0);
2656 ok(hwnd != NULL, "failed to create a listview window\n");
2657 header = subclass_header(hwnd);
2659 /* LVS_REPORT, single item, no columns added */
2660 insert_item(hwnd, 0);
2662 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2665 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2667 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
2669 /* LVS_REPORT, single item, single column */
2670 insert_column(hwnd, 0);
2672 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2675 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2677 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
2679 memset(&rect, 0, sizeof(rect));
2680 SendMessage(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
2683 /* offset by header height */
2684 expect(rect.bottom - rect.top, pt.y);
2686 DestroyWindow(hwnd);
2689 static void test_columnscreation(void)
2694 hwnd = create_listview_control(0);
2695 ok(hwnd != NULL, "failed to create a listview window\n");
2697 insert_item(hwnd, 0);
2699 /* headers columns aren't created automatically */
2700 header = (HWND)SendMessage(hwnd, LVM_GETHEADER, 0, 0);
2701 ok(IsWindow(header), "Expected header handle\n");
2702 r = SendMessage(header, HDM_GETITEMCOUNT, 0, 0);
2705 DestroyWindow(hwnd);
2708 static void test_getitemrect(void)
2720 hwnd = create_listview_control(0);
2721 ok(hwnd != NULL, "failed to create a listview window\n");
2724 memset(&item, 0, sizeof(item));
2727 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2730 rect.left = LVIR_BOUNDS;
2731 rect.right = rect.top = rect.bottom = -1;
2732 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2735 /* zero width rectangle with no padding */
2736 expect(0, rect.left);
2737 todo_wine expect(0, rect.right);
2739 insert_column(hwnd, 0);
2740 insert_column(hwnd, 1);
2742 col.mask = LVCF_WIDTH;
2744 r = SendMessage(hwnd, LVM_SETCOLUMN, 0, (LPARAM)&col);
2747 col.mask = LVCF_WIDTH;
2749 r = SendMessage(hwnd, LVM_SETCOLUMN, 1, (LPARAM)&col);
2752 rect.left = LVIR_BOUNDS;
2753 rect.right = rect.top = rect.bottom = -1;
2754 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2757 /* still no left padding */
2758 expect(0, rect.left);
2759 expect(150, rect.right);
2761 rect.left = LVIR_SELECTBOUNDS;
2762 rect.right = rect.top = rect.bottom = -1;
2763 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2766 expect(2, rect.left);
2768 rect.left = LVIR_LABEL;
2769 rect.right = rect.top = rect.bottom = -1;
2770 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2772 /* padding, column width */
2773 expect(2, rect.left);
2774 expect(50, rect.right);
2776 /* no icons attached */
2777 rect.left = LVIR_ICON;
2778 rect.right = rect.top = rect.bottom = -1;
2779 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2782 expect(2, rect.left);
2783 expect(2, rect.right);
2786 order[0] = 1; order[1] = 0;
2787 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
2790 r = SendMessage(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
2792 /* 1 indexed column width + padding */
2793 todo_wine expect(102, pt.x);
2794 /* rect is at zero too */
2795 rect.left = LVIR_BOUNDS;
2796 rect.right = rect.top = rect.bottom = -1;
2797 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2799 expect(0, rect.left);
2800 /* just width sum */
2801 expect(150, rect.right);
2803 rect.left = LVIR_SELECTBOUNDS;
2804 rect.right = rect.top = rect.bottom = -1;
2805 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2807 /* column width + padding */
2808 todo_wine expect(102, rect.left);
2810 /* back to initial order */
2811 order[0] = 0; order[1] = 1;
2812 r = SendMessage(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
2816 himl = ImageList_Create(16, 16, 0, 2, 2);
2817 ok(himl != NULL, "failed to create imagelist\n");
2818 hbm = CreateBitmap(16, 16, 1, 1, NULL);
2819 ok(hbm != NULL, "failed to create bitmap\n");
2820 r = ImageList_Add(himl, hbm, 0);
2821 ok(r == 0, "should be zero\n");
2822 hbm = CreateBitmap(16, 16, 1, 1, NULL);
2823 ok(hbm != NULL, "failed to create bitmap\n");
2824 r = ImageList_Add(himl, hbm, 0);
2825 ok(r == 1, "should be one\n");
2827 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
2828 ok(r == 0, "should return zero\n");
2830 item.mask = LVIF_STATE;
2831 item.state = INDEXTOSTATEIMAGEMASK(1);
2832 item.stateMask = LVIS_STATEIMAGEMASK;
2835 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2839 rect.left = LVIR_ICON;
2840 rect.right = rect.top = rect.bottom = -1;
2841 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2843 /* padding + stateicon width */
2844 expect(18, rect.left);
2845 expect(18, rect.right);
2847 rect.left = LVIR_LABEL;
2848 rect.right = rect.top = rect.bottom = -1;
2849 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2851 /* padding + stateicon width -> column width */
2852 expect(18, rect.left);
2853 expect(50, rect.right);
2855 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)NULL);
2856 ok(r != 0, "should return current list handle\n");
2858 r = SendMessage(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
2859 ok(r == 0, "should return zero\n");
2861 item.mask = LVIF_STATE | LVIF_IMAGE;
2864 item.stateMask = ~0;
2867 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2871 rect.left = LVIR_ICON;
2872 rect.right = rect.top = rect.bottom = -1;
2873 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2875 /* padding, icon width */
2876 expect(2, rect.left);
2877 expect(18, rect.right);
2879 rect.left = LVIR_LABEL;
2880 rect.right = rect.top = rect.bottom = -1;
2881 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2883 /* padding + icon width -> column width */
2884 expect(18, rect.left);
2885 expect(50, rect.right);
2888 rect.left = LVIR_SELECTBOUNDS;
2889 rect.right = rect.top = rect.bottom = -1;
2890 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2892 /* padding, column width */
2893 expect(2, rect.left);
2894 todo_wine expect(50, rect.right);
2896 /* try with indentation */
2897 item.mask = LVIF_INDENT;
2901 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
2905 rect.left = LVIR_BOUNDS;
2906 rect.right = rect.top = rect.bottom = -1;
2907 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2909 /* padding + 1 icon width, column width */
2910 expect(0, rect.left);
2911 expect(150, rect.right);
2914 rect.left = LVIR_SELECTBOUNDS;
2915 rect.right = rect.top = rect.bottom = -1;
2916 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2918 /* padding + 1 icon width, column width */
2919 expect(2 + 16, rect.left);
2920 todo_wine expect(50, rect.right);
2923 rect.left = LVIR_LABEL;
2924 rect.right = rect.top = rect.bottom = -1;
2925 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2927 /* padding + 2 icon widths, column width */
2928 expect(2 + 16*2, rect.left);
2929 expect(50, rect.right);
2932 rect.left = LVIR_ICON;
2933 rect.right = rect.top = rect.bottom = -1;
2934 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
2936 /* padding + 1 icon width indentation, icon width */
2937 expect(2 + 16, rect.left);
2938 expect(34, rect.right);
2941 DestroyWindow(hwnd);
2944 static void test_editbox(void)
2946 HWND hwnd, hwndedit, hwndedit2;
2949 static CHAR testitemA[] = "testitem";
2950 static CHAR testitem1A[] = "testitem1";
2951 static CHAR buffer[10];
2953 hwnd = create_listview_control(LVS_EDITLABELS);
2954 ok(hwnd != NULL, "failed to create a listview window\n");
2956 insert_column(hwnd, 0);
2958 memset(&item, 0, sizeof(item));
2959 item.mask = LVIF_TEXT;
2960 item.pszText = testitemA;
2963 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
2966 /* setting focus is necessary */
2968 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
2969 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
2971 /* modify initial string */
2972 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
2974 /* return focus to listview */
2977 memset(&item, 0, sizeof(item));
2978 item.mask = LVIF_TEXT;
2979 item.pszText = buffer;
2980 item.cchTextMax = 10;
2983 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
2986 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
2988 /* send LVM_EDITLABEL on already created edit */
2990 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
2991 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
2992 /* focus will be set to edit */
2993 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
2994 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
2995 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
2997 /* creating label disabled when control isn't focused */
2999 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3000 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3002 /* check EN_KILLFOCUS handling */
3003 memset(&item, 0, sizeof(item));
3004 item.pszText = testitemA;
3007 r = SendMessage(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3011 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3012 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3013 /* modify edit and notify control that it lost focus */
3014 r = SendMessage(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
3016 r = SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
3018 memset(&item, 0, sizeof(item));
3019 item.pszText = buffer;
3020 item.cchTextMax = 10;
3023 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3024 expect(lstrlen(item.pszText), r);
3025 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3026 /* end edit without saving */
3027 r = SendMessage(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
3029 memset(&item, 0, sizeof(item));
3030 item.pszText = buffer;
3031 item.cchTextMax = 10;
3034 r = SendMessage(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
3035 expect(lstrlen(item.pszText), r);
3036 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
3038 /* LVM_EDITLABEL with -1 destroys current edit */
3039 hwndedit = (HWND)SendMessage(hwnd, LVM_GETEDITCONTROL, 0, 0);
3040 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3041 /* no edit present */
3042 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3043 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
3044 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3045 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3047 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3048 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -1, 0);
3049 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3050 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3051 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3052 /* check another negative value */
3053 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3054 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3055 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3056 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, -2, 0);
3057 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3058 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3059 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3060 /* and value greater then max item index */
3061 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3062 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3063 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
3064 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
3065 hwndedit2 = (HWND)SendMessage(hwnd, LVM_EDITLABEL, r, 0);
3066 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
3067 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
3068 ok(GetFocus() == hwnd, "Expected List to be focused\n");
3070 /* messaging tests */
3072 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3074 hwndedit = (HWND)SendMessage(hwnd, LVM_EDITLABEL, 0, 0);
3075 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
3076 /* testing only sizing messages */
3077 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
3078 "edit box create - sizing", TRUE);
3080 DestroyWindow(hwnd);
3083 START_TEST(listview)
3086 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
3088 hComctl32 = GetModuleHandleA("comctl32.dll");
3089 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
3090 if (pInitCommonControlsEx)
3092 INITCOMMONCONTROLSEX iccex;
3093 iccex.dwSize = sizeof(iccex);
3094 iccex.dwICC = ICC_LISTVIEW_CLASSES;
3095 pInitCommonControlsEx(&iccex);
3098 InitCommonControls();
3100 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
3102 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3103 hwndparent = create_parent_window();
3104 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent window", TRUE);
3105 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3113 test_icon_spacing();
3116 test_item_position();
3121 test_subitem_rect();
3125 test_nosortheader();
3129 test_getitemposition();
3130 test_columnscreation();
3133 DestroyWindow(hwndparent);