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 static 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 /* without TVS_NONEVENHEIGHT */
717 SetWindowLong(hTree, GWL_STYLE, GetWindowLong(hTree, GWL_STYLE) & ~TVS_NONEVENHEIGHT);
719 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 3, 0);
720 ok(ulOldHeight == 8, "got %d, expected %d\n", ulOldHeight, 8);
721 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
722 ok(ulNewHeight == 2, "got %d, expected %d\n", ulNewHeight, 2);
724 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 4, 0);
725 ok(ulOldHeight == 2, "got %d, expected %d\n", ulOldHeight, 2);
726 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
727 ok(ulNewHeight == 4, "got %d, expected %d\n", ulNewHeight, 4);
729 /* with TVS_NONEVENHEIGHT */
730 SetWindowLong(hTree, GWL_STYLE, GetWindowLong(hTree, GWL_STYLE) | TVS_NONEVENHEIGHT);
732 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 3, 0);
733 ok(ulOldHeight == 4, "got %d, expected %d\n", ulOldHeight, 4);
734 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
735 ok(ulNewHeight == 3, "got %d, expected %d\n", ulNewHeight, 3);
737 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 10, 0);
738 ok(ulOldHeight == 3, "got %d, expected %d\n", ulOldHeight, 3);
739 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
740 ok(ulNewHeight == 10, "got %d, expected %d\n", ulNewHeight, 10);
742 DestroyWindow(hTree);
745 static void test_get_set_scrolltime(void)
747 int ulExpectedTime = 20;
751 hTree = create_treeview_control();
754 flush_sequences(sequences, NUM_MSG_SEQUENCES);
756 SendMessage( hTree, TVM_SETSCROLLTIME, ulExpectedTime, 0 );
757 ulTime = (int)SendMessage( hTree, TVM_GETSCROLLTIME, 0, 0 );
758 ok(ulTime == ulExpectedTime, "Scroll time reported as %d, expected %d\n", ulTime, ulExpectedTime);
760 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_scrolltime_seq,
761 "test get set scroll time", FALSE);
763 DestroyWindow(hTree);
766 static void test_get_set_textcolor(void)
768 /* If the value is -1, the control is using the system color for the text color. */
769 COLORREF crColor = RGB(0,0,0);
772 hTree = create_treeview_control();
775 flush_sequences(sequences, NUM_MSG_SEQUENCES);
777 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
778 ok(crColor == -1, "Default text color reported as 0x%.8x\n", crColor);
780 /* Test for black text */
781 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, RGB(0,0,0) );
782 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
783 ok(crColor == RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor);
785 /* Test for white text */
786 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, RGB(255,255,255) );
787 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
788 ok(crColor == RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor);
790 /* Reset the default text color */
791 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, CLR_NONE );
793 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_textcolor_seq,
794 "test get set text color", FALSE);
796 DestroyWindow(hTree);
799 static void test_get_set_tooltips(void)
801 HWND hwndLastToolTip = NULL;
805 hTree = create_treeview_control();
808 flush_sequences(sequences, NUM_MSG_SEQUENCES);
810 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
811 hPopupTreeView = CreateWindow(WC_TREEVIEW, NULL, WS_POPUP|WS_VISIBLE, 0, 0, 100, 100, hMainWnd, NULL, NULL, NULL);
812 DestroyWindow(hPopupTreeView);
814 /* Testing setting a NULL ToolTip */
815 SendMessage( hTree, TVM_SETTOOLTIPS, 0, 0 );
816 hwndLastToolTip = (HWND)SendMessage( hTree, TVM_GETTOOLTIPS, 0, 0 );
817 ok(hwndLastToolTip == NULL, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip);
819 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_tooltips_seq,
820 "test get set tooltips", TRUE);
822 /* TODO: Add a test of an actual tooltip */
823 DestroyWindow(hTree);
826 static void test_get_set_unicodeformat(void)
828 BOOL bPreviousSetting = 0;
829 BOOL bNewSetting = 0;
832 hTree = create_treeview_control();
835 flush_sequences(sequences, NUM_MSG_SEQUENCES);
838 bPreviousSetting = (BOOL)SendMessage( hTree, TVM_SETUNICODEFORMAT, 1, 0 );
839 bNewSetting = (BOOL)SendMessage( hTree, TVM_GETUNICODEFORMAT, 0, 0 );
840 ok(bNewSetting == 1, "Unicode setting did not work.\n");
843 SendMessage( hTree, TVM_SETUNICODEFORMAT, 0, 0 );
844 bNewSetting = (BOOL)SendMessage( hTree, TVM_GETUNICODEFORMAT, 0, 0 );
845 ok(bNewSetting == 0, "ANSI setting did not work.\n");
847 /* Revert to original setting */
848 SendMessage( hTree, TVM_SETUNICODEFORMAT, bPreviousSetting, 0 );
850 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_unicodeformat_seq,
851 "test get set unicode format", FALSE);
853 DestroyWindow(hTree);
856 static TVITEMA g_item_expanding, g_item_expanded;
857 static BOOL g_get_from_expand;
858 static BOOL g_get_rect_in_expand;
860 static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
862 static LONG defwndproc_counter = 0;
866 HTREEITEM visibleItem;
868 msg.message = message;
869 msg.flags = sent|wparam|lparam;
870 if (defwndproc_counter) msg.flags |= defwinproc;
873 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
875 /* log system messages, except for painting */
876 if (message < WM_USER &&
877 message != WM_PAINT &&
878 message != WM_ERASEBKGND &&
879 message != WM_NCPAINT &&
880 message != WM_NCHITTEST &&
881 message != WM_GETTEXT &&
882 message != WM_GETICON &&
883 message != WM_DEVICECHANGE)
885 trace("parent: %p, %04x, %08lx, %08lx\n", hWnd, message, wParam, lParam);
886 add_message(sequences, PARENT_SEQ_INDEX, &msg);
892 NMHDR *pHdr = (NMHDR *)lParam;
894 ok(pHdr->code != NM_TOOLTIPSCREATED, "Treeview should not send NM_TOOLTIPSCREATED\n");
895 if (pHdr->idFrom == 100)
897 NMTREEVIEWA *pTreeView = (LPNMTREEVIEWA) lParam;
900 case TVN_SELCHANGINGA:
902 IdentifyItem(pTreeView->itemOld.hItem);
903 IdentifyItem(pTreeView->itemNew.hItem);
905 case TVN_SELCHANGEDA:
907 IdentifyItem(pTreeView->itemOld.hItem);
908 IdentifyItem(pTreeView->itemNew.hItem);
910 case TVN_GETDISPINFOA: {
911 NMTVDISPINFOA *disp = (NMTVDISPINFOA *)lParam;
912 if (disp->item.mask & TVIF_TEXT) {
913 lstrcpyn(disp->item.pszText, TEST_CALLBACK_TEXT, disp->item.cchTextMax);
917 case TVN_ENDLABELEDIT: return TRUE;
918 case TVN_ITEMEXPANDINGA:
919 ok(pTreeView->itemNew.mask ==
920 (TVIF_HANDLE | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_PARAM | TVIF_STATE),
921 "got wrong mask %x\n", pTreeView->itemNew.mask);
922 ok((pTreeView->itemNew.state & TVIS_EXPANDED) == 0,
923 "got wrong state %x\n", pTreeView->itemNew.state);
924 ok(pTreeView->itemOld.mask == 0,
925 "got wrong mask %x\n", pTreeView->itemOld.mask);
927 if (g_get_from_expand)
929 g_item_expanding.mask = TVIF_STATE;
930 g_item_expanding.hItem = hRoot;
931 ret = SendMessageA(pHdr->hwndFrom, TVM_GETITEMA, 0, (LPARAM)&g_item_expanding);
932 ok(ret == TRUE, "got %lu\n", ret);
935 case TVN_ITEMEXPANDEDA:
936 ok(pTreeView->itemNew.mask & TVIF_STATE, "got wrong mask %x\n", pTreeView->itemNew.mask);
937 ok(pTreeView->itemNew.state & (TVIS_EXPANDED|TVIS_EXPANDEDONCE),
938 "got wrong mask %x\n", pTreeView->itemNew.mask);
939 ok(pTreeView->itemOld.mask == 0,
940 "got wrong mask %x\n", pTreeView->itemOld.mask);
942 if (g_get_from_expand)
944 g_item_expanded.mask = TVIF_STATE;
945 g_item_expanded.hItem = hRoot;
946 ret = SendMessageA(pHdr->hwndFrom, TVM_GETITEMA, 0, (LPARAM)&g_item_expanded);
947 ok(ret == TRUE, "got %lu\n", ret);
949 if (g_get_rect_in_expand)
951 visibleItem = TreeView_GetNextItem(pHdr->hwndFrom, NULL, TVGN_FIRSTVISIBLE);
952 ok(pTreeView->itemNew.hItem == visibleItem, "expanded item == first visible item\n");
953 *(HTREEITEM*)&rect = visibleItem;
954 ok(SendMessage(pHdr->hwndFrom, TVM_GETITEMRECT, TRUE, (LPARAM)&rect), "Failed to get rect for first visible item.\n");
955 visibleItem = TreeView_GetNextItem(pHdr->hwndFrom, visibleItem, TVGN_NEXTVISIBLE);
956 *(HTREEITEM*)&rect = visibleItem;
957 ok(visibleItem != NULL, "There must be a visible item after the first visisble item.\n");
958 ok(SendMessage(pHdr->hwndFrom, TVM_GETITEMRECT, TRUE, (LPARAM)&rect), "Failed to get rect for second visible item.\n");
970 defwndproc_counter++;
971 ret = DefWindowProcA(hWnd, message, wParam, lParam);
972 defwndproc_counter--;
977 static void test_expandinvisible(void)
979 static CHAR nodeText[][5] = {"0", "1", "2", "3", "4"};
987 hTree = create_treeview_control();
989 /* The test builds the following tree and expands then node 1, while node 0 is collapsed.
999 ret = TreeView_DeleteAllItems(hTree);
1000 ok(ret == TRUE, "ret\n");
1001 ins.hParent = TVI_ROOT;
1002 ins.hInsertAfter = TVI_ROOT;
1003 U(ins).item.mask = TVIF_TEXT;
1004 U(ins).item.pszText = nodeText[0];
1005 node[0] = TreeView_InsertItem(hTree, &ins);
1008 ins.hInsertAfter = TVI_LAST;
1009 U(ins).item.mask = TVIF_TEXT;
1010 ins.hParent = node[0];
1012 U(ins).item.pszText = nodeText[1];
1013 node[1] = TreeView_InsertItem(hTree, &ins);
1015 U(ins).item.pszText = nodeText[4];
1016 node[4] = TreeView_InsertItem(hTree, &ins);
1019 ins.hParent = node[1];
1021 U(ins).item.pszText = nodeText[2];
1022 node[2] = TreeView_InsertItem(hTree, &ins);
1024 U(ins).item.pszText = nodeText[3];
1025 node[3] = TreeView_InsertItem(hTree, &ins);
1029 nodeVisible = TreeView_GetItemRect(hTree, node[1], &dummyRect, FALSE);
1030 ok(!nodeVisible, "Node 1 should not be visible.\n");
1031 nodeVisible = TreeView_GetItemRect(hTree, node[2], &dummyRect, FALSE);
1032 ok(!nodeVisible, "Node 2 should not be visible.\n");
1033 nodeVisible = TreeView_GetItemRect(hTree, node[3], &dummyRect, FALSE);
1034 ok(!nodeVisible, "Node 3 should not be visible.\n");
1035 nodeVisible = TreeView_GetItemRect(hTree, node[4], &dummyRect, FALSE);
1036 ok(!nodeVisible, "Node 4 should not be visible.\n");
1038 ok(TreeView_Expand(hTree, node[1], TVE_EXPAND), "Expand of node 1 failed.\n");
1040 nodeVisible = TreeView_GetItemRect(hTree, node[1], &dummyRect, FALSE);
1041 ok(!nodeVisible, "Node 1 should not be visible.\n");
1042 nodeVisible = TreeView_GetItemRect(hTree, node[2], &dummyRect, FALSE);
1043 ok(!nodeVisible, "Node 2 should not be visible.\n");
1044 nodeVisible = TreeView_GetItemRect(hTree, node[3], &dummyRect, FALSE);
1045 ok(!nodeVisible, "Node 3 should not be visible.\n");
1046 nodeVisible = TreeView_GetItemRect(hTree, node[4], &dummyRect, FALSE);
1047 ok(!nodeVisible, "Node 4 should not be visible.\n");
1049 DestroyWindow(hTree);
1052 static void test_itemedit(void)
1060 hTree = create_treeview_control();
1063 /* try with null item */
1064 edit = (HWND)SendMessage(hTree, TVM_EDITLABEL, 0, 0);
1065 ok(!IsWindow(edit), "Expected valid handle\n");
1068 edit = (HWND)SendMessage(hTree, TVM_EDITLABEL, 0, (LPARAM)hRoot);
1069 ok(IsWindow(edit), "Expected valid handle\n");
1070 /* item shouldn't be selected automatically after TVM_EDITLABEL */
1071 r = SendMessage(hTree, TVM_GETITEMSTATE, (WPARAM)hRoot, TVIS_SELECTED);
1073 /* try to cancel with wrong edit handle */
1074 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), 0);
1076 ok(IsWindow(edit), "Expected edit control to be valid\n");
1077 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1079 ok(!IsWindow(edit), "Expected edit control to be destroyed\n");
1080 /* try to cancel without creating edit */
1081 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), 0);
1084 /* try to cancel with wrong (not null) handle */
1085 edit = (HWND)SendMessage(hTree, TVM_EDITLABEL, 0, (LPARAM)hRoot);
1086 ok(IsWindow(edit), "Expected valid handle\n");
1087 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hTree);
1089 ok(IsWindow(edit), "Expected edit control to be valid\n");
1090 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1093 /* remove selection after starting edit */
1094 r = TreeView_SelectItem(hTree, hRoot);
1096 edit = (HWND)SendMessage(hTree, TVM_EDITLABEL, 0, (LPARAM)hRoot);
1097 ok(IsWindow(edit), "Expected valid handle\n");
1098 r = TreeView_SelectItem(hTree, NULL);
1101 strncpy(buff, "x", sizeof(buff)/sizeof(CHAR));
1102 r = SendMessage(edit, WM_SETTEXT, 0, (LPARAM)buff);
1104 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1106 ok(!IsWindow(edit), "Expected edit control to be destroyed\n");
1107 /* check that text is saved */
1108 item.mask = TVIF_TEXT;
1110 item.pszText = buff;
1111 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
1112 r = SendMessage(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1114 ok(!strcmp("x", buff), "Expected item text to change\n");
1116 DestroyWindow(hTree);
1119 static void test_treeview_classinfo(void)
1123 memset(&cls, 0, sizeof(cls));
1124 GetClassInfo(GetModuleHandleA("comctl32.dll"), WC_TREEVIEWA, &cls);
1125 ok(cls.hbrBackground == NULL, "Expected NULL background brush, got %p\n", cls.hbrBackground);
1126 ok(cls.style == (CS_GLOBALCLASS | CS_DBLCLKS), "Expected got %x\n", cls.style);
1127 expect(0, cls.cbClsExtra);
1130 static void test_get_linecolor(void)
1135 hTree = create_treeview_control();
1137 /* newly created control has default color */
1138 clr = (COLORREF)SendMessage(hTree, TVM_GETLINECOLOR, 0, 0);
1140 win_skip("TVM_GETLINECOLOR is not supported on comctl32 < 5.80\n");
1142 expect(CLR_DEFAULT, clr);
1144 DestroyWindow(hTree);
1147 static void test_get_insertmarkcolor(void)
1152 hTree = create_treeview_control();
1154 /* newly created control has default color */
1155 clr = (COLORREF)SendMessage(hTree, TVM_GETINSERTMARKCOLOR, 0, 0);
1157 win_skip("TVM_GETINSERTMARKCOLOR is not supported on comctl32 < 5.80\n");
1159 expect(CLR_DEFAULT, clr);
1161 DestroyWindow(hTree);
1164 static void test_expandnotify(void)
1170 hTree = create_treeview_control();
1174 item.mask = TVIF_STATE;
1176 item.state = TVIS_EXPANDED;
1177 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1178 ok(ret == TRUE, "got %d\n", ret);
1179 ok((item.state & TVIS_EXPANDED) == 0, "expected collapsed\n");
1181 /* preselect root node here */
1182 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1183 ok(ret == TRUE, "got %d\n", ret);
1185 g_get_from_expand = TRUE;
1187 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1188 g_item_expanding.state = 0xdeadbeef;
1189 g_item_expanded.state = 0xdeadbeef;
1190 ret = SendMessageA(hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hRoot);
1191 ok(ret == TRUE, "got %d\n", ret);
1192 ok(g_item_expanding.state == TVIS_SELECTED, "got state on TVN_ITEMEXPANDING 0x%08x\n",
1193 g_item_expanding.state);
1194 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDED), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1195 g_item_expanded.state);
1196 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_seq, "expand notifications", FALSE);
1197 g_get_from_expand = FALSE;
1199 /* check that it's expanded */
1200 item.state = TVIS_EXPANDED;
1201 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1202 ok(ret == TRUE, "got %d\n", ret);
1203 ok((item.state & TVIS_EXPANDED) == TVIS_EXPANDED, "expected expanded\n");
1206 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1207 ret = SendMessageA(hTree, TVM_EXPAND, TVE_COLLAPSE, (LPARAM)hRoot);
1208 ok(ret == TRUE, "got %d\n", ret);
1209 item.state = TVIS_EXPANDED;
1210 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1211 ok(ret == TRUE, "got %d\n", ret);
1212 ok((item.state & TVIS_EXPANDED) == 0, "expected collapsed\n");
1213 /* all next collapse/expand attempts won't produce any notifications,
1214 the only way is to reset with all children removed */
1215 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "collapse after expand notifications", FALSE);
1217 DestroyWindow(hTree);
1219 /* test TVM_GETITEMRECT inside TVN_ITEMEXPANDED notification */
1220 hTree = create_treeview_control();
1222 g_get_rect_in_expand = TRUE;
1223 ret = TreeView_Select(hTree, hChild, TVGN_CARET);
1224 g_get_rect_in_expand = FALSE;
1225 ok(ret, "got %d\n", ret);
1226 DestroyWindow(hTree);
1229 static void test_expandedimage(void)
1235 hTree = create_treeview_control();
1238 item.mask = TVIF_EXPANDEDIMAGE;
1239 item.iExpandedImage = 1;
1241 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1242 ok(ret, "got %d\n", ret);
1244 item.mask = TVIF_EXPANDEDIMAGE;
1245 item.iExpandedImage = -1;
1247 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1248 ok(ret, "got %d\n", ret);
1250 if (item.iExpandedImage != 1)
1252 win_skip("TVIF_EXPANDEDIMAGE not supported\n");
1253 DestroyWindow(hTree);
1257 /* test for default iExpandedImage value */
1258 item.mask = TVIF_EXPANDEDIMAGE;
1259 item.iExpandedImage = -1;
1260 item.hItem = hChild;
1261 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1262 ok(ret, "got %d\n", ret);
1263 ok(item.iExpandedImage == (WORD)I_IMAGENONE, "got %d\n", item.iExpandedImage);
1265 DestroyWindow(hTree);
1268 static void test_TVS_SINGLEEXPAND(void)
1273 hTree = create_treeview_control();
1274 SetWindowLongA(hTree, GWL_STYLE, GetWindowLong(hTree, GWL_STYLE) | TVS_SINGLEEXPAND);
1275 /* to avoid paiting related notifications */
1276 ShowWindow(hTree, SW_HIDE);
1279 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1280 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1281 ok(ret, "got %d\n", ret);
1282 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_singleexpand_seq, "singleexpand notifications", FALSE);
1284 /* a workaround for NT4 that sends expanding notification when nothing is about to expand */
1285 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hRoot);
1286 ok(ret, "got %d\n", ret);
1288 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
1289 ok(ret, "got %d\n", ret);
1291 DestroyWindow(hTree);
1294 static void test_WM_PAINT(void)
1302 hTree = create_treeview_control();
1304 clr = SendMessageA(hTree, TVM_SETBKCOLOR, 0, RGB(255, 0, 0));
1305 ok(clr == -1, "got %d, expected -1\n", clr);
1307 hdc = GetDC(hMainWnd);
1309 GetClientRect(hMainWnd, &rc);
1310 FillRect(hdc, &rc, GetStockObject(BLACK_BRUSH));
1312 clr = GetPixel(hdc, 1, 1);
1313 ok(clr == RGB(0, 0, 0), "got 0x%x\n", clr);
1315 ret = SendMessageA(hTree, WM_PAINT, (WPARAM)hdc, 0);
1316 ok(ret == 0, "got %d\n", ret);
1318 clr = GetPixel(hdc, 1, 1);
1319 ok(clr == RGB(255, 0, 0) || broken(clr == RGB(0, 0, 0)) /* win98 */,
1322 ReleaseDC(hMainWnd, hdc);
1324 DestroyWindow(hTree);
1327 START_TEST(treeview)
1330 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1334 ULONG_PTR ctx_cookie;
1338 hComctl32 = GetModuleHandleA("comctl32.dll");
1339 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1340 if (pInitCommonControlsEx)
1342 INITCOMMONCONTROLSEX iccex;
1343 iccex.dwSize = sizeof(iccex);
1344 iccex.dwICC = ICC_TREEVIEW_CLASSES;
1345 pInitCommonControlsEx(&iccex);
1348 InitCommonControls();
1350 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1352 wc.style = CS_HREDRAW | CS_VREDRAW;
1355 wc.hInstance = GetModuleHandleA(NULL);
1357 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
1358 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1359 wc.lpszMenuName = NULL;
1360 wc.lpszClassName = "MyTestWnd";
1361 wc.lpfnWndProc = parent_wnd_proc;
1362 RegisterClassA(&wc);
1364 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
1365 CW_USEDEFAULT, CW_USEDEFAULT, 130, 105, NULL, NULL, GetModuleHandleA(NULL), 0);
1367 ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n");
1368 if (!hMainWnd) return;
1374 test_get_set_bkcolor();
1375 test_get_set_imagelist();
1376 test_get_set_indent();
1377 test_get_set_insertmark();
1378 test_get_set_item();
1379 test_get_set_itemheight();
1380 test_get_set_scrolltime();
1381 test_get_set_textcolor();
1382 test_get_linecolor();
1383 test_get_insertmarkcolor();
1384 test_get_set_tooltips();
1385 test_get_set_unicodeformat();
1387 test_expandinvisible();
1389 test_treeview_classinfo();
1390 test_expandnotify();
1391 test_TVS_SINGLEEXPAND();
1394 if (!load_v6_module(&ctx_cookie, &hCtx))
1396 DestroyWindow(hMainWnd);
1400 /* this is a XP SP3 failure workaround */
1401 hwnd = CreateWindowExA(0, WC_TREEVIEW, "foo",
1402 WS_CHILD | WS_BORDER | WS_VISIBLE,
1404 hMainWnd, NULL, GetModuleHandleA(NULL), NULL);
1405 if (!IsWindow(hwnd))
1407 win_skip("FIXME: failed to create TreeView window.\n");
1408 unload_v6_module(ctx_cookie, hCtx);
1409 DestroyWindow(hMainWnd);
1413 DestroyWindow(hwnd);
1415 /* comctl32 version 6 tests start here */
1416 test_expandedimage();
1418 unload_v6_module(ctx_cookie, hCtx);
1420 PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
1421 while(GetMessageA(&msg, 0, 0, 0))
1423 TranslateMessage(&msg);
1424 DispatchMessageA(&msg);