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 static const struct message save_parent_seq
[] = {
58 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, -1 },
59 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 0 },
60 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 1 },
61 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 2 },
62 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 3 },
63 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 4 },
64 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 5 },
65 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_SAVE
, 6 },
69 static const struct message restore_parent_seq
[] = {
70 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, -1 },
71 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 0 },
72 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 1 },
73 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 2 },
74 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 3 },
75 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 4 },
76 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 5 },
77 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 6 },
78 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 7 },
79 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 8 },
80 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 9 },
81 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_RESTORE
, 0xa },
82 { WM_NOTIFY
, sent
|id
, 0, 0, TBN_BEGINADJUST
},
83 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_GETBUTTONINFOA
, 0 },
84 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_GETBUTTONINFOA
, 1 },
85 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_GETBUTTONINFOA
, 2 },
86 { WM_NOTIFY
, sent
|id
|custdraw
, 0, 0, TBN_GETBUTTONINFOA
, 3 },
87 { WM_NOTIFY
, sent
|id
, 0, 0, TBN_ENDADJUST
},
91 #define DEFINE_EXPECT(func) \
92 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
94 #define CHECK_EXPECT2(func) \
96 ok(expect_ ##func, "unexpected call " #func "\n"); \
97 called_ ## func = TRUE; \
100 #define CHECK_CALLED(func) \
102 ok(called_ ## func, "expected " #func "\n"); \
103 expect_ ## func = called_ ## func = FALSE; \
106 #define SET_EXPECT(func) \
107 expect_ ## func = TRUE
109 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
111 #define check_rect(name, val, exp, ...) ok(EqualRect(&val, &exp), \
112 "invalid rect %s - expected %s - (" name ")\n", \
113 wine_dbgstr_rect(&val), wine_dbgstr_rect(&exp), __VA_ARGS__);
115 #define compare(val, exp, format) ok((val) == (exp), #val " value " format " expected " format "\n", (val), (exp));
117 #define check_button_size(handle, width, height, ...) {\
118 LRESULT bsize = SendMessageA(handle, TB_GETBUTTONSIZE, 0, 0);\
119 ok(bsize == MAKELONG(width, height), "Unexpected button size - got size (%d, %d), expected (%d, %d)\n", LOWORD(bsize), HIWORD(bsize), width, height);\
122 static void MakeButton(TBBUTTON
*p
, int idCommand
, int fsStyle
, int nString
) {
124 p
->idCommand
= idCommand
;
125 p
->fsState
= TBSTATE_ENABLED
;
126 p
->fsStyle
= fsStyle
;
127 p
->iString
= nString
;
130 static void *alloced_str
;
132 static LRESULT
parent_wnd_notify(LPARAM lParam
)
134 NMHDR
*hdr
= (NMHDR
*)lParam
;
136 NMTBDISPINFOA
*nmdisp
;
139 case TBN_HOTITEMCHANGE
:
140 nmhi
= (NMTBHOTITEM
*)lParam
;
141 g_fReceivedHotItemChange
= TRUE
;
142 if (g_fExpectedHotItemOld
!= g_fExpectedHotItemNew
)
144 compare(nmhi
->idOld
, g_fExpectedHotItemOld
, "%d");
145 compare(nmhi
->idNew
, g_fExpectedHotItemNew
, "%d");
147 if (g_fBlockHotItemChange
)
151 case TBN_GETDISPINFOA
:
152 ok(FALSE
, "TBN_GETDISPINFOA received\n");
155 case TBN_GETINFOTIPA
:
157 NMTBGETINFOTIPA
*tbgit
= (NMTBGETINFOTIPA
*)lParam
;
159 if (g_ResetDispTextPtr
)
161 tbgit
->pszText
= NULL
;
166 case TBN_GETDISPINFOW
:
167 nmdisp
= (NMTBDISPINFOA
*)lParam
;
169 compare(nmdisp
->dwMask
, g_dwExpectedDispInfoMask
, "%x");
170 ok(nmdisp
->pszText
== NULL
, "pszText is not NULL\n");
174 NMTBSAVE
*save
= (NMTBSAVE
*)lParam
;
175 if (save
->iItem
== -1)
177 save
->cbData
= save
->cbData
* 2 + 11 * sizeof(DWORD
);
178 save
->pData
= HeapAlloc( GetProcessHeap(), 0, save
->cbData
);
179 save
->pData
[0] = 0xcafe;
180 save
->pCurrent
= save
->pData
+ 1;
184 save
->pCurrent
[0] = 0xcafe0000 + save
->iItem
;
188 /* Add on 5 more pseudo buttons. */
189 if (save
->iItem
== save
->cButtons
- 1)
191 save
->pCurrent
[0] = 0xffffffff;
192 save
->pCurrent
[1] = 0xcafe0007;
193 save
->pCurrent
[2] = 0xfffffffe;
194 save
->pCurrent
[3] = 0xcafe0008;
195 save
->pCurrent
[4] = 0x80000000;
196 save
->pCurrent
[5] = 0xcafe0009;
197 save
->pCurrent
[6] = 0x7fffffff;
198 save
->pCurrent
[7] = 0xcafe000a;
199 save
->pCurrent
[8] = 0x100;
200 save
->pCurrent
[9] = 0xcafe000b;
203 /* Return value is ignored */
208 NMTBRESTORE
*restore
= (NMTBRESTORE
*)lParam
;
210 if (restore
->iItem
== -1)
212 ok( restore
->cButtons
== 25, "got %d\n", restore
->cButtons
);
213 ok( *restore
->pCurrent
== 0xcafe, "got %08x\n", *restore
->pCurrent
);
214 /* Skip the last one */
215 restore
->cButtons
= 11;
217 /* BytesPerRecord is ignored */
218 restore
->cbBytesPerRecord
= 10;
222 ok( *restore
->pCurrent
== 0xcafe0000 + restore
->iItem
, "got %08x\n", *restore
->pCurrent
);
223 if (restore
->iItem
< 7 || restore
->iItem
== 10)
225 ok( restore
->tbButton
.iBitmap
== -1, "got %08x\n", restore
->tbButton
.iBitmap
);
226 if (restore
->iItem
< 7)
227 ok( restore
->tbButton
.idCommand
== restore
->iItem
* 2 + 1, "%d: got %08x\n", restore
->iItem
, restore
->tbButton
.idCommand
);
229 ok( restore
->tbButton
.idCommand
== 0x7fffffff, "%d: got %08x\n", restore
->iItem
, restore
->tbButton
.idCommand
);
230 ok( restore
->tbButton
.fsState
== 0, "%d: got %02x\n", restore
->iItem
, restore
->tbButton
.fsState
);
231 ok( restore
->tbButton
.fsStyle
== 0, "%d: got %02x\n", restore
->iItem
, restore
->tbButton
.fsStyle
);
235 ok( restore
->tbButton
.iBitmap
== 8, "got %08x\n", restore
->tbButton
.iBitmap
);
236 ok( restore
->tbButton
.idCommand
== 0, "%d: got %08x\n", restore
->iItem
, restore
->tbButton
.idCommand
);
237 if (restore
->iItem
== 7)
238 ok( restore
->tbButton
.fsState
== 0, "%d: got %02x\n", restore
->iItem
, restore
->tbButton
.fsState
);
240 ok( restore
->tbButton
.fsState
== TBSTATE_HIDDEN
, "%d: got %02x\n", restore
->iItem
, restore
->tbButton
.fsState
);
241 ok( restore
->tbButton
.fsStyle
== BTNS_SEP
, "%d: got %02x\n", restore
->iItem
, restore
->tbButton
.fsStyle
);
244 ok( restore
->tbButton
.dwData
== 0, "got %08lx\n", restore
->tbButton
.dwData
);
245 ok( restore
->tbButton
.iString
== 0, "got %08lx\n", restore
->tbButton
.iString
);
247 restore
->tbButton
.iBitmap
= 0;
248 restore
->tbButton
.fsState
= TBSTATE_ENABLED
;
249 restore
->tbButton
.fsStyle
= 0;
250 restore
->tbButton
.dwData
= restore
->iItem
;
252 if (restore
->iItem
== 0)
254 restore
->tbButton
.iString
= (INT_PTR
)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, 8 );
255 strcpy( (char *)restore
->tbButton
.iString
, "foo" );
257 else if (restore
->iItem
== 1)
258 restore
->tbButton
.iString
= 2;
260 restore
->tbButton
.iString
= -1;
263 /* Altering cButtons after the 1st call makes no difference. */
267 /* Returning non-zero from the 1st call aborts the restore,
268 otherwise the return value is ignored. */
269 if (restore
->iItem
== -1) return 0;
272 case TBN_GETBUTTONINFOA
:
274 NMTOOLBARA
*tb
= (NMTOOLBARA
*)lParam
;
275 tb
->tbButton
.iBitmap
= 0;
276 tb
->tbButton
.fsState
= 0;
277 tb
->tbButton
.fsStyle
= 0;
278 tb
->tbButton
.dwData
= 0;
279 ok( tb
->cchText
== 128, "got %d\n", tb
->cchText
);
283 tb
->tbButton
.idCommand
= 7;
284 alloced_str
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, 8 );
285 strcpy( alloced_str
, "foo" );
286 tb
->tbButton
.iString
= (INT_PTR
)alloced_str
;
289 tb
->tbButton
.idCommand
= 9;
290 tb
->tbButton
.iString
= 0;
291 /* tb->pszText is ignored */
292 strcpy( tb
->pszText
, "foo" );
295 tb
->tbButton
.idCommand
= 11;
296 tb
->tbButton
.iString
= 3;
305 static LRESULT CALLBACK
parent_wnd_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
307 static LONG defwndproc_counter
= 0;
311 msg
.message
= message
;
312 msg
.flags
= sent
|wparam
|lparam
;
313 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
316 if (message
== WM_NOTIFY
&& lParam
)
318 msg
.id
= ((NMHDR
*)lParam
)->code
;
323 NMTBSAVE
*save
= (NMTBSAVE
*)lParam
;
324 msg
.stage
= save
->iItem
;
329 NMTBRESTORE
*restore
= (NMTBRESTORE
*)lParam
;
330 msg
.stage
= restore
->iItem
;
333 case TBN_GETBUTTONINFOA
:
335 NMTOOLBARA
*tb
= (NMTOOLBARA
*)lParam
;
336 msg
.stage
= tb
->iItem
;
342 /* log system messages, except for painting */
343 if (message
< WM_USER
&&
344 message
!= WM_PAINT
&&
345 message
!= WM_ERASEBKGND
&&
346 message
!= WM_NCPAINT
&&
347 message
!= WM_NCHITTEST
&&
348 message
!= WM_GETTEXT
&&
349 message
!= WM_GETICON
&&
350 message
!= WM_DEVICECHANGE
)
352 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
358 return parent_wnd_notify(lParam
);
361 defwndproc_counter
++;
362 ret
= DefWindowProcA(hWnd
, message
, wParam
, lParam
);
363 defwndproc_counter
--;
368 static void basic_test(void)
375 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_CHECKGROUP
, 0);
376 MakeButton(buttons
+3, 1003, TBSTYLE_SEP
|TBSTYLE_GROUP
, 0);
377 MakeButton(buttons
+6, 1006, TBSTYLE_SEP
, 0);
379 hToolbar
= CreateToolbarEx(hMainWnd
,
380 WS_VISIBLE
| WS_CLIPCHILDREN
| CCS_TOP
|
381 WS_CHILD
| TBSTYLE_LIST
,
384 buttons
, sizeof(buttons
)/sizeof(buttons
[0]),
385 0, 0, 20, 16, sizeof(TBBUTTON
));
386 ok(hToolbar
!= NULL
, "Toolbar creation\n");
387 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)"test\000");
389 /* test for exclusion working inside a separator-separated :-) group */
390 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1000, 1); /* press A1 */
391 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
392 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1001, 0), "A2 not pressed\n");
394 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1004, 1); /* press A5, release A1 */
395 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1004, 0), "A5 pressed\n");
396 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 not pressed anymore\n");
398 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1005, 1); /* press A6, release A5 */
399 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 pressed\n");
400 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1004, 0), "A5 not pressed anymore\n");
402 /* test for inter-group crosstalk, i.e. two radio groups interfering with each other */
403 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1007, 1); /* press B2 */
404 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 still pressed, no inter-group crosstalk\n");
405 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 still not pressed\n");
406 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 pressed\n");
408 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1000, 1); /* press A1 and ensure B group didn't suffer */
409 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 not pressed anymore\n");
410 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
411 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 still pressed\n");
413 SendMessageA(hToolbar
, TB_CHECKBUTTON
, 1008, 1); /* press B3, and ensure A group didn't suffer */
414 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1005, 0), "A6 pressed\n");
415 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1000, 0), "A1 pressed\n");
416 ok(!SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1007, 0), "B2 not pressed\n");
417 ok(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 1008, 0), "B3 pressed\n");
419 /* tests with invalid index */
420 compare(SendMessageA(hToolbar
, TB_ISBUTTONCHECKED
, 0xdeadbeef, 0), -1L, "%ld");
421 compare(SendMessageA(hToolbar
, TB_ISBUTTONPRESSED
, 0xdeadbeef, 0), -1L, "%ld");
422 compare(SendMessageA(hToolbar
, TB_ISBUTTONENABLED
, 0xdeadbeef, 0), -1L, "%ld");
423 compare(SendMessageA(hToolbar
, TB_ISBUTTONINDETERMINATE
, 0xdeadbeef, 0), -1L, "%ld");
424 compare(SendMessageA(hToolbar
, TB_ISBUTTONHIGHLIGHTED
, 0xdeadbeef, 0), -1L, "%ld");
425 compare(SendMessageA(hToolbar
, TB_ISBUTTONHIDDEN
, 0xdeadbeef, 0), -1L, "%ld");
427 DestroyWindow(hToolbar
);
430 static void rebuild_toolbar(HWND
*hToolbar
)
433 DestroyWindow(*hToolbar
);
434 *hToolbar
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0,
435 hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
436 ok(*hToolbar
!= NULL
, "Toolbar creation problem\n");
437 ok(SendMessageA(*hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0) == 0, "TB_BUTTONSTRUCTSIZE failed\n");
438 ok(SendMessageA(*hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
439 ok(SendMessageA(*hToolbar
, WM_SETFONT
, (WPARAM
)GetStockObject(SYSTEM_FONT
), 0)==1, "WM_SETFONT\n");
442 static void rebuild_toolbar_with_buttons(HWND
*hToolbar
)
445 rebuild_toolbar(hToolbar
);
447 ZeroMemory(&buttons
, sizeof(buttons
));
448 buttons
[0].idCommand
= 1;
449 buttons
[0].fsStyle
= BTNS_BUTTON
;
450 buttons
[0].fsState
= TBSTATE_ENABLED
;
451 buttons
[0].iString
= -1;
452 buttons
[1].idCommand
= 3;
453 buttons
[1].fsStyle
= BTNS_BUTTON
;
454 buttons
[1].fsState
= TBSTATE_ENABLED
;
455 buttons
[1].iString
= -1;
456 buttons
[2].idCommand
= 5;
457 buttons
[2].fsStyle
= BTNS_SEP
;
458 buttons
[2].fsState
= TBSTATE_ENABLED
;
459 buttons
[2].iString
= -1;
460 buttons
[3].idCommand
= 7;
461 buttons
[3].fsStyle
= BTNS_BUTTON
;
462 buttons
[3].fsState
= TBSTATE_ENABLED
;
463 buttons
[3].iString
= -1;
464 buttons
[4].idCommand
= 9;
465 buttons
[4].fsStyle
= BTNS_BUTTON
;
466 buttons
[4].fsState
= 0; /* disabled */
467 buttons
[4].iString
= -1;
468 ok(SendMessageA(*hToolbar
, TB_ADDBUTTONSA
, 5, (LPARAM
)buttons
) == 1, "TB_ADDBUTTONSA failed\n");
469 ok(SendMessageA(*hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
472 static void add_128x15_bitmap(HWND hToolbar
, int nCmds
)
475 bmp128
.hInst
= GetModuleHandleA(NULL
);
476 bmp128
.nID
= IDB_BITMAP_128x15
;
477 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, nCmds
, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
480 #define CHECK_IMAGELIST(count, dx, dy) { \
482 HIMAGELIST himl = (HIMAGELIST)SendMessageA(hToolbar, TB_GETIMAGELIST, 0, 0); \
483 ok(himl != NULL, "No image list\n"); \
485 ok(ImageList_GetImageCount(himl) == count, "Images count mismatch - %d vs %d\n", count, ImageList_GetImageCount(himl)); \
486 ImageList_GetIconSize(himl, &cx, &cy); \
487 ok(cx == dx && cy == dy, "Icon size mismatch - %dx%d vs %dx%d\n", dx, dy, cx, cy); \
491 static void test_add_bitmap(void)
493 HWND hToolbar
= NULL
;
496 TBADDBITMAP stdsmall
;
501 /* empty 128x15 bitmap */
502 bmp128
.hInst
= GetModuleHandleA(NULL
);
503 bmp128
.nID
= IDB_BITMAP_128x15
;
505 /* empty 80x15 bitmap */
506 bmp80
.hInst
= GetModuleHandleA(NULL
);
507 bmp80
.nID
= IDB_BITMAP_80x15
;
509 /* standard bitmap - 240x15 pixels */
510 stdsmall
.hInst
= HINST_COMMCTRL
;
511 stdsmall
.nID
= IDB_STD_SMALL_COLOR
;
513 rebuild_toolbar(&hToolbar
);
514 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 8, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
515 CHECK_IMAGELIST(8, 16, 16);
517 /* adding more bitmaps */
518 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
) == 8, "TB_ADDBITMAP - unexpected return\n");
519 CHECK_IMAGELIST(13, 16, 16);
520 /* adding the same bitmap will simply return the index of the already loaded block */
521 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 8, (LPARAM
)&bmp128
);
522 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
523 CHECK_IMAGELIST(13, 16, 16);
524 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
);
525 ok(ret
== 8, "TB_ADDBITMAP - unexpected return %d\n", ret
);
526 CHECK_IMAGELIST(13, 16, 16);
527 /* even if we increase the wParam */
528 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 55, (LPARAM
)&bmp80
);
529 ok(ret
== 8, "TB_ADDBITMAP - unexpected return %d\n", ret
);
530 CHECK_IMAGELIST(13, 16, 16);
532 /* when the wParam is smaller than the bitmaps count but non-zero, all the bitmaps will be added*/
533 rebuild_toolbar(&hToolbar
);
534 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 3, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
535 CHECK_IMAGELIST(8, 16, 16);
536 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
);
537 ok(ret
== 3, "TB_ADDBITMAP - unexpected return %d\n", ret
);
538 /* the returned value is misleading - id 8 is the id of the first icon from bmp80 */
539 CHECK_IMAGELIST(13, 16, 16);
541 /* the same for negative wParam */
542 rebuild_toolbar(&hToolbar
);
543 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, -143, (LPARAM
)&bmp128
);
544 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
545 CHECK_IMAGELIST(8, 16, 16);
546 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp80
);
547 ok(ret
== -143, "TB_ADDBITMAP - unexpected return %d\n", ret
);
548 CHECK_IMAGELIST(13, 16, 16);
550 /* for zero only one bitmap will be added */
551 rebuild_toolbar(&hToolbar
);
552 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&bmp80
);
553 ok(ret
== 0, "TB_ADDBITMAP - unexpected return %d\n", ret
);
554 CHECK_IMAGELIST(1, 16, 16);
556 /* if wParam is larger than the amount of icons, the list is grown */
557 rebuild_toolbar(&hToolbar
);
558 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp80
) == 0, "TB_ADDBITMAP - unexpected return\n");
559 CHECK_IMAGELIST(100, 16, 16);
560 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp128
);
561 ok(ret
== 100, "TB_ADDBITMAP - unexpected return %d\n", ret
);
562 CHECK_IMAGELIST(200, 16, 16);
564 /* adding built-in items - the wParam is ignored */
565 rebuild_toolbar(&hToolbar
);
566 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp80
) == 0, "TB_ADDBITMAP - unexpected return\n");
567 CHECK_IMAGELIST(5, 16, 16);
568 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&stdsmall
) == 5, "TB_ADDBITMAP - unexpected return\n");
569 CHECK_IMAGELIST(20, 16, 16);
570 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp128
) == 20, "TB_ADDBITMAP - unexpected return\n");
571 CHECK_IMAGELIST(28, 16, 16);
573 /* when we increase the bitmap size, less icons will be created */
574 rebuild_toolbar(&hToolbar
);
575 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(20, 20)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
576 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
577 CHECK_IMAGELIST(6, 20, 20);
578 ret
= SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp80
);
579 ok(ret
== 1, "TB_ADDBITMAP - unexpected return %d\n", ret
);
580 CHECK_IMAGELIST(10, 20, 20);
581 /* the icons can be resized - an UpdateWindow is needed as this probably happens during WM_PAINT */
582 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
583 UpdateWindow(hToolbar
);
584 CHECK_IMAGELIST(26, 8, 8);
585 /* loading a standard bitmaps automatically resizes the icons */
586 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&stdsmall
) == 2, "TB_ADDBITMAP - unexpected return\n");
587 UpdateWindow(hToolbar
);
588 CHECK_IMAGELIST(28, 16, 16);
590 /* two more SETBITMAPSIZE tests */
591 rebuild_toolbar(&hToolbar
);
592 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
593 CHECK_IMAGELIST(100, 16, 16);
594 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 100, (LPARAM
)&bmp80
) == 100, "TB_ADDBITMAP - unexpected return\n");
595 CHECK_IMAGELIST(200, 16, 16);
596 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
597 UpdateWindow(hToolbar
);
598 CHECK_IMAGELIST(200, 8, 8);
599 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(30, 30)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
600 UpdateWindow(hToolbar
);
601 CHECK_IMAGELIST(200, 30, 30);
602 rebuild_toolbar(&hToolbar
);
603 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 5, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
604 CHECK_IMAGELIST(8, 16, 16);
605 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 3, (LPARAM
)&bmp80
) == 5, "TB_ADDBITMAP - unexpected return\n");
606 CHECK_IMAGELIST(13, 16, 16);
607 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(30, 30)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
608 UpdateWindow(hToolbar
);
609 CHECK_IMAGELIST(8, 30, 30);
610 /* when the width or height is zero, set it to 1 */
611 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(0, 0)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
612 UpdateWindow(hToolbar
);
613 CHECK_IMAGELIST(208, 1, 1);
614 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(0, 5)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
615 UpdateWindow(hToolbar
);
616 CHECK_IMAGELIST(208, 1, 5);
617 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(5, 0)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
618 UpdateWindow(hToolbar
);
619 CHECK_IMAGELIST(41, 5, 1);
621 /* the control can add bitmaps to an existing image list */
622 rebuild_toolbar(&hToolbar
);
623 himl
= ImageList_LoadImageA(GetModuleHandleA(NULL
), (LPCSTR
)MAKEINTRESOURCE(IDB_BITMAP_80x15
),
624 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
625 ok(himl
!= NULL
, "failed to create imagelist\n");
626 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
627 CHECK_IMAGELIST(4, 20, 15);
628 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&bmp128
) == 0, "TB_ADDBITMAP - unexpected return\n");
629 CHECK_IMAGELIST(10, 20, 15);
630 /* however TB_SETBITMAPSIZE/add std bitmap won't change the image size (the button size does change) */
631 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(8, 8)) == TRUE
, "TB_SETBITMAPSIZE failed\n");
632 UpdateWindow(hToolbar
);
633 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(15, 14), "%x");
634 CHECK_IMAGELIST(10, 20, 15);
635 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&stdsmall
) == 1, "TB_SETBITMAPSIZE failed\n");
636 UpdateWindow(hToolbar
);
637 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(23, 22), "%x");
638 CHECK_IMAGELIST(22, 20, 15);
640 /* check standard bitmaps */
641 addbmp
.hInst
= HINST_COMMCTRL
;
642 addbmp
.nID
= IDB_STD_SMALL_COLOR
;
643 rebuild_toolbar(&hToolbar
);
644 ImageList_Destroy(himl
);
646 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
647 CHECK_IMAGELIST(15, 16, 16);
648 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(23, 22), "%x");
649 addbmp
.nID
= IDB_STD_LARGE_COLOR
;
650 rebuild_toolbar(&hToolbar
);
651 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
652 CHECK_IMAGELIST(15, 24, 24);
653 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(31, 30), "%x");
655 addbmp
.nID
= IDB_VIEW_SMALL_COLOR
;
656 rebuild_toolbar(&hToolbar
);
657 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
658 CHECK_IMAGELIST(12, 16, 16);
659 addbmp
.nID
= IDB_VIEW_LARGE_COLOR
;
660 rebuild_toolbar(&hToolbar
);
661 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
662 CHECK_IMAGELIST(12, 24, 24);
664 addbmp
.nID
= IDB_HIST_SMALL_COLOR
;
665 rebuild_toolbar(&hToolbar
);
666 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
667 CHECK_IMAGELIST(5, 16, 16);
668 addbmp
.nID
= IDB_HIST_LARGE_COLOR
;
669 rebuild_toolbar(&hToolbar
);
670 ok(SendMessageA(hToolbar
, TB_ADDBITMAP
, 1, (LPARAM
)&addbmp
) == 0, "TB_ADDBITMAP - unexpected return\n");
671 CHECK_IMAGELIST(5, 24, 24);
674 DestroyWindow(hToolbar
);
677 #define CHECK_STRING_TABLE(count, tab) { \
680 for (_i = 0; _i < (count); _i++) {\
681 ret = SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(260, _i), (LPARAM)_buf); \
682 ok(ret >= 0, "TB_GETSTRINGA - unexpected return %d while checking string %d\n", ret, _i); \
684 ok(strcmp(_buf, (tab)[_i]) == 0, "Invalid string #%d - '%s' vs '%s'\n", _i, (tab)[_i], _buf); \
686 ok(SendMessageA(hToolbar, TB_GETSTRINGA, MAKEWPARAM(260, (count)), (LPARAM)_buf) == -1, \
687 "Too many strings in table\n"); \
690 static void test_add_string(void)
692 LPCSTR test1
= "a\0b\0";
693 LPCSTR test2
= "|a|b||\0";
694 LPCSTR ret1
[] = {"a", "b"};
695 LPCSTR ret2
[] = {"a", "b", "|a|b||"};
696 LPCSTR ret3
[] = {"a", "b", "|a|b||", "p", "q"};
697 LPCSTR ret4
[] = {"a", "b", "|a|b||", "p", "q", "p"};
698 LPCSTR ret5
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q"};
699 LPCSTR ret6
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q"};
700 LPCSTR ret7
[] = {"a", "b", "|a|b||", "p", "q", "p", "p", "q", "p", "", "q", "br", "c", "d"};
701 HWND hToolbar
= NULL
;
706 rebuild_toolbar(&hToolbar
);
707 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)test1
);
708 ok(ret
== 0, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
709 ret
= SendMessageA(hToolbar
, TB_GETSTRINGA
, MAKEWPARAM(260, 1), (LPARAM
)buf
);
712 win_skip("TB_GETSTRINGA needs 5.80\n");
715 CHECK_STRING_TABLE(2, ret1
);
716 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)test2
);
717 ok(ret
== 2, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
718 CHECK_STRING_TABLE(3, ret2
);
720 /* null instance handle */
721 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, IDS_TBADD1
);
722 ok(ret
== -1, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
724 /* invalid instance handle */
725 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0xdeadbeef, IDS_TBADD1
);
726 ok(ret
== -1, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
728 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD1
);
729 ok(ret
== 3, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
730 CHECK_STRING_TABLE(3, ret2
);
731 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD2
);
732 ok(ret
== 3, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
733 CHECK_STRING_TABLE(5, ret3
);
734 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD3
);
735 ok(ret
== 5, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
736 CHECK_STRING_TABLE(6, ret4
);
737 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD4
);
738 ok(ret
== 6, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
739 CHECK_STRING_TABLE(8, ret5
);
740 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD5
);
741 ok(ret
== 8, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
742 CHECK_STRING_TABLE(11, ret6
);
743 ret
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, (WPARAM
)GetModuleHandleA(NULL
), IDS_TBADD7
);
744 ok(ret
== 11, "TB_ADDSTRINGA - unexpected return %d\n", ret
);
745 CHECK_STRING_TABLE(14, ret7
);
747 ZeroMemory(&button
, sizeof(button
));
748 button
.iString
= (UINT_PTR
)"Test";
749 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, 0, (LPARAM
)&button
);
750 CHECK_STRING_TABLE(14, ret7
);
751 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&button
);
752 CHECK_STRING_TABLE(14, ret7
);
754 DestroyWindow(hToolbar
);
757 static void expect_hot_notify(int idold
, int idnew
)
759 g_fExpectedHotItemOld
= idold
;
760 g_fExpectedHotItemNew
= idnew
;
761 g_fReceivedHotItemChange
= FALSE
;
764 #define check_hot_notify() \
765 ok(g_fReceivedHotItemChange, "TBN_HOTITEMCHANGE not received\n"); \
766 g_fExpectedHotItemOld = g_fExpectedHotItemNew = 0;
768 static void test_hotitem(void)
770 HWND hToolbar
= NULL
;
771 TBBUTTONINFOA tbinfo
;
774 g_fBlockHotItemChange
= FALSE
;
776 rebuild_toolbar_with_buttons(&hToolbar
);
777 /* set TBSTYLE_FLAT. comctl5 allows hot items only for such toolbars.
778 * comctl6 doesn't have this requirement even when theme == NULL */
779 SetWindowLongA(hToolbar
, GWL_STYLE
, TBSTYLE_FLAT
| GetWindowLongA(hToolbar
, GWL_STYLE
));
780 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
781 ok(ret
== -1, "Hot item: %ld, expected -1\n", ret
);
782 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 1, 0);
783 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
784 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
785 ok(ret
== 1, "Hot item: %ld, expected 1\n", ret
);
786 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 2, 0);
787 ok(ret
== 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret
);
789 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 0xbeef, 0);
790 ok(ret
== 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
791 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
792 ok(ret
== 2, "Hot item: %lx, expected 2\n", ret
);
793 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, -0xbeef, 0);
794 ok(ret
== 2, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
795 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
796 ok(ret
== -1, "Hot item: %lx, expected -1\n", ret
);
798 expect_hot_notify(0, 7);
799 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 3, 0);
800 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
802 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
803 ok(ret
== 3, "Hot item: %lx, expected 3\n", ret
);
804 g_fBlockHotItemChange
= TRUE
;
805 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 2, 0);
806 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 2\n", ret
);
807 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
808 ok(ret
== 3, "Hot item: %lx, expected 3\n", ret
);
809 g_fBlockHotItemChange
= FALSE
;
811 g_fReceivedHotItemChange
= FALSE
;
812 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 0xbeaf, 0);
813 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
814 ok(g_fReceivedHotItemChange
== FALSE
, "TBN_HOTITEMCHANGE received for invalid parameter\n");
816 g_fReceivedHotItemChange
= FALSE
;
817 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 3, 0);
818 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
819 ok(g_fReceivedHotItemChange
== FALSE
, "TBN_HOTITEMCHANGE received after a duplication\n");
821 expect_hot_notify(7, 0);
822 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, -0xbeaf, 0);
823 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
825 SendMessageA(hToolbar
, TB_SETHOTITEM
, 3, 0);
827 /* setting disabled buttons will generate a notify with the button id but no button will be hot */
828 expect_hot_notify(7, 9);
829 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 4, 0);
830 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
832 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
833 ok(ret
== -1, "Hot item: %lx, expected -1\n", ret
);
834 /* enabling the button won't change that */
835 SendMessageA(hToolbar
, TB_ENABLEBUTTON
, 9, TRUE
);
836 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
837 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
839 /* disabling a hot button works */
840 ret
= SendMessageA(hToolbar
, TB_SETHOTITEM
, 3, 0);
841 ok(ret
== -1, "TB_SETHOTITEM returned %ld, expected -1\n", ret
);
842 g_fReceivedHotItemChange
= FALSE
;
843 SendMessageA(hToolbar
, TB_ENABLEBUTTON
, 7, FALSE
);
844 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
845 ok(ret
== 3, "TB_SETHOTITEM returned %ld, expected 3\n", ret
);
846 ok(g_fReceivedHotItemChange
== FALSE
, "Unexpected TBN_HOTITEMCHANGE\n");
848 SendMessageA(hToolbar
, TB_SETHOTITEM
, 1, 0);
849 tbinfo
.cbSize
= sizeof(TBBUTTONINFOA
);
850 tbinfo
.dwMask
= TBIF_STATE
;
851 tbinfo
.fsState
= 0; /* disabled */
852 g_fReceivedHotItemChange
= FALSE
;
853 ok(SendMessageA(hToolbar
, TB_SETBUTTONINFOA
, 1, (LPARAM
)&tbinfo
) == TRUE
, "TB_SETBUTTONINFOA failed\n");
854 ret
= SendMessageA(hToolbar
, TB_GETHOTITEM
, 0, 0);
855 ok(ret
== 1, "TB_SETHOTITEM returned %ld, expected 1\n", ret
);
856 ok(g_fReceivedHotItemChange
== FALSE
, "Unexpected TBN_HOTITEMCHANGE\n");
858 DestroyWindow(hToolbar
);
861 #if 0 /* use this to generate more tests*/
863 static void dump_sizes(HWND hToolbar
)
867 int count
= SendMessageA(hToolbar
, TB_BUTTONCOUNT
, 0, 0);
870 GetClientRect(hToolbar
, &r
);
871 SendMessageA(hToolbar
, TB_GETMAXSIZE
, 0, &sz
);
872 printf(" { {%d, %d, %d, %d}, {%d, %d}, %d, {", r
.left
, r
.top
, r
.right
, r
.bottom
,
873 sz
.cx
, sz
.cy
, count
);
874 for (i
=0; i
<count
; i
++)
876 SendMessageA(hToolbar
, TB_GETITEMRECT
, i
, &r
);
877 printf("%s{%3d, %3d, %3d, %3d}, ", (i
%3==0 ? "\n " : ""), r
.left
, r
.top
, r
.right
, r
.bottom
);
879 printf("\n }, },\n");
882 #define check_sizes() dump_sizes(hToolbar);
883 #define check_sizes_todo(todomask) dump_sizes(hToolbar);
887 static int system_font_height(void) {
891 hDC
= CreateCompatibleDC(NULL
);
892 GetTextMetricsA(hDC
, &tm
);
898 static int string_width(const CHAR
*s
) {
902 hdc
= CreateCompatibleDC(NULL
);
903 GetTextExtentPoint32A(hdc
, s
, strlen(s
), &sz
);
917 static tbsize_result_t
init_tbsize_result(int nButtonsAlloc
, int cleft
, int ctop
, int cright
, int cbottom
, int minx
, int miny
) {
920 SetRect(&ret
.rcClient
, cleft
, ctop
, cright
, cbottom
);
924 ret
.prcButtons
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nButtonsAlloc
*sizeof(RECT
));
929 static void tbsize_addbutton(tbsize_result_t
*tbsr
, int left
, int top
, int right
, int bottom
) {
930 SetRect(&tbsr
->prcButtons
[tbsr
->nButtons
], left
, top
, right
, bottom
);
935 #define STRING1 "MMMMMMMMMMMMM"
936 #define STRING2 "Tst"
938 static tbsize_result_t
*tbsize_results
;
940 #define tbsize_results_num 28
942 static void init_tbsize_results(void) {
943 int fontheight
= system_font_height();
946 tbsize_results
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, tbsize_results_num
*sizeof(tbsize_result_t
));
948 tbsize_results
[0] = init_tbsize_result(5, 0, 0 ,672 ,26, 100 ,22);
949 tbsize_addbutton(&tbsize_results
[0], 0, 2, 23, 24);
950 tbsize_addbutton(&tbsize_results
[0], 23, 2, 46, 24);
951 tbsize_addbutton(&tbsize_results
[0], 46, 2, 54, 24);
952 tbsize_addbutton(&tbsize_results
[0], 54, 2, 77, 24);
953 tbsize_addbutton(&tbsize_results
[0], 77, 2, 100, 24);
955 tbsize_results
[1] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
956 tbsize_addbutton(&tbsize_results
[1], 0, 2, 23, 24);
957 tbsize_addbutton(&tbsize_results
[1], 23, 2, 46, 24);
958 tbsize_addbutton(&tbsize_results
[1], 46, 2, 54, 24);
959 tbsize_addbutton(&tbsize_results
[1], 54, 2, 77, 24);
960 tbsize_addbutton(&tbsize_results
[1], 77, 2, 100, 24);
961 tbsize_addbutton(&tbsize_results
[1], 100, 2, 123, 24);
962 tbsize_addbutton(&tbsize_results
[1], 0, 24, 23, 46);
964 tbsize_results
[2] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
965 tbsize_addbutton(&tbsize_results
[2], 0, 2, 23, 24);
966 tbsize_addbutton(&tbsize_results
[2], 23, 2, 46, 24);
967 tbsize_addbutton(&tbsize_results
[2], 46, 2, 54, 24);
968 tbsize_addbutton(&tbsize_results
[2], 54, 2, 77, 24);
969 tbsize_addbutton(&tbsize_results
[2], 77, 2, 100, 24);
970 tbsize_addbutton(&tbsize_results
[2], 100, 2, 123, 24);
971 tbsize_addbutton(&tbsize_results
[2], 0, 24, 23, 46);
973 tbsize_results
[3] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
974 tbsize_addbutton(&tbsize_results
[3], 0, 2, 23, 24);
975 tbsize_addbutton(&tbsize_results
[3], 23, 2, 46, 24);
976 tbsize_addbutton(&tbsize_results
[3], 46, 2, 54, 24);
977 tbsize_addbutton(&tbsize_results
[3], 54, 2, 77, 24);
978 tbsize_addbutton(&tbsize_results
[3], 77, 2, 100, 24);
979 tbsize_addbutton(&tbsize_results
[3], 100, 2, 123, 24);
980 tbsize_addbutton(&tbsize_results
[3], 123, 2, 146, 24);
982 tbsize_results
[4] = init_tbsize_result(9, 0, 0, 672, 26, 192, 22);
983 tbsize_addbutton(&tbsize_results
[4], 0, 2, 23, 24);
984 tbsize_addbutton(&tbsize_results
[4], 23, 2, 46, 24);
985 tbsize_addbutton(&tbsize_results
[4], 46, 2, 54, 24);
986 tbsize_addbutton(&tbsize_results
[4], 54, 2, 77, 24);
987 tbsize_addbutton(&tbsize_results
[4], 77, 2, 100, 24);
988 tbsize_addbutton(&tbsize_results
[4], 100, 2, 123, 24);
989 tbsize_addbutton(&tbsize_results
[4], 123, 2, 146, 24);
990 tbsize_addbutton(&tbsize_results
[4], 146, 2, 169, 24);
991 tbsize_addbutton(&tbsize_results
[4], 169, 2, 192, 24);
993 tbsize_results
[5] = init_tbsize_result(39, 0, 0, 672, 92, 882, 22);
994 tbsize_addbutton(&tbsize_results
[5], 0, 2, 23, 24);
995 tbsize_addbutton(&tbsize_results
[5], 23, 2, 46, 24);
996 tbsize_addbutton(&tbsize_results
[5], 0, 2, 8, 29);
997 tbsize_addbutton(&tbsize_results
[5], 0, 29, 23, 51);
998 tbsize_addbutton(&tbsize_results
[5], 23, 29, 46, 51);
999 tbsize_addbutton(&tbsize_results
[5], 46, 29, 69, 51);
1000 tbsize_addbutton(&tbsize_results
[5], 69, 29, 92, 51);
1001 tbsize_addbutton(&tbsize_results
[5], 92, 29, 115, 51);
1002 tbsize_addbutton(&tbsize_results
[5], 115, 29, 138, 51);
1003 tbsize_addbutton(&tbsize_results
[5], 138, 29, 161, 51);
1004 tbsize_addbutton(&tbsize_results
[5], 161, 29, 184, 51);
1005 tbsize_addbutton(&tbsize_results
[5], 184, 29, 207, 51);
1006 tbsize_addbutton(&tbsize_results
[5], 207, 29, 230, 51);
1007 tbsize_addbutton(&tbsize_results
[5], 230, 29, 253, 51);
1008 tbsize_addbutton(&tbsize_results
[5], 253, 29, 276, 51);
1009 tbsize_addbutton(&tbsize_results
[5], 276, 29, 299, 51);
1010 tbsize_addbutton(&tbsize_results
[5], 299, 29, 322, 51);
1011 tbsize_addbutton(&tbsize_results
[5], 322, 29, 345, 51);
1012 tbsize_addbutton(&tbsize_results
[5], 345, 29, 368, 51);
1013 tbsize_addbutton(&tbsize_results
[5], 368, 29, 391, 51);
1014 tbsize_addbutton(&tbsize_results
[5], 391, 29, 414, 51);
1015 tbsize_addbutton(&tbsize_results
[5], 414, 29, 437, 51);
1016 tbsize_addbutton(&tbsize_results
[5], 437, 29, 460, 51);
1017 tbsize_addbutton(&tbsize_results
[5], 460, 29, 483, 51);
1018 tbsize_addbutton(&tbsize_results
[5], 483, 29, 506, 51);
1019 tbsize_addbutton(&tbsize_results
[5], 506, 29, 529, 51);
1020 tbsize_addbutton(&tbsize_results
[5], 529, 29, 552, 51);
1021 tbsize_addbutton(&tbsize_results
[5], 552, 29, 575, 51);
1022 tbsize_addbutton(&tbsize_results
[5], 575, 29, 598, 51);
1023 tbsize_addbutton(&tbsize_results
[5], 598, 29, 621, 51);
1024 tbsize_addbutton(&tbsize_results
[5], 621, 29, 644, 51);
1025 tbsize_addbutton(&tbsize_results
[5], 644, 29, 667, 51);
1026 tbsize_addbutton(&tbsize_results
[5], 0, 51, 23, 73);
1027 tbsize_addbutton(&tbsize_results
[5], 23, 51, 46, 73);
1028 tbsize_addbutton(&tbsize_results
[5], 46, 51, 69, 73);
1029 tbsize_addbutton(&tbsize_results
[5], 69, 51, 92, 73);
1030 tbsize_addbutton(&tbsize_results
[5], 92, 51, 115, 73);
1031 tbsize_addbutton(&tbsize_results
[5], 115, 51, 138, 73);
1032 tbsize_addbutton(&tbsize_results
[5], 138, 51, 161, 73);
1034 tbsize_results
[6] = init_tbsize_result(7, 0, 0, 48, 226, 23, 140);
1035 tbsize_addbutton(&tbsize_results
[6], 0, 2, 23, 24);
1036 tbsize_addbutton(&tbsize_results
[6], 23, 2, 46, 24);
1037 tbsize_addbutton(&tbsize_results
[6], 46, 2, 94, 24);
1038 tbsize_addbutton(&tbsize_results
[6], 94, 2, 117, 24);
1039 tbsize_addbutton(&tbsize_results
[6], 117, 2, 140, 24);
1040 tbsize_addbutton(&tbsize_results
[6], 140, 2, 163, 24);
1041 tbsize_addbutton(&tbsize_results
[6], 0, 24, 23, 46);
1043 tbsize_results
[7] = init_tbsize_result(7, 0, 0, 92, 226, 23, 140);
1044 tbsize_addbutton(&tbsize_results
[7], 0, 2, 23, 24);
1045 tbsize_addbutton(&tbsize_results
[7], 23, 2, 46, 24);
1046 tbsize_addbutton(&tbsize_results
[7], 0, 24, 92, 32);
1047 tbsize_addbutton(&tbsize_results
[7], 0, 32, 23, 54);
1048 tbsize_addbutton(&tbsize_results
[7], 23, 32, 46, 54);
1049 tbsize_addbutton(&tbsize_results
[7], 46, 32, 69, 54);
1050 tbsize_addbutton(&tbsize_results
[7], 69, 32, 92, 54);
1052 tbsize_results
[8] = init_tbsize_result(7, 0, 0, 672, 26, 194, 30);
1053 tbsize_addbutton(&tbsize_results
[8], 0, 2, 31, 32);
1054 tbsize_addbutton(&tbsize_results
[8], 31, 2, 62, 32);
1055 tbsize_addbutton(&tbsize_results
[8], 62, 2, 70, 32);
1056 tbsize_addbutton(&tbsize_results
[8], 70, 2, 101, 32);
1057 tbsize_addbutton(&tbsize_results
[8], 101, 2, 132, 32);
1058 tbsize_addbutton(&tbsize_results
[8], 132, 2, 163, 32);
1059 tbsize_addbutton(&tbsize_results
[8], 0, 32, 31, 62);
1061 tbsize_results
[9] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
1062 tbsize_addbutton(&tbsize_results
[9], 0, 2, 31, 32);
1063 tbsize_addbutton(&tbsize_results
[9], 31, 2, 62, 32);
1064 tbsize_addbutton(&tbsize_results
[9], 62, 2, 70, 32);
1065 tbsize_addbutton(&tbsize_results
[9], 70, 2, 101, 32);
1066 tbsize_addbutton(&tbsize_results
[9], 101, 2, 132, 32);
1067 tbsize_addbutton(&tbsize_results
[9], 132, 2, 163, 32);
1068 tbsize_addbutton(&tbsize_results
[9], 0, 32, 31, 62);
1070 tbsize_results
[10] = init_tbsize_result(7, 0, 0, 672, 64, 194, 30);
1071 tbsize_addbutton(&tbsize_results
[10], 0, 0, 31, 30);
1072 tbsize_addbutton(&tbsize_results
[10], 31, 0, 62, 30);
1073 tbsize_addbutton(&tbsize_results
[10], 62, 0, 70, 30);
1074 tbsize_addbutton(&tbsize_results
[10], 70, 0, 101, 30);
1075 tbsize_addbutton(&tbsize_results
[10], 101, 0, 132, 30);
1076 tbsize_addbutton(&tbsize_results
[10], 132, 0, 163, 30);
1077 tbsize_addbutton(&tbsize_results
[10], 0, 30, 31, 60);
1079 tbsize_results
[11] = init_tbsize_result(7, 0, 0, 124, 226, 31, 188);
1080 tbsize_addbutton(&tbsize_results
[11], 0, 0, 31, 30);
1081 tbsize_addbutton(&tbsize_results
[11], 31, 0, 62, 30);
1082 tbsize_addbutton(&tbsize_results
[11], 0, 30, 124, 38);
1083 tbsize_addbutton(&tbsize_results
[11], 0, 38, 31, 68);
1084 tbsize_addbutton(&tbsize_results
[11], 31, 38, 62, 68);
1085 tbsize_addbutton(&tbsize_results
[11], 62, 38, 93, 68);
1086 tbsize_addbutton(&tbsize_results
[11], 93, 38, 124, 68);
1088 tbsize_results
[12] = init_tbsize_result(7, 0, 0, 672, 26, 146, 22);
1089 tbsize_addbutton(&tbsize_results
[12], 0, 2, 23, 24);
1090 tbsize_addbutton(&tbsize_results
[12], 23, 2, 46, 24);
1091 tbsize_addbutton(&tbsize_results
[12], 46, 2, 54, 24);
1092 tbsize_addbutton(&tbsize_results
[12], 54, 2, 77, 24);
1093 tbsize_addbutton(&tbsize_results
[12], 77, 2, 100, 24);
1094 tbsize_addbutton(&tbsize_results
[12], 100, 2, 123, 24);
1095 tbsize_addbutton(&tbsize_results
[12], 123, 2, 146, 24);
1097 tbsize_results
[13] = init_tbsize_result(7, 0, 0, 672, 26, 146, 100);
1098 tbsize_addbutton(&tbsize_results
[13], 0, 0, 23, 100);
1099 tbsize_addbutton(&tbsize_results
[13], 23, 0, 46, 100);
1100 tbsize_addbutton(&tbsize_results
[13], 46, 0, 54, 100);
1101 tbsize_addbutton(&tbsize_results
[13], 54, 0, 77, 100);
1102 tbsize_addbutton(&tbsize_results
[13], 77, 0, 100, 100);
1103 tbsize_addbutton(&tbsize_results
[13], 100, 0, 123, 100);
1104 tbsize_addbutton(&tbsize_results
[13], 123, 0, 146, 100);
1106 tbsize_results
[14] = init_tbsize_result(10, 0, 0, 672, 26, 146, 100);
1107 tbsize_addbutton(&tbsize_results
[14], 0, 0, 23, 100);
1108 tbsize_addbutton(&tbsize_results
[14], 23, 0, 46, 100);
1109 tbsize_addbutton(&tbsize_results
[14], 46, 0, 54, 100);
1110 tbsize_addbutton(&tbsize_results
[14], 54, 0, 77, 100);
1111 tbsize_addbutton(&tbsize_results
[14], 77, 0, 100, 100);
1112 tbsize_addbutton(&tbsize_results
[14], 100, 0, 123, 100);
1113 tbsize_addbutton(&tbsize_results
[14], 123, 0, 146, 100);
1114 tbsize_addbutton(&tbsize_results
[14], 146, 0, 169, 100);
1115 tbsize_addbutton(&tbsize_results
[14], 169, 0, 192, 100);
1116 tbsize_addbutton(&tbsize_results
[14], 192, 0, 215, 100);
1118 tbsize_results
[15] = init_tbsize_result(11, 0, 0, 672, 26, 238, 39);
1119 tbsize_addbutton(&tbsize_results
[15], 0, 0, 23, 23 + fontheight
);
1120 tbsize_addbutton(&tbsize_results
[15], 23, 0, 46, 23 + fontheight
);
1121 tbsize_addbutton(&tbsize_results
[15], 46, 0, 54, 23 + fontheight
);
1122 tbsize_addbutton(&tbsize_results
[15], 54, 0, 77, 23 + fontheight
);
1123 tbsize_addbutton(&tbsize_results
[15], 77, 0, 100, 23 + fontheight
);
1124 tbsize_addbutton(&tbsize_results
[15], 100, 0, 123, 23 + fontheight
);
1125 tbsize_addbutton(&tbsize_results
[15], 123, 0, 146, 23 + fontheight
);
1126 tbsize_addbutton(&tbsize_results
[15], 146, 0, 169, 23 + fontheight
);
1127 tbsize_addbutton(&tbsize_results
[15], 169, 0, 192, 23 + fontheight
);
1128 tbsize_addbutton(&tbsize_results
[15], 192, 0, 215, 23 + fontheight
);
1129 tbsize_addbutton(&tbsize_results
[15], 215, 0, 238, 23 + fontheight
);
1131 tbsize_results
[16] = init_tbsize_result(11, 0, 0, 672, 26, 239, 22);
1132 tbsize_addbutton(&tbsize_results
[16], 0, 0, 23, 22);
1133 tbsize_addbutton(&tbsize_results
[16], 23, 0, 46, 22);
1134 tbsize_addbutton(&tbsize_results
[16], 46, 0, 54, 22);
1135 tbsize_addbutton(&tbsize_results
[16], 54, 0, 77, 22);
1136 tbsize_addbutton(&tbsize_results
[16], 77, 0, 100, 22);
1137 tbsize_addbutton(&tbsize_results
[16], 100, 0, 123, 22);
1138 tbsize_addbutton(&tbsize_results
[16], 123, 0, 146, 22);
1139 tbsize_addbutton(&tbsize_results
[16], 146, 0, 169, 22);
1140 tbsize_addbutton(&tbsize_results
[16], 169, 0, 192, 22);
1141 tbsize_addbutton(&tbsize_results
[16], 192, 0, 215, 22);
1142 tbsize_addbutton(&tbsize_results
[16], 215, 0, 238, 22);
1144 buttonwidth
= 7 + string_width(STRING1
);
1146 tbsize_results
[17] = init_tbsize_result(3, 0, 0, 672, 26, 489, 39);
1147 tbsize_addbutton(&tbsize_results
[17], 0, 2, buttonwidth
, 25 + fontheight
);
1148 tbsize_addbutton(&tbsize_results
[17], buttonwidth
, 2, 2*buttonwidth
+ 4, 25 + fontheight
);
1149 tbsize_addbutton(&tbsize_results
[17], 2*buttonwidth
+ 4, 2, 3*buttonwidth
+ 4, 25 + fontheight
);
1151 tbsize_results
[18] = init_tbsize_result(6, 0, 0, 672, 104, 978, 24);
1152 tbsize_addbutton(&tbsize_results
[18], 0, 2, buttonwidth
, 10 + fontheight
);
1153 tbsize_addbutton(&tbsize_results
[18], buttonwidth
, 2, 2*buttonwidth
, 10 + fontheight
);
1154 tbsize_addbutton(&tbsize_results
[18], 2*buttonwidth
, 2, 3*buttonwidth
, 10 + fontheight
);
1155 tbsize_addbutton(&tbsize_results
[18], 3*buttonwidth
, 2, 4*buttonwidth
, 10 + fontheight
);
1156 tbsize_addbutton(&tbsize_results
[18], 4*buttonwidth
, 2, 5*buttonwidth
+ 4, 10 + fontheight
);
1157 tbsize_addbutton(&tbsize_results
[18], 5*buttonwidth
+ 4, 2, 5*buttonwidth
+ 4 + string_width(STRING2
) + 11, 10 + fontheight
);
1159 tbsize_results
[19] = init_tbsize_result(6, 0, 0, 672, 28, 978, 38);
1160 tbsize_addbutton(&tbsize_results
[19], 0, 0, buttonwidth
, 22 + fontheight
);
1161 tbsize_addbutton(&tbsize_results
[19], buttonwidth
, 0, 2*buttonwidth
, 22 + fontheight
);
1162 tbsize_addbutton(&tbsize_results
[19], 2*buttonwidth
, 0, 3*buttonwidth
, 22 + fontheight
);
1163 tbsize_addbutton(&tbsize_results
[19], 3*buttonwidth
, 0, 4*buttonwidth
, 22 + fontheight
);
1164 tbsize_addbutton(&tbsize_results
[19], 4*buttonwidth
, 0, 5*buttonwidth
+ 4, 22 + fontheight
);
1165 tbsize_addbutton(&tbsize_results
[19], 5*buttonwidth
+ 4, 0, 5*buttonwidth
+ 4 + string_width(STRING2
) + 11, 22 + fontheight
);
1167 tbsize_results
[20] = init_tbsize_result(3, 0, 0, 672, 100, 239, 102);
1168 tbsize_addbutton(&tbsize_results
[20], 0, 2, 100, 102);
1169 tbsize_addbutton(&tbsize_results
[20], 100, 2, 139, 102);
1170 tbsize_addbutton(&tbsize_results
[20], 139, 2, 239, 102);
1172 tbsize_results
[21] = init_tbsize_result(3, 0, 0, 672, 42, 185, 40);
1173 tbsize_addbutton(&tbsize_results
[21], 0, 2, 75, 40);
1174 tbsize_addbutton(&tbsize_results
[21], 75, 2, 118, 40);
1175 tbsize_addbutton(&tbsize_results
[21], 118, 2, 165 + string_width(STRING2
), 40);
1177 tbsize_results
[22] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1178 tbsize_addbutton(&tbsize_results
[22], 0, 2, 47 + string_width(STRING2
), 40);
1180 tbsize_results
[23] = init_tbsize_result(2, 0, 0, 672, 42, 67, 41);
1181 tbsize_addbutton(&tbsize_results
[23], 0, 2, 672, 25 + fontheight
);
1182 tbsize_addbutton(&tbsize_results
[23], 0, 25 + fontheight
, 672, 48 + 2*fontheight
);
1184 tbsize_results
[24] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1185 tbsize_addbutton(&tbsize_results
[24], 0, 2, 11 + string_width(STRING2
), 24);
1187 tbsize_results
[25] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1188 tbsize_addbutton(&tbsize_results
[25], 0, 2, 40, 24);
1190 tbsize_results
[26] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1191 tbsize_addbutton(&tbsize_results
[26], 0, 2, 40, 24);
1193 tbsize_results
[27] = init_tbsize_result(1, 0, 0, 672, 42, 67, 40);
1194 tbsize_addbutton(&tbsize_results
[27], 0, 2, 40, 24);
1197 static void free_tbsize_results(void) {
1200 for (i
= 0; i
< tbsize_results_num
; i
++)
1201 HeapFree(GetProcessHeap(), 0, tbsize_results
[i
].prcButtons
);
1202 HeapFree(GetProcessHeap(), 0, tbsize_results
);
1203 tbsize_results
= NULL
;
1206 static int tbsize_numtests
= 0;
1213 } tbsize_alt_result_t
;
1215 static tbsize_alt_result_t tbsize_alt_results
[] =
1217 { 5, 2, { 0, 24, 8, 29 } },
1218 { 20, 1, { 100, 2, 107, 102 } },
1219 { 20, 2, { 107, 2, 207, 102 } }
1222 static DWORD tbsize_alt_numtests
= 0;
1224 #define check_sizes_todo(todomask) { \
1226 int buttonCount, i, mask=(todomask); \
1227 tbsize_result_t *res = &tbsize_results[tbsize_numtests]; \
1228 GetClientRect(hToolbar, &rc); \
1229 /*check_rect("client", rc, res->rcClient);*/ \
1230 buttonCount = SendMessageA(hToolbar, TB_BUTTONCOUNT, 0, 0); \
1231 compare(buttonCount, res->nButtons, "%d"); \
1232 for (i=0; i<min(buttonCount, res->nButtons); i++) { \
1233 ok(SendMessageA(hToolbar, TB_GETITEMRECT, i, (LPARAM)&rc) == 1, "TB_GETITEMRECT\n"); \
1234 if (broken(tbsize_alt_numtests < sizeof(tbsize_alt_results)/sizeof(tbsize_alt_results[0]) && \
1235 memcmp(&rc, &tbsize_alt_results[tbsize_alt_numtests].rcButton, sizeof(RECT)) == 0)) { \
1236 win_skip("Alternate rect found\n"); \
1237 tbsize_alt_numtests++; \
1238 } else if (!(mask&1)) { \
1239 check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); \
1241 todo_wine { check_rect("button = %d, tbsize_numtests = %d", rc, res->prcButtons[i], i, tbsize_numtests); } \
1245 tbsize_numtests++; \
1248 #define check_sizes() check_sizes_todo(0)
1252 static TBBUTTON buttons1
[] = {
1253 {0, 10, TBSTATE_WRAP
|TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1254 {0, 11, 0, 0, {0, }, 0, -1},
1256 static TBBUTTON buttons2
[] = {
1257 {0, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1258 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1260 static TBBUTTON buttons3
[] = {
1261 {0, 30, TBSTATE_ENABLED
, 0, {0, }, 0, 0},
1262 {0, 31, TBSTATE_ENABLED
, 0, {0, }, 0, 1},
1263 {0, 32, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, 1},
1264 {0, 33, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, (UINT_PTR
)STRING2
}
1266 static TBBUTTON buttons4
[] = {
1267 {0, 40, TBSTATE_ENABLED
, BTNS_AUTOSIZE
, {0, }, 0, (UINT_PTR
)STRING2
},
1268 {0, 41, TBSTATE_ENABLED
, 0, {0, }, 0, (UINT_PTR
)STRING2
},
1269 {0, 41, TBSTATE_ENABLED
, BTNS_SHOWTEXT
, {0, }, 0, (UINT_PTR
)STRING2
}
1272 static void test_sizes(void)
1274 HWND hToolbar
= NULL
;
1275 HIMAGELIST himl
, himl2
;
1276 TBBUTTONINFOA tbinfo
;
1280 int fontheight
= system_font_height();
1282 init_tbsize_results();
1284 rebuild_toolbar_with_buttons(&hToolbar
);
1285 style
= GetWindowLongA(hToolbar
, GWL_STYLE
);
1286 ok(style
== (WS_CHILD
|WS_VISIBLE
|CCS_TOP
), "Invalid style %x\n", style
);
1288 /* the TBSTATE_WRAP makes a second row */
1289 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons1
);
1291 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1293 SendMessageA(hToolbar
, TB_GETBUTTON
, 5, (LPARAM
)&button
);
1294 ok(button
.fsState
== (TBSTATE_WRAP
|TBSTATE_ENABLED
), "got %08x\n", button
.fsState
);
1295 /* after setting the TBSTYLE_WRAPABLE the TBSTATE_WRAP is ignored */
1296 SetWindowLongA(hToolbar
, GWL_STYLE
, style
|TBSTYLE_WRAPABLE
);
1298 SendMessageA(hToolbar
, TB_GETBUTTON
, 5, (LPARAM
)&button
);
1299 ok(button
.fsState
== TBSTATE_ENABLED
, "got %08x\n", button
.fsState
);
1300 /* adding new buttons with TBSTYLE_WRAPABLE doesn't add a new row */
1301 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons1
);
1303 /* only after adding enough buttons the bar will be wrapped on a
1304 * separator and then on the first button */
1305 for (i
=0; i
<15; i
++)
1306 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons1
);
1307 check_sizes_todo(0x4);
1308 SendMessageA(hToolbar
, TB_GETBUTTON
, 31, (LPARAM
)&button
);
1309 ok(button
.fsState
== (TBSTATE_WRAP
|TBSTATE_ENABLED
), "got %08x\n", button
.fsState
);
1310 SetWindowLongA(hToolbar
, GWL_STYLE
, style
);
1311 SendMessageA(hToolbar
, TB_GETBUTTON
, 31, (LPARAM
)&button
);
1312 ok(button
.fsState
== TBSTATE_ENABLED
, "got %08x\n", button
.fsState
);
1314 rebuild_toolbar_with_buttons(&hToolbar
);
1315 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons1
);
1316 /* setting the buttons vertical will only change the window client size */
1317 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| CCS_VERT
);
1318 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1319 check_sizes_todo(0x3c);
1320 /* with a TBSTYLE_WRAPABLE a wrapping will occur on the separator */
1321 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| TBSTYLE_WRAPABLE
| CCS_VERT
);
1322 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1323 check_sizes_todo(0x7c);
1325 rebuild_toolbar_with_buttons(&hToolbar
);
1326 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons1
);
1327 /* a TB_SETBITMAPSIZE changes button sizes*/
1328 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(24, 24));
1331 /* setting a TBSTYLE_FLAT doesn't change anything - even after a TB_AUTOSIZE */
1332 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
);
1333 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1335 /* but after a TB_SETBITMAPSIZE the top margins is changed */
1336 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(20, 20));
1337 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(24, 24));
1339 /* some vertical toolbar sizes */
1340 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
| TBSTYLE_WRAPABLE
| CCS_VERT
);
1341 check_sizes_todo(0x7c);
1343 rebuild_toolbar_with_buttons(&hToolbar
);
1344 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| TBSTYLE_FLAT
);
1345 /* newly added buttons will be use the previous margin */
1346 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons2
);
1348 /* TB_SETBUTTONSIZE can't be used to reduce the size of a button below the default */
1349 check_button_size(hToolbar
, 23, 22);
1350 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(22, 21))==1, "TB_SETBUTTONSIZE\n");
1351 check_button_size(hToolbar
, 23, 22);
1352 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1353 check_button_size(hToolbar
, 23, 100);
1354 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3))==1, "TB_SETBUTTONSIZE\n");
1355 check_button_size(hToolbar
, 23, 22);
1356 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(5, 100))==1, "TB_SETBUTTONSIZE\n");
1357 check_button_size(hToolbar
, 23, 100);
1359 /* add some buttons with non-default sizes */
1360 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons2
);
1361 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, -1, (LPARAM
)&buttons2
[0]);
1363 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[0]);
1364 /* TB_ADDSTRINGA resets the size */
1365 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
) STRING0
"\0" STRING1
"\0");
1366 check_button_size(hToolbar
, 23, 23 + fontheight
);
1368 /* TB_SETBUTTONSIZE can be used to crop the text */
1369 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1370 check_button_size(hToolbar
, 23, 22);
1372 /* the default size is bitmap size + padding */
1373 SendMessageA(hToolbar
, TB_SETPADDING
, 0, MAKELONG(1, 1));
1374 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1375 check_button_size(hToolbar
, 17, 17);
1376 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(3, 3));
1377 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(3, 3));
1378 check_button_size(hToolbar
, 4, 4);
1380 rebuild_toolbar(&hToolbar
);
1381 /* sending a TB_SETBITMAPSIZE with the same sizes is enough to make the button smaller */
1382 check_button_size(hToolbar
, 23, 22);
1383 SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(16, 15));
1384 check_button_size(hToolbar
, 23, 21);
1385 /* -1 in TB_SETBITMAPSIZE is a special code meaning that the coordinate shouldn't be changed */
1386 add_128x15_bitmap(hToolbar
, 16);
1387 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(14, -1)), "TB_SETBITMAPSIZE failed\n");
1388 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 21), "%x");
1389 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(-1, 12)), "TB_SETBITMAPSIZE failed\n");
1390 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 18), "%x");
1391 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(-1, -1)), "TB_SETBITMAPSIZE failed\n");
1392 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), MAKELONG(21, 18), "%x");
1393 /* check the imagelist */
1394 InvalidateRect(hToolbar
, NULL
, TRUE
);
1395 UpdateWindow(hToolbar
);
1396 CHECK_IMAGELIST(16, 14, 12);
1398 rebuild_toolbar(&hToolbar
);
1399 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)STRING0
"\0" STRING1
"\0");
1400 /* the height is increased after a TB_ADDSTRINGA */
1401 check_button_size(hToolbar
, 23, 23 + fontheight
);
1402 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1403 /* if a string is in the pool, even adding a button without a string resets the size */
1404 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons2
[0]);
1405 check_button_size(hToolbar
, 23, 22);
1406 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1407 /* an BTNS_AUTOSIZE button is also considered when computing the new size */
1408 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[2]);
1409 check_button_size(hToolbar
, 7 + string_width(STRING1
), 23 + fontheight
);
1410 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[0]);
1412 /* delete button doesn't change the buttons size */
1413 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 2, 0);
1414 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 1, 0);
1415 check_button_size(hToolbar
, 7 + string_width(STRING1
), 23 + fontheight
);
1416 /* TB_INSERTBUTTONAS will */
1417 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, 1, (LPARAM
)&buttons2
[0]);
1418 check_button_size(hToolbar
, 23, 22);
1420 /* TB_HIDEBUTTON and TB_MOVEBUTTON doesn't force a recalc */
1421 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1422 ok(SendMessageA(hToolbar
, TB_MOVEBUTTON
, 0, 1), "TB_MOVEBUTTON failed\n");
1423 check_button_size(hToolbar
, 100, 100);
1424 ok(SendMessageA(hToolbar
, TB_HIDEBUTTON
, 20, TRUE
), "TB_HIDEBUTTON failed\n");
1425 check_button_size(hToolbar
, 100, 100);
1426 /* however changing the hidden flag with TB_SETSTATE does */
1427 ok(SendMessageA(hToolbar
, TB_SETSTATE
, 20, TBSTATE_ENABLED
|TBSTATE_HIDDEN
), "TB_SETSTATE failed\n");
1428 check_button_size(hToolbar
, 100, 100);
1429 ok(SendMessageA(hToolbar
, TB_SETSTATE
, 20, TBSTATE_ENABLED
), "TB_SETSTATE failed\n");
1430 check_button_size(hToolbar
, 23, 22);
1432 /* TB_SETIMAGELIST always changes the height but the width only if necessary */
1433 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1434 himl
= ImageList_LoadImageA(GetModuleHandleA(NULL
), (LPCSTR
)MAKEINTRESOURCE(IDB_BITMAP_80x15
),
1435 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
1436 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1437 check_button_size(hToolbar
, 100, 21);
1438 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(100, 100));
1439 check_button_size(hToolbar
, 100, 100);
1440 /* But there are no update when we change imagelist, and image sizes are the same */
1441 himl2
= ImageList_LoadImageA(GetModuleHandleA(NULL
), (LPCSTR
)MAKEINTRESOURCE(IDB_BITMAP_128x15
),
1442 20, 2, CLR_NONE
, IMAGE_BITMAP
, LR_DEFAULTCOLOR
);
1443 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LRESULT
)himl2
) == (LRESULT
)himl
, "TB_SETIMAGELIST failed\n");
1444 check_button_size(hToolbar
, 100, 100);
1445 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(1, 1));
1446 check_button_size(hToolbar
, 27, 21);
1447 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, 0) == (LRESULT
)himl2
, "TB_SETIMAGELIST failed\n");
1448 check_button_size(hToolbar
, 27, 7);
1449 SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELONG(1, 1));
1450 check_button_size(hToolbar
, 8, 7)
1451 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1452 check_button_size(hToolbar
, 27, 21)
1453 /* the text is taken into account */
1454 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)STRING0
"\0" STRING1
"\0");
1455 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 4, (LPARAM
)buttons3
);
1456 check_button_size(hToolbar
, 7 + string_width(STRING1
), 22 + fontheight
);
1457 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, 0) == (LRESULT
)himl
, "TB_SETIMAGELIST failed\n");
1458 check_button_size(hToolbar
, 7 + string_width(STRING1
), 8 + fontheight
);
1459 /* the style change also comes into effect */
1461 SetWindowLongA(hToolbar
, GWL_STYLE
, GetWindowLongA(hToolbar
, GWL_STYLE
) | TBSTYLE_FLAT
);
1462 ok(SendMessageA(hToolbar
, TB_SETIMAGELIST
, 0, (LPARAM
)himl
) == 0, "TB_SETIMAGELIST failed\n");
1463 check_sizes_todo(0x30); /* some small problems with BTNS_AUTOSIZE button sizes */
1465 rebuild_toolbar(&hToolbar
);
1466 ImageList_Destroy(himl
);
1467 ImageList_Destroy(himl2
);
1469 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]);
1470 check_button_size(hToolbar
, 7 + string_width(STRING2
), 23 + fontheight
);
1471 SendMessageA(hToolbar
, TB_DELETEBUTTON
, 0, 0);
1472 check_button_size(hToolbar
, 7 + string_width(STRING2
), 23 + fontheight
);
1474 rebuild_toolbar(&hToolbar
);
1476 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1477 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1478 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons2
[0]) == 1, "TB_ADDBUTTONSA failed\n");
1479 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[2]) == 1, "TB_ADDBUTTONSA failed\n");
1480 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[0]) == 1, "TB_ADDBUTTONSA failed\n");
1481 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1484 rebuild_toolbar(&hToolbar
);
1485 SetWindowLongA(hToolbar
, GWL_STYLE
, TBSTYLE_LIST
| GetWindowLongA(hToolbar
, GWL_STYLE
));
1486 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1487 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1488 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons2
[0]) == 1, "TB_ADDBUTTONSA failed\n");
1489 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[2]) == 1, "TB_ADDBUTTONSA failed\n");
1490 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONSA failed\n");
1491 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1492 check_sizes_todo(0xff);
1494 rebuild_toolbar(&hToolbar
);
1495 SetWindowLongA(hToolbar
, GWL_STYLE
, TBSTYLE_LIST
| GetWindowLongA(hToolbar
, GWL_STYLE
));
1496 ok(SendMessageA(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(32, 32)) == 1, "TB_SETBITMAPSIZE failed\n");
1497 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(100, 100)) == 1, "TB_SETBUTTONSIZE failed\n");
1498 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONSA failed\n");
1499 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1502 rebuild_toolbar(&hToolbar
);
1503 SetWindowLongA(hToolbar
, GWL_STYLE
, TBSTYLE_WRAPABLE
| GetWindowLongA(hToolbar
, GWL_STYLE
));
1504 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONSA failed\n");
1505 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]) == 1, "TB_ADDBUTTONSA failed\n");
1507 tbinfo
.cbSize
= sizeof(TBBUTTONINFOA
);
1508 tbinfo
.dwMask
= TBIF_SIZE
| TBIF_BYINDEX
;
1509 if (SendMessageA(hToolbar
, TB_SETBUTTONINFOA
, 0, (LPARAM
)&tbinfo
))
1511 ok(SendMessageA(hToolbar
, TB_SETBUTTONINFOA
, 1, (LPARAM
)&tbinfo
) != 0, "TB_SETBUTTONINFOA failed\n");
1512 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0);
1515 else /* TBIF_BYINDEX probably not supported, confirm that this was the reason for the failure */
1517 tbinfo
.dwMask
= TBIF_SIZE
;
1518 ok(SendMessageA(hToolbar
, TB_SETBUTTONINFOA
, 33, (LPARAM
)&tbinfo
) != 0, "TB_SETBUTTONINFOA failed\n");
1522 /* Single BTNS_AUTOSIZE button with string. */
1523 rebuild_toolbar(&hToolbar
);
1524 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons4
[0]) == 1, "TB_ADDBUTTONSA failed\n");
1525 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1526 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1529 /* Single non-BTNS_AUTOSIZE button with string. */
1530 rebuild_toolbar(&hToolbar
);
1531 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons4
[1]) == 1, "TB_ADDBUTTONSA failed\n");
1532 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1533 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1536 /* Single non-BTNS_AUTOSIZE button with string with TBSTYLE_EX_MIXEDBUTTONS set. */
1537 rebuild_toolbar(&hToolbar
);
1538 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1539 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons4
[1]) == 1, "TB_ADDBUTTONSA failed\n");
1540 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1541 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1544 /* Single non-BTNS_AUTOSIZE, BTNS_SHOWTEXT button with string with TBSTYLE_EX_MIXEDBUTTONS set. */
1545 rebuild_toolbar(&hToolbar
);
1546 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1547 ok(SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons4
[2]) == 1, "TB_ADDBUTTONSA failed\n");
1548 ok(SendMessageA(hToolbar
, TB_SETBUTTONSIZE
, 0, MAKELPARAM(40, 20)) == 1, "TB_SETBUTTONSIZE failed\n");
1549 SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0 );
1552 free_tbsize_results();
1553 DestroyWindow(hToolbar
);
1556 /* Toolbar control has two ways of reacting to a change. We call them a
1557 * relayout and recalc. A recalc forces a recompute of values like button size
1558 * and top margin (the latter in comctl32 <v6), while a relayout uses the cached
1559 * values. This functions creates a flat toolbar with a top margin of a non-flat
1560 * toolbar. We will notice a recalc, as it will recompte the top margin and
1561 * change it to zero*/
1562 static void prepare_recalc_test(HWND
*phToolbar
)
1565 rebuild_toolbar_with_buttons(phToolbar
);
1566 SetWindowLongA(*phToolbar
, GWL_STYLE
,
1567 GetWindowLongA(*phToolbar
, GWL_STYLE
) | TBSTYLE_FLAT
);
1568 SendMessageA(*phToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1569 ok(rect
.top
== 2, "Test will make no sense because initial top is %d instead of 2\n",
1573 static BOOL
did_recalc(HWND hToolbar
)
1576 SendMessageA(hToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1577 ok(rect
.top
== 2 || rect
.top
== 0, "Unexpected top margin %d in recalc test\n",
1579 return (rect
.top
== 0);
1582 /* call after a recalc did happen to return to an unstable state */
1583 static void restore_recalc_state(HWND hToolbar
)
1586 /* return to style with a 2px top margin */
1587 SetWindowLongA(hToolbar
, GWL_STYLE
,
1588 SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0) & ~TBSTYLE_FLAT
);
1590 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 1, (LPARAM
)&buttons3
[3]);
1591 /* top margin will be 0px if a recalc occurs */
1592 SetWindowLongA(hToolbar
, GWL_STYLE
,
1593 SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0) | TBSTYLE_FLAT
);
1595 SendMessageA(hToolbar
, TB_GETITEMRECT
, 1, (LPARAM
)&rect
);
1596 ok(rect
.top
== 2, "Test will make no sense because initial top is %d instead of 2\n",
1600 static void test_recalc(void)
1602 HWND hToolbar
= NULL
;
1604 CHAR test
[] = "Test";
1605 const int EX_STYLES_COUNT
= 5;
1610 /* Like TB_ADDBUTTONSA tested in test_sized, inserting a button without text
1611 * results in a relayout, while adding one with text forces a recalc */
1612 prepare_recalc_test(&hToolbar
);
1613 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, 1, (LPARAM
)&buttons3
[0]);
1614 recalc
= did_recalc(hToolbar
);
1615 ok(!recalc
, "Unexpected recalc - adding button without text\n");
1617 prepare_recalc_test(&hToolbar
);
1618 SendMessageA(hToolbar
, TB_INSERTBUTTONA
, 1, (LPARAM
)&buttons3
[3]);
1619 recalc
= did_recalc(hToolbar
);
1620 ok(recalc
, "Expected a recalc - adding button with text\n");
1622 /* TB_SETBUTTONINFOA, even when adding a text, results only in a relayout */
1623 prepare_recalc_test(&hToolbar
);
1624 bi
.cbSize
= sizeof(bi
);
1625 bi
.dwMask
= TBIF_TEXT
;
1627 SendMessageA(hToolbar
, TB_SETBUTTONINFOA
, 1, (LPARAM
)&bi
);
1628 recalc
= did_recalc(hToolbar
);
1629 ok(!recalc
, "Unexpected recalc - setting a button text\n");
1631 /* most extended styled doesn't force a recalc (testing all the bits gives
1632 * the same results, but prints some ERRs while testing) */
1633 for (i
= 0; i
< EX_STYLES_COUNT
; i
++)
1635 if (i
== 1 || i
== 3) /* an undoc style and TBSTYLE_EX_MIXEDBUTTONS */
1637 prepare_recalc_test(&hToolbar
);
1638 expect(0, (int)SendMessageA(hToolbar
, TB_GETEXTENDEDSTYLE
, 0, 0));
1639 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, (1 << i
));
1640 recalc
= did_recalc(hToolbar
);
1641 ok(!recalc
, "Unexpected recalc - setting bit %d\n", i
);
1642 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, 0);
1643 recalc
= did_recalc(hToolbar
);
1644 ok(!recalc
, "Unexpected recalc - clearing bit %d\n", i
);
1645 expect(0, (int)SendMessageA(hToolbar
, TB_GETEXTENDEDSTYLE
, 0, 0));
1648 /* TBSTYLE_EX_MIXEDBUTTONS does a recalc on change */
1649 prepare_recalc_test(&hToolbar
);
1650 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1651 recalc
= did_recalc(hToolbar
);
1654 ok(recalc
, "Expected a recalc - setting TBSTYLE_EX_MIXEDBUTTONS\n");
1655 restore_recalc_state(hToolbar
);
1656 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_MIXEDBUTTONS
);
1657 recalc
= did_recalc(hToolbar
);
1658 ok(!recalc
, "Unexpected recalc - setting TBSTYLE_EX_MIXEDBUTTONS again\n");
1659 restore_recalc_state(hToolbar
);
1660 SendMessageA(hToolbar
, TB_SETEXTENDEDSTYLE
, 0, 0);
1661 recalc
= did_recalc(hToolbar
);
1662 ok(recalc
, "Expected a recalc - clearing TBSTYLE_EX_MIXEDBUTTONS\n");
1664 else win_skip( "No recalc on TBSTYLE_EX_MIXEDBUTTONS\n" );
1666 /* undocumented exstyle 0x2 seems to change the top margin, which
1667 * interferes with these tests */
1669 /* Show that a change in TBSTYLE_WRAPABLE causes a recalc */
1670 prepare_recalc_test(&hToolbar
);
1671 style
= SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0);
1672 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
);
1673 recalc
= did_recalc(hToolbar
);
1674 ok(!recalc
, "recalc %d\n", recalc
);
1676 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
| TBSTYLE_TOOLTIPS
| TBSTYLE_TRANSPARENT
| CCS_BOTTOM
);
1677 recalc
= did_recalc(hToolbar
);
1678 ok(!recalc
, "recalc %d\n", recalc
);
1680 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
| TBSTYLE_WRAPABLE
);
1681 recalc
= did_recalc(hToolbar
);
1682 ok(recalc
, "recalc %d\n", recalc
);
1683 restore_recalc_state(hToolbar
);
1685 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
| TBSTYLE_WRAPABLE
);
1686 recalc
= did_recalc(hToolbar
);
1687 ok(!recalc
, "recalc %d\n", recalc
);
1689 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
);
1690 recalc
= did_recalc(hToolbar
);
1691 ok(recalc
, "recalc %d\n", recalc
);
1692 restore_recalc_state(hToolbar
);
1694 /* Changing CCS_VERT does not recalc */
1695 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
| CCS_VERT
);
1696 recalc
= did_recalc(hToolbar
);
1697 ok(!recalc
, "recalc %d\n", recalc
);
1698 restore_recalc_state(hToolbar
);
1700 SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style
);
1701 recalc
= did_recalc(hToolbar
);
1702 ok(!recalc
, "recalc %d\n", recalc
);
1703 restore_recalc_state(hToolbar
);
1705 /* Setting the window's style directly also causes recalc */
1706 SetWindowLongA(hToolbar
, GWL_STYLE
, style
| TBSTYLE_WRAPABLE
);
1707 recalc
= did_recalc(hToolbar
);
1708 ok(recalc
, "recalc %d\n", recalc
);
1710 DestroyWindow(hToolbar
);
1713 static void test_getbuttoninfo(void)
1715 HWND hToolbar
= NULL
;
1718 rebuild_toolbar_with_buttons(&hToolbar
);
1719 for (i
= 0; i
< 128; i
++)
1725 tbi
.dwMask
= TBIF_COMMAND
;
1726 ret
= (int)SendMessageA(hToolbar
, TB_GETBUTTONINFOA
, 1, (LPARAM
)&tbi
);
1727 if (i
== sizeof(TBBUTTONINFOA
)) {
1728 compare(ret
, 0, "%d");
1730 compare(ret
, -1, "%d");
1733 DestroyWindow(hToolbar
);
1736 static void test_createtoolbarex(void)
1740 ZeroMemory(&btns
, sizeof(btns
));
1742 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1743 3, 20, 20, 16, 16, sizeof(TBBUTTON
));
1744 CHECK_IMAGELIST(16, 20, 20);
1745 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x1a001b, "%x");
1746 DestroyWindow(hToolbar
);
1748 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1749 3, 4, 4, 16, 16, sizeof(TBBUTTON
));
1750 CHECK_IMAGELIST(32, 4, 4);
1751 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xa000b, "%x");
1752 DestroyWindow(hToolbar
);
1754 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1755 3, 0, 8, 12, 12, sizeof(TBBUTTON
));
1756 CHECK_IMAGELIST(16, 12, 12);
1757 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x120013, "%x");
1758 DestroyWindow(hToolbar
);
1760 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1761 3, -1, 8, 12, 12, sizeof(TBBUTTON
));
1762 CHECK_IMAGELIST(16, 12, 8);
1763 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xe0013, "%x");
1764 DestroyWindow(hToolbar
);
1766 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1767 3, -1, 8, -1, 12, sizeof(TBBUTTON
));
1768 CHECK_IMAGELIST(16, 16, 8);
1769 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0xe0017, "%x");
1770 DestroyWindow(hToolbar
);
1772 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1773 3, 0, 0, 12, -1, sizeof(TBBUTTON
));
1774 CHECK_IMAGELIST(16, 12, 16);
1775 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x160013, "%x");
1776 DestroyWindow(hToolbar
);
1778 hToolbar
= CreateToolbarEx(hMainWnd
, WS_VISIBLE
, 1, 16, GetModuleHandleA(NULL
), IDB_BITMAP_128x15
, btns
,
1779 3, 0, 0, 0, 12, sizeof(TBBUTTON
));
1780 CHECK_IMAGELIST(16, 16, 16);
1781 compare((int)SendMessageA(hToolbar
, TB_GETBUTTONSIZE
, 0, 0), 0x160017, "%x");
1782 DestroyWindow(hToolbar
);
1785 static void test_dispinfo(void)
1787 HWND hToolbar
= NULL
;
1788 const TBBUTTON buttons_disp
[] = {
1789 {-1, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1790 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1794 rebuild_toolbar(&hToolbar
);
1795 SendMessageA(hToolbar
, TB_LOADIMAGES
, IDB_HIST_SMALL_COLOR
, (LPARAM
)HINST_COMMCTRL
);
1796 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons_disp
);
1797 g_dwExpectedDispInfoMask
= TBNF_IMAGE
;
1798 /* Some TBN_GETDISPINFO tests will be done in MyWnd_Notify function.
1799 * We will receive TBN_GETDISPINFOW even if the control is ANSI */
1800 compare((BOOL
)SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 0, "%d");
1801 ShowWindow(hToolbar
, SW_SHOW
);
1802 UpdateWindow(hToolbar
);
1804 ret
= (BOOL
)SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, TRUE
, 0);
1805 compare(ret
, FALSE
, "%d");
1806 compare(SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 1L, "%ld");
1807 InvalidateRect(hToolbar
, NULL
, FALSE
);
1808 UpdateWindow(hToolbar
);
1810 ret
= (BOOL
)SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, FALSE
, 0);
1811 compare(ret
, TRUE
, "%d");
1812 compare(SendMessageA(hToolbar
, CCM_GETUNICODEFORMAT
, 0, 0), 0L, "%ld");
1813 InvalidateRect(hToolbar
, NULL
, FALSE
);
1814 UpdateWindow(hToolbar
);
1816 DestroyWindow(hToolbar
);
1817 g_dwExpectedDispInfoMask
= 0;
1827 static tbrows_result_t tbrows_results
[] =
1829 {1, TRUE
, 1}, /* 0: Simple case 9 in a row */
1830 {2, TRUE
, 2}, /* 1: Another simple case 5 on one row, 4 on another*/
1831 {3, FALSE
, 3}, /* 2: 3 lines - should be 3 lines of 3 buttons */
1832 {8, FALSE
, 5}, /* 3: 8 lines - should be 5 lines of 2 buttons */
1833 {8, TRUE
, 9}, /* 4: 8 lines but grow - should be 9 lines */
1834 {1, TRUE
, 1} /* 5: Back to simple case */
1837 static void test_setrows(void)
1839 TBBUTTON buttons
[9];
1844 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_FLAT
| TBSTYLE_CHECKGROUP
, 0);
1846 /* Test 1 - 9 buttons */
1847 hToolbar
= CreateToolbarEx(hMainWnd
,
1848 WS_VISIBLE
| WS_CLIPCHILDREN
| WS_CHILD
| CCS_NORESIZE
| CCS_NOPARENTALIGN
1849 | CCS_NOMOVEY
| CCS_TOP
,
1852 buttons
, sizeof(buttons
)/sizeof(buttons
[0]),
1853 20, 20, 0, 0, sizeof(TBBUTTON
));
1854 ok(hToolbar
!= NULL
, "Toolbar creation\n");
1855 ok(SendMessageA(hToolbar
, TB_AUTOSIZE
, 0, 0) == 0, "TB_AUTOSIZE failed\n");
1857 /* test setting rows to each of 1-10 with bLarger true and false */
1858 for (i
=0; i
<(sizeof(tbrows_results
) / sizeof(tbrows_result_t
)); i
++) {
1862 memset(&rc
, 0xCC, sizeof(rc
));
1863 SendMessageA(hToolbar
, TB_SETROWS
,
1864 MAKELONG(tbrows_results
[i
].nRows
, tbrows_results
[i
].bLarger
),
1867 rows
= SendMessageA(hToolbar
, TB_GETROWS
, MAKELONG(0,0), MAKELONG(0,0));
1868 ok(rows
== tbrows_results
[i
].expectedRows
,
1869 "[%d] Unexpected number of rows %d (expected %d)\n", i
, rows
,
1870 tbrows_results
[i
].expectedRows
);
1873 DestroyWindow(hToolbar
);
1876 static void test_getstring(void)
1878 HWND hToolbar
= NULL
;
1881 static const char answer
[] = "STR";
1882 static const WCHAR answerW
[] = { 'S','T','R',0 };
1885 hToolbar
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0, hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
1886 ok(hToolbar
!= NULL
, "Toolbar creation problem\n");
1888 r
= SendMessageA(hToolbar
, TB_GETSTRINGA
, MAKEWPARAM(0, 0), 0);
1891 win_skip("TB_GETSTRINGA and TB_GETSTRINGW need 5.80\n");
1892 DestroyWindow(hToolbar
);
1896 r
= SendMessageW(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(0, 0), 0);
1898 r
= SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)answer
);
1900 r
= SendMessageA(hToolbar
, TB_GETSTRINGA
, MAKEWPARAM(0, 0), 0);
1901 expect(lstrlenA(answer
), r
);
1902 r
= SendMessageW(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(0, 0), 0);
1903 expect(lstrlenA(answer
), r
);
1904 r
= SendMessageA(hToolbar
, TB_GETSTRINGA
, MAKEWPARAM(sizeof(str
), 0), (LPARAM
)str
);
1905 expect(lstrlenA(answer
), r
);
1906 expect(0, lstrcmpA(answer
, str
));
1907 r
= SendMessageW(hToolbar
, TB_GETSTRINGW
, MAKEWPARAM(sizeof(strW
), 0), (LPARAM
)strW
);
1908 expect(lstrlenA(answer
), r
);
1909 expect(0, lstrcmpW(answerW
, strW
));
1911 DestroyWindow(hToolbar
);
1914 static void test_tooltip(void)
1916 HWND hToolbar
= NULL
;
1917 const TBBUTTON buttons_disp
[] = {
1918 {-1, 20, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1919 {0, 21, TBSTATE_ENABLED
, 0, {0, }, 0, -1},
1921 NMTTDISPINFOW nmtti
;
1924 rebuild_toolbar(&hToolbar
);
1926 SendMessageA(hToolbar
, TB_ADDBUTTONSA
, 2, (LPARAM
)buttons_disp
);
1928 /* W used to get through toolbar code that assumes tooltip is always Unicode */
1929 memset(&nmtti
, 0, sizeof(nmtti
));
1930 nmtti
.hdr
.code
= TTN_GETDISPINFOW
;
1931 nmtti
.hdr
.idFrom
= 20;
1933 SendMessageA(hToolbar
, CCM_SETUNICODEFORMAT
, FALSE
, 0);
1935 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1936 SendMessageA(hToolbar
, WM_NOTIFY
, 0, (LPARAM
)&nmtti
);
1937 ok_sequence(sequences
, PARENT_SEQ_INDEX
, ttgetdispinfo_parent_seq
,
1938 "dispinfo from tooltip", TRUE
);
1940 g_ResetDispTextPtr
= TRUE
;
1941 SendMessageA(hToolbar
, WM_NOTIFY
, 0, (LPARAM
)&nmtti
);
1942 g_ResetDispTextPtr
= FALSE
;
1944 DestroyWindow(hToolbar
);
1946 /* TBSTYLE_TOOLTIPS */
1947 hToolbar
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0,
1948 hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
1949 tooltip
= (HWND
)SendMessageA(hToolbar
, TB_GETTOOLTIPS
, 0, 0);
1950 ok(tooltip
== NULL
, "got %p\n", tooltip
);
1951 DestroyWindow(hToolbar
);
1954 static void test_get_set_style(void)
1956 TBBUTTON buttons
[9];
1957 DWORD style
, style2
, ret
;
1962 MakeButton(buttons
+i
, 1000+i
, TBSTYLE_CHECKGROUP
, 0);
1963 MakeButton(buttons
+3, 1003, TBSTYLE_SEP
|TBSTYLE_GROUP
, 0);
1964 MakeButton(buttons
+6, 1006, TBSTYLE_SEP
, 0);
1966 hToolbar
= CreateToolbarEx(hMainWnd
,
1967 WS_VISIBLE
| WS_CLIPCHILDREN
| CCS_TOP
|
1968 WS_CHILD
| TBSTYLE_LIST
,
1971 buttons
, sizeof(buttons
)/sizeof(buttons
[0]),
1972 0, 0, 20, 16, sizeof(TBBUTTON
));
1973 ok(hToolbar
!= NULL
, "Toolbar creation\n");
1974 SendMessageA(hToolbar
, TB_ADDSTRINGA
, 0, (LPARAM
)"test\000");
1976 style
= SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0);
1977 style2
= GetWindowLongA(hToolbar
, GWL_STYLE
);
1979 ok(style
== style2
, "got 0x%08x, expected 0x%08x\n", style
, style2
);
1981 /* try to alter common window bits */
1982 style2
|= WS_BORDER
;
1983 ret
= SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style2
);
1984 ok(ret
== 0, "got %d\n", ret
);
1985 style
= SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0);
1986 style2
= GetWindowLongA(hToolbar
, GWL_STYLE
);
1987 ok((style
!= style2
) && (style
== (style2
| WS_BORDER
)),
1988 "got 0x%08x, expected 0x%08x\n", style
, style2
);
1989 ok(style
& WS_BORDER
, "got 0x%08x\n", style
);
1991 /* now styles are the same, alter window style */
1992 ret
= SendMessageA(hToolbar
, TB_SETSTYLE
, 0, style2
);
1993 ok(ret
== 0, "got %d\n", ret
);
1994 style2
|= WS_BORDER
;
1995 SetWindowLongA(hToolbar
, GWL_STYLE
, style2
);
1996 style
= SendMessageA(hToolbar
, TB_GETSTYLE
, 0, 0);
1997 ok(style
== style2
, "got 0x%08x, expected 0x%08x\n", style
, style2
);
1999 DestroyWindow(hToolbar
);
2002 static HHOOK g_tbhook
;
2003 static HWND g_toolbar
;
2005 DEFINE_EXPECT(g_hook_create
);
2006 DEFINE_EXPECT(g_hook_WM_NCCREATE
);
2007 DEFINE_EXPECT(g_hook_WM_CREATE
);
2009 static LRESULT WINAPI
toolbar_subclass_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2011 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
2015 if (msg
== WM_NCCREATE
)
2017 if (g_toolbar
== hwnd
)
2019 CHECK_EXPECT2(g_hook_WM_NCCREATE
);
2021 ret
= CallWindowProcA(oldproc
, hwnd
, msg
, wParam
, lParam
);
2023 /* control is already set up */
2024 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
2025 ok(style
!= 0, "got %x\n", style
);
2027 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2028 ok((style
& TBSTYLE_TOOLTIPS
) == 0, "got 0x%08x\n", style
);
2029 SetWindowLongA(hwnd
, GWL_STYLE
, style
|TBSTYLE_TOOLTIPS
);
2030 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2031 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
2036 else if (msg
== WM_CREATE
)
2038 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
2040 if (g_toolbar
== hwnd
)
2042 CHECK_EXPECT2(g_hook_WM_CREATE
);
2044 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2045 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
2047 /* test if toolbar-specific messages are already working before WM_CREATE */
2048 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
2049 ok(style
!= 0, "got %x\n", style
);
2050 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%x\n", style
);
2051 ok((cs
->style
& TBSTYLE_TOOLTIPS
) == 0, "0x%08x\n", cs
->style
);
2053 ret
= CallWindowProcA(oldproc
, hwnd
, msg
, wParam
, lParam
);
2055 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2056 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
2058 /* test if toolbar-specific messages are already working before WM_CREATE */
2059 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
2060 ok(style
!= 0, "got %x\n", style
);
2061 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%x\n", style
);
2067 return CallWindowProcA(oldproc
, hwnd
, msg
, wParam
, lParam
);
2070 static LRESULT CALLBACK
cbt_hook_proc(int code
, WPARAM wParam
, LPARAM lParam
)
2072 if (code
== HCBT_CREATEWND
)
2074 HWND hwnd
= (HWND
)wParam
;
2080 CHECK_EXPECT2(g_hook_create
);
2083 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)toolbar_subclass_proc
);
2084 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
2089 return CallNextHookEx(g_tbhook
, code
, wParam
, lParam
);
2092 static void test_create(void)
2097 g_tbhook
= SetWindowsHookA(WH_CBT
, cbt_hook_proc
);
2099 SET_EXPECT(g_hook_create
);
2100 SET_EXPECT(g_hook_WM_NCCREATE
);
2101 SET_EXPECT(g_hook_WM_CREATE
);
2103 hwnd
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, NULL
, WS_CHILD
| WS_VISIBLE
, 0, 0, 0, 0,
2104 hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
2106 CHECK_CALLED(g_hook_create
);
2107 CHECK_CALLED(g_hook_WM_NCCREATE
);
2108 CHECK_CALLED(g_hook_WM_CREATE
);
2110 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2111 ok((style
& TBSTYLE_TOOLTIPS
) == TBSTYLE_TOOLTIPS
, "got 0x%08x\n", style
);
2113 tooltip
= (HWND
)SendMessageA(hwnd
, TB_GETTOOLTIPS
, 0, 0);
2114 ok(tooltip
!= NULL
, "got %p\n", tooltip
);
2115 ok(GetParent(tooltip
) == hMainWnd
, "got %p, %p\n", hMainWnd
, hwnd
);
2117 DestroyWindow(hwnd
);
2118 UnhookWindowsHook(WH_CBT
, cbt_hook_proc
);
2120 /* TBSTYLE_TRANSPARENT */
2121 hwnd
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, NULL
,
2122 WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|TBSTYLE_FLAT
|TBSTYLE_TOOLTIPS
|TBSTYLE_GROUP
,
2123 0, 0, 0, 0, hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
2125 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
2126 ok((style
& TBSTYLE_TRANSPARENT
) == TBSTYLE_TRANSPARENT
, "got 0x%08x\n", style
);
2128 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
2129 ok((style
& TBSTYLE_TRANSPARENT
) == TBSTYLE_TRANSPARENT
, "got 0x%08x\n", style
);
2131 DestroyWindow(hwnd
);
2140 static const extended_style_t extended_style_test
[] = {
2142 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
,
2143 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
,
2144 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
2147 TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
,
2148 TBSTYLE_EX_DRAWDDARROWS
| TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_DOUBLEBUFFER
| TBSTYLE_EX_MIXEDBUTTONS
2151 { 0, TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
},
2153 { 0, TBSTYLE_EX_DRAWDDARROWS
, TBSTYLE_EX_DRAWDDARROWS
},
2154 { 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS
, TBSTYLE_EX_HIDECLIPPEDBUTTONS
},
2157 { TBSTYLE_EX_HIDECLIPPEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
, 0 },
2158 { TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_HIDECLIPPEDBUTTONS
, 0 },
2159 { TBSTYLE_EX_DOUBLEBUFFER
, TBSTYLE_EX_MIXEDBUTTONS
, 0 },
2162 TBSTYLE_EX_DOUBLEBUFFER
| TBSTYLE_EX_MIXEDBUTTONS
,
2163 TBSTYLE_EX_MIXEDBUTTONS
, TBSTYLE_EX_MIXEDBUTTONS
2166 TBSTYLE_EX_DOUBLEBUFFER
| TBSTYLE_EX_MIXEDBUTTONS
,
2167 TBSTYLE_EX_DOUBLEBUFFER
, TBSTYLE_EX_DOUBLEBUFFER
2171 static void test_TB_GET_SET_EXTENDEDSTYLE(void)
2173 DWORD style
, oldstyle
, oldstyle2
;
2174 const extended_style_t
*ptr
;
2178 rebuild_toolbar(&hwnd
);
2180 SendMessageA(hwnd
, TB_SETEXTENDEDSTYLE
, TBSTYLE_EX_DOUBLEBUFFER
, TBSTYLE_EX_MIXEDBUTTONS
);
2181 style
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
2182 if (style
== TBSTYLE_EX_MIXEDBUTTONS
)
2184 win_skip("Some extended style bits are not supported\n");
2185 DestroyWindow(hwnd
);
2189 for (i
= 0; i
< sizeof(extended_style_test
)/sizeof(extended_style_t
); i
++)
2191 ptr
= &extended_style_test
[i
];
2193 oldstyle2
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
2195 oldstyle
= SendMessageA(hwnd
, TB_SETEXTENDEDSTYLE
, ptr
->mask
, ptr
->style
);
2196 ok(oldstyle
== oldstyle2
, "%d: got old style 0x%08x, expected 0x%08x\n", i
, oldstyle
, oldstyle2
);
2197 style
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
2198 ok(style
== ptr
->style_set
, "%d: got style 0x%08x, expected 0x%08x\n", i
, style
, ptr
->style_set
);
2201 /* Windows sets CCS_VERT when TB_GETEXTENDEDSTYLE is set */
2202 oldstyle2
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
2203 oldstyle
= SendMessageA(hwnd
, TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_VERTICAL
);
2204 ok(oldstyle
== oldstyle2
, "got old style 0x%08x, expected 0x%08x\n", oldstyle
, oldstyle2
);
2205 style
= SendMessageA(hwnd
, TB_GETEXTENDEDSTYLE
, 0, 0);
2206 ok(style
== TBSTYLE_EX_VERTICAL
, "got style 0x%08x, expected 0x%08x\n", style
, TBSTYLE_EX_VERTICAL
);
2207 style
= SendMessageA(hwnd
, TB_GETSTYLE
, 0, 0);
2209 ok(style
== CCS_VERT
, "got style 0x%08x, expected CCS_VERT\n", style
);
2211 DestroyWindow(hwnd
);
2214 static void test_noresize(void)
2218 TBBUTTON button
= {0, 10, TBSTATE_ENABLED
, 0, {0, }, 0, -1};
2220 wnd
= CreateWindowExA(0, TOOLBARCLASSNAMEA
, NULL
, WS_CHILD
| WS_VISIBLE
| CCS_NORESIZE
| TBSTYLE_WRAPABLE
, 0, 0, 100, 20,
2221 hMainWnd
, (HMENU
)5, GetModuleHandleA(NULL
), NULL
);
2222 SendMessageA(wnd
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
2224 for (i
=0; i
<30; i
++)
2226 button
.idCommand
= 10 + i
;
2227 SendMessageA(wnd
, TB_ADDBUTTONSA
, 1, (LPARAM
)&button
);
2230 SendMessageA(wnd
, TB_SETSTATE
, 10, TBSTATE_WRAP
|TBSTATE_ENABLED
);
2232 /* autosize clears the wrap on button 0 */
2233 SendMessageA(wnd
, TB_AUTOSIZE
, 0, 0);
2234 for (i
=0; i
<30; i
++)
2236 SendMessageA(wnd
, TB_GETBUTTON
, i
, (LPARAM
)&button
);
2238 ok(button
.fsState
== (TBSTATE_WRAP
|TBSTATE_ENABLED
), "%d: got %08x\n", i
, button
.fsState
);
2240 ok(button
.fsState
== TBSTATE_ENABLED
, "%d: got %08x\n", i
, button
.fsState
);
2243 /* changing the parent doesn't do anything */
2244 MoveWindow(hMainWnd
, 0,0, 400, 200, FALSE
);
2245 for (i
=0; i
<30; i
++)
2247 SendMessageA(wnd
, TB_GETBUTTON
, i
, (LPARAM
)&button
);
2249 ok(button
.fsState
== (TBSTATE_WRAP
|TBSTATE_ENABLED
), "%d: got %08x\n", i
, button
.fsState
);
2251 ok(button
.fsState
== TBSTATE_ENABLED
, "%d: got %08x\n", i
, button
.fsState
);
2254 /* again nothing here */
2255 SendMessageA(wnd
, TB_AUTOSIZE
, 0, 0);
2256 for (i
=0; i
<30; i
++)
2258 SendMessageA(wnd
, TB_GETBUTTON
, i
, (LPARAM
)&button
);
2260 ok(button
.fsState
== (TBSTATE_WRAP
|TBSTATE_ENABLED
), "%d: got %08x\n", i
, button
.fsState
);
2262 ok(button
.fsState
== TBSTATE_ENABLED
, "%d: got %08x\n", i
, button
.fsState
);
2269 static void test_save(void)
2272 TBSAVEPARAMSW params
;
2273 static const WCHAR subkey
[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','T','e','s','t',0};
2274 static const WCHAR value
[] = {'t','o','o','l','b','a','r','t','e','s','t',0};
2278 DWORD size
= sizeof(data
), type
, i
, count
;
2280 static const TBBUTTON more_btns
[2] =
2282 {0, 11, TBSTATE_HIDDEN
, BTNS_BUTTON
, {0}, 0, -1},
2283 {0, 13, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, -1}
2285 static const DWORD expect
[] = {0xcafe, 1, 0xcafe0000, 3, 0xcafe0001, 5, 0xcafe0002, 7, 0xcafe0003,
2286 9, 0xcafe0004, 11, 0xcafe0005, 13, 0xcafe0006, 0xffffffff, 0xcafe0007,
2287 0xfffffffe, 0xcafe0008, 0x80000000, 0xcafe0009, 0x7fffffff, 0xcafe000a,
2289 static const TBBUTTON expect_btns
[] =
2291 {0, 1, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0},
2292 {0, 3, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 1, 2},
2293 {0, 5, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 2, 0},
2294 {0, 7, 0, BTNS_BUTTON
, {0}, 0, (INT_PTR
)"foo"},
2295 {0, 9, 0, BTNS_BUTTON
, {0}, 0, 0},
2296 {0, 11, 0, BTNS_BUTTON
, {0}, 0, 3},
2297 {0, 13, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 6, 0},
2298 {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 7, 0},
2299 {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 8, 0},
2300 {0, 0, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 9, 0},
2301 {0, 0x7fffffff, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0xa, 0},
2304 params
.hkr
= HKEY_CURRENT_USER
;
2305 params
.pszSubKey
= subkey
;
2306 params
.pszValueName
= value
;
2308 rebuild_toolbar_with_buttons( &wnd
);
2309 SendMessageW( wnd
, TB_ADDBUTTONSW
, sizeof(more_btns
) / sizeof(more_btns
[0]), (LPARAM
)more_btns
);
2311 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2312 res
= SendMessageW( wnd
, TB_SAVERESTOREW
, TRUE
, (LPARAM
)¶ms
);
2313 ok( res
, "saving failed\n" );
2314 ok_sequence(sequences
, PARENT_SEQ_INDEX
, save_parent_seq
, "save", FALSE
);
2315 DestroyWindow( wnd
);
2317 res
= RegOpenKeyW( HKEY_CURRENT_USER
, subkey
, &key
);
2318 ok( !res
, "got %08x\n", res
);
2319 res
= RegQueryValueExW( key
, value
, NULL
, &type
, data
, &size
);
2320 ok( !res
, "got %08x\n", res
);
2321 ok( type
== REG_BINARY
, "got %08x\n", type
);
2322 ok( size
== sizeof(expect
), "got %08x\n", size
);
2323 ok( !memcmp( data
, expect
, size
), "mismatch\n" );
2328 rebuild_toolbar( &wnd
);
2330 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
2331 res
= SendMessageW( wnd
, TB_SAVERESTOREW
, FALSE
, (LPARAM
)¶ms
);
2332 ok( res
, "restoring failed\n" );
2333 ok_sequence(sequences
, PARENT_SEQ_INDEX
, restore_parent_seq
, "restore", FALSE
);
2334 count
= SendMessageW( wnd
, TB_BUTTONCOUNT
, 0, 0 );
2335 ok( count
== sizeof(expect_btns
) / sizeof(expect_btns
[0]), "got %d\n", count
);
2337 for (i
= 0; i
< count
; i
++)
2339 res
= SendMessageW( wnd
, TB_GETBUTTON
, i
, (LPARAM
)&tb
);
2340 ok( res
, "got %d\n", res
);
2342 ok( tb
.iBitmap
== expect_btns
[i
].iBitmap
, "%d: got %d\n", i
, tb
.iBitmap
);
2343 ok( tb
.idCommand
== expect_btns
[i
].idCommand
, "%d: got %d\n", i
, tb
.idCommand
);
2344 ok( tb
.fsState
== expect_btns
[i
].fsState
, "%d: got %02x\n", i
, tb
.fsState
);
2345 ok( tb
.fsStyle
== expect_btns
[i
].fsStyle
, "%d: got %02x\n", i
, tb
.fsStyle
);
2346 ok( tb
.dwData
== expect_btns
[i
].dwData
, "%d: got %lx\n", i
, tb
.dwData
);
2347 if (IS_INTRESOURCE(expect_btns
[i
].iString
))
2348 ok( tb
.iString
== expect_btns
[i
].iString
, "%d: got %lx\n", i
, tb
.iString
);
2350 ok( !strcmp( (char *)tb
.iString
, (char *)expect_btns
[i
].iString
),
2351 "%d: got %s\n", i
, (char *)tb
.iString
);
2353 /* In fact the ptr value set in TBN_GETBUTTONINFOA is simply copied */
2354 if (tb
.idCommand
== 7)
2355 ok( tb
.iString
== (INT_PTR
)alloced_str
, "string not set\n");
2358 DestroyWindow( wnd
);
2359 RegOpenKeyW( HKEY_CURRENT_USER
, subkey
, &key
);
2360 RegDeleteValueW( key
, value
);
2370 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
2372 InitCommonControls();
2374 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2377 wc
.hInstance
= GetModuleHandleA(NULL
);
2379 wc
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_IBEAM
);
2380 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2381 wc
.lpszMenuName
= NULL
;
2382 wc
.lpszClassName
= "Toolbar test parent";
2383 wc
.lpfnWndProc
= parent_wnd_proc
;
2384 RegisterClassA(&wc
);
2386 hMainWnd
= CreateWindowExA(0, "Toolbar test parent", "Blah", WS_OVERLAPPEDWINDOW
,
2387 CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
2388 GetClientRect(hMainWnd
, &rc
);
2389 ShowWindow(hMainWnd
, SW_SHOW
);
2397 test_getbuttoninfo();
2398 test_createtoolbarex();
2403 test_get_set_style();
2405 test_TB_GET_SET_EXTENDEDSTYLE();
2410 while(GetMessageA(&msg
,0,0,0)) {
2411 TranslateMessage(&msg
);
2412 DispatchMessageA(&msg
);
2414 DestroyWindow(hMainWnd
);