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];
45 static struct msg_sequence *item_sequence[1];
47 static const struct message FillRootSeq[] = {
48 { TVM_INSERTITEM, sent },
49 { TVM_INSERTITEM, sent },
53 static const struct message rootnone_select_seq[] = {
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 },
59 { TVM_SELECTITEM, sent|wparam, 9 },
63 static const struct message rootchild_select_seq[] = {
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 },
69 { TVM_SELECTITEM, sent|wparam, 9 },
73 static const struct message getitemtext_seq[] = {
74 { TVM_INSERTITEMA, sent },
75 { TVM_GETITEMA, sent },
76 { TVM_DELETEITEM, sent },
80 static const struct message focus_seq[] = {
81 { TVM_INSERTITEM, sent },
82 { TVM_INSERTITEM, sent },
83 { TVM_SELECTITEM, sent|wparam, 9 },
84 /* The following end up out of order in wine */
85 { WM_WINDOWPOSCHANGING, sent|defwinproc },
86 { WM_NCCALCSIZE, sent|wparam|defwinproc, TRUE },
87 { WM_WINDOWPOSCHANGED, sent|defwinproc },
88 { WM_SIZE, sent|defwinproc },
89 { WM_PAINT, sent|defwinproc },
90 { WM_NCPAINT, sent|wparam|defwinproc, 1 },
91 { WM_ERASEBKGND, sent|defwinproc },
92 { TVM_EDITLABEL, sent },
93 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_UPDATE) },
94 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_CHANGE) },
95 { WM_PARENTNOTIFY, sent|wparam|defwinproc, MAKEWPARAM(WM_CREATE, 0) },
96 { WM_KILLFOCUS, sent|defwinproc },
97 { WM_PAINT, sent|defwinproc },
98 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
99 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_SETFOCUS) },
100 { WM_ERASEBKGND, sent|defwinproc|optional },
101 { WM_CTLCOLOREDIT, sent|defwinproc|optional },
102 { WM_CTLCOLOREDIT, sent|defwinproc|optional },
106 static const struct message test_get_set_bkcolor_seq[] = {
107 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
108 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, 0 },
109 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
110 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, 0x00ffffff },
111 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
112 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, -1 },
116 static const struct message test_get_set_imagelist_seq[] = {
117 { TVM_SETIMAGELIST, sent|wparam|lparam, 0, 0 },
118 { TVM_GETIMAGELIST, sent|wparam|lparam, 0, 0 },
122 static const struct message test_get_set_indent_seq[] = {
123 { TVM_SETINDENT, sent|wparam|lparam, 0, 0 },
124 { TVM_GETINDENT, sent|wparam|lparam, 0, 0 },
125 /* The actual amount to indent is dependent on the system for this message */
126 { TVM_SETINDENT, sent },
127 { TVM_GETINDENT, sent|wparam|lparam, 0, 0 },
131 static const struct message test_get_set_insertmarkcolor_seq[] = {
132 { TVM_SETINSERTMARKCOLOR, sent|wparam|lparam, 0, 0 },
133 { TVM_GETINSERTMARKCOLOR, sent|wparam|lparam, 0, 0 },
137 static const struct message test_get_set_item_seq[] = {
138 { TVM_GETITEMA, sent },
139 { TVM_SETITEMA, sent },
140 { TVM_GETITEMA, sent },
141 { TVM_SETITEMA, sent },
145 static const struct message test_get_set_itemheight_seq[] = {
146 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
147 { TVM_SETITEMHEIGHT, sent|wparam|lparam, -1, 0 },
148 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
149 { TVM_SETITEMHEIGHT, sent|lparam, 0xcccccccc, 0 },
150 { TVM_GETITEMHEIGHT, sent|wparam|lparam|optional, 0, 0 },
151 { TVM_SETITEMHEIGHT, sent|wparam|lparam|optional, 9, 0 },
152 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
156 static const struct message test_get_set_scrolltime_seq[] = {
157 { TVM_SETSCROLLTIME, sent|wparam|lparam, 20, 0 },
158 { TVM_GETSCROLLTIME, sent|wparam|lparam, 0, 0 },
162 static const struct message test_get_set_textcolor_seq[] = {
163 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
164 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
165 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
166 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, RGB(255, 255, 255) },
167 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
168 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, CLR_NONE },
172 static const struct message test_get_set_tooltips_seq[] = {
173 { WM_KILLFOCUS, sent },
174 { WM_IME_SETCONTEXT, sent|optional },
175 { WM_IME_NOTIFY, sent|optional },
176 { TVM_SETTOOLTIPS, sent|wparam|lparam, 0, 0 },
177 { TVM_GETTOOLTIPS, sent|wparam|lparam, 0, 0 },
181 static const struct message test_get_set_unicodeformat_seq[] = {
182 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, TRUE, 0 },
183 { TVM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
184 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
185 { TVM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
186 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
190 static const struct message parent_expand_seq[] = {
191 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
192 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
196 static const struct message parent_singleexpand_seq[] = {
197 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGINGA },
198 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGEDA },
199 { WM_NOTIFY, sent|id, 0, 0, TVN_SINGLEEXPAND },
200 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
201 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
205 static const struct message empty_seq[] = {
209 static HWND hMainWnd;
211 static HTREEITEM hRoot, hChild;
214 static char sequence[256];
216 static void Clear(void)
222 static void AddItem(char ch)
224 sequence[pos++] = ch;
225 sequence[pos] = '\0';
228 static void IdentifyItem(HTREEITEM hItem)
230 if (hItem == hRoot) {
234 if (hItem == hChild) {
245 /* This function hooks in and records all messages to the treeview control */
246 static LRESULT WINAPI TreeviewWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
248 static LONG defwndproc_counter = 0;
251 WNDPROC lpOldProc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
253 msg.message = message;
254 msg.flags = sent|wparam|lparam;
255 if (defwndproc_counter) msg.flags |= defwinproc;
258 add_message(sequences, TREEVIEW_SEQ_INDEX, &msg);
260 defwndproc_counter++;
261 ret = CallWindowProcA(lpOldProc, hwnd, message, wParam, lParam);
262 defwndproc_counter--;
267 static HWND create_treeview_control(void)
272 hTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL, WS_CHILD|WS_VISIBLE|
273 TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS|TVS_EDITLABELS,
274 0, 0, 120, 100, hMainWnd, (HMENU)100, GetModuleHandleA(0), 0);
278 /* Record the old WNDPROC so we can call it after recording the messages */
279 pOldWndProc = (WNDPROC)SetWindowLongPtrA(hTree, GWLP_WNDPROC, (LONG_PTR)TreeviewWndProc);
280 SetWindowLongPtrA(hTree, GWLP_USERDATA, (LONG_PTR)pOldWndProc);
285 static void fill_tree(HWND hTree)
288 static CHAR root[] = "Root",
291 ins.hParent = TVI_ROOT;
292 ins.hInsertAfter = TVI_ROOT;
293 U(ins).item.mask = TVIF_TEXT;
294 U(ins).item.pszText = root;
295 hRoot = TreeView_InsertItem(hTree, &ins);
298 ins.hInsertAfter = TVI_FIRST;
299 U(ins).item.mask = TVIF_TEXT;
300 U(ins).item.pszText = child;
301 hChild = TreeView_InsertItem(hTree, &ins);
304 static void test_fillroot(void)
309 hTree = create_treeview_control();
311 flush_sequences(sequences, NUM_MSG_SEQUENCES);
321 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, FillRootSeq, "FillRoot", FALSE);
322 ok(!strcmp(sequence, "AB."), "Item creation\n");
324 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
326 tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
327 SendMessage( hTree, TVM_GETITEMA, 0, (LPARAM)&tvi );
328 ok(tvi.iImage == 0, "tvi.iImage=%d\n", tvi.iImage);
329 ok(tvi.iSelectedImage == 0, "tvi.iSelectedImage=%d\n", tvi.iSelectedImage);
331 DestroyWindow(hTree);
334 static void test_callback(void)
337 HTREEITEM hItem1, hItem2;
340 CHAR test_string[] = "Test_string";
345 hTree = create_treeview_control();
348 ret = TreeView_DeleteAllItems(hTree);
349 ok(ret == TRUE, "ret\n");
350 ins.hParent = TVI_ROOT;
351 ins.hInsertAfter = TVI_ROOT;
352 U(ins).item.mask = TVIF_TEXT;
353 U(ins).item.pszText = LPSTR_TEXTCALLBACK;
354 hRoot = TreeView_InsertItem(hTree, &ins);
358 tvi.mask = TVIF_TEXT;
360 tvi.cchTextMax = sizeof(buf)/sizeof(buf[0]);
361 ret = TreeView_GetItem(hTree, &tvi);
362 ok(ret == 1, "ret\n");
363 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Callback item text mismatch %s vs %s\n",
364 tvi.pszText, TEST_CALLBACK_TEXT);
367 ins.hInsertAfter = TVI_FIRST;
368 U(ins).item.mask = TVIF_TEXT;
369 U(ins).item.pszText = test_string;
370 hItem1 = TreeView_InsertItem(hTree, &ins);
374 ret = TreeView_GetItem(hTree, &tvi);
375 ok(ret == TRUE, "ret\n");
376 ok(strcmp(tvi.pszText, test_string) == 0, "Item text mismatch %s vs %s\n",
377 tvi.pszText, test_string);
379 /* undocumented: pszText of NULL also means LPSTR_CALLBACK: */
381 ret = TreeView_SetItem(hTree, &tvi);
382 ok(ret == 1, "Expected SetItem return 1, got %ld\n", ret);
384 ret = TreeView_GetItem(hTree, &tvi);
385 ok(ret == TRUE, "Expected GetItem return TRUE, got %ld\n", ret);
386 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Item text mismatch %s vs %s\n",
387 tvi.pszText, TEST_CALLBACK_TEXT);
389 U(ins).item.pszText = NULL;
390 hItem2 = TreeView_InsertItem(hTree, &ins);
393 memset(buf, 0, sizeof(buf));
394 ret = TreeView_GetItem(hTree, &tvi);
395 ok(ret == TRUE, "Expected GetItem return TRUE, got %ld\n", ret);
396 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Item text mismatch %s vs %s\n",
397 tvi.pszText, TEST_CALLBACK_TEXT);
399 DestroyWindow(hTree);
402 static void test_select(void)
407 hTree = create_treeview_control();
410 /* root-none select tests */
411 flush_sequences(sequences, NUM_MSG_SEQUENCES);
412 r = TreeView_SelectItem(hTree, NULL);
416 r = TreeView_SelectItem(hTree, hRoot);
419 r = TreeView_SelectItem(hTree, hRoot);
422 r = TreeView_SelectItem(hTree, NULL);
425 r = TreeView_SelectItem(hTree, NULL);
428 r = TreeView_SelectItem(hTree, hRoot);
431 ok(!strcmp(sequence, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
432 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, rootnone_select_seq,
433 "root-none select seq", FALSE);
435 /* root-child select tests */
436 flush_sequences(sequences, NUM_MSG_SEQUENCES);
437 r = TreeView_SelectItem(hTree, NULL);
442 r = TreeView_SelectItem(hTree, hRoot);
445 r = TreeView_SelectItem(hTree, hRoot);
448 r = TreeView_SelectItem(hTree, hChild);
451 r = TreeView_SelectItem(hTree, hChild);
454 r = TreeView_SelectItem(hTree, hRoot);
457 ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
458 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, rootchild_select_seq,
459 "root-child select seq", FALSE);
461 DestroyWindow(hTree);
464 static void test_getitemtext(void)
471 CHAR szBuffer[80] = "Blah";
472 int nBufferSize = sizeof(szBuffer)/sizeof(CHAR);
474 hTree = create_treeview_control();
477 flush_sequences(sequences, NUM_MSG_SEQUENCES);
479 /* add an item without TVIF_TEXT mask and pszText == NULL */
481 ins.hInsertAfter = TVI_ROOT;
482 U(ins).item.mask = 0;
483 U(ins).item.pszText = NULL;
484 U(ins).item.cchTextMax = 0;
485 hChild = TreeView_InsertItem(hTree, &ins);
488 /* retrieve it with TVIF_TEXT mask */
490 tvi.mask = TVIF_TEXT;
491 tvi.cchTextMax = nBufferSize;
492 tvi.pszText = szBuffer;
494 SendMessageA( hTree, TVM_GETITEMA, 0, (LPARAM)&tvi );
495 ok(!strcmp(szBuffer, ""), "szBuffer=\"%s\", expected \"\"\n", szBuffer);
496 ok(SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild), "DeleteItem failed\n");
497 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, getitemtext_seq, "get item text seq", FALSE);
499 DestroyWindow(hTree);
502 static void test_focus(void)
505 static CHAR child1[] = "Edit",
506 child2[] = "A really long string";
507 HTREEITEM hChild1, hChild2;
511 hTree = create_treeview_control();
514 flush_sequences(sequences, NUM_MSG_SEQUENCES);
516 /* This test verifies that when a label is being edited, scrolling
517 * the treeview does not cause the label to lose focus. To test
518 * this, first some additional entries are added to generate
522 ins.hInsertAfter = hChild;
523 U(ins).item.mask = TVIF_TEXT;
524 U(ins).item.pszText = child1;
525 hChild1 = TreeView_InsertItem(hTree, &ins);
527 ins.hInsertAfter = hChild1;
528 U(ins).item.mask = TVIF_TEXT;
529 U(ins).item.pszText = child2;
530 hChild2 = TreeView_InsertItem(hTree, &ins);
533 ShowWindow(hMainWnd,SW_SHOW);
534 SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
535 hEdit = TreeView_EditLabel(hTree, hChild);
536 ScrollWindowEx(hTree, -10, 0, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN);
537 ok(GetFocus() == hEdit, "Edit control should have focus\n");
538 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, focus_seq, "focus test", TRUE);
540 DestroyWindow(hTree);
543 static void test_get_set_bkcolor(void)
545 COLORREF crColor = RGB(0,0,0);
548 hTree = create_treeview_control();
551 flush_sequences(sequences, NUM_MSG_SEQUENCES);
553 /* If the value is -1, the control is using the system color for the background color. */
554 crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
555 ok(crColor == -1, "Default background color reported as 0x%.8x\n", crColor);
557 /* Test for black background */
558 SendMessage( hTree, TVM_SETBKCOLOR, 0, RGB(0,0,0) );
559 crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
560 ok(crColor == RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor);
562 /* Test for white background */
563 SendMessage( hTree, TVM_SETBKCOLOR, 0, RGB(255,255,255) );
564 crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
565 ok(crColor == RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor);
567 /* Reset the default background */
568 SendMessage( hTree, TVM_SETBKCOLOR, 0, -1 );
570 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_bkcolor_seq,
571 "test get set bkcolor", FALSE);
573 DestroyWindow(hTree);
576 static void test_get_set_imagelist(void)
578 HIMAGELIST hImageList = NULL;
581 hTree = create_treeview_control();
584 flush_sequences(sequences, NUM_MSG_SEQUENCES);
586 /* Test a NULL HIMAGELIST */
587 SendMessage( hTree, TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)hImageList );
588 hImageList = (HIMAGELIST)SendMessage( hTree, TVM_GETIMAGELIST, TVSIL_NORMAL, 0 );
589 ok(hImageList == NULL, "NULL image list, reported as 0x%p, expected 0.\n", hImageList);
591 /* TODO: Test an actual image list */
593 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_imagelist_seq,
594 "test get imagelist", FALSE);
596 DestroyWindow(hTree);
599 static void test_get_set_indent(void)
602 int ulMinIndent = -1;
603 int ulMoreThanTwiceMin = -1;
606 hTree = create_treeview_control();
609 flush_sequences(sequences, NUM_MSG_SEQUENCES);
611 /* Finding the minimum indent */
612 SendMessage( hTree, TVM_SETINDENT, 0, 0 );
613 ulMinIndent = (int)SendMessage( hTree, TVM_GETINDENT, 0, 0 );
615 /* Checking an indent that is more than twice the default indent */
616 ulMoreThanTwiceMin = 2*ulMinIndent+1;
617 SendMessage( hTree, TVM_SETINDENT, ulMoreThanTwiceMin, 0 );
618 ulIndent = (DWORD)SendMessage( hTree, TVM_GETINDENT, 0, 0 );
619 ok(ulIndent == ulMoreThanTwiceMin, "Indent reported as %d, expected %d\n", ulIndent, ulMoreThanTwiceMin);
621 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_indent_seq,
622 "test get set indent", FALSE);
624 DestroyWindow(hTree);
627 static void test_get_set_insertmark(void)
629 COLORREF crColor = RGB(0,0,0);
632 hTree = create_treeview_control();
635 flush_sequences(sequences, NUM_MSG_SEQUENCES);
637 SendMessage( hTree, TVM_SETINSERTMARKCOLOR, 0, crColor );
638 crColor = (COLORREF)SendMessage( hTree, TVM_GETINSERTMARKCOLOR, 0, 0 );
639 ok(crColor == RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor);
641 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_insertmarkcolor_seq,
642 "test get set insertmark color", FALSE);
644 DestroyWindow(hTree);
647 static void test_get_set_item(void)
649 TVITEMA tviRoot = {0};
650 int nBufferSize = 80;
651 char szBuffer[80] = {0};
654 hTree = create_treeview_control();
657 flush_sequences(sequences, NUM_MSG_SEQUENCES);
659 /* Test the root item */
660 tviRoot.hItem = hRoot;
661 tviRoot.mask = TVIF_TEXT;
662 tviRoot.cchTextMax = nBufferSize;
663 tviRoot.pszText = szBuffer;
664 SendMessage( hTree, TVM_GETITEMA, 0, (LPARAM)&tviRoot );
665 ok(!strcmp("Root", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer);
667 /* Change the root text */
668 strncpy(szBuffer, "Testing123", nBufferSize);
669 SendMessage( hTree, TVM_SETITEMA, 0, (LPARAM)&tviRoot );
670 memset(szBuffer, 0, nBufferSize);
671 SendMessage( hTree, TVM_GETITEMA, 0, (LPARAM)&tviRoot );
672 ok(!strcmp("Testing123", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer);
674 /* Reset the root text */
675 memset(szBuffer, 0, nBufferSize);
676 strncpy(szBuffer, "Root", nBufferSize);
677 SendMessage( hTree, TVM_SETITEMA, 0, (LPARAM)&tviRoot );
679 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_item_seq,
680 "test get set item", FALSE);
682 DestroyWindow(hTree);
685 static void test_get_set_itemheight(void)
691 hTree = create_treeview_control();
694 flush_sequences(sequences, NUM_MSG_SEQUENCES);
696 /* Assuming default height to begin with */
697 ulOldHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
699 /* Explicitly setting and getting the default height */
700 SendMessage( hTree, TVM_SETITEMHEIGHT, -1, 0 );
701 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
702 ok(ulNewHeight == ulOldHeight, "Default height not set properly, reported %d, expected %d\n", ulNewHeight, ulOldHeight);
704 /* Explicitly setting and getting the height of twice the normal */
705 SendMessage( hTree, TVM_SETITEMHEIGHT, 2*ulOldHeight, 0 );
706 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
707 ok(ulNewHeight == 2*ulOldHeight, "New height not set properly, reported %d, expected %d\n", ulNewHeight, 2*ulOldHeight);
709 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
710 SendMessage( hTree, TVM_SETITEMHEIGHT, 9, 0 );
711 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
712 ok(ulNewHeight == 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight, 8);
714 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_itemheight_seq,
715 "test get set item height", FALSE);
717 /* without TVS_NONEVENHEIGHT */
718 SetWindowLong(hTree, GWL_STYLE, GetWindowLong(hTree, GWL_STYLE) & ~TVS_NONEVENHEIGHT);
720 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 3, 0);
721 ok(ulOldHeight == 8, "got %d, expected %d\n", ulOldHeight, 8);
722 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
723 ok(ulNewHeight == 2, "got %d, expected %d\n", ulNewHeight, 2);
725 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 4, 0);
726 ok(ulOldHeight == 2, "got %d, expected %d\n", ulOldHeight, 2);
727 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
728 ok(ulNewHeight == 4, "got %d, expected %d\n", ulNewHeight, 4);
730 /* with TVS_NONEVENHEIGHT */
731 SetWindowLong(hTree, GWL_STYLE, GetWindowLong(hTree, GWL_STYLE) | TVS_NONEVENHEIGHT);
733 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 3, 0);
734 ok(ulOldHeight == 4, "got %d, expected %d\n", ulOldHeight, 4);
735 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
736 ok(ulNewHeight == 3, "got %d, expected %d\n", ulNewHeight, 3);
738 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 10, 0);
739 ok(ulOldHeight == 3, "got %d, expected %d\n", ulOldHeight, 3);
740 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
741 ok(ulNewHeight == 10, "got %d, expected %d\n", ulNewHeight, 10);
743 DestroyWindow(hTree);
746 static void test_get_set_scrolltime(void)
748 int ulExpectedTime = 20;
752 hTree = create_treeview_control();
755 flush_sequences(sequences, NUM_MSG_SEQUENCES);
757 SendMessage( hTree, TVM_SETSCROLLTIME, ulExpectedTime, 0 );
758 ulTime = (int)SendMessage( hTree, TVM_GETSCROLLTIME, 0, 0 );
759 ok(ulTime == ulExpectedTime, "Scroll time reported as %d, expected %d\n", ulTime, ulExpectedTime);
761 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_scrolltime_seq,
762 "test get set scroll time", FALSE);
764 DestroyWindow(hTree);
767 static void test_get_set_textcolor(void)
769 /* If the value is -1, the control is using the system color for the text color. */
770 COLORREF crColor = RGB(0,0,0);
773 hTree = create_treeview_control();
776 flush_sequences(sequences, NUM_MSG_SEQUENCES);
778 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
779 ok(crColor == -1, "Default text color reported as 0x%.8x\n", crColor);
781 /* Test for black text */
782 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, RGB(0,0,0) );
783 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
784 ok(crColor == RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor);
786 /* Test for white text */
787 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, RGB(255,255,255) );
788 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
789 ok(crColor == RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor);
791 /* Reset the default text color */
792 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, CLR_NONE );
794 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_textcolor_seq,
795 "test get set text color", FALSE);
797 DestroyWindow(hTree);
800 static void test_get_set_tooltips(void)
802 HWND hwndLastToolTip = NULL;
806 hTree = create_treeview_control();
809 flush_sequences(sequences, NUM_MSG_SEQUENCES);
811 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
812 hPopupTreeView = CreateWindow(WC_TREEVIEW, NULL, WS_POPUP|WS_VISIBLE, 0, 0, 100, 100, hMainWnd, NULL, NULL, NULL);
813 DestroyWindow(hPopupTreeView);
815 /* Testing setting a NULL ToolTip */
816 SendMessage( hTree, TVM_SETTOOLTIPS, 0, 0 );
817 hwndLastToolTip = (HWND)SendMessage( hTree, TVM_GETTOOLTIPS, 0, 0 );
818 ok(hwndLastToolTip == NULL, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip);
820 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_tooltips_seq,
821 "test get set tooltips", TRUE);
823 /* TODO: Add a test of an actual tooltip */
824 DestroyWindow(hTree);
827 static void test_get_set_unicodeformat(void)
829 BOOL bPreviousSetting = 0;
830 BOOL bNewSetting = 0;
833 hTree = create_treeview_control();
836 flush_sequences(sequences, NUM_MSG_SEQUENCES);
839 bPreviousSetting = (BOOL)SendMessage( hTree, TVM_SETUNICODEFORMAT, 1, 0 );
840 bNewSetting = (BOOL)SendMessage( hTree, TVM_GETUNICODEFORMAT, 0, 0 );
841 ok(bNewSetting == 1, "Unicode setting did not work.\n");
844 SendMessage( hTree, TVM_SETUNICODEFORMAT, 0, 0 );
845 bNewSetting = (BOOL)SendMessage( hTree, TVM_GETUNICODEFORMAT, 0, 0 );
846 ok(bNewSetting == 0, "ANSI setting did not work.\n");
848 /* Revert to original setting */
849 SendMessage( hTree, TVM_SETUNICODEFORMAT, bPreviousSetting, 0 );
851 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_unicodeformat_seq,
852 "test get set unicode format", FALSE);
854 DestroyWindow(hTree);
857 static TVITEMA g_item_expanding, g_item_expanded;
858 static BOOL g_get_from_expand;
859 static BOOL g_get_rect_in_expand;
861 static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
863 static LONG defwndproc_counter = 0;
867 HTREEITEM visibleItem;
869 msg.message = message;
870 msg.flags = sent|wparam|lparam;
871 if (defwndproc_counter) msg.flags |= defwinproc;
874 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
876 /* log system messages, except for painting */
877 if (message < WM_USER &&
878 message != WM_PAINT &&
879 message != WM_ERASEBKGND &&
880 message != WM_NCPAINT &&
881 message != WM_NCHITTEST &&
882 message != WM_GETTEXT &&
883 message != WM_GETICON &&
884 message != WM_DEVICECHANGE)
886 trace("parent: %p, %04x, %08lx, %08lx\n", hWnd, message, wParam, lParam);
887 add_message(sequences, PARENT_SEQ_INDEX, &msg);
893 NMHDR *pHdr = (NMHDR *)lParam;
895 ok(pHdr->code != NM_TOOLTIPSCREATED, "Treeview should not send NM_TOOLTIPSCREATED\n");
896 if (pHdr->idFrom == 100)
898 NMTREEVIEWA *pTreeView = (LPNMTREEVIEWA) lParam;
901 case TVN_SELCHANGINGA:
903 IdentifyItem(pTreeView->itemOld.hItem);
904 IdentifyItem(pTreeView->itemNew.hItem);
906 case TVN_SELCHANGEDA:
908 IdentifyItem(pTreeView->itemOld.hItem);
909 IdentifyItem(pTreeView->itemNew.hItem);
911 case TVN_GETDISPINFOA: {
912 NMTVDISPINFOA *disp = (NMTVDISPINFOA *)lParam;
913 if (disp->item.mask & TVIF_TEXT) {
914 lstrcpyn(disp->item.pszText, TEST_CALLBACK_TEXT, disp->item.cchTextMax);
918 case TVN_ENDLABELEDIT: return TRUE;
919 case TVN_ITEMEXPANDINGA:
920 ok(pTreeView->itemNew.mask ==
921 (TVIF_HANDLE | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_PARAM | TVIF_STATE),
922 "got wrong mask %x\n", pTreeView->itemNew.mask);
923 ok((pTreeView->itemNew.state & TVIS_EXPANDED) == 0,
924 "got wrong state %x\n", pTreeView->itemNew.state);
925 ok(pTreeView->itemOld.mask == 0,
926 "got wrong mask %x\n", pTreeView->itemOld.mask);
928 if (g_get_from_expand)
930 g_item_expanding.mask = TVIF_STATE;
931 g_item_expanding.hItem = hRoot;
932 ret = SendMessageA(pHdr->hwndFrom, TVM_GETITEMA, 0, (LPARAM)&g_item_expanding);
933 ok(ret == TRUE, "got %lu\n", ret);
936 case TVN_ITEMEXPANDEDA:
937 ok(pTreeView->itemNew.mask & TVIF_STATE, "got wrong mask %x\n", pTreeView->itemNew.mask);
938 ok(pTreeView->itemNew.state & (TVIS_EXPANDED|TVIS_EXPANDEDONCE),
939 "got wrong mask %x\n", pTreeView->itemNew.mask);
940 ok(pTreeView->itemOld.mask == 0,
941 "got wrong mask %x\n", pTreeView->itemOld.mask);
943 if (g_get_from_expand)
945 g_item_expanded.mask = TVIF_STATE;
946 g_item_expanded.hItem = hRoot;
947 ret = SendMessageA(pHdr->hwndFrom, TVM_GETITEMA, 0, (LPARAM)&g_item_expanded);
948 ok(ret == TRUE, "got %lu\n", ret);
950 if (g_get_rect_in_expand)
952 visibleItem = TreeView_GetNextItem(pHdr->hwndFrom, NULL, TVGN_FIRSTVISIBLE);
953 ok(pTreeView->itemNew.hItem == visibleItem, "expanded item == first visible item\n");
954 *(HTREEITEM*)&rect = visibleItem;
955 ok(SendMessage(pHdr->hwndFrom, TVM_GETITEMRECT, TRUE, (LPARAM)&rect), "Failed to get rect for first visible item.\n");
956 visibleItem = TreeView_GetNextItem(pHdr->hwndFrom, visibleItem, TVGN_NEXTVISIBLE);
957 *(HTREEITEM*)&rect = visibleItem;
958 ok(visibleItem != NULL, "There must be a visible item after the first visisble item.\n");
959 ok(SendMessage(pHdr->hwndFrom, TVM_GETITEMRECT, TRUE, (LPARAM)&rect), "Failed to get rect for second visible item.\n");
962 case TVN_DELETEITEMA:
966 ok(pTreeView->itemNew.mask == 0, "got wrong mask 0x%x\n", pTreeView->itemNew.mask);
968 ok(pTreeView->itemOld.mask == (TVIF_HANDLE | TVIF_PARAM), "got wrong mask 0x%x\n", pTreeView->itemOld.mask);
969 ok(pTreeView->itemOld.hItem != NULL, "got %p\n", pTreeView->itemOld.hItem);
971 memset(&item, 0, sizeof(item));
972 item.lParam = (LPARAM)pTreeView->itemOld.hItem;
973 add_message(item_sequence, 0, &item);
986 defwndproc_counter++;
987 ret = DefWindowProcA(hWnd, message, wParam, lParam);
988 defwndproc_counter--;
993 static void test_expandinvisible(void)
995 static CHAR nodeText[][5] = {"0", "1", "2", "3", "4"};
1003 hTree = create_treeview_control();
1005 /* The test builds the following tree and expands then node 1, while node 0 is collapsed.
1015 ret = TreeView_DeleteAllItems(hTree);
1016 ok(ret == TRUE, "ret\n");
1017 ins.hParent = TVI_ROOT;
1018 ins.hInsertAfter = TVI_ROOT;
1019 U(ins).item.mask = TVIF_TEXT;
1020 U(ins).item.pszText = nodeText[0];
1021 node[0] = TreeView_InsertItem(hTree, &ins);
1024 ins.hInsertAfter = TVI_LAST;
1025 U(ins).item.mask = TVIF_TEXT;
1026 ins.hParent = node[0];
1028 U(ins).item.pszText = nodeText[1];
1029 node[1] = TreeView_InsertItem(hTree, &ins);
1031 U(ins).item.pszText = nodeText[4];
1032 node[4] = TreeView_InsertItem(hTree, &ins);
1035 ins.hParent = node[1];
1037 U(ins).item.pszText = nodeText[2];
1038 node[2] = TreeView_InsertItem(hTree, &ins);
1040 U(ins).item.pszText = nodeText[3];
1041 node[3] = TreeView_InsertItem(hTree, &ins);
1045 nodeVisible = TreeView_GetItemRect(hTree, node[1], &dummyRect, FALSE);
1046 ok(!nodeVisible, "Node 1 should not be visible.\n");
1047 nodeVisible = TreeView_GetItemRect(hTree, node[2], &dummyRect, FALSE);
1048 ok(!nodeVisible, "Node 2 should not be visible.\n");
1049 nodeVisible = TreeView_GetItemRect(hTree, node[3], &dummyRect, FALSE);
1050 ok(!nodeVisible, "Node 3 should not be visible.\n");
1051 nodeVisible = TreeView_GetItemRect(hTree, node[4], &dummyRect, FALSE);
1052 ok(!nodeVisible, "Node 4 should not be visible.\n");
1054 ok(TreeView_Expand(hTree, node[1], TVE_EXPAND), "Expand of node 1 failed.\n");
1056 nodeVisible = TreeView_GetItemRect(hTree, node[1], &dummyRect, FALSE);
1057 ok(!nodeVisible, "Node 1 should not be visible.\n");
1058 nodeVisible = TreeView_GetItemRect(hTree, node[2], &dummyRect, FALSE);
1059 ok(!nodeVisible, "Node 2 should not be visible.\n");
1060 nodeVisible = TreeView_GetItemRect(hTree, node[3], &dummyRect, FALSE);
1061 ok(!nodeVisible, "Node 3 should not be visible.\n");
1062 nodeVisible = TreeView_GetItemRect(hTree, node[4], &dummyRect, FALSE);
1063 ok(!nodeVisible, "Node 4 should not be visible.\n");
1065 DestroyWindow(hTree);
1068 static void test_itemedit(void)
1076 hTree = create_treeview_control();
1079 /* try with null item */
1080 edit = (HWND)SendMessage(hTree, TVM_EDITLABEL, 0, 0);
1081 ok(!IsWindow(edit), "Expected valid handle\n");
1084 edit = (HWND)SendMessage(hTree, TVM_EDITLABEL, 0, (LPARAM)hRoot);
1085 ok(IsWindow(edit), "Expected valid handle\n");
1086 /* item shouldn't be selected automatically after TVM_EDITLABEL */
1087 r = SendMessage(hTree, TVM_GETITEMSTATE, (WPARAM)hRoot, TVIS_SELECTED);
1089 /* try to cancel with wrong edit handle */
1090 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), 0);
1092 ok(IsWindow(edit), "Expected edit control to be valid\n");
1093 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1095 ok(!IsWindow(edit), "Expected edit control to be destroyed\n");
1096 /* try to cancel without creating edit */
1097 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), 0);
1100 /* try to cancel with wrong (not null) handle */
1101 edit = (HWND)SendMessage(hTree, TVM_EDITLABEL, 0, (LPARAM)hRoot);
1102 ok(IsWindow(edit), "Expected valid handle\n");
1103 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hTree);
1105 ok(IsWindow(edit), "Expected edit control to be valid\n");
1106 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1109 /* remove selection after starting edit */
1110 r = TreeView_SelectItem(hTree, hRoot);
1112 edit = (HWND)SendMessage(hTree, TVM_EDITLABEL, 0, (LPARAM)hRoot);
1113 ok(IsWindow(edit), "Expected valid handle\n");
1114 r = TreeView_SelectItem(hTree, NULL);
1117 strncpy(buff, "x", sizeof(buff)/sizeof(CHAR));
1118 r = SendMessage(edit, WM_SETTEXT, 0, (LPARAM)buff);
1120 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1122 ok(!IsWindow(edit), "Expected edit control to be destroyed\n");
1123 /* check that text is saved */
1124 item.mask = TVIF_TEXT;
1126 item.pszText = buff;
1127 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
1128 r = SendMessage(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1130 ok(!strcmp("x", buff), "Expected item text to change\n");
1132 DestroyWindow(hTree);
1135 static void test_treeview_classinfo(void)
1139 memset(&cls, 0, sizeof(cls));
1140 GetClassInfo(GetModuleHandleA("comctl32.dll"), WC_TREEVIEWA, &cls);
1141 ok(cls.hbrBackground == NULL, "Expected NULL background brush, got %p\n", cls.hbrBackground);
1142 ok(cls.style == (CS_GLOBALCLASS | CS_DBLCLKS), "Expected got %x\n", cls.style);
1143 expect(0, cls.cbClsExtra);
1146 static void test_get_linecolor(void)
1151 hTree = create_treeview_control();
1153 /* newly created control has default color */
1154 clr = (COLORREF)SendMessage(hTree, TVM_GETLINECOLOR, 0, 0);
1156 win_skip("TVM_GETLINECOLOR is not supported on comctl32 < 5.80\n");
1158 expect(CLR_DEFAULT, clr);
1160 DestroyWindow(hTree);
1163 static void test_get_insertmarkcolor(void)
1168 hTree = create_treeview_control();
1170 /* newly created control has default color */
1171 clr = (COLORREF)SendMessage(hTree, TVM_GETINSERTMARKCOLOR, 0, 0);
1173 win_skip("TVM_GETINSERTMARKCOLOR is not supported on comctl32 < 5.80\n");
1175 expect(CLR_DEFAULT, clr);
1177 DestroyWindow(hTree);
1180 static void test_expandnotify(void)
1186 hTree = create_treeview_control();
1190 item.mask = TVIF_STATE;
1192 item.state = TVIS_EXPANDED;
1193 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1194 ok(ret == TRUE, "got %d\n", ret);
1195 ok((item.state & TVIS_EXPANDED) == 0, "expected collapsed\n");
1197 /* preselect root node here */
1198 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1199 ok(ret == TRUE, "got %d\n", ret);
1201 g_get_from_expand = TRUE;
1203 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1204 g_item_expanding.state = 0xdeadbeef;
1205 g_item_expanded.state = 0xdeadbeef;
1206 ret = SendMessageA(hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hRoot);
1207 ok(ret == TRUE, "got %d\n", ret);
1208 ok(g_item_expanding.state == TVIS_SELECTED, "got state on TVN_ITEMEXPANDING 0x%08x\n",
1209 g_item_expanding.state);
1210 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDED), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1211 g_item_expanded.state);
1212 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_seq, "expand notifications", FALSE);
1213 g_get_from_expand = FALSE;
1215 /* check that it's expanded */
1216 item.state = TVIS_EXPANDED;
1217 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1218 ok(ret == TRUE, "got %d\n", ret);
1219 ok((item.state & TVIS_EXPANDED) == TVIS_EXPANDED, "expected expanded\n");
1222 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1223 ret = SendMessageA(hTree, TVM_EXPAND, TVE_COLLAPSE, (LPARAM)hRoot);
1224 ok(ret == TRUE, "got %d\n", ret);
1225 item.state = TVIS_EXPANDED;
1226 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1227 ok(ret == TRUE, "got %d\n", ret);
1228 ok((item.state & TVIS_EXPANDED) == 0, "expected collapsed\n");
1229 /* all next collapse/expand attempts won't produce any notifications,
1230 the only way is to reset with all children removed */
1231 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "collapse after expand notifications", FALSE);
1233 DestroyWindow(hTree);
1235 /* test TVM_GETITEMRECT inside TVN_ITEMEXPANDED notification */
1236 hTree = create_treeview_control();
1238 g_get_rect_in_expand = TRUE;
1239 ret = TreeView_Select(hTree, hChild, TVGN_CARET);
1240 g_get_rect_in_expand = FALSE;
1241 ok(ret, "got %d\n", ret);
1242 DestroyWindow(hTree);
1245 static void test_expandedimage(void)
1251 hTree = create_treeview_control();
1254 item.mask = TVIF_EXPANDEDIMAGE;
1255 item.iExpandedImage = 1;
1257 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1258 ok(ret, "got %d\n", ret);
1260 item.mask = TVIF_EXPANDEDIMAGE;
1261 item.iExpandedImage = -1;
1263 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1264 ok(ret, "got %d\n", ret);
1266 if (item.iExpandedImage != 1)
1268 win_skip("TVIF_EXPANDEDIMAGE not supported\n");
1269 DestroyWindow(hTree);
1273 /* test for default iExpandedImage value */
1274 item.mask = TVIF_EXPANDEDIMAGE;
1275 item.iExpandedImage = -1;
1276 item.hItem = hChild;
1277 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1278 ok(ret, "got %d\n", ret);
1279 ok(item.iExpandedImage == (WORD)I_IMAGENONE, "got %d\n", item.iExpandedImage);
1281 DestroyWindow(hTree);
1284 static void test_TVS_SINGLEEXPAND(void)
1289 hTree = create_treeview_control();
1290 SetWindowLongA(hTree, GWL_STYLE, GetWindowLong(hTree, GWL_STYLE) | TVS_SINGLEEXPAND);
1291 /* to avoid paiting related notifications */
1292 ShowWindow(hTree, SW_HIDE);
1295 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1296 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1297 ok(ret, "got %d\n", ret);
1298 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_singleexpand_seq, "singleexpand notifications", FALSE);
1300 /* a workaround for NT4 that sends expanding notification when nothing is about to expand */
1301 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hRoot);
1302 ok(ret, "got %d\n", ret);
1304 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
1305 ok(ret, "got %d\n", ret);
1307 DestroyWindow(hTree);
1310 static void test_WM_PAINT(void)
1318 hTree = create_treeview_control();
1320 clr = SendMessageA(hTree, TVM_SETBKCOLOR, 0, RGB(255, 0, 0));
1321 ok(clr == -1, "got %d, expected -1\n", clr);
1323 hdc = GetDC(hMainWnd);
1325 GetClientRect(hMainWnd, &rc);
1326 FillRect(hdc, &rc, GetStockObject(BLACK_BRUSH));
1328 clr = GetPixel(hdc, 1, 1);
1329 ok(clr == RGB(0, 0, 0), "got 0x%x\n", clr);
1331 ret = SendMessageA(hTree, WM_PAINT, (WPARAM)hdc, 0);
1332 ok(ret == 0, "got %d\n", ret);
1334 clr = GetPixel(hdc, 1, 1);
1335 ok(clr == RGB(255, 0, 0) || broken(clr == RGB(0, 0, 0)) /* win98 */,
1338 ReleaseDC(hMainWnd, hdc);
1340 DestroyWindow(hTree);
1343 static void test_delete_items(void)
1345 const struct message *msg;
1349 hTree = create_treeview_control();
1352 /* check delete order */
1353 flush_sequences(item_sequence, 1);
1354 ret = SendMessage(hTree, TVM_DELETEITEM, 0, 0);
1355 ok(ret == TRUE, "got %d\n", ret);
1357 msg = item_sequence[0]->sequence;
1358 ok(item_sequence[0]->count == 2, "expected 2 items, got %d\n", item_sequence[0]->count);
1360 if (item_sequence[0]->count == 2)
1362 ok(msg[0].lParam == (LPARAM)hChild, "expected %p, got 0x%lx\n", hChild, msg[0].lParam);
1363 ok(msg[1].lParam == (LPARAM)hRoot, "expected %p, got 0x%lx\n", hRoot, msg[1].lParam);
1366 ret = SendMessageA(hTree, TVM_GETCOUNT, 0, 0);
1367 ok(ret == 0, "got %d\n", ret);
1369 DestroyWindow(hTree);
1372 START_TEST(treeview)
1375 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1379 ULONG_PTR ctx_cookie;
1383 hComctl32 = GetModuleHandleA("comctl32.dll");
1384 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1385 if (pInitCommonControlsEx)
1387 INITCOMMONCONTROLSEX iccex;
1388 iccex.dwSize = sizeof(iccex);
1389 iccex.dwICC = ICC_TREEVIEW_CLASSES;
1390 pInitCommonControlsEx(&iccex);
1393 InitCommonControls();
1395 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1396 init_msg_sequences(item_sequence, 1);
1398 wc.style = CS_HREDRAW | CS_VREDRAW;
1401 wc.hInstance = GetModuleHandleA(NULL);
1403 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
1404 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1405 wc.lpszMenuName = NULL;
1406 wc.lpszClassName = "MyTestWnd";
1407 wc.lpfnWndProc = parent_wnd_proc;
1408 RegisterClassA(&wc);
1410 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
1411 CW_USEDEFAULT, CW_USEDEFAULT, 130, 105, NULL, NULL, GetModuleHandleA(NULL), 0);
1413 ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n");
1414 if (!hMainWnd) return;
1420 test_get_set_bkcolor();
1421 test_get_set_imagelist();
1422 test_get_set_indent();
1423 test_get_set_insertmark();
1424 test_get_set_item();
1425 test_get_set_itemheight();
1426 test_get_set_scrolltime();
1427 test_get_set_textcolor();
1428 test_get_linecolor();
1429 test_get_insertmarkcolor();
1430 test_get_set_tooltips();
1431 test_get_set_unicodeformat();
1433 test_expandinvisible();
1435 test_treeview_classinfo();
1436 test_expandnotify();
1437 test_TVS_SINGLEEXPAND();
1439 test_delete_items();
1441 if (!load_v6_module(&ctx_cookie, &hCtx))
1443 DestroyWindow(hMainWnd);
1447 /* this is a XP SP3 failure workaround */
1448 hwnd = CreateWindowExA(0, WC_TREEVIEW, "foo",
1449 WS_CHILD | WS_BORDER | WS_VISIBLE,
1451 hMainWnd, NULL, GetModuleHandleA(NULL), NULL);
1452 if (!IsWindow(hwnd))
1454 win_skip("FIXME: failed to create TreeView window.\n");
1455 unload_v6_module(ctx_cookie, hCtx);
1456 DestroyWindow(hMainWnd);
1460 DestroyWindow(hwnd);
1462 /* comctl32 version 6 tests start here */
1463 test_expandedimage();
1465 unload_v6_module(ctx_cookie, hCtx);
1467 PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
1468 while(GetMessageA(&msg, 0, 0, 0))
1470 TranslateMessage(&msg);
1471 DispatchMessageA(&msg);