comctl32/tests: Fix treeview test failures on French Windows XP.
[wine.git] / dlls / comctl32 / tests / treeview.c
bloba014625a0ae58ef82e34ae8e4bdc2e01890259cc
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 <stdarg.h>
22 #include <stdio.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 "v6util.h"
34 #include "msg.h"
36 static const char *TEST_CALLBACK_TEXT = "callback_text";
38 static TVITEMA g_item_expanding, g_item_expanded;
39 static BOOL g_get_from_expand;
40 static BOOL g_get_rect_in_expand;
41 static BOOL g_disp_A_to_W;
42 static BOOL g_disp_set_stateimage;
43 static BOOL g_beginedit_alter_text;
44 static HFONT g_customdraw_font;
45 static BOOL g_v6;
47 #define NUM_MSG_SEQUENCES 3
48 #define TREEVIEW_SEQ_INDEX 0
49 #define PARENT_SEQ_INDEX 1
50 #define PARENT_CD_SEQ_INDEX 2
52 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
54 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
55 static struct msg_sequence *item_sequence[1];
57 static void flush_events(void)
59 MSG msg;
60 int diff = 200;
61 int min_timeout = 100;
62 DWORD time = GetTickCount() + diff;
64 while (diff > 0)
66 if (MsgWaitForMultipleObjects(0, NULL, FALSE, min_timeout, QS_ALLINPUT) == WAIT_TIMEOUT) break;
67 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
68 diff = time - GetTickCount();
72 static const struct message FillRootSeq[] = {
73 { TVM_INSERTITEMA, sent },
74 { TVM_INSERTITEMA, sent },
75 { 0 }
78 static const struct message rootnone_select_seq[] = {
79 { TVM_SELECTITEM, sent|wparam, 9 },
80 { TVM_SELECTITEM, sent|wparam, 9 },
81 { TVM_SELECTITEM, sent|wparam, 9 },
82 { TVM_SELECTITEM, sent|wparam, 9 },
83 { TVM_SELECTITEM, sent|wparam, 9 },
84 { TVM_SELECTITEM, sent|wparam, 9 },
85 { 0 }
88 static const struct message rootchild_select_seq[] = {
89 { TVM_SELECTITEM, sent|wparam, 9 },
90 { TVM_SELECTITEM, sent|wparam, 9 },
91 { TVM_SELECTITEM, sent|wparam, 9 },
92 { TVM_SELECTITEM, sent|wparam, 9 },
93 { TVM_SELECTITEM, sent|wparam, 9 },
94 { TVM_SELECTITEM, sent|wparam, 9 },
95 { 0 }
98 static const struct message getitemtext_seq[] = {
99 { TVM_INSERTITEMA, sent },
100 { TVM_GETITEMA, sent },
101 { TVM_DELETEITEM, sent },
102 { 0 }
105 static const struct message focus_seq[] = {
106 { TVM_INSERTITEMA, sent },
107 { TVM_INSERTITEMA, sent },
108 { TVM_SELECTITEM, sent|wparam, 9 },
109 /* The following end up out of order in wine */
110 { WM_WINDOWPOSCHANGING, sent|defwinproc },
111 { WM_NCCALCSIZE, sent|wparam|defwinproc, TRUE },
112 { WM_WINDOWPOSCHANGED, sent|defwinproc },
113 { WM_SIZE, sent|defwinproc },
114 { WM_WINDOWPOSCHANGING, sent|defwinproc|optional },
115 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, TRUE },
116 { WM_WINDOWPOSCHANGED, sent|defwinproc|optional },
117 { WM_SIZE, sent|defwinproc|optional },
118 { WM_PAINT, sent|defwinproc },
119 { WM_NCPAINT, sent|wparam|defwinproc, 1 },
120 { WM_ERASEBKGND, sent|defwinproc },
121 { TVM_EDITLABELA, sent },
122 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_UPDATE) },
123 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_CHANGE) },
124 { WM_PARENTNOTIFY, sent|wparam|defwinproc, MAKEWPARAM(WM_CREATE, 0) },
125 { WM_KILLFOCUS, sent|defwinproc },
126 { WM_PAINT, sent|defwinproc },
127 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
128 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_SETFOCUS) },
129 { WM_ERASEBKGND, sent|defwinproc|optional },
130 { WM_CTLCOLOREDIT, sent|defwinproc|optional },
131 { WM_CTLCOLOREDIT, sent|defwinproc|optional },
132 { 0 }
135 static const struct message test_get_set_bkcolor_seq[] = {
136 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
137 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, 0 },
138 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
139 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, 0x00ffffff },
140 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
141 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, -1 },
142 { 0 }
145 static const struct message test_get_set_imagelist_seq[] = {
146 { TVM_SETIMAGELIST, sent|wparam|lparam, 0, 0 },
147 { TVM_GETIMAGELIST, sent|wparam|lparam, 0, 0 },
148 { 0 }
151 static const struct message test_get_set_indent_seq[] = {
152 { TVM_SETINDENT, sent|wparam|lparam, 0, 0 },
153 { TVM_GETINDENT, sent|wparam|lparam, 0, 0 },
154 /* The actual amount to indent is dependent on the system for this message */
155 { TVM_SETINDENT, sent },
156 { TVM_GETINDENT, sent|wparam|lparam, 0, 0 },
157 { 0 }
160 static const struct message test_get_set_insertmarkcolor_seq[] = {
161 { TVM_SETINSERTMARKCOLOR, sent|wparam|lparam, 0, 0 },
162 { TVM_GETINSERTMARKCOLOR, sent|wparam|lparam, 0, 0 },
163 { 0 }
166 static const struct message test_get_set_item_seq[] = {
167 { TVM_GETITEMA, sent },
168 { TVM_SETITEMA, sent },
169 { TVM_GETITEMA, sent },
170 { TVM_SETITEMA, sent },
171 { 0 }
174 static const struct message test_get_set_itemheight_seq[] = {
175 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
176 { TVM_SETITEMHEIGHT, sent|wparam|lparam, -1, 0 },
177 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
178 { TVM_SETITEMHEIGHT, sent|lparam, 0xcccccccc, 0 },
179 { TVM_GETITEMHEIGHT, sent|wparam|lparam|optional, 0, 0 },
180 { TVM_SETITEMHEIGHT, sent|wparam|lparam|optional, 9, 0 },
181 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
182 { 0 }
185 static const struct message test_get_set_scrolltime_seq[] = {
186 { TVM_SETSCROLLTIME, sent|wparam|lparam, 20, 0 },
187 { TVM_GETSCROLLTIME, sent|wparam|lparam, 0, 0 },
188 { 0 }
191 static const struct message test_get_set_textcolor_seq[] = {
192 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
193 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
194 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
195 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, RGB(255, 255, 255) },
196 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
197 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, CLR_NONE },
198 { 0 }
201 static const struct message test_get_set_tooltips_seq[] = {
202 { WM_KILLFOCUS, sent },
203 { WM_IME_SETCONTEXT, sent|optional },
204 { WM_IME_NOTIFY, sent|optional },
205 { TVM_SETTOOLTIPS, sent|wparam|lparam, 0, 0 },
206 { TVM_GETTOOLTIPS, sent|wparam|lparam, 0, 0 },
207 { 0 }
210 static const struct message test_get_set_unicodeformat_seq[] = {
211 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, TRUE, 0 },
212 { TVM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
213 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
214 { TVM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
215 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
216 { 0 }
219 static const struct message test_right_click_seq[] = {
220 { WM_RBUTTONDOWN, sent|wparam, MK_RBUTTON },
221 { WM_CAPTURECHANGED, sent|defwinproc },
222 { TVM_GETNEXTITEM, sent|wparam|lparam|defwinproc, TVGN_CARET, 0 },
223 { WM_NCHITTEST, sent|optional },
224 { WM_SETCURSOR, sent|optional },
225 { WM_MOUSEMOVE, sent|optional },
226 { 0 }
229 static const struct message parent_expand_seq[] = {
230 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
231 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
232 { 0 }
235 static const struct message parent_expand_kb_seq[] = {
236 { WM_NOTIFY, sent|id, 0, 0, TVN_KEYDOWN },
237 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
238 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
239 { WM_CHANGEUISTATE, sent|optional },
240 { 0 }
243 static const struct message parent_collapse_2nd_kb_seq[] = {
244 { WM_NOTIFY, sent|id|optional, 0, 0, TVN_KEYDOWN },
245 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
246 { WM_CHANGEUISTATE, sent|optional },
247 { 0 }
250 static const struct message parent_expand_empty_kb_seq[] = {
251 { WM_NOTIFY, sent|id, 0, 0, TVN_KEYDOWN },
252 { WM_CHANGEUISTATE, sent|optional },
253 { 0 }
256 static const struct message parent_singleexpand_seq0[] = {
257 /* alpha expands */
258 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGINGA },
259 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGEDA },
260 { WM_NOTIFY, sent|id, 0, 0, TVN_SINGLEEXPAND },
261 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
262 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
263 { 0 }
266 static const struct message parent_singleexpand_seq1[] = {
267 /* bravo expands */
268 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGINGA },
269 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGEDA },
270 { WM_NOTIFY, sent|id, 0, 0, TVN_SINGLEEXPAND },
271 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
272 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
273 { 0 }
276 static const struct message parent_singleexpand_seq2[] = {
277 /* delta expands, bravo collapses */
278 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGINGA },
279 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGEDA },
280 { WM_NOTIFY, sent|id, 0, 0, TVN_SINGLEEXPAND },
281 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
282 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
283 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
284 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
285 { 0 }
288 static const struct message parent_singleexpand_seq3[] = {
289 /* foxtrot expands, alpha and delta collapse */
290 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGINGA },
291 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGEDA },
292 { WM_NOTIFY, sent|id, 0, 0, TVN_SINGLEEXPAND },
293 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
294 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
295 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
296 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
297 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
298 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
299 { 0 }
302 static const struct message parent_singleexpand_seq4[] = {
303 /* alpha expands, foxtrot collapses */
304 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGINGA },
305 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGEDA },
306 { WM_NOTIFY, sent|id, 0, 0, TVN_SINGLEEXPAND },
307 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
308 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
309 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
310 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
311 { 0 }
314 static const struct message parent_singleexpand_seq5[] = {
315 /* foxtrot expands while golf is selected, then golf expands and alpha collapses */
316 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGINGA },
317 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
318 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
319 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGEDA },
320 { WM_NOTIFY, sent|id, 0, 0, TVN_SINGLEEXPAND },
321 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
322 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
323 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
324 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
325 { 0 }
328 static const struct message parent_singleexpand_seq6[] = {
329 /* hotel does not expand and india does not collapse because they have no children */
330 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGINGA },
331 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGEDA },
332 { WM_NOTIFY, sent|id, 0, 0, TVN_SINGLEEXPAND },
333 { 0 }
336 static const struct message parent_singleexpand_seq7[] = {
337 /* india does not expand and hotel does not collapse because they have no children */
338 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGINGA },
339 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGEDA },
340 { WM_NOTIFY, sent|id, 0, 0, TVN_SINGLEEXPAND },
341 { 0 }
344 static const struct message parent_get_dispinfo_seq[] = {
345 { WM_NOTIFY, sent|id, 0, 0, TVN_GETDISPINFOA },
346 { 0 }
349 static const struct message empty_seq[] = {
350 { 0 }
353 static const struct message parent_cd_seq[] = {
354 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_PREPAINT },
355 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT },
356 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT },
357 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPREPAINT },
358 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_ITEMPOSTPAINT },
359 { WM_NOTIFY, sent|id|custdraw, 0, 0, NM_CUSTOMDRAW, CDDS_POSTPAINT },
360 { 0 }
363 static const struct message parent_vk_return_seq[] = {
364 { WM_NOTIFY, sent|id, 0, 0, TVN_KEYDOWN },
365 { WM_NOTIFY, sent|id, 0, 0, NM_RETURN },
366 { WM_CHANGEUISTATE, sent|optional },
367 { 0 }
370 static const struct message parent_right_click_seq[] = {
371 { WM_NOTIFY, sent|id, 0, 0, NM_RCLICK },
372 { WM_CONTEXTMENU, sent },
373 { WM_NOTIFY, sent|optional },
374 { WM_SETCURSOR, sent|optional },
375 { 0 }
378 static HWND hMainWnd;
380 static HTREEITEM hRoot, hChild;
382 static int pos = 0;
383 static char sequence[256];
385 static void Clear(void)
387 pos = 0;
388 sequence[0] = '\0';
391 static void AddItem(char ch)
393 sequence[pos++] = ch;
394 sequence[pos] = '\0';
397 static void IdentifyItem(HTREEITEM hItem)
399 if (hItem == hRoot) {
400 AddItem('R');
401 return;
403 if (hItem == hChild) {
404 AddItem('C');
405 return;
407 if (hItem == NULL) {
408 AddItem('n');
409 return;
411 AddItem('?');
414 /* This function hooks in and records all messages to the treeview control */
415 static LRESULT WINAPI TreeviewWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
417 static LONG defwndproc_counter = 0;
418 LRESULT ret;
419 WNDPROC lpOldProc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
420 struct message msg = { 0 };
422 msg.message = message;
423 msg.flags = sent|wparam|lparam;
424 if (defwndproc_counter) msg.flags |= defwinproc;
425 msg.wParam = wParam;
426 msg.lParam = lParam;
427 add_message(sequences, TREEVIEW_SEQ_INDEX, &msg);
429 defwndproc_counter++;
430 ret = CallWindowProcA(lpOldProc, hwnd, message, wParam, lParam);
431 defwndproc_counter--;
433 return ret;
436 static HWND create_treeview_control(DWORD style)
438 WNDPROC pOldWndProc;
439 HWND hTree;
441 hTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL, WS_CHILD|WS_VISIBLE|
442 TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS|TVS_EDITLABELS|style,
443 0, 0, 120, 100, hMainWnd, (HMENU)100, GetModuleHandleA(0), 0);
445 SetFocus(hTree);
447 /* Record the old WNDPROC so we can call it after recording the messages */
448 pOldWndProc = (WNDPROC)SetWindowLongPtrA(hTree, GWLP_WNDPROC, (LONG_PTR)TreeviewWndProc);
449 SetWindowLongPtrA(hTree, GWLP_USERDATA, (LONG_PTR)pOldWndProc);
451 return hTree;
454 static void fill_tree(HWND hTree)
456 TVINSERTSTRUCTA ins;
457 static CHAR root[] = "Root",
458 child[] = "Child";
460 ins.hParent = TVI_ROOT;
461 ins.hInsertAfter = TVI_ROOT;
462 U(ins).item.mask = TVIF_TEXT;
463 U(ins).item.pszText = root;
464 hRoot = TreeView_InsertItemA(hTree, &ins);
466 ins.hParent = hRoot;
467 ins.hInsertAfter = TVI_FIRST;
468 U(ins).item.mask = TVIF_TEXT;
469 U(ins).item.pszText = child;
470 hChild = TreeView_InsertItemA(hTree, &ins);
473 static void test_fillroot(void)
475 TVITEMA tvi;
476 HWND hTree;
478 hTree = create_treeview_control(0);
480 flush_sequences(sequences, NUM_MSG_SEQUENCES);
482 fill_tree(hTree);
484 Clear();
485 AddItem('A');
486 ok(hRoot != NULL, "failed to set root\n");
487 AddItem('B');
488 ok(hChild != NULL, "failed to set child\n");
489 AddItem('.');
490 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, FillRootSeq, "FillRoot", FALSE);
491 ok(!strcmp(sequence, "AB."), "Item creation\n");
493 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
494 tvi.hItem = hRoot;
495 tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
496 SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&tvi);
497 ok(tvi.iImage == 0, "tvi.iImage=%d\n", tvi.iImage);
498 ok(tvi.iSelectedImage == 0, "tvi.iSelectedImage=%d\n", tvi.iSelectedImage);
500 DestroyWindow(hTree);
503 static void test_callback(void)
505 HTREEITEM hRoot;
506 HTREEITEM hItem1, hItem2;
507 TVINSERTSTRUCTA ins;
508 TVITEMA tvi;
509 CHAR test_string[] = "Test_string";
510 static const CHAR test2A[] = "TEST2";
511 CHAR buf[128];
512 HWND hTree;
513 DWORD ret;
515 hTree = create_treeview_control(0);
517 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
518 expect(TRUE, ret);
519 ins.hParent = TVI_ROOT;
520 ins.hInsertAfter = TVI_ROOT;
521 U(ins).item.mask = TVIF_TEXT;
522 U(ins).item.pszText = LPSTR_TEXTCALLBACKA;
523 hRoot = TreeView_InsertItemA(hTree, &ins);
524 ok(hRoot != NULL, "failed to set root\n");
526 tvi.hItem = hRoot;
527 tvi.mask = TVIF_TEXT;
528 tvi.pszText = buf;
529 tvi.cchTextMax = sizeof(buf)/sizeof(buf[0]);
530 ret = TreeView_GetItemA(hTree, &tvi);
531 expect(TRUE, ret);
532 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Callback item text mismatch %s vs %s\n",
533 tvi.pszText, TEST_CALLBACK_TEXT);
535 ins.hParent = hRoot;
536 ins.hInsertAfter = TVI_FIRST;
537 U(ins).item.mask = TVIF_TEXT;
538 U(ins).item.pszText = test_string;
539 hItem1 = TreeView_InsertItemA(hTree, &ins);
540 ok(hItem1 != NULL, "failed to set Item1\n");
542 tvi.hItem = hItem1;
543 ret = TreeView_GetItemA(hTree, &tvi);
544 expect(TRUE, ret);
545 ok(strcmp(tvi.pszText, test_string) == 0, "Item text mismatch %s vs %s\n",
546 tvi.pszText, test_string);
548 /* undocumented: pszText of NULL also means LPSTR_CALLBACK: */
549 tvi.pszText = NULL;
550 ret = TreeView_SetItemA(hTree, &tvi);
551 expect(TRUE, ret);
552 tvi.pszText = buf;
553 ret = TreeView_GetItemA(hTree, &tvi);
554 expect(TRUE, ret);
555 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Item text mismatch %s vs %s\n",
556 tvi.pszText, TEST_CALLBACK_TEXT);
558 U(ins).item.pszText = NULL;
559 hItem2 = TreeView_InsertItemA(hTree, &ins);
560 ok(hItem2 != NULL, "failed to set Item2\n");
561 tvi.hItem = hItem2;
562 memset(buf, 0, sizeof(buf));
563 ret = TreeView_GetItemA(hTree, &tvi);
564 expect(TRUE, ret);
565 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Item text mismatch %s vs %s\n",
566 tvi.pszText, TEST_CALLBACK_TEXT);
568 /* notification handler changed A->W */
569 g_disp_A_to_W = TRUE;
570 tvi.hItem = hItem2;
571 memset(buf, 0, sizeof(buf));
572 ret = TreeView_GetItemA(hTree, &tvi);
573 expect(TRUE, ret);
574 ok(strcmp(tvi.pszText, test2A) == 0, "got %s, expected %s\n",
575 tvi.pszText, test2A);
576 g_disp_A_to_W = FALSE;
578 /* handler changes state image index */
579 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
581 /* clear selection, handler will set selected state */
582 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
583 expect(TRUE, ret);
585 flush_sequences(sequences, NUM_MSG_SEQUENCES);
587 tvi.hItem = hRoot;
588 tvi.mask = TVIF_STATE;
589 tvi.state = TVIS_SELECTED;
590 ret = TreeView_GetItemA(hTree, &tvi);
591 expect(TRUE, ret);
592 ok(tvi.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", tvi.state);
594 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
595 "no TVN_GETDISPINFO for a state seq", FALSE);
597 tvi.hItem = hRoot;
598 tvi.mask = TVIF_IMAGE | TVIF_STATE;
599 tvi.state = TVIS_FOCUSED;
600 tvi.stateMask = TVIS_FOCUSED;
601 tvi.iImage = I_IMAGECALLBACK;
602 ret = TreeView_SetItemA(hTree, &tvi);
603 expect(TRUE, ret);
605 /* ask for item image index through callback - state is also set with state image index */
606 flush_sequences(sequences, NUM_MSG_SEQUENCES);
608 tvi.hItem = hRoot;
609 tvi.mask = TVIF_IMAGE;
610 tvi.state = 0;
611 ret = TreeView_GetItemA(hTree, &tvi);
612 expect(TRUE, ret);
613 ok(tvi.state == (INDEXTOSTATEIMAGEMASK(1) | TVIS_FOCUSED), "got 0x%x\n", tvi.state);
615 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_get_dispinfo_seq,
616 "callback for state/overlay image index, noop seq", FALSE);
618 /* ask for image again and overwrite state to some value in handler */
619 flush_sequences(sequences, NUM_MSG_SEQUENCES);
621 g_disp_set_stateimage = TRUE;
622 tvi.hItem = hRoot;
623 tvi.mask = TVIF_IMAGE;
624 tvi.state = INDEXTOSTATEIMAGEMASK(1);
625 tvi.stateMask = 0;
626 ret = TreeView_GetItemA(hTree, &tvi);
627 expect(TRUE, ret);
628 /* handler sets TVIS_SELECTED as well */
629 ok(tvi.state == (TVIS_FOCUSED | TVIS_SELECTED | INDEXTOSTATEIMAGEMASK(2) | INDEXTOOVERLAYMASK(3)), "got 0x%x\n", tvi.state);
630 g_disp_set_stateimage = FALSE;
632 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_get_dispinfo_seq,
633 "callback for state/overlay image index seq", FALSE);
635 DestroyWindow(hTree);
638 static void test_select(void)
640 BOOL r;
641 HWND hTree;
643 hTree = create_treeview_control(0);
644 fill_tree(hTree);
646 /* root-none select tests */
647 flush_sequences(sequences, NUM_MSG_SEQUENCES);
648 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
649 expect(TRUE, r);
650 Clear();
651 AddItem('1');
652 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
653 expect(TRUE, r);
654 AddItem('2');
655 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
656 expect(TRUE, r);
657 AddItem('3');
658 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
659 expect(TRUE, r);
660 AddItem('4');
661 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
662 expect(TRUE, r);
663 AddItem('5');
664 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
665 expect(TRUE, r);
666 AddItem('.');
667 ok(!strcmp(sequence, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
668 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, rootnone_select_seq,
669 "root-none select seq", FALSE);
671 /* root-child select tests */
672 flush_sequences(sequences, NUM_MSG_SEQUENCES);
673 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
674 expect(TRUE, r);
676 Clear();
677 AddItem('1');
678 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
679 expect(TRUE, r);
680 AddItem('2');
681 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
682 expect(TRUE, r);
683 AddItem('3');
684 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
685 expect(TRUE, r);
686 AddItem('4');
687 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
688 expect(TRUE, r);
689 AddItem('5');
690 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
691 expect(TRUE, r);
692 AddItem('.');
693 ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
694 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, rootchild_select_seq,
695 "root-child select seq", FALSE);
697 DestroyWindow(hTree);
700 static void test_getitemtext(void)
702 TVINSERTSTRUCTA ins;
703 HTREEITEM hChild;
704 TVITEMA tvi;
705 HWND hTree;
707 CHAR szBuffer[80] = "Blah";
708 int nBufferSize = sizeof(szBuffer)/sizeof(CHAR);
710 hTree = create_treeview_control(0);
711 fill_tree(hTree);
713 flush_sequences(sequences, NUM_MSG_SEQUENCES);
715 /* add an item without TVIF_TEXT mask and pszText == NULL */
716 ins.hParent = hRoot;
717 ins.hInsertAfter = TVI_ROOT;
718 U(ins).item.mask = 0;
719 U(ins).item.pszText = NULL;
720 U(ins).item.cchTextMax = 0;
721 hChild = TreeView_InsertItemA(hTree, &ins);
722 ok(hChild != NULL, "failed to set hChild\n");
724 /* retrieve it with TVIF_TEXT mask */
725 tvi.hItem = hChild;
726 tvi.mask = TVIF_TEXT;
727 tvi.cchTextMax = nBufferSize;
728 tvi.pszText = szBuffer;
730 SendMessageA( hTree, TVM_GETITEMA, 0, (LPARAM)&tvi );
731 ok(!strcmp(szBuffer, ""), "szBuffer=\"%s\", expected \"\"\n", szBuffer);
732 ok(SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild), "DeleteItem failed\n");
733 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, getitemtext_seq, "get item text seq", FALSE);
735 DestroyWindow(hTree);
738 static void test_focus(void)
740 TVINSERTSTRUCTA ins;
741 static CHAR child1[] = "Edit",
742 child2[] = "A really long string";
743 HTREEITEM hChild1, hChild2;
744 HWND hTree;
745 HWND hEdit;
747 hTree = create_treeview_control(0);
748 fill_tree(hTree);
750 flush_sequences(sequences, NUM_MSG_SEQUENCES);
752 /* This test verifies that when a label is being edited, scrolling
753 * the treeview does not cause the label to lose focus. To test
754 * this, first some additional entries are added to generate
755 * scrollbars.
757 ins.hParent = hRoot;
758 ins.hInsertAfter = hChild;
759 U(ins).item.mask = TVIF_TEXT;
760 U(ins).item.pszText = child1;
761 hChild1 = TreeView_InsertItemA(hTree, &ins);
762 ok(hChild1 != NULL, "failed to set hChild1\n");
763 ins.hInsertAfter = hChild1;
764 U(ins).item.mask = TVIF_TEXT;
765 U(ins).item.pszText = child2;
766 hChild2 = TreeView_InsertItemA(hTree, &ins);
767 ok(hChild2 != NULL, "failed to set hChild2\n");
769 ShowWindow(hMainWnd,SW_SHOW);
770 SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
771 hEdit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hChild);
772 ScrollWindowEx(hTree, -10, 0, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN);
773 ok(GetFocus() == hEdit, "Edit control should have focus\n");
774 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, focus_seq, "focus test", TRUE);
776 DestroyWindow(hTree);
779 static void test_get_set_bkcolor(void)
781 COLORREF crColor;
782 HWND hTree;
784 hTree = create_treeview_control(0);
785 fill_tree(hTree);
787 flush_sequences(sequences, NUM_MSG_SEQUENCES);
789 /* If the value is -1, the control is using the system color for the background color. */
790 crColor = SendMessageA(hTree, TVM_GETBKCOLOR, 0, 0);
791 ok(crColor == ~0u, "Default background color reported as 0x%.8x\n", crColor);
793 /* Test for black background */
794 SendMessageA(hTree, TVM_SETBKCOLOR, 0, RGB(0,0,0));
795 crColor = SendMessageA(hTree, TVM_GETBKCOLOR, 0, 0);
796 ok(crColor == RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor);
798 /* Test for white background */
799 SendMessageA(hTree, TVM_SETBKCOLOR, 0, RGB(255,255,255));
800 crColor = SendMessageA(hTree, TVM_GETBKCOLOR, 0, 0);
801 ok(crColor == RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor);
803 /* Reset the default background */
804 SendMessageA(hTree, TVM_SETBKCOLOR, 0, -1);
806 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_bkcolor_seq,
807 "test get set bkcolor", FALSE);
809 DestroyWindow(hTree);
812 static void test_get_set_imagelist(void)
814 HIMAGELIST himl;
815 HWND hTree;
817 hTree = create_treeview_control(0);
818 fill_tree(hTree);
820 flush_sequences(sequences, NUM_MSG_SEQUENCES);
822 /* Test a NULL HIMAGELIST */
823 SendMessageA(hTree, TVM_SETIMAGELIST, TVSIL_NORMAL, 0);
824 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_NORMAL, 0);
825 ok(himl == NULL, "NULL image list, reported as %p, expected 0.\n", himl);
827 /* TODO: Test an actual image list */
829 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_imagelist_seq,
830 "test get imagelist", FALSE);
832 DestroyWindow(hTree);
835 static void test_get_set_indent(void)
837 int ulIndent;
838 int ulMinIndent;
839 int ulMoreThanTwiceMin;
840 HWND hTree;
842 hTree = create_treeview_control(0);
843 fill_tree(hTree);
845 flush_sequences(sequences, NUM_MSG_SEQUENCES);
847 /* Finding the minimum indent */
848 SendMessageA(hTree, TVM_SETINDENT, 0, 0);
849 ulMinIndent = SendMessageA(hTree, TVM_GETINDENT, 0, 0);
851 /* Checking an indent that is more than twice the default indent */
852 ulMoreThanTwiceMin = 2*ulMinIndent+1;
853 SendMessageA(hTree, TVM_SETINDENT, ulMoreThanTwiceMin, 0);
854 ulIndent = SendMessageA(hTree, TVM_GETINDENT, 0, 0);
855 ok(ulIndent == ulMoreThanTwiceMin, "Indent reported as %d, expected %d\n", ulIndent, ulMoreThanTwiceMin);
857 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_indent_seq,
858 "test get set indent", FALSE);
860 DestroyWindow(hTree);
863 static void test_get_set_insertmark(void)
865 COLORREF crColor = RGB(0,0,0);
866 HWND hTree;
868 hTree = create_treeview_control(0);
869 fill_tree(hTree);
871 flush_sequences(sequences, NUM_MSG_SEQUENCES);
873 SendMessageA(hTree, TVM_SETINSERTMARKCOLOR, 0, crColor);
874 crColor = SendMessageA(hTree, TVM_GETINSERTMARKCOLOR, 0, 0);
875 ok(crColor == RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor);
877 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_insertmarkcolor_seq,
878 "test get set insertmark color", FALSE);
880 DestroyWindow(hTree);
883 static void test_get_set_item(void)
885 TVITEMA tviRoot = {0};
886 int nBufferSize = 80;
887 char szBuffer[80] = {0};
888 HWND hTree, hTree2;
889 DWORD ret;
891 hTree = create_treeview_control(0);
892 fill_tree(hTree);
894 tviRoot.hItem = hRoot;
895 tviRoot.mask = TVIF_STATE;
896 tviRoot.state = TVIS_FOCUSED;
897 tviRoot.stateMask = TVIS_FOCUSED;
898 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&tviRoot);
899 expect(TRUE, ret);
901 flush_sequences(sequences, NUM_MSG_SEQUENCES);
903 /* Test the root item, state is set even when not requested */
904 tviRoot.hItem = hRoot;
905 tviRoot.mask = TVIF_TEXT;
906 tviRoot.state = 0;
907 tviRoot.stateMask = 0;
908 tviRoot.cchTextMax = nBufferSize;
909 tviRoot.pszText = szBuffer;
910 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&tviRoot);
911 expect(TRUE, ret);
912 ok(!strcmp("Root", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer);
913 ok(tviRoot.state == TVIS_FOCUSED, "got 0x%0x\n", tviRoot.state);
915 /* Change the root text */
916 lstrcpynA(szBuffer, "Testing123", nBufferSize);
917 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&tviRoot);
918 expect(TRUE, ret);
919 memset(szBuffer, 0, nBufferSize);
920 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&tviRoot);
921 expect(TRUE, ret);
922 ok(!strcmp("Testing123", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer);
924 /* Reset the root text */
925 memset(szBuffer, 0, nBufferSize);
926 lstrcpynA(szBuffer, "Root", nBufferSize);
927 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&tviRoot);
928 expect(TRUE, ret);
930 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_item_seq,
931 "test get set item", FALSE);
933 /* get item from a different tree */
934 hTree2 = create_treeview_control(0);
936 tviRoot.hItem = hRoot;
937 tviRoot.mask = TVIF_STATE;
938 tviRoot.state = 0;
939 ret = SendMessageA(hTree2, TVM_GETITEMA, 0, (LPARAM)&tviRoot);
940 expect(TRUE, ret);
941 ok(tviRoot.state == TVIS_FOCUSED, "got state 0x%0x\n", tviRoot.state);
943 /* invalid item pointer, nt4 crashes here but later versions just return 0 */
944 tviRoot.hItem = (HTREEITEM)0xdeadbeef;
945 tviRoot.mask = TVIF_STATE;
946 tviRoot.state = 0;
947 ret = SendMessageA(hTree2, TVM_GETITEMA, 0, (LPARAM)&tviRoot);
948 expect(FALSE, ret);
950 DestroyWindow(hTree);
951 DestroyWindow(hTree2);
954 static void test_get_set_itemheight(void)
956 int ulOldHeight = 0;
957 int ulNewHeight = 0;
958 HWND hTree;
960 hTree = create_treeview_control(0);
961 fill_tree(hTree);
963 flush_sequences(sequences, NUM_MSG_SEQUENCES);
965 /* Assuming default height to begin with */
966 ulOldHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
968 /* Explicitly setting and getting the default height */
969 SendMessageA(hTree, TVM_SETITEMHEIGHT, -1, 0);
970 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
971 ok(ulNewHeight == ulOldHeight, "Default height not set properly, reported %d, expected %d\n", ulNewHeight, ulOldHeight);
973 /* Explicitly setting and getting the height of twice the normal */
974 SendMessageA(hTree, TVM_SETITEMHEIGHT, 2*ulOldHeight, 0);
975 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
976 ok(ulNewHeight == 2*ulOldHeight, "New height not set properly, reported %d, expected %d\n", ulNewHeight, 2*ulOldHeight);
978 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
979 SendMessageA(hTree, TVM_SETITEMHEIGHT, 9, 0);
980 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
981 ok(ulNewHeight == 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight, 8);
983 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_itemheight_seq,
984 "test get set item height", FALSE);
986 /* without TVS_NONEVENHEIGHT */
987 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) & ~TVS_NONEVENHEIGHT);
988 /* odd value */
989 ulOldHeight = SendMessageA(hTree, TVM_SETITEMHEIGHT, 3, 0);
990 ok(ulOldHeight == 8, "got %d, expected %d\n", ulOldHeight, 8);
991 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
992 ok(ulNewHeight == 2, "got %d, expected %d\n", ulNewHeight, 2);
994 ulOldHeight = SendMessageA(hTree, TVM_SETITEMHEIGHT, 4, 0);
995 ok(ulOldHeight == 2, "got %d, expected %d\n", ulOldHeight, 2);
996 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
997 ok(ulNewHeight == 4, "got %d, expected %d\n", ulNewHeight, 4);
999 /* with TVS_NONEVENHEIGHT */
1000 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_NONEVENHEIGHT);
1001 /* odd value */
1002 ulOldHeight = SendMessageA(hTree, TVM_SETITEMHEIGHT, 3, 0);
1003 ok(ulOldHeight == 4, "got %d, expected %d\n", ulOldHeight, 4);
1004 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
1005 ok(ulNewHeight == 3, "got %d, expected %d\n", ulNewHeight, 3);
1006 /* even value */
1007 ulOldHeight = SendMessageA(hTree, TVM_SETITEMHEIGHT, 10, 0);
1008 ok(ulOldHeight == 3, "got %d, expected %d\n", ulOldHeight, 3);
1009 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
1010 ok(ulNewHeight == 10, "got %d, expected %d\n", ulNewHeight, 10);
1012 DestroyWindow(hTree);
1015 static void test_get_set_scrolltime(void)
1017 int ulExpectedTime = 20;
1018 int ulTime = 0;
1019 HWND hTree;
1021 hTree = create_treeview_control(0);
1022 fill_tree(hTree);
1024 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1026 SendMessageA(hTree, TVM_SETSCROLLTIME, ulExpectedTime, 0);
1027 ulTime = SendMessageA(hTree, TVM_GETSCROLLTIME, 0, 0);
1028 ok(ulTime == ulExpectedTime, "Scroll time reported as %d, expected %d\n", ulTime, ulExpectedTime);
1030 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_scrolltime_seq,
1031 "test get set scroll time", FALSE);
1033 DestroyWindow(hTree);
1036 static void test_get_set_textcolor(void)
1038 /* If the value is -1, the control is using the system color for the text color. */
1039 COLORREF crColor;
1040 HWND hTree;
1042 hTree = create_treeview_control(0);
1043 fill_tree(hTree);
1045 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1047 crColor = SendMessageA(hTree, TVM_GETTEXTCOLOR, 0, 0);
1048 ok(crColor == ~0u, "Default text color reported as 0x%.8x\n", crColor);
1050 /* Test for black text */
1051 SendMessageA(hTree, TVM_SETTEXTCOLOR, 0, RGB(0,0,0));
1052 crColor = SendMessageA(hTree, TVM_GETTEXTCOLOR, 0, 0);
1053 ok(crColor == RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor);
1055 /* Test for white text */
1056 SendMessageA(hTree, TVM_SETTEXTCOLOR, 0, RGB(255,255,255));
1057 crColor = SendMessageA(hTree, TVM_GETTEXTCOLOR, 0, 0);
1058 ok(crColor == RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor);
1060 /* Reset the default text color */
1061 SendMessageA(hTree, TVM_SETTEXTCOLOR, 0, CLR_NONE);
1063 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_textcolor_seq,
1064 "test get set text color", FALSE);
1066 DestroyWindow(hTree);
1069 static void test_get_set_tooltips(void)
1071 HWND hwndLastToolTip = NULL;
1072 HWND hPopupTreeView;
1073 HWND hTree;
1075 hTree = create_treeview_control(0);
1076 fill_tree(hTree);
1078 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1080 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
1081 hPopupTreeView = CreateWindowA(WC_TREEVIEWA, NULL, WS_POPUP|WS_VISIBLE, 0, 0, 100, 100,
1082 hMainWnd, NULL, NULL, NULL);
1083 DestroyWindow(hPopupTreeView);
1085 /* Testing setting a NULL ToolTip */
1086 SendMessageA(hTree, TVM_SETTOOLTIPS, 0, 0);
1087 hwndLastToolTip = (HWND)SendMessageA(hTree, TVM_GETTOOLTIPS, 0, 0);
1088 ok(hwndLastToolTip == NULL, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip);
1090 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_tooltips_seq,
1091 "test get set tooltips", TRUE);
1093 /* TODO: Add a test of an actual tooltip */
1094 DestroyWindow(hTree);
1097 static void test_get_set_unicodeformat(void)
1099 BOOL bPreviousSetting;
1100 BOOL bNewSetting;
1101 HWND hTree;
1103 hTree = create_treeview_control(0);
1104 fill_tree(hTree);
1106 /* Check that an invalid format returned by NF_QUERY defaults to ANSI */
1107 bPreviousSetting = SendMessageA(hTree, TVM_GETUNICODEFORMAT, 0, 0);
1108 ok(bPreviousSetting == FALSE, "Format should be ANSI.\n");
1110 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1112 /* Set to Unicode */
1113 bPreviousSetting = SendMessageA(hTree, TVM_SETUNICODEFORMAT, 1, 0);
1114 bNewSetting = SendMessageA(hTree, TVM_GETUNICODEFORMAT, 0, 0);
1115 ok(bNewSetting == TRUE, "Unicode setting did not work.\n");
1117 /* Set to ANSI */
1118 SendMessageA(hTree, TVM_SETUNICODEFORMAT, 0, 0);
1119 bNewSetting = SendMessageA(hTree, TVM_GETUNICODEFORMAT, 0, 0);
1120 ok(bNewSetting == FALSE, "ANSI setting did not work.\n");
1122 /* Revert to original setting */
1123 SendMessageA(hTree, TVM_SETUNICODEFORMAT, bPreviousSetting, 0);
1125 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_unicodeformat_seq,
1126 "test get set unicode format", FALSE);
1128 DestroyWindow(hTree);
1131 static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1133 static LONG defwndproc_counter = 0;
1134 struct message msg = { 0 };
1135 LRESULT ret;
1136 RECT rect;
1137 HTREEITEM visibleItem;
1139 msg.message = message;
1140 msg.flags = sent|wparam|lparam;
1141 if (defwndproc_counter) msg.flags |= defwinproc;
1142 msg.wParam = wParam;
1143 msg.lParam = lParam;
1144 if (message == WM_NOTIFY && lParam)
1145 msg.id = ((NMHDR*)lParam)->code;
1147 /* log system messages, except for painting */
1148 if (message < WM_USER &&
1149 message != WM_PAINT &&
1150 message != WM_ERASEBKGND &&
1151 message != WM_NCPAINT &&
1152 message != WM_NCHITTEST &&
1153 message != WM_GETTEXT &&
1154 message != WM_GETICON &&
1155 message != WM_DEVICECHANGE)
1157 add_message(sequences, PARENT_SEQ_INDEX, &msg);
1160 switch(message) {
1161 case WM_NOTIFYFORMAT:
1163 /* Make NF_QUERY return an invalid format to show that it defaults to ANSI */
1164 if (lParam == NF_QUERY) return 0;
1165 break;
1168 case WM_NOTIFY:
1170 NMHDR *pHdr = (NMHDR *)lParam;
1172 ok(pHdr->code != NM_TOOLTIPSCREATED, "Treeview should not send NM_TOOLTIPSCREATED\n");
1173 if (pHdr->idFrom == 100)
1175 NMTREEVIEWA *pTreeView = (LPNMTREEVIEWA) lParam;
1176 switch(pHdr->code)
1178 case TVN_SELCHANGINGA:
1179 AddItem('(');
1180 IdentifyItem(pTreeView->itemOld.hItem);
1181 IdentifyItem(pTreeView->itemNew.hItem);
1182 break;
1183 case TVN_SELCHANGEDA:
1184 AddItem(')');
1185 IdentifyItem(pTreeView->itemOld.hItem);
1186 IdentifyItem(pTreeView->itemNew.hItem);
1187 break;
1188 case TVN_GETDISPINFOA: {
1189 NMTVDISPINFOA *disp = (NMTVDISPINFOA *)lParam;
1190 if (disp->item.mask & TVIF_TEXT) {
1191 lstrcpynA(disp->item.pszText, TEST_CALLBACK_TEXT, disp->item.cchTextMax);
1194 if (g_disp_A_to_W && (disp->item.mask & TVIF_TEXT)) {
1195 static const WCHAR testW[] = {'T','E','S','T','2',0};
1197 disp->hdr.code = TVN_GETDISPINFOW;
1198 memcpy(disp->item.pszText, testW, sizeof(testW));
1201 if (g_disp_set_stateimage)
1203 ok(disp->item.mask == TVIF_IMAGE, "got %x\n", disp->item.mask);
1204 /* both masks set here are necessary to change state bits */
1205 disp->item.mask |= TVIF_STATE;
1206 disp->item.state = TVIS_SELECTED | INDEXTOSTATEIMAGEMASK(2) | INDEXTOOVERLAYMASK(3);
1207 disp->item.stateMask = TVIS_SELECTED | TVIS_OVERLAYMASK | TVIS_STATEIMAGEMASK;
1210 break;
1212 case TVN_BEGINLABELEDITA:
1214 if (g_beginedit_alter_text)
1216 static const char* textA = "<edittextaltered>";
1217 HWND edit;
1219 edit = (HWND)SendMessageA(pHdr->hwndFrom, TVM_GETEDITCONTROL, 0, 0);
1220 ok(IsWindow(edit), "failed to get edit handle\n");
1221 SetWindowTextA(edit, textA);
1224 break;
1227 case TVN_ENDLABELEDITA: return TRUE;
1228 case TVN_ITEMEXPANDINGA:
1230 UINT newmask = pTreeView->itemNew.mask & ~TVIF_CHILDREN;
1231 ok(newmask ==
1232 (TVIF_HANDLE | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_PARAM | TVIF_STATE),
1233 "got wrong mask %x\n", pTreeView->itemNew.mask);
1234 ok(pTreeView->itemOld.mask == 0,
1235 "got wrong mask %x\n", pTreeView->itemOld.mask);
1237 if (g_get_from_expand)
1239 g_item_expanding.mask = TVIF_STATE;
1240 g_item_expanding.hItem = hRoot;
1241 ret = SendMessageA(pHdr->hwndFrom, TVM_GETITEMA, 0, (LPARAM)&g_item_expanding);
1242 ok(ret == TRUE, "got %lu\n", ret);
1244 break;
1246 case TVN_ITEMEXPANDEDA:
1247 ok(pTreeView->itemNew.mask & TVIF_STATE, "got wrong mask %x\n", pTreeView->itemNew.mask);
1248 ok(pTreeView->itemNew.state & (TVIS_EXPANDED|TVIS_EXPANDEDONCE),
1249 "got wrong mask %x\n", pTreeView->itemNew.mask);
1250 ok(pTreeView->itemOld.mask == 0,
1251 "got wrong mask %x\n", pTreeView->itemOld.mask);
1253 if (g_get_from_expand)
1255 g_item_expanded.mask = TVIF_STATE;
1256 g_item_expanded.hItem = hRoot;
1257 ret = SendMessageA(pHdr->hwndFrom, TVM_GETITEMA, 0, (LPARAM)&g_item_expanded);
1258 ok(ret == TRUE, "got %lu\n", ret);
1260 if (g_get_rect_in_expand)
1262 visibleItem = (HTREEITEM)SendMessageA(pHdr->hwndFrom, TVM_GETNEXTITEM,
1263 TVGN_FIRSTVISIBLE, 0);
1264 ok(pTreeView->itemNew.hItem == visibleItem, "expanded item == first visible item\n");
1265 *(HTREEITEM*)&rect = visibleItem;
1266 ok(SendMessageA(pHdr->hwndFrom, TVM_GETITEMRECT, TRUE, (LPARAM)&rect),
1267 "Failed to get rect for first visible item.\n");
1268 visibleItem = (HTREEITEM)SendMessageA(pHdr->hwndFrom, TVM_GETNEXTITEM,
1269 TVGN_NEXTVISIBLE, (LPARAM)visibleItem);
1270 *(HTREEITEM*)&rect = visibleItem;
1271 ok(visibleItem != NULL, "There must be a visible item after the first visisble item.\n");
1272 ok(SendMessageA(pHdr->hwndFrom, TVM_GETITEMRECT, TRUE, (LPARAM)&rect),
1273 "Failed to get rect for second visible item.\n");
1275 break;
1276 case TVN_DELETEITEMA:
1278 struct message item;
1280 ok(pTreeView->itemNew.mask == 0, "got wrong mask 0x%x\n", pTreeView->itemNew.mask);
1282 ok(pTreeView->itemOld.mask == (TVIF_HANDLE | TVIF_PARAM), "got wrong mask 0x%x\n", pTreeView->itemOld.mask);
1283 ok(pTreeView->itemOld.hItem != NULL, "got %p\n", pTreeView->itemOld.hItem);
1285 memset(&item, 0, sizeof(item));
1286 item.lParam = (LPARAM)pTreeView->itemOld.hItem;
1287 add_message(item_sequence, 0, &item);
1289 break;
1291 case NM_CUSTOMDRAW:
1293 NMTVCUSTOMDRAW *nmcd = (NMTVCUSTOMDRAW*)lParam;
1294 COLORREF c0ffee = RGB(0xc0,0xff,0xee), cafe = RGB(0xca,0xfe,0x00);
1295 COLORREF text = GetTextColor(nmcd->nmcd.hdc), bkgnd = GetBkColor(nmcd->nmcd.hdc);
1297 msg.flags |= custdraw;
1298 msg.stage = nmcd->nmcd.dwDrawStage;
1299 add_message(sequences, PARENT_CD_SEQ_INDEX, &msg);
1301 switch (msg.stage)
1303 case CDDS_PREPAINT:
1304 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYITEMERASE|CDRF_NOTIFYPOSTPAINT;
1305 case CDDS_ITEMPREPAINT:
1306 ok(text == nmcd->clrText || (g_v6 && nmcd->clrText == 0xffffffff),
1307 "got %08x vs %08x\n", text, nmcd->clrText);
1308 ok(bkgnd == nmcd->clrTextBk || (g_v6 && nmcd->clrTextBk == 0xffffffff),
1309 "got %08x vs %08x\n", bkgnd, nmcd->clrTextBk);
1310 nmcd->clrText = cafe;
1311 nmcd->clrTextBk = c0ffee;
1312 SetTextColor(nmcd->nmcd.hdc, c0ffee);
1313 SetBkColor(nmcd->nmcd.hdc, cafe);
1314 if (g_customdraw_font)
1315 SelectObject(nmcd->nmcd.hdc, g_customdraw_font);
1316 return CDRF_NOTIFYPOSTPAINT|CDRF_NEWFONT;
1317 case CDDS_ITEMPOSTPAINT:
1318 /* at the point of post paint notification colors are already restored */
1319 ok(nmcd->clrText == cafe, "got 0%x\n", nmcd->clrText);
1320 ok(nmcd->clrTextBk == c0ffee, "got 0%x\n", nmcd->clrTextBk);
1321 ok(text != cafe, "got 0%x\n", text);
1322 ok(bkgnd != c0ffee, "got 0%x\n", bkgnd);
1323 if (g_customdraw_font)
1324 ok(GetCurrentObject(nmcd->nmcd.hdc, OBJ_FONT) != g_customdraw_font, "got %p\n",
1325 GetCurrentObject(nmcd->nmcd.hdc, OBJ_FONT));
1326 break;
1327 default:
1330 break;
1332 case NM_RCLICK:
1334 HTREEITEM selected = (HTREEITEM)SendMessageA(((NMHDR *)lParam)->hwndFrom,
1335 TVM_GETNEXTITEM, TVGN_CARET, 0);
1336 ok(selected == hChild, "child item should still be selected\n");
1337 break;
1341 break;
1344 case WM_DESTROY:
1345 PostQuitMessage(0);
1346 break;
1349 defwndproc_counter++;
1350 ret = DefWindowProcA(hWnd, message, wParam, lParam);
1351 defwndproc_counter--;
1353 return ret;
1356 static void test_expandinvisible(void)
1358 static CHAR nodeText[][5] = {"0", "1", "2", "3", "4"};
1359 TVINSERTSTRUCTA ins;
1360 HTREEITEM node[5];
1361 RECT dummyRect;
1362 BOOL nodeVisible;
1363 LRESULT ret;
1364 HWND hTree;
1366 hTree = create_treeview_control(0);
1368 /* The test builds the following tree and expands node 1, while node 0 is collapsed.
1371 * |- 1
1372 * | |- 2
1373 * | |- 3
1374 * |- 4
1378 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
1379 ok(ret == TRUE, "ret\n");
1380 ins.hParent = TVI_ROOT;
1381 ins.hInsertAfter = TVI_ROOT;
1382 U(ins).item.mask = TVIF_TEXT;
1383 U(ins).item.pszText = nodeText[0];
1384 node[0] = TreeView_InsertItemA(hTree, &ins);
1385 ok(node[0] != NULL, "failed to set node[0]\n");
1387 ins.hInsertAfter = TVI_LAST;
1388 U(ins).item.mask = TVIF_TEXT;
1389 ins.hParent = node[0];
1391 U(ins).item.pszText = nodeText[1];
1392 node[1] = TreeView_InsertItemA(hTree, &ins);
1393 ok(node[1] != NULL, "failed to set node[1]\n");
1394 U(ins).item.pszText = nodeText[4];
1395 node[4] = TreeView_InsertItemA(hTree, &ins);
1396 ok(node[4] != NULL, "failed to set node[4]\n");
1398 ins.hParent = node[1];
1400 U(ins).item.pszText = nodeText[2];
1401 node[2] = TreeView_InsertItemA(hTree, &ins);
1402 ok(node[2] != NULL, "failed to set node[2]\n");
1403 U(ins).item.pszText = nodeText[3];
1404 node[3] = TreeView_InsertItemA(hTree, &ins);
1405 ok(node[3] != NULL, "failed to set node[3]\n");
1407 *(HTREEITEM *)&dummyRect = node[1];
1408 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1409 ok(!nodeVisible, "Node 1 should not be visible.\n");
1410 *(HTREEITEM *)&dummyRect = node[2];
1411 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1412 ok(!nodeVisible, "Node 2 should not be visible.\n");
1413 *(HTREEITEM *)&dummyRect = node[3];
1414 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1415 ok(!nodeVisible, "Node 3 should not be visible.\n");
1416 *(HTREEITEM *)&dummyRect = node[4];
1417 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1418 ok(!nodeVisible, "Node 4 should not be visible.\n");
1420 ok(SendMessageA(hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)node[1]), "Expand of node 1 failed.\n");
1422 *(HTREEITEM *)&dummyRect = node[1];
1423 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1424 ok(!nodeVisible, "Node 1 should not be visible.\n");
1425 *(HTREEITEM *)&dummyRect = node[2];
1426 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1427 ok(!nodeVisible, "Node 2 should not be visible.\n");
1428 *(HTREEITEM *)&dummyRect = node[3];
1429 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1430 ok(!nodeVisible, "Node 3 should not be visible.\n");
1431 *(HTREEITEM *)&dummyRect = node[4];
1432 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1433 ok(!nodeVisible, "Node 4 should not be visible.\n");
1435 DestroyWindow(hTree);
1438 static void test_itemedit(void)
1440 DWORD r;
1441 HWND edit;
1442 TVITEMA item;
1443 CHAR buffA[20];
1444 HWND hTree;
1446 hTree = create_treeview_control(0);
1447 fill_tree(hTree);
1449 /* try with null item */
1450 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, 0);
1451 ok(!IsWindow(edit), "Expected valid handle\n");
1453 /* trigger edit */
1454 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1455 ok(IsWindow(edit), "Expected valid handle\n");
1456 /* item shouldn't be selected automatically after TVM_EDITLABELA */
1457 r = SendMessageA(hTree, TVM_GETITEMSTATE, (WPARAM)hRoot, TVIS_SELECTED);
1458 expect(0, r);
1459 /* try to cancel with wrong edit handle */
1460 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), 0);
1461 expect(0, r);
1462 ok(IsWindow(edit), "Expected edit control to be valid\n");
1463 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1464 expect(0, r);
1465 ok(!IsWindow(edit), "Expected edit control to be destroyed\n");
1466 /* try to cancel without creating edit */
1467 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), 0);
1468 expect(0, r);
1470 /* try to cancel with wrong (not null) handle */
1471 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1472 ok(IsWindow(edit), "Expected valid handle\n");
1473 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hTree);
1474 expect(0, r);
1475 ok(IsWindow(edit), "Expected edit control to be valid\n");
1476 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1477 expect(0, r);
1479 /* remove selection after starting edit */
1480 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1481 expect(TRUE, r);
1482 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1483 ok(IsWindow(edit), "Expected valid handle\n");
1484 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
1485 expect(TRUE, r);
1486 /* alter text */
1487 strcpy(buffA, "x");
1488 r = SendMessageA(edit, WM_SETTEXT, 0, (LPARAM)buffA);
1489 expect(TRUE, r);
1490 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1491 expect(0, r);
1492 ok(!IsWindow(edit), "Expected edit control to be destroyed\n");
1493 /* check that text is saved */
1494 item.mask = TVIF_TEXT;
1495 item.hItem = hRoot;
1496 item.pszText = buffA;
1497 item.cchTextMax = sizeof(buffA)/sizeof(CHAR);
1498 r = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1499 expect(TRUE, r);
1500 ok(!strcmp("x", buffA), "Expected item text to change\n");
1502 /* try A/W messages */
1503 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1504 ok(IsWindow(edit), "Expected valid handle\n");
1505 ok(IsWindowUnicode(edit), "got ansi window\n");
1506 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1507 expect(0, r);
1508 ok(!IsWindow(edit), "expected invalid handle\n");
1510 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELW, 0, (LPARAM)hRoot);
1511 ok(IsWindow(edit), "Expected valid handle\n");
1512 ok(IsWindowUnicode(edit), "got ansi window\n");
1513 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1514 expect(0, r);
1516 /* alter text during TVM_BEGINLABELEDIT, check that it's preserved */
1517 strcpy(buffA, "<root>");
1519 item.mask = TVIF_TEXT;
1520 item.hItem = hRoot;
1521 item.pszText = buffA;
1522 item.cchTextMax = 0;
1523 r = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1524 expect(TRUE, r);
1526 g_beginedit_alter_text = TRUE;
1527 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1528 ok(IsWindow(edit), "Expected valid handle\n");
1529 g_beginedit_alter_text = FALSE;
1531 GetWindowTextA(edit, buffA, sizeof(buffA)/sizeof(CHAR));
1532 ok(!strcmp(buffA, "<edittextaltered>"), "got string %s\n", buffA);
1534 DestroyWindow(hTree);
1537 static void test_treeview_classinfo(void)
1539 WNDCLASSA cls;
1541 memset(&cls, 0, sizeof(cls));
1542 GetClassInfoA(GetModuleHandleA("comctl32.dll"), WC_TREEVIEWA, &cls);
1543 ok(cls.hbrBackground == NULL, "Expected NULL background brush, got %p\n", cls.hbrBackground);
1544 ok(cls.style == (CS_GLOBALCLASS | CS_DBLCLKS), "Expected got %x\n", cls.style);
1545 expect(0, cls.cbClsExtra);
1548 static void test_get_linecolor(void)
1550 COLORREF clr;
1551 HWND hTree;
1553 hTree = create_treeview_control(0);
1555 /* newly created control has default color */
1556 clr = SendMessageA(hTree, TVM_GETLINECOLOR, 0, 0);
1557 if (clr == 0)
1558 win_skip("TVM_GETLINECOLOR is not supported on comctl32 < 5.80\n");
1559 else
1560 expect(CLR_DEFAULT, clr);
1562 DestroyWindow(hTree);
1565 static void test_get_insertmarkcolor(void)
1567 COLORREF clr;
1568 HWND hTree;
1570 hTree = create_treeview_control(0);
1572 /* newly created control has default color */
1573 clr = SendMessageA(hTree, TVM_GETINSERTMARKCOLOR, 0, 0);
1574 if (clr == 0)
1575 win_skip("TVM_GETINSERTMARKCOLOR is not supported on comctl32 < 5.80\n");
1576 else
1577 expect(CLR_DEFAULT, clr);
1579 DestroyWindow(hTree);
1582 static void test_expandnotify(void)
1584 HTREEITEM hitem;
1585 HWND hTree;
1586 BOOL ret;
1587 TVITEMA item;
1589 hTree = create_treeview_control(0);
1590 fill_tree(hTree);
1592 item.hItem = hRoot;
1593 item.mask = TVIF_STATE;
1595 item.state = TVIS_EXPANDED;
1596 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1597 expect(TRUE, ret);
1598 ok((item.state & TVIS_EXPANDED) == 0, "expected collapsed\n");
1600 /* preselect root node here */
1601 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1602 expect(TRUE, ret);
1604 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1605 ret = SendMessageA(hTree, TVM_EXPAND, TVE_COLLAPSE, (LPARAM)hRoot);
1606 expect(FALSE, ret);
1607 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "no collapse notifications", FALSE);
1609 g_get_from_expand = TRUE;
1610 /* expand */
1611 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1612 g_item_expanding.state = 0xdeadbeef;
1613 g_item_expanded.state = 0xdeadbeef;
1614 ret = SendMessageA(hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hRoot);
1615 expect(TRUE, ret);
1616 ok(g_item_expanding.state == TVIS_SELECTED, "got state on TVN_ITEMEXPANDING 0x%08x\n",
1617 g_item_expanding.state);
1618 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDED), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1619 g_item_expanded.state);
1620 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_seq, "expand notifications", FALSE);
1621 g_get_from_expand = FALSE;
1623 /* check that it's expanded */
1624 item.state = TVIS_EXPANDED;
1625 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1626 expect(TRUE, ret);
1627 ok((item.state & TVIS_EXPANDED) == TVIS_EXPANDED, "expected expanded\n");
1629 /* collapse */
1630 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1631 ret = SendMessageA(hTree, TVM_EXPAND, TVE_COLLAPSE, (LPARAM)hRoot);
1632 expect(TRUE, ret);
1633 item.state = TVIS_EXPANDED;
1634 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1635 expect(TRUE, ret);
1636 ok((item.state & TVIS_EXPANDED) == 0, "expected collapsed\n");
1637 /* all further collapse/expand attempts won't produce any notifications,
1638 the only way is to reset with all children removed */
1639 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "collapse after expand notifications", FALSE);
1641 /* try to toggle child that doesn't have children itself */
1642 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1643 ret = SendMessageA(hTree, TVM_EXPAND, TVE_TOGGLE, (LPARAM)hChild);
1644 expect(FALSE, ret);
1645 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "toggle node without children", FALSE);
1647 DestroyWindow(hTree);
1649 /* test TVM_GETITEMRECT inside TVN_ITEMEXPANDED notification */
1650 hTree = create_treeview_control(0);
1651 fill_tree(hTree);
1652 g_get_rect_in_expand = TRUE;
1653 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
1654 expect(TRUE, ret);
1655 g_get_rect_in_expand = FALSE;
1657 DestroyWindow(hTree);
1659 /* TVE_TOGGLE acts as any other TVM_EXPAND */
1660 hTree = create_treeview_control(0);
1661 fill_tree(hTree);
1663 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1664 ret = SendMessageA(hTree, TVM_EXPAND, TVE_TOGGLE, (LPARAM)hRoot);
1665 expect(TRUE, ret);
1666 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_seq, "toggle node (expand)", FALSE);
1668 /* toggle again - no notifications */
1669 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1670 ret = SendMessageA(hTree, TVM_EXPAND, TVE_TOGGLE, (LPARAM)hRoot);
1671 expect(TRUE, ret);
1672 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "toggle node (collapse)", FALSE);
1674 DestroyWindow(hTree);
1676 /* some keyboard events are also translated to expand */
1677 hTree = create_treeview_control(0);
1678 fill_tree(hTree);
1680 /* preselect root node here */
1681 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1682 expect(TRUE, ret);
1684 g_get_from_expand = TRUE;
1685 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1686 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1687 expect(FALSE, ret);
1688 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "expand node", FALSE);
1689 ok(g_item_expanding.state == TVIS_SELECTED, "got state on TVN_ITEMEXPANDING 0x%08x\n",
1690 g_item_expanding.state);
1691 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDED), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1692 g_item_expanded.state);
1694 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1695 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1696 expect(FALSE, ret);
1697 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "expand node again", FALSE);
1698 ok(g_item_expanding.state == (TVIS_SELECTED|TVIS_EXPANDED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDING 0x%08x\n",
1699 g_item_expanding.state);
1700 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1701 g_item_expanded.state);
1703 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1704 ret = SendMessageA(hTree, WM_KEYDOWN, VK_SUBTRACT, 0);
1705 expect(FALSE, ret);
1706 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "collapse node", FALSE);
1707 ok(g_item_expanding.state == (TVIS_SELECTED|TVIS_EXPANDED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDING 0x%08x\n",
1708 g_item_expanding.state);
1709 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1710 g_item_expanded.state);
1712 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1713 ret = SendMessageA(hTree, WM_KEYDOWN, VK_SUBTRACT, 0);
1714 expect(FALSE, ret);
1715 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_collapse_2nd_kb_seq, "collapse node again", FALSE);
1716 ok(g_item_expanding.state == (TVIS_SELECTED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDING 0x%08x\n",
1717 g_item_expanding.state);
1718 g_get_from_expand = FALSE;
1720 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1721 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1722 expect(FALSE, ret);
1723 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "expand node", FALSE);
1725 /* go to child */
1726 ret = SendMessageA(hTree, WM_KEYDOWN, VK_RIGHT, 0);
1727 expect(FALSE, ret);
1729 /* try to expand child that doesn't have children itself */
1730 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1731 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1732 expect(FALSE, ret);
1733 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_empty_kb_seq, "expand node with no children", FALSE);
1735 /* stay on current selection and set non-zero children count */
1736 hitem = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CARET, 0);
1737 ok(hitem != NULL, "got %p\n", hitem);
1739 item.hItem = hitem;
1740 item.mask = TVIF_CHILDREN;
1741 item.cChildren = 0x80000000;
1743 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1744 expect(TRUE, ret);
1746 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1747 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1748 expect(FALSE, ret);
1749 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_collapse_2nd_kb_seq, "expand node with children", FALSE);
1751 DestroyWindow(hTree);
1754 static void test_expandedimage(void)
1756 TVITEMEXA item;
1757 HWND hTree;
1758 BOOL ret;
1760 hTree = create_treeview_control(0);
1761 fill_tree(hTree);
1763 item.mask = TVIF_EXPANDEDIMAGE;
1764 item.iExpandedImage = 1;
1765 item.hItem = hRoot;
1766 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1767 ok(ret, "got %d\n", ret);
1769 item.mask = TVIF_EXPANDEDIMAGE;
1770 item.iExpandedImage = -1;
1771 item.hItem = hRoot;
1772 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1773 ok(ret, "got %d\n", ret);
1775 if (item.iExpandedImage != 1)
1777 win_skip("TVIF_EXPANDEDIMAGE not supported\n");
1778 DestroyWindow(hTree);
1779 return;
1782 /* test for default iExpandedImage value */
1783 item.mask = TVIF_EXPANDEDIMAGE;
1784 item.iExpandedImage = -1;
1785 item.hItem = hChild;
1786 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1787 ok(ret, "got %d\n", ret);
1788 ok(item.iExpandedImage == (WORD)I_IMAGENONE, "got %d\n", item.iExpandedImage);
1790 DestroyWindow(hTree);
1793 static void test_TVS_SINGLEEXPAND(void)
1795 HWND hTree;
1796 HTREEITEM alpha, bravo, charlie, delta, echo, foxtrot, golf, hotel, india, juliet;
1797 TVINSERTSTRUCTA ins;
1798 char foo[] = "foo";
1799 char context[32];
1800 int i;
1801 BOOL ret;
1803 /* build a fairly complex tree
1804 * - TVI_ROOT
1805 * - alpha
1806 * - bravo
1807 * - charlie
1808 * - delta
1809 * - echo
1810 * - foxtrot
1811 * - golf
1812 * - hotel
1813 * - india
1814 * - juliet
1816 struct
1818 HTREEITEM *handle;
1819 HTREEITEM *parent;
1820 UINT final_state;
1822 items[] =
1824 { &alpha, NULL, TVIS_EXPANDEDONCE },
1825 { &bravo, &alpha, TVIS_EXPANDEDONCE },
1826 { &charlie, &bravo, 0 },
1827 { &delta, &alpha, TVIS_EXPANDEDONCE },
1828 { &echo, &delta, 0 },
1829 { &foxtrot, NULL, TVIS_EXPANDEDONCE|TVIS_EXPANDED },
1830 { &golf, &foxtrot, TVIS_EXPANDEDONCE|TVIS_EXPANDED },
1831 { &hotel, &golf, 0 },
1832 { &india, &golf, TVIS_SELECTED },
1833 { &juliet, &foxtrot, 0 }
1836 struct
1838 HTREEITEM *select;
1839 const struct message *sequence;
1841 sequence_tests[] =
1843 { &alpha, parent_singleexpand_seq0 },
1844 { &bravo, parent_singleexpand_seq1 },
1845 { &delta, parent_singleexpand_seq2 },
1846 { &foxtrot, parent_singleexpand_seq3 },
1847 { &alpha, parent_singleexpand_seq4 },
1848 { &golf, parent_singleexpand_seq5 },
1849 { &hotel, parent_singleexpand_seq6 },
1850 { &india, parent_singleexpand_seq7 },
1851 { &india, empty_seq }
1854 hTree = create_treeview_control(0);
1855 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_SINGLEEXPAND);
1856 /* to avoid painting related notifications */
1857 ShowWindow(hTree, SW_HIDE);
1858 for (i = 0; i < sizeof(items)/sizeof(items[0]); i++)
1860 ins.hParent = items[i].parent ? *items[i].parent : TVI_ROOT;
1861 ins.hInsertAfter = TVI_FIRST;
1862 U(ins).item.mask = TVIF_TEXT;
1863 U(ins).item.pszText = foo;
1864 *items[i].handle = TreeView_InsertItemA(hTree, &ins);
1867 for (i = 0; i < sizeof(sequence_tests)/sizeof(sequence_tests[0]); i++)
1869 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1870 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)(*sequence_tests[i].select));
1871 ok(ret, "got %d\n", ret);
1872 sprintf(context, "singleexpand notifications %d", i);
1873 ok_sequence(sequences, PARENT_SEQ_INDEX, sequence_tests[i].sequence, context, FALSE);
1876 for (i = 0; i < sizeof(items)/sizeof(items[0]); i++)
1878 ret = SendMessageA(hTree, TVM_GETITEMSTATE, (WPARAM)(*items[i].handle), 0xFFFF);
1879 ok(ret == items[i].final_state, "singleexpand items[%d]: expected state 0x%x got 0x%x\n",
1880 i, items[i].final_state, ret);
1883 /* a workaround for NT4 that sends expand notifications when nothing is about to expand */
1884 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
1885 ok(ret, "got %d\n", ret);
1886 fill_tree(hTree);
1887 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
1888 ok(ret, "got %d\n", ret);
1890 DestroyWindow(hTree);
1893 static void test_WM_PAINT(void)
1895 HWND hTree;
1896 COLORREF clr;
1897 LONG ret;
1898 RECT rc;
1899 HDC hdc;
1901 hTree = create_treeview_control(0);
1903 clr = SendMessageA(hTree, TVM_SETBKCOLOR, 0, RGB(255, 0, 0));
1904 ok(clr == ~0u, "got %d, expected -1\n", clr);
1906 hdc = GetDC(hMainWnd);
1908 GetClientRect(hMainWnd, &rc);
1909 FillRect(hdc, &rc, GetStockObject(BLACK_BRUSH));
1911 clr = GetPixel(hdc, 1, 1);
1912 ok(clr == RGB(0, 0, 0), "got 0x%x\n", clr);
1914 ret = SendMessageA(hTree, WM_PAINT, (WPARAM)hdc, 0);
1915 ok(ret == 0, "got %d\n", ret);
1917 clr = GetPixel(hdc, 1, 1);
1918 ok(clr == RGB(255, 0, 0) || broken(clr == RGB(0, 0, 0)) /* win98 */,
1919 "got 0x%x\n", clr);
1921 ReleaseDC(hMainWnd, hdc);
1923 DestroyWindow(hTree);
1926 static void test_delete_items(void)
1928 const struct message *msg;
1929 HWND hTree;
1930 HTREEITEM hItem1, hItem2;
1931 TVINSERTSTRUCTA ins;
1932 INT ret;
1934 static CHAR item1[] = "Item 1";
1935 static CHAR item2[] = "Item 2";
1937 hTree = create_treeview_control(0);
1938 fill_tree(hTree);
1940 /* check delete order */
1941 flush_sequences(item_sequence, 1);
1942 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, 0);
1943 ok(ret == TRUE, "got %d\n", ret);
1945 msg = item_sequence[0]->sequence;
1946 ok(item_sequence[0]->count == 2, "expected 2 items, got %d\n", item_sequence[0]->count);
1948 if (item_sequence[0]->count == 2)
1950 ok(msg[0].lParam == (LPARAM)hChild, "expected %p, got 0x%lx\n", hChild, msg[0].lParam);
1951 ok(msg[1].lParam == (LPARAM)hRoot, "expected %p, got 0x%lx\n", hRoot, msg[1].lParam);
1954 ret = SendMessageA(hTree, TVM_GETCOUNT, 0, 0);
1955 ok(ret == 0, "got %d\n", ret);
1957 DestroyWindow(hTree);
1959 /* Regression test for a crash when deleting the first visible item while bRedraw == false. */
1960 hTree = create_treeview_control(0);
1962 ret = SendMessageA(hTree, WM_SETREDRAW, FALSE, 0);
1963 ok(ret == 0, "got %d\n", ret);
1965 ins.hParent = TVI_ROOT;
1966 ins.hInsertAfter = TVI_ROOT;
1967 U(ins).item.mask = TVIF_TEXT;
1968 U(ins).item.pszText = item1;
1969 hItem1 = TreeView_InsertItemA(hTree, &ins);
1970 ok(hItem1 != NULL, "InsertItem failed\n");
1972 ins.hParent = TVI_ROOT;
1973 ins.hInsertAfter = hItem1;
1974 U(ins).item.mask = TVIF_TEXT;
1975 U(ins).item.pszText = item2;
1976 hItem2 = TreeView_InsertItemA(hTree, &ins);
1977 ok(hItem2 != NULL, "InsertItem failed\n");
1979 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hItem1);
1980 ok(ret == TRUE, "got %d\n", ret);
1982 ret = SendMessageA(hTree, WM_SETREDRAW, TRUE, 0);
1983 ok(ret == 0, "got %d\n", ret);
1985 DestroyWindow(hTree);
1988 static void test_cchildren(void)
1990 HWND hTree;
1991 INT ret;
1992 TVITEMA item;
1994 hTree = create_treeview_control(0);
1995 fill_tree(hTree);
1997 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild);
1998 expect(TRUE, ret);
2000 /* check cChildren - automatic mode */
2001 item.hItem = hRoot;
2002 item.mask = TVIF_CHILDREN;
2004 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2005 expect(TRUE, ret);
2006 expect(0, item.cChildren);
2008 DestroyWindow(hTree);
2010 /* start over */
2011 hTree = create_treeview_control(0);
2012 fill_tree(hTree);
2014 /* turn off automatic mode by setting cChildren explicitly */
2015 item.hItem = hRoot;
2016 item.mask = TVIF_CHILDREN;
2018 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2019 expect(TRUE, ret);
2020 expect(1, item.cChildren);
2022 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
2023 expect(TRUE, ret);
2025 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild);
2026 expect(TRUE, ret);
2028 /* check cChildren */
2029 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2030 expect(TRUE, ret);
2031 todo_wine
2032 expect(1, item.cChildren);
2034 DestroyWindow(hTree);
2037 struct _ITEM_DATA
2039 HTREEITEM parent; /* for root value of parent field is unidetified */
2040 HTREEITEM nextsibling;
2041 HTREEITEM firstchild;
2044 static void _check_item(HTREEITEM item, HTREEITEM parent, HTREEITEM nextsibling, HTREEITEM firstchild, int line)
2046 struct _ITEM_DATA *data = (struct _ITEM_DATA*)item;
2048 ok_(__FILE__, line)(data->parent == parent, "parent %p, got %p\n", parent, data->parent);
2049 ok_(__FILE__, line)(data->nextsibling == nextsibling, "sibling %p, got %p\n", nextsibling, data->nextsibling);
2050 ok_(__FILE__, line)(data->firstchild == firstchild, "firstchild %p, got %p\n", firstchild, data->firstchild);
2053 #define check_item(a, b, c, d) _check_item(a, b, c, d, __LINE__)
2055 static void test_htreeitem_layout(void)
2057 TVINSERTSTRUCTA ins;
2058 HTREEITEM item1, item2;
2059 HWND hTree;
2061 hTree = create_treeview_control(0);
2062 fill_tree(hTree);
2064 /* root has some special pointer in parent field */
2065 check_item(hRoot, ((struct _ITEM_DATA*)hRoot)->parent, 0, hChild);
2066 check_item(hChild, hRoot, 0, 0);
2068 ins.hParent = hChild;
2069 ins.hInsertAfter = TVI_FIRST;
2070 U(ins).item.mask = 0;
2071 item1 = TreeView_InsertItemA(hTree, &ins);
2073 check_item(item1, hChild, 0, 0);
2075 ins.hParent = hRoot;
2076 ins.hInsertAfter = TVI_FIRST;
2077 U(ins).item.mask = 0;
2078 item2 = TreeView_InsertItemA(hTree, &ins);
2080 check_item(item2, hRoot, hChild, 0);
2082 SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild);
2084 /* without children now */
2085 check_item(hRoot, ((struct _ITEM_DATA*)hRoot)->parent, 0, item2);
2087 DestroyWindow(hTree);
2090 static void test_TVS_CHECKBOXES(void)
2092 HIMAGELIST himl, himl2;
2093 HWND hTree, hTree2;
2094 TVITEMA item;
2095 DWORD ret;
2096 MSG msg;
2098 hTree = create_treeview_control(0);
2099 fill_tree(hTree);
2101 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
2102 ok(himl == NULL, "got %p\n", himl);
2104 item.hItem = hRoot;
2105 item.mask = TVIF_STATE;
2106 item.state = INDEXTOSTATEIMAGEMASK(1);
2107 item.stateMask = TVIS_STATEIMAGEMASK;
2108 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2109 expect(TRUE, ret);
2110 ok(item.state == 0, "got 0x%x\n", item.state);
2112 /* set some index for a child */
2113 item.hItem = hChild;
2114 item.mask = TVIF_STATE;
2115 item.state = INDEXTOSTATEIMAGEMASK(4);
2116 item.stateMask = TVIS_STATEIMAGEMASK;
2117 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
2118 expect(TRUE, ret);
2120 /* enabling check boxes set all items to 1 state image index */
2121 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
2122 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
2123 ok(himl != NULL, "got %p\n", himl);
2125 himl2 = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
2126 ok(himl2 != NULL, "got %p\n", himl2);
2127 ok(himl2 == himl, "got %p, expected %p\n", himl2, himl);
2129 item.hItem = hRoot;
2130 item.mask = TVIF_STATE;
2131 item.state = 0;
2132 item.stateMask = TVIS_STATEIMAGEMASK;
2133 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2134 expect(TRUE, ret);
2135 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
2137 item.hItem = hChild;
2138 item.mask = TVIF_STATE;
2139 item.state = 0;
2140 item.stateMask = TVIS_STATEIMAGEMASK;
2141 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2142 expect(TRUE, ret);
2143 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
2145 /* create another control and check its checkbox list */
2146 hTree2 = create_treeview_control(0);
2147 fill_tree(hTree2);
2149 /* set some index for a child */
2150 item.hItem = hChild;
2151 item.mask = TVIF_STATE;
2152 item.state = INDEXTOSTATEIMAGEMASK(4);
2153 item.stateMask = TVIS_STATEIMAGEMASK;
2154 ret = SendMessageA(hTree2, TVM_SETITEMA, 0, (LPARAM)&item);
2155 expect(TRUE, ret);
2157 /* enabling check boxes set all items to 1 state image index */
2158 SetWindowLongA(hTree2, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
2159 himl2 = (HIMAGELIST)SendMessageA(hTree2, TVM_GETIMAGELIST, TVSIL_STATE, 0);
2160 ok(himl2 != NULL, "got %p\n", himl2);
2161 ok(himl != himl2, "got %p, expected %p\n", himl2, himl);
2163 DestroyWindow(hTree2);
2164 DestroyWindow(hTree);
2166 /* the same, but initially created with TVS_CHECKBOXES */
2167 hTree = create_treeview_control(TVS_CHECKBOXES);
2168 fill_tree(hTree);
2169 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
2170 ok(himl == NULL, "got %p\n", himl);
2172 item.hItem = hRoot;
2173 item.mask = TVIF_STATE;
2174 item.state = 0;
2175 item.stateMask = TVIS_STATEIMAGEMASK;
2176 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2177 expect(TRUE, ret);
2178 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
2180 item.hItem = hChild;
2181 item.mask = TVIF_STATE;
2182 item.state = 0;
2183 item.stateMask = TVIS_STATEIMAGEMASK;
2184 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2185 expect(TRUE, ret);
2186 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
2188 item.hItem = hChild;
2189 item.mask = TVIF_STATE;
2190 item.state = INDEXTOSTATEIMAGEMASK(2);
2191 item.stateMask = TVIS_STATEIMAGEMASK;
2192 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
2193 expect(TRUE, ret);
2195 item.hItem = hChild;
2196 item.mask = TVIF_STATE;
2197 item.state = 0;
2198 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2199 expect(TRUE, ret);
2200 ok(item.state == INDEXTOSTATEIMAGEMASK(2), "got 0x%x\n", item.state);
2202 while(GetMessageA(&msg, 0, 0, 0))
2204 TranslateMessage(&msg);
2205 DispatchMessageA(&msg);
2207 if((msg.hwnd == hTree) && (msg.message == WM_PAINT))
2208 break;
2211 item.hItem = hChild;
2212 item.mask = TVIF_STATE;
2213 item.state = 0;
2214 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2215 expect(TRUE, ret);
2216 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
2218 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
2219 ok(himl != NULL, "got %p\n", himl);
2221 DestroyWindow(hTree);
2223 /* check what happens if TVSIL_STATE image list is removed */
2224 hTree = create_treeview_control(0);
2225 fill_tree(hTree);
2226 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
2227 ok(himl == NULL, "got %p\n", himl);
2229 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
2230 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
2231 ok(himl != NULL, "got %p\n", himl);
2233 himl2 = (HIMAGELIST)SendMessageA(hTree, TVM_SETIMAGELIST, TVSIL_STATE, 0);
2234 ok(himl2 == himl, "got %p\n", himl2);
2236 himl2 = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
2237 ok(himl2 == NULL, "got %p\n", himl2);
2239 item.hItem = hChild;
2240 item.mask = TVIF_STATE;
2241 item.state = INDEXTOSTATEIMAGEMASK(2);
2242 item.stateMask = TVIS_STATEIMAGEMASK;
2243 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
2244 expect(TRUE, ret);
2246 item.hItem = hChild;
2247 item.mask = TVIF_STATE;
2248 item.state = 0;
2249 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2250 expect(TRUE, ret);
2251 ok(item.state == INDEXTOSTATEIMAGEMASK(2), "got 0x%x\n", item.state);
2253 while(GetMessageA(&msg, 0, 0, 0))
2255 TranslateMessage(&msg);
2256 DispatchMessageA(&msg);
2258 if((msg.hwnd == hTree) && (msg.message == WM_PAINT))
2259 break;
2262 item.hItem = hChild;
2263 item.mask = TVIF_STATE;
2264 item.state = 0;
2265 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
2266 expect(TRUE, ret);
2267 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
2269 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
2270 ok(himl != NULL, "got %p\n", himl);
2272 DestroyWindow(hTree);
2275 static void test_TVM_GETNEXTITEM(void)
2277 HTREEITEM item;
2278 HWND hTree;
2280 hTree = create_treeview_control(0);
2281 fill_tree(hTree);
2283 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, 0);
2284 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
2286 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, (LPARAM)TVI_ROOT);
2287 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
2289 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, (LPARAM)hRoot);
2290 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
2292 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, (LPARAM)hChild);
2293 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
2295 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CHILD, 0);
2296 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
2298 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hRoot);
2299 ok(item == hChild, "got %p, expected %p\n", item, hChild);
2301 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)TVI_ROOT);
2302 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
2304 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_PARENT, 0);
2305 ok(item == NULL, "got %p\n", item);
2307 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hChild);
2308 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
2310 DestroyWindow(hTree);
2313 static void test_TVM_HITTEST(void)
2315 HWND hTree;
2316 LRESULT ret;
2317 RECT rc;
2318 TVHITTESTINFO ht;
2320 hTree = create_treeview_control(0);
2321 fill_tree(hTree);
2323 *(HTREEITEM*)&rc = hRoot;
2324 ret = SendMessageA(hTree, TVM_GETITEMRECT, TRUE, (LPARAM)&rc);
2325 expect(TRUE, (BOOL)ret);
2327 ht.pt.x = rc.left-1;
2328 ht.pt.y = rc.top;
2330 ret = SendMessageA(hTree, TVM_HITTEST, 0, (LPARAM)&ht);
2331 ok((HTREEITEM)ret == hRoot, "got %p, expected %p\n", (HTREEITEM)ret, hRoot);
2332 ok(ht.hItem == hRoot, "got %p, expected %p\n", ht.hItem, hRoot);
2333 ok(ht.flags == TVHT_ONITEMBUTTON, "got %d, expected %d\n", ht.flags, TVHT_ONITEMBUTTON);
2335 ret = SendMessageA(hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hRoot);
2336 expect(TRUE, (BOOL)ret);
2338 *(HTREEITEM*)&rc = hChild;
2339 ret = SendMessageA(hTree, TVM_GETITEMRECT, TRUE, (LPARAM)&rc);
2340 expect(TRUE, (BOOL)ret);
2342 ht.pt.x = rc.left-1;
2343 ht.pt.y = rc.top;
2345 ret = SendMessageA(hTree, TVM_HITTEST, 0, (LPARAM)&ht);
2346 ok((HTREEITEM)ret == hChild, "got %p, expected %p\n", (HTREEITEM)ret, hChild);
2347 ok(ht.hItem == hChild, "got %p, expected %p\n", ht.hItem, hChild);
2348 /* Wine returns item button here, but this item has no button */
2349 todo_wine ok(ht.flags == TVHT_ONITEMINDENT, "got %d, expected %d\n", ht.flags, TVHT_ONITEMINDENT);
2351 DestroyWindow(hTree);
2354 static void test_WM_GETDLGCODE(void)
2356 DWORD code;
2357 HWND hTree;
2359 hTree = create_treeview_control(0);
2361 code = SendMessageA(hTree, WM_GETDLGCODE, VK_TAB, 0);
2362 ok(code == (DLGC_WANTCHARS | DLGC_WANTARROWS), "0x%08x\n", code);
2364 DestroyWindow(hTree);
2367 static void test_customdraw(void)
2369 LOGFONTA lf;
2370 HWND hwnd;
2372 hwnd = create_treeview_control(0);
2373 fill_tree(hwnd);
2374 SendMessageA(hwnd, TVM_EXPAND, TVE_EXPAND, (WPARAM)hRoot);
2376 /* create additional font, custom draw handler will select it */
2377 SystemParametersInfoA(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
2378 lf.lfHeight *= 2;
2379 g_customdraw_font = CreateFontIndirectA(&lf);
2380 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2381 InvalidateRect(hwnd, NULL, TRUE);
2382 UpdateWindow(hwnd);
2383 ok_sequence(sequences, PARENT_CD_SEQ_INDEX, parent_cd_seq, "custom draw notifications", FALSE);
2384 DeleteObject(g_customdraw_font);
2385 g_customdraw_font = NULL;
2387 DestroyWindow(hwnd);
2390 static void test_WM_KEYDOWN(void)
2392 static const char *rootA = "root";
2393 TVINSERTSTRUCTA ins;
2394 HTREEITEM hRoot;
2395 HWND hwnd;
2397 hwnd = create_treeview_control(0);
2399 ins.hParent = TVI_ROOT;
2400 ins.hInsertAfter = TVI_ROOT;
2401 U(ins).item.mask = TVIF_TEXT;
2402 U(ins).item.pszText = (char*)rootA;
2403 hRoot = TreeView_InsertItemA(hwnd, &ins);
2404 ok(hRoot != NULL, "got %p\n", hRoot);
2406 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2407 SendMessageA(hwnd, WM_KEYDOWN, VK_RETURN, 0);
2408 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_vk_return_seq, "WM_KEYDOWN/VK_RETURN parent notification", TRUE);
2410 DestroyWindow(hwnd);
2413 static void test_TVS_FULLROWSELECT(void)
2415 DWORD style;
2416 HWND hwnd;
2418 /* try to create both with TVS_HASLINES and TVS_FULLROWSELECT */
2419 hwnd = create_treeview_control(TVS_FULLROWSELECT);
2421 style = GetWindowLongA(hwnd, GWL_STYLE);
2422 ok((style & (TVS_FULLROWSELECT | TVS_HASLINES)) == (TVS_FULLROWSELECT | TVS_HASLINES), "got style 0x%08x\n", style);
2424 DestroyWindow(hwnd);
2426 /* create just with TVS_HASLINES, try to enable TVS_FULLROWSELECT later */
2427 hwnd = create_treeview_control(0);
2429 style = GetWindowLongA(hwnd, GWL_STYLE);
2430 SetWindowLongA(hwnd, GWL_STYLE, style | TVS_FULLROWSELECT);
2431 style = GetWindowLongA(hwnd, GWL_STYLE);
2432 ok(style & TVS_FULLROWSELECT, "got style 0x%08x\n", style);
2434 DestroyWindow(hwnd);
2437 static void get_item_names_string(HWND hwnd, HTREEITEM item, char *str)
2439 TVITEMA tvitem = { 0 };
2440 HTREEITEM child;
2441 char name[16];
2443 if (!item)
2445 item = (HTREEITEM)SendMessageA(hwnd, TVM_GETNEXTITEM, TVGN_ROOT, 0);
2446 str[0] = 0;
2449 child = (HTREEITEM)SendMessageA(hwnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)item);
2451 tvitem.mask = TVIF_TEXT;
2452 tvitem.hItem = item;
2453 tvitem.pszText = name;
2454 tvitem.cchTextMax = sizeof(name);
2455 SendMessageA(hwnd, TVM_GETITEMA, 0, (LPARAM)&tvitem);
2456 strcat(str, tvitem.pszText);
2458 while (child != NULL)
2460 get_item_names_string(hwnd, child, str);
2461 child = (HTREEITEM)SendMessageA(hwnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)child);
2465 static void fill_treeview_sort_test(HWND hwnd)
2467 static const char *itemnames[] =
2469 "root", "Wasp", "Caribou", "Vacuum",
2470 "Ocelot", "Newspaper", "Litter bin"
2473 HTREEITEM root, children[2];
2474 TVINSERTSTRUCTA ins;
2475 unsigned i = 0;
2477 SendMessageA(hwnd, TVM_DELETEITEM, 0, 0);
2479 /* root, two children, with two children each */
2480 ins.hParent = TVI_ROOT;
2481 ins.hInsertAfter = TVI_ROOT;
2482 U(ins).item.mask = TVIF_TEXT;
2483 U(ins).item.pszText = (char *)itemnames[i++];
2484 root = (HTREEITEM)SendMessageA(hwnd, TVM_INSERTITEMA, 0, (LPARAM)&ins);
2486 ins.hParent = root;
2487 ins.hInsertAfter = TVI_LAST;
2488 U(ins).item.mask = TVIF_TEXT;
2489 U(ins).item.pszText = (char *)itemnames[i++];
2490 children[0] = (HTREEITEM)SendMessageA(hwnd, TVM_INSERTITEMA, 0, (LPARAM)&ins);
2492 U(ins).item.pszText = (char *)itemnames[i++];
2493 children[1] = (HTREEITEM)SendMessageA(hwnd, TVM_INSERTITEMA, 0, (LPARAM)&ins);
2495 ins.hParent = children[0];
2496 U(ins).item.pszText = (char *)itemnames[i++];
2497 SendMessageA(hwnd, TVM_INSERTITEMA, 0, (LPARAM)&ins);
2499 U(ins).item.pszText = (char *)itemnames[i++];
2500 SendMessageA(hwnd, TVM_INSERTITEMA, 0, (LPARAM)&ins);
2502 ins.hParent = children[1];
2503 U(ins).item.pszText = (char *)itemnames[i++];
2504 SendMessageA(hwnd, TVM_INSERTITEMA, 0, (LPARAM)&ins);
2506 U(ins).item.pszText = (char *)itemnames[i++];
2507 SendMessageA(hwnd, TVM_INSERTITEMA, 0, (LPARAM)&ins);
2510 static void test_TVM_SORTCHILDREN(void)
2512 static const char *initial_order = "rootWaspVacuumOcelotCaribouNewspaperLitter bin";
2513 static const char *sorted_order = "rootCaribouNewspaperLitter binWaspVacuumOcelot";
2514 TVINSERTSTRUCTA ins;
2515 char buff[256];
2516 HTREEITEM root;
2517 HWND hwnd;
2518 BOOL ret;
2520 hwnd = create_treeview_control(0);
2522 /* call on empty tree */
2523 ret = SendMessageA(hwnd, TVM_SORTCHILDREN, 0, 0);
2524 ok(!ret, "Unexpected ret value %d\n", ret);
2526 ret = SendMessageA(hwnd, TVM_SORTCHILDREN, 0, (LPARAM)TVI_ROOT);
2527 ok(!ret, "Unexpected ret value %d\n", ret);
2529 /* add only root, sort from it */
2530 ins.hParent = TVI_ROOT;
2531 ins.hInsertAfter = TVI_ROOT;
2532 U(ins).item.mask = TVIF_TEXT;
2533 U(ins).item.pszText = (char *)"root";
2534 root = (HTREEITEM)SendMessageA(hwnd, TVM_INSERTITEMA, 0, (LPARAM)&ins);
2535 ok(root != NULL, "Expected root node\n");
2537 ret = SendMessageA(hwnd, TVM_SORTCHILDREN, 0, (LPARAM)root);
2538 ok(!ret, "Unexpected ret value %d\n", ret);
2540 ret = SendMessageA(hwnd, TVM_SORTCHILDREN, TRUE, (LPARAM)root);
2541 ok(!ret, "Unexpected ret value %d\n", ret);
2543 /* root, two children, with two children each */
2544 fill_treeview_sort_test(hwnd);
2545 get_item_names_string(hwnd, NULL, buff);
2546 ok(!strcmp(buff, initial_order), "Wrong initial order %s, expected %s\n", buff, initial_order);
2548 /* with NULL item nothing is sorted */
2549 fill_treeview_sort_test(hwnd);
2550 ret = SendMessageA(hwnd, TVM_SORTCHILDREN, 0, 0);
2551 todo_wine
2552 ok(ret, "Unexpected ret value %d\n", ret);
2553 get_item_names_string(hwnd, NULL, buff);
2554 ok(!strcmp(buff, initial_order), "Wrong sorted order %s, expected %s\n", buff, initial_order);
2556 /* TVI_ROOT as item */
2557 fill_treeview_sort_test(hwnd);
2558 ret = SendMessageA(hwnd, TVM_SORTCHILDREN, 0, (LPARAM)TVI_ROOT);
2559 todo_wine
2560 ok(ret, "Unexpected ret value %d\n", ret);
2561 get_item_names_string(hwnd, NULL, buff);
2562 ok(!strcmp(buff, initial_order), "Wrong sorted order %s, expected %s\n", buff, initial_order);
2564 /* zero WPARAM, item is specified */
2565 fill_treeview_sort_test(hwnd);
2566 root = (HTREEITEM)SendMessageA(hwnd, TVM_GETNEXTITEM, TVGN_ROOT, 0);
2567 ok(root != NULL, "Failed to get root item\n");
2568 ret = SendMessageA(hwnd, TVM_SORTCHILDREN, 0, (LPARAM)root);
2569 ok(ret, "Unexpected ret value %d\n", ret);
2570 get_item_names_string(hwnd, NULL, buff);
2571 ok(!strcmp(buff, sorted_order), "Wrong sorted order %s, expected %s\n", buff, sorted_order);
2573 /* non-zero WPARAM, NULL item */
2574 fill_treeview_sort_test(hwnd);
2575 ret = SendMessageA(hwnd, TVM_SORTCHILDREN, TRUE, 0);
2576 todo_wine
2577 ok(ret, "Unexpected ret value %d\n", ret);
2578 get_item_names_string(hwnd, NULL, buff);
2579 ok(!strcmp(buff, initial_order), "Wrong sorted order %s, expected %s\n", buff, sorted_order);
2581 /* TVI_ROOT as item */
2582 fill_treeview_sort_test(hwnd);
2583 ret = SendMessageA(hwnd, TVM_SORTCHILDREN, TRUE, (LPARAM)TVI_ROOT);
2584 todo_wine
2585 ok(ret, "Unexpected ret value %d\n", ret);
2586 get_item_names_string(hwnd, NULL, buff);
2587 ok(!strcmp(buff, initial_order), "Wrong sorted order %s, expected %s\n", buff, sorted_order);
2589 /* non-zero WPARAM, item is specified */
2590 fill_treeview_sort_test(hwnd);
2591 root = (HTREEITEM)SendMessageA(hwnd, TVM_GETNEXTITEM, TVGN_ROOT, 0);
2592 ok(root != NULL, "Failed to get root item\n");
2593 ret = SendMessageA(hwnd, TVM_SORTCHILDREN, TRUE, (LPARAM)root);
2594 ok(ret, "Unexpected ret value %d\n", ret);
2595 get_item_names_string(hwnd, NULL, buff);
2596 ok(!strcmp(buff, sorted_order), "Wrong sorted order %s, expected %s\n", buff, sorted_order);
2598 /* case insensitive comparison */
2599 SendMessageA(hwnd, TVM_DELETEITEM, 0, 0);
2601 ins.hParent = TVI_ROOT;
2602 ins.hInsertAfter = TVI_ROOT;
2603 U(ins).item.mask = TVIF_TEXT;
2604 U(ins).item.pszText = (char *)"root";
2605 root = (HTREEITEM)SendMessageA(hwnd, TVM_INSERTITEMA, 0, (LPARAM)&ins);
2606 ok(root != NULL, "Expected root node\n");
2608 ins.hParent = root;
2609 ins.hInsertAfter = TVI_LAST;
2610 U(ins).item.pszText = (char *)"I1";
2611 SendMessageA(hwnd, TVM_INSERTITEMA, 0, (LPARAM)&ins);
2613 ins.hParent = root;
2614 ins.hInsertAfter = TVI_LAST;
2615 U(ins).item.pszText = (char *)"i1";
2616 SendMessageA(hwnd, TVM_INSERTITEMA, 0, (LPARAM)&ins);
2618 ret = SendMessageA(hwnd, TVM_SORTCHILDREN, TRUE, (LPARAM)root);
2619 ok(ret, "Unexpected ret value %d\n", ret);
2620 get_item_names_string(hwnd, NULL, buff);
2621 ok(!strcmp(buff, "rootI1i1"), "Wrong sorted order %s\n", buff);
2623 DestroyWindow(hwnd);
2626 static void test_right_click(void)
2628 HWND hTree;
2629 HTREEITEM selected;
2630 RECT rc;
2631 LRESULT result;
2632 POINT pt;
2634 hTree = create_treeview_control(0);
2635 fill_tree(hTree);
2637 SendMessageA(hTree, TVM_ENSUREVISIBLE, 0, (LPARAM)hChild);
2638 SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
2639 selected = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CARET, 0);
2640 ok(selected == hChild, "child item not selected\n");
2642 *(HTREEITEM *)&rc = hRoot;
2643 result = SendMessageA(hTree, TVM_GETITEMRECT, TRUE, (LPARAM)&rc);
2644 ok(result, "TVM_GETITEMRECT failed\n");
2646 flush_events();
2648 pt.x = (rc.left + rc.right) / 2;
2649 pt.y = (rc.top + rc.bottom) / 2;
2650 ClientToScreen(hMainWnd, &pt);
2652 flush_events();
2653 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2655 PostMessageA(hTree, WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(pt.x, pt.y));
2656 PostMessageA(hTree, WM_RBUTTONUP, 0, MAKELPARAM(pt.x, pt.y));
2658 flush_events();
2660 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_right_click_seq, "right click sequence", FALSE);
2661 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_right_click_seq, "parent right click sequence", FALSE);
2663 selected = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CARET, 0);
2664 ok(selected == hChild, "child item should still be selected\n");
2666 DestroyWindow(hTree);
2669 START_TEST(treeview)
2671 HMODULE hComctl32;
2672 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
2673 WNDCLASSA wc;
2674 MSG msg;
2676 ULONG_PTR ctx_cookie;
2677 HANDLE hCtx;
2679 hComctl32 = GetModuleHandleA("comctl32.dll");
2680 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
2681 if (pInitCommonControlsEx)
2683 INITCOMMONCONTROLSEX iccex;
2684 iccex.dwSize = sizeof(iccex);
2685 iccex.dwICC = ICC_TREEVIEW_CLASSES;
2686 pInitCommonControlsEx(&iccex);
2688 else
2689 InitCommonControls();
2691 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
2692 init_msg_sequences(item_sequence, 1);
2694 wc.style = CS_HREDRAW | CS_VREDRAW;
2695 wc.cbClsExtra = 0;
2696 wc.cbWndExtra = 0;
2697 wc.hInstance = GetModuleHandleA(NULL);
2698 wc.hIcon = NULL;
2699 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_IBEAM);
2700 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
2701 wc.lpszMenuName = NULL;
2702 wc.lpszClassName = "MyTestWnd";
2703 wc.lpfnWndProc = parent_wnd_proc;
2704 RegisterClassA(&wc);
2706 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
2707 CW_USEDEFAULT, CW_USEDEFAULT, 130, 105, NULL, NULL, GetModuleHandleA(NULL), 0);
2709 ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n");
2710 if (!hMainWnd) return;
2712 test_fillroot();
2713 test_select();
2714 test_getitemtext();
2715 test_focus();
2716 test_get_set_bkcolor();
2717 test_get_set_imagelist();
2718 test_get_set_indent();
2719 test_get_set_insertmark();
2720 test_get_set_item();
2721 test_get_set_itemheight();
2722 test_get_set_scrolltime();
2723 test_get_set_textcolor();
2724 test_get_linecolor();
2725 test_get_insertmarkcolor();
2726 test_get_set_tooltips();
2727 test_get_set_unicodeformat();
2728 test_callback();
2729 test_expandinvisible();
2730 test_itemedit();
2731 test_treeview_classinfo();
2732 test_expandnotify();
2733 test_TVS_SINGLEEXPAND();
2734 test_WM_PAINT();
2735 test_delete_items();
2736 test_cchildren();
2737 test_htreeitem_layout();
2738 test_TVS_CHECKBOXES();
2739 test_TVM_GETNEXTITEM();
2740 test_TVM_HITTEST();
2741 test_WM_GETDLGCODE();
2742 test_customdraw();
2743 test_WM_KEYDOWN();
2744 test_TVS_FULLROWSELECT();
2745 test_TVM_SORTCHILDREN();
2746 test_right_click();
2748 if (!load_v6_module(&ctx_cookie, &hCtx))
2750 DestroyWindow(hMainWnd);
2751 return;
2754 /* comctl32 version 6 tests start here */
2755 g_v6 = TRUE;
2756 test_expandedimage();
2757 test_htreeitem_layout();
2758 test_WM_GETDLGCODE();
2760 unload_v6_module(ctx_cookie, hCtx);
2762 PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
2763 while(GetMessageA(&msg, 0, 0, 0))
2765 TranslateMessage(&msg);
2766 DispatchMessageA(&msg);