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 "resources.h"
33 #include "wine/test.h"
37 static void MakeButton(TBBUTTON *p, int idCommand, int fsStyle, int nString) {
39 p->idCommand = idCommand;
40 p->fsState = TBSTATE_ENABLED;
45 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
47 return DefWindowProcA(hWnd, msg, wParam, lParam);
50 static void basic_test(void)
56 MakeButton(buttons+i, 1000+i, TBSTYLE_CHECKGROUP, 0);
57 MakeButton(buttons+3, 1003, TBSTYLE_SEP|TBSTYLE_GROUP, 0);
58 MakeButton(buttons+6, 1006, TBSTYLE_SEP, 0);
60 hToolbar = CreateToolbarEx(hMainWnd,
61 WS_VISIBLE | WS_CLIPCHILDREN | CCS_TOP |
62 WS_CHILD | TBSTYLE_LIST,
65 buttons, sizeof(buttons)/sizeof(buttons[0]),
66 0, 0, 20, 16, sizeof(TBBUTTON));
67 ok(hToolbar != NULL, "Toolbar creation\n");
68 SendMessage(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"test\000");
70 /* test for exclusion working inside a separator-separated :-) group */
71 SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 */
72 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
73 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1001, 0), "A2 not pressed\n");
75 SendMessage(hToolbar, TB_CHECKBUTTON, 1004, 1); /* press A5, release A1 */
76 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 pressed\n");
77 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 not pressed anymore\n");
79 SendMessage(hToolbar, TB_CHECKBUTTON, 1005, 1); /* press A6, release A5 */
80 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
81 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 not pressed anymore\n");
83 /* test for inter-group crosstalk, ie. two radio groups interfering with each other */
84 SendMessage(hToolbar, TB_CHECKBUTTON, 1007, 1); /* press B2 */
85 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
86 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 still not pressed\n");
87 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 pressed\n");
89 SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 and ensure B group didn't suffer */
90 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 not pressed anymore\n");
91 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
92 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 still pressed\n");
94 SendMessage(hToolbar, TB_CHECKBUTTON, 1008, 1); /* press B3, and ensure A group didn't suffer */
95 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
96 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
97 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 not pressed\n");
98 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1008, 0), "B3 pressed\n");
99 DestroyWindow(hToolbar);
102 static void rebuild_toolbar(HWND *hToolbar)
104 if (*hToolbar != NULL)
105 DestroyWindow(*hToolbar);
106 *hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
107 hMainWnd, (HMENU)5, GetModuleHandle(NULL), NULL);
108 ok(*hToolbar != NULL, "Toolbar creation problem\n");
109 ok(SendMessage(*hToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
110 ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
113 #define CHECK_IMAGELIST(count, dx, dy) { \
115 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
116 ok(himl != NULL, "No image list\n"); \
118 ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
119 ImageList_GetIconSize(himl, &cx, &cy); \
120 ok(cx == dx && cy == cy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
124 #define CHECK_IMAGELIST_TODO_COUNT(count, dx, dy) { \
126 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
127 ok(himl != NULL, "No image list\n"); \
129 todo_wine ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
130 ImageList_GetIconSize(himl, &cx, &cy); \
131 ok(cx == dx && cy == cy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
135 #define CHECK_IMAGELIST_TODO_COUNT_SIZE(count, dx, dy) { \
137 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
138 ok(himl != NULL, "No image list\n"); \
140 todo_wine ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
141 ImageList_GetIconSize(himl, &cx, &cy); \
142 todo_wine ok(cx == dx && cy == cy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
146 static void test_add_bitmap(void)
148 HWND hToolbar = NULL;
151 TBADDBITMAP stdsmall;
155 /* empty 128x15 bitmap */
156 bmp128.hInst = GetModuleHandle(NULL);
157 bmp128.nID = IDB_BITMAP_128x15;
159 /* empty 80x15 bitmap */
160 bmp80.hInst = GetModuleHandle(NULL);
161 bmp80.nID = IDB_BITMAP_80x15;
163 /* standard bitmap - 240x15 pixels */
164 stdsmall.hInst = HINST_COMMCTRL;
165 stdsmall.nID = IDB_STD_SMALL_COLOR;
167 rebuild_toolbar(&hToolbar);
168 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
169 CHECK_IMAGELIST(8, 16, 15);
171 /* adding more bitmaps */
172 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 8, "TB_ADDBITMAP - unexpected return\n");
173 CHECK_IMAGELIST(13, 16, 15);
174 /* adding the same bitmap will simply return the index of the already loaded block */
175 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128);
176 todo_wine ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
177 CHECK_IMAGELIST_TODO_COUNT(13, 16, 15);
178 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
179 todo_wine ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
180 CHECK_IMAGELIST_TODO_COUNT(13, 16, 15);
181 /* even if we increase the wParam */
182 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 55, (LPARAM)&bmp80);
183 todo_wine ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
184 CHECK_IMAGELIST_TODO_COUNT(13, 16, 15);
186 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
187 rebuild_toolbar(&hToolbar);
188 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
189 CHECK_IMAGELIST(8, 16, 15);
190 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
191 todo_wine ok(ret == 3, "TB_ADDBITMAP - unexpected return %d\n", ret);
192 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
193 CHECK_IMAGELIST(13, 16, 15);
195 /* the same for negative wParam */
196 rebuild_toolbar(&hToolbar);
197 ret = SendMessageA(hToolbar, TB_ADDBITMAP, -143, (LPARAM)&bmp128);
198 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
199 CHECK_IMAGELIST(8, 16, 15);
200 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
201 todo_wine ok(ret == -143, "TB_ADDBITMAP - unexpected return %d\n", ret);
202 CHECK_IMAGELIST(13, 16, 15);
204 /* for zero only one bitmap will be added */
205 rebuild_toolbar(&hToolbar);
206 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&bmp80);
207 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
208 CHECK_IMAGELIST(1, 16, 15);
210 /* if wParam is larger than the amount of icons, the list is grown */
211 rebuild_toolbar(&hToolbar);
212 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
213 CHECK_IMAGELIST(100, 16, 15);
214 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128);
215 ok(ret == 100, "TB_ADDBITMAP - unexpected return %d\n", ret);
216 CHECK_IMAGELIST(200, 16, 15);
218 /* adding built-in items - the wParam is ignored */
219 rebuild_toolbar(&hToolbar);
220 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
221 CHECK_IMAGELIST(5, 16, 15);
222 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 5, "TB_ADDBITMAP - unexpected return\n");
223 CHECK_IMAGELIST(20, 16, 15);
224 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 20, "TB_ADDBITMAP - unexpected return\n");
225 CHECK_IMAGELIST(28, 16, 15);
227 /* when we increase the bitmap size, less icons will be created */
228 rebuild_toolbar(&hToolbar);
229 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20)) == TRUE, "TB_SETBITMAPSIZE failed\n");
230 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
231 CHECK_IMAGELIST(6, 20, 20);
232 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
233 todo_wine ok(ret == 1, "TB_ADDBITMAP - unexpected return %d\n", ret);
234 CHECK_IMAGELIST(10, 20, 20);
235 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
236 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
237 UpdateWindow(hToolbar);
238 CHECK_IMAGELIST_TODO_COUNT_SIZE(26, 8, 8);
239 /* loading a standard bitmaps automatically resizes the icons */
240 todo_wine ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&stdsmall) == 2, "TB_ADDBITMAP - unexpected return\n");
241 UpdateWindow(hToolbar);
242 CHECK_IMAGELIST_TODO_COUNT_SIZE(28, 16, 15);
244 /* check standard bitmaps */
245 addbmp.hInst = HINST_COMMCTRL;
246 addbmp.nID = IDB_STD_SMALL_COLOR;
247 rebuild_toolbar(&hToolbar);
248 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
249 CHECK_IMAGELIST(15, 16, 15);
250 addbmp.nID = IDB_STD_LARGE_COLOR;
251 rebuild_toolbar(&hToolbar);
252 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
253 CHECK_IMAGELIST(15, 24, 24);
255 addbmp.nID = IDB_VIEW_SMALL_COLOR;
256 rebuild_toolbar(&hToolbar);
257 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
258 CHECK_IMAGELIST(12, 16, 15);
259 addbmp.nID = IDB_VIEW_LARGE_COLOR;
260 rebuild_toolbar(&hToolbar);
261 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
262 CHECK_IMAGELIST(12, 24, 24);
264 addbmp.nID = IDB_HIST_SMALL_COLOR;
265 rebuild_toolbar(&hToolbar);
266 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
267 CHECK_IMAGELIST(5, 16, 15);
268 addbmp.nID = IDB_HIST_LARGE_COLOR;
269 rebuild_toolbar(&hToolbar);
270 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
271 CHECK_IMAGELIST(5, 24, 24);
274 DestroyWindow(hToolbar);
283 InitCommonControls();
285 wc.style = CS_HREDRAW | CS_VREDRAW;
288 wc.hInstance = GetModuleHandleA(NULL);
290 wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_IBEAM));
291 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
292 wc.lpszMenuName = NULL;
293 wc.lpszClassName = "MyTestWnd";
294 wc.lpfnWndProc = MyWndProc;
297 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
298 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
299 GetClientRect(hMainWnd, &rc);
300 ShowWindow(hMainWnd, SW_SHOW);
306 while(GetMessageA(&msg,0,0,0)) {
307 TranslateMessage(&msg);
308 DispatchMessageA(&msg);
310 DestroyWindow(hMainWnd);