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_expand_empty_kb_seq
[] = {
216 { WM_NOTIFY
, sent
|id
|optional
, 0, 0, TVN_KEYDOWN
},
217 { WM_CHANGEUISTATE
, sent
|optional
},
221 static const struct message parent_singleexpand_seq
[] = {
222 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_SELCHANGINGA
},
223 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_SELCHANGEDA
},
224 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_SINGLEEXPAND
},
225 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_ITEMEXPANDINGA
},
226 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_ITEMEXPANDEDA
},
230 static const struct message parent_get_dispinfo_seq
[] = {
231 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_GETDISPINFOA
},
235 static const struct message empty_seq
[] = {
239 static HWND hMainWnd
;
241 static HTREEITEM hRoot
, hChild
;
244 static char sequence
[256];
246 static void Clear(void)
252 static void AddItem(char ch
)
254 sequence
[pos
++] = ch
;
255 sequence
[pos
] = '\0';
258 static void IdentifyItem(HTREEITEM hItem
)
260 if (hItem
== hRoot
) {
264 if (hItem
== hChild
) {
275 /* This function hooks in and records all messages to the treeview control */
276 static LRESULT WINAPI
TreeviewWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
278 static LONG defwndproc_counter
= 0;
281 WNDPROC lpOldProc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
283 msg
.message
= message
;
284 msg
.flags
= sent
|wparam
|lparam
;
285 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
288 add_message(sequences
, TREEVIEW_SEQ_INDEX
, &msg
);
290 defwndproc_counter
++;
291 ret
= CallWindowProcA(lpOldProc
, hwnd
, message
, wParam
, lParam
);
292 defwndproc_counter
--;
297 static HWND
create_treeview_control(DWORD style
)
302 hTree
= CreateWindowExA(WS_EX_CLIENTEDGE
, WC_TREEVIEWA
, NULL
, WS_CHILD
|WS_VISIBLE
|
303 TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_EDITLABELS
|style
,
304 0, 0, 120, 100, hMainWnd
, (HMENU
)100, GetModuleHandleA(0), 0);
308 /* Record the old WNDPROC so we can call it after recording the messages */
309 pOldWndProc
= (WNDPROC
)SetWindowLongPtrA(hTree
, GWLP_WNDPROC
, (LONG_PTR
)TreeviewWndProc
);
310 SetWindowLongPtrA(hTree
, GWLP_USERDATA
, (LONG_PTR
)pOldWndProc
);
315 static void fill_tree(HWND hTree
)
318 static CHAR root
[] = "Root",
321 ins
.hParent
= TVI_ROOT
;
322 ins
.hInsertAfter
= TVI_ROOT
;
323 U(ins
).item
.mask
= TVIF_TEXT
;
324 U(ins
).item
.pszText
= root
;
325 hRoot
= TreeView_InsertItem(hTree
, &ins
);
328 ins
.hInsertAfter
= TVI_FIRST
;
329 U(ins
).item
.mask
= TVIF_TEXT
;
330 U(ins
).item
.pszText
= child
;
331 hChild
= TreeView_InsertItem(hTree
, &ins
);
334 static void test_fillroot(void)
339 hTree
= create_treeview_control(0);
341 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
351 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, FillRootSeq
, "FillRoot", FALSE
);
352 ok(!strcmp(sequence
, "AB."), "Item creation\n");
354 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
356 tvi
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
357 SendMessage( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tvi
);
358 ok(tvi
.iImage
== 0, "tvi.iImage=%d\n", tvi
.iImage
);
359 ok(tvi
.iSelectedImage
== 0, "tvi.iSelectedImage=%d\n", tvi
.iSelectedImage
);
361 DestroyWindow(hTree
);
364 static void test_callback(void)
367 HTREEITEM hItem1
, hItem2
;
370 CHAR test_string
[] = "Test_string";
371 static const CHAR test2A
[] = "TEST2";
376 hTree
= create_treeview_control(0);
378 ret
= TreeView_DeleteAllItems(hTree
);
380 ins
.hParent
= TVI_ROOT
;
381 ins
.hInsertAfter
= TVI_ROOT
;
382 U(ins
).item
.mask
= TVIF_TEXT
;
383 U(ins
).item
.pszText
= LPSTR_TEXTCALLBACK
;
384 hRoot
= TreeView_InsertItem(hTree
, &ins
);
388 tvi
.mask
= TVIF_TEXT
;
390 tvi
.cchTextMax
= sizeof(buf
)/sizeof(buf
[0]);
391 ret
= TreeView_GetItem(hTree
, &tvi
);
393 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Callback item text mismatch %s vs %s\n",
394 tvi
.pszText
, TEST_CALLBACK_TEXT
);
397 ins
.hInsertAfter
= TVI_FIRST
;
398 U(ins
).item
.mask
= TVIF_TEXT
;
399 U(ins
).item
.pszText
= test_string
;
400 hItem1
= TreeView_InsertItem(hTree
, &ins
);
404 ret
= TreeView_GetItem(hTree
, &tvi
);
406 ok(strcmp(tvi
.pszText
, test_string
) == 0, "Item text mismatch %s vs %s\n",
407 tvi
.pszText
, test_string
);
409 /* undocumented: pszText of NULL also means LPSTR_CALLBACK: */
411 ret
= TreeView_SetItem(hTree
, &tvi
);
414 ret
= TreeView_GetItem(hTree
, &tvi
);
416 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
417 tvi
.pszText
, TEST_CALLBACK_TEXT
);
419 U(ins
).item
.pszText
= NULL
;
420 hItem2
= TreeView_InsertItem(hTree
, &ins
);
423 memset(buf
, 0, sizeof(buf
));
424 ret
= TreeView_GetItem(hTree
, &tvi
);
426 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
427 tvi
.pszText
, TEST_CALLBACK_TEXT
);
429 /* notification handler changed A->W */
430 g_disp_A_to_W
= TRUE
;
432 memset(buf
, 0, sizeof(buf
));
433 ret
= TreeView_GetItem(hTree
, &tvi
);
435 ok(strcmp(tvi
.pszText
, test2A
) == 0, "got %s, expected %s\n",
436 tvi
.pszText
, test2A
);
437 g_disp_A_to_W
= FALSE
;
439 /* handler changes state image index */
440 SetWindowLongA(hTree
, GWL_STYLE
, GetWindowLongA(hTree
, GWL_STYLE
) | TVS_CHECKBOXES
);
442 /* clear selection, handler will set selected state */
443 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, 0);
446 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
449 tvi
.mask
= TVIF_STATE
;
450 tvi
.state
= TVIS_SELECTED
;
451 ret
= TreeView_GetItem(hTree
, &tvi
);
453 ok(tvi
.state
== INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", tvi
.state
);
455 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
456 "no TVN_GETDISPINFO for a state seq", FALSE
);
459 tvi
.mask
= TVIF_IMAGE
| TVIF_STATE
;
460 tvi
.state
= TVIS_FOCUSED
;
461 tvi
.stateMask
= TVIS_FOCUSED
;
462 tvi
.iImage
= I_IMAGECALLBACK
;
463 ret
= TreeView_SetItem(hTree
, &tvi
);
466 /* ask for item image index through callback - state is also set with state image index */
467 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
470 tvi
.mask
= TVIF_IMAGE
;
472 ret
= TreeView_GetItem(hTree
, &tvi
);
474 ok(tvi
.state
== (INDEXTOSTATEIMAGEMASK(1) | TVIS_FOCUSED
), "got 0x%x\n", tvi
.state
);
476 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_get_dispinfo_seq
,
477 "callback for state/overlay image index, noop seq", FALSE
);
479 /* ask for image again and overwrite state to some value in handler */
480 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
482 g_disp_set_stateimage
= TRUE
;
484 tvi
.mask
= TVIF_IMAGE
;
485 tvi
.state
= INDEXTOSTATEIMAGEMASK(1);
487 ret
= TreeView_GetItem(hTree
, &tvi
);
489 /* handler sets TVIS_SELECTED as well */
490 ok(tvi
.state
== (TVIS_FOCUSED
| TVIS_SELECTED
| INDEXTOSTATEIMAGEMASK(2) | INDEXTOOVERLAYMASK(3)), "got 0x%x\n", tvi
.state
);
491 g_disp_set_stateimage
= FALSE
;
493 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_get_dispinfo_seq
,
494 "callback for state/overlay image index seq", FALSE
);
496 DestroyWindow(hTree
);
499 static void test_select(void)
504 hTree
= create_treeview_control(0);
507 /* root-none select tests */
508 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
509 r
= TreeView_SelectItem(hTree
, NULL
);
513 r
= TreeView_SelectItem(hTree
, hRoot
);
516 r
= TreeView_SelectItem(hTree
, hRoot
);
519 r
= TreeView_SelectItem(hTree
, NULL
);
522 r
= TreeView_SelectItem(hTree
, NULL
);
525 r
= TreeView_SelectItem(hTree
, hRoot
);
528 ok(!strcmp(sequence
, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
529 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, rootnone_select_seq
,
530 "root-none select seq", FALSE
);
532 /* root-child select tests */
533 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
534 r
= TreeView_SelectItem(hTree
, NULL
);
539 r
= TreeView_SelectItem(hTree
, hRoot
);
542 r
= TreeView_SelectItem(hTree
, hRoot
);
545 r
= TreeView_SelectItem(hTree
, hChild
);
548 r
= TreeView_SelectItem(hTree
, hChild
);
551 r
= TreeView_SelectItem(hTree
, hRoot
);
554 ok(!strcmp(sequence
, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
555 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, rootchild_select_seq
,
556 "root-child select seq", FALSE
);
558 DestroyWindow(hTree
);
561 static void test_getitemtext(void)
568 CHAR szBuffer
[80] = "Blah";
569 int nBufferSize
= sizeof(szBuffer
)/sizeof(CHAR
);
571 hTree
= create_treeview_control(0);
574 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
576 /* add an item without TVIF_TEXT mask and pszText == NULL */
578 ins
.hInsertAfter
= TVI_ROOT
;
579 U(ins
).item
.mask
= 0;
580 U(ins
).item
.pszText
= NULL
;
581 U(ins
).item
.cchTextMax
= 0;
582 hChild
= TreeView_InsertItem(hTree
, &ins
);
585 /* retrieve it with TVIF_TEXT mask */
587 tvi
.mask
= TVIF_TEXT
;
588 tvi
.cchTextMax
= nBufferSize
;
589 tvi
.pszText
= szBuffer
;
591 SendMessageA( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tvi
);
592 ok(!strcmp(szBuffer
, ""), "szBuffer=\"%s\", expected \"\"\n", szBuffer
);
593 ok(SendMessageA(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hChild
), "DeleteItem failed\n");
594 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, getitemtext_seq
, "get item text seq", FALSE
);
596 DestroyWindow(hTree
);
599 static void test_focus(void)
602 static CHAR child1
[] = "Edit",
603 child2
[] = "A really long string";
604 HTREEITEM hChild1
, hChild2
;
608 hTree
= create_treeview_control(0);
611 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
613 /* This test verifies that when a label is being edited, scrolling
614 * the treeview does not cause the label to lose focus. To test
615 * this, first some additional entries are added to generate
619 ins
.hInsertAfter
= hChild
;
620 U(ins
).item
.mask
= TVIF_TEXT
;
621 U(ins
).item
.pszText
= child1
;
622 hChild1
= TreeView_InsertItem(hTree
, &ins
);
624 ins
.hInsertAfter
= hChild1
;
625 U(ins
).item
.mask
= TVIF_TEXT
;
626 U(ins
).item
.pszText
= child2
;
627 hChild2
= TreeView_InsertItem(hTree
, &ins
);
630 ShowWindow(hMainWnd
,SW_SHOW
);
631 SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hChild
);
632 hEdit
= TreeView_EditLabel(hTree
, hChild
);
633 ScrollWindowEx(hTree
, -10, 0, NULL
, NULL
, NULL
, NULL
, SW_SCROLLCHILDREN
);
634 ok(GetFocus() == hEdit
, "Edit control should have focus\n");
635 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, focus_seq
, "focus test", TRUE
);
637 DestroyWindow(hTree
);
640 static void test_get_set_bkcolor(void)
642 COLORREF crColor
= RGB(0,0,0);
645 hTree
= create_treeview_control(0);
648 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
650 /* If the value is -1, the control is using the system color for the background color. */
651 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
652 ok(crColor
== ~0u, "Default background color reported as 0x%.8x\n", crColor
);
654 /* Test for black background */
655 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, RGB(0,0,0) );
656 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
657 ok(crColor
== RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor
);
659 /* Test for white background */
660 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, RGB(255,255,255) );
661 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
662 ok(crColor
== RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor
);
664 /* Reset the default background */
665 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, -1 );
667 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_bkcolor_seq
,
668 "test get set bkcolor", FALSE
);
670 DestroyWindow(hTree
);
673 static void test_get_set_imagelist(void)
678 hTree
= create_treeview_control(0);
681 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
683 /* Test a NULL HIMAGELIST */
684 SendMessage( hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, 0 );
685 himl
= (HIMAGELIST
)SendMessage( hTree
, TVM_GETIMAGELIST
, TVSIL_NORMAL
, 0 );
686 ok(himl
== NULL
, "NULL image list, reported as %p, expected 0.\n", himl
);
688 /* TODO: Test an actual image list */
690 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_imagelist_seq
,
691 "test get imagelist", FALSE
);
693 DestroyWindow(hTree
);
696 static void test_get_set_indent(void)
699 int ulMinIndent
= -1;
700 int ulMoreThanTwiceMin
= -1;
703 hTree
= create_treeview_control(0);
706 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
708 /* Finding the minimum indent */
709 SendMessage( hTree
, TVM_SETINDENT
, 0, 0 );
710 ulMinIndent
= (int)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
712 /* Checking an indent that is more than twice the default indent */
713 ulMoreThanTwiceMin
= 2*ulMinIndent
+1;
714 SendMessage( hTree
, TVM_SETINDENT
, ulMoreThanTwiceMin
, 0 );
715 ulIndent
= (DWORD
)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
716 ok(ulIndent
== ulMoreThanTwiceMin
, "Indent reported as %d, expected %d\n", ulIndent
, ulMoreThanTwiceMin
);
718 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_indent_seq
,
719 "test get set indent", FALSE
);
721 DestroyWindow(hTree
);
724 static void test_get_set_insertmark(void)
726 COLORREF crColor
= RGB(0,0,0);
729 hTree
= create_treeview_control(0);
732 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
734 SendMessage( hTree
, TVM_SETINSERTMARKCOLOR
, 0, crColor
);
735 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0 );
736 ok(crColor
== RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor
);
738 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_insertmarkcolor_seq
,
739 "test get set insertmark color", FALSE
);
741 DestroyWindow(hTree
);
744 static void test_get_set_item(void)
746 TVITEMA tviRoot
= {0};
747 int nBufferSize
= 80;
748 char szBuffer
[80] = {0};
752 hTree
= create_treeview_control(0);
755 tviRoot
.hItem
= hRoot
;
756 tviRoot
.mask
= TVIF_STATE
;
757 tviRoot
.state
= TVIS_FOCUSED
;
758 tviRoot
.stateMask
= TVIS_FOCUSED
;
759 ret
= SendMessage( hTree
, TVM_SETITEMA
, 0, (LPARAM
)&tviRoot
);
762 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
764 /* Test the root item, state is set even when not requested */
765 tviRoot
.hItem
= hRoot
;
766 tviRoot
.mask
= TVIF_TEXT
;
768 tviRoot
.stateMask
= 0;
769 tviRoot
.cchTextMax
= nBufferSize
;
770 tviRoot
.pszText
= szBuffer
;
771 ret
= SendMessage( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tviRoot
);
773 ok(!strcmp("Root", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer
);
774 ok(tviRoot
.state
== TVIS_FOCUSED
, "got 0x%0x\n", tviRoot
.state
);
776 /* Change the root text */
777 strncpy(szBuffer
, "Testing123", nBufferSize
);
778 ret
= SendMessage( hTree
, TVM_SETITEMA
, 0, (LPARAM
)&tviRoot
);
780 memset(szBuffer
, 0, nBufferSize
);
781 ret
= SendMessage( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tviRoot
);
783 ok(!strcmp("Testing123", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer
);
785 /* Reset the root text */
786 memset(szBuffer
, 0, nBufferSize
);
787 strncpy(szBuffer
, "Root", nBufferSize
);
788 ret
= SendMessage( hTree
, TVM_SETITEMA
, 0, (LPARAM
)&tviRoot
);
791 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_item_seq
,
792 "test get set item", FALSE
);
794 /* get item from a different tree */
795 hTree2
= create_treeview_control(0);
797 tviRoot
.hItem
= hRoot
;
798 tviRoot
.mask
= TVIF_STATE
;
800 ret
= SendMessage( hTree2
, TVM_GETITEMA
, 0, (LPARAM
)&tviRoot
);
802 ok(tviRoot
.state
== TVIS_FOCUSED
, "got state 0x%0x\n", tviRoot
.state
);
804 DestroyWindow(hTree
);
805 DestroyWindow(hTree2
);
808 static void test_get_set_itemheight(void)
814 hTree
= create_treeview_control(0);
817 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
819 /* Assuming default height to begin with */
820 ulOldHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
822 /* Explicitly setting and getting the default height */
823 SendMessage( hTree
, TVM_SETITEMHEIGHT
, -1, 0 );
824 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
825 ok(ulNewHeight
== ulOldHeight
, "Default height not set properly, reported %d, expected %d\n", ulNewHeight
, ulOldHeight
);
827 /* Explicitly setting and getting the height of twice the normal */
828 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 2*ulOldHeight
, 0 );
829 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
830 ok(ulNewHeight
== 2*ulOldHeight
, "New height not set properly, reported %d, expected %d\n", ulNewHeight
, 2*ulOldHeight
);
832 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
833 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 9, 0 );
834 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
835 ok(ulNewHeight
== 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight
, 8);
837 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_itemheight_seq
,
838 "test get set item height", FALSE
);
840 /* without TVS_NONEVENHEIGHT */
841 SetWindowLong(hTree
, GWL_STYLE
, GetWindowLong(hTree
, GWL_STYLE
) & ~TVS_NONEVENHEIGHT
);
843 ulOldHeight
= SendMessage( hTree
, TVM_SETITEMHEIGHT
, 3, 0);
844 ok(ulOldHeight
== 8, "got %d, expected %d\n", ulOldHeight
, 8);
845 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
846 ok(ulNewHeight
== 2, "got %d, expected %d\n", ulNewHeight
, 2);
848 ulOldHeight
= SendMessage( hTree
, TVM_SETITEMHEIGHT
, 4, 0);
849 ok(ulOldHeight
== 2, "got %d, expected %d\n", ulOldHeight
, 2);
850 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
851 ok(ulNewHeight
== 4, "got %d, expected %d\n", ulNewHeight
, 4);
853 /* with TVS_NONEVENHEIGHT */
854 SetWindowLong(hTree
, GWL_STYLE
, GetWindowLong(hTree
, GWL_STYLE
) | TVS_NONEVENHEIGHT
);
856 ulOldHeight
= SendMessage( hTree
, TVM_SETITEMHEIGHT
, 3, 0);
857 ok(ulOldHeight
== 4, "got %d, expected %d\n", ulOldHeight
, 4);
858 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
859 ok(ulNewHeight
== 3, "got %d, expected %d\n", ulNewHeight
, 3);
861 ulOldHeight
= SendMessage( hTree
, TVM_SETITEMHEIGHT
, 10, 0);
862 ok(ulOldHeight
== 3, "got %d, expected %d\n", ulOldHeight
, 3);
863 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
864 ok(ulNewHeight
== 10, "got %d, expected %d\n", ulNewHeight
, 10);
866 DestroyWindow(hTree
);
869 static void test_get_set_scrolltime(void)
871 int ulExpectedTime
= 20;
875 hTree
= create_treeview_control(0);
878 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
880 SendMessage( hTree
, TVM_SETSCROLLTIME
, ulExpectedTime
, 0 );
881 ulTime
= (int)SendMessage( hTree
, TVM_GETSCROLLTIME
, 0, 0 );
882 ok(ulTime
== ulExpectedTime
, "Scroll time reported as %d, expected %d\n", ulTime
, ulExpectedTime
);
884 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_scrolltime_seq
,
885 "test get set scroll time", FALSE
);
887 DestroyWindow(hTree
);
890 static void test_get_set_textcolor(void)
892 /* If the value is -1, the control is using the system color for the text color. */
893 COLORREF crColor
= RGB(0,0,0);
896 hTree
= create_treeview_control(0);
899 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
901 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
902 ok(crColor
== ~0u, "Default text color reported as 0x%.8x\n", crColor
);
904 /* Test for black text */
905 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, RGB(0,0,0) );
906 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
907 ok(crColor
== RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor
);
909 /* Test for white text */
910 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, RGB(255,255,255) );
911 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
912 ok(crColor
== RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor
);
914 /* Reset the default text color */
915 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, CLR_NONE
);
917 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_textcolor_seq
,
918 "test get set text color", FALSE
);
920 DestroyWindow(hTree
);
923 static void test_get_set_tooltips(void)
925 HWND hwndLastToolTip
= NULL
;
929 hTree
= create_treeview_control(0);
932 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
934 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
935 hPopupTreeView
= CreateWindow(WC_TREEVIEW
, NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 100, 100, hMainWnd
, NULL
, NULL
, NULL
);
936 DestroyWindow(hPopupTreeView
);
938 /* Testing setting a NULL ToolTip */
939 SendMessage( hTree
, TVM_SETTOOLTIPS
, 0, 0 );
940 hwndLastToolTip
= (HWND
)SendMessage( hTree
, TVM_GETTOOLTIPS
, 0, 0 );
941 ok(hwndLastToolTip
== NULL
, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip
);
943 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_tooltips_seq
,
944 "test get set tooltips", TRUE
);
946 /* TODO: Add a test of an actual tooltip */
947 DestroyWindow(hTree
);
950 static void test_get_set_unicodeformat(void)
952 BOOL bPreviousSetting
= 0;
953 BOOL bNewSetting
= 0;
956 hTree
= create_treeview_control(0);
959 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
962 bPreviousSetting
= (BOOL
)SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 1, 0 );
963 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
964 ok(bNewSetting
== 1, "Unicode setting did not work.\n");
967 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 0, 0 );
968 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
969 ok(bNewSetting
== 0, "ANSI setting did not work.\n");
971 /* Revert to original setting */
972 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, bPreviousSetting
, 0 );
974 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_unicodeformat_seq
,
975 "test get set unicode format", FALSE
);
977 DestroyWindow(hTree
);
980 static LRESULT CALLBACK
parent_wnd_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
982 static LONG defwndproc_counter
= 0;
986 HTREEITEM visibleItem
;
988 msg
.message
= message
;
989 msg
.flags
= sent
|wparam
|lparam
;
990 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
993 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
995 /* log system messages, except for painting */
996 if (message
< WM_USER
&&
997 message
!= WM_PAINT
&&
998 message
!= WM_ERASEBKGND
&&
999 message
!= WM_NCPAINT
&&
1000 message
!= WM_NCHITTEST
&&
1001 message
!= WM_GETTEXT
&&
1002 message
!= WM_GETICON
&&
1003 message
!= WM_DEVICECHANGE
)
1005 trace("parent: %p, %04x, %08lx, %08lx\n", hWnd
, message
, wParam
, lParam
);
1006 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
1012 NMHDR
*pHdr
= (NMHDR
*)lParam
;
1014 ok(pHdr
->code
!= NM_TOOLTIPSCREATED
, "Treeview should not send NM_TOOLTIPSCREATED\n");
1015 if (pHdr
->idFrom
== 100)
1017 NMTREEVIEWA
*pTreeView
= (LPNMTREEVIEWA
) lParam
;
1020 case TVN_SELCHANGINGA
:
1022 IdentifyItem(pTreeView
->itemOld
.hItem
);
1023 IdentifyItem(pTreeView
->itemNew
.hItem
);
1025 case TVN_SELCHANGEDA
:
1027 IdentifyItem(pTreeView
->itemOld
.hItem
);
1028 IdentifyItem(pTreeView
->itemNew
.hItem
);
1030 case TVN_GETDISPINFOA
: {
1031 NMTVDISPINFOA
*disp
= (NMTVDISPINFOA
*)lParam
;
1032 if (disp
->item
.mask
& TVIF_TEXT
) {
1033 lstrcpyn(disp
->item
.pszText
, TEST_CALLBACK_TEXT
, disp
->item
.cchTextMax
);
1036 if (g_disp_A_to_W
&& (disp
->item
.mask
& TVIF_TEXT
)) {
1037 static const WCHAR testW
[] = {'T','E','S','T','2',0};
1039 disp
->hdr
.code
= TVN_GETDISPINFOW
;
1040 memcpy(disp
->item
.pszText
, testW
, sizeof(testW
));
1043 if (g_disp_set_stateimage
)
1045 ok(disp
->item
.mask
== TVIF_IMAGE
, "got %x\n", disp
->item
.mask
);
1046 /* both masks set here are necessary to change state bits */
1047 disp
->item
.mask
|= TVIF_STATE
;
1048 disp
->item
.state
= TVIS_SELECTED
| INDEXTOSTATEIMAGEMASK(2) | INDEXTOOVERLAYMASK(3);
1049 disp
->item
.stateMask
= TVIS_SELECTED
| TVIS_OVERLAYMASK
| TVIS_STATEIMAGEMASK
;
1054 case TVN_BEGINLABELEDIT
:
1056 if (g_beginedit_alter_text
)
1058 static const char* textA
= "<edittextaltered>";
1061 edit
= (HWND
)SendMessageA(pHdr
->hwndFrom
, TVM_GETEDITCONTROL
, 0, 0);
1062 ok(IsWindow(edit
), "failed to get edit handle\n");
1063 SetWindowTextA(edit
, textA
);
1069 case TVN_ENDLABELEDIT
: return TRUE
;
1070 case TVN_ITEMEXPANDINGA
:
1071 ok(pTreeView
->itemNew
.mask
==
1072 (TVIF_HANDLE
| TVIF_SELECTEDIMAGE
| TVIF_IMAGE
| TVIF_PARAM
| TVIF_STATE
),
1073 "got wrong mask %x\n", pTreeView
->itemNew
.mask
);
1074 ok((pTreeView
->itemNew
.state
& TVIS_EXPANDED
) == 0,
1075 "got wrong state %x\n", pTreeView
->itemNew
.state
);
1076 ok(pTreeView
->itemOld
.mask
== 0,
1077 "got wrong mask %x\n", pTreeView
->itemOld
.mask
);
1079 if (g_get_from_expand
)
1081 g_item_expanding
.mask
= TVIF_STATE
;
1082 g_item_expanding
.hItem
= hRoot
;
1083 ret
= SendMessageA(pHdr
->hwndFrom
, TVM_GETITEMA
, 0, (LPARAM
)&g_item_expanding
);
1084 ok(ret
== TRUE
, "got %lu\n", ret
);
1087 case TVN_ITEMEXPANDEDA
:
1088 ok(pTreeView
->itemNew
.mask
& TVIF_STATE
, "got wrong mask %x\n", pTreeView
->itemNew
.mask
);
1089 ok(pTreeView
->itemNew
.state
& (TVIS_EXPANDED
|TVIS_EXPANDEDONCE
),
1090 "got wrong mask %x\n", pTreeView
->itemNew
.mask
);
1091 ok(pTreeView
->itemOld
.mask
== 0,
1092 "got wrong mask %x\n", pTreeView
->itemOld
.mask
);
1094 if (g_get_from_expand
)
1096 g_item_expanded
.mask
= TVIF_STATE
;
1097 g_item_expanded
.hItem
= hRoot
;
1098 ret
= SendMessageA(pHdr
->hwndFrom
, TVM_GETITEMA
, 0, (LPARAM
)&g_item_expanded
);
1099 ok(ret
== TRUE
, "got %lu\n", ret
);
1101 if (g_get_rect_in_expand
)
1103 visibleItem
= TreeView_GetNextItem(pHdr
->hwndFrom
, NULL
, TVGN_FIRSTVISIBLE
);
1104 ok(pTreeView
->itemNew
.hItem
== visibleItem
, "expanded item == first visible item\n");
1105 *(HTREEITEM
*)&rect
= visibleItem
;
1106 ok(SendMessage(pHdr
->hwndFrom
, TVM_GETITEMRECT
, TRUE
, (LPARAM
)&rect
), "Failed to get rect for first visible item.\n");
1107 visibleItem
= TreeView_GetNextItem(pHdr
->hwndFrom
, visibleItem
, TVGN_NEXTVISIBLE
);
1108 *(HTREEITEM
*)&rect
= visibleItem
;
1109 ok(visibleItem
!= NULL
, "There must be a visible item after the first visisble item.\n");
1110 ok(SendMessage(pHdr
->hwndFrom
, TVM_GETITEMRECT
, TRUE
, (LPARAM
)&rect
), "Failed to get rect for second visible item.\n");
1113 case TVN_DELETEITEMA
:
1115 struct message item
;
1117 ok(pTreeView
->itemNew
.mask
== 0, "got wrong mask 0x%x\n", pTreeView
->itemNew
.mask
);
1119 ok(pTreeView
->itemOld
.mask
== (TVIF_HANDLE
| TVIF_PARAM
), "got wrong mask 0x%x\n", pTreeView
->itemOld
.mask
);
1120 ok(pTreeView
->itemOld
.hItem
!= NULL
, "got %p\n", pTreeView
->itemOld
.hItem
);
1122 memset(&item
, 0, sizeof(item
));
1123 item
.lParam
= (LPARAM
)pTreeView
->itemOld
.hItem
;
1124 add_message(item_sequence
, 0, &item
);
1138 defwndproc_counter
++;
1139 ret
= DefWindowProcA(hWnd
, message
, wParam
, lParam
);
1140 defwndproc_counter
--;
1145 static void test_expandinvisible(void)
1147 static CHAR nodeText
[][5] = {"0", "1", "2", "3", "4"};
1148 TVINSERTSTRUCTA ins
;
1155 hTree
= create_treeview_control(0);
1157 /* The test builds the following tree and expands node 1, while node 0 is collapsed.
1167 ret
= TreeView_DeleteAllItems(hTree
);
1168 ok(ret
== TRUE
, "ret\n");
1169 ins
.hParent
= TVI_ROOT
;
1170 ins
.hInsertAfter
= TVI_ROOT
;
1171 U(ins
).item
.mask
= TVIF_TEXT
;
1172 U(ins
).item
.pszText
= nodeText
[0];
1173 node
[0] = TreeView_InsertItem(hTree
, &ins
);
1176 ins
.hInsertAfter
= TVI_LAST
;
1177 U(ins
).item
.mask
= TVIF_TEXT
;
1178 ins
.hParent
= node
[0];
1180 U(ins
).item
.pszText
= nodeText
[1];
1181 node
[1] = TreeView_InsertItem(hTree
, &ins
);
1183 U(ins
).item
.pszText
= nodeText
[4];
1184 node
[4] = TreeView_InsertItem(hTree
, &ins
);
1187 ins
.hParent
= node
[1];
1189 U(ins
).item
.pszText
= nodeText
[2];
1190 node
[2] = TreeView_InsertItem(hTree
, &ins
);
1192 U(ins
).item
.pszText
= nodeText
[3];
1193 node
[3] = TreeView_InsertItem(hTree
, &ins
);
1197 nodeVisible
= TreeView_GetItemRect(hTree
, node
[1], &dummyRect
, FALSE
);
1198 ok(!nodeVisible
, "Node 1 should not be visible.\n");
1199 nodeVisible
= TreeView_GetItemRect(hTree
, node
[2], &dummyRect
, FALSE
);
1200 ok(!nodeVisible
, "Node 2 should not be visible.\n");
1201 nodeVisible
= TreeView_GetItemRect(hTree
, node
[3], &dummyRect
, FALSE
);
1202 ok(!nodeVisible
, "Node 3 should not be visible.\n");
1203 nodeVisible
= TreeView_GetItemRect(hTree
, node
[4], &dummyRect
, FALSE
);
1204 ok(!nodeVisible
, "Node 4 should not be visible.\n");
1206 ok(TreeView_Expand(hTree
, node
[1], TVE_EXPAND
), "Expand of node 1 failed.\n");
1208 nodeVisible
= TreeView_GetItemRect(hTree
, node
[1], &dummyRect
, FALSE
);
1209 ok(!nodeVisible
, "Node 1 should not be visible.\n");
1210 nodeVisible
= TreeView_GetItemRect(hTree
, node
[2], &dummyRect
, FALSE
);
1211 ok(!nodeVisible
, "Node 2 should not be visible.\n");
1212 nodeVisible
= TreeView_GetItemRect(hTree
, node
[3], &dummyRect
, FALSE
);
1213 ok(!nodeVisible
, "Node 3 should not be visible.\n");
1214 nodeVisible
= TreeView_GetItemRect(hTree
, node
[4], &dummyRect
, FALSE
);
1215 ok(!nodeVisible
, "Node 4 should not be visible.\n");
1217 DestroyWindow(hTree
);
1220 static void test_itemedit(void)
1228 hTree
= create_treeview_control(0);
1231 /* try with null item */
1232 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABELA
, 0, 0);
1233 ok(!IsWindow(edit
), "Expected valid handle\n");
1236 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABELA
, 0, (LPARAM
)hRoot
);
1237 ok(IsWindow(edit
), "Expected valid handle\n");
1238 /* item shouldn't be selected automatically after TVM_EDITLABEL */
1239 r
= SendMessage(hTree
, TVM_GETITEMSTATE
, (WPARAM
)hRoot
, TVIS_SELECTED
);
1241 /* try to cancel with wrong edit handle */
1242 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), 0);
1244 ok(IsWindow(edit
), "Expected edit control to be valid\n");
1245 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1247 ok(!IsWindow(edit
), "Expected edit control to be destroyed\n");
1248 /* try to cancel without creating edit */
1249 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), 0);
1252 /* try to cancel with wrong (not null) handle */
1253 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABELA
, 0, (LPARAM
)hRoot
);
1254 ok(IsWindow(edit
), "Expected valid handle\n");
1255 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hTree
);
1257 ok(IsWindow(edit
), "Expected edit control to be valid\n");
1258 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1261 /* remove selection after starting edit */
1262 r
= TreeView_SelectItem(hTree
, hRoot
);
1264 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABELA
, 0, (LPARAM
)hRoot
);
1265 ok(IsWindow(edit
), "Expected valid handle\n");
1266 r
= TreeView_SelectItem(hTree
, NULL
);
1270 r
= SendMessage(edit
, WM_SETTEXT
, 0, (LPARAM
)buffA
);
1272 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1274 ok(!IsWindow(edit
), "Expected edit control to be destroyed\n");
1275 /* check that text is saved */
1276 item
.mask
= TVIF_TEXT
;
1278 item
.pszText
= buffA
;
1279 item
.cchTextMax
= sizeof(buffA
)/sizeof(CHAR
);
1280 r
= SendMessage(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1282 ok(!strcmp("x", buffA
), "Expected item text to change\n");
1284 /* try A/W messages */
1285 edit
= (HWND
)SendMessageA(hTree
, TVM_EDITLABELA
, 0, (LPARAM
)hRoot
);
1286 ok(IsWindow(edit
), "Expected valid handle\n");
1287 ok(IsWindowUnicode(edit
), "got ansi window\n");
1288 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1290 ok(!IsWindow(edit
), "expected invalid handle\n");
1292 edit
= (HWND
)SendMessageA(hTree
, TVM_EDITLABELW
, 0, (LPARAM
)hRoot
);
1293 ok(IsWindow(edit
), "Expected valid handle\n");
1294 ok(IsWindowUnicode(edit
), "got ansi window\n");
1295 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1298 /* alter text during TVM_BEGINLABELEDIT, check that it's preserved */
1299 strcpy(buffA
, "<root>");
1301 item
.mask
= TVIF_TEXT
;
1303 item
.pszText
= buffA
;
1304 item
.cchTextMax
= 0;
1305 r
= SendMessage(hTree
, TVM_SETITEMA
, 0, (LPARAM
)&item
);
1308 g_beginedit_alter_text
= TRUE
;
1309 edit
= (HWND
)SendMessageA(hTree
, TVM_EDITLABELA
, 0, (LPARAM
)hRoot
);
1310 ok(IsWindow(edit
), "Expected valid handle\n");
1311 g_beginedit_alter_text
= FALSE
;
1313 GetWindowTextA(edit
, buffA
, sizeof(buffA
)/sizeof(CHAR
));
1314 ok(!strcmp(buffA
, "<edittextaltered>"), "got string %s\n", buffA
);
1316 DestroyWindow(hTree
);
1319 static void test_treeview_classinfo(void)
1323 memset(&cls
, 0, sizeof(cls
));
1324 GetClassInfo(GetModuleHandleA("comctl32.dll"), WC_TREEVIEWA
, &cls
);
1325 ok(cls
.hbrBackground
== NULL
, "Expected NULL background brush, got %p\n", cls
.hbrBackground
);
1326 ok(cls
.style
== (CS_GLOBALCLASS
| CS_DBLCLKS
), "Expected got %x\n", cls
.style
);
1327 expect(0, cls
.cbClsExtra
);
1330 static void test_get_linecolor(void)
1335 hTree
= create_treeview_control(0);
1337 /* newly created control has default color */
1338 clr
= (COLORREF
)SendMessage(hTree
, TVM_GETLINECOLOR
, 0, 0);
1340 win_skip("TVM_GETLINECOLOR is not supported on comctl32 < 5.80\n");
1342 expect(CLR_DEFAULT
, clr
);
1344 DestroyWindow(hTree
);
1347 static void test_get_insertmarkcolor(void)
1352 hTree
= create_treeview_control(0);
1354 /* newly created control has default color */
1355 clr
= (COLORREF
)SendMessage(hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0);
1357 win_skip("TVM_GETINSERTMARKCOLOR is not supported on comctl32 < 5.80\n");
1359 expect(CLR_DEFAULT
, clr
);
1361 DestroyWindow(hTree
);
1364 static void test_expandnotify(void)
1370 hTree
= create_treeview_control(0);
1374 item
.mask
= TVIF_STATE
;
1376 item
.state
= TVIS_EXPANDED
;
1377 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1379 ok((item
.state
& TVIS_EXPANDED
) == 0, "expected collapsed\n");
1381 /* preselect root node here */
1382 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hRoot
);
1385 g_get_from_expand
= TRUE
;
1387 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1388 g_item_expanding
.state
= 0xdeadbeef;
1389 g_item_expanded
.state
= 0xdeadbeef;
1390 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)hRoot
);
1392 ok(g_item_expanding
.state
== TVIS_SELECTED
, "got state on TVN_ITEMEXPANDING 0x%08x\n",
1393 g_item_expanding
.state
);
1394 ok(g_item_expanded
.state
== (TVIS_SELECTED
|TVIS_EXPANDED
), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1395 g_item_expanded
.state
);
1396 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_expand_seq
, "expand notifications", FALSE
);
1397 g_get_from_expand
= FALSE
;
1399 /* check that it's expanded */
1400 item
.state
= TVIS_EXPANDED
;
1401 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1403 ok((item
.state
& TVIS_EXPANDED
) == TVIS_EXPANDED
, "expected expanded\n");
1406 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1407 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_COLLAPSE
, (LPARAM
)hRoot
);
1409 item
.state
= TVIS_EXPANDED
;
1410 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1412 ok((item
.state
& TVIS_EXPANDED
) == 0, "expected collapsed\n");
1413 /* all further collapse/expand attempts won't produce any notifications,
1414 the only way is to reset with all children removed */
1415 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "collapse after expand notifications", FALSE
);
1417 /* try to toggle child that doesn't have children itself */
1418 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1419 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_TOGGLE
, (LPARAM
)hChild
);
1421 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "toggle node without children", FALSE
);
1423 DestroyWindow(hTree
);
1425 /* test TVM_GETITEMRECT inside TVN_ITEMEXPANDED notification */
1426 hTree
= create_treeview_control(0);
1428 g_get_rect_in_expand
= TRUE
;
1429 ret
= TreeView_Select(hTree
, hChild
, TVGN_CARET
);
1431 g_get_rect_in_expand
= FALSE
;
1433 DestroyWindow(hTree
);
1435 /* TVE_TOGGLE acts as any other TVM_EXPAND */
1436 hTree
= create_treeview_control(0);
1439 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1440 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_TOGGLE
, (LPARAM
)hRoot
);
1442 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_expand_seq
, "toggle node (expand)", FALSE
);
1444 /* toggle again - no notifications */
1445 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1446 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_TOGGLE
, (LPARAM
)hRoot
);
1448 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "toggle node (collapse)", FALSE
);
1450 DestroyWindow(hTree
);
1452 /* some keyboard events are also translated to expand */
1453 hTree
= create_treeview_control(0);
1456 /* preselect root node here */
1457 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hRoot
);
1460 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1461 ret
= SendMessageA(hTree
, WM_KEYDOWN
, VK_ADD
, 0);
1463 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_expand_kb_seq
, "expand node", FALSE
);
1466 ret
= SendMessageA(hTree
, WM_KEYDOWN
, VK_RIGHT
, 0);
1469 /* try to expand child that doesn't have children itself */
1470 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1471 ret
= SendMessageA(hTree
, WM_KEYDOWN
, VK_ADD
, 0);
1473 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_expand_empty_kb_seq
, "expand node with no children", TRUE
);
1475 DestroyWindow(hTree
);
1478 static void test_expandedimage(void)
1484 hTree
= create_treeview_control(0);
1487 item
.mask
= TVIF_EXPANDEDIMAGE
;
1488 item
.iExpandedImage
= 1;
1490 ret
= SendMessageA(hTree
, TVM_SETITEMA
, 0, (LPARAM
)&item
);
1491 ok(ret
, "got %d\n", ret
);
1493 item
.mask
= TVIF_EXPANDEDIMAGE
;
1494 item
.iExpandedImage
= -1;
1496 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1497 ok(ret
, "got %d\n", ret
);
1499 if (item
.iExpandedImage
!= 1)
1501 win_skip("TVIF_EXPANDEDIMAGE not supported\n");
1502 DestroyWindow(hTree
);
1506 /* test for default iExpandedImage value */
1507 item
.mask
= TVIF_EXPANDEDIMAGE
;
1508 item
.iExpandedImage
= -1;
1509 item
.hItem
= hChild
;
1510 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1511 ok(ret
, "got %d\n", ret
);
1512 ok(item
.iExpandedImage
== (WORD
)I_IMAGENONE
, "got %d\n", item
.iExpandedImage
);
1514 DestroyWindow(hTree
);
1517 static void test_TVS_SINGLEEXPAND(void)
1522 hTree
= create_treeview_control(0);
1523 SetWindowLongA(hTree
, GWL_STYLE
, GetWindowLong(hTree
, GWL_STYLE
) | TVS_SINGLEEXPAND
);
1524 /* to avoid painting related notifications */
1525 ShowWindow(hTree
, SW_HIDE
);
1528 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1529 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hRoot
);
1530 ok(ret
, "got %d\n", ret
);
1531 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_singleexpand_seq
, "singleexpand notifications", FALSE
);
1533 /* a workaround for NT4 that sends expand notifications when nothing is about to expand */
1534 ret
= SendMessageA(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hRoot
);
1535 ok(ret
, "got %d\n", ret
);
1537 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, 0);
1538 ok(ret
, "got %d\n", ret
);
1540 DestroyWindow(hTree
);
1543 static void test_WM_PAINT(void)
1551 hTree
= create_treeview_control(0);
1553 clr
= SendMessageA(hTree
, TVM_SETBKCOLOR
, 0, RGB(255, 0, 0));
1554 ok(clr
== ~0u, "got %d, expected -1\n", clr
);
1556 hdc
= GetDC(hMainWnd
);
1558 GetClientRect(hMainWnd
, &rc
);
1559 FillRect(hdc
, &rc
, GetStockObject(BLACK_BRUSH
));
1561 clr
= GetPixel(hdc
, 1, 1);
1562 ok(clr
== RGB(0, 0, 0), "got 0x%x\n", clr
);
1564 ret
= SendMessageA(hTree
, WM_PAINT
, (WPARAM
)hdc
, 0);
1565 ok(ret
== 0, "got %d\n", ret
);
1567 clr
= GetPixel(hdc
, 1, 1);
1568 ok(clr
== RGB(255, 0, 0) || broken(clr
== RGB(0, 0, 0)) /* win98 */,
1571 ReleaseDC(hMainWnd
, hdc
);
1573 DestroyWindow(hTree
);
1576 static void test_delete_items(void)
1578 const struct message
*msg
;
1582 hTree
= create_treeview_control(0);
1585 /* check delete order */
1586 flush_sequences(item_sequence
, 1);
1587 ret
= SendMessage(hTree
, TVM_DELETEITEM
, 0, 0);
1588 ok(ret
== TRUE
, "got %d\n", ret
);
1590 msg
= item_sequence
[0]->sequence
;
1591 ok(item_sequence
[0]->count
== 2, "expected 2 items, got %d\n", item_sequence
[0]->count
);
1593 if (item_sequence
[0]->count
== 2)
1595 ok(msg
[0].lParam
== (LPARAM
)hChild
, "expected %p, got 0x%lx\n", hChild
, msg
[0].lParam
);
1596 ok(msg
[1].lParam
== (LPARAM
)hRoot
, "expected %p, got 0x%lx\n", hRoot
, msg
[1].lParam
);
1599 ret
= SendMessageA(hTree
, TVM_GETCOUNT
, 0, 0);
1600 ok(ret
== 0, "got %d\n", ret
);
1602 DestroyWindow(hTree
);
1605 static void test_cchildren(void)
1611 hTree
= create_treeview_control(0);
1614 ret
= SendMessage(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hChild
);
1617 /* check cChildren - automatic mode */
1619 item
.mask
= TVIF_CHILDREN
;
1621 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1623 expect(0, item
.cChildren
);
1625 DestroyWindow(hTree
);
1628 hTree
= create_treeview_control(0);
1631 /* turn off automatic mode by setting cChildren explicitly */
1633 item
.mask
= TVIF_CHILDREN
;
1635 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1637 expect(1, item
.cChildren
);
1639 ret
= SendMessageA(hTree
, TVM_SETITEMA
, 0, (LPARAM
)&item
);
1642 ret
= SendMessage(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hChild
);
1645 /* check cChildren */
1646 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1649 expect(1, item
.cChildren
);
1651 DestroyWindow(hTree
);
1656 HTREEITEM parent
; /* for root value of parent field is unidetified */
1657 HTREEITEM nextsibling
;
1658 HTREEITEM firstchild
;
1661 static void _check_item(HTREEITEM item
, HTREEITEM parent
, HTREEITEM nextsibling
, HTREEITEM firstchild
, int line
)
1663 struct _ITEM_DATA
*data
= (struct _ITEM_DATA
*)item
;
1665 ok_(__FILE__
, line
)(data
->parent
== parent
, "parent %p, got %p\n", parent
, data
->parent
);
1666 ok_(__FILE__
, line
)(data
->nextsibling
== nextsibling
, "sibling %p, got %p\n", nextsibling
, data
->nextsibling
);
1667 ok_(__FILE__
, line
)(data
->firstchild
== firstchild
, "firstchild %p, got %p\n", firstchild
, data
->firstchild
);
1670 #define check_item(a, b, c, d) _check_item(a, b, c, d, __LINE__)
1672 static void test_htreeitem_layout(void)
1674 TVINSERTSTRUCTA ins
;
1675 HTREEITEM item1
, item2
;
1678 hTree
= create_treeview_control(0);
1681 /* root has some special pointer in parent field */
1682 check_item(hRoot
, ((struct _ITEM_DATA
*)hRoot
)->parent
, 0, hChild
);
1683 check_item(hChild
, hRoot
, 0, 0);
1685 ins
.hParent
= hChild
;
1686 ins
.hInsertAfter
= TVI_FIRST
;
1687 U(ins
).item
.mask
= 0;
1688 item1
= TreeView_InsertItem(hTree
, &ins
);
1690 check_item(item1
, hChild
, 0, 0);
1692 ins
.hParent
= hRoot
;
1693 ins
.hInsertAfter
= TVI_FIRST
;
1694 U(ins
).item
.mask
= 0;
1695 item2
= TreeView_InsertItem(hTree
, &ins
);
1697 check_item(item2
, hRoot
, hChild
, 0);
1699 SendMessage(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hChild
);
1701 /* without children now */
1702 check_item(hRoot
, ((struct _ITEM_DATA
*)hRoot
)->parent
, 0, item2
);
1704 DestroyWindow(hTree
);
1707 static void test_TVS_CHECKBOXES(void)
1709 HIMAGELIST himl
, himl2
;
1714 hTree
= create_treeview_control(0);
1717 himl
= (HIMAGELIST
)SendMessageA(hTree
, TVM_GETIMAGELIST
, TVSIL_STATE
, 0);
1718 ok(himl
== NULL
, "got %p\n", himl
);
1721 item
.mask
= TVIF_STATE
;
1722 item
.state
= INDEXTOSTATEIMAGEMASK(1);
1723 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1724 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1726 ok(item
.state
== 0, "got 0x%x\n", item
.state
);
1728 /* set some index for a child */
1729 item
.hItem
= hChild
;
1730 item
.mask
= TVIF_STATE
;
1731 item
.state
= INDEXTOSTATEIMAGEMASK(4);
1732 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1733 ret
= SendMessageA(hTree
, TVM_SETITEMA
, 0, (LPARAM
)&item
);
1736 /* enabling check boxes set all items to 1 state image index */
1737 SetWindowLongA(hTree
, GWL_STYLE
, GetWindowLongA(hTree
, GWL_STYLE
) | TVS_CHECKBOXES
);
1738 himl
= (HIMAGELIST
)SendMessageA(hTree
, TVM_GETIMAGELIST
, TVSIL_STATE
, 0);
1739 ok(himl
!= NULL
, "got %p\n", himl
);
1741 himl2
= (HIMAGELIST
)SendMessageA(hTree
, TVM_GETIMAGELIST
, TVSIL_STATE
, 0);
1742 ok(himl2
!= NULL
, "got %p\n", himl2
);
1743 ok(himl2
== himl
, "got %p, expected %p\n", himl2
, himl
);
1746 item
.mask
= TVIF_STATE
;
1748 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1749 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1751 ok(item
.state
== INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item
.state
);
1753 item
.hItem
= hChild
;
1754 item
.mask
= TVIF_STATE
;
1756 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1757 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1759 ok(item
.state
== INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item
.state
);
1761 /* create another control and check its checkbox list */
1762 hTree2
= create_treeview_control(0);
1765 /* set some index for a child */
1766 item
.hItem
= hChild
;
1767 item
.mask
= TVIF_STATE
;
1768 item
.state
= INDEXTOSTATEIMAGEMASK(4);
1769 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1770 ret
= SendMessageA(hTree2
, TVM_SETITEMA
, 0, (LPARAM
)&item
);
1773 /* enabling check boxes set all items to 1 state image index */
1774 SetWindowLongA(hTree2
, GWL_STYLE
, GetWindowLongA(hTree
, GWL_STYLE
) | TVS_CHECKBOXES
);
1775 himl2
= (HIMAGELIST
)SendMessageA(hTree2
, TVM_GETIMAGELIST
, TVSIL_STATE
, 0);
1776 ok(himl2
!= NULL
, "got %p\n", himl2
);
1777 ok(himl
!= himl2
, "got %p, expected %p\n", himl2
, himl
);
1779 DestroyWindow(hTree2
);
1780 DestroyWindow(hTree
);
1782 /* the same, but initially created with TVS_CHECKBOXES */
1783 hTree
= create_treeview_control(0);
1785 himl
= (HIMAGELIST
)SendMessageA(hTree
, TVM_GETIMAGELIST
, TVSIL_STATE
, 0);
1786 ok(himl
== NULL
, "got %p\n", himl
);
1787 DestroyWindow(hTree
);
1789 hTree
= create_treeview_control(TVS_CHECKBOXES
);
1791 himl
= (HIMAGELIST
)SendMessageA(hTree
, TVM_GETIMAGELIST
, TVSIL_STATE
, 0);
1792 todo_wine
ok(himl
== NULL
, "got %p\n", himl
);
1795 item
.mask
= TVIF_STATE
;
1797 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1798 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1800 ok(item
.state
== INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item
.state
);
1802 item
.hItem
= hChild
;
1803 item
.mask
= TVIF_STATE
;
1805 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1806 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1808 ok(item
.state
== INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item
.state
);
1810 DestroyWindow(hTree
);
1813 static void test_TVM_GETNEXTITEM(void)
1818 hTree
= create_treeview_control(0);
1821 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_ROOT
, 0);
1822 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1824 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_ROOT
, (LPARAM
)TVI_ROOT
);
1825 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1827 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_ROOT
, (LPARAM
)hRoot
);
1828 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1830 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_ROOT
, (LPARAM
)hChild
);
1831 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1833 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_CHILD
, 0);
1834 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1836 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)hRoot
);
1837 ok(item
== hChild
, "got %p, expected %p\n", item
, hChild
);
1839 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)TVI_ROOT
);
1840 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1842 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_PARENT
, 0);
1843 ok(item
== NULL
, "got %p\n", item
);
1845 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_PARENT
, (LPARAM
)hChild
);
1846 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1848 DestroyWindow(hTree
);
1851 static void test_TVM_HITTEST(void)
1858 hTree
= create_treeview_control(0);
1861 *(HTREEITEM
*)&rc
= hRoot
;
1862 ret
= SendMessage(hTree
, TVM_GETITEMRECT
, TRUE
, (LPARAM
)&rc
);
1863 expect(TRUE
, (BOOL
)ret
);
1865 ht
.pt
.x
= rc
.left
-1;
1868 ret
= SendMessage(hTree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
1869 ok((HTREEITEM
)ret
== hRoot
, "got %p, expected %p\n", (HTREEITEM
)ret
, hRoot
);
1870 ok(ht
.hItem
== hRoot
, "got %p, expected %p\n", ht
.hItem
, hRoot
);
1871 ok(ht
.flags
== TVHT_ONITEMBUTTON
, "got %d, expected %d\n", ht
.flags
, TVHT_ONITEMBUTTON
);
1873 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)hRoot
);
1874 expect(TRUE
, (BOOL
)ret
);
1876 *(HTREEITEM
*)&rc
= hChild
;
1877 ret
= SendMessage(hTree
, TVM_GETITEMRECT
, TRUE
, (LPARAM
)&rc
);
1878 expect(TRUE
, (BOOL
)ret
);
1880 ht
.pt
.x
= rc
.left
-1;
1883 ret
= SendMessage(hTree
, TVM_HITTEST
, 0, (LPARAM
)&ht
);
1884 ok((HTREEITEM
)ret
== hChild
, "got %p, expected %p\n", (HTREEITEM
)ret
, hChild
);
1885 ok(ht
.hItem
== hChild
, "got %p, expected %p\n", ht
.hItem
, hChild
);
1886 /* Wine returns item button here, but this item has no button */
1887 todo_wine
ok(ht
.flags
== TVHT_ONITEMINDENT
, "got %d, expected %d\n", ht
.flags
, TVHT_ONITEMINDENT
);
1889 DestroyWindow(hTree
);
1892 START_TEST(treeview
)
1895 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
1899 ULONG_PTR ctx_cookie
;
1903 hComctl32
= GetModuleHandleA("comctl32.dll");
1904 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
1905 if (pInitCommonControlsEx
)
1907 INITCOMMONCONTROLSEX iccex
;
1908 iccex
.dwSize
= sizeof(iccex
);
1909 iccex
.dwICC
= ICC_TREEVIEW_CLASSES
;
1910 pInitCommonControlsEx(&iccex
);
1913 InitCommonControls();
1915 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
1916 init_msg_sequences(item_sequence
, 1);
1918 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1921 wc
.hInstance
= GetModuleHandleA(NULL
);
1923 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
1924 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1925 wc
.lpszMenuName
= NULL
;
1926 wc
.lpszClassName
= "MyTestWnd";
1927 wc
.lpfnWndProc
= parent_wnd_proc
;
1928 RegisterClassA(&wc
);
1930 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
1931 CW_USEDEFAULT
, CW_USEDEFAULT
, 130, 105, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1933 ok(hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n");
1934 if (!hMainWnd
) return;
1940 test_get_set_bkcolor();
1941 test_get_set_imagelist();
1942 test_get_set_indent();
1943 test_get_set_insertmark();
1944 test_get_set_item();
1945 test_get_set_itemheight();
1946 test_get_set_scrolltime();
1947 test_get_set_textcolor();
1948 test_get_linecolor();
1949 test_get_insertmarkcolor();
1950 test_get_set_tooltips();
1951 test_get_set_unicodeformat();
1953 test_expandinvisible();
1955 test_treeview_classinfo();
1956 test_expandnotify();
1957 test_TVS_SINGLEEXPAND();
1959 test_delete_items();
1961 test_htreeitem_layout();
1962 test_TVS_CHECKBOXES();
1963 test_TVM_GETNEXTITEM();
1966 if (!load_v6_module(&ctx_cookie
, &hCtx
))
1968 DestroyWindow(hMainWnd
);
1972 /* this is a XP SP3 failure workaround */
1973 hwnd
= CreateWindowExA(0, WC_TREEVIEW
, "foo",
1974 WS_CHILD
| WS_BORDER
| WS_VISIBLE
,
1976 hMainWnd
, NULL
, GetModuleHandleA(NULL
), NULL
);
1977 if (!IsWindow(hwnd
))
1979 win_skip("FIXME: failed to create TreeView window.\n");
1980 unload_v6_module(ctx_cookie
, hCtx
);
1981 DestroyWindow(hMainWnd
);
1985 DestroyWindow(hwnd
);
1987 /* comctl32 version 6 tests start here */
1988 test_expandedimage();
1989 test_htreeitem_layout();
1991 unload_v6_module(ctx_cookie
, hCtx
);
1993 PostMessageA(hMainWnd
, WM_CLOSE
, 0, 0);
1994 while(GetMessageA(&msg
, 0, 0, 0))
1996 TranslateMessage(&msg
);
1997 DispatchMessageA(&msg
);