[COMCTL32_WINETEST]
[reactos.git] / rostests / winetests / comctl32 / treeview.c
1 /* Unit tests for treeview.
2 *
3 * Copyright 2005 Krzysztof Foltman
4 * Copyright 2007 Christopher James Peterson
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winnls.h"
28 #include "winreg.h"
29 #include "wine/commctrl.h"
30
31 #include "wine/test.h"
32 #include "v6util.h"
33 #include "msg.h"
34
35 static const char *TEST_CALLBACK_TEXT = "callback_text";
36
37 static TVITEMA g_item_expanding, g_item_expanded;
38 static BOOL g_get_from_expand;
39 static BOOL g_get_rect_in_expand;
40 static BOOL g_disp_A_to_W;
41 static BOOL g_disp_set_stateimage;
42 static BOOL g_beginedit_alter_text;
43
44 #define NUM_MSG_SEQUENCES 2
45 #define TREEVIEW_SEQ_INDEX 0
46 #define PARENT_SEQ_INDEX 1
47
48 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
49
50 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
51 static struct msg_sequence *item_sequence[1];
52
53 static const struct message FillRootSeq[] = {
54 { TVM_INSERTITEMA, sent },
55 { TVM_INSERTITEMA, sent },
56 { 0 }
57 };
58
59 static const struct message rootnone_select_seq[] = {
60 { TVM_SELECTITEM, sent|wparam, 9 },
61 { TVM_SELECTITEM, sent|wparam, 9 },
62 { TVM_SELECTITEM, sent|wparam, 9 },
63 { TVM_SELECTITEM, sent|wparam, 9 },
64 { TVM_SELECTITEM, sent|wparam, 9 },
65 { TVM_SELECTITEM, sent|wparam, 9 },
66 { 0 }
67 };
68
69 static const struct message rootchild_select_seq[] = {
70 { TVM_SELECTITEM, sent|wparam, 9 },
71 { TVM_SELECTITEM, sent|wparam, 9 },
72 { TVM_SELECTITEM, sent|wparam, 9 },
73 { TVM_SELECTITEM, sent|wparam, 9 },
74 { TVM_SELECTITEM, sent|wparam, 9 },
75 { TVM_SELECTITEM, sent|wparam, 9 },
76 { 0 }
77 };
78
79 static const struct message getitemtext_seq[] = {
80 { TVM_INSERTITEMA, sent },
81 { TVM_GETITEMA, sent },
82 { TVM_DELETEITEM, sent },
83 { 0 }
84 };
85
86 static const struct message focus_seq[] = {
87 { TVM_INSERTITEMA, sent },
88 { TVM_INSERTITEMA, sent },
89 { TVM_SELECTITEM, sent|wparam, 9 },
90 /* The following end up out of order in wine */
91 { WM_WINDOWPOSCHANGING, sent|defwinproc },
92 { WM_NCCALCSIZE, sent|wparam|defwinproc, TRUE },
93 { WM_WINDOWPOSCHANGED, sent|defwinproc },
94 { WM_SIZE, sent|defwinproc },
95 { WM_WINDOWPOSCHANGING, sent|defwinproc|optional },
96 { WM_NCCALCSIZE, sent|wparam|defwinproc|optional, TRUE },
97 { WM_WINDOWPOSCHANGED, sent|defwinproc|optional },
98 { WM_SIZE, sent|defwinproc|optional },
99 { WM_PAINT, sent|defwinproc },
100 { WM_NCPAINT, sent|wparam|defwinproc, 1 },
101 { WM_ERASEBKGND, sent|defwinproc },
102 { TVM_EDITLABELA, sent },
103 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_UPDATE) },
104 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_CHANGE) },
105 { WM_PARENTNOTIFY, sent|wparam|defwinproc, MAKEWPARAM(WM_CREATE, 0) },
106 { WM_KILLFOCUS, sent|defwinproc },
107 { WM_PAINT, sent|defwinproc },
108 { WM_IME_SETCONTEXT, sent|defwinproc|optional },
109 { WM_COMMAND, sent|wparam|defwinproc, MAKEWPARAM(0, EN_SETFOCUS) },
110 { WM_ERASEBKGND, sent|defwinproc|optional },
111 { WM_CTLCOLOREDIT, sent|defwinproc|optional },
112 { WM_CTLCOLOREDIT, sent|defwinproc|optional },
113 { 0 }
114 };
115
116 static const struct message test_get_set_bkcolor_seq[] = {
117 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
118 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, 0 },
119 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
120 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, 0x00ffffff },
121 { TVM_GETBKCOLOR, sent|wparam|lparam, 0, 0 },
122 { TVM_SETBKCOLOR, sent|wparam|lparam, 0, -1 },
123 { 0 }
124 };
125
126 static const struct message test_get_set_imagelist_seq[] = {
127 { TVM_SETIMAGELIST, sent|wparam|lparam, 0, 0 },
128 { TVM_GETIMAGELIST, sent|wparam|lparam, 0, 0 },
129 { 0 }
130 };
131
132 static const struct message test_get_set_indent_seq[] = {
133 { TVM_SETINDENT, sent|wparam|lparam, 0, 0 },
134 { TVM_GETINDENT, sent|wparam|lparam, 0, 0 },
135 /* The actual amount to indent is dependent on the system for this message */
136 { TVM_SETINDENT, sent },
137 { TVM_GETINDENT, sent|wparam|lparam, 0, 0 },
138 { 0 }
139 };
140
141 static const struct message test_get_set_insertmarkcolor_seq[] = {
142 { TVM_SETINSERTMARKCOLOR, sent|wparam|lparam, 0, 0 },
143 { TVM_GETINSERTMARKCOLOR, sent|wparam|lparam, 0, 0 },
144 { 0 }
145 };
146
147 static const struct message test_get_set_item_seq[] = {
148 { TVM_GETITEMA, sent },
149 { TVM_SETITEMA, sent },
150 { TVM_GETITEMA, sent },
151 { TVM_SETITEMA, sent },
152 { 0 }
153 };
154
155 static const struct message test_get_set_itemheight_seq[] = {
156 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
157 { TVM_SETITEMHEIGHT, sent|wparam|lparam, -1, 0 },
158 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
159 { TVM_SETITEMHEIGHT, sent|lparam, 0xcccccccc, 0 },
160 { TVM_GETITEMHEIGHT, sent|wparam|lparam|optional, 0, 0 },
161 { TVM_SETITEMHEIGHT, sent|wparam|lparam|optional, 9, 0 },
162 { TVM_GETITEMHEIGHT, sent|wparam|lparam, 0, 0 },
163 { 0 }
164 };
165
166 static const struct message test_get_set_scrolltime_seq[] = {
167 { TVM_SETSCROLLTIME, sent|wparam|lparam, 20, 0 },
168 { TVM_GETSCROLLTIME, sent|wparam|lparam, 0, 0 },
169 { 0 }
170 };
171
172 static const struct message test_get_set_textcolor_seq[] = {
173 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
174 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
175 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
176 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, RGB(255, 255, 255) },
177 { TVM_GETTEXTCOLOR, sent|wparam|lparam, 0, 0 },
178 { TVM_SETTEXTCOLOR, sent|wparam|lparam, 0, CLR_NONE },
179 { 0 }
180 };
181
182 static const struct message test_get_set_tooltips_seq[] = {
183 { WM_KILLFOCUS, sent },
184 { WM_IME_SETCONTEXT, sent|optional },
185 { WM_IME_NOTIFY, sent|optional },
186 { TVM_SETTOOLTIPS, sent|wparam|lparam, 0, 0 },
187 { TVM_GETTOOLTIPS, sent|wparam|lparam, 0, 0 },
188 { 0 }
189 };
190
191 static const struct message test_get_set_unicodeformat_seq[] = {
192 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, TRUE, 0 },
193 { TVM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
194 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
195 { TVM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
196 { TVM_SETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
197 { 0 }
198 };
199
200 static const struct message parent_expand_seq[] = {
201 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
202 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
203 { 0 }
204 };
205
206 static const struct message parent_expand_kb_seq[] = {
207 { WM_NOTIFY, sent|id|optional, 0, 0, TVN_KEYDOWN },
208 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
209 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
210 { WM_CHANGEUISTATE, sent|optional },
211 { 0 }
212 };
213
214 static const struct message parent_collapse_2nd_kb_seq[] = {
215 { WM_NOTIFY, sent|id|optional, 0, 0, TVN_KEYDOWN },
216 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
217 { WM_CHANGEUISTATE, sent|optional },
218 { 0 }
219 };
220
221 static const struct message parent_expand_empty_kb_seq[] = {
222 { WM_NOTIFY, sent|id|optional, 0, 0, TVN_KEYDOWN },
223 { WM_CHANGEUISTATE, sent|optional },
224 { 0 }
225 };
226
227 static const struct message parent_singleexpand_seq[] = {
228 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGINGA },
229 { WM_NOTIFY, sent|id, 0, 0, TVN_SELCHANGEDA },
230 { WM_NOTIFY, sent|id, 0, 0, TVN_SINGLEEXPAND },
231 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDINGA },
232 { WM_NOTIFY, sent|id, 0, 0, TVN_ITEMEXPANDEDA },
233 { 0 }
234 };
235
236 static const struct message parent_get_dispinfo_seq[] = {
237 { WM_NOTIFY, sent|id, 0, 0, TVN_GETDISPINFOA },
238 { 0 }
239 };
240
241 static const struct message empty_seq[] = {
242 { 0 }
243 };
244
245 static HWND hMainWnd;
246
247 static HTREEITEM hRoot, hChild;
248
249 static int pos = 0;
250 static char sequence[256];
251
252 static void Clear(void)
253 {
254 pos = 0;
255 sequence[0] = '\0';
256 }
257
258 static void AddItem(char ch)
259 {
260 sequence[pos++] = ch;
261 sequence[pos] = '\0';
262 }
263
264 static void IdentifyItem(HTREEITEM hItem)
265 {
266 if (hItem == hRoot) {
267 AddItem('R');
268 return;
269 }
270 if (hItem == hChild) {
271 AddItem('C');
272 return;
273 }
274 if (hItem == NULL) {
275 AddItem('n');
276 return;
277 }
278 AddItem('?');
279 }
280
281 /* This function hooks in and records all messages to the treeview control */
282 static LRESULT WINAPI TreeviewWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
283 {
284 static LONG defwndproc_counter = 0;
285 LRESULT ret;
286 struct message msg;
287 WNDPROC lpOldProc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
288
289 msg.message = message;
290 msg.flags = sent|wparam|lparam;
291 if (defwndproc_counter) msg.flags |= defwinproc;
292 msg.wParam = wParam;
293 msg.lParam = lParam;
294 msg.id = 0;
295 add_message(sequences, TREEVIEW_SEQ_INDEX, &msg);
296
297 defwndproc_counter++;
298 ret = CallWindowProcA(lpOldProc, hwnd, message, wParam, lParam);
299 defwndproc_counter--;
300
301 return ret;
302 }
303
304 static HWND create_treeview_control(DWORD style)
305 {
306 WNDPROC pOldWndProc;
307 HWND hTree;
308
309 hTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL, WS_CHILD|WS_VISIBLE|
310 TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS|TVS_EDITLABELS|style,
311 0, 0, 120, 100, hMainWnd, (HMENU)100, GetModuleHandleA(0), 0);
312
313 SetFocus(hTree);
314
315 /* Record the old WNDPROC so we can call it after recording the messages */
316 pOldWndProc = (WNDPROC)SetWindowLongPtrA(hTree, GWLP_WNDPROC, (LONG_PTR)TreeviewWndProc);
317 SetWindowLongPtrA(hTree, GWLP_USERDATA, (LONG_PTR)pOldWndProc);
318
319 return hTree;
320 }
321
322 static void fill_tree(HWND hTree)
323 {
324 TVINSERTSTRUCTA ins;
325 static CHAR root[] = "Root",
326 child[] = "Child";
327
328 ins.hParent = TVI_ROOT;
329 ins.hInsertAfter = TVI_ROOT;
330 U(ins).item.mask = TVIF_TEXT;
331 U(ins).item.pszText = root;
332 hRoot = TreeView_InsertItemA(hTree, &ins);
333
334 ins.hParent = hRoot;
335 ins.hInsertAfter = TVI_FIRST;
336 U(ins).item.mask = TVIF_TEXT;
337 U(ins).item.pszText = child;
338 hChild = TreeView_InsertItemA(hTree, &ins);
339 }
340
341 static void test_fillroot(void)
342 {
343 TVITEMA tvi;
344 HWND hTree;
345
346 hTree = create_treeview_control(0);
347
348 flush_sequences(sequences, NUM_MSG_SEQUENCES);
349
350 fill_tree(hTree);
351
352 Clear();
353 AddItem('A');
354 ok(hRoot != NULL, "failed to set root\n");
355 AddItem('B');
356 ok(hChild != NULL, "failed to set child\n");
357 AddItem('.');
358 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, FillRootSeq, "FillRoot", FALSE);
359 ok(!strcmp(sequence, "AB."), "Item creation\n");
360
361 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
362 tvi.hItem = hRoot;
363 tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
364 SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&tvi);
365 ok(tvi.iImage == 0, "tvi.iImage=%d\n", tvi.iImage);
366 ok(tvi.iSelectedImage == 0, "tvi.iSelectedImage=%d\n", tvi.iSelectedImage);
367
368 DestroyWindow(hTree);
369 }
370
371 static void test_callback(void)
372 {
373 HTREEITEM hRoot;
374 HTREEITEM hItem1, hItem2;
375 TVINSERTSTRUCTA ins;
376 TVITEMA tvi;
377 CHAR test_string[] = "Test_string";
378 static const CHAR test2A[] = "TEST2";
379 CHAR buf[128];
380 HWND hTree;
381 DWORD ret;
382
383 hTree = create_treeview_control(0);
384
385 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
386 expect(TRUE, ret);
387 ins.hParent = TVI_ROOT;
388 ins.hInsertAfter = TVI_ROOT;
389 U(ins).item.mask = TVIF_TEXT;
390 U(ins).item.pszText = LPSTR_TEXTCALLBACKA;
391 hRoot = TreeView_InsertItemA(hTree, &ins);
392 ok(hRoot != NULL, "failed to set root\n");
393
394 tvi.hItem = hRoot;
395 tvi.mask = TVIF_TEXT;
396 tvi.pszText = buf;
397 tvi.cchTextMax = sizeof(buf)/sizeof(buf[0]);
398 ret = TreeView_GetItemA(hTree, &tvi);
399 expect(TRUE, ret);
400 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Callback item text mismatch %s vs %s\n",
401 tvi.pszText, TEST_CALLBACK_TEXT);
402
403 ins.hParent = hRoot;
404 ins.hInsertAfter = TVI_FIRST;
405 U(ins).item.mask = TVIF_TEXT;
406 U(ins).item.pszText = test_string;
407 hItem1 = TreeView_InsertItemA(hTree, &ins);
408 ok(hItem1 != NULL, "failed to set Item1\n");
409
410 tvi.hItem = hItem1;
411 ret = TreeView_GetItemA(hTree, &tvi);
412 expect(TRUE, ret);
413 ok(strcmp(tvi.pszText, test_string) == 0, "Item text mismatch %s vs %s\n",
414 tvi.pszText, test_string);
415
416 /* undocumented: pszText of NULL also means LPSTR_CALLBACK: */
417 tvi.pszText = NULL;
418 ret = TreeView_SetItemA(hTree, &tvi);
419 expect(TRUE, ret);
420 tvi.pszText = buf;
421 ret = TreeView_GetItemA(hTree, &tvi);
422 expect(TRUE, ret);
423 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Item text mismatch %s vs %s\n",
424 tvi.pszText, TEST_CALLBACK_TEXT);
425
426 U(ins).item.pszText = NULL;
427 hItem2 = TreeView_InsertItemA(hTree, &ins);
428 ok(hItem2 != NULL, "failed to set Item2\n");
429 tvi.hItem = hItem2;
430 memset(buf, 0, sizeof(buf));
431 ret = TreeView_GetItemA(hTree, &tvi);
432 expect(TRUE, ret);
433 ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Item text mismatch %s vs %s\n",
434 tvi.pszText, TEST_CALLBACK_TEXT);
435
436 /* notification handler changed A->W */
437 g_disp_A_to_W = TRUE;
438 tvi.hItem = hItem2;
439 memset(buf, 0, sizeof(buf));
440 ret = TreeView_GetItemA(hTree, &tvi);
441 expect(TRUE, ret);
442 ok(strcmp(tvi.pszText, test2A) == 0, "got %s, expected %s\n",
443 tvi.pszText, test2A);
444 g_disp_A_to_W = FALSE;
445
446 /* handler changes state image index */
447 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
448
449 /* clear selection, handler will set selected state */
450 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
451 expect(TRUE, ret);
452
453 flush_sequences(sequences, NUM_MSG_SEQUENCES);
454
455 tvi.hItem = hRoot;
456 tvi.mask = TVIF_STATE;
457 tvi.state = TVIS_SELECTED;
458 ret = TreeView_GetItemA(hTree, &tvi);
459 expect(TRUE, ret);
460 ok(tvi.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", tvi.state);
461
462 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
463 "no TVN_GETDISPINFO for a state seq", FALSE);
464
465 tvi.hItem = hRoot;
466 tvi.mask = TVIF_IMAGE | TVIF_STATE;
467 tvi.state = TVIS_FOCUSED;
468 tvi.stateMask = TVIS_FOCUSED;
469 tvi.iImage = I_IMAGECALLBACK;
470 ret = TreeView_SetItemA(hTree, &tvi);
471 expect(TRUE, ret);
472
473 /* ask for item image index through callback - state is also set with state image index */
474 flush_sequences(sequences, NUM_MSG_SEQUENCES);
475
476 tvi.hItem = hRoot;
477 tvi.mask = TVIF_IMAGE;
478 tvi.state = 0;
479 ret = TreeView_GetItemA(hTree, &tvi);
480 expect(TRUE, ret);
481 ok(tvi.state == (INDEXTOSTATEIMAGEMASK(1) | TVIS_FOCUSED), "got 0x%x\n", tvi.state);
482
483 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_get_dispinfo_seq,
484 "callback for state/overlay image index, noop seq", FALSE);
485
486 /* ask for image again and overwrite state to some value in handler */
487 flush_sequences(sequences, NUM_MSG_SEQUENCES);
488
489 g_disp_set_stateimage = TRUE;
490 tvi.hItem = hRoot;
491 tvi.mask = TVIF_IMAGE;
492 tvi.state = INDEXTOSTATEIMAGEMASK(1);
493 tvi.stateMask = 0;
494 ret = TreeView_GetItemA(hTree, &tvi);
495 expect(TRUE, ret);
496 /* handler sets TVIS_SELECTED as well */
497 ok(tvi.state == (TVIS_FOCUSED | TVIS_SELECTED | INDEXTOSTATEIMAGEMASK(2) | INDEXTOOVERLAYMASK(3)), "got 0x%x\n", tvi.state);
498 g_disp_set_stateimage = FALSE;
499
500 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_get_dispinfo_seq,
501 "callback for state/overlay image index seq", FALSE);
502
503 DestroyWindow(hTree);
504 }
505
506 static void test_select(void)
507 {
508 BOOL r;
509 HWND hTree;
510
511 hTree = create_treeview_control(0);
512 fill_tree(hTree);
513
514 /* root-none select tests */
515 flush_sequences(sequences, NUM_MSG_SEQUENCES);
516 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
517 expect(TRUE, r);
518 Clear();
519 AddItem('1');
520 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
521 expect(TRUE, r);
522 AddItem('2');
523 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
524 expect(TRUE, r);
525 AddItem('3');
526 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
527 expect(TRUE, r);
528 AddItem('4');
529 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
530 expect(TRUE, r);
531 AddItem('5');
532 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
533 expect(TRUE, r);
534 AddItem('.');
535 ok(!strcmp(sequence, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
536 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, rootnone_select_seq,
537 "root-none select seq", FALSE);
538
539 /* root-child select tests */
540 flush_sequences(sequences, NUM_MSG_SEQUENCES);
541 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
542 expect(TRUE, r);
543
544 Clear();
545 AddItem('1');
546 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
547 expect(TRUE, r);
548 AddItem('2');
549 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
550 expect(TRUE, r);
551 AddItem('3');
552 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
553 expect(TRUE, r);
554 AddItem('4');
555 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
556 expect(TRUE, r);
557 AddItem('5');
558 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
559 expect(TRUE, r);
560 AddItem('.');
561 ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
562 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, rootchild_select_seq,
563 "root-child select seq", FALSE);
564
565 DestroyWindow(hTree);
566 }
567
568 static void test_getitemtext(void)
569 {
570 TVINSERTSTRUCTA ins;
571 HTREEITEM hChild;
572 TVITEMA tvi;
573 HWND hTree;
574
575 CHAR szBuffer[80] = "Blah";
576 int nBufferSize = sizeof(szBuffer)/sizeof(CHAR);
577
578 hTree = create_treeview_control(0);
579 fill_tree(hTree);
580
581 flush_sequences(sequences, NUM_MSG_SEQUENCES);
582
583 /* add an item without TVIF_TEXT mask and pszText == NULL */
584 ins.hParent = hRoot;
585 ins.hInsertAfter = TVI_ROOT;
586 U(ins).item.mask = 0;
587 U(ins).item.pszText = NULL;
588 U(ins).item.cchTextMax = 0;
589 hChild = TreeView_InsertItemA(hTree, &ins);
590 ok(hChild != NULL, "failed to set hChild\n");
591
592 /* retrieve it with TVIF_TEXT mask */
593 tvi.hItem = hChild;
594 tvi.mask = TVIF_TEXT;
595 tvi.cchTextMax = nBufferSize;
596 tvi.pszText = szBuffer;
597
598 SendMessageA( hTree, TVM_GETITEMA, 0, (LPARAM)&tvi );
599 ok(!strcmp(szBuffer, ""), "szBuffer=\"%s\", expected \"\"\n", szBuffer);
600 ok(SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild), "DeleteItem failed\n");
601 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, getitemtext_seq, "get item text seq", FALSE);
602
603 DestroyWindow(hTree);
604 }
605
606 static void test_focus(void)
607 {
608 TVINSERTSTRUCTA ins;
609 static CHAR child1[] = "Edit",
610 child2[] = "A really long string";
611 HTREEITEM hChild1, hChild2;
612 HWND hTree;
613 HWND hEdit;
614
615 hTree = create_treeview_control(0);
616 fill_tree(hTree);
617
618 flush_sequences(sequences, NUM_MSG_SEQUENCES);
619
620 /* This test verifies that when a label is being edited, scrolling
621 * the treeview does not cause the label to lose focus. To test
622 * this, first some additional entries are added to generate
623 * scrollbars.
624 */
625 ins.hParent = hRoot;
626 ins.hInsertAfter = hChild;
627 U(ins).item.mask = TVIF_TEXT;
628 U(ins).item.pszText = child1;
629 hChild1 = TreeView_InsertItemA(hTree, &ins);
630 ok(hChild1 != NULL, "failed to set hChild1\n");
631 ins.hInsertAfter = hChild1;
632 U(ins).item.mask = TVIF_TEXT;
633 U(ins).item.pszText = child2;
634 hChild2 = TreeView_InsertItemA(hTree, &ins);
635 ok(hChild2 != NULL, "failed to set hChild2\n");
636
637 ShowWindow(hMainWnd,SW_SHOW);
638 SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
639 hEdit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hChild);
640 ScrollWindowEx(hTree, -10, 0, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN);
641 ok(GetFocus() == hEdit, "Edit control should have focus\n");
642 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, focus_seq, "focus test", TRUE);
643
644 DestroyWindow(hTree);
645 }
646
647 static void test_get_set_bkcolor(void)
648 {
649 COLORREF crColor = RGB(0,0,0);
650 HWND hTree;
651
652 hTree = create_treeview_control(0);
653 fill_tree(hTree);
654
655 flush_sequences(sequences, NUM_MSG_SEQUENCES);
656
657 /* If the value is -1, the control is using the system color for the background color. */
658 crColor = SendMessageA(hTree, TVM_GETBKCOLOR, 0, 0);
659 ok(crColor == ~0u, "Default background color reported as 0x%.8x\n", crColor);
660
661 /* Test for black background */
662 SendMessageA(hTree, TVM_SETBKCOLOR, 0, RGB(0,0,0));
663 crColor = SendMessageA(hTree, TVM_GETBKCOLOR, 0, 0);
664 ok(crColor == RGB(0,0,0), "Black background color reported as 0x%.8x\n", crColor);
665
666 /* Test for white background */
667 SendMessageA(hTree, TVM_SETBKCOLOR, 0, RGB(255,255,255));
668 crColor = SendMessageA(hTree, TVM_GETBKCOLOR, 0, 0);
669 ok(crColor == RGB(255,255,255), "White background color reported as 0x%.8x\n", crColor);
670
671 /* Reset the default background */
672 SendMessageA(hTree, TVM_SETBKCOLOR, 0, -1);
673
674 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_bkcolor_seq,
675 "test get set bkcolor", FALSE);
676
677 DestroyWindow(hTree);
678 }
679
680 static void test_get_set_imagelist(void)
681 {
682 HIMAGELIST himl;
683 HWND hTree;
684
685 hTree = create_treeview_control(0);
686 fill_tree(hTree);
687
688 flush_sequences(sequences, NUM_MSG_SEQUENCES);
689
690 /* Test a NULL HIMAGELIST */
691 SendMessageA(hTree, TVM_SETIMAGELIST, TVSIL_NORMAL, 0);
692 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_NORMAL, 0);
693 ok(himl == NULL, "NULL image list, reported as %p, expected 0.\n", himl);
694
695 /* TODO: Test an actual image list */
696
697 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_imagelist_seq,
698 "test get imagelist", FALSE);
699
700 DestroyWindow(hTree);
701 }
702
703 static void test_get_set_indent(void)
704 {
705 int ulIndent = -1;
706 int ulMinIndent = -1;
707 int ulMoreThanTwiceMin = -1;
708 HWND hTree;
709
710 hTree = create_treeview_control(0);
711 fill_tree(hTree);
712
713 flush_sequences(sequences, NUM_MSG_SEQUENCES);
714
715 /* Finding the minimum indent */
716 SendMessageA(hTree, TVM_SETINDENT, 0, 0);
717 ulMinIndent = SendMessageA(hTree, TVM_GETINDENT, 0, 0);
718
719 /* Checking an indent that is more than twice the default indent */
720 ulMoreThanTwiceMin = 2*ulMinIndent+1;
721 SendMessageA(hTree, TVM_SETINDENT, ulMoreThanTwiceMin, 0);
722 ulIndent = SendMessageA(hTree, TVM_GETINDENT, 0, 0);
723 ok(ulIndent == ulMoreThanTwiceMin, "Indent reported as %d, expected %d\n", ulIndent, ulMoreThanTwiceMin);
724
725 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_indent_seq,
726 "test get set indent", FALSE);
727
728 DestroyWindow(hTree);
729 }
730
731 static void test_get_set_insertmark(void)
732 {
733 COLORREF crColor = RGB(0,0,0);
734 HWND hTree;
735
736 hTree = create_treeview_control(0);
737 fill_tree(hTree);
738
739 flush_sequences(sequences, NUM_MSG_SEQUENCES);
740
741 SendMessageA(hTree, TVM_SETINSERTMARKCOLOR, 0, crColor);
742 crColor = SendMessageA(hTree, TVM_GETINSERTMARKCOLOR, 0, 0);
743 ok(crColor == RGB(0,0,0), "Insert mark color reported as 0x%.8x, expected 0x00000000\n", crColor);
744
745 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_insertmarkcolor_seq,
746 "test get set insertmark color", FALSE);
747
748 DestroyWindow(hTree);
749 }
750
751 static void test_get_set_item(void)
752 {
753 TVITEMA tviRoot = {0};
754 int nBufferSize = 80;
755 char szBuffer[80] = {0};
756 HWND hTree, hTree2;
757 DWORD ret;
758
759 hTree = create_treeview_control(0);
760 fill_tree(hTree);
761
762 tviRoot.hItem = hRoot;
763 tviRoot.mask = TVIF_STATE;
764 tviRoot.state = TVIS_FOCUSED;
765 tviRoot.stateMask = TVIS_FOCUSED;
766 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&tviRoot);
767 expect(TRUE, ret);
768
769 flush_sequences(sequences, NUM_MSG_SEQUENCES);
770
771 /* Test the root item, state is set even when not requested */
772 tviRoot.hItem = hRoot;
773 tviRoot.mask = TVIF_TEXT;
774 tviRoot.state = 0;
775 tviRoot.stateMask = 0;
776 tviRoot.cchTextMax = nBufferSize;
777 tviRoot.pszText = szBuffer;
778 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&tviRoot);
779 expect(TRUE, ret);
780 ok(!strcmp("Root", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Root\"\n", szBuffer);
781 ok(tviRoot.state == TVIS_FOCUSED, "got 0x%0x\n", tviRoot.state);
782
783 /* Change the root text */
784 lstrcpynA(szBuffer, "Testing123", nBufferSize);
785 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&tviRoot);
786 expect(TRUE, ret);
787 memset(szBuffer, 0, nBufferSize);
788 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&tviRoot);
789 expect(TRUE, ret);
790 ok(!strcmp("Testing123", szBuffer), "GetItem: szBuffer=\"%s\", expected \"Testing123\"\n", szBuffer);
791
792 /* Reset the root text */
793 memset(szBuffer, 0, nBufferSize);
794 lstrcpynA(szBuffer, "Root", nBufferSize);
795 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&tviRoot);
796 expect(TRUE, ret);
797
798 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_item_seq,
799 "test get set item", FALSE);
800
801 /* get item from a different tree */
802 hTree2 = create_treeview_control(0);
803
804 tviRoot.hItem = hRoot;
805 tviRoot.mask = TVIF_STATE;
806 tviRoot.state = 0;
807 ret = SendMessageA(hTree2, TVM_GETITEMA, 0, (LPARAM)&tviRoot);
808 expect(TRUE, ret);
809 ok(tviRoot.state == TVIS_FOCUSED, "got state 0x%0x\n", tviRoot.state);
810
811 DestroyWindow(hTree);
812 DestroyWindow(hTree2);
813 }
814
815 static void test_get_set_itemheight(void)
816 {
817 int ulOldHeight = 0;
818 int ulNewHeight = 0;
819 HWND hTree;
820
821 hTree = create_treeview_control(0);
822 fill_tree(hTree);
823
824 flush_sequences(sequences, NUM_MSG_SEQUENCES);
825
826 /* Assuming default height to begin with */
827 ulOldHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
828
829 /* Explicitly setting and getting the default height */
830 SendMessageA(hTree, TVM_SETITEMHEIGHT, -1, 0);
831 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
832 ok(ulNewHeight == ulOldHeight, "Default height not set properly, reported %d, expected %d\n", ulNewHeight, ulOldHeight);
833
834 /* Explicitly setting and getting the height of twice the normal */
835 SendMessageA(hTree, TVM_SETITEMHEIGHT, 2*ulOldHeight, 0);
836 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
837 ok(ulNewHeight == 2*ulOldHeight, "New height not set properly, reported %d, expected %d\n", ulNewHeight, 2*ulOldHeight);
838
839 /* Assuming tree doesn't have TVS_NONEVENHEIGHT set, so a set of 9 will round down to 8 */
840 SendMessageA(hTree, TVM_SETITEMHEIGHT, 9, 0);
841 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
842 ok(ulNewHeight == 8, "Uneven height not set properly, reported %d, expected %d\n", ulNewHeight, 8);
843
844 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_itemheight_seq,
845 "test get set item height", FALSE);
846
847 /* without TVS_NONEVENHEIGHT */
848 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) & ~TVS_NONEVENHEIGHT);
849 /* odd value */
850 ulOldHeight = SendMessageA(hTree, TVM_SETITEMHEIGHT, 3, 0);
851 ok(ulOldHeight == 8, "got %d, expected %d\n", ulOldHeight, 8);
852 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
853 ok(ulNewHeight == 2, "got %d, expected %d\n", ulNewHeight, 2);
854
855 ulOldHeight = SendMessageA(hTree, TVM_SETITEMHEIGHT, 4, 0);
856 ok(ulOldHeight == 2, "got %d, expected %d\n", ulOldHeight, 2);
857 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
858 ok(ulNewHeight == 4, "got %d, expected %d\n", ulNewHeight, 4);
859
860 /* with TVS_NONEVENHEIGHT */
861 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_NONEVENHEIGHT);
862 /* odd value */
863 ulOldHeight = SendMessageA(hTree, TVM_SETITEMHEIGHT, 3, 0);
864 ok(ulOldHeight == 4, "got %d, expected %d\n", ulOldHeight, 4);
865 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
866 ok(ulNewHeight == 3, "got %d, expected %d\n", ulNewHeight, 3);
867 /* even value */
868 ulOldHeight = SendMessageA(hTree, TVM_SETITEMHEIGHT, 10, 0);
869 ok(ulOldHeight == 3, "got %d, expected %d\n", ulOldHeight, 3);
870 ulNewHeight = SendMessageA(hTree, TVM_GETITEMHEIGHT, 0, 0);
871 ok(ulNewHeight == 10, "got %d, expected %d\n", ulNewHeight, 10);
872
873 DestroyWindow(hTree);
874 }
875
876 static void test_get_set_scrolltime(void)
877 {
878 int ulExpectedTime = 20;
879 int ulTime = 0;
880 HWND hTree;
881
882 hTree = create_treeview_control(0);
883 fill_tree(hTree);
884
885 flush_sequences(sequences, NUM_MSG_SEQUENCES);
886
887 SendMessageA(hTree, TVM_SETSCROLLTIME, ulExpectedTime, 0);
888 ulTime = SendMessageA(hTree, TVM_GETSCROLLTIME, 0, 0);
889 ok(ulTime == ulExpectedTime, "Scroll time reported as %d, expected %d\n", ulTime, ulExpectedTime);
890
891 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_scrolltime_seq,
892 "test get set scroll time", FALSE);
893
894 DestroyWindow(hTree);
895 }
896
897 static void test_get_set_textcolor(void)
898 {
899 /* If the value is -1, the control is using the system color for the text color. */
900 COLORREF crColor = RGB(0,0,0);
901 HWND hTree;
902
903 hTree = create_treeview_control(0);
904 fill_tree(hTree);
905
906 flush_sequences(sequences, NUM_MSG_SEQUENCES);
907
908 crColor = SendMessageA(hTree, TVM_GETTEXTCOLOR, 0, 0);
909 ok(crColor == ~0u, "Default text color reported as 0x%.8x\n", crColor);
910
911 /* Test for black text */
912 SendMessageA(hTree, TVM_SETTEXTCOLOR, 0, RGB(0,0,0));
913 crColor = SendMessageA(hTree, TVM_GETTEXTCOLOR, 0, 0);
914 ok(crColor == RGB(0,0,0), "Black text color reported as 0x%.8x\n", crColor);
915
916 /* Test for white text */
917 SendMessageA(hTree, TVM_SETTEXTCOLOR, 0, RGB(255,255,255));
918 crColor = SendMessageA(hTree, TVM_GETTEXTCOLOR, 0, 0);
919 ok(crColor == RGB(255,255,255), "White text color reported as 0x%.8x\n", crColor);
920
921 /* Reset the default text color */
922 SendMessageA(hTree, TVM_SETTEXTCOLOR, 0, CLR_NONE);
923
924 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_textcolor_seq,
925 "test get set text color", FALSE);
926
927 DestroyWindow(hTree);
928 }
929
930 static void test_get_set_tooltips(void)
931 {
932 HWND hwndLastToolTip = NULL;
933 HWND hPopupTreeView;
934 HWND hTree;
935
936 hTree = create_treeview_control(0);
937 fill_tree(hTree);
938
939 flush_sequences(sequences, NUM_MSG_SEQUENCES);
940
941 /* show even WS_POPUP treeview don't send NM_TOOLTIPSCREATED */
942 hPopupTreeView = CreateWindowA(WC_TREEVIEWA, NULL, WS_POPUP|WS_VISIBLE, 0, 0, 100, 100,
943 hMainWnd, NULL, NULL, NULL);
944 DestroyWindow(hPopupTreeView);
945
946 /* Testing setting a NULL ToolTip */
947 SendMessageA(hTree, TVM_SETTOOLTIPS, 0, 0);
948 hwndLastToolTip = (HWND)SendMessageA(hTree, TVM_GETTOOLTIPS, 0, 0);
949 ok(hwndLastToolTip == NULL, "NULL tool tip, reported as 0x%p, expected 0.\n", hwndLastToolTip);
950
951 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_tooltips_seq,
952 "test get set tooltips", TRUE);
953
954 /* TODO: Add a test of an actual tooltip */
955 DestroyWindow(hTree);
956 }
957
958 static void test_get_set_unicodeformat(void)
959 {
960 BOOL bPreviousSetting = FALSE;
961 BOOL bNewSetting = FALSE;
962 HWND hTree;
963
964 hTree = create_treeview_control(0);
965 fill_tree(hTree);
966
967 /* Check that an invalid format returned by NF_QUERY defaults to ANSI */
968 bPreviousSetting = SendMessageA(hTree, TVM_GETUNICODEFORMAT, 0, 0);
969 ok(bPreviousSetting == FALSE, "Format should be ANSI.\n");
970
971 flush_sequences(sequences, NUM_MSG_SEQUENCES);
972
973 /* Set to Unicode */
974 bPreviousSetting = SendMessageA(hTree, TVM_SETUNICODEFORMAT, 1, 0);
975 bNewSetting = SendMessageA(hTree, TVM_GETUNICODEFORMAT, 0, 0);
976 ok(bNewSetting == TRUE, "Unicode setting did not work.\n");
977
978 /* Set to ANSI */
979 SendMessageA(hTree, TVM_SETUNICODEFORMAT, 0, 0);
980 bNewSetting = SendMessageA(hTree, TVM_GETUNICODEFORMAT, 0, 0);
981 ok(bNewSetting == FALSE, "ANSI setting did not work.\n");
982
983 /* Revert to original setting */
984 SendMessageA(hTree, TVM_SETUNICODEFORMAT, bPreviousSetting, 0);
985
986 ok_sequence(sequences, TREEVIEW_SEQ_INDEX, test_get_set_unicodeformat_seq,
987 "test get set unicode format", FALSE);
988
989 DestroyWindow(hTree);
990 }
991
992 static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
993 {
994 static LONG defwndproc_counter = 0;
995 struct message msg;
996 LRESULT ret;
997 RECT rect;
998 HTREEITEM visibleItem;
999
1000 msg.message = message;
1001 msg.flags = sent|wparam|lparam;
1002 if (defwndproc_counter) msg.flags |= defwinproc;
1003 msg.wParam = wParam;
1004 msg.lParam = lParam;
1005 if (message == WM_NOTIFY && lParam)
1006 msg.id = ((NMHDR*)lParam)->code;
1007 else
1008 msg.id = 0;
1009
1010 /* log system messages, except for painting */
1011 if (message < WM_USER &&
1012 message != WM_PAINT &&
1013 message != WM_ERASEBKGND &&
1014 message != WM_NCPAINT &&
1015 message != WM_NCHITTEST &&
1016 message != WM_GETTEXT &&
1017 message != WM_GETICON &&
1018 message != WM_DEVICECHANGE)
1019 {
1020 trace("parent: %p, %04x, %08lx, %08lx\n", hWnd, message, wParam, lParam);
1021 add_message(sequences, PARENT_SEQ_INDEX, &msg);
1022 }
1023
1024 switch(message) {
1025 case WM_NOTIFYFORMAT:
1026 {
1027 /* Make NF_QUERY return an invalid format to show that it defaults to ANSI */
1028 if (lParam == NF_QUERY) return 0;
1029 break;
1030 }
1031
1032 case WM_NOTIFY:
1033 {
1034 NMHDR *pHdr = (NMHDR *)lParam;
1035
1036 ok(pHdr->code != NM_TOOLTIPSCREATED, "Treeview should not send NM_TOOLTIPSCREATED\n");
1037 if (pHdr->idFrom == 100)
1038 {
1039 NMTREEVIEWA *pTreeView = (LPNMTREEVIEWA) lParam;
1040 switch(pHdr->code)
1041 {
1042 case TVN_SELCHANGINGA:
1043 AddItem('(');
1044 IdentifyItem(pTreeView->itemOld.hItem);
1045 IdentifyItem(pTreeView->itemNew.hItem);
1046 break;
1047 case TVN_SELCHANGEDA:
1048 AddItem(')');
1049 IdentifyItem(pTreeView->itemOld.hItem);
1050 IdentifyItem(pTreeView->itemNew.hItem);
1051 break;
1052 case TVN_GETDISPINFOA: {
1053 NMTVDISPINFOA *disp = (NMTVDISPINFOA *)lParam;
1054 if (disp->item.mask & TVIF_TEXT) {
1055 lstrcpynA(disp->item.pszText, TEST_CALLBACK_TEXT, disp->item.cchTextMax);
1056 }
1057
1058 if (g_disp_A_to_W && (disp->item.mask & TVIF_TEXT)) {
1059 static const WCHAR testW[] = {'T','E','S','T','2',0};
1060
1061 disp->hdr.code = TVN_GETDISPINFOW;
1062 memcpy(disp->item.pszText, testW, sizeof(testW));
1063 }
1064
1065 if (g_disp_set_stateimage)
1066 {
1067 ok(disp->item.mask == TVIF_IMAGE, "got %x\n", disp->item.mask);
1068 /* both masks set here are necessary to change state bits */
1069 disp->item.mask |= TVIF_STATE;
1070 disp->item.state = TVIS_SELECTED | INDEXTOSTATEIMAGEMASK(2) | INDEXTOOVERLAYMASK(3);
1071 disp->item.stateMask = TVIS_SELECTED | TVIS_OVERLAYMASK | TVIS_STATEIMAGEMASK;
1072 }
1073
1074 break;
1075 }
1076 case TVN_BEGINLABELEDITA:
1077 {
1078 if (g_beginedit_alter_text)
1079 {
1080 static const char* textA = "<edittextaltered>";
1081 HWND edit;
1082
1083 edit = (HWND)SendMessageA(pHdr->hwndFrom, TVM_GETEDITCONTROL, 0, 0);
1084 ok(IsWindow(edit), "failed to get edit handle\n");
1085 SetWindowTextA(edit, textA);
1086 }
1087
1088 break;
1089 }
1090
1091 case TVN_ENDLABELEDITA: return TRUE;
1092 case TVN_ITEMEXPANDINGA:
1093 ok(pTreeView->itemNew.mask ==
1094 (TVIF_HANDLE | TVIF_SELECTEDIMAGE | TVIF_IMAGE | TVIF_PARAM | TVIF_STATE),
1095 "got wrong mask %x\n", pTreeView->itemNew.mask);
1096 ok(pTreeView->itemOld.mask == 0,
1097 "got wrong mask %x\n", pTreeView->itemOld.mask);
1098
1099 if (g_get_from_expand)
1100 {
1101 g_item_expanding.mask = TVIF_STATE;
1102 g_item_expanding.hItem = hRoot;
1103 ret = SendMessageA(pHdr->hwndFrom, TVM_GETITEMA, 0, (LPARAM)&g_item_expanding);
1104 ok(ret == TRUE, "got %lu\n", ret);
1105 }
1106 break;
1107 case TVN_ITEMEXPANDEDA:
1108 ok(pTreeView->itemNew.mask & TVIF_STATE, "got wrong mask %x\n", pTreeView->itemNew.mask);
1109 ok(pTreeView->itemNew.state & (TVIS_EXPANDED|TVIS_EXPANDEDONCE),
1110 "got wrong mask %x\n", pTreeView->itemNew.mask);
1111 ok(pTreeView->itemOld.mask == 0,
1112 "got wrong mask %x\n", pTreeView->itemOld.mask);
1113
1114 if (g_get_from_expand)
1115 {
1116 g_item_expanded.mask = TVIF_STATE;
1117 g_item_expanded.hItem = hRoot;
1118 ret = SendMessageA(pHdr->hwndFrom, TVM_GETITEMA, 0, (LPARAM)&g_item_expanded);
1119 ok(ret == TRUE, "got %lu\n", ret);
1120 }
1121 if (g_get_rect_in_expand)
1122 {
1123 visibleItem = (HTREEITEM)SendMessageA(pHdr->hwndFrom, TVM_GETNEXTITEM,
1124 TVGN_FIRSTVISIBLE, 0);
1125 ok(pTreeView->itemNew.hItem == visibleItem, "expanded item == first visible item\n");
1126 *(HTREEITEM*)&rect = visibleItem;
1127 ok(SendMessageA(pHdr->hwndFrom, TVM_GETITEMRECT, TRUE, (LPARAM)&rect),
1128 "Failed to get rect for first visible item.\n");
1129 visibleItem = (HTREEITEM)SendMessageA(pHdr->hwndFrom, TVM_GETNEXTITEM,
1130 TVGN_NEXTVISIBLE, (LPARAM)visibleItem);
1131 *(HTREEITEM*)&rect = visibleItem;
1132 ok(visibleItem != NULL, "There must be a visible item after the first visisble item.\n");
1133 ok(SendMessageA(pHdr->hwndFrom, TVM_GETITEMRECT, TRUE, (LPARAM)&rect),
1134 "Failed to get rect for second visible item.\n");
1135 }
1136 break;
1137 case TVN_DELETEITEMA:
1138 {
1139 struct message item;
1140
1141 ok(pTreeView->itemNew.mask == 0, "got wrong mask 0x%x\n", pTreeView->itemNew.mask);
1142
1143 ok(pTreeView->itemOld.mask == (TVIF_HANDLE | TVIF_PARAM), "got wrong mask 0x%x\n", pTreeView->itemOld.mask);
1144 ok(pTreeView->itemOld.hItem != NULL, "got %p\n", pTreeView->itemOld.hItem);
1145
1146 memset(&item, 0, sizeof(item));
1147 item.lParam = (LPARAM)pTreeView->itemOld.hItem;
1148 add_message(item_sequence, 0, &item);
1149
1150 break;
1151 }
1152 }
1153 }
1154 break;
1155 }
1156
1157 case WM_DESTROY:
1158 PostQuitMessage(0);
1159 break;
1160 }
1161
1162 defwndproc_counter++;
1163 ret = DefWindowProcA(hWnd, message, wParam, lParam);
1164 defwndproc_counter--;
1165
1166 return ret;
1167 }
1168
1169 static void test_expandinvisible(void)
1170 {
1171 static CHAR nodeText[][5] = {"0", "1", "2", "3", "4"};
1172 TVINSERTSTRUCTA ins;
1173 HTREEITEM node[5];
1174 RECT dummyRect;
1175 BOOL nodeVisible;
1176 LRESULT ret;
1177 HWND hTree;
1178
1179 hTree = create_treeview_control(0);
1180
1181 /* The test builds the following tree and expands node 1, while node 0 is collapsed.
1182 *
1183 * 0
1184 * |- 1
1185 * | |- 2
1186 * | |- 3
1187 * |- 4
1188 *
1189 */
1190
1191 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
1192 ok(ret == TRUE, "ret\n");
1193 ins.hParent = TVI_ROOT;
1194 ins.hInsertAfter = TVI_ROOT;
1195 U(ins).item.mask = TVIF_TEXT;
1196 U(ins).item.pszText = nodeText[0];
1197 node[0] = TreeView_InsertItemA(hTree, &ins);
1198 ok(node[0] != NULL, "failed to set node[0]\n");
1199
1200 ins.hInsertAfter = TVI_LAST;
1201 U(ins).item.mask = TVIF_TEXT;
1202 ins.hParent = node[0];
1203
1204 U(ins).item.pszText = nodeText[1];
1205 node[1] = TreeView_InsertItemA(hTree, &ins);
1206 ok(node[1] != NULL, "failed to set node[1]\n");
1207 U(ins).item.pszText = nodeText[4];
1208 node[4] = TreeView_InsertItemA(hTree, &ins);
1209 ok(node[4] != NULL, "failed to set node[4]\n");
1210
1211 ins.hParent = node[1];
1212
1213 U(ins).item.pszText = nodeText[2];
1214 node[2] = TreeView_InsertItemA(hTree, &ins);
1215 ok(node[2] != NULL, "failed to set node[2]\n");
1216 U(ins).item.pszText = nodeText[3];
1217 node[3] = TreeView_InsertItemA(hTree, &ins);
1218 ok(node[3] != NULL, "failed to set node[3]\n");
1219
1220 *(HTREEITEM *)&dummyRect = node[1];
1221 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1222 ok(!nodeVisible, "Node 1 should not be visible.\n");
1223 *(HTREEITEM *)&dummyRect = node[2];
1224 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1225 ok(!nodeVisible, "Node 2 should not be visible.\n");
1226 *(HTREEITEM *)&dummyRect = node[3];
1227 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1228 ok(!nodeVisible, "Node 3 should not be visible.\n");
1229 *(HTREEITEM *)&dummyRect = node[4];
1230 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1231 ok(!nodeVisible, "Node 4 should not be visible.\n");
1232
1233 ok(SendMessageA(hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)node[1]), "Expand of node 1 failed.\n");
1234
1235 *(HTREEITEM *)&dummyRect = node[1];
1236 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1237 ok(!nodeVisible, "Node 1 should not be visible.\n");
1238 *(HTREEITEM *)&dummyRect = node[2];
1239 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1240 ok(!nodeVisible, "Node 2 should not be visible.\n");
1241 *(HTREEITEM *)&dummyRect = node[3];
1242 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1243 ok(!nodeVisible, "Node 3 should not be visible.\n");
1244 *(HTREEITEM *)&dummyRect = node[4];
1245 nodeVisible = SendMessageA(hTree, TVM_GETITEMRECT, FALSE, (LPARAM)&dummyRect);
1246 ok(!nodeVisible, "Node 4 should not be visible.\n");
1247
1248 DestroyWindow(hTree);
1249 }
1250
1251 static void test_itemedit(void)
1252 {
1253 DWORD r;
1254 HWND edit;
1255 TVITEMA item;
1256 CHAR buffA[20];
1257 HWND hTree;
1258
1259 hTree = create_treeview_control(0);
1260 fill_tree(hTree);
1261
1262 /* try with null item */
1263 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, 0);
1264 ok(!IsWindow(edit), "Expected valid handle\n");
1265
1266 /* trigger edit */
1267 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1268 ok(IsWindow(edit), "Expected valid handle\n");
1269 /* item shouldn't be selected automatically after TVM_EDITLABELA */
1270 r = SendMessageA(hTree, TVM_GETITEMSTATE, (WPARAM)hRoot, TVIS_SELECTED);
1271 expect(0, r);
1272 /* try to cancel with wrong edit handle */
1273 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), 0);
1274 expect(0, r);
1275 ok(IsWindow(edit), "Expected edit control to be valid\n");
1276 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1277 expect(0, r);
1278 ok(!IsWindow(edit), "Expected edit control to be destroyed\n");
1279 /* try to cancel without creating edit */
1280 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), 0);
1281 expect(0, r);
1282
1283 /* try to cancel with wrong (not null) handle */
1284 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1285 ok(IsWindow(edit), "Expected valid handle\n");
1286 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hTree);
1287 expect(0, r);
1288 ok(IsWindow(edit), "Expected edit control to be valid\n");
1289 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1290 expect(0, r);
1291
1292 /* remove selection after starting edit */
1293 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1294 expect(TRUE, r);
1295 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1296 ok(IsWindow(edit), "Expected valid handle\n");
1297 r = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
1298 expect(TRUE, r);
1299 /* alter text */
1300 strcpy(buffA, "x");
1301 r = SendMessageA(edit, WM_SETTEXT, 0, (LPARAM)buffA);
1302 expect(TRUE, r);
1303 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1304 expect(0, r);
1305 ok(!IsWindow(edit), "Expected edit control to be destroyed\n");
1306 /* check that text is saved */
1307 item.mask = TVIF_TEXT;
1308 item.hItem = hRoot;
1309 item.pszText = buffA;
1310 item.cchTextMax = sizeof(buffA)/sizeof(CHAR);
1311 r = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1312 expect(TRUE, r);
1313 ok(!strcmp("x", buffA), "Expected item text to change\n");
1314
1315 /* try A/W messages */
1316 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1317 ok(IsWindow(edit), "Expected valid handle\n");
1318 ok(IsWindowUnicode(edit), "got ansi window\n");
1319 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1320 expect(0, r);
1321 ok(!IsWindow(edit), "expected invalid handle\n");
1322
1323 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELW, 0, (LPARAM)hRoot);
1324 ok(IsWindow(edit), "Expected valid handle\n");
1325 ok(IsWindowUnicode(edit), "got ansi window\n");
1326 r = SendMessageA(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
1327 expect(0, r);
1328
1329 /* alter text during TVM_BEGINLABELEDIT, check that it's preserved */
1330 strcpy(buffA, "<root>");
1331
1332 item.mask = TVIF_TEXT;
1333 item.hItem = hRoot;
1334 item.pszText = buffA;
1335 item.cchTextMax = 0;
1336 r = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1337 expect(TRUE, r);
1338
1339 g_beginedit_alter_text = TRUE;
1340 edit = (HWND)SendMessageA(hTree, TVM_EDITLABELA, 0, (LPARAM)hRoot);
1341 ok(IsWindow(edit), "Expected valid handle\n");
1342 g_beginedit_alter_text = FALSE;
1343
1344 GetWindowTextA(edit, buffA, sizeof(buffA)/sizeof(CHAR));
1345 ok(!strcmp(buffA, "<edittextaltered>"), "got string %s\n", buffA);
1346
1347 DestroyWindow(hTree);
1348 }
1349
1350 static void test_treeview_classinfo(void)
1351 {
1352 WNDCLASSA cls;
1353
1354 memset(&cls, 0, sizeof(cls));
1355 GetClassInfoA(GetModuleHandleA("comctl32.dll"), WC_TREEVIEWA, &cls);
1356 ok(cls.hbrBackground == NULL, "Expected NULL background brush, got %p\n", cls.hbrBackground);
1357 ok(cls.style == (CS_GLOBALCLASS | CS_DBLCLKS), "Expected got %x\n", cls.style);
1358 expect(0, cls.cbClsExtra);
1359 }
1360
1361 static void test_get_linecolor(void)
1362 {
1363 COLORREF clr;
1364 HWND hTree;
1365
1366 hTree = create_treeview_control(0);
1367
1368 /* newly created control has default color */
1369 clr = SendMessageA(hTree, TVM_GETLINECOLOR, 0, 0);
1370 if (clr == 0)
1371 win_skip("TVM_GETLINECOLOR is not supported on comctl32 < 5.80\n");
1372 else
1373 expect(CLR_DEFAULT, clr);
1374
1375 DestroyWindow(hTree);
1376 }
1377
1378 static void test_get_insertmarkcolor(void)
1379 {
1380 COLORREF clr;
1381 HWND hTree;
1382
1383 hTree = create_treeview_control(0);
1384
1385 /* newly created control has default color */
1386 clr = SendMessageA(hTree, TVM_GETINSERTMARKCOLOR, 0, 0);
1387 if (clr == 0)
1388 win_skip("TVM_GETINSERTMARKCOLOR is not supported on comctl32 < 5.80\n");
1389 else
1390 expect(CLR_DEFAULT, clr);
1391
1392 DestroyWindow(hTree);
1393 }
1394
1395 static void test_expandnotify(void)
1396 {
1397 HWND hTree;
1398 BOOL ret;
1399 TVITEMA item;
1400
1401 hTree = create_treeview_control(0);
1402 fill_tree(hTree);
1403
1404 item.hItem = hRoot;
1405 item.mask = TVIF_STATE;
1406
1407 item.state = TVIS_EXPANDED;
1408 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1409 expect(TRUE, ret);
1410 ok((item.state & TVIS_EXPANDED) == 0, "expected collapsed\n");
1411
1412 /* preselect root node here */
1413 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1414 expect(TRUE, ret);
1415
1416 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1417 ret = SendMessageA(hTree, TVM_EXPAND, TVE_COLLAPSE, (LPARAM)hRoot);
1418 expect(FALSE, ret);
1419 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "no collapse notifications", FALSE);
1420
1421 g_get_from_expand = TRUE;
1422 /* expand */
1423 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1424 g_item_expanding.state = 0xdeadbeef;
1425 g_item_expanded.state = 0xdeadbeef;
1426 ret = SendMessageA(hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hRoot);
1427 expect(TRUE, ret);
1428 ok(g_item_expanding.state == TVIS_SELECTED, "got state on TVN_ITEMEXPANDING 0x%08x\n",
1429 g_item_expanding.state);
1430 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDED), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1431 g_item_expanded.state);
1432 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_seq, "expand notifications", FALSE);
1433 g_get_from_expand = FALSE;
1434
1435 /* check that it's expanded */
1436 item.state = TVIS_EXPANDED;
1437 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1438 expect(TRUE, ret);
1439 ok((item.state & TVIS_EXPANDED) == TVIS_EXPANDED, "expected expanded\n");
1440
1441 /* collapse */
1442 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1443 ret = SendMessageA(hTree, TVM_EXPAND, TVE_COLLAPSE, (LPARAM)hRoot);
1444 expect(TRUE, ret);
1445 item.state = TVIS_EXPANDED;
1446 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1447 expect(TRUE, ret);
1448 ok((item.state & TVIS_EXPANDED) == 0, "expected collapsed\n");
1449 /* all further collapse/expand attempts won't produce any notifications,
1450 the only way is to reset with all children removed */
1451 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "collapse after expand notifications", FALSE);
1452
1453 /* try to toggle child that doesn't have children itself */
1454 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1455 ret = SendMessageA(hTree, TVM_EXPAND, TVE_TOGGLE, (LPARAM)hChild);
1456 expect(FALSE, ret);
1457 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "toggle node without children", FALSE);
1458
1459 DestroyWindow(hTree);
1460
1461 /* test TVM_GETITEMRECT inside TVN_ITEMEXPANDED notification */
1462 hTree = create_treeview_control(0);
1463 fill_tree(hTree);
1464 g_get_rect_in_expand = TRUE;
1465 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
1466 expect(TRUE, ret);
1467 g_get_rect_in_expand = FALSE;
1468
1469 DestroyWindow(hTree);
1470
1471 /* TVE_TOGGLE acts as any other TVM_EXPAND */
1472 hTree = create_treeview_control(0);
1473 fill_tree(hTree);
1474
1475 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1476 ret = SendMessageA(hTree, TVM_EXPAND, TVE_TOGGLE, (LPARAM)hRoot);
1477 expect(TRUE, ret);
1478 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_seq, "toggle node (expand)", FALSE);
1479
1480 /* toggle again - no notifications */
1481 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1482 ret = SendMessageA(hTree, TVM_EXPAND, TVE_TOGGLE, (LPARAM)hRoot);
1483 expect(TRUE, ret);
1484 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "toggle node (collapse)", FALSE);
1485
1486 DestroyWindow(hTree);
1487
1488 /* some keyboard events are also translated to expand */
1489 hTree = create_treeview_control(0);
1490 fill_tree(hTree);
1491
1492 /* preselect root node here */
1493 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1494 expect(TRUE, ret);
1495
1496 g_get_from_expand = TRUE;
1497 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1498 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1499 expect(FALSE, ret);
1500 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "expand node", FALSE);
1501 ok(g_item_expanding.state == TVIS_SELECTED, "got state on TVN_ITEMEXPANDING 0x%08x\n",
1502 g_item_expanding.state);
1503 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDED), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1504 g_item_expanded.state);
1505
1506 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1507 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1508 expect(FALSE, ret);
1509 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "expand node again", FALSE);
1510 ok(g_item_expanding.state == (TVIS_SELECTED|TVIS_EXPANDED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDING 0x%08x\n",
1511 g_item_expanding.state);
1512 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1513 g_item_expanded.state);
1514
1515 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1516 ret = SendMessageA(hTree, WM_KEYDOWN, VK_SUBTRACT, 0);
1517 expect(FALSE, ret);
1518 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "collapse node", FALSE);
1519 ok(g_item_expanding.state == (TVIS_SELECTED|TVIS_EXPANDED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDING 0x%08x\n",
1520 g_item_expanding.state);
1521 ok(g_item_expanded.state == (TVIS_SELECTED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDED 0x%08x\n",
1522 g_item_expanded.state);
1523
1524 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1525 ret = SendMessageA(hTree, WM_KEYDOWN, VK_SUBTRACT, 0);
1526 expect(FALSE, ret);
1527 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_collapse_2nd_kb_seq, "collapse node again", FALSE);
1528 ok(g_item_expanding.state == (TVIS_SELECTED|TVIS_EXPANDEDONCE), "got state on TVN_ITEMEXPANDING 0x%08x\n",
1529 g_item_expanding.state);
1530 g_get_from_expand = FALSE;
1531
1532 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1533 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1534 expect(FALSE, ret);
1535 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_kb_seq, "expand node", FALSE);
1536
1537 /* go to child */
1538 ret = SendMessageA(hTree, WM_KEYDOWN, VK_RIGHT, 0);
1539 expect(FALSE, ret);
1540
1541 /* try to expand child that doesn't have children itself */
1542 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1543 ret = SendMessageA(hTree, WM_KEYDOWN, VK_ADD, 0);
1544 expect(FALSE, ret);
1545 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_expand_empty_kb_seq, "expand node with no children", FALSE);
1546
1547 DestroyWindow(hTree);
1548 }
1549
1550 static void test_expandedimage(void)
1551 {
1552 TVITEMEXA item;
1553 HWND hTree;
1554 BOOL ret;
1555
1556 hTree = create_treeview_control(0);
1557 fill_tree(hTree);
1558
1559 item.mask = TVIF_EXPANDEDIMAGE;
1560 item.iExpandedImage = 1;
1561 item.hItem = hRoot;
1562 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1563 ok(ret, "got %d\n", ret);
1564
1565 item.mask = TVIF_EXPANDEDIMAGE;
1566 item.iExpandedImage = -1;
1567 item.hItem = hRoot;
1568 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1569 ok(ret, "got %d\n", ret);
1570
1571 if (item.iExpandedImage != 1)
1572 {
1573 win_skip("TVIF_EXPANDEDIMAGE not supported\n");
1574 DestroyWindow(hTree);
1575 return;
1576 }
1577
1578 /* test for default iExpandedImage value */
1579 item.mask = TVIF_EXPANDEDIMAGE;
1580 item.iExpandedImage = -1;
1581 item.hItem = hChild;
1582 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1583 ok(ret, "got %d\n", ret);
1584 ok(item.iExpandedImage == (WORD)I_IMAGENONE, "got %d\n", item.iExpandedImage);
1585
1586 DestroyWindow(hTree);
1587 }
1588
1589 static void test_TVS_SINGLEEXPAND(void)
1590 {
1591 HWND hTree;
1592 BOOL ret;
1593
1594 hTree = create_treeview_control(0);
1595 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_SINGLEEXPAND);
1596 /* to avoid painting related notifications */
1597 ShowWindow(hTree, SW_HIDE);
1598 fill_tree(hTree);
1599
1600 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1601 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hRoot);
1602 ok(ret, "got %d\n", ret);
1603 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_singleexpand_seq, "singleexpand notifications", FALSE);
1604
1605 /* a workaround for NT4 that sends expand notifications when nothing is about to expand */
1606 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hRoot);
1607 ok(ret, "got %d\n", ret);
1608 fill_tree(hTree);
1609 ret = SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, 0);
1610 ok(ret, "got %d\n", ret);
1611
1612 DestroyWindow(hTree);
1613 }
1614
1615 static void test_WM_PAINT(void)
1616 {
1617 HWND hTree;
1618 COLORREF clr;
1619 LONG ret;
1620 RECT rc;
1621 HDC hdc;
1622
1623 hTree = create_treeview_control(0);
1624
1625 clr = SendMessageA(hTree, TVM_SETBKCOLOR, 0, RGB(255, 0, 0));
1626 ok(clr == ~0u, "got %d, expected -1\n", clr);
1627
1628 hdc = GetDC(hMainWnd);
1629
1630 GetClientRect(hMainWnd, &rc);
1631 FillRect(hdc, &rc, GetStockObject(BLACK_BRUSH));
1632
1633 clr = GetPixel(hdc, 1, 1);
1634 ok(clr == RGB(0, 0, 0), "got 0x%x\n", clr);
1635
1636 ret = SendMessageA(hTree, WM_PAINT, (WPARAM)hdc, 0);
1637 ok(ret == 0, "got %d\n", ret);
1638
1639 clr = GetPixel(hdc, 1, 1);
1640 ok(clr == RGB(255, 0, 0) || broken(clr == RGB(0, 0, 0)) /* win98 */,
1641 "got 0x%x\n", clr);
1642
1643 ReleaseDC(hMainWnd, hdc);
1644
1645 DestroyWindow(hTree);
1646 }
1647
1648 static void test_delete_items(void)
1649 {
1650 const struct message *msg;
1651 HWND hTree;
1652 INT ret;
1653
1654 hTree = create_treeview_control(0);
1655 fill_tree(hTree);
1656
1657 /* check delete order */
1658 flush_sequences(item_sequence, 1);
1659 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, 0);
1660 ok(ret == TRUE, "got %d\n", ret);
1661
1662 msg = item_sequence[0]->sequence;
1663 ok(item_sequence[0]->count == 2, "expected 2 items, got %d\n", item_sequence[0]->count);
1664
1665 if (item_sequence[0]->count == 2)
1666 {
1667 ok(msg[0].lParam == (LPARAM)hChild, "expected %p, got 0x%lx\n", hChild, msg[0].lParam);
1668 ok(msg[1].lParam == (LPARAM)hRoot, "expected %p, got 0x%lx\n", hRoot, msg[1].lParam);
1669 }
1670
1671 ret = SendMessageA(hTree, TVM_GETCOUNT, 0, 0);
1672 ok(ret == 0, "got %d\n", ret);
1673
1674 DestroyWindow(hTree);
1675 }
1676
1677 static void test_cchildren(void)
1678 {
1679 HWND hTree;
1680 INT ret;
1681 TVITEMA item;
1682
1683 hTree = create_treeview_control(0);
1684 fill_tree(hTree);
1685
1686 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild);
1687 expect(TRUE, ret);
1688
1689 /* check cChildren - automatic mode */
1690 item.hItem = hRoot;
1691 item.mask = TVIF_CHILDREN;
1692
1693 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1694 expect(TRUE, ret);
1695 expect(0, item.cChildren);
1696
1697 DestroyWindow(hTree);
1698
1699 /* start over */
1700 hTree = create_treeview_control(0);
1701 fill_tree(hTree);
1702
1703 /* turn off automatic mode by setting cChildren explicitly */
1704 item.hItem = hRoot;
1705 item.mask = TVIF_CHILDREN;
1706
1707 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1708 expect(TRUE, ret);
1709 expect(1, item.cChildren);
1710
1711 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1712 expect(TRUE, ret);
1713
1714 ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild);
1715 expect(TRUE, ret);
1716
1717 /* check cChildren */
1718 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1719 expect(TRUE, ret);
1720 todo_wine
1721 expect(1, item.cChildren);
1722
1723 DestroyWindow(hTree);
1724 }
1725
1726 struct _ITEM_DATA
1727 {
1728 HTREEITEM parent; /* for root value of parent field is unidetified */
1729 HTREEITEM nextsibling;
1730 HTREEITEM firstchild;
1731 };
1732
1733 static void _check_item(HTREEITEM item, HTREEITEM parent, HTREEITEM nextsibling, HTREEITEM firstchild, int line)
1734 {
1735 struct _ITEM_DATA *data = (struct _ITEM_DATA*)item;
1736
1737 ok_(__FILE__, line)(data->parent == parent, "parent %p, got %p\n", parent, data->parent);
1738 ok_(__FILE__, line)(data->nextsibling == nextsibling, "sibling %p, got %p\n", nextsibling, data->nextsibling);
1739 ok_(__FILE__, line)(data->firstchild == firstchild, "firstchild %p, got %p\n", firstchild, data->firstchild);
1740 }
1741
1742 #define check_item(a, b, c, d) _check_item(a, b, c, d, __LINE__)
1743
1744 static void test_htreeitem_layout(void)
1745 {
1746 TVINSERTSTRUCTA ins;
1747 HTREEITEM item1, item2;
1748 HWND hTree;
1749
1750 hTree = create_treeview_control(0);
1751 fill_tree(hTree);
1752
1753 /* root has some special pointer in parent field */
1754 check_item(hRoot, ((struct _ITEM_DATA*)hRoot)->parent, 0, hChild);
1755 check_item(hChild, hRoot, 0, 0);
1756
1757 ins.hParent = hChild;
1758 ins.hInsertAfter = TVI_FIRST;
1759 U(ins).item.mask = 0;
1760 item1 = TreeView_InsertItemA(hTree, &ins);
1761
1762 check_item(item1, hChild, 0, 0);
1763
1764 ins.hParent = hRoot;
1765 ins.hInsertAfter = TVI_FIRST;
1766 U(ins).item.mask = 0;
1767 item2 = TreeView_InsertItemA(hTree, &ins);
1768
1769 check_item(item2, hRoot, hChild, 0);
1770
1771 SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hChild);
1772
1773 /* without children now */
1774 check_item(hRoot, ((struct _ITEM_DATA*)hRoot)->parent, 0, item2);
1775
1776 DestroyWindow(hTree);
1777 }
1778
1779 static void test_TVS_CHECKBOXES(void)
1780 {
1781 HIMAGELIST himl, himl2;
1782 HWND hTree, hTree2;
1783 TVITEMA item;
1784 DWORD ret;
1785 MSG msg;
1786
1787 hTree = create_treeview_control(0);
1788 fill_tree(hTree);
1789
1790 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1791 ok(himl == NULL, "got %p\n", himl);
1792
1793 item.hItem = hRoot;
1794 item.mask = TVIF_STATE;
1795 item.state = INDEXTOSTATEIMAGEMASK(1);
1796 item.stateMask = TVIS_STATEIMAGEMASK;
1797 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1798 expect(TRUE, ret);
1799 ok(item.state == 0, "got 0x%x\n", item.state);
1800
1801 /* set some index for a child */
1802 item.hItem = hChild;
1803 item.mask = TVIF_STATE;
1804 item.state = INDEXTOSTATEIMAGEMASK(4);
1805 item.stateMask = TVIS_STATEIMAGEMASK;
1806 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1807 expect(TRUE, ret);
1808
1809 /* enabling check boxes set all items to 1 state image index */
1810 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
1811 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1812 ok(himl != NULL, "got %p\n", himl);
1813
1814 himl2 = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1815 ok(himl2 != NULL, "got %p\n", himl2);
1816 ok(himl2 == himl, "got %p, expected %p\n", himl2, himl);
1817
1818 item.hItem = hRoot;
1819 item.mask = TVIF_STATE;
1820 item.state = 0;
1821 item.stateMask = TVIS_STATEIMAGEMASK;
1822 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1823 expect(TRUE, ret);
1824 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
1825
1826 item.hItem = hChild;
1827 item.mask = TVIF_STATE;
1828 item.state = 0;
1829 item.stateMask = TVIS_STATEIMAGEMASK;
1830 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1831 expect(TRUE, ret);
1832 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
1833
1834 /* create another control and check its checkbox list */
1835 hTree2 = create_treeview_control(0);
1836 fill_tree(hTree2);
1837
1838 /* set some index for a child */
1839 item.hItem = hChild;
1840 item.mask = TVIF_STATE;
1841 item.state = INDEXTOSTATEIMAGEMASK(4);
1842 item.stateMask = TVIS_STATEIMAGEMASK;
1843 ret = SendMessageA(hTree2, TVM_SETITEMA, 0, (LPARAM)&item);
1844 expect(TRUE, ret);
1845
1846 /* enabling check boxes set all items to 1 state image index */
1847 SetWindowLongA(hTree2, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
1848 himl2 = (HIMAGELIST)SendMessageA(hTree2, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1849 ok(himl2 != NULL, "got %p\n", himl2);
1850 ok(himl != himl2, "got %p, expected %p\n", himl2, himl);
1851
1852 DestroyWindow(hTree2);
1853 DestroyWindow(hTree);
1854
1855 /* the same, but initially created with TVS_CHECKBOXES */
1856 hTree = create_treeview_control(TVS_CHECKBOXES);
1857 fill_tree(hTree);
1858 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1859 ok(himl == NULL, "got %p\n", himl);
1860
1861 item.hItem = hRoot;
1862 item.mask = TVIF_STATE;
1863 item.state = 0;
1864 item.stateMask = TVIS_STATEIMAGEMASK;
1865 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1866 expect(TRUE, ret);
1867 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
1868
1869 item.hItem = hChild;
1870 item.mask = TVIF_STATE;
1871 item.state = 0;
1872 item.stateMask = TVIS_STATEIMAGEMASK;
1873 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1874 expect(TRUE, ret);
1875 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
1876
1877 item.hItem = hChild;
1878 item.mask = TVIF_STATE;
1879 item.state = INDEXTOSTATEIMAGEMASK(2);
1880 item.stateMask = TVIS_STATEIMAGEMASK;
1881 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1882 expect(TRUE, ret);
1883
1884 item.hItem = hChild;
1885 item.mask = TVIF_STATE;
1886 item.state = 0;
1887 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1888 expect(TRUE, ret);
1889 ok(item.state == INDEXTOSTATEIMAGEMASK(2), "got 0x%x\n", item.state);
1890
1891 while(GetMessageA(&msg, 0, 0, 0))
1892 {
1893 TranslateMessage(&msg);
1894 DispatchMessageA(&msg);
1895
1896 if((msg.hwnd == hTree) && (msg.message == WM_PAINT))
1897 break;
1898 }
1899
1900 item.hItem = hChild;
1901 item.mask = TVIF_STATE;
1902 item.state = 0;
1903 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1904 expect(TRUE, ret);
1905 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
1906
1907 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1908 ok(himl != NULL, "got %p\n", himl);
1909
1910 DestroyWindow(hTree);
1911
1912 /* check what happens if TVSIL_STATE image list is removed */
1913 hTree = create_treeview_control(0);
1914 fill_tree(hTree);
1915 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1916 ok(himl == NULL, "got %p\n", himl);
1917
1918 SetWindowLongA(hTree, GWL_STYLE, GetWindowLongA(hTree, GWL_STYLE) | TVS_CHECKBOXES);
1919 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1920 ok(himl != NULL, "got %p\n", himl);
1921
1922 himl2 = (HIMAGELIST)SendMessageA(hTree, TVM_SETIMAGELIST, TVSIL_STATE, 0);
1923 ok(himl2 == himl, "got %p\n", himl2);
1924
1925 himl2 = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1926 ok(himl2 == NULL, "got %p\n", himl2);
1927
1928 item.hItem = hChild;
1929 item.mask = TVIF_STATE;
1930 item.state = INDEXTOSTATEIMAGEMASK(2);
1931 item.stateMask = TVIS_STATEIMAGEMASK;
1932 ret = SendMessageA(hTree, TVM_SETITEMA, 0, (LPARAM)&item);
1933 expect(TRUE, ret);
1934
1935 item.hItem = hChild;
1936 item.mask = TVIF_STATE;
1937 item.state = 0;
1938 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1939 expect(TRUE, ret);
1940 ok(item.state == INDEXTOSTATEIMAGEMASK(2), "got 0x%x\n", item.state);
1941
1942 while(GetMessageA(&msg, 0, 0, 0))
1943 {
1944 TranslateMessage(&msg);
1945 DispatchMessageA(&msg);
1946
1947 if((msg.hwnd == hTree) && (msg.message == WM_PAINT))
1948 break;
1949 }
1950
1951 item.hItem = hChild;
1952 item.mask = TVIF_STATE;
1953 item.state = 0;
1954 ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item);
1955 expect(TRUE, ret);
1956 ok(item.state == INDEXTOSTATEIMAGEMASK(1), "got 0x%x\n", item.state);
1957
1958 himl = (HIMAGELIST)SendMessageA(hTree, TVM_GETIMAGELIST, TVSIL_STATE, 0);
1959 ok(himl != NULL, "got %p\n", himl);
1960
1961 DestroyWindow(hTree);
1962 }
1963
1964 static void test_TVM_GETNEXTITEM(void)
1965 {
1966 HTREEITEM item;
1967 HWND hTree;
1968
1969 hTree = create_treeview_control(0);
1970 fill_tree(hTree);
1971
1972 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, 0);
1973 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1974
1975 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, (LPARAM)TVI_ROOT);
1976 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1977
1978 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, (LPARAM)hRoot);
1979 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1980
1981 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, (LPARAM)hChild);
1982 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1983
1984 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CHILD, 0);
1985 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1986
1987 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hRoot);
1988 ok(item == hChild, "got %p, expected %p\n", item, hChild);
1989
1990 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)TVI_ROOT);
1991 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1992
1993 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_PARENT, 0);
1994 ok(item == NULL, "got %p\n", item);
1995
1996 item = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hChild);
1997 ok(item == hRoot, "got %p, expected %p\n", item, hRoot);
1998
1999 DestroyWindow(hTree);
2000 }
2001
2002 static void test_TVM_HITTEST(void)
2003 {
2004 HWND hTree;
2005 LRESULT ret;
2006 RECT rc;
2007 TVHITTESTINFO ht;
2008
2009 hTree = create_treeview_control(0);
2010 fill_tree(hTree);
2011
2012 *(HTREEITEM*)&rc = hRoot;
2013 ret = SendMessageA(hTree, TVM_GETITEMRECT, TRUE, (LPARAM)&rc);
2014 expect(TRUE, (BOOL)ret);
2015
2016 ht.pt.x = rc.left-1;
2017 ht.pt.y = rc.top;
2018
2019 ret = SendMessageA(hTree, TVM_HITTEST, 0, (LPARAM)&ht);
2020 ok((HTREEITEM)ret == hRoot, "got %p, expected %p\n", (HTREEITEM)ret, hRoot);
2021 ok(ht.hItem == hRoot, "got %p, expected %p\n", ht.hItem, hRoot);
2022 ok(ht.flags == TVHT_ONITEMBUTTON, "got %d, expected %d\n", ht.flags, TVHT_ONITEMBUTTON);
2023
2024 ret = SendMessageA(hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hRoot);
2025 expect(TRUE, (BOOL)ret);
2026
2027 *(HTREEITEM*)&rc = hChild;
2028 ret = SendMessageA(hTree, TVM_GETITEMRECT, TRUE, (LPARAM)&rc);
2029 expect(TRUE, (BOOL)ret);
2030
2031 ht.pt.x = rc.left-1;
2032 ht.pt.y = rc.top;
2033
2034 ret = SendMessageA(hTree, TVM_HITTEST, 0, (LPARAM)&ht);
2035 ok((HTREEITEM)ret == hChild, "got %p, expected %p\n", (HTREEITEM)ret, hChild);
2036 ok(ht.hItem == hChild, "got %p, expected %p\n", ht.hItem, hChild);
2037 /* Wine returns item button here, but this item has no button */
2038 todo_wine ok(ht.flags == TVHT_ONITEMINDENT, "got %d, expected %d\n", ht.flags, TVHT_ONITEMINDENT);
2039
2040 DestroyWindow(hTree);
2041 }
2042
2043 static void test_WM_GETDLGCODE(void)
2044 {
2045 DWORD code;
2046 HWND hTree;
2047
2048 hTree = create_treeview_control(0);
2049
2050 code = SendMessageA(hTree, WM_GETDLGCODE, VK_TAB, 0);
2051 ok(code == (DLGC_WANTCHARS | DLGC_WANTARROWS), "0x%08x\n", code);
2052
2053 DestroyWindow(hTree);
2054 }
2055
2056 START_TEST(treeview)
2057 {
2058 HMODULE hComctl32;
2059 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
2060 WNDCLASSA wc;
2061 MSG msg;
2062
2063 ULONG_PTR ctx_cookie;
2064 HANDLE hCtx;
2065
2066 hComctl32 = GetModuleHandleA("comctl32.dll");
2067 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
2068 if (pInitCommonControlsEx)
2069 {
2070 INITCOMMONCONTROLSEX iccex;
2071 iccex.dwSize = sizeof(iccex);
2072 iccex.dwICC = ICC_TREEVIEW_CLASSES;
2073 pInitCommonControlsEx(&iccex);
2074 }
2075 else
2076 InitCommonControls();
2077
2078 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
2079 init_msg_sequences(item_sequence, 1);
2080
2081 wc.style = CS_HREDRAW | CS_VREDRAW;
2082 wc.cbClsExtra = 0;
2083 wc.cbWndExtra = 0;
2084 wc.hInstance = GetModuleHandleA(NULL);
2085 wc.hIcon = NULL;
2086 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_IBEAM);
2087 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
2088 wc.lpszMenuName = NULL;
2089 wc.lpszClassName = "MyTestWnd";
2090 wc.lpfnWndProc = parent_wnd_proc;
2091 RegisterClassA(&wc);
2092
2093 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
2094 CW_USEDEFAULT, CW_USEDEFAULT, 130, 105, NULL, NULL, GetModuleHandleA(NULL), 0);
2095
2096 ok(hMainWnd != NULL, "Failed to create parent window. Tests aborted.\n");
2097 if (!hMainWnd) return;
2098
2099 test_fillroot();
2100 test_select();
2101 test_getitemtext();
2102 test_focus();
2103 test_get_set_bkcolor();
2104 test_get_set_imagelist();
2105 test_get_set_indent();
2106 test_get_set_insertmark();
2107 test_get_set_item();
2108 test_get_set_itemheight();
2109 test_get_set_scrolltime();
2110 test_get_set_textcolor();
2111 test_get_linecolor();
2112 test_get_insertmarkcolor();
2113 test_get_set_tooltips();
2114 test_get_set_unicodeformat();
2115 test_callback();
2116 test_expandinvisible();
2117 test_itemedit();
2118 test_treeview_classinfo();
2119 test_expandnotify();
2120 test_TVS_SINGLEEXPAND();
2121 test_WM_PAINT();
2122 test_delete_items();
2123 test_cchildren();
2124 test_htreeitem_layout();
2125 test_TVS_CHECKBOXES();
2126 test_TVM_GETNEXTITEM();
2127 test_TVM_HITTEST();
2128 test_WM_GETDLGCODE();
2129
2130 if (!load_v6_module(&ctx_cookie, &hCtx))
2131 {
2132 DestroyWindow(hMainWnd);
2133 return;
2134 }
2135
2136 /* comctl32 version 6 tests start here */
2137 test_expandedimage();
2138 test_htreeitem_layout();
2139 test_WM_GETDLGCODE();
2140
2141 unload_v6_module(ctx_cookie, hCtx);
2142
2143 PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
2144 while(GetMessageA(&msg, 0, 0, 0))
2145 {
2146 TranslateMessage(&msg);
2147 DispatchMessageA(&msg);
2148 }
2149 }