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"
35 const char *TEST_CALLBACK_TEXT
= "callback_text";
37 #define NUM_MSG_SEQUENCES 1
38 #define LISTVIEW_SEQ_INDEX 0
40 static struct msg_sequence
*MsgSequences
[NUM_MSG_SEQUENCES
];
42 static const struct message FillRootSeq
[] = {
43 { TVM_INSERTITEM
, sent
},
44 { TVM_GETITEM
, sent
},
45 { TVM_INSERTITEM
, sent
},
49 static const struct message DoTest1Seq
[] = {
50 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
51 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
52 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
53 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
54 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
55 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
59 static const struct message DoTest2Seq
[] = {
60 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
61 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
62 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
63 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
64 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
65 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
69 static const struct message DoTest3Seq
[] = {
70 { TVM_INSERTITEM
, sent
},
71 { TVM_GETITEM
, sent
},
72 { TVM_DELETEITEM
, sent
},
76 static const struct message DoFocusTestSeq
[] = {
77 { TVM_INSERTITEM
, sent
},
78 { TVM_INSERTITEM
, sent
},
79 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
},
80 { WM_NCCALCSIZE
, sent
|wparam
|defwinproc
, 0x00000001 },
81 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
},
82 { WM_SIZE
, sent
|defwinproc
},
83 { WM_WINDOWPOSCHANGING
, sent
},
84 { WM_NCCALCSIZE
, sent
|wparam
, 0x00000001 },
85 { WM_WINDOWPOSCHANGED
, sent
},
86 { WM_SIZE
, sent
|defwinproc
},
87 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
|optional
},
88 { WM_NCCALCSIZE
, sent
|wparam
|defwinproc
|optional
, 0x00000001 },
89 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
|optional
},
90 { WM_SIZE
, sent
|defwinproc
|optional
},
91 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
92 /* The following end up out of order in wine */
93 { WM_PAINT
, sent
|defwinproc
},
94 { WM_NCPAINT
, sent
|wparam
|defwinproc
, 0x00000001 },
95 { WM_ERASEBKGND
, sent
|defwinproc
},
96 { TVM_EDITLABEL
, sent
},
97 { WM_COMMAND
, sent
|wparam
|defwinproc
, 0x04000000 },
98 { WM_COMMAND
, sent
|wparam
|defwinproc
, 0x03000000 },
99 { WM_PARENTNOTIFY
, sent
|wparam
|defwinproc
, 0x00000001 },
100 { WM_KILLFOCUS
, sent
|defwinproc
},
101 { WM_PAINT
, sent
|defwinproc
},
102 { WM_IME_SETCONTEXT
, sent
|defwinproc
|optional
},
103 { WM_COMMAND
, sent
|wparam
|defwinproc
, 0x01000000},
104 { WM_ERASEBKGND
, sent
|defwinproc
},
105 { WM_CTLCOLOREDIT
, sent
|defwinproc
|optional
},
106 { WM_CTLCOLOREDIT
, sent
|defwinproc
|optional
},
110 static const struct message TestGetSetBkColorSeq
[] = {
111 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
112 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
113 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
114 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00ffffff },
115 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
116 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, -1 },
120 static const struct message TestGetSetImageListSeq
[] = {
121 { TVM_SETIMAGELIST
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
122 { TVM_GETIMAGELIST
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
126 static const struct message TestGetSetIndentSeq
[] = {
127 { TVM_SETINDENT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
128 { TVM_GETINDENT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
129 /* The actual amount to indent is dependent on the system for this message */
130 { TVM_SETINDENT
, sent
},
131 { TVM_GETINDENT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
135 static const struct message TestGetSetInsertMarkColorSeq
[] = {
136 { TVM_SETINSERTMARKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
137 { TVM_GETINSERTMARKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
141 static const struct message TestGetSetItemSeq
[] = {
142 { TVM_GETITEM
, sent
},
143 { TVM_SETITEM
, sent
},
144 { TVM_GETITEM
, sent
},
145 { TVM_SETITEM
, sent
},
149 static const struct message TestGetSetItemHeightSeq
[] = {
150 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
151 { TVM_SETITEMHEIGHT
, sent
|wparam
|lparam
, -1, 0x00000000 },
152 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
153 { TVM_SETITEMHEIGHT
, sent
|lparam
, 0xcccccccc, 0x00000000 },
154 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
|optional
, 0x00000000, 0x00000000 },
155 { TVM_SETITEMHEIGHT
, sent
|wparam
|lparam
|optional
, 0x00000009, 0x00000000 },
156 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
},
157 { WM_NCCALCSIZE
, sent
|wparam
|defwinproc
, 0x00000001 },
158 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
},
159 { WM_SIZE
, sent
|defwinproc
},
160 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
164 static const struct message TestGetSetScrollTimeSeq
[] = {
165 { TVM_SETSCROLLTIME
, sent
|wparam
|lparam
, 0x00000014, 0x00000000 },
166 { TVM_GETSCROLLTIME
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
170 static const struct message TestGetSetTextColorSeq
[] = {
171 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
172 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
173 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
174 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00ffffff },
175 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
176 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, -1 },
180 static const struct message TestGetSetToolTipsSeq
[] = {
181 { WM_COMMAND
, sent
|wparam
, 0x02000000 },
182 { WM_PARENTNOTIFY
, sent
|wparam
|defwinproc
, 0x00020002 },
183 { TVM_SETTOOLTIPS
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
184 { TVM_GETTOOLTIPS
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
188 static const struct message TestGetSetUnicodeFormatSeq
[] = {
189 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000001, 0x00000000 },
190 { TVM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
191 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
192 { TVM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
193 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
197 static HWND hMainWnd
;
199 static HWND hTree
, hEdit
;
200 static HTREEITEM hRoot
, hChild
;
203 static char sequence
[256];
205 static void Clear(void)
211 static void AddItem(char ch
)
213 sequence
[pos
++] = ch
;
214 sequence
[pos
] = '\0';
217 static void IdentifyItem(HTREEITEM hItem
)
219 if (hItem
== hRoot
) {
223 if (hItem
== hChild
) {
234 static void FillRoot(void)
238 static CHAR root
[] = "Root",
243 ins
.hParent
= TVI_ROOT
;
244 ins
.hInsertAfter
= TVI_ROOT
;
245 U(ins
).item
.mask
= TVIF_TEXT
;
246 U(ins
).item
.pszText
= root
;
247 hRoot
= TreeView_InsertItem(hTree
, &ins
);
250 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
252 tvi
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
253 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
254 ok(tvi
.iImage
== 0, "tvi.iImage=%d\n", tvi
.iImage
);
255 ok(tvi
.iSelectedImage
== 0, "tvi.iSelectedImage=%d\n", tvi
.iSelectedImage
);
259 ins
.hInsertAfter
= TVI_FIRST
;
260 U(ins
).item
.mask
= TVIF_TEXT
;
261 U(ins
).item
.pszText
= child
;
262 hChild
= TreeView_InsertItem(hTree
, &ins
);
266 ok(!strcmp(sequence
, "AB."), "Item creation\n");
269 static void TestCallback(void)
272 HTREEITEM hItem1
, hItem2
;
275 CHAR test_string
[] = "Test_string";
279 ret
= TreeView_DeleteAllItems(hTree
);
280 ok(ret
== TRUE
, "ret\n");
281 ins
.hParent
= TVI_ROOT
;
282 ins
.hInsertAfter
= TVI_ROOT
;
283 U(ins
).item
.mask
= TVIF_TEXT
;
284 U(ins
).item
.pszText
= LPSTR_TEXTCALLBACK
;
285 hRoot
= TreeView_InsertItem(hTree
, &ins
);
289 tvi
.mask
= TVIF_TEXT
;
291 tvi
.cchTextMax
= sizeof(buf
)/sizeof(buf
[0]);
292 ret
= TreeView_GetItem(hTree
, &tvi
);
293 ok(ret
== 1, "ret\n");
294 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Callback item text mismatch %s vs %s\n",
295 tvi
.pszText
, TEST_CALLBACK_TEXT
);
298 ins
.hInsertAfter
= TVI_FIRST
;
299 U(ins
).item
.mask
= TVIF_TEXT
;
300 U(ins
).item
.pszText
= test_string
;
301 hItem1
= TreeView_InsertItem(hTree
, &ins
);
305 ret
= TreeView_GetItem(hTree
, &tvi
);
306 ok(ret
== TRUE
, "ret\n");
307 ok(strcmp(tvi
.pszText
, test_string
) == 0, "Item text mismatch %s vs %s\n",
308 tvi
.pszText
, test_string
);
310 /* undocumented: pszText of NULL also means LPSTR_CALLBACK: */
312 ret
= TreeView_SetItem(hTree
, &tvi
);
313 ok(ret
== 1, "Expected SetItem return 1, got %ld\n", ret
);
315 ret
= TreeView_GetItem(hTree
, &tvi
);
316 ok(ret
== TRUE
, "Expected GetItem return TRUE, got %ld\n", ret
);
317 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
318 tvi
.pszText
, TEST_CALLBACK_TEXT
);
320 U(ins
).item
.pszText
= NULL
;
321 hItem2
= TreeView_InsertItem(hTree
, &ins
);
324 memset(buf
, 0, sizeof(buf
));
325 ret
= TreeView_GetItem(hTree
, &tvi
);
326 ok(ret
== TRUE
, "Expected GetItem return TRUE, got %ld\n", ret
);
327 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
328 tvi
.pszText
, TEST_CALLBACK_TEXT
);
331 static void DoTest1(void)
334 r
= TreeView_SelectItem(hTree
, NULL
);
337 r
= TreeView_SelectItem(hTree
, hRoot
);
339 r
= TreeView_SelectItem(hTree
, hRoot
);
341 r
= TreeView_SelectItem(hTree
, NULL
);
343 r
= TreeView_SelectItem(hTree
, NULL
);
345 r
= TreeView_SelectItem(hTree
, hRoot
);
347 ok(!strcmp(sequence
, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
350 static void DoTest2(void)
353 r
= TreeView_SelectItem(hTree
, NULL
);
356 r
= TreeView_SelectItem(hTree
, hRoot
);
358 r
= TreeView_SelectItem(hTree
, hRoot
);
360 r
= TreeView_SelectItem(hTree
, hChild
);
362 r
= TreeView_SelectItem(hTree
, hChild
);
364 r
= TreeView_SelectItem(hTree
, hRoot
);
366 ok(!strcmp(sequence
, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
369 static void DoTest3(void)
375 int nBufferSize
= 80;
376 CHAR szBuffer
[80] = "Blah";
378 /* add an item without TVIF_TEXT mask and pszText == NULL */
380 ins
.hInsertAfter
= TVI_ROOT
;
381 U(ins
).item
.mask
= 0;
382 U(ins
).item
.pszText
= NULL
;
383 U(ins
).item
.cchTextMax
= 0;
384 hChild
= TreeView_InsertItem(hTree
, &ins
);
387 /* retrieve it with TVIF_TEXT mask */
389 tvi
.mask
= TVIF_TEXT
;
390 tvi
.cchTextMax
= nBufferSize
;
391 tvi
.pszText
= szBuffer
;
393 SendMessageA( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
394 ok(!strcmp(szBuffer
, ""), "szBuffer=\"%s\", expected \"\"\n", szBuffer
);
395 ok(SendMessageA(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hChild
), "DeleteItem failed\n");
398 static void DoFocusTest(void)
401 static CHAR child1
[] = "Edit",
402 child2
[] = "A really long string";
403 HTREEITEM hChild1
, hChild2
;
405 /* This test verifies that when a label is being edited, scrolling
406 * the treeview does not cause the label to lose focus. To test
407 * this, first some additional entries are added to generate
411 ins
.hInsertAfter
= hChild
;
412 U(ins
).item
.mask
= TVIF_TEXT
;
413 U(ins
).item
.pszText
= child1
;
414 hChild1
= TreeView_InsertItem(hTree
, &ins
);
416 ins
.hInsertAfter
= hChild1
;
417 U(ins
).item
.mask
= TVIF_TEXT
;
418 U(ins
).item
.pszText
= child2
;
419 hChild2
= TreeView_InsertItem(hTree
, &ins
);
422 ShowWindow(hMainWnd
,SW_SHOW
);
423 /* Using SendMessageA since Win98 doesn't have default unicode support */
424 SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hChild
);
425 hEdit
= TreeView_EditLabel(hTree
, hChild
);
426 ScrollWindowEx(hTree
, -10, 0, NULL
, NULL
, NULL
, NULL
, SW_SCROLLCHILDREN
);
427 ok(GetFocus() == hEdit
, "Edit control should have focus\n");
430 static void TestGetSetBkColor(void)
432 COLORREF crColor
= RGB(0,0,0);
434 /* If the value is -1, the control is using the system color for the background color. */
435 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
436 ok(crColor
== -1, "Default background color reported as 0x%.8x\n", crColor
);
438 /* Test for black background */
439 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, (LPARAM
)RGB(0,0,0) );
440 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
441 ok(crColor
== RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor
);
443 /* Test for white background */
444 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, (LPARAM
)RGB(255,255,255) );
445 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
446 ok(crColor
== RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor
);
448 /* Reset the default background */
449 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, -1 );
452 static void TestGetSetImageList(void)
454 HIMAGELIST hImageList
= NULL
;
456 /* Test a NULL HIMAGELIST */
457 SendMessage( hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)hImageList
);
458 hImageList
= (HIMAGELIST
)SendMessage( hTree
, TVM_GETIMAGELIST
, TVSIL_NORMAL
, 0 );
459 ok(hImageList
== NULL
, "NULL image list, reported as 0x%p, expected 0.\n", hImageList
);
461 /* TODO: Test an actual image list */
464 static void TestGetSetIndent(void)
467 int ulMinIndent
= -1;
468 int ulMoreThanTwiceMin
= -1;
470 /* Finding the minimum indent */
471 SendMessage( hTree
, TVM_SETINDENT
, 0, 0 );
472 ulMinIndent
= (int)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
474 /* Checking an indent that is more than twice the default indent */
475 ulMoreThanTwiceMin
= 2*ulMinIndent
+1;
476 SendMessage( hTree
, TVM_SETINDENT
, ulMoreThanTwiceMin
, 0 );
477 ulIndent
= (DWORD
)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
478 ok(ulIndent
== ulMoreThanTwiceMin
, "Indent reported as %d, expected %d\n", ulIndent
, ulMoreThanTwiceMin
);
481 static void TestGetSetInsertMarkColor(void)
483 COLORREF crColor
= RGB(0,0,0);
484 SendMessage( hTree
, TVM_SETINSERTMARKCOLOR
, 0, crColor
);
485 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0 );
486 ok(crColor
== RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor
);
489 static void TestGetSetItem(void)
491 TVITEM tviRoot
= {0};
492 int nBufferSize
= 80;
493 char szBuffer
[80] = {0};
495 /* Test the root item */
496 tviRoot
.hItem
= hRoot
;
497 tviRoot
.mask
= TVIF_TEXT
;
498 tviRoot
.cchTextMax
= nBufferSize
;
499 tviRoot
.pszText
= szBuffer
;
500 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tviRoot
);
501 ok(!strcmp("Root", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer
);
503 /* Change the root text */
504 strncpy(szBuffer
, "Testing123", nBufferSize
);
505 SendMessage( hTree
, TVM_SETITEM
, 0, (LPARAM
)&tviRoot
);
506 memset(szBuffer
, 0, nBufferSize
);
507 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tviRoot
);
508 ok(!strcmp("Testing123", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer
);
510 /* Reset the root text */
511 memset(szBuffer
, 0, nBufferSize
);
512 strncpy(szBuffer
, "Root", nBufferSize
);
513 SendMessage( hTree
, TVM_SETITEM
, 0, (LPARAM
)&tviRoot
);
516 static void TestGetSetItemHeight(void)
521 /* Assuming default height to begin with */
522 ulOldHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
524 /* Explicitly setting and getting the default height */
525 SendMessage( hTree
, TVM_SETITEMHEIGHT
, -1, 0 );
526 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
527 ok(ulNewHeight
== ulOldHeight
, "Default height not set properly, reported %d, expected %d\n", ulNewHeight
, ulOldHeight
);
529 /* Explicitly setting and getting the height of twice the normal */
530 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 2*ulOldHeight
, 0 );
531 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
532 ok(ulNewHeight
== 2*ulOldHeight
, "New height not set properly, reported %d, expected %d\n", ulNewHeight
, 2*ulOldHeight
);
534 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
535 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 9, 0 );
536 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
537 ok(ulNewHeight
== 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight
, 8);
540 static void TestGetSetScrollTime(void)
542 int ulExpectedTime
= 20;
544 SendMessage( hTree
, TVM_SETSCROLLTIME
, ulExpectedTime
, 0 );
545 ulTime
= (int)SendMessage( hTree
, TVM_GETSCROLLTIME
, 0, 0 );
546 ok(ulTime
== ulExpectedTime
, "Scroll time reported as %d, expected %d\n", ulTime
, ulExpectedTime
);
549 static void TestGetSetTextColor(void)
551 /* If the value is -1, the control is using the system color for the text color. */
552 COLORREF crColor
= RGB(0,0,0);
553 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
554 ok(crColor
== -1, "Default text color reported as 0x%.8x\n", crColor
);
556 /* Test for black text */
557 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, (LPARAM
)RGB(0,0,0) );
558 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
559 ok(crColor
== RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor
);
561 /* Test for white text */
562 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, (LPARAM
)RGB(255,255,255) );
563 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
564 ok(crColor
== RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor
);
566 /* Reset the default text color */
567 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, -1 );
570 static void TestGetSetToolTips(void)
572 HWND hwndLastToolTip
= NULL
;
575 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
576 hPopupTreeView
= CreateWindow(WC_TREEVIEW
, NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 100, 100, hMainWnd
, NULL
, NULL
, NULL
);
577 DestroyWindow(hPopupTreeView
);
579 /* Testing setting a NULL ToolTip */
580 SendMessage( hTree
, TVM_SETTOOLTIPS
, 0, 0 );
581 hwndLastToolTip
= (HWND
)SendMessage( hTree
, TVM_GETTOOLTIPS
, 0, 0 );
582 ok(hwndLastToolTip
== NULL
, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip
);
584 /* TODO: Add a test of an actual tooltip */
587 static void TestGetSetUnicodeFormat(void)
589 BOOL bPreviousSetting
= 0;
590 BOOL bNewSetting
= 0;
593 bPreviousSetting
= (BOOL
)SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 1, 0 );
594 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
595 ok(bNewSetting
== 1, "Unicode setting did not work.\n");
598 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 0, 0 );
599 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
600 ok(bNewSetting
== 0, "ANSI setting did not work.\n");
602 /* Revert to original setting */
603 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, (LPARAM
)bPreviousSetting
, 0 );
606 static void TestGetSet(void)
608 /* TVM_GETBKCOLOR and TVM_SETBKCOLOR */
609 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
611 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetBkColorSeq
,
612 "TestGetSetBkColor", FALSE
);
614 /* TVM_GETIMAGELIST and TVM_SETIMAGELIST */
615 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
616 TestGetSetImageList();
617 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetImageListSeq
,
618 "TestGetImageList", FALSE
);
620 /* TVM_SETINDENT and TVM_GETINDENT */
621 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
623 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetIndentSeq
,
624 "TestGetSetIndent", FALSE
);
626 /* TVM_GETINSERTMARKCOLOR and TVM_GETINSERTMARKCOLOR */
627 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
628 TestGetSetInsertMarkColor();
629 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetInsertMarkColorSeq
,
630 "TestGetSetInsertMarkColor", FALSE
);
632 /* TVM_GETITEM and TVM_SETITEM */
633 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
635 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetItemSeq
,
636 "TestGetSetItem", FALSE
);
638 /* TVM_GETITEMHEIGHT and TVM_SETITEMHEIGHT */
639 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
640 TestGetSetItemHeight();
641 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetItemHeightSeq
,
642 "TestGetSetItemHeight", FALSE
);
644 /* TVM_GETSCROLLTIME and TVM_SETSCROLLTIME */
645 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
646 TestGetSetScrollTime();
647 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetScrollTimeSeq
,
648 "TestGetSetScrollTime", FALSE
);
650 /* TVM_GETTEXTCOLOR and TVM_SETTEXTCOLOR */
651 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
652 TestGetSetTextColor();
653 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetTextColorSeq
,
654 "TestGetSetTextColor", FALSE
);
656 /* TVM_GETTOOLTIPS and TVM_SETTOOLTIPS */
657 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
658 TestGetSetToolTips();
659 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetToolTipsSeq
,
660 "TestGetSetToolTips", TRUE
);
662 /* TVM_GETUNICODEFORMAT and TVM_SETUNICODEFORMAT */
663 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
664 TestGetSetUnicodeFormat();
665 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetUnicodeFormatSeq
,
666 "TestGetSetUnicodeFormat", FALSE
);
669 /* This function hooks in and records all messages to the treeview control */
670 static LRESULT WINAPI
TreeviewWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
672 static LONG defwndproc_counter
= 0;
675 WNDPROC lpOldProc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
677 msg
.message
= message
;
678 msg
.flags
= sent
|wparam
|lparam
;
679 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
682 add_message(MsgSequences
, LISTVIEW_SEQ_INDEX
, &msg
);
684 defwndproc_counter
++;
685 ret
= CallWindowProcA(lpOldProc
, hwnd
, message
, wParam
, lParam
);
686 defwndproc_counter
--;
691 static LRESULT CALLBACK
MyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
699 hTree
= CreateWindowExA(WS_EX_CLIENTEDGE
, WC_TREEVIEWA
, NULL
, WS_CHILD
|WS_VISIBLE
|
700 TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_EDITLABELS
,
701 0, 0, 120, 100, hWnd
, (HMENU
)100, GetModuleHandleA(0), 0);
705 /* Record the old WNDPROC so we can call it after recording the messages */
706 pOldWndProc
= (WNDPROC
)SetWindowLongPtrA(hTree
, GWLP_WNDPROC
, (LONG_PTR
)TreeviewWndProc
);
707 SetWindowLongPtrA(hTree
, GWLP_USERDATA
, (LONG_PTR
)pOldWndProc
);
713 NMHDR
*pHdr
= (NMHDR
*)lParam
;
715 ok(pHdr
->code
!= NM_FIRST
- 19, "Treeview should not send NM_TOOLTIPSCREATED\n");
716 if (pHdr
->idFrom
== 100) {
717 NMTREEVIEWA
*pTreeView
= (LPNMTREEVIEWA
) lParam
;
719 case TVN_SELCHANGINGA
:
721 IdentifyItem(pTreeView
->itemOld
.hItem
);
722 IdentifyItem(pTreeView
->itemNew
.hItem
);
724 case TVN_SELCHANGEDA
:
726 IdentifyItem(pTreeView
->itemOld
.hItem
);
727 IdentifyItem(pTreeView
->itemNew
.hItem
);
729 case TVN_GETDISPINFOA
: {
730 NMTVDISPINFOA
*disp
= (NMTVDISPINFOA
*)lParam
;
731 if (disp
->item
.mask
& TVIF_TEXT
) {
732 lstrcpyn(disp
->item
.pszText
, TEST_CALLBACK_TEXT
, disp
->item
.cchTextMax
);
742 MoveWindow(hTree
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
750 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
755 static void TestExpandInvisible(void)
757 static CHAR nodeText
[][5] = {"0", "1", "2", "3", "4"};
764 /* The test builds the following tree and expands then node 1, while node 0 is collapsed.
774 ret
= TreeView_DeleteAllItems(hTree
);
775 ok(ret
== TRUE
, "ret\n");
776 ins
.hParent
= TVI_ROOT
;
777 ins
.hInsertAfter
= TVI_ROOT
;
778 U(ins
).item
.mask
= TVIF_TEXT
;
779 U(ins
).item
.pszText
= nodeText
[0];
780 node
[0] = TreeView_InsertItem(hTree
, &ins
);
783 ins
.hInsertAfter
= TVI_LAST
;
784 U(ins
).item
.mask
= TVIF_TEXT
;
785 ins
.hParent
= node
[0];
787 U(ins
).item
.pszText
= nodeText
[1];
788 node
[1] = TreeView_InsertItem(hTree
, &ins
);
790 U(ins
).item
.pszText
= nodeText
[4];
791 node
[4] = TreeView_InsertItem(hTree
, &ins
);
794 ins
.hParent
= node
[1];
796 U(ins
).item
.pszText
= nodeText
[2];
797 node
[2] = TreeView_InsertItem(hTree
, &ins
);
799 U(ins
).item
.pszText
= nodeText
[3];
800 node
[3] = TreeView_InsertItem(hTree
, &ins
);
804 nodeVisible
= TreeView_GetItemRect(hTree
, node
[1], &dummyRect
, FALSE
);
805 ok(!nodeVisible
, "Node 1 should not be visible.\n");
806 nodeVisible
= TreeView_GetItemRect(hTree
, node
[2], &dummyRect
, FALSE
);
807 ok(!nodeVisible
, "Node 2 should not be visible.\n");
808 nodeVisible
= TreeView_GetItemRect(hTree
, node
[3], &dummyRect
, FALSE
);
809 ok(!nodeVisible
, "Node 3 should not be visible.\n");
810 nodeVisible
= TreeView_GetItemRect(hTree
, node
[4], &dummyRect
, FALSE
);
811 ok(!nodeVisible
, "Node 4 should not be visible.\n");
813 ok(TreeView_Expand(hTree
, node
[1], TVE_EXPAND
), "Expand of node 1 failed.\n");
815 nodeVisible
= TreeView_GetItemRect(hTree
, node
[1], &dummyRect
, FALSE
);
816 ok(!nodeVisible
, "Node 1 should not be visible.\n");
817 nodeVisible
= TreeView_GetItemRect(hTree
, node
[2], &dummyRect
, FALSE
);
818 ok(!nodeVisible
, "Node 2 should not be visible.\n");
819 nodeVisible
= TreeView_GetItemRect(hTree
, node
[3], &dummyRect
, FALSE
);
820 ok(!nodeVisible
, "Node 3 should not be visible.\n");
821 nodeVisible
= TreeView_GetItemRect(hTree
, node
[4], &dummyRect
, FALSE
);
822 ok(!nodeVisible
, "Node 4 should not be visible.\n");
829 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
833 hComctl32
= GetModuleHandleA("comctl32.dll");
834 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
835 if (pInitCommonControlsEx
)
837 INITCOMMONCONTROLSEX iccex
;
838 iccex
.dwSize
= sizeof(iccex
);
839 iccex
.dwICC
= ICC_TREEVIEW_CLASSES
;
840 pInitCommonControlsEx(&iccex
);
843 InitCommonControls();
845 init_msg_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
847 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
850 wc
.hInstance
= GetModuleHandleA(NULL
);
852 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
853 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
854 wc
.lpszMenuName
= NULL
;
855 wc
.lpszClassName
= "MyTestWnd";
856 wc
.lpfnWndProc
= MyWndProc
;
860 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
861 CW_USEDEFAULT
, CW_USEDEFAULT
, 130, 105, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
863 if ( !ok(hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n") )
866 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
868 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, FillRootSeq
, "FillRoot", FALSE
);
870 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
872 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoTest1Seq
, "DoTest1", FALSE
);
874 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
876 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoTest2Seq
, "DoTest2", FALSE
);
878 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
880 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoTest3Seq
, "DoTest3", FALSE
);
882 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
884 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoFocusTestSeq
, "DoFocusTest", TRUE
);
886 /* Sequences tested inside due to number */
889 /* Clears all the previous items */
892 /* Clears all the previous items */
893 TestExpandInvisible();
895 PostMessageA(hMainWnd
, WM_CLOSE
, 0, 0);
896 while(GetMessageA(&msg
,0,0,0)) {
897 TranslateMessage(&msg
);
898 DispatchMessageA(&msg
);