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"
36 const char *TEST_CALLBACK_TEXT
= "callback_text";
38 #define NUM_MSG_SEQUENCES 2
39 #define TREEVIEW_SEQ_INDEX 0
40 #define PARENT_SEQ_INDEX 1
42 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
44 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
46 static const struct message FillRootSeq
[] = {
47 { TVM_INSERTITEM
, sent
},
48 { TVM_INSERTITEM
, sent
},
52 static const struct message rootnone_select_seq
[] = {
53 { TVM_SELECTITEM
, sent
|wparam
, 9 },
54 { TVM_SELECTITEM
, sent
|wparam
, 9 },
55 { TVM_SELECTITEM
, sent
|wparam
, 9 },
56 { TVM_SELECTITEM
, sent
|wparam
, 9 },
57 { TVM_SELECTITEM
, sent
|wparam
, 9 },
58 { TVM_SELECTITEM
, sent
|wparam
, 9 },
62 static const struct message rootchild_select_seq
[] = {
63 { TVM_SELECTITEM
, sent
|wparam
, 9 },
64 { TVM_SELECTITEM
, sent
|wparam
, 9 },
65 { TVM_SELECTITEM
, sent
|wparam
, 9 },
66 { TVM_SELECTITEM
, sent
|wparam
, 9 },
67 { TVM_SELECTITEM
, sent
|wparam
, 9 },
68 { TVM_SELECTITEM
, sent
|wparam
, 9 },
72 static const struct message getitemtext_seq
[] = {
73 { TVM_INSERTITEMA
, sent
},
74 { TVM_GETITEMA
, sent
},
75 { TVM_DELETEITEM
, sent
},
79 static const struct message focus_seq
[] = {
80 { TVM_INSERTITEM
, sent
},
81 { TVM_INSERTITEM
, sent
},
82 { TVM_SELECTITEM
, sent
|wparam
, 9 },
83 /* The following end up out of order in wine */
84 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
},
85 { WM_NCCALCSIZE
, sent
|wparam
|defwinproc
, TRUE
},
86 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
},
87 { WM_SIZE
, sent
|defwinproc
},
88 { WM_PAINT
, sent
|defwinproc
},
89 { WM_NCPAINT
, sent
|wparam
|defwinproc
, 1 },
90 { WM_ERASEBKGND
, sent
|defwinproc
},
91 { TVM_EDITLABEL
, sent
},
92 { WM_COMMAND
, sent
|wparam
|defwinproc
, MAKEWPARAM(0, EN_UPDATE
) },
93 { WM_COMMAND
, sent
|wparam
|defwinproc
, MAKEWPARAM(0, EN_CHANGE
) },
94 { WM_PARENTNOTIFY
, sent
|wparam
|defwinproc
, MAKEWPARAM(WM_CREATE
, 0) },
95 { WM_KILLFOCUS
, sent
|defwinproc
},
96 { WM_PAINT
, sent
|defwinproc
},
97 { WM_IME_SETCONTEXT
, sent
|defwinproc
|optional
},
98 { WM_COMMAND
, sent
|wparam
|defwinproc
, MAKEWPARAM(0, EN_SETFOCUS
) },
99 { WM_ERASEBKGND
, sent
|defwinproc
|optional
},
100 { WM_CTLCOLOREDIT
, sent
|defwinproc
|optional
},
101 { WM_CTLCOLOREDIT
, sent
|defwinproc
|optional
},
105 static const struct message test_get_set_bkcolor_seq
[] = {
106 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
107 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
108 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
109 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0, 0x00ffffff },
110 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
111 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0, -1 },
115 static const struct message test_get_set_imagelist_seq
[] = {
116 { TVM_SETIMAGELIST
, sent
|wparam
|lparam
, 0, 0 },
117 { TVM_GETIMAGELIST
, sent
|wparam
|lparam
, 0, 0 },
121 static const struct message test_get_set_indent_seq
[] = {
122 { TVM_SETINDENT
, sent
|wparam
|lparam
, 0, 0 },
123 { TVM_GETINDENT
, sent
|wparam
|lparam
, 0, 0 },
124 /* The actual amount to indent is dependent on the system for this message */
125 { TVM_SETINDENT
, sent
},
126 { TVM_GETINDENT
, sent
|wparam
|lparam
, 0, 0 },
130 static const struct message test_get_set_insertmarkcolor_seq
[] = {
131 { TVM_SETINSERTMARKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
132 { TVM_GETINSERTMARKCOLOR
, sent
|wparam
|lparam
, 0, 0 },
136 static const struct message test_get_set_item_seq
[] = {
137 { TVM_GETITEMA
, sent
},
138 { TVM_SETITEMA
, sent
},
139 { TVM_GETITEMA
, sent
},
140 { TVM_SETITEMA
, sent
},
144 static const struct message test_get_set_itemheight_seq
[] = {
145 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0, 0 },
146 { TVM_SETITEMHEIGHT
, sent
|wparam
|lparam
, -1, 0 },
147 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0, 0 },
148 { TVM_SETITEMHEIGHT
, sent
|lparam
, 0xcccccccc, 0 },
149 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
|optional
, 0, 0 },
150 { TVM_SETITEMHEIGHT
, sent
|wparam
|lparam
|optional
, 9, 0 },
151 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0, 0 },
155 static const struct message test_get_set_scrolltime_seq
[] = {
156 { TVM_SETSCROLLTIME
, sent
|wparam
|lparam
, 20, 0 },
157 { TVM_GETSCROLLTIME
, sent
|wparam
|lparam
, 0, 0 },
161 static const struct message test_get_set_textcolor_seq
[] = {
162 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0, 0 },
163 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0, 0 },
164 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0, 0 },
165 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0, RGB(255, 255, 255) },
166 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0, 0 },
167 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0, CLR_NONE
},
171 static const struct message test_get_set_tooltips_seq
[] = {
172 { WM_KILLFOCUS
, sent
},
173 { WM_IME_SETCONTEXT
, sent
|optional
},
174 { WM_IME_NOTIFY
, sent
|optional
},
175 { TVM_SETTOOLTIPS
, sent
|wparam
|lparam
, 0, 0 },
176 { TVM_GETTOOLTIPS
, sent
|wparam
|lparam
, 0, 0 },
180 static const struct message test_get_set_unicodeformat_seq
[] = {
181 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, TRUE
, 0 },
182 { TVM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0 },
183 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0 },
184 { TVM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0 },
185 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0, 0 },
189 static const struct message parent_expand_seq
[] = {
190 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_ITEMEXPANDINGA
},
191 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_ITEMEXPANDEDA
},
195 static const struct message parent_singleexpand_seq
[] = {
196 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_SELCHANGINGA
},
197 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_SELCHANGEDA
},
198 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_SINGLEEXPAND
},
199 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_ITEMEXPANDINGA
},
200 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_ITEMEXPANDEDA
},
204 static const struct message empty_seq
[] = {
208 static HWND hMainWnd
;
210 static HTREEITEM hRoot
, hChild
;
213 static char sequence
[256];
215 static void Clear(void)
221 static void AddItem(char ch
)
223 sequence
[pos
++] = ch
;
224 sequence
[pos
] = '\0';
227 static void IdentifyItem(HTREEITEM hItem
)
229 if (hItem
== hRoot
) {
233 if (hItem
== hChild
) {
244 /* This function hooks in and records all messages to the treeview control */
245 static LRESULT WINAPI
TreeviewWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
247 static LONG defwndproc_counter
= 0;
250 WNDPROC lpOldProc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
252 msg
.message
= message
;
253 msg
.flags
= sent
|wparam
|lparam
;
254 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
257 add_message(sequences
, TREEVIEW_SEQ_INDEX
, &msg
);
259 defwndproc_counter
++;
260 ret
= CallWindowProcA(lpOldProc
, hwnd
, message
, wParam
, lParam
);
261 defwndproc_counter
--;
266 static HWND
create_treeview_control(void)
271 hTree
= CreateWindowExA(WS_EX_CLIENTEDGE
, WC_TREEVIEWA
, NULL
, WS_CHILD
|WS_VISIBLE
|
272 TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_EDITLABELS
,
273 0, 0, 120, 100, hMainWnd
, (HMENU
)100, GetModuleHandleA(0), 0);
277 /* Record the old WNDPROC so we can call it after recording the messages */
278 pOldWndProc
= (WNDPROC
)SetWindowLongPtrA(hTree
, GWLP_WNDPROC
, (LONG_PTR
)TreeviewWndProc
);
279 SetWindowLongPtrA(hTree
, GWLP_USERDATA
, (LONG_PTR
)pOldWndProc
);
284 static void fill_tree(HWND hTree
)
287 static CHAR root
[] = "Root",
290 ins
.hParent
= TVI_ROOT
;
291 ins
.hInsertAfter
= TVI_ROOT
;
292 U(ins
).item
.mask
= TVIF_TEXT
;
293 U(ins
).item
.pszText
= root
;
294 hRoot
= TreeView_InsertItem(hTree
, &ins
);
297 ins
.hInsertAfter
= TVI_FIRST
;
298 U(ins
).item
.mask
= TVIF_TEXT
;
299 U(ins
).item
.pszText
= child
;
300 hChild
= TreeView_InsertItem(hTree
, &ins
);
303 static void test_fillroot(void)
308 hTree
= create_treeview_control();
310 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
320 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, FillRootSeq
, "FillRoot", FALSE
);
321 ok(!strcmp(sequence
, "AB."), "Item creation\n");
323 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
325 tvi
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
326 SendMessage( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tvi
);
327 ok(tvi
.iImage
== 0, "tvi.iImage=%d\n", tvi
.iImage
);
328 ok(tvi
.iSelectedImage
== 0, "tvi.iSelectedImage=%d\n", tvi
.iSelectedImage
);
330 DestroyWindow(hTree
);
333 static void test_callback(void)
336 HTREEITEM hItem1
, hItem2
;
339 CHAR test_string
[] = "Test_string";
344 hTree
= create_treeview_control();
347 ret
= TreeView_DeleteAllItems(hTree
);
348 ok(ret
== TRUE
, "ret\n");
349 ins
.hParent
= TVI_ROOT
;
350 ins
.hInsertAfter
= TVI_ROOT
;
351 U(ins
).item
.mask
= TVIF_TEXT
;
352 U(ins
).item
.pszText
= LPSTR_TEXTCALLBACK
;
353 hRoot
= TreeView_InsertItem(hTree
, &ins
);
357 tvi
.mask
= TVIF_TEXT
;
359 tvi
.cchTextMax
= sizeof(buf
)/sizeof(buf
[0]);
360 ret
= TreeView_GetItem(hTree
, &tvi
);
361 ok(ret
== 1, "ret\n");
362 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Callback item text mismatch %s vs %s\n",
363 tvi
.pszText
, TEST_CALLBACK_TEXT
);
366 ins
.hInsertAfter
= TVI_FIRST
;
367 U(ins
).item
.mask
= TVIF_TEXT
;
368 U(ins
).item
.pszText
= test_string
;
369 hItem1
= TreeView_InsertItem(hTree
, &ins
);
373 ret
= TreeView_GetItem(hTree
, &tvi
);
374 ok(ret
== TRUE
, "ret\n");
375 ok(strcmp(tvi
.pszText
, test_string
) == 0, "Item text mismatch %s vs %s\n",
376 tvi
.pszText
, test_string
);
378 /* undocumented: pszText of NULL also means LPSTR_CALLBACK: */
380 ret
= TreeView_SetItem(hTree
, &tvi
);
381 ok(ret
== 1, "Expected SetItem return 1, got %ld\n", ret
);
383 ret
= TreeView_GetItem(hTree
, &tvi
);
384 ok(ret
== TRUE
, "Expected GetItem return TRUE, got %ld\n", ret
);
385 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
386 tvi
.pszText
, TEST_CALLBACK_TEXT
);
388 U(ins
).item
.pszText
= NULL
;
389 hItem2
= TreeView_InsertItem(hTree
, &ins
);
392 memset(buf
, 0, sizeof(buf
));
393 ret
= TreeView_GetItem(hTree
, &tvi
);
394 ok(ret
== TRUE
, "Expected GetItem return TRUE, got %ld\n", ret
);
395 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
396 tvi
.pszText
, TEST_CALLBACK_TEXT
);
398 DestroyWindow(hTree
);
401 static void test_select(void)
406 hTree
= create_treeview_control();
409 /* root-none select tests */
410 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
411 r
= TreeView_SelectItem(hTree
, NULL
);
415 r
= TreeView_SelectItem(hTree
, hRoot
);
418 r
= TreeView_SelectItem(hTree
, hRoot
);
421 r
= TreeView_SelectItem(hTree
, NULL
);
424 r
= TreeView_SelectItem(hTree
, NULL
);
427 r
= TreeView_SelectItem(hTree
, hRoot
);
430 ok(!strcmp(sequence
, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
431 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, rootnone_select_seq
,
432 "root-none select seq", FALSE
);
434 /* root-child select tests */
435 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
436 r
= TreeView_SelectItem(hTree
, NULL
);
441 r
= TreeView_SelectItem(hTree
, hRoot
);
444 r
= TreeView_SelectItem(hTree
, hRoot
);
447 r
= TreeView_SelectItem(hTree
, hChild
);
450 r
= TreeView_SelectItem(hTree
, hChild
);
453 r
= TreeView_SelectItem(hTree
, hRoot
);
456 ok(!strcmp(sequence
, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
457 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, rootchild_select_seq
,
458 "root-child select seq", FALSE
);
460 DestroyWindow(hTree
);
463 static void test_getitemtext(void)
470 CHAR szBuffer
[80] = "Blah";
471 int nBufferSize
= sizeof(szBuffer
)/sizeof(CHAR
);
473 hTree
= create_treeview_control();
476 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
478 /* add an item without TVIF_TEXT mask and pszText == NULL */
480 ins
.hInsertAfter
= TVI_ROOT
;
481 U(ins
).item
.mask
= 0;
482 U(ins
).item
.pszText
= NULL
;
483 U(ins
).item
.cchTextMax
= 0;
484 hChild
= TreeView_InsertItem(hTree
, &ins
);
487 /* retrieve it with TVIF_TEXT mask */
489 tvi
.mask
= TVIF_TEXT
;
490 tvi
.cchTextMax
= nBufferSize
;
491 tvi
.pszText
= szBuffer
;
493 SendMessageA( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tvi
);
494 ok(!strcmp(szBuffer
, ""), "szBuffer=\"%s\", expected \"\"\n", szBuffer
);
495 ok(SendMessageA(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hChild
), "DeleteItem failed\n");
496 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, getitemtext_seq
, "get item text seq", FALSE
);
498 DestroyWindow(hTree
);
501 static void test_focus(void)
504 static CHAR child1
[] = "Edit",
505 child2
[] = "A really long string";
506 HTREEITEM hChild1
, hChild2
;
510 hTree
= create_treeview_control();
513 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
515 /* This test verifies that when a label is being edited, scrolling
516 * the treeview does not cause the label to lose focus. To test
517 * this, first some additional entries are added to generate
521 ins
.hInsertAfter
= hChild
;
522 U(ins
).item
.mask
= TVIF_TEXT
;
523 U(ins
).item
.pszText
= child1
;
524 hChild1
= TreeView_InsertItem(hTree
, &ins
);
526 ins
.hInsertAfter
= hChild1
;
527 U(ins
).item
.mask
= TVIF_TEXT
;
528 U(ins
).item
.pszText
= child2
;
529 hChild2
= TreeView_InsertItem(hTree
, &ins
);
532 ShowWindow(hMainWnd
,SW_SHOW
);
533 SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hChild
);
534 hEdit
= TreeView_EditLabel(hTree
, hChild
);
535 ScrollWindowEx(hTree
, -10, 0, NULL
, NULL
, NULL
, NULL
, SW_SCROLLCHILDREN
);
536 ok(GetFocus() == hEdit
, "Edit control should have focus\n");
537 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, focus_seq
, "focus test", TRUE
);
539 DestroyWindow(hTree
);
542 static void test_get_set_bkcolor(void)
544 COLORREF crColor
= RGB(0,0,0);
547 hTree
= create_treeview_control();
550 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
552 /* If the value is -1, the control is using the system color for the background color. */
553 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
554 ok(crColor
== -1, "Default background color reported as 0x%.8x\n", crColor
);
556 /* Test for black background */
557 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, RGB(0,0,0) );
558 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
559 ok(crColor
== RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor
);
561 /* Test for white background */
562 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, RGB(255,255,255) );
563 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
564 ok(crColor
== RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor
);
566 /* Reset the default background */
567 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, -1 );
569 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_bkcolor_seq
,
570 "test get set bkcolor", FALSE
);
572 DestroyWindow(hTree
);
575 static void test_get_set_imagelist(void)
577 HIMAGELIST hImageList
= NULL
;
580 hTree
= create_treeview_control();
583 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
585 /* Test a NULL HIMAGELIST */
586 SendMessage( hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)hImageList
);
587 hImageList
= (HIMAGELIST
)SendMessage( hTree
, TVM_GETIMAGELIST
, TVSIL_NORMAL
, 0 );
588 ok(hImageList
== NULL
, "NULL image list, reported as 0x%p, expected 0.\n", hImageList
);
590 /* TODO: Test an actual image list */
592 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_imagelist_seq
,
593 "test get imagelist", FALSE
);
595 DestroyWindow(hTree
);
598 static void test_get_set_indent(void)
601 int ulMinIndent
= -1;
602 int ulMoreThanTwiceMin
= -1;
605 hTree
= create_treeview_control();
608 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
610 /* Finding the minimum indent */
611 SendMessage( hTree
, TVM_SETINDENT
, 0, 0 );
612 ulMinIndent
= (int)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
614 /* Checking an indent that is more than twice the default indent */
615 ulMoreThanTwiceMin
= 2*ulMinIndent
+1;
616 SendMessage( hTree
, TVM_SETINDENT
, ulMoreThanTwiceMin
, 0 );
617 ulIndent
= (DWORD
)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
618 ok(ulIndent
== ulMoreThanTwiceMin
, "Indent reported as %d, expected %d\n", ulIndent
, ulMoreThanTwiceMin
);
620 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_indent_seq
,
621 "test get set indent", FALSE
);
623 DestroyWindow(hTree
);
626 static void test_get_set_insertmark(void)
628 COLORREF crColor
= RGB(0,0,0);
631 hTree
= create_treeview_control();
634 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
636 SendMessage( hTree
, TVM_SETINSERTMARKCOLOR
, 0, crColor
);
637 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0 );
638 ok(crColor
== RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor
);
640 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_insertmarkcolor_seq
,
641 "test get set insertmark color", FALSE
);
643 DestroyWindow(hTree
);
646 static void test_get_set_item(void)
648 TVITEMA tviRoot
= {0};
649 int nBufferSize
= 80;
650 char szBuffer
[80] = {0};
653 hTree
= create_treeview_control();
656 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
658 /* Test the root item */
659 tviRoot
.hItem
= hRoot
;
660 tviRoot
.mask
= TVIF_TEXT
;
661 tviRoot
.cchTextMax
= nBufferSize
;
662 tviRoot
.pszText
= szBuffer
;
663 SendMessage( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tviRoot
);
664 ok(!strcmp("Root", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer
);
666 /* Change the root text */
667 strncpy(szBuffer
, "Testing123", nBufferSize
);
668 SendMessage( hTree
, TVM_SETITEMA
, 0, (LPARAM
)&tviRoot
);
669 memset(szBuffer
, 0, nBufferSize
);
670 SendMessage( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tviRoot
);
671 ok(!strcmp("Testing123", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer
);
673 /* Reset the root text */
674 memset(szBuffer
, 0, nBufferSize
);
675 strncpy(szBuffer
, "Root", nBufferSize
);
676 SendMessage( hTree
, TVM_SETITEMA
, 0, (LPARAM
)&tviRoot
);
678 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_item_seq
,
679 "test get set item", FALSE
);
681 DestroyWindow(hTree
);
684 static void test_get_set_itemheight(void)
690 hTree
= create_treeview_control();
693 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
695 /* Assuming default height to begin with */
696 ulOldHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
698 /* Explicitly setting and getting the default height */
699 SendMessage( hTree
, TVM_SETITEMHEIGHT
, -1, 0 );
700 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
701 ok(ulNewHeight
== ulOldHeight
, "Default height not set properly, reported %d, expected %d\n", ulNewHeight
, ulOldHeight
);
703 /* Explicitly setting and getting the height of twice the normal */
704 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 2*ulOldHeight
, 0 );
705 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
706 ok(ulNewHeight
== 2*ulOldHeight
, "New height not set properly, reported %d, expected %d\n", ulNewHeight
, 2*ulOldHeight
);
708 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
709 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 9, 0 );
710 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
711 ok(ulNewHeight
== 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight
, 8);
713 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_itemheight_seq
,
714 "test get set item height", FALSE
);
716 DestroyWindow(hTree
);
719 static void test_get_set_scrolltime(void)
721 int ulExpectedTime
= 20;
725 hTree
= create_treeview_control();
728 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
730 SendMessage( hTree
, TVM_SETSCROLLTIME
, ulExpectedTime
, 0 );
731 ulTime
= (int)SendMessage( hTree
, TVM_GETSCROLLTIME
, 0, 0 );
732 ok(ulTime
== ulExpectedTime
, "Scroll time reported as %d, expected %d\n", ulTime
, ulExpectedTime
);
734 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_scrolltime_seq
,
735 "test get set scroll time", FALSE
);
737 DestroyWindow(hTree
);
740 static void test_get_set_textcolor(void)
742 /* If the value is -1, the control is using the system color for the text color. */
743 COLORREF crColor
= RGB(0,0,0);
746 hTree
= create_treeview_control();
749 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
751 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
752 ok(crColor
== -1, "Default text color reported as 0x%.8x\n", crColor
);
754 /* Test for black text */
755 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, RGB(0,0,0) );
756 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
757 ok(crColor
== RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor
);
759 /* Test for white text */
760 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, RGB(255,255,255) );
761 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
762 ok(crColor
== RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor
);
764 /* Reset the default text color */
765 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, CLR_NONE
);
767 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_textcolor_seq
,
768 "test get set text color", FALSE
);
770 DestroyWindow(hTree
);
773 static void test_get_set_tooltips(void)
775 HWND hwndLastToolTip
= NULL
;
779 hTree
= create_treeview_control();
782 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
784 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
785 hPopupTreeView
= CreateWindow(WC_TREEVIEW
, NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 100, 100, hMainWnd
, NULL
, NULL
, NULL
);
786 DestroyWindow(hPopupTreeView
);
788 /* Testing setting a NULL ToolTip */
789 SendMessage( hTree
, TVM_SETTOOLTIPS
, 0, 0 );
790 hwndLastToolTip
= (HWND
)SendMessage( hTree
, TVM_GETTOOLTIPS
, 0, 0 );
791 ok(hwndLastToolTip
== NULL
, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip
);
793 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_tooltips_seq
,
794 "test get set tooltips", TRUE
);
796 /* TODO: Add a test of an actual tooltip */
797 DestroyWindow(hTree
);
800 static void test_get_set_unicodeformat(void)
802 BOOL bPreviousSetting
= 0;
803 BOOL bNewSetting
= 0;
806 hTree
= create_treeview_control();
809 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
812 bPreviousSetting
= (BOOL
)SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 1, 0 );
813 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
814 ok(bNewSetting
== 1, "Unicode setting did not work.\n");
817 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 0, 0 );
818 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
819 ok(bNewSetting
== 0, "ANSI setting did not work.\n");
821 /* Revert to original setting */
822 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, bPreviousSetting
, 0 );
824 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_unicodeformat_seq
,
825 "test get set unicode format", FALSE
);
827 DestroyWindow(hTree
);
830 static TVITEMA g_item_expanding
, g_item_expanded
;
831 static BOOL g_get_from_expand
;
832 static BOOL g_get_rect_in_expand
;
834 static LRESULT CALLBACK
parent_wnd_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
836 static LONG defwndproc_counter
= 0;
840 HTREEITEM visibleItem
;
842 msg
.message
= message
;
843 msg
.flags
= sent
|wparam
|lparam
;
844 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
847 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
849 /* log system messages, except for painting */
850 if (message
< WM_USER
&&
851 message
!= WM_PAINT
&&
852 message
!= WM_ERASEBKGND
&&
853 message
!= WM_NCPAINT
&&
854 message
!= WM_NCHITTEST
&&
855 message
!= WM_GETTEXT
&&
856 message
!= WM_GETICON
&&
857 message
!= WM_DEVICECHANGE
)
859 trace("parent: %p, %04x, %08lx, %08lx\n", hWnd
, message
, wParam
, lParam
);
860 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
866 NMHDR
*pHdr
= (NMHDR
*)lParam
;
868 ok(pHdr
->code
!= NM_TOOLTIPSCREATED
, "Treeview should not send NM_TOOLTIPSCREATED\n");
869 if (pHdr
->idFrom
== 100)
871 NMTREEVIEWA
*pTreeView
= (LPNMTREEVIEWA
) lParam
;
874 case TVN_SELCHANGINGA
:
876 IdentifyItem(pTreeView
->itemOld
.hItem
);
877 IdentifyItem(pTreeView
->itemNew
.hItem
);
879 case TVN_SELCHANGEDA
:
881 IdentifyItem(pTreeView
->itemOld
.hItem
);
882 IdentifyItem(pTreeView
->itemNew
.hItem
);
884 case TVN_GETDISPINFOA
: {
885 NMTVDISPINFOA
*disp
= (NMTVDISPINFOA
*)lParam
;
886 if (disp
->item
.mask
& TVIF_TEXT
) {
887 lstrcpyn(disp
->item
.pszText
, TEST_CALLBACK_TEXT
, disp
->item
.cchTextMax
);
891 case TVN_ENDLABELEDIT
: return TRUE
;
892 case TVN_ITEMEXPANDINGA
:
893 ok(pTreeView
->itemNew
.mask
==
894 (TVIF_HANDLE
| TVIF_SELECTEDIMAGE
| TVIF_IMAGE
| TVIF_PARAM
| TVIF_STATE
),
895 "got wrong mask %x\n", pTreeView
->itemNew
.mask
);
896 ok((pTreeView
->itemNew
.state
& TVIS_EXPANDED
) == 0,
897 "got wrong state %x\n", pTreeView
->itemNew
.state
);
898 ok(pTreeView
->itemOld
.mask
== 0,
899 "got wrong mask %x\n", pTreeView
->itemOld
.mask
);
901 if (g_get_from_expand
)
903 g_item_expanding
.mask
= TVIF_STATE
;
904 g_item_expanding
.hItem
= hRoot
;
905 ret
= SendMessageA(pHdr
->hwndFrom
, TVM_GETITEMA
, 0, (LPARAM
)&g_item_expanding
);
906 ok(ret
== TRUE
, "got %lu\n", ret
);
909 case TVN_ITEMEXPANDEDA
:
910 ok(pTreeView
->itemNew
.mask
& TVIF_STATE
, "got wrong mask %x\n", pTreeView
->itemNew
.mask
);
911 ok(pTreeView
->itemNew
.state
& (TVIS_EXPANDED
|TVIS_EXPANDEDONCE
),
912 "got wrong mask %x\n", pTreeView
->itemNew
.mask
);
913 ok(pTreeView
->itemOld
.mask
== 0,
914 "got wrong mask %x\n", pTreeView
->itemOld
.mask
);
916 if (g_get_from_expand
)
918 g_item_expanded
.mask
= TVIF_STATE
;
919 g_item_expanded
.hItem
= hRoot
;
920 ret
= SendMessageA(pHdr
->hwndFrom
, TVM_GETITEMA
, 0, (LPARAM
)&g_item_expanded
);
921 ok(ret
== TRUE
, "got %lu\n", ret
);
923 if (g_get_rect_in_expand
)
925 visibleItem
= TreeView_GetNextItem(pHdr
->hwndFrom
, NULL
, TVGN_FIRSTVISIBLE
);
926 ok(pTreeView
->itemNew
.hItem
== visibleItem
, "expanded item == first visible item\n");
927 *(HTREEITEM
*)&rect
= visibleItem
;
928 ok(SendMessage(pHdr
->hwndFrom
, TVM_GETITEMRECT
, TRUE
, (LPARAM
)&rect
), "Failed to get rect for first visible item.\n");
929 visibleItem
= TreeView_GetNextItem(pHdr
->hwndFrom
, visibleItem
, TVGN_NEXTVISIBLE
);
930 *(HTREEITEM
*)&rect
= visibleItem
;
931 ok(visibleItem
!= NULL
, "There must be a visible item after the first visisble item.\n");
932 ok(SendMessage(pHdr
->hwndFrom
, TVM_GETITEMRECT
, TRUE
, (LPARAM
)&rect
), "Failed to get rect for second visible item.\n");
944 defwndproc_counter
++;
945 ret
= DefWindowProcA(hWnd
, message
, wParam
, lParam
);
946 defwndproc_counter
--;
951 static void test_expandinvisible(void)
953 static CHAR nodeText
[][5] = {"0", "1", "2", "3", "4"};
961 hTree
= create_treeview_control();
963 /* The test builds the following tree and expands then node 1, while node 0 is collapsed.
973 ret
= TreeView_DeleteAllItems(hTree
);
974 ok(ret
== TRUE
, "ret\n");
975 ins
.hParent
= TVI_ROOT
;
976 ins
.hInsertAfter
= TVI_ROOT
;
977 U(ins
).item
.mask
= TVIF_TEXT
;
978 U(ins
).item
.pszText
= nodeText
[0];
979 node
[0] = TreeView_InsertItem(hTree
, &ins
);
982 ins
.hInsertAfter
= TVI_LAST
;
983 U(ins
).item
.mask
= TVIF_TEXT
;
984 ins
.hParent
= node
[0];
986 U(ins
).item
.pszText
= nodeText
[1];
987 node
[1] = TreeView_InsertItem(hTree
, &ins
);
989 U(ins
).item
.pszText
= nodeText
[4];
990 node
[4] = TreeView_InsertItem(hTree
, &ins
);
993 ins
.hParent
= node
[1];
995 U(ins
).item
.pszText
= nodeText
[2];
996 node
[2] = TreeView_InsertItem(hTree
, &ins
);
998 U(ins
).item
.pszText
= nodeText
[3];
999 node
[3] = TreeView_InsertItem(hTree
, &ins
);
1003 nodeVisible
= TreeView_GetItemRect(hTree
, node
[1], &dummyRect
, FALSE
);
1004 ok(!nodeVisible
, "Node 1 should not be visible.\n");
1005 nodeVisible
= TreeView_GetItemRect(hTree
, node
[2], &dummyRect
, FALSE
);
1006 ok(!nodeVisible
, "Node 2 should not be visible.\n");
1007 nodeVisible
= TreeView_GetItemRect(hTree
, node
[3], &dummyRect
, FALSE
);
1008 ok(!nodeVisible
, "Node 3 should not be visible.\n");
1009 nodeVisible
= TreeView_GetItemRect(hTree
, node
[4], &dummyRect
, FALSE
);
1010 ok(!nodeVisible
, "Node 4 should not be visible.\n");
1012 ok(TreeView_Expand(hTree
, node
[1], TVE_EXPAND
), "Expand of node 1 failed.\n");
1014 nodeVisible
= TreeView_GetItemRect(hTree
, node
[1], &dummyRect
, FALSE
);
1015 ok(!nodeVisible
, "Node 1 should not be visible.\n");
1016 nodeVisible
= TreeView_GetItemRect(hTree
, node
[2], &dummyRect
, FALSE
);
1017 ok(!nodeVisible
, "Node 2 should not be visible.\n");
1018 nodeVisible
= TreeView_GetItemRect(hTree
, node
[3], &dummyRect
, FALSE
);
1019 ok(!nodeVisible
, "Node 3 should not be visible.\n");
1020 nodeVisible
= TreeView_GetItemRect(hTree
, node
[4], &dummyRect
, FALSE
);
1021 ok(!nodeVisible
, "Node 4 should not be visible.\n");
1023 DestroyWindow(hTree
);
1026 static void test_itemedit(void)
1034 hTree
= create_treeview_control();
1037 /* try with null item */
1038 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABEL
, 0, 0);
1039 ok(!IsWindow(edit
), "Expected valid handle\n");
1042 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABEL
, 0, (LPARAM
)hRoot
);
1043 ok(IsWindow(edit
), "Expected valid handle\n");
1044 /* item shouldn't be selected automatically after TVM_EDITLABEL */
1045 r
= SendMessage(hTree
, TVM_GETITEMSTATE
, (WPARAM
)hRoot
, TVIS_SELECTED
);
1047 /* try to cancel with wrong edit handle */
1048 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), 0);
1050 ok(IsWindow(edit
), "Expected edit control to be valid\n");
1051 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1053 ok(!IsWindow(edit
), "Expected edit control to be destroyed\n");
1054 /* try to cancel without creating edit */
1055 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), 0);
1058 /* try to cancel with wrong (not null) handle */
1059 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABEL
, 0, (LPARAM
)hRoot
);
1060 ok(IsWindow(edit
), "Expected valid handle\n");
1061 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hTree
);
1063 ok(IsWindow(edit
), "Expected edit control to be valid\n");
1064 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1067 /* remove selection after starting edit */
1068 r
= TreeView_SelectItem(hTree
, hRoot
);
1070 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABEL
, 0, (LPARAM
)hRoot
);
1071 ok(IsWindow(edit
), "Expected valid handle\n");
1072 r
= TreeView_SelectItem(hTree
, NULL
);
1075 strncpy(buff
, "x", sizeof(buff
)/sizeof(CHAR
));
1076 r
= SendMessage(edit
, WM_SETTEXT
, 0, (LPARAM
)buff
);
1078 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1080 ok(!IsWindow(edit
), "Expected edit control to be destroyed\n");
1081 /* check that text is saved */
1082 item
.mask
= TVIF_TEXT
;
1084 item
.pszText
= buff
;
1085 item
.cchTextMax
= sizeof(buff
)/sizeof(CHAR
);
1086 r
= SendMessage(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1088 ok(!strcmp("x", buff
), "Expected item text to change\n");
1090 DestroyWindow(hTree
);
1093 static void test_treeview_classinfo(void)
1097 memset(&cls
, 0, sizeof(cls
));
1098 GetClassInfo(GetModuleHandleA("comctl32.dll"), WC_TREEVIEWA
, &cls
);
1099 ok(cls
.hbrBackground
== NULL
, "Expected NULL background brush, got %p\n", cls
.hbrBackground
);
1100 ok(cls
.style
== (CS_GLOBALCLASS
| CS_DBLCLKS
), "Expected got %x\n", cls
.style
);
1101 expect(0, cls
.cbClsExtra
);
1104 static void test_get_linecolor(void)
1109 hTree
= create_treeview_control();
1111 /* newly created control has default color */
1112 clr
= (COLORREF
)SendMessage(hTree
, TVM_GETLINECOLOR
, 0, 0);
1114 win_skip("TVM_GETLINECOLOR is not supported on comctl32 < 5.80\n");
1116 expect(CLR_DEFAULT
, clr
);
1118 DestroyWindow(hTree
);
1121 static void test_get_insertmarkcolor(void)
1126 hTree
= create_treeview_control();
1128 /* newly created control has default color */
1129 clr
= (COLORREF
)SendMessage(hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0);
1131 win_skip("TVM_GETINSERTMARKCOLOR is not supported on comctl32 < 5.80\n");
1133 expect(CLR_DEFAULT
, clr
);
1135 DestroyWindow(hTree
);
1138 static void test_expandnotify(void)
1144 hTree
= create_treeview_control();
1148 item
.mask
= TVIF_STATE
;
1150 item
.state
= TVIS_EXPANDED
;
1151 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1152 ok(ret
== TRUE
, "got %d\n", ret
);
1153 ok((item
.state
& TVIS_EXPANDED
) == 0, "expected collapsed\n");
1155 /* preselect root node here */
1156 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hRoot
);
1157 ok(ret
== TRUE
, "got %d\n", ret
);
1159 g_get_from_expand
= TRUE
;
1161 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1162 g_item_expanding
.state
= 0xdeadbeef;
1163 g_item_expanded
.state
= 0xdeadbeef;
1164 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)hRoot
);
1165 ok(ret
== TRUE
, "got %d\n", ret
);
1166 ok(g_item_expanding
.state
== TVIS_SELECTED
, "got state on TVN_ITEMEXPANDING 0x%08x\n",
1167 g_item_expanding
.state
);
1168 ok(g_item_expanded
.state
== (TVIS_SELECTED
|TVIS_EXPANDED
), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1169 g_item_expanded
.state
);
1170 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_expand_seq
, "expand notifications", FALSE
);
1171 g_get_from_expand
= FALSE
;
1173 /* check that it's expanded */
1174 item
.state
= TVIS_EXPANDED
;
1175 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1176 ok(ret
== TRUE
, "got %d\n", ret
);
1177 ok((item
.state
& TVIS_EXPANDED
) == TVIS_EXPANDED
, "expected expanded\n");
1180 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1181 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_COLLAPSE
, (LPARAM
)hRoot
);
1182 ok(ret
== TRUE
, "got %d\n", ret
);
1183 item
.state
= TVIS_EXPANDED
;
1184 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1185 ok(ret
== TRUE
, "got %d\n", ret
);
1186 ok((item
.state
& TVIS_EXPANDED
) == 0, "expected collapsed\n");
1187 /* all next collapse/expand attempts won't produce any notifications,
1188 the only way is to reset with all children removed */
1189 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "collapse after expand notifications", FALSE
);
1191 DestroyWindow(hTree
);
1193 /* test TVM_GETITEMRECT inside TVN_ITEMEXPANDED notification */
1194 hTree
= create_treeview_control();
1196 g_get_rect_in_expand
= TRUE
;
1197 ret
= TreeView_Select(hTree
, hChild
, TVGN_CARET
);
1198 g_get_rect_in_expand
= FALSE
;
1199 ok(ret
, "got %d\n", ret
);
1200 DestroyWindow(hTree
);
1203 static void test_expandedimage(void)
1209 hTree
= create_treeview_control();
1212 item
.mask
= TVIF_EXPANDEDIMAGE
;
1213 item
.iExpandedImage
= 1;
1215 ret
= SendMessageA(hTree
, TVM_SETITEMA
, 0, (LPARAM
)&item
);
1216 ok(ret
, "got %d\n", ret
);
1218 item
.mask
= TVIF_EXPANDEDIMAGE
;
1219 item
.iExpandedImage
= -1;
1221 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1222 ok(ret
, "got %d\n", ret
);
1224 if (item
.iExpandedImage
!= 1)
1226 win_skip("TVIF_EXPANDEDIMAGE not supported\n");
1227 DestroyWindow(hTree
);
1231 /* test for default iExpandedImage value */
1232 item
.mask
= TVIF_EXPANDEDIMAGE
;
1233 item
.iExpandedImage
= -1;
1234 item
.hItem
= hChild
;
1235 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1236 ok(ret
, "got %d\n", ret
);
1237 ok(item
.iExpandedImage
== (WORD
)I_IMAGENONE
, "got %d\n", item
.iExpandedImage
);
1239 DestroyWindow(hTree
);
1242 static void test_TVS_SINGLEEXPAND(void)
1247 hTree
= create_treeview_control();
1248 SetWindowLongA(hTree
, GWL_STYLE
, GetWindowLong(hTree
, GWL_STYLE
) | TVS_SINGLEEXPAND
);
1249 /* to avoid paiting related notifications */
1250 ShowWindow(hTree
, SW_HIDE
);
1253 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1254 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hRoot
);
1255 ok(ret
, "got %d\n", ret
);
1256 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_singleexpand_seq
, "singleexpand notifications", FALSE
);
1258 /* a workaround for NT4 that sends expanding notification when nothing is about to expand */
1259 ret
= SendMessageA(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hRoot
);
1260 ok(ret
, "got %d\n", ret
);
1262 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, 0);
1263 ok(ret
, "got %d\n", ret
);
1265 DestroyWindow(hTree
);
1268 START_TEST(treeview
)
1271 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
1275 ULONG_PTR ctx_cookie
;
1279 hComctl32
= GetModuleHandleA("comctl32.dll");
1280 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
1281 if (pInitCommonControlsEx
)
1283 INITCOMMONCONTROLSEX iccex
;
1284 iccex
.dwSize
= sizeof(iccex
);
1285 iccex
.dwICC
= ICC_TREEVIEW_CLASSES
;
1286 pInitCommonControlsEx(&iccex
);
1289 InitCommonControls();
1291 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
1293 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1296 wc
.hInstance
= GetModuleHandleA(NULL
);
1298 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
1299 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1300 wc
.lpszMenuName
= NULL
;
1301 wc
.lpszClassName
= "MyTestWnd";
1302 wc
.lpfnWndProc
= parent_wnd_proc
;
1303 RegisterClassA(&wc
);
1305 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
1306 CW_USEDEFAULT
, CW_USEDEFAULT
, 130, 105, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1308 ok(hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n");
1309 if (!hMainWnd
) return;
1315 test_get_set_bkcolor();
1316 test_get_set_imagelist();
1317 test_get_set_indent();
1318 test_get_set_insertmark();
1319 test_get_set_item();
1320 test_get_set_itemheight();
1321 test_get_set_scrolltime();
1322 test_get_set_textcolor();
1323 test_get_linecolor();
1324 test_get_insertmarkcolor();
1325 test_get_set_tooltips();
1326 test_get_set_unicodeformat();
1328 test_expandinvisible();
1330 test_treeview_classinfo();
1331 test_expandnotify();
1332 test_TVS_SINGLEEXPAND();
1334 if (!load_v6_module(&ctx_cookie
, &hCtx
))
1336 DestroyWindow(hMainWnd
);
1340 /* this is a XP SP3 failure workaround */
1341 hwnd
= CreateWindowExA(0, WC_TREEVIEW
, "foo",
1342 WS_CHILD
| WS_BORDER
| WS_VISIBLE
,
1344 hMainWnd
, NULL
, GetModuleHandleA(NULL
), NULL
);
1345 if (!IsWindow(hwnd
))
1347 win_skip("FIXME: failed to create TreeView window.\n");
1348 unload_v6_module(ctx_cookie
, hCtx
);
1349 DestroyWindow(hMainWnd
);
1353 DestroyWindow(hwnd
);
1355 /* comctl32 version 6 tests start here */
1356 test_expandedimage();
1358 unload_v6_module(ctx_cookie
, hCtx
);
1360 PostMessageA(hMainWnd
, WM_CLOSE
, 0, 0);
1361 while(GetMessageA(&msg
, 0, 0, 0))
1363 TranslateMessage(&msg
);
1364 DispatchMessageA(&msg
);