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 DoFocusTestSeq
[] = {
68 { TVM_INSERTITEM
, sent
},
69 { TVM_INSERTITEM
, sent
},
70 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
},
71 { WM_NCCALCSIZE
, sent
|wparam
|defwinproc
, 0x00000001 },
72 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
},
73 { WM_SIZE
, sent
|defwinproc
},
74 { WM_WINDOWPOSCHANGING
, sent
},
75 { WM_NCCALCSIZE
, sent
|wparam
, 0x00000001 },
76 { WM_WINDOWPOSCHANGED
, sent
},
77 { WM_SIZE
, sent
|defwinproc
},
78 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
},
79 { WM_NCCALCSIZE
, sent
|wparam
|defwinproc
, 0x00000001 },
80 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
},
81 { WM_SIZE
, sent
|defwinproc
},
82 { TVM_SELECTITEM
, sent
|wparam
, 0x00000009 },
83 /* The following end up out of order in wine */
84 { WM_PAINT
, sent
|defwinproc
},
85 { WM_NCPAINT
, sent
|wparam
|defwinproc
, 0x00000001 },
86 { WM_ERASEBKGND
, sent
|defwinproc
},
87 { TVM_EDITLABEL
, sent
},
88 { WM_COMMAND
, sent
|wparam
|defwinproc
, 0x04000000 },
89 { WM_COMMAND
, sent
|wparam
|defwinproc
, 0x03000000 },
90 { WM_PARENTNOTIFY
, sent
|wparam
|defwinproc
, 0x00000001 },
91 { WM_KILLFOCUS
, sent
|defwinproc
},
92 { WM_PAINT
, sent
|defwinproc
},
93 { WM_IME_SETCONTEXT
, sent
|defwinproc
|optional
},
94 { WM_COMMAND
, sent
|wparam
|defwinproc
, 0x01000000},
95 { WM_ERASEBKGND
, sent
|defwinproc
},
96 { WM_CTLCOLOREDIT
, sent
|defwinproc
|optional
},
97 { WM_CTLCOLOREDIT
, sent
|defwinproc
|optional
},
101 static const struct message TestGetSetBkColorSeq
[] = {
102 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
103 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
104 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
105 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00ffffff },
106 { TVM_GETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
107 { TVM_SETBKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0xffffffff },
111 static const struct message TestGetSetImageListSeq
[] = {
112 { TVM_SETIMAGELIST
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
113 { TVM_GETIMAGELIST
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
117 static const struct message TestGetSetIndentSeq
[] = {
118 { TVM_SETINDENT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
119 { TVM_GETINDENT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
120 /* The actual amount to indent is dependent on the system for this message */
121 { TVM_SETINDENT
, sent
},
122 { TVM_GETINDENT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
126 static const struct message TestGetSetInsertMarkColorSeq
[] = {
127 { TVM_SETINSERTMARKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
128 { TVM_GETINSERTMARKCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
132 static const struct message TestGetSetItemSeq
[] = {
133 { TVM_GETITEM
, sent
},
134 { TVM_SETITEM
, sent
},
135 { TVM_GETITEM
, sent
},
136 { TVM_SETITEM
, sent
},
140 static const struct message TestGetSetItemHeightSeq
[] = {
141 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
142 { TVM_SETITEMHEIGHT
, sent
|wparam
|lparam
, 0xffffffff, 0x00000000 },
143 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
144 { TVM_SETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000020, 0x00000000 },
145 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
146 { TVM_SETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000009, 0x00000000 },
147 { WM_WINDOWPOSCHANGING
, sent
|defwinproc
},
148 { WM_NCCALCSIZE
, sent
|wparam
|defwinproc
, 0x00000001 },
149 { WM_WINDOWPOSCHANGED
, sent
|defwinproc
},
150 { WM_SIZE
, sent
|defwinproc
},
151 { TVM_GETITEMHEIGHT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
155 static const struct message TestGetSetScrollTimeSeq
[] = {
156 { TVM_SETSCROLLTIME
, sent
|wparam
|lparam
, 0x00000014, 0x00000000 },
157 { TVM_GETSCROLLTIME
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
161 static const struct message TestGetSetTextColorSeq
[] = {
162 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
163 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
164 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
165 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00ffffff },
166 { TVM_GETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
167 { TVM_SETTEXTCOLOR
, sent
|wparam
|lparam
, 0x00000000, 0xffffffff },
171 static const struct message TestGetSetToolTipsSeq
[] = {
172 { TVM_SETTOOLTIPS
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
173 { TVM_GETTOOLTIPS
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
177 static const struct message TestGetSetUnicodeFormatSeq
[] = {
178 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000001, 0x00000000 },
179 { TVM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
180 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
181 { TVM_GETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
182 { TVM_SETUNICODEFORMAT
, sent
|wparam
|lparam
, 0x00000000, 0x00000000 },
186 static HWND hMainWnd
;
188 static HWND hTree
, hEdit
;
189 static HTREEITEM hRoot
, hChild
;
192 static char sequence
[256];
194 static void Clear(void)
200 static void AddItem(char ch
)
202 sequence
[pos
++] = ch
;
203 sequence
[pos
] = '\0';
206 static void IdentifyItem(HTREEITEM hItem
)
208 if (hItem
== hRoot
) {
212 if (hItem
== hChild
) {
223 static void FillRoot(void)
227 static CHAR root
[] = "Root",
232 ins
.hParent
= TVI_ROOT
;
233 ins
.hInsertAfter
= TVI_ROOT
;
234 U(ins
).item
.mask
= TVIF_TEXT
;
235 U(ins
).item
.pszText
= root
;
236 hRoot
= TreeView_InsertItem(hTree
, &ins
);
239 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
241 tvi
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
242 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
243 ok(tvi
.iImage
== 0, "tvi.iImage=%d\n", tvi
.iImage
);
244 ok(tvi
.iSelectedImage
== 0, "tvi.iSelectedImage=%d\n", tvi
.iSelectedImage
);
248 ins
.hInsertAfter
= TVI_FIRST
;
249 U(ins
).item
.mask
= TVIF_TEXT
;
250 U(ins
).item
.pszText
= child
;
251 hChild
= TreeView_InsertItem(hTree
, &ins
);
255 ok(!strcmp(sequence
, "AB."), "Item creation\n");
258 static void DoTest1(void)
261 r
= TreeView_SelectItem(hTree
, NULL
);
264 r
= TreeView_SelectItem(hTree
, hRoot
);
266 r
= TreeView_SelectItem(hTree
, hRoot
);
268 r
= TreeView_SelectItem(hTree
, NULL
);
270 r
= TreeView_SelectItem(hTree
, NULL
);
272 r
= TreeView_SelectItem(hTree
, hRoot
);
274 ok(!strcmp(sequence
, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
277 static void DoTest2(void)
280 r
= TreeView_SelectItem(hTree
, NULL
);
283 r
= TreeView_SelectItem(hTree
, hRoot
);
285 r
= TreeView_SelectItem(hTree
, hRoot
);
287 r
= TreeView_SelectItem(hTree
, hChild
);
289 r
= TreeView_SelectItem(hTree
, hChild
);
291 r
= TreeView_SelectItem(hTree
, hRoot
);
293 ok(!strcmp(sequence
, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
296 static void DoFocusTest(void)
299 static CHAR child1
[] = "Edit",
300 child2
[] = "A really long string";
301 HTREEITEM hChild1
, hChild2
;
303 /* This test verifies that when a label is being edited, scrolling
304 * the treeview does not cause the label to lose focus. To test
305 * this, first some additional entries are added to generate
309 ins
.hInsertAfter
= hChild
;
310 U(ins
).item
.mask
= TVIF_TEXT
;
311 U(ins
).item
.pszText
= child1
;
312 hChild1
= TreeView_InsertItem(hTree
, &ins
);
314 ins
.hInsertAfter
= hChild1
;
315 U(ins
).item
.mask
= TVIF_TEXT
;
316 U(ins
).item
.pszText
= child2
;
317 hChild2
= TreeView_InsertItem(hTree
, &ins
);
320 ShowWindow(hMainWnd
,SW_SHOW
);
321 /* Using SendMessageA since Win98 doesn't have default unicode support */
322 SendMessageA(hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hChild
);
323 hEdit
= TreeView_EditLabel(hTree
, hChild
);
324 ScrollWindowEx(hTree
, -10, 0, NULL
, NULL
, NULL
, NULL
, SW_SCROLLCHILDREN
);
325 ok(GetFocus() == hEdit
, "Edit control should have focus\n");
328 static void TestGetSetBkColor(void)
330 COLORREF crColor
= RGB(0,0,0);
333 /* If the value is -1, the control is using the system color for the background color. */
334 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
335 ok(crColor
== -1, "Default background color reported as 0x%.8x\n", crColor
);
338 /* Test for black background */
339 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, (LPARAM
)RGB(0,0,0) );
340 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
341 ok(crColor
== RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor
);
343 /* Test for white background */
344 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, (LPARAM
)RGB(255,255,255) );
345 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETBKCOLOR
, 0, 0 );
346 ok(crColor
== RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor
);
348 /* Reset the default background */
349 SendMessage( hTree
, TVM_SETBKCOLOR
, 0, -1 );
352 static void TestGetSetImageList(void)
354 HIMAGELIST hImageList
= NULL
;
356 /* Test a NULL HIMAGELIST */
357 SendMessage( hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)hImageList
);
358 hImageList
= (HIMAGELIST
)SendMessage( hTree
, TVM_GETIMAGELIST
, TVSIL_NORMAL
, 0 );
359 ok(hImageList
== NULL
, "NULL image list, reported as 0x%p, expected 0.\n", hImageList
);
361 /* TODO: Test an actual image list */
364 static void TestGetSetIndent(void)
367 int ulMinIndent
= -1;
368 int ulMoreThanTwiceMin
= -1;
370 /* Finding the minimum indent */
371 SendMessage( hTree
, TVM_SETINDENT
, 0, 0 );
372 ulMinIndent
= (int)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
374 /* Checking an indent that is more than twice the default indent */
375 ulMoreThanTwiceMin
= 2*ulMinIndent
+1;
376 SendMessage( hTree
, TVM_SETINDENT
, ulMoreThanTwiceMin
, 0 );
377 ulIndent
= (DWORD
)SendMessage( hTree
, TVM_GETINDENT
, 0, 0 );
378 ok(ulIndent
== ulMoreThanTwiceMin
, "Indent reported as %d, expected %d\n", ulIndent
, ulMoreThanTwiceMin
);
381 static void TestGetSetInsertMarkColor(void)
383 COLORREF crColor
= RGB(0,0,0);
384 SendMessage( hTree
, TVM_SETINSERTMARKCOLOR
, 0, crColor
);
385 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETINSERTMARKCOLOR
, 0, 0 );
386 ok(crColor
== RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor
);
389 static void TestGetSetItem(void)
391 TVITEM tviRoot
= {0};
392 int nBufferSize
= 80;
393 char szBuffer
[80] = {0};
395 /* Test the root item */
396 tviRoot
.hItem
= hRoot
;
397 tviRoot
.mask
= TVIF_TEXT
;
398 tviRoot
.cchTextMax
= nBufferSize
;
399 tviRoot
.pszText
= szBuffer
;
400 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tviRoot
);
401 ok(!strcmp("Root", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer
);
403 /* Change the root text */
404 strncpy(szBuffer
, "Testing123", nBufferSize
);
405 SendMessage( hTree
, TVM_SETITEM
, 0, (LPARAM
)&tviRoot
);
406 memset(szBuffer
, 0, nBufferSize
);
407 SendMessage( hTree
, TVM_GETITEM
, 0, (LPARAM
)&tviRoot
);
408 ok(!strcmp("Testing123", szBuffer
), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer
);
410 /* Reset the root text */
411 memset(szBuffer
, 0, nBufferSize
);
412 strncpy(szBuffer
, "Root", nBufferSize
);
413 SendMessage( hTree
, TVM_SETITEM
, 0, (LPARAM
)&tviRoot
);
416 static void TestGetSetItemHeight(void)
421 /* Assuming default height to begin with */
422 ulOldHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
424 /* Explicitly setting and getting the default height */
425 SendMessage( hTree
, TVM_SETITEMHEIGHT
, -1, 0 );
426 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
427 ok(ulNewHeight
== ulOldHeight
, "Default height not set properly, reported %d, expected %d\n", ulNewHeight
, ulOldHeight
);
429 /* Explicitly setting and getting the height of twice the normal */
430 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 2*ulOldHeight
, 0 );
431 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
432 ok(ulNewHeight
== 2*ulOldHeight
, "New height not set properly, reported %d, expected %d\n", ulNewHeight
, 2*ulOldHeight
);
434 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
435 SendMessage( hTree
, TVM_SETITEMHEIGHT
, 9, 0 );
436 ulNewHeight
= (int) SendMessage( hTree
, TVM_GETITEMHEIGHT
, 0, 0 );
437 ok(ulNewHeight
== 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight
, 8);
440 static void TestGetSetScrollTime(void)
442 int ulExpectedTime
= 20;
444 SendMessage( hTree
, TVM_SETSCROLLTIME
, ulExpectedTime
, 0 );
445 ulTime
= (int)SendMessage( hTree
, TVM_GETSCROLLTIME
, 0, 0 );
446 ok(ulTime
== ulExpectedTime
, "Scroll time reported as %d, expected %d\n", ulTime
, ulExpectedTime
);
449 static void TestGetSetTextColor(void)
451 /* If the value is -1, the control is using the system color for the text color. */
452 COLORREF crColor
= RGB(0,0,0);
453 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
454 ok(crColor
== -1, "Default text color reported as 0x%.8x\n", crColor
);
456 /* Test for black text */
457 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, (LPARAM
)RGB(0,0,0) );
458 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
459 ok(crColor
== RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor
);
461 /* Test for white text */
462 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, (LPARAM
)RGB(255,255,255) );
463 crColor
= (COLORREF
)SendMessage( hTree
, TVM_GETTEXTCOLOR
, 0, 0 );
464 ok(crColor
== RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor
);
466 /* Reset the default text color */
467 SendMessage( hTree
, TVM_SETTEXTCOLOR
, 0, -1 );
470 static void TestGetSetToolTips(void)
472 HWND hwndLastToolTip
= NULL
;
474 /* Testing setting a NULL ToolTip */
475 SendMessage( hTree
, TVM_SETTOOLTIPS
, 0, 0 );
476 hwndLastToolTip
= (HWND
)SendMessage( hTree
, TVM_GETTOOLTIPS
, 0, 0 );
477 ok(hwndLastToolTip
== NULL
, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip
);
479 /* TODO: Add a test of an actual tooltip */
482 static void TestGetSetUnicodeFormat(void)
484 BOOL bPreviousSetting
= 0;
485 BOOL bNewSetting
= 0;
488 bPreviousSetting
= (BOOL
)SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 1, 0 );
489 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
490 ok(bNewSetting
== 1, "Unicode setting did not work.\n");
493 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, 0, 0 );
494 bNewSetting
= (BOOL
)SendMessage( hTree
, TVM_GETUNICODEFORMAT
, 0, 0 );
495 ok(bNewSetting
== 0, "ANSI setting did not work.\n");
497 /* Revert to original setting */
498 SendMessage( hTree
, TVM_SETUNICODEFORMAT
, (LPARAM
)bPreviousSetting
, 0 );
501 static void TestGetSet(void)
503 /* TVM_GETBKCOLOR and TVM_SETBKCOLOR */
504 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
506 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetBkColorSeq
,
507 "TestGetSetBkColor", FALSE
);
509 /* TVM_GETIMAGELIST and TVM_SETIMAGELIST */
510 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
511 TestGetSetImageList();
512 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetImageListSeq
,
513 "TestGetImageList", FALSE
);
515 /* TVM_SETINDENT and TVM_GETINDENT */
516 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
518 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetIndentSeq
,
519 "TestGetSetIndent", FALSE
);
521 /* TVM_GETINSERTMARKCOLOR and TVM_GETINSERTMARKCOLOR */
522 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
523 TestGetSetInsertMarkColor();
524 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetInsertMarkColorSeq
,
525 "TestGetSetInsertMarkColor", FALSE
);
527 /* TVM_GETITEM and TVM_SETITEM */
528 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
530 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetItemSeq
,
531 "TestGetSetItem", FALSE
);
533 /* TVM_GETITEMHEIGHT and TVM_SETITEMHEIGHT */
534 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
535 TestGetSetItemHeight();
536 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetItemHeightSeq
,
537 "TestGetSetItemHeight", FALSE
);
539 /* TVM_GETSCROLLTIME and TVM_SETSCROLLTIME */
540 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
541 TestGetSetScrollTime();
542 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetScrollTimeSeq
,
543 "TestGetSetScrollTime", FALSE
);
545 /* TVM_GETTEXTCOLOR and TVM_SETTEXTCOLOR */
546 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
547 TestGetSetTextColor();
548 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetTextColorSeq
,
549 "TestGetSetTextColor", FALSE
);
551 /* TVM_GETTOOLTIPS and TVM_SETTOOLTIPS */
552 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
553 TestGetSetToolTips();
554 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetToolTipsSeq
,
555 "TestGetSetToolTips", FALSE
);
557 /* TVM_GETUNICODEFORMAT and TVM_SETUNICODEFORMAT */
558 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
559 TestGetSetUnicodeFormat();
560 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, TestGetSetUnicodeFormatSeq
,
561 "TestGetSetUnicodeFormat", FALSE
);
564 /* This function hooks in and records all messages to the treeview control */
565 static LRESULT WINAPI
TreeviewWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
567 static long defwndproc_counter
= 0;
570 WNDPROC
*lpOldProc
= (WNDPROC
*)GetWindowLongA(hwnd
, GWL_USERDATA
);
572 msg
.message
= message
;
573 msg
.flags
= sent
|wparam
|lparam
;
574 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
577 add_message(MsgSequences
, LISTVIEW_SEQ_INDEX
, &msg
);
579 defwndproc_counter
++;
580 ret
= CallWindowProcA(*lpOldProc
, hwnd
, message
, wParam
, lParam
);
581 defwndproc_counter
--;
586 static LRESULT CALLBACK
MyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
588 WNDPROC
*pOldWndProc
;
594 hTree
= CreateWindowExA(WS_EX_CLIENTEDGE
, WC_TREEVIEWA
, NULL
, WS_CHILD
|WS_VISIBLE
|
595 TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_EDITLABELS
,
596 0, 0, 120, 100, hWnd
, (HMENU
)100, GetModuleHandleA(0), 0);
600 pOldWndProc
= HeapAlloc(GetProcessHeap(), 0, sizeof(WNDPROC
));
601 if ( !ok(pOldWndProc
!= NULL
, "Failed to allocate memory for subclass_info.\n") )
607 /* Record the old WNDPROC so we can call it after recording the messages */
608 *pOldWndProc
= (WNDPROC
)SetWindowLongA(hTree
, GWL_WNDPROC
, (LONG
)TreeviewWndProc
);
609 SetWindowLongA(hTree
, GWL_USERDATA
, (LONG
)pOldWndProc
);
615 NMHDR
*pHdr
= (NMHDR
*)lParam
;
617 if (pHdr
->idFrom
== 100) {
618 NMTREEVIEWA
*pTreeView
= (LPNMTREEVIEWA
) lParam
;
620 case TVN_SELCHANGINGA
:
622 IdentifyItem(pTreeView
->itemOld
.hItem
);
623 IdentifyItem(pTreeView
->itemNew
.hItem
);
625 case TVN_SELCHANGEDA
:
627 IdentifyItem(pTreeView
->itemOld
.hItem
);
628 IdentifyItem(pTreeView
->itemNew
.hItem
);
636 MoveWindow(hTree
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
644 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
653 INITCOMMONCONTROLSEX icex
;
655 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
656 icex
.dwICC
= ICC_TREEVIEW_CLASSES
;
657 InitCommonControlsEx(&icex
);
658 init_msg_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
660 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
663 wc
.hInstance
= GetModuleHandleA(NULL
);
665 wc
.hCursor
= LoadCursorA(NULL
, MAKEINTRESOURCEA(IDC_IBEAM
));
666 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
667 wc
.lpszMenuName
= NULL
;
668 wc
.lpszClassName
= "MyTestWnd";
669 wc
.lpfnWndProc
= MyWndProc
;
673 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
674 CW_USEDEFAULT
, CW_USEDEFAULT
, 130, 105, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
676 if ( !ok(hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n") )
679 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
681 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, FillRootSeq
, "FillRoot", FALSE
);
683 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
685 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoTest1Seq
, "DoTest1", FALSE
);
687 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
689 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoTest2Seq
, "DoTest2", FALSE
);
691 flush_sequences(MsgSequences
, NUM_MSG_SEQUENCES
);
693 ok_sequence(MsgSequences
, LISTVIEW_SEQ_INDEX
, DoFocusTestSeq
, "DoFocusTest", TRUE
);
695 /* Sequences tested inside due to number */
698 PostMessageA(hMainWnd
, WM_CLOSE
, 0, 0);
699 while(GetMessageA(&msg
,0,0,0)) {
700 TranslateMessage(&msg
);
701 DispatchMessageA(&msg
);