1 /* Unit tests for treeview.
3 * Copyright 2005 Krzysztof Foltman
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/test.h"
36 static HTREEITEM hRoot, hChild;
39 static char sequence[256];
41 static void Clear(void)
47 static void AddItem(char ch)
53 static void IdentifyItem(HTREEITEM hItem)
59 if (hItem == hChild) {
70 static void FillRoot(void)
74 static CHAR root[] = "Root",
79 ins.hParent = TVI_ROOT;
80 ins.hInsertAfter = TVI_ROOT;
81 U(ins).item.mask = TVIF_TEXT;
82 U(ins).item.pszText = root;
83 hRoot = TreeView_InsertItem(hTree, &ins);
86 /* UMLPad 1.15 depends on this being not -1 (I_IMAGECALLBACK) */
88 tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
89 SendMessage( hTree, TVM_GETITEM, 0, (LPARAM)&tvi );
90 ok(tvi.iImage == 0, "tvi.iImage=%d\n", tvi.iImage);
91 ok(tvi.iSelectedImage == 0, "tvi.iSelectedImage=%d\n", tvi.iSelectedImage);
95 ins.hInsertAfter = TVI_FIRST;
96 U(ins).item.mask = TVIF_TEXT;
97 U(ins).item.pszText = child;
98 hChild = TreeView_InsertItem(hTree, &ins);
102 ok(!strcmp(sequence, "AB."), "Item creation\n");
105 static void DoTest1(void)
108 r = TreeView_SelectItem(hTree, NULL);
111 r = TreeView_SelectItem(hTree, hRoot);
113 r = TreeView_SelectItem(hTree, hRoot);
115 r = TreeView_SelectItem(hTree, NULL);
117 r = TreeView_SelectItem(hTree, NULL);
119 r = TreeView_SelectItem(hTree, hRoot);
121 ok(!strcmp(sequence, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test\n");
124 static void DoTest2(void)
127 r = TreeView_SelectItem(hTree, NULL);
130 r = TreeView_SelectItem(hTree, hRoot);
132 r = TreeView_SelectItem(hTree, hRoot);
134 r = TreeView_SelectItem(hTree, hChild);
136 r = TreeView_SelectItem(hTree, hChild);
138 r = TreeView_SelectItem(hTree, hRoot);
140 ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
143 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
149 hTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL, WS_CHILD|WS_VISIBLE|
150 TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS,
151 0, 0, 300, 50, hWnd, (HMENU)100, GetModuleHandleA(0), 0);
158 NMHDR *pHdr = (NMHDR *)lParam;
160 if (pHdr->idFrom == 100) {
161 NMTREEVIEWA *pTreeView = (LPNMTREEVIEWA) lParam;
163 case TVN_SELCHANGINGA:
165 IdentifyItem(pTreeView->itemOld.hItem);
166 IdentifyItem(pTreeView->itemNew.hItem);
168 case TVN_SELCHANGEDA:
170 IdentifyItem(pTreeView->itemOld.hItem);
171 IdentifyItem(pTreeView->itemNew.hItem);
179 MoveWindow(hTree, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
187 return DefWindowProcA(hWnd, msg, wParam, lParam);
196 INITCOMMONCONTROLSEX icex;
199 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
200 icex.dwICC = ICC_TREEVIEW_CLASSES;
201 InitCommonControlsEx(&icex);
203 wc.style = CS_HREDRAW | CS_VREDRAW;
206 wc.hInstance = GetModuleHandleA(NULL);
208 wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_IBEAM));
209 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
210 wc.lpszMenuName = NULL;
211 wc.lpszClassName = "MyTestWnd";
212 wc.lpfnWndProc = MyWndProc;
216 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
217 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
218 GetClientRect(hMainWnd, &rc);
224 PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
225 while(GetMessageA(&msg,0,0,0)) {
226 TranslateMessage(&msg);
227 DispatchMessageA(&msg);