1 /* Unit tests for toolbar.
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;
41 static DWORD g_dwExpectedDispInfoMask;
43 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
45 #define check_rect(name, val, exp) ok(val.top == exp.top && val.bottom == exp.bottom && \
46 val.left == exp.left && val.right == exp.right, "invalid rect (" name ") (%d,%d) (%d,%d) - expected (%d,%d) (%d,%d)\n", \
47 val.left, val.top, val.right, val.bottom, exp.left, exp.top, exp.right, exp.bottom);
49 #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
51 static void MakeButton(TBBUTTON *p, int idCommand, int fsStyle, int nString) {
53 p->idCommand = idCommand;
54 p->fsState = TBSTATE_ENABLED;
59 static LRESULT MyWnd_Notify(LPARAM lParam)
61 NMHDR *hdr = (NMHDR *)lParam;
66 case TBN_HOTITEMCHANGE:
67 nmhi = (NMTBHOTITEM *)lParam;
68 g_fReceivedHotItemChange = TRUE;
69 if (g_fExpectedHotItemOld != g_fExpectedHotItemNew)
71 compare(nmhi->idOld, g_fExpectedHotItemOld, "%d");
72 compare(nmhi->idNew, g_fExpectedHotItemNew, "%d");
74 if (g_fBlockHotItemChange)
78 case TBN_GETDISPINFOA:
79 ok(FALSE, "TBN_GETDISPINFOA received\n");
82 case TBN_GETDISPINFOW:
83 nmdisp = (NMTBDISPINFOA *)lParam;
85 compare(nmdisp->dwMask, g_dwExpectedDispInfoMask, "%x");
86 ok(nmdisp->pszText == NULL, "pszText is not NULL\n");
92 static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
97 return MyWnd_Notify(lParam);
99 return DefWindowProcA(hWnd, msg, wParam, lParam);
102 static void basic_test(void)
108 MakeButton(buttons+i, 1000+i, TBSTYLE_CHECKGROUP, 0);
109 MakeButton(buttons+3, 1003, TBSTYLE_SEP|TBSTYLE_GROUP, 0);
110 MakeButton(buttons+6, 1006, TBSTYLE_SEP, 0);
112 hToolbar = CreateToolbarEx(hMainWnd,
113 WS_VISIBLE | WS_CLIPCHILDREN | CCS_TOP |
114 WS_CHILD | TBSTYLE_LIST,
117 buttons, sizeof(buttons)/sizeof(buttons[0]),
118 0, 0, 20, 16, sizeof(TBBUTTON));
119 ok(hToolbar != NULL, "Toolbar creation\n");
120 SendMessage(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"test\000");
122 /* test for exclusion working inside a separator-separated :-) group */
123 SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 */
124 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
125 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1001, 0), "A2 not pressed\n");
127 SendMessage(hToolbar, TB_CHECKBUTTON, 1004, 1); /* press A5, release A1 */
128 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 pressed\n");
129 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 not pressed anymore\n");
131 SendMessage(hToolbar, TB_CHECKBUTTON, 1005, 1); /* press A6, release A5 */
132 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
133 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 not pressed anymore\n");
135 /* test for inter-group crosstalk, ie. two radio groups interfering with each other */
136 SendMessage(hToolbar, TB_CHECKBUTTON, 1007, 1); /* press B2 */
137 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
138 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 still not pressed\n");
139 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 pressed\n");
141 SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 and ensure B group didn't suffer */
142 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 not pressed anymore\n");
143 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
144 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 still pressed\n");
146 SendMessage(hToolbar, TB_CHECKBUTTON, 1008, 1); /* press B3, and ensure A group didn't suffer */
147 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
148 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
149 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 not pressed\n");
150 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1008, 0), "B3 pressed\n");
152 /* tests with invalid index */
153 compare(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 0xdeadbeef, 0), -1L, "%ld");
154 compare(SendMessage(hToolbar, TB_ISBUTTONPRESSED, 0xdeadbeef, 0), -1L, "%ld");
155 compare(SendMessage(hToolbar, TB_ISBUTTONENABLED, 0xdeadbeef, 0), -1L, "%ld");
156 compare(SendMessage(hToolbar, TB_ISBUTTONINDETERMINATE, 0xdeadbeef, 0), -1L, "%ld");
157 compare(SendMessage(hToolbar, TB_ISBUTTONHIGHLIGHTED, 0xdeadbeef, 0), -1L, "%ld");
158 compare(SendMessage(hToolbar, TB_ISBUTTONHIDDEN, 0xdeadbeef, 0), -1L, "%ld");
160 DestroyWindow(hToolbar);
163 static void rebuild_toolbar(HWND *hToolbar)
166 DestroyWindow(*hToolbar);
167 *hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
168 hMainWnd, (HMENU)5, GetModuleHandle(NULL), NULL);
169 ok(*hToolbar != NULL, "Toolbar creation problem\n");
170 ok(SendMessage(*hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
171 ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
172 ok(SendMessage(*hToolbar, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0)==1, "WM_SETFONT\n");
175 static void rebuild_toolbar_with_buttons(HWND *hToolbar)
178 rebuild_toolbar(hToolbar);
180 ZeroMemory(&buttons, sizeof(buttons));
181 buttons[0].idCommand = 1;
182 buttons[0].fsStyle = BTNS_BUTTON;
183 buttons[0].fsState = TBSTATE_ENABLED;
184 buttons[0].iString = -1;
185 buttons[1].idCommand = 3;
186 buttons[1].fsStyle = BTNS_BUTTON;
187 buttons[1].fsState = TBSTATE_ENABLED;
188 buttons[1].iString = -1;
189 buttons[2].idCommand = 5;
190 buttons[2].fsStyle = BTNS_SEP;
191 buttons[2].fsState = TBSTATE_ENABLED;
192 buttons[2].iString = -1;
193 buttons[3].idCommand = 7;
194 buttons[3].fsStyle = BTNS_BUTTON;
195 buttons[3].fsState = TBSTATE_ENABLED;
196 buttons[3].iString = -1;
197 buttons[4].idCommand = 9;
198 buttons[4].fsStyle = BTNS_BUTTON;
199 buttons[4].fsState = 0; /* disabled */
200 buttons[4].iString = -1;
201 ok(SendMessage(*hToolbar, TB_ADDBUTTONS, 5, (LPARAM)buttons) == 1, "TB_ADDBUTTONS failed\n");
202 ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
205 static void add_128x15_bitmap(HWND hToolbar, int nCmds)
208 bmp128.hInst = GetModuleHandle(NULL);
209 bmp128.nID = IDB_BITMAP_128x15;
210 ok(SendMessageA(hToolbar, TB_ADDBITMAP, nCmds, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
213 #define CHECK_IMAGELIST(count, dx, dy) { \
215 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
216 ok(himl != NULL, "No image list\n"); \
218 ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
219 ImageList_GetIconSize(himl, &cx, &cy); \
220 ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
224 static void test_add_bitmap(void)
226 HWND hToolbar = NULL;
229 TBADDBITMAP stdsmall;
234 /* empty 128x15 bitmap */
235 bmp128.hInst = GetModuleHandle(NULL);
236 bmp128.nID = IDB_BITMAP_128x15;
238 /* empty 80x15 bitmap */
239 bmp80.hInst = GetModuleHandle(NULL);
240 bmp80.nID = IDB_BITMAP_80x15;
242 /* standard bitmap - 240x15 pixels */
243 stdsmall.hInst = HINST_COMMCTRL;
244 stdsmall.nID = IDB_STD_SMALL_COLOR;
246 rebuild_toolbar(&hToolbar);
247 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
248 CHECK_IMAGELIST(8, 16, 16);
250 /* adding more bitmaps */
251 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 8, "TB_ADDBITMAP - unexpected return\n");
252 CHECK_IMAGELIST(13, 16, 16);
253 /* adding the same bitmap will simply return the index of the already loaded block */
254 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128);
255 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
256 CHECK_IMAGELIST(13, 16, 16);
257 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
258 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
259 CHECK_IMAGELIST(13, 16, 16);
260 /* even if we increase the wParam */
261 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 55, (LPARAM)&bmp80);
262 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
263 CHECK_IMAGELIST(13, 16, 16);
265 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
266 rebuild_toolbar(&hToolbar);
267 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
268 CHECK_IMAGELIST(8, 16, 16);
269 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
270 ok(ret == 3, "TB_ADDBITMAP - unexpected return %d\n", ret);
271 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
272 CHECK_IMAGELIST(13, 16, 16);
274 /* the same for negative wParam */
275 rebuild_toolbar(&hToolbar);
276 ret = SendMessageA(hToolbar, TB_ADDBITMAP, -143, (LPARAM)&bmp128);
277 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
278 CHECK_IMAGELIST(8, 16, 16);
279 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
280 ok(ret == -143, "TB_ADDBITMAP - unexpected return %d\n", ret);
281 CHECK_IMAGELIST(13, 16, 16);
283 /* for zero only one bitmap will be added */
284 rebuild_toolbar(&hToolbar);
285 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&bmp80);
286 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
287 CHECK_IMAGELIST(1, 16, 16);
289 /* if wParam is larger than the amount of icons, the list is grown */
290 rebuild_toolbar(&hToolbar);
291 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
292 CHECK_IMAGELIST(100, 16, 16);
293 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128);
294 ok(ret == 100, "TB_ADDBITMAP - unexpected return %d\n", ret);
295 CHECK_IMAGELIST(200, 16, 16);
297 /* adding built-in items - the wParam is ignored */
298 rebuild_toolbar(&hToolbar);
299 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
300 CHECK_IMAGELIST(5, 16, 16);
301 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 5, "TB_ADDBITMAP - unexpected return\n");
302 CHECK_IMAGELIST(20, 16, 16);
303 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 20, "TB_ADDBITMAP - unexpected return\n");
304 CHECK_IMAGELIST(28, 16, 16);
306 /* when we increase the bitmap size, less icons will be created */
307 rebuild_toolbar(&hToolbar);
308 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20)) == TRUE, "TB_SETBITMAPSIZE failed\n");
309 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
310 CHECK_IMAGELIST(6, 20, 20);
311 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
312 ok(ret == 1, "TB_ADDBITMAP - unexpected return %d\n", ret);
313 CHECK_IMAGELIST(10, 20, 20);
314 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
315 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
316 UpdateWindow(hToolbar);
317 CHECK_IMAGELIST(26, 8, 8);
318 /* loading a standard bitmaps automatically resizes the icons */
319 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&stdsmall) == 2, "TB_ADDBITMAP - unexpected return\n");
320 UpdateWindow(hToolbar);
321 CHECK_IMAGELIST(28, 16, 16);
323 /* two more SETBITMAPSIZE tests */
324 rebuild_toolbar(&hToolbar);
325 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
326 CHECK_IMAGELIST(100, 16, 16);
327 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 100, "TB_ADDBITMAP - unexpected return\n");
328 CHECK_IMAGELIST(200, 16, 16);
329 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
330 UpdateWindow(hToolbar);
331 CHECK_IMAGELIST(200, 8, 8);
332 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
333 UpdateWindow(hToolbar);
334 CHECK_IMAGELIST(200, 30, 30);
335 rebuild_toolbar(&hToolbar);
336 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
337 CHECK_IMAGELIST(8, 16, 16);
338 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp80) == 5, "TB_ADDBITMAP - unexpected return\n");
339 CHECK_IMAGELIST(13, 16, 16);
340 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
341 UpdateWindow(hToolbar);
342 CHECK_IMAGELIST(8, 30, 30);
343 /* when the width or height is zero, set it to 1 */
344 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
345 UpdateWindow(hToolbar);
346 CHECK_IMAGELIST(208, 1, 1);
347 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 5)) == TRUE, "TB_SETBITMAPSIZE failed\n");
348 UpdateWindow(hToolbar);
349 CHECK_IMAGELIST(208, 1, 5);
350 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(5, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
351 UpdateWindow(hToolbar);
352 CHECK_IMAGELIST(41, 5, 1);
354 /* the control can add bitmaps to an existing image list */
355 rebuild_toolbar(&hToolbar);
356 himl = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_80x15), 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
357 ok(himl != NULL, "failed to create imagelist\n");
358 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
359 CHECK_IMAGELIST(4, 20, 15);
360 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
361 CHECK_IMAGELIST(10, 20, 15);
362 /* however TB_SETBITMAPSIZE/add std bitmap won't change the image size (the button size does change) */
363 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
364 UpdateWindow(hToolbar);
365 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(15, 14), "%x");
366 CHECK_IMAGELIST(10, 20, 15);
367 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 1, "TB_SETBITMAPSIZE failed\n");
368 UpdateWindow(hToolbar);
369 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(23, 22), "%x");
370 CHECK_IMAGELIST(22, 20, 15);
372 /* check standard bitmaps */
373 addbmp.hInst = HINST_COMMCTRL;
374 addbmp.nID = IDB_STD_SMALL_COLOR;
375 rebuild_toolbar(&hToolbar);
376 ImageList_Destroy(himl);
378 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
379 CHECK_IMAGELIST(15, 16, 16);
380 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(23, 22), "%x");
381 addbmp.nID = IDB_STD_LARGE_COLOR;
382 rebuild_toolbar(&hToolbar);
383 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
384 CHECK_IMAGELIST(15, 24, 24);
385 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(31, 30), "%x");
387 addbmp.nID = IDB_VIEW_SMALL_COLOR;
388 rebuild_toolbar(&hToolbar);
389 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
390 CHECK_IMAGELIST(12, 16, 16);
391 addbmp.nID = IDB_VIEW_LARGE_COLOR;
392 rebuild_toolbar(&hToolbar);
393 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
394 CHECK_IMAGELIST(12, 24, 24);
396 addbmp.nID = IDB_HIST_SMALL_COLOR;
397 rebuild_toolbar(&hToolbar);
398 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
399 CHECK_IMAGELIST(5, 16, 16);
400 addbmp.nID = IDB_HIST_LARGE_COLOR;
401 rebuild_toolbar(&hToolbar);
402 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
403 CHECK_IMAGELIST(5, 24, 24);
406 DestroyWindow(hToolbar);
409 #define CHECK_STRING_TABLE(count, tab) { \
412 for (_i = 0; _i < (count); _i++) {\
413 ret = SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, _i), (LPARAM)_buf); \
414 ok(ret >= 0, "TB_GETSTRING - unexpected return %d while checking string %d\n", ret, _i); \
416 ok(strcmp(_buf, (tab)[_i]) == 0, "Invalid string #%d - '%s' vs '%s'\n", _i, (tab)[_i], _buf); \
418 ok(SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, (count)), (LPARAM)_buf) == -1, \
419 "Too many strings in table\n"); \
422 static void test_add_string(void)
424 LPCSTR test1 = "a\0b\0";
425 LPCSTR test2 = "|a|b||\0";
426 LPCSTR ret1[] = {"a", "b"};
427 LPCSTR ret2[] = {"a", "b", "|a|b||"};
428 LPCSTR ret3[] = {"a", "b", "|a|b||", "p", "q"};
429 LPCSTR ret4[] = {"a", "b", "|a|b||", "p", "q", "p"};
430 LPCSTR ret5[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q"};
431 LPCSTR ret6[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q"};
432 LPCSTR ret7[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q", "br", "c", "d"};
433 HWND hToolbar = NULL;
438 rebuild_toolbar(&hToolbar);
439 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test1);
440 ok(ret == 0, "TB_ADDSTRINGA - unexpected return %d\n", ret);
441 ret = SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, 1), (LPARAM)buf);
444 win_skip("TB_GETSTRING needs 5.80\n");
447 CHECK_STRING_TABLE(2, ret1);
448 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test2);
449 ok(ret == 2, "TB_ADDSTRINGA - unexpected return %d\n", ret);
450 CHECK_STRING_TABLE(3, ret2);
452 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD1);
453 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
454 CHECK_STRING_TABLE(3, ret2);
455 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD2);
456 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
457 CHECK_STRING_TABLE(5, ret3);
458 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD3);
459 ok(ret == 5, "TB_ADDSTRINGA - unexpected return %d\n", ret);
460 CHECK_STRING_TABLE(6, ret4);
461 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD4);
462 ok(ret == 6, "TB_ADDSTRINGA - unexpected return %d\n", ret);
463 CHECK_STRING_TABLE(8, ret5);
464 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD5);
465 ok(ret == 8, "TB_ADDSTRINGA - unexpected return %d\n", ret);
466 CHECK_STRING_TABLE(11, ret6);
467 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD7);
468 ok(ret == 11, "TB_ADDSTRINGA - unexpected return %d\n", ret);
469 CHECK_STRING_TABLE(14, ret7);
471 ZeroMemory(&button, sizeof(button));
472 button.iString = (UINT_PTR)"Test";
473 SendMessageA(hToolbar, TB_INSERTBUTTONA, 0, (LPARAM)&button);
474 CHECK_STRING_TABLE(14, ret7);
475 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&button);
476 CHECK_STRING_TABLE(14, ret7);
478 DestroyWindow(hToolbar);
481 static void expect_hot_notify(int idold, int idnew)
483 g_fExpectedHotItemOld = idold;
484 g_fExpectedHotItemNew = idnew;
485 g_fReceivedHotItemChange = FALSE;
488 #define check_hot_notify() \
489 ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
490 g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
492 static void test_hotitem(void)
494 HWND hToolbar = NULL;
498 g_fBlockHotItemChange = FALSE;
500 rebuild_toolbar_with_buttons(&hToolbar);
501 /* set TBSTYLE_FLAT. comctl5 allows hot items only for such toolbars.
502 * comctl6 doesn't have this requirement even when theme == NULL */
503 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_FLAT | GetWindowLong(hToolbar, GWL_STYLE));
504 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
505 ok(ret == -1, "Hot item: %ld, expected -1\n", ret);
506 ret = SendMessage(hToolbar, TB_SETHOTITEM, 1, 0);
507 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
508 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
509 ok(ret == 1, "Hot item: %ld, expected 1\n", ret);
510 ret = SendMessage(hToolbar, TB_SETHOTITEM, 2, 0);
511 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
513 ret = SendMessage(hToolbar, TB_SETHOTITEM, 0xbeef, 0);
514 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
515 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
516 ok(ret == 2, "Hot item: %lx, expected 2\n", ret);
517 ret = SendMessage(hToolbar, TB_SETHOTITEM, -0xbeef, 0);
518 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
519 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
520 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
522 expect_hot_notify(0, 7);
523 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
524 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
526 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
527 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
528 g_fBlockHotItemChange = TRUE;
529 ret = SendMessage(hToolbar, TB_SETHOTITEM, 2, 0);
530 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
531 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
532 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
533 g_fBlockHotItemChange = FALSE;
535 g_fReceivedHotItemChange = FALSE;
536 ret = SendMessage(hToolbar, TB_SETHOTITEM, 0xbeaf, 0);
537 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
538 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received for invalid parameter\n");
540 g_fReceivedHotItemChange = FALSE;
541 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
542 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
543 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received after a duplication\n");
545 expect_hot_notify(7, 0);
546 ret = SendMessage(hToolbar, TB_SETHOTITEM, -0xbeaf, 0);
547 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
549 SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
551 /* setting disabled buttons will generate a notify with the button id but no button will be hot */
552 expect_hot_notify(7, 9);
553 ret = SendMessage(hToolbar, TB_SETHOTITEM, 4, 0);
554 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
556 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
557 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
558 /* enabling the button won't change that */
559 SendMessage(hToolbar, TB_ENABLEBUTTON, 9, TRUE);
560 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
561 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
563 /* disabling a hot button works */
564 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
565 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
566 g_fReceivedHotItemChange = FALSE;
567 SendMessage(hToolbar, TB_ENABLEBUTTON, 7, FALSE);
568 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
569 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
570 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
572 SendMessage(hToolbar, TB_SETHOTITEM, 1, 0);
573 tbinfo.cbSize = sizeof(TBBUTTONINFO);
574 tbinfo.dwMask = TBIF_STATE;
575 tbinfo.fsState = 0; /* disabled */
576 g_fReceivedHotItemChange = FALSE;
577 ok(SendMessage(hToolbar, TB_SETBUTTONINFO, 1, (LPARAM)&tbinfo) == TRUE, "TB_SETBUTTONINFO failed\n");
578 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
579 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
580 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
582 DestroyWindow(hToolbar);
585 #if 0 /* use this to generate more tests*/
587 static void dump_sizes(HWND hToolbar)
591 int count = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0);
594 GetClientRect(hToolbar, &r);
595 SendMessageA(hToolbar, TB_GETMAXSIZE, 0, &sz);
596 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r.left, r.top, r.right, r.bottom,
597 sz.cx, sz.cy, count);
598 for (i=0; i<count; i++)
600 SendMessageA(hToolbar, TB_GETITEMRECT, i, &r);
601 printf("%s{%3d, %3d, %3d, %3d}, ", (i%3==0 ? "\n " : ""), r.left, r.top, r.right, r.bottom);
603 printf("\n }, },\n");
606 #define check_sizes() dump_sizes(hToolbar);
607 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
619 static tbsize_result_t tbsize_results[] =
621 { {0, 0, 672, 26}, {100, 22}, 5, {
622 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
623 { 54, 2, 77, 24}, { 77, 2, 100, 24},
625 { {0, 0, 672, 26}, {146, 22}, 7, {
626 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
627 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
630 { {0, 0, 672, 48}, {146, 22}, 7, {
631 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
632 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
635 { {0, 0, 672, 26}, {146, 22}, 7, {
636 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
637 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
640 { {0, 0, 672, 26}, {192, 22}, 9, {
641 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
642 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
643 {123, 2, 146, 24}, {146, 2, 169, 24}, {169, 2, 192, 24},
645 { {0, 0, 672, 92}, {882, 22}, 39, {
646 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 0, 2, 8, 29},
647 { 0, 29, 23, 51}, { 23, 29, 46, 51}, { 46, 29, 69, 51},
648 { 69, 29, 92, 51}, { 92, 29, 115, 51}, {115, 29, 138, 51},
649 {138, 29, 161, 51}, {161, 29, 184, 51}, {184, 29, 207, 51},
650 {207, 29, 230, 51}, {230, 29, 253, 51}, {253, 29, 276, 51},
651 {276, 29, 299, 51}, {299, 29, 322, 51}, {322, 29, 345, 51},
652 {345, 29, 368, 51}, {368, 29, 391, 51}, {391, 29, 414, 51},
653 {414, 29, 437, 51}, {437, 29, 460, 51}, {460, 29, 483, 51},
654 {483, 29, 506, 51}, {506, 29, 529, 51}, {529, 29, 552, 51},
655 {552, 29, 575, 51}, {575, 29, 598, 51}, {598, 29, 621, 51},
656 {621, 29, 644, 51}, {644, 29, 667, 51}, { 0, 51, 23, 73},
657 { 23, 51, 46, 73}, { 46, 51, 69, 73}, { 69, 51, 92, 73},
658 { 92, 51, 115, 73}, {115, 51, 138, 73}, {138, 51, 161, 73},
660 { {0, 0, 48, 226}, {23, 140}, 7, {
661 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 94, 24},
662 { 94, 2, 117, 24}, {117, 2, 140, 24}, {140, 2, 163, 24},
665 { {0, 0, 92, 226}, {23, 140}, 7, {
666 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 0, 24, 92, 32},
667 { 0, 32, 23, 54}, { 23, 32, 46, 54}, { 46, 32, 69, 54},
670 { {0, 0, 672, 26}, {194, 30}, 7, {
671 { 0, 2, 31, 32}, { 31, 2, 62, 32}, { 62, 2, 70, 32},
672 { 70, 2, 101, 32}, {101, 2, 132, 32}, {132, 2, 163, 32},
675 { {0, 0, 672, 64}, {194, 30}, 7, {
676 { 0, 2, 31, 32}, { 31, 2, 62, 32}, { 62, 2, 70, 32},
677 { 70, 2, 101, 32}, {101, 2, 132, 32}, {132, 2, 163, 32},
680 { {0, 0, 672, 64}, {194, 30}, 7, {
681 { 0, 0, 31, 30}, { 31, 0, 62, 30}, { 62, 0, 70, 30},
682 { 70, 0, 101, 30}, {101, 0, 132, 30}, {132, 0, 163, 30},
685 { {0, 0, 124, 226}, {31, 188}, 7, {
686 { 0, 0, 31, 30}, { 31, 0, 62, 30}, { 0, 30, 124, 38},
687 { 0, 38, 31, 68}, { 31, 38, 62, 68}, { 62, 38, 93, 68},
690 { {0, 0, 672, 26}, {146, 22}, 7, {
691 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
692 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
695 { {0, 0, 672, 26}, {146, 100}, 7, {
696 { 0, 0, 23, 100}, { 23, 0, 46, 100}, { 46, 0, 54, 100},
697 { 54, 0, 77, 100}, { 77, 0, 100, 100}, {100, 0, 123, 100},
700 { {0, 0, 672, 26}, {215, 100}, 10, {
701 { 0, 0, 23, 100}, { 23, 0, 46, 100}, { 46, 0, 54, 100},
702 { 54, 0, 77, 100}, { 77, 0, 100, 100}, {100, 0, 123, 100},
703 {123, 0, 146, 100}, {146, 0, 169, 100}, {169, 0, 192, 100},
706 { {0, 0, 672, 26}, {238, 39}, 11, {
707 { 0, 0, 23, 39}, { 23, 0, 46, 39}, { 46, 0, 54, 39},
708 { 54, 0, 77, 39}, { 77, 0, 100, 39}, {100, 0, 123, 39},
709 {123, 0, 146, 39}, {146, 0, 169, 39}, {169, 0, 192, 39},
710 {192, 0, 215, 39}, {215, 0, 238, 39},
712 { {0, 0, 672, 26}, {238, 22}, 11, {
713 { 0, 0, 23, 22}, { 23, 0, 46, 22}, { 46, 0, 54, 22},
714 { 54, 0, 77, 22}, { 77, 0, 100, 22}, {100, 0, 123, 22},
715 {123, 0, 146, 22}, {146, 0, 169, 22}, {169, 0, 192, 22},
716 {192, 0, 215, 22}, {215, 0, 238, 22},
718 { {0, 0, 672, 26}, {489, 39}, 3, {
719 { 0, 2, 163, 41}, {163, 2, 330, 41}, {330, 2, 493, 41},
721 { {0, 0, 672, 104}, {978, 24}, 6, {
722 { 0, 2, 163, 26}, {163, 2, 326, 26}, {326, 2, 489, 26},
723 {489, 2, 652, 26}, {652, 2, 819, 26}, {819, 2, 850, 26},
725 { {0, 0, 672, 28}, {978, 38}, 6, {
726 { 0, 0, 163, 38}, {163, 0, 326, 38}, {326, 0, 489, 38},
727 {489, 0, 652, 38}, {652, 0, 819, 38}, {819, 0, 850, 38},
729 { {0, 0, 672, 100}, {239, 102}, 3, {
730 { 0, 2, 100, 102}, {100, 2, 139, 102}, {139, 2, 239, 102},
732 { {0, 0, 672, 42}, {185, 40}, 3, {
733 { 0, 2, 75, 40}, {75, 2, 118, 40}, {118, 2, 185, 40},
735 { {0, 0, 672, 42}, {67, 40}, 1, {
738 { {0, 0, 672, 42}, {67, 41}, 2, {
739 { 0, 2, 672, 41}, { 0, 41, 672, 80},
743 static int tbsize_numtests = 0;
750 } tbsize_alt_result_t;
752 static tbsize_alt_result_t tbsize_alt_results[] =
754 { 5, 2, { 0, 24, 8, 29 } },
755 { 20, 1, { 100, 2, 107, 102 } },
756 { 20, 2, { 107, 2, 207, 102 } }
759 static int tbsize_alt_numtests = 0;
761 #define check_sizes_todo(todomask) { \
763 int buttonCount, i, mask=(todomask); \
764 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
765 assert(tbsize_numtests < sizeof(tbsize_results)/sizeof(tbsize_results[0])); \
766 GetClientRect(hToolbar, &rc); \
767 /*check_rect("client", rc, res->rcClient);*/ \
768 buttonCount = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0); \
769 compare(buttonCount, res->nButtons, "%d"); \
770 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
771 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
772 if (broken(tbsize_alt_numtests < sizeof(tbsize_alt_results)/sizeof(tbsize_alt_results[0]) && \
773 memcmp(&rc, &tbsize_alt_results[tbsize_alt_numtests].rcButton, sizeof(RECT)) == 0)) { \
774 win_skip("Alternate rect found\n"); \
775 tbsize_alt_numtests++; \
776 } else if (!(mask&1)) { \
777 check_rect("button", rc, res->rcButtons[i]); \
779 todo_wine { check_rect("button", rc, res->rcButtons[i]); } \
786 #define check_sizes() check_sizes_todo(0)
790 static TBBUTTON buttons1[] = {
791 {0, 10, TBSTATE_WRAP|TBSTATE_ENABLED, 0, {0, }, 0, -1},
792 {0, 11, 0, 0, {0, }, 0, -1},
794 static TBBUTTON buttons2[] = {
795 {0, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
796 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
798 static TBBUTTON buttons3[] = {
799 {0, 30, TBSTATE_ENABLED, 0, {0, }, 0, 0},
800 {0, 31, TBSTATE_ENABLED, 0, {0, }, 0, 1},
801 {0, 32, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, 1},
802 {0, 33, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, (UINT_PTR)"Tst"}
805 static void test_sizes(void)
807 HWND hToolbar = NULL;
808 HIMAGELIST himl, himl2;
813 rebuild_toolbar_with_buttons(&hToolbar);
814 style = GetWindowLong(hToolbar, GWL_STYLE);
815 ok(style == (WS_CHILD|WS_VISIBLE|CCS_TOP), "Invalid style %x\n", style);
817 /* the TBSTATE_WRAP makes a second row */
818 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
820 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
822 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
823 SetWindowLong(hToolbar, GWL_STYLE, style|TBSTYLE_WRAPABLE);
825 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
826 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
828 /* only after adding enough buttons the bar will be wrapped on a
829 * separator and then on the first button */
831 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
832 check_sizes_todo(0x4);
834 rebuild_toolbar_with_buttons(&hToolbar);
835 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
836 /* setting the buttons vertical will only change the window client size */
837 SetWindowLong(hToolbar, GWL_STYLE, style | CCS_VERT);
838 SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
839 check_sizes_todo(0x3c);
840 /* with a TBSTYLE_WRAPABLE a wrapping will occur on the separator */
841 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_WRAPABLE | CCS_VERT);
842 SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
843 check_sizes_todo(0x7c);
845 rebuild_toolbar_with_buttons(&hToolbar);
846 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
847 /* a TB_SETBITMAPSIZE changes button sizes*/
848 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
851 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
852 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
853 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
855 /* but after a TB_SETBITMAPSIZE the top margins is changed */
856 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20));
857 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
859 /* some vertical toolbar sizes */
860 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT | TBSTYLE_WRAPABLE | CCS_VERT);
861 check_sizes_todo(0x7c);
863 rebuild_toolbar_with_buttons(&hToolbar);
864 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
865 /* newly added buttons will be use the previous margin */
866 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons2);
868 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
869 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
870 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
871 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
872 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
873 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n");
874 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
875 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
876 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
877 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n");
879 /* add some buttons with non-default sizes */
880 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons2);
881 SendMessageA(hToolbar, TB_INSERTBUTTON, -1, (LPARAM)&buttons2[0]);
883 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]);
884 /* TB_ADDSTRING resets the size */
885 SendMessageA(hToolbar, TB_ADDSTRING, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
886 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n");
888 /* TB_SETBUTTONSIZE can be used to crop the text */
889 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
890 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
892 /* the default size is bitmap size + padding */
893 SendMessageA(hToolbar, TB_SETPADDING, 0, MAKELONG(1, 1));
894 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
895 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(17, 17), "Unexpected button size\n");
896 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(3, 3));
897 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
898 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(4, 4), "Unexpected button size\n");
900 rebuild_toolbar(&hToolbar);
901 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
902 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
903 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(16, 15));
904 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 21), "Unexpected button size\n");
905 /* -1 in TB_SETBITMAPSIZE is a special code meaning that the coordinate shouldn't be changed */
906 add_128x15_bitmap(hToolbar, 16);
907 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(14, -1)), "TB_SETBITMAPSIZE failed\n");
908 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 21), "%x");
909 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, 12)), "TB_SETBITMAPSIZE failed\n");
910 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
911 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, -1)), "TB_SETBITMAPSIZE failed\n");
912 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
913 /* check the imagelist */
914 InvalidateRect(hToolbar, NULL, TRUE);
915 UpdateWindow(hToolbar);
916 CHECK_IMAGELIST(16, 14, 12);
918 rebuild_toolbar(&hToolbar);
919 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
920 /* the height is increased after a TB_ADDSTRING */
921 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n");
922 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
923 /* if a string is in the pool, even adding a button without a string resets the size */
924 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons2[0]);
925 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
926 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
927 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
928 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[2]);
929 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 39), "Unexpected button size\n");
930 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]);
932 /* delete button doesn't change the buttons size */
933 SendMessageA(hToolbar, TB_DELETEBUTTON, 2, 0);
934 SendMessageA(hToolbar, TB_DELETEBUTTON, 1, 0);
935 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 39), "Unexpected button size\n");
936 /* TB_INSERTBUTTONS will */
937 SendMessageA(hToolbar, TB_INSERTBUTTON, 1, (LPARAM)&buttons2[0]);
938 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
940 /* TB_HIDEBUTTON and TB_MOVEBUTTON doesn't force a recalc */
941 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
942 ok(SendMessageA(hToolbar, TB_MOVEBUTTON, 0, 1), "TB_MOVEBUTTON failed\n");
943 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
944 ok(SendMessageA(hToolbar, TB_HIDEBUTTON, 20, TRUE), "TB_HIDEBUTTON failed\n");
945 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
946 /* however changing the hidden flag with TB_SETSTATE does */
947 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED|TBSTATE_HIDDEN), "TB_SETSTATE failed\n");
948 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
949 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED), "TB_SETSTATE failed\n");
950 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
952 /* TB_SETIMAGELIST always changes the height but the width only if necessary */
953 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
954 himl = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_80x15), 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
955 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
956 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 21), "Unexpected button size\n");
957 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
958 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
959 /* But there are no update when we change imagelist, and image sizes are the same */
960 himl2 = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_128x15), 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
961 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LRESULT)himl2) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
962 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
963 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
964 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 21), "Unexpected button size\n");
965 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl2, "TB_SETIMAGELIST failed\n");
966 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 7), "Unexpected button size\n");
967 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
968 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(8, 7), "Unexpected button size\n");
969 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
970 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 21), "Unexpected button size\n");
971 /* the text is taken into account */
972 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
973 SendMessageA(hToolbar, TB_ADDBUTTONS, 4, (LPARAM)buttons3);
974 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 38), "Unexpected button size\n");
975 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
976 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 24), "Unexpected button size\n");
977 /* the style change also comes into effect */
979 SetWindowLong(hToolbar, GWL_STYLE, GetWindowLong(hToolbar, GWL_STYLE) | TBSTYLE_FLAT);
980 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
981 check_sizes_todo(0x30); /* some small problems with BTNS_AUTOSIZE button sizes */
983 rebuild_toolbar(&hToolbar);
984 ImageList_Destroy(himl);
985 ImageList_Destroy(himl2);
987 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]);
988 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n");
989 SendMessageA(hToolbar, TB_DELETEBUTTON, 0, 0);
990 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n");
992 rebuild_toolbar(&hToolbar);
994 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
995 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
996 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons2[0]) == 1, "TB_ADDBUTTONS failed\n");
997 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[2]) == 1, "TB_ADDBUTTONS failed\n");
998 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]) == 1, "TB_ADDBUTTONS failed\n");
999 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1002 rebuild_toolbar(&hToolbar);
1003 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_LIST | GetWindowLong(hToolbar, GWL_STYLE));
1004 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1005 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1006 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons2[0]) == 1, "TB_ADDBUTTONS failed\n");
1007 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[2]) == 1, "TB_ADDBUTTONS failed\n");
1008 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
1009 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1010 check_sizes_todo(0xff);
1012 rebuild_toolbar(&hToolbar);
1013 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_LIST | GetWindowLong(hToolbar, GWL_STYLE));
1014 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1015 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1016 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
1017 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1020 rebuild_toolbar(&hToolbar);
1021 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_WRAPABLE | GetWindowLong(hToolbar, GWL_STYLE));
1022 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
1023 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
1025 tbinfo.cbSize = sizeof(TBBUTTONINFO);
1026 tbinfo.dwMask = TBIF_SIZE | TBIF_BYINDEX;
1027 if (SendMessageA(hToolbar, TB_SETBUTTONINFO, 0, (LPARAM)&tbinfo))
1029 ok(SendMessageA(hToolbar, TB_SETBUTTONINFO, 1, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFO failed\n");
1030 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1033 else /* TBIF_BYINDEX probably not supported, confirm that this was the reason for the failure */
1035 tbinfo.dwMask = TBIF_SIZE;
1036 ok(SendMessageA(hToolbar, TB_SETBUTTONINFO, 33, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFO failed\n");
1039 DestroyWindow(hToolbar);
1042 /* Toolbar control has two ways of reacting to a change. We call them a
1043 * relayout and recalc. A recalc forces a recompute of values like button size
1044 * and top margin (the latter in comctl32 <v6), while a relayout uses the cached
1045 * values. This functions creates a flat toolbar with a top margin of a non-flat
1046 * toolbar. We will notice a recalc, as it will recompte the top margin and
1047 * change it to zero*/
1048 static void prepare_recalc_test(HWND *phToolbar)
1051 rebuild_toolbar_with_buttons(phToolbar);
1052 SetWindowLong(*phToolbar, GWL_STYLE,
1053 GetWindowLong(*phToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1054 SendMessage(*phToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1055 ok(rect.top == 2, "Test will make no sense because initial top is %d instead of 2\n",
1059 static BOOL did_recalc(HWND hToolbar)
1062 SendMessage(hToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1063 ok(rect.top == 2 || rect.top == 0, "Unexpected top margin %d in recalc test\n",
1065 return (rect.top == 0);
1068 /* call after a recalc did happen to return to an unstable state */
1069 static void restore_recalc_state(HWND hToolbar)
1072 /* return to style with a 2px top margin */
1073 SetWindowLong(hToolbar, GWL_STYLE,
1074 GetWindowLong(hToolbar, GWL_STYLE) & ~TBSTYLE_FLAT);
1076 SendMessage(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]);
1077 /* top margin will be 0px if a recalc occurs */
1078 SetWindowLong(hToolbar, GWL_STYLE,
1079 GetWindowLong(hToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1081 SendMessage(hToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1082 ok(rect.top == 2, "Test will make no sense because initial top is %d instead of 2\n",
1086 static void test_recalc(void)
1088 HWND hToolbar = NULL;
1090 CHAR test[] = "Test";
1091 const int EX_STYLES_COUNT = 5;
1095 /* Like TB_ADDBUTTONS tested in test_sized, inserting a button without text
1096 * results in a relayout, while adding one with text forces a recalc */
1097 prepare_recalc_test(&hToolbar);
1098 SendMessage(hToolbar, TB_INSERTBUTTON, 1, (LPARAM)&buttons3[0]);
1099 recalc = did_recalc(hToolbar);
1100 ok(!recalc, "Unexpected recalc - adding button without text\n");
1102 prepare_recalc_test(&hToolbar);
1103 SendMessage(hToolbar, TB_INSERTBUTTON, 1, (LPARAM)&buttons3[3]);
1104 recalc = did_recalc(hToolbar);
1105 ok(recalc, "Expected a recalc - adding button with text\n");
1107 /* TB_SETBUTTONINFO, even when adding a text, results only in a relayout */
1108 prepare_recalc_test(&hToolbar);
1109 bi.cbSize = sizeof(bi);
1110 bi.dwMask = TBIF_TEXT;
1112 SendMessage(hToolbar, TB_SETBUTTONINFO, 1, (LPARAM)&bi);
1113 recalc = did_recalc(hToolbar);
1114 ok(!recalc, "Unexpected recalc - setting a button text\n");
1116 /* most extended styled doesn't force a recalc (testing all the bits gives
1117 * the same results, but prints some ERRs while testing) */
1118 for (i = 0; i < EX_STYLES_COUNT; i++)
1120 if (i == 1 || i == 3) /* an undoc style and TBSTYLE_EX_MIXEDBUTTONS */
1122 prepare_recalc_test(&hToolbar);
1123 expect(0, (int)SendMessage(hToolbar, TB_GETEXTENDEDSTYLE, 0, 0));
1124 SendMessage(hToolbar, TB_SETEXTENDEDSTYLE, 0, (1 << i));
1125 recalc = did_recalc(hToolbar);
1126 ok(!recalc, "Unexpected recalc - setting bit %d\n", i);
1127 SendMessage(hToolbar, TB_SETEXTENDEDSTYLE, 0, 0);
1128 recalc = did_recalc(hToolbar);
1129 ok(!recalc, "Unexpected recalc - clearing bit %d\n", i);
1130 expect(0, (int)SendMessage(hToolbar, TB_GETEXTENDEDSTYLE, 0, 0));
1133 /* TBSTYLE_EX_MIXEDBUTTONS does a recalc on change */
1134 prepare_recalc_test(&hToolbar);
1135 SendMessage(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1136 recalc = did_recalc(hToolbar);
1139 ok(recalc, "Expected a recalc - setting TBSTYLE_EX_MIXEDBUTTONS\n");
1140 restore_recalc_state(hToolbar);
1141 SendMessage(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1142 recalc = did_recalc(hToolbar);
1143 ok(!recalc, "Unexpected recalc - setting TBSTYLE_EX_MIXEDBUTTONS again\n");
1144 restore_recalc_state(hToolbar);
1145 SendMessage(hToolbar, TB_SETEXTENDEDSTYLE, 0, 0);
1146 recalc = did_recalc(hToolbar);
1147 ok(recalc, "Expected a recalc - clearing TBSTYLE_EX_MIXEDBUTTONS\n");
1149 else win_skip( "No recalc on TBSTYLE_EX_MIXEDBUTTONS\n" );
1151 /* undocumented exstyle 0x2 seems to changes the top margin, what
1152 * interferes with these tests */
1154 DestroyWindow(hToolbar);
1157 static void test_getbuttoninfo(void)
1159 HWND hToolbar = NULL;
1162 rebuild_toolbar_with_buttons(&hToolbar);
1163 for (i = 0; i < 128; i++)
1169 tbi.dwMask = TBIF_COMMAND;
1170 ret = (int)SendMessage(hToolbar, TB_GETBUTTONINFO, 1, (LPARAM)&tbi);
1171 if (i == sizeof(TBBUTTONINFO)) {
1172 compare(ret, 0, "%d");
1174 compare(ret, -1, "%d");
1177 DestroyWindow(hToolbar);
1180 static void test_createtoolbarex(void)
1184 ZeroMemory(&btns, sizeof(btns));
1186 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1187 3, 20, 20, 16, 16, sizeof(TBBUTTON));
1188 CHECK_IMAGELIST(16, 20, 20);
1189 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x1a001b, "%x");
1190 DestroyWindow(hToolbar);
1192 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1193 3, 4, 4, 16, 16, sizeof(TBBUTTON));
1194 CHECK_IMAGELIST(32, 4, 4);
1195 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xa000b, "%x");
1196 DestroyWindow(hToolbar);
1198 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1199 3, 0, 8, 12, 12, sizeof(TBBUTTON));
1200 CHECK_IMAGELIST(16, 12, 12);
1201 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x120013, "%x");
1202 DestroyWindow(hToolbar);
1204 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1205 3, -1, 8, 12, 12, sizeof(TBBUTTON));
1206 CHECK_IMAGELIST(16, 12, 8);
1207 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0013, "%x");
1208 DestroyWindow(hToolbar);
1210 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1211 3, -1, 8, -1, 12, sizeof(TBBUTTON));
1212 CHECK_IMAGELIST(16, 16, 8);
1213 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0017, "%x");
1214 DestroyWindow(hToolbar);
1216 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1217 3, 0, 0, 12, -1, sizeof(TBBUTTON));
1218 CHECK_IMAGELIST(16, 12, 16);
1219 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160013, "%x");
1220 DestroyWindow(hToolbar);
1222 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1223 3, 0, 0, 0, 12, sizeof(TBBUTTON));
1224 CHECK_IMAGELIST(16, 16, 16);
1225 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160017, "%x");
1226 DestroyWindow(hToolbar);
1229 static void test_dispinfo(void)
1231 HWND hToolbar = NULL;
1232 const TBBUTTON buttons_disp[] = {
1233 {-1, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1234 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1238 rebuild_toolbar(&hToolbar);
1239 SendMessageA(hToolbar, TB_LOADIMAGES, IDB_HIST_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
1240 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons_disp);
1241 g_dwExpectedDispInfoMask = TBNF_IMAGE;
1242 /* Some TBN_GETDISPINFO tests will be done in MyWnd_Notify function.
1243 * We will receive TBN_GETDISPINFOW even if the control is ANSI */
1244 compare((BOOL)SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0, "%d");
1245 ShowWindow(hToolbar, SW_SHOW);
1246 UpdateWindow(hToolbar);
1248 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, TRUE, 0);
1249 compare(ret, FALSE, "%d");
1250 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 1L, "%ld");
1251 InvalidateRect(hToolbar, NULL, FALSE);
1252 UpdateWindow(hToolbar);
1254 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, FALSE, 0);
1255 compare(ret, TRUE, "%d");
1256 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0L, "%ld");
1257 InvalidateRect(hToolbar, NULL, FALSE);
1258 UpdateWindow(hToolbar);
1260 DestroyWindow(hToolbar);
1261 g_dwExpectedDispInfoMask = 0;
1271 static tbrows_result_t tbrows_results[] =
1273 {1, TRUE, 1}, /* 0: Simple case 9 in a row */
1274 {2, TRUE, 2}, /* 1: Another simple case 5 on one row, 4 on another*/
1275 {3, FALSE, 3}, /* 2: 3 lines - should be 3 lines of 3 buttons */
1276 {8, FALSE, 5}, /* 3: 8 lines - should be 5 lines of 2 buttons */
1277 {8, TRUE, 9}, /* 4: 8 lines but grow - should be 9 lines */
1278 {1, TRUE, 1} /* 5: Back to simple case */
1281 static void test_setrows(void)
1283 TBBUTTON buttons[9];
1288 MakeButton(buttons+i, 1000+i, TBSTYLE_FLAT | TBSTYLE_CHECKGROUP, 0);
1290 /* Test 1 - 9 buttons */
1291 hToolbar = CreateToolbarEx(hMainWnd,
1292 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD | CCS_NORESIZE | CCS_NOPARENTALIGN
1293 | CCS_NOMOVEY | CCS_TOP,
1296 buttons, sizeof(buttons)/sizeof(buttons[0]),
1297 20, 20, 0, 0, sizeof(TBBUTTON));
1298 ok(hToolbar != NULL, "Toolbar creation\n");
1299 ok(SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
1301 /* test setting rows to each of 1-10 with bLarger true and false */
1302 for (i=0; i<(sizeof(tbrows_results) / sizeof(tbrows_result_t)); i++) {
1306 memset(&rc, 0xCC, sizeof(rc));
1307 SendMessageA(hToolbar, TB_SETROWS,
1308 MAKELONG(tbrows_results[i].nRows, tbrows_results[i].bLarger),
1311 rows = SendMessageA(hToolbar, TB_GETROWS, MAKELONG(0,0), MAKELONG(0,0));
1312 ok(rows == tbrows_results[i].expectedRows,
1313 "[%d] Unexpected number of rows %d (expected %d)\n", i, rows,
1314 tbrows_results[i].expectedRows);
1317 DestroyWindow(hToolbar);
1320 static void test_getstring(void)
1322 HWND hToolbar = NULL;
1325 static const char answer[] = "STR";
1326 static const WCHAR answerW[] = { 'S','T','R',0 };
1329 hToolbar = CreateWindowExA(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hMainWnd, (HMENU)5, GetModuleHandle(NULL), NULL);
1330 ok(hToolbar != NULL, "Toolbar creation problem\n");
1332 r = SendMessage(hToolbar, TB_GETSTRING, MAKEWPARAM(0, 0), 0);
1335 win_skip("TB_GETSTRING and TB_GETSTRINGW need 5.80\n");
1336 DestroyWindow(hToolbar);
1340 r = SendMessage(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1342 r = SendMessage(hToolbar, TB_ADDSTRING, 0, (LPARAM)answer);
1344 r = SendMessage(hToolbar, TB_GETSTRING, MAKEWPARAM(0, 0), 0);
1345 expect(lstrlenA(answer), r);
1346 r = SendMessage(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1347 expect(lstrlenA(answer), r);
1348 r = SendMessage(hToolbar, TB_GETSTRING, MAKEWPARAM(sizeof(str), 0), (LPARAM)str);
1349 expect(lstrlenA(answer), r);
1350 expect(0, lstrcmp(answer, str));
1351 r = SendMessage(hToolbar, TB_GETSTRINGW, MAKEWPARAM(sizeof(strW), 0), (LPARAM)strW);
1352 expect(lstrlenA(answer), r);
1353 expect(0, lstrcmpW(answerW, strW));
1355 DestroyWindow(hToolbar);
1364 InitCommonControls();
1366 wc.style = CS_HREDRAW | CS_VREDRAW;
1369 wc.hInstance = GetModuleHandleA(NULL);
1371 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
1372 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1373 wc.lpszMenuName = NULL;
1374 wc.lpszClassName = "MyTestWnd";
1375 wc.lpfnWndProc = MyWndProc;
1376 RegisterClassA(&wc);
1378 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
1379 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
1380 GetClientRect(hMainWnd, &rc);
1381 ShowWindow(hMainWnd, SW_SHOW);
1389 test_getbuttoninfo();
1390 test_createtoolbarex();
1396 while(GetMessageA(&msg,0,0,0)) {
1397 TranslateMessage(&msg);
1398 DispatchMessageA(&msg);
1400 DestroyWindow(hMainWnd);