ReactOS 0.4.16-dev-258-g81860b4
listview.c
Go to the documentation of this file.
1/*
2 * ListView tests
3 *
4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009-2014 Nikolay Sivov
7 *
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.
12 *
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.
17 *
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
21 */
22
23#include <stdio.h>
24#include <windows.h>
25#include <commctrl.h>
26
27#include "wine/test.h"
28#include "v6util.h"
29#include "msg.h"
30
31static HIMAGELIST (WINAPI *pImageList_Create)(int, int, UINT, int, int);
32static BOOL (WINAPI *pImageList_Destroy)(HIMAGELIST);
33static int (WINAPI *pImageList_Add)(HIMAGELIST, HBITMAP, HBITMAP);
34static BOOL (WINAPI *p_TrackMouseEvent)(TRACKMOUSEEVENT *);
35
44};
45
46#define LISTVIEW_ID 0
47#define HEADER_ID 1
48
49#define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
50#define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
51 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
52
53static const WCHAR testparentclassW[] =
54 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
55
57/* prevents edit box creation, LVN_BEGINLABELEDIT return value */
59/* return nonzero on NM_HOVER */
61/* notification data for LVN_ITEMCHANGED */
63/* notification data for LVN_ITEMCHANGING */
65/* format reported to control:
66 -1 falls to defproc, anything else returned */
68/* indicates we're running < 5.80 version */
70/* item data passed to LVN_GETDISPINFOA */
72/* alter notification code A->W */
74/* dispinfo data sent with LVN_LVN_ENDLABELEDIT */
76/* when this is set focus will be tested on LVN_DELETEITEM */
78/* Whether to send WM_KILLFOCUS to the edit control during LVN_ENDLABELEDIT */
80
81static HWND subclass_editbox(HWND hwndListview);
82
83static void init_functions(void)
84{
85 HMODULE hComCtl32 = LoadLibraryA("comctl32.dll");
86
87#define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
92#undef X
93}
94
96
98 { WM_NOTIFYFORMAT, sent },
99 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
100 { WM_MEASUREITEM, sent },
102 { 0 }
103};
104
105static const struct message redraw_listview_seq[] = {
106 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
107 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
108 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
110 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
111 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
113 { 0 }
114};
115
116static const struct message listview_icon_spacing_seq[] = {
117 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
118 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
119 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
120 { 0 }
121};
122
123static const struct message listview_color_seq[] = {
124 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
125 { LVM_GETBKCOLOR, sent },
126 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
128 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
130
131 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
132 { LVM_GETBKCOLOR, sent },
133 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
135 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
137
139 { LVM_GETBKCOLOR, sent },
144
145 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
146 { LVM_GETBKCOLOR, sent },
147 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
149 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
151 { 0 }
152};
153
154static const struct message listview_item_count_seq[] = {
160 { LVM_DELETEITEM, sent|wparam, 2 },
171 { 0 }
172};
173
174static const struct message listview_itempos_seq[] = {
186 { 0 }
187};
188
190 { WM_STYLECHANGING, sent },
191 { WM_STYLECHANGED, sent },
192 { 0 }
193};
194
195static const struct message listview_getorderarray_seq[] = {
197 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
199 { HDM_GETORDERARRAY, sent|id|wparam, 0, 0, HEADER_ID },
200 { 0 }
201};
202
203static const struct message listview_setorderarray_seq[] = {
205 { HDM_SETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
207 { HDM_SETORDERARRAY, sent|id|wparam, 0, 0, HEADER_ID },
208 { 0 }
209};
210
211static const struct message empty_seq[] = {
212 { 0 }
213};
214
216 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
217 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
218 { 0 }
219};
220
221static const struct message forward_erasebkgnd_parent_seq[] = {
222 { WM_ERASEBKGND, sent },
223 { 0 }
224};
225
227 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
228 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
229 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
230 { 0 }
231};
232
234 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
235 { 0 }
236};
237
239 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
240 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
242 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
243 { 0 }
244};
245
247 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
248 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
249 { 0 }
250};
251
252static const struct message change_all_parent_seq[] = {
253 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
254 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
255
256 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
257 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
258
259 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
260 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
261
262 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
263 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
264
265 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
266 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
267 { 0 }
268};
269
270static const struct message changing_all_parent_seq[] = {
271 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
272 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
273 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
274 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
275 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
276 { 0 }
277};
278
280 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
281 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
282 { 0 }
283};
284
285static const struct message single_getdispinfo_parent_seq[] = {
286 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
287 { 0 }
288};
289
290static const struct message getitemposition_seq1[] = {
292 { 0 }
293};
294
295static const struct message getitemposition_seq2[] = {
297 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
298 { 0 }
299};
300
301static const struct message getsubitemrect_seq[] = {
303 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
305 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
306 { LVM_GETSUBITEMRECT, sent|id|wparam, -10, 0, LISTVIEW_ID },
307 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
309 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
310 { 0 }
311};
312
313static const struct message editbox_create_pos[] = {
314 /* sequence sent after LVN_BEGINLABELEDIT */
315 /* next two are 4.7x specific */
318
320 { WM_NCCALCSIZE, sent },
324 /* the rest is todo, skipped in 4.7x */
327 { 0 }
328};
329
330static const struct message scroll_parent_seq[] = {
331 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
332 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
333 { 0 }
334};
335
336static const struct message setredraw_seq[] = {
338 { 0 }
339};
340
341static const struct message lvs_ex_transparentbkgnd_seq[] = {
343 { 0 }
344};
345
346static const struct message edit_end_nochange[] = {
348 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW }, /* todo */
349 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
350 { 0 }
351};
352
353static const struct message hover_parent[] = {
354 { WM_GETDLGCODE, sent }, /* todo_wine */
355 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
356 { 0 }
357};
358
359static const struct message listview_destroy[] = {
360 { 0x0090, sent|optional }, /* Vista */
362 { WM_SHOWWINDOW, sent },
365 { WM_DESTROY, sent },
367 { WM_NCDESTROY, sent },
368 { 0 }
369};
370
371static const struct message listview_ownerdata_destroy[] = {
372 { 0x0090, sent|optional }, /* Vista */
374 { WM_SHOWWINDOW, sent },
377 { WM_DESTROY, sent },
378 { WM_NCDESTROY, sent },
379 { 0 }
380};
381
382static const struct message listview_ownerdata_deleteall[] = {
385 { 0 }
386};
387
388static const struct message listview_header_changed_seq[] = {
389 { LVM_SETCOLUMNA, sent },
390 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
391 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
392 { 0 }
393};
394
395static const struct message parent_header_click_seq[] = {
396 { WM_NOTIFY, sent|id, 0, 0, LVN_COLUMNCLICK },
397 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCLICKA },
398 { 0 }
399};
400
403 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
404 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
405 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGEDA },
407 { 0 }
408};
409
410static const struct message listview_set_imagelist[] = {
412 { 0 }
413};
414
415static const struct message listview_header_set_imagelist[] = {
417 { HDM_SETIMAGELIST, sent|id, 0, 0, HEADER_ID },
418 { 0 }
419};
420
421static const struct message parent_insert_focused_seq[] = {
422 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
423 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
424 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
425 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
426 { WM_NOTIFY, sent|id, 0, 0, LVN_INSERTITEM },
427 { 0 }
428};
429
430static const struct message parent_report_cd_seq[] = {
439 { 0 }
440};
441
442static const struct message parent_list_cd_seq[] = {
447 { 0 }
448};
449
450static const struct message listview_end_label_edit[] = {
453 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
454 { WM_NOTIFY, sent|id|optional, 0, 0, NM_CUSTOMDRAW }, /* XP */
455 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
456 { 0 }
457};
458
461 { WM_COMMAND, sent|id|optional, 0, 0, EN_KILLFOCUS }, /* todo: not sent by wine yet */
462 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
463 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
464 { WM_NOTIFY, sent|id|optional, 0, 0, NM_CUSTOMDRAW }, /* XP */
465 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
466 { 0 }
467};
468
470{
471 static LONG defwndproc_counter = 0;
472 LRESULT ret;
473 struct message msg;
474
475 msg.message = message;
476 msg.flags = sent|wparam|lparam;
477 if (defwndproc_counter) msg.flags |= defwinproc;
478 msg.wParam = wParam;
479 msg.lParam = lParam;
480 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
481 if (message == WM_COMMAND) msg.id = HIWORD(wParam);
482
483 /* log system messages, except for painting */
484 if (message < WM_USER &&
485 message != WM_PAINT &&
487 message != WM_NCPAINT &&
489 message != WM_GETTEXT &&
490 message != WM_GETICON &&
492 {
495 }
497
498 switch (message)
499 {
500 case WM_NOTIFY:
501 {
502 switch (((NMHDR*)lParam)->code)
503 {
505 {
506 HWND edit = NULL;
507
508 /* subclass edit box */
509 if (!blockEdit)
510 edit = subclass_editbox(((NMHDR*)lParam)->hwndFrom);
511
512 if (edit)
513 {
514 INT len = SendMessageA(edit, EM_GETLIMITTEXT, 0, 0);
515 ok(len == 259 || broken(len == 260) /* includes NULL in NT4 */,
516 "text limit %d, expected 259\n", len);
517 }
518
519 return blockEdit;
520 }
522 {
523 HWND edit;
524
525 /* always accept new item text */
528
529 /* edit control still available from this notification */
530 edit = (HWND)SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETEDITCONTROL, 0, 0);
531 ok(IsWindow(edit), "expected valid edit control handle\n");
532 ok((GetWindowLongA(edit, GWL_STYLE) & ES_MULTILINE) == 0, "edit is multiline\n");
533
535 SendMessageA(edit, WM_KILLFOCUS, 0, 0);
536
537 return TRUE;
538 }
539 case LVN_ITEMCHANGING:
540 {
541 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
542 g_nmlistview_changing = *nmlv;
543 }
544 break;
545 case LVN_ITEMCHANGED:
546 {
547 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
548 g_nmlistview = *nmlv;
549 }
550 break;
551 case LVN_GETDISPINFOA:
552 {
553 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
554 g_itema = dispinfo->item;
555
556 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
557 {
558 static const WCHAR testW[] = {'T','E','S','T',0};
559 dispinfo->hdr.code = LVN_GETDISPINFOW;
560 memcpy(dispinfo->item.pszText, testW, sizeof(testW));
561 }
562
563 /* test control buffer size for text, 10 used to mask cases when control
564 is using caller buffer to process LVM_GETITEM for example */
565 if (dispinfo->item.mask & LVIF_TEXT && dispinfo->item.cchTextMax > 10)
566 ok(dispinfo->item.cchTextMax == 260 ||
567 broken(dispinfo->item.cchTextMax == 264) /* NT4 reports aligned size */,
568 "buffer size %d\n", dispinfo->item.cchTextMax);
569 }
570 break;
571 case LVN_DELETEITEM:
573 {
574 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
575 UINT state;
576
578 ok(state == 0, "got state %x\n", state);
579 }
580 break;
581 case NM_HOVER:
582 if (g_block_hover) return 1;
583 break;
584 }
585 break;
586 }
587 case WM_NOTIFYFORMAT:
588 {
589 /* force to return format */
590 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
591 break;
592 }
593 }
594
595 defwndproc_counter++;
598 else
600 defwndproc_counter--;
601
602 return ret;
603}
604
606{
607 WNDCLASSA clsA;
608 WNDCLASSW clsW;
609
610 if (Unicode)
611 {
612 clsW.style = 0;
614 clsW.cbClsExtra = 0;
615 clsW.cbWndExtra = 0;
617 clsW.hIcon = 0;
620 clsW.lpszMenuName = NULL;
622 }
623 else
624 {
625 clsA.style = 0;
627 clsA.cbClsExtra = 0;
628 clsA.cbWndExtra = 0;
630 clsA.hIcon = 0;
633 clsA.lpszMenuName = NULL;
634 clsA.lpszClassName = "Listview test parent class";
635 }
636
637 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
638}
639
641{
642 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
643 HWND hwnd;
644
645 if (!register_parent_wnd_class(Unicode))
646 return NULL;
647
649 notifyFormat = -1;
650
651 if (Unicode)
655 0, 0, 100, 100,
657 else
658 hwnd = CreateWindowExA(0, "Listview test parent class",
659 "Listview test parent window",
662 0, 0, 100, 100,
665 return hwnd;
666}
667
669{
671 static LONG defwndproc_counter = 0;
672 LRESULT ret;
673 struct message msg;
674
675 msg.message = message;
676 msg.flags = sent|wparam|lparam;
677 if (defwndproc_counter) msg.flags |= defwinproc;
678 msg.wParam = wParam;
679 msg.lParam = lParam;
680 msg.id = LISTVIEW_ID;
683
684 defwndproc_counter++;
686 defwndproc_counter--;
687 return ret;
688}
689
691{
692 WNDPROC oldproc;
693 HWND hwnd;
694 RECT rect;
695
699 0, 0, rect.right, rect.bottom,
701 ok(hwnd != NULL, "gle=%d\n", GetLastError());
702
703 if (!hwnd) return NULL;
704
708
709 return hwnd;
710}
711
712/* unicode listview window with specified parent */
714{
715 WNDPROC oldproc;
716 HWND hwnd;
717 RECT rect;
718 static const WCHAR nameW[] = {'f','o','o',0};
719
723 0, 0, rect.right, rect.bottom,
725 ok(hwnd != NULL, "gle=%d\n", GetLastError());
726
727 if (!hwnd) return NULL;
728
732
733 return hwnd;
734}
735
736static BOOL is_win_xp(void)
737{
739 BOOL ret;
740
742 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, LVS_EX_HEADERINALLVIEWS);
744 ret = !IsWindow(header);
745
747
748 return ret;
749}
750
752{
754 static LONG defwndproc_counter = 0;
755 struct message msg = { 0 };
756 LRESULT ret;
757
758 msg.message = message;
759 msg.flags = sent|wparam|lparam;
760 if (defwndproc_counter) msg.flags |= defwinproc;
761 msg.wParam = wParam;
762 msg.lParam = lParam;
763 msg.id = HEADER_ID;
765
766 defwndproc_counter++;
768 defwndproc_counter--;
769 return ret;
770}
771
772static HWND subclass_header(HWND hwndListview)
773{
774 WNDPROC oldproc;
775 HWND hwnd;
776
777 hwnd = (HWND)SendMessageA(hwndListview, LVM_GETHEADER, 0, 0);
781
782 return hwnd;
783}
784
786{
788 static LONG defwndproc_counter = 0;
789 struct message msg = { 0 };
790 LRESULT ret;
791
792 msg.message = message;
793 msg.flags = sent|wparam|lparam;
794 if (defwndproc_counter) msg.flags |= defwinproc;
795 msg.wParam = wParam;
796 msg.lParam = lParam;
797
798 /* all we need is sizing */
802 message == WM_MOVE ||
803 message == WM_SIZE)
804 {
806 }
807
808 defwndproc_counter++;
810 defwndproc_counter--;
811 return ret;
812}
813
814static HWND subclass_editbox(HWND hwndListview)
815{
816 WNDPROC oldproc;
817 HWND hwnd;
818
819 hwnd = (HWND)SendMessageA(hwndListview, LVM_GETEDITCONTROL, 0, 0);
823
824 return hwnd;
825}
826
827/* Performs a single LVM_HITTEST test */
828static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
829 BOOL todo_item, BOOL todo_flags, int line)
830{
831 LVHITTESTINFO lpht;
832 INT ret;
833
834 lpht.pt.x = x;
835 lpht.pt.y = y;
836 lpht.iSubItem = 10;
837
838 ret = SendMessageA(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
839
840 todo_wine_if(todo_item)
841 {
842 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
843 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
844 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
845 }
846
847 if (todo_flags)
848 {
850 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
851 }
852 else if (broken_flags)
853 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
854 "Expected flags %x, got %x\n", flags, lpht.flags);
855 else
856 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
857}
858
859#define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
860
861/* Performs a single LVM_SUBITEMHITTEST test */
863 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
864{
865 LVHITTESTINFO lpht;
866 INT ret;
867
868 lpht.pt.x = x;
869 lpht.pt.y = y;
870
872
873 todo_wine_if(todo_item)
874 {
875 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
876 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
877 }
878
879 todo_wine_if(todo_subitem)
880 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
881
882 todo_wine_if(todo_flags)
883 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
884}
885
886#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__)
887
888static void test_images(void)
889{
890 HWND hwnd;
891 INT r;
895 RECT r1, r2;
896 static CHAR hello[] = "hello";
897
898 himl = pImageList_Create(40, 40, 0, 4, 4);
899 ok(himl != NULL, "failed to create imagelist\n");
900
901 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
902 ok(hbmp != NULL, "failed to create bitmap\n");
903
904 r = pImageList_Add(himl, hbmp, 0);
905 ok(r == 0, "should be zero\n");
906
908 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
909 ok(hwnd != NULL, "failed to create listview window\n");
910
913
914 ok(r == 0, "should return zero\n");
915
917 ok(r == 0, "should return zero\n");
918
920 ok(r != 0, "got 0\n");
921
922 /* returns dimensions */
923
925 ok(r == 0, "should be zero items\n");
926
927 item.mask = LVIF_IMAGE | LVIF_TEXT;
928 item.iItem = 0;
929 item.iSubItem = 1;
930 item.iImage = 0;
931 item.pszText = 0;
933 ok(r == -1, "should fail\n");
934
935 item.iSubItem = 0;
936 item.pszText = hello;
938 ok(r == 0, "should not fail\n");
939
940 SetRect(&r1, LVIR_ICON, 0, 0, 0);
942 expect(1, r);
943
945 ok(r == TRUE, "should not fail\n");
946
947 item.iSubItem = 0;
948 item.pszText = hello;
950 ok(r == 0, "should not fail\n");
951
952 SetRect(&r2, LVIR_ICON, 0, 0, 0);
954 expect(1, r);
955
956 ok(EqualRect(&r1, &r2), "rectangle should be the same\n");
957
959
960 /* I_IMAGECALLBACK set for item, try to get image with invalid subitem. */
962 ok(hwnd != NULL, "Failed to create listview.\n");
963
964 memset(&item, 0, sizeof(item));
965 item.mask = LVIF_IMAGE;
966 item.iImage = I_IMAGECALLBACK;
968 ok(!r, "Failed to insert item.\n");
969
971
972 memset(&item, 0, sizeof(item));
973 item.mask = LVIF_IMAGE;
975 ok(r, "Failed to get item.\n");
976
978
980
981 memset(&item, 0, sizeof(item));
982 item.mask = LVIF_IMAGE;
983 item.iSubItem = 1;
985 ok(r, "Failed to get item.\n");
986
987 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "get image dispinfo 2", FALSE);
988
990}
991
992static void test_checkboxes(void)
993{
994 HWND hwnd;
996 DWORD r;
997 static CHAR text[] = "Text",
998 text2[] = "Text2",
999 text3[] = "Text3";
1000
1002 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1003 ok(hwnd != NULL, "failed to create listview window\n");
1004
1005 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
1006 item.mask = LVIF_TEXT | LVIF_STATE;
1007 item.stateMask = 0xffff;
1008 item.state = 0xfccc;
1009 item.iItem = 0;
1010 item.iSubItem = 0;
1011 item.pszText = text;
1013 expect(0, r);
1014
1015 item.iItem = 0;
1016 item.mask = LVIF_STATE;
1017 item.stateMask = 0xffff;
1019 expect(1, r);
1020 ok(item.state == 0xfccc, "state %x\n", item.state);
1021
1022 /* Don't set LVIF_STATE */
1023 item.mask = LVIF_TEXT;
1024 item.stateMask = 0xffff;
1025 item.state = 0xfccc;
1026 item.iItem = 1;
1027 item.iSubItem = 0;
1028 item.pszText = text;
1030 expect(1, r);
1031
1032 item.iItem = 1;
1033 item.mask = LVIF_STATE;
1034 item.stateMask = 0xffff;
1036 expect(1, r);
1037 ok(item.state == 0, "state %x\n", item.state);
1038
1040 expect(0, r);
1041
1042 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
1043 item.iItem = 0;
1044 item.mask = LVIF_STATE;
1045 item.stateMask = 0xffff;
1047 expect(1, r);
1048 if (item.state != 0x1ccc)
1049 {
1050 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
1052 return;
1053 }
1054
1055 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
1056 item.iItem = 2;
1057 item.mask = LVIF_TEXT;
1058 item.state = 0;
1059 item.pszText = text2;
1061 expect(2, r);
1062
1063 item.iItem = 2;
1064 item.mask = LVIF_STATE;
1065 item.stateMask = 0xffff;
1067 expect(1, r);
1068 ok(item.state == 0x1000, "state %x\n", item.state);
1069
1070 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
1071 item.iItem = 3;
1072 item.mask = LVIF_TEXT | LVIF_STATE;
1073 item.stateMask = 0xffff;
1074 item.state = 0x2aaa;
1075 item.pszText = text3;
1077 expect(3, r);
1078
1079 item.iItem = 3;
1080 item.mask = LVIF_STATE;
1081 item.stateMask = 0xffff;
1083 expect(1, r);
1084 ok(item.state == 0x1aaa, "state %x\n", item.state);
1085
1086 /* Set an item's state to checked */
1087 item.iItem = 3;
1088 item.mask = LVIF_STATE;
1089 item.stateMask = 0xf000;
1090 item.state = 0x2000;
1092 expect(1, r);
1093
1094 item.iItem = 3;
1095 item.mask = LVIF_STATE;
1096 item.stateMask = 0xffff;
1098 expect(1, r);
1099 ok(item.state == 0x2aaa, "state %x\n", item.state);
1100
1101 /* Check that only the bits we asked for are returned,
1102 * and that all the others are set to zero
1103 */
1104 item.iItem = 3;
1105 item.mask = LVIF_STATE;
1106 item.stateMask = 0xf000;
1107 item.state = 0xffff;
1109 expect(1, r);
1110 ok(item.state == 0x2000, "state %x\n", item.state);
1111
1112 /* Set the style again and check that doesn't change an item's state */
1114 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1115
1116 item.iItem = 3;
1117 item.mask = LVIF_STATE;
1118 item.stateMask = 0xffff;
1120 expect(1, r);
1121 ok(item.state == 0x2aaa, "state %x\n", item.state);
1122
1123 /* Unsetting the checkbox extended style doesn't change an item's state */
1125 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1126
1127 item.iItem = 3;
1128 item.mask = LVIF_STATE;
1129 item.stateMask = 0xffff;
1131 expect(1, r);
1132 ok(item.state == 0x2aaa, "state %x\n", item.state);
1133
1134 /* Now setting the style again will change an item's state */
1136 expect(0, r);
1137
1138 item.iItem = 3;
1139 item.mask = LVIF_STATE;
1140 item.stateMask = 0xffff;
1142 expect(1, r);
1143 ok(item.state == 0x1aaa, "state %x\n", item.state);
1144
1145 /* Toggle checkbox tests (bug 9934) */
1146 memset (&item, 0xcc, sizeof(item));
1147 item.mask = LVIF_STATE;
1148 item.iItem = 3;
1149 item.iSubItem = 0;
1150 item.state = LVIS_FOCUSED;
1151 item.stateMask = LVIS_FOCUSED;
1153 expect(1, r);
1154
1155 item.iItem = 3;
1156 item.mask = LVIF_STATE;
1157 item.stateMask = 0xffff;
1159 expect(1, r);
1160 ok(item.state == 0x1aab, "state %x\n", item.state);
1161
1163 expect(0, r);
1165 expect(0, r);
1166
1167 item.iItem = 3;
1168 item.mask = LVIF_STATE;
1169 item.stateMask = 0xffff;
1171 expect(1, r);
1172 ok(item.state == 0x2aab, "state %x\n", item.state);
1173
1175 expect(0, r);
1177 expect(0, r);
1178
1179 item.iItem = 3;
1180 item.mask = LVIF_STATE;
1181 item.stateMask = 0xffff;
1183 expect(1, r);
1184 ok(item.state == 0x1aab, "state %x\n", item.state);
1185
1187}
1188
1189static void insert_column(HWND hwnd, int idx)
1190{
1192 INT rc;
1193
1194 memset(&column, 0xcc, sizeof(column));
1195 column.mask = LVCF_SUBITEM;
1196 column.iSubItem = idx;
1197
1199 expect(idx, rc);
1200}
1201
1202static void insert_item(HWND hwnd, int idx)
1203{
1204 static CHAR text[] = "foo";
1205
1206 LVITEMA item;
1207 INT rc;
1208
1209 memset(&item, 0xcc, sizeof (item));
1210 item.mask = LVIF_TEXT;
1211 item.iItem = idx;
1212 item.iSubItem = 0;
1213 item.pszText = text;
1214
1216 expect(idx, rc);
1217}
1218
1219static void test_items(void)
1220{
1221 const LPARAM lparamTest = 0x42;
1222 static CHAR text[] = "Text";
1223 char buffA[5];
1224 HWND hwnd;
1225 LVITEMA item;
1226 DWORD r;
1227
1229 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1230 ok(hwnd != NULL, "failed to create listview window\n");
1231
1232 /*
1233 * Test setting/getting item params
1234 */
1235
1236 /* Set up two columns */
1237 insert_column(hwnd, 0);
1238 insert_column(hwnd, 1);
1239
1240 /* LVIS_SELECTED with zero stateMask */
1241 /* set */
1242 memset (&item, 0, sizeof (item));
1243 item.mask = LVIF_STATE;
1244 item.state = LVIS_SELECTED;
1245 item.stateMask = 0;
1246 item.iItem = 0;
1247 item.iSubItem = 0;
1249 expect(0, r);
1250 /* get */
1251 memset (&item, 0xcc, sizeof (item));
1252 item.mask = LVIF_STATE;
1253 item.stateMask = LVIS_SELECTED;
1254 item.state = 0;
1255 item.iItem = 0;
1256 item.iSubItem = 0;
1258 expect(1, r);
1259 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1261 ok(r, "got %d\n", r);
1262
1263 /* LVIS_SELECTED with zero stateMask */
1264 /* set */
1265 memset (&item, 0, sizeof (item));
1266 item.mask = LVIF_STATE;
1267 item.state = LVIS_FOCUSED;
1268 item.stateMask = 0;
1269 item.iItem = 0;
1270 item.iSubItem = 0;
1272 expect(0, r);
1273 /* get */
1274 memset (&item, 0xcc, sizeof (item));
1275 item.mask = LVIF_STATE;
1276 item.stateMask = LVIS_FOCUSED;
1277 item.state = 0;
1278 item.iItem = 0;
1279 item.iSubItem = 0;
1281 expect(1, r);
1282 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1284 ok(r, "got %d\n", r);
1285
1286 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1287 /* set */
1288 memset (&item, 0, sizeof (item));
1289 item.mask = LVIF_STATE;
1290 item.state = LVIS_CUT;
1291 item.stateMask = LVIS_FOCUSED;
1292 item.iItem = 0;
1293 item.iSubItem = 0;
1295 expect(0, r);
1296 /* get */
1297 memset (&item, 0xcc, sizeof (item));
1298 item.mask = LVIF_STATE;
1299 item.stateMask = LVIS_CUT;
1300 item.state = 0;
1301 item.iItem = 0;
1302 item.iSubItem = 0;
1304 expect(1, r);
1305 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1307 ok(r, "got %d\n", r);
1308
1309 /* Insert an item with just a param */
1310 memset (&item, 0xcc, sizeof (item));
1311 item.mask = LVIF_PARAM;
1312 item.iItem = 0;
1313 item.iSubItem = 0;
1314 item.lParam = lparamTest;
1316 expect(0, r);
1317
1318 /* Test getting of the param */
1319 memset (&item, 0xcc, sizeof (item));
1320 item.mask = LVIF_PARAM;
1321 item.iItem = 0;
1322 item.iSubItem = 0;
1324 expect(1, r);
1325 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1326
1327 /* Set up a subitem */
1328 memset (&item, 0xcc, sizeof (item));
1329 item.mask = LVIF_TEXT;
1330 item.iItem = 0;
1331 item.iSubItem = 1;
1332 item.pszText = text;
1334 expect(1, r);
1335
1336 item.mask = LVIF_TEXT;
1337 item.iItem = 0;
1338 item.iSubItem = 1;
1339 item.pszText = buffA;
1340 item.cchTextMax = sizeof(buffA);
1342 expect(1, r);
1343 ok(!memcmp(item.pszText, text, sizeof(text)), "got text %s, expected %s\n", item.pszText, text);
1344
1345 /* set up with extra flag */
1346 /* 1. reset subitem text */
1347 item.mask = LVIF_TEXT;
1348 item.iItem = 0;
1349 item.iSubItem = 1;
1350 item.pszText = NULL;
1352 expect(1, r);
1353
1354 item.mask = LVIF_TEXT;
1355 item.iItem = 0;
1356 item.iSubItem = 1;
1357 item.pszText = buffA;
1358 buffA[0] = 'a';
1359 item.cchTextMax = sizeof(buffA);
1361 expect(1, r);
1362 ok(item.pszText[0] == 0, "got %p\n", item.pszText);
1363
1364 /* 2. set new text with extra flag specified */
1366 item.iItem = 0;
1367 item.iSubItem = 1;
1368 item.pszText = text;
1370 ok(r == 1 || broken(r == 0) /* NT4 */, "ret %d\n", r);
1371
1372 if (r == 1)
1373 {
1374 item.mask = LVIF_TEXT;
1375 item.iItem = 0;
1376 item.iSubItem = 1;
1377 item.pszText = buffA;
1378 buffA[0] = 'a';
1379 item.cchTextMax = sizeof(buffA);
1381 expect(1, r);
1382 ok(!memcmp(item.pszText, text, sizeof(text)), "got %s, expected %s\n", item.pszText, text);
1383 }
1384
1385 /* Query param from subitem: returns main item param */
1386 memset (&item, 0xcc, sizeof (item));
1387 item.mask = LVIF_PARAM;
1388 item.iItem = 0;
1389 item.iSubItem = 1;
1391 expect(1, r);
1392 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1393
1394 /* Set up param on first subitem: no effect */
1395 memset (&item, 0xcc, sizeof (item));
1396 item.mask = LVIF_PARAM;
1397 item.iItem = 0;
1398 item.iSubItem = 1;
1399 item.lParam = lparamTest+1;
1401 expect(0, r);
1402
1403 /* Query param from subitem again: should still return main item param */
1404 memset (&item, 0xcc, sizeof (item));
1405 item.mask = LVIF_PARAM;
1406 item.iItem = 0;
1407 item.iSubItem = 1;
1409 expect(1, r);
1410 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1411
1412 /**** Some tests of state highlighting ****/
1413 memset (&item, 0xcc, sizeof (item));
1414 item.mask = LVIF_STATE;
1415 item.iItem = 0;
1416 item.iSubItem = 0;
1417 item.state = LVIS_SELECTED;
1418 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1420 expect(1, r);
1421 item.iSubItem = 1;
1422 item.state = LVIS_DROPHILITED;
1424 expect(1, r);
1425
1426 memset (&item, 0xcc, sizeof (item));
1427 item.mask = LVIF_STATE;
1428 item.iItem = 0;
1429 item.iSubItem = 0;
1430 item.stateMask = -1;
1432 expect(1, r);
1433 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1434 item.iSubItem = 1;
1436 expect(1, r);
1437 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1438
1439 /* some notnull but meaningless masks */
1440 memset (&item, 0, sizeof(item));
1441 item.mask = LVIF_NORECOMPUTE;
1442 item.iItem = 0;
1443 item.iSubItem = 0;
1445 expect(1, r);
1446 memset (&item, 0, sizeof(item));
1447 item.mask = LVIF_DI_SETITEM;
1448 item.iItem = 0;
1449 item.iSubItem = 0;
1451 expect(1, r);
1452
1453 /* set text to callback value already having it */
1455 expect(TRUE, r);
1456 memset (&item, 0, sizeof (item));
1457 item.mask = LVIF_TEXT;
1458 item.pszText = LPSTR_TEXTCALLBACKA;
1459 item.iItem = 0;
1461 expect(0, r);
1462 memset (&item, 0, sizeof (item));
1463
1465
1466 item.pszText = LPSTR_TEXTCALLBACKA;
1468 expect(TRUE, r);
1469
1471 "check callback text comparison rule", FALSE);
1472
1474}
1475
1476static void test_columns(void)
1477{
1478 HWND hwnd, header;
1480 LVITEMA item;
1481 INT order[2];
1482 CHAR buff[5];
1483 DWORD rc;
1484
1486 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1487 ok(hwnd != NULL, "failed to create listview window\n");
1488
1490 ok(header == NULL, "got %p\n", header);
1491
1493 ok(rc == 0, "got %d\n", rc);
1494
1496 ok(header == NULL, "got %p\n", header);
1497
1499
1501 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1502 ok(hwnd != NULL, "failed to create listview window\n");
1503
1504 rc = SendMessageA(hwnd, LVM_DELETECOLUMN, -1, 0);
1505 ok(!rc, "got %d\n", rc);
1506
1507 rc = SendMessageA(hwnd, LVM_DELETECOLUMN, 0, 0);
1508 ok(!rc, "got %d\n", rc);
1509
1510 /* Add a column with no mask */
1511 memset(&column, 0xcc, sizeof(column));
1512 column.mask = 0;
1514 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1515
1516 /* Check its width */
1518 ok(rc == 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1519
1521
1522 /* LVM_GETCOLUMNORDERARRAY */
1525
1526 memset(&column, 0, sizeof(column));
1527 column.mask = LVCF_WIDTH;
1528 column.cx = 100;
1530 expect(0, rc);
1531
1532 column.cx = 200;
1534 expect(1, rc);
1535
1537
1539 expect(1, rc);
1540 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1541 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1542
1544 expect(0, rc);
1545
1547
1548 /* LVM_SETCOLUMNORDERARRAY */
1550
1551 order[0] = 0;
1552 order[1] = 1;
1554 expect(1, rc);
1555
1557 expect(0, rc);
1558
1560
1561 /* after column added subitem is considered as present */
1562 insert_item(hwnd, 0);
1563
1565
1566 item.pszText = buff;
1567 item.cchTextMax = sizeof(buff);
1568 item.iItem = 0;
1569 item.iSubItem = 1;
1570 item.mask = LVIF_TEXT;
1571 memset(&g_itema, 0, sizeof(g_itema));
1573 expect(1, rc);
1574 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1575
1577 "get subitem text after column added", FALSE);
1578
1580
1581 /* Columns are not created right away. */
1583 ok(hwnd != NULL, "Failed to create a listview window.\n");
1584
1585 insert_item(hwnd, 0);
1586
1588 ok(IsWindow(header), "Expected header handle.\n");
1590 ok(!rc, "Unexpected column count.\n");
1591
1593}
1594
1595/* test setting imagelist between WM_NCCREATE and WM_CREATE */
1598
1600{
1601 LRESULT ret;
1602
1603 if (uMsg == WM_CREATE)
1604 {
1606 lpcs->style |= LVS_REPORT;
1607 }
1610 return ret;
1611}
1612
1613/* Header creation is delayed in classic implementation. */
1614#define TEST_NO_HEADER(a) test_header_presence_(a, FALSE, __LINE__)
1615#define TEST_HEADER_EXPECTED(a) test_header_presence_(a, TRUE, __LINE__)
1616#define TEST_NO_HEADER2(a, b) test_header_presence_(a, b, __LINE__)
1617static void test_header_presence_(HWND hwnd, BOOL present, int line)
1618{
1620
1621 if (present)
1622 {
1623 ok_(__FILE__, line)(IsWindow(header), "Header should have been created.\n");
1624 if (header) /* FIXME: remove when todo's are fixed */
1625 ok_(__FILE__, line)(header == GetDlgItem(hwnd, 0), "Dialog item expected.\n");
1626 }
1627 else
1628 {
1629 ok_(__FILE__, line)(!IsWindow(header), "Header shouldn't be created.\n");
1630 ok_(__FILE__, line)(NULL == GetDlgItem(hwnd, 0), "NULL dialog item expected.\n");
1631 }
1632}
1633
1634static void test_create(BOOL is_version_6)
1635{
1636 static const WCHAR testtextW[] = {'t','e','s','t',' ','t','e','x','t',0};
1637 char buff[16];
1638 HWND hList;
1639 HWND hHeader;
1640 LONG_PTR ret;
1641 LONG r;
1642 LVCOLUMNA col;
1643 RECT rect;
1644 WNDCLASSEXA cls;
1645 DWORD style;
1646 ATOM class;
1647
1648 if (is_win_xp() && is_version_6)
1649 {
1650 win_skip("Skipping some tests on XP.\n");
1651 return;
1652 }
1653
1654 cls.cbSize = sizeof(WNDCLASSEXA);
1656 ok(r, "Failed to get class info.\n");
1659 cls.lpszClassName = "MyListView32";
1660 class = RegisterClassExA(&cls);
1661 ok(class, "Failed to register class.\n");
1662
1663 test_create_imagelist = pImageList_Create(16, 16, 0, 5, 10);
1664 hList = CreateWindowA("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1665 ok((HIMAGELIST)SendMessageA(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1666 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1667 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1668 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1670
1671 /* header isn't created on LVS_ICON and LVS_LIST styles */
1672 hList = CreateWindowA(WC_LISTVIEWA, "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1674
1675 /* insert column */
1676 memset(&col, 0, sizeof(LVCOLUMNA));
1677 col.mask = LVCF_WIDTH;
1678 col.cx = 100;
1680 expect(0, r);
1682 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1683 style = GetWindowLongA(hHeader, GWL_STYLE);
1684 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1686
1687 hList = CreateWindowA(WC_LISTVIEWA, "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1690 /* insert column */
1691 memset(&col, 0, sizeof(LVCOLUMNA));
1692 col.mask = LVCF_WIDTH;
1693 col.cx = 100;
1695 expect(0, r);
1698
1699 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1700 hList = CreateWindowA(WC_LISTVIEWA, "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1703 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1706 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1709
1710 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1711 hList = CreateWindowA(WC_LISTVIEWA, "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1715 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1718 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1721
1722 /* LVS_REPORT without WS_VISIBLE */
1723 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1725 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1726todo_wine_if(is_version_6)
1727 TEST_NO_HEADER2(hList, is_version_6);
1728
1729 /* insert column */
1730 memset(&col, 0, sizeof(LVCOLUMNA));
1731 col.mask = LVCF_WIDTH;
1732 col.cx = 100;
1734 expect(0, r);
1737
1738 /* LVS_REPORT without WS_VISIBLE, try to show it */
1739 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1741todo_wine_if(is_version_6)
1742 TEST_NO_HEADER2(hList, is_version_6);
1743
1747
1748 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1750 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1752 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1753 /* HDS_DRAGDROP set by default */
1754 ok(GetWindowLongPtrA(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1756
1757 /* setting LVS_EX_HEADERDRAGDROP creates header */
1758 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1760todo_wine_if(is_version_6)
1761 TEST_NO_HEADER2(hList, is_version_6);
1762
1766
1767 /* setting LVS_EX_GRIDLINES creates header */
1768 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1770todo_wine_if(is_version_6)
1771 TEST_NO_HEADER2(hList, is_version_6);
1772
1776
1777 /* setting LVS_EX_FULLROWSELECT creates header */
1778 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1780todo_wine_if(is_version_6)
1781 TEST_NO_HEADER2(hList, is_version_6);
1785
1786 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1790 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1792
1793 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1794 hList = CreateWindowA(WC_LISTVIEWA, "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1796todo_wine_if(is_version_6)
1797 TEST_NO_HEADER2(hList, is_version_6);
1798
1799 SetRect(&rect, LVIR_BOUNDS, 1, -10, -10);
1801 ok(r == 1, "Unexpected ret value %d.\n", r);
1802 /* right value contains garbage, probably because header columns are not set up */
1803 ok(rect.bottom >= 0, "Unexpected rectangle.\n");
1804
1805todo_wine_if(is_version_6)
1806 TEST_NO_HEADER2(hList, is_version_6);
1808
1809 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1813 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1815
1816 /* Test that window text is preserved. */
1818 0, 0, 100, 100, hwndparent, NULL, GetModuleHandleA(NULL), NULL);
1819 ok(hList != NULL, "Failed to create ListView window.\n");
1820 *buff = 0;
1821 GetWindowTextA(hList, buff, sizeof(buff));
1822 ok(!strcmp(buff, "test text"), "Unexpected window text %s.\n", buff);
1824
1826 0, 0, 100, 100, hwndparent, NULL, GetModuleHandleA(NULL), NULL);
1827 ok(hList != NULL, "Failed to create ListView window.\n");
1828 *buff = 0;
1829 GetWindowTextA(hList, buff, sizeof(buff));
1830 ok(!strcmp(buff, "test text"), "Unexpected window text %s.\n", buff);
1832
1833 r = UnregisterClassA("MyListView32", NULL);
1834 ok(r, "Failed to unregister test class.\n");
1835}
1836
1837static void test_redraw(void)
1838{
1839 HWND hwnd;
1840 HDC hdc;
1841 BOOL res;
1842 DWORD r;
1843 RECT rect;
1844
1847
1849
1853
1855
1856 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1857 /* 1. Without backbuffer */
1859 expect(TRUE, res);
1860
1862
1865 ok(r == 1, "Expected not zero result\n");
1867 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1868
1870 expect(TRUE, res);
1871
1874 expect(1, r);
1876 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1877
1878 /* 2. With backbuffer */
1882 expect(TRUE, res);
1883
1886 expect(1, r);
1888 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1889
1891 expect(TRUE, res);
1892
1895 todo_wine expect(1, r);
1897 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1898
1900
1901 /* test setting the window style to what it already was */
1905 ok(rect.left == 0 && rect.top == 0 && rect.right == 0 && rect.bottom == 0,
1906 "Expected empty update rect, got %s\n", wine_dbgstr_rect(&rect));
1907
1909}
1910
1912{
1913 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1914
1915 if(message == WM_NOTIFY) {
1916 NMHDR *nmhdr = (NMHDR*)lParam;
1917 if(nmhdr->code == NM_CUSTOMDRAW) {
1918 NMLVCUSTOMDRAW *nmlvcd = (NMLVCUSTOMDRAW*)nmhdr;
1919 BOOL showsel_always = !!(GetWindowLongA(nmlvcd->nmcd.hdr.hwndFrom, GWL_STYLE) & LVS_SHOWSELALWAYS);
1920 BOOL is_selected = !!(nmlvcd->nmcd.uItemState & CDIS_SELECTED);
1921 struct message msg;
1922
1923 msg.message = message;
1924 msg.flags = sent|wparam|lparam|custdraw;
1925 msg.wParam = wParam;
1926 msg.lParam = lParam;
1927 msg.id = nmhdr->code;
1928 msg.stage = nmlvcd->nmcd.dwDrawStage;
1930
1931 switch(nmlvcd->nmcd.dwDrawStage) {
1932 case CDDS_PREPAINT:
1933 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1935 case CDDS_ITEMPREPAINT:
1936 clr = GetBkColor(nmlvcd->nmcd.hdc);
1937 todo_wine_if(nmlvcd->iSubItem)
1938 ok(clr == c0ffee, "Unexpected background color %#x.\n", clr);
1939 nmlvcd->clrTextBk = CLR_DEFAULT;
1940 nmlvcd->clrText = RGB(0, 255, 0);
1943 clr = GetBkColor(nmlvcd->nmcd.hdc);
1944 todo_wine_if(showsel_always && is_selected && nmlvcd->iSubItem)
1945 {
1946 ok(nmlvcd->clrTextBk == CLR_DEFAULT, "Unexpected text background %#x.\n", nmlvcd->clrTextBk);
1947 ok(nmlvcd->clrText == RGB(0, 255, 0), "Unexpected text color %#x.\n", nmlvcd->clrText);
1948 }
1949 if (showsel_always && is_selected && nmlvcd->iSubItem)
1950 ok(clr == GetSysColor(COLOR_3DFACE), "Unexpected background color %#x.\n", clr);
1951 else
1952 todo_wine_if(nmlvcd->iSubItem)
1953 ok(clr == c0ffee, "clr=%.8x\n", clr);
1954 return CDRF_NOTIFYPOSTPAINT;
1956 clr = GetBkColor(nmlvcd->nmcd.hdc);
1957 if (showsel_always && is_selected)
1958 ok(clr == GetSysColor(COLOR_3DFACE), "Unexpected background color %#x.\n", clr);
1959 else
1960 {
1961 todo_wine
1962 ok(clr == c0ffee, "Unexpected background color %#x.\n", clr);
1963 }
1964
1965 todo_wine_if(showsel_always)
1966 {
1967 ok(nmlvcd->clrTextBk == CLR_DEFAULT, "Unexpected text background color %#x.\n", nmlvcd->clrTextBk);
1968 ok(nmlvcd->clrText == RGB(0, 255, 0), "got 0x%x\n", nmlvcd->clrText);
1969 }
1970 return CDRF_DODEFAULT;
1971 }
1972 return CDRF_DODEFAULT;
1973 }
1974 }
1975
1977}
1978
1979static void test_customdraw(void)
1980{
1981 HWND hwnd;
1982 WNDPROC oldwndproc;
1983 LVITEMA item;
1984
1986
1987 insert_column(hwnd, 0);
1988 insert_column(hwnd, 1);
1989 insert_item(hwnd, 0);
1990
1993
1996
1997 /* message tests */
2001 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_report_cd_seq, "parent customdraw, LVS_REPORT", FALSE);
2002
2003 /* Check colors when item is selected. */
2004 item.mask = LVIF_STATE;
2005 item.stateMask = LVIS_SELECTED;
2006 item.state = LVIS_SELECTED;
2008
2013 "parent customdraw, item selected, LVS_REPORT, selection", FALSE);
2014
2020 "parent customdraw, item selected, LVS_SHOWSELALWAYS, LVS_REPORT", FALSE);
2021
2023
2025
2026 insert_column(hwnd, 0);
2027 insert_column(hwnd, 1);
2028 insert_item(hwnd, 0);
2029
2033 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_list_cd_seq, "parent customdraw, LVS_LIST", FALSE);
2034
2037}
2038
2039static void test_icon_spacing(void)
2040{
2041 /* LVM_SETICONSPACING */
2042 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
2043
2044 HWND hwnd;
2045 WORD w, h;
2046 INT r;
2047
2049 ok(hwnd != NULL, "failed to create a listview window\n");
2050
2051 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
2052 expect(NFR_ANSI, r);
2053
2054 /* reset the icon spacing to defaults */
2056
2057 /* now we can request what the defaults are */
2059 w = LOWORD(r);
2060 h = HIWORD(r);
2061
2063
2065 ok(r == MAKELONG(w, h) ||
2066 broken(r == MAKELONG(w, w)), /* win98 */
2067 "Expected %d, got %d\n", MAKELONG(w, h), r);
2068
2070 expect(MAKELONG(20,30), r);
2071
2073 expect(MAKELONG(25,35), r);
2074
2076
2079}
2080
2081static void test_color(void)
2082{
2083 RECT rect;
2084 HWND hwnd;
2085 DWORD r;
2086 int i;
2087
2089 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
2090
2092 ok(hwnd != NULL, "failed to create a listview window\n");
2093
2095
2096 for (i = 0; i < 4; i++)
2097 {
2098 color = colors[i];
2099
2101 expect(TRUE, r);
2103 expect(color, r);
2104
2106 expect (TRUE, r);
2108 expect(color, r);
2109
2111 expect(TRUE, r);
2113 expect(color, r);
2114 }
2115
2118
2119 /* invalidation test done separately to avoid a message chain mess */
2120 r = ValidateRect(hwnd, NULL);
2121 expect(TRUE, r);
2122 r = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, colors[0]);
2123 expect(TRUE, r);
2124
2125 rect.right = rect.bottom = 1;
2128 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2129
2130 r = ValidateRect(hwnd, NULL);
2131 expect(TRUE, r);
2132 r = SendMessageA(hwnd, LVM_SETTEXTCOLOR, 0, colors[0]);
2133 expect(TRUE, r);
2134
2135 rect.right = rect.bottom = 1;
2138 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2139
2140 r = ValidateRect(hwnd, NULL);
2141 expect(TRUE, r);
2142 r = SendMessageA(hwnd, LVM_SETTEXTBKCOLOR, 0, colors[0]);
2143 expect(TRUE, r);
2144
2145 rect.right = rect.bottom = 1;
2148 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
2149
2151}
2152
2153static void test_item_count(void)
2154{
2155 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
2156
2157 HWND hwnd;
2158 DWORD r;
2159 HDC hdc;
2160 HFONT hOldFont;
2162 RECT rect;
2163 INT height;
2164
2165 LVITEMA item0;
2166 LVITEMA item1;
2167 LVITEMA item2;
2168 static CHAR item0text[] = "item0";
2169 static CHAR item1text[] = "item1";
2170 static CHAR item2text[] = "item2";
2171
2173 ok(hwnd != NULL, "failed to create a listview window\n");
2174
2175 /* resize in dpiaware manner to fit all 3 items added */
2176 hdc = GetDC(0);
2179 /* 2 extra pixels for bounds and header border */
2180 height = tm.tmHeight + 2;
2181 SelectObject(hdc, hOldFont);
2182 ReleaseDC(0, hdc);
2183
2185 /* 3 items + 1 header + 1 to be sure */
2186 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
2187
2189
2191 expect(0, r);
2192
2193 /* [item0] */
2194 item0.mask = LVIF_TEXT;
2195 item0.iItem = 0;
2196 item0.iSubItem = 0;
2197 item0.pszText = item0text;
2198 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item0);
2199 expect(0, r);
2200
2201 /* [item0, item1] */
2202 item1.mask = LVIF_TEXT;
2203 item1.iItem = 1;
2204 item1.iSubItem = 0;
2205 item1.pszText = item1text;
2207 expect(1, r);
2208
2209 /* [item0, item1, item2] */
2210 item2.mask = LVIF_TEXT;
2211 item2.iItem = 2;
2212 item2.iSubItem = 0;
2213 item2.pszText = item2text;
2215 expect(2, r);
2216
2218 expect(3, r);
2219
2220 /* [item0, item1] */
2222 expect(TRUE, r);
2223
2225 expect(2, r);
2226
2227 /* [] */
2229 expect(TRUE, r);
2230
2232 expect(0, r);
2233
2234 /* [item0] */
2236 expect(0, r);
2237
2238 /* [item0, item1] */
2240 expect(1, r);
2241
2243 expect(2, r);
2244
2245 /* [item0, item1, item2] */
2247 expect(2, r);
2248
2250 expect(3, r);
2251
2253
2256}
2257
2258static void test_item_position(void)
2259{
2260 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2261
2262 HWND hwnd;
2263 DWORD r;
2264 POINT position;
2265
2266 LVITEMA item0;
2267 LVITEMA item1;
2268 LVITEMA item2;
2269 static CHAR item0text[] = "item0";
2270 static CHAR item1text[] = "item1";
2271 static CHAR item2text[] = "item2";
2272
2274 ok(hwnd != NULL, "failed to create a listview window\n");
2275
2277
2278 /* [item0] */
2279 item0.mask = LVIF_TEXT;
2280 item0.iItem = 0;
2281 item0.iSubItem = 0;
2282 item0.pszText = item0text;
2283 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item0);
2284 expect(0, r);
2285
2286 /* [item0, item1] */
2287 item1.mask = LVIF_TEXT;
2288 item1.iItem = 1;
2289 item1.iSubItem = 0;
2290 item1.pszText = item1text;
2292 expect(1, r);
2293
2294 /* [item0, item1, item2] */
2295 item2.mask = LVIF_TEXT;
2296 item2.iItem = 2;
2297 item2.iSubItem = 0;
2298 item2.pszText = item2text;
2300 expect(2, r);
2301
2303 expect(TRUE, r);
2304 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
2305 expect(TRUE, r);
2306 expect2(10, 5, position.x, position.y);
2307
2309 expect(TRUE, r);
2310 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
2311 expect(TRUE, r);
2312 expect2(0, 0, position.x, position.y);
2313
2315 expect(TRUE, r);
2316 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
2317 expect(TRUE, r);
2318 expect2(20, 20, position.x, position.y);
2319
2321
2324}
2325
2326static void test_getorigin(void)
2327{
2328 /* LVM_GETORIGIN */
2329
2330 HWND hwnd;
2331 DWORD r;
2332 POINT position;
2333
2334 position.x = position.y = 0;
2335
2337 ok(hwnd != NULL, "failed to create a listview window\n");
2339
2340 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2341 expect(TRUE, r);
2344
2346 ok(hwnd != NULL, "failed to create a listview window\n");
2348
2349 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2350 expect(TRUE, r);
2353
2355 ok(hwnd != NULL, "failed to create a listview window\n");
2357
2358 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2359 expect(FALSE, r);
2362
2364 ok(hwnd != NULL, "failed to create a listview window\n");
2366
2367 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2368 expect(FALSE, r);
2371}
2372
2373static void test_multiselect(void)
2374{
2375 typedef struct t_select_task
2376 {
2377 const char *descr;
2378 int initPos;
2379 int loopVK;
2380 int count;
2381 int result;
2382 } select_task;
2383
2384 HWND hwnd;
2385 INT r;
2386 int i, j;
2387 static const int items=5;
2388 DWORD item_count;
2389 BYTE kstate[256];
2390 select_task task;
2392 LVITEMA item;
2393
2394 static struct t_select_task task_list[] = {
2395 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
2396 { "using VK_UP", -1, VK_UP, -1, -1 },
2397 { "using VK_END", 0, VK_END, 1, -1 },
2398 { "using VK_HOME", -1, VK_HOME, 1, -1 }
2399 };
2400
2402
2403 for (i = 0; i < items; i++)
2404 insert_item(hwnd, 0);
2405
2406 item_count = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2407 expect(items, item_count);
2408
2410 ok(r == -1, "got %d\n", r);
2411
2413 ok(r == -1, "got %d\n", r);
2414
2416 ok(r == 0, "got %d\n", r);
2417
2418 /* out of range index */
2420 ok(r == 0, "got %d\n", r);
2421
2423 ok(r == 0, "got %d\n", r);
2424
2426 ok(r == 0, "got %d\n", r);
2427
2429 ok(r == 0, "got %d\n", r);
2430
2431 for (i = 0; i < ARRAY_SIZE(task_list); i++) {
2432 DWORD selected_count;
2433 LVITEMA item;
2434
2435 task = task_list[i];
2436
2437 /* deselect all items */
2438 item.state = 0;
2439 item.stateMask = LVIS_SELECTED;
2441 ok(r, "got %d\n", r);
2443
2444 /* set initial position */
2445 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
2446 ok(r, "got %d\n", r);
2447
2448 item.state = LVIS_SELECTED;
2449 item.stateMask = LVIS_SELECTED;
2450 r = SendMessageA(hwnd, LVM_SETITEMSTATE, task.initPos == -1 ? item_count-1 : task.initPos, (LPARAM)&item);
2451 ok(r, "got %d\n", r);
2452
2453 selected_count = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2454 ok(selected_count == 1, "expected 1, got %d\n", selected_count);
2455
2456 /* Set SHIFT key pressed */
2457 GetKeyboardState(kstate);
2458 kstate[VK_SHIFT]=0x80;
2459 SetKeyboardState(kstate);
2460
2461 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
2462 r = SendMessageA(hwnd, WM_KEYDOWN, task.loopVK, 0);
2463 expect(0,r);
2464 r = SendMessageA(hwnd, WM_KEYUP, task.loopVK, 0);
2465 expect(0,r);
2466 }
2467
2468 selected_count = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2469
2470 ok((task.result == -1 ? item_count : task.result) == selected_count,
2471 "Failed multiple selection %s. There should be %d selected items (is %d)\n",
2472 task.descr, item_count, selected_count);
2473
2474 /* Set SHIFT key released */
2475 GetKeyboardState(kstate);
2476 kstate[VK_SHIFT]=0x00;
2477 SetKeyboardState(kstate);
2478 }
2480
2481 /* make multiple selection, then switch to LVS_SINGLESEL */
2483 for (i=0;i<items;i++) {
2484 insert_item(hwnd, 0);
2485 }
2486 item_count = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2487 expect(items,item_count);
2488
2489 /* try with NULL pointer */
2491 expect(FALSE, r);
2492
2493 /* select all, check notifications */
2494 item.state = 0;
2495 item.stateMask = LVIS_SELECTED;
2497 ok(r, "got %d\n", r);
2498
2500
2501 item.stateMask = LVIS_SELECTED;
2502 item.state = LVIS_SELECTED;
2504 expect(TRUE, r);
2505
2507 "select all notification", FALSE);
2508
2509 /* select all again (all selected already) */
2511
2513
2514 item.stateMask = LVIS_SELECTED;
2515 item.state = LVIS_SELECTED;
2517 expect(TRUE, r);
2518
2522
2524 "select all notification 2", FALSE);
2525
2526 /* deselect all items */
2528
2529 item.state = 0;
2530 item.stateMask = LVIS_SELECTED;
2532 ok(r, "got %d\n", r);
2533
2535 "deselect all notification", FALSE);
2536
2537 /* deselect all items again */
2539 item.state = 0;
2540 item.stateMask = LVIS_SELECTED;
2542 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "deselect all notification 2", FALSE);
2543
2544 /* any non-zero state value does the same */
2546
2548
2549 item.stateMask = LVIS_SELECTED;
2550 item.state = LVIS_CUT;
2552 expect(TRUE, r);
2553
2557
2559 "set state all notification 3", FALSE);
2560
2562 ok(r, "got %d\n", r);
2563 for (i = 0; i < 3; i++) {
2564 item.state = LVIS_SELECTED;
2565 item.stateMask = LVIS_SELECTED;
2567 ok(r, "got %d\n", r);
2568 }
2569
2571 expect(3, r);
2573 expect(-1, r);
2574
2576 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2578 /* check that style is accepted */
2580 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2581
2582 for (i=0;i<3;i++) {
2584 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2585 }
2587 expect(3, r);
2589 ok(r == -1, "got %d\n", r);
2590
2591 /* select one more */
2592 item.state = LVIS_SELECTED;
2593 item.stateMask = LVIS_SELECTED;
2595 ok(r, "got %d\n", r);
2596
2597 for (i=0;i<3;i++) {
2599 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2600 }
2601
2603 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2604
2606 expect(1, r);
2608 expect(-1, r);
2609
2610 /* try to select all on LVS_SINGLESEL */
2611 memset(&item, 0, sizeof(item));
2612 item.stateMask = LVIS_SELECTED;
2614 expect(TRUE, r);
2616 ok(r == -1, "got %d\n", r);
2617
2618 item.stateMask = LVIS_SELECTED;
2619 item.state = LVIS_SELECTED;
2621 expect(FALSE, r);
2622
2624 expect(0, r);
2626 expect(-1, r);
2627
2628 /* try to deselect all on LVS_SINGLESEL */
2629 item.stateMask = LVIS_SELECTED;
2630 item.state = LVIS_SELECTED;
2632 expect(TRUE, r);
2633
2634 item.stateMask = LVIS_SELECTED;
2635 item.state = 0;
2637 expect(TRUE, r);
2639 expect(0, r);
2640
2641 /* 1. selection mark is update when new focused item is set */
2644
2646 expect(-1, r);
2647
2648 item.stateMask = LVIS_FOCUSED;
2649 item.state = LVIS_FOCUSED;
2651 expect(TRUE, r);
2652
2654 expect(0, r);
2655
2656 /* it's not updated if already set */
2657 item.stateMask = LVIS_FOCUSED;
2658 item.state = LVIS_FOCUSED;
2660 expect(TRUE, r);
2661
2663 expect(0, r);
2664
2666 expect(0, r);
2667
2668 item.stateMask = LVIS_FOCUSED;
2669 item.state = LVIS_FOCUSED;
2671 expect(TRUE, r);
2672
2674 expect(-1, r);
2675
2676 /* need to reset focused item first */
2677 item.stateMask = LVIS_FOCUSED;
2678 item.state = 0;
2680 expect(TRUE, r);
2681
2682 item.stateMask = LVIS_FOCUSED;
2683 item.state = LVIS_FOCUSED;
2685 expect(TRUE, r);
2686
2688 expect(2, r);
2689
2690 item.stateMask = LVIS_FOCUSED;
2691 item.state = 0;
2693 expect(TRUE, r);
2694
2696 expect(2, r);
2697
2698 /* 2. same tests, with LVM_SETITEM */
2701
2703 expect(2, r);
2704
2705 item.stateMask = LVIS_FOCUSED;
2706 item.state = LVIS_FOCUSED;
2707 item.mask = LVIF_STATE;
2708 item.iItem = item.iSubItem = 0;
2710 expect(TRUE, r);
2711
2713 expect(0, r);
2714
2715 /* it's not updated if already set */
2716 item.stateMask = LVIS_FOCUSED;
2717 item.state = LVIS_FOCUSED;
2718 item.mask = LVIF_STATE;
2719 item.iItem = 1;
2720 item.iSubItem = 0;
2722 expect(TRUE, r);
2723
2725 expect(0, r);
2726
2728 expect(0, r);
2729
2730 item.stateMask = LVIS_FOCUSED;
2731 item.state = LVIS_FOCUSED;
2732 item.mask = LVIF_STATE;
2733 item.iItem = 1;
2734 item.iSubItem = 0;
2736 expect(TRUE, r);
2737
2739 expect(-1, r);
2740
2741 /* need to reset focused item first */
2742 item.stateMask = LVIS_FOCUSED;
2743 item.state = 0;
2745 expect(TRUE, r);
2746
2747 item.stateMask = LVIS_FOCUSED;
2748 item.state = LVIS_FOCUSED;
2749 item.mask = LVIF_STATE;
2750 item.iItem = 2;
2751 item.iSubItem = 0;
2753 expect(TRUE, r);
2754
2756 expect(2, r);
2757
2758 item.stateMask = LVIS_FOCUSED;
2759 item.state = 0;
2761 expect(TRUE, r);
2762
2764 expect(2, r);
2765
2767}
2768
2769static void test_subitem_rect(void)
2770{
2771 HWND hwnd;
2772 DWORD r;
2773 LVCOLUMNA col;
2774 RECT rect, rect2;
2775 INT arr[3];
2776
2777 /* test LVM_GETSUBITEMRECT for header */
2779 ok(hwnd != NULL, "failed to create a listview window\n");
2780 /* add some columns */
2781 memset(&col, 0, sizeof(LVCOLUMNA));
2782 col.mask = LVCF_WIDTH;
2783 col.cx = 100;
2785 expect(0, r);
2786 col.cx = 150;
2788 expect(1, r);
2789 col.cx = 200;
2791 expect(2, r);
2792 /* item = -1 means header, subitem index is 1 based */
2793 SetRect(&rect, LVIR_BOUNDS, 0, 0, 0);
2795 expect(0, r);
2796
2797 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2799 expect(1, r);
2800
2801 expect(100, rect.left);
2802 expect(250, rect.right);
2803 expect(3, rect.top);
2804
2805 SetRect(&rect, LVIR_BOUNDS, 2, 0, 0);
2807 expect(1, r);
2808
2809 expect(250, rect.left);
2810 expect(450, rect.right);
2811 expect(3, rect.top);
2812
2813 /* item LVS_REPORT padding isn't applied to subitems */
2814 insert_item(hwnd, 0);
2815
2816 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2818 expect(1, r);
2819 expect(100, rect.left);
2820 expect(250, rect.right);
2821
2822 SetRect(&rect, LVIR_ICON, 1, 0, 0);
2824 expect(1, r);
2825 /* no icon attached - zero width rectangle, with no left padding */
2826 expect(100, rect.left);
2827 expect(100, rect.right);
2828
2829 SetRect(&rect, LVIR_LABEL, 1, 0, 0);
2831 expect(1, r);
2832 /* same as full LVIR_BOUNDS */
2833 expect(100, rect.left);
2834 expect(250, rect.right);
2835
2836 r = SendMessageA(hwnd, LVM_SCROLL, 10, 0);
2837 ok(r, "got %d\n", r);
2838
2839 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2841 expect(1, r);
2842 expect(90, rect.left);
2843 expect(240, rect.right);
2844
2845 SendMessageA(hwnd, LVM_SCROLL, -10, 0);
2846
2847 /* test header interaction */
2850
2851 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2853 expect(1, r);
2854
2855 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2857 expect(1, r);
2858
2859 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2861 expect(1, r);
2862
2863 SetRect(&rect, LVIR_BOUNDS, 1, 0, 0);
2865 expect(1, r);
2866
2867 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getsubitemrect_seq, "LVM_GETSUBITEMRECT negative index", FALSE);
2868
2870
2871 /* test subitem rects after re-arranging columns */
2873 ok(hwnd != NULL, "failed to create a listview window\n");
2874 memset(&col, 0, sizeof(LVCOLUMNA));
2875 col.mask = LVCF_WIDTH;
2876
2877 col.cx = 100;
2879 expect(0, r);
2880
2881 col.cx = 200;
2883 expect(1, r);
2884
2885 col.cx = 300;
2887 expect(2, r);
2888
2889 insert_item(hwnd, 0);
2890 insert_item(hwnd, 1);
2891
2892 /* wrong item is refused for main item */
2893 SetRect(&rect, LVIR_BOUNDS, 0, -1, -1);
2895 expect(FALSE, r);
2896
2897 /* for subitems rectangle is calculated even if there's no item added */
2898 SetRect(&rect, LVIR_BOUNDS, 1, -1, -1);
2900 expect(TRUE, r);
2901
2902 SetRect(&rect2, LVIR_BOUNDS, 1, -1, -1);
2904 expect(TRUE, r);
2905 expect(rect.right, rect2.right);
2906 expect(rect.left, rect2.left);
2907 expect(rect.bottom, rect2.top);
2908 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2909
2910 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2912 expect(TRUE, r);
2913
2914 SetRect(&rect, LVIR_BOUNDS, 0, -1, -1);
2916 expect(TRUE, r);
2917 expect(0, rect.left);
2918 expect(600, rect.right);
2919
2920 SetRect(&rect, LVIR_BOUNDS, 1, -1, -1);
2922 expect(TRUE, r);
2923 expect(0, rect.left);
2924 expect(200, rect.right);
2925
2926 SetRect(&rect2, LVIR_BOUNDS, 1, -1, -1);