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);
430 /* If the value is -1, the control is using the system color for the background color. */
431 crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
432 ok(crColor == -1, "Default background color reported as 0x%.8x\n", crColor);
434 /* Test for black background */
435 SendMessage( hTree, TVM_SETBKCOLOR, 0, (LPARAM)RGB(0,0,0) );
436 crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
437 ok(crColor == RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor);
439 /* Test for white background */
440 SendMessage( hTree, TVM_SETBKCOLOR, 0, (LPARAM)RGB(255,255,255) );
441 crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
442 ok(crColor == RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor);
444 /* Reset the default background */
445 SendMessage( hTree, TVM_SETBKCOLOR, 0, -1 );
448 static void TestGetSetImageList(void)
450 HIMAGELIST hImageList = NULL;
452 /* Test a NULL HIMAGELIST */
453 SendMessage( hTree, TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)hImageList );
454 hImageList = (HIMAGELIST)SendMessage( hTree, TVM_GETIMAGELIST, TVSIL_NORMAL, 0 );
455 ok(hImageList == NULL, "NULL image list, reported as 0x%p, expected 0.\n", hImageList);
457 /* TODO: Test an actual image list */
460 static void TestGetSetIndent(void)
463 int ulMinIndent = -1;
464 int ulMoreThanTwiceMin = -1;
466 /* Finding the minimum indent */
467 SendMessage( hTree, TVM_SETINDENT, 0, 0 );
468 ulMinIndent = (int)SendMessage( hTree, TVM_GETINDENT, 0, 0 );
470 /* Checking an indent that is more than twice the default indent */
471 ulMoreThanTwiceMin = 2*ulMinIndent+1;
472 SendMessage( hTree, TVM_SETINDENT, ulMoreThanTwiceMin, 0 );
473 ulIndent = (DWORD)SendMessage( hTree, TVM_GETINDENT, 0, 0 );
474 ok(ulIndent == ulMoreThanTwiceMin, "Indent reported as %d, expected %d\n", ulIndent, ulMoreThanTwiceMin);
477 static void TestGetSetInsertMarkColor(void)
479 COLORREF crColor = RGB(0,0,0);
480 SendMessage( hTree, TVM_SETINSERTMARKCOLOR, 0, crColor );
481 crColor = (COLORREF)SendMessage( hTree, TVM_GETINSERTMARKCOLOR, 0, 0 );
482 ok(crColor == RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor);
485 static void TestGetSetItem(void)
487 TVITEM tviRoot = {0};
488 int nBufferSize = 80;
489 char szBuffer[80] = {0};
491 /* Test the root item */
492 tviRoot.hItem = hRoot;
493 tviRoot.mask = TVIF_TEXT;
494 tviRoot.cchTextMax = nBufferSize;
495 tviRoot.pszText = szBuffer;
496 SendMessage( hTree, TVM_GETITEM, 0, (LPARAM)&tviRoot );
497 ok(!strcmp("Root", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer);
499 /* Change the root text */
500 strncpy(szBuffer, "Testing123", nBufferSize);
501 SendMessage( hTree, TVM_SETITEM, 0, (LPARAM)&tviRoot );
502 memset(szBuffer, 0, nBufferSize);
503 SendMessage( hTree, TVM_GETITEM, 0, (LPARAM)&tviRoot );
504 ok(!strcmp("Testing123", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer);
506 /* Reset the root text */
507 memset(szBuffer, 0, nBufferSize);
508 strncpy(szBuffer, "Root", nBufferSize);
509 SendMessage( hTree, TVM_SETITEM, 0, (LPARAM)&tviRoot );
512 static void TestGetSetItemHeight(void)
517 /* Assuming default height to begin with */
518 ulOldHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
520 /* Explicitly setting and getting the default height */
521 SendMessage( hTree, TVM_SETITEMHEIGHT, -1, 0 );
522 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
523 ok(ulNewHeight == ulOldHeight, "Default height not set properly, reported %d, expected %d\n", ulNewHeight, ulOldHeight);
525 /* Explicitly setting and getting the height of twice the normal */
526 SendMessage( hTree, TVM_SETITEMHEIGHT, 2*ulOldHeight, 0 );
527 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
528 ok(ulNewHeight == 2*ulOldHeight, "New height not set properly, reported %d, expected %d\n", ulNewHeight, 2*ulOldHeight);
530 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
531 SendMessage( hTree, TVM_SETITEMHEIGHT, 9, 0 );
532 ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
533 ok(ulNewHeight == 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight, 8);
536 static void TestGetSetScrollTime(void)
538 int ulExpectedTime = 20;
540 SendMessage( hTree, TVM_SETSCROLLTIME, ulExpectedTime, 0 );
541 ulTime = (int)SendMessage( hTree, TVM_GETSCROLLTIME, 0, 0 );
542 ok(ulTime == ulExpectedTime, "Scroll time reported as %d, expected %d\n", ulTime, ulExpectedTime);
545 static void TestGetSetTextColor(void)
547 /* If the value is -1, the control is using the system color for the text color. */
548 COLORREF crColor = RGB(0,0,0);
549 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
550 ok(crColor == -1, "Default text color reported as 0x%.8x\n", crColor);
552 /* Test for black text */
553 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, (LPARAM)RGB(0,0,0) );
554 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
555 ok(crColor == RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor);
557 /* Test for white text */
558 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, (LPARAM)RGB(255,255,255) );
559 crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
560 ok(crColor == RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor);
562 /* Reset the default text color */
563 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, -1 );
566 static void TestGetSetToolTips(void)
568 HWND hwndLastToolTip = NULL;
571 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
572 hPopupTreeView = CreateWindow(WC_TREEVIEW, NULL, WS_POPUP|WS_VISIBLE, 0, 0, 100, 100, hMainWnd, NULL, NULL, NULL);
573 DestroyWindow(hPopupTreeView);
575 /* Testing setting a NULL ToolTip */
576 SendMessage( hTree, TVM_SETTOOLTIPS, 0, 0 );
577 hwndLastToolTip = (HWND)SendMessage( hTree, TVM_GETTOOLTIPS, 0, 0 );
578 ok(hwndLastToolTip == NULL, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip);
580 /* TODO: Add a test of an actual tooltip */
583 static void TestGetSetUnicodeFormat(void)
585 BOOL bPreviousSetting = 0;
586 BOOL bNewSetting = 0;
589 bPreviousSetting = (BOOL)SendMessage( hTree, TVM_SETUNICODEFORMAT, 1, 0 );
590 bNewSetting = (BOOL)SendMessage( hTree, TVM_GETUNICODEFORMAT, 0, 0 );
591 ok(bNewSetting == 1, "Unicode setting did not work.\n");
594 SendMessage( hTree, TVM_SETUNICODEFORMAT, 0, 0 );
595 bNewSetting = (BOOL)SendMessage( hTree, TVM_GETUNICODEFORMAT, 0, 0 );
596 ok(bNewSetting == 0, "ANSI setting did not work.\n");
598 /* Revert to original setting */
599 SendMessage( hTree, TVM_SETUNICODEFORMAT, (LPARAM)bPreviousSetting, 0 );
602 static void TestGetSet(void)
604 /* TVM_GETBKCOLOR and TVM_SETBKCOLOR */
605 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
607 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetBkColorSeq,
608 "TestGetSetBkColor", FALSE);
610 /* TVM_GETIMAGELIST and TVM_SETIMAGELIST */
611 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
612 TestGetSetImageList();
613 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetImageListSeq,
614 "TestGetImageList", FALSE);
616 /* TVM_SETINDENT and TVM_GETINDENT */
617 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
619 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetIndentSeq,
620 "TestGetSetIndent", FALSE);
622 /* TVM_GETINSERTMARKCOLOR and TVM_GETINSERTMARKCOLOR */
623 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
624 TestGetSetInsertMarkColor();
625 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetInsertMarkColorSeq,
626 "TestGetSetInsertMarkColor", FALSE);
628 /* TVM_GETITEM and TVM_SETITEM */
629 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
631 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetItemSeq,
632 "TestGetSetItem", FALSE);
634 /* TVM_GETITEMHEIGHT and TVM_SETITEMHEIGHT */
635 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
636 TestGetSetItemHeight();
637 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetItemHeightSeq,
638 "TestGetSetItemHeight", FALSE);
640 /* TVM_GETSCROLLTIME and TVM_SETSCROLLTIME */
641 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
642 TestGetSetScrollTime();
643 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetScrollTimeSeq,
644 "TestGetSetScrollTime", FALSE);
646 /* TVM_GETTEXTCOLOR and TVM_SETTEXTCOLOR */
647 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
648 TestGetSetTextColor();
649 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetTextColorSeq,
650 "TestGetSetTextColor", FALSE);
652 /* TVM_GETTOOLTIPS and TVM_SETTOOLTIPS */
653 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
654 TestGetSetToolTips();
655 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetToolTipsSeq,
656 "TestGetSetToolTips", TRUE);
658 /* TVM_GETUNICODEFORMAT and TVM_SETUNICODEFORMAT */
659 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
660 TestGetSetUnicodeFormat();
661 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetUnicodeFormatSeq,
662 "TestGetSetUnicodeFormat", FALSE);
665 /* This function hooks in and records all messages to the treeview control */
666 static LRESULT WINAPI TreeviewWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
668 static LONG defwndproc_counter = 0;
671 WNDPROC lpOldProc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
673 msg.message = message;
674 msg.flags = sent|wparam|lparam;
675 if (defwndproc_counter) msg.flags |= defwinproc;
678 add_message(MsgSequences, LISTVIEW_SEQ_INDEX, &msg);
680 defwndproc_counter++;
681 ret = CallWindowProcA(lpOldProc, hwnd, message, wParam, lParam);
682 defwndproc_counter--;
687 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
695 hTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL, WS_CHILD|WS_VISIBLE|
696 TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS|TVS_EDITLABELS,
697 0, 0, 120, 100, hWnd, (HMENU)100, GetModuleHandleA(0), 0);
701 /* Record the old WNDPROC so we can call it after recording the messages */
702 pOldWndProc = (WNDPROC)SetWindowLongPtrA(hTree, GWLP_WNDPROC, (LONG_PTR)TreeviewWndProc);
703 SetWindowLongPtrA(hTree, GWLP_USERDATA, (LONG_PTR)pOldWndProc);
709 NMHDR *pHdr = (NMHDR *)lParam;
711 ok(pHdr->code != NM_FIRST - 19, "Treeview should not send NM_TOOLTIPSCREATED\n");
712 if (pHdr->idFrom == 100) {
713 NMTREEVIEWA *pTreeView = (LPNMTREEVIEWA) lParam;
715 case TVN_SELCHANGINGA:
717 IdentifyItem(pTreeView->itemOld.hItem);
718 IdentifyItem(pTreeView->itemNew.hItem);
720 case TVN_SELCHANGEDA:
722 IdentifyItem(pTreeView->itemOld.hItem);
723 IdentifyItem(pTreeView->itemNew.hItem);
725 case TVN_GETDISPINFOA: {
726 NMTVDISPINFOA *disp = (NMTVDISPINFOA *)lParam;
727 if (disp->item.mask & TVIF_TEXT) {
728 lstrcpyn(disp->item.pszText, TEST_CALLBACK_TEXT, disp->item.cchTextMax);
738 MoveWindow(hTree, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
746 return DefWindowProcA(hWnd, msg, wParam, lParam);
751 static void TestExpandInvisible(void)
753 static CHAR nodeText[][5] = {"0", "1", "2", "3", "4"};
759 /* The test builds the following tree and expands then node 1, while node 0 is collapsed.
769 TreeView_DeleteAllItems(hTree);
771 ins.hParent = TVI_ROOT;
772 ins.hInsertAfter = TVI_ROOT;
773 U(ins).item.mask = TVIF_TEXT;
774 U(ins).item.pszText = nodeText[0];
775 node[0] = TreeView_InsertItem(hTree, &ins);
778 ins.hInsertAfter = TVI_LAST;
779 U(ins).item.mask = TVIF_TEXT;
780 ins.hParent = node[0];
782 U(ins).item.pszText = nodeText[1];
783 node[1] = TreeView_InsertItem(hTree, &ins);
785 U(ins).item.pszText = nodeText[4];
786 node[4] = TreeView_InsertItem(hTree, &ins);
789 ins.hParent = node[1];
791 U(ins).item.pszText = nodeText[2];
792 node[2] = TreeView_InsertItem(hTree, &ins);
794 U(ins).item.pszText = nodeText[3];
795 node[3] = TreeView_InsertItem(hTree, &ins);
799 nodeVisible = TreeView_GetItemRect(hTree, node[1], &dummyRect, FALSE);
800 ok(!nodeVisible, "Node 1 should not be visible.\n");
801 nodeVisible = TreeView_GetItemRect(hTree, node[2], &dummyRect, FALSE);
802 ok(!nodeVisible, "Node 2 should not be visible.\n");
803 nodeVisible = TreeView_GetItemRect(hTree, node[3], &dummyRect, FALSE);
804 ok(!nodeVisible, "Node 3 should not be visible.\n");
805 nodeVisible = TreeView_GetItemRect(hTree, node[4], &dummyRect, FALSE);
806 ok(!nodeVisible, "Node 4 should not be visible.\n");
808 ok(TreeView_Expand(hTree, node[1], TVE_EXPAND), "Expand of node 1 failed.\n");
810 nodeVisible = TreeView_GetItemRect(hTree, node[1], &dummyRect, FALSE);
811 ok(!nodeVisible, "Node 1 should not be visible.\n");
812 nodeVisible = TreeView_GetItemRect(hTree, node[2], &dummyRect, FALSE);
814 ok(!nodeVisible, "Node 2 should not be visible.\n");
815 nodeVisible = TreeView_GetItemRect(hTree, node[3], &dummyRect, FALSE);
817 ok(!nodeVisible, "Node 3 should not be visible.\n");
818 nodeVisible = TreeView_GetItemRect(hTree, node[4], &dummyRect, FALSE);
820 ok(!nodeVisible, "Node 4 should not be visible.\n");
827 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
831 hComctl32 = GetModuleHandleA("comctl32.dll");
832 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
833 if (pInitCommonControlsEx)
835 INITCOMMONCONTROLSEX iccex;
836 iccex.dwSize = sizeof(iccex);
837 iccex.dwICC = ICC_TREEVIEW_CLASSES;
838 pInitCommonControlsEx(&iccex);
841 InitCommonControls();
843 init_msg_sequences(MsgSequences, NUM_MSG_SEQUENCES);
845 wc.style = CS_HREDRAW | CS_VREDRAW;
848 wc.hInstance = GetModuleHandleA(NULL);
850 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
851 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
852 wc.lpszMenuName = NULL;
853 wc.lpszClassName = "MyTestWnd";
854 wc.lpfnWndProc = MyWndProc;
858 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
859 CW_USEDEFAULT, CW_USEDEFAULT, 130, 105, NULL, NULL, GetModuleHandleA(NULL), 0);
861 if ( !ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n") )
864 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
866 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, FillRootSeq, "FillRoot", FALSE);
868 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
870 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoTest1Seq, "DoTest1", FALSE);
872 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
874 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoTest2Seq, "DoTest2", FALSE);
876 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
878 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoTest3Seq, "DoTest3", FALSE);
880 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
882 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoFocusTestSeq, "DoFocusTest", TRUE);
884 /* Sequences tested inside due to number */
887 /* Clears all the previous items */
890 /* Clears all the previous items */
891 TestExpandInvisible();
893 PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
894 while(GetMessageA(&msg,0,0,0)) {
895 TranslateMessage(&msg);
896 DispatchMessageA(&msg);