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 expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
59 #define check_rect(name, val, exp, ...) ok(val.top == exp.top && val.bottom == exp.bottom && \
60 val.left == exp.left && val.right == exp.right, "invalid rect (%d,%d) (%d,%d) - expected (%d,%d) (%d,%d) - (" name ")\n", \
61 val.left, val.top, val.right, val.bottom, exp.left, exp.top, exp.right, exp.bottom, __VA_ARGS__);
63 #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
65 #define check_button_size(handle, width, height, ...) {\
66 LRESULT bsize = SendMessageA(handle, TB_GETBUTTONSIZE, 0, 0);\
67 ok(bsize == MAKELONG(width, height), "Unexpected button size - got size (%d, %d), expected (%d, %d)\n", LOWORD(bsize), HIWORD(bsize), width, height);\
70 static void MakeButton(TBBUTTON
*p
, int idCommand
, int fsStyle
, int nString
) {
72 p
->idCommand
= idCommand
;
73 p
->fsState
= TBSTATE_ENABLED
;
78 static LRESULT
parent_wnd_notify(LPARAM lParam
)
80 NMHDR
*hdr
= (NMHDR
*)lParam
;
85 case TBN_HOTITEMCHANGE
:
86 nmhi
= (NMTBHOTITEM
*)lParam
;
87 g_fReceivedHotItemChange
= TRUE
;
88 if (g_fExpectedHotItemOld
!= g_fExpectedHotItemNew
)
90 compare(nmhi
->idOld
, g_fExpectedHotItemOld
, "%d");
91 compare(nmhi
->idNew
, g_fExpectedHotItemNew
, "%d");
93 if (g_fBlockHotItemChange
)
97 case TBN_GETDISPINFOA
:
98 ok(FALSE
, "TBN_GETDISPINFOA received\n");
101 case TBN_GETINFOTIPA
:
103 NMTBGETINFOTIPA
*tbgit
= (NMTBGETINFOTIPA
*)lParam
;
105 if (g_ResetDispTextPtr
)
107 tbgit
->pszText
= NULL
;
112 case TBN_GETDISPINFOW
:
113 nmdisp
= (NMTBDISPINFOA
*)lParam
;
115 compare(nmdisp
->dwMask
, g_dwExpectedDispInfoMask
, "%x");
116 ok(nmdisp
->pszText
== NULL
, "pszText is not NULL\n");
122 static LRESULT CALLBACK
parent_wnd_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
124 static LONG defwndproc_counter
= 0;
128 msg
.message
= message
;
129 msg
.flags
= sent
|wparam
|lparam
;
130 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
133 if (message
== WM_NOTIFY
&& lParam
) msg
.id
= ((NMHDR
*)lParam
)->code
;
135 /* log system messages, except for painting */
136 if (message
< WM_USER
&&
137 message
!= WM_PAINT
&&
138 message
!= WM_ERASEBKGND
&&
139 message
!= WM_NCPAINT
&&
140 message
!= WM_NCHITTEST
&&
141 message
!= WM_GETTEXT
&&
142 message
!= WM_GETICON
&&
143 message
!= WM_DEVICECHANGE
)
145 trace("parent: %p, %04x, %08lx, %08lx\n", hWnd
, message
, wParam
, lParam
);
146 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
152 return parent_wnd_notify(lParam
);
155 defwndproc_counter
++;
156 ret
= DefWindowProcA(hWnd
, message
, wParam
, lParam
);
157 defwndproc_counter
--;
162 static void basic_test(void)
168 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_CHECKGROUP
, 0);
169 MakeButton(buttons
+3, 1003, TBSTYLE_SEP
|TBSTYLE_GROUP
, 0);
170 MakeButton(buttons
+6, 1006, TBSTYLE_SEP
, 0);
172 hToolbar
= CreateToolbarEx(hMainWnd
,
173 WS_VISIBLE
| WS_CLIPCHILDREN
| CCS_TOP
|
174 WS_CHILD
| TBSTYLE_LIST
,
177 buttons
, sizeof(buttons
)/sizeof(buttons
[0]),
178 0, 0, 20, 16, sizeof(TBBUTTON
));
179 ok(hToolbar
!= NULL
, "Toolbar creation\n");
180 SendMessage(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)"test\000");
182 /* test for exclusion working inside a separator-separated :-) group */
183 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1000, 1); /* press A1 */
184 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
185 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1001, 0), "A2 not pressed\n");
187 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1004, 1); /* press A5, release A1 */
188 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1004, 0), "A5 pressed\n");
189 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 not pressed anymore\n");
191 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1005, 1); /* press A6, release A5 */
192 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 pressed\n");
193 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1004, 0), "A5 not pressed anymore\n");
195 /* test for inter-group crosstalk, ie. two radio groups interfering with each other */
196 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1007, 1); /* press B2 */
197 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
198 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 still not pressed\n");
199 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 pressed\n");
201 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1000, 1); /* press A1 and ensure B group didn't suffer */
202 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 not pressed anymore\n");
203 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
204 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 still pressed\n");
206 SendMessage(hToolbar
, TB_CHECKBUTTON
, 1008, 1); /* press B3, and ensure A group didn't suffer */
207 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 pressed\n");
208 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
209 ok(!SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 not pressed\n");
210 ok(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 1008, 0), "B3 pressed\n");
212 /* tests with invalid index */
213 compare(SendMessage(hToolbar
, TB_ISBUTTONCHECKED
, 0xdeadbeef, 0), -1L, "%ld");
214 compare(SendMessage(hToolbar
, TB_ISBUTTONPRESSED
, 0xdeadbeef, 0), -1L, "%ld");
215 compare(SendMessage(hToolbar
, TB_ISBUTTONENABLED
, 0xdeadbeef, 0), -1L, "%ld");
216 compare(SendMessage(hToolbar
, TB_ISBUTTONINDETERMINATE
, 0xdeadbeef, 0), -1L, "%ld");
217 compare(SendMessage(hToolbar
, TB_ISBUTTONHIGHLIGHTED
, 0xdeadbeef, 0), -1L, "%ld");
218 compare(SendMessage(hToolbar
, TB_ISBUTTONHIDDEN
, 0xdeadbeef, 0), -1L, "%ld");
220 DestroyWindow(hToolbar
);
223 static void rebuild_toolbar(HWND
*hToolbar
)
226 DestroyWindow(*hToolbar
);
227 *hToolbar
= CreateWindowEx(0, TOOLBARCLASSNAME
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0,
228 hMainWnd
, (HMENU
)5, GetModuleHandle(NULL
), NULL
);
229 ok(*hToolbar
!= NULL
, "Toolbar creation problem\n");
230 ok(SendMessage(*hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
231 ok(SendMessage(*hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
232 ok(SendMessage(*hToolbar
, WM_SETFONT
, (WPARAM
)GetStockObject(SYSTEM_FONT
), 0)==1, "WM_SETFONT\n");
235 static void rebuild_toolbar_with_buttons(HWND
*hToolbar
)
238 rebuild_toolbar(hToolbar
);
240 ZeroMemory(&buttons
, sizeof(buttons
));
241 buttons
[0].idCommand
= 1;
242 buttons
[0].fsStyle
= BTNS_BUTTON
;
243 buttons
[0].fsState
= TBSTATE_ENABLED
;
244 buttons
[0].iString
= -1;
245 buttons
[1].idCommand
= 3;
246 buttons
[1].fsStyle
= BTNS_BUTTON
;
247 buttons
[1].fsState
= TBSTATE_ENABLED
;
248 buttons
[1].iString
= -1;
249 buttons
[2].idCommand
= 5;
250 buttons
[2].fsStyle
= BTNS_SEP
;
251 buttons
[2].fsState
= TBSTATE_ENABLED
;
252 buttons
[2].iString
= -1;
253 buttons
[3].idCommand
= 7;
254 buttons
[3].fsStyle
= BTNS_BUTTON
;
255 buttons
[3].fsState
= TBSTATE_ENABLED
;
256 buttons
[3].iString
= -1;
257 buttons
[4].idCommand
= 9;
258 buttons
[4].fsStyle
= BTNS_BUTTON
;
259 buttons
[4].fsState
= 0; /* disabled */
260 buttons
[4].iString
= -1;
261 ok(SendMessage(*hToolbar
, TB_ADDBUTTONS
, 5, (LPARAM
)buttons
) == 1, "TB_ADDBUTTONS failed\n");
262 ok(SendMessage(*hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
265 static void add_128x15_bitmap(HWND hToolbar
, int nCmds
)
268 bmp128
.hInst
= GetModuleHandle(NULL
);
269 bmp128
.nID
= IDB_BITMAP_128x15
;
270 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, nCmds
, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
273 #define CHECK_IMAGELIST(count, dx, dy) { \
275 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
276 ok(himl != NULL, "No image list\n"); \
278 ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
279 ImageList_GetIconSize(himl, &cx, &cy); \
280 ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
284 static void test_add_bitmap(void)
286 HWND hToolbar
= NULL
;
289 TBADDBITMAP stdsmall
;
294 /* empty 128x15 bitmap */
295 bmp128
.hInst
= GetModuleHandle(NULL
);
296 bmp128
.nID
= IDB_BITMAP_128x15
;
298 /* empty 80x15 bitmap */
299 bmp80
.hInst
= GetModuleHandle(NULL
);
300 bmp80
.nID
= IDB_BITMAP_80x15
;
302 /* standard bitmap - 240x15 pixels */
303 stdsmall
.hInst
= HINST_COMMCTRL
;
304 stdsmall
.nID
= IDB_STD_SMALL_COLOR
;
306 rebuild_toolbar(&hToolbar
);
307 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 8, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
308 CHECK_IMAGELIST(8, 16, 16);
310 /* adding more bitmaps */
311 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
) == 8, "TB_ADDBITMAP - unexpected return\n");
312 CHECK_IMAGELIST(13, 16, 16);
313 /* adding the same bitmap will simply return the index of the already loaded block */
314 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 8, (LPARAM
)&bmp128
);
315 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
316 CHECK_IMAGELIST(13, 16, 16);
317 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
);
318 ok(ret
== 8, "TB_ADDBITMAP - unexpected return %d\n", ret
);
319 CHECK_IMAGELIST(13, 16, 16);
320 /* even if we increase the wParam */
321 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 55, (LPARAM
)&bmp80
);
322 ok(ret
== 8, "TB_ADDBITMAP - unexpected return %d\n", ret
);
323 CHECK_IMAGELIST(13, 16, 16);
325 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
326 rebuild_toolbar(&hToolbar
);
327 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 3, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
328 CHECK_IMAGELIST(8, 16, 16);
329 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
);
330 ok(ret
== 3, "TB_ADDBITMAP - unexpected return %d\n", ret
);
331 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
332 CHECK_IMAGELIST(13, 16, 16);
334 /* the same for negative wParam */
335 rebuild_toolbar(&hToolbar
);
336 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, -143, (LPARAM
)&bmp128
);
337 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
338 CHECK_IMAGELIST(8, 16, 16);
339 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp80
);
340 ok(ret
== -143, "TB_ADDBITMAP - unexpected return %d\n", ret
);
341 CHECK_IMAGELIST(13, 16, 16);
343 /* for zero only one bitmap will be added */
344 rebuild_toolbar(&hToolbar
);
345 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&bmp80
);
346 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
347 CHECK_IMAGELIST(1, 16, 16);
349 /* if wParam is larger than the amount of icons, the list is grown */
350 rebuild_toolbar(&hToolbar
);
351 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp80
) == 0, "TB_ADDBITMAP - unexpected return\n");
352 CHECK_IMAGELIST(100, 16, 16);
353 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp128
);
354 ok(ret
== 100, "TB_ADDBITMAP - unexpected return %d\n", ret
);
355 CHECK_IMAGELIST(200, 16, 16);
357 /* adding built-in items - the wParam is ignored */
358 rebuild_toolbar(&hToolbar
);
359 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
) == 0, "TB_ADDBITMAP - unexpected return\n");
360 CHECK_IMAGELIST(5, 16, 16);
361 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&stdsmall
) == 5, "TB_ADDBITMAP - unexpected return\n");
362 CHECK_IMAGELIST(20, 16, 16);
363 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp128
) == 20, "TB_ADDBITMAP - unexpected return\n");
364 CHECK_IMAGELIST(28, 16, 16);
366 /* when we increase the bitmap size, less icons will be created */
367 rebuild_toolbar(&hToolbar
);
368 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(20, 20)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
369 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
370 CHECK_IMAGELIST(6, 20, 20);
371 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp80
);
372 ok(ret
== 1, "TB_ADDBITMAP - unexpected return %d\n", ret
);
373 CHECK_IMAGELIST(10, 20, 20);
374 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
375 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
376 UpdateWindow(hToolbar
);
377 CHECK_IMAGELIST(26, 8, 8);
378 /* loading a standard bitmaps automatically resizes the icons */
379 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&stdsmall
) == 2, "TB_ADDBITMAP - unexpected return\n");
380 UpdateWindow(hToolbar
);
381 CHECK_IMAGELIST(28, 16, 16);
383 /* two more SETBITMAPSIZE tests */
384 rebuild_toolbar(&hToolbar
);
385 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
386 CHECK_IMAGELIST(100, 16, 16);
387 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp80
) == 100, "TB_ADDBITMAP - unexpected return\n");
388 CHECK_IMAGELIST(200, 16, 16);
389 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
390 UpdateWindow(hToolbar
);
391 CHECK_IMAGELIST(200, 8, 8);
392 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(30, 30)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
393 UpdateWindow(hToolbar
);
394 CHECK_IMAGELIST(200, 30, 30);
395 rebuild_toolbar(&hToolbar
);
396 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
397 CHECK_IMAGELIST(8, 16, 16);
398 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 3, (LPARAM
)&bmp80
) == 5, "TB_ADDBITMAP - unexpected return\n");
399 CHECK_IMAGELIST(13, 16, 16);
400 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(30, 30)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
401 UpdateWindow(hToolbar
);
402 CHECK_IMAGELIST(8, 30, 30);
403 /* when the width or height is zero, set it to 1 */
404 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(0, 0)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
405 UpdateWindow(hToolbar
);
406 CHECK_IMAGELIST(208, 1, 1);
407 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(0, 5)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
408 UpdateWindow(hToolbar
);
409 CHECK_IMAGELIST(208, 1, 5);
410 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(5, 0)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
411 UpdateWindow(hToolbar
);
412 CHECK_IMAGELIST(41, 5, 1);
414 /* the control can add bitmaps to an existing image list */
415 rebuild_toolbar(&hToolbar
);
416 himl
= ImageList_LoadImage(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_BITMAP_80x15
), 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
417 ok(himl
!= NULL
, "failed to create imagelist\n");
418 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
419 CHECK_IMAGELIST(4, 20, 15);
420 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
421 CHECK_IMAGELIST(10, 20, 15);
422 /* however TB_SETBITMAPSIZE/add std bitmap won't change the image size (the button size does change) */
423 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
424 UpdateWindow(hToolbar
);
425 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(15, 14), "%x");
426 CHECK_IMAGELIST(10, 20, 15);
427 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&stdsmall
) == 1, "TB_SETBITMAPSIZE failed\n");
428 UpdateWindow(hToolbar
);
429 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(23, 22), "%x");
430 CHECK_IMAGELIST(22, 20, 15);
432 /* check standard bitmaps */
433 addbmp
.hInst
= HINST_COMMCTRL
;
434 addbmp
.nID
= IDB_STD_SMALL_COLOR
;
435 rebuild_toolbar(&hToolbar
);
436 ImageList_Destroy(himl
);
438 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
439 CHECK_IMAGELIST(15, 16, 16);
440 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(23, 22), "%x");
441 addbmp
.nID
= IDB_STD_LARGE_COLOR
;
442 rebuild_toolbar(&hToolbar
);
443 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
444 CHECK_IMAGELIST(15, 24, 24);
445 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(31, 30), "%x");
447 addbmp
.nID
= IDB_VIEW_SMALL_COLOR
;
448 rebuild_toolbar(&hToolbar
);
449 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
450 CHECK_IMAGELIST(12, 16, 16);
451 addbmp
.nID
= IDB_VIEW_LARGE_COLOR
;
452 rebuild_toolbar(&hToolbar
);
453 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
454 CHECK_IMAGELIST(12, 24, 24);
456 addbmp
.nID
= IDB_HIST_SMALL_COLOR
;
457 rebuild_toolbar(&hToolbar
);
458 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
459 CHECK_IMAGELIST(5, 16, 16);
460 addbmp
.nID
= IDB_HIST_LARGE_COLOR
;
461 rebuild_toolbar(&hToolbar
);
462 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
463 CHECK_IMAGELIST(5, 24, 24);
466 DestroyWindow(hToolbar
);
469 #define CHECK_STRING_TABLE(count, tab) { \
472 for (_i = 0; _i < (count); _i++) {\
473 ret = SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, _i), (LPARAM)_buf); \
474 ok(ret >= 0, "TB_GETSTRING - unexpected return %d while checking string %d\n", ret, _i); \
476 ok(strcmp(_buf, (tab)[_i]) == 0, "Invalid string #%d - '%s' vs '%s'\n", _i, (tab)[_i], _buf); \
478 ok(SendMessageA(hToolbar, TB_GETSTRING, MAKEWPARAM(260, (count)), (LPARAM)_buf) == -1, \
479 "Too many strings in table\n"); \
482 static void test_add_string(void)
484 LPCSTR test1
= "a\0b\0";
485 LPCSTR test2
= "|a|b||\0";
486 LPCSTR ret1
[] = {"a", "b"};
487 LPCSTR ret2
[] = {"a", "b", "|a|b||"};
488 LPCSTR ret3
[] = {"a", "b", "|a|b||", "p", "q"};
489 LPCSTR ret4
[] = {"a", "b", "|a|b||", "p", "q", "p"};
490 LPCSTR ret5
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q"};
491 LPCSTR ret6
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q"};
492 LPCSTR ret7
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q", "br", "c", "d"};
493 HWND hToolbar
= NULL
;
498 rebuild_toolbar(&hToolbar
);
499 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)test1
);
500 ok(ret
== 0, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
501 ret
= SendMessageA(hToolbar
, TB_GETSTRING
, MAKEWPARAM(260, 1), (LPARAM
)buf
);
504 win_skip("TB_GETSTRING needs 5.80\n");
507 CHECK_STRING_TABLE(2, ret1
);
508 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)test2
);
509 ok(ret
== 2, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
510 CHECK_STRING_TABLE(3, ret2
);
512 /* null instance handle */
513 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, IDS_TBADD1
);
514 ok(ret
== -1, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
516 /* invalid instance handle */
517 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0xdeadbeef, IDS_TBADD1
);
518 ok(ret
== -1, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
520 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD1
);
521 ok(ret
== 3, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
522 CHECK_STRING_TABLE(3, ret2
);
523 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD2
);
524 ok(ret
== 3, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
525 CHECK_STRING_TABLE(5, ret3
);
526 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD3
);
527 ok(ret
== 5, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
528 CHECK_STRING_TABLE(6, ret4
);
529 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD4
);
530 ok(ret
== 6, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
531 CHECK_STRING_TABLE(8, ret5
);
532 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD5
);
533 ok(ret
== 8, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
534 CHECK_STRING_TABLE(11, ret6
);
535 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandle(NULL
), IDS_TBADD7
);
536 ok(ret
== 11, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
537 CHECK_STRING_TABLE(14, ret7
);
539 ZeroMemory(&button
, sizeof(button
));
540 button
.iString
= (UINT_PTR
)"Test";
541 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, 0, (LPARAM
)&button
);
542 CHECK_STRING_TABLE(14, ret7
);
543 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&button
);
544 CHECK_STRING_TABLE(14, ret7
);
546 DestroyWindow(hToolbar
);
549 static void expect_hot_notify(int idold
, int idnew
)
551 g_fExpectedHotItemOld
= idold
;
552 g_fExpectedHotItemNew
= idnew
;
553 g_fReceivedHotItemChange
= FALSE
;
556 #define check_hot_notify() \
557 ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
558 g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
560 static void test_hotitem(void)
562 HWND hToolbar
= NULL
;
566 g_fBlockHotItemChange
= FALSE
;
568 rebuild_toolbar_with_buttons(&hToolbar
);
569 /* set TBSTYLE_FLAT. comctl5 allows hot items only for such toolbars.
570 * comctl6 doesn't have this requirement even when theme == NULL */
571 SetWindowLong(hToolbar
, GWL_STYLE
, TBSTYLE_FLAT
| GetWindowLong(hToolbar
, GWL_STYLE
));
572 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
573 ok(ret
== -1, "Hot item: %ld, expected -1\n", ret
);
574 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 1, 0);
575 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
576 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
577 ok(ret
== 1, "Hot item: %ld, expected 1\n", ret
);
578 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 2, 0);
579 ok(ret
== 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret
);
581 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 0xbeef, 0);
582 ok(ret
== 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
583 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
584 ok(ret
== 2, "Hot item: %lx, expected 2\n", ret
);
585 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, -0xbeef, 0);
586 ok(ret
== 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
587 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
588 ok(ret
== -1, "Hot item: %lx, expected -1\n", ret
);
590 expect_hot_notify(0, 7);
591 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
592 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
594 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
595 ok(ret
== 3, "Hot item: %lx, expected 3\n", ret
);
596 g_fBlockHotItemChange
= TRUE
;
597 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 2, 0);
598 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
599 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
600 ok(ret
== 3, "Hot item: %lx, expected 3\n", ret
);
601 g_fBlockHotItemChange
= FALSE
;
603 g_fReceivedHotItemChange
= FALSE
;
604 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 0xbeaf, 0);
605 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
606 ok(g_fReceivedHotItemChange
== FALSE
, "TBN_HOTITEMCHANGE received for invalid parameter\n");
608 g_fReceivedHotItemChange
= FALSE
;
609 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
610 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
611 ok(g_fReceivedHotItemChange
== FALSE
, "TBN_HOTITEMCHANGE received after a duplication\n");
613 expect_hot_notify(7, 0);
614 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, -0xbeaf, 0);
615 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
617 SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
619 /* setting disabled buttons will generate a notify with the button id but no button will be hot */
620 expect_hot_notify(7, 9);
621 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 4, 0);
622 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
624 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
625 ok(ret
== -1, "Hot item: %lx, expected -1\n", ret
);
626 /* enabling the button won't change that */
627 SendMessage(hToolbar
, TB_ENABLEBUTTON
, 9, TRUE
);
628 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
629 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
631 /* disabling a hot button works */
632 ret
= SendMessage(hToolbar
, TB_SETHOTITEM
, 3, 0);
633 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
634 g_fReceivedHotItemChange
= FALSE
;
635 SendMessage(hToolbar
, TB_ENABLEBUTTON
, 7, FALSE
);
636 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
637 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
638 ok(g_fReceivedHotItemChange
== FALSE
, "Unexpected TBN_HOTITEMCHANGE\n");
640 SendMessage(hToolbar
, TB_SETHOTITEM
, 1, 0);
641 tbinfo
.cbSize
= sizeof(TBBUTTONINFO
);
642 tbinfo
.dwMask
= TBIF_STATE
;
643 tbinfo
.fsState
= 0; /* disabled */
644 g_fReceivedHotItemChange
= FALSE
;
645 ok(SendMessage(hToolbar
, TB_SETBUTTONINFO
, 1, (LPARAM
)&tbinfo
) == TRUE
, "TB_SETBUTTONINFO failed\n");
646 ret
= SendMessage(hToolbar
, TB_GETHOTITEM
, 0, 0);
647 ok(ret
== 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret
);
648 ok(g_fReceivedHotItemChange
== FALSE
, "Unexpected TBN_HOTITEMCHANGE\n");
650 DestroyWindow(hToolbar
);
653 #if 0 /* use this to generate more tests*/
655 static void dump_sizes(HWND hToolbar
)
659 int count
= SendMessage(hToolbar
, TB_BUTTONCOUNT
, 0, 0);
662 GetClientRect(hToolbar
, &r
);
663 SendMessageA(hToolbar
, TB_GETMAXSIZE
, 0, &sz
);
664 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r
.left
, r
.top
, r
.right
, r
.bottom
,
665 sz
.cx
, sz
.cy
, count
);
666 for (i
=0; i
<count
; i
++)
668 SendMessageA(hToolbar
, TB_GETITEMRECT
, i
, &r
);
669 printf("%s{%3d, %3d, %3d, %3d}, ", (i
%3==0 ? "\n " : ""), r
.left
, r
.top
, r
.right
, r
.bottom
);
671 printf("\n }, },\n");
674 #define check_sizes() dump_sizes(hToolbar);
675 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
679 static int system_font_height(void) {
683 hDC
= CreateCompatibleDC(NULL
);
684 GetTextMetrics(hDC
, &tm
);
690 static int string_width(const CHAR
*s
) {
694 hdc
= CreateCompatibleDC(NULL
);
695 GetTextExtentPoint32A(hdc
, s
, strlen(s
), &sz
);
709 static tbsize_result_t
init_tbsize_result(int nButtonsAlloc
, int cleft
, int ctop
, int cright
, int cbottom
, int minx
, int miny
) {
712 SetRect(&ret
.rcClient
, cleft
, ctop
, cright
, cbottom
);
716 ret
.prcButtons
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nButtonsAlloc
*sizeof(RECT
));
721 static void tbsize_addbutton(tbsize_result_t
*tbsr
, int left
, int top
, int right
, int bottom
) {
722 SetRect(&tbsr
->prcButtons
[tbsr
->nButtons
], left
, top
, right
, bottom
);
727 #define STRING1 "MMMMMMMMMMMMM"
728 #define STRING2 "Tst"
730 static tbsize_result_t
*tbsize_results
;
732 #define tbsize_results_num 24
734 static void init_tbsize_results(void) {
735 int fontheight
= system_font_height();
738 tbsize_results
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, tbsize_results_num
*sizeof(tbsize_result_t
));
740 tbsize_results
[0] = init_tbsize_result(5, 0, 0 ,672 ,26, 100 ,22);
741 tbsize_addbutton(&tbsize_results
[0], 0, 2, 23, 24);
742 tbsize_addbutton(&tbsize_results
[0], 23, 2, 46, 24);
743 tbsize_addbutton(&tbsize_results
[0], 46, 2, 54, 24);
744 tbsize_addbutton(&tbsize_results
[0], 54, 2, 77, 24);
745 tbsize_addbutton(&tbsize_results
[0], 77, 2, 100, 24);
747 tbsize_results
[1] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
748 tbsize_addbutton(&tbsize_results
[1], 0, 2, 23, 24);
749 tbsize_addbutton(&tbsize_results
[1], 23, 2, 46, 24);
750 tbsize_addbutton(&tbsize_results
[1], 46, 2, 54, 24);
751 tbsize_addbutton(&tbsize_results
[1], 54, 2, 77, 24);
752 tbsize_addbutton(&tbsize_results
[1], 77, 2, 100, 24);
753 tbsize_addbutton(&tbsize_results
[1], 100, 2, 123, 24);
754 tbsize_addbutton(&tbsize_results
[1], 0, 24, 23, 46);
756 tbsize_results
[2] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
757 tbsize_addbutton(&tbsize_results
[2], 0, 2, 23, 24);
758 tbsize_addbutton(&tbsize_results
[2], 23, 2, 46, 24);
759 tbsize_addbutton(&tbsize_results
[2], 46, 2, 54, 24);
760 tbsize_addbutton(&tbsize_results
[2], 54, 2, 77, 24);
761 tbsize_addbutton(&tbsize_results
[2], 77, 2, 100, 24);
762 tbsize_addbutton(&tbsize_results
[2], 100, 2, 123, 24);
763 tbsize_addbutton(&tbsize_results
[2], 0, 24, 23, 46);
765 tbsize_results
[3] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
766 tbsize_addbutton(&tbsize_results
[3], 0, 2, 23, 24);
767 tbsize_addbutton(&tbsize_results
[3], 23, 2, 46, 24);
768 tbsize_addbutton(&tbsize_results
[3], 46, 2, 54, 24);
769 tbsize_addbutton(&tbsize_results
[3], 54, 2, 77, 24);
770 tbsize_addbutton(&tbsize_results
[3], 77, 2, 100, 24);
771 tbsize_addbutton(&tbsize_results
[3], 100, 2, 123, 24);
772 tbsize_addbutton(&tbsize_results
[3], 123, 2, 146, 24);
774 tbsize_results
[4] = init_tbsize_result(9, 0, 0, 672, 26, 192, 22);
775 tbsize_addbutton(&tbsize_results
[4], 0, 2, 23, 24);
776 tbsize_addbutton(&tbsize_results
[4], 23, 2, 46, 24);
777 tbsize_addbutton(&tbsize_results
[4], 46, 2, 54, 24);
778 tbsize_addbutton(&tbsize_results
[4], 54, 2, 77, 24);
779 tbsize_addbutton(&tbsize_results
[4], 77, 2, 100, 24);
780 tbsize_addbutton(&tbsize_results
[4], 100, 2, 123, 24);
781 tbsize_addbutton(&tbsize_results
[4], 123, 2, 146, 24);
782 tbsize_addbutton(&tbsize_results
[4], 146, 2, 169, 24);
783 tbsize_addbutton(&tbsize_results
[4], 169, 2, 192, 24);
785 tbsize_results
[5] = init_tbsize_result(39, 0, 0, 672, 92, 882, 22);
786 tbsize_addbutton(&tbsize_results
[5], 0, 2, 23, 24);
787 tbsize_addbutton(&tbsize_results
[5], 23, 2, 46, 24);
788 tbsize_addbutton(&tbsize_results
[5], 0, 2, 8, 29);
789 tbsize_addbutton(&tbsize_results
[5], 0, 29, 23, 51);
790 tbsize_addbutton(&tbsize_results
[5], 23, 29, 46, 51);
791 tbsize_addbutton(&tbsize_results
[5], 46, 29, 69, 51);
792 tbsize_addbutton(&tbsize_results
[5], 69, 29, 92, 51);
793 tbsize_addbutton(&tbsize_results
[5], 92, 29, 115, 51);
794 tbsize_addbutton(&tbsize_results
[5], 115, 29, 138, 51);
795 tbsize_addbutton(&tbsize_results
[5], 138, 29, 161, 51);
796 tbsize_addbutton(&tbsize_results
[5], 161, 29, 184, 51);
797 tbsize_addbutton(&tbsize_results
[5], 184, 29, 207, 51);
798 tbsize_addbutton(&tbsize_results
[5], 207, 29, 230, 51);
799 tbsize_addbutton(&tbsize_results
[5], 230, 29, 253, 51);
800 tbsize_addbutton(&tbsize_results
[5], 253, 29, 276, 51);
801 tbsize_addbutton(&tbsize_results
[5], 276, 29, 299, 51);
802 tbsize_addbutton(&tbsize_results
[5], 299, 29, 322, 51);
803 tbsize_addbutton(&tbsize_results
[5], 322, 29, 345, 51);
804 tbsize_addbutton(&tbsize_results
[5], 345, 29, 368, 51);
805 tbsize_addbutton(&tbsize_results
[5], 368, 29, 391, 51);
806 tbsize_addbutton(&tbsize_results
[5], 391, 29, 414, 51);
807 tbsize_addbutton(&tbsize_results
[5], 414, 29, 437, 51);
808 tbsize_addbutton(&tbsize_results
[5], 437, 29, 460, 51);
809 tbsize_addbutton(&tbsize_results
[5], 460, 29, 483, 51);
810 tbsize_addbutton(&tbsize_results
[5], 483, 29, 506, 51);
811 tbsize_addbutton(&tbsize_results
[5], 506, 29, 529, 51);
812 tbsize_addbutton(&tbsize_results
[5], 529, 29, 552, 51);
813 tbsize_addbutton(&tbsize_results
[5], 552, 29, 575, 51);
814 tbsize_addbutton(&tbsize_results
[5], 575, 29, 598, 51);
815 tbsize_addbutton(&tbsize_results
[5], 598, 29, 621, 51);
816 tbsize_addbutton(&tbsize_results
[5], 621, 29, 644, 51);
817 tbsize_addbutton(&tbsize_results
[5], 644, 29, 667, 51);
818 tbsize_addbutton(&tbsize_results
[5], 0, 51, 23, 73);
819 tbsize_addbutton(&tbsize_results
[5], 23, 51, 46, 73);
820 tbsize_addbutton(&tbsize_results
[5], 46, 51, 69, 73);
821 tbsize_addbutton(&tbsize_results
[5], 69, 51, 92, 73);
822 tbsize_addbutton(&tbsize_results
[5], 92, 51, 115, 73);
823 tbsize_addbutton(&tbsize_results
[5], 115, 51, 138, 73);
824 tbsize_addbutton(&tbsize_results
[5], 138, 51, 161, 73);
826 tbsize_results
[6] = init_tbsize_result(7, 0, 0, 48, 226, 23, 140);
827 tbsize_addbutton(&tbsize_results
[6], 0, 2, 23, 24);
828 tbsize_addbutton(&tbsize_results
[6], 23, 2, 46, 24);
829 tbsize_addbutton(&tbsize_results
[6], 46, 2, 94, 24);
830 tbsize_addbutton(&tbsize_results
[6], 94, 2, 117, 24);
831 tbsize_addbutton(&tbsize_results
[6], 117, 2, 140, 24);
832 tbsize_addbutton(&tbsize_results
[6], 140, 2, 163, 24);
833 tbsize_addbutton(&tbsize_results
[6], 0, 24, 23, 46);
835 tbsize_results
[7] = init_tbsize_result(7, 0, 0, 92, 226, 23, 140);
836 tbsize_addbutton(&tbsize_results
[7], 0, 2, 23, 24);
837 tbsize_addbutton(&tbsize_results
[7], 23, 2, 46, 24);
838 tbsize_addbutton(&tbsize_results
[7], 0, 24, 92, 32);
839 tbsize_addbutton(&tbsize_results
[7], 0, 32, 23, 54);
840 tbsize_addbutton(&tbsize_results
[7], 23, 32, 46, 54);
841 tbsize_addbutton(&tbsize_results
[7], 46, 32, 69, 54);
842 tbsize_addbutton(&tbsize_results
[7], 69, 32, 92, 54);
844 tbsize_results
[8] = init_tbsize_result(7, 0, 0, 672, 26, 194, 30);
845 tbsize_addbutton(&tbsize_results
[8], 0, 2, 31, 32);
846 tbsize_addbutton(&tbsize_results
[8], 31, 2, 62, 32);
847 tbsize_addbutton(&tbsize_results
[8], 62, 2, 70, 32);
848 tbsize_addbutton(&tbsize_results
[8], 70, 2, 101, 32);
849 tbsize_addbutton(&tbsize_results
[8], 101, 2, 132, 32);
850 tbsize_addbutton(&tbsize_results
[8], 132, 2, 163, 32);
851 tbsize_addbutton(&tbsize_results
[8], 0, 32, 31, 62);
853 tbsize_results
[9] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
854 tbsize_addbutton(&tbsize_results
[9], 0, 2, 31, 32);
855 tbsize_addbutton(&tbsize_results
[9], 31, 2, 62, 32);
856 tbsize_addbutton(&tbsize_results
[9], 62, 2, 70, 32);
857 tbsize_addbutton(&tbsize_results
[9], 70, 2, 101, 32);
858 tbsize_addbutton(&tbsize_results
[9], 101, 2, 132, 32);
859 tbsize_addbutton(&tbsize_results
[9], 132, 2, 163, 32);
860 tbsize_addbutton(&tbsize_results
[9], 0, 32, 31, 62);
862 tbsize_results
[10] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
863 tbsize_addbutton(&tbsize_results
[10], 0, 0, 31, 30);
864 tbsize_addbutton(&tbsize_results
[10], 31, 0, 62, 30);
865 tbsize_addbutton(&tbsize_results
[10], 62, 0, 70, 30);
866 tbsize_addbutton(&tbsize_results
[10], 70, 0, 101, 30);
867 tbsize_addbutton(&tbsize_results
[10], 101, 0, 132, 30);
868 tbsize_addbutton(&tbsize_results
[10], 132, 0, 163, 30);
869 tbsize_addbutton(&tbsize_results
[10], 0, 30, 31, 60);
871 tbsize_results
[11] = init_tbsize_result(7, 0, 0, 124, 226, 31, 188);
872 tbsize_addbutton(&tbsize_results
[11], 0, 0, 31, 30);
873 tbsize_addbutton(&tbsize_results
[11], 31, 0, 62, 30);
874 tbsize_addbutton(&tbsize_results
[11], 0, 30, 124, 38);
875 tbsize_addbutton(&tbsize_results
[11], 0, 38, 31, 68);
876 tbsize_addbutton(&tbsize_results
[11], 31, 38, 62, 68);
877 tbsize_addbutton(&tbsize_results
[11], 62, 38, 93, 68);
878 tbsize_addbutton(&tbsize_results
[11], 93, 38, 124, 68);
880 tbsize_results
[12] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
881 tbsize_addbutton(&tbsize_results
[12], 0, 2, 23, 24);
882 tbsize_addbutton(&tbsize_results
[12], 23, 2, 46, 24);
883 tbsize_addbutton(&tbsize_results
[12], 46, 2, 54, 24);
884 tbsize_addbutton(&tbsize_results
[12], 54, 2, 77, 24);
885 tbsize_addbutton(&tbsize_results
[12], 77, 2, 100, 24);
886 tbsize_addbutton(&tbsize_results
[12], 100, 2, 123, 24);
887 tbsize_addbutton(&tbsize_results
[12], 123, 2, 146, 24);
889 tbsize_results
[13] = init_tbsize_result(7, 0, 0, 672, 26, 146, 100);
890 tbsize_addbutton(&tbsize_results
[13], 0, 0, 23, 100);
891 tbsize_addbutton(&tbsize_results
[13], 23, 0, 46, 100);
892 tbsize_addbutton(&tbsize_results
[13], 46, 0, 54, 100);
893 tbsize_addbutton(&tbsize_results
[13], 54, 0, 77, 100);
894 tbsize_addbutton(&tbsize_results
[13], 77, 0, 100, 100);
895 tbsize_addbutton(&tbsize_results
[13], 100, 0, 123, 100);
896 tbsize_addbutton(&tbsize_results
[13], 123, 0, 146, 100);
898 tbsize_results
[14] = init_tbsize_result(10, 0, 0, 672, 26, 146, 100);
899 tbsize_addbutton(&tbsize_results
[14], 0, 0, 23, 100);
900 tbsize_addbutton(&tbsize_results
[14], 23, 0, 46, 100);
901 tbsize_addbutton(&tbsize_results
[14], 46, 0, 54, 100);
902 tbsize_addbutton(&tbsize_results
[14], 54, 0, 77, 100);
903 tbsize_addbutton(&tbsize_results
[14], 77, 0, 100, 100);
904 tbsize_addbutton(&tbsize_results
[14], 100, 0, 123, 100);
905 tbsize_addbutton(&tbsize_results
[14], 123, 0, 146, 100);
906 tbsize_addbutton(&tbsize_results
[14], 146, 0, 169, 100);
907 tbsize_addbutton(&tbsize_results
[14], 169, 0, 192, 100);
908 tbsize_addbutton(&tbsize_results
[14], 192, 0, 215, 100);
910 tbsize_results
[15] = init_tbsize_result(11, 0, 0, 672, 26, 238, 39);
911 tbsize_addbutton(&tbsize_results
[15], 0, 0, 23, 23 + fontheight
);
912 tbsize_addbutton(&tbsize_results
[15], 23, 0, 46, 23 + fontheight
);
913 tbsize_addbutton(&tbsize_results
[15], 46, 0, 54, 23 + fontheight
);
914 tbsize_addbutton(&tbsize_results
[15], 54, 0, 77, 23 + fontheight
);
915 tbsize_addbutton(&tbsize_results
[15], 77, 0, 100, 23 + fontheight
);
916 tbsize_addbutton(&tbsize_results
[15], 100, 0, 123, 23 + fontheight
);
917 tbsize_addbutton(&tbsize_results
[15], 123, 0, 146, 23 + fontheight
);
918 tbsize_addbutton(&tbsize_results
[15], 146, 0, 169, 23 + fontheight
);
919 tbsize_addbutton(&tbsize_results
[15], 169, 0, 192, 23 + fontheight
);
920 tbsize_addbutton(&tbsize_results
[15], 192, 0, 215, 23 + fontheight
);
921 tbsize_addbutton(&tbsize_results
[15], 215, 0, 238, 23 + fontheight
);
923 tbsize_results
[16] = init_tbsize_result(11, 0, 0, 672, 26, 239, 22);
924 tbsize_addbutton(&tbsize_results
[16], 0, 0, 23, 22);
925 tbsize_addbutton(&tbsize_results
[16], 23, 0, 46, 22);
926 tbsize_addbutton(&tbsize_results
[16], 46, 0, 54, 22);
927 tbsize_addbutton(&tbsize_results
[16], 54, 0, 77, 22);
928 tbsize_addbutton(&tbsize_results
[16], 77, 0, 100, 22);
929 tbsize_addbutton(&tbsize_results
[16], 100, 0, 123, 22);
930 tbsize_addbutton(&tbsize_results
[16], 123, 0, 146, 22);
931 tbsize_addbutton(&tbsize_results
[16], 146, 0, 169, 22);
932 tbsize_addbutton(&tbsize_results
[16], 169, 0, 192, 22);
933 tbsize_addbutton(&tbsize_results
[16], 192, 0, 215, 22);
934 tbsize_addbutton(&tbsize_results
[16], 215, 0, 238, 22);
936 buttonwidth
= 7 + string_width(STRING1
);
938 tbsize_results
[17] = init_tbsize_result(3, 0, 0, 672, 26, 489, 39);
939 tbsize_addbutton(&tbsize_results
[17], 0, 2, buttonwidth
, 25 + fontheight
);
940 tbsize_addbutton(&tbsize_results
[17], buttonwidth
, 2, 2*buttonwidth
+ 4, 25 + fontheight
);
941 tbsize_addbutton(&tbsize_results
[17], 2*buttonwidth
+ 4, 2, 3*buttonwidth
+ 4, 25 + fontheight
);
943 tbsize_results
[18] = init_tbsize_result(6, 0, 0, 672, 104, 978, 24);
944 tbsize_addbutton(&tbsize_results
[18], 0, 2, buttonwidth
, 10 + fontheight
);
945 tbsize_addbutton(&tbsize_results
[18], buttonwidth
, 2, 2*buttonwidth
, 10 + fontheight
);
946 tbsize_addbutton(&tbsize_results
[18], 2*buttonwidth
, 2, 3*buttonwidth
, 10 + fontheight
);
947 tbsize_addbutton(&tbsize_results
[18], 3*buttonwidth
, 2, 4*buttonwidth
, 10 + fontheight
);
948 tbsize_addbutton(&tbsize_results
[18], 4*buttonwidth
, 2, 5*buttonwidth
+ 4, 10 + fontheight
);
949 tbsize_addbutton(&tbsize_results
[18], 5*buttonwidth
+ 4, 2, 5*buttonwidth
+ 4 + string_width(STRING2
) + 11, 10 + fontheight
);
951 tbsize_results
[19] = init_tbsize_result(6, 0, 0, 672, 28, 978, 38);
952 tbsize_addbutton(&tbsize_results
[19], 0, 0, buttonwidth
, 22 + fontheight
);
953 tbsize_addbutton(&tbsize_results
[19], buttonwidth
, 0, 2*buttonwidth
, 22 + fontheight
);
954 tbsize_addbutton(&tbsize_results
[19], 2*buttonwidth
, 0, 3*buttonwidth
, 22 + fontheight
);
955 tbsize_addbutton(&tbsize_results
[19], 3*buttonwidth
, 0, 4*buttonwidth
, 22 + fontheight
);
956 tbsize_addbutton(&tbsize_results
[19], 4*buttonwidth
, 0, 5*buttonwidth
+ 4, 22 + fontheight
);
957 tbsize_addbutton(&tbsize_results
[19], 5*buttonwidth
+ 4, 0, 5*buttonwidth
+ 4 + string_width(STRING2
) + 11, 22 + fontheight
);
959 tbsize_results
[20] = init_tbsize_result(3, 0, 0, 672, 100, 239, 102);
960 tbsize_addbutton(&tbsize_results
[20], 0, 2, 100, 102);
961 tbsize_addbutton(&tbsize_results
[20], 100, 2, 139, 102);
962 tbsize_addbutton(&tbsize_results
[20], 139, 2, 239, 102);
964 tbsize_results
[21] = init_tbsize_result(3, 0, 0, 672, 42, 185, 40);
965 tbsize_addbutton(&tbsize_results
[21], 0, 2, 75, 40);
966 tbsize_addbutton(&tbsize_results
[21], 75, 2, 118, 40);
967 tbsize_addbutton(&tbsize_results
[21], 118, 2, 165 + string_width(STRING2
), 40);
969 tbsize_results
[22] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
970 tbsize_addbutton(&tbsize_results
[22], 0, 2, 47 + string_width(STRING2
), 40);
972 tbsize_results
[23] = init_tbsize_result(2, 0, 0, 672, 42, 67, 41);
973 tbsize_addbutton(&tbsize_results
[23], 0, 2, 672, 25 + fontheight
);
974 tbsize_addbutton(&tbsize_results
[23], 0, 25 + fontheight
, 672, 48 + 2*fontheight
);
977 static void free_tbsize_results(void) {
980 for (i
= 0; i
< tbsize_results_num
; i
++)
981 HeapFree(GetProcessHeap(), 0, tbsize_results
[i
].prcButtons
);
982 HeapFree(GetProcessHeap(), 0, tbsize_results
);
983 tbsize_results
= NULL
;
986 static int tbsize_numtests
= 0;
993 } tbsize_alt_result_t
;
995 static tbsize_alt_result_t tbsize_alt_results
[] =
997 { 5, 2, { 0, 24, 8, 29 } },
998 { 20, 1, { 100, 2, 107, 102 } },
999 { 20, 2, { 107, 2, 207, 102 } }
1002 static DWORD tbsize_alt_numtests
= 0;
1004 #define check_sizes_todo(todomask) { \
1006 int buttonCount, i, mask=(todomask); \
1007 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
1008 GetClientRect(hToolbar, &rc); \
1009 /*check_rect("client", rc, res->rcClient);*/ \
1010 buttonCount = SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0); \
1011 compare(buttonCount, res->nButtons, "%d"); \
1012 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
1013 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
1014 if (broken(tbsize_alt_numtests < sizeof(tbsize_alt_results)/sizeof(tbsize_alt_results[0]) && \
1015 memcmp(&rc, &tbsize_alt_results[tbsize_alt_numtests].rcButton, sizeof(RECT)) == 0)) { \
1016 win_skip("Alternate rect found\n"); \
1017 tbsize_alt_numtests++; \
1018 } else if (!(mask&1)) { \
1019 check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); \
1021 todo_wine { check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); } \
1025 tbsize_numtests++; \
1028 #define check_sizes() check_sizes_todo(0)
1032 static TBBUTTON buttons1
[] = {
1033 {0, 10, TBSTATE_WRAP
|TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1034 {0, 11, 0, 0, {0, }, 0, -1},
1036 static TBBUTTON buttons2
[] = {
1037 {0, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1038 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1040 static TBBUTTON buttons3
[] = {
1041 {0, 30, TBSTATE_ENABLED
, 0, {0, }, 0, 0},
1042 {0, 31, TBSTATE_ENABLED
, 0, {0, }, 0, 1},
1043 {0, 32, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, 1},
1044 {0, 33, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, (UINT_PTR
)STRING2
}
1047 static void test_sizes(void)
1049 HWND hToolbar
= NULL
;
1050 HIMAGELIST himl
, himl2
;
1051 TBBUTTONINFO tbinfo
;
1054 int fontheight
= system_font_height();
1056 init_tbsize_results();
1058 rebuild_toolbar_with_buttons(&hToolbar
);
1059 style
= GetWindowLong(hToolbar
, GWL_STYLE
);
1060 ok(style
== (WS_CHILD
|WS_VISIBLE
|CCS_TOP
), "Invalid style %x\n", style
);
1062 /* the TBSTATE_WRAP makes a second row */
1063 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
1065 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1067 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
1068 SetWindowLong(hToolbar
, GWL_STYLE
, style
|TBSTYLE_WRAPABLE
);
1070 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
1071 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
1073 /* only after adding enough buttons the bar will be wrapped on a
1074 * separator and then on the first button */
1075 for (i
=0; i
<15; i
++)
1076 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
1077 check_sizes_todo(0x4);
1079 rebuild_toolbar_with_buttons(&hToolbar
);
1080 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
1081 /* setting the buttons vertical will only change the window client size */
1082 SetWindowLong(hToolbar
, GWL_STYLE
, style
| CCS_VERT
);
1083 SendMessage(hToolbar
, TB_AUTOSIZE
, 0, 0);
1084 check_sizes_todo(0x3c);
1085 /* with a TBSTYLE_WRAPABLE a wrapping will occur on the separator */
1086 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_WRAPABLE
| CCS_VERT
);
1087 SendMessage(hToolbar
, TB_AUTOSIZE
, 0, 0);
1088 check_sizes_todo(0x7c);
1090 rebuild_toolbar_with_buttons(&hToolbar
);
1091 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons1
);
1092 /* a TB_SETBITMAPSIZE changes button sizes*/
1093 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(24, 24));
1096 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
1097 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
);
1098 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1100 /* but after a TB_SETBITMAPSIZE the top margins is changed */
1101 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(20, 20));
1102 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(24, 24));
1104 /* some vertical toolbar sizes */
1105 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
| TBSTYLE_WRAPABLE
| CCS_VERT
);
1106 check_sizes_todo(0x7c);
1108 rebuild_toolbar_with_buttons(&hToolbar
);
1109 SetWindowLong(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
);
1110 /* newly added buttons will be use the previous margin */
1111 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons2
);
1113 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
1114 check_button_size(hToolbar
, 23, 22);
1115 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
1116 check_button_size(hToolbar
, 23, 22);
1117 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1118 check_button_size(hToolbar
, 23, 100);
1119 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
1120 check_button_size(hToolbar
, 23, 22);
1121 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1122 check_button_size(hToolbar
, 23, 100);
1124 /* add some buttons with non-default sizes */
1125 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons2
);
1126 SendMessageA(hToolbar
, TB_INSERTBUTTON
, -1, (LPARAM
)&buttons2
[0]);
1128 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[0]);
1129 /* TB_ADDSTRING resets the size */
1130 SendMessageA(hToolbar
, TB_ADDSTRING
, 0, (LPARAM
) STRING0
"\0" STRING1
"\0");
1131 check_button_size(hToolbar
, 23, 23 + fontheight
);
1133 /* TB_SETBUTTONSIZE can be used to crop the text */
1134 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1135 check_button_size(hToolbar
, 23, 22);
1137 /* the default size is bitmap size + padding */
1138 SendMessageA(hToolbar
, TB_SETPADDING
, 0, MAKELONG(1, 1));
1139 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1140 check_button_size(hToolbar
, 17, 17);
1141 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(3, 3));
1142 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1143 check_button_size(hToolbar
, 4, 4);
1145 rebuild_toolbar(&hToolbar
);
1146 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
1147 check_button_size(hToolbar
, 23, 22);
1148 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(16, 15));
1149 check_button_size(hToolbar
, 23, 21);
1150 /* -1 in TB_SETBITMAPSIZE is a special code meaning that the coordinate shouldn't be changed */
1151 add_128x15_bitmap(hToolbar
, 16);
1152 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(14, -1)), "TB_SETBITMAPSIZE failed\n");
1153 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 21), "%x");
1154 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(-1, 12)), "TB_SETBITMAPSIZE failed\n");
1155 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 18), "%x");
1156 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(-1, -1)), "TB_SETBITMAPSIZE failed\n");
1157 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 18), "%x");
1158 /* check the imagelist */
1159 InvalidateRect(hToolbar
, NULL
, TRUE
);
1160 UpdateWindow(hToolbar
);
1161 CHECK_IMAGELIST(16, 14, 12);
1163 rebuild_toolbar(&hToolbar
);
1164 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)STRING0
"\0" STRING1
"\0");
1165 /* the height is increased after a TB_ADDSTRING */
1166 check_button_size(hToolbar
, 23, 23 + fontheight
);
1167 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1168 /* if a string is in the pool, even adding a button without a string resets the size */
1169 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons2
[0]);
1170 check_button_size(hToolbar
, 23, 22);
1171 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1172 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
1173 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[2]);
1174 check_button_size(hToolbar
, 7 + string_width(STRING1
), 23 + fontheight
);
1175 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[0]);
1177 /* delete button doesn't change the buttons size */
1178 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 2, 0);
1179 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 1, 0);
1180 check_button_size(hToolbar
, 7 + string_width(STRING1
), 23 + fontheight
);
1181 /* TB_INSERTBUTTONS will */
1182 SendMessageA(hToolbar
, TB_INSERTBUTTON
, 1, (LPARAM
)&buttons2
[0]);
1183 check_button_size(hToolbar
, 23, 22);
1185 /* TB_HIDEBUTTON and TB_MOVEBUTTON doesn't force a recalc */
1186 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1187 ok(SendMessageA(hToolbar
, TB_MOVEBUTTON
, 0, 1), "TB_MOVEBUTTON failed\n");
1188 check_button_size(hToolbar
, 100, 100);
1189 ok(SendMessageA(hToolbar
, TB_HIDEBUTTON
, 20, TRUE
), "TB_HIDEBUTTON failed\n");
1190 check_button_size(hToolbar
, 100, 100);
1191 /* however changing the hidden flag with TB_SETSTATE does */
1192 ok(SendMessageA(hToolbar
, TB_SETSTATE
, 20, TBSTATE_ENABLED
|TBSTATE_HIDDEN
), "TB_SETSTATE failed\n");
1193 check_button_size(hToolbar
, 100, 100);
1194 ok(SendMessageA(hToolbar
, TB_SETSTATE
, 20, TBSTATE_ENABLED
), "TB_SETSTATE failed\n");
1195 check_button_size(hToolbar
, 23, 22);
1197 /* TB_SETIMAGELIST always changes the height but the width only if necessary */
1198 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1199 himl
= ImageList_LoadImage(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_BITMAP_80x15
), 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
1200 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1201 check_button_size(hToolbar
, 100, 21);
1202 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1203 check_button_size(hToolbar
, 100, 100);
1204 /* But there are no update when we change imagelist, and image sizes are the same */
1205 himl2
= ImageList_LoadImage(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDB_BITMAP_128x15
), 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
1206 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LRESULT
)himl2
) == (LRESULT
)himl
, "TB_SETIMAGELIST failed\n");
1207 check_button_size(hToolbar
, 100, 100);
1208 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(1, 1));
1209 check_button_size(hToolbar
, 27, 21);
1210 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, 0) == (LRESULT
)himl2
, "TB_SETIMAGELIST failed\n");
1211 check_button_size(hToolbar
, 27, 7);
1212 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(1, 1));
1213 check_button_size(hToolbar
, 8, 7)
1214 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1215 check_button_size(hToolbar
, 27, 21)
1216 /* the text is taken into account */
1217 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)STRING0
"\0" STRING1
"\0");
1218 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 4, (LPARAM
)buttons3
);
1219 check_button_size(hToolbar
, 7 + string_width(STRING1
), 22 + fontheight
);
1220 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, 0) == (LRESULT
)himl
, "TB_SETIMAGELIST failed\n");
1221 check_button_size(hToolbar
, 7 + string_width(STRING1
), 8 + fontheight
);
1222 /* the style change also comes into effect */
1224 SetWindowLong(hToolbar
, GWL_STYLE
, GetWindowLong(hToolbar
, GWL_STYLE
) | TBSTYLE_FLAT
);
1225 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1226 check_sizes_todo(0x30); /* some small problems with BTNS_AUTOSIZE button sizes */
1228 rebuild_toolbar(&hToolbar
);
1229 ImageList_Destroy(himl
);
1230 ImageList_Destroy(himl2
);
1232 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]);
1233 check_button_size(hToolbar
, 7 + string_width(STRING2
), 23 + fontheight
);
1234 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 0, 0);
1235 check_button_size(hToolbar
, 7 + string_width(STRING2
), 23 + fontheight
);
1237 rebuild_toolbar(&hToolbar
);
1239 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1240 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1241 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons2
[0]) == 1, "TB_ADDBUTTONS failed\n");
1242 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[2]) == 1, "TB_ADDBUTTONS failed\n");
1243 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[0]) == 1, "TB_ADDBUTTONS failed\n");
1244 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1247 rebuild_toolbar(&hToolbar
);
1248 SetWindowLong(hToolbar
, GWL_STYLE
, TBSTYLE_LIST
| GetWindowLong(hToolbar
, GWL_STYLE
));
1249 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1250 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1251 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons2
[0]) == 1, "TB_ADDBUTTONS failed\n");
1252 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[2]) == 1, "TB_ADDBUTTONS failed\n");
1253 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONS failed\n");
1254 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1255 check_sizes_todo(0xff);
1257 rebuild_toolbar(&hToolbar
);
1258 SetWindowLong(hToolbar
, GWL_STYLE
, TBSTYLE_LIST
| GetWindowLong(hToolbar
, GWL_STYLE
));
1259 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1260 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1261 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONS failed\n");
1262 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1265 rebuild_toolbar(&hToolbar
);
1266 SetWindowLong(hToolbar
, GWL_STYLE
, TBSTYLE_WRAPABLE
| GetWindowLong(hToolbar
, GWL_STYLE
));
1267 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONS failed\n");
1268 ok(SendMessageA(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONS failed\n");
1270 tbinfo
.cbSize
= sizeof(TBBUTTONINFO
);
1271 tbinfo
.dwMask
= TBIF_SIZE
| TBIF_BYINDEX
;
1272 if (SendMessageA(hToolbar
, TB_SETBUTTONINFO
, 0, (LPARAM
)&tbinfo
))
1274 ok(SendMessageA(hToolbar
, TB_SETBUTTONINFO
, 1, (LPARAM
)&tbinfo
) != 0, "TB_SETBUTTONINFO failed\n");
1275 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1278 else /* TBIF_BYINDEX probably not supported, confirm that this was the reason for the failure */
1280 tbinfo
.dwMask
= TBIF_SIZE
;
1281 ok(SendMessageA(hToolbar
, TB_SETBUTTONINFO
, 33, (LPARAM
)&tbinfo
) != 0, "TB_SETBUTTONINFO failed\n");
1284 free_tbsize_results();
1285 DestroyWindow(hToolbar
);
1288 /* Toolbar control has two ways of reacting to a change. We call them a
1289 * relayout and recalc. A recalc forces a recompute of values like button size
1290 * and top margin (the latter in comctl32 <v6), while a relayout uses the cached
1291 * values. This functions creates a flat toolbar with a top margin of a non-flat
1292 * toolbar. We will notice a recalc, as it will recompte the top margin and
1293 * change it to zero*/
1294 static void prepare_recalc_test(HWND
*phToolbar
)
1297 rebuild_toolbar_with_buttons(phToolbar
);
1298 SetWindowLong(*phToolbar
, GWL_STYLE
,
1299 GetWindowLong(*phToolbar
, GWL_STYLE
) | TBSTYLE_FLAT
);
1300 SendMessage(*phToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1301 ok(rect
.top
== 2, "Test will make no sense because initial top is %d instead of 2\n",
1305 static BOOL
did_recalc(HWND hToolbar
)
1308 SendMessage(hToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1309 ok(rect
.top
== 2 || rect
.top
== 0, "Unexpected top margin %d in recalc test\n",
1311 return (rect
.top
== 0);
1314 /* call after a recalc did happen to return to an unstable state */
1315 static void restore_recalc_state(HWND hToolbar
)
1318 /* return to style with a 2px top margin */
1319 SetWindowLong(hToolbar
, GWL_STYLE
,
1320 GetWindowLong(hToolbar
, GWL_STYLE
) & ~TBSTYLE_FLAT
);
1322 SendMessage(hToolbar
, TB_ADDBUTTONS
, 1, (LPARAM
)&buttons3
[3]);
1323 /* top margin will be 0px if a recalc occurs */
1324 SetWindowLong(hToolbar
, GWL_STYLE
,
1325 GetWindowLong(hToolbar
, GWL_STYLE
) | TBSTYLE_FLAT
);
1327 SendMessage(hToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1328 ok(rect
.top
== 2, "Test will make no sense because initial top is %d instead of 2\n",
1332 static void test_recalc(void)
1334 HWND hToolbar
= NULL
;
1336 CHAR test
[] = "Test";
1337 const int EX_STYLES_COUNT
= 5;
1341 /* Like TB_ADDBUTTONS tested in test_sized, inserting a button without text
1342 * results in a relayout, while adding one with text forces a recalc */
1343 prepare_recalc_test(&hToolbar
);
1344 SendMessage(hToolbar
, TB_INSERTBUTTON
, 1, (LPARAM
)&buttons3
[0]);
1345 recalc
= did_recalc(hToolbar
);
1346 ok(!recalc
, "Unexpected recalc - adding button without text\n");
1348 prepare_recalc_test(&hToolbar
);
1349 SendMessage(hToolbar
, TB_INSERTBUTTON
, 1, (LPARAM
)&buttons3
[3]);
1350 recalc
= did_recalc(hToolbar
);
1351 ok(recalc
, "Expected a recalc - adding button with text\n");
1353 /* TB_SETBUTTONINFO, even when adding a text, results only in a relayout */
1354 prepare_recalc_test(&hToolbar
);
1355 bi
.cbSize
= sizeof(bi
);
1356 bi
.dwMask
= TBIF_TEXT
;
1358 SendMessage(hToolbar
, TB_SETBUTTONINFO
, 1, (LPARAM
)&bi
);
1359 recalc
= did_recalc(hToolbar
);
1360 ok(!recalc
, "Unexpected recalc - setting a button text\n");
1362 /* most extended styled doesn't force a recalc (testing all the bits gives
1363 * the same results, but prints some ERRs while testing) */
1364 for (i
= 0; i
< EX_STYLES_COUNT
; i
++)
1366 if (i
== 1 || i
== 3) /* an undoc style and TBSTYLE_EX_MIXEDBUTTONS */
1368 prepare_recalc_test(&hToolbar
);
1369 expect(0, (int)SendMessage(hToolbar
, TB_GETEXTENDEDSTYLE
, 0, 0));
1370 SendMessage(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, (1 << i
));
1371 recalc
= did_recalc(hToolbar
);
1372 ok(!recalc
, "Unexpected recalc - setting bit %d\n", i
);
1373 SendMessage(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, 0);
1374 recalc
= did_recalc(hToolbar
);
1375 ok(!recalc
, "Unexpected recalc - clearing bit %d\n", i
);
1376 expect(0, (int)SendMessage(hToolbar
, TB_GETEXTENDEDSTYLE
, 0, 0));
1379 /* TBSTYLE_EX_MIXEDBUTTONS does a recalc on change */
1380 prepare_recalc_test(&hToolbar
);
1381 SendMessage(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1382 recalc
= did_recalc(hToolbar
);
1385 ok(recalc
, "Expected a recalc - setting TBSTYLE_EX_MIXEDBUTTONS\n");
1386 restore_recalc_state(hToolbar
);
1387 SendMessage(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1388 recalc
= did_recalc(hToolbar
);
1389 ok(!recalc
, "Unexpected recalc - setting TBSTYLE_EX_MIXEDBUTTONS again\n");
1390 restore_recalc_state(hToolbar
);
1391 SendMessage(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, 0);
1392 recalc
= did_recalc(hToolbar
);
1393 ok(recalc
, "Expected a recalc - clearing TBSTYLE_EX_MIXEDBUTTONS\n");
1395 else win_skip( "No recalc on TBSTYLE_EX_MIXEDBUTTONS\n" );
1397 /* undocumented exstyle 0x2 seems to changes the top margin, what
1398 * interferes with these tests */
1400 DestroyWindow(hToolbar
);
1403 static void test_getbuttoninfo(void)
1405 HWND hToolbar
= NULL
;
1408 rebuild_toolbar_with_buttons(&hToolbar
);
1409 for (i
= 0; i
< 128; i
++)
1415 tbi
.dwMask
= TBIF_COMMAND
;
1416 ret
= (int)SendMessage(hToolbar
, TB_GETBUTTONINFO
, 1, (LPARAM
)&tbi
);
1417 if (i
== sizeof(TBBUTTONINFO
)) {
1418 compare(ret
, 0, "%d");
1420 compare(ret
, -1, "%d");
1423 DestroyWindow(hToolbar
);
1426 static void test_createtoolbarex(void)
1430 ZeroMemory(&btns
, sizeof(btns
));
1432 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1433 3, 20, 20, 16, 16, sizeof(TBBUTTON
));
1434 CHECK_IMAGELIST(16, 20, 20);
1435 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x1a001b, "%x");
1436 DestroyWindow(hToolbar
);
1438 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1439 3, 4, 4, 16, 16, sizeof(TBBUTTON
));
1440 CHECK_IMAGELIST(32, 4, 4);
1441 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xa000b, "%x");
1442 DestroyWindow(hToolbar
);
1444 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1445 3, 0, 8, 12, 12, sizeof(TBBUTTON
));
1446 CHECK_IMAGELIST(16, 12, 12);
1447 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x120013, "%x");
1448 DestroyWindow(hToolbar
);
1450 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1451 3, -1, 8, 12, 12, sizeof(TBBUTTON
));
1452 CHECK_IMAGELIST(16, 12, 8);
1453 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xe0013, "%x");
1454 DestroyWindow(hToolbar
);
1456 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1457 3, -1, 8, -1, 12, sizeof(TBBUTTON
));
1458 CHECK_IMAGELIST(16, 16, 8);
1459 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xe0017, "%x");
1460 DestroyWindow(hToolbar
);
1462 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1463 3, 0, 0, 12, -1, sizeof(TBBUTTON
));
1464 CHECK_IMAGELIST(16, 12, 16);
1465 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x160013, "%x");
1466 DestroyWindow(hToolbar
);
1468 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandle(NULL
), IDB_BITMAP_128x15
, btns
,
1469 3, 0, 0, 0, 12, sizeof(TBBUTTON
));
1470 CHECK_IMAGELIST(16, 16, 16);
1471 compare((int)SendMessage(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x160017, "%x");
1472 DestroyWindow(hToolbar
);
1475 static void test_dispinfo(void)
1477 HWND hToolbar
= NULL
;
1478 const TBBUTTON buttons_disp
[] = {
1479 {-1, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1480 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1484 rebuild_toolbar(&hToolbar
);
1485 SendMessageA(hToolbar
, TB_LOADIMAGES
, IDB_HIST_SMALL_COLOR
, (LPARAM
)HINST_COMMCTRL
);
1486 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons_disp
);
1487 g_dwExpectedDispInfoMask
= TBNF_IMAGE
;
1488 /* Some TBN_GETDISPINFO tests will be done in MyWnd_Notify function.
1489 * We will receive TBN_GETDISPINFOW even if the control is ANSI */
1490 compare((BOOL
)SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 0, "%d");
1491 ShowWindow(hToolbar
, SW_SHOW
);
1492 UpdateWindow(hToolbar
);
1494 ret
= (BOOL
)SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, TRUE
, 0);
1495 compare(ret
, FALSE
, "%d");
1496 compare(SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 1L, "%ld");
1497 InvalidateRect(hToolbar
, NULL
, FALSE
);
1498 UpdateWindow(hToolbar
);
1500 ret
= (BOOL
)SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, FALSE
, 0);
1501 compare(ret
, TRUE
, "%d");
1502 compare(SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 0L, "%ld");
1503 InvalidateRect(hToolbar
, NULL
, FALSE
);
1504 UpdateWindow(hToolbar
);
1506 DestroyWindow(hToolbar
);
1507 g_dwExpectedDispInfoMask
= 0;
1517 static tbrows_result_t tbrows_results
[] =
1519 {1, TRUE
, 1}, /* 0: Simple case 9 in a row */
1520 {2, TRUE
, 2}, /* 1: Another simple case 5 on one row, 4 on another*/
1521 {3, FALSE
, 3}, /* 2: 3 lines - should be 3 lines of 3 buttons */
1522 {8, FALSE
, 5}, /* 3: 8 lines - should be 5 lines of 2 buttons */
1523 {8, TRUE
, 9}, /* 4: 8 lines but grow - should be 9 lines */
1524 {1, TRUE
, 1} /* 5: Back to simple case */
1527 static void test_setrows(void)
1529 TBBUTTON buttons
[9];
1534 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_FLAT
| TBSTYLE_CHECKGROUP
, 0);
1536 /* Test 1 - 9 buttons */
1537 hToolbar
= CreateToolbarEx(hMainWnd
,
1538 WS_VISIBLE
| WS_CLIPCHILDREN
| WS_CHILD
| CCS_NORESIZE
| CCS_NOPARENTALIGN
1539 | CCS_NOMOVEY
| CCS_TOP
,
1542 buttons
, sizeof(buttons
)/sizeof(buttons
[0]),
1543 20, 20, 0, 0, sizeof(TBBUTTON
));
1544 ok(hToolbar
!= NULL
, "Toolbar creation\n");
1545 ok(SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
1547 /* test setting rows to each of 1-10 with bLarger true and false */
1548 for (i
=0; i
<(sizeof(tbrows_results
) / sizeof(tbrows_result_t
)); i
++) {
1552 memset(&rc
, 0xCC, sizeof(rc
));
1553 SendMessageA(hToolbar
, TB_SETROWS
,
1554 MAKELONG(tbrows_results
[i
].nRows
, tbrows_results
[i
].bLarger
),
1557 rows
= SendMessageA(hToolbar
, TB_GETROWS
, MAKELONG(0,0), MAKELONG(0,0));
1558 ok(rows
== tbrows_results
[i
].expectedRows
,
1559 "[%d] Unexpected number of rows %d (expected %d)\n", i
, rows
,
1560 tbrows_results
[i
].expectedRows
);
1563 DestroyWindow(hToolbar
);
1566 static void test_getstring(void)
1568 HWND hToolbar
= NULL
;
1571 static const char answer
[] = "STR";
1572 static const WCHAR answerW
[] = { 'S','T','R',0 };
1575 hToolbar
= CreateWindowExA(0, TOOLBARCLASSNAME
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, hMainWnd
, (HMENU
)5, GetModuleHandle(NULL
), NULL
);
1576 ok(hToolbar
!= NULL
, "Toolbar creation problem\n");
1578 r
= SendMessage(hToolbar
, TB_GETSTRING
, MAKEWPARAM(0, 0), 0);
1581 win_skip("TB_GETSTRING and TB_GETSTRINGW need 5.80\n");
1582 DestroyWindow(hToolbar
);
1586 r
= SendMessage(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(0, 0), 0);
1588 r
= SendMessage(hToolbar
, TB_ADDSTRING
, 0, (LPARAM
)answer
);
1590 r
= SendMessage(hToolbar
, TB_GETSTRING
, MAKEWPARAM(0, 0), 0);
1591 expect(lstrlenA(answer
), r
);
1592 r
= SendMessage(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(0, 0), 0);
1593 expect(lstrlenA(answer
), r
);
1594 r
= SendMessage(hToolbar
, TB_GETSTRING
, MAKEWPARAM(sizeof(str
), 0), (LPARAM
)str
);
1595 expect(lstrlenA(answer
), r
);
1596 expect(0, lstrcmp(answer
, str
));
1597 r
= SendMessage(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(sizeof(strW
), 0), (LPARAM
)strW
);
1598 expect(lstrlenA(answer
), r
);
1599 expect(0, lstrcmpW(answerW
, strW
));
1601 DestroyWindow(hToolbar
);
1604 static void test_tooltip(void)
1606 HWND hToolbar
= NULL
;
1607 const TBBUTTON buttons_disp
[] = {
1608 {-1, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1609 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1611 NMTTDISPINFOW nmtti
;
1613 rebuild_toolbar(&hToolbar
);
1615 SendMessageA(hToolbar
, TB_ADDBUTTONS
, 2, (LPARAM
)buttons_disp
);
1617 /* W used to get through toolbar code that assumes tooltip is always Unicode */
1618 memset(&nmtti
, 0, sizeof(nmtti
));
1619 nmtti
.hdr
.code
= TTN_GETDISPINFOW
;
1620 nmtti
.hdr
.idFrom
= 20;
1622 SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, FALSE
, 0);
1624 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1625 SendMessageA(hToolbar
, WM_NOTIFY
, 0, (LPARAM
)&nmtti
);
1626 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ttgetdispinfo_parent_seq
,
1627 "dispinfo from tooltip", TRUE
);
1629 g_ResetDispTextPtr
= TRUE
;
1630 SendMessageA(hToolbar
, WM_NOTIFY
, 0, (LPARAM
)&nmtti
);
1631 g_ResetDispTextPtr
= FALSE
;
1633 DestroyWindow(hToolbar
);
1642 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
1644 InitCommonControls();
1646 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1649 wc
.hInstance
= GetModuleHandleA(NULL
);
1651 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
1652 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1653 wc
.lpszMenuName
= NULL
;
1654 wc
.lpszClassName
= "Toolbar test parent";
1655 wc
.lpfnWndProc
= parent_wnd_proc
;
1656 RegisterClassA(&wc
);
1658 hMainWnd
= CreateWindowExA(0, "Toolbar test parent", "Blah", WS_OVERLAPPEDWINDOW
,
1659 CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1660 GetClientRect(hMainWnd
, &rc
);
1661 ShowWindow(hMainWnd
, SW_SHOW
);
1669 test_getbuttoninfo();
1670 test_createtoolbarex();
1677 while(GetMessageA(&msg
,0,0,0)) {
1678 TranslateMessage(&msg
);
1679 DispatchMessageA(&msg
);
1681 DestroyWindow(hMainWnd
);