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 #define NUM_MSG_SEQUENCES 1
36 #define LISTVIEW_SEQ_INDEX 0
38 static struct msg_sequence
*MsgSequences
[NUM_MSG_SEQUENCES
];
40 static const struct message FillRootSeq
[] = {
41 { TVM_INSERTITEM
, sent
},
42 { TVM_GETITEM
, sent
},
43 { TVM_INSERTITEM
, sent
},
47 static const struct message DoTest1Seq
[] = {
48 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
49 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
50 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
51 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
52 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
53 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
57 static const struct message DoTest2Seq
[] = {
58 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
59 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
60 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
61 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
62 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
63 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
67 static const struct message DoTest3Seq
[] = {
68 { TVM_INSERTITEM
, sent
},
69 { TVM_GETITEM
, sent
},
70 { TVM_DELETEITEM
, sent
},
74 static const struct message DoFocusTestSeq
[] = {
75 { TVM_INSERTITEM
, sent
},
76 { TVM_INSERTITEM
, sent
},
77 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
},
78 { WM_NCCALCSIZE
, sent
|wparam
|defwinproc
, 0x00000001 },
79 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
},
80 { WM_SIZE
, sent
|defwinproc
},
81 { WM_WINDOWPOSCHANGING
, sent
},
82 { WM_NCCALCSIZE
, sent
|wparam
, 0x00000001 },
83 { WM_WINDOWPOSCHANGED
, sent
},
84 { WM_SIZE
, sent
|defwinproc
},
85 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
|optional
},
86 { WM_NCCALCSIZE
, sent
|wparam
|defwinproc
|optional
, 0x00000001 },
87 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
|optional
},
88 { WM_SIZE
, sent
|defwinproc
|optional
},
89 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
90 /* The following end up out of order in wine */
91 { WM_PAINT
, sent
|defwinproc
},
92 { WM_NCPAINT
, sent
|wparam
|defwinproc
, 0x00000001 },
93 { WM_ERASEBKGND
, sent
|defwinproc
},
94 { TVM_EDITLABEL
, sent
},
95 { WM_COMMAND
, sent
|wparam
|defwinproc
, 0x04000000 },
96 { WM_COMMAND
, sent
|wparam
|defwinproc
, 0x03000000 },
97 { WM_PARENTNOTIFY
, sent
|wparam
|defwinproc
, 0x00000001 },
98 { WM_KILLFOCUS
, sent
|defwinproc
},
99 { WM_PAINT
, sent
|defwinproc
},
100 { WM_IME_SETCONTEXT
, sent
|defwinproc
|optional
},
101 { WM_COMMAND
, sent
|wparam
|defwinproc
, 0x01000000},
102 { WM_ERASEBKGND
, sent
|defwinproc
},
103 { WM_CTLCOLOREDIT
, sent
|defwinproc
|optional
},
104 { WM_CTLCOLOREDIT
, sent
|defwinproc
|optional
},
108 static const struct message TestGetSetBkColorSeq
[] = {
109 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
110 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
111 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
112 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00ffffff },
113 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
114 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0xffffffff },
118 static const struct message TestGetSetImageListSeq
[] = {
119 { TVM_SETIMAGELIST
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
120 { TVM_GETIMAGELIST
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
124 static const struct message TestGetSetIndentSeq
[] = {
125 { TVM_SETINDENT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
126 { TVM_GETINDENT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
127 /* The actual amount to indent is dependent on the system for this message */
128 { TVM_SETINDENT
, sent
},
129 { TVM_GETINDENT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
133 static const struct message TestGetSetInsertMarkColorSeq
[] = {
134 { TVM_SETINSERTMARKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
135 { TVM_GETINSERTMARKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
139 static const struct message TestGetSetItemSeq
[] = {
140 { TVM_GETITEM
, sent
},
141 { TVM_SETITEM
, sent
},
142 { TVM_GETITEM
, sent
},
143 { TVM_SETITEM
, sent
},
147 static const struct message TestGetSetItemHeightSeq
[] = {
148 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
149 { TVM_SETITEMHEIGHT
, sent
|wparam
|lparam
, 0xffffffff, 0x00000000 },
150 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
151 { TVM_SETITEMHEIGHT
, sent
|lparam
, 0xcccccccc, 0x00000000 },
152 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
|optional
, 0x00000000, 0x00000000 },
153 { TVM_SETITEMHEIGHT
, sent
|wparam
|lparam
|optional
, 0x00000009, 0x00000000 },
154 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
},
155 { WM_NCCALCSIZE
, sent
|wparam
|defwinproc
, 0x00000001 },
156 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
},
157 { WM_SIZE
, sent
|defwinproc
},
158 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
162 static const struct message TestGetSetScrollTimeSeq
[] = {
163 { TVM_SETSCROLLTIME
, sent
|wparam
|lparam
, 0x00000014, 0x00000000 },
164 { TVM_GETSCROLLTIME
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
168 static const struct message TestGetSetTextColorSeq
[] = {
169 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
170 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
171 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
172 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00ffffff },
173 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
174 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0xffffffff },
178 static const struct message TestGetSetToolTipsSeq
[] = {
179 { WM_COMMAND
, sent
|wparam
, 0x02000000 },
180 { WM_PARENTNOTIFY
, sent
|wparam
|defwinproc
, 0x00020002 },
181 { TVM_SETTOOLTIPS
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
182 { TVM_GETTOOLTIPS
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
186 static const struct message TestGetSetUnicodeFormatSeq
[] = {
187 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000001, 0x00000000 },
188 { TVM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
189 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
190 { TVM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
191 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
195 static HWND hMainWnd
;
197 static HWND hTree
, hEdit
;
198 static HTREEITEM hRoot
, hChild
;
201 static char sequence
[256];
203 static void Clear(void)
209 static void AddItem(char ch
)
211 sequence
[pos
++] = ch
;
212 sequence
[pos
] = '\0';
215 static void IdentifyItem(HTREEITEM hItem
)
217 if (hItem
== hRoot
) {
221 if (hItem
== hChild
) {
232 static void FillRoot(void)
236 static CHAR root
[] = "Root",
241 ins
.hParent
= TVI_ROOT
;
242 ins
.hInsertAfter
= TVI_ROOT
;
243 U(ins
).item
.mask
= TVIF_TEXT
;
244 U(ins
).item
.pszText
= root
;
245 hRoot
= TreeView_InsertItem(hTree
, &ins
);
248 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
250 tvi
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
251 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
252 ok(tvi
.iImage
== 0, "tvi.iImage=%d\n", tvi
.iImage
);
253 ok(tvi
.iSelectedImage
== 0, "tvi.iSelectedImage=%d\n", tvi
.iSelectedImage
);
257 ins
.hInsertAfter
= TVI_FIRST
;
258 U(ins
).item
.mask
= TVIF_TEXT
;
259 U(ins
).item
.pszText
= child
;
260 hChild
= TreeView_InsertItem(hTree
, &ins
);
264 ok(!strcmp(sequence
, "AB."), "Item creation\n");
267 static void DoTest1(void)
270 r
= TreeView_SelectItem(hTree
, NULL
);
273 r
= TreeView_SelectItem(hTree
, hRoot
);
275 r
= TreeView_SelectItem(hTree
, hRoot
);
277 r
= TreeView_SelectItem(hTree
, NULL
);
279 r
= TreeView_SelectItem(hTree
, NULL
);
281 r
= TreeView_SelectItem(hTree
, hRoot
);
283 ok(!strcmp(sequence
, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
286 static void DoTest2(void)
289 r
= TreeView_SelectItem(hTree
, NULL
);
292 r
= TreeView_SelectItem(hTree
, hRoot
);
294 r
= TreeView_SelectItem(hTree
, hRoot
);
296 r
= TreeView_SelectItem(hTree
, hChild
);
298 r
= TreeView_SelectItem(hTree
, hChild
);
300 r
= TreeView_SelectItem(hTree
, hRoot
);
302 ok(!strcmp(sequence
, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
305 static void DoTest3(void)
311 int nBufferSize
= 80;
312 CHAR szBuffer
[80] = "Blah";
314 /* add an item without TVIF_TEXT mask and pszText == NULL */
316 ins
.hInsertAfter
= TVI_ROOT
;
317 U(ins
).item
.mask
= 0;
318 U(ins
).item
.pszText
= NULL
;
319 U(ins
).item
.cchTextMax
= 0;
320 hChild
= TreeView_InsertItem(hTree
, &ins
);
323 /* retrieve it with TVIF_TEXT mask */
325 tvi
.mask
= TVIF_TEXT
;
326 tvi
.cchTextMax
= nBufferSize
;
327 tvi
.pszText
= szBuffer
;
329 SendMessageA( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
330 ok(!strcmp(szBuffer
, ""), "szBuffer=\"%s\", expected \"\"\n", szBuffer
);
331 ok(SendMessageA(hTree
, TVM_DELETEITEM
, 0, (LPARAM
)hChild
), "DeleteItem failed\n");
334 static void DoFocusTest(void)
337 static CHAR child1
[] = "Edit",
338 child2
[] = "A really long string";
339 HTREEITEM hChild1
, hChild2
;
341 /* This test verifies that when a label is being edited, scrolling
342 * the treeview does not cause the label to lose focus. To test
343 * this, first some additional entries are added to generate
347 ins
.hInsertAfter
= hChild
;
348 U(ins
).item
.mask
= TVIF_TEXT
;
349 U(ins
).item
.pszText
= child1
;
350 hChild1
= TreeView_InsertItem(hTree
, &ins
);
352 ins
.hInsertAfter
= hChild1
;
353 U(ins
).item
.mask
= TVIF_TEXT
;
354 U(ins
).item
.pszText
= child2
;
355 hChild2
= TreeView_InsertItem(hTree
, &ins
);
358 ShowWindow(hMainWnd
,SW_SHOW
);
359 /* Using SendMessageA since Win98 doesn't have default unicode support */
360 SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hChild
);
361 hEdit
= TreeView_EditLabel(hTree
, hChild
);
362 ScrollWindowEx(hTree
, -10, 0, NULL
, NULL
, NULL
, NULL
, SW_SCROLLCHILDREN
);
363 ok(GetFocus() == hEdit
, "Edit control should have focus\n");
366 static void TestGetSetBkColor(void)
368 COLORREF crColor
= RGB(0,0,0);
371 /* If the value is -1, the control is using the system color for the background color. */
372 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
373 ok(crColor
== -1, "Default background color reported as 0x%.8x\n", crColor
);
376 /* Test for black background */
377 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, (LPARAM
)RGB(0,0,0) );
378 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
379 ok(crColor
== RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor
);
381 /* Test for white background */
382 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, (LPARAM
)RGB(255,255,255) );
383 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
384 ok(crColor
== RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor
);
386 /* Reset the default background */
387 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, -1 );
390 static void TestGetSetImageList(void)
392 HIMAGELIST hImageList
= NULL
;
394 /* Test a NULL HIMAGELIST */
395 SendMessage( hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)hImageList
);
396 hImageList
= (HIMAGELIST
)SendMessage( hTree
, TVM_GETIMAGELIST
, TVSIL_NORMAL
, 0 );
397 ok(hImageList
== NULL
, "NULL image list, reported as 0x%p, expected 0.\n", hImageList
);
399 /* TODO: Test an actual image list */
402 static void TestGetSetIndent(void)
405 int ulMinIndent
= -1;
406 int ulMoreThanTwiceMin
= -1;
408 /* Finding the minimum indent */
409 SendMessage( hTree
, TVM_SETINDENT
, 0, 0 );
410 ulMinIndent
= (int)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
412 /* Checking an indent that is more than twice the default indent */
413 ulMoreThanTwiceMin
= 2*ulMinIndent
+1;
414 SendMessage( hTree
, TVM_SETINDENT
, ulMoreThanTwiceMin
, 0 );
415 ulIndent
= (DWORD
)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
416 ok(ulIndent
== ulMoreThanTwiceMin
, "Indent reported as %d, expected %d\n", ulIndent
, ulMoreThanTwiceMin
);
419 static void TestGetSetInsertMarkColor(void)
421 COLORREF crColor
= RGB(0,0,0);
422 SendMessage( hTree
, TVM_SETINSERTMARKCOLOR
, 0, crColor
);
423 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0 );
424 ok(crColor
== RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor
);
427 static void TestGetSetItem(void)
429 TVITEM tviRoot
= {0};
430 int nBufferSize
= 80;
431 char szBuffer
[80] = {0};
433 /* Test the root item */
434 tviRoot
.hItem
= hRoot
;
435 tviRoot
.mask
= TVIF_TEXT
;
436 tviRoot
.cchTextMax
= nBufferSize
;
437 tviRoot
.pszText
= szBuffer
;
438 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tviRoot
);
439 ok(!strcmp("Root", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer
);
441 /* Change the root text */
442 strncpy(szBuffer
, "Testing123", nBufferSize
);
443 SendMessage( hTree
, TVM_SETITEM
, 0, (LPARAM
)&tviRoot
);
444 memset(szBuffer
, 0, nBufferSize
);
445 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tviRoot
);
446 ok(!strcmp("Testing123", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer
);
448 /* Reset the root text */
449 memset(szBuffer
, 0, nBufferSize
);
450 strncpy(szBuffer
, "Root", nBufferSize
);
451 SendMessage( hTree
, TVM_SETITEM
, 0, (LPARAM
)&tviRoot
);
454 static void TestGetSetItemHeight(void)
459 /* Assuming default height to begin with */
460 ulOldHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
462 /* Explicitly setting and getting the default height */
463 SendMessage( hTree
, TVM_SETITEMHEIGHT
, -1, 0 );
464 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
465 ok(ulNewHeight
== ulOldHeight
, "Default height not set properly, reported %d, expected %d\n", ulNewHeight
, ulOldHeight
);
467 /* Explicitly setting and getting the height of twice the normal */
468 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 2*ulOldHeight
, 0 );
469 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
470 ok(ulNewHeight
== 2*ulOldHeight
, "New height not set properly, reported %d, expected %d\n", ulNewHeight
, 2*ulOldHeight
);
472 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
473 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 9, 0 );
474 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
475 ok(ulNewHeight
== 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight
, 8);
478 static void TestGetSetScrollTime(void)
480 int ulExpectedTime
= 20;
482 SendMessage( hTree
, TVM_SETSCROLLTIME
, ulExpectedTime
, 0 );
483 ulTime
= (int)SendMessage( hTree
, TVM_GETSCROLLTIME
, 0, 0 );
484 ok(ulTime
== ulExpectedTime
, "Scroll time reported as %d, expected %d\n", ulTime
, ulExpectedTime
);
487 static void TestGetSetTextColor(void)
489 /* If the value is -1, the control is using the system color for the text color. */
490 COLORREF crColor
= RGB(0,0,0);
491 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
492 ok(crColor
== -1, "Default text color reported as 0x%.8x\n", crColor
);
494 /* Test for black text */
495 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, (LPARAM
)RGB(0,0,0) );
496 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
497 ok(crColor
== RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor
);
499 /* Test for white text */
500 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, (LPARAM
)RGB(255,255,255) );
501 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
502 ok(crColor
== RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor
);
504 /* Reset the default text color */
505 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, -1 );
508 static void TestGetSetToolTips(void)
510 HWND hwndLastToolTip
= NULL
;
513 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
514 hPopupTreeView
= CreateWindow(WC_TREEVIEW
, NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 100, 100, hMainWnd
, NULL
, NULL
, NULL
);
515 DestroyWindow(hPopupTreeView
);
517 /* Testing setting a NULL ToolTip */
518 SendMessage( hTree
, TVM_SETTOOLTIPS
, 0, 0 );
519 hwndLastToolTip
= (HWND
)SendMessage( hTree
, TVM_GETTOOLTIPS
, 0, 0 );
520 ok(hwndLastToolTip
== NULL
, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip
);
522 /* TODO: Add a test of an actual tooltip */
525 static void TestGetSetUnicodeFormat(void)
527 BOOL bPreviousSetting
= 0;
528 BOOL bNewSetting
= 0;
531 bPreviousSetting
= (BOOL
)SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 1, 0 );
532 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
533 ok(bNewSetting
== 1, "Unicode setting did not work.\n");
536 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 0, 0 );
537 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
538 ok(bNewSetting
== 0, "ANSI setting did not work.\n");
540 /* Revert to original setting */
541 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, (LPARAM
)bPreviousSetting
, 0 );
544 static void TestGetSet(void)
546 /* TVM_GETBKCOLOR and TVM_SETBKCOLOR */
547 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
549 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetBkColorSeq
,
550 "TestGetSetBkColor", FALSE
);
552 /* TVM_GETIMAGELIST and TVM_SETIMAGELIST */
553 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
554 TestGetSetImageList();
555 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetImageListSeq
,
556 "TestGetImageList", FALSE
);
558 /* TVM_SETINDENT and TVM_GETINDENT */
559 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
561 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetIndentSeq
,
562 "TestGetSetIndent", FALSE
);
564 /* TVM_GETINSERTMARKCOLOR and TVM_GETINSERTMARKCOLOR */
565 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
566 TestGetSetInsertMarkColor();
567 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetInsertMarkColorSeq
,
568 "TestGetSetInsertMarkColor", FALSE
);
570 /* TVM_GETITEM and TVM_SETITEM */
571 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
573 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetItemSeq
,
574 "TestGetSetItem", FALSE
);
576 /* TVM_GETITEMHEIGHT and TVM_SETITEMHEIGHT */
577 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
578 TestGetSetItemHeight();
579 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetItemHeightSeq
,
580 "TestGetSetItemHeight", FALSE
);
582 /* TVM_GETSCROLLTIME and TVM_SETSCROLLTIME */
583 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
584 TestGetSetScrollTime();
585 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetScrollTimeSeq
,
586 "TestGetSetScrollTime", FALSE
);
588 /* TVM_GETTEXTCOLOR and TVM_SETTEXTCOLOR */
589 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
590 TestGetSetTextColor();
591 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetTextColorSeq
,
592 "TestGetSetTextColor", FALSE
);
594 /* TVM_GETTOOLTIPS and TVM_SETTOOLTIPS */
595 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
596 TestGetSetToolTips();
597 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetToolTipsSeq
,
598 "TestGetSetToolTips", TRUE
);
600 /* TVM_GETUNICODEFORMAT and TVM_SETUNICODEFORMAT */
601 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
602 TestGetSetUnicodeFormat();
603 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetUnicodeFormatSeq
,
604 "TestGetSetUnicodeFormat", FALSE
);
607 /* This function hooks in and records all messages to the treeview control */
608 static LRESULT WINAPI
TreeviewWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
610 static long defwndproc_counter
= 0;
613 WNDPROC lpOldProc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
615 msg
.message
= message
;
616 msg
.flags
= sent
|wparam
|lparam
;
617 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
620 add_message(MsgSequences
, LISTVIEW_SEQ_INDEX
, &msg
);
622 defwndproc_counter
++;
623 ret
= CallWindowProcA(lpOldProc
, hwnd
, message
, wParam
, lParam
);
624 defwndproc_counter
--;
629 static LRESULT CALLBACK
MyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
637 hTree
= CreateWindowExA(WS_EX_CLIENTEDGE
, WC_TREEVIEWA
, NULL
, WS_CHILD
|WS_VISIBLE
|
638 TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_EDITLABELS
,
639 0, 0, 120, 100, hWnd
, (HMENU
)100, GetModuleHandleA(0), 0);
643 /* Record the old WNDPROC so we can call it after recording the messages */
644 pOldWndProc
= (WNDPROC
)SetWindowLongPtrA(hTree
, GWLP_WNDPROC
, (LONG_PTR
)TreeviewWndProc
);
645 SetWindowLongPtrA(hTree
, GWLP_USERDATA
, (LONG_PTR
)pOldWndProc
);
651 NMHDR
*pHdr
= (NMHDR
*)lParam
;
653 ok(pHdr
->code
!= NM_FIRST
- 19, "Treeview should not send NM_TOOLTIPSCREATED\n");
654 if (pHdr
->idFrom
== 100) {
655 NMTREEVIEWA
*pTreeView
= (LPNMTREEVIEWA
) lParam
;
657 case TVN_SELCHANGINGA
:
659 IdentifyItem(pTreeView
->itemOld
.hItem
);
660 IdentifyItem(pTreeView
->itemNew
.hItem
);
662 case TVN_SELCHANGEDA
:
664 IdentifyItem(pTreeView
->itemOld
.hItem
);
665 IdentifyItem(pTreeView
->itemNew
.hItem
);
673 MoveWindow(hTree
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
681 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
689 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
693 hComctl32
= GetModuleHandleA("comctl32.dll");
694 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
695 if (pInitCommonControlsEx
)
697 INITCOMMONCONTROLSEX iccex
;
698 iccex
.dwSize
= sizeof(iccex
);
699 iccex
.dwICC
= ICC_TREEVIEW_CLASSES
;
700 pInitCommonControlsEx(&iccex
);
703 InitCommonControls();
705 init_msg_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
707 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
710 wc
.hInstance
= GetModuleHandleA(NULL
);
712 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
713 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
714 wc
.lpszMenuName
= NULL
;
715 wc
.lpszClassName
= "MyTestWnd";
716 wc
.lpfnWndProc
= MyWndProc
;
720 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
721 CW_USEDEFAULT
, CW_USEDEFAULT
, 130, 105, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
723 if ( !ok(hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n") )
726 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
728 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, FillRootSeq
, "FillRoot", FALSE
);
730 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
732 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoTest1Seq
, "DoTest1", FALSE
);
734 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
736 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoTest2Seq
, "DoTest2", FALSE
);
738 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
740 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoTest3Seq
, "DoTest3", FALSE
);
742 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
744 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoFocusTestSeq
, "DoFocusTest", TRUE
);
746 /* Sequences tested inside due to number */
749 PostMessageA(hMainWnd
, WM_CLOSE
, 0, 0);
750 while(GetMessageA(&msg
,0,0,0)) {
751 TranslateMessage(&msg
);
752 DispatchMessageA(&msg
);