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
31 #include "resources.h"
33 #include "wine/test.h"
37 #define PARENT_SEQ_INDEX 0
38 #define NUM_MSG_SEQUENCES 1
40 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
43 static BOOL g_fBlockHotItemChange
;
44 static BOOL g_fReceivedHotItemChange
;
45 static BOOL g_fExpectedHotItemOld
;
46 static BOOL g_fExpectedHotItemNew
;
47 static DWORD g_dwExpectedDispInfoMask
;
48 static BOOL g_ResetDispTextPtr
;
50 static const struct message ttgetdispinfo_parent_seq
[] = {
51 { WM_NOTIFY
, sent
|id
, 0, 0, TBN_GETINFOTIPA
},
52 /* next line is todo, currently TTN_GETDISPINFOW is raised here */
53 { WM_NOTIFY
, sent
|id
, 0, 0, TTN_GETDISPINFOA
},
57 #define DEFINE_EXPECT(func) \
58 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
60 #define CHECK_EXPECT2(func) \
62 ok(expect_ ##func, "unexpected call " #func "\n"); \
63 called_ ## func = TRUE; \
66 #define CHECK_CALLED(func) \
68 ok(called_ ## func, "expected " #func "\n"); \
69 expect_ ## func = called_ ## func = FALSE; \
72 #define SET_EXPECT(func) \
73 expect_ ## func = TRUE
75 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
77 #define check_rect(name, val, exp, ...) ok(val.top == exp.top && val.bottom == exp.bottom && \
78 val.left == exp.left && val.right == exp.right, "invalid rect (%d,%d) (%d,%d) - expected (%d,%d) (%d,%d) - (" name ")\n", \
79 val.left, val.top, val.right, val.bottom, exp.left, exp.top, exp.right, exp.bottom, __VA_ARGS__);
81 #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
83 #define check_button_size(handle, width, height, ...) {\
84 LRESULT bsize = SendMessageA(handle, TB_GETBUTTONSIZE, 0, 0);\
85 ok(bsize == MAKELONG(width, height), "Unexpected button size - got size (%d, %d), expected (%d, %d)\n", LOWORD(bsize), HIWORD(bsize), width, height);\
88 static void MakeButton(TBBUTTON
*p
, int idCommand
, int fsStyle
, int nString
) {
90 p
->idCommand
= idCommand
;
91 p
->fsState
= TBSTATE_ENABLED
;
96 static LRESULT
parent_wnd_notify(LPARAM lParam
)
98 NMHDR
*hdr
= (NMHDR
*)lParam
;
100 NMTBDISPINFO
*nmdisp
;
103 case TBN_HOTITEMCHANGE
:
104 nmhi
= (NMTBHOTITEM
*)lParam
;
105 g_fReceivedHotItemChange
= TRUE
;
106 if (g_fExpectedHotItemOld
!= g_fExpectedHotItemNew
)
108 compare(nmhi
->idOld
, g_fExpectedHotItemOld
, "%d");
109 compare(nmhi
->idNew
, g_fExpectedHotItemNew
, "%d");
111 if (g_fBlockHotItemChange
)
115 case TBN_GETDISPINFOA
:
116 ok(FALSE
, "TBN_GETDISPINFOA received\n");
119 case TBN_GETINFOTIPA
:
121 NMTBGETINFOTIPA
*tbgit
= (NMTBGETINFOTIPA
*)lParam
;
123 if (g_ResetDispTextPtr
)
125 tbgit
->pszText
= NULL
;
130 case TBN_GETDISPINFOW
:
131 nmdisp
= (NMTBDISPINFOA
*)lParam
;
133 compare(nmdisp
->dwMask
, g_dwExpectedDispInfoMask
, "%x");
134 ok(nmdisp
->pszText
== NULL
, "pszText is not NULL\n");
140 static LRESULT CALLBACK
parent_wnd_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
142 static LONG defwndproc_counter
= 0;
146 msg
.message
= message
;
147 msg
.flags
= sent
|wparam
|lparam
;
148 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
151 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
153 /* log system messages, except for painting */
154 if (message
< WM_USER
&&
155 message
!= WM_PAINT
&&
156 message
!= WM_ERASEBKGND
&&
157 message
!= WM_NCPAINT
&&
158 message
!= WM_NCHITTEST
&&
159 message
!= WM_GETTEXT
&&
160 message
!= WM_GETICON
&&
161 message
!= WM_DEVICECHANGE
)
163 trace("parent: %p, %04x, %08lx, %08lx\n", hWnd
, message
, wParam
, lParam
);
164 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
170 return parent_wnd_notify(lParam
);
173 defwndproc_counter
++;
174 ret
= DefWindowProcA(hWnd
, message
, wParam
, lParam
);
175 defwndproc_counter
--;
180 static void basic_test(void)
187 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_CHECKGROUP
, 0);
188 MakeButton(buttons
+3, 1003, TBSTYLE_SEP
|TBSTYLE_GROUP
, 0);
189 MakeButton(buttons
+6, 1006, TBSTYLE_SEP
, 0);
191 hToolbar
= CreateToolbarEx(hMainWnd
,
192 WS_VISIBLE
| WS_CLIPCHILDREN
| CCS_TOP
|
193 WS_CHILD
| TBSTYLE_LIST
,
196 buttons
, sizeof(buttons
)/sizeof(buttons
[0]),
197 0, 0, 20, 16, sizeof(TBBUTTON
));
198 ok(hToolbar
!= NULL
, "Toolbar creation\n");
199 SendMessage(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)"test\000");
201 /* test for exclusion working inside a separator-separated :-) group */
202 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1000, 1); /* press A1 */
203 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
204 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1001, 0), "A2 not pressed\n");
206 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1004, 1); /* press A5, release A1 */
207 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1004, 0), "A5 pressed\n");
208 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 not pressed anymore\n");
210 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1005, 1); /* press A6, release A5 */
211 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 pressed\n");
212 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1004, 0), "A5 not pressed anymore\n");
214 /* test for inter-group crosstalk, ie. two radio groups interfering with each other */
215 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1007, 1); /* press B2 */
216 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
217 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 still not pressed\n");
218 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 pressed\n");
220 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1000, 1); /* press A1 and ensure B group didn't suffer */
221 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 not pressed anymore\n");
222 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
223 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 still pressed\n");
225 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1008, 1); /* press B3, and ensure A group didn't suffer */
226 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 pressed\n");
227 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
228 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 not pressed\n");
229 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1008, 0), "B3 pressed\n");
231 /* tests with invalid index */
232 compare(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 0xdeadbeef, 0), -1L, "%ld");
233 compare(SendMessage(hToolbar
, TB_ISBUTTONPRESSED
, 0xdeadbeef, 0), -1L, "%ld");
234 compare(SendMessage(hToolbar
, TB_ISBUTTONENABLED
, 0xdeadbeef, 0), -1L, "%ld");
235 compare(SendMessage(hToolbar
, TB_ISBUTTONINDETERMINATE
, 0xdeadbeef, 0), -1L, "%ld");
236 compare(SendMessage(hToolbar
, TB_ISBUTTONHIGHLIGHTED
, 0xdeadbeef, 0), -1L, "%ld");
237 compare(SendMessage(hToolbar
, TB_ISBUTTONHIDDEN
, 0xdeadbeef, 0), -1L, "%ld");
239 DestroyWindow(hToolbar
);
242 static void rebuild_toolbar(HWND
*hToolbar
)
245 DestroyWindow(*hToolbar
);
246 *hToolbar
= CreateWindowEx(0, TOOLBARCLASSNAME
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0,
247 hMainWnd
, (HMENU
)5, GetModuleHandle(NULL
), NULL
);
248 ok(*hToolbar
!= NULL
, "Toolbar creation problem\n");
249 ok(SendMessage(*hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
250 ok(SendMessage(*hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
251 ok(SendMessage(*hToolbar
, WM_SETFONT
, (WPARAM
)GetStockObject(SYSTEM_FONT
), 0)==1, "WM_SETFONT\n");
254 static void rebuild_toolbar_with_buttons(HWND
*hToolbar
)
257 rebuild_toolbar(hToolbar
);
259 ZeroMemory(&buttons
, sizeof(buttons
));
260 buttons
[0].idCommand
= 1;
261 buttons
[0].fsStyle
= BTNS_BUTTON
;
262 buttons
[0].fsState
= TBSTATE_ENABLED
;
263 buttons
[0].iString
= -1;
264 buttons
[1].idCommand
= 3;
265 buttons
[1].fsStyle
= BTNS_BUTTON
;
266 buttons
[1].fsState
= TBSTATE_ENABLED
;
267 buttons
[1].iString
= -1;
268 buttons
[2].idCommand
= 5;
269 buttons
[2].fsStyle
= BTNS_SEP
;
270 buttons
[2].fsState
= TBSTATE_ENABLED
;
271 buttons
[2].iString
= -1;
272 buttons
[3].idCommand
= 7;
273 buttons
[3].fsStyle
= BTNS_BUTTON
;
274 buttons
[3].fsState
= TBSTATE_ENABLED
;
275 buttons
[3].iString
= -1;
276 buttons
[4].idCommand
= 9;
277 buttons
[4].fsStyle
= BTNS_BUTTON
;
278 buttons
[4].fsState
= 0; /* disabled */
279 buttons
[4].iString
= -1;
280 ok(SendMessage(*hToolbar
, TB_ADDBUTTONS
, 5, (LPARAM
)buttons
) == 1, "TB_ADDBUTTONS failed\n");
281 ok(SendMessage(*hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
284 static void add_128x15_bitmap(HWND hToolbar
, int nCmds
)
287 bmp128
.hInst
= GetModuleHandle(NULL
);
288 bmp128
.nID
= IDB_BITMAP_128x15
;
289 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, nCmds
, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
292 #define CHECK_IMAGELIST(count, dx, dy) { \
294 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
295 ok(himl != NULL, "No image list\n"); \
297 ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
298 ImageList_GetIconSize(himl, &cx, &cy); \
299 ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
303 static void test_add_bitmap(void)
305 HWND hToolbar
= NULL
;
308 TBADDBITMAP stdsmall
;
313 /* empty 128x15 bitmap */
314 bmp128
.hInst
= GetModuleHandle(NULL
);
315 bmp128
.nID
= IDB_BITMAP_128x15
;
317 /* empty 80x15 bitmap */
318 bmp80
.hInst
= GetModuleHandle(NULL
);
319 bmp80
.nID
= IDB_BITMAP_80x15
;
321 /* standard bitmap - 240x15 pixels */
322 stdsmall
.hInst
= HINST_COMMCTRL
;
323 stdsmall
.nID
= IDB_STD_SMALL_COLOR
;
325 rebuild_toolbar(&hToolbar
);
326 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 8, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
327 CHECK_IMAGELIST(8, 16, 16);
329 /* adding more bitmaps */
330 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
) == 8, "TB_ADDBITMAP - unexpected return\n");
331 CHECK_IMAGELIST(13, 16, 16);
332 /* adding the same bitmap will simply return the index of the already loaded block */
333 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 8, (LPARAM
)&bmp128
);
334 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
335 CHECK_IMAGELIST(13, 16, 16);
336 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
);
337 ok(ret
== 8, "TB_ADDBITMAP - unexpected return %d\n", ret
);
338 CHECK_IMAGELIST(13, 16, 16);
339 /* even if we increase the wParam */
340 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 55, (LPARAM
)&bmp80
);
341 ok(ret
== 8, "TB_ADDBITMAP - unexpected return %d\n", ret
);
342 CHECK_IMAGELIST(13, 16, 16);
344 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
345 rebuild_toolbar(&hToolbar
);
346 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 3, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
347 CHECK_IMAGELIST(8, 16, 16);
348 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
);
349 ok(ret
== 3, "TB_ADDBITMAP - unexpected return %d\n", ret
);
350 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
351 CHECK_IMAGELIST(13, 16, 16);
353 /* the same for negative wParam */
354 rebuild_toolbar(&hToolbar
);
355 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, -143, (LPARAM
)&bmp128
);
356 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
357 CHECK_IMAGELIST(8, 16, 16);
358 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp80
);
359 ok(ret
== -143, "TB_ADDBITMAP - unexpected return %d\n", ret
);
360 CHECK_IMAGELIST(13, 16, 16);
362 /* for zero only one bitmap will be added */
363 rebuild_toolbar(&hToolbar
);
364 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&bmp80
);
365 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
366 CHECK_IMAGELIST(1, 16, 16);
368 /* if wParam is larger than the amount of icons, the list is grown */
369 rebuild_toolbar(&hToolbar
);
370 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp80
) == 0, "TB_ADDBITMAP - unexpected return\n");
371 CHECK_IMAGELIST(100, 16, 16);
372 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp128
);
373 ok(ret
== 100, "TB_ADDBITMAP - unexpected return %d\n", ret
);
374 CHECK_IMAGELIST(200, 16, 16);
376 /* adding built-in items - the wParam is ignored */
377 rebuild_toolbar(&hToolbar
);
378 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
) == 0, "TB_ADDBITMAP - unexpected return\n");
379 CHECK_IMAGELIST(5, 16, 16);
380 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&stdsmall
) == 5, "TB_ADDBITMAP - unexpected return\n");
381 CHECK_IMAGELIST(20, 16, 16);
382 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp128
) == 20, "TB_ADDBITMAP - unexpected return\n");
383 CHECK_IMAGELIST(28, 16, 16);
385 /* when we increase the bitmap size, less icons will be created */
386 rebuild_toolbar(&hToolbar
);
387 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(20, 20)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
388 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
389 CHECK_IMAGELIST(6, 20, 20);
390 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp80
);
391 ok(ret
== 1, "TB_ADDBITMAP - unexpected return %d\n", ret
);
392 CHECK_IMAGELIST(10, 20, 20);
393 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
394 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
395 UpdateWindow(hToolbar
);
396 CHECK_IMAGELIST(26, 8, 8);
397 /* loading a standard bitmaps automatically resizes the icons */
398 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&stdsmall
) == 2, "TB_ADDBITMAP - unexpected return\n");
399 UpdateWindow(hToolbar
);
400 CHECK_IMAGELIST(28, 16, 16);
402 /* two more SETBITMAPSIZE tests */
403 rebuild_toolbar(&hToolbar
);
404 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
405 CHECK_IMAGELIST(100, 16, 16);
406 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp80
) == 100, "TB_ADDBITMAP - unexpected return\n");
407 CHECK_IMAGELIST(200, 16, 16);
408 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
409 UpdateWindow(hToolbar
);
410 CHECK_IMAGELIST(200, 8, 8);
411 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(30, 30)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
412 UpdateWindow(hToolbar
);
413 CHECK_IMAGELIST(200, 30, 30);
414 rebuild_toolbar(&hToolbar
);
415 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
416 CHECK_IMAGELIST(8, 16, 16);
417 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 3, (LPARAM
)&bmp80
) == 5, "TB_ADDBITMAP - unexpected return\n");
418 CHECK_IMAGELIST(13, 16, 16);
419 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(30, 30)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
420 UpdateWindow(hToolbar
);
421 CHECK_IMAGELIST(8, 30, 30);
422 /* when the width or height is zero, set it to 1 */
423 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(0, 0)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
424 UpdateWindow(hToolbar
);
425 CHECK_IMAGELIST(208, 1, 1);
426 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(0, 5)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
427 UpdateWindow(hToolbar
);
428 CHECK_IMAGELIST(208, 1, 5);
429 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(5, 0)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
430 UpdateWindow(hToolbar
);
431 CHECK_IMAGELIST(41, 5, 1);
433 /* the control can add bitmaps to an existing image list */
434 rebuild_toolbar(&hToolbar
);
435 himl
= ImageList_LoadImage(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_BITMAP_80x15
), 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
436 ok(himl
!= NULL
, "failed to create imagelist\n");
437 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
438 CHECK_IMAGELIST(4, 20, 15);
439 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
440 CHECK_IMAGELIST(10, 20, 15);
441 /* however TB_SETBITMAPSIZE/add std bitmap won't change the image size (the button size does change) */
442 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
443 UpdateWindow(hToolbar
);
444 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(15, 14), "%x");
445 CHECK_IMAGELIST(10, 20, 15);
446 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&stdsmall
) == 1, "TB_SETBITMAPSIZE failed\n");
447 UpdateWindow(hToolbar
);
448 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(23, 22), "%x");
449 CHECK_IMAGELIST(22, 20, 15);
451 /* check standard bitmaps */
452 addbmp
.hInst
= HINST_COMMCTRL
;
453 addbmp
.nID
= IDB_STD_SMALL_COLOR
;
454 rebuild_toolbar(&hToolbar
);
455 ImageList_Destroy(himl
);
457 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
458 CHECK_IMAGELIST(15, 16, 16);
459 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(23, 22), "%x");
460 addbmp
.nID
= IDB_STD_LARGE_COLOR
;
461 rebuild_toolbar(&hToolbar
);
462 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
463 CHECK_IMAGELIST(15, 24, 24);
464 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(31, 30), "%x");
466 addbmp
.nID
= IDB_VIEW_SMALL_COLOR
;
467 rebuild_toolbar(&hToolbar
);
468 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
469 CHECK_IMAGELIST(12, 16, 16);
470 addbmp
.nID
= IDB_VIEW_LARGE_COLOR
;
471 rebuild_toolbar(&hToolbar
);
472 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
473 CHECK_IMAGELIST(12, 24, 24);
475 addbmp
.nID
= IDB_HIST_SMALL_COLOR
;
476 rebuild_toolbar(&hToolbar
);
477 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
478 CHECK_IMAGELIST(5, 16, 16);
479 addbmp
.nID
= IDB_HIST_LARGE_COLOR
;
480 rebuild_toolbar(&hToolbar
);
481 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
482 CHECK_IMAGELIST(5, 24, 24);
485 DestroyWindow(hToolbar
);
488 #define CHECK_STRING_TABLE(count, tab) { \
491 for (_i = 0; _i < (count); _i++) {\
492 ret = SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, _i), (LPARAM)_buf); \
493 ok(ret >= 0, "TB_GETSTRING - unexpected return %d while checking string %d\n", ret, _i); \
495 ok(strcmp(_buf, (tab)[_i]) == 0, "Invalid string #%d - '%s' vs '%s'\n", _i, (tab)[_i], _buf); \
497 ok(SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, (count)), (LPARAM)_buf) == -1, \
498 "Too many strings in table\n"); \
501 static void test_add_string(void)
503 LPCSTR test1
= "a\0b\0";
504 LPCSTR test2
= "|a|b||\0";
505 LPCSTR ret1
[] = {"a", "b"};
506 LPCSTR ret2
[] = {"a", "b", "|a|b||"};
507 LPCSTR ret3
[] = {"a", "b", "|a|b||", "p", "q"};
508 LPCSTR ret4
[] = {"a", "b", "|a|b||", "p", "q", "p"};
509 LPCSTR ret5
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q"};
510 LPCSTR ret6
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q"};
511 LPCSTR ret7
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q", "br", "c", "d"};
512 HWND hToolbar
= NULL
;
517 rebuild_toolbar(&hToolbar
);
518 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)test1
);
519 ok(ret
== 0, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
520 ret
= SendMessageA(hToolbar
, TB_GETSTRING
, MAKEWPARAM(260, 1), (LPARAM
)buf
);
523 win_skip("TB_GETSTRING needs 5.80\n");
526 CHECK_STRING_TABLE(2, ret1
);
527 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)test2
);
528 ok(ret
== 2, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
529 CHECK_STRING_TABLE(3, ret2
);
531 /* null instance handle */
532 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, IDS_TBADD1
);
533 ok(ret
== -1, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
535 /* invalid instance handle */
536 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0xdeadbeef, IDS_TBADD1
);
537 ok(ret
== -1, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
539 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD1
);
540 ok(ret
== 3, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
541 CHECK_STRING_TABLE(3, ret2
);
542 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD2
);
543 ok(ret
== 3, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
544 CHECK_STRING_TABLE(5, ret3
);
545 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD3
);
546 ok(ret
== 5, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
547 CHECK_STRING_TABLE(6, ret4
);
548 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD4
);
549 ok(ret
== 6, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
550 CHECK_STRING_TABLE(8, ret5
);
551 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD5
);
552 ok(ret
== 8, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
553 CHECK_STRING_TABLE(11, ret6
);
554 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD7
);
555 ok(ret
== 11, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
556 CHECK_STRING_TABLE(14, ret7
);
558 ZeroMemory(&button
, sizeof(button
));
559 button
.iString
= (UINT_PTR
)"Test";
560 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, 0, (LPARAM
)&button
);
561 CHECK_STRING_TABLE(14, ret7
);
562 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&button
);
563 CHECK_STRING_TABLE(14, ret7
);
565 DestroyWindow(hToolbar
);
568 static void expect_hot_notify(int idold
, int idnew
)
570 g_fExpectedHotItemOld
= idold
;
571 g_fExpectedHotItemNew
= idnew
;
572 g_fReceivedHotItemChange
= FALSE
;
575 #define check_hot_notify() \
576 ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
577 g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
579 static void test_hotitem(void)
581 HWND hToolbar
= NULL
;
585 g_fBlockHotItemChange
= FALSE
;
587 rebuild_toolbar_with_buttons(&hToolbar
);
588 /* set TBSTYLE_FLAT. comctl5 allows hot items only for such toolbars.
589 * comctl6 doesn't have this requirement even when theme == NULL */
590 SetWindowLong(hToolbar
, GWL_STYLE
, TBSTYLE_FLAT
| GetWindowLong(hToolbar
, GWL_STYLE
));
591 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
592 ok(ret
== -1, "Hot item: %ld, expected -1\n", ret
);
593 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 1, 0);
594 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
595 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
596 ok(ret
== 1, "Hot item: %ld, expected 1\n", ret
);
597 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 2, 0);
598 ok(ret
== 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret
);
600 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 0xbeef, 0);
601 ok(ret
== 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
602 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
603 ok(ret
== 2, "Hot item: %lx, expected 2\n", ret
);
604 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, -0xbeef, 0);
605 ok(ret
== 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
606 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
607 ok(ret
== -1, "Hot item: %lx, expected -1\n", ret
);
609 expect_hot_notify(0, 7);
610 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
611 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
613 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
614 ok(ret
== 3, "Hot item: %lx, expected 3\n", ret
);
615 g_fBlockHotItemChange
= TRUE
;
616 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 2, 0);
617 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
618 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
619 ok(ret
== 3, "Hot item: %lx, expected 3\n", ret
);
620 g_fBlockHotItemChange
= FALSE
;
622 g_fReceivedHotItemChange
= FALSE
;
623 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 0xbeaf, 0);
624 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
625 ok(g_fReceivedHotItemChange
== FALSE
, "TBN_HOTITEMCHANGE received for invalid parameter\n");
627 g_fReceivedHotItemChange
= FALSE
;
628 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
629 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
630 ok(g_fReceivedHotItemChange
== FALSE
, "TBN_HOTITEMCHANGE received after a duplication\n");
632 expect_hot_notify(7, 0);
633 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, -0xbeaf, 0);
634 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
636 SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
638 /* setting disabled buttons will generate a notify with the button id but no button will be hot */
639 expect_hot_notify(7, 9);
640 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 4, 0);
641 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
643 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
644 ok(ret
== -1, "Hot item: %lx, expected -1\n", ret
);
645 /* enabling the button won't change that */
646 SendMessage(hToolbar
, TB_ENABLEBUTTON
, 9, TRUE
);
647 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
648 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
650 /* disabling a hot button works */
651 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
652 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
653 g_fReceivedHotItemChange
= FALSE
;
654 SendMessage(hToolbar
, TB_ENABLEBUTTON
, 7, FALSE
);
655 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
656 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
657 ok(g_fReceivedHotItemChange
== FALSE
, "Unexpected TBN_HOTITEMCHANGE\n");
659 SendMessage(hToolbar
, TB_SETHOTITEM
, 1, 0);
660 tbinfo
.cbSize
= sizeof(TBBUTTONINFO
);
661 tbinfo
.dwMask
= TBIF_STATE
;
662 tbinfo
.fsState
= 0; /* disabled */
663 g_fReceivedHotItemChange
= FALSE
;
664 ok(SendMessage(hToolbar
, TB_SETBUTTONINFO
, 1, (LPARAM
)&tbinfo
) == TRUE
, "TB_SETBUTTONINFO failed\n");
665 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
666 ok(ret
== 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret
);
667 ok(g_fReceivedHotItemChange
== FALSE
, "Unexpected TBN_HOTITEMCHANGE\n");
669 DestroyWindow(hToolbar
);
672 #if 0 /* use this to generate more tests*/
674 static void dump_sizes(HWND hToolbar
)
678 int count
= SendMessage(hToolbar
, TB_BUTTONCOUNT
, 0, 0);
681 GetClientRect(hToolbar
, &r
);
682 SendMessageA(hToolbar
, TB_GETMAXSIZE
, 0, &sz
);
683 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r
.left
, r
.top
, r
.right
, r
.bottom
,
684 sz
.cx
, sz
.cy
, count
);
685 for (i
=0; i
<count
; i
++)
687 SendMessageA(hToolbar
, TB_GETITEMRECT
, i
, &r
);
688 printf("%s{%3d, %3d, %3d, %3d}, ", (i
%3==0 ? "\n " : ""), r
.left
, r
.top
, r
.right
, r
.bottom
);
690 printf("\n }, },\n");
693 #define check_sizes() dump_sizes(hToolbar);
694 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
698 static int system_font_height(void) {
702 hDC
= CreateCompatibleDC(NULL
);
703 GetTextMetrics(hDC
, &tm
);
709 static int string_width(const CHAR
*s
) {
713 hdc
= CreateCompatibleDC(NULL
);
714 GetTextExtentPoint32A(hdc
, s
, strlen(s
), &sz
);
728 static tbsize_result_t
init_tbsize_result(int nButtonsAlloc
, int cleft
, int ctop
, int cright
, int cbottom
, int minx
, int miny
) {
731 SetRect(&ret
.rcClient
, cleft
, ctop
, cright
, cbottom
);
735 ret
.prcButtons
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nButtonsAlloc
*sizeof(RECT
));
740 static void tbsize_addbutton(tbsize_result_t
*tbsr
, int left
, int top
, int right
, int bottom
) {
741 SetRect(&tbsr
->prcButtons
[tbsr
->nButtons
], left
, top
, right
, bottom
);
746 #define STRING1 "MMMMMMMMMMMMM"
747 #define STRING2 "Tst"
749 static tbsize_result_t
*tbsize_results
;
751 #define tbsize_results_num 24
753 static void init_tbsize_results(void) {
754 int fontheight
= system_font_height();
757 tbsize_results
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, tbsize_results_num
*sizeof(tbsize_result_t
));
759 tbsize_results
[0] = init_tbsize_result(5, 0, 0 ,672 ,26, 100 ,22);
760 tbsize_addbutton(&tbsize_results
[0], 0, 2, 23, 24);
761 tbsize_addbutton(&tbsize_results
[0], 23, 2, 46, 24);
762 tbsize_addbutton(&tbsize_results
[0], 46, 2, 54, 24);
763 tbsize_addbutton(&tbsize_results
[0], 54, 2, 77, 24);
764 tbsize_addbutton(&tbsize_results
[0], 77, 2, 100, 24);
766 tbsize_results
[1] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
767 tbsize_addbutton(&tbsize_results
[1], 0, 2, 23, 24);
768 tbsize_addbutton(&tbsize_results
[1], 23, 2, 46, 24);
769 tbsize_addbutton(&tbsize_results
[1], 46, 2, 54, 24);
770 tbsize_addbutton(&tbsize_results
[1], 54, 2, 77, 24);
771 tbsize_addbutton(&tbsize_results
[1], 77, 2, 100, 24);
772 tbsize_addbutton(&tbsize_results
[1], 100, 2, 123, 24);
773 tbsize_addbutton(&tbsize_results
[1], 0, 24, 23, 46);
775 tbsize_results
[2] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
776 tbsize_addbutton(&tbsize_results
[2], 0, 2, 23, 24);
777 tbsize_addbutton(&tbsize_results
[2], 23, 2, 46, 24);
778 tbsize_addbutton(&tbsize_results
[2], 46, 2, 54, 24);
779 tbsize_addbutton(&tbsize_results
[2], 54, 2, 77, 24);
780 tbsize_addbutton(&tbsize_results
[2], 77, 2, 100, 24);
781 tbsize_addbutton(&tbsize_results
[2], 100, 2, 123, 24);
782 tbsize_addbutton(&tbsize_results
[2], 0, 24, 23, 46);
784 tbsize_results
[3] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
785 tbsize_addbutton(&tbsize_results
[3], 0, 2, 23, 24);
786 tbsize_addbutton(&tbsize_results
[3], 23, 2, 46, 24);
787 tbsize_addbutton(&tbsize_results
[3], 46, 2, 54, 24);
788 tbsize_addbutton(&tbsize_results
[3], 54, 2, 77, 24);
789 tbsize_addbutton(&tbsize_results
[3], 77, 2, 100, 24);
790 tbsize_addbutton(&tbsize_results
[3], 100, 2, 123, 24);
791 tbsize_addbutton(&tbsize_results
[3], 123, 2, 146, 24);
793 tbsize_results
[4] = init_tbsize_result(9, 0, 0, 672, 26, 192, 22);
794 tbsize_addbutton(&tbsize_results
[4], 0, 2, 23, 24);
795 tbsize_addbutton(&tbsize_results
[4], 23, 2, 46, 24);
796 tbsize_addbutton(&tbsize_results
[4], 46, 2, 54, 24);
797 tbsize_addbutton(&tbsize_results
[4], 54, 2, 77, 24);
798 tbsize_addbutton(&tbsize_results
[4], 77, 2, 100, 24);
799 tbsize_addbutton(&tbsize_results
[4], 100, 2, 123, 24);
800 tbsize_addbutton(&tbsize_results
[4], 123, 2, 146, 24);
801 tbsize_addbutton(&tbsize_results
[4], 146, 2, 169, 24);
802 tbsize_addbutton(&tbsize_results
[4], 169, 2, 192, 24);
804 tbsize_results
[5] = init_tbsize_result(39, 0, 0, 672, 92, 882, 22);
805 tbsize_addbutton(&tbsize_results
[5], 0, 2, 23, 24);
806 tbsize_addbutton(&tbsize_results
[5], 23, 2, 46, 24);
807 tbsize_addbutton(&tbsize_results
[5], 0, 2, 8, 29);
808 tbsize_addbutton(&tbsize_results
[5], 0, 29, 23, 51);
809 tbsize_addbutton(&tbsize_results
[5], 23, 29, 46, 51);
810 tbsize_addbutton(&tbsize_results
[5], 46, 29, 69, 51);
811 tbsize_addbutton(&tbsize_results
[5], 69, 29, 92, 51);
812 tbsize_addbutton(&tbsize_results
[5], 92, 29, 115, 51);
813 tbsize_addbutton(&tbsize_results
[5], 115, 29, 138, 51);
814 tbsize_addbutton(&tbsize_results
[5], 138, 29, 161, 51);
815 tbsize_addbutton(&tbsize_results
[5], 161, 29, 184, 51);
816 tbsize_addbutton(&tbsize_results
[5], 184, 29, 207, 51);
817 tbsize_addbutton(&tbsize_results
[5], 207, 29, 230, 51);
818 tbsize_addbutton(&tbsize_results
[5], 230, 29, 253, 51);
819 tbsize_addbutton(&tbsize_results
[5], 253, 29, 276, 51);
820 tbsize_addbutton(&tbsize_results
[5], 276, 29, 299, 51);
821 tbsize_addbutton(&tbsize_results
[5], 299, 29, 322, 51);
822 tbsize_addbutton(&tbsize_results
[5], 322, 29, 345, 51);
823 tbsize_addbutton(&tbsize_results
[5], 345, 29, 368, 51);
824 tbsize_addbutton(&tbsize_results
[5], 368, 29, 391, 51);
825 tbsize_addbutton(&tbsize_results
[5], 391, 29, 414, 51);
826 tbsize_addbutton(&tbsize_results
[5], 414, 29, 437, 51);
827 tbsize_addbutton(&tbsize_results
[5], 437, 29, 460, 51);
828 tbsize_addbutton(&tbsize_results
[5], 460, 29, 483, 51);
829 tbsize_addbutton(&tbsize_results
[5], 483, 29, 506, 51);
830 tbsize_addbutton(&tbsize_results
[5], 506, 29, 529, 51);
831 tbsize_addbutton(&tbsize_results
[5], 529, 29, 552, 51);
832 tbsize_addbutton(&tbsize_results
[5], 552, 29, 575, 51);
833 tbsize_addbutton(&tbsize_results
[5], 575, 29, 598, 51);
834 tbsize_addbutton(&tbsize_results
[5], 598, 29, 621, 51);
835 tbsize_addbutton(&tbsize_results
[5], 621, 29, 644, 51);
836 tbsize_addbutton(&tbsize_results
[5], 644, 29, 667, 51);
837 tbsize_addbutton(&tbsize_results
[5], 0, 51, 23, 73);
838 tbsize_addbutton(&tbsize_results
[5], 23, 51, 46, 73);
839 tbsize_addbutton(&tbsize_results
[5], 46, 51, 69, 73);
840 tbsize_addbutton(&tbsize_results
[5], 69, 51, 92, 73);
841 tbsize_addbutton(&tbsize_results
[5], 92, 51, 115, 73);
842 tbsize_addbutton(&tbsize_results
[5], 115, 51, 138, 73);
843 tbsize_addbutton(&tbsize_results
[5], 138, 51, 161, 73);
845 tbsize_results
[6] = init_tbsize_result(7, 0, 0, 48, 226, 23, 140);
846 tbsize_addbutton(&tbsize_results
[6], 0, 2, 23, 24);
847 tbsize_addbutton(&tbsize_results
[6], 23, 2, 46, 24);
848 tbsize_addbutton(&tbsize_results
[6], 46, 2, 94, 24);
849 tbsize_addbutton(&tbsize_results
[6], 94, 2, 117, 24);
850 tbsize_addbutton(&tbsize_results
[6], 117, 2, 140, 24);
851 tbsize_addbutton(&tbsize_results
[6], 140, 2, 163, 24);
852 tbsize_addbutton(&tbsize_results
[6], 0, 24, 23, 46);
854 tbsize_results
[7] = init_tbsize_result(7, 0, 0, 92, 226, 23, 140);
855 tbsize_addbutton(&tbsize_results
[7], 0, 2, 23, 24);
856 tbsize_addbutton(&tbsize_results
[7], 23, 2, 46, 24);
857 tbsize_addbutton(&tbsize_results
[7], 0, 24, 92, 32);
858 tbsize_addbutton(&tbsize_results
[7], 0, 32, 23, 54);
859 tbsize_addbutton(&tbsize_results
[7], 23, 32, 46, 54);
860 tbsize_addbutton(&tbsize_results
[7], 46, 32, 69, 54);
861 tbsize_addbutton(&tbsize_results
[7], 69, 32, 92, 54);
863 tbsize_results
[8] = init_tbsize_result(7, 0, 0, 672, 26, 194, 30);
864 tbsize_addbutton(&tbsize_results
[8], 0, 2, 31, 32);
865 tbsize_addbutton(&tbsize_results
[8], 31, 2, 62, 32);
866 tbsize_addbutton(&tbsize_results
[8], 62, 2, 70, 32);
867 tbsize_addbutton(&tbsize_results
[8], 70, 2, 101, 32);
868 tbsize_addbutton(&tbsize_results
[8], 101, 2, 132, 32);
869 tbsize_addbutton(&tbsize_results
[8], 132, 2, 163, 32);
870 tbsize_addbutton(&tbsize_results
[8], 0, 32, 31, 62);
872 tbsize_results
[9] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
873 tbsize_addbutton(&tbsize_results
[9], 0, 2, 31, 32);
874 tbsize_addbutton(&tbsize_results
[9], 31, 2, 62, 32);
875 tbsize_addbutton(&tbsize_results
[9], 62, 2, 70, 32);
876 tbsize_addbutton(&tbsize_results
[9], 70, 2, 101, 32);
877 tbsize_addbutton(&tbsize_results
[9], 101, 2, 132, 32);
878 tbsize_addbutton(&tbsize_results
[9], 132, 2, 163, 32);
879 tbsize_addbutton(&tbsize_results
[9], 0, 32, 31, 62);
881 tbsize_results
[10] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
882 tbsize_addbutton(&tbsize_results
[10], 0, 0, 31, 30);
883 tbsize_addbutton(&tbsize_results
[10], 31, 0, 62, 30);
884 tbsize_addbutton(&tbsize_results
[10], 62, 0, 70, 30);
885 tbsize_addbutton(&tbsize_results
[10], 70, 0, 101, 30);
886 tbsize_addbutton(&tbsize_results
[10], 101, 0, 132, 30);
887 tbsize_addbutton(&tbsize_results
[10], 132, 0, 163, 30);
888 tbsize_addbutton(&tbsize_results
[10], 0, 30, 31, 60);
890 tbsize_results
[11] = init_tbsize_result(7, 0, 0, 124, 226, 31, 188);
891 tbsize_addbutton(&tbsize_results
[11], 0, 0, 31, 30);
892 tbsize_addbutton(&tbsize_results
[11], 31, 0, 62, 30);
893 tbsize_addbutton(&tbsize_results
[11], 0, 30, 124, 38);
894 tbsize_addbutton(&tbsize_results
[11], 0, 38, 31, 68);
895 tbsize_addbutton(&tbsize_results
[11], 31, 38, 62, 68);
896 tbsize_addbutton(&tbsize_results
[11], 62, 38, 93, 68);
897 tbsize_addbutton(&tbsize_results
[11], 93, 38, 124, 68);
899 tbsize_results
[12] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
900 tbsize_addbutton(&tbsize_results
[12], 0, 2, 23, 24);
901 tbsize_addbutton(&tbsize_results
[12], 23, 2, 46, 24);
902 tbsize_addbutton(&tbsize_results
[12], 46, 2, 54, 24);
903 tbsize_addbutton(&tbsize_results
[12], 54, 2, 77, 24);
904 tbsize_addbutton(&tbsize_results
[12], 77, 2, 100, 24);
905 tbsize_addbutton(&tbsize_results
[12], 100, 2, 123, 24);
906 tbsize_addbutton(&tbsize_results
[12], 123, 2, 146, 24);
908 tbsize_results
[13] = init_tbsize_result(7, 0, 0, 672, 26, 146, 100);
909 tbsize_addbutton(&tbsize_results
[13], 0, 0, 23, 100);
910 tbsize_addbutton(&tbsize_results
[13], 23, 0, 46, 100);
911 tbsize_addbutton(&tbsize_results
[13], 46, 0, 54, 100);
912 tbsize_addbutton(&tbsize_results
[13], 54, 0, 77, 100);
913 tbsize_addbutton(&tbsize_results
[13], 77, 0, 100, 100);
914 tbsize_addbutton(&tbsize_results
[13], 100, 0, 123, 100);
915 tbsize_addbutton(&tbsize_results
[13], 123, 0, 146, 100);
917 tbsize_results
[14] = init_tbsize_result(10, 0, 0, 672, 26, 146, 100);
918 tbsize_addbutton(&tbsize_results
[14], 0, 0, 23, 100);
919 tbsize_addbutton(&tbsize_results
[14], 23, 0, 46, 100);
920 tbsize_addbutton(&tbsize_results
[14], 46, 0, 54, 100);
921 tbsize_addbutton(&tbsize_results
[14], 54, 0, 77, 100);
922 tbsize_addbutton(&tbsize_results
[14], 77, 0, 100, 100);
923 tbsize_addbutton(&tbsize_results
[14], 100, 0, 123, 100);
924 tbsize_addbutton(&tbsize_results
[14], 123, 0, 146, 100);
925 tbsize_addbutton(&tbsize_results
[14], 146, 0, 169, 100);
926 tbsize_addbutton(&tbsize_results
[14], 169, 0, 192, 100);
927 tbsize_addbutton(&tbsize_results
[14], 192, 0, 215, 100);
929 tbsize_results
[15] = init_tbsize_result(11, 0, 0, 672, 26, 238, 39);
930 tbsize_addbutton(&tbsize_results
[15], 0, 0, 23, 23 + fontheight
);
931 tbsize_addbutton(&tbsize_results
[15], 23, 0, 46, 23 + fontheight
);
932 tbsize_addbutton(&tbsize_results
[15], 46, 0, 54, 23 + fontheight
);
933 tbsize_addbutton(&tbsize_results
[15], 54, 0, 77, 23 + fontheight
);
934 tbsize_addbutton(&tbsize_results
[15], 77, 0, 100, 23 + fontheight
);
935 tbsize_addbutton(&tbsize_results
[15], 100, 0, 123, 23 + fontheight
);
936 tbsize_addbutton(&tbsize_results
[15], 123, 0, 146, 23 + fontheight
);
937 tbsize_addbutton(&tbsize_results
[15], 146, 0, 169, 23 + fontheight
);
938 tbsize_addbutton(&tbsize_results
[15], 169, 0, 192, 23 + fontheight
);
939 tbsize_addbutton(&tbsize_results
[15], 192, 0, 215, 23 + fontheight
);
940 tbsize_addbutton(&tbsize_results
[15], 215, 0, 238, 23 + fontheight
);
942 tbsize_results
[16] = init_tbsize_result(11, 0, 0, 672, 26, 239, 22);
943 tbsize_addbutton(&tbsize_results
[16], 0, 0, 23, 22);
944 tbsize_addbutton(&tbsize_results
[16], 23, 0, 46, 22);
945 tbsize_addbutton(&tbsize_results
[16], 46, 0, 54, 22);
946 tbsize_addbutton(&tbsize_results
[16], 54, 0, 77, 22);
947 tbsize_addbutton(&tbsize_results
[16], 77, 0, 100, 22);
948 tbsize_addbutton(&tbsize_results
[16], 100, 0, 123, 22);
949 tbsize_addbutton(&tbsize_results
[16], 123, 0, 146, 22);
950 tbsize_addbutton(&tbsize_results
[16], 146, 0, 169, 22);
951 tbsize_addbutton(&tbsize_results
[16], 169, 0, 192, 22);
952 tbsize_addbutton(&tbsize_results
[16], 192, 0, 215, 22);
953 tbsize_addbutton(&tbsize_results
[16], 215, 0, 238, 22);
955 buttonwidth
= 7 + string_width(STRING1
);
957 tbsize_results
[17] = init_tbsize_result(3, 0, 0, 672, 26, 489, 39);
958 tbsize_addbutton(&tbsize_results
[17], 0, 2, buttonwidth
, 25 + fontheight
);
959 tbsize_addbutton(&tbsize_results
[17], buttonwidth
, 2, 2*buttonwidth
+ 4, 25 + fontheight
);
960 tbsize_addbutton(&tbsize_results
[17], 2*buttonwidth
+ 4, 2, 3*buttonwidth
+ 4, 25 + fontheight
);
962 tbsize_results
[18] = init_tbsize_result(6, 0, 0, 672, 104, 978, 24);
963 tbsize_addbutton(&tbsize_results
[18], 0, 2, buttonwidth
, 10 + fontheight
);
964 tbsize_addbutton(&tbsize_results
[18], buttonwidth
, 2, 2*buttonwidth
, 10 + fontheight
);
965 tbsize_addbutton(&tbsize_results
[18], 2*buttonwidth
, 2, 3*buttonwidth
, 10 + fontheight
);
966 tbsize_addbutton(&tbsize_results
[18], 3*buttonwidth
, 2, 4*buttonwidth
, 10 + fontheight
);
967 tbsize_addbutton(&tbsize_results
[18], 4*buttonwidth
, 2, 5*buttonwidth
+ 4, 10 + fontheight
);
968 tbsize_addbutton(&tbsize_results
[18], 5*buttonwidth
+ 4, 2, 5*buttonwidth
+ 4 + string_width(STRING2
) + 11, 10 + fontheight
);
970 tbsize_results
[19] = init_tbsize_result(6, 0, 0, 672, 28, 978, 38);
971 tbsize_addbutton(&tbsize_results
[19], 0, 0, buttonwidth
, 22 + fontheight
);
972 tbsize_addbutton(&tbsize_results
[19], buttonwidth
, 0, 2*buttonwidth
, 22 + fontheight
);
973 tbsize_addbutton(&tbsize_results
[19], 2*buttonwidth
, 0, 3*buttonwidth
, 22 + fontheight
);
974 tbsize_addbutton(&tbsize_results
[19], 3*buttonwidth
, 0, 4*buttonwidth
, 22 + fontheight
);
975 tbsize_addbutton(&tbsize_results
[19], 4*buttonwidth
, 0, 5*buttonwidth
+ 4, 22 + fontheight
);
976 tbsize_addbutton(&tbsize_results
[19], 5*buttonwidth
+ 4, 0, 5*buttonwidth
+ 4 + string_width(STRING2
) + 11, 22 + fontheight
);
978 tbsize_results
[20] = init_tbsize_result(3, 0, 0, 672, 100, 239, 102);
979 tbsize_addbutton(&tbsize_results
[20], 0, 2, 100, 102);
980 tbsize_addbutton(&tbsize_results
[20], 100, 2, 139, 102);
981 tbsize_addbutton(&tbsize_results
[20], 139, 2, 239, 102);
983 tbsize_results
[21] = init_tbsize_result(3, 0, 0, 672, 42, 185, 40);
984 tbsize_addbutton(&tbsize_results
[21], 0, 2, 75, 40);
985 tbsize_addbutton(&tbsize_results
[21], 75, 2, 118, 40);
986 tbsize_addbutton(&tbsize_results
[21], 118, 2, 165 + string_width(STRING2
), 40);
988 tbsize_results
[22] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
989 tbsize_addbutton(&tbsize_results
[22], 0, 2, 47 + string_width(STRING2
), 40);
991 tbsize_results
[23] = init_tbsize_result(2, 0, 0, 672, 42, 67, 41);
992 tbsize_addbutton(&tbsize_results
[23], 0, 2, 672, 25 + fontheight
);
993 tbsize_addbutton(&tbsize_results
[23], 0, 25 + fontheight
, 672, 48 + 2*fontheight
);
996 static void free_tbsize_results(void) {
999 for (i
= 0; i
< tbsize_results_num
; i
++)
1000 HeapFree(GetProcessHeap(), 0, tbsize_results
[i
].prcButtons
);
1001 HeapFree(GetProcessHeap(), 0, tbsize_results
);
1002 tbsize_results
= NULL
;
1005 static int tbsize_numtests
= 0;
1012 } tbsize_alt_result_t
;
1014 static tbsize_alt_result_t tbsize_alt_results
[] =
1016 { 5, 2, { 0, 24, 8, 29 } },
1017 { 20, 1, { 100, 2, 107, 102 } },
1018 { 20, 2, { 107, 2, 207, 102 } }
1021 static DWORD tbsize_alt_numtests
= 0;
1023 #define check_sizes_todo(todomask) { \
1025 int buttonCount, i, mask=(todomask); \
1026 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
1027 GetClientRect(hToolbar, &rc); \
1028 /*check_rect("client", rc, res->rcClient);*/ \
1029 buttonCount = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0); \
1030 compare(buttonCount, res->nButtons, "%d"); \
1031 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
1032 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
1033 if (broken(tbsize_alt_numtests < sizeof(tbsize_alt_results)/sizeof(tbsize_alt_results[0]) && \
1034 memcmp(&rc, &tbsize_alt_results[tbsize_alt_numtests].rcButton, sizeof(RECT)) == 0)) { \
1035 win_skip("Alternate rect found\n"); \
1036 tbsize_alt_numtests++; \
1037 } else if (!(mask&1)) { \
1038 check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); \
1040 todo_wine { check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); } \
1044 tbsize_numtests++; \
1047 #define check_sizes() check_sizes_todo(0)
1051 static TBBUTTON buttons1
[] = {
1052 {0, 10, TBSTATE_WRAP
|TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1053 {0, 11, 0, 0, {0, }, 0, -1},
1055 static TBBUTTON buttons2
[] = {
1056 {0, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1057 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1059 static TBBUTTON buttons3
[] = {
1060 {0, 30, TBSTATE_ENABLED
, 0, {0, }, 0, 0},
1061 {0, 31, TBSTATE_ENABLED
, 0, {0, }, 0, 1},
1062 {0, 32, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, 1},
1063 {0, 33, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, (UINT_PTR
)STRING2
}
1066 static void test_sizes(void)
1068 HWND hToolbar
= NULL
;
1069 HIMAGELIST himl
, himl2
;
1070 TBBUTTONINFO tbinfo
;
1073 int fontheight
= system_font_height();
1075 init_tbsize_results();
1077 rebuild_toolbar_with_buttons(&hToolbar
);
1078 style
= GetWindowLong(hToolbar
, GWL_STYLE
);
1079 ok(style
== (WS_CHILD
|WS_VISIBLE
|CCS_TOP
), "Invalid style %x\n", style
);
1081 /* the TBSTATE_WRAP makes a second row */
1082 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
1084 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1086 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
1087 SetWindowLong(hToolbar
, GWL_STYLE
, style
|TBSTYLE_WRAPABLE
);
1089 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
1090 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
1092 /* only after adding enough buttons the bar will be wrapped on a
1093 * separator and then on the first button */
1094 for (i
=0; i
<15; i
++)
1095 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
1096 check_sizes_todo(0x4);
1098 rebuild_toolbar_with_buttons(&hToolbar
);
1099 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
1100 /* setting the buttons vertical will only change the window client size */
1101 SetWindowLong(hToolbar
, GWL_STYLE
, style
| CCS_VERT
);
1102 SendMessage(hToolbar
, TB_AUTOSIZE
, 0, 0);
1103 check_sizes_todo(0x3c);
1104 /* with a TBSTYLE_WRAPABLE a wrapping will occur on the separator */
1105 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_WRAPABLE
| CCS_VERT
);
1106 SendMessage(hToolbar
, TB_AUTOSIZE
, 0, 0);
1107 check_sizes_todo(0x7c);
1109 rebuild_toolbar_with_buttons(&hToolbar
);
1110 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
1111 /* a TB_SETBITMAPSIZE changes button sizes*/
1112 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(24, 24));
1115 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
1116 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
);
1117 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1119 /* but after a TB_SETBITMAPSIZE the top margins is changed */
1120 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(20, 20));
1121 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(24, 24));
1123 /* some vertical toolbar sizes */
1124 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
| TBSTYLE_WRAPABLE
| CCS_VERT
);
1125 check_sizes_todo(0x7c);
1127 rebuild_toolbar_with_buttons(&hToolbar
);
1128 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
);
1129 /* newly added buttons will be use the previous margin */
1130 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons2
);
1132 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
1133 check_button_size(hToolbar
, 23, 22);
1134 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
1135 check_button_size(hToolbar
, 23, 22);
1136 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1137 check_button_size(hToolbar
, 23, 100);
1138 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
1139 check_button_size(hToolbar
, 23, 22);
1140 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1141 check_button_size(hToolbar
, 23, 100);
1143 /* add some buttons with non-default sizes */
1144 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons2
);
1145 SendMessageA(hToolbar
, TB_INSERTBUTTON
, -1, (LPARAM
)&buttons2
[0]);
1147 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[0]);
1148 /* TB_ADDSTRING resets the size */
1149 SendMessageA(hToolbar
, TB_ADDSTRING
, 0, (LPARAM
) STRING0
"\0" STRING1
"\0");
1150 check_button_size(hToolbar
, 23, 23 + fontheight
);
1152 /* TB_SETBUTTONSIZE can be used to crop the text */
1153 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1154 check_button_size(hToolbar
, 23, 22);
1156 /* the default size is bitmap size + padding */
1157 SendMessageA(hToolbar
, TB_SETPADDING
, 0, MAKELONG(1, 1));
1158 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1159 check_button_size(hToolbar
, 17, 17);
1160 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(3, 3));
1161 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1162 check_button_size(hToolbar
, 4, 4);
1164 rebuild_toolbar(&hToolbar
);
1165 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
1166 check_button_size(hToolbar
, 23, 22);
1167 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(16, 15));
1168 check_button_size(hToolbar
, 23, 21);
1169 /* -1 in TB_SETBITMAPSIZE is a special code meaning that the coordinate shouldn't be changed */
1170 add_128x15_bitmap(hToolbar
, 16);
1171 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(14, -1)), "TB_SETBITMAPSIZE failed\n");
1172 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 21), "%x");
1173 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(-1, 12)), "TB_SETBITMAPSIZE failed\n");
1174 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 18), "%x");
1175 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(-1, -1)), "TB_SETBITMAPSIZE failed\n");
1176 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 18), "%x");
1177 /* check the imagelist */
1178 InvalidateRect(hToolbar
, NULL
, TRUE
);
1179 UpdateWindow(hToolbar
);
1180 CHECK_IMAGELIST(16, 14, 12);
1182 rebuild_toolbar(&hToolbar
);
1183 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)STRING0
"\0" STRING1
"\0");
1184 /* the height is increased after a TB_ADDSTRING */
1185 check_button_size(hToolbar
, 23, 23 + fontheight
);
1186 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1187 /* if a string is in the pool, even adding a button without a string resets the size */
1188 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons2
[0]);
1189 check_button_size(hToolbar
, 23, 22);
1190 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1191 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
1192 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[2]);
1193 check_button_size(hToolbar
, 7 + string_width(STRING1
), 23 + fontheight
);
1194 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[0]);
1196 /* delete button doesn't change the buttons size */
1197 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 2, 0);
1198 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 1, 0);
1199 check_button_size(hToolbar
, 7 + string_width(STRING1
), 23 + fontheight
);
1200 /* TB_INSERTBUTTONS will */
1201 SendMessageA(hToolbar
, TB_INSERTBUTTON
, 1, (LPARAM
)&buttons2
[0]);
1202 check_button_size(hToolbar
, 23, 22);
1204 /* TB_HIDEBUTTON and TB_MOVEBUTTON doesn't force a recalc */
1205 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1206 ok(SendMessageA(hToolbar
, TB_MOVEBUTTON
, 0, 1), "TB_MOVEBUTTON failed\n");
1207 check_button_size(hToolbar
, 100, 100);
1208 ok(SendMessageA(hToolbar
, TB_HIDEBUTTON
, 20, TRUE
), "TB_HIDEBUTTON failed\n");
1209 check_button_size(hToolbar
, 100, 100);
1210 /* however changing the hidden flag with TB_SETSTATE does */
1211 ok(SendMessageA(hToolbar
, TB_SETSTATE
, 20, TBSTATE_ENABLED
|TBSTATE_HIDDEN
), "TB_SETSTATE failed\n");
1212 check_button_size(hToolbar
, 100, 100);
1213 ok(SendMessageA(hToolbar
, TB_SETSTATE
, 20, TBSTATE_ENABLED
), "TB_SETSTATE failed\n");
1214 check_button_size(hToolbar
, 23, 22);
1216 /* TB_SETIMAGELIST always changes the height but the width only if necessary */
1217 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1218 himl
= ImageList_LoadImage(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_BITMAP_80x15
), 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
1219 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1220 check_button_size(hToolbar
, 100, 21);
1221 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1222 check_button_size(hToolbar
, 100, 100);
1223 /* But there are no update when we change imagelist, and image sizes are the same */
1224 himl2
= ImageList_LoadImage(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_BITMAP_128x15
), 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
1225 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LRESULT
)himl2
) == (LRESULT
)himl
, "TB_SETIMAGELIST failed\n");
1226 check_button_size(hToolbar
, 100, 100);
1227 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(1, 1));
1228 check_button_size(hToolbar
, 27, 21);
1229 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, 0) == (LRESULT
)himl2
, "TB_SETIMAGELIST failed\n");
1230 check_button_size(hToolbar
, 27, 7);
1231 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(1, 1));
1232 check_button_size(hToolbar
, 8, 7)
1233 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1234 check_button_size(hToolbar
, 27, 21)
1235 /* the text is taken into account */
1236 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)STRING0
"\0" STRING1
"\0");
1237 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 4, (LPARAM
)buttons3
);
1238 check_button_size(hToolbar
, 7 + string_width(STRING1
), 22 + fontheight
);
1239 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, 0) == (LRESULT
)himl
, "TB_SETIMAGELIST failed\n");
1240 check_button_size(hToolbar
, 7 + string_width(STRING1
), 8 + fontheight
);
1241 /* the style change also comes into effect */
1243 SetWindowLong(hToolbar
, GWL_STYLE
, GetWindowLong(hToolbar
, GWL_STYLE
) | TBSTYLE_FLAT
);
1244 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1245 check_sizes_todo(0x30); /* some small problems with BTNS_AUTOSIZE button sizes */
1247 rebuild_toolbar(&hToolbar
);
1248 ImageList_Destroy(himl
);
1249 ImageList_Destroy(himl2
);
1251 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]);
1252 check_button_size(hToolbar
, 7 + string_width(STRING2
), 23 + fontheight
);
1253 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 0, 0);
1254 check_button_size(hToolbar
, 7 + string_width(STRING2
), 23 + fontheight
);
1256 rebuild_toolbar(&hToolbar
);
1258 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1259 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1260 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons2
[0]) == 1, "TB_ADDBUTTONS failed\n");
1261 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[2]) == 1, "TB_ADDBUTTONS failed\n");
1262 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[0]) == 1, "TB_ADDBUTTONS failed\n");
1263 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1266 rebuild_toolbar(&hToolbar
);
1267 SetWindowLong(hToolbar
, GWL_STYLE
, TBSTYLE_LIST
| GetWindowLong(hToolbar
, GWL_STYLE
));
1268 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1269 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1270 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons2
[0]) == 1, "TB_ADDBUTTONS failed\n");
1271 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[2]) == 1, "TB_ADDBUTTONS failed\n");
1272 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONS failed\n");
1273 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1274 check_sizes_todo(0xff);
1276 rebuild_toolbar(&hToolbar
);
1277 SetWindowLong(hToolbar
, GWL_STYLE
, TBSTYLE_LIST
| GetWindowLong(hToolbar
, GWL_STYLE
));
1278 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1279 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1280 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONS failed\n");
1281 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1284 rebuild_toolbar(&hToolbar
);
1285 SetWindowLong(hToolbar
, GWL_STYLE
, TBSTYLE_WRAPABLE
| GetWindowLong(hToolbar
, GWL_STYLE
));
1286 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONS failed\n");
1287 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONS failed\n");
1289 tbinfo
.cbSize
= sizeof(TBBUTTONINFO
);
1290 tbinfo
.dwMask
= TBIF_SIZE
| TBIF_BYINDEX
;
1291 if (SendMessageA(hToolbar
, TB_SETBUTTONINFO
, 0, (LPARAM
)&tbinfo
))
1293 ok(SendMessageA(hToolbar
, TB_SETBUTTONINFO
, 1, (LPARAM
)&tbinfo
) != 0, "TB_SETBUTTONINFO failed\n");
1294 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1297 else /* TBIF_BYINDEX probably not supported, confirm that this was the reason for the failure */
1299 tbinfo
.dwMask
= TBIF_SIZE
;
1300 ok(SendMessageA(hToolbar
, TB_SETBUTTONINFO
, 33, (LPARAM
)&tbinfo
) != 0, "TB_SETBUTTONINFO failed\n");
1303 free_tbsize_results();
1304 DestroyWindow(hToolbar
);
1307 /* Toolbar control has two ways of reacting to a change. We call them a
1308 * relayout and recalc. A recalc forces a recompute of values like button size
1309 * and top margin (the latter in comctl32 <v6), while a relayout uses the cached
1310 * values. This functions creates a flat toolbar with a top margin of a non-flat
1311 * toolbar. We will notice a recalc, as it will recompte the top margin and
1312 * change it to zero*/
1313 static void prepare_recalc_test(HWND
*phToolbar
)
1316 rebuild_toolbar_with_buttons(phToolbar
);
1317 SetWindowLong(*phToolbar
, GWL_STYLE
,
1318 GetWindowLong(*phToolbar
, GWL_STYLE
) | TBSTYLE_FLAT
);
1319 SendMessage(*phToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1320 ok(rect
.top
== 2, "Test will make no sense because initial top is %d instead of 2\n",
1324 static BOOL
did_recalc(HWND hToolbar
)
1327 SendMessage(hToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1328 ok(rect
.top
== 2 || rect
.top
== 0, "Unexpected top margin %d in recalc test\n",
1330 return (rect
.top
== 0);
1333 /* call after a recalc did happen to return to an unstable state */
1334 static void restore_recalc_state(HWND hToolbar
)
1337 /* return to style with a 2px top margin */
1338 SetWindowLong(hToolbar
, GWL_STYLE
,
1339 GetWindowLong(hToolbar
, GWL_STYLE
) & ~TBSTYLE_FLAT
);
1341 SendMessage(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]);
1342 /* top margin will be 0px if a recalc occurs */
1343 SetWindowLong(hToolbar
, GWL_STYLE
,
1344 GetWindowLong(hToolbar
, GWL_STYLE
) | TBSTYLE_FLAT
);
1346 SendMessage(hToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1347 ok(rect
.top
== 2, "Test will make no sense because initial top is %d instead of 2\n",
1351 static void test_recalc(void)
1353 HWND hToolbar
= NULL
;
1355 CHAR test
[] = "Test";
1356 const int EX_STYLES_COUNT
= 5;
1360 /* Like TB_ADDBUTTONS tested in test_sized, inserting a button without text
1361 * results in a relayout, while adding one with text forces a recalc */
1362 prepare_recalc_test(&hToolbar
);
1363 SendMessage(hToolbar
, TB_INSERTBUTTON
, 1, (LPARAM
)&buttons3
[0]);
1364 recalc
= did_recalc(hToolbar
);
1365 ok(!recalc
, "Unexpected recalc - adding button without text\n");
1367 prepare_recalc_test(&hToolbar
);
1368 SendMessage(hToolbar
, TB_INSERTBUTTON
, 1, (LPARAM
)&buttons3
[3]);
1369 recalc
= did_recalc(hToolbar
);
1370 ok(recalc
, "Expected a recalc - adding button with text\n");
1372 /* TB_SETBUTTONINFO, even when adding a text, results only in a relayout */
1373 prepare_recalc_test(&hToolbar
);
1374 bi
.cbSize
= sizeof(bi
);
1375 bi
.dwMask
= TBIF_TEXT
;
1377 SendMessage(hToolbar
, TB_SETBUTTONINFO
, 1, (LPARAM
)&bi
);
1378 recalc
= did_recalc(hToolbar
);
1379 ok(!recalc
, "Unexpected recalc - setting a button text\n");
1381 /* most extended styled doesn't force a recalc (testing all the bits gives
1382 * the same results, but prints some ERRs while testing) */
1383 for (i
= 0; i
< EX_STYLES_COUNT
; i
++)
1385 if (i
== 1 || i
== 3) /* an undoc style and TBSTYLE_EX_MIXEDBUTTONS */
1387 prepare_recalc_test(&hToolbar
);
1388 expect(0, (int)SendMessage(hToolbar
, TB_GETEXTENDEDSTYLE
, 0, 0));
1389 SendMessage(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, (1 << i
));
1390 recalc
= did_recalc(hToolbar
);
1391 ok(!recalc
, "Unexpected recalc - setting bit %d\n", i
);
1392 SendMessage(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, 0);
1393 recalc
= did_recalc(hToolbar
);
1394 ok(!recalc
, "Unexpected recalc - clearing bit %d\n", i
);
1395 expect(0, (int)SendMessage(hToolbar
, TB_GETEXTENDEDSTYLE
, 0, 0));
1398 /* TBSTYLE_EX_MIXEDBUTTONS does a recalc on change */
1399 prepare_recalc_test(&hToolbar
);
1400 SendMessage(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1401 recalc
= did_recalc(hToolbar
);
1404 ok(recalc
, "Expected a recalc - setting TBSTYLE_EX_MIXEDBUTTONS\n");
1405 restore_recalc_state(hToolbar
);
1406 SendMessage(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1407 recalc
= did_recalc(hToolbar
);
1408 ok(!recalc
, "Unexpected recalc - setting TBSTYLE_EX_MIXEDBUTTONS again\n");
1409 restore_recalc_state(hToolbar
);
1410 SendMessage(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, 0);
1411 recalc
= did_recalc(hToolbar
);
1412 ok(recalc
, "Expected a recalc - clearing TBSTYLE_EX_MIXEDBUTTONS\n");
1414 else win_skip( "No recalc on TBSTYLE_EX_MIXEDBUTTONS\n" );
1416 /* undocumented exstyle 0x2 seems to changes the top margin, what
1417 * interferes with these tests */
1419 DestroyWindow(hToolbar
);
1422 static void test_getbuttoninfo(void)
1424 HWND hToolbar
= NULL
;
1427 rebuild_toolbar_with_buttons(&hToolbar
);
1428 for (i
= 0; i
< 128; i
++)
1434 tbi
.dwMask
= TBIF_COMMAND
;
1435 ret
= (int)SendMessage(hToolbar
, TB_GETBUTTONINFO
, 1, (LPARAM
)&tbi
);
1436 if (i
== sizeof(TBBUTTONINFO
)) {
1437 compare(ret
, 0, "%d");
1439 compare(ret
, -1, "%d");
1442 DestroyWindow(hToolbar
);
1445 static void test_createtoolbarex(void)
1449 ZeroMemory(&btns
, sizeof(btns
));
1451 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1452 3, 20, 20, 16, 16, sizeof(TBBUTTON
));
1453 CHECK_IMAGELIST(16, 20, 20);
1454 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x1a001b, "%x");
1455 DestroyWindow(hToolbar
);
1457 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1458 3, 4, 4, 16, 16, sizeof(TBBUTTON
));
1459 CHECK_IMAGELIST(32, 4, 4);
1460 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xa000b, "%x");
1461 DestroyWindow(hToolbar
);
1463 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1464 3, 0, 8, 12, 12, sizeof(TBBUTTON
));
1465 CHECK_IMAGELIST(16, 12, 12);
1466 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x120013, "%x");
1467 DestroyWindow(hToolbar
);
1469 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1470 3, -1, 8, 12, 12, sizeof(TBBUTTON
));
1471 CHECK_IMAGELIST(16, 12, 8);
1472 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xe0013, "%x");
1473 DestroyWindow(hToolbar
);
1475 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1476 3, -1, 8, -1, 12, sizeof(TBBUTTON
));
1477 CHECK_IMAGELIST(16, 16, 8);
1478 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xe0017, "%x");
1479 DestroyWindow(hToolbar
);
1481 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1482 3, 0, 0, 12, -1, sizeof(TBBUTTON
));
1483 CHECK_IMAGELIST(16, 12, 16);
1484 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x160013, "%x");
1485 DestroyWindow(hToolbar
);
1487 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1488 3, 0, 0, 0, 12, sizeof(TBBUTTON
));
1489 CHECK_IMAGELIST(16, 16, 16);
1490 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x160017, "%x");
1491 DestroyWindow(hToolbar
);
1494 static void test_dispinfo(void)
1496 HWND hToolbar
= NULL
;
1497 const TBBUTTON buttons_disp
[] = {
1498 {-1, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1499 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1503 rebuild_toolbar(&hToolbar
);
1504 SendMessageA(hToolbar
, TB_LOADIMAGES
, IDB_HIST_SMALL_COLOR
, (LPARAM
)HINST_COMMCTRL
);
1505 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons_disp
);
1506 g_dwExpectedDispInfoMask
= TBNF_IMAGE
;
1507 /* Some TBN_GETDISPINFO tests will be done in MyWnd_Notify function.
1508 * We will receive TBN_GETDISPINFOW even if the control is ANSI */
1509 compare((BOOL
)SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 0, "%d");
1510 ShowWindow(hToolbar
, SW_SHOW
);
1511 UpdateWindow(hToolbar
);
1513 ret
= (BOOL
)SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, TRUE
, 0);
1514 compare(ret
, FALSE
, "%d");
1515 compare(SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 1L, "%ld");
1516 InvalidateRect(hToolbar
, NULL
, FALSE
);
1517 UpdateWindow(hToolbar
);
1519 ret
= (BOOL
)SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, FALSE
, 0);
1520 compare(ret
, TRUE
, "%d");
1521 compare(SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 0L, "%ld");
1522 InvalidateRect(hToolbar
, NULL
, FALSE
);
1523 UpdateWindow(hToolbar
);
1525 DestroyWindow(hToolbar
);
1526 g_dwExpectedDispInfoMask
= 0;
1536 static tbrows_result_t tbrows_results
[] =
1538 {1, TRUE
, 1}, /* 0: Simple case 9 in a row */
1539 {2, TRUE
, 2}, /* 1: Another simple case 5 on one row, 4 on another*/
1540 {3, FALSE
, 3}, /* 2: 3 lines - should be 3 lines of 3 buttons */
1541 {8, FALSE
, 5}, /* 3: 8 lines - should be 5 lines of 2 buttons */
1542 {8, TRUE
, 9}, /* 4: 8 lines but grow - should be 9 lines */
1543 {1, TRUE
, 1} /* 5: Back to simple case */
1546 static void test_setrows(void)
1548 TBBUTTON buttons
[9];
1553 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_FLAT
| TBSTYLE_CHECKGROUP
, 0);
1555 /* Test 1 - 9 buttons */
1556 hToolbar
= CreateToolbarEx(hMainWnd
,
1557 WS_VISIBLE
| WS_CLIPCHILDREN
| WS_CHILD
| CCS_NORESIZE
| CCS_NOPARENTALIGN
1558 | CCS_NOMOVEY
| CCS_TOP
,
1561 buttons
, sizeof(buttons
)/sizeof(buttons
[0]),
1562 20, 20, 0, 0, sizeof(TBBUTTON
));
1563 ok(hToolbar
!= NULL
, "Toolbar creation\n");
1564 ok(SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
1566 /* test setting rows to each of 1-10 with bLarger true and false */
1567 for (i
=0; i
<(sizeof(tbrows_results
) / sizeof(tbrows_result_t
)); i
++) {
1571 memset(&rc
, 0xCC, sizeof(rc
));
1572 SendMessageA(hToolbar
, TB_SETROWS
,
1573 MAKELONG(tbrows_results
[i
].nRows
, tbrows_results
[i
].bLarger
),
1576 rows
= SendMessageA(hToolbar
, TB_GETROWS
, MAKELONG(0,0), MAKELONG(0,0));
1577 ok(rows
== tbrows_results
[i
].expectedRows
,
1578 "[%d] Unexpected number of rows %d (expected %d)\n", i
, rows
,
1579 tbrows_results
[i
].expectedRows
);
1582 DestroyWindow(hToolbar
);
1585 static void test_getstring(void)
1587 HWND hToolbar
= NULL
;
1590 static const char answer
[] = "STR";
1591 static const WCHAR answerW
[] = { 'S','T','R',0 };
1594 hToolbar
= CreateWindowExA(0, TOOLBARCLASSNAME
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, hMainWnd
, (HMENU
)5, GetModuleHandle(NULL
), NULL
);
1595 ok(hToolbar
!= NULL
, "Toolbar creation problem\n");
1597 r
= SendMessage(hToolbar
, TB_GETSTRING
, MAKEWPARAM(0, 0), 0);
1600 win_skip("TB_GETSTRING and TB_GETSTRINGW need 5.80\n");
1601 DestroyWindow(hToolbar
);
1605 r
= SendMessage(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(0, 0), 0);
1607 r
= SendMessage(hToolbar
, TB_ADDSTRING
, 0, (LPARAM
)answer
);
1609 r
= SendMessage(hToolbar
, TB_GETSTRING
, MAKEWPARAM(0, 0), 0);
1610 expect(lstrlenA(answer
), r
);
1611 r
= SendMessage(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(0, 0), 0);
1612 expect(lstrlenA(answer
), r
);
1613 r
= SendMessage(hToolbar
, TB_GETSTRING
, MAKEWPARAM(sizeof(str
), 0), (LPARAM
)str
);
1614 expect(lstrlenA(answer
), r
);
1615 expect(0, lstrcmp(answer
, str
));
1616 r
= SendMessage(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(sizeof(strW
), 0), (LPARAM
)strW
);
1617 expect(lstrlenA(answer
), r
);
1618 expect(0, lstrcmpW(answerW
, strW
));
1620 DestroyWindow(hToolbar
);
1623 static void test_tooltip(void)
1625 HWND hToolbar
= NULL
;
1626 const TBBUTTON buttons_disp
[] = {
1627 {-1, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1628 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1630 NMTTDISPINFOW nmtti
;
1633 rebuild_toolbar(&hToolbar
);
1635 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons_disp
);
1637 /* W used to get through toolbar code that assumes tooltip is always Unicode */
1638 memset(&nmtti
, 0, sizeof(nmtti
));
1639 nmtti
.hdr
.code
= TTN_GETDISPINFOW
;
1640 nmtti
.hdr
.idFrom
= 20;
1642 SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, FALSE
, 0);
1644 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1645 SendMessageA(hToolbar
, WM_NOTIFY
, 0, (LPARAM
)&nmtti
);
1646 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ttgetdispinfo_parent_seq
,
1647 "dispinfo from tooltip", TRUE
);
1649 g_ResetDispTextPtr
= TRUE
;
1650 SendMessageA(hToolbar
, WM_NOTIFY
, 0, (LPARAM
)&nmtti
);
1651 g_ResetDispTextPtr
= FALSE
;
1653 DestroyWindow(hToolbar
);
1655 /* TBSTYLE_TOOLTIPS */
1656 hToolbar
= CreateWindowExA(0, TOOLBARCLASSNAME
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0,
1657 hMainWnd
, (HMENU
)5, GetModuleHandle(NULL
), NULL
);
1658 tooltip
= (HWND
)SendMessageA(hToolbar
, TB_GETTOOLTIPS
, 0, 0);
1659 ok(tooltip
== NULL
, "got %p\n", tooltip
);
1660 DestroyWindow(hToolbar
);
1663 static void test_get_set_style(void)
1665 TBBUTTON buttons
[9];
1666 DWORD style
, style2
, ret
;
1671 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_CHECKGROUP
, 0);
1672 MakeButton(buttons
+3, 1003, TBSTYLE_SEP
|TBSTYLE_GROUP
, 0);
1673 MakeButton(buttons
+6, 1006, TBSTYLE_SEP
, 0);
1675 hToolbar
= CreateToolbarEx(hMainWnd
,
1676 WS_VISIBLE
| WS_CLIPCHILDREN
| CCS_TOP
|
1677 WS_CHILD
| TBSTYLE_LIST
,
1680 buttons
, sizeof(buttons
)/sizeof(buttons
[0]),
1681 0, 0, 20, 16, sizeof(TBBUTTON
));
1682 ok(hToolbar
!= NULL
, "Toolbar creation\n");
1683 SendMessage(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)"test\000");
1685 style
= SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0);
1686 style2
= GetWindowLongA(hToolbar
, GWL_STYLE
);
1688 ok(style
== style2
, "got 0x%08x, expected 0x%08x\n", style
, style2
);
1690 /* try to alter common window bits */
1691 style2
|= WS_BORDER
;
1692 ret
= SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style2
);
1693 ok(ret
== 0, "got %d\n", ret
);
1694 style
= SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0);
1695 style2
= GetWindowLongA(hToolbar
, GWL_STYLE
);
1696 ok((style
!= style2
) && (style
== (style2
| WS_BORDER
)),
1697 "got 0x%08x, expected 0x%08x\n", style
, style2
);
1698 ok(style
& WS_BORDER
, "got 0x%08x\n", style
);
1700 /* now styles are the same, alter window style */
1701 ret
= SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style2
);
1702 ok(ret
== 0, "got %d\n", ret
);
1703 style2
|= WS_BORDER
;
1704 SetWindowLongA(hToolbar
, GWL_STYLE
, style2
);
1705 style
= SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0);
1706 ok(style
== style2
, "got 0x%08x, expected 0x%08x\n", style
, style2
);
1708 DestroyWindow(hToolbar
);
1711 static HHOOK g_tbhook
;
1712 static HWND g_toolbar
;
1714 DEFINE_EXPECT(g_hook_create
);
1715 DEFINE_EXPECT(g_hook_WM_NCCREATE
);
1716 DEFINE_EXPECT(g_hook_WM_CREATE
);
1718 static LRESULT WINAPI
toolbar_subclass_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1720 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
1724 if (msg
== WM_NCCREATE
)
1726 if (g_toolbar
== hwnd
)
1728 CHECK_EXPECT2(g_hook_WM_NCCREATE
);
1730 ret
= CallWindowProcA(oldproc
, hwnd
, msg
, wParam
, lParam
);
1732 /* control is already set up */
1733 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
1734 ok(style
!= 0, "got %x\n", style
);
1736 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1737 ok((style
& TBSTYLE_TOOLTIPS
) == 0, "got 0x%08x\n", style
);
1738 SetWindowLongA(hwnd
, GWL_STYLE
, style
|TBSTYLE_TOOLTIPS
);
1739 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1740 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
1745 else if (msg
== WM_CREATE
)
1747 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
1749 if (g_toolbar
== hwnd
)
1751 CHECK_EXPECT2(g_hook_WM_CREATE
);
1753 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1754 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
1756 /* test if toolbar-specific messages are already working before WM_CREATE */
1757 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
1758 ok(style
!= 0, "got %x\n", style
);
1759 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%x\n", style
);
1760 ok((cs
->style
& TBSTYLE_TOOLTIPS
) == 0, "0x%08x\n", cs
->style
);
1762 ret
= CallWindowProcA(oldproc
, hwnd
, msg
, wParam
, lParam
);
1764 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1765 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
1767 /* test if toolbar-specific messages are already working before WM_CREATE */
1768 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
1769 ok(style
!= 0, "got %x\n", style
);
1770 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%x\n", style
);
1776 return CallWindowProcA(oldproc
, hwnd
, msg
, wParam
, lParam
);
1779 static LRESULT CALLBACK
cbt_hook_proc(int code
, WPARAM wParam
, LPARAM lParam
)
1781 if (code
== HCBT_CREATEWND
)
1783 HWND hwnd
= (HWND
)wParam
;
1789 CHECK_EXPECT2(g_hook_create
);
1792 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)toolbar_subclass_proc
);
1793 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
1798 return CallNextHookEx(g_tbhook
, code
, wParam
, lParam
);
1801 static void test_create(void)
1806 g_tbhook
= SetWindowsHookA(WH_CBT
, cbt_hook_proc
);
1808 SET_EXPECT(g_hook_create
);
1809 SET_EXPECT(g_hook_WM_NCCREATE
);
1810 SET_EXPECT(g_hook_WM_CREATE
);
1812 hwnd
= CreateWindowExA(0, TOOLBARCLASSNAME
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0,
1813 hMainWnd
, (HMENU
)5, GetModuleHandle(NULL
), NULL
);
1815 CHECK_CALLED(g_hook_create
);
1816 CHECK_CALLED(g_hook_WM_NCCREATE
);
1817 CHECK_CALLED(g_hook_WM_CREATE
);
1819 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1820 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
1822 tooltip
= (HWND
)SendMessageA(hwnd
, TB_GETTOOLTIPS
, 0, 0);
1823 ok(tooltip
!= NULL
, "got %p\n", tooltip
);
1824 ok(GetParent(tooltip
) == hMainWnd
, "got %p, %p\n", hMainWnd
, hwnd
);
1826 DestroyWindow(hwnd
);
1827 UnhookWindowsHook(WH_CBT
, cbt_hook_proc
);
1829 /* TBSTYLE_TRANSPARENT */
1830 hwnd
= CreateWindowExA(0, TOOLBARCLASSNAME
, NULL
,
1831 WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|TBSTYLE_FLAT
|TBSTYLE_TOOLTIPS
|TBSTYLE_GROUP
,
1832 0, 0, 0, 0, hMainWnd
, (HMENU
)5, GetModuleHandle(NULL
), NULL
);
1834 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1835 ok((style
& TBSTYLE_TRANSPARENT
) == TBSTYLE_TRANSPARENT
, "got 0x%08x\n", style
);
1837 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
1838 ok((style
& TBSTYLE_TRANSPARENT
) == TBSTYLE_TRANSPARENT
, "got 0x%08x\n", style
);
1840 DestroyWindow(hwnd
);
1849 static const extended_style_t extended_style_test
[] = {
1851 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
,
1852 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
,
1853 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
1856 TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
,
1857 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
| TBSTYLE_EX_MIXEDBUTTONS
1860 { 0, TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
},
1862 { 0, TBSTYLE_EX_DRAWDDARROWS
, TBSTYLE_EX_DRAWDDARROWS
},
1863 { 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS
, TBSTYLE_EX_HIDECLIPPEDBUTTONS
},
1866 { TBSTYLE_EX_HIDECLIPPEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
, 0 },
1867 { TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_HIDECLIPPEDBUTTONS
, 0 },
1868 { TBSTYLE_EX_DOUBLEBUFFER
, TBSTYLE_EX_MIXEDBUTTONS
, 0 },
1871 TBSTYLE_EX_DOUBLEBUFFER
| TBSTYLE_EX_MIXEDBUTTONS
,
1872 TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
1875 TBSTYLE_EX_DOUBLEBUFFER
| TBSTYLE_EX_MIXEDBUTTONS
,
1876 TBSTYLE_EX_DOUBLEBUFFER
, TBSTYLE_EX_DOUBLEBUFFER
1880 static void test_TB_GET_SET_EXTENDEDSTYLE(void)
1882 DWORD style
, oldstyle
, oldstyle2
;
1883 const extended_style_t
*ptr
;
1887 rebuild_toolbar(&hwnd
);
1889 SendMessageA(hwnd
, TB_SETEXTENDEDSTYLE
, TBSTYLE_EX_DOUBLEBUFFER
, TBSTYLE_EX_MIXEDBUTTONS
);
1890 style
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
1891 if (style
== TBSTYLE_EX_MIXEDBUTTONS
)
1893 win_skip("Some extended style bits are not supported\n");
1894 DestroyWindow(hwnd
);
1898 for (i
= 0; i
< sizeof(extended_style_test
)/sizeof(extended_style_t
); i
++)
1900 ptr
= &extended_style_test
[i
];
1902 oldstyle2
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
1904 oldstyle
= SendMessageA(hwnd
, TB_SETEXTENDEDSTYLE
, ptr
->mask
, ptr
->style
);
1905 ok(oldstyle
== oldstyle2
, "%d: got old style 0x%08x, expected 0x%08x\n", i
, oldstyle
, oldstyle2
);
1906 style
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
1907 ok(style
== ptr
->style_set
, "%d: got style 0x%08x, expected 0x%08x\n", i
, style
, ptr
->style_set
);
1910 DestroyWindow(hwnd
);
1919 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
1921 InitCommonControls();
1923 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1926 wc
.hInstance
= GetModuleHandleA(NULL
);
1928 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
1929 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1930 wc
.lpszMenuName
= NULL
;
1931 wc
.lpszClassName
= "Toolbar test parent";
1932 wc
.lpfnWndProc
= parent_wnd_proc
;
1933 RegisterClassA(&wc
);
1935 hMainWnd
= CreateWindowExA(0, "Toolbar test parent", "Blah", WS_OVERLAPPEDWINDOW
,
1936 CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1937 GetClientRect(hMainWnd
, &rc
);
1938 ShowWindow(hMainWnd
, SW_SHOW
);
1946 test_getbuttoninfo();
1947 test_createtoolbarex();
1952 test_get_set_style();
1954 test_TB_GET_SET_EXTENDEDSTYLE();
1957 while(GetMessageA(&msg
,0,0,0)) {
1958 TranslateMessage(&msg
);
1959 DispatchMessageA(&msg
);
1961 DestroyWindow(hMainWnd
);