1 /* Unit tests for treeview.
3 * Copyright 2005 Krzysztof Foltman
4 * Copyright 2007 Christopher James Peterson
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/test.h"
35 const char *TEST_CALLBACK_TEXT
= "callback_text";
37 #define NUM_MSG_SEQUENCES 1
38 #define TREEVIEW_SEQ_INDEX 0
40 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
42 static struct msg_sequence
*MsgSequences
[NUM_MSG_SEQUENCES
];
44 static const struct message FillRootSeq
[] = {
45 { TVM_INSERTITEM
, sent
},
46 { TVM_INSERTITEM
, sent
},
50 static const struct message rootnone_select_seq
[] = {
51 { TVM_SELECTITEM
, sent
|wparam
, 9 },
52 { TVM_SELECTITEM
, sent
|wparam
, 9 },
53 { TVM_SELECTITEM
, sent
|wparam
, 9 },
54 { TVM_SELECTITEM
, sent
|wparam
, 9 },
55 { TVM_SELECTITEM
, sent
|wparam
, 9 },
56 { TVM_SELECTITEM
, sent
|wparam
, 9 },
60 static const struct message rootchild_select_seq
[] = {
61 { TVM_SELECTITEM
, sent
|wparam
, 9 },
62 { TVM_SELECTITEM
, sent
|wparam
, 9 },
63 { TVM_SELECTITEM
, sent
|wparam
, 9 },
64 { TVM_SELECTITEM
, sent
|wparam
, 9 },
65 { TVM_SELECTITEM
, sent
|wparam
, 9 },
66 { TVM_SELECTITEM
, sent
|wparam
, 9 },
70 static const struct message getitemtext_seq
[] = {
71 { TVM_INSERTITEM
, sent
},
72 { TVM_GETITEM
, sent
},
73 { TVM_DELETEITEM
, sent
},
77 static const struct message focus_seq
[] = {
78 { TVM_INSERTITEM
, sent
},
79 { TVM_INSERTITEM
, sent
},
80 { TVM_SELECTITEM
, sent
|wparam
, 9 },
81 /* The following end up out of order in wine */
82 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
},
83 { WM_NCCALCSIZE
, sent
|wparam
|defwinproc
, TRUE
},
84 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
},
85 { WM_SIZE
, sent
|defwinproc
},
86 { WM_PAINT
, sent
|defwinproc
},
87 { WM_NCPAINT
, sent
|wparam
|defwinproc
, 1 },
88 { WM_ERASEBKGND
, sent
|defwinproc
},
89 { TVM_EDITLABEL
, sent
},
90 { WM_COMMAND
, sent
|wparam
|defwinproc
, MAKEWPARAM(0, EN_UPDATE
) },
91 { WM_COMMAND
, sent
|wparam
|defwinproc
, MAKEWPARAM(0, EN_CHANGE
) },
92 { WM_PARENTNOTIFY
, sent
|wparam
|defwinproc
, MAKEWPARAM(WM_CREATE
, 0) },
93 { WM_KILLFOCUS
, sent
|defwinproc
},
94 { WM_PAINT
, sent
|defwinproc
},
95 { WM_IME_SETCONTEXT
, sent
|defwinproc
|optional
},
96 { WM_COMMAND
, sent
|wparam
|defwinproc
, MAKEWPARAM(0, EN_SETFOCUS
) },
97 { WM_ERASEBKGND
, sent
|defwinproc
|optional
},
98 { WM_CTLCOLOREDIT
, sent
|defwinproc
|optional
},
99 { WM_CTLCOLOREDIT
, sent
|defwinproc
|optional
},
103 static const struct message test_get_set_bkcolor_seq
[] = {
104 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
105 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
106 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
107 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0, 0x00ffffff },
108 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
109 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0, -1 },
113 static const struct message test_get_set_imagelist_seq
[] = {
114 { TVM_SETIMAGELIST
, sent
|wparam
|lparam
, 0, 0 },
115 { TVM_GETIMAGELIST
, sent
|wparam
|lparam
, 0, 0 },
119 static const struct message test_get_set_indent_seq
[] = {
120 { TVM_SETINDENT
, sent
|wparam
|lparam
, 0, 0 },
121 { TVM_GETINDENT
, sent
|wparam
|lparam
, 0, 0 },
122 /* The actual amount to indent is dependent on the system for this message */
123 { TVM_SETINDENT
, sent
},
124 { TVM_GETINDENT
, sent
|wparam
|lparam
, 0, 0 },
128 static const struct message test_get_set_insertmarkcolor_seq
[] = {
129 { TVM_SETINSERTMARKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
130 { TVM_GETINSERTMARKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
134 static const struct message test_get_set_item_seq
[] = {
135 { TVM_GETITEM
, sent
},
136 { TVM_SETITEM
, sent
},
137 { TVM_GETITEM
, sent
},
138 { TVM_SETITEM
, sent
},
142 static const struct message test_get_set_itemheight_seq
[] = {
143 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0, 0 },
144 { TVM_SETITEMHEIGHT
, sent
|wparam
|lparam
, -1, 0 },
145 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0, 0 },
146 { TVM_SETITEMHEIGHT
, sent
|lparam
, 0xcccccccc, 0 },
147 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
|optional
, 0, 0 },
148 { TVM_SETITEMHEIGHT
, sent
|wparam
|lparam
|optional
, 9, 0 },
149 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0, 0 },
153 static const struct message test_get_set_scrolltime_seq
[] = {
154 { TVM_SETSCROLLTIME
, sent
|wparam
|lparam
, 20, 0 },
155 { TVM_GETSCROLLTIME
, sent
|wparam
|lparam
, 0, 0 },
159 static const struct message test_get_set_textcolor_seq
[] = {
160 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0, 0 },
161 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0, 0 },
162 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0, 0 },
163 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0, RGB(255, 255, 255) },
164 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0, 0 },
165 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0, CLR_NONE
},
169 static const struct message test_get_set_tooltips_seq
[] = {
170 { WM_KILLFOCUS
, sent
},
171 { WM_IME_SETCONTEXT
, sent
|optional
},
172 { WM_IME_NOTIFY
, sent
|optional
},
173 { TVM_SETTOOLTIPS
, sent
|wparam
|lparam
, 0, 0 },
174 { TVM_GETTOOLTIPS
, sent
|wparam
|lparam
, 0, 0 },
178 static const struct message test_get_set_unicodeformat_seq
[] = {
179 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, TRUE
, 0 },
180 { TVM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0 },
181 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0 },
182 { TVM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0 },
183 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0 },
187 static HWND hMainWnd
;
189 static HTREEITEM hRoot
, hChild
;
192 static char sequence
[256];
194 static void Clear(void)
200 static void AddItem(char ch
)
202 sequence
[pos
++] = ch
;
203 sequence
[pos
] = '\0';
206 static void IdentifyItem(HTREEITEM hItem
)
208 if (hItem
== hRoot
) {
212 if (hItem
== hChild
) {
223 /* This function hooks in and records all messages to the treeview control */
224 static LRESULT WINAPI
TreeviewWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
226 static LONG defwndproc_counter
= 0;
229 WNDPROC lpOldProc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
231 msg
.message
= message
;
232 msg
.flags
= sent
|wparam
|lparam
;
233 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
236 add_message(MsgSequences
, TREEVIEW_SEQ_INDEX
, &msg
);
238 defwndproc_counter
++;
239 ret
= CallWindowProcA(lpOldProc
, hwnd
, message
, wParam
, lParam
);
240 defwndproc_counter
--;
245 static HWND
create_treeview_control(void)
250 hTree
= CreateWindowExA(WS_EX_CLIENTEDGE
, WC_TREEVIEWA
, NULL
, WS_CHILD
|WS_VISIBLE
|
251 TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_EDITLABELS
,
252 0, 0, 120, 100, hMainWnd
, (HMENU
)100, GetModuleHandleA(0), 0);
256 /* Record the old WNDPROC so we can call it after recording the messages */
257 pOldWndProc
= (WNDPROC
)SetWindowLongPtrA(hTree
, GWLP_WNDPROC
, (LONG_PTR
)TreeviewWndProc
);
258 SetWindowLongPtrA(hTree
, GWLP_USERDATA
, (LONG_PTR
)pOldWndProc
);
263 static void fill_tree(HWND hTree
)
266 static CHAR root
[] = "Root",
269 ins
.hParent
= TVI_ROOT
;
270 ins
.hInsertAfter
= TVI_ROOT
;
271 U(ins
).item
.mask
= TVIF_TEXT
;
272 U(ins
).item
.pszText
= root
;
273 hRoot
= TreeView_InsertItem(hTree
, &ins
);
276 ins
.hInsertAfter
= TVI_FIRST
;
277 U(ins
).item
.mask
= TVIF_TEXT
;
278 U(ins
).item
.pszText
= child
;
279 hChild
= TreeView_InsertItem(hTree
, &ins
);
282 static void test_fillroot(void)
287 hTree
= create_treeview_control();
289 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
299 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, FillRootSeq
, "FillRoot", FALSE
);
300 ok(!strcmp(sequence
, "AB."), "Item creation\n");
302 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
304 tvi
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
305 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
306 ok(tvi
.iImage
== 0, "tvi.iImage=%d\n", tvi
.iImage
);
307 ok(tvi
.iSelectedImage
== 0, "tvi.iSelectedImage=%d\n", tvi
.iSelectedImage
);
309 DestroyWindow(hTree
);
312 static void test_callback(void)
315 HTREEITEM hItem1
, hItem2
;
318 CHAR test_string
[] = "Test_string";
323 hTree
= create_treeview_control();
326 ret
= TreeView_DeleteAllItems(hTree
);
327 ok(ret
== TRUE
, "ret\n");
328 ins
.hParent
= TVI_ROOT
;
329 ins
.hInsertAfter
= TVI_ROOT
;
330 U(ins
).item
.mask
= TVIF_TEXT
;
331 U(ins
).item
.pszText
= LPSTR_TEXTCALLBACK
;
332 hRoot
= TreeView_InsertItem(hTree
, &ins
);
336 tvi
.mask
= TVIF_TEXT
;
338 tvi
.cchTextMax
= sizeof(buf
)/sizeof(buf
[0]);
339 ret
= TreeView_GetItem(hTree
, &tvi
);
340 ok(ret
== 1, "ret\n");
341 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Callback item text mismatch %s vs %s\n",
342 tvi
.pszText
, TEST_CALLBACK_TEXT
);
345 ins
.hInsertAfter
= TVI_FIRST
;
346 U(ins
).item
.mask
= TVIF_TEXT
;
347 U(ins
).item
.pszText
= test_string
;
348 hItem1
= TreeView_InsertItem(hTree
, &ins
);
352 ret
= TreeView_GetItem(hTree
, &tvi
);
353 ok(ret
== TRUE
, "ret\n");
354 ok(strcmp(tvi
.pszText
, test_string
) == 0, "Item text mismatch %s vs %s\n",
355 tvi
.pszText
, test_string
);
357 /* undocumented: pszText of NULL also means LPSTR_CALLBACK: */
359 ret
= TreeView_SetItem(hTree
, &tvi
);
360 ok(ret
== 1, "Expected SetItem return 1, got %ld\n", ret
);
362 ret
= TreeView_GetItem(hTree
, &tvi
);
363 ok(ret
== TRUE
, "Expected GetItem return TRUE, got %ld\n", ret
);
364 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
365 tvi
.pszText
, TEST_CALLBACK_TEXT
);
367 U(ins
).item
.pszText
= NULL
;
368 hItem2
= TreeView_InsertItem(hTree
, &ins
);
371 memset(buf
, 0, sizeof(buf
));
372 ret
= TreeView_GetItem(hTree
, &tvi
);
373 ok(ret
== TRUE
, "Expected GetItem return TRUE, got %ld\n", ret
);
374 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
375 tvi
.pszText
, TEST_CALLBACK_TEXT
);
377 DestroyWindow(hTree
);
380 static void test_select(void)
385 hTree
= create_treeview_control();
388 /* root-none select tests */
389 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
390 r
= TreeView_SelectItem(hTree
, NULL
);
393 r
= TreeView_SelectItem(hTree
, hRoot
);
395 r
= TreeView_SelectItem(hTree
, hRoot
);
397 r
= TreeView_SelectItem(hTree
, NULL
);
399 r
= TreeView_SelectItem(hTree
, NULL
);
401 r
= TreeView_SelectItem(hTree
, hRoot
);
403 ok(!strcmp(sequence
, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
404 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, rootnone_select_seq
,
405 "root-none select seq", FALSE
);
407 /* root-child select tests */
408 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
409 r
= TreeView_SelectItem(hTree
, NULL
);
412 r
= TreeView_SelectItem(hTree
, hRoot
);
414 r
= TreeView_SelectItem(hTree
, hRoot
);
416 r
= TreeView_SelectItem(hTree
, hChild
);
418 r
= TreeView_SelectItem(hTree
, hChild
);
420 r
= TreeView_SelectItem(hTree
, hRoot
);
422 ok(!strcmp(sequence
, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
423 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, rootchild_select_seq
,
424 "root-child select seq", FALSE
);
426 DestroyWindow(hTree
);
429 static void test_getitemtext(void)
436 CHAR szBuffer
[80] = "Blah";
437 int nBufferSize
= sizeof(szBuffer
)/sizeof(CHAR
);
439 hTree
= create_treeview_control();
442 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
444 /* add an item without TVIF_TEXT mask and pszText == NULL */
446 ins
.hInsertAfter
= TVI_ROOT
;
447 U(ins
).item
.mask
= 0;
448 U(ins
).item
.pszText
= NULL
;
449 U(ins
).item
.cchTextMax
= 0;
450 hChild
= TreeView_InsertItem(hTree
, &ins
);
453 /* retrieve it with TVIF_TEXT mask */
455 tvi
.mask
= TVIF_TEXT
;
456 tvi
.cchTextMax
= nBufferSize
;
457 tvi
.pszText
= szBuffer
;
459 SendMessageA( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
460 ok(!strcmp(szBuffer
, ""), "szBuffer=\"%s\", expected \"\"\n", szBuffer
);
461 ok(SendMessageA(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hChild
), "DeleteItem failed\n");
462 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, getitemtext_seq
, "get item text seq", FALSE
);
464 DestroyWindow(hTree
);
467 static void test_focus(void)
470 static CHAR child1
[] = "Edit",
471 child2
[] = "A really long string";
472 HTREEITEM hChild1
, hChild2
;
476 hTree
= create_treeview_control();
479 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
481 /* This test verifies that when a label is being edited, scrolling
482 * the treeview does not cause the label to lose focus. To test
483 * this, first some additional entries are added to generate
487 ins
.hInsertAfter
= hChild
;
488 U(ins
).item
.mask
= TVIF_TEXT
;
489 U(ins
).item
.pszText
= child1
;
490 hChild1
= TreeView_InsertItem(hTree
, &ins
);
492 ins
.hInsertAfter
= hChild1
;
493 U(ins
).item
.mask
= TVIF_TEXT
;
494 U(ins
).item
.pszText
= child2
;
495 hChild2
= TreeView_InsertItem(hTree
, &ins
);
498 ShowWindow(hMainWnd
,SW_SHOW
);
499 SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hChild
);
500 hEdit
= TreeView_EditLabel(hTree
, hChild
);
501 ScrollWindowEx(hTree
, -10, 0, NULL
, NULL
, NULL
, NULL
, SW_SCROLLCHILDREN
);
502 ok(GetFocus() == hEdit
, "Edit control should have focus\n");
503 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, focus_seq
, "focus test", TRUE
);
505 DestroyWindow(hTree
);
508 static void test_get_set_bkcolor(void)
510 COLORREF crColor
= RGB(0,0,0);
513 hTree
= create_treeview_control();
516 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
518 /* If the value is -1, the control is using the system color for the background color. */
519 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
520 ok(crColor
== -1, "Default background color reported as 0x%.8x\n", crColor
);
522 /* Test for black background */
523 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, RGB(0,0,0) );
524 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
525 ok(crColor
== RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor
);
527 /* Test for white background */
528 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, RGB(255,255,255) );
529 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
530 ok(crColor
== RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor
);
532 /* Reset the default background */
533 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, -1 );
535 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, test_get_set_bkcolor_seq
,
536 "test get set bkcolor", FALSE
);
538 DestroyWindow(hTree
);
541 static void test_get_set_imagelist(void)
543 HIMAGELIST hImageList
= NULL
;
546 hTree
= create_treeview_control();
549 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
551 /* Test a NULL HIMAGELIST */
552 SendMessage( hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)hImageList
);
553 hImageList
= (HIMAGELIST
)SendMessage( hTree
, TVM_GETIMAGELIST
, TVSIL_NORMAL
, 0 );
554 ok(hImageList
== NULL
, "NULL image list, reported as 0x%p, expected 0.\n", hImageList
);
556 /* TODO: Test an actual image list */
558 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, test_get_set_imagelist_seq
,
559 "test get imagelist", FALSE
);
561 DestroyWindow(hTree
);
564 static void test_get_set_indent(void)
567 int ulMinIndent
= -1;
568 int ulMoreThanTwiceMin
= -1;
571 hTree
= create_treeview_control();
574 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
576 /* Finding the minimum indent */
577 SendMessage( hTree
, TVM_SETINDENT
, 0, 0 );
578 ulMinIndent
= (int)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
580 /* Checking an indent that is more than twice the default indent */
581 ulMoreThanTwiceMin
= 2*ulMinIndent
+1;
582 SendMessage( hTree
, TVM_SETINDENT
, ulMoreThanTwiceMin
, 0 );
583 ulIndent
= (DWORD
)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
584 ok(ulIndent
== ulMoreThanTwiceMin
, "Indent reported as %d, expected %d\n", ulIndent
, ulMoreThanTwiceMin
);
586 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, test_get_set_indent_seq
,
587 "test get set indent", FALSE
);
589 DestroyWindow(hTree
);
592 static void test_get_set_insertmark(void)
594 COLORREF crColor
= RGB(0,0,0);
597 hTree
= create_treeview_control();
600 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
602 SendMessage( hTree
, TVM_SETINSERTMARKCOLOR
, 0, crColor
);
603 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0 );
604 ok(crColor
== RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor
);
606 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, test_get_set_insertmarkcolor_seq
,
607 "test get set insertmark color", FALSE
);
609 DestroyWindow(hTree
);
612 static void test_get_set_item(void)
614 TVITEM tviRoot
= {0};
615 int nBufferSize
= 80;
616 char szBuffer
[80] = {0};
619 hTree
= create_treeview_control();
622 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
624 /* Test the root item */
625 tviRoot
.hItem
= hRoot
;
626 tviRoot
.mask
= TVIF_TEXT
;
627 tviRoot
.cchTextMax
= nBufferSize
;
628 tviRoot
.pszText
= szBuffer
;
629 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tviRoot
);
630 ok(!strcmp("Root", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer
);
632 /* Change the root text */
633 strncpy(szBuffer
, "Testing123", nBufferSize
);
634 SendMessage( hTree
, TVM_SETITEM
, 0, (LPARAM
)&tviRoot
);
635 memset(szBuffer
, 0, nBufferSize
);
636 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tviRoot
);
637 ok(!strcmp("Testing123", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer
);
639 /* Reset the root text */
640 memset(szBuffer
, 0, nBufferSize
);
641 strncpy(szBuffer
, "Root", nBufferSize
);
642 SendMessage( hTree
, TVM_SETITEM
, 0, (LPARAM
)&tviRoot
);
644 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, test_get_set_item_seq
,
645 "test get set item", FALSE
);
647 DestroyWindow(hTree
);
650 static void test_get_set_itemheight(void)
656 hTree
= create_treeview_control();
659 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
661 /* Assuming default height to begin with */
662 ulOldHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
664 /* Explicitly setting and getting the default height */
665 SendMessage( hTree
, TVM_SETITEMHEIGHT
, -1, 0 );
666 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
667 ok(ulNewHeight
== ulOldHeight
, "Default height not set properly, reported %d, expected %d\n", ulNewHeight
, ulOldHeight
);
669 /* Explicitly setting and getting the height of twice the normal */
670 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 2*ulOldHeight
, 0 );
671 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
672 ok(ulNewHeight
== 2*ulOldHeight
, "New height not set properly, reported %d, expected %d\n", ulNewHeight
, 2*ulOldHeight
);
674 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
675 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 9, 0 );
676 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
677 ok(ulNewHeight
== 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight
, 8);
679 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, test_get_set_itemheight_seq
,
680 "test get set item height", FALSE
);
682 DestroyWindow(hTree
);
685 static void test_get_set_scrolltime(void)
687 int ulExpectedTime
= 20;
691 hTree
= create_treeview_control();
694 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
696 SendMessage( hTree
, TVM_SETSCROLLTIME
, ulExpectedTime
, 0 );
697 ulTime
= (int)SendMessage( hTree
, TVM_GETSCROLLTIME
, 0, 0 );
698 ok(ulTime
== ulExpectedTime
, "Scroll time reported as %d, expected %d\n", ulTime
, ulExpectedTime
);
700 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, test_get_set_scrolltime_seq
,
701 "test get set scroll time", FALSE
);
703 DestroyWindow(hTree
);
706 static void test_get_set_textcolor(void)
708 /* If the value is -1, the control is using the system color for the text color. */
709 COLORREF crColor
= RGB(0,0,0);
712 hTree
= create_treeview_control();
715 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
717 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
718 ok(crColor
== -1, "Default text color reported as 0x%.8x\n", crColor
);
720 /* Test for black text */
721 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, RGB(0,0,0) );
722 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
723 ok(crColor
== RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor
);
725 /* Test for white text */
726 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, RGB(255,255,255) );
727 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
728 ok(crColor
== RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor
);
730 /* Reset the default text color */
731 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, CLR_NONE
);
733 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, test_get_set_textcolor_seq
,
734 "test get set text color", FALSE
);
736 DestroyWindow(hTree
);
739 static void test_get_set_tooltips(void)
741 HWND hwndLastToolTip
= NULL
;
745 hTree
= create_treeview_control();
748 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
750 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
751 hPopupTreeView
= CreateWindow(WC_TREEVIEW
, NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 100, 100, hMainWnd
, NULL
, NULL
, NULL
);
752 DestroyWindow(hPopupTreeView
);
754 /* Testing setting a NULL ToolTip */
755 SendMessage( hTree
, TVM_SETTOOLTIPS
, 0, 0 );
756 hwndLastToolTip
= (HWND
)SendMessage( hTree
, TVM_GETTOOLTIPS
, 0, 0 );
757 ok(hwndLastToolTip
== NULL
, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip
);
759 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, test_get_set_tooltips_seq
,
760 "test get set tooltips", TRUE
);
762 /* TODO: Add a test of an actual tooltip */
763 DestroyWindow(hTree
);
766 static void test_get_set_unicodeformat(void)
768 BOOL bPreviousSetting
= 0;
769 BOOL bNewSetting
= 0;
772 hTree
= create_treeview_control();
775 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
778 bPreviousSetting
= (BOOL
)SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 1, 0 );
779 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
780 ok(bNewSetting
== 1, "Unicode setting did not work.\n");
783 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 0, 0 );
784 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
785 ok(bNewSetting
== 0, "ANSI setting did not work.\n");
787 /* Revert to original setting */
788 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, bPreviousSetting
, 0 );
790 ok_sequence(MsgSequences
, TREEVIEW_SEQ_INDEX
, test_get_set_unicodeformat_seq
,
791 "test get set unicode format", FALSE
);
793 DestroyWindow(hTree
);
796 static LRESULT CALLBACK
MyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
801 NMHDR
*pHdr
= (NMHDR
*)lParam
;
803 ok(pHdr
->code
!= NM_FIRST
- 19, "Treeview should not send NM_TOOLTIPSCREATED\n");
804 if (pHdr
->idFrom
== 100) {
805 NMTREEVIEWA
*pTreeView
= (LPNMTREEVIEWA
) lParam
;
807 case TVN_SELCHANGINGA
:
809 IdentifyItem(pTreeView
->itemOld
.hItem
);
810 IdentifyItem(pTreeView
->itemNew
.hItem
);
812 case TVN_SELCHANGEDA
:
814 IdentifyItem(pTreeView
->itemOld
.hItem
);
815 IdentifyItem(pTreeView
->itemNew
.hItem
);
817 case TVN_GETDISPINFOA
: {
818 NMTVDISPINFOA
*disp
= (NMTVDISPINFOA
*)lParam
;
819 if (disp
->item
.mask
& TVIF_TEXT
) {
820 lstrcpyn(disp
->item
.pszText
, TEST_CALLBACK_TEXT
, disp
->item
.cchTextMax
);
824 case TVN_ENDLABELEDIT
: return TRUE
;
835 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
840 static void test_expandinvisible(void)
842 static CHAR nodeText
[][5] = {"0", "1", "2", "3", "4"};
850 hTree
= create_treeview_control();
852 /* The test builds the following tree and expands then node 1, while node 0 is collapsed.
862 ret
= TreeView_DeleteAllItems(hTree
);
863 ok(ret
== TRUE
, "ret\n");
864 ins
.hParent
= TVI_ROOT
;
865 ins
.hInsertAfter
= TVI_ROOT
;
866 U(ins
).item
.mask
= TVIF_TEXT
;
867 U(ins
).item
.pszText
= nodeText
[0];
868 node
[0] = TreeView_InsertItem(hTree
, &ins
);
871 ins
.hInsertAfter
= TVI_LAST
;
872 U(ins
).item
.mask
= TVIF_TEXT
;
873 ins
.hParent
= node
[0];
875 U(ins
).item
.pszText
= nodeText
[1];
876 node
[1] = TreeView_InsertItem(hTree
, &ins
);
878 U(ins
).item
.pszText
= nodeText
[4];
879 node
[4] = TreeView_InsertItem(hTree
, &ins
);
882 ins
.hParent
= node
[1];
884 U(ins
).item
.pszText
= nodeText
[2];
885 node
[2] = TreeView_InsertItem(hTree
, &ins
);
887 U(ins
).item
.pszText
= nodeText
[3];
888 node
[3] = TreeView_InsertItem(hTree
, &ins
);
892 nodeVisible
= TreeView_GetItemRect(hTree
, node
[1], &dummyRect
, FALSE
);
893 ok(!nodeVisible
, "Node 1 should not be visible.\n");
894 nodeVisible
= TreeView_GetItemRect(hTree
, node
[2], &dummyRect
, FALSE
);
895 ok(!nodeVisible
, "Node 2 should not be visible.\n");
896 nodeVisible
= TreeView_GetItemRect(hTree
, node
[3], &dummyRect
, FALSE
);
897 ok(!nodeVisible
, "Node 3 should not be visible.\n");
898 nodeVisible
= TreeView_GetItemRect(hTree
, node
[4], &dummyRect
, FALSE
);
899 ok(!nodeVisible
, "Node 4 should not be visible.\n");
901 ok(TreeView_Expand(hTree
, node
[1], TVE_EXPAND
), "Expand of node 1 failed.\n");
903 nodeVisible
= TreeView_GetItemRect(hTree
, node
[1], &dummyRect
, FALSE
);
904 ok(!nodeVisible
, "Node 1 should not be visible.\n");
905 nodeVisible
= TreeView_GetItemRect(hTree
, node
[2], &dummyRect
, FALSE
);
906 ok(!nodeVisible
, "Node 2 should not be visible.\n");
907 nodeVisible
= TreeView_GetItemRect(hTree
, node
[3], &dummyRect
, FALSE
);
908 ok(!nodeVisible
, "Node 3 should not be visible.\n");
909 nodeVisible
= TreeView_GetItemRect(hTree
, node
[4], &dummyRect
, FALSE
);
910 ok(!nodeVisible
, "Node 4 should not be visible.\n");
912 DestroyWindow(hTree
);
915 static void test_itemedit(void)
923 hTree
= create_treeview_control();
926 /* try with null item */
927 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABEL
, 0, 0);
928 ok(!IsWindow(edit
), "Expected valid handle\n");
931 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABEL
, 0, (LPARAM
)hRoot
);
932 ok(IsWindow(edit
), "Expected valid handle\n");
933 /* item shouldn't be selected automatically after TVM_EDITLABEL */
934 r
= SendMessage(hTree
, TVM_GETITEMSTATE
, (WPARAM
)hRoot
, TVIS_SELECTED
);
936 /* try to cancel with wrong edit handle */
937 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), 0);
939 ok(IsWindow(edit
), "Expected edit control to be valid\n");
940 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
942 ok(!IsWindow(edit
), "Expected edit control to be destroyed\n");
943 /* try to cancel without creating edit */
944 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), 0);
947 /* try to cancel with wrong (not null) handle */
948 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABEL
, 0, (LPARAM
)hRoot
);
949 ok(IsWindow(edit
), "Expected valid handle\n");
950 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hTree
);
952 ok(IsWindow(edit
), "Expected edit control to be valid\n");
953 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
956 /* remove selection after starting edit */
957 r
= TreeView_SelectItem(hTree
, hRoot
);
959 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABEL
, 0, (LPARAM
)hRoot
);
960 ok(IsWindow(edit
), "Expected valid handle\n");
961 r
= TreeView_SelectItem(hTree
, NULL
);
964 strncpy(buff
, "x", sizeof(buff
)/sizeof(CHAR
));
965 r
= SendMessage(edit
, WM_SETTEXT
, 0, (LPARAM
)buff
);
967 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
969 ok(!IsWindow(edit
), "Expected edit control to be destroyed\n");
970 /* check that text is saved */
971 item
.mask
= TVIF_TEXT
;
974 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
975 r
= SendMessage(hTree
, TVM_GETITEM
, 0, (LPARAM
)&item
);
977 ok(!strcmp("x", buff
), "Expected item text to change\n");
979 DestroyWindow(hTree
);
982 static void test_treeview_classinfo(void)
986 memset(&cls
, 0, sizeof(cls
));
987 GetClassInfo(GetModuleHandleA("comctl32.dll"), WC_TREEVIEWA
, &cls
);
988 ok(cls
.hbrBackground
== NULL
, "Expected NULL background brush, got %p\n", cls
.hbrBackground
);
989 ok(cls
.style
== (CS_GLOBALCLASS
| CS_DBLCLKS
), "Expected got %x\n", cls
.style
);
990 expect(0, cls
.cbClsExtra
);
993 static void test_get_linecolor(void)
998 hTree
= create_treeview_control();
1000 /* newly created control has default color */
1001 clr
= (COLORREF
)SendMessage(hTree
, TVM_GETLINECOLOR
, 0, 0);
1003 win_skip("TVM_GETLINECOLOR is not supported on comctl32 < 5.80\n");
1005 expect(CLR_DEFAULT
, clr
);
1007 DestroyWindow(hTree
);
1010 static void test_get_insertmarkcolor(void)
1015 hTree
= create_treeview_control();
1017 /* newly created control has default color */
1018 clr
= (COLORREF
)SendMessage(hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0);
1020 win_skip("TVM_GETINSERTMARKCOLOR is not supported on comctl32 < 5.80\n");
1022 expect(CLR_DEFAULT
, clr
);
1024 DestroyWindow(hTree
);
1027 START_TEST(treeview
)
1030 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
1034 hComctl32
= GetModuleHandleA("comctl32.dll");
1035 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
1036 if (pInitCommonControlsEx
)
1038 INITCOMMONCONTROLSEX iccex
;
1039 iccex
.dwSize
= sizeof(iccex
);
1040 iccex
.dwICC
= ICC_TREEVIEW_CLASSES
;
1041 pInitCommonControlsEx(&iccex
);
1044 InitCommonControls();
1046 init_msg_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
1048 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1051 wc
.hInstance
= GetModuleHandleA(NULL
);
1053 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
1054 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1055 wc
.lpszMenuName
= NULL
;
1056 wc
.lpszClassName
= "MyTestWnd";
1057 wc
.lpfnWndProc
= MyWndProc
;
1058 RegisterClassA(&wc
);
1060 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
1061 CW_USEDEFAULT
, CW_USEDEFAULT
, 130, 105, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1063 if ( !ok(hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n") )
1070 test_get_set_bkcolor();
1071 test_get_set_imagelist();
1072 test_get_set_indent();
1073 test_get_set_insertmark();
1074 test_get_set_item();
1075 test_get_set_itemheight();
1076 test_get_set_scrolltime();
1077 test_get_set_textcolor();
1078 test_get_linecolor();
1079 test_get_insertmarkcolor();
1080 test_get_set_tooltips();
1081 test_get_set_unicodeformat();
1083 test_expandinvisible();
1085 test_treeview_classinfo();
1087 PostMessageA(hMainWnd
, WM_CLOSE
, 0, 0);
1088 while(GetMessageA(&msg
,0,0,0)) {
1089 TranslateMessage(&msg
);
1090 DispatchMessageA(&msg
);