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_singleexpand_seq
[] = {
208 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_SELCHANGINGA
},
209 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_SELCHANGEDA
},
210 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_SINGLEEXPAND
},
211 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_ITEMEXPANDINGA
},
212 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_ITEMEXPANDEDA
},
216 static const struct message parent_get_dispinfo_seq
[] = {
217 { WM_NOTIFY
, sent
|id
, 0, 0, TVN_GETDISPINFOA
},
221 static const struct message empty_seq
[] = {
225 static HWND hMainWnd
;
227 static HTREEITEM hRoot
, hChild
;
230 static char sequence
[256];
232 static void Clear(void)
238 static void AddItem(char ch
)
240 sequence
[pos
++] = ch
;
241 sequence
[pos
] = '\0';
244 static void IdentifyItem(HTREEITEM hItem
)
246 if (hItem
== hRoot
) {
250 if (hItem
== hChild
) {
261 /* This function hooks in and records all messages to the treeview control */
262 static LRESULT WINAPI
TreeviewWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
264 static LONG defwndproc_counter
= 0;
267 WNDPROC lpOldProc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
269 msg
.message
= message
;
270 msg
.flags
= sent
|wparam
|lparam
;
271 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
274 add_message(sequences
, TREEVIEW_SEQ_INDEX
, &msg
);
276 defwndproc_counter
++;
277 ret
= CallWindowProcA(lpOldProc
, hwnd
, message
, wParam
, lParam
);
278 defwndproc_counter
--;
283 static HWND
create_treeview_control(DWORD style
)
288 hTree
= CreateWindowExA(WS_EX_CLIENTEDGE
, WC_TREEVIEWA
, NULL
, WS_CHILD
|WS_VISIBLE
|
289 TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_EDITLABELS
|style
,
290 0, 0, 120, 100, hMainWnd
, (HMENU
)100, GetModuleHandleA(0), 0);
294 /* Record the old WNDPROC so we can call it after recording the messages */
295 pOldWndProc
= (WNDPROC
)SetWindowLongPtrA(hTree
, GWLP_WNDPROC
, (LONG_PTR
)TreeviewWndProc
);
296 SetWindowLongPtrA(hTree
, GWLP_USERDATA
, (LONG_PTR
)pOldWndProc
);
301 static void fill_tree(HWND hTree
)
304 static CHAR root
[] = "Root",
307 ins
.hParent
= TVI_ROOT
;
308 ins
.hInsertAfter
= TVI_ROOT
;
309 U(ins
).item
.mask
= TVIF_TEXT
;
310 U(ins
).item
.pszText
= root
;
311 hRoot
= TreeView_InsertItem(hTree
, &ins
);
314 ins
.hInsertAfter
= TVI_FIRST
;
315 U(ins
).item
.mask
= TVIF_TEXT
;
316 U(ins
).item
.pszText
= child
;
317 hChild
= TreeView_InsertItem(hTree
, &ins
);
320 static void test_fillroot(void)
325 hTree
= create_treeview_control(0);
327 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
337 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, FillRootSeq
, "FillRoot", FALSE
);
338 ok(!strcmp(sequence
, "AB."), "Item creation\n");
340 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
342 tvi
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
343 SendMessage( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tvi
);
344 ok(tvi
.iImage
== 0, "tvi.iImage=%d\n", tvi
.iImage
);
345 ok(tvi
.iSelectedImage
== 0, "tvi.iSelectedImage=%d\n", tvi
.iSelectedImage
);
347 DestroyWindow(hTree
);
350 static void test_callback(void)
353 HTREEITEM hItem1
, hItem2
;
356 CHAR test_string
[] = "Test_string";
357 static const CHAR test2A
[] = "TEST2";
362 hTree
= create_treeview_control(0);
364 ret
= TreeView_DeleteAllItems(hTree
);
366 ins
.hParent
= TVI_ROOT
;
367 ins
.hInsertAfter
= TVI_ROOT
;
368 U(ins
).item
.mask
= TVIF_TEXT
;
369 U(ins
).item
.pszText
= LPSTR_TEXTCALLBACK
;
370 hRoot
= TreeView_InsertItem(hTree
, &ins
);
374 tvi
.mask
= TVIF_TEXT
;
376 tvi
.cchTextMax
= sizeof(buf
)/sizeof(buf
[0]);
377 ret
= TreeView_GetItem(hTree
, &tvi
);
379 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Callback item text mismatch %s vs %s\n",
380 tvi
.pszText
, TEST_CALLBACK_TEXT
);
383 ins
.hInsertAfter
= TVI_FIRST
;
384 U(ins
).item
.mask
= TVIF_TEXT
;
385 U(ins
).item
.pszText
= test_string
;
386 hItem1
= TreeView_InsertItem(hTree
, &ins
);
390 ret
= TreeView_GetItem(hTree
, &tvi
);
392 ok(strcmp(tvi
.pszText
, test_string
) == 0, "Item text mismatch %s vs %s\n",
393 tvi
.pszText
, test_string
);
395 /* undocumented: pszText of NULL also means LPSTR_CALLBACK: */
397 ret
= TreeView_SetItem(hTree
, &tvi
);
400 ret
= TreeView_GetItem(hTree
, &tvi
);
402 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
403 tvi
.pszText
, TEST_CALLBACK_TEXT
);
405 U(ins
).item
.pszText
= NULL
;
406 hItem2
= TreeView_InsertItem(hTree
, &ins
);
409 memset(buf
, 0, sizeof(buf
));
410 ret
= TreeView_GetItem(hTree
, &tvi
);
412 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
413 tvi
.pszText
, TEST_CALLBACK_TEXT
);
415 /* notification handler changed A->W */
416 g_disp_A_to_W
= TRUE
;
418 memset(buf
, 0, sizeof(buf
));
419 ret
= TreeView_GetItem(hTree
, &tvi
);
421 ok(strcmp(tvi
.pszText
, test2A
) == 0, "got %s, expected %s\n",
422 tvi
.pszText
, test2A
);
423 g_disp_A_to_W
= FALSE
;
425 /* handler changes state image index */
426 SetWindowLongA(hTree
, GWL_STYLE
, GetWindowLongA(hTree
, GWL_STYLE
) | TVS_CHECKBOXES
);
428 /* clear selection, handler will set selected state */
429 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, 0);
432 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
435 tvi
.mask
= TVIF_STATE
;
436 tvi
.state
= TVIS_SELECTED
;
437 ret
= TreeView_GetItem(hTree
, &tvi
);
439 ok(tvi
.state
== INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", tvi
.state
);
441 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
,
442 "no TVN_GETDISPINFO for a state seq", FALSE
);
445 tvi
.mask
= TVIF_IMAGE
| TVIF_STATE
;
446 tvi
.state
= TVIS_FOCUSED
;
447 tvi
.stateMask
= TVIS_FOCUSED
;
448 tvi
.iImage
= I_IMAGECALLBACK
;
449 ret
= TreeView_SetItem(hTree
, &tvi
);
452 /* ask for item image index through callback - state is also set with state image index */
453 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
456 tvi
.mask
= TVIF_IMAGE
;
458 ret
= TreeView_GetItem(hTree
, &tvi
);
460 ok(tvi
.state
== (INDEXTOSTATEIMAGEMASK(1) | TVIS_FOCUSED
), "got 0x%x\n", tvi
.state
);
462 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_get_dispinfo_seq
,
463 "callback for state/overlay image index, noop seq", FALSE
);
465 /* ask for image again and overwrite state to some value in handler */
466 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
468 g_disp_set_stateimage
= TRUE
;
470 tvi
.mask
= TVIF_IMAGE
;
471 tvi
.state
= INDEXTOSTATEIMAGEMASK(1);
473 ret
= TreeView_GetItem(hTree
, &tvi
);
475 /* handler sets TVIS_SELECTED as well */
476 ok(tvi
.state
== (TVIS_FOCUSED
| TVIS_SELECTED
| INDEXTOSTATEIMAGEMASK(2) | INDEXTOOVERLAYMASK(3)), "got 0x%x\n", tvi
.state
);
477 g_disp_set_stateimage
= FALSE
;
479 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_get_dispinfo_seq
,
480 "callback for state/overlay image index seq", FALSE
);
482 DestroyWindow(hTree
);
485 static void test_select(void)
490 hTree
= create_treeview_control(0);
493 /* root-none select tests */
494 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
495 r
= TreeView_SelectItem(hTree
, NULL
);
499 r
= TreeView_SelectItem(hTree
, hRoot
);
502 r
= TreeView_SelectItem(hTree
, hRoot
);
505 r
= TreeView_SelectItem(hTree
, NULL
);
508 r
= TreeView_SelectItem(hTree
, NULL
);
511 r
= TreeView_SelectItem(hTree
, hRoot
);
514 ok(!strcmp(sequence
, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
515 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, rootnone_select_seq
,
516 "root-none select seq", FALSE
);
518 /* root-child select tests */
519 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
520 r
= TreeView_SelectItem(hTree
, NULL
);
525 r
= TreeView_SelectItem(hTree
, hRoot
);
528 r
= TreeView_SelectItem(hTree
, hRoot
);
531 r
= TreeView_SelectItem(hTree
, hChild
);
534 r
= TreeView_SelectItem(hTree
, hChild
);
537 r
= TreeView_SelectItem(hTree
, hRoot
);
540 ok(!strcmp(sequence
, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
541 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, rootchild_select_seq
,
542 "root-child select seq", FALSE
);
544 DestroyWindow(hTree
);
547 static void test_getitemtext(void)
554 CHAR szBuffer
[80] = "Blah";
555 int nBufferSize
= sizeof(szBuffer
)/sizeof(CHAR
);
557 hTree
= create_treeview_control(0);
560 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
562 /* add an item without TVIF_TEXT mask and pszText == NULL */
564 ins
.hInsertAfter
= TVI_ROOT
;
565 U(ins
).item
.mask
= 0;
566 U(ins
).item
.pszText
= NULL
;
567 U(ins
).item
.cchTextMax
= 0;
568 hChild
= TreeView_InsertItem(hTree
, &ins
);
571 /* retrieve it with TVIF_TEXT mask */
573 tvi
.mask
= TVIF_TEXT
;
574 tvi
.cchTextMax
= nBufferSize
;
575 tvi
.pszText
= szBuffer
;
577 SendMessageA( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tvi
);
578 ok(!strcmp(szBuffer
, ""), "szBuffer=\"%s\", expected \"\"\n", szBuffer
);
579 ok(SendMessageA(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hChild
), "DeleteItem failed\n");
580 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, getitemtext_seq
, "get item text seq", FALSE
);
582 DestroyWindow(hTree
);
585 static void test_focus(void)
588 static CHAR child1
[] = "Edit",
589 child2
[] = "A really long string";
590 HTREEITEM hChild1
, hChild2
;
594 hTree
= create_treeview_control(0);
597 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
599 /* This test verifies that when a label is being edited, scrolling
600 * the treeview does not cause the label to lose focus. To test
601 * this, first some additional entries are added to generate
605 ins
.hInsertAfter
= hChild
;
606 U(ins
).item
.mask
= TVIF_TEXT
;
607 U(ins
).item
.pszText
= child1
;
608 hChild1
= TreeView_InsertItem(hTree
, &ins
);
610 ins
.hInsertAfter
= hChild1
;
611 U(ins
).item
.mask
= TVIF_TEXT
;
612 U(ins
).item
.pszText
= child2
;
613 hChild2
= TreeView_InsertItem(hTree
, &ins
);
616 ShowWindow(hMainWnd
,SW_SHOW
);
617 SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hChild
);
618 hEdit
= TreeView_EditLabel(hTree
, hChild
);
619 ScrollWindowEx(hTree
, -10, 0, NULL
, NULL
, NULL
, NULL
, SW_SCROLLCHILDREN
);
620 ok(GetFocus() == hEdit
, "Edit control should have focus\n");
621 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, focus_seq
, "focus test", TRUE
);
623 DestroyWindow(hTree
);
626 static void test_get_set_bkcolor(void)
628 COLORREF crColor
= RGB(0,0,0);
631 hTree
= create_treeview_control(0);
634 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
636 /* If the value is -1, the control is using the system color for the background color. */
637 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
638 ok(crColor
== ~0u, "Default background color reported as 0x%.8x\n", crColor
);
640 /* Test for black background */
641 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, RGB(0,0,0) );
642 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
643 ok(crColor
== RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor
);
645 /* Test for white background */
646 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, RGB(255,255,255) );
647 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
648 ok(crColor
== RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor
);
650 /* Reset the default background */
651 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, -1 );
653 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_bkcolor_seq
,
654 "test get set bkcolor", FALSE
);
656 DestroyWindow(hTree
);
659 static void test_get_set_imagelist(void)
664 hTree
= create_treeview_control(0);
667 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
669 /* Test a NULL HIMAGELIST */
670 SendMessage( hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, 0 );
671 himl
= (HIMAGELIST
)SendMessage( hTree
, TVM_GETIMAGELIST
, TVSIL_NORMAL
, 0 );
672 ok(himl
== NULL
, "NULL image list, reported as %p, expected 0.\n", himl
);
674 /* TODO: Test an actual image list */
676 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_imagelist_seq
,
677 "test get imagelist", FALSE
);
679 DestroyWindow(hTree
);
682 static void test_get_set_indent(void)
685 int ulMinIndent
= -1;
686 int ulMoreThanTwiceMin
= -1;
689 hTree
= create_treeview_control(0);
692 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
694 /* Finding the minimum indent */
695 SendMessage( hTree
, TVM_SETINDENT
, 0, 0 );
696 ulMinIndent
= (int)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
698 /* Checking an indent that is more than twice the default indent */
699 ulMoreThanTwiceMin
= 2*ulMinIndent
+1;
700 SendMessage( hTree
, TVM_SETINDENT
, ulMoreThanTwiceMin
, 0 );
701 ulIndent
= (DWORD
)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
702 ok(ulIndent
== ulMoreThanTwiceMin
, "Indent reported as %d, expected %d\n", ulIndent
, ulMoreThanTwiceMin
);
704 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_indent_seq
,
705 "test get set indent", FALSE
);
707 DestroyWindow(hTree
);
710 static void test_get_set_insertmark(void)
712 COLORREF crColor
= RGB(0,0,0);
715 hTree
= create_treeview_control(0);
718 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
720 SendMessage( hTree
, TVM_SETINSERTMARKCOLOR
, 0, crColor
);
721 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0 );
722 ok(crColor
== RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor
);
724 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_insertmarkcolor_seq
,
725 "test get set insertmark color", FALSE
);
727 DestroyWindow(hTree
);
730 static void test_get_set_item(void)
732 TVITEMA tviRoot
= {0};
733 int nBufferSize
= 80;
734 char szBuffer
[80] = {0};
738 hTree
= create_treeview_control(0);
741 tviRoot
.hItem
= hRoot
;
742 tviRoot
.mask
= TVIF_STATE
;
743 tviRoot
.state
= TVIS_FOCUSED
;
744 tviRoot
.stateMask
= TVIS_FOCUSED
;
745 ret
= SendMessage( hTree
, TVM_SETITEMA
, 0, (LPARAM
)&tviRoot
);
748 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
750 /* Test the root item, state is set even when not requested */
751 tviRoot
.hItem
= hRoot
;
752 tviRoot
.mask
= TVIF_TEXT
;
754 tviRoot
.stateMask
= 0;
755 tviRoot
.cchTextMax
= nBufferSize
;
756 tviRoot
.pszText
= szBuffer
;
757 ret
= SendMessage( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tviRoot
);
759 ok(!strcmp("Root", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer
);
760 ok(tviRoot
.state
== TVIS_FOCUSED
, "got 0x%0x\n", tviRoot
.state
);
762 /* Change the root text */
763 strncpy(szBuffer
, "Testing123", nBufferSize
);
764 ret
= SendMessage( hTree
, TVM_SETITEMA
, 0, (LPARAM
)&tviRoot
);
766 memset(szBuffer
, 0, nBufferSize
);
767 ret
= SendMessage( hTree
, TVM_GETITEMA
, 0, (LPARAM
)&tviRoot
);
769 ok(!strcmp("Testing123", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer
);
771 /* Reset the root text */
772 memset(szBuffer
, 0, nBufferSize
);
773 strncpy(szBuffer
, "Root", nBufferSize
);
774 ret
= SendMessage( hTree
, TVM_SETITEMA
, 0, (LPARAM
)&tviRoot
);
777 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_item_seq
,
778 "test get set item", FALSE
);
780 DestroyWindow(hTree
);
783 static void test_get_set_itemheight(void)
789 hTree
= create_treeview_control(0);
792 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
794 /* Assuming default height to begin with */
795 ulOldHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
797 /* Explicitly setting and getting the default height */
798 SendMessage( hTree
, TVM_SETITEMHEIGHT
, -1, 0 );
799 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
800 ok(ulNewHeight
== ulOldHeight
, "Default height not set properly, reported %d, expected %d\n", ulNewHeight
, ulOldHeight
);
802 /* Explicitly setting and getting the height of twice the normal */
803 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 2*ulOldHeight
, 0 );
804 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
805 ok(ulNewHeight
== 2*ulOldHeight
, "New height not set properly, reported %d, expected %d\n", ulNewHeight
, 2*ulOldHeight
);
807 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
808 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 9, 0 );
809 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
810 ok(ulNewHeight
== 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight
, 8);
812 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_itemheight_seq
,
813 "test get set item height", FALSE
);
815 /* without TVS_NONEVENHEIGHT */
816 SetWindowLong(hTree
, GWL_STYLE
, GetWindowLong(hTree
, GWL_STYLE
) & ~TVS_NONEVENHEIGHT
);
818 ulOldHeight
= SendMessage( hTree
, TVM_SETITEMHEIGHT
, 3, 0);
819 ok(ulOldHeight
== 8, "got %d, expected %d\n", ulOldHeight
, 8);
820 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
821 ok(ulNewHeight
== 2, "got %d, expected %d\n", ulNewHeight
, 2);
823 ulOldHeight
= SendMessage( hTree
, TVM_SETITEMHEIGHT
, 4, 0);
824 ok(ulOldHeight
== 2, "got %d, expected %d\n", ulOldHeight
, 2);
825 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
826 ok(ulNewHeight
== 4, "got %d, expected %d\n", ulNewHeight
, 4);
828 /* with TVS_NONEVENHEIGHT */
829 SetWindowLong(hTree
, GWL_STYLE
, GetWindowLong(hTree
, GWL_STYLE
) | TVS_NONEVENHEIGHT
);
831 ulOldHeight
= SendMessage( hTree
, TVM_SETITEMHEIGHT
, 3, 0);
832 ok(ulOldHeight
== 4, "got %d, expected %d\n", ulOldHeight
, 4);
833 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
834 ok(ulNewHeight
== 3, "got %d, expected %d\n", ulNewHeight
, 3);
836 ulOldHeight
= SendMessage( hTree
, TVM_SETITEMHEIGHT
, 10, 0);
837 ok(ulOldHeight
== 3, "got %d, expected %d\n", ulOldHeight
, 3);
838 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
839 ok(ulNewHeight
== 10, "got %d, expected %d\n", ulNewHeight
, 10);
841 DestroyWindow(hTree
);
844 static void test_get_set_scrolltime(void)
846 int ulExpectedTime
= 20;
850 hTree
= create_treeview_control(0);
853 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
855 SendMessage( hTree
, TVM_SETSCROLLTIME
, ulExpectedTime
, 0 );
856 ulTime
= (int)SendMessage( hTree
, TVM_GETSCROLLTIME
, 0, 0 );
857 ok(ulTime
== ulExpectedTime
, "Scroll time reported as %d, expected %d\n", ulTime
, ulExpectedTime
);
859 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_scrolltime_seq
,
860 "test get set scroll time", FALSE
);
862 DestroyWindow(hTree
);
865 static void test_get_set_textcolor(void)
867 /* If the value is -1, the control is using the system color for the text color. */
868 COLORREF crColor
= RGB(0,0,0);
871 hTree
= create_treeview_control(0);
874 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
876 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
877 ok(crColor
== ~0u, "Default text color reported as 0x%.8x\n", crColor
);
879 /* Test for black text */
880 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, RGB(0,0,0) );
881 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
882 ok(crColor
== RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor
);
884 /* Test for white text */
885 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, RGB(255,255,255) );
886 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
887 ok(crColor
== RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor
);
889 /* Reset the default text color */
890 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, CLR_NONE
);
892 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_textcolor_seq
,
893 "test get set text color", FALSE
);
895 DestroyWindow(hTree
);
898 static void test_get_set_tooltips(void)
900 HWND hwndLastToolTip
= NULL
;
904 hTree
= create_treeview_control(0);
907 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
909 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
910 hPopupTreeView
= CreateWindow(WC_TREEVIEW
, NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 100, 100, hMainWnd
, NULL
, NULL
, NULL
);
911 DestroyWindow(hPopupTreeView
);
913 /* Testing setting a NULL ToolTip */
914 SendMessage( hTree
, TVM_SETTOOLTIPS
, 0, 0 );
915 hwndLastToolTip
= (HWND
)SendMessage( hTree
, TVM_GETTOOLTIPS
, 0, 0 );
916 ok(hwndLastToolTip
== NULL
, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip
);
918 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_tooltips_seq
,
919 "test get set tooltips", TRUE
);
921 /* TODO: Add a test of an actual tooltip */
922 DestroyWindow(hTree
);
925 static void test_get_set_unicodeformat(void)
927 BOOL bPreviousSetting
= 0;
928 BOOL bNewSetting
= 0;
931 hTree
= create_treeview_control(0);
934 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
937 bPreviousSetting
= (BOOL
)SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 1, 0 );
938 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
939 ok(bNewSetting
== 1, "Unicode setting did not work.\n");
942 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 0, 0 );
943 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
944 ok(bNewSetting
== 0, "ANSI setting did not work.\n");
946 /* Revert to original setting */
947 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, bPreviousSetting
, 0 );
949 ok_sequence(sequences
, TREEVIEW_SEQ_INDEX
, test_get_set_unicodeformat_seq
,
950 "test get set unicode format", FALSE
);
952 DestroyWindow(hTree
);
955 static LRESULT CALLBACK
parent_wnd_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
957 static LONG defwndproc_counter
= 0;
961 HTREEITEM visibleItem
;
963 msg
.message
= message
;
964 msg
.flags
= sent
|wparam
|lparam
;
965 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
968 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
970 /* log system messages, except for painting */
971 if (message
< WM_USER
&&
972 message
!= WM_PAINT
&&
973 message
!= WM_ERASEBKGND
&&
974 message
!= WM_NCPAINT
&&
975 message
!= WM_NCHITTEST
&&
976 message
!= WM_GETTEXT
&&
977 message
!= WM_GETICON
&&
978 message
!= WM_DEVICECHANGE
)
980 trace("parent: %p, %04x, %08lx, %08lx\n", hWnd
, message
, wParam
, lParam
);
981 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
987 NMHDR
*pHdr
= (NMHDR
*)lParam
;
989 ok(pHdr
->code
!= NM_TOOLTIPSCREATED
, "Treeview should not send NM_TOOLTIPSCREATED\n");
990 if (pHdr
->idFrom
== 100)
992 NMTREEVIEWA
*pTreeView
= (LPNMTREEVIEWA
) lParam
;
995 case TVN_SELCHANGINGA
:
997 IdentifyItem(pTreeView
->itemOld
.hItem
);
998 IdentifyItem(pTreeView
->itemNew
.hItem
);
1000 case TVN_SELCHANGEDA
:
1002 IdentifyItem(pTreeView
->itemOld
.hItem
);
1003 IdentifyItem(pTreeView
->itemNew
.hItem
);
1005 case TVN_GETDISPINFOA
: {
1006 NMTVDISPINFOA
*disp
= (NMTVDISPINFOA
*)lParam
;
1007 if (disp
->item
.mask
& TVIF_TEXT
) {
1008 lstrcpyn(disp
->item
.pszText
, TEST_CALLBACK_TEXT
, disp
->item
.cchTextMax
);
1011 if (g_disp_A_to_W
&& (disp
->item
.mask
& TVIF_TEXT
)) {
1012 static const WCHAR testW
[] = {'T','E','S','T','2',0};
1014 disp
->hdr
.code
= TVN_GETDISPINFOW
;
1015 memcpy(disp
->item
.pszText
, testW
, sizeof(testW
));
1018 if (g_disp_set_stateimage
)
1020 ok(disp
->item
.mask
== TVIF_IMAGE
, "got %x\n", disp
->item
.mask
);
1021 /* both masks set here are necessary to change state bits */
1022 disp
->item
.mask
|= TVIF_STATE
;
1023 disp
->item
.state
= TVIS_SELECTED
| INDEXTOSTATEIMAGEMASK(2) | INDEXTOOVERLAYMASK(3);
1024 disp
->item
.stateMask
= TVIS_SELECTED
| TVIS_OVERLAYMASK
| TVIS_STATEIMAGEMASK
;
1029 case TVN_BEGINLABELEDIT
:
1031 if (g_beginedit_alter_text
)
1033 static const char* textA
= "<edittextaltered>";
1036 edit
= (HWND
)SendMessageA(pHdr
->hwndFrom
, TVM_GETEDITCONTROL
, 0, 0);
1037 ok(IsWindow(edit
), "failed to get edit handle\n");
1038 SetWindowTextA(edit
, textA
);
1044 case TVN_ENDLABELEDIT
: return TRUE
;
1045 case TVN_ITEMEXPANDINGA
:
1046 ok(pTreeView
->itemNew
.mask
==
1047 (TVIF_HANDLE
| TVIF_SELECTEDIMAGE
| TVIF_IMAGE
| TVIF_PARAM
| TVIF_STATE
),
1048 "got wrong mask %x\n", pTreeView
->itemNew
.mask
);
1049 ok((pTreeView
->itemNew
.state
& TVIS_EXPANDED
) == 0,
1050 "got wrong state %x\n", pTreeView
->itemNew
.state
);
1051 ok(pTreeView
->itemOld
.mask
== 0,
1052 "got wrong mask %x\n", pTreeView
->itemOld
.mask
);
1054 if (g_get_from_expand
)
1056 g_item_expanding
.mask
= TVIF_STATE
;
1057 g_item_expanding
.hItem
= hRoot
;
1058 ret
= SendMessageA(pHdr
->hwndFrom
, TVM_GETITEMA
, 0, (LPARAM
)&g_item_expanding
);
1059 ok(ret
== TRUE
, "got %lu\n", ret
);
1062 case TVN_ITEMEXPANDEDA
:
1063 ok(pTreeView
->itemNew
.mask
& TVIF_STATE
, "got wrong mask %x\n", pTreeView
->itemNew
.mask
);
1064 ok(pTreeView
->itemNew
.state
& (TVIS_EXPANDED
|TVIS_EXPANDEDONCE
),
1065 "got wrong mask %x\n", pTreeView
->itemNew
.mask
);
1066 ok(pTreeView
->itemOld
.mask
== 0,
1067 "got wrong mask %x\n", pTreeView
->itemOld
.mask
);
1069 if (g_get_from_expand
)
1071 g_item_expanded
.mask
= TVIF_STATE
;
1072 g_item_expanded
.hItem
= hRoot
;
1073 ret
= SendMessageA(pHdr
->hwndFrom
, TVM_GETITEMA
, 0, (LPARAM
)&g_item_expanded
);
1074 ok(ret
== TRUE
, "got %lu\n", ret
);
1076 if (g_get_rect_in_expand
)
1078 visibleItem
= TreeView_GetNextItem(pHdr
->hwndFrom
, NULL
, TVGN_FIRSTVISIBLE
);
1079 ok(pTreeView
->itemNew
.hItem
== visibleItem
, "expanded item == first visible item\n");
1080 *(HTREEITEM
*)&rect
= visibleItem
;
1081 ok(SendMessage(pHdr
->hwndFrom
, TVM_GETITEMRECT
, TRUE
, (LPARAM
)&rect
), "Failed to get rect for first visible item.\n");
1082 visibleItem
= TreeView_GetNextItem(pHdr
->hwndFrom
, visibleItem
, TVGN_NEXTVISIBLE
);
1083 *(HTREEITEM
*)&rect
= visibleItem
;
1084 ok(visibleItem
!= NULL
, "There must be a visible item after the first visisble item.\n");
1085 ok(SendMessage(pHdr
->hwndFrom
, TVM_GETITEMRECT
, TRUE
, (LPARAM
)&rect
), "Failed to get rect for second visible item.\n");
1088 case TVN_DELETEITEMA
:
1090 struct message item
;
1092 ok(pTreeView
->itemNew
.mask
== 0, "got wrong mask 0x%x\n", pTreeView
->itemNew
.mask
);
1094 ok(pTreeView
->itemOld
.mask
== (TVIF_HANDLE
| TVIF_PARAM
), "got wrong mask 0x%x\n", pTreeView
->itemOld
.mask
);
1095 ok(pTreeView
->itemOld
.hItem
!= NULL
, "got %p\n", pTreeView
->itemOld
.hItem
);
1097 memset(&item
, 0, sizeof(item
));
1098 item
.lParam
= (LPARAM
)pTreeView
->itemOld
.hItem
;
1099 add_message(item_sequence
, 0, &item
);
1113 defwndproc_counter
++;
1114 ret
= DefWindowProcA(hWnd
, message
, wParam
, lParam
);
1115 defwndproc_counter
--;
1120 static void test_expandinvisible(void)
1122 static CHAR nodeText
[][5] = {"0", "1", "2", "3", "4"};
1123 TVINSERTSTRUCTA ins
;
1130 hTree
= create_treeview_control(0);
1132 /* The test builds the following tree and expands node 1, while node 0 is collapsed.
1142 ret
= TreeView_DeleteAllItems(hTree
);
1143 ok(ret
== TRUE
, "ret\n");
1144 ins
.hParent
= TVI_ROOT
;
1145 ins
.hInsertAfter
= TVI_ROOT
;
1146 U(ins
).item
.mask
= TVIF_TEXT
;
1147 U(ins
).item
.pszText
= nodeText
[0];
1148 node
[0] = TreeView_InsertItem(hTree
, &ins
);
1151 ins
.hInsertAfter
= TVI_LAST
;
1152 U(ins
).item
.mask
= TVIF_TEXT
;
1153 ins
.hParent
= node
[0];
1155 U(ins
).item
.pszText
= nodeText
[1];
1156 node
[1] = TreeView_InsertItem(hTree
, &ins
);
1158 U(ins
).item
.pszText
= nodeText
[4];
1159 node
[4] = TreeView_InsertItem(hTree
, &ins
);
1162 ins
.hParent
= node
[1];
1164 U(ins
).item
.pszText
= nodeText
[2];
1165 node
[2] = TreeView_InsertItem(hTree
, &ins
);
1167 U(ins
).item
.pszText
= nodeText
[3];
1168 node
[3] = TreeView_InsertItem(hTree
, &ins
);
1172 nodeVisible
= TreeView_GetItemRect(hTree
, node
[1], &dummyRect
, FALSE
);
1173 ok(!nodeVisible
, "Node 1 should not be visible.\n");
1174 nodeVisible
= TreeView_GetItemRect(hTree
, node
[2], &dummyRect
, FALSE
);
1175 ok(!nodeVisible
, "Node 2 should not be visible.\n");
1176 nodeVisible
= TreeView_GetItemRect(hTree
, node
[3], &dummyRect
, FALSE
);
1177 ok(!nodeVisible
, "Node 3 should not be visible.\n");
1178 nodeVisible
= TreeView_GetItemRect(hTree
, node
[4], &dummyRect
, FALSE
);
1179 ok(!nodeVisible
, "Node 4 should not be visible.\n");
1181 ok(TreeView_Expand(hTree
, node
[1], TVE_EXPAND
), "Expand of node 1 failed.\n");
1183 nodeVisible
= TreeView_GetItemRect(hTree
, node
[1], &dummyRect
, FALSE
);
1184 ok(!nodeVisible
, "Node 1 should not be visible.\n");
1185 nodeVisible
= TreeView_GetItemRect(hTree
, node
[2], &dummyRect
, FALSE
);
1186 ok(!nodeVisible
, "Node 2 should not be visible.\n");
1187 nodeVisible
= TreeView_GetItemRect(hTree
, node
[3], &dummyRect
, FALSE
);
1188 ok(!nodeVisible
, "Node 3 should not be visible.\n");
1189 nodeVisible
= TreeView_GetItemRect(hTree
, node
[4], &dummyRect
, FALSE
);
1190 ok(!nodeVisible
, "Node 4 should not be visible.\n");
1192 DestroyWindow(hTree
);
1195 static void test_itemedit(void)
1203 hTree
= create_treeview_control(0);
1206 /* try with null item */
1207 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABELA
, 0, 0);
1208 ok(!IsWindow(edit
), "Expected valid handle\n");
1211 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABELA
, 0, (LPARAM
)hRoot
);
1212 ok(IsWindow(edit
), "Expected valid handle\n");
1213 /* item shouldn't be selected automatically after TVM_EDITLABEL */
1214 r
= SendMessage(hTree
, TVM_GETITEMSTATE
, (WPARAM
)hRoot
, TVIS_SELECTED
);
1216 /* try to cancel with wrong edit handle */
1217 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), 0);
1219 ok(IsWindow(edit
), "Expected edit control to be valid\n");
1220 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1222 ok(!IsWindow(edit
), "Expected edit control to be destroyed\n");
1223 /* try to cancel without creating edit */
1224 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), 0);
1227 /* try to cancel with wrong (not null) handle */
1228 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABELA
, 0, (LPARAM
)hRoot
);
1229 ok(IsWindow(edit
), "Expected valid handle\n");
1230 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)hTree
);
1232 ok(IsWindow(edit
), "Expected edit control to be valid\n");
1233 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1236 /* remove selection after starting edit */
1237 r
= TreeView_SelectItem(hTree
, hRoot
);
1239 edit
= (HWND
)SendMessage(hTree
, TVM_EDITLABELA
, 0, (LPARAM
)hRoot
);
1240 ok(IsWindow(edit
), "Expected valid handle\n");
1241 r
= TreeView_SelectItem(hTree
, NULL
);
1245 r
= SendMessage(edit
, WM_SETTEXT
, 0, (LPARAM
)buffA
);
1247 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1249 ok(!IsWindow(edit
), "Expected edit control to be destroyed\n");
1250 /* check that text is saved */
1251 item
.mask
= TVIF_TEXT
;
1253 item
.pszText
= buffA
;
1254 item
.cchTextMax
= sizeof(buffA
)/sizeof(CHAR
);
1255 r
= SendMessage(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1257 ok(!strcmp("x", buffA
), "Expected item text to change\n");
1259 /* try A/W messages */
1260 edit
= (HWND
)SendMessageA(hTree
, TVM_EDITLABELA
, 0, (LPARAM
)hRoot
);
1261 ok(IsWindow(edit
), "Expected valid handle\n");
1262 ok(IsWindowUnicode(edit
), "got ansi window\n");
1263 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1265 ok(!IsWindow(edit
), "expected invalid handle\n");
1267 edit
= (HWND
)SendMessageA(hTree
, TVM_EDITLABELW
, 0, (LPARAM
)hRoot
);
1268 ok(IsWindow(edit
), "Expected valid handle\n");
1269 ok(IsWindowUnicode(edit
), "got ansi window\n");
1270 r
= SendMessage(hTree
, WM_COMMAND
, MAKEWPARAM(0, EN_KILLFOCUS
), (LPARAM
)edit
);
1273 /* alter text during TVM_BEGINLABELEDIT, check that it's preserved */
1274 strcpy(buffA
, "<root>");
1276 item
.mask
= TVIF_TEXT
;
1278 item
.pszText
= buffA
;
1279 item
.cchTextMax
= 0;
1280 r
= SendMessage(hTree
, TVM_SETITEMA
, 0, (LPARAM
)&item
);
1283 g_beginedit_alter_text
= TRUE
;
1284 edit
= (HWND
)SendMessageA(hTree
, TVM_EDITLABELA
, 0, (LPARAM
)hRoot
);
1285 ok(IsWindow(edit
), "Expected valid handle\n");
1286 g_beginedit_alter_text
= FALSE
;
1288 GetWindowTextA(edit
, buffA
, sizeof(buffA
)/sizeof(CHAR
));
1289 ok(!strcmp(buffA
, "<edittextaltered>"), "got string %s\n", buffA
);
1291 DestroyWindow(hTree
);
1294 static void test_treeview_classinfo(void)
1298 memset(&cls
, 0, sizeof(cls
));
1299 GetClassInfo(GetModuleHandleA("comctl32.dll"), WC_TREEVIEWA
, &cls
);
1300 ok(cls
.hbrBackground
== NULL
, "Expected NULL background brush, got %p\n", cls
.hbrBackground
);
1301 ok(cls
.style
== (CS_GLOBALCLASS
| CS_DBLCLKS
), "Expected got %x\n", cls
.style
);
1302 expect(0, cls
.cbClsExtra
);
1305 static void test_get_linecolor(void)
1310 hTree
= create_treeview_control(0);
1312 /* newly created control has default color */
1313 clr
= (COLORREF
)SendMessage(hTree
, TVM_GETLINECOLOR
, 0, 0);
1315 win_skip("TVM_GETLINECOLOR is not supported on comctl32 < 5.80\n");
1317 expect(CLR_DEFAULT
, clr
);
1319 DestroyWindow(hTree
);
1322 static void test_get_insertmarkcolor(void)
1327 hTree
= create_treeview_control(0);
1329 /* newly created control has default color */
1330 clr
= (COLORREF
)SendMessage(hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0);
1332 win_skip("TVM_GETINSERTMARKCOLOR is not supported on comctl32 < 5.80\n");
1334 expect(CLR_DEFAULT
, clr
);
1336 DestroyWindow(hTree
);
1339 static void test_expandnotify(void)
1345 hTree
= create_treeview_control(0);
1349 item
.mask
= TVIF_STATE
;
1351 item
.state
= TVIS_EXPANDED
;
1352 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1354 ok((item
.state
& TVIS_EXPANDED
) == 0, "expected collapsed\n");
1356 /* preselect root node here */
1357 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hRoot
);
1360 g_get_from_expand
= TRUE
;
1362 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1363 g_item_expanding
.state
= 0xdeadbeef;
1364 g_item_expanded
.state
= 0xdeadbeef;
1365 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)hRoot
);
1367 ok(g_item_expanding
.state
== TVIS_SELECTED
, "got state on TVN_ITEMEXPANDING 0x%08x\n",
1368 g_item_expanding
.state
);
1369 ok(g_item_expanded
.state
== (TVIS_SELECTED
|TVIS_EXPANDED
), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1370 g_item_expanded
.state
);
1371 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_expand_seq
, "expand notifications", FALSE
);
1372 g_get_from_expand
= FALSE
;
1374 /* check that it's expanded */
1375 item
.state
= TVIS_EXPANDED
;
1376 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1378 ok((item
.state
& TVIS_EXPANDED
) == TVIS_EXPANDED
, "expected expanded\n");
1381 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1382 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_COLLAPSE
, (LPARAM
)hRoot
);
1384 item
.state
= TVIS_EXPANDED
;
1385 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1387 ok((item
.state
& TVIS_EXPANDED
) == 0, "expected collapsed\n");
1388 /* all further collapse/expand attempts won't produce any notifications,
1389 the only way is to reset with all children removed */
1390 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "collapse after expand notifications", FALSE
);
1392 /* try to toggle child that doesn't have children itself */
1393 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1394 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_TOGGLE
, (LPARAM
)hChild
);
1396 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "toggle node without children", FALSE
);
1398 DestroyWindow(hTree
);
1400 /* test TVM_GETITEMRECT inside TVN_ITEMEXPANDED notification */
1401 hTree
= create_treeview_control(0);
1403 g_get_rect_in_expand
= TRUE
;
1404 ret
= TreeView_Select(hTree
, hChild
, TVGN_CARET
);
1406 g_get_rect_in_expand
= FALSE
;
1408 DestroyWindow(hTree
);
1410 /* TVE_TOGGLE acts as any other TVM_EXPAND */
1411 hTree
= create_treeview_control(0);
1414 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1415 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_TOGGLE
, (LPARAM
)hRoot
);
1417 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_expand_seq
, "toggle node (expand)", FALSE
);
1419 /* toggle again - no notifications */
1420 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1421 ret
= SendMessageA(hTree
, TVM_EXPAND
, TVE_TOGGLE
, (LPARAM
)hRoot
);
1423 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_seq
, "toggle node (collapse)", FALSE
);
1425 DestroyWindow(hTree
);
1428 static void test_expandedimage(void)
1434 hTree
= create_treeview_control(0);
1437 item
.mask
= TVIF_EXPANDEDIMAGE
;
1438 item
.iExpandedImage
= 1;
1440 ret
= SendMessageA(hTree
, TVM_SETITEMA
, 0, (LPARAM
)&item
);
1441 ok(ret
, "got %d\n", ret
);
1443 item
.mask
= TVIF_EXPANDEDIMAGE
;
1444 item
.iExpandedImage
= -1;
1446 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1447 ok(ret
, "got %d\n", ret
);
1449 if (item
.iExpandedImage
!= 1)
1451 win_skip("TVIF_EXPANDEDIMAGE not supported\n");
1452 DestroyWindow(hTree
);
1456 /* test for default iExpandedImage value */
1457 item
.mask
= TVIF_EXPANDEDIMAGE
;
1458 item
.iExpandedImage
= -1;
1459 item
.hItem
= hChild
;
1460 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1461 ok(ret
, "got %d\n", ret
);
1462 ok(item
.iExpandedImage
== (WORD
)I_IMAGENONE
, "got %d\n", item
.iExpandedImage
);
1464 DestroyWindow(hTree
);
1467 static void test_TVS_SINGLEEXPAND(void)
1472 hTree
= create_treeview_control(0);
1473 SetWindowLongA(hTree
, GWL_STYLE
, GetWindowLong(hTree
, GWL_STYLE
) | TVS_SINGLEEXPAND
);
1474 /* to avoid painting related notifications */
1475 ShowWindow(hTree
, SW_HIDE
);
1478 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1479 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hRoot
);
1480 ok(ret
, "got %d\n", ret
);
1481 ok_sequence(sequences
, PARENT_SEQ_INDEX
, parent_singleexpand_seq
, "singleexpand notifications", FALSE
);
1483 /* a workaround for NT4 that sends expand notifications when nothing is about to expand */
1484 ret
= SendMessageA(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hRoot
);
1485 ok(ret
, "got %d\n", ret
);
1487 ret
= SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, 0);
1488 ok(ret
, "got %d\n", ret
);
1490 DestroyWindow(hTree
);
1493 static void test_WM_PAINT(void)
1501 hTree
= create_treeview_control(0);
1503 clr
= SendMessageA(hTree
, TVM_SETBKCOLOR
, 0, RGB(255, 0, 0));
1504 ok(clr
== ~0u, "got %d, expected -1\n", clr
);
1506 hdc
= GetDC(hMainWnd
);
1508 GetClientRect(hMainWnd
, &rc
);
1509 FillRect(hdc
, &rc
, GetStockObject(BLACK_BRUSH
));
1511 clr
= GetPixel(hdc
, 1, 1);
1512 ok(clr
== RGB(0, 0, 0), "got 0x%x\n", clr
);
1514 ret
= SendMessageA(hTree
, WM_PAINT
, (WPARAM
)hdc
, 0);
1515 ok(ret
== 0, "got %d\n", ret
);
1517 clr
= GetPixel(hdc
, 1, 1);
1518 ok(clr
== RGB(255, 0, 0) || broken(clr
== RGB(0, 0, 0)) /* win98 */,
1521 ReleaseDC(hMainWnd
, hdc
);
1523 DestroyWindow(hTree
);
1526 static void test_delete_items(void)
1528 const struct message
*msg
;
1532 hTree
= create_treeview_control(0);
1535 /* check delete order */
1536 flush_sequences(item_sequence
, 1);
1537 ret
= SendMessage(hTree
, TVM_DELETEITEM
, 0, 0);
1538 ok(ret
== TRUE
, "got %d\n", ret
);
1540 msg
= item_sequence
[0]->sequence
;
1541 ok(item_sequence
[0]->count
== 2, "expected 2 items, got %d\n", item_sequence
[0]->count
);
1543 if (item_sequence
[0]->count
== 2)
1545 ok(msg
[0].lParam
== (LPARAM
)hChild
, "expected %p, got 0x%lx\n", hChild
, msg
[0].lParam
);
1546 ok(msg
[1].lParam
== (LPARAM
)hRoot
, "expected %p, got 0x%lx\n", hRoot
, msg
[1].lParam
);
1549 ret
= SendMessageA(hTree
, TVM_GETCOUNT
, 0, 0);
1550 ok(ret
== 0, "got %d\n", ret
);
1552 DestroyWindow(hTree
);
1557 HTREEITEM parent
; /* for root value of parent field is unidetified */
1558 HTREEITEM nextsibling
;
1559 HTREEITEM firstchild
;
1562 static void _check_item(HTREEITEM item
, HTREEITEM parent
, HTREEITEM nextsibling
, HTREEITEM firstchild
, int line
)
1564 struct _ITEM_DATA
*data
= (struct _ITEM_DATA
*)item
;
1566 ok_(__FILE__
, line
)(data
->parent
== parent
, "parent %p, got %p\n", parent
, data
->parent
);
1567 ok_(__FILE__
, line
)(data
->nextsibling
== nextsibling
, "sibling %p, got %p\n", nextsibling
, data
->nextsibling
);
1568 ok_(__FILE__
, line
)(data
->firstchild
== firstchild
, "firstchild %p, got %p\n", firstchild
, data
->firstchild
);
1571 #define check_item(a, b, c, d) _check_item(a, b, c, d, __LINE__)
1573 static void test_htreeitem_layout(void)
1575 TVINSERTSTRUCTA ins
;
1576 HTREEITEM item1
, item2
;
1579 hTree
= create_treeview_control(0);
1582 /* root has some special pointer in parent field */
1583 check_item(hRoot
, ((struct _ITEM_DATA
*)hRoot
)->parent
, 0, hChild
);
1584 check_item(hChild
, hRoot
, 0, 0);
1586 ins
.hParent
= hChild
;
1587 ins
.hInsertAfter
= TVI_FIRST
;
1588 U(ins
).item
.mask
= 0;
1589 item1
= TreeView_InsertItem(hTree
, &ins
);
1591 check_item(item1
, hChild
, 0, 0);
1593 ins
.hParent
= hRoot
;
1594 ins
.hInsertAfter
= TVI_FIRST
;
1595 U(ins
).item
.mask
= 0;
1596 item2
= TreeView_InsertItem(hTree
, &ins
);
1598 check_item(item2
, hRoot
, hChild
, 0);
1600 SendMessage(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hChild
);
1602 /* without children now */
1603 check_item(hRoot
, ((struct _ITEM_DATA
*)hRoot
)->parent
, 0, item2
);
1605 DestroyWindow(hTree
);
1608 static void test_TVS_CHECKBOXES(void)
1615 hTree
= create_treeview_control(0);
1618 himl
= (HIMAGELIST
)SendMessageA(hTree
, TVM_GETIMAGELIST
, TVSIL_STATE
, 0);
1619 ok(himl
== NULL
, "got %p\n", himl
);
1622 item
.mask
= TVIF_STATE
;
1623 item
.state
= INDEXTOSTATEIMAGEMASK(1);
1624 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1625 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1627 ok(item
.state
== 0, "got 0x%x\n", item
.state
);
1629 /* set some index for a child */
1630 item
.hItem
= hChild
;
1631 item
.mask
= TVIF_STATE
;
1632 item
.state
= INDEXTOSTATEIMAGEMASK(4);
1633 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1634 ret
= SendMessageA(hTree
, TVM_SETITEMA
, 0, (LPARAM
)&item
);
1637 /* enabling check boxes set all items to 1 state image index */
1638 SetWindowLongA(hTree
, GWL_STYLE
, GetWindowLongA(hTree
, GWL_STYLE
) | TVS_CHECKBOXES
);
1639 himl
= (HIMAGELIST
)SendMessageA(hTree
, TVM_GETIMAGELIST
, TVSIL_STATE
, 0);
1640 ok(himl
!= NULL
, "got %p\n", himl
);
1643 item
.mask
= TVIF_STATE
;
1645 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1646 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1648 ok(item
.state
== INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item
.state
);
1650 item
.hItem
= hChild
;
1651 item
.mask
= TVIF_STATE
;
1653 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1654 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1656 ok(item
.state
== INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item
.state
);
1658 DestroyWindow(hTree
);
1660 /* the same, but initially created with TVS_CHECKBOXES */
1661 hTree
= create_treeview_control(0);
1663 himl
= (HIMAGELIST
)SendMessageA(hTree
, TVM_GETIMAGELIST
, TVSIL_STATE
, 0);
1664 ok(himl
== NULL
, "got %p\n", himl
);
1665 DestroyWindow(hTree
);
1667 hTree
= create_treeview_control(TVS_CHECKBOXES
);
1669 himl
= (HIMAGELIST
)SendMessageA(hTree
, TVM_GETIMAGELIST
, TVSIL_STATE
, 0);
1670 todo_wine
ok(himl
== NULL
, "got %p\n", himl
);
1673 item
.mask
= TVIF_STATE
;
1675 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1676 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1678 ok(item
.state
== INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item
.state
);
1680 item
.hItem
= hChild
;
1681 item
.mask
= TVIF_STATE
;
1683 item
.stateMask
= TVIS_STATEIMAGEMASK
;
1684 ret
= SendMessageA(hTree
, TVM_GETITEMA
, 0, (LPARAM
)&item
);
1686 ok(item
.state
== INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item
.state
);
1688 DestroyWindow(hTree
);
1691 static void test_TVM_GETNEXTITEM(void)
1696 hTree
= create_treeview_control(0);
1699 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_ROOT
, 0);
1700 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1702 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_ROOT
, (LPARAM
)TVI_ROOT
);
1703 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1705 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_ROOT
, (LPARAM
)hRoot
);
1706 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1708 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_ROOT
, (LPARAM
)hChild
);
1709 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1711 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_CHILD
, 0);
1712 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1714 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)hRoot
);
1715 ok(item
== hChild
, "got %p, expected %p\n", item
, hChild
);
1717 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)TVI_ROOT
);
1718 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1720 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_PARENT
, 0);
1721 ok(item
== NULL
, "got %p\n", item
);
1723 item
= (HTREEITEM
)SendMessageA(hTree
, TVM_GETNEXTITEM
, TVGN_PARENT
, (LPARAM
)hChild
);
1724 ok(item
== hRoot
, "got %p, expected %p\n", item
, hRoot
);
1726 DestroyWindow(hTree
);
1729 START_TEST(treeview
)
1732 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
1736 ULONG_PTR ctx_cookie
;
1740 hComctl32
= GetModuleHandleA("comctl32.dll");
1741 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
1742 if (pInitCommonControlsEx
)
1744 INITCOMMONCONTROLSEX iccex
;
1745 iccex
.dwSize
= sizeof(iccex
);
1746 iccex
.dwICC
= ICC_TREEVIEW_CLASSES
;
1747 pInitCommonControlsEx(&iccex
);
1750 InitCommonControls();
1752 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
1753 init_msg_sequences(item_sequence
, 1);
1755 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1758 wc
.hInstance
= GetModuleHandleA(NULL
);
1760 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
1761 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1762 wc
.lpszMenuName
= NULL
;
1763 wc
.lpszClassName
= "MyTestWnd";
1764 wc
.lpfnWndProc
= parent_wnd_proc
;
1765 RegisterClassA(&wc
);
1767 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
1768 CW_USEDEFAULT
, CW_USEDEFAULT
, 130, 105, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1770 ok(hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n");
1771 if (!hMainWnd
) return;
1777 test_get_set_bkcolor();
1778 test_get_set_imagelist();
1779 test_get_set_indent();
1780 test_get_set_insertmark();
1781 test_get_set_item();
1782 test_get_set_itemheight();
1783 test_get_set_scrolltime();
1784 test_get_set_textcolor();
1785 test_get_linecolor();
1786 test_get_insertmarkcolor();
1787 test_get_set_tooltips();
1788 test_get_set_unicodeformat();
1790 test_expandinvisible();
1792 test_treeview_classinfo();
1793 test_expandnotify();
1794 test_TVS_SINGLEEXPAND();
1796 test_delete_items();
1797 test_htreeitem_layout();
1798 test_TVS_CHECKBOXES();
1799 test_TVM_GETNEXTITEM();
1801 if (!load_v6_module(&ctx_cookie
, &hCtx
))
1803 DestroyWindow(hMainWnd
);
1807 /* this is a XP SP3 failure workaround */
1808 hwnd
= CreateWindowExA(0, WC_TREEVIEW
, "foo",
1809 WS_CHILD
| WS_BORDER
| WS_VISIBLE
,
1811 hMainWnd
, NULL
, GetModuleHandleA(NULL
), NULL
);
1812 if (!IsWindow(hwnd
))
1814 win_skip("FIXME: failed to create TreeView window.\n");
1815 unload_v6_module(ctx_cookie
, hCtx
);
1816 DestroyWindow(hMainWnd
);
1820 DestroyWindow(hwnd
);
1822 /* comctl32 version 6 tests start here */
1823 test_expandedimage();
1824 test_htreeitem_layout();
1826 unload_v6_module(ctx_cookie
, hCtx
);
1828 PostMessageA(hMainWnd
, WM_CLOSE
, 0, 0);
1829 while(GetMessageA(&msg
, 0, 0, 0))
1831 TranslateMessage(&msg
);
1832 DispatchMessageA(&msg
);