comctl32: datetime: Reject out of range dates in DTM_SETSYSTEMTIME.
[wine] / dlls / comctl32 / tests / treeview.c
1 /* Unit tests for treeview.
2  *
3  * Copyright 2005 Krzysztof Foltman
4  * Copyright 2007 Christopher James Peterson
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <assert.h>
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winnls.h"
29 #include "winreg.h"
30 #include "commctrl.h" 
31
32 #include "wine/test.h"
33 #include "msg.h"
34
35 #define NUM_MSG_SEQUENCES   1
36 #define LISTVIEW_SEQ_INDEX  0
37
38 static struct msg_sequence *MsgSequences[NUM_MSG_SEQUENCES];
39
40 static const struct message FillRootSeq[] = {
41     { TVM_INSERTITEM, sent },
42     { TVM_GETITEM, sent },
43     { TVM_INSERTITEM, sent },
44     { 0 }
45 };
46
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 },
54     { 0 }
55 };
56
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 },
64     { 0 }
65 };
66
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_COMMAND, sent|wparam|defwinproc, 0x01000000},
94     { WM_ERASEBKGND, sent|defwinproc },
95     { 0 }
96 };
97
98 static const struct message TestGetSetBkColorSeq[] = {
99     { TVM_GETBKCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
100     { TVM_SETBKCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
101     { TVM_GETBKCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
102     { TVM_SETBKCOLOR, sent|wparam|lparam, 0x00000000, 0x00ffffff },
103     { TVM_GETBKCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
104     { TVM_SETBKCOLOR, sent|wparam|lparam, 0x00000000, 0xffffffff },
105     { 0 }
106 };
107
108 static const struct message TestGetSetImageListSeq[] = {
109     { TVM_SETIMAGELIST, sent|wparam|lparam, 0x00000000, 0x00000000 },
110     { TVM_GETIMAGELIST, sent|wparam|lparam, 0x00000000, 0x00000000 },
111     { 0 }
112 };
113
114 static const struct message TestGetSetIndentSeq[] = {
115     { TVM_SETINDENT, sent|wparam|lparam, 0x00000000, 0x00000000 },
116     { TVM_GETINDENT, sent|wparam|lparam, 0x00000000, 0x00000000 },
117     /* The actual amount to indent is dependent on the system for this message */
118     { TVM_SETINDENT, sent },
119     { TVM_GETINDENT, sent|wparam|lparam, 0x00000000, 0x00000000 },
120     { 0 }
121 };
122
123 static const struct message TestGetSetInsertMarkColorSeq[] = {
124     { TVM_SETINSERTMARKCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
125     { TVM_GETINSERTMARKCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
126     { 0 }
127 };
128
129 static const struct message TestGetSetItemSeq[] = {
130     { TVM_GETITEM, sent },
131     { TVM_SETITEM, sent },
132     { TVM_GETITEM, sent },
133     { TVM_SETITEM, sent },
134     { 0 }
135 };
136
137 static const struct message TestGetSetItemHeightSeq[] = {
138     { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0x00000000, 0x00000000 },
139     { TVM_SETITEMHEIGHT, sent|wparam|lparam, 0xffffffff, 0x00000000 },
140     { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0x00000000, 0x00000000 },
141     { TVM_SETITEMHEIGHT, sent|wparam|lparam, 0x00000020, 0x00000000 },
142     { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0x00000000, 0x00000000 },
143     { TVM_SETITEMHEIGHT, sent|wparam|lparam, 0x00000009, 0x00000000 },
144     { WM_WINDOWPOSCHANGING, sent|defwinproc },
145     { WM_NCCALCSIZE, sent|wparam|defwinproc, 0x00000001 },
146     { WM_WINDOWPOSCHANGED, sent|defwinproc },
147     { WM_SIZE, sent|defwinproc },
148     { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0x00000000, 0x00000000 },
149     { 0 }
150 };
151
152 static const struct message TestGetSetScrollTimeSeq[] = {
153     { TVM_SETSCROLLTIME, sent|wparam|lparam, 0x00000014, 0x00000000 },
154     { TVM_GETSCROLLTIME, sent|wparam|lparam, 0x00000000, 0x00000000 },
155     { 0 }
156 };
157
158 static const struct message TestGetSetTextColorSeq[] = {
159     { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
160     { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
161     { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
162     { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0x00000000, 0x00ffffff },
163     { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
164     { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0x00000000, 0xffffffff },
165     { 0 }
166 };
167
168 static const struct message TestGetSetToolTipsSeq[] = {
169     { TVM_SETTOOLTIPS, sent|wparam|lparam, 0x00000000, 0x00000000 },
170     { TVM_GETTOOLTIPS, sent|wparam|lparam, 0x00000000, 0x00000000 },
171     { 0 }
172 };
173
174 static const struct message TestGetSetUnicodeFormatSeq[] = {
175     { TVM_SETUNICODEFORMAT, sent|wparam|lparam, 0x00000001, 0x00000000 },
176     { TVM_GETUNICODEFORMAT, sent|wparam|lparam, 0x00000000, 0x00000000 },
177     { TVM_SETUNICODEFORMAT, sent|wparam|lparam, 0x00000000, 0x00000000 },
178     { TVM_GETUNICODEFORMAT, sent|wparam|lparam, 0x00000000, 0x00000000 },
179     { TVM_SETUNICODEFORMAT, sent|wparam|lparam, 0x00000000, 0x00000000 },
180     { 0 }
181 };
182
183 static HWND hMainWnd;
184
185 static HWND hTree, hEdit;
186 static HTREEITEM hRoot, hChild;
187
188 static int pos = 0;
189 static char sequence[256];
190
191 static void Clear(void)
192 {
193     pos = 0;
194     sequence[0] = '\0';
195 }
196
197 static void AddItem(char ch)
198 {
199     sequence[pos++] = ch;
200     sequence[pos] = '\0';
201 }
202
203 static void IdentifyItem(HTREEITEM hItem)
204 {
205     if (hItem == hRoot) {
206         AddItem('R');
207         return;
208     }
209     if (hItem == hChild) {
210         AddItem('C');
211         return;
212     }
213     if (hItem == NULL) {
214         AddItem('n');
215         return;
216     }
217     AddItem('?');
218 }
219
220 static void FillRoot(void)
221 {
222     TVINSERTSTRUCTA ins;
223     TVITEM tvi;
224     static CHAR root[]  = "Root",
225                 child[] = "Child";
226
227     Clear();
228     AddItem('A');
229     ins.hParent = TVI_ROOT;
230     ins.hInsertAfter = TVI_ROOT;
231     U(ins).item.mask = TVIF_TEXT;
232     U(ins).item.pszText = root;
233     hRoot = TreeView_InsertItem(hTree, &ins);
234     assert(hRoot);
235
236     /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
237     tvi.hItem = hRoot;
238     tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
239     SendMessage( hTree, TVM_GETITEM, 0, (LPARAM)&tvi );
240     ok(tvi.iImage == 0, "tvi.iImage=%d\n", tvi.iImage);
241     ok(tvi.iSelectedImage == 0, "tvi.iSelectedImage=%d\n", tvi.iSelectedImage);
242
243     AddItem('B');
244     ins.hParent = hRoot;
245     ins.hInsertAfter = TVI_FIRST;
246     U(ins).item.mask = TVIF_TEXT;
247     U(ins).item.pszText = child;
248     hChild = TreeView_InsertItem(hTree, &ins);
249     assert(hChild);
250     AddItem('.');
251
252     ok(!strcmp(sequence, "AB."), "Item creation\n");
253 }
254
255 static void DoTest1(void)
256 {
257     BOOL r;
258     r = TreeView_SelectItem(hTree, NULL);
259     Clear();
260     AddItem('1');
261     r = TreeView_SelectItem(hTree, hRoot);
262     AddItem('2');
263     r = TreeView_SelectItem(hTree, hRoot);
264     AddItem('3');
265     r = TreeView_SelectItem(hTree, NULL);
266     AddItem('4');
267     r = TreeView_SelectItem(hTree, NULL);
268     AddItem('5');
269     r = TreeView_SelectItem(hTree, hRoot);
270     AddItem('.');
271     ok(!strcmp(sequence, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
272 }
273
274 static void DoTest2(void)
275 {
276     BOOL r;
277     r = TreeView_SelectItem(hTree, NULL);
278     Clear();
279     AddItem('1');
280     r = TreeView_SelectItem(hTree, hRoot);
281     AddItem('2');
282     r = TreeView_SelectItem(hTree, hRoot);
283     AddItem('3');
284     r = TreeView_SelectItem(hTree, hChild);
285     AddItem('4');
286     r = TreeView_SelectItem(hTree, hChild);
287     AddItem('5');
288     r = TreeView_SelectItem(hTree, hRoot);
289     AddItem('.');
290     ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
291 }
292
293 static void DoFocusTest(void)
294 {
295     TVINSERTSTRUCTA ins;
296     static CHAR child1[]  = "Edit",
297                 child2[]  = "A really long string";
298     HTREEITEM hChild1, hChild2;
299
300     /* This test verifies that when a label is being edited, scrolling
301      * the treeview does not cause the label to lose focus. To test
302      * this, first some additional entries are added to generate
303      * scrollbars.
304      */
305     ins.hParent = hRoot;
306     ins.hInsertAfter = hChild;
307     U(ins).item.mask = TVIF_TEXT;
308     U(ins).item.pszText = child1;
309     hChild1 = TreeView_InsertItem(hTree, &ins);
310     assert(hChild1);
311     ins.hInsertAfter = hChild1;
312     U(ins).item.mask = TVIF_TEXT;
313     U(ins).item.pszText = child2;
314     hChild2 = TreeView_InsertItem(hTree, &ins);
315     assert(hChild2);
316
317     ShowWindow(hMainWnd,SW_SHOW);
318     /* Using SendMessageA since Win98 doesn't have default unicode support */
319     SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
320     hEdit = TreeView_EditLabel(hTree, hChild);
321     ScrollWindowEx(hTree, -10, 0, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN);
322     ok(GetFocus() == hEdit, "Edit control should have focus\n");
323 }
324
325 static void TestGetSetBkColor(void)
326 {
327     COLORREF crColor = RGB(0,0,0);
328
329     todo_wine{
330         /* If the value is -1, the control is using the system color for the background color. */
331         crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
332         ok(crColor == -1, "Default background color reported as 0x%.8x\n", crColor);
333     }
334
335     /* Test for black background */
336     SendMessage( hTree, TVM_SETBKCOLOR, 0, (LPARAM)RGB(0,0,0) );
337     crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
338     ok(crColor == RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor);
339
340     /* Test for white background */
341     SendMessage( hTree, TVM_SETBKCOLOR, 0, (LPARAM)RGB(255,255,255) );
342     crColor = (COLORREF)SendMessage( hTree, TVM_GETBKCOLOR, 0, 0 );
343     ok(crColor == RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor);
344
345     /* Reset the default background */
346     SendMessage( hTree, TVM_SETBKCOLOR, 0, -1 );
347 }
348
349 static void TestGetSetImageList(void)
350 {
351     HIMAGELIST hImageList = NULL;
352
353     /* Test a NULL HIMAGELIST */
354     SendMessage( hTree, TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)hImageList );
355     hImageList = (HIMAGELIST)SendMessage( hTree, TVM_GETIMAGELIST, TVSIL_NORMAL, 0 );
356     ok(hImageList == NULL, "NULL image list, reported as 0x%p, expected 0.\n", hImageList);
357
358     /* TODO: Test an actual image list */
359 }
360
361 static void TestGetSetIndent(void)
362 {
363     int ulIndent = -1;
364     int ulMinIndent = -1;
365     int ulMoreThanTwiceMin = -1;
366
367     /* Finding the minimum indent */
368     SendMessage( hTree, TVM_SETINDENT, 0, 0 );
369     ulMinIndent = (int)SendMessage( hTree, TVM_GETINDENT, 0, 0 );
370
371     /* Checking an indent that is more than twice the default indent */
372     ulMoreThanTwiceMin = 2*ulMinIndent+1;
373     SendMessage( hTree, TVM_SETINDENT, ulMoreThanTwiceMin, 0 );
374     ulIndent = (DWORD)SendMessage( hTree, TVM_GETINDENT, 0, 0 );
375     ok(ulIndent == ulMoreThanTwiceMin, "Indent reported as %d, expected %d\n", ulIndent, ulMoreThanTwiceMin);
376 }
377
378 static void TestGetSetInsertMarkColor(void)
379 {
380     COLORREF crColor = RGB(0,0,0);
381     SendMessage( hTree, TVM_SETINSERTMARKCOLOR, 0, crColor );
382     crColor = (COLORREF)SendMessage( hTree, TVM_GETINSERTMARKCOLOR, 0, 0 );
383     ok(crColor == RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor);
384 }
385
386 static void TestGetSetItem(void)
387 {
388     TVITEM tviRoot = {0};
389     int nBufferSize = 80;
390     char szBuffer[80] = {0};
391
392     /* Test the root item */
393     tviRoot.hItem = hRoot;
394     tviRoot.mask = TVIF_TEXT;
395     tviRoot.cchTextMax = nBufferSize;
396     tviRoot.pszText = szBuffer;
397     SendMessage( hTree, TVM_GETITEM, 0, (LPARAM)&tviRoot );
398     ok(!strcmp("Root", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer);
399
400     /* Change the root text */
401     strncpy(szBuffer, "Testing123", nBufferSize);
402     SendMessage( hTree, TVM_SETITEM, 0, (LPARAM)&tviRoot );
403     memset(szBuffer, 0, nBufferSize);
404     SendMessage( hTree, TVM_GETITEM, 0, (LPARAM)&tviRoot );
405     ok(!strcmp("Testing123", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer);
406
407     /* Reset the root text */
408     memset(szBuffer, 0, nBufferSize);
409     strncpy(szBuffer, "Root", nBufferSize);
410     SendMessage( hTree, TVM_SETITEM, 0, (LPARAM)&tviRoot );
411 }
412
413 static void TestGetSetItemHeight(void)
414 {
415     int ulOldHeight = 0;
416     int ulNewHeight = 0;
417
418     /* Assuming default height to begin with */
419     ulOldHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
420
421     /* Explicitly setting and getting the default height */
422     SendMessage( hTree, TVM_SETITEMHEIGHT, -1, 0 );
423     ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
424     ok(ulNewHeight == ulOldHeight, "Default height not set properly, reported %d, expected %d\n", ulNewHeight, ulOldHeight);
425
426     /* Explicitly setting and getting the height of twice the normal */
427     SendMessage( hTree, TVM_SETITEMHEIGHT, 2*ulOldHeight, 0 );
428     ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
429     ok(ulNewHeight == 2*ulOldHeight, "New height not set properly, reported %d, expected %d\n", ulNewHeight, 2*ulOldHeight);
430
431     /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
432     SendMessage( hTree, TVM_SETITEMHEIGHT, 9, 0 );
433     ulNewHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
434     ok(ulNewHeight == 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight, 8);
435 }
436
437 static void TestGetSetScrollTime(void)
438 {
439     int ulExpectedTime = 20;
440     int ulTime = 0;
441     SendMessage( hTree, TVM_SETSCROLLTIME, ulExpectedTime, 0 );
442     ulTime = (int)SendMessage( hTree, TVM_GETSCROLLTIME, 0, 0 );
443     ok(ulTime == ulExpectedTime, "Scroll time reported as %d, expected %d\n", ulTime, ulExpectedTime);
444 }
445
446 static void TestGetSetTextColor(void)
447 {
448     /* If the value is -1, the control is using the system color for the text color. */
449     COLORREF crColor = RGB(0,0,0);
450     crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
451     ok(crColor == -1, "Default text color reported as 0x%.8x\n", crColor);
452
453     /* Test for black text */
454     SendMessage( hTree, TVM_SETTEXTCOLOR, 0, (LPARAM)RGB(0,0,0) );
455     crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
456     ok(crColor == RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor);
457
458     /* Test for white text */
459     SendMessage( hTree, TVM_SETTEXTCOLOR, 0, (LPARAM)RGB(255,255,255) );
460     crColor = (COLORREF)SendMessage( hTree, TVM_GETTEXTCOLOR, 0, 0 );
461     ok(crColor == RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor);
462
463     /* Reset the default text color */
464     SendMessage( hTree, TVM_SETTEXTCOLOR, 0, -1 );
465 }
466
467 static void TestGetSetToolTips(void)
468 {
469     HWND hwndLastToolTip = NULL;
470
471     /* Testing setting a NULL ToolTip */
472     SendMessage( hTree, TVM_SETTOOLTIPS, 0, 0 );
473     hwndLastToolTip = (HWND)SendMessage( hTree, TVM_GETTOOLTIPS, 0, 0 );
474     ok(hwndLastToolTip == NULL, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip);
475
476     /* TODO: Add a test of an actual tooltip */
477 }
478
479 static void TestGetSetUnicodeFormat(void)
480 {
481     BOOL bPreviousSetting = 0;
482     BOOL bNewSetting = 0;
483
484     /* Set to Unicode */
485     bPreviousSetting = (BOOL)SendMessage( hTree, TVM_SETUNICODEFORMAT, 1, 0 );
486     bNewSetting = (BOOL)SendMessage( hTree, TVM_GETUNICODEFORMAT, 0, 0 );
487     ok(bNewSetting == 1, "Unicode setting did not work.\n");
488
489     /* Set to ANSI */
490     SendMessage( hTree, TVM_SETUNICODEFORMAT, 0, 0 );
491     bNewSetting = (BOOL)SendMessage( hTree, TVM_GETUNICODEFORMAT, 0, 0 );
492     ok(bNewSetting == 0, "ANSI setting did not work.\n");
493
494     /* Revert to original setting */
495     SendMessage( hTree, TVM_SETUNICODEFORMAT, (LPARAM)bPreviousSetting, 0 );
496 }
497
498 static void TestGetSet(void)
499 {
500     /* TVM_GETBKCOLOR and TVM_SETBKCOLOR */
501     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
502     TestGetSetBkColor();
503     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetBkColorSeq,
504         "TestGetSetBkColor", FALSE);
505
506     /* TVM_GETIMAGELIST and TVM_SETIMAGELIST */
507     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
508     TestGetSetImageList();
509     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetImageListSeq,
510         "TestGetImageList", FALSE);
511
512     /* TVM_SETINDENT and TVM_GETINDENT */
513     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
514     TestGetSetIndent();
515     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetIndentSeq,
516         "TestGetSetIndent", FALSE);
517
518     /* TVM_GETINSERTMARKCOLOR and TVM_GETINSERTMARKCOLOR */
519     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
520     TestGetSetInsertMarkColor();
521     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetInsertMarkColorSeq,
522         "TestGetSetInsertMarkColor", FALSE);
523
524     /* TVM_GETITEM and TVM_SETITEM */
525     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
526     TestGetSetItem();
527     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetItemSeq,
528         "TestGetSetItem", FALSE);
529
530     /* TVM_GETITEMHEIGHT and TVM_SETITEMHEIGHT */
531     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
532     TestGetSetItemHeight();
533     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetItemHeightSeq,
534         "TestGetSetItemHeight", FALSE);
535
536     /* TVM_GETSCROLLTIME and TVM_SETSCROLLTIME */
537     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
538     TestGetSetScrollTime();
539     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetScrollTimeSeq,
540         "TestGetSetScrollTime", FALSE);
541
542     /* TVM_GETTEXTCOLOR and TVM_SETTEXTCOLOR */
543     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
544     TestGetSetTextColor();
545     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetTextColorSeq,
546         "TestGetSetTextColor", FALSE);
547
548     /* TVM_GETTOOLTIPS and TVM_SETTOOLTIPS */
549     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
550     TestGetSetToolTips();
551     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetToolTipsSeq,
552         "TestGetSetToolTips", FALSE);
553
554     /* TVM_GETUNICODEFORMAT and TVM_SETUNICODEFORMAT */
555     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
556     TestGetSetUnicodeFormat();
557     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetUnicodeFormatSeq,
558         "TestGetSetUnicodeFormat", FALSE);
559 }
560
561 /* This function hooks in and records all messages to the treeview control */
562 static LRESULT WINAPI TreeviewWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
563 {
564     static long defwndproc_counter = 0;
565     LRESULT ret;
566     struct message msg;
567     WNDPROC *lpOldProc = (WNDPROC*)GetWindowLongA(hwnd, GWL_USERDATA);
568
569     msg.message = message;
570     msg.flags = sent|wparam|lparam;
571     if (defwndproc_counter) msg.flags |= defwinproc;
572     msg.wParam = wParam;
573     msg.lParam = lParam;
574     add_message(MsgSequences, LISTVIEW_SEQ_INDEX, &msg);
575
576     defwndproc_counter++;
577     ret = CallWindowProcA(*lpOldProc, hwnd, message, wParam, lParam);
578     defwndproc_counter--;
579
580     return ret;
581 }
582
583 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
584 {
585     WNDPROC *pOldWndProc;
586
587     switch(msg) {
588
589     case WM_CREATE:
590     {
591         hTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL, WS_CHILD|WS_VISIBLE|
592             TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS|TVS_EDITLABELS,
593             0, 0, 120, 100, hWnd, (HMENU)100, GetModuleHandleA(0), 0);
594
595         SetFocus(hTree);
596
597         pOldWndProc = HeapAlloc(GetProcessHeap(), 0, sizeof(WNDPROC));
598         if ( !ok(pOldWndProc != NULL, "Failed to allocate memory for subclass_info.\n") )
599         {
600             PostQuitMessage(1);
601             break;
602         }
603
604         /* Record the old WNDPROC so we can call it after recording the messages */
605         *pOldWndProc = (WNDPROC)SetWindowLongA(hTree, GWL_WNDPROC, (LONG)TreeviewWndProc);
606         SetWindowLongA(hTree, GWL_USERDATA, (LONG)pOldWndProc);
607
608         return 0;
609     }
610     case WM_NOTIFY:
611     {
612         NMHDR *pHdr = (NMHDR *)lParam;
613     
614         if (pHdr->idFrom == 100) {
615             NMTREEVIEWA *pTreeView = (LPNMTREEVIEWA) lParam;
616             switch(pHdr->code) {
617             case TVN_SELCHANGINGA:
618                 AddItem('(');
619                 IdentifyItem(pTreeView->itemOld.hItem);
620                 IdentifyItem(pTreeView->itemNew.hItem);
621                 return 0;
622             case TVN_SELCHANGEDA:
623                 AddItem(')');
624                 IdentifyItem(pTreeView->itemOld.hItem);
625                 IdentifyItem(pTreeView->itemNew.hItem);
626                 return 0;
627             }
628         }
629         return 0;
630     }
631   
632     case WM_SIZE:
633         MoveWindow(hTree, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
634         break;
635       
636     case WM_DESTROY:
637         PostQuitMessage(0);
638         break;
639   
640     default:
641         return DefWindowProcA(hWnd, msg, wParam, lParam);
642     }
643     return 0L;
644 }
645
646 START_TEST(treeview)
647 {
648     WNDCLASSA wc;
649     MSG msg;
650     INITCOMMONCONTROLSEX icex;
651   
652     icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
653     icex.dwICC   = ICC_TREEVIEW_CLASSES;
654     InitCommonControlsEx(&icex);
655     init_msg_sequences(MsgSequences, NUM_MSG_SEQUENCES);
656   
657     wc.style = CS_HREDRAW | CS_VREDRAW;
658     wc.cbClsExtra = 0;
659     wc.cbWndExtra = 0;
660     wc.hInstance = GetModuleHandleA(NULL);
661     wc.hIcon = NULL;
662     wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_IBEAM));
663     wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
664     wc.lpszMenuName = NULL;
665     wc.lpszClassName = "MyTestWnd";
666     wc.lpfnWndProc = MyWndProc;
667     RegisterClassA(&wc);
668
669
670     hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
671       CW_USEDEFAULT, CW_USEDEFAULT, 130, 105, NULL, NULL, GetModuleHandleA(NULL), 0);
672
673     if ( !ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n") )
674         return;
675
676     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
677     FillRoot();
678     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, FillRootSeq, "FillRoot", FALSE);
679
680     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
681     DoTest1();
682     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoTest1Seq, "DoTest1", FALSE);
683
684     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
685     DoTest2();
686     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoTest2Seq, "DoTest2", FALSE);
687
688     flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
689     DoFocusTest();
690     ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoFocusTestSeq, "DoFocusTest", TRUE);
691
692     /* Sequences tested inside due to number */
693     TestGetSet();
694
695     PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
696     while(GetMessageA(&msg,0,0,0)) {
697         TranslateMessage(&msg);
698         DispatchMessageA(&msg);
699     }
700 }