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 TreeView_DeleteAllItems(hTree
);
280 ins
.hParent
= TVI_ROOT
;
281 ins
.hInsertAfter
= TVI_ROOT
;
282 U(ins
).item
.mask
= TVIF_TEXT
;
283 U(ins
).item
.pszText
= LPSTR_TEXTCALLBACK
;
284 hRoot
= TreeView_InsertItem(hTree
, &ins
);
288 tvi
.mask
= TVIF_TEXT
;
290 tvi
.cchTextMax
= sizeof(buf
)/sizeof(buf
[0]);
291 ret
= TreeView_GetItem(hTree
, &tvi
);
292 ok(ret
== 1, "ret\n");
293 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Callback item text mismatch %s vs %s\n",
294 tvi
.pszText
, TEST_CALLBACK_TEXT
);
297 ins
.hInsertAfter
= TVI_FIRST
;
298 U(ins
).item
.mask
= TVIF_TEXT
;
299 U(ins
).item
.pszText
= test_string
;
300 hItem1
= TreeView_InsertItem(hTree
, &ins
);
304 TreeView_GetItem(hTree
, &tvi
);
305 ok(strcmp(tvi
.pszText
, test_string
) == 0, "Item text mismatch %s vs %s\n",
306 tvi
.pszText
, test_string
);
308 /* undocumented: pszText of NULL also means LPSTR_CALLBACK: */
310 ret
= TreeView_SetItem(hTree
, &tvi
);
311 ok(ret
== 1, "Expected SetItem return 1, got %ld\n", ret
);
313 TreeView_GetItem(hTree
, &tvi
);
314 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
315 tvi
.pszText
, TEST_CALLBACK_TEXT
);
317 U(ins
).item
.pszText
= NULL
;
318 hItem2
= TreeView_InsertItem(hTree
, &ins
);
321 memset(buf
, 0, sizeof(buf
));
322 TreeView_GetItem(hTree
, &tvi
);
323 ok(strcmp(tvi
.pszText
, TEST_CALLBACK_TEXT
) == 0, "Item text mismatch %s vs %s\n",
324 tvi
.pszText
, TEST_CALLBACK_TEXT
);
327 static void DoTest1(void)
330 r
= TreeView_SelectItem(hTree
, NULL
);
333 r
= TreeView_SelectItem(hTree
, hRoot
);
335 r
= TreeView_SelectItem(hTree
, hRoot
);
337 r
= TreeView_SelectItem(hTree
, NULL
);
339 r
= TreeView_SelectItem(hTree
, NULL
);
341 r
= TreeView_SelectItem(hTree
, hRoot
);
343 ok(!strcmp(sequence
, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
346 static void DoTest2(void)
349 r
= TreeView_SelectItem(hTree
, NULL
);
352 r
= TreeView_SelectItem(hTree
, hRoot
);
354 r
= TreeView_SelectItem(hTree
, hRoot
);
356 r
= TreeView_SelectItem(hTree
, hChild
);
358 r
= TreeView_SelectItem(hTree
, hChild
);
360 r
= TreeView_SelectItem(hTree
, hRoot
);
362 ok(!strcmp(sequence
, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
365 static void DoTest3(void)
371 int nBufferSize
= 80;
372 CHAR szBuffer
[80] = "Blah";
374 /* add an item without TVIF_TEXT mask and pszText == NULL */
376 ins
.hInsertAfter
= TVI_ROOT
;
377 U(ins
).item
.mask
= 0;
378 U(ins
).item
.pszText
= NULL
;
379 U(ins
).item
.cchTextMax
= 0;
380 hChild
= TreeView_InsertItem(hTree
, &ins
);
383 /* retrieve it with TVIF_TEXT mask */
385 tvi
.mask
= TVIF_TEXT
;
386 tvi
.cchTextMax
= nBufferSize
;
387 tvi
.pszText
= szBuffer
;
389 SendMessageA( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
390 ok(!strcmp(szBuffer
, ""), "szBuffer=\"%s\", expected \"\"\n", szBuffer
);
391 ok(SendMessageA(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hChild
), "DeleteItem failed\n");
394 static void DoFocusTest(void)
397 static CHAR child1
[] = "Edit",
398 child2
[] = "A really long string";
399 HTREEITEM hChild1
, hChild2
;
401 /* This test verifies that when a label is being edited, scrolling
402 * the treeview does not cause the label to lose focus. To test
403 * this, first some additional entries are added to generate
407 ins
.hInsertAfter
= hChild
;
408 U(ins
).item
.mask
= TVIF_TEXT
;
409 U(ins
).item
.pszText
= child1
;
410 hChild1
= TreeView_InsertItem(hTree
, &ins
);
412 ins
.hInsertAfter
= hChild1
;
413 U(ins
).item
.mask
= TVIF_TEXT
;
414 U(ins
).item
.pszText
= child2
;
415 hChild2
= TreeView_InsertItem(hTree
, &ins
);
418 ShowWindow(hMainWnd
,SW_SHOW
);
419 /* Using SendMessageA since Win98 doesn't have default unicode support */
420 SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hChild
);
421 hEdit
= TreeView_EditLabel(hTree
, hChild
);
422 ScrollWindowEx(hTree
, -10, 0, NULL
, NULL
, NULL
, NULL
, SW_SCROLLCHILDREN
);
423 ok(GetFocus() == hEdit
, "Edit control should have focus\n");
426 static void TestGetSetBkColor(void)
428 COLORREF crColor
= RGB(0,0,0);
431 /* If the value is -1, the control is using the system color for the background color. */
432 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
433 ok(crColor
== -1, "Default background color reported as 0x%.8x\n", crColor
);
436 /* Test for black background */
437 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, (LPARAM
)RGB(0,0,0) );
438 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
439 ok(crColor
== RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor
);
441 /* Test for white background */
442 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, (LPARAM
)RGB(255,255,255) );
443 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
444 ok(crColor
== RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor
);
446 /* Reset the default background */
447 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, -1 );
450 static void TestGetSetImageList(void)
452 HIMAGELIST hImageList
= NULL
;
454 /* Test a NULL HIMAGELIST */
455 SendMessage( hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)hImageList
);
456 hImageList
= (HIMAGELIST
)SendMessage( hTree
, TVM_GETIMAGELIST
, TVSIL_NORMAL
, 0 );
457 ok(hImageList
== NULL
, "NULL image list, reported as 0x%p, expected 0.\n", hImageList
);
459 /* TODO: Test an actual image list */
462 static void TestGetSetIndent(void)
465 int ulMinIndent
= -1;
466 int ulMoreThanTwiceMin
= -1;
468 /* Finding the minimum indent */
469 SendMessage( hTree
, TVM_SETINDENT
, 0, 0 );
470 ulMinIndent
= (int)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
472 /* Checking an indent that is more than twice the default indent */
473 ulMoreThanTwiceMin
= 2*ulMinIndent
+1;
474 SendMessage( hTree
, TVM_SETINDENT
, ulMoreThanTwiceMin
, 0 );
475 ulIndent
= (DWORD
)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
476 ok(ulIndent
== ulMoreThanTwiceMin
, "Indent reported as %d, expected %d\n", ulIndent
, ulMoreThanTwiceMin
);
479 static void TestGetSetInsertMarkColor(void)
481 COLORREF crColor
= RGB(0,0,0);
482 SendMessage( hTree
, TVM_SETINSERTMARKCOLOR
, 0, crColor
);
483 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0 );
484 ok(crColor
== RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor
);
487 static void TestGetSetItem(void)
489 TVITEM tviRoot
= {0};
490 int nBufferSize
= 80;
491 char szBuffer
[80] = {0};
493 /* Test the root item */
494 tviRoot
.hItem
= hRoot
;
495 tviRoot
.mask
= TVIF_TEXT
;
496 tviRoot
.cchTextMax
= nBufferSize
;
497 tviRoot
.pszText
= szBuffer
;
498 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tviRoot
);
499 ok(!strcmp("Root", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer
);
501 /* Change the root text */
502 strncpy(szBuffer
, "Testing123", nBufferSize
);
503 SendMessage( hTree
, TVM_SETITEM
, 0, (LPARAM
)&tviRoot
);
504 memset(szBuffer
, 0, nBufferSize
);
505 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tviRoot
);
506 ok(!strcmp("Testing123", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer
);
508 /* Reset the root text */
509 memset(szBuffer
, 0, nBufferSize
);
510 strncpy(szBuffer
, "Root", nBufferSize
);
511 SendMessage( hTree
, TVM_SETITEM
, 0, (LPARAM
)&tviRoot
);
514 static void TestGetSetItemHeight(void)
519 /* Assuming default height to begin with */
520 ulOldHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
522 /* Explicitly setting and getting the default height */
523 SendMessage( hTree
, TVM_SETITEMHEIGHT
, -1, 0 );
524 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
525 ok(ulNewHeight
== ulOldHeight
, "Default height not set properly, reported %d, expected %d\n", ulNewHeight
, ulOldHeight
);
527 /* Explicitly setting and getting the height of twice the normal */
528 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 2*ulOldHeight
, 0 );
529 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
530 ok(ulNewHeight
== 2*ulOldHeight
, "New height not set properly, reported %d, expected %d\n", ulNewHeight
, 2*ulOldHeight
);
532 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
533 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 9, 0 );
534 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
535 ok(ulNewHeight
== 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight
, 8);
538 static void TestGetSetScrollTime(void)
540 int ulExpectedTime
= 20;
542 SendMessage( hTree
, TVM_SETSCROLLTIME
, ulExpectedTime
, 0 );
543 ulTime
= (int)SendMessage( hTree
, TVM_GETSCROLLTIME
, 0, 0 );
544 ok(ulTime
== ulExpectedTime
, "Scroll time reported as %d, expected %d\n", ulTime
, ulExpectedTime
);
547 static void TestGetSetTextColor(void)
549 /* If the value is -1, the control is using the system color for the text color. */
550 COLORREF crColor
= RGB(0,0,0);
551 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
552 ok(crColor
== -1, "Default text color reported as 0x%.8x\n", crColor
);
554 /* Test for black text */
555 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, (LPARAM
)RGB(0,0,0) );
556 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
557 ok(crColor
== RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor
);
559 /* Test for white text */
560 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, (LPARAM
)RGB(255,255,255) );
561 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
562 ok(crColor
== RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor
);
564 /* Reset the default text color */
565 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, -1 );
568 static void TestGetSetToolTips(void)
570 HWND hwndLastToolTip
= NULL
;
573 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
574 hPopupTreeView
= CreateWindow(WC_TREEVIEW
, NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 100, 100, hMainWnd
, NULL
, NULL
, NULL
);
575 DestroyWindow(hPopupTreeView
);
577 /* Testing setting a NULL ToolTip */
578 SendMessage( hTree
, TVM_SETTOOLTIPS
, 0, 0 );
579 hwndLastToolTip
= (HWND
)SendMessage( hTree
, TVM_GETTOOLTIPS
, 0, 0 );
580 ok(hwndLastToolTip
== NULL
, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip
);
582 /* TODO: Add a test of an actual tooltip */
585 static void TestGetSetUnicodeFormat(void)
587 BOOL bPreviousSetting
= 0;
588 BOOL bNewSetting
= 0;
591 bPreviousSetting
= (BOOL
)SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 1, 0 );
592 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
593 ok(bNewSetting
== 1, "Unicode setting did not work.\n");
596 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 0, 0 );
597 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
598 ok(bNewSetting
== 0, "ANSI setting did not work.\n");
600 /* Revert to original setting */
601 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, (LPARAM
)bPreviousSetting
, 0 );
604 static void TestGetSet(void)
606 /* TVM_GETBKCOLOR and TVM_SETBKCOLOR */
607 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
609 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetBkColorSeq
,
610 "TestGetSetBkColor", FALSE
);
612 /* TVM_GETIMAGELIST and TVM_SETIMAGELIST */
613 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
614 TestGetSetImageList();
615 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetImageListSeq
,
616 "TestGetImageList", FALSE
);
618 /* TVM_SETINDENT and TVM_GETINDENT */
619 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
621 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetIndentSeq
,
622 "TestGetSetIndent", FALSE
);
624 /* TVM_GETINSERTMARKCOLOR and TVM_GETINSERTMARKCOLOR */
625 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
626 TestGetSetInsertMarkColor();
627 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetInsertMarkColorSeq
,
628 "TestGetSetInsertMarkColor", FALSE
);
630 /* TVM_GETITEM and TVM_SETITEM */
631 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
633 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetItemSeq
,
634 "TestGetSetItem", FALSE
);
636 /* TVM_GETITEMHEIGHT and TVM_SETITEMHEIGHT */
637 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
638 TestGetSetItemHeight();
639 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetItemHeightSeq
,
640 "TestGetSetItemHeight", FALSE
);
642 /* TVM_GETSCROLLTIME and TVM_SETSCROLLTIME */
643 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
644 TestGetSetScrollTime();
645 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetScrollTimeSeq
,
646 "TestGetSetScrollTime", FALSE
);
648 /* TVM_GETTEXTCOLOR and TVM_SETTEXTCOLOR */
649 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
650 TestGetSetTextColor();
651 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetTextColorSeq
,
652 "TestGetSetTextColor", FALSE
);
654 /* TVM_GETTOOLTIPS and TVM_SETTOOLTIPS */
655 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
656 TestGetSetToolTips();
657 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetToolTipsSeq
,
658 "TestGetSetToolTips", TRUE
);
660 /* TVM_GETUNICODEFORMAT and TVM_SETUNICODEFORMAT */
661 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
662 TestGetSetUnicodeFormat();
663 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetUnicodeFormatSeq
,
664 "TestGetSetUnicodeFormat", FALSE
);
667 /* This function hooks in and records all messages to the treeview control */
668 static LRESULT WINAPI
TreeviewWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
670 static long defwndproc_counter
= 0;
673 WNDPROC lpOldProc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
675 msg
.message
= message
;
676 msg
.flags
= sent
|wparam
|lparam
;
677 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
680 add_message(MsgSequences
, LISTVIEW_SEQ_INDEX
, &msg
);
682 defwndproc_counter
++;
683 ret
= CallWindowProcA(lpOldProc
, hwnd
, message
, wParam
, lParam
);
684 defwndproc_counter
--;
689 static LRESULT CALLBACK
MyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
697 hTree
= CreateWindowExA(WS_EX_CLIENTEDGE
, WC_TREEVIEWA
, NULL
, WS_CHILD
|WS_VISIBLE
|
698 TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_EDITLABELS
,
699 0, 0, 120, 100, hWnd
, (HMENU
)100, GetModuleHandleA(0), 0);
703 /* Record the old WNDPROC so we can call it after recording the messages */
704 pOldWndProc
= (WNDPROC
)SetWindowLongPtrA(hTree
, GWLP_WNDPROC
, (LONG_PTR
)TreeviewWndProc
);
705 SetWindowLongPtrA(hTree
, GWLP_USERDATA
, (LONG_PTR
)pOldWndProc
);
711 NMHDR
*pHdr
= (NMHDR
*)lParam
;
713 ok(pHdr
->code
!= NM_FIRST
- 19, "Treeview should not send NM_TOOLTIPSCREATED\n");
714 if (pHdr
->idFrom
== 100) {
715 NMTREEVIEWA
*pTreeView
= (LPNMTREEVIEWA
) lParam
;
717 case TVN_SELCHANGINGA
:
719 IdentifyItem(pTreeView
->itemOld
.hItem
);
720 IdentifyItem(pTreeView
->itemNew
.hItem
);
722 case TVN_SELCHANGEDA
:
724 IdentifyItem(pTreeView
->itemOld
.hItem
);
725 IdentifyItem(pTreeView
->itemNew
.hItem
);
727 case TVN_GETDISPINFOA
: {
728 NMTVDISPINFOA
*disp
= (NMTVDISPINFOA
*)lParam
;
729 if (disp
->item
.mask
& TVIF_TEXT
) {
730 lstrcpyn(disp
->item
.pszText
, TEST_CALLBACK_TEXT
, disp
->item
.cchTextMax
);
740 MoveWindow(hTree
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
748 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
756 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
760 hComctl32
= GetModuleHandleA("comctl32.dll");
761 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
762 if (pInitCommonControlsEx
)
764 INITCOMMONCONTROLSEX iccex
;
765 iccex
.dwSize
= sizeof(iccex
);
766 iccex
.dwICC
= ICC_TREEVIEW_CLASSES
;
767 pInitCommonControlsEx(&iccex
);
770 InitCommonControls();
772 init_msg_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
774 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
777 wc
.hInstance
= GetModuleHandleA(NULL
);
779 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
780 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
781 wc
.lpszMenuName
= NULL
;
782 wc
.lpszClassName
= "MyTestWnd";
783 wc
.lpfnWndProc
= MyWndProc
;
787 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
788 CW_USEDEFAULT
, CW_USEDEFAULT
, 130, 105, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
790 if ( !ok(hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n") )
793 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
795 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, FillRootSeq
, "FillRoot", FALSE
);
797 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
799 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoTest1Seq
, "DoTest1", FALSE
);
801 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
803 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoTest2Seq
, "DoTest2", FALSE
);
805 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
807 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoTest3Seq
, "DoTest3", FALSE
);
809 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
811 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoFocusTestSeq
, "DoFocusTest", TRUE
);
813 /* Sequences tested inside due to number */
816 /* Clears all the previous items */
819 PostMessageA(hMainWnd
, WM_CLOSE
, 0, 0);
820 while(GetMessageA(&msg
,0,0,0)) {
821 TranslateMessage(&msg
);
822 DispatchMessageA(&msg
);