wer: Add new stubbed wer.dll.
[wine/hramrach.git] / dlls / comctl32 / tests / toolbar.c
blob8311df575ec6378e28ef3468a9bf105cf95d065e
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
21 #include <assert.h>
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winnls.h"
29 #include "winreg.h"
30 #include "commctrl.h"
32 #include "resources.h"
34 #include "wine/test.h"
36 #include "msg.h"
38 #define PARENT_SEQ_INDEX 0
39 #define NUM_MSG_SEQUENCES 1
41 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
43 static HWND hMainWnd;
44 static BOOL g_fBlockHotItemChange;
45 static BOOL g_fReceivedHotItemChange;
46 static BOOL g_fExpectedHotItemOld;
47 static BOOL g_fExpectedHotItemNew;
48 static DWORD g_dwExpectedDispInfoMask;
49 static BOOL g_ResetDispTextPtr;
51 static const struct message ttgetdispinfo_parent_seq[] = {
52 { WM_NOTIFY, sent|id, 0, 0, TBN_GETINFOTIPA },
53 /* next line is todo, currently TTN_GETDISPINFOW is raised here */
54 { WM_NOTIFY, sent|id, 0, 0, TTN_GETDISPINFOA },
55 { 0 }
58 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
60 #define check_rect(name, val, exp) ok(val.top == exp.top && val.bottom == exp.bottom && \
61 val.left == exp.left && val.right == exp.right, "invalid rect (" name ") (%d,%d) (%d,%d) - expected (%d,%d) (%d,%d)\n", \
62 val.left, val.top, val.right, val.bottom, exp.left, exp.top, exp.right, exp.bottom);
64 #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
66 static void MakeButton(TBBUTTON *p, int idCommand, int fsStyle, int nString) {
67 p->iBitmap = -2;
68 p->idCommand = idCommand;
69 p->fsState = TBSTATE_ENABLED;
70 p->fsStyle = fsStyle;
71 p->iString = nString;
74 static LRESULT parent_wnd_notify(LPARAM lParam)
76 NMHDR *hdr = (NMHDR *)lParam;
77 NMTBHOTITEM *nmhi;
78 NMTBDISPINFO *nmdisp;
79 switch (hdr->code)
81 case TBN_HOTITEMCHANGE:
82 nmhi = (NMTBHOTITEM *)lParam;
83 g_fReceivedHotItemChange = TRUE;
84 if (g_fExpectedHotItemOld != g_fExpectedHotItemNew)
86 compare(nmhi->idOld, g_fExpectedHotItemOld, "%d");
87 compare(nmhi->idNew, g_fExpectedHotItemNew, "%d");
89 if (g_fBlockHotItemChange)
90 return 1;
91 break;
93 case TBN_GETDISPINFOA:
94 ok(FALSE, "TBN_GETDISPINFOA received\n");
95 break;
97 case TBN_GETINFOTIPA:
99 NMTBGETINFOTIPA *tbgit = (NMTBGETINFOTIPA*)lParam;
101 if (g_ResetDispTextPtr)
103 tbgit->pszText = NULL;
104 return 0;
106 break;
108 case TBN_GETDISPINFOW:
109 nmdisp = (NMTBDISPINFOA *)lParam;
111 compare(nmdisp->dwMask, g_dwExpectedDispInfoMask, "%x");
112 ok(nmdisp->pszText == NULL, "pszText is not NULL\n");
113 break;
115 return 0;
118 static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
120 static LONG defwndproc_counter = 0;
121 struct message msg;
122 LRESULT ret;
124 msg.message = message;
125 msg.flags = sent|wparam|lparam;
126 if (defwndproc_counter) msg.flags |= defwinproc;
127 msg.wParam = wParam;
128 msg.lParam = lParam;
129 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
131 /* log system messages, except for painting */
132 if (message < WM_USER &&
133 message != WM_PAINT &&
134 message != WM_ERASEBKGND &&
135 message != WM_NCPAINT &&
136 message != WM_NCHITTEST &&
137 message != WM_GETTEXT &&
138 message != WM_GETICON &&
139 message != WM_DEVICECHANGE)
141 trace("parent: %p, %04x, %08lx, %08lx\n", hWnd, message, wParam, lParam);
142 add_message(sequences, PARENT_SEQ_INDEX, &msg);
145 switch (message)
147 case WM_NOTIFY:
148 return parent_wnd_notify(lParam);
151 defwndproc_counter++;
152 ret = DefWindowProcA(hWnd, message, wParam, lParam);
153 defwndproc_counter--;
155 return ret;
158 static void basic_test(void)
160 TBBUTTON buttons[9];
161 HWND hToolbar;
162 int i;
163 for (i=0; i<9; i++)
164 MakeButton(buttons+i, 1000+i, TBSTYLE_CHECKGROUP, 0);
165 MakeButton(buttons+3, 1003, TBSTYLE_SEP|TBSTYLE_GROUP, 0);
166 MakeButton(buttons+6, 1006, TBSTYLE_SEP, 0);
168 hToolbar = CreateToolbarEx(hMainWnd,
169 WS_VISIBLE | WS_CLIPCHILDREN | CCS_TOP |
170 WS_CHILD | TBSTYLE_LIST,
171 100,
172 0, NULL, 0,
173 buttons, sizeof(buttons)/sizeof(buttons[0]),
174 0, 0, 20, 16, sizeof(TBBUTTON));
175 ok(hToolbar != NULL, "Toolbar creation\n");
176 SendMessage(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"test\000");
178 /* test for exclusion working inside a separator-separated :-) group */
179 SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 */
180 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
181 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1001, 0), "A2 not pressed\n");
183 SendMessage(hToolbar, TB_CHECKBUTTON, 1004, 1); /* press A5, release A1 */
184 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 pressed\n");
185 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 not pressed anymore\n");
187 SendMessage(hToolbar, TB_CHECKBUTTON, 1005, 1); /* press A6, release A5 */
188 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
189 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1004, 0), "A5 not pressed anymore\n");
191 /* test for inter-group crosstalk, ie. two radio groups interfering with each other */
192 SendMessage(hToolbar, TB_CHECKBUTTON, 1007, 1); /* press B2 */
193 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
194 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 still not pressed\n");
195 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 pressed\n");
197 SendMessage(hToolbar, TB_CHECKBUTTON, 1000, 1); /* press A1 and ensure B group didn't suffer */
198 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 not pressed anymore\n");
199 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
200 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 still pressed\n");
202 SendMessage(hToolbar, TB_CHECKBUTTON, 1008, 1); /* press B3, and ensure A group didn't suffer */
203 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1005, 0), "A6 pressed\n");
204 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1000, 0), "A1 pressed\n");
205 ok(!SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1007, 0), "B2 not pressed\n");
206 ok(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 1008, 0), "B3 pressed\n");
208 /* tests with invalid index */
209 compare(SendMessage(hToolbar, TB_ISBUTTONCHECKED, 0xdeadbeef, 0), -1L, "%ld");
210 compare(SendMessage(hToolbar, TB_ISBUTTONPRESSED, 0xdeadbeef, 0), -1L, "%ld");
211 compare(SendMessage(hToolbar, TB_ISBUTTONENABLED, 0xdeadbeef, 0), -1L, "%ld");
212 compare(SendMessage(hToolbar, TB_ISBUTTONINDETERMINATE, 0xdeadbeef, 0), -1L, "%ld");
213 compare(SendMessage(hToolbar, TB_ISBUTTONHIGHLIGHTED, 0xdeadbeef, 0), -1L, "%ld");
214 compare(SendMessage(hToolbar, TB_ISBUTTONHIDDEN, 0xdeadbeef, 0), -1L, "%ld");
216 DestroyWindow(hToolbar);
219 static void rebuild_toolbar(HWND *hToolbar)
221 if (*hToolbar)
222 DestroyWindow(*hToolbar);
223 *hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
224 hMainWnd, (HMENU)5, GetModuleHandle(NULL), NULL);
225 ok(*hToolbar != NULL, "Toolbar creation problem\n");
226 ok(SendMessage(*hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
227 ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
228 ok(SendMessage(*hToolbar, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FONT), 0)==1, "WM_SETFONT\n");
231 static void rebuild_toolbar_with_buttons(HWND *hToolbar)
233 TBBUTTON buttons[5];
234 rebuild_toolbar(hToolbar);
236 ZeroMemory(&buttons, sizeof(buttons));
237 buttons[0].idCommand = 1;
238 buttons[0].fsStyle = BTNS_BUTTON;
239 buttons[0].fsState = TBSTATE_ENABLED;
240 buttons[0].iString = -1;
241 buttons[1].idCommand = 3;
242 buttons[1].fsStyle = BTNS_BUTTON;
243 buttons[1].fsState = TBSTATE_ENABLED;
244 buttons[1].iString = -1;
245 buttons[2].idCommand = 5;
246 buttons[2].fsStyle = BTNS_SEP;
247 buttons[2].fsState = TBSTATE_ENABLED;
248 buttons[2].iString = -1;
249 buttons[3].idCommand = 7;
250 buttons[3].fsStyle = BTNS_BUTTON;
251 buttons[3].fsState = TBSTATE_ENABLED;
252 buttons[3].iString = -1;
253 buttons[4].idCommand = 9;
254 buttons[4].fsStyle = BTNS_BUTTON;
255 buttons[4].fsState = 0; /* disabled */
256 buttons[4].iString = -1;
257 ok(SendMessage(*hToolbar, TB_ADDBUTTONS, 5, (LPARAM)buttons) == 1, "TB_ADDBUTTONS failed\n");
258 ok(SendMessage(*hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
261 static void add_128x15_bitmap(HWND hToolbar, int nCmds)
263 TBADDBITMAP bmp128;
264 bmp128.hInst = GetModuleHandle(NULL);
265 bmp128.nID = IDB_BITMAP_128x15;
266 ok(SendMessageA(hToolbar, TB_ADDBITMAP, nCmds, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
269 #define CHECK_IMAGELIST(count, dx, dy) { \
270 int cx, cy; \
271 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
272 ok(himl != NULL, "No image list\n"); \
273 if (himl != NULL) {\
274 ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
275 ImageList_GetIconSize(himl, &cx, &cy); \
276 ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
280 static void test_add_bitmap(void)
282 HWND hToolbar = NULL;
283 TBADDBITMAP bmp128;
284 TBADDBITMAP bmp80;
285 TBADDBITMAP stdsmall;
286 TBADDBITMAP addbmp;
287 HIMAGELIST himl;
288 INT ret;
290 /* empty 128x15 bitmap */
291 bmp128.hInst = GetModuleHandle(NULL);
292 bmp128.nID = IDB_BITMAP_128x15;
294 /* empty 80x15 bitmap */
295 bmp80.hInst = GetModuleHandle(NULL);
296 bmp80.nID = IDB_BITMAP_80x15;
298 /* standard bitmap - 240x15 pixels */
299 stdsmall.hInst = HINST_COMMCTRL;
300 stdsmall.nID = IDB_STD_SMALL_COLOR;
302 rebuild_toolbar(&hToolbar);
303 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
304 CHECK_IMAGELIST(8, 16, 16);
306 /* adding more bitmaps */
307 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 8, "TB_ADDBITMAP - unexpected return\n");
308 CHECK_IMAGELIST(13, 16, 16);
309 /* adding the same bitmap will simply return the index of the already loaded block */
310 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&bmp128);
311 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
312 CHECK_IMAGELIST(13, 16, 16);
313 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
314 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
315 CHECK_IMAGELIST(13, 16, 16);
316 /* even if we increase the wParam */
317 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 55, (LPARAM)&bmp80);
318 ok(ret == 8, "TB_ADDBITMAP - unexpected return %d\n", ret);
319 CHECK_IMAGELIST(13, 16, 16);
321 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
322 rebuild_toolbar(&hToolbar);
323 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
324 CHECK_IMAGELIST(8, 16, 16);
325 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80);
326 ok(ret == 3, "TB_ADDBITMAP - unexpected return %d\n", ret);
327 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
328 CHECK_IMAGELIST(13, 16, 16);
330 /* the same for negative wParam */
331 rebuild_toolbar(&hToolbar);
332 ret = SendMessageA(hToolbar, TB_ADDBITMAP, -143, (LPARAM)&bmp128);
333 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
334 CHECK_IMAGELIST(8, 16, 16);
335 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
336 ok(ret == -143, "TB_ADDBITMAP - unexpected return %d\n", ret);
337 CHECK_IMAGELIST(13, 16, 16);
339 /* for zero only one bitmap will be added */
340 rebuild_toolbar(&hToolbar);
341 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&bmp80);
342 ok(ret == 0, "TB_ADDBITMAP - unexpected return %d\n", ret);
343 CHECK_IMAGELIST(1, 16, 16);
345 /* if wParam is larger than the amount of icons, the list is grown */
346 rebuild_toolbar(&hToolbar);
347 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
348 CHECK_IMAGELIST(100, 16, 16);
349 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128);
350 ok(ret == 100, "TB_ADDBITMAP - unexpected return %d\n", ret);
351 CHECK_IMAGELIST(200, 16, 16);
353 /* adding built-in items - the wParam is ignored */
354 rebuild_toolbar(&hToolbar);
355 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp80) == 0, "TB_ADDBITMAP - unexpected return\n");
356 CHECK_IMAGELIST(5, 16, 16);
357 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 5, "TB_ADDBITMAP - unexpected return\n");
358 CHECK_IMAGELIST(20, 16, 16);
359 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 20, "TB_ADDBITMAP - unexpected return\n");
360 CHECK_IMAGELIST(28, 16, 16);
362 /* when we increase the bitmap size, less icons will be created */
363 rebuild_toolbar(&hToolbar);
364 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20)) == TRUE, "TB_SETBITMAPSIZE failed\n");
365 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
366 CHECK_IMAGELIST(6, 20, 20);
367 ret = SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp80);
368 ok(ret == 1, "TB_ADDBITMAP - unexpected return %d\n", ret);
369 CHECK_IMAGELIST(10, 20, 20);
370 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
371 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
372 UpdateWindow(hToolbar);
373 CHECK_IMAGELIST(26, 8, 8);
374 /* loading a standard bitmaps automatically resizes the icons */
375 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&stdsmall) == 2, "TB_ADDBITMAP - unexpected return\n");
376 UpdateWindow(hToolbar);
377 CHECK_IMAGELIST(28, 16, 16);
379 /* two more SETBITMAPSIZE tests */
380 rebuild_toolbar(&hToolbar);
381 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
382 CHECK_IMAGELIST(100, 16, 16);
383 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 100, (LPARAM)&bmp80) == 100, "TB_ADDBITMAP - unexpected return\n");
384 CHECK_IMAGELIST(200, 16, 16);
385 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
386 UpdateWindow(hToolbar);
387 CHECK_IMAGELIST(200, 8, 8);
388 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
389 UpdateWindow(hToolbar);
390 CHECK_IMAGELIST(200, 30, 30);
391 rebuild_toolbar(&hToolbar);
392 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 5, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
393 CHECK_IMAGELIST(8, 16, 16);
394 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 3, (LPARAM)&bmp80) == 5, "TB_ADDBITMAP - unexpected return\n");
395 CHECK_IMAGELIST(13, 16, 16);
396 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(30, 30)) == TRUE, "TB_SETBITMAPSIZE failed\n");
397 UpdateWindow(hToolbar);
398 CHECK_IMAGELIST(8, 30, 30);
399 /* when the width or height is zero, set it to 1 */
400 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
401 UpdateWindow(hToolbar);
402 CHECK_IMAGELIST(208, 1, 1);
403 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(0, 5)) == TRUE, "TB_SETBITMAPSIZE failed\n");
404 UpdateWindow(hToolbar);
405 CHECK_IMAGELIST(208, 1, 5);
406 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(5, 0)) == TRUE, "TB_SETBITMAPSIZE failed\n");
407 UpdateWindow(hToolbar);
408 CHECK_IMAGELIST(41, 5, 1);
410 /* the control can add bitmaps to an existing image list */
411 rebuild_toolbar(&hToolbar);
412 himl = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_80x15), 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
413 ok(himl != NULL, "failed to create imagelist\n");
414 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
415 CHECK_IMAGELIST(4, 20, 15);
416 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&bmp128) == 0, "TB_ADDBITMAP - unexpected return\n");
417 CHECK_IMAGELIST(10, 20, 15);
418 /* however TB_SETBITMAPSIZE/add std bitmap won't change the image size (the button size does change) */
419 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(8, 8)) == TRUE, "TB_SETBITMAPSIZE failed\n");
420 UpdateWindow(hToolbar);
421 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(15, 14), "%x");
422 CHECK_IMAGELIST(10, 20, 15);
423 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&stdsmall) == 1, "TB_SETBITMAPSIZE failed\n");
424 UpdateWindow(hToolbar);
425 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(23, 22), "%x");
426 CHECK_IMAGELIST(22, 20, 15);
428 /* check standard bitmaps */
429 addbmp.hInst = HINST_COMMCTRL;
430 addbmp.nID = IDB_STD_SMALL_COLOR;
431 rebuild_toolbar(&hToolbar);
432 ImageList_Destroy(himl);
434 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
435 CHECK_IMAGELIST(15, 16, 16);
436 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(23, 22), "%x");
437 addbmp.nID = IDB_STD_LARGE_COLOR;
438 rebuild_toolbar(&hToolbar);
439 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
440 CHECK_IMAGELIST(15, 24, 24);
441 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(31, 30), "%x");
443 addbmp.nID = IDB_VIEW_SMALL_COLOR;
444 rebuild_toolbar(&hToolbar);
445 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
446 CHECK_IMAGELIST(12, 16, 16);
447 addbmp.nID = IDB_VIEW_LARGE_COLOR;
448 rebuild_toolbar(&hToolbar);
449 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
450 CHECK_IMAGELIST(12, 24, 24);
452 addbmp.nID = IDB_HIST_SMALL_COLOR;
453 rebuild_toolbar(&hToolbar);
454 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
455 CHECK_IMAGELIST(5, 16, 16);
456 addbmp.nID = IDB_HIST_LARGE_COLOR;
457 rebuild_toolbar(&hToolbar);
458 ok(SendMessageA(hToolbar, TB_ADDBITMAP, 1, (LPARAM)&addbmp) == 0, "TB_ADDBITMAP - unexpected return\n");
459 CHECK_IMAGELIST(5, 24, 24);
462 DestroyWindow(hToolbar);
465 #define CHECK_STRING_TABLE(count, tab) { \
466 INT _i; \
467 CHAR _buf[260]; \
468 for (_i = 0; _i < (count); _i++) {\
469 ret = SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, _i), (LPARAM)_buf); \
470 ok(ret >= 0, "TB_GETSTRING - unexpected return %d while checking string %d\n", ret, _i); \
471 if (ret >= 0) \
472 ok(strcmp(_buf, (tab)[_i]) == 0, "Invalid string #%d - '%s' vs '%s'\n", _i, (tab)[_i], _buf); \
474 ok(SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, (count)), (LPARAM)_buf) == -1, \
475 "Too many strings in table\n"); \
478 static void test_add_string(void)
480 LPCSTR test1 = "a\0b\0";
481 LPCSTR test2 = "|a|b||\0";
482 LPCSTR ret1[] = {"a", "b"};
483 LPCSTR ret2[] = {"a", "b", "|a|b||"};
484 LPCSTR ret3[] = {"a", "b", "|a|b||", "p", "q"};
485 LPCSTR ret4[] = {"a", "b", "|a|b||", "p", "q", "p"};
486 LPCSTR ret5[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q"};
487 LPCSTR ret6[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q"};
488 LPCSTR ret7[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q", "br", "c", "d"};
489 HWND hToolbar = NULL;
490 TBBUTTON button;
491 int ret;
492 CHAR buf[260];
494 rebuild_toolbar(&hToolbar);
495 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test1);
496 ok(ret == 0, "TB_ADDSTRINGA - unexpected return %d\n", ret);
497 ret = SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, 1), (LPARAM)buf);
498 if (ret == 0)
500 win_skip("TB_GETSTRING needs 5.80\n");
501 return;
503 CHECK_STRING_TABLE(2, ret1);
504 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)test2);
505 ok(ret == 2, "TB_ADDSTRINGA - unexpected return %d\n", ret);
506 CHECK_STRING_TABLE(3, ret2);
508 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD1);
509 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
510 CHECK_STRING_TABLE(3, ret2);
511 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD2);
512 ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
513 CHECK_STRING_TABLE(5, ret3);
514 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD3);
515 ok(ret == 5, "TB_ADDSTRINGA - unexpected return %d\n", ret);
516 CHECK_STRING_TABLE(6, ret4);
517 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD4);
518 ok(ret == 6, "TB_ADDSTRINGA - unexpected return %d\n", ret);
519 CHECK_STRING_TABLE(8, ret5);
520 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD5);
521 ok(ret == 8, "TB_ADDSTRINGA - unexpected return %d\n", ret);
522 CHECK_STRING_TABLE(11, ret6);
523 ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD7);
524 ok(ret == 11, "TB_ADDSTRINGA - unexpected return %d\n", ret);
525 CHECK_STRING_TABLE(14, ret7);
527 ZeroMemory(&button, sizeof(button));
528 button.iString = (UINT_PTR)"Test";
529 SendMessageA(hToolbar, TB_INSERTBUTTONA, 0, (LPARAM)&button);
530 CHECK_STRING_TABLE(14, ret7);
531 SendMessageA(hToolbar, TB_ADDBUTTONSA, 1, (LPARAM)&button);
532 CHECK_STRING_TABLE(14, ret7);
534 DestroyWindow(hToolbar);
537 static void expect_hot_notify(int idold, int idnew)
539 g_fExpectedHotItemOld = idold;
540 g_fExpectedHotItemNew = idnew;
541 g_fReceivedHotItemChange = FALSE;
544 #define check_hot_notify() \
545 ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
546 g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
548 static void test_hotitem(void)
550 HWND hToolbar = NULL;
551 TBBUTTONINFO tbinfo;
552 LRESULT ret;
554 g_fBlockHotItemChange = FALSE;
556 rebuild_toolbar_with_buttons(&hToolbar);
557 /* set TBSTYLE_FLAT. comctl5 allows hot items only for such toolbars.
558 * comctl6 doesn't have this requirement even when theme == NULL */
559 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_FLAT | GetWindowLong(hToolbar, GWL_STYLE));
560 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
561 ok(ret == -1, "Hot item: %ld, expected -1\n", ret);
562 ret = SendMessage(hToolbar, TB_SETHOTITEM, 1, 0);
563 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
564 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
565 ok(ret == 1, "Hot item: %ld, expected 1\n", ret);
566 ret = SendMessage(hToolbar, TB_SETHOTITEM, 2, 0);
567 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
569 ret = SendMessage(hToolbar, TB_SETHOTITEM, 0xbeef, 0);
570 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
571 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
572 ok(ret == 2, "Hot item: %lx, expected 2\n", ret);
573 ret = SendMessage(hToolbar, TB_SETHOTITEM, -0xbeef, 0);
574 ok(ret == 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
575 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
576 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
578 expect_hot_notify(0, 7);
579 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
580 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
581 check_hot_notify();
582 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
583 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
584 g_fBlockHotItemChange = TRUE;
585 ret = SendMessage(hToolbar, TB_SETHOTITEM, 2, 0);
586 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 2\n", ret);
587 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
588 ok(ret == 3, "Hot item: %lx, expected 3\n", ret);
589 g_fBlockHotItemChange = FALSE;
591 g_fReceivedHotItemChange = FALSE;
592 ret = SendMessage(hToolbar, TB_SETHOTITEM, 0xbeaf, 0);
593 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
594 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received for invalid parameter\n");
596 g_fReceivedHotItemChange = FALSE;
597 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
598 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
599 ok(g_fReceivedHotItemChange == FALSE, "TBN_HOTITEMCHANGE received after a duplication\n");
601 expect_hot_notify(7, 0);
602 ret = SendMessage(hToolbar, TB_SETHOTITEM, -0xbeaf, 0);
603 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
604 check_hot_notify();
605 SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
607 /* setting disabled buttons will generate a notify with the button id but no button will be hot */
608 expect_hot_notify(7, 9);
609 ret = SendMessage(hToolbar, TB_SETHOTITEM, 4, 0);
610 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
611 check_hot_notify();
612 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
613 ok(ret == -1, "Hot item: %lx, expected -1\n", ret);
614 /* enabling the button won't change that */
615 SendMessage(hToolbar, TB_ENABLEBUTTON, 9, TRUE);
616 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
617 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
619 /* disabling a hot button works */
620 ret = SendMessage(hToolbar, TB_SETHOTITEM, 3, 0);
621 ok(ret == -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret);
622 g_fReceivedHotItemChange = FALSE;
623 SendMessage(hToolbar, TB_ENABLEBUTTON, 7, FALSE);
624 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
625 ok(ret == 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret);
626 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
628 SendMessage(hToolbar, TB_SETHOTITEM, 1, 0);
629 tbinfo.cbSize = sizeof(TBBUTTONINFO);
630 tbinfo.dwMask = TBIF_STATE;
631 tbinfo.fsState = 0; /* disabled */
632 g_fReceivedHotItemChange = FALSE;
633 ok(SendMessage(hToolbar, TB_SETBUTTONINFO, 1, (LPARAM)&tbinfo) == TRUE, "TB_SETBUTTONINFO failed\n");
634 ret = SendMessage(hToolbar, TB_GETHOTITEM, 0, 0);
635 ok(ret == 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret);
636 ok(g_fReceivedHotItemChange == FALSE, "Unexpected TBN_HOTITEMCHANGE\n");
638 DestroyWindow(hToolbar);
641 #if 0 /* use this to generate more tests*/
643 static void dump_sizes(HWND hToolbar)
645 SIZE sz;
646 RECT r;
647 int count = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0);
648 int i;
650 GetClientRect(hToolbar, &r);
651 SendMessageA(hToolbar, TB_GETMAXSIZE, 0, &sz);
652 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r.left, r.top, r.right, r.bottom,
653 sz.cx, sz.cy, count);
654 for (i=0; i<count; i++)
656 SendMessageA(hToolbar, TB_GETITEMRECT, i, &r);
657 printf("%s{%3d, %3d, %3d, %3d}, ", (i%3==0 ? "\n " : ""), r.left, r.top, r.right, r.bottom);
659 printf("\n }, },\n");
662 #define check_sizes() dump_sizes(hToolbar);
663 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
665 #else
667 typedef struct
669 RECT rcClient;
670 SIZE szMin;
671 INT nButtons;
672 RECT rcButtons[100];
673 } tbsize_result_t;
675 static tbsize_result_t tbsize_results[] =
677 { {0, 0, 672, 26}, {100, 22}, 5, {
678 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
679 { 54, 2, 77, 24}, { 77, 2, 100, 24},
680 }, },
681 { {0, 0, 672, 26}, {146, 22}, 7, {
682 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
683 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
684 { 0, 24, 23, 46},
685 }, },
686 { {0, 0, 672, 48}, {146, 22}, 7, {
687 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
688 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
689 { 0, 24, 23, 46},
690 }, },
691 { {0, 0, 672, 26}, {146, 22}, 7, {
692 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
693 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
694 {123, 2, 146, 24},
695 }, },
696 { {0, 0, 672, 26}, {192, 22}, 9, {
697 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
698 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
699 {123, 2, 146, 24}, {146, 2, 169, 24}, {169, 2, 192, 24},
700 }, },
701 { {0, 0, 672, 92}, {882, 22}, 39, {
702 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 0, 2, 8, 29},
703 { 0, 29, 23, 51}, { 23, 29, 46, 51}, { 46, 29, 69, 51},
704 { 69, 29, 92, 51}, { 92, 29, 115, 51}, {115, 29, 138, 51},
705 {138, 29, 161, 51}, {161, 29, 184, 51}, {184, 29, 207, 51},
706 {207, 29, 230, 51}, {230, 29, 253, 51}, {253, 29, 276, 51},
707 {276, 29, 299, 51}, {299, 29, 322, 51}, {322, 29, 345, 51},
708 {345, 29, 368, 51}, {368, 29, 391, 51}, {391, 29, 414, 51},
709 {414, 29, 437, 51}, {437, 29, 460, 51}, {460, 29, 483, 51},
710 {483, 29, 506, 51}, {506, 29, 529, 51}, {529, 29, 552, 51},
711 {552, 29, 575, 51}, {575, 29, 598, 51}, {598, 29, 621, 51},
712 {621, 29, 644, 51}, {644, 29, 667, 51}, { 0, 51, 23, 73},
713 { 23, 51, 46, 73}, { 46, 51, 69, 73}, { 69, 51, 92, 73},
714 { 92, 51, 115, 73}, {115, 51, 138, 73}, {138, 51, 161, 73},
715 }, },
716 { {0, 0, 48, 226}, {23, 140}, 7, {
717 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 94, 24},
718 { 94, 2, 117, 24}, {117, 2, 140, 24}, {140, 2, 163, 24},
719 { 0, 24, 23, 46},
720 }, },
721 { {0, 0, 92, 226}, {23, 140}, 7, {
722 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 0, 24, 92, 32},
723 { 0, 32, 23, 54}, { 23, 32, 46, 54}, { 46, 32, 69, 54},
724 { 69, 32, 92, 54},
725 }, },
726 { {0, 0, 672, 26}, {194, 30}, 7, {
727 { 0, 2, 31, 32}, { 31, 2, 62, 32}, { 62, 2, 70, 32},
728 { 70, 2, 101, 32}, {101, 2, 132, 32}, {132, 2, 163, 32},
729 { 0, 32, 31, 62},
730 }, },
731 { {0, 0, 672, 64}, {194, 30}, 7, {
732 { 0, 2, 31, 32}, { 31, 2, 62, 32}, { 62, 2, 70, 32},
733 { 70, 2, 101, 32}, {101, 2, 132, 32}, {132, 2, 163, 32},
734 { 0, 32, 31, 62},
735 }, },
736 { {0, 0, 672, 64}, {194, 30}, 7, {
737 { 0, 0, 31, 30}, { 31, 0, 62, 30}, { 62, 0, 70, 30},
738 { 70, 0, 101, 30}, {101, 0, 132, 30}, {132, 0, 163, 30},
739 { 0, 30, 31, 60},
740 }, },
741 { {0, 0, 124, 226}, {31, 188}, 7, {
742 { 0, 0, 31, 30}, { 31, 0, 62, 30}, { 0, 30, 124, 38},
743 { 0, 38, 31, 68}, { 31, 38, 62, 68}, { 62, 38, 93, 68},
744 { 93, 38, 124, 68},
745 }, },
746 { {0, 0, 672, 26}, {146, 22}, 7, {
747 { 0, 2, 23, 24}, { 23, 2, 46, 24}, { 46, 2, 54, 24},
748 { 54, 2, 77, 24}, { 77, 2, 100, 24}, {100, 2, 123, 24},
749 {123, 2, 146, 24},
750 }, },
751 { {0, 0, 672, 26}, {146, 100}, 7, {
752 { 0, 0, 23, 100}, { 23, 0, 46, 100}, { 46, 0, 54, 100},
753 { 54, 0, 77, 100}, { 77, 0, 100, 100}, {100, 0, 123, 100},
754 {123, 0, 146, 100},
755 }, },
756 { {0, 0, 672, 26}, {215, 100}, 10, {
757 { 0, 0, 23, 100}, { 23, 0, 46, 100}, { 46, 0, 54, 100},
758 { 54, 0, 77, 100}, { 77, 0, 100, 100}, {100, 0, 123, 100},
759 {123, 0, 146, 100}, {146, 0, 169, 100}, {169, 0, 192, 100},
760 {192, 0, 215, 100},
761 }, },
762 { {0, 0, 672, 26}, {238, 39}, 11, {
763 { 0, 0, 23, 39}, { 23, 0, 46, 39}, { 46, 0, 54, 39},
764 { 54, 0, 77, 39}, { 77, 0, 100, 39}, {100, 0, 123, 39},
765 {123, 0, 146, 39}, {146, 0, 169, 39}, {169, 0, 192, 39},
766 {192, 0, 215, 39}, {215, 0, 238, 39},
767 }, },
768 { {0, 0, 672, 26}, {238, 22}, 11, {
769 { 0, 0, 23, 22}, { 23, 0, 46, 22}, { 46, 0, 54, 22},
770 { 54, 0, 77, 22}, { 77, 0, 100, 22}, {100, 0, 123, 22},
771 {123, 0, 146, 22}, {146, 0, 169, 22}, {169, 0, 192, 22},
772 {192, 0, 215, 22}, {215, 0, 238, 22},
773 }, },
774 { {0, 0, 672, 26}, {489, 39}, 3, {
775 { 0, 2, 163, 41}, {163, 2, 330, 41}, {330, 2, 493, 41},
776 }, },
777 { {0, 0, 672, 104}, {978, 24}, 6, {
778 { 0, 2, 163, 26}, {163, 2, 326, 26}, {326, 2, 489, 26},
779 {489, 2, 652, 26}, {652, 2, 819, 26}, {819, 2, 850, 26},
780 }, },
781 { {0, 0, 672, 28}, {978, 38}, 6, {
782 { 0, 0, 163, 38}, {163, 0, 326, 38}, {326, 0, 489, 38},
783 {489, 0, 652, 38}, {652, 0, 819, 38}, {819, 0, 850, 38},
784 }, },
785 { {0, 0, 672, 100}, {239, 102}, 3, {
786 { 0, 2, 100, 102}, {100, 2, 139, 102}, {139, 2, 239, 102},
787 }, },
788 { {0, 0, 672, 42}, {185, 40}, 3, {
789 { 0, 2, 75, 40}, {75, 2, 118, 40}, {118, 2, 185, 40},
790 }, },
791 { {0, 0, 672, 42}, {67, 40}, 1, {
792 { 0, 2, 67, 40},
793 }, },
794 { {0, 0, 672, 42}, {67, 41}, 2, {
795 { 0, 2, 672, 41}, { 0, 41, 672, 80},
796 }, },
799 static int tbsize_numtests = 0;
801 typedef struct
803 int test_num;
804 int rect_index;
805 RECT rcButton;
806 } tbsize_alt_result_t;
808 static tbsize_alt_result_t tbsize_alt_results[] =
810 { 5, 2, { 0, 24, 8, 29 } },
811 { 20, 1, { 100, 2, 107, 102 } },
812 { 20, 2, { 107, 2, 207, 102 } }
815 static int tbsize_alt_numtests = 0;
817 #define check_sizes_todo(todomask) { \
818 RECT rc; \
819 int buttonCount, i, mask=(todomask); \
820 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
821 assert(tbsize_numtests < sizeof(tbsize_results)/sizeof(tbsize_results[0])); \
822 GetClientRect(hToolbar, &rc); \
823 /*check_rect("client", rc, res->rcClient);*/ \
824 buttonCount = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0); \
825 compare(buttonCount, res->nButtons, "%d"); \
826 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
827 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
828 if (broken(tbsize_alt_numtests < sizeof(tbsize_alt_results)/sizeof(tbsize_alt_results[0]) && \
829 memcmp(&rc, &tbsize_alt_results[tbsize_alt_numtests].rcButton, sizeof(RECT)) == 0)) { \
830 win_skip("Alternate rect found\n"); \
831 tbsize_alt_numtests++; \
832 } else if (!(mask&1)) { \
833 check_rect("button", rc, res->rcButtons[i]); \
834 } else {\
835 todo_wine { check_rect("button", rc, res->rcButtons[i]); } \
837 mask >>= 1; \
839 tbsize_numtests++; \
842 #define check_sizes() check_sizes_todo(0)
844 #endif
846 static TBBUTTON buttons1[] = {
847 {0, 10, TBSTATE_WRAP|TBSTATE_ENABLED, 0, {0, }, 0, -1},
848 {0, 11, 0, 0, {0, }, 0, -1},
850 static TBBUTTON buttons2[] = {
851 {0, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
852 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
854 static TBBUTTON buttons3[] = {
855 {0, 30, TBSTATE_ENABLED, 0, {0, }, 0, 0},
856 {0, 31, TBSTATE_ENABLED, 0, {0, }, 0, 1},
857 {0, 32, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, 1},
858 {0, 33, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0, }, 0, (UINT_PTR)"Tst"}
861 static void test_sizes(void)
863 HWND hToolbar = NULL;
864 HIMAGELIST himl, himl2;
865 TBBUTTONINFO tbinfo;
866 int style;
867 int i;
869 rebuild_toolbar_with_buttons(&hToolbar);
870 style = GetWindowLong(hToolbar, GWL_STYLE);
871 ok(style == (WS_CHILD|WS_VISIBLE|CCS_TOP), "Invalid style %x\n", style);
872 check_sizes();
873 /* the TBSTATE_WRAP makes a second row */
874 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
875 check_sizes();
876 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
877 check_sizes();
878 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
879 SetWindowLong(hToolbar, GWL_STYLE, style|TBSTYLE_WRAPABLE);
880 check_sizes();
881 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
882 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
883 check_sizes();
884 /* only after adding enough buttons the bar will be wrapped on a
885 * separator and then on the first button */
886 for (i=0; i<15; i++)
887 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
888 check_sizes_todo(0x4);
890 rebuild_toolbar_with_buttons(&hToolbar);
891 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
892 /* setting the buttons vertical will only change the window client size */
893 SetWindowLong(hToolbar, GWL_STYLE, style | CCS_VERT);
894 SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
895 check_sizes_todo(0x3c);
896 /* with a TBSTYLE_WRAPABLE a wrapping will occur on the separator */
897 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_WRAPABLE | CCS_VERT);
898 SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
899 check_sizes_todo(0x7c);
901 rebuild_toolbar_with_buttons(&hToolbar);
902 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons1);
903 /* a TB_SETBITMAPSIZE changes button sizes*/
904 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
905 check_sizes();
907 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
908 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
909 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
910 check_sizes();
911 /* but after a TB_SETBITMAPSIZE the top margins is changed */
912 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20));
913 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(24, 24));
914 check_sizes();
915 /* some vertical toolbar sizes */
916 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT | TBSTYLE_WRAPABLE | CCS_VERT);
917 check_sizes_todo(0x7c);
919 rebuild_toolbar_with_buttons(&hToolbar);
920 SetWindowLong(hToolbar, GWL_STYLE, style | TBSTYLE_FLAT);
921 /* newly added buttons will be use the previous margin */
922 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons2);
923 check_sizes();
924 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
925 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
926 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
927 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
928 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
929 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n");
930 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
931 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
932 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
933 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 100), "Unexpected button size\n");
934 check_sizes();
935 /* add some buttons with non-default sizes */
936 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons2);
937 SendMessageA(hToolbar, TB_INSERTBUTTON, -1, (LPARAM)&buttons2[0]);
938 check_sizes();
939 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]);
940 /* TB_ADDSTRING resets the size */
941 SendMessageA(hToolbar, TB_ADDSTRING, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
942 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n");
943 check_sizes();
944 /* TB_SETBUTTONSIZE can be used to crop the text */
945 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
946 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
947 check_sizes();
948 /* the default size is bitmap size + padding */
949 SendMessageA(hToolbar, TB_SETPADDING, 0, MAKELONG(1, 1));
950 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
951 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(17, 17), "Unexpected button size\n");
952 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(3, 3));
953 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(3, 3));
954 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(4, 4), "Unexpected button size\n");
956 rebuild_toolbar(&hToolbar);
957 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
958 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
959 SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(16, 15));
960 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 21), "Unexpected button size\n");
961 /* -1 in TB_SETBITMAPSIZE is a special code meaning that the coordinate shouldn't be changed */
962 add_128x15_bitmap(hToolbar, 16);
963 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(14, -1)), "TB_SETBITMAPSIZE failed\n");
964 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 21), "%x");
965 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, 12)), "TB_SETBITMAPSIZE failed\n");
966 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
967 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(-1, -1)), "TB_SETBITMAPSIZE failed\n");
968 compare((int)SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0), MAKELONG(21, 18), "%x");
969 /* check the imagelist */
970 InvalidateRect(hToolbar, NULL, TRUE);
971 UpdateWindow(hToolbar);
972 CHECK_IMAGELIST(16, 14, 12);
974 rebuild_toolbar(&hToolbar);
975 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
976 /* the height is increased after a TB_ADDSTRING */
977 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 39), "Unexpected button size\n");
978 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
979 /* if a string is in the pool, even adding a button without a string resets the size */
980 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons2[0]);
981 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
982 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
983 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
984 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[2]);
985 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 39), "Unexpected button size\n");
986 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]);
987 check_sizes();
988 /* delete button doesn't change the buttons size */
989 SendMessageA(hToolbar, TB_DELETEBUTTON, 2, 0);
990 SendMessageA(hToolbar, TB_DELETEBUTTON, 1, 0);
991 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 39), "Unexpected button size\n");
992 /* TB_INSERTBUTTONS will */
993 SendMessageA(hToolbar, TB_INSERTBUTTON, 1, (LPARAM)&buttons2[0]);
994 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
996 /* TB_HIDEBUTTON and TB_MOVEBUTTON doesn't force a recalc */
997 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
998 ok(SendMessageA(hToolbar, TB_MOVEBUTTON, 0, 1), "TB_MOVEBUTTON failed\n");
999 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
1000 ok(SendMessageA(hToolbar, TB_HIDEBUTTON, 20, TRUE), "TB_HIDEBUTTON failed\n");
1001 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
1002 /* however changing the hidden flag with TB_SETSTATE does */
1003 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED|TBSTATE_HIDDEN), "TB_SETSTATE failed\n");
1004 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
1005 ok(SendMessageA(hToolbar, TB_SETSTATE, 20, TBSTATE_ENABLED), "TB_SETSTATE failed\n");
1006 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(23, 22), "Unexpected button size\n");
1008 /* TB_SETIMAGELIST always changes the height but the width only if necessary */
1009 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1010 himl = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_80x15), 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
1011 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1012 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 21), "Unexpected button size\n");
1013 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(100, 100));
1014 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
1015 /* But there are no update when we change imagelist, and image sizes are the same */
1016 himl2 = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP_128x15), 20, 2, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
1017 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LRESULT)himl2) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
1018 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(100, 100), "Unexpected button size\n");
1019 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
1020 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 21), "Unexpected button size\n");
1021 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl2, "TB_SETIMAGELIST failed\n");
1022 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 7), "Unexpected button size\n");
1023 SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(1, 1));
1024 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(8, 7), "Unexpected button size\n");
1025 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1026 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 21), "Unexpected button size\n");
1027 /* the text is taken into account */
1028 SendMessageA(hToolbar, TB_ADDSTRINGA, 0, (LPARAM)"A\0MMMMMMMMMMMMM\0");
1029 SendMessageA(hToolbar, TB_ADDBUTTONS, 4, (LPARAM)buttons3);
1030 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 38), "Unexpected button size\n");
1031 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, 0) == (LRESULT)himl, "TB_SETIMAGELIST failed\n");
1032 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(163, 24), "Unexpected button size\n");
1033 /* the style change also comes into effect */
1034 check_sizes();
1035 SetWindowLong(hToolbar, GWL_STYLE, GetWindowLong(hToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1036 ok(SendMessageA(hToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl) == 0, "TB_SETIMAGELIST failed\n");
1037 check_sizes_todo(0x30); /* some small problems with BTNS_AUTOSIZE button sizes */
1039 rebuild_toolbar(&hToolbar);
1040 ImageList_Destroy(himl);
1041 ImageList_Destroy(himl2);
1043 SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]);
1044 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n");
1045 SendMessageA(hToolbar, TB_DELETEBUTTON, 0, 0);
1046 ok(SendMessageA(hToolbar, TB_GETBUTTONSIZE, 0, 0) == MAKELONG(27, 39), "Unexpected button size\n");
1048 rebuild_toolbar(&hToolbar);
1050 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1051 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1052 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons2[0]) == 1, "TB_ADDBUTTONS failed\n");
1053 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[2]) == 1, "TB_ADDBUTTONS failed\n");
1054 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[0]) == 1, "TB_ADDBUTTONS failed\n");
1055 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1056 check_sizes();
1058 rebuild_toolbar(&hToolbar);
1059 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_LIST | GetWindowLong(hToolbar, GWL_STYLE));
1060 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1061 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1062 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons2[0]) == 1, "TB_ADDBUTTONS failed\n");
1063 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[2]) == 1, "TB_ADDBUTTONS failed\n");
1064 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
1065 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1066 check_sizes_todo(0xff);
1068 rebuild_toolbar(&hToolbar);
1069 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_LIST | GetWindowLong(hToolbar, GWL_STYLE));
1070 ok(SendMessageA(hToolbar, TB_SETBITMAPSIZE, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1071 ok(SendMessageA(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1072 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
1073 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0 );
1074 check_sizes();
1076 rebuild_toolbar(&hToolbar);
1077 SetWindowLong(hToolbar, GWL_STYLE, TBSTYLE_WRAPABLE | GetWindowLong(hToolbar, GWL_STYLE));
1078 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
1079 ok(SendMessageA(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]) == 1, "TB_ADDBUTTONS failed\n");
1080 tbinfo.cx = 672;
1081 tbinfo.cbSize = sizeof(TBBUTTONINFO);
1082 tbinfo.dwMask = TBIF_SIZE | TBIF_BYINDEX;
1083 if (SendMessageA(hToolbar, TB_SETBUTTONINFO, 0, (LPARAM)&tbinfo))
1085 ok(SendMessageA(hToolbar, TB_SETBUTTONINFO, 1, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFO failed\n");
1086 SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0);
1087 check_sizes();
1089 else /* TBIF_BYINDEX probably not supported, confirm that this was the reason for the failure */
1091 tbinfo.dwMask = TBIF_SIZE;
1092 ok(SendMessageA(hToolbar, TB_SETBUTTONINFO, 33, (LPARAM)&tbinfo) != 0, "TB_SETBUTTONINFO failed\n");
1095 DestroyWindow(hToolbar);
1098 /* Toolbar control has two ways of reacting to a change. We call them a
1099 * relayout and recalc. A recalc forces a recompute of values like button size
1100 * and top margin (the latter in comctl32 <v6), while a relayout uses the cached
1101 * values. This functions creates a flat toolbar with a top margin of a non-flat
1102 * toolbar. We will notice a recalc, as it will recompte the top margin and
1103 * change it to zero*/
1104 static void prepare_recalc_test(HWND *phToolbar)
1106 RECT rect;
1107 rebuild_toolbar_with_buttons(phToolbar);
1108 SetWindowLong(*phToolbar, GWL_STYLE,
1109 GetWindowLong(*phToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1110 SendMessage(*phToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1111 ok(rect.top == 2, "Test will make no sense because initial top is %d instead of 2\n",
1112 rect.top);
1115 static BOOL did_recalc(HWND hToolbar)
1117 RECT rect;
1118 SendMessage(hToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1119 ok(rect.top == 2 || rect.top == 0, "Unexpected top margin %d in recalc test\n",
1120 rect.top);
1121 return (rect.top == 0);
1124 /* call after a recalc did happen to return to an unstable state */
1125 static void restore_recalc_state(HWND hToolbar)
1127 RECT rect;
1128 /* return to style with a 2px top margin */
1129 SetWindowLong(hToolbar, GWL_STYLE,
1130 GetWindowLong(hToolbar, GWL_STYLE) & ~TBSTYLE_FLAT);
1131 /* recalc */
1132 SendMessage(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&buttons3[3]);
1133 /* top margin will be 0px if a recalc occurs */
1134 SetWindowLong(hToolbar, GWL_STYLE,
1135 GetWindowLong(hToolbar, GWL_STYLE) | TBSTYLE_FLAT);
1136 /* safety check */
1137 SendMessage(hToolbar, TB_GETITEMRECT, 1, (LPARAM)&rect);
1138 ok(rect.top == 2, "Test will make no sense because initial top is %d instead of 2\n",
1139 rect.top);
1142 static void test_recalc(void)
1144 HWND hToolbar = NULL;
1145 TBBUTTONINFO bi;
1146 CHAR test[] = "Test";
1147 const int EX_STYLES_COUNT = 5;
1148 int i;
1149 BOOL recalc;
1151 /* Like TB_ADDBUTTONS tested in test_sized, inserting a button without text
1152 * results in a relayout, while adding one with text forces a recalc */
1153 prepare_recalc_test(&hToolbar);
1154 SendMessage(hToolbar, TB_INSERTBUTTON, 1, (LPARAM)&buttons3[0]);
1155 recalc = did_recalc(hToolbar);
1156 ok(!recalc, "Unexpected recalc - adding button without text\n");
1158 prepare_recalc_test(&hToolbar);
1159 SendMessage(hToolbar, TB_INSERTBUTTON, 1, (LPARAM)&buttons3[3]);
1160 recalc = did_recalc(hToolbar);
1161 ok(recalc, "Expected a recalc - adding button with text\n");
1163 /* TB_SETBUTTONINFO, even when adding a text, results only in a relayout */
1164 prepare_recalc_test(&hToolbar);
1165 bi.cbSize = sizeof(bi);
1166 bi.dwMask = TBIF_TEXT;
1167 bi.pszText = test;
1168 SendMessage(hToolbar, TB_SETBUTTONINFO, 1, (LPARAM)&bi);
1169 recalc = did_recalc(hToolbar);
1170 ok(!recalc, "Unexpected recalc - setting a button text\n");
1172 /* most extended styled doesn't force a recalc (testing all the bits gives
1173 * the same results, but prints some ERRs while testing) */
1174 for (i = 0; i < EX_STYLES_COUNT; i++)
1176 if (i == 1 || i == 3) /* an undoc style and TBSTYLE_EX_MIXEDBUTTONS */
1177 continue;
1178 prepare_recalc_test(&hToolbar);
1179 expect(0, (int)SendMessage(hToolbar, TB_GETEXTENDEDSTYLE, 0, 0));
1180 SendMessage(hToolbar, TB_SETEXTENDEDSTYLE, 0, (1 << i));
1181 recalc = did_recalc(hToolbar);
1182 ok(!recalc, "Unexpected recalc - setting bit %d\n", i);
1183 SendMessage(hToolbar, TB_SETEXTENDEDSTYLE, 0, 0);
1184 recalc = did_recalc(hToolbar);
1185 ok(!recalc, "Unexpected recalc - clearing bit %d\n", i);
1186 expect(0, (int)SendMessage(hToolbar, TB_GETEXTENDEDSTYLE, 0, 0));
1189 /* TBSTYLE_EX_MIXEDBUTTONS does a recalc on change */
1190 prepare_recalc_test(&hToolbar);
1191 SendMessage(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1192 recalc = did_recalc(hToolbar);
1193 if (recalc)
1195 ok(recalc, "Expected a recalc - setting TBSTYLE_EX_MIXEDBUTTONS\n");
1196 restore_recalc_state(hToolbar);
1197 SendMessage(hToolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
1198 recalc = did_recalc(hToolbar);
1199 ok(!recalc, "Unexpected recalc - setting TBSTYLE_EX_MIXEDBUTTONS again\n");
1200 restore_recalc_state(hToolbar);
1201 SendMessage(hToolbar, TB_SETEXTENDEDSTYLE, 0, 0);
1202 recalc = did_recalc(hToolbar);
1203 ok(recalc, "Expected a recalc - clearing TBSTYLE_EX_MIXEDBUTTONS\n");
1205 else win_skip( "No recalc on TBSTYLE_EX_MIXEDBUTTONS\n" );
1207 /* undocumented exstyle 0x2 seems to changes the top margin, what
1208 * interferes with these tests */
1210 DestroyWindow(hToolbar);
1213 static void test_getbuttoninfo(void)
1215 HWND hToolbar = NULL;
1216 int i;
1218 rebuild_toolbar_with_buttons(&hToolbar);
1219 for (i = 0; i < 128; i++)
1221 TBBUTTONINFO tbi;
1222 int ret;
1224 tbi.cbSize = i;
1225 tbi.dwMask = TBIF_COMMAND;
1226 ret = (int)SendMessage(hToolbar, TB_GETBUTTONINFO, 1, (LPARAM)&tbi);
1227 if (i == sizeof(TBBUTTONINFO)) {
1228 compare(ret, 0, "%d");
1229 } else {
1230 compare(ret, -1, "%d");
1233 DestroyWindow(hToolbar);
1236 static void test_createtoolbarex(void)
1238 HWND hToolbar;
1239 TBBUTTON btns[3];
1240 ZeroMemory(&btns, sizeof(btns));
1242 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1243 3, 20, 20, 16, 16, sizeof(TBBUTTON));
1244 CHECK_IMAGELIST(16, 20, 20);
1245 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x1a001b, "%x");
1246 DestroyWindow(hToolbar);
1248 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1249 3, 4, 4, 16, 16, sizeof(TBBUTTON));
1250 CHECK_IMAGELIST(32, 4, 4);
1251 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xa000b, "%x");
1252 DestroyWindow(hToolbar);
1254 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1255 3, 0, 8, 12, 12, sizeof(TBBUTTON));
1256 CHECK_IMAGELIST(16, 12, 12);
1257 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x120013, "%x");
1258 DestroyWindow(hToolbar);
1260 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1261 3, -1, 8, 12, 12, sizeof(TBBUTTON));
1262 CHECK_IMAGELIST(16, 12, 8);
1263 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0013, "%x");
1264 DestroyWindow(hToolbar);
1266 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1267 3, -1, 8, -1, 12, sizeof(TBBUTTON));
1268 CHECK_IMAGELIST(16, 16, 8);
1269 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0xe0017, "%x");
1270 DestroyWindow(hToolbar);
1272 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1273 3, 0, 0, 12, -1, sizeof(TBBUTTON));
1274 CHECK_IMAGELIST(16, 12, 16);
1275 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160013, "%x");
1276 DestroyWindow(hToolbar);
1278 hToolbar = CreateToolbarEx(hMainWnd, WS_VISIBLE, 1, 16, GetModuleHandle(NULL), IDB_BITMAP_128x15, btns,
1279 3, 0, 0, 0, 12, sizeof(TBBUTTON));
1280 CHECK_IMAGELIST(16, 16, 16);
1281 compare((int)SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0), 0x160017, "%x");
1282 DestroyWindow(hToolbar);
1285 static void test_dispinfo(void)
1287 HWND hToolbar = NULL;
1288 const TBBUTTON buttons_disp[] = {
1289 {-1, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1290 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1292 BOOL ret;
1294 rebuild_toolbar(&hToolbar);
1295 SendMessageA(hToolbar, TB_LOADIMAGES, IDB_HIST_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
1296 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons_disp);
1297 g_dwExpectedDispInfoMask = TBNF_IMAGE;
1298 /* Some TBN_GETDISPINFO tests will be done in MyWnd_Notify function.
1299 * We will receive TBN_GETDISPINFOW even if the control is ANSI */
1300 compare((BOOL)SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0, "%d");
1301 ShowWindow(hToolbar, SW_SHOW);
1302 UpdateWindow(hToolbar);
1304 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, TRUE, 0);
1305 compare(ret, FALSE, "%d");
1306 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 1L, "%ld");
1307 InvalidateRect(hToolbar, NULL, FALSE);
1308 UpdateWindow(hToolbar);
1310 ret = (BOOL)SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, FALSE, 0);
1311 compare(ret, TRUE, "%d");
1312 compare(SendMessageA(hToolbar, CCM_GETUNICODEFORMAT, 0, 0), 0L, "%ld");
1313 InvalidateRect(hToolbar, NULL, FALSE);
1314 UpdateWindow(hToolbar);
1316 DestroyWindow(hToolbar);
1317 g_dwExpectedDispInfoMask = 0;
1320 typedef struct
1322 int nRows;
1323 BOOL bLarger;
1324 int expectedRows;
1325 } tbrows_result_t;
1327 static tbrows_result_t tbrows_results[] =
1329 {1, TRUE, 1}, /* 0: Simple case 9 in a row */
1330 {2, TRUE, 2}, /* 1: Another simple case 5 on one row, 4 on another*/
1331 {3, FALSE, 3}, /* 2: 3 lines - should be 3 lines of 3 buttons */
1332 {8, FALSE, 5}, /* 3: 8 lines - should be 5 lines of 2 buttons */
1333 {8, TRUE, 9}, /* 4: 8 lines but grow - should be 9 lines */
1334 {1, TRUE, 1} /* 5: Back to simple case */
1337 static void test_setrows(void)
1339 TBBUTTON buttons[9];
1340 HWND hToolbar;
1341 int i;
1343 for (i=0; i<9; i++)
1344 MakeButton(buttons+i, 1000+i, TBSTYLE_FLAT | TBSTYLE_CHECKGROUP, 0);
1346 /* Test 1 - 9 buttons */
1347 hToolbar = CreateToolbarEx(hMainWnd,
1348 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD | CCS_NORESIZE | CCS_NOPARENTALIGN
1349 | CCS_NOMOVEY | CCS_TOP,
1351 0, NULL, 0,
1352 buttons, sizeof(buttons)/sizeof(buttons[0]),
1353 20, 20, 0, 0, sizeof(TBBUTTON));
1354 ok(hToolbar != NULL, "Toolbar creation\n");
1355 ok(SendMessageA(hToolbar, TB_AUTOSIZE, 0, 0) == 0, "TB_AUTOSIZE failed\n");
1357 /* test setting rows to each of 1-10 with bLarger true and false */
1358 for (i=0; i<(sizeof(tbrows_results) / sizeof(tbrows_result_t)); i++) {
1359 RECT rc;
1360 int rows;
1362 memset(&rc, 0xCC, sizeof(rc));
1363 SendMessageA(hToolbar, TB_SETROWS,
1364 MAKELONG(tbrows_results[i].nRows, tbrows_results[i].bLarger),
1365 (LPARAM) &rc);
1367 rows = SendMessageA(hToolbar, TB_GETROWS, MAKELONG(0,0), MAKELONG(0,0));
1368 ok(rows == tbrows_results[i].expectedRows,
1369 "[%d] Unexpected number of rows %d (expected %d)\n", i, rows,
1370 tbrows_results[i].expectedRows);
1373 DestroyWindow(hToolbar);
1376 static void test_getstring(void)
1378 HWND hToolbar = NULL;
1379 char str[10];
1380 WCHAR strW[10];
1381 static const char answer[] = "STR";
1382 static const WCHAR answerW[] = { 'S','T','R',0 };
1383 INT r;
1385 hToolbar = CreateWindowExA(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hMainWnd, (HMENU)5, GetModuleHandle(NULL), NULL);
1386 ok(hToolbar != NULL, "Toolbar creation problem\n");
1388 r = SendMessage(hToolbar, TB_GETSTRING, MAKEWPARAM(0, 0), 0);
1389 if (r == 0)
1391 win_skip("TB_GETSTRING and TB_GETSTRINGW need 5.80\n");
1392 DestroyWindow(hToolbar);
1393 return;
1395 expect(-1, r);
1396 r = SendMessage(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1397 expect(-1, r);
1398 r = SendMessage(hToolbar, TB_ADDSTRING, 0, (LPARAM)answer);
1399 expect(0, r);
1400 r = SendMessage(hToolbar, TB_GETSTRING, MAKEWPARAM(0, 0), 0);
1401 expect(lstrlenA(answer), r);
1402 r = SendMessage(hToolbar, TB_GETSTRINGW, MAKEWPARAM(0, 0), 0);
1403 expect(lstrlenA(answer), r);
1404 r = SendMessage(hToolbar, TB_GETSTRING, MAKEWPARAM(sizeof(str), 0), (LPARAM)str);
1405 expect(lstrlenA(answer), r);
1406 expect(0, lstrcmp(answer, str));
1407 r = SendMessage(hToolbar, TB_GETSTRINGW, MAKEWPARAM(sizeof(strW), 0), (LPARAM)strW);
1408 expect(lstrlenA(answer), r);
1409 expect(0, lstrcmpW(answerW, strW));
1411 DestroyWindow(hToolbar);
1414 static void test_tooltip(void)
1416 HWND hToolbar = NULL;
1417 const TBBUTTON buttons_disp[] = {
1418 {-1, 20, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1419 {0, 21, TBSTATE_ENABLED, 0, {0, }, 0, -1},
1421 NMTTDISPINFOW nmtti;
1423 rebuild_toolbar(&hToolbar);
1425 SendMessageA(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)buttons_disp);
1427 /* W used to get through toolbar code that assumes tooltip is always Unicode */
1428 memset(&nmtti, 0, sizeof(nmtti));
1429 nmtti.hdr.code = TTN_GETDISPINFOW;
1430 nmtti.hdr.idFrom = 20;
1432 SendMessageA(hToolbar, CCM_SETUNICODEFORMAT, FALSE, 0);
1434 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1435 SendMessageA(hToolbar, WM_NOTIFY, 0, (LPARAM)&nmtti);
1436 ok_sequence(sequences, PARENT_SEQ_INDEX, ttgetdispinfo_parent_seq,
1437 "dispinfo from tooltip", TRUE);
1439 g_ResetDispTextPtr = TRUE;
1440 SendMessageA(hToolbar, WM_NOTIFY, 0, (LPARAM)&nmtti);
1441 g_ResetDispTextPtr = FALSE;
1443 DestroyWindow(hToolbar);
1446 START_TEST(toolbar)
1448 WNDCLASSA wc;
1449 MSG msg;
1450 RECT rc;
1452 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1454 InitCommonControls();
1456 wc.style = CS_HREDRAW | CS_VREDRAW;
1457 wc.cbClsExtra = 0;
1458 wc.cbWndExtra = 0;
1459 wc.hInstance = GetModuleHandleA(NULL);
1460 wc.hIcon = NULL;
1461 wc.hCursor = LoadCursorA(NULL, IDC_IBEAM);
1462 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1463 wc.lpszMenuName = NULL;
1464 wc.lpszClassName = "Toolbar test parent";
1465 wc.lpfnWndProc = parent_wnd_proc;
1466 RegisterClassA(&wc);
1468 hMainWnd = CreateWindowExA(0, "Toolbar test parent", "Blah", WS_OVERLAPPEDWINDOW,
1469 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
1470 GetClientRect(hMainWnd, &rc);
1471 ShowWindow(hMainWnd, SW_SHOW);
1473 basic_test();
1474 test_add_bitmap();
1475 test_add_string();
1476 test_hotitem();
1477 test_sizes();
1478 test_recalc();
1479 test_getbuttoninfo();
1480 test_createtoolbarex();
1481 test_dispinfo();
1482 test_setrows();
1483 test_getstring();
1484 test_tooltip();
1486 PostQuitMessage(0);
1487 while(GetMessageA(&msg,0,0,0)) {
1488 TranslateMessage(&msg);
1489 DispatchMessageA(&msg);
1491 DestroyWindow(hMainWnd);