comctl32: treeview: Make the focus test pass under Windows XP.
[wine/winequartzdrv.git] / dlls / comctl32 / tests / treeview.c
blob6f94fa7876120861a93510a397ed5167884697eb
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
21 #include <assert.h>
22 #include <stdarg.h>
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"
32 #include "wine/test.h"
33 #include "msg.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 },
44 { 0 }
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 }
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 }
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 },
98 { 0 }
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 },
108 { 0 }
111 static const struct message TestGetSetImageListSeq[] = {
112 { TVM_SETIMAGELIST, sent|wparam|lparam, 0x00000000, 0x00000000 },
113 { TVM_GETIMAGELIST, sent|wparam|lparam, 0x00000000, 0x00000000 },
114 { 0 }
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 },
123 { 0 }
126 static const struct message TestGetSetInsertMarkColorSeq[] = {
127 { TVM_SETINSERTMARKCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
128 { TVM_GETINSERTMARKCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
129 { 0 }
132 static const struct message TestGetSetItemSeq[] = {
133 { TVM_GETITEM, sent },
134 { TVM_SETITEM, sent },
135 { TVM_GETITEM, sent },
136 { TVM_SETITEM, sent },
137 { 0 }
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 },
152 { 0 }
155 static const struct message TestGetSetScrollTimeSeq[] = {
156 { TVM_SETSCROLLTIME, sent|wparam|lparam, 0x00000014, 0x00000000 },
157 { TVM_GETSCROLLTIME, sent|wparam|lparam, 0x00000000, 0x00000000 },
158 { 0 }
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 },
168 { 0 }
171 static const struct message TestGetSetToolTipsSeq[] = {
172 { TVM_SETTOOLTIPS, sent|wparam|lparam, 0x00000000, 0x00000000 },
173 { TVM_GETTOOLTIPS, sent|wparam|lparam, 0x00000000, 0x00000000 },
174 { 0 }
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 },
183 { 0 }
186 static HWND hMainWnd;
188 static HWND hTree, hEdit;
189 static HTREEITEM hRoot, hChild;
191 static int pos = 0;
192 static char sequence[256];
194 static void Clear(void)
196 pos = 0;
197 sequence[0] = '\0';
200 static void AddItem(char ch)
202 sequence[pos++] = ch;
203 sequence[pos] = '\0';
206 static void IdentifyItem(HTREEITEM hItem)
208 if (hItem == hRoot) {
209 AddItem('R');
210 return;
212 if (hItem == hChild) {
213 AddItem('C');
214 return;
216 if (hItem == NULL) {
217 AddItem('n');
218 return;
220 AddItem('?');
223 static void FillRoot(void)
225 TVINSERTSTRUCTA ins;
226 TVITEM tvi;
227 static CHAR root[] = "Root",
228 child[] = "Child";
230 Clear();
231 AddItem('A');
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);
237 assert(hRoot);
239 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
240 tvi.hItem = hRoot;
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);
246 AddItem('B');
247 ins.hParent = hRoot;
248 ins.hInsertAfter = TVI_FIRST;
249 U(ins).item.mask = TVIF_TEXT;
250 U(ins).item.pszText = child;
251 hChild = TreeView_InsertItem(hTree, &ins);
252 assert(hChild);
253 AddItem('.');
255 ok(!strcmp(sequence, "AB."), "Item creation\n");
258 static void DoTest1(void)
260 BOOL r;
261 r = TreeView_SelectItem(hTree, NULL);
262 Clear();
263 AddItem('1');
264 r = TreeView_SelectItem(hTree, hRoot);
265 AddItem('2');
266 r = TreeView_SelectItem(hTree, hRoot);
267 AddItem('3');
268 r = TreeView_SelectItem(hTree, NULL);
269 AddItem('4');
270 r = TreeView_SelectItem(hTree, NULL);
271 AddItem('5');
272 r = TreeView_SelectItem(hTree, hRoot);
273 AddItem('.');
274 ok(!strcmp(sequence, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
277 static void DoTest2(void)
279 BOOL r;
280 r = TreeView_SelectItem(hTree, NULL);
281 Clear();
282 AddItem('1');
283 r = TreeView_SelectItem(hTree, hRoot);
284 AddItem('2');
285 r = TreeView_SelectItem(hTree, hRoot);
286 AddItem('3');
287 r = TreeView_SelectItem(hTree, hChild);
288 AddItem('4');
289 r = TreeView_SelectItem(hTree, hChild);
290 AddItem('5');
291 r = TreeView_SelectItem(hTree, hRoot);
292 AddItem('.');
293 ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
296 static void DoFocusTest(void)
298 TVINSERTSTRUCTA ins;
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
306 * scrollbars.
308 ins.hParent = hRoot;
309 ins.hInsertAfter = hChild;
310 U(ins).item.mask = TVIF_TEXT;
311 U(ins).item.pszText = child1;
312 hChild1 = TreeView_InsertItem(hTree, &ins);
313 assert(hChild1);
314 ins.hInsertAfter = hChild1;
315 U(ins).item.mask = TVIF_TEXT;
316 U(ins).item.pszText = child2;
317 hChild2 = TreeView_InsertItem(hTree, &ins);
318 assert(hChild2);
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);
332 todo_wine{
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)
366 int ulIndent = -1;
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)
418 int ulOldHeight = 0;
419 int ulNewHeight = 0;
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;
443 int ulTime = 0;
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;
487 /* Set to Unicode */
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");
492 /* Set to ANSI */
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);
505 TestGetSetBkColor();
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);
517 TestGetSetIndent();
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);
529 TestGetSetItem();
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;
568 LRESULT ret;
569 struct message msg;
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;
575 msg.wParam = wParam;
576 msg.lParam = lParam;
577 add_message(MsgSequences, LISTVIEW_SEQ_INDEX, &msg);
579 defwndproc_counter++;
580 ret = CallWindowProcA(*lpOldProc, hwnd, message, wParam, lParam);
581 defwndproc_counter--;
583 return ret;
586 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
588 WNDPROC *pOldWndProc;
590 switch(msg) {
592 case WM_CREATE:
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);
598 SetFocus(hTree);
600 pOldWndProc = HeapAlloc(GetProcessHeap(), 0, sizeof(WNDPROC));
601 if ( !ok(pOldWndProc != NULL, "Failed to allocate memory for subclass_info.\n") )
603 PostQuitMessage(1);
604 break;
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);
611 return 0;
613 case WM_NOTIFY:
615 NMHDR *pHdr = (NMHDR *)lParam;
617 if (pHdr->idFrom == 100) {
618 NMTREEVIEWA *pTreeView = (LPNMTREEVIEWA) lParam;
619 switch(pHdr->code) {
620 case TVN_SELCHANGINGA:
621 AddItem('(');
622 IdentifyItem(pTreeView->itemOld.hItem);
623 IdentifyItem(pTreeView->itemNew.hItem);
624 return 0;
625 case TVN_SELCHANGEDA:
626 AddItem(')');
627 IdentifyItem(pTreeView->itemOld.hItem);
628 IdentifyItem(pTreeView->itemNew.hItem);
629 return 0;
632 return 0;
635 case WM_SIZE:
636 MoveWindow(hTree, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
637 break;
639 case WM_DESTROY:
640 PostQuitMessage(0);
641 break;
643 default:
644 return DefWindowProcA(hWnd, msg, wParam, lParam);
646 return 0L;
649 START_TEST(treeview)
651 WNDCLASSA wc;
652 MSG msg;
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;
661 wc.cbClsExtra = 0;
662 wc.cbWndExtra = 0;
663 wc.hInstance = GetModuleHandleA(NULL);
664 wc.hIcon = 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;
670 RegisterClassA(&wc);
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") )
677 return;
679 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
680 FillRoot();
681 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, FillRootSeq, "FillRoot", FALSE);
683 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
684 DoTest1();
685 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoTest1Seq, "DoTest1", FALSE);
687 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
688 DoTest2();
689 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoTest2Seq, "DoTest2", FALSE);
691 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
692 DoFocusTest();
693 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoFocusTestSeq, "DoFocusTest", TRUE);
695 /* Sequences tested inside due to number */
696 TestGetSet();
698 PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
699 while(GetMessageA(&msg,0,0,0)) {
700 TranslateMessage(&msg);
701 DispatchMessageA(&msg);