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_COMMAND, sent|wparam|defwinproc, 0x01000000},
94 { WM_ERASEBKGND, sent|defwinproc },
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 },
108 static const struct message TestGetSetImageListSeq[] = {
109 { TVM_SETIMAGELIST, sent|wparam|lparam, 0x00000000, 0x00000000 },
110 { TVM_GETIMAGELIST, sent|wparam|lparam, 0x00000000, 0x00000000 },
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 },
123 static const struct message TestGetSetInsertMarkColorSeq[] = {
124 { TVM_SETINSERTMARKCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
125 { TVM_GETINSERTMARKCOLOR, sent|wparam|lparam, 0x00000000, 0x00000000 },
129 static const struct message TestGetSetItemSeq[] = {
130 { TVM_GETITEM, sent },
131 { TVM_SETITEM, sent },
132 { TVM_GETITEM, sent },
133 { TVM_SETITEM, sent },
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 },
152 static const struct message TestGetSetScrollTimeSeq[] = {
153 { TVM_SETSCROLLTIME, sent|wparam|lparam, 0x00000014, 0x00000000 },
154 { TVM_GETSCROLLTIME, sent|wparam|lparam, 0x00000000, 0x00000000 },
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 },
168 static const struct message TestGetSetToolTipsSeq[] = {
169 { TVM_SETTOOLTIPS, sent|wparam|lparam, 0x00000000, 0x00000000 },
170 { TVM_GETTOOLTIPS, sent|wparam|lparam, 0x00000000, 0x00000000 },
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 },
183 static HWND hMainWnd;
185 static HWND hTree, hEdit;
186 static HTREEITEM hRoot, hChild;
189 static char sequence[256];
191 static void Clear(void)
197 static void AddItem(char ch)
199 sequence[pos++] = ch;
200 sequence[pos] = '\0';
203 static void IdentifyItem(HTREEITEM hItem)
205 if (hItem == hRoot) {
209 if (hItem == hChild) {
220 static void FillRoot(void)
224 static CHAR root[] = "Root",
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);
236 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
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);
245 ins.hInsertAfter = TVI_FIRST;
246 U(ins).item.mask = TVIF_TEXT;
247 U(ins).item.pszText = child;
248 hChild = TreeView_InsertItem(hTree, &ins);
252 ok(!strcmp(sequence, "AB."), "Item creation\n");
255 static void DoTest1(void)
258 r = TreeView_SelectItem(hTree, NULL);
261 r = TreeView_SelectItem(hTree, hRoot);
263 r = TreeView_SelectItem(hTree, hRoot);
265 r = TreeView_SelectItem(hTree, NULL);
267 r = TreeView_SelectItem(hTree, NULL);
269 r = TreeView_SelectItem(hTree, hRoot);
271 ok(!strcmp(sequence, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
274 static void DoTest2(void)
277 r = TreeView_SelectItem(hTree, NULL);
280 r = TreeView_SelectItem(hTree, hRoot);
282 r = TreeView_SelectItem(hTree, hRoot);
284 r = TreeView_SelectItem(hTree, hChild);
286 r = TreeView_SelectItem(hTree, hChild);
288 r = TreeView_SelectItem(hTree, hRoot);
290 ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
293 static void DoFocusTest(void)
296 static CHAR child1[] = "Edit",
297 child2[] = "A really long string";
298 HTREEITEM hChild1, hChild2;
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
306 ins.hInsertAfter = hChild;
307 U(ins).item.mask = TVIF_TEXT;
308 U(ins).item.pszText = child1;
309 hChild1 = TreeView_InsertItem(hTree, &ins);
311 ins.hInsertAfter = hChild1;
312 U(ins).item.mask = TVIF_TEXT;
313 U(ins).item.pszText = child2;
314 hChild2 = TreeView_InsertItem(hTree, &ins);
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");
325 static void TestGetSetBkColor(void)
327 COLORREF crColor = RGB(0,0,0);
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);
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);
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);
345 /* Reset the default background */
346 SendMessage( hTree, TVM_SETBKCOLOR, 0, -1 );
349 static void TestGetSetImageList(void)
351 HIMAGELIST hImageList = NULL;
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);
358 /* TODO: Test an actual image list */
361 static void TestGetSetIndent(void)
364 int ulMinIndent = -1;
365 int ulMoreThanTwiceMin = -1;
367 /* Finding the minimum indent */
368 SendMessage( hTree, TVM_SETINDENT, 0, 0 );
369 ulMinIndent = (int)SendMessage( hTree, TVM_GETINDENT, 0, 0 );
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);
378 static void TestGetSetInsertMarkColor(void)
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);
386 static void TestGetSetItem(void)
388 TVITEM tviRoot = {0};
389 int nBufferSize = 80;
390 char szBuffer[80] = {0};
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);
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);
407 /* Reset the root text */
408 memset(szBuffer, 0, nBufferSize);
409 strncpy(szBuffer, "Root", nBufferSize);
410 SendMessage( hTree, TVM_SETITEM, 0, (LPARAM)&tviRoot );
413 static void TestGetSetItemHeight(void)
418 /* Assuming default height to begin with */
419 ulOldHeight = (int) SendMessage( hTree, TVM_GETITEMHEIGHT, 0, 0 );
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);
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);
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);
437 static void TestGetSetScrollTime(void)
439 int ulExpectedTime = 20;
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);
446 static void TestGetSetTextColor(void)
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);
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);
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);
463 /* Reset the default text color */
464 SendMessage( hTree, TVM_SETTEXTCOLOR, 0, -1 );
467 static void TestGetSetToolTips(void)
469 HWND hwndLastToolTip = NULL;
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);
476 /* TODO: Add a test of an actual tooltip */
479 static void TestGetSetUnicodeFormat(void)
481 BOOL bPreviousSetting = 0;
482 BOOL bNewSetting = 0;
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");
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");
494 /* Revert to original setting */
495 SendMessage( hTree, TVM_SETUNICODEFORMAT, (LPARAM)bPreviousSetting, 0 );
498 static void TestGetSet(void)
500 /* TVM_GETBKCOLOR and TVM_SETBKCOLOR */
501 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
503 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetBkColorSeq,
504 "TestGetSetBkColor", FALSE);
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);
512 /* TVM_SETINDENT and TVM_GETINDENT */
513 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
515 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetIndentSeq,
516 "TestGetSetIndent", FALSE);
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);
524 /* TVM_GETITEM and TVM_SETITEM */
525 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
527 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, TestGetSetItemSeq,
528 "TestGetSetItem", FALSE);
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);
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);
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);
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);
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);
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)
564 static long defwndproc_counter = 0;
567 WNDPROC *lpOldProc = (WNDPROC*)GetWindowLongA(hwnd, GWL_USERDATA);
569 msg.message = message;
570 msg.flags = sent|wparam|lparam;
571 if (defwndproc_counter) msg.flags |= defwinproc;
574 add_message(MsgSequences, LISTVIEW_SEQ_INDEX, &msg);
576 defwndproc_counter++;
577 ret = CallWindowProcA(*lpOldProc, hwnd, message, wParam, lParam);
578 defwndproc_counter--;
583 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
585 WNDPROC *pOldWndProc;
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);
597 pOldWndProc = HeapAlloc(GetProcessHeap(), 0, sizeof(WNDPROC));
598 if ( !ok(pOldWndProc != NULL, "Failed to allocate memory for subclass_info.\n") )
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);
612 NMHDR *pHdr = (NMHDR *)lParam;
614 if (pHdr->idFrom == 100) {
615 NMTREEVIEWA *pTreeView = (LPNMTREEVIEWA) lParam;
617 case TVN_SELCHANGINGA:
619 IdentifyItem(pTreeView->itemOld.hItem);
620 IdentifyItem(pTreeView->itemNew.hItem);
622 case TVN_SELCHANGEDA:
624 IdentifyItem(pTreeView->itemOld.hItem);
625 IdentifyItem(pTreeView->itemNew.hItem);
633 MoveWindow(hTree, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
641 return DefWindowProcA(hWnd, msg, wParam, lParam);
650 INITCOMMONCONTROLSEX icex;
652 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
653 icex.dwICC = ICC_TREEVIEW_CLASSES;
654 InitCommonControlsEx(&icex);
655 init_msg_sequences(MsgSequences, NUM_MSG_SEQUENCES);
657 wc.style = CS_HREDRAW | CS_VREDRAW;
660 wc.hInstance = GetModuleHandleA(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;
670 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
671 CW_USEDEFAULT, CW_USEDEFAULT, 130, 105, NULL, NULL, GetModuleHandleA(NULL), 0);
673 if ( !ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n") )
676 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
678 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, FillRootSeq, "FillRoot", FALSE);
680 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
682 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoTest1Seq, "DoTest1", FALSE);
684 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
686 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoTest2Seq, "DoTest2", FALSE);
688 flush_sequences(MsgSequences, NUM_MSG_SEQUENCES);
690 ok_sequence(MsgSequences, LISTVIEW_SEQ_INDEX, DoFocusTestSeq, "DoFocusTest", TRUE);
692 /* Sequences tested inside due to number */
695 PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
696 while(GetMessageA(&msg,0,0,0)) {
697 TranslateMessage(&msg);
698 DispatchMessageA(&msg);