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 static TVITEMA g_item_expanding, g_item_expanded;
39 static BOOL g_get_from_expand;
40 static BOOL g_get_rect_in_expand;
41 static BOOL g_disp_A_to_W;
42 static BOOL g_disp_set_stateimage;
43 static BOOL g_beginedit_alter_text;
45 #define NUM_MSG_SEQUENCES 2
46 #define TREEVIEW_SEQ_INDEX 0
47 #define PARENT_SEQ_INDEX 1
49 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
51 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
52 static struct msg_sequence *item_sequence[1];
54 static const struct message FillRootSeq[] = {
55 { TVM_INSERTITEM, sent },
56 { TVM_INSERTITEM, sent },
60 static const struct message rootnone_select_seq[] = {
61 { TVM_SELECTITEM, sent|wparam, 9 },
62 { TVM_SELECTITEM, sent|wparam, 9 },
63 { TVM_SELECTITEM, sent|wparam, 9 },
64 { TVM_SELECTITEM, sent|wparam, 9 },
65 { TVM_SELECTITEM, sent|wparam, 9 },
66 { TVM_SELECTITEM, sent|wparam, 9 },
70 static const struct message rootchild_select_seq[] = {
71 { TVM_SELECTITEM, sent|wparam, 9 },
72 { TVM_SELECTITEM, sent|wparam, 9 },
73 { TVM_SELECTITEM, sent|wparam, 9 },
74 { TVM_SELECTITEM, sent|wparam, 9 },
75 { TVM_SELECTITEM, sent|wparam, 9 },
76 { TVM_SELECTITEM, sent|wparam, 9 },
80 static const struct message getitemtext_seq[] = {
81 { TVM_INSERTITEMA, sent },
82 { TVM_GETITEMA, sent },
83 { TVM_DELETEITEM, sent },
87 static const struct message focus_seq[] = {
88 { TVM_INSERTITEM, sent },
89 { TVM_INSERTITEM, sent },
90 { TVM_SELECTITEM, sent|wparam, 9 },
91 /* The following end up out of order in wine */
92 { WM_WINDOWPOSCHANGING, sent|defwinproc },
93 { WM_NCCALCSIZE, sent|wparam|defwinproc, TRUE },
94 { WM_WINDOWPOSCHANGED, sent|defwinproc },
95 { WM_SIZE, sent|defwinproc },
96 { WM_WINDOWPOSCHANGING, sent|defwinproc|optional },
97 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, TRUE },
98 { WM_WINDOWPOSCHANGED, sent|defwinproc|optional },
99 { WM_SIZE, sent|defwinproc|optional },
100 { WM_PAINT, sent|defwinproc },
101 { WM_NCPAINT, sent|wparam|defwinproc, 1 },
102 { WM_ERASEBKGND, sent|defwinproc },
103 { TVM_EDITLABELA, sent },
104 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_UPDATE) },
105 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_CHANGE) },
106 { WM_PARENTNOTIFY, sent|wparam|defwinproc, MAKEWPARAM(WM_CREATE, 0) },
107 { WM_KILLFOCUS, sent|defwinproc },
108 { WM_PAINT, sent|defwinproc },
109 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
110 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_SETFOCUS) },
111 { WM_ERASEBKGND, sent|defwinproc|optional },
112 { WM_CTLCOLOREDIT, sent|defwinproc|optional },
113 { WM_CTLCOLOREDIT, sent|defwinproc|optional },
117 static const struct message test_get_set_bkcolor_seq[] = {
118 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
119 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, 0 },
120 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
121 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, 0x00ffffff },
122 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
123 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, -1 },
127 static const struct message test_get_set_imagelist_seq[] = {
128 { TVM_SETIMAGELIST, sent|wparam|lparam, 0, 0 },
129 { TVM_GETIMAGELIST, sent|wparam|lparam, 0, 0 },
133 static const struct message test_get_set_indent_seq[] = {
134 { TVM_SETINDENT, sent|wparam|lparam, 0, 0 },
135 { TVM_GETINDENT, sent|wparam|lparam, 0, 0 },
136 /* The actual amount to indent is dependent on the system for this message */
137 { TVM_SETINDENT, sent },
138 { TVM_GETINDENT, sent|wparam|lparam, 0, 0 },
142 static const struct message test_get_set_insertmarkcolor_seq[] = {
143 { TVM_SETINSERTMARKCOLOR, sent|wparam|lparam, 0, 0 },
144 { TVM_GETINSERTMARKCOLOR, sent|wparam|lparam, 0, 0 },
148 static const struct message test_get_set_item_seq[] = {
149 { TVM_GETITEMA, sent },
150 { TVM_SETITEMA, sent },
151 { TVM_GETITEMA, sent },
152 { TVM_SETITEMA, sent },
156 static const struct message test_get_set_itemheight_seq[] = {
157 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
158 { TVM_SETITEMHEIGHT, sent|wparam|lparam, -1, 0 },
159 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
160 { TVM_SETITEMHEIGHT, sent|lparam, 0xcccccccc, 0 },
161 { TVM_GETITEMHEIGHT, sent|wparam|lparam|optional, 0, 0 },
162 { TVM_SETITEMHEIGHT, sent|wparam|lparam|optional, 9, 0 },
163 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
167 static const struct message test_get_set_scrolltime_seq[] = {
168 { TVM_SETSCROLLTIME, sent|wparam|lparam, 20, 0 },
169 { TVM_GETSCROLLTIME, sent|wparam|lparam, 0, 0 },
173 static const struct message test_get_set_textcolor_seq[] = {
174 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
175 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
176 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
177 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, RGB(255, 255, 255) },
178 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
179 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, CLR_NONE },
183 static const struct message test_get_set_tooltips_seq[] = {
184 { WM_KILLFOCUS, sent },
185 { WM_IME_SETCONTEXT, sent|optional },
186 { WM_IME_NOTIFY, sent|optional },
187 { TVM_SETTOOLTIPS, sent|wparam|lparam, 0, 0 },
188 { TVM_GETTOOLTIPS, sent|wparam|lparam, 0, 0 },
192 static const struct message test_get_set_unicodeformat_seq[] = {
193 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, TRUE, 0 },
194 { TVM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
195 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
196 { TVM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
197 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
201 static const struct message parent_expand_seq[] = {
202 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
203 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
207 static const struct message parent_expand_kb_seq[] = {
208 { WM_NOTIFY, sent|id|optional, 0, 0, TVN_KEYDOWN },
209 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
210 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
211 { WM_CHANGEUISTATE, sent|optional },
215 static const struct message parent_collapse_2nd_kb_seq[] = {
216 { WM_NOTIFY, sent|id|optional, 0, 0, TVN_KEYDOWN },
217 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
218 { WM_CHANGEUISTATE, sent|optional },
222 static const struct message parent_expand_empty_kb_seq[] = {
223 { WM_NOTIFY, sent|id|optional, 0, 0, TVN_KEYDOWN },
224 { WM_CHANGEUISTATE, sent|optional },
228 static const struct message parent_singleexpand_seq[] = {
229 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGINGA },
230 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGEDA },
231 { WM_NOTIFY, sent|id, 0, 0, TVN_SINGLEEXPAND },
232 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
233 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
237 static const struct message parent_get_dispinfo_seq[] = {
238 { WM_NOTIFY, sent|id, 0, 0, TVN_GETDISPINFOA },
242 static const struct message empty_seq[] = {
246 static HWND hMainWnd;
248 static HTREEITEM hRoot, hChild;
251 static char sequence[256];
253 static void Clear(void)
259 static void AddItem(char ch)
261 sequence[pos++] = ch;
262 sequence[pos] = '\0';
265 static void IdentifyItem(HTREEITEM hItem)
267 if (hItem == hRoot) {
271 if (hItem == hChild) {
282 /* This function hooks in and records all messages to the treeview control */
283 static LRESULT WINAPI TreeviewWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
285 static LONG defwndproc_counter = 0;
288 WNDPROC lpOldProc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
290 msg.message = message;
291 msg.flags = sent|wparam|lparam;
292 if (defwndproc_counter) msg.flags |= defwinproc;
296 add_message(sequences, TREEVIEW_SEQ_INDEX, &msg);
298 defwndproc_counter++;
299 ret = CallWindowProcA(lpOldProc, hwnd, message, wParam, lParam);
300 defwndproc_counter--;
305 static HWND create_treeview_control(DWORD style)
310 hTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL, WS_CHILD|WS_VISIBLE|
311 TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS|TVS_EDITLABELS|style,
312 0, 0, 120, 100, hMainWnd, (HMENU)100, GetModuleHandleA(0), 0);
316 /* Record the old WNDPROC so we can call it after recording the messages */
317 pOldWndProc = (WNDPROC)SetWindowLongPtrA(hTree, GWLP_WNDPROC, (LONG_PTR)TreeviewWndProc);
318 SetWindowLongPtrA(hTree, GWLP_USERDATA, (LONG_PTR)pOldWndProc);
323 static void fill_tree(HWND hTree)
326 static CHAR root[] = "Root",
329 ins.hParent = TVI_ROOT;
330 ins.hInsertAfter = TVI_ROOT;
331 U(ins).item.mask = TVIF_TEXT;
332 U(ins).item.pszText = root;
333 hRoot = TreeView_InsertItem(hTree, &ins);
336 ins.hInsertAfter = TVI_FIRST;
337 U(ins).item.mask = TVIF_TEXT;
338 U(ins).item.pszText = child;
339 hChild = TreeView_InsertItem(hTree, &ins);
342 static void test_fillroot(void)
347 hTree = create_treeview_control(0);
349 flush_sequences(sequences, NUM_MSG_SEQUENCES);
359 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, FillRootSeq, "FillRoot", FALSE);
360 ok(!strcmp(sequence, "AB."), "Item creation\n");
362 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
364 tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
365 SendMessage( hTree, TVM_GETITEMA, 0, (LPARAM)&tvi );
366 ok(tvi.iImage == 0, "tvi.iImage=%d\n", tvi.iImage);
367 ok(tvi.iSelectedImage == 0, "tvi.iSelectedImage=%d\n", tvi.iSelectedImage);
369 DestroyWindow(hTree);
372 static void test_callback(void)
375 HTREEITEM hItem1, hItem2;
378 CHAR test_string[] = "Test_string";
379 static const CHAR test2A[] = "TEST2";
384 hTree = create_treeview_control(0);
386 ret = TreeView_DeleteAllItems(hTree);
388 ins.hParent = TVI_ROOT;
389 ins.hInsertAfter = TVI_ROOT;
390 U(ins).item.mask = TVIF_TEXT;
391 U(ins).item.pszText = LPSTR_TEXTCALLBACK;
392 hRoot = TreeView_InsertItem(hTree, &ins);
396 tvi.mask = TVIF_TEXT;
398 tvi.cchTextMax = sizeof(buf)/sizeof(buf[0]);
399 ret = TreeView_GetItem(hTree, &tvi);
401 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Callback item text mismatch %s vs %s\n",
402 tvi.pszText, TEST_CALLBACK_TEXT);
405 ins.hInsertAfter = TVI_FIRST;
406 U(ins).item.mask = TVIF_TEXT;
407 U(ins).item.pszText = test_string;
408 hItem1 = TreeView_InsertItem(hTree, &ins);
412 ret = TreeView_GetItem(hTree, &tvi);
414 ok(strcmp(tvi.pszText, test_string) == 0, "Item text mismatch %s vs %s\n",
415 tvi.pszText, test_string);
417 /* undocumented: pszText of NULL also means LPSTR_CALLBACK: */
419 ret = TreeView_SetItem(hTree, &tvi);
422 ret = TreeView_GetItem(hTree, &tvi);
424 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Item text mismatch %s vs %s\n",
425 tvi.pszText, TEST_CALLBACK_TEXT);
427 U(ins).item.pszText = NULL;
428 hItem2 = TreeView_InsertItem(hTree, &ins);
431 memset(buf, 0, sizeof(buf));
432 ret = TreeView_GetItem(hTree, &tvi);
434 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Item text mismatch %s vs %s\n",
435 tvi.pszText, TEST_CALLBACK_TEXT);
437 /* notification handler changed A->W */
438 g_disp_A_to_W = TRUE;
440 memset(buf, 0, sizeof(buf));
441 ret = TreeView_GetItem(hTree, &tvi);
443 ok(strcmp(tvi.pszText, test2A) == 0, "got %s, expected %s\n",
444 tvi.pszText, test2A);
445 g_disp_A_to_W = FALSE;
447 /* handler changes state image index */
448 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
450 /* clear selection, handler will set selected state */
451 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
454 flush_sequences(sequences, NUM_MSG_SEQUENCES);
457 tvi.mask = TVIF_STATE;
458 tvi.state = TVIS_SELECTED;
459 ret = TreeView_GetItem(hTree, &tvi);
461 ok(tvi.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", tvi.state);
463 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
464 "no TVN_GETDISPINFO for a state seq", FALSE);
467 tvi.mask = TVIF_IMAGE | TVIF_STATE;
468 tvi.state = TVIS_FOCUSED;
469 tvi.stateMask = TVIS_FOCUSED;
470 tvi.iImage = I_IMAGECALLBACK;
471 ret = TreeView_SetItem(hTree, &tvi);
474 /* ask for item image index through callback - state is also set with state image index */
475 flush_sequences(sequences, NUM_MSG_SEQUENCES);
478 tvi.mask = TVIF_IMAGE;
480 ret = TreeView_GetItem(hTree, &tvi);
482 ok(tvi.state == (INDEXTOSTATEIMAGEMASK(1) | TVIS_FOCUSED), "got 0x%x\n", tvi.state);
484 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_get_dispinfo_seq,
485 "callback for state/overlay image index, noop seq", FALSE);
487 /* ask for image again and overwrite state to some value in handler */
488 flush_sequences(sequences, NUM_MSG_SEQUENCES);
490 g_disp_set_stateimage = TRUE;
492 tvi.mask = TVIF_IMAGE;
493 tvi.state = INDEXTOSTATEIMAGEMASK(1);
495 ret = TreeView_GetItem(hTree, &tvi);
497 /* handler sets TVIS_SELECTED as well */
498 ok(tvi.state == (TVIS_FOCUSED | TVIS_SELECTED | INDEXTOSTATEIMAGEMASK(2) | INDEXTOOVERLAYMASK(3)), "got 0x%x\n", tvi.state);
499 g_disp_set_stateimage = FALSE;
501 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_get_dispinfo_seq,
502 "callback for state/overlay image index seq", FALSE);
504 DestroyWindow(hTree);
507 static void test_select(void)
512 hTree = create_treeview_control(0);
515 /* root-none select tests */
516 flush_sequences(sequences, NUM_MSG_SEQUENCES);
517 r = TreeView_SelectItem(hTree, NULL);
521 r = TreeView_SelectItem(hTree, hRoot);
524 r = TreeView_SelectItem(hTree, hRoot);
527 r = TreeView_SelectItem(hTree, NULL);
530 r = TreeView_SelectItem(hTree, NULL);
533 r = TreeView_SelectItem(hTree, hRoot);
536 ok(!strcmp(sequence, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
537 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, rootnone_select_seq,
538 "root-none select seq", FALSE);
540 /* root-child select tests */
541 flush_sequences(sequences, NUM_MSG_SEQUENCES);
542 r = TreeView_SelectItem(hTree, NULL);
547 r = TreeView_SelectItem(hTree, hRoot);
550 r = TreeView_SelectItem(hTree, hRoot);
553 r = TreeView_SelectItem(hTree, hChild);
556 r = TreeView_SelectItem(hTree, hChild);
559 r = TreeView_SelectItem(hTree, hRoot);
562 ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
563 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, rootchild_select_seq,
564 "root-child select seq", FALSE);
566 DestroyWindow(hTree);
569 static void test_getitemtext(void)
576 CHAR szBuffer[80] = "Blah";
577 int nBufferSize = sizeof(szBuffer)/sizeof(CHAR);
579 hTree = create_treeview_control(0);
582 flush_sequences(sequences, NUM_MSG_SEQUENCES);
584 /* add an item without TVIF_TEXT mask and pszText == NULL */
586 ins.hInsertAfter = TVI_ROOT;
587 U(ins).item.mask = 0;
588 U(ins).item.pszText = NULL;
589 U(ins).item.cchTextMax = 0;
590 hChild = TreeView_InsertItem(hTree, &ins);
593 /* retrieve it with TVIF_TEXT mask */
595 tvi.mask = TVIF_TEXT;
596 tvi.cchTextMax = nBufferSize;
597 tvi.pszText = szBuffer;
599 SendMessageA( hTree, TVM_GETITEMA, 0, (LPARAM)&tvi );
600 ok(!strcmp(szBuffer, ""), "szBuffer=\"%s\", expected \"\"\n", szBuffer);
601 ok(SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild), "DeleteItem failed\n");
602 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, getitemtext_seq, "get item text seq", FALSE);
604 DestroyWindow(hTree);
607 static void test_focus(void)
610 static CHAR child1[] = "Edit",
611 child2[] = "A really long string";
612 HTREEITEM hChild1, hChild2;
616 hTree = create_treeview_control(0);
619 flush_sequences(sequences, NUM_MSG_SEQUENCES);
621 /* This test verifies that when a label is being edited, scrolling
622 * the treeview does not cause the label to lose focus. To test
623 * this, first some additional entries are added to generate
627 ins.hInsertAfter = hChild;
628 U(ins).item.mask = TVIF_TEXT;
629 U(ins).item.pszText = child1;
630 hChild1 = TreeView_InsertItem(hTree, &ins);
632 ins.hInsertAfter = hChild1;
633 U(ins).item.mask = TVIF_TEXT;
634 U(ins).item.pszText = child2;
635 hChild2 = TreeView_InsertItem(hTree, &ins);
638 ShowWindow(hMainWnd,SW_SHOW);
639 SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
640 hEdit = TreeView_EditLabel(hTree, hChild);
641 ScrollWindowEx(hTree, -10, 0, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN);
642 ok(GetFocus() == hEdit, "Edit control should have focus\n");
643 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, focus_seq, "focus test", TRUE);
645 DestroyWindow(hTree);
648 static void test_get_set_bkcolor(void)
650 COLORREF crColor = RGB(0,0,0);
653 hTree = create_treeview_control(0);
656 flush_sequences(sequences, NUM_MSG_SEQUENCES);
658 /* If the value is -1, the control is using the system color for the background color. */
659 crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
660 ok(crColor == ~0u, "Default background color reported as 0x%.8x\n", crColor);
662 /* Test for black background */
663 SendMessage( hTree, TVM_SETBKCOLOR, 0, RGB(0,0,0) );
664 crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
665 ok(crColor == RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor);
667 /* Test for white background */
668 SendMessage( hTree, TVM_SETBKCOLOR, 0, RGB(255,255,255) );
669 crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
670 ok(crColor == RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor);
672 /* Reset the default background */
673 SendMessage( hTree, TVM_SETBKCOLOR, 0, -1 );
675 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_bkcolor_seq,
676 "test get set bkcolor", FALSE);
678 DestroyWindow(hTree);
681 static void test_get_set_imagelist(void)
686 hTree = create_treeview_control(0);
689 flush_sequences(sequences, NUM_MSG_SEQUENCES);
691 /* Test a NULL HIMAGELIST */
692 SendMessage( hTree, TVM_SETIMAGELIST, TVSIL_NORMAL, 0 );
693 himl = (HIMAGELIST)SendMessage( hTree, TVM_GETIMAGELIST, TVSIL_NORMAL, 0 );
694 ok(himl == NULL, "NULL image list, reported as %p, expected 0.\n", himl);
696 /* TODO: Test an actual image list */
698 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_imagelist_seq,
699 "test get imagelist", FALSE);
701 DestroyWindow(hTree);
704 static void test_get_set_indent(void)
707 int ulMinIndent = -1;
708 int ulMoreThanTwiceMin = -1;
711 hTree = create_treeview_control(0);
714 flush_sequences(sequences, NUM_MSG_SEQUENCES);
716 /* Finding the minimum indent */
717 SendMessage( hTree, TVM_SETINDENT, 0, 0 );
718 ulMinIndent = (int)SendMessage( hTree, TVM_GETINDENT, 0, 0 );
720 /* Checking an indent that is more than twice the default indent */
721 ulMoreThanTwiceMin = 2*ulMinIndent+1;
722 SendMessage( hTree, TVM_SETINDENT, ulMoreThanTwiceMin, 0 );
723 ulIndent = (DWORD)SendMessage( hTree, TVM_GETINDENT, 0, 0 );
724 ok(ulIndent == ulMoreThanTwiceMin, "Indent reported as %d, expected %d\n", ulIndent, ulMoreThanTwiceMin);
726 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_indent_seq,
727 "test get set indent", FALSE);
729 DestroyWindow(hTree);
732 static void test_get_set_insertmark(void)
734 COLORREF crColor = RGB(0,0,0);
737 hTree = create_treeview_control(0);
740 flush_sequences(sequences, NUM_MSG_SEQUENCES);
742 SendMessage( hTree, TVM_SETINSERTMARKCOLOR, 0, crColor );
743 crColor = (COLORREF)SendMessage( hTree, TVM_GETINSERTMARKCOLOR, 0, 0 );
744 ok(crColor == RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor);
746 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_insertmarkcolor_seq,
747 "test get set insertmark color", FALSE);
749 DestroyWindow(hTree);
752 static void test_get_set_item(void)
754 TVITEMA tviRoot = {0};
755 int nBufferSize = 80;
756 char szBuffer[80] = {0};
760 hTree = create_treeview_control(0);
763 tviRoot.hItem = hRoot;
764 tviRoot.mask = TVIF_STATE;
765 tviRoot.state = TVIS_FOCUSED;
766 tviRoot.stateMask = TVIS_FOCUSED;
767 ret = SendMessage( hTree, TVM_SETITEMA, 0, (LPARAM)&tviRoot );
770 flush_sequences(sequences, NUM_MSG_SEQUENCES);
772 /* Test the root item, state is set even when not requested */
773 tviRoot.hItem = hRoot;
774 tviRoot.mask = TVIF_TEXT;
776 tviRoot.stateMask = 0;
777 tviRoot.cchTextMax = nBufferSize;
778 tviRoot.pszText = szBuffer;
779 ret = SendMessage( hTree, TVM_GETITEMA, 0, (LPARAM)&tviRoot );
781 ok(!strcmp("Root", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer);
782 ok(tviRoot.state == TVIS_FOCUSED, "got 0x%0x\n", tviRoot.state);
784 /* Change the root text */
785 strncpy(szBuffer, "Testing123", nBufferSize);
786 ret = SendMessage( hTree, TVM_SETITEMA, 0, (LPARAM)&tviRoot );
788 memset(szBuffer, 0, nBufferSize);
789 ret = SendMessage( hTree, TVM_GETITEMA, 0, (LPARAM)&tviRoot );
791 ok(!strcmp("Testing123", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer);
793 /* Reset the root text */
794 memset(szBuffer, 0, nBufferSize);
795 strncpy(szBuffer, "Root", nBufferSize);
796 ret = SendMessage( hTree, TVM_SETITEMA, 0, (LPARAM)&tviRoot );
799 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_item_seq,
800 "test get set item", FALSE);
802 /* get item from a different tree */
803 hTree2 = create_treeview_control(0);
805 tviRoot.hItem = hRoot;
806 tviRoot.mask = TVIF_STATE;
808 ret = SendMessage( hTree2, TVM_GETITEMA, 0, (LPARAM)&tviRoot );
810 ok(tviRoot.state == TVIS_FOCUSED, "got state 0x%0x\n", tviRoot.state);
812 DestroyWindow(hTree);
813 DestroyWindow(hTree2);
816 static void test_get_set_itemheight(void)
822 hTree = create_treeview_control(0);
825 flush_sequences(sequences, NUM_MSG_SEQUENCES);
827 /* Assuming default height to begin with */
828 ulOldHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
830 /* Explicitly setting and getting the default height */
831 SendMessage( hTree, TVM_SETITEMHEIGHT, -1, 0 );
832 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
833 ok(ulNewHeight == ulOldHeight, "Default height not set properly, reported %d, expected %d\n", ulNewHeight, ulOldHeight);
835 /* Explicitly setting and getting the height of twice the normal */
836 SendMessage( hTree, TVM_SETITEMHEIGHT, 2*ulOldHeight, 0 );
837 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
838 ok(ulNewHeight == 2*ulOldHeight, "New height not set properly, reported %d, expected %d\n", ulNewHeight, 2*ulOldHeight);
840 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
841 SendMessage( hTree, TVM_SETITEMHEIGHT, 9, 0 );
842 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
843 ok(ulNewHeight == 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight, 8);
845 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_itemheight_seq,
846 "test get set item height", FALSE);
848 /* without TVS_NONEVENHEIGHT */
849 SetWindowLong(hTree, GWL_STYLE, GetWindowLong(hTree, GWL_STYLE) & ~TVS_NONEVENHEIGHT);
851 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 3, 0);
852 ok(ulOldHeight == 8, "got %d, expected %d\n", ulOldHeight, 8);
853 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
854 ok(ulNewHeight == 2, "got %d, expected %d\n", ulNewHeight, 2);
856 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 4, 0);
857 ok(ulOldHeight == 2, "got %d, expected %d\n", ulOldHeight, 2);
858 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
859 ok(ulNewHeight == 4, "got %d, expected %d\n", ulNewHeight, 4);
861 /* with TVS_NONEVENHEIGHT */
862 SetWindowLong(hTree, GWL_STYLE, GetWindowLong(hTree, GWL_STYLE) | TVS_NONEVENHEIGHT);
864 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 3, 0);
865 ok(ulOldHeight == 4, "got %d, expected %d\n", ulOldHeight, 4);
866 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
867 ok(ulNewHeight == 3, "got %d, expected %d\n", ulNewHeight, 3);
869 ulOldHeight = SendMessage( hTree, TVM_SETITEMHEIGHT, 10, 0);
870 ok(ulOldHeight == 3, "got %d, expected %d\n", ulOldHeight, 3);
871 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
872 ok(ulNewHeight == 10, "got %d, expected %d\n", ulNewHeight, 10);
874 DestroyWindow(hTree);
877 static void test_get_set_scrolltime(void)
879 int ulExpectedTime = 20;
883 hTree = create_treeview_control(0);
886 flush_sequences(sequences, NUM_MSG_SEQUENCES);
888 SendMessage( hTree, TVM_SETSCROLLTIME, ulExpectedTime, 0 );
889 ulTime = (int)SendMessage( hTree, TVM_GETSCROLLTIME, 0, 0 );
890 ok(ulTime == ulExpectedTime, "Scroll time reported as %d, expected %d\n", ulTime, ulExpectedTime);
892 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_scrolltime_seq,
893 "test get set scroll time", FALSE);
895 DestroyWindow(hTree);
898 static void test_get_set_textcolor(void)
900 /* If the value is -1, the control is using the system color for the text color. */
901 COLORREF crColor = RGB(0,0,0);
904 hTree = create_treeview_control(0);
907 flush_sequences(sequences, NUM_MSG_SEQUENCES);
909 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
910 ok(crColor == ~0u, "Default text color reported as 0x%.8x\n", crColor);
912 /* Test for black text */
913 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, RGB(0,0,0) );
914 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
915 ok(crColor == RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor);
917 /* Test for white text */
918 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, RGB(255,255,255) );
919 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
920 ok(crColor == RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor);
922 /* Reset the default text color */
923 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, CLR_NONE );
925 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_textcolor_seq,
926 "test get set text color", FALSE);
928 DestroyWindow(hTree);
931 static void test_get_set_tooltips(void)
933 HWND hwndLastToolTip = NULL;
937 hTree = create_treeview_control(0);
940 flush_sequences(sequences, NUM_MSG_SEQUENCES);
942 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
943 hPopupTreeView = CreateWindow(WC_TREEVIEW, NULL, WS_POPUP|WS_VISIBLE, 0, 0, 100, 100, hMainWnd, NULL, NULL, NULL);
944 DestroyWindow(hPopupTreeView);
946 /* Testing setting a NULL ToolTip */
947 SendMessage( hTree, TVM_SETTOOLTIPS, 0, 0 );
948 hwndLastToolTip = (HWND)SendMessage( hTree, TVM_GETTOOLTIPS, 0, 0 );
949 ok(hwndLastToolTip == NULL, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip);
951 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_tooltips_seq,
952 "test get set tooltips", TRUE);
954 /* TODO: Add a test of an actual tooltip */
955 DestroyWindow(hTree);
958 static void test_get_set_unicodeformat(void)
960 BOOL bPreviousSetting = 0;
961 BOOL bNewSetting = 0;
964 hTree = create_treeview_control(0);
967 /* Check that an invalid format returned by NF_QUERY defaults to ANSI */
968 bPreviousSetting = (BOOL)SendMessage( hTree, TVM_GETUNICODEFORMAT, 0, 0 );
969 ok(bPreviousSetting == 0, "Format should be ANSI.\n");
971 flush_sequences(sequences, NUM_MSG_SEQUENCES);
974 bPreviousSetting = (BOOL)SendMessage( hTree, TVM_SETUNICODEFORMAT, 1, 0 );
975 bNewSetting = (BOOL)SendMessage( hTree, TVM_GETUNICODEFORMAT, 0, 0 );
976 ok(bNewSetting == 1, "Unicode setting did not work.\n");
979 SendMessage( hTree, TVM_SETUNICODEFORMAT, 0, 0 );
980 bNewSetting = (BOOL)SendMessage( hTree, TVM_GETUNICODEFORMAT, 0, 0 );
981 ok(bNewSetting == 0, "ANSI setting did not work.\n");
983 /* Revert to original setting */
984 SendMessage( hTree, TVM_SETUNICODEFORMAT, bPreviousSetting, 0 );
986 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_unicodeformat_seq,
987 "test get set unicode format", FALSE);
989 DestroyWindow(hTree);
992 static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
994 static LONG defwndproc_counter = 0;
998 HTREEITEM visibleItem;
1000 msg.message = message;
1001 msg.flags = sent|wparam|lparam;
1002 if (defwndproc_counter) msg.flags |= defwinproc;
1003 msg.wParam = wParam;
1004 msg.lParam = lParam;
1005 if (message == WM_NOTIFY && lParam)
1006 msg.id = ((NMHDR*)lParam)->code;
1010 /* log system messages, except for painting */
1011 if (message < WM_USER &&
1012 message != WM_PAINT &&
1013 message != WM_ERASEBKGND &&
1014 message != WM_NCPAINT &&
1015 message != WM_NCHITTEST &&
1016 message != WM_GETTEXT &&
1017 message != WM_GETICON &&
1018 message != WM_DEVICECHANGE)
1020 trace("parent: %p, %04x, %08lx, %08lx\n", hWnd, message, wParam, lParam);
1021 add_message(sequences, PARENT_SEQ_INDEX, &msg);
1025 case WM_NOTIFYFORMAT:
1027 /* Make NF_QUERY return an invalid format to show that it defaults to ANSI */
1028 if (lParam == NF_QUERY) return 0;
1034 NMHDR *pHdr = (NMHDR *)lParam;
1036 ok(pHdr->code != NM_TOOLTIPSCREATED, "Treeview should not send NM_TOOLTIPSCREATED\n");
1037 if (pHdr->idFrom == 100)
1039 NMTREEVIEWA *pTreeView = (LPNMTREEVIEWA) lParam;
1042 case TVN_SELCHANGINGA:
1044 IdentifyItem(pTreeView->itemOld.hItem);
1045 IdentifyItem(pTreeView->itemNew.hItem);
1047 case TVN_SELCHANGEDA:
1049 IdentifyItem(pTreeView->itemOld.hItem);
1050 IdentifyItem(pTreeView->itemNew.hItem);
1052 case TVN_GETDISPINFOA: {
1053 NMTVDISPINFOA *disp = (NMTVDISPINFOA *)lParam;
1054 if (disp->item.mask & TVIF_TEXT) {
1055 lstrcpyn(disp->item.pszText, TEST_CALLBACK_TEXT, disp->item.cchTextMax);
1058 if (g_disp_A_to_W && (disp->item.mask & TVIF_TEXT)) {
1059 static const WCHAR testW[] = {'T','E','S','T','2',0};
1061 disp->hdr.code = TVN_GETDISPINFOW;
1062 memcpy(disp->item.pszText, testW, sizeof(testW));
1065 if (g_disp_set_stateimage)
1067 ok(disp->item.mask == TVIF_IMAGE, "got %x\n", disp->item.mask);
1068 /* both masks set here are necessary to change state bits */
1069 disp->item.mask |= TVIF_STATE;
1070 disp->item.state = TVIS_SELECTED | INDEXTOSTATEIMAGEMASK(2) | INDEXTOOVERLAYMASK(3);
1071 disp->item.stateMask = TVIS_SELECTED | TVIS_OVERLAYMASK | TVIS_STATEIMAGEMASK;
1076 case TVN_BEGINLABELEDIT:
1078 if (g_beginedit_alter_text)
1080 static const char* textA = "<edittextaltered>";
1083 edit = (HWND)SendMessageA(pHdr->hwndFrom, TVM_GETEDITCONTROL, 0, 0);
1084 ok(IsWindow(edit), "failed to get edit handle\n");
1085 SetWindowTextA(edit, textA);
1091 case TVN_ENDLABELEDIT: return TRUE;
1092 case TVN_ITEMEXPANDINGA:
1093 ok(pTreeView->itemNew.mask ==
1094 (TVIF_HANDLE | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_PARAM | TVIF_STATE),
1095 "got wrong mask %x\n", pTreeView->itemNew.mask);
1096 ok(pTreeView->itemOld.mask == 0,
1097 "got wrong mask %x\n", pTreeView->itemOld.mask);
1099 if (g_get_from_expand)
1101 g_item_expanding.mask = TVIF_STATE;
1102 g_item_expanding.hItem = hRoot;
1103 ret = SendMessageA(pHdr->hwndFrom, TVM_GETITEMA, 0, (LPARAM)&g_item_expanding);
1104 ok(ret == TRUE, "got %lu\n", ret);
1107 case TVN_ITEMEXPANDEDA:
1108 ok(pTreeView->itemNew.mask & TVIF_STATE, "got wrong mask %x\n", pTreeView->itemNew.mask);
1109 ok(pTreeView->itemNew.state & (TVIS_EXPANDED|TVIS_EXPANDEDONCE),
1110 "got wrong mask %x\n", pTreeView->itemNew.mask);
1111 ok(pTreeView->itemOld.mask == 0,
1112 "got wrong mask %x\n", pTreeView->itemOld.mask);
1114 if (g_get_from_expand)
1116 g_item_expanded.mask = TVIF_STATE;
1117 g_item_expanded.hItem = hRoot;
1118 ret = SendMessageA(pHdr->hwndFrom, TVM_GETITEMA, 0, (LPARAM)&g_item_expanded);
1119 ok(ret == TRUE, "got %lu\n", ret);
1121 if (g_get_rect_in_expand)
1123 visibleItem = TreeView_GetNextItem(pHdr->hwndFrom, NULL, TVGN_FIRSTVISIBLE);
1124 ok(pTreeView->itemNew.hItem == visibleItem, "expanded item == first visible item\n");
1125 *(HTREEITEM*)&rect = visibleItem;
1126 ok(SendMessage(pHdr->hwndFrom, TVM_GETITEMRECT, TRUE, (LPARAM)&rect), "Failed to get rect for first visible item.\n");
1127 visibleItem = TreeView_GetNextItem(pHdr->hwndFrom, visibleItem, TVGN_NEXTVISIBLE);
1128 *(HTREEITEM*)&rect = visibleItem;
1129 ok(visibleItem != NULL, "There must be a visible item after the first visisble item.\n");
1130 ok(SendMessage(pHdr->hwndFrom, TVM_GETITEMRECT, TRUE, (LPARAM)&rect), "Failed to get rect for second visible item.\n");
1133 case TVN_DELETEITEMA:
1135 struct message item;
1137 ok(pTreeView->itemNew.mask == 0, "got wrong mask 0x%x\n", pTreeView->itemNew.mask);
1139 ok(pTreeView->itemOld.mask == (TVIF_HANDLE | TVIF_PARAM), "got wrong mask 0x%x\n", pTreeView->itemOld.mask);
1140 ok(pTreeView->itemOld.hItem != NULL, "got %p\n", pTreeView->itemOld.hItem);
1142 memset(&item, 0, sizeof(item));
1143 item.lParam = (LPARAM)pTreeView->itemOld.hItem;
1144 add_message(item_sequence, 0, &item);
1158 defwndproc_counter++;
1159 ret = DefWindowProcA(hWnd, message, wParam, lParam);
1160 defwndproc_counter--;
1165 static void test_expandinvisible(void)
1167 static CHAR nodeText[][5] = {"0", "1", "2", "3", "4"};
1168 TVINSERTSTRUCTA ins;
1175 hTree = create_treeview_control(0);
1177 /* The test builds the following tree and expands node 1, while node 0 is collapsed.
1187 ret = TreeView_DeleteAllItems(hTree);
1188 ok(ret == TRUE, "ret\n");
1189 ins.hParent = TVI_ROOT;
1190 ins.hInsertAfter = TVI_ROOT;
1191 U(ins).item.mask = TVIF_TEXT;
1192 U(ins).item.pszText = nodeText[0];
1193 node[0] = TreeView_InsertItem(hTree, &ins);
1196 ins.hInsertAfter = TVI_LAST;
1197 U(ins).item.mask = TVIF_TEXT;
1198 ins.hParent = node[0];
1200 U(ins).item.pszText = nodeText[1];
1201 node[1] = TreeView_InsertItem(hTree, &ins);
1203 U(ins).item.pszText = nodeText[4];
1204 node[4] = TreeView_InsertItem(hTree, &ins);
1207 ins.hParent = node[1];
1209 U(ins).item.pszText = nodeText[2];
1210 node[2] = TreeView_InsertItem(hTree, &ins);
1212 U(ins).item.pszText = nodeText[3];
1213 node[3] = TreeView_InsertItem(hTree, &ins);
1217 nodeVisible = TreeView_GetItemRect(hTree, node[1], &dummyRect, FALSE);
1218 ok(!nodeVisible, "Node 1 should not be visible.\n");
1219 nodeVisible = TreeView_GetItemRect(hTree, node[2], &dummyRect, FALSE);
1220 ok(!nodeVisible, "Node 2 should not be visible.\n");
1221 nodeVisible = TreeView_GetItemRect(hTree, node[3], &dummyRect, FALSE);
1222 ok(!nodeVisible, "Node 3 should not be visible.\n");
1223 nodeVisible = TreeView_GetItemRect(hTree, node[4], &dummyRect, FALSE);
1224 ok(!nodeVisible, "Node 4 should not be visible.\n");
1226 ok(TreeView_Expand(hTree, node[1], TVE_EXPAND), "Expand of node 1 failed.\n");
1228 nodeVisible = TreeView_GetItemRect(hTree, node[1], &dummyRect, FALSE);
1229 ok(!nodeVisible, "Node 1 should not be visible.\n");
1230 nodeVisible = TreeView_GetItemRect(hTree, node[2], &dummyRect, FALSE);
1231 ok(!nodeVisible, "Node 2 should not be visible.\n");
1232 nodeVisible = TreeView_GetItemRect(hTree, node[3], &dummyRect, FALSE);
1233 ok(!nodeVisible, "Node 3 should not be visible.\n");
1234 nodeVisible = TreeView_GetItemRect(hTree, node[4], &dummyRect, FALSE);
1235 ok(!nodeVisible, "Node 4 should not be visible.\n");
1237 DestroyWindow(hTree);
1240 static void test_itemedit(void)
1248 hTree = create_treeview_control(0);
1251 /* try with null item */
1252 edit = (HWND)SendMessage(hTree, TVM_EDITLABELA, 0, 0);
1253 ok(!IsWindow(edit), "Expected valid handle\n");
1256 edit = (HWND)SendMessage(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1257 ok(IsWindow(edit), "Expected valid handle\n");
1258 /* item shouldn't be selected automatically after TVM_EDITLABEL */
1259 r = SendMessage(hTree, TVM_GETITEMSTATE, (WPARAM)hRoot, TVIS_SELECTED);
1261 /* try to cancel with wrong edit handle */
1262 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), 0);
1264 ok(IsWindow(edit), "Expected edit control to be valid\n");
1265 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1267 ok(!IsWindow(edit), "Expected edit control to be destroyed\n");
1268 /* try to cancel without creating edit */
1269 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), 0);
1272 /* try to cancel with wrong (not null) handle */
1273 edit = (HWND)SendMessage(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1274 ok(IsWindow(edit), "Expected valid handle\n");
1275 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hTree);
1277 ok(IsWindow(edit), "Expected edit control to be valid\n");
1278 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1281 /* remove selection after starting edit */
1282 r = TreeView_SelectItem(hTree, hRoot);
1284 edit = (HWND)SendMessage(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1285 ok(IsWindow(edit), "Expected valid handle\n");
1286 r = TreeView_SelectItem(hTree, NULL);
1290 r = SendMessage(edit, WM_SETTEXT, 0, (LPARAM)buffA);
1292 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1294 ok(!IsWindow(edit), "Expected edit control to be destroyed\n");
1295 /* check that text is saved */
1296 item.mask = TVIF_TEXT;
1298 item.pszText = buffA;
1299 item.cchTextMax = sizeof(buffA)/sizeof(CHAR);
1300 r = SendMessage(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1302 ok(!strcmp("x", buffA), "Expected item text to change\n");
1304 /* try A/W messages */
1305 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1306 ok(IsWindow(edit), "Expected valid handle\n");
1307 ok(IsWindowUnicode(edit), "got ansi window\n");
1308 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1310 ok(!IsWindow(edit), "expected invalid handle\n");
1312 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELW, 0, (LPARAM)hRoot);
1313 ok(IsWindow(edit), "Expected valid handle\n");
1314 ok(IsWindowUnicode(edit), "got ansi window\n");
1315 r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1318 /* alter text during TVM_BEGINLABELEDIT, check that it's preserved */
1319 strcpy(buffA, "<root>");
1321 item.mask = TVIF_TEXT;
1323 item.pszText = buffA;
1324 item.cchTextMax = 0;
1325 r = SendMessage(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1328 g_beginedit_alter_text = TRUE;
1329 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1330 ok(IsWindow(edit), "Expected valid handle\n");
1331 g_beginedit_alter_text = FALSE;
1333 GetWindowTextA(edit, buffA, sizeof(buffA)/sizeof(CHAR));
1334 ok(!strcmp(buffA, "<edittextaltered>"), "got string %s\n", buffA);
1336 DestroyWindow(hTree);
1339 static void test_treeview_classinfo(void)
1343 memset(&cls, 0, sizeof(cls));
1344 GetClassInfo(GetModuleHandleA("comctl32.dll"), WC_TREEVIEWA, &cls);
1345 ok(cls.hbrBackground == NULL, "Expected NULL background brush, got %p\n", cls.hbrBackground);
1346 ok(cls.style == (CS_GLOBALCLASS | CS_DBLCLKS), "Expected got %x\n", cls.style);
1347 expect(0, cls.cbClsExtra);
1350 static void test_get_linecolor(void)
1355 hTree = create_treeview_control(0);
1357 /* newly created control has default color */
1358 clr = (COLORREF)SendMessage(hTree, TVM_GETLINECOLOR, 0, 0);
1360 win_skip("TVM_GETLINECOLOR is not supported on comctl32 < 5.80\n");
1362 expect(CLR_DEFAULT, clr);
1364 DestroyWindow(hTree);
1367 static void test_get_insertmarkcolor(void)
1372 hTree = create_treeview_control(0);
1374 /* newly created control has default color */
1375 clr = (COLORREF)SendMessage(hTree, TVM_GETINSERTMARKCOLOR, 0, 0);
1377 win_skip("TVM_GETINSERTMARKCOLOR is not supported on comctl32 < 5.80\n");
1379 expect(CLR_DEFAULT, clr);
1381 DestroyWindow(hTree);
1384 static void test_expandnotify(void)
1390 hTree = create_treeview_control(0);
1394 item.mask = TVIF_STATE;
1396 item.state = TVIS_EXPANDED;
1397 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1399 ok((item.state & TVIS_EXPANDED) == 0, "expected collapsed\n");
1401 /* preselect root node here */
1402 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1405 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1406 ret = SendMessageA(hTree, TVM_EXPAND, TVE_COLLAPSE, (LPARAM)hRoot);
1408 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "no collapse notifications", FALSE);
1410 g_get_from_expand = TRUE;
1412 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1413 g_item_expanding.state = 0xdeadbeef;
1414 g_item_expanded.state = 0xdeadbeef;
1415 ret = SendMessageA(hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hRoot);
1417 ok(g_item_expanding.state == TVIS_SELECTED, "got state on TVN_ITEMEXPANDING 0x%08x\n",
1418 g_item_expanding.state);
1419 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDED), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1420 g_item_expanded.state);
1421 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_seq, "expand notifications", FALSE);
1422 g_get_from_expand = FALSE;
1424 /* check that it's expanded */
1425 item.state = TVIS_EXPANDED;
1426 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1428 ok((item.state & TVIS_EXPANDED) == TVIS_EXPANDED, "expected expanded\n");
1431 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1432 ret = SendMessageA(hTree, TVM_EXPAND, TVE_COLLAPSE, (LPARAM)hRoot);
1434 item.state = TVIS_EXPANDED;
1435 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1437 ok((item.state & TVIS_EXPANDED) == 0, "expected collapsed\n");
1438 /* all further collapse/expand attempts won't produce any notifications,
1439 the only way is to reset with all children removed */
1440 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "collapse after expand notifications", FALSE);
1442 /* try to toggle child that doesn't have children itself */
1443 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1444 ret = SendMessageA(hTree, TVM_EXPAND, TVE_TOGGLE, (LPARAM)hChild);
1446 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "toggle node without children", FALSE);
1448 DestroyWindow(hTree);
1450 /* test TVM_GETITEMRECT inside TVN_ITEMEXPANDED notification */
1451 hTree = create_treeview_control(0);
1453 g_get_rect_in_expand = TRUE;
1454 ret = TreeView_Select(hTree, hChild, TVGN_CARET);
1456 g_get_rect_in_expand = FALSE;
1458 DestroyWindow(hTree);
1460 /* TVE_TOGGLE acts as any other TVM_EXPAND */
1461 hTree = create_treeview_control(0);
1464 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1465 ret = SendMessageA(hTree, TVM_EXPAND, TVE_TOGGLE, (LPARAM)hRoot);
1467 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_seq, "toggle node (expand)", FALSE);
1469 /* toggle again - no notifications */
1470 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1471 ret = SendMessageA(hTree, TVM_EXPAND, TVE_TOGGLE, (LPARAM)hRoot);
1473 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "toggle node (collapse)", FALSE);
1475 DestroyWindow(hTree);
1477 /* some keyboard events are also translated to expand */
1478 hTree = create_treeview_control(0);
1481 /* preselect root node here */
1482 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1485 g_get_from_expand = TRUE;
1486 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1487 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1489 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "expand node", FALSE);
1490 ok(g_item_expanding.state == TVIS_SELECTED, "got state on TVN_ITEMEXPANDING 0x%08x\n",
1491 g_item_expanding.state);
1492 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDED), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1493 g_item_expanded.state);
1495 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1496 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1498 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "expand node again", FALSE);
1499 ok(g_item_expanding.state == (TVIS_SELECTED|TVIS_EXPANDED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDING 0x%08x\n",
1500 g_item_expanding.state);
1501 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1502 g_item_expanded.state);
1504 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1505 ret = SendMessageA(hTree, WM_KEYDOWN, VK_SUBTRACT, 0);
1507 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "collapse node", FALSE);
1508 ok(g_item_expanding.state == (TVIS_SELECTED|TVIS_EXPANDED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDING 0x%08x\n",
1509 g_item_expanding.state);
1510 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1511 g_item_expanded.state);
1513 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1514 ret = SendMessageA(hTree, WM_KEYDOWN, VK_SUBTRACT, 0);
1516 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_collapse_2nd_kb_seq, "collapse node again", FALSE);
1517 ok(g_item_expanding.state == (TVIS_SELECTED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDING 0x%08x\n",
1518 g_item_expanding.state);
1519 g_get_from_expand = FALSE;
1521 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1522 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1524 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "expand node", FALSE);
1527 ret = SendMessageA(hTree, WM_KEYDOWN, VK_RIGHT, 0);
1530 /* try to expand child that doesn't have children itself */
1531 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1532 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1534 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_empty_kb_seq, "expand node with no children", FALSE);
1536 DestroyWindow(hTree);
1539 static void test_expandedimage(void)
1545 hTree = create_treeview_control(0);
1548 item.mask = TVIF_EXPANDEDIMAGE;
1549 item.iExpandedImage = 1;
1551 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1552 ok(ret, "got %d\n", ret);
1554 item.mask = TVIF_EXPANDEDIMAGE;
1555 item.iExpandedImage = -1;
1557 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1558 ok(ret, "got %d\n", ret);
1560 if (item.iExpandedImage != 1)
1562 win_skip("TVIF_EXPANDEDIMAGE not supported\n");
1563 DestroyWindow(hTree);
1567 /* test for default iExpandedImage value */
1568 item.mask = TVIF_EXPANDEDIMAGE;
1569 item.iExpandedImage = -1;
1570 item.hItem = hChild;
1571 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1572 ok(ret, "got %d\n", ret);
1573 ok(item.iExpandedImage == (WORD)I_IMAGENONE, "got %d\n", item.iExpandedImage);
1575 DestroyWindow(hTree);
1578 static void test_TVS_SINGLEEXPAND(void)
1583 hTree = create_treeview_control(0);
1584 SetWindowLongA(hTree, GWL_STYLE, GetWindowLong(hTree, GWL_STYLE) | TVS_SINGLEEXPAND);
1585 /* to avoid painting related notifications */
1586 ShowWindow(hTree, SW_HIDE);
1589 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1590 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1591 ok(ret, "got %d\n", ret);
1592 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_singleexpand_seq, "singleexpand notifications", FALSE);
1594 /* a workaround for NT4 that sends expand notifications when nothing is about to expand */
1595 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hRoot);
1596 ok(ret, "got %d\n", ret);
1598 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
1599 ok(ret, "got %d\n", ret);
1601 DestroyWindow(hTree);
1604 static void test_WM_PAINT(void)
1612 hTree = create_treeview_control(0);
1614 clr = SendMessageA(hTree, TVM_SETBKCOLOR, 0, RGB(255, 0, 0));
1615 ok(clr == ~0u, "got %d, expected -1\n", clr);
1617 hdc = GetDC(hMainWnd);
1619 GetClientRect(hMainWnd, &rc);
1620 FillRect(hdc, &rc, GetStockObject(BLACK_BRUSH));
1622 clr = GetPixel(hdc, 1, 1);
1623 ok(clr == RGB(0, 0, 0), "got 0x%x\n", clr);
1625 ret = SendMessageA(hTree, WM_PAINT, (WPARAM)hdc, 0);
1626 ok(ret == 0, "got %d\n", ret);
1628 clr = GetPixel(hdc, 1, 1);
1629 ok(clr == RGB(255, 0, 0) || broken(clr == RGB(0, 0, 0)) /* win98 */,
1632 ReleaseDC(hMainWnd, hdc);
1634 DestroyWindow(hTree);
1637 static void test_delete_items(void)
1639 const struct message *msg;
1643 hTree = create_treeview_control(0);
1646 /* check delete order */
1647 flush_sequences(item_sequence, 1);
1648 ret = SendMessage(hTree, TVM_DELETEITEM, 0, 0);
1649 ok(ret == TRUE, "got %d\n", ret);
1651 msg = item_sequence[0]->sequence;
1652 ok(item_sequence[0]->count == 2, "expected 2 items, got %d\n", item_sequence[0]->count);
1654 if (item_sequence[0]->count == 2)
1656 ok(msg[0].lParam == (LPARAM)hChild, "expected %p, got 0x%lx\n", hChild, msg[0].lParam);
1657 ok(msg[1].lParam == (LPARAM)hRoot, "expected %p, got 0x%lx\n", hRoot, msg[1].lParam);
1660 ret = SendMessageA(hTree, TVM_GETCOUNT, 0, 0);
1661 ok(ret == 0, "got %d\n", ret);
1663 DestroyWindow(hTree);
1666 static void test_cchildren(void)
1672 hTree = create_treeview_control(0);
1675 ret = SendMessage(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild);
1678 /* check cChildren - automatic mode */
1680 item.mask = TVIF_CHILDREN;
1682 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1684 expect(0, item.cChildren);
1686 DestroyWindow(hTree);
1689 hTree = create_treeview_control(0);
1692 /* turn off automatic mode by setting cChildren explicitly */
1694 item.mask = TVIF_CHILDREN;
1696 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1698 expect(1, item.cChildren);
1700 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1703 ret = SendMessage(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild);
1706 /* check cChildren */
1707 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1710 expect(1, item.cChildren);
1712 DestroyWindow(hTree);
1717 HTREEITEM parent; /* for root value of parent field is unidetified */
1718 HTREEITEM nextsibling;
1719 HTREEITEM firstchild;
1722 static void _check_item(HTREEITEM item, HTREEITEM parent, HTREEITEM nextsibling, HTREEITEM firstchild, int line)
1724 struct _ITEM_DATA *data = (struct _ITEM_DATA*)item;
1726 ok_(__FILE__, line)(data->parent == parent, "parent %p, got %p\n", parent, data->parent);
1727 ok_(__FILE__, line)(data->nextsibling == nextsibling, "sibling %p, got %p\n", nextsibling, data->nextsibling);
1728 ok_(__FILE__, line)(data->firstchild == firstchild, "firstchild %p, got %p\n", firstchild, data->firstchild);
1731 #define check_item(a, b, c, d) _check_item(a, b, c, d, __LINE__)
1733 static void test_htreeitem_layout(void)
1735 TVINSERTSTRUCTA ins;
1736 HTREEITEM item1, item2;
1739 hTree = create_treeview_control(0);
1742 /* root has some special pointer in parent field */
1743 check_item(hRoot, ((struct _ITEM_DATA*)hRoot)->parent, 0, hChild);
1744 check_item(hChild, hRoot, 0, 0);
1746 ins.hParent = hChild;
1747 ins.hInsertAfter = TVI_FIRST;
1748 U(ins).item.mask = 0;
1749 item1 = TreeView_InsertItem(hTree, &ins);
1751 check_item(item1, hChild, 0, 0);
1753 ins.hParent = hRoot;
1754 ins.hInsertAfter = TVI_FIRST;
1755 U(ins).item.mask = 0;
1756 item2 = TreeView_InsertItem(hTree, &ins);
1758 check_item(item2, hRoot, hChild, 0);
1760 SendMessage(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild);
1762 /* without children now */
1763 check_item(hRoot, ((struct _ITEM_DATA*)hRoot)->parent, 0, item2);
1765 DestroyWindow(hTree);
1768 static void test_TVS_CHECKBOXES(void)
1770 HIMAGELIST himl, himl2;
1775 hTree = create_treeview_control(0);
1778 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1779 ok(himl == NULL, "got %p\n", himl);
1782 item.mask = TVIF_STATE;
1783 item.state = INDEXTOSTATEIMAGEMASK(1);
1784 item.stateMask = TVIS_STATEIMAGEMASK;
1785 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1787 ok(item.state == 0, "got 0x%x\n", item.state);
1789 /* set some index for a child */
1790 item.hItem = hChild;
1791 item.mask = TVIF_STATE;
1792 item.state = INDEXTOSTATEIMAGEMASK(4);
1793 item.stateMask = TVIS_STATEIMAGEMASK;
1794 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1797 /* enabling check boxes set all items to 1 state image index */
1798 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
1799 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1800 ok(himl != NULL, "got %p\n", himl);
1802 himl2 = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1803 ok(himl2 != NULL, "got %p\n", himl2);
1804 ok(himl2 == himl, "got %p, expected %p\n", himl2, himl);
1807 item.mask = TVIF_STATE;
1809 item.stateMask = TVIS_STATEIMAGEMASK;
1810 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1812 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
1814 item.hItem = hChild;
1815 item.mask = TVIF_STATE;
1817 item.stateMask = TVIS_STATEIMAGEMASK;
1818 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1820 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
1822 /* create another control and check its checkbox list */
1823 hTree2 = create_treeview_control(0);
1826 /* set some index for a child */
1827 item.hItem = hChild;
1828 item.mask = TVIF_STATE;
1829 item.state = INDEXTOSTATEIMAGEMASK(4);
1830 item.stateMask = TVIS_STATEIMAGEMASK;
1831 ret = SendMessageA(hTree2, TVM_SETITEMA, 0, (LPARAM)&item);
1834 /* enabling check boxes set all items to 1 state image index */
1835 SetWindowLongA(hTree2, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
1836 himl2 = (HIMAGELIST)SendMessageA(hTree2, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1837 ok(himl2 != NULL, "got %p\n", himl2);
1838 ok(himl != himl2, "got %p, expected %p\n", himl2, himl);
1840 DestroyWindow(hTree2);
1841 DestroyWindow(hTree);
1843 /* the same, but initially created with TVS_CHECKBOXES */
1844 hTree = create_treeview_control(0);
1846 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1847 ok(himl == NULL, "got %p\n", himl);
1848 DestroyWindow(hTree);
1850 hTree = create_treeview_control(TVS_CHECKBOXES);
1852 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1853 todo_wine ok(himl == NULL, "got %p\n", himl);
1856 item.mask = TVIF_STATE;
1858 item.stateMask = TVIS_STATEIMAGEMASK;
1859 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1861 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
1863 item.hItem = hChild;
1864 item.mask = TVIF_STATE;
1866 item.stateMask = TVIS_STATEIMAGEMASK;
1867 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1869 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
1871 DestroyWindow(hTree);
1874 static void test_TVM_GETNEXTITEM(void)
1879 hTree = create_treeview_control(0);
1882 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, 0);
1883 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1885 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, (LPARAM)TVI_ROOT);
1886 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1888 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, (LPARAM)hRoot);
1889 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1891 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, (LPARAM)hChild);
1892 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1894 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CHILD, 0);
1895 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1897 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hRoot);
1898 ok(item == hChild, "got %p, expected %p\n", item, hChild);
1900 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)TVI_ROOT);
1901 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1903 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_PARENT, 0);
1904 ok(item == NULL, "got %p\n", item);
1906 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hChild);
1907 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1909 DestroyWindow(hTree);
1912 static void test_TVM_HITTEST(void)
1919 hTree = create_treeview_control(0);
1922 *(HTREEITEM*)&rc = hRoot;
1923 ret = SendMessage(hTree, TVM_GETITEMRECT, TRUE, (LPARAM)&rc);
1924 expect(TRUE, (BOOL)ret);
1926 ht.pt.x = rc.left-1;
1929 ret = SendMessage(hTree, TVM_HITTEST, 0, (LPARAM)&ht);
1930 ok((HTREEITEM)ret == hRoot, "got %p, expected %p\n", (HTREEITEM)ret, hRoot);
1931 ok(ht.hItem == hRoot, "got %p, expected %p\n", ht.hItem, hRoot);
1932 ok(ht.flags == TVHT_ONITEMBUTTON, "got %d, expected %d\n", ht.flags, TVHT_ONITEMBUTTON);
1934 ret = SendMessageA(hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hRoot);
1935 expect(TRUE, (BOOL)ret);
1937 *(HTREEITEM*)&rc = hChild;
1938 ret = SendMessage(hTree, TVM_GETITEMRECT, TRUE, (LPARAM)&rc);
1939 expect(TRUE, (BOOL)ret);
1941 ht.pt.x = rc.left-1;
1944 ret = SendMessage(hTree, TVM_HITTEST, 0, (LPARAM)&ht);
1945 ok((HTREEITEM)ret == hChild, "got %p, expected %p\n", (HTREEITEM)ret, hChild);
1946 ok(ht.hItem == hChild, "got %p, expected %p\n", ht.hItem, hChild);
1947 /* Wine returns item button here, but this item has no button */
1948 todo_wine ok(ht.flags == TVHT_ONITEMINDENT, "got %d, expected %d\n", ht.flags, TVHT_ONITEMINDENT);
1950 DestroyWindow(hTree);
1953 static void test_WM_GETDLGCODE(void)
1958 hTree = create_treeview_control(0);
1960 code = SendMessageA(hTree, WM_GETDLGCODE, VK_TAB, 0);
1961 ok(code == (DLGC_WANTCHARS | DLGC_WANTARROWS), "0x%08x\n", code);
1963 DestroyWindow(hTree);
1966 START_TEST(treeview)
1969 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1973 ULONG_PTR ctx_cookie;
1977 hComctl32 = GetModuleHandleA("comctl32.dll");
1978 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1979 if (pInitCommonControlsEx)
1981 INITCOMMONCONTROLSEX iccex;
1982 iccex.dwSize = sizeof(iccex);
1983 iccex.dwICC = ICC_TREEVIEW_CLASSES;
1984 pInitCommonControlsEx(&iccex);
1987 InitCommonControls();
1989 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1990 init_msg_sequences(item_sequence, 1);
1992 wc.style = CS_HREDRAW | CS_VREDRAW;
1995 wc.hInstance = GetModuleHandleA(NULL);
1997 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
1998 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1999 wc.lpszMenuName = NULL;
2000 wc.lpszClassName = "MyTestWnd";
2001 wc.lpfnWndProc = parent_wnd_proc;
2002 RegisterClassA(&wc);
2004 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
2005 CW_USEDEFAULT, CW_USEDEFAULT, 130, 105, NULL, NULL, GetModuleHandleA(NULL), 0);
2007 ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n");
2008 if (!hMainWnd) return;
2014 test_get_set_bkcolor();
2015 test_get_set_imagelist();
2016 test_get_set_indent();
2017 test_get_set_insertmark();
2018 test_get_set_item();
2019 test_get_set_itemheight();
2020 test_get_set_scrolltime();
2021 test_get_set_textcolor();
2022 test_get_linecolor();
2023 test_get_insertmarkcolor();
2024 test_get_set_tooltips();
2025 test_get_set_unicodeformat();
2027 test_expandinvisible();
2029 test_treeview_classinfo();
2030 test_expandnotify();
2031 test_TVS_SINGLEEXPAND();
2033 test_delete_items();
2035 test_htreeitem_layout();
2036 test_TVS_CHECKBOXES();
2037 test_TVM_GETNEXTITEM();
2039 test_WM_GETDLGCODE();
2041 if (!load_v6_module(&ctx_cookie, &hCtx))
2043 DestroyWindow(hMainWnd);
2047 /* this is a XP SP3 failure workaround */
2048 hwnd = CreateWindowExA(0, WC_TREEVIEW, "foo",
2049 WS_CHILD | WS_BORDER | WS_VISIBLE,
2051 hMainWnd, NULL, GetModuleHandleA(NULL), NULL);
2052 if (!IsWindow(hwnd))
2054 win_skip("FIXME: failed to create TreeView window.\n");
2055 unload_v6_module(ctx_cookie, hCtx);
2056 DestroyWindow(hMainWnd);
2060 DestroyWindow(hwnd);
2062 /* comctl32 version 6 tests start here */
2063 test_expandedimage();
2064 test_htreeitem_layout();
2065 test_WM_GETDLGCODE();
2067 unload_v6_module(ctx_cookie, hCtx);
2069 PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
2070 while(GetMessageA(&msg, 0, 0, 0))
2072 TranslateMessage(&msg);
2073 DispatchMessageA(&msg);