1 /* Unit tests for treeview.
3 * Copyright 2005 Krzysztof Foltman
4 * Copyright 2007 Mikolaj Zalewski
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "resources.h"
34 #include "wine/test.h"
37 static BOOL g_fBlockHotItemChange;
38 static BOOL g_fReceivedHotItemChange;
39 static BOOL g_fExpectedHotItemOld;
40 static BOOL g_fExpectedHotItemNew;
42 #define check_rect(name, val, exp) ok(val.top == exp.top && val.bottom == exp.bottom && \
43 val.left == exp.left && val.right == exp.right, "invalid rect (" name ") (%d,%d) (%d,%d) - expected (%d,%d) (%d,%d)\n", \
44 val.left, val.top, val.right, val.bottom, exp.left, exp.top, exp.right, exp.bottom);
46 #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
48 static void MakeButton(TBBUTTON *p, int idCommand, int fsStyle, int nString) {
50 p->idCommand = idCommand;
51 p->fsState = TBSTATE_ENABLED;
56 static LRESULT MyWnd_Notify(LPARAM lParam)
58 NMHDR *hdr = (NMHDR *)lParam;
62 case TBN_HOTITEMCHANGE:
63 nmhi = (NMTBHOTITEM *)lParam;
64 g_fReceivedHotItemChange = TRUE;
65 if (g_fExpectedHotItemOld != g_fExpectedHotItemNew)
67 compare(nmhi->idOld, g_fExpectedHotItemOld, "%d");
68 compare(nmhi->idNew, g_fExpectedHotItemNew, "%d");
70 if (g_fBlockHotItemChange)
77 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
82 return MyWnd_Notify(lParam);
84 return DefWindowProcA(hWnd, msg, wParam, lParam);
87 static void basic_test(void)
93 MakeButton(buttons+i, 1000+i, TBSTYLE_CHECKGROUP, 0);
94 MakeButton(buttons+3, 1003, TBSTYLE_SEP|TBSTYLE_GROUP, 0);
95 MakeButton(buttons+6, 1006, TBSTYLE_SEP, 0);
97 hToolbar = CreateToolbarEx(hMainWnd,
98 WS_VISIBLE | WS_CLIPCHILDREN | CCS_TOP |
99 WS_CHILD | TBSTYLE_LIST,
102 buttons, sizeof(buttons)/sizeof(buttons[0]),
103 0, 0, 20, 16, sizeof(TBBUTTON));
104 ok(hToolbar != NULL, "Toolbar creation\n");
105 SendMessage(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"test\000");
107 /* test for exclusion working inside a separator-separated :-) group */
108 SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 */
109 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
110 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1001, 0), "A2 not pressed\n");
112 SendMessage(hToolbar, TB_CHECKBUTTON, 1004, 1); /* press A5, release A1 */
113 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 pressed\n");
114 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 not pressed anymore\n");
116 SendMessage(hToolbar, TB_CHECKBUTTON, 1005, 1); /* press A6, release A5 */
117 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
118 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 not pressed anymore\n");
120 /* test for inter-group crosstalk, ie. two radio groups interfering with each other */
121 SendMessage(hToolbar, TB_CHECKBUTTON, 1007, 1); /* press B2 */
122 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
123 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 still not pressed\n");
124 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 pressed\n");
126 SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 and ensure B group didn't suffer */
127 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 not pressed anymore\n");
128 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
129 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 still pressed\n");
131 SendMessage(hToolbar, TB_CHECKBUTTON, 1008, 1); /* press B3, and ensure A group didn't suffer */
132 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
133 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
134 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 not pressed\n");
135 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1008, 0), "B3 pressed\n");
136 DestroyWindow(hToolbar);
139 static void rebuild_toolbar(HWND *hToolbar)
141 if (*hToolbar != NULL)
142 DestroyWindow(*hToolbar);
143 *hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
144 hMainWnd, (HMENU)5, GetModuleHandle(NULL), NULL);
145 ok(*hToolbar != NULL, "Toolbar creation problem\n");
146 ok(SendMessage(*hToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
147 ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
148 ok(SendMessage(*hToolbar, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0)==1, "WM_SETFONT\n");
151 static void rebuild_toolbar_with_buttons(HWND *hToolbar)
154 rebuild_toolbar(hToolbar);
156 ZeroMemory(&buttons, sizeof(buttons));
157 buttons[0].idCommand = 1;
158 buttons[0].fsStyle = BTNS_BUTTON;
159 buttons[0].fsState = TBSTATE_ENABLED;
160 buttons[0].iString = -1;
161 buttons[1].idCommand = 3;
162 buttons[1].fsStyle = BTNS_BUTTON;
163 buttons[1].fsState = TBSTATE_ENABLED;
164 buttons[1].iString = -1;
165 buttons[2].idCommand = 5;
166 buttons[2].fsStyle = BTNS_SEP;
167 buttons[2].fsState = TBSTATE_ENABLED;
168 buttons[2].iString = -1;
169 buttons[3].idCommand = 7;
170 buttons[3].fsStyle = BTNS_BUTTON;
171 buttons[3].fsState = TBSTATE_ENABLED;
172 buttons[3].iString = -1;
173 buttons[4].idCommand = 9;
174 buttons[4].fsStyle = BTNS_BUTTON;
175 buttons[4].fsState = 0; /* disabled */
176 buttons[4].iString = -1;
177 ok(SendMessage(*hToolbar, TB_ADDBUTTONS, 5, (LPARAM)buttons) == 1, "TB_ADDBUTTONS failed\n");
178 ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
182 #define CHECK_IMAGELIST(count, dx, dy) { \
184 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
185 ok(himl != NULL, "No image list\n"); \
187 ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
188 ImageList_GetIconSize(himl, &cx, &cy); \
189 ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
193 #define CHECK_IMAGELIST_TODO_COUNT(count, dx, dy) { \
195 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
196 ok(himl != NULL, "No image list\n"); \
198 todo_wine ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
199 ImageList_GetIconSize(himl, &cx, &cy); \
200 ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
204 #define CHECK_IMAGELIST_TODO_COUNT_SIZE(count, dx, dy) { \
206 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
207 ok(himl != NULL, "No image list\n"); \
209 todo_wine ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
210 ImageList_GetIconSize(himl, &cx, &cy); \
211 todo_wine ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
215 static void test_add_bitmap(void)
217 HWND hToolbar = NULL;
220 TBADDBITMAP stdsmall;
225 /* empty 128x15 bitmap */
226 bmp128.hInst = GetModuleHandle(NULL);
227 bmp128.nID = IDB_BITMAP_128x15;
229 /* empty 80x15 bitmap */
230 bmp80.hInst = GetModuleHandle(NULL);
231 bmp80.nID = IDB_BITMAP_80x15;
233 /* standard bitmap - 240x15 pixels */
234 stdsmall.hInst = HINST_COMMCTRL;
235 stdsmall.nID = IDB_STD_SMALL_COLOR;
237 rebuild_toolbar(&hToolbar);
238 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
239 CHECK_IMAGELIST(8, 16, 16);
241 /* adding more bitmaps */
242 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 8, "TB_ADDBITMAP - unexpected return\n");
243 CHECK_IMAGELIST(13, 16, 16);
244 /* adding the same bitmap will simply return the index of the already loaded block */
245 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128);
246 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
247 CHECK_IMAGELIST(13, 16, 16);
248 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
249 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
250 CHECK_IMAGELIST(13, 16, 16);
251 /* even if we increase the wParam */
252 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 55, (LPARAM)&bmp80);
253 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
254 CHECK_IMAGELIST(13, 16, 16);
256 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
257 rebuild_toolbar(&hToolbar);
258 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
259 CHECK_IMAGELIST(8, 16, 16);
260 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
261 ok(ret == 3, "TB_ADDBITMAP - unexpected return %d\n", ret);
262 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
263 CHECK_IMAGELIST(13, 16, 16);
265 /* the same for negative wParam */
266 rebuild_toolbar(&hToolbar);
267 ret = SendMessageA(hToolbar, TB_ADDBITMAP, -143, (LPARAM)&bmp128);
268 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
269 CHECK_IMAGELIST(8, 16, 16);
270 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
271 ok(ret == -143, "TB_ADDBITMAP - unexpected return %d\n", ret);
272 CHECK_IMAGELIST(13, 16, 16);
274 /* for zero only one bitmap will be added */
275 rebuild_toolbar(&hToolbar);
276 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&bmp80);
277 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
278 CHECK_IMAGELIST(1, 16, 16);
280 /* if wParam is larger than the amount of icons, the list is grown */
281 rebuild_toolbar(&hToolbar);
282 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
283 CHECK_IMAGELIST(100, 16, 16);
284 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128);
285 ok(ret == 100, "TB_ADDBITMAP - unexpected return %d\n", ret);
286 CHECK_IMAGELIST(200, 16, 16);
288 /* adding built-in items - the wParam is ignored */
289 rebuild_toolbar(&hToolbar);
290 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
291 CHECK_IMAGELIST(5, 16, 16);
292 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 5, "TB_ADDBITMAP - unexpected return\n");
293 CHECK_IMAGELIST(20, 16, 16);
294 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 20, "TB_ADDBITMAP - unexpected return\n");
295 CHECK_IMAGELIST(28, 16, 16);
297 /* when we increase the bitmap size, less icons will be created */
298 rebuild_toolbar(&hToolbar);
299 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20)) == TRUE, "TB_SETBITMAPSIZE failed\n");
300 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
301 CHECK_IMAGELIST(6, 20, 20);
302 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
303 ok(ret == 1, "TB_ADDBITMAP - unexpected return %d\n", ret);
304 CHECK_IMAGELIST(10, 20, 20);
305 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
306 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
307 UpdateWindow(hToolbar);
308 CHECK_IMAGELIST(26, 8, 8);
309 /* loading a standard bitmaps automatically resizes the icons */
310 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&stdsmall) == 2, "TB_ADDBITMAP - unexpected return\n");
311 UpdateWindow(hToolbar);
312 CHECK_IMAGELIST(28, 16, 16);
314 /* two more SETBITMAPSIZE tests */
315 rebuild_toolbar(&hToolbar);
316 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
317 CHECK_IMAGELIST(100, 16, 16);
318 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 100, "TB_ADDBITMAP - unexpected return\n");
319 CHECK_IMAGELIST(200, 16, 16);
320 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
321 UpdateWindow(hToolbar);
322 CHECK_IMAGELIST(200, 8, 8);
323 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
324 UpdateWindow(hToolbar);
325 CHECK_IMAGELIST(200, 30, 30);
326 rebuild_toolbar(&hToolbar);
327 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
328 CHECK_IMAGELIST(8, 16, 16);
329 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp80) == 5, "TB_ADDBITMAP - unexpected return\n");
330 CHECK_IMAGELIST(13, 16, 16);
331 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
332 UpdateWindow(hToolbar);
333 CHECK_IMAGELIST(8, 30, 30);
334 /* when the width or height is zero, set it to 1 */
335 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
336 UpdateWindow(hToolbar);
337 CHECK_IMAGELIST(208, 1, 1);
338 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 5)) == TRUE, "TB_SETBITMAPSIZE failed\n");
339 UpdateWindow(hToolbar);
340 CHECK_IMAGELIST(208, 1, 5);
341 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(5, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
342 UpdateWindow(hToolbar);
343 CHECK_IMAGELIST(41, 5, 1);
345 /* the control can add bitmaps to an existing image list */
346 rebuild_toolbar(&hToolbar);
347 himl = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_80x15), 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
348 ok(himl != NULL, "failed to create imagelist\n");
349 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
350 CHECK_IMAGELIST(4, 20, 15);
351 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
352 CHECK_IMAGELIST(10, 20, 15);
353 /* however TB_SETBITMAPSIZE/add std bitmap won't change the image size (the button size does change!) */
354 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
355 UpdateWindow(hToolbar);
356 CHECK_IMAGELIST(10, 20, 15);
357 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 1, "TB_SETBITMAPSIZE failed\n");
358 UpdateWindow(hToolbar);
359 CHECK_IMAGELIST_TODO_COUNT(22, 20, 15);
361 /* check standard bitmaps */
362 addbmp.hInst = HINST_COMMCTRL;
363 addbmp.nID = IDB_STD_SMALL_COLOR;
364 rebuild_toolbar(&hToolbar);
365 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
366 CHECK_IMAGELIST(15, 16, 16);
367 addbmp.nID = IDB_STD_LARGE_COLOR;
368 rebuild_toolbar(&hToolbar);
369 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
370 CHECK_IMAGELIST(15, 24, 24);
372 addbmp.nID = IDB_VIEW_SMALL_COLOR;
373 rebuild_toolbar(&hToolbar);
374 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
375 CHECK_IMAGELIST(12, 16, 16);
376 addbmp.nID = IDB_VIEW_LARGE_COLOR;
377 rebuild_toolbar(&hToolbar);
378 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
379 CHECK_IMAGELIST(12, 24, 24);
381 addbmp.nID = IDB_HIST_SMALL_COLOR;
382 rebuild_toolbar(&hToolbar);
383 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
384 CHECK_IMAGELIST(5, 16, 16);
385 addbmp.nID = IDB_HIST_LARGE_COLOR;
386 rebuild_toolbar(&hToolbar);
387 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
388 CHECK_IMAGELIST(5, 24, 24);
391 DestroyWindow(hToolbar);
394 #define CHECK_STRING_TABLE(count, tab) { \
397 for (_i = 0; _i < (count); _i++) {\
398 ret = SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, _i), (LPARAM)_buf); \
399 ok(ret >= 0, "TB_GETSTRING - unexpected return %d while checking string %d\n", ret, _i); \
401 ok(strcmp(_buf, (tab)[_i]) == 0, "Invalid string #%d - '%s' vs '%s'\n", _i, (tab)[_i], _buf); \
403 ok(SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, (count)), (LPARAM)_buf) == -1, \
404 "Too many string in table\n"); \
407 static void test_add_string(void)
409 LPCSTR test1 = "a\0b\0";
410 LPCSTR test2 = "|a|b||\0";
411 LPCSTR ret1[] = {"a", "b"};
412 LPCSTR ret2[] = {"a", "b", "|a|b||"};
413 LPCSTR ret3[] = {"a", "b", "|a|b||", "p", "q"};
414 LPCSTR ret4[] = {"a", "b", "|a|b||", "p", "q", "p"};
415 LPCSTR ret5[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q"};
416 LPCSTR ret6[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q"};
417 LPCSTR ret7[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q", "br", "c", "d"};
418 HWND hToolbar = NULL;
422 rebuild_toolbar(&hToolbar);
423 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test1);
424 ok(ret == 0, "TB_ADDSTRINGA - unexpected return %d\n", ret);
425 CHECK_STRING_TABLE(2, ret1);
426 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test2);
427 ok(ret == 2, "TB_ADDSTRINGA - unexpected return %d\n", ret);
428 CHECK_STRING_TABLE(3, ret2);
430 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD1);
431 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
432 CHECK_STRING_TABLE(3, ret2);
433 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD2);
434 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
435 CHECK_STRING_TABLE(5, ret3);
436 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD3);
437 ok(ret == 5, "TB_ADDSTRINGA - unexpected return %d\n", ret);
438 CHECK_STRING_TABLE(6, ret4);
439 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD4);
440 ok(ret == 6, "TB_ADDSTRINGA - unexpected return %d\n", ret);
441 CHECK_STRING_TABLE(8, ret5);
442 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD5);
443 ok(ret == 8, "TB_ADDSTRINGA - unexpected return %d\n", ret);
444 CHECK_STRING_TABLE(11, ret6);
445 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD7);
446 ok(ret == 11, "TB_ADDSTRINGA - unexpected return %d\n", ret);
447 CHECK_STRING_TABLE(14, ret7);
449 ZeroMemory(&button, sizeof(button));
450 button.iString = (UINT_PTR)"Test";
451 SendMessageA(hToolbar, TB_INSERTBUTTONA, 0, (LPARAM)&button);
452 CHECK_STRING_TABLE(14, ret7);
453 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&button);
454 CHECK_STRING_TABLE(14, ret7);
456 DestroyWindow(hToolbar);
459 static void expect_hot_notify(int idold, int idnew)
461 g_fExpectedHotItemOld = idold;
462 g_fExpectedHotItemNew = idnew;
463 g_fReceivedHotItemChange = FALSE;
466 #define check_hot_notify() \
467 ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
468 g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
470 static void test_hotitem(void)
472 HWND hToolbar = NULL;
476 g_fBlockHotItemChange = FALSE;
478 rebuild_toolbar_with_buttons(&hToolbar);
479 /* set TBSTYLE_FLAT. comctl5 allows hot items only for such toolbars.
480 * comctl6 doesn't have this requirement even when theme == NULL */
481 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_FLAT | GetWindowLong(hToolbar, GWL_STYLE));
482 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
483 ok(ret == -1, "Hot item: %ld, expected -1\n", ret);
484 ret = SendMessage(hToolbar, TB_SETHOTITEM, 1, 0);
485 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
486 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
487 ok(ret == 1, "Hot item: %ld, expected 1\n", ret);
488 ret = SendMessage(hToolbar, TB_SETHOTITEM, 2, 0);
489 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
491 ret = SendMessage(hToolbar, TB_SETHOTITEM, 0xbeef, 0);
492 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
493 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
494 ok(ret == 2, "Hot item: %lx, expected 2\n", ret);
495 ret = SendMessage(hToolbar, TB_SETHOTITEM, -0xbeef, 0);
496 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
497 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
498 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
500 expect_hot_notify(0, 7);
501 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
502 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
504 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
505 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
506 g_fBlockHotItemChange = TRUE;
507 ret = SendMessage(hToolbar, TB_SETHOTITEM, 2, 0);
508 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
509 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
510 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
511 g_fBlockHotItemChange = FALSE;
513 g_fReceivedHotItemChange = FALSE;
514 ret = SendMessage(hToolbar, TB_SETHOTITEM, 0xbeaf, 0);
515 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
516 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received for invalid parameter\n");
518 g_fReceivedHotItemChange = FALSE;
519 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
520 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
521 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received after a duplication\n");
523 expect_hot_notify(7, 0);
524 ret = SendMessage(hToolbar, TB_SETHOTITEM, -0xbeaf, 0);
525 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
527 SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
529 /* setting disabled buttons will generate a notify with the button id but no button will be hot */
530 expect_hot_notify(7, 9);
531 ret = SendMessage(hToolbar, TB_SETHOTITEM, 4, 0);
532 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
534 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
535 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
536 /* enabling the button won't change that */
537 SendMessage(hToolbar, TB_ENABLEBUTTON, 9, TRUE);
538 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
539 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
541 /* disabling a hot button works */
542 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
543 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
544 g_fReceivedHotItemChange = FALSE;
545 SendMessage(hToolbar, TB_ENABLEBUTTON, 7, FALSE);
546 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
547 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
548 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
550 SendMessage(hToolbar, TB_SETHOTITEM, 1, 0);
551 tbinfo.cbSize = sizeof(TBBUTTONINFO);
552 tbinfo.dwMask = TBIF_STATE;
553 tbinfo.fsState = 0; /* disabled */
554 g_fReceivedHotItemChange = FALSE;
555 ok(SendMessage(hToolbar, TB_SETBUTTONINFO, 1, (LPARAM)&tbinfo) == TRUE, "TB_SETBUTTONINFO failed\n");
556 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
557 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
558 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
560 DestroyWindow(hToolbar);
563 #if 0 /* use this to generate more tests*/
565 static void dump_sizes(HWND hToolbar)
569 int count = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0);
572 GetClientRect(hToolbar, &r);
573 SendMessageA(hToolbar, TB_GETMAXSIZE, 0, &sz);
574 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r.left, r.top, r.right, r.bottom,
575 sz.cx, sz.cy, count);
576 for (i=0; i<count; i++)
578 SendMessageA(hToolbar, TB_GETITEMRECT, i, &r);
579 printf("%s{%3d, %3d, %3d, %3d}, ", (i%3==0 ? "\n " : ""), r.left, r.top, r.right, r.bottom);
581 printf("\n }, }, \n");
584 #define check_sizes() dump_sizes(hToolbar);
585 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
597 static tbsize_result_t tbsize_results[] =
599 { {0, 0, 672, 26}, {100, 22}, 5, {
600 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
601 { 54, 2, 77, 24}, { 77, 2, 100, 24},
603 { {0, 0, 672, 26}, {146, 22}, 7, {
604 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
605 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
608 { {0, 0, 672, 48}, {146, 22}, 7, {
609 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
610 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
613 { {0, 0, 672, 26}, {146, 22}, 7, {
614 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
615 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
618 { {0, 0, 672, 26}, {192, 22}, 9, {
619 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
620 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
621 {123, 2, 146, 24}, {146, 2, 169, 24}, {169, 2, 192, 24},
623 { {0, 0, 672, 92}, {882, 22}, 39, {
624 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 0, 2, 8, 29},
625 { 0, 29, 23, 51}, { 23, 29, 46, 51}, { 46, 29, 69, 51},
626 { 69, 29, 92, 51}, { 92, 29, 115, 51}, {115, 29, 138, 51},
627 {138, 29, 161, 51}, {161, 29, 184, 51}, {184, 29, 207, 51},
628 {207, 29, 230, 51}, {230, 29, 253, 51}, {253, 29, 276, 51},
629 {276, 29, 299, 51}, {299, 29, 322, 51}, {322, 29, 345, 51},
630 {345, 29, 368, 51}, {368, 29, 391, 51}, {391, 29, 414, 51},
631 {414, 29, 437, 51}, {437, 29, 460, 51}, {460, 29, 483, 51},
632 {483, 29, 506, 51}, {506, 29, 529, 51}, {529, 29, 552, 51},
633 {552, 29, 575, 51}, {575, 29, 598, 51}, {598, 29, 621, 51},
634 {621, 29, 644, 51}, {644, 29, 667, 51}, { 0, 51, 23, 73},
635 { 23, 51, 46, 73}, { 46, 51, 69, 73}, { 69, 51, 92, 73},
636 { 92, 51, 115, 73}, {115, 51, 138, 73}, {138, 51, 161, 73},
638 { {0, 0, 48, 226}, {23, 140}, 7, {
639 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 94, 24},
640 { 94, 2, 117, 24}, {117, 2, 140, 24}, {140, 2, 163, 24},
643 { {0, 0, 92, 226}, {23, 140}, 7, {
644 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 0, 24, 92, 32},
645 { 0, 32, 23, 54}, { 23, 32, 46, 54}, { 46, 32, 69, 54},
648 { {0, 0, 672, 26}, {194, 30}, 7, {
649 { 0, 2, 31, 32}, { 31, 2, 62, 32}, { 62, 2, 70, 32},
650 { 70, 2, 101, 32}, {101, 2, 132, 32}, {132, 2, 163, 32},
653 { {0, 0, 672, 64}, {194, 30}, 7, {
654 { 0, 2, 31, 32}, { 31, 2, 62, 32}, { 62, 2, 70, 32},
655 { 70, 2, 101, 32}, {101, 2, 132, 32}, {132, 2, 163, 32},
658 { {0, 0, 672, 64}, {194, 30}, 7, {
659 { 0, 0, 31, 30}, { 31, 0, 62, 30}, { 62, 0, 70, 30},
660 { 70, 0, 101, 30}, {101, 0, 132, 30}, {132, 0, 163, 30},
663 { {0, 0, 124, 226}, {31, 188}, 7, {
664 { 0, 0, 31, 30}, { 31, 0, 62, 30}, { 0, 30, 124, 38},
665 { 0, 38, 31, 68}, { 31, 38, 62, 68}, { 62, 38, 93, 68},
668 { {0, 0, 672, 26}, {146, 22}, 7, {
669 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
670 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
673 { {0, 0, 672, 26}, {146, 100}, 7, {
674 { 0, 0, 23, 100}, { 23, 0, 46, 100}, { 46, 0, 54, 100},
675 { 54, 0, 77, 100}, { 77, 0, 100, 100}, {100, 0, 123, 100},
678 { {0, 0, 672, 26}, {215, 100}, 10, {
679 { 0, 0, 23, 100}, { 23, 0, 46, 100}, { 46, 0, 54, 100},
680 { 54, 0, 77, 100}, { 77, 0, 100, 100}, {100, 0, 123, 100},
681 {123, 0, 146, 100}, {146, 0, 169, 100}, {169, 0, 192, 100},
684 { {0, 0, 672, 26}, {238, 39}, 11, {
685 { 0, 0, 23, 39}, { 23, 0, 46, 39}, { 46, 0, 54, 39},
686 { 54, 0, 77, 39}, { 77, 0, 100, 39}, {100, 0, 123, 39},
687 {123, 0, 146, 39}, {146, 0, 169, 39}, {169, 0, 192, 39},
688 {192, 0, 215, 39}, {215, 0, 238, 39},
690 { {0, 0, 672, 26}, {238, 22}, 11, {
691 { 0, 0, 23, 22}, { 23, 0, 46, 22}, { 46, 0, 54, 22},
692 { 54, 0, 77, 22}, { 77, 0, 100, 22}, {100, 0, 123, 22},
693 {123, 0, 146, 22}, {146, 0, 169, 22}, {169, 0, 192, 22},
694 {192, 0, 215, 22}, {215, 0, 238, 22},
696 { {0, 0, 672, 26}, {489, 39}, 3, {
697 { 0, 2, 163, 41}, {163, 2, 330, 41}, {330, 2, 493, 41},
701 static int tbsize_numtests = 0;
703 #define check_sizes_todo(todomask) { \
705 int buttonCount, i, mask=(todomask); \
706 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
707 assert(tbsize_numtests < sizeof(tbsize_results)/sizeof(tbsize_results[0])); \
708 GetClientRect(hToolbar, &rc); \
709 /*check_rect("client", rc, res->rcClient);*/ \
710 buttonCount = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0); \
711 compare(buttonCount, res->nButtons, "%d"); \
712 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
713 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
715 check_rect("button", rc, res->rcButtons[i]); \
717 todo_wine { check_rect("button", rc, res->rcButtons[i]); } \
724 #define check_sizes() check_sizes_todo(0)
728 static TBBUTTON buttons1[] = {
729 {0, 10, TBSTATE_WRAP|TBSTATE_ENABLED, 0, {0, }, 0, -1},
730 {0, 11, 0, 0, {0, }, 0, -1},
732 static TBBUTTON buttons2[] = {
733 {0, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
734 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
736 static TBBUTTON buttons3[] = {
737 {0, 30, TBSTATE_ENABLED, 0, {0, }, 0, 0},
738 {0, 31, TBSTATE_ENABLED, 0, {0, }, 0, 1},
739 {0, 32, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, 1},
740 {0, 33, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, (UINT_PTR)"Tst"}
743 static void test_sizes(void)
745 HWND hToolbar = NULL;
749 rebuild_toolbar_with_buttons(&hToolbar);
750 style = GetWindowLong(hToolbar, GWL_STYLE);
751 ok(style == (WS_CHILD|WS_VISIBLE|CCS_TOP), "Invalid style %x\n", style);
753 /* the TBSTATE_WRAP makes a second row */
754 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
756 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
758 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
759 SetWindowLong(hToolbar, GWL_STYLE, style|TBSTYLE_WRAPABLE);
761 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
762 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
764 /* only after adding enough buttons the bar will be wrapped on a
765 * separator and then on the first button */
767 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
768 check_sizes_todo(0x4);
770 rebuild_toolbar_with_buttons(&hToolbar);
771 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
772 /* setting the buttons vertical will only change the window client size */
773 SetWindowLong(hToolbar, GWL_STYLE, style | CCS_VERT);
774 SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
775 check_sizes_todo(0x3c);
776 /* with a TBSTYLE_WRAPABLE a wrapping will occure on the separator */
777 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_WRAPABLE | CCS_VERT);
778 SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
779 check_sizes_todo(0x7c);
781 rebuild_toolbar_with_buttons(&hToolbar);
782 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
783 /* a TB_SETBITMAPSIZE changes button sizes*/
784 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
787 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
788 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
789 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
791 /* but after a TB_SETBITMAPSIZE the top margins is changed */
792 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20));
793 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
795 /* some vertical toolbar sizes */
796 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT | TBSTYLE_WRAPABLE | CCS_VERT);
797 check_sizes_todo(0x7c);
799 rebuild_toolbar_with_buttons(&hToolbar);
800 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
801 /* newly added buttons will be use the previous margin */
802 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons2);
804 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
805 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
806 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
807 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
808 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
809 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n");
810 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
811 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
812 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
813 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n");
815 /* add some buttons with non-default sizes */
816 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons2);
817 SendMessageA(hToolbar, TB_INSERTBUTTON, -1, (LPARAM)&buttons2[0]);
819 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]);
820 /* TB_ADDSTRING resets the size */
821 SendMessageA(hToolbar, TB_ADDSTRING, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
822 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n");
824 /* TB_SETBUTTONSIZE can be used to crop the text */
825 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
826 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
828 /* except for the first size, the default size is bitmap size + padding */
829 SendMessageA(hToolbar, TB_SETPADDING, 0, MAKELONG(1, 1));
830 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
831 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(17, 17), "Unexpected button size\n");
832 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(3, 3));
833 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
834 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(4, 4), "Unexpected button size\n");
836 rebuild_toolbar(&hToolbar);
837 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
838 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
839 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(16, 15));
840 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 21), "Unexpected button size\n");
842 rebuild_toolbar(&hToolbar);
843 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
844 /* the height is increased after a TB_ADDSTRING */
845 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n");
846 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
847 /* if a string is in the pool, even adding a button without a string resets the size */
848 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons2[0]);
849 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
850 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
851 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
852 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[2]);
853 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 39), "Unexpected button size\n");
854 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]);
856 /* delete button doesn't change the buttons size */
857 SendMessageA(hToolbar, TB_DELETEBUTTON, 2, 0);
858 SendMessageA(hToolbar, TB_DELETEBUTTON, 1, 0);
859 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 39), "Unexpected button size\n");
860 /* TB_INSERTBUTTONS will */
861 SendMessageA(hToolbar, TB_INSERTBUTTON, 1, (LPARAM)&buttons2[0]);
862 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
864 rebuild_toolbar(&hToolbar);
865 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]);
866 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n");
867 SendMessageA(hToolbar, TB_DELETEBUTTON, 0, 0);
868 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n");
870 DestroyWindow(hToolbar);
874 static void test_createtoolbarex()
878 ZeroMemory(&btns, sizeof(btns));
880 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
881 3, 20, 20, 16, 16, sizeof(TBBUTTON));
882 CHECK_IMAGELIST(16, 20, 20);
883 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x1a001b, "%x");
884 DestroyWindow(hToolbar);
886 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
887 3, 4, 4, 16, 16, sizeof(TBBUTTON));
888 CHECK_IMAGELIST(32, 4, 4);
889 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xa000b, "%x");
890 DestroyWindow(hToolbar);
892 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
893 3, 0, 8, 12, 12, sizeof(TBBUTTON));
894 CHECK_IMAGELIST(16, 12, 12);
895 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x120013, "%x");
896 DestroyWindow(hToolbar);
898 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
899 3, -1, 8, 12, 12, sizeof(TBBUTTON));
900 CHECK_IMAGELIST(16, 12, 8);
901 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0013, "%x");
902 DestroyWindow(hToolbar);
904 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
905 3, -1, 8, -1, 12, sizeof(TBBUTTON));
906 CHECK_IMAGELIST(16, 16, 8);
907 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0017, "%x");
908 DestroyWindow(hToolbar);
918 InitCommonControls();
920 wc.style = CS_HREDRAW | CS_VREDRAW;
923 wc.hInstance = GetModuleHandleA(NULL);
925 wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_IBEAM));
926 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
927 wc.lpszMenuName = NULL;
928 wc.lpszClassName = "MyTestWnd";
929 wc.lpfnWndProc = MyWndProc;
932 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
933 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
934 GetClientRect(hMainWnd, &rc);
935 ShowWindow(hMainWnd, SW_SHOW);
942 test_createtoolbarex();
945 while(GetMessageA(&msg,0,0,0)) {
946 TranslateMessage(&msg);
947 DispatchMessageA(&msg);
949 DestroyWindow(hMainWnd);